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