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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 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
|
---|
52 | typedef unsigned char uint8_t;
|
---|
53 | typedef unsigned short uint16_t;
|
---|
54 | typedef 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(_ARCH_PPC64)
|
---|
59 | typedef unsigned long uint64_t;
|
---|
60 | #else
|
---|
61 | typedef 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__
|
---|
69 | typedef signed char int8_t;
|
---|
70 | #endif
|
---|
71 | typedef signed short int16_t;
|
---|
72 | typedef 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(_ARCH_PPC64)
|
---|
76 | typedef signed long int64_t;
|
---|
77 | #else
|
---|
78 | typedef signed long long int64_t;
|
---|
79 | #endif
|
---|
80 | #endif
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | /* XXX: This may be wrong for 64-bit ILP32 hosts. */
|
---|
84 | typedef 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
|
---|
100 | typedef struct __sFILE FILE;
|
---|
101 | #else
|
---|
102 | typedef struct FILE FILE;
|
---|
103 | #endif
|
---|
104 | extern int fprintf(FILE *, const char *, ...);
|
---|
105 | extern int fputs(const char *, FILE *);
|
---|
106 | extern 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. */
|
---|
113 | typedef 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(_ARCH_PPC)
|
---|
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 | #define xglue(x, y) x ## y
|
---|
231 | #define glue(x, y) xglue(x, y)
|
---|
232 | #define stringify(s) tostring(s)
|
---|
233 | #define tostring(s) #s
|
---|
234 |
|
---|
235 | /* The return address may point to the start of the next instruction.
|
---|
236 | Subtracting one gets us the call instruction itself. */
|
---|
237 | #if defined(__s390__)
|
---|
238 | # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1))
|
---|
239 | #elif defined(__arm__)
|
---|
240 | /* Thumb return addresses have the low bit set, so we need to subtract two.
|
---|
241 | This is still safe in ARM mode because instructions are 4 bytes. */
|
---|
242 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2))
|
---|
243 | #else
|
---|
244 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1))
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | #endif /* !defined(__DYNGEN_EXEC_H__) */
|
---|