]> git.proxmox.com Git - qemu.git/blob - exec-i386.h
update
[qemu.git] / exec-i386.h
1 /*
2 * i386 execution defines
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 #include "dyngen-exec.h"
21
22 /* at least 4 register variables are defines */
23 register struct CPUX86State *env asm(AREG0);
24 register uint32_t T0 asm(AREG1);
25 register uint32_t T1 asm(AREG2);
26 register uint32_t T2 asm(AREG3);
27
28 #define A0 T2
29
30 /* if more registers are available, we define some registers too */
31 #ifdef AREG4
32 register uint32_t EAX asm(AREG4);
33 #define reg_EAX
34 #endif
35
36 #ifdef AREG5
37 register uint32_t ESP asm(AREG5);
38 #define reg_ESP
39 #endif
40
41 #ifdef AREG6
42 register uint32_t EBP asm(AREG6);
43 #define reg_EBP
44 #endif
45
46 #ifdef AREG7
47 register uint32_t ECX asm(AREG7);
48 #define reg_ECX
49 #endif
50
51 #ifdef AREG8
52 register uint32_t EDX asm(AREG8);
53 #define reg_EDX
54 #endif
55
56 #ifdef AREG9
57 register uint32_t EBX asm(AREG9);
58 #define reg_EBX
59 #endif
60
61 #ifdef AREG10
62 register uint32_t ESI asm(AREG10);
63 #define reg_ESI
64 #endif
65
66 #ifdef AREG11
67 register uint32_t EDI asm(AREG11);
68 #define reg_EDI
69 #endif
70
71 extern FILE *logfile;
72 extern int loglevel;
73
74 #ifndef reg_EAX
75 #define EAX (env->regs[R_EAX])
76 #endif
77 #ifndef reg_ECX
78 #define ECX (env->regs[R_ECX])
79 #endif
80 #ifndef reg_EDX
81 #define EDX (env->regs[R_EDX])
82 #endif
83 #ifndef reg_EBX
84 #define EBX (env->regs[R_EBX])
85 #endif
86 #ifndef reg_ESP
87 #define ESP (env->regs[R_ESP])
88 #endif
89 #ifndef reg_EBP
90 #define EBP (env->regs[R_EBP])
91 #endif
92 #ifndef reg_ESI
93 #define ESI (env->regs[R_ESI])
94 #endif
95 #ifndef reg_EDI
96 #define EDI (env->regs[R_EDI])
97 #endif
98 #define EIP (env->eip)
99 #define DF (env->df)
100
101 #define CC_SRC (env->cc_src)
102 #define CC_DST (env->cc_dst)
103 #define CC_OP (env->cc_op)
104
105 /* float macros */
106 #define FT0 (env->ft0)
107 #define ST0 (env->fpregs[env->fpstt])
108 #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7])
109 #define ST1 ST(1)
110
111 #ifdef USE_FP_CONVERT
112 #define FP_CONVERT (env->fp_convert)
113 #endif
114
115 #include "cpu-i386.h"
116 #include "exec.h"
117
118 typedef struct CCTable {
119 int (*compute_all)(void); /* return all the flags */
120 int (*compute_c)(void); /* return the C flag */
121 } CCTable;
122
123 extern CCTable cc_table[];
124
125 void load_seg(int seg_reg, int selector, unsigned cur_eip);
126 void __hidden cpu_lock(void);
127 void __hidden cpu_unlock(void);
128 void raise_interrupt(int intno, int is_int, int error_code,
129 unsigned int next_eip);
130 void raise_exception_err(int exception_index, int error_code);
131 void raise_exception(int exception_index);
132 void __hidden cpu_loop_exit(void);
133 void helper_fsave(uint8_t *ptr, int data32);
134 void helper_frstor(uint8_t *ptr, int data32);
135
136 void OPPROTO op_movl_eflags_T0(void);
137 void OPPROTO op_movl_T0_eflags(void);
138 void raise_interrupt(int intno, int is_int, int error_code,
139 unsigned int next_eip);
140 void raise_exception_err(int exception_index, int error_code);
141 void raise_exception(int exception_index);
142 void helper_divl_EAX_T0(uint32_t eip);
143 void helper_idivl_EAX_T0(uint32_t eip);
144 void helper_cmpxchg8b(void);
145 void helper_cpuid(void);
146 void helper_rdtsc(void);
147 void helper_lsl(void);
148 void helper_lar(void);
149
150 #ifdef USE_X86LDOUBLE
151 /* use long double functions */
152 #define lrint lrintl
153 #define llrint llrintl
154 #define fabs fabsl
155 #define sin sinl
156 #define cos cosl
157 #define sqrt sqrtl
158 #define pow powl
159 #define log logl
160 #define tan tanl
161 #define atan2 atan2l
162 #define floor floorl
163 #define ceil ceill
164 #define rint rintl
165 #endif
166
167 extern int lrint(CPU86_LDouble x);
168 extern int64_t llrint(CPU86_LDouble x);
169 extern CPU86_LDouble fabs(CPU86_LDouble x);
170 extern CPU86_LDouble sin(CPU86_LDouble x);
171 extern CPU86_LDouble cos(CPU86_LDouble x);
172 extern CPU86_LDouble sqrt(CPU86_LDouble x);
173 extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
174 extern CPU86_LDouble log(CPU86_LDouble x);
175 extern CPU86_LDouble tan(CPU86_LDouble x);
176 extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
177 extern CPU86_LDouble floor(CPU86_LDouble x);
178 extern CPU86_LDouble ceil(CPU86_LDouble x);
179 extern CPU86_LDouble rint(CPU86_LDouble x);
180
181 #define RC_MASK 0xc00
182 #define RC_NEAR 0x000
183 #define RC_DOWN 0x400
184 #define RC_UP 0x800
185 #define RC_CHOP 0xc00
186
187 #define MAXTAN 9223372036854775808.0
188
189 #ifdef __arm__
190 /* we have no way to do correct rounding - a FPU emulator is needed */
191 #define FE_DOWNWARD FE_TONEAREST
192 #define FE_UPWARD FE_TONEAREST
193 #define FE_TOWARDZERO FE_TONEAREST
194 #endif
195
196 #ifdef USE_X86LDOUBLE
197
198 /* only for x86 */
199 typedef union {
200 long double d;
201 struct {
202 unsigned long long lower;
203 unsigned short upper;
204 } l;
205 } CPU86_LDoubleU;
206
207 /* the following deal with x86 long double-precision numbers */
208 #define MAXEXPD 0x7fff
209 #define EXPBIAS 16383
210 #define EXPD(fp) (fp.l.upper & 0x7fff)
211 #define SIGND(fp) ((fp.l.upper) & 0x8000)
212 #define MANTD(fp) (fp.l.lower)
213 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
214
215 #else
216
217 /* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
218 typedef union {
219 double d;
220 #if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
221 struct {
222 uint32_t lower;
223 int32_t upper;
224 } l;
225 #else
226 struct {
227 int32_t upper;
228 uint32_t lower;
229 } l;
230 #endif
231 #ifndef __arm__
232 int64_t ll;
233 #endif
234 } CPU86_LDoubleU;
235
236 /* the following deal with IEEE double-precision numbers */
237 #define MAXEXPD 0x7ff
238 #define EXPBIAS 1023
239 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
240 #define SIGND(fp) ((fp.l.upper) & 0x80000000)
241 #ifdef __arm__
242 #define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
243 #else
244 #define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
245 #endif
246 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
247 #endif
248
249 static inline void fpush(void)
250 {
251 env->fpstt = (env->fpstt - 1) & 7;
252 env->fptags[env->fpstt] = 0; /* validate stack entry */
253 }
254
255 static inline void fpop(void)
256 {
257 env->fptags[env->fpstt] = 1; /* invvalidate stack entry */
258 env->fpstt = (env->fpstt + 1) & 7;
259 }
260
261 #ifndef USE_X86LDOUBLE
262 static inline CPU86_LDouble helper_fldt(uint8_t *ptr)
263 {
264 CPU86_LDoubleU temp;
265 int upper, e;
266 uint64_t ll;
267
268 /* mantissa */
269 upper = lduw(ptr + 8);
270 /* XXX: handle overflow ? */
271 e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */
272 e |= (upper >> 4) & 0x800; /* sign */
273 ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1);
274 #ifdef __arm__
275 temp.l.upper = (e << 20) | (ll >> 32);
276 temp.l.lower = ll;
277 #else
278 temp.ll = ll | ((uint64_t)e << 52);
279 #endif
280 return temp.d;
281 }
282
283 static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
284 {
285 CPU86_LDoubleU temp;
286 int e;
287
288 temp.d = f;
289 /* mantissa */
290 stq(ptr, (MANTD(temp) << 11) | (1LL << 63));
291 /* exponent + sign */
292 e = EXPD(temp) - EXPBIAS + 16383;
293 e |= SIGND(temp) >> 16;
294 stw(ptr + 8, e);
295 }
296 #endif
297
298 const CPU86_LDouble f15rk[7];
299
300 void helper_fldt_ST0_A0(void);
301 void helper_fstt_ST0_A0(void);
302 void helper_fbld_ST0_A0(void);
303 void helper_fbst_ST0_A0(void);
304 void helper_f2xm1(void);
305 void helper_fyl2x(void);
306 void helper_fptan(void);
307 void helper_fpatan(void);
308 void helper_fxtract(void);
309 void helper_fprem1(void);
310 void helper_fprem(void);
311 void helper_fyl2xp1(void);
312 void helper_fsqrt(void);
313 void helper_fsincos(void);
314 void helper_frndint(void);
315 void helper_fscale(void);
316 void helper_fsin(void);
317 void helper_fcos(void);
318 void helper_fxam_ST0(void);
319 void helper_fstenv(uint8_t *ptr, int data32);
320 void helper_fldenv(uint8_t *ptr, int data32);
321 void helper_fsave(uint8_t *ptr, int data32);
322 void helper_frstor(uint8_t *ptr, int data32);
323
324 const uint8_t parity_table[256];
325 const uint8_t rclw_table[32];
326 const uint8_t rclb_table[32];