github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/tests/x86check.c (about) 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 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 struct { 57 unsigned control; 58 unsigned status; 59 unsigned tag; 60 unsigned other[4]; 61 } calling_conventions_fenv; 62 #ifdef __cplusplus 63 } 64 #endif 65 66 /* expected values, as per x86call.asm */ 67 #define VALUE_EBX 0x01234567 68 #define VALUE_ESI 0x89ABCDEF 69 #define VALUE_EDI 0xFEDCBA98 70 #define VALUE_EBP 0x76543210 71 72 73 const char *regname[] = {"ebx", "ebp", "esi", "edi"}; 74 75 #define DIR_BIT(eflags) (((eflags) & (1<<10)) != 0) 76 77 78 /* Return 1 if ok, 0 if not */ 79 80 int 81 calling_conventions_check (void) 82 { 83 const char *header = "Violated calling conventions:\n"; 84 int ret = 1; 85 int i; 86 87 #define CHECK(callreg, regstr, value) \ 88 if (callreg != value) \ 89 { \ 90 printf ("%s %s got 0x%08X want 0x%08X\n", \ 91 header, regstr, callreg, value); \ 92 header = ""; \ 93 ret = 0; \ 94 } 95 96 for (i = 0; i < 4; i++) 97 { 98 CHECK (calling_conventions_values[VAL+i], regname[i], calling_conventions_values[WANT+i]); 99 } 100 101 if (DIR_BIT (calling_conventions_values[EFLAGS]) != 0) 102 { 103 printf ("%s eflags dir bit got %d want 0\n", 104 header, DIR_BIT (calling_conventions_values[EFLAGS])); 105 header = ""; 106 ret = 0; 107 } 108 109 if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF) 110 { 111 printf ("%s fpu tags got 0x%X want 0xFFFF\n", 112 header, calling_conventions_fenv.tag & 0xFFFF); 113 header = ""; 114 ret = 0; 115 } 116 117 return ret; 118 }