1 | /*
|
---|
2 | * dyngen defines for micro operation code
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003 Fabrice Bellard
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 | #if !defined(__DYNGEN_EXEC_H__)
|
---|
30 | #define __DYNGEN_EXEC_H__
|
---|
31 |
|
---|
32 | /* prevent Solaris from trying to typedef FILE in gcc's
|
---|
33 | include/floatingpoint.h which will conflict with the
|
---|
34 | definition down below */
|
---|
35 | #ifdef __sun__
|
---|
36 | #define _FILEDEFED
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | /* NOTE: standard headers should be used with special care at this
|
---|
40 | point because host CPU registers are used as global variables. Some
|
---|
41 | host headers do not allow that. */
|
---|
42 | #include <stddef.h>
|
---|
43 |
|
---|
44 | #ifndef VBOX
|
---|
45 |
|
---|
46 | typedef unsigned char uint8_t;
|
---|
47 | typedef unsigned short uint16_t;
|
---|
48 | typedef unsigned int uint32_t;
|
---|
49 | /* Linux/Sparc64 defines uint64_t */
|
---|
50 | #if !(defined (__sparc_v9__) && defined(__linux__))
|
---|
51 | /* XXX may be done for all 64 bits targets ? */
|
---|
52 | #if defined (__x86_64__) || defined(__ia64)
|
---|
53 | typedef unsigned long uint64_t;
|
---|
54 | #else
|
---|
55 | typedef unsigned long long uint64_t;
|
---|
56 | #endif
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | /* if Solaris/__sun__, don't typedef int8_t, as it will be typedef'd
|
---|
60 | prior to this and will cause an error in compliation, conflicting
|
---|
61 | with /usr/include/sys/int_types.h, line 75 */
|
---|
62 | #ifndef __sun__
|
---|
63 | typedef signed char int8_t;
|
---|
64 | #endif
|
---|
65 | typedef signed short int16_t;
|
---|
66 | typedef signed int int32_t;
|
---|
67 | // Linux/Sparc64 defines int64_t
|
---|
68 | #if !(defined (__sparc_v9__) && defined(__linux__))
|
---|
69 | #if defined (__x86_64__) || defined(__ia64)
|
---|
70 | typedef signed long int64_t;
|
---|
71 | #else
|
---|
72 | typedef signed long long int64_t;
|
---|
73 | #endif
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /* XXX: This may be wrong for 64-bit ILP32 hosts. */
|
---|
77 | typedef void * host_reg_t;
|
---|
78 |
|
---|
79 | #define INT8_MIN (-128)
|
---|
80 | #define INT16_MIN (-32767-1)
|
---|
81 | #define INT32_MIN (-2147483647-1)
|
---|
82 | #define INT64_MIN (-(int64_t)(9223372036854775807)-1)
|
---|
83 | #define INT8_MAX (127)
|
---|
84 | #define INT16_MAX (32767)
|
---|
85 | #define INT32_MAX (2147483647)
|
---|
86 | #define INT64_MAX ((int64_t)(9223372036854775807))
|
---|
87 | #define UINT8_MAX (255)
|
---|
88 | #define UINT16_MAX (65535)
|
---|
89 | #define UINT32_MAX (4294967295U)
|
---|
90 | #define UINT64_MAX ((uint64_t)(18446744073709551615))
|
---|
91 |
|
---|
92 | #ifdef _BSD
|
---|
93 | typedef struct __sFILE FILE;
|
---|
94 | #else
|
---|
95 | typedef struct FILE FILE;
|
---|
96 | #endif
|
---|
97 | extern int fprintf(FILE *, const char *, ...);
|
---|
98 | extern int fputs(const char *, FILE *);
|
---|
99 | extern int printf(const char *, ...);
|
---|
100 | #undef NULL
|
---|
101 | #define NULL 0
|
---|
102 |
|
---|
103 | #else /* VBOX */
|
---|
104 |
|
---|
105 | /* XXX: This may be wrong for 64-bit ILP32 hosts. */
|
---|
106 | typedef void * host_reg_t;
|
---|
107 |
|
---|
108 | #include <iprt/stdint.h>
|
---|
109 | #include <stdio.h>
|
---|
110 |
|
---|
111 | #endif /* VBOX */
|
---|
112 |
|
---|
113 | #ifdef __i386__
|
---|
114 | #define AREG0 "ebp"
|
---|
115 | #define AREG1 "ebx"
|
---|
116 | #define AREG2 "esi"
|
---|
117 | #define AREG3 "edi"
|
---|
118 | #endif
|
---|
119 | #ifdef __x86_64__
|
---|
120 | #if 0 && defined(VBOX)
|
---|
121 | /* gcc 3.4.3 on 64-bit Solaris screws up when using rbp, it
|
---|
122 | seems so at least. (Setting AREG4 to "r15" causes compiler
|
---|
123 | error btw, so don't try it.) */
|
---|
124 | # define AREG0 "rbx"
|
---|
125 | # define AREG1 "r12"
|
---|
126 | # define AREG2 "r13"
|
---|
127 | # define AREG3 "r14"
|
---|
128 | #else
|
---|
129 | #define AREG0 "rbp"
|
---|
130 | #define AREG1 "rbx"
|
---|
131 | #define AREG2 "r12"
|
---|
132 | #define AREG3 "r13"
|
---|
133 | #endif
|
---|
134 | //#define AREG4 "r14"
|
---|
135 | //#define AREG5 "r15"
|
---|
136 | #endif
|
---|
137 | #ifdef __powerpc__
|
---|
138 | #define AREG0 "r27"
|
---|
139 | #define AREG1 "r24"
|
---|
140 | #define AREG2 "r25"
|
---|
141 | #define AREG3 "r26"
|
---|
142 | /* XXX: suppress this hack */
|
---|
143 | #if defined(CONFIG_USER_ONLY)
|
---|
144 | #define AREG4 "r16"
|
---|
145 | #define AREG5 "r17"
|
---|
146 | #define AREG6 "r18"
|
---|
147 | #define AREG7 "r19"
|
---|
148 | #define AREG8 "r20"
|
---|
149 | #define AREG9 "r21"
|
---|
150 | #define AREG10 "r22"
|
---|
151 | #define AREG11 "r23"
|
---|
152 | #endif
|
---|
153 | #define USE_INT_TO_FLOAT_HELPERS
|
---|
154 | #define BUGGY_GCC_DIV64
|
---|
155 | #endif
|
---|
156 | #ifdef __arm__
|
---|
157 | #define AREG0 "r7"
|
---|
158 | #define AREG1 "r4"
|
---|
159 | #define AREG2 "r5"
|
---|
160 | #define AREG3 "r6"
|
---|
161 | #endif
|
---|
162 | #ifdef __mips__
|
---|
163 | #define AREG0 "s3"
|
---|
164 | #define AREG1 "s0"
|
---|
165 | #define AREG2 "s1"
|
---|
166 | #define AREG3 "s2"
|
---|
167 | #endif
|
---|
168 | #ifdef __sparc__
|
---|
169 | #ifdef HOST_SOLARIS
|
---|
170 | #define AREG0 "g2"
|
---|
171 | #define AREG1 "g3"
|
---|
172 | #define AREG2 "g4"
|
---|
173 | #define AREG3 "g5"
|
---|
174 | #define AREG4 "g6"
|
---|
175 | #else
|
---|
176 | #ifdef __sparc_v9__
|
---|
177 | #define AREG0 "g1"
|
---|
178 | #define AREG1 "g4"
|
---|
179 | #define AREG2 "g5"
|
---|
180 | #define AREG3 "g7"
|
---|
181 | #else
|
---|
182 | #define AREG0 "g6"
|
---|
183 | #define AREG1 "g1"
|
---|
184 | #define AREG2 "g2"
|
---|
185 | #define AREG3 "g3"
|
---|
186 | #define AREG4 "l0"
|
---|
187 | #define AREG5 "l1"
|
---|
188 | #define AREG6 "l2"
|
---|
189 | #define AREG7 "l3"
|
---|
190 | #define AREG8 "l4"
|
---|
191 | #define AREG9 "l5"
|
---|
192 | #define AREG10 "l6"
|
---|
193 | #define AREG11 "l7"
|
---|
194 | #endif
|
---|
195 | #endif
|
---|
196 | #define USE_FP_CONVERT
|
---|
197 | #endif
|
---|
198 | #ifdef __s390__
|
---|
199 | #define AREG0 "r10"
|
---|
200 | #define AREG1 "r7"
|
---|
201 | #define AREG2 "r8"
|
---|
202 | #define AREG3 "r9"
|
---|
203 | #endif
|
---|
204 | #ifdef __alpha__
|
---|
205 | /* Note $15 is the frame pointer, so anything in op-i386.c that would
|
---|
206 | require a frame pointer, like alloca, would probably loose. */
|
---|
207 | #define AREG0 "$15"
|
---|
208 | #define AREG1 "$9"
|
---|
209 | #define AREG2 "$10"
|
---|
210 | #define AREG3 "$11"
|
---|
211 | #define AREG4 "$12"
|
---|
212 | #define AREG5 "$13"
|
---|
213 | #define AREG6 "$14"
|
---|
214 | #endif
|
---|
215 | #ifdef __mc68000
|
---|
216 | #define AREG0 "%a5"
|
---|
217 | #define AREG1 "%a4"
|
---|
218 | #define AREG2 "%d7"
|
---|
219 | #define AREG3 "%d6"
|
---|
220 | #define AREG4 "%d5"
|
---|
221 | #endif
|
---|
222 | #ifdef __ia64__
|
---|
223 | #define AREG0 "r7"
|
---|
224 | #define AREG1 "r4"
|
---|
225 | #define AREG2 "r5"
|
---|
226 | #define AREG3 "r6"
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | #ifndef VBOX
|
---|
230 | /* force GCC to generate only one epilog at the end of the function */
|
---|
231 | #define FORCE_RET() __asm__ __volatile__("" : : : "memory");
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | #ifndef OPPROTO
|
---|
235 | #define OPPROTO
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | #define xglue(x, y) x ## y
|
---|
239 | #define glue(x, y) xglue(x, y)
|
---|
240 | #define stringify(s) tostring(s)
|
---|
241 | #define tostring(s) #s
|
---|
242 |
|
---|
243 | #if defined(__alpha__) || defined(__s390__)
|
---|
244 | /* the symbols are considered non exported so a br immediate is generated */
|
---|
245 | #define __hidden __attribute__((visibility("hidden")))
|
---|
246 | #else
|
---|
247 | #define __hidden
|
---|
248 | #endif
|
---|
249 |
|
---|
250 | #if defined(__alpha__)
|
---|
251 | /* Suggested by Richard Henderson. This will result in code like
|
---|
252 | ldah $0,__op_param1($29) !gprelhigh
|
---|
253 | lda $0,__op_param1($0) !gprellow
|
---|
254 | We can then conveniently change $29 to $31 and adapt the offsets to
|
---|
255 | emit the appropriate constant. */
|
---|
256 | extern int __op_param1 __hidden;
|
---|
257 | extern int __op_param2 __hidden;
|
---|
258 | extern int __op_param3 __hidden;
|
---|
259 | #define PARAM1 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param1)); _r; })
|
---|
260 | #define PARAM2 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param2)); _r; })
|
---|
261 | #define PARAM3 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param3)); _r; })
|
---|
262 | #else
|
---|
263 | #if defined(__APPLE__)
|
---|
264 | static int __op_param1, __op_param2, __op_param3;
|
---|
265 | #else
|
---|
266 | extern int __op_param1, __op_param2, __op_param3;
|
---|
267 | #endif
|
---|
268 | #define PARAM1 ((long)(&__op_param1))
|
---|
269 | #define PARAM2 ((long)(&__op_param2))
|
---|
270 | #define PARAM3 ((long)(&__op_param3))
|
---|
271 | #endif /* !defined(__alpha__) */
|
---|
272 |
|
---|
273 | extern int __op_jmp0, __op_jmp1, __op_jmp2, __op_jmp3;
|
---|
274 |
|
---|
275 | #if defined(_WIN32) || defined(__APPLE__) || defined(__OS2__)
|
---|
276 | #define ASM_NAME(x) "_" #x
|
---|
277 | #else
|
---|
278 | #define ASM_NAME(x) #x
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | #ifdef __i386__
|
---|
282 | #define EXIT_TB() asm volatile ("ret")
|
---|
283 | #define GOTO_LABEL_PARAM(n) asm volatile ("jmp " ASM_NAME(__op_gen_label) #n)
|
---|
284 | #endif
|
---|
285 | #ifdef __x86_64__
|
---|
286 | #define EXIT_TB() asm volatile ("ret")
|
---|
287 | #define GOTO_LABEL_PARAM(n) asm volatile ("jmp " ASM_NAME(__op_gen_label) #n)
|
---|
288 | #endif
|
---|
289 | #ifdef __powerpc__
|
---|
290 | #define EXIT_TB() asm volatile ("blr")
|
---|
291 | #define GOTO_LABEL_PARAM(n) asm volatile ("b " ASM_NAME(__op_gen_label) #n)
|
---|
292 | #endif
|
---|
293 | #ifdef __s390__
|
---|
294 | #define EXIT_TB() asm volatile ("br %r14")
|
---|
295 | #define GOTO_LABEL_PARAM(n) asm volatile ("b " ASM_NAME(__op_gen_label) #n)
|
---|
296 | #endif
|
---|
297 | #ifdef __alpha__
|
---|
298 | #define EXIT_TB() asm volatile ("ret")
|
---|
299 | #endif
|
---|
300 | #ifdef __ia64__
|
---|
301 | #define EXIT_TB() asm volatile ("br.ret.sptk.many b0;;")
|
---|
302 | #define GOTO_LABEL_PARAM(n) asm volatile ("br.sptk.many " \
|
---|
303 | ASM_NAME(__op_gen_label) #n)
|
---|
304 | #endif
|
---|
305 | #ifdef __sparc__
|
---|
306 | #define EXIT_TB() asm volatile ("jmpl %i0 + 8, %g0; nop")
|
---|
307 | #define GOTO_LABEL_PARAM(n) asm volatile ("ba " ASM_NAME(__op_gen_label) #n ";nop")
|
---|
308 | #endif
|
---|
309 | #ifdef __arm__
|
---|
310 | #define EXIT_TB() asm volatile ("b exec_loop")
|
---|
311 | #define GOTO_LABEL_PARAM(n) asm volatile ("b " ASM_NAME(__op_gen_label) #n)
|
---|
312 | #endif
|
---|
313 | #ifdef __mc68000
|
---|
314 | #define EXIT_TB() asm volatile ("rts")
|
---|
315 | #endif
|
---|
316 |
|
---|
317 |
|
---|
318 | #ifdef VBOX
|
---|
319 | #define GETPC() ASMReturnAddress()
|
---|
320 | #elif defined(__s390__)
|
---|
321 | /* The return address may point to the start of the next instruction.
|
---|
322 | Subtracting one gets us the call instruction itself. */
|
---|
323 | # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1))
|
---|
324 | #elif defined(__arm__)
|
---|
325 | /* Thumb return addresses have the low bit set, so we need to subtract two.
|
---|
326 | This is still safe in ARM mode because instructions are 4 bytes. */
|
---|
327 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2))
|
---|
328 | #else
|
---|
329 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1))
|
---|
330 | #endif
|
---|
331 | #endif /* !defined(__DYNGEN_EXEC_H__) */
|
---|