Blame tests/x86check.c

Packit 5c3484
/* x86 calling conventions checking. */
Packit 5c3484
Packit 5c3484
/*
Packit 5c3484
Copyright 2000, 2001, 2010 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[17] =
Packit 5c3484
{
Packit 5c3484
  CNST_LIMB(0x12345678),	/* want_ebx */
Packit 5c3484
  CNST_LIMB(0x89ABCDEF),	/* want_ebp */
Packit 5c3484
  CNST_LIMB(0xDEADBEEF),	/* want_esi */
Packit 5c3484
  CNST_LIMB(0xFFEEDDCC),	/* want_edi */
Packit 5c3484
Packit 5c3484
  CNST_LIMB(0xFEEDABBA),	/* JUNK_EAX */
Packit 5c3484
  CNST_LIMB(0xAB78DE89),	/* JUNK_ECX */
Packit 5c3484
  CNST_LIMB(0x12389018)		/* JUNK_EDX */
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	4
Packit 5c3484
#define SAVE	7
Packit 5c3484
#define RETADDR	11
Packit 5c3484
#define VAL	12
Packit 5c3484
#define EFLAGS	16
Packit 5c3484
Packit 5c3484
Packit 5c3484
/* values to check */
Packit 5c3484
#ifdef __cplusplus
Packit 5c3484
extern "C" {
Packit 5c3484
#endif
Packit 5c3484
struct {
Packit 5c3484
  unsigned  control;
Packit 5c3484
  unsigned  status;
Packit 5c3484
  unsigned  tag;
Packit 5c3484
  unsigned  other[4];
Packit 5c3484
} calling_conventions_fenv;
Packit 5c3484
#ifdef __cplusplus
Packit 5c3484
}
Packit 5c3484
#endif
Packit 5c3484
Packit 5c3484
/* expected values, as per x86call.asm */
Packit 5c3484
#define VALUE_EBX   0x01234567
Packit 5c3484
#define VALUE_ESI   0x89ABCDEF
Packit 5c3484
#define VALUE_EDI   0xFEDCBA98
Packit 5c3484
#define VALUE_EBP   0x76543210
Packit 5c3484
Packit 5c3484
Packit 5c3484
const char *regname[] = {"ebx", "ebp", "esi", "edi"};
Packit 5c3484
Packit 5c3484
#define DIR_BIT(eflags)   (((eflags) & (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%08X want 0x%08X\n",      \
Packit 5c3484
              header, regstr, callreg, value);          \
Packit 5c3484
      header = "";                                      \
Packit 5c3484
      ret = 0;                                          \
Packit 5c3484
    }
Packit 5c3484
Packit 5c3484
  for (i = 0; i < 4; 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[EFLAGS]) != 0)
Packit 5c3484
    {
Packit 5c3484
      printf ("%s   eflags dir bit  got %d want 0\n",
Packit 5c3484
              header, DIR_BIT (calling_conventions_values[EFLAGS]));
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
}