VirtualBox

source: vbox/trunk/src/recompiler_new/target-i386/exec.h@ 13382

最後變更 在這個檔案從13382是 13382,由 vboxsync 提交於 16 年 前

more MSVC-related stuff

  • 屬性 svn:eol-style 設為 native
檔案大小: 13.7 KB
 
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
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#include "config.h"
30#include "dyngen-exec.h"
31
32/* XXX: factorize this mess */
33#ifdef TARGET_X86_64
34#define TARGET_LONG_BITS 64
35#else
36#define TARGET_LONG_BITS 32
37#endif
38
39#include "cpu-defs.h"
40
41#ifndef VBOX
42/* at least 4 register variables are defined */
43register struct CPUX86State *env asm(AREG0);
44#else
45REGISTER_BOUND_GLOBAL(struct CPUX86State*, env, AREG0);
46#endif /* VBOX */
47
48#include "qemu-log.h"
49
50#ifndef reg_EAX
51#define EAX (env->regs[R_EAX])
52#endif
53#ifndef reg_ECX
54#define ECX (env->regs[R_ECX])
55#endif
56#ifndef reg_EDX
57#define EDX (env->regs[R_EDX])
58#endif
59#ifndef reg_EBX
60#define EBX (env->regs[R_EBX])
61#endif
62#ifndef reg_ESP
63#define ESP (env->regs[R_ESP])
64#endif
65#ifndef reg_EBP
66#define EBP (env->regs[R_EBP])
67#endif
68#ifndef reg_ESI
69#define ESI (env->regs[R_ESI])
70#endif
71#ifndef reg_EDI
72#define EDI (env->regs[R_EDI])
73#endif
74#define EIP (env->eip)
75#define DF (env->df)
76
77#define CC_SRC (env->cc_src)
78#define CC_DST (env->cc_dst)
79#define CC_OP (env->cc_op)
80
81/* float macros */
82#define FT0 (env->ft0)
83#define ST0 (env->fpregs[env->fpstt].d)
84#define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d)
85#define ST1 ST(1)
86
87#include "cpu.h"
88#include "exec-all.h"
89
90void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);
91void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
92int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
93 int is_write, int mmu_idx, int is_softmmu);
94void __hidden cpu_lock(void);
95void __hidden cpu_unlock(void);
96void do_interrupt(int intno, int is_int, int error_code,
97 target_ulong next_eip, int is_hw);
98void do_interrupt_user(int intno, int is_int, int error_code,
99 target_ulong next_eip);
100void raise_interrupt(int intno, int is_int, int error_code,
101 int next_eip_addend);
102void raise_exception_err(int exception_index, int error_code);
103void raise_exception(int exception_index);
104void do_smm_enter(void);
105void __hidden cpu_loop_exit(void);
106
107void OPPROTO op_movl_eflags_T0(void);
108void OPPROTO op_movl_T0_eflags(void);
109#ifdef VBOX
110void OPPROTO op_movl_T0_eflags_vme(void);
111void OPPROTO op_movw_eflags_T0_vme(void);
112void OPPROTO op_cli_vme(void);
113void OPPROTO op_sti_vme(void);
114#endif
115
116/* n must be a constant to be efficient */
117#ifndef VBOX
118static inline target_long lshift(target_long x, int n)
119#else
120DECLINLINE(target_long) lshift(target_long x, int n)
121#endif
122{
123 if (n >= 0)
124 return x << n;
125 else
126 return x >> (-n);
127}
128
129#include "helper.h"
130
131#ifndef VBOX
132static inline void svm_check_intercept(uint32_t type)
133#else
134DECLINLINE(void) svm_check_intercept(uint32_t type)
135#endif
136{
137 helper_svm_check_intercept_param(type, 0);
138}
139
140void check_iob_T0(void);
141void check_iow_T0(void);
142void check_iol_T0(void);
143void check_iob_DX(void);
144void check_iow_DX(void);
145void check_iol_DX(void);
146
147#if !defined(CONFIG_USER_ONLY)
148
149#include "softmmu_exec.h"
150
151#ifndef VBOX
152static inline double ldfq(target_ulong ptr)
153#else
154DECLINLINE(double) ldfq(target_ulong ptr)
155#endif
156{
157 union {
158 double d;
159 uint64_t i;
160 } u;
161 u.i = ldq(ptr);
162 return u.d;
163}
164
165#ifndef VBOX
166static inline void stfq(target_ulong ptr, double v)
167#else
168DECLINLINE(void) stfq(target_ulong ptr, double v)
169#endif
170{
171 union {
172 double d;
173 uint64_t i;
174 } u;
175 u.d = v;
176 stq(ptr, u.i);
177}
178
179#ifndef VBOX
180static inline float ldfl(target_ulong ptr)
181#else
182DECLINLINE(float) ldfl(target_ulong ptr)
183#endif
184{
185 union {
186 float f;
187 uint32_t i;
188 } u;
189 u.i = ldl(ptr);
190 return u.f;
191}
192
193#ifndef VBOX
194static inline void stfl(target_ulong ptr, float v)
195#else
196DECLINLINE(void) stfl(target_ulong ptr, float v)
197#endif
198{
199 union {
200 float f;
201 uint32_t i;
202 } u;
203 u.f = v;
204 stl(ptr, u.i);
205}
206
207#endif /* !defined(CONFIG_USER_ONLY) */
208
209#ifdef USE_X86LDOUBLE
210/* use long double functions */
211#define floatx_to_int32 floatx80_to_int32
212#define floatx_to_int64 floatx80_to_int64
213#define floatx_to_int32_round_to_zero floatx80_to_int32_round_to_zero
214#define floatx_to_int64_round_to_zero floatx80_to_int64_round_to_zero
215#define int32_to_floatx int32_to_floatx80
216#define int64_to_floatx int64_to_floatx80
217#define float32_to_floatx float32_to_floatx80
218#define float64_to_floatx float64_to_floatx80
219#define floatx_to_float32 floatx80_to_float32
220#define floatx_to_float64 floatx80_to_float64
221#define floatx_abs floatx80_abs
222#define floatx_chs floatx80_chs
223#define floatx_round_to_int floatx80_round_to_int
224#define floatx_compare floatx80_compare
225#define floatx_compare_quiet floatx80_compare_quiet
226#ifdef VBOX
227#undef sin
228#undef cos
229#undef sqrt
230#undef pow
231#undef log
232#undef tan
233#undef atan2
234#undef floor
235#undef ceil
236#undef ldexp
237#endif /* !VBOX */
238#define sin sinl
239#define cos cosl
240#define sqrt sqrtl
241#define pow powl
242#define log logl
243#define tan tanl
244#define atan2 atan2l
245#define floor floorl
246#define ceil ceill
247#define ldexp ldexpl
248#else
249#define floatx_to_int32 float64_to_int32
250#define floatx_to_int64 float64_to_int64
251#define floatx_to_int32_round_to_zero float64_to_int32_round_to_zero
252#define floatx_to_int64_round_to_zero float64_to_int64_round_to_zero
253#define int32_to_floatx int32_to_float64
254#define int64_to_floatx int64_to_float64
255#define float32_to_floatx float32_to_float64
256#define float64_to_floatx(x, e) (x)
257#define floatx_to_float32 float64_to_float32
258#define floatx_to_float64(x, e) (x)
259#define floatx_abs float64_abs
260#define floatx_chs float64_chs
261#define floatx_round_to_int float64_round_to_int
262#define floatx_compare float64_compare
263#define floatx_compare_quiet float64_compare_quiet
264#endif
265
266#ifdef VBOX
267#ifndef _MSC_VER
268extern CPU86_LDouble sin(CPU86_LDouble x);
269extern CPU86_LDouble cos(CPU86_LDouble x);
270extern CPU86_LDouble sqrt(CPU86_LDouble x);
271extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
272extern CPU86_LDouble log(CPU86_LDouble x);
273extern CPU86_LDouble tan(CPU86_LDouble x);
274extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
275extern CPU86_LDouble floor(CPU86_LDouble x);
276extern CPU86_LDouble ceil(CPU86_LDouble x);
277#endif /* !_MSC_VER */
278#endif /* VBOX */
279
280#define RC_MASK 0xc00
281#ifndef RC_NEAR
282#define RC_NEAR 0x000
283#endif
284#ifndef RC_DOWN
285#define RC_DOWN 0x400
286#endif
287#ifndef RC_UP
288#define RC_UP 0x800
289#endif
290#ifndef RC_CHOP
291#define RC_CHOP 0xc00
292#endif
293
294#define MAXTAN 9223372036854775808.0
295
296#ifdef USE_X86LDOUBLE
297
298/* only for x86 */
299typedef union {
300 long double d;
301 struct {
302 unsigned long long lower;
303 unsigned short upper;
304 } l;
305} CPU86_LDoubleU;
306
307/* the following deal with x86 long double-precision numbers */
308#define MAXEXPD 0x7fff
309#define EXPBIAS 16383
310#define EXPD(fp) (fp.l.upper & 0x7fff)
311#define SIGND(fp) ((fp.l.upper) & 0x8000)
312#define MANTD(fp) (fp.l.lower)
313#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
314
315#else
316
317/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
318typedef union {
319 double d;
320#if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
321 struct {
322 uint32_t lower;
323 int32_t upper;
324 } l;
325#else
326 struct {
327 int32_t upper;
328 uint32_t lower;
329 } l;
330#endif
331#ifndef __arm__
332 int64_t ll;
333#endif
334} CPU86_LDoubleU;
335
336/* the following deal with IEEE double-precision numbers */
337#define MAXEXPD 0x7ff
338#define EXPBIAS 1023
339#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
340#define SIGND(fp) ((fp.l.upper) & 0x80000000)
341#ifdef __arm__
342#define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
343#else
344#define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
345#endif
346#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
347#endif
348
349#ifndef VBOX
350static inline void fpush(void)
351#else
352DECLINLINE(void) fpush(void)
353#endif
354{
355 env->fpstt = (env->fpstt - 1) & 7;
356 env->fptags[env->fpstt] = 0; /* validate stack entry */
357}
358
359#ifndef VBOX
360static inline void fpop(void)
361#else
362DECLINLINE(void) fpop(void)
363#endif
364{
365 env->fptags[env->fpstt] = 1; /* invvalidate stack entry */
366 env->fpstt = (env->fpstt + 1) & 7;
367}
368
369#ifndef USE_X86LDOUBLE
370static inline CPU86_LDouble helper_fldt(target_ulong ptr)
371{
372 CPU86_LDoubleU temp;
373 int upper, e;
374 uint64_t ll;
375
376 /* mantissa */
377 upper = lduw(ptr + 8);
378 /* XXX: handle overflow ? */
379 e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */
380 e |= (upper >> 4) & 0x800; /* sign */
381 ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1);
382#ifdef __arm__
383 temp.l.upper = (e << 20) | (ll >> 32);
384 temp.l.lower = ll;
385#else
386 temp.ll = ll | ((uint64_t)e << 52);
387#endif
388 return temp.d;
389}
390
391static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
392{
393 CPU86_LDoubleU temp;
394 int e;
395
396 temp.d = f;
397 /* mantissa */
398 stq(ptr, (MANTD(temp) << 11) | (1LL << 63));
399 /* exponent + sign */
400 e = EXPD(temp) - EXPBIAS + 16383;
401 e |= SIGND(temp) >> 16;
402 stw(ptr + 8, e);
403}
404#else
405
406/* XXX: same endianness assumed */
407
408#ifdef CONFIG_USER_ONLY
409
410static inline CPU86_LDouble helper_fldt(target_ulong ptr)
411{
412 return *(CPU86_LDouble *)ptr;
413}
414
415static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
416{
417 *(CPU86_LDouble *)ptr = f;
418}
419
420#else
421
422/* we use memory access macros */
423
424#ifndef VBOX
425static inline CPU86_LDouble helper_fldt(target_ulong ptr)
426#else
427DECLINLINE(CPU86_LDouble) helper_fldt(target_ulong ptr)
428#endif
429{
430 CPU86_LDoubleU temp;
431
432 temp.l.lower = ldq(ptr);
433 temp.l.upper = lduw(ptr + 8);
434 return temp.d;
435}
436
437#ifndef VBOX
438static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
439#else
440DECLINLINE(void) helper_fstt(CPU86_LDouble f, target_ulong ptr)
441#endif
442{
443 CPU86_LDoubleU temp;
444
445 temp.d = f;
446 stq(ptr, temp.l.lower);
447 stw(ptr + 8, temp.l.upper);
448}
449
450#endif /* !CONFIG_USER_ONLY */
451
452#endif /* USE_X86LDOUBLE */
453
454#define FPUS_IE (1 << 0)
455#define FPUS_DE (1 << 1)
456#define FPUS_ZE (1 << 2)
457#define FPUS_OE (1 << 3)
458#define FPUS_UE (1 << 4)
459#define FPUS_PE (1 << 5)
460#define FPUS_SF (1 << 6)
461#define FPUS_SE (1 << 7)
462#define FPUS_B (1 << 15)
463
464#define FPUC_EM 0x3f
465
466extern const CPU86_LDouble f15rk[7];
467
468void fpu_raise_exception(void);
469void restore_native_fp_state(CPUState *env);
470void save_native_fp_state(CPUState *env);
471
472extern const uint8_t parity_table[256];
473extern const uint8_t rclw_table[32];
474extern const uint8_t rclb_table[32];
475
476#ifndef VBOX
477static inline uint32_t compute_eflags(void)
478#else
479DECLINLINE(uint32_t) compute_eflags(void)
480#endif
481{
482 return env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
483}
484
485/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
486#ifndef VBOX
487static inline void load_eflags(int eflags, int update_mask)
488#else
489DECLINLINE(void) load_eflags(int eflags, int update_mask)
490#endif
491{
492 CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
493 DF = 1 - (2 * ((eflags >> 10) & 1));
494 env->eflags = (env->eflags & ~update_mask) |
495 (eflags & update_mask);
496}
497
498#ifndef VBOX
499static inline void env_to_regs(void)
500#else
501DECLINLINE(void) env_to_regs(void)
502#endif
503{
504#ifdef reg_EAX
505 EAX = env->regs[R_EAX];
506#endif
507#ifdef reg_ECX
508 ECX = env->regs[R_ECX];
509#endif
510#ifdef reg_EDX
511 EDX = env->regs[R_EDX];
512#endif
513#ifdef reg_EBX
514 EBX = env->regs[R_EBX];
515#endif
516#ifdef reg_ESP
517 ESP = env->regs[R_ESP];
518#endif
519#ifdef reg_EBP
520 EBP = env->regs[R_EBP];
521#endif
522#ifdef reg_ESI
523 ESI = env->regs[R_ESI];
524#endif
525#ifdef reg_EDI
526 EDI = env->regs[R_EDI];
527#endif
528}
529
530#ifndef VBOX
531static inline void regs_to_env(void)
532#else
533DECLINLINE(void) regs_to_env(void)
534#endif
535{
536#ifdef reg_EAX
537 env->regs[R_EAX] = EAX;
538#endif
539#ifdef reg_ECX
540 env->regs[R_ECX] = ECX;
541#endif
542#ifdef reg_EDX
543 env->regs[R_EDX] = EDX;
544#endif
545#ifdef reg_EBX
546 env->regs[R_EBX] = EBX;
547#endif
548#ifdef reg_ESP
549 env->regs[R_ESP] = ESP;
550#endif
551#ifdef reg_EBP
552 env->regs[R_EBP] = EBP;
553#endif
554#ifdef reg_ESI
555 env->regs[R_ESI] = ESI;
556#endif
557#ifdef reg_EDI
558 env->regs[R_EDI] = EDI;
559#endif
560}
561
562#ifndef VBOX
563static inline int cpu_halted(CPUState *env) {
564#else
565DECLINLINE(int) cpu_halted(CPUState *env) {
566#endif
567 /* handle exit of HALTED state */
568 if (!env->halted)
569 return 0;
570 /* disable halt condition */
571 if (((env->interrupt_request & CPU_INTERRUPT_HARD) &&
572 (env->eflags & IF_MASK)) ||
573 (env->interrupt_request & CPU_INTERRUPT_NMI)) {
574 env->halted = 0;
575 return 0;
576 }
577 return EXCP_HALTED;
578}
579
580/* load efer and update the corresponding hflags. XXX: do consistency
581 checks with cpuid bits ? */
582#ifndef VBOX
583static inline void cpu_load_efer(CPUState *env, uint64_t val)
584#else
585DECLINLINE(void) cpu_load_efer(CPUState *env, uint64_t val)
586#endif
587{
588 env->efer = val;
589 env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK);
590 if (env->efer & MSR_EFER_LMA)
591 env->hflags |= HF_LMA_MASK;
592 if (env->efer & MSR_EFER_SVME)
593 env->hflags |= HF_SVME_MASK;
594}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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