Blame tests/amd64check.c

Packit 5c3484
/* AMD64 calling conventions checking.
Packit 5c3484
Packit 5c3484
Copyright 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
Packit 5c3484
Packit 5c3484
This file is part of the GNU MP Library test suite.
Packit 5c3484
Packit 5c3484
The GNU MP Library test suite is free software; you can redistribute it
Packit 5c3484
and/or modify it under the terms of the GNU General Public License as
Packit 5c3484
published by the Free Software Foundation; either version 3 of the License,
Packit 5c3484
or (at your option) any later version.
Packit 5c3484
Packit 5c3484
The GNU MP Library test suite is distributed in the hope that it will be
Packit 5c3484
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5c3484
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 5c3484
Public License for more details.
Packit 5c3484
Packit 5c3484
You should have received a copy of the GNU General Public License along with
Packit 5c3484
the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
Packit 5c3484
Packit 5c3484
#include <stdio.h>
Packit 5c3484
#include "gmp.h"
Packit 5c3484
#include "gmp-impl.h"
Packit 5c3484
#include "tests.h"
Packit 5c3484
Packit 5c3484
Packit 5c3484
/* Vector if constants and register values.  We use one vector to allow access
Packit 5c3484
   via a base pointer, very beneficial for the PIC-enabled amd64call.asm.  */
Packit 5c3484
mp_limb_t calling_conventions_values[23] =
Packit 5c3484
{
Packit 5c3484
  CNST_LIMB(0x1234567887654321),	/* want_rbx */
Packit 5c3484
  CNST_LIMB(0x89ABCDEFFEDCBA98),	/* want_rbp */
Packit 5c3484
  CNST_LIMB(0xDEADBEEFBADECAFE),	/* want_r12 */
Packit 5c3484
  CNST_LIMB(0xFFEEDDCCBBAA9988),	/* want_r13 */
Packit 5c3484
  CNST_LIMB(0x0011223344556677),	/* want_r14 */
Packit 5c3484
  CNST_LIMB(0x1234432156788765),	/* want_r15 */
Packit 5c3484
Packit 5c3484
  CNST_LIMB(0xFEEDABBACAAFBEED),	/* JUNK_RAX */
Packit 5c3484
  CNST_LIMB(0xAB78DE89FF5125BB),	/* JUNK_R10 */
Packit 5c3484
  CNST_LIMB(0x1238901890189031)		/* JUNK_R11 */
Packit 5c3484
Packit 5c3484
  /* rest of array used for dynamic values.  */
Packit 5c3484
};
Packit 5c3484
Packit 5c3484
/* Index starts for various regions in above vector.  */
Packit 5c3484
#define WANT	0
Packit 5c3484
#define JUNK	6
Packit 5c3484
#define SAVE	9
Packit 5c3484
#define RETADDR	15
Packit 5c3484
#define VAL	16
Packit 5c3484
#define RFLAGS	22
Packit 5c3484
Packit 5c3484
/* values to check */
Packit 5c3484
#ifdef __cplusplus
Packit 5c3484
extern "C" {
Packit 5c3484
#endif
Packit 5c3484
struct {
Packit 5c3484
  int  control;
Packit 5c3484
  int  status;
Packit 5c3484
  int  tag;
Packit 5c3484
  int  other[4];
Packit 5c3484
} calling_conventions_fenv;
Packit 5c3484
#ifdef __cplusplus
Packit 5c3484
}
Packit 5c3484
#endif
Packit 5c3484
Packit 5c3484
Packit 5c3484
const char *regname[6] = {"rbx", "rbp", "r12", "r13", "r14", "r15"};
Packit 5c3484
Packit 5c3484
#define DIR_BIT(rflags)   (((rflags) & (1<<10)) != 0)
Packit 5c3484
Packit 5c3484
Packit 5c3484
/* Return 1 if ok, 0 if not */
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
calling_conventions_check (void)
Packit 5c3484
{
Packit 5c3484
  const char  *header = "Violated calling conventions:\n";
Packit 5c3484
  int  ret = 1;
Packit 5c3484
  int i;
Packit 5c3484
Packit 5c3484
#define CHECK(callreg, regstr, value)			\
Packit 5c3484
  if (callreg != value)					\
Packit 5c3484
    {							\
Packit 5c3484
      printf ("%s   %s	got 0x%016lX want 0x%016lX\n",	\
Packit 5c3484
	      header, regstr, callreg, value);		\
Packit 5c3484
      header = "";					\
Packit 5c3484
      ret = 0;						\
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  for (i = 0; i < 6; i++)
Packit 5c3484
    {
Packit 5c3484
      CHECK (calling_conventions_values[VAL+i], regname[i], calling_conventions_values[WANT+i]);
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  if (DIR_BIT (calling_conventions_values[RFLAGS]) != 0)
Packit 5c3484
    {
Packit 5c3484
      printf ("%s   rflags dir bit  got %d want 0\n",
Packit 5c3484
	      header, DIR_BIT (calling_conventions_values[RFLAGS]));
Packit 5c3484
      header = "";
Packit 5c3484
      ret = 0;
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF)
Packit 5c3484
    {
Packit 5c3484
      printf ("%s   fpu tags  got 0x%X want 0xFFFF\n",
Packit 5c3484
	      header, calling_conventions_fenv.tag & 0xFFFF);
Packit 5c3484
      header = "";
Packit 5c3484
      ret = 0;
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  return ret;
Packit 5c3484
}