summaryrefslogtreecommitdiff
path: root/tests/x86check.c
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2010-11-29 16:48:22 +0100
committerTorbjorn Granlund <tege@gmplib.org>2010-11-29 16:48:22 +0100
commit19028f635911416e76e0aac3a7bcfefedf6250f6 (patch)
tree84e7989e61b58cda5c4b130821eb2d61c1ecd1ae /tests/x86check.c
parent198a1add0f2d556eb75bf2d85c7fceb9fafe9f51 (diff)
downloadgmp-19028f635911416e76e0aac3a7bcfefedf6250f6.tar.gz
Rewrite x86 calling conventions checking code for code size and to support PIC.
Diffstat (limited to 'tests/x86check.c')
-rw-r--r--tests/x86check.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/tests/x86check.c b/tests/x86check.c
index dfebd7a98..0e809e8b3 100644
--- a/tests/x86check.c
+++ b/tests/x86check.c
@@ -1,7 +1,7 @@
/* x86 calling conventions checking. */
/*
-Copyright 2000, 2001 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2010 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -24,13 +24,30 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "tests.h"
-/* temporaries */
-int calling_conventions_save_ebx;
-int calling_conventions_save_esi;
-int calling_conventions_save_edi;
-int calling_conventions_save_ebp;
-int calling_conventions_retaddr;
-int calling_conventions_retval;
+/* Vector if constants and register values. We use one vector to allow access
+ via a base pointer, very beneficial for the PIC-enabled amd64call.asm. */
+mp_limb_t calling_conventions_values[17] =
+{
+ CNST_LIMB(0x12345678), /* want_ebx */
+ CNST_LIMB(0x89ABCDEF), /* want_ebp */
+ CNST_LIMB(0xDEADBEEF), /* want_esi */
+ CNST_LIMB(0xFFEEDDCC), /* want_edi */
+
+ CNST_LIMB(0xFEEDABBA), /* JUNK_EAX */
+ CNST_LIMB(0xAB78DE89), /* JUNK_ECX */
+ CNST_LIMB(0x12389018) /* JUNK_EDX */
+
+ /* rest of array used for dynamic values. */
+};
+
+/* Index starts for various regions in above vector. */
+#define WANT 0
+#define JUNK 4
+#define SAVE 7
+#define RETADDR 11
+#define VAL 12
+#define EFLAGS 16
+
/* values to check */
struct {
@@ -39,11 +56,6 @@ struct {
unsigned tag;
unsigned other[4];
} calling_conventions_fenv;
-int calling_conventions_ebx;
-int calling_conventions_esi;
-int calling_conventions_edi;
-int calling_conventions_ebp;
-int calling_conventions_eflags;
/* expected values, as per x86call.asm */
#define VALUE_EBX 0x01234567
@@ -51,6 +63,9 @@ int calling_conventions_eflags;
#define VALUE_EDI 0xFEDCBA98
#define VALUE_EBP 0x76543210
+
+const char *regname[] = {"ebx", "ebp", "esi", "edi"};
+
#define DIR_BIT(eflags) (((eflags) & (1<<10)) != 0)
@@ -61,6 +76,7 @@ calling_conventions_check (void)
{
const char *header = "Violated calling conventions:\n";
int ret = 1;
+ int i;
#define CHECK(callreg, regstr, value) \
if (callreg != value) \
@@ -71,15 +87,15 @@ calling_conventions_check (void)
ret = 0; \
}
- CHECK (calling_conventions_ebx, "ebx", VALUE_EBX);
- CHECK (calling_conventions_esi, "esi", VALUE_ESI);
- CHECK (calling_conventions_edi, "edi", VALUE_EDI);
- CHECK (calling_conventions_ebp, "ebp", VALUE_EBP);
+ for (i = 0; i < 4; i++)
+ {
+ CHECK (calling_conventions_values[VAL+i], regname[i], calling_conventions_values[WANT+i]);
+ }
- if (DIR_BIT (calling_conventions_eflags) != 0)
+ if (DIR_BIT (calling_conventions_values[EFLAGS]) != 0)
{
printf ("%s eflags dir bit got %d want 0\n",
- header, DIR_BIT (calling_conventions_eflags));
+ header, DIR_BIT (calling_conventions_values[EFLAGS]));
header = "";
ret = 0;
}