source: trunk/third/gmp/tests/x86check.c @ 18191

Revision 18191, 2.9 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* x86 calling conventions checking. */
2
3/*
4Copyright 2000, 2001 Free Software Foundation, Inc.
5
6This file is part of the GNU MP Library.
7
8The GNU MP Library is free software; you can redistribute it and/or modify
9it under the terms of the GNU Lesser General Public License as published by
10the Free Software Foundation; either version 2.1 of the License, or (at your
11option) any later version.
12
13The GNU MP Library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21MA 02111-1307, USA.
22*/
23
24#include <stdio.h>
25#include "gmp.h"
26#include "gmp-impl.h"
27#include "tests.h"
28
29
30/* temporaries */
31int  calling_conventions_save_ebx;
32int  calling_conventions_save_esi;
33int  calling_conventions_save_edi;
34int  calling_conventions_save_ebp;
35int  calling_conventions_retaddr;
36int  calling_conventions_retval;
37
38/* values to check */
39struct {
40  unsigned  control;
41  unsigned  status;
42  unsigned  tag;
43  unsigned  other[4];
44} calling_conventions_fenv;
45int  calling_conventions_ebx;
46int  calling_conventions_esi;
47int  calling_conventions_edi;
48int  calling_conventions_ebp;
49int  calling_conventions_eflags;
50
51/* expected values, as per x86call.asm */
52#define VALUE_EBX   0x01234567
53#define VALUE_ESI   0x89ABCDEF
54#define VALUE_EDI   0xFEDCBA98
55#define VALUE_EBP   0x76543210
56
57#define DIR_BIT(eflags)   (((eflags) & (1<<10)) != 0)
58
59
60/* Return 1 if ok, 0 if not */
61
62int
63calling_conventions_check (void)
64{
65  const char  *header = "Violated calling conventions:\n";
66  int  ret = 1;
67
68#define CHECK(callreg, regstr, value)                   \
69  if (callreg != value)                                 \
70    {                                                   \
71      printf ("%s   %s  got 0x%08X want 0x%08X\n",      \
72              header, regstr, callreg, value);          \
73      header = "";                                      \
74      ret = 0;                                          \
75    }
76
77  CHECK (calling_conventions_ebx, "ebx", VALUE_EBX);
78  CHECK (calling_conventions_esi, "esi", VALUE_ESI);
79  CHECK (calling_conventions_edi, "edi", VALUE_EDI);
80  CHECK (calling_conventions_ebp, "ebp", VALUE_EBP);
81
82  if (DIR_BIT (calling_conventions_eflags) != 0)
83    {
84      printf ("%s   eflags dir bit  got %d want 0\n",
85              header, DIR_BIT (calling_conventions_eflags));
86      header = "";
87      ret = 0;
88    }
89
90  if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF)
91    {
92      printf ("%s   fpu tags  got 0x%X want 0xFFFF\n",
93              header, calling_conventions_fenv.tag & 0xFFFF);
94      header = "";
95      ret = 0;
96    }
97
98  return ret;
99}
Note: See TracBrowser for help on using the repository browser.