1 /* x86 calling conventions checking. */
2
3 /*
4 Copyright 2000, 2001, 2010 Free Software Foundation, Inc.
5
6 This file is part of the GNU MP Library test suite.
7
8 The GNU MP Library test suite is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 3 of the License,
11 or (at your option) any later version.
12
13 The GNU MP Library test suite is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with
19 the GNU MP Library test suite. If not, see https://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 /* Vector if constants and register values. We use one vector to allow access
28 via a base pointer, very beneficial for the PIC-enabled amd64call.asm. */
29 mp_limb_t calling_conventions_values[17] =
30 {
31 CNST_LIMB(0x12345678), /* want_ebx */
32 CNST_LIMB(0x89ABCDEF), /* want_ebp */
33 CNST_LIMB(0xDEADBEEF), /* want_esi */
34 CNST_LIMB(0xFFEEDDCC), /* want_edi */
35
36 CNST_LIMB(0xFEEDABBA), /* JUNK_EAX */
37 CNST_LIMB(0xAB78DE89), /* JUNK_ECX */
38 CNST_LIMB(0x12389018) /* JUNK_EDX */
39
40 /* rest of array used for dynamic values. */
41 };
42
43 /* Index starts for various regions in above vector. */
44 #define WANT 0
45 #define JUNK 4
46 #define SAVE 7
47 #define RETADDR 11
48 #define VAL 12
49 #define EFLAGS 16
50
51
52 /* values to check */
53 struct {
54 unsigned control;
55 unsigned status;
56 unsigned tag;
57 unsigned other[4];
58 } calling_conventions_fenv;
59
60 /* expected values, as per x86call.asm */
61 #define VALUE_EBX 0x01234567
62 #define VALUE_ESI 0x89ABCDEF
63 #define VALUE_EDI 0xFEDCBA98
64 #define VALUE_EBP 0x76543210
65
66
67 const char *regname[] = {"ebx", "ebp", "esi", "edi"};
68
69 #define DIR_BIT(eflags) (((eflags) & (1<<10)) != 0)
70
71
72 /* Return 1 if ok, 0 if not */
73
74 int
calling_conventions_check(void)75 calling_conventions_check (void)
76 {
77 const char *header = "Violated calling conventions:\n";
78 int ret = 1;
79 int i;
80
81 #define CHECK(callreg, regstr, value) \
82 if (callreg != value) \
83 { \
84 printf ("%s %s got 0x%08X want 0x%08X\n", \
85 header, regstr, callreg, value); \
86 header = ""; \
87 ret = 0; \
88 }
89
90 for (i = 0; i < 4; i++)
91 {
92 CHECK (calling_conventions_values[VAL+i], regname[i], calling_conventions_values[WANT+i]);
93 }
94
95 if (DIR_BIT (calling_conventions_values[EFLAGS]) != 0)
96 {
97 printf ("%s eflags dir bit got %d want 0\n",
98 header, DIR_BIT (calling_conventions_values[EFLAGS]));
99 header = "";
100 ret = 0;
101 }
102
103 if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF)
104 {
105 printf ("%s fpu tags got 0x%X want 0xFFFF\n",
106 header, calling_conventions_fenv.tag & 0xFFFF);
107 header = "";
108 ret = 0;
109 }
110
111 return ret;
112 }
113