]>
git.proxmox.com Git - qemu.git/blob - target-i386/exec.h
2 * i386 execution defines
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
21 #include "dyngen-exec.h"
23 /* at least 4 register variables are defined */
24 register struct CPUX86State
*env
asm(AREG0
);
25 register uint32_t T0
asm(AREG1
);
26 register uint32_t T1
asm(AREG2
);
27 register uint32_t T2
asm(AREG3
);
31 /* if more registers are available, we define some registers too */
33 register uint32_t EAX
asm(AREG4
);
38 register uint32_t ESP
asm(AREG5
);
43 register uint32_t EBP
asm(AREG6
);
48 register uint32_t ECX
asm(AREG7
);
53 register uint32_t EDX
asm(AREG8
);
58 register uint32_t EBX
asm(AREG9
);
63 register uint32_t ESI
asm(AREG10
);
68 register uint32_t EDI
asm(AREG11
);
76 #define EAX (env->regs[R_EAX])
79 #define ECX (env->regs[R_ECX])
82 #define EDX (env->regs[R_EDX])
85 #define EBX (env->regs[R_EBX])
88 #define ESP (env->regs[R_ESP])
91 #define EBP (env->regs[R_EBP])
94 #define ESI (env->regs[R_ESI])
97 #define EDI (env->regs[R_EDI])
99 #define EIP (env->eip)
102 #define CC_SRC (env->cc_src)
103 #define CC_DST (env->cc_dst)
104 #define CC_OP (env->cc_op)
107 #define FT0 (env->ft0)
108 #define ST0 (env->fpregs[env->fpstt])
109 #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7])
112 #ifdef USE_FP_CONVERT
113 #define FP_CONVERT (env->fp_convert)
117 #include "exec-all.h"
119 typedef struct CCTable
{
120 int (*compute_all
)(void); /* return all the flags */
121 int (*compute_c
)(void); /* return the C flag */
124 extern CCTable cc_table
[];
126 void load_seg(int seg_reg
, int selector
);
127 void helper_ljmp_protected_T0_T1(int next_eip
);
128 void helper_lcall_real_T0_T1(int shift
, int next_eip
);
129 void helper_lcall_protected_T0_T1(int shift
, int next_eip
);
130 void helper_iret_real(int shift
);
131 void helper_iret_protected(int shift
, int next_eip
);
132 void helper_lret_protected(int shift
, int addend
);
133 void helper_lldt_T0(void);
134 void helper_ltr_T0(void);
135 void helper_movl_crN_T0(int reg
);
136 void helper_movl_drN_T0(int reg
);
137 void helper_invlpg(unsigned int addr
);
138 void cpu_x86_update_cr0(CPUX86State
*env
, uint32_t new_cr0
);
139 void cpu_x86_update_cr3(CPUX86State
*env
, uint32_t new_cr3
);
140 void cpu_x86_update_cr4(CPUX86State
*env
, uint32_t new_cr4
);
141 void cpu_x86_flush_tlb(CPUX86State
*env
, uint32_t addr
);
142 int cpu_x86_handle_mmu_fault(CPUX86State
*env
, uint32_t addr
,
143 int is_write
, int is_user
, int is_softmmu
);
144 void tlb_fill(unsigned long addr
, int is_write
, int is_user
,
146 void __hidden
cpu_lock(void);
147 void __hidden
cpu_unlock(void);
148 void do_interrupt(int intno
, int is_int
, int error_code
,
149 unsigned int next_eip
, int is_hw
);
150 void do_interrupt_user(int intno
, int is_int
, int error_code
,
151 unsigned int next_eip
);
152 void raise_interrupt(int intno
, int is_int
, int error_code
,
153 unsigned int next_eip
);
154 void raise_exception_err(int exception_index
, int error_code
);
155 void raise_exception(int exception_index
);
156 void __hidden
cpu_loop_exit(void);
157 void helper_fsave(uint8_t *ptr
, int data32
);
158 void helper_frstor(uint8_t *ptr
, int data32
);
160 void OPPROTO
op_movl_eflags_T0(void);
161 void OPPROTO
op_movl_T0_eflags(void);
162 void raise_interrupt(int intno
, int is_int
, int error_code
,
163 unsigned int next_eip
);
164 void raise_exception_err(int exception_index
, int error_code
);
165 void raise_exception(int exception_index
);
166 void helper_divl_EAX_T0(uint32_t eip
);
167 void helper_idivl_EAX_T0(uint32_t eip
);
168 void helper_cmpxchg8b(void);
169 void helper_cpuid(void);
170 void helper_sysenter(void);
171 void helper_sysexit(void);
172 void helper_rdtsc(void);
173 void helper_rdmsr(void);
174 void helper_wrmsr(void);
175 void helper_lsl(void);
176 void helper_lar(void);
177 void helper_verr(void);
178 void helper_verw(void);
180 void check_iob_T0(void);
181 void check_iow_T0(void);
182 void check_iol_T0(void);
183 void check_iob_DX(void);
184 void check_iow_DX(void);
185 void check_iol_DX(void);
187 /* XXX: move that to a generic header */
188 #if !defined(CONFIG_USER_ONLY)
190 #define ldul_user ldl_user
191 #define ldul_kernel ldl_kernel
193 #define ACCESS_TYPE 0
194 #define MEMSUFFIX _kernel
196 #include "softmmu_header.h"
199 #include "softmmu_header.h"
202 #include "softmmu_header.h"
205 #include "softmmu_header.h"
209 #define ACCESS_TYPE 1
210 #define MEMSUFFIX _user
212 #include "softmmu_header.h"
215 #include "softmmu_header.h"
218 #include "softmmu_header.h"
221 #include "softmmu_header.h"
225 /* these access are slower, they must be as rare as possible */
226 #define ACCESS_TYPE 2
227 #define MEMSUFFIX _data
229 #include "softmmu_header.h"
232 #include "softmmu_header.h"
235 #include "softmmu_header.h"
238 #include "softmmu_header.h"
242 #define ldub(p) ldub_data(p)
243 #define ldsb(p) ldsb_data(p)
244 #define lduw(p) lduw_data(p)
245 #define ldsw(p) ldsw_data(p)
246 #define ldl(p) ldl_data(p)
247 #define ldq(p) ldq_data(p)
249 #define stb(p, v) stb_data(p, v)
250 #define stw(p, v) stw_data(p, v)
251 #define stl(p, v) stl_data(p, v)
252 #define stq(p, v) stq_data(p, v)
254 static inline double ldfq(void *ptr
)
264 static inline void stfq(void *ptr
, double v
)
274 static inline float ldfl(void *ptr
)
284 static inline void stfl(void *ptr
, float v
)
294 #endif /* !defined(CONFIG_USER_ONLY) */
296 #ifdef USE_X86LDOUBLE
297 /* use long double functions */
299 #define llrint llrintl
314 extern int lrint(CPU86_LDouble x
);
315 extern int64_t llrint(CPU86_LDouble x
);
317 #define lrint(d) ((int)rint(d))
318 #define llrint(d) ((int)rint(d))
320 extern CPU86_LDouble
fabs(CPU86_LDouble x
);
321 extern CPU86_LDouble
sin(CPU86_LDouble x
);
322 extern CPU86_LDouble
cos(CPU86_LDouble x
);
323 extern CPU86_LDouble
sqrt(CPU86_LDouble x
);
324 extern CPU86_LDouble
pow(CPU86_LDouble
, CPU86_LDouble
);
325 extern CPU86_LDouble
log(CPU86_LDouble x
);
326 extern CPU86_LDouble
tan(CPU86_LDouble x
);
327 extern CPU86_LDouble
atan2(CPU86_LDouble
, CPU86_LDouble
);
328 extern CPU86_LDouble
floor(CPU86_LDouble x
);
329 extern CPU86_LDouble
ceil(CPU86_LDouble x
);
330 extern CPU86_LDouble
rint(CPU86_LDouble x
);
332 #define RC_MASK 0xc00
333 #define RC_NEAR 0x000
334 #define RC_DOWN 0x400
336 #define RC_CHOP 0xc00
338 #define MAXTAN 9223372036854775808.0
341 /* we have no way to do correct rounding - a FPU emulator is needed */
342 #define FE_DOWNWARD FE_TONEAREST
343 #define FE_UPWARD FE_TONEAREST
344 #define FE_TOWARDZERO FE_TONEAREST
347 #ifdef USE_X86LDOUBLE
353 unsigned long long lower
;
354 unsigned short upper
;
358 /* the following deal with x86 long double-precision numbers */
359 #define MAXEXPD 0x7fff
360 #define EXPBIAS 16383
361 #define EXPD(fp) (fp.l.upper & 0x7fff)
362 #define SIGND(fp) ((fp.l.upper) & 0x8000)
363 #define MANTD(fp) (fp.l.lower)
364 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
368 /* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
371 #if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
387 /* the following deal with IEEE double-precision numbers */
388 #define MAXEXPD 0x7ff
390 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
391 #define SIGND(fp) ((fp.l.upper) & 0x80000000)
393 #define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
395 #define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
397 #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
400 static inline void fpush(void)
402 env
->fpstt
= (env
->fpstt
- 1) & 7;
403 env
->fptags
[env
->fpstt
] = 0; /* validate stack entry */
406 static inline void fpop(void)
408 env
->fptags
[env
->fpstt
] = 1; /* invvalidate stack entry */
409 env
->fpstt
= (env
->fpstt
+ 1) & 7;
412 #ifndef USE_X86LDOUBLE
413 static inline CPU86_LDouble
helper_fldt(uint8_t *ptr
)
420 upper
= lduw(ptr
+ 8);
421 /* XXX: handle overflow ? */
422 e
= (upper
& 0x7fff) - 16383 + EXPBIAS
; /* exponent */
423 e
|= (upper
>> 4) & 0x800; /* sign */
424 ll
= (ldq(ptr
) >> 11) & ((1LL << 52) - 1);
426 temp
.l
.upper
= (e
<< 20) | (ll
>> 32);
429 temp
.ll
= ll
| ((uint64_t)e
<< 52);
434 static inline void helper_fstt(CPU86_LDouble f
, uint8_t *ptr
)
441 stq(ptr
, (MANTD(temp
) << 11) | (1LL << 63));
442 /* exponent + sign */
443 e
= EXPD(temp
) - EXPBIAS
+ 16383;
444 e
|= SIGND(temp
) >> 16;
449 /* XXX: same endianness assumed */
451 #ifdef CONFIG_USER_ONLY
453 static inline CPU86_LDouble
helper_fldt(uint8_t *ptr
)
455 return *(CPU86_LDouble
*)ptr
;
458 static inline void helper_fstt(CPU86_LDouble f
, uint8_t *ptr
)
460 *(CPU86_LDouble
*)ptr
= f
;
465 /* we use memory access macros */
467 static inline CPU86_LDouble
helper_fldt(uint8_t *ptr
)
471 temp
.l
.lower
= ldq(ptr
);
472 temp
.l
.upper
= lduw(ptr
+ 8);
476 static inline void helper_fstt(CPU86_LDouble f
, uint8_t *ptr
)
481 stq(ptr
, temp
.l
.lower
);
482 stw(ptr
+ 8, temp
.l
.upper
);
485 #endif /* !CONFIG_USER_ONLY */
487 #endif /* USE_X86LDOUBLE */
489 #define FPUS_IE (1 << 0)
490 #define FPUS_DE (1 << 1)
491 #define FPUS_ZE (1 << 2)
492 #define FPUS_OE (1 << 3)
493 #define FPUS_UE (1 << 4)
494 #define FPUS_PE (1 << 5)
495 #define FPUS_SF (1 << 6)
496 #define FPUS_SE (1 << 7)
497 #define FPUS_B (1 << 15)
501 extern const CPU86_LDouble f15rk
[7];
503 void helper_fldt_ST0_A0(void);
504 void helper_fstt_ST0_A0(void);
505 void fpu_raise_exception(void);
506 CPU86_LDouble
helper_fdiv(CPU86_LDouble a
, CPU86_LDouble b
);
507 void helper_fbld_ST0_A0(void);
508 void helper_fbst_ST0_A0(void);
509 void helper_f2xm1(void);
510 void helper_fyl2x(void);
511 void helper_fptan(void);
512 void helper_fpatan(void);
513 void helper_fxtract(void);
514 void helper_fprem1(void);
515 void helper_fprem(void);
516 void helper_fyl2xp1(void);
517 void helper_fsqrt(void);
518 void helper_fsincos(void);
519 void helper_frndint(void);
520 void helper_fscale(void);
521 void helper_fsin(void);
522 void helper_fcos(void);
523 void helper_fxam_ST0(void);
524 void helper_fstenv(uint8_t *ptr
, int data32
);
525 void helper_fldenv(uint8_t *ptr
, int data32
);
526 void helper_fsave(uint8_t *ptr
, int data32
);
527 void helper_frstor(uint8_t *ptr
, int data32
);
528 void restore_native_fp_state(CPUState
*env
);
529 void save_native_fp_state(CPUState
*env
);
531 extern const uint8_t parity_table
[256];
532 extern const uint8_t rclw_table
[32];
533 extern const uint8_t rclb_table
[32];
535 static inline uint32_t compute_eflags(void)
537 return env
->eflags
| cc_table
[CC_OP
].compute_all() | (DF
& DF_MASK
);
540 /* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
541 static inline void load_eflags(int eflags
, int update_mask
)
543 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
544 DF
= 1 - (2 * ((eflags
>> 10) & 1));
545 env
->eflags
= (env
->eflags
& ~update_mask
) |
546 (eflags
& update_mask
);
549 static inline void env_to_regs(void)
552 EAX
= env
->regs
[R_EAX
];
555 ECX
= env
->regs
[R_ECX
];
558 EDX
= env
->regs
[R_EDX
];
561 EBX
= env
->regs
[R_EBX
];
564 ESP
= env
->regs
[R_ESP
];
567 EBP
= env
->regs
[R_EBP
];
570 ESI
= env
->regs
[R_ESI
];
573 EDI
= env
->regs
[R_EDI
];
577 static inline void regs_to_env(void)
580 env
->regs
[R_EAX
] = EAX
;
583 env
->regs
[R_ECX
] = ECX
;
586 env
->regs
[R_EDX
] = EDX
;
589 env
->regs
[R_EBX
] = EBX
;
592 env
->regs
[R_ESP
] = ESP
;
595 env
->regs
[R_EBP
] = EBP
;
598 env
->regs
[R_ESI
] = ESI
;
601 env
->regs
[R_EDI
] = EDI
;