2 * dyngen defines for micro operation code
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
20 #if !defined(__DYNGEN_EXEC_H__)
21 #define __DYNGEN_EXEC_H__
23 /* prevent Solaris from trying to typedef FILE in gcc's
24 include/floatingpoint.h which will conflict with the
25 definition down below */
30 /* NOTE: standard headers should be used with special care at this
31 point because host CPU registers are used as global variables. Some
32 host headers do not allow that. */
35 typedef unsigned char uint8_t;
36 typedef unsigned short uint16_t;
37 typedef unsigned int uint32_t;
38 // Linux/Sparc64 defines uint64_t
39 #if !(defined (__sparc_v9__) && defined(__linux__)) && !(defined(__APPLE__) && defined(__x86_64__))
40 /* XXX may be done for all 64 bits targets ? */
41 #if defined (__x86_64__) || defined(__ia64) || defined(__s390x__) || defined(__alpha__) || defined(__powerpc64__)
42 typedef unsigned long uint64_t;
44 typedef unsigned long long uint64_t;
48 /* if Solaris/__sun__, don't typedef int8_t, as it will be typedef'd
49 prior to this and will cause an error in compliation, conflicting
50 with /usr/include/sys/int_types.h, line 75 */
52 typedef signed char int8_t;
54 typedef signed short int16_t;
55 typedef signed int int32_t;
56 // Linux/Sparc64 defines int64_t
57 #if !(defined (__sparc_v9__) && defined(__linux__)) && !(defined(__APPLE__) && defined(__x86_64__))
58 #if defined (__x86_64__) || defined(__ia64) || defined(__s390x__) || defined(__alpha__) || defined(__powerpc64__)
59 typedef signed long int64_t;
61 typedef signed long long int64_t;
65 /* XXX: This may be wrong for 64-bit ILP32 hosts. */
66 typedef void * host_reg_t
;
68 #define INT8_MIN (-128)
69 #define INT16_MIN (-32767-1)
70 #define INT32_MIN (-2147483647-1)
71 #define INT64_MIN (-(int64_t)(9223372036854775807)-1)
72 #define INT8_MAX (127)
73 #define INT16_MAX (32767)
74 #define INT32_MAX (2147483647)
75 #define INT64_MAX ((int64_t)(9223372036854775807))
76 #define UINT8_MAX (255)
77 #define UINT16_MAX (65535)
78 #define UINT32_MAX (4294967295U)
79 #define UINT64_MAX ((uint64_t)(18446744073709551615))
82 typedef struct __sFILE
FILE;
84 typedef struct FILE FILE;
86 extern int fprintf(FILE *, const char *, ...);
87 extern int fputs(const char *, FILE *);
88 extern int printf(const char *, ...);
97 #elif defined(__x86_64__)
102 //#define AREG4 "rbp"
103 //#define AREG5 "rbx"
104 #elif defined(__powerpc__)
109 /* XXX: suppress this hack */
110 #if defined(CONFIG_USER_ONLY)
120 #elif defined(__arm__)
125 #elif defined(__hppa__)
130 #elif defined(__mips__)
140 #elif defined(__sparc__)
167 #elif defined(__s390__)
172 #elif defined(__alpha__)
173 /* Note $15 is the frame pointer, so anything in op-i386.c that would
174 require a frame pointer, like alloca, would probably loose. */
182 #elif defined(__mc68000)
188 #elif defined(__ia64__)
194 #error unsupported CPU
197 /* force GCC to generate only one epilog at the end of the function */
198 #define FORCE_RET() __asm__ __volatile__("" : : : "memory");
204 #define xglue(x, y) x ## y
205 #define glue(x, y) xglue(x, y)
206 #define stringify(s) tostring(s)
207 #define tostring(s) #s
209 #if defined(__alpha__) || defined(__s390__)
210 /* the symbols are considered non exported so a br immediate is generated */
211 #define __hidden __attribute__((visibility("hidden")))
216 #if defined(__alpha__)
217 /* Suggested by Richard Henderson. This will result in code like
218 ldah $0,__op_param1($29) !gprelhigh
219 lda $0,__op_param1($0) !gprellow
220 We can then conveniently change $29 to $31 and adapt the offsets to
221 emit the appropriate constant. */
222 extern int __op_param1 __hidden
;
223 extern int __op_param2 __hidden
;
224 extern int __op_param3 __hidden
;
225 #define PARAM1 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param1)); _r; })
226 #define PARAM2 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param2)); _r; })
227 #define PARAM3 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param3)); _r; })
228 #elif defined(__s390__)
229 extern int __op_param1 __hidden
;
230 extern int __op_param2 __hidden
;
231 extern int __op_param3 __hidden
;
232 #define PARAM1 ({ int _r; asm("bras %0,8; .long " ASM_NAME(__op_param1) "; l %0,0(%0)" : "=r"(_r) : ); _r; })
233 #define PARAM2 ({ int _r; asm("bras %0,8; .long " ASM_NAME(__op_param2) "; l %0,0(%0)" : "=r"(_r) : ); _r; })
234 #define PARAM3 ({ int _r; asm("bras %0,8; .long " ASM_NAME(__op_param3) "; l %0,0(%0)" : "=r"(_r) : ); _r; })
236 #if defined(__APPLE__)
237 static int __op_param1
, __op_param2
, __op_param3
;
239 extern int __op_param1
, __op_param2
, __op_param3
;
241 #define PARAM1 ((long)(&__op_param1))
242 #define PARAM2 ((long)(&__op_param2))
243 #define PARAM3 ((long)(&__op_param3))
244 #endif /* !defined(__alpha__) */
246 extern int __op_jmp0
, __op_jmp1
, __op_jmp2
, __op_jmp3
;
248 #if defined(_WIN32) || defined(__APPLE__)
249 #define ASM_NAME(x) "_" #x
251 #define ASM_NAME(x) #x
254 #if defined(__i386__)
255 #define EXIT_TB() asm volatile ("ret")
256 #define GOTO_LABEL_PARAM(n) asm volatile ("jmp " ASM_NAME(__op_gen_label) #n)
257 #elif defined(__x86_64__)
258 #define EXIT_TB() asm volatile ("ret")
259 #define GOTO_LABEL_PARAM(n) asm volatile ("jmp " ASM_NAME(__op_gen_label) #n)
260 #elif defined(__powerpc__)
261 #define EXIT_TB() asm volatile ("blr")
262 #define GOTO_LABEL_PARAM(n) asm volatile ("b " ASM_NAME(__op_gen_label) #n)
263 #elif defined(__s390__)
264 #define EXIT_TB() asm volatile ("br %r14")
265 #define GOTO_LABEL_PARAM(n) asm volatile ("larl %r7,12; l %r7,0(%r7); br %r7; .long " ASM_NAME(__op_gen_label) #n)
266 #elif defined(__alpha__)
267 #define EXIT_TB() asm volatile ("ret")
268 #elif defined(__ia64__)
269 #define EXIT_TB() asm volatile ("br.ret.sptk.many b0;;")
270 #define GOTO_LABEL_PARAM(n) asm volatile ("br.sptk.many " \
271 ASM_NAME(__op_gen_label) #n)
272 #elif defined(__sparc__)
273 #define EXIT_TB() asm volatile ("jmpl %i0 + 8, %g0; nop")
274 #define GOTO_LABEL_PARAM(n) asm volatile ("ba " ASM_NAME(__op_gen_label) #n ";nop")
275 #elif defined(__arm__)
276 #define EXIT_TB() asm volatile ("b exec_loop")
277 #define GOTO_LABEL_PARAM(n) asm volatile ("b " ASM_NAME(__op_gen_label) #n)
278 #elif defined(__mc68000)
279 #define EXIT_TB() asm volatile ("rts")
280 #elif defined(__mips__)
281 #define EXIT_TB() asm volatile ("jr $ra")
282 #define GOTO_LABEL_PARAM(n) asm volatile (".set noat; la $1, " ASM_NAME(__op_gen_label) #n "; jr $1; .set at")
283 #elif defined(__hppa__)
284 #define GOTO_LABEL_PARAM(n) asm volatile ("b,n " ASM_NAME(__op_gen_label) #n)
286 #error unsupported CPU
289 /* The return address may point to the start of the next instruction.
290 Subtracting one gets us the call instruction itself. */
291 #if defined(__s390__)
292 # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1))
293 #elif defined(__arm__)
294 /* Thumb return addresses have the low bit set, so we need to subtract two.
295 This is still safe in ARM mode because instructions are 4 bytes. */
296 # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2))
298 # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1))
301 #endif /* !defined(__DYNGEN_EXEC_H__) */