VirtualBox

source: vbox/trunk/src/recompiler_new/dyngen-exec.h@ 13649

Last change on this file since 13649 was 13649, checked in by vboxsync, 16 years ago

draft 32-bit recompiler

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette