1 /* AMD64 calling conventions checking.
3 Copyright 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 /* Vector if constants and register values. We use one vector to allow access
27 via a base pointer, very beneficial for the PIC-enabled amd64call.asm. */
28 mp_limb_t calling_conventions_values[23] =
30 CNST_LIMB(0x1234567887654321), /* want_rbx */
31 CNST_LIMB(0x89ABCDEFFEDCBA98), /* want_rbp */
32 CNST_LIMB(0xDEADBEEFBADECAFE), /* want_r12 */
33 CNST_LIMB(0xFFEEDDCCBBAA9988), /* want_r13 */
34 CNST_LIMB(0x0011223344556677), /* want_r14 */
35 CNST_LIMB(0x1234432156788765), /* want_r15 */
37 CNST_LIMB(0xFEEDABBACAAFBEED), /* JUNK_RAX */
38 CNST_LIMB(0xAB78DE89FF5125BB), /* JUNK_R10 */
39 CNST_LIMB(0x1238901890189031) /* JUNK_R11 */
41 /* rest of array used for dynamic values. */
44 /* Index starts for various regions in above vector. */
58 } calling_conventions_fenv;
61 char *regname[6] = {"rbx", "rbp", "r12", "r13", "r14", "r15"};
63 #define DIR_BIT(rflags) (((rflags) & (1<<10)) != 0)
66 /* Return 1 if ok, 0 if not */
69 calling_conventions_check (void)
71 const char *header = "Violated calling conventions:\n";
75 #define CHECK(callreg, regstr, value) \
76 if (callreg != value) \
78 printf ("%s %s got 0x%016lX want 0x%016lX\n", \
79 header, regstr, callreg, value); \
84 for (i = 0; i < 6; i++)
86 CHECK (calling_conventions_values[VAL+i], regname[i], calling_conventions_values[WANT+i]);
89 if (DIR_BIT (calling_conventions_values[RFLAGS]) != 0)
91 printf ("%s rflags dir bit got %d want 0\n",
92 header, DIR_BIT (calling_conventions_values[RFLAGS]));
97 if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF)
99 printf ("%s fpu tags got 0x%X want 0xFFFF\n",
100 header, calling_conventions_fenv.tag & 0xFFFF);