VirtualBox

source: vbox/trunk/src/recompiler/dyngen-exec.h@ 36140

Last change on this file since 36140 was 36140, checked in by vboxsync, 14 years ago

rem: Re-synced to svn://svn.savannah.nongnu.org/qemu/trunk@5495 (repo UUID c046a42c-6fe2-441c-8c8c-71466251a162).

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

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