initial x86-64 host support (Gwenole Beauchesne)
[qemu] / dyngen-exec.h
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 #if !defined(__DYNGEN_EXEC_H__)
21 #define __DYNGEN_EXEC_H__
22
23 #include <stddef.h>
24
25 typedef unsigned char uint8_t;
26 typedef unsigned short uint16_t;
27 typedef unsigned int uint32_t;
28 typedef unsigned long long uint64_t;
29
30 typedef signed char int8_t;
31 typedef signed short int16_t;
32 typedef signed int int32_t;
33 typedef signed long long int64_t;
34
35 #define INT8_MIN                (-128)
36 #define INT16_MIN               (-32767-1)
37 #define INT32_MIN               (-2147483647-1)
38 #define INT64_MIN               (-(int64_t)(9223372036854775807)-1)
39 #define INT8_MAX                (127)
40 #define INT16_MAX               (32767)
41 #define INT32_MAX               (2147483647)
42 #define INT64_MAX               ((int64_t)(9223372036854775807))
43 #define UINT8_MAX               (255)
44 #define UINT16_MAX              (65535)
45 #define UINT32_MAX              (4294967295U)
46 #define UINT64_MAX              ((uint64_t)(18446744073709551615))
47
48 #define bswap32(x) \
49 ({ \
50         uint32_t __x = (x); \
51         ((uint32_t)( \
52                 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
53                 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) <<  8) | \
54                 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >>  8) | \
55                 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
56 })
57
58 typedef struct FILE FILE;
59 extern int fprintf(FILE *, const char *, ...);
60 extern int printf(const char *, ...);
61 #undef NULL
62 #define NULL 0
63 #include <fenv.h>
64
65 #ifdef __i386__
66 #define AREG0 "ebp"
67 #define AREG1 "ebx"
68 #define AREG2 "esi"
69 #define AREG3 "edi"
70 #endif
71 #ifdef __x86_64__
72 #define AREG0 "rbp"
73 #define AREG1 "rbx"
74 #define AREG2 "r12"
75 #define AREG3 "r13"
76 #define AREG4 "r14"
77 #define AREG5 "r15"
78 #endif
79 #ifdef __powerpc__
80 #define AREG0 "r27"
81 #define AREG1 "r24"
82 #define AREG2 "r25"
83 #define AREG3 "r26"
84 /* XXX: suppress this hack */
85 #if defined(CONFIG_USER_ONLY)
86 #define AREG4 "r16"
87 #define AREG5 "r17"
88 #define AREG6 "r18"
89 #define AREG7 "r19"
90 #define AREG8 "r20"
91 #define AREG9 "r21"
92 #define AREG10 "r22"
93 #define AREG11 "r23"
94 #endif
95 #define USE_INT_TO_FLOAT_HELPERS
96 #define BUGGY_GCC_DIV64
97 #endif
98 #ifdef __arm__
99 #define AREG0 "r7"
100 #define AREG1 "r4"
101 #define AREG2 "r5"
102 #define AREG3 "r6"
103 #endif
104 #ifdef __mips__
105 #define AREG0 "s3"
106 #define AREG1 "s0"
107 #define AREG2 "s1"
108 #define AREG3 "s2"
109 #endif
110 #ifdef __sparc__
111 #define AREG0 "g6"
112 #define AREG1 "g1"
113 #define AREG2 "g2"
114 #define AREG3 "g3"
115 #define AREG4 "l0"
116 #define AREG5 "l1"
117 #define AREG6 "l2"
118 #define AREG7 "l3"
119 #define AREG8 "l4"
120 #define AREG9 "l5"
121 #define AREG10 "l6"
122 #define AREG11 "l7"
123 #define USE_FP_CONVERT
124 #endif
125 #ifdef __s390__
126 #define AREG0 "r10"
127 #define AREG1 "r7"
128 #define AREG2 "r8"
129 #define AREG3 "r9"
130 #endif
131 #ifdef __alpha__
132 /* Note $15 is the frame pointer, so anything in op-i386.c that would
133    require a frame pointer, like alloca, would probably loose.  */
134 #define AREG0 "$15"
135 #define AREG1 "$9"
136 #define AREG2 "$10"
137 #define AREG3 "$11"
138 #define AREG4 "$12"
139 #define AREG5 "$13"
140 #define AREG6 "$14"
141 #endif
142 #ifdef __mc68000
143 #define AREG0 "%a5"
144 #define AREG1 "%a4"
145 #define AREG2 "%d7"
146 #define AREG3 "%d6"
147 #define AREG4 "%d5"
148 #endif
149 #ifdef __ia64__
150 #define AREG0 "r27"
151 #define AREG1 "r24"
152 #define AREG2 "r25"
153 #define AREG3 "r26"
154 #endif
155
156 /* force GCC to generate only one epilog at the end of the function */
157 #define FORCE_RET() asm volatile ("");
158
159 #ifndef OPPROTO
160 #define OPPROTO
161 #endif
162
163 #define xglue(x, y) x ## y
164 #define glue(x, y) xglue(x, y)
165 #define stringify(s)    tostring(s)
166 #define tostring(s)     #s
167
168 #ifdef __alpha__
169 /* the symbols are considered non exported so a br immediate is generated */
170 #define __hidden __attribute__((visibility("hidden")))
171 #else
172 #define __hidden 
173 #endif
174
175 #ifdef __alpha__
176 /* Suggested by Richard Henderson. This will result in code like
177         ldah $0,__op_param1($29)        !gprelhigh
178         lda $0,__op_param1($0)          !gprellow
179    We can then conveniently change $29 to $31 and adapt the offsets to
180    emit the appropriate constant.  */
181 extern int __op_param1 __hidden;
182 extern int __op_param2 __hidden;
183 extern int __op_param3 __hidden;
184 #define PARAM1 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param1)); _r; })
185 #define PARAM2 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param2)); _r; })
186 #define PARAM3 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param3)); _r; })
187 #else
188 extern int __op_param1, __op_param2, __op_param3;
189 #define PARAM1 ((long)(&__op_param1))
190 #define PARAM2 ((long)(&__op_param2))
191 #define PARAM3 ((long)(&__op_param3))
192 #endif
193
194 extern int __op_jmp0, __op_jmp1, __op_jmp2, __op_jmp3;
195
196 #ifdef __i386__
197 #define EXIT_TB() asm volatile ("ret")
198 #endif
199 #ifdef __x86_64__
200 #define EXIT_TB() asm volatile ("ret")
201 #endif
202 #ifdef __powerpc__
203 #define EXIT_TB() asm volatile ("blr")
204 #endif
205 #ifdef __s390__
206 #define EXIT_TB() asm volatile ("br %r14")
207 #endif
208 #ifdef __alpha__
209 #define EXIT_TB() asm volatile ("ret")
210 #endif
211 #ifdef __ia64__
212 #define EXIT_TB() asm volatile ("br.ret.sptk.many b0;;")
213 #endif
214 #ifdef __sparc__
215 #define EXIT_TB() asm volatile ("jmpl %i0 + 8, %g0\n" \
216                                 "nop")
217 #endif
218 #ifdef __arm__
219 #define EXIT_TB() asm volatile ("b exec_loop")
220 #endif
221 #ifdef __mc68000
222 #define EXIT_TB() asm volatile ("rts")
223 #endif
224
225 #endif /* !defined(__DYNGEN_EXEC_H__) */