Lines 1-6
Link Here
|
1 |
dnl x86 calling conventions checking. |
1 |
dnl x86 calling conventions checking. |
2 |
|
2 |
|
3 |
dnl Copyright 2000, 2003 Free Software Foundation, Inc. |
3 |
dnl Copyright 2000, 2003, 2010 Free Software Foundation, Inc. |
4 |
dnl |
4 |
dnl |
5 |
dnl This file is part of the GNU MP Library. |
5 |
dnl This file is part of the GNU MP Library. |
6 |
dnl |
6 |
dnl |
Lines 18-23
Link Here
|
18 |
dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. |
18 |
dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. |
19 |
|
19 |
|
20 |
|
20 |
|
|
|
21 |
dnl The current version of the code attempts to keep the call/return |
22 |
dnl prediction stack valid, but matching calls and returns. |
23 |
|
21 |
include(`../config.m4') |
24 |
include(`../config.m4') |
22 |
|
25 |
|
23 |
|
26 |
|
Lines 61-66
Link Here
|
61 |
C Perhaps the finit should be done only if the tags word isn't clear, but |
64 |
C Perhaps the finit should be done only if the tags word isn't clear, but |
62 |
C nothing uses the rounding mode or anything at the moment. |
65 |
C nothing uses the rounding mode or anything at the moment. |
63 |
|
66 |
|
|
|
67 |
define(`WANT_EBX', eval(4*0)($1)) |
68 |
define(`WANT_EBP', eval(4*1)($1)) |
69 |
define(`WANT_ESI', eval(4*2)($1)) |
70 |
define(`WANT_EDI', eval(4*3)($1)) |
71 |
|
72 |
define(`JUNK_EAX', eval(4*4)($1)) |
73 |
define(`JUNK_ECX', eval(4*5)($1)) |
74 |
define(`JUNK_EDX', eval(4*6)($1)) |
75 |
|
76 |
define(`SAVE_EBX', eval(4*7)($1)) |
77 |
define(`SAVE_EBP', eval(4*8)($1)) |
78 |
define(`SAVE_ESI', eval(4*9)($1)) |
79 |
define(`SAVE_EDI', eval(4*10)($1)) |
80 |
|
81 |
define(`RETADDR', eval(4*11)($1)) |
82 |
|
83 |
define(`EBX', eval(4*12)($1)) |
84 |
define(`EBP', eval(4*13)($1)) |
85 |
define(`ESI', eval(4*14)($1)) |
86 |
define(`EDI', eval(4*15)($1)) |
87 |
define(`EFLAGS', eval(4*16)($1)) |
88 |
|
89 |
|
64 |
define(G, |
90 |
define(G, |
65 |
m4_assert_numargs(1) |
91 |
m4_assert_numargs(1) |
66 |
`GSYM_PREFIX`'$1') |
92 |
`GSYM_PREFIX`'$1') |
Lines 68-115
Link Here
|
68 |
.text |
94 |
.text |
69 |
ALIGN(8) |
95 |
ALIGN(8) |
70 |
PROLOGUE(calling_conventions) |
96 |
PROLOGUE(calling_conventions) |
71 |
movl (%esp), %eax |
97 |
LEA( G(calling_conventions_values), %ecx) |
72 |
movl %eax, G(calling_conventions_retaddr) |
98 |
popl RETADDR(%ecx) |
73 |
|
99 |
|
74 |
movl $L(return), (%esp) |
100 |
movl %ebx, SAVE_EBX(%ecx) |
75 |
|
101 |
movl %ebp, SAVE_EBP(%ecx) |
76 |
movl %ebx, G(calling_conventions_save_ebx) |
102 |
movl %esi, SAVE_ESI(%ecx) |
77 |
movl %esi, G(calling_conventions_save_esi) |
103 |
movl %edi, SAVE_EDI(%ecx) |
78 |
movl %edi, G(calling_conventions_save_edi) |
104 |
|
79 |
movl %ebp, G(calling_conventions_save_ebp) |
105 |
movl WANT_EBX(%ecx), %ebx |
80 |
|
106 |
movl WANT_EBP(%ecx), %ebp |
81 |
movl $0x01234567, %ebx |
107 |
movl WANT_ESI(%ecx), %esi |
82 |
movl $0x89ABCDEF, %esi |
108 |
movl WANT_EDI(%ecx), %edi |
83 |
movl $0xFEDCBA98, %edi |
109 |
|
84 |
movl $0x76543210, %ebp |
110 |
C try to provoke a problem by starting with junk in the caller-saves |
85 |
|
111 |
C registers, especially in %eax and %edx which will be return values |
86 |
C try to provoke a problem by starting with junk in the registers, |
112 |
movl JUNK_EAX(%ecx), %eax |
87 |
C especially in %eax and %edx which will be return values |
113 |
movl JUNK_EDX(%ecx), %edx |
88 |
movl $0x70246135, %eax |
114 |
C movl JUNK_ECX(%ecx), %ecx |
89 |
movl $0x8ACE9BDF, %ecx |
115 |
|
90 |
movl $0xFDB97531, %edx |
116 |
ifdef(`PIC',` |
91 |
|
117 |
LEA( G(calling_conventions_function), %ecx) |
92 |
jmp *G(calling_conventions_function) |
118 |
call *(%ecx) |
93 |
|
119 |
',` |
94 |
L(return): |
120 |
call *G(calling_conventions_function) |
95 |
movl %ebx, G(calling_conventions_ebx) |
121 |
') |
96 |
movl %esi, G(calling_conventions_esi) |
122 |
|
97 |
movl %edi, G(calling_conventions_edi) |
123 |
LEA( G(calling_conventions_values), %ecx) |
98 |
movl %ebp, G(calling_conventions_ebp) |
124 |
|
|
|
125 |
movl %ebx, EBX(%ecx) |
126 |
movl %ebp, EBP(%ecx) |
127 |
movl %esi, ESI(%ecx) |
128 |
movl %edi, EDI(%ecx) |
99 |
|
129 |
|
100 |
pushf |
130 |
pushf |
101 |
popl %ebx |
131 |
popl %ebx |
102 |
movl %ebx, G(calling_conventions_eflags) |
132 |
movl %ebx, EFLAGS(%ecx) |
103 |
|
133 |
|
|
|
134 |
movl SAVE_EBX(%ecx), %ebx |
135 |
movl SAVE_ESI(%ecx), %esi |
136 |
movl SAVE_EDI(%ecx), %edi |
137 |
movl SAVE_EBP(%ecx), %ebp |
138 |
|
139 |
pushl RETADDR(%ecx) |
140 |
|
141 |
ifdef(`PIC',` |
142 |
LEA( G(calling_conventions_fenv), %ecx) |
143 |
fstenv (%ecx) |
144 |
',` |
104 |
fstenv G(calling_conventions_fenv) |
145 |
fstenv G(calling_conventions_fenv) |
|
|
146 |
') |
105 |
finit |
147 |
finit |
106 |
|
148 |
|
107 |
movl G(calling_conventions_save_ebx), %ebx |
149 |
ret |
108 |
movl G(calling_conventions_save_esi), %esi |
|
|
109 |
movl G(calling_conventions_save_edi), %edi |
110 |
movl G(calling_conventions_save_ebp), %ebp |
111 |
|
112 |
jmp *G(calling_conventions_retaddr) |
113 |
|
150 |
|
114 |
EPILOGUE() |
151 |
EPILOGUE() |
115 |
|
|
|