2003-03-23 23:17:16 +03:00
|
|
|
/*
|
|
|
|
* i386 execution defines
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2003-06-15 23:46:57 +04:00
|
|
|
#include "dyngen-exec.h"
|
|
|
|
|
|
|
|
/* at least 4 register variables are defines */
|
|
|
|
register struct CPUX86State *env asm(AREG0);
|
|
|
|
register uint32_t T0 asm(AREG1);
|
|
|
|
register uint32_t T1 asm(AREG2);
|
|
|
|
register uint32_t T2 asm(AREG3);
|
|
|
|
|
|
|
|
#define A0 T2
|
|
|
|
|
|
|
|
/* if more registers are available, we define some registers too */
|
|
|
|
#ifdef AREG4
|
|
|
|
register uint32_t EAX asm(AREG4);
|
2003-03-21 01:33:23 +03:00
|
|
|
#define reg_EAX
|
2003-03-07 02:23:54 +03:00
|
|
|
#endif
|
2003-06-15 23:46:57 +04:00
|
|
|
|
|
|
|
#ifdef AREG5
|
|
|
|
register uint32_t ESP asm(AREG5);
|
2003-05-13 22:59:59 +04:00
|
|
|
#define reg_ESP
|
2003-06-15 23:46:57 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AREG6
|
|
|
|
register uint32_t EBP asm(AREG6);
|
2003-05-13 22:59:59 +04:00
|
|
|
#define reg_EBP
|
2003-03-07 02:23:54 +03:00
|
|
|
#endif
|
2003-06-15 23:46:57 +04:00
|
|
|
|
|
|
|
#ifdef AREG7
|
|
|
|
register uint32_t ECX asm(AREG7);
|
|
|
|
#define reg_ECX
|
2003-03-29 20:32:36 +03:00
|
|
|
#endif
|
2003-06-15 23:46:57 +04:00
|
|
|
|
|
|
|
#ifdef AREG8
|
|
|
|
register uint32_t EDX asm(AREG8);
|
|
|
|
#define reg_EDX
|
2003-04-08 01:33:21 +04:00
|
|
|
#endif
|
2003-06-15 23:46:57 +04:00
|
|
|
|
|
|
|
#ifdef AREG9
|
|
|
|
register uint32_t EBX asm(AREG9);
|
|
|
|
#define reg_EBX
|
2003-04-30 01:10:09 +04:00
|
|
|
#endif
|
2003-03-07 02:23:54 +03:00
|
|
|
|
2003-06-15 23:46:57 +04:00
|
|
|
#ifdef AREG10
|
|
|
|
register uint32_t ESI asm(AREG10);
|
|
|
|
#define reg_ESI
|
|
|
|
#endif
|
2003-03-07 02:23:54 +03:00
|
|
|
|
2003-06-15 23:46:57 +04:00
|
|
|
#ifdef AREG11
|
|
|
|
register uint32_t EDI asm(AREG11);
|
|
|
|
#define reg_EDI
|
2003-03-07 02:23:54 +03:00
|
|
|
#endif
|
|
|
|
|
2003-06-15 23:46:57 +04:00
|
|
|
extern FILE *logfile;
|
|
|
|
extern int loglevel;
|
2003-03-07 02:23:54 +03:00
|
|
|
|
2003-03-21 01:33:23 +03:00
|
|
|
#ifndef reg_EAX
|
2003-03-07 02:23:54 +03:00
|
|
|
#define EAX (env->regs[R_EAX])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_ECX
|
2003-03-07 02:23:54 +03:00
|
|
|
#define ECX (env->regs[R_ECX])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_EDX
|
2003-03-07 02:23:54 +03:00
|
|
|
#define EDX (env->regs[R_EDX])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_EBX
|
2003-03-07 02:23:54 +03:00
|
|
|
#define EBX (env->regs[R_EBX])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_ESP
|
2003-03-07 02:23:54 +03:00
|
|
|
#define ESP (env->regs[R_ESP])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_EBP
|
2003-03-07 02:23:54 +03:00
|
|
|
#define EBP (env->regs[R_EBP])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_ESI
|
2003-03-07 02:23:54 +03:00
|
|
|
#define ESI (env->regs[R_ESI])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
|
|
|
#ifndef reg_EDI
|
2003-03-07 02:23:54 +03:00
|
|
|
#define EDI (env->regs[R_EDI])
|
2003-03-21 01:33:23 +03:00
|
|
|
#endif
|
2003-03-22 18:23:14 +03:00
|
|
|
#define EIP (env->eip)
|
2003-03-07 02:23:54 +03:00
|
|
|
#define DF (env->df)
|
|
|
|
|
|
|
|
#define CC_SRC (env->cc_src)
|
|
|
|
#define CC_DST (env->cc_dst)
|
|
|
|
#define CC_OP (env->cc_op)
|
|
|
|
|
|
|
|
/* float macros */
|
|
|
|
#define FT0 (env->ft0)
|
|
|
|
#define ST0 (env->fpregs[env->fpstt])
|
|
|
|
#define ST(n) (env->fpregs[(env->fpstt + (n)) & 7])
|
|
|
|
#define ST1 ST(1)
|
|
|
|
|
2003-04-30 01:26:53 +04:00
|
|
|
#ifdef USE_FP_CONVERT
|
|
|
|
#define FP_CONVERT (env->fp_convert)
|
|
|
|
#endif
|
|
|
|
|
2003-03-07 02:23:54 +03:00
|
|
|
#include "cpu-i386.h"
|
2003-05-25 20:46:15 +04:00
|
|
|
#include "exec.h"
|
2003-03-07 02:23:54 +03:00
|
|
|
|
|
|
|
typedef struct CCTable {
|
|
|
|
int (*compute_all)(void); /* return all the flags */
|
|
|
|
int (*compute_c)(void); /* return the C flag */
|
|
|
|
} CCTable;
|
|
|
|
|
|
|
|
extern CCTable cc_table[];
|
2003-03-16 21:05:05 +03:00
|
|
|
|
2003-05-28 03:29:48 +04:00
|
|
|
void load_seg(int seg_reg, int selector, unsigned cur_eip);
|
2003-06-21 17:13:13 +04:00
|
|
|
void jmp_seg(int selector, unsigned int new_eip);
|
|
|
|
void helper_lldt_T0(void);
|
|
|
|
void helper_ltr_T0(void);
|
|
|
|
void helper_movl_crN_T0(int reg);
|
|
|
|
void helper_movl_drN_T0(int reg);
|
2003-06-05 04:54:09 +04:00
|
|
|
void __hidden cpu_lock(void);
|
|
|
|
void __hidden cpu_unlock(void);
|
2003-05-28 03:29:48 +04:00
|
|
|
void raise_interrupt(int intno, int is_int, int error_code,
|
|
|
|
unsigned int next_eip);
|
2003-05-08 19:38:21 +04:00
|
|
|
void raise_exception_err(int exception_index, int error_code);
|
2003-03-23 19:49:39 +03:00
|
|
|
void raise_exception(int exception_index);
|
2003-06-05 04:54:09 +04:00
|
|
|
void __hidden cpu_loop_exit(void);
|
2003-05-30 00:04:28 +04:00
|
|
|
void helper_fsave(uint8_t *ptr, int data32);
|
|
|
|
void helper_frstor(uint8_t *ptr, int data32);
|
2003-03-23 19:49:39 +03:00
|
|
|
|
|
|
|
void OPPROTO op_movl_eflags_T0(void);
|
|
|
|
void OPPROTO op_movl_T0_eflags(void);
|
2003-06-05 04:54:09 +04:00
|
|
|
void raise_interrupt(int intno, int is_int, int error_code,
|
|
|
|
unsigned int next_eip);
|
|
|
|
void raise_exception_err(int exception_index, int error_code);
|
|
|
|
void raise_exception(int exception_index);
|
2003-06-09 19:28:45 +04:00
|
|
|
void helper_divl_EAX_T0(uint32_t eip);
|
|
|
|
void helper_idivl_EAX_T0(uint32_t eip);
|
|
|
|
void helper_cmpxchg8b(void);
|
2003-06-05 04:54:09 +04:00
|
|
|
void helper_cpuid(void);
|
2003-06-09 19:28:45 +04:00
|
|
|
void helper_rdtsc(void);
|
2003-06-05 04:54:09 +04:00
|
|
|
void helper_lsl(void);
|
|
|
|
void helper_lar(void);
|
|
|
|
|
|
|
|
#ifdef USE_X86LDOUBLE
|
|
|
|
/* use long double functions */
|
|
|
|
#define lrint lrintl
|
|
|
|
#define llrint llrintl
|
|
|
|
#define fabs fabsl
|
|
|
|
#define sin sinl
|
|
|
|
#define cos cosl
|
|
|
|
#define sqrt sqrtl
|
|
|
|
#define pow powl
|
|
|
|
#define log logl
|
|
|
|
#define tan tanl
|
|
|
|
#define atan2 atan2l
|
|
|
|
#define floor floorl
|
|
|
|
#define ceil ceill
|
|
|
|
#define rint rintl
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int lrint(CPU86_LDouble x);
|
|
|
|
extern int64_t llrint(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble fabs(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble sin(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble cos(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble sqrt(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
|
|
|
|
extern CPU86_LDouble log(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble tan(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
|
|
|
|
extern CPU86_LDouble floor(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble ceil(CPU86_LDouble x);
|
|
|
|
extern CPU86_LDouble rint(CPU86_LDouble x);
|
|
|
|
|
|
|
|
#define RC_MASK 0xc00
|
|
|
|
#define RC_NEAR 0x000
|
|
|
|
#define RC_DOWN 0x400
|
|
|
|
#define RC_UP 0x800
|
|
|
|
#define RC_CHOP 0xc00
|
|
|
|
|
|
|
|
#define MAXTAN 9223372036854775808.0
|
|
|
|
|
2003-06-09 19:28:45 +04:00
|
|
|
#ifdef __arm__
|
|
|
|
/* we have no way to do correct rounding - a FPU emulator is needed */
|
|
|
|
#define FE_DOWNWARD FE_TONEAREST
|
|
|
|
#define FE_UPWARD FE_TONEAREST
|
|
|
|
#define FE_TOWARDZERO FE_TONEAREST
|
|
|
|
#endif
|
|
|
|
|
2003-06-05 04:54:09 +04:00
|
|
|
#ifdef USE_X86LDOUBLE
|
|
|
|
|
|
|
|
/* only for x86 */
|
|
|
|
typedef union {
|
|
|
|
long double d;
|
|
|
|
struct {
|
|
|
|
unsigned long long lower;
|
|
|
|
unsigned short upper;
|
|
|
|
} l;
|
|
|
|
} CPU86_LDoubleU;
|
|
|
|
|
|
|
|
/* the following deal with x86 long double-precision numbers */
|
|
|
|
#define MAXEXPD 0x7fff
|
|
|
|
#define EXPBIAS 16383
|
|
|
|
#define EXPD(fp) (fp.l.upper & 0x7fff)
|
|
|
|
#define SIGND(fp) ((fp.l.upper) & 0x8000)
|
|
|
|
#define MANTD(fp) (fp.l.lower)
|
|
|
|
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2003-06-09 19:28:45 +04:00
|
|
|
/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
2003-06-05 04:54:09 +04:00
|
|
|
typedef union {
|
|
|
|
double d;
|
2003-06-09 19:28:45 +04:00
|
|
|
#if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
|
2003-06-05 04:54:09 +04:00
|
|
|
struct {
|
|
|
|
uint32_t lower;
|
|
|
|
int32_t upper;
|
|
|
|
} l;
|
|
|
|
#else
|
|
|
|
struct {
|
|
|
|
int32_t upper;
|
|
|
|
uint32_t lower;
|
|
|
|
} l;
|
|
|
|
#endif
|
2003-06-09 19:28:45 +04:00
|
|
|
#ifndef __arm__
|
2003-06-05 04:54:09 +04:00
|
|
|
int64_t ll;
|
2003-06-09 19:28:45 +04:00
|
|
|
#endif
|
2003-06-05 04:54:09 +04:00
|
|
|
} CPU86_LDoubleU;
|
|
|
|
|
|
|
|
/* the following deal with IEEE double-precision numbers */
|
|
|
|
#define MAXEXPD 0x7ff
|
|
|
|
#define EXPBIAS 1023
|
|
|
|
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
|
|
|
|
#define SIGND(fp) ((fp.l.upper) & 0x80000000)
|
2003-06-09 19:28:45 +04:00
|
|
|
#ifdef __arm__
|
|
|
|
#define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
|
|
|
|
#else
|
2003-06-05 04:54:09 +04:00
|
|
|
#define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
|
2003-06-09 19:28:45 +04:00
|
|
|
#endif
|
2003-06-05 04:54:09 +04:00
|
|
|
#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void fpush(void)
|
|
|
|
{
|
|
|
|
env->fpstt = (env->fpstt - 1) & 7;
|
|
|
|
env->fptags[env->fpstt] = 0; /* validate stack entry */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void fpop(void)
|
|
|
|
{
|
|
|
|
env->fptags[env->fpstt] = 1; /* invvalidate stack entry */
|
|
|
|
env->fpstt = (env->fpstt + 1) & 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_X86LDOUBLE
|
|
|
|
static inline CPU86_LDouble helper_fldt(uint8_t *ptr)
|
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
|
|
|
int upper, e;
|
2003-06-09 19:28:45 +04:00
|
|
|
uint64_t ll;
|
|
|
|
|
2003-06-05 04:54:09 +04:00
|
|
|
/* mantissa */
|
|
|
|
upper = lduw(ptr + 8);
|
|
|
|
/* XXX: handle overflow ? */
|
|
|
|
e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */
|
|
|
|
e |= (upper >> 4) & 0x800; /* sign */
|
2003-06-09 19:28:45 +04:00
|
|
|
ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1);
|
|
|
|
#ifdef __arm__
|
|
|
|
temp.l.upper = (e << 20) | (ll >> 32);
|
|
|
|
temp.l.lower = ll;
|
|
|
|
#else
|
|
|
|
temp.ll = ll | ((uint64_t)e << 52);
|
|
|
|
#endif
|
2003-06-05 04:54:09 +04:00
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
|
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
|
|
|
int e;
|
2003-06-09 19:28:45 +04:00
|
|
|
|
2003-06-05 04:54:09 +04:00
|
|
|
temp.d = f;
|
|
|
|
/* mantissa */
|
|
|
|
stq(ptr, (MANTD(temp) << 11) | (1LL << 63));
|
|
|
|
/* exponent + sign */
|
|
|
|
e = EXPD(temp) - EXPBIAS + 16383;
|
|
|
|
e |= SIGND(temp) >> 16;
|
|
|
|
stw(ptr + 8, e);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-06-09 19:28:45 +04:00
|
|
|
const CPU86_LDouble f15rk[7];
|
|
|
|
|
2003-06-05 04:54:09 +04:00
|
|
|
void helper_fldt_ST0_A0(void);
|
|
|
|
void helper_fstt_ST0_A0(void);
|
|
|
|
void helper_fbld_ST0_A0(void);
|
|
|
|
void helper_fbst_ST0_A0(void);
|
|
|
|
void helper_f2xm1(void);
|
|
|
|
void helper_fyl2x(void);
|
|
|
|
void helper_fptan(void);
|
|
|
|
void helper_fpatan(void);
|
|
|
|
void helper_fxtract(void);
|
|
|
|
void helper_fprem1(void);
|
|
|
|
void helper_fprem(void);
|
|
|
|
void helper_fyl2xp1(void);
|
|
|
|
void helper_fsqrt(void);
|
|
|
|
void helper_fsincos(void);
|
|
|
|
void helper_frndint(void);
|
|
|
|
void helper_fscale(void);
|
|
|
|
void helper_fsin(void);
|
|
|
|
void helper_fcos(void);
|
|
|
|
void helper_fxam_ST0(void);
|
|
|
|
void helper_fstenv(uint8_t *ptr, int data32);
|
|
|
|
void helper_fldenv(uint8_t *ptr, int data32);
|
|
|
|
void helper_fsave(uint8_t *ptr, int data32);
|
|
|
|
void helper_frstor(uint8_t *ptr, int data32);
|
|
|
|
|
2003-06-15 23:46:57 +04:00
|
|
|
const uint8_t parity_table[256];
|
|
|
|
const uint8_t rclw_table[32];
|
|
|
|
const uint8_t rclb_table[32];
|