2003-10-01 00:34:21 +04:00
|
|
|
/*
|
2007-09-17 01:08:06 +04:00
|
|
|
* i386 execution defines
|
2003-10-01 00:34:21 +04:00
|
|
|
*
|
|
|
|
* 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
|
2009-07-17 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2003-10-01 00:34:21 +04:00
|
|
|
*/
|
2004-05-12 23:32:15 +04:00
|
|
|
#include "config.h"
|
2003-10-01 00:34:21 +04:00
|
|
|
#include "dyngen-exec.h"
|
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
/* XXX: factorize this mess */
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
#define TARGET_LONG_BITS 64
|
|
|
|
#else
|
|
|
|
#define TARGET_LONG_BITS 32
|
|
|
|
#endif
|
|
|
|
|
2005-03-02 01:33:42 +03:00
|
|
|
#include "cpu-defs.h"
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
register struct CPUX86State *env asm(AREG0);
|
2005-01-04 02:50:08 +03:00
|
|
|
|
2009-01-14 22:00:36 +03:00
|
|
|
#include "qemu-common.h"
|
2008-08-30 13:51:20 +04:00
|
|
|
#include "qemu-log.h"
|
2003-10-01 00:34:21 +04:00
|
|
|
|
|
|
|
#define EAX (env->regs[R_EAX])
|
|
|
|
#define ECX (env->regs[R_ECX])
|
|
|
|
#define EDX (env->regs[R_EDX])
|
|
|
|
#define EBX (env->regs[R_EBX])
|
|
|
|
#define ESP (env->regs[R_ESP])
|
|
|
|
#define EBP (env->regs[R_EBP])
|
|
|
|
#define ESI (env->regs[R_ESI])
|
|
|
|
#define EDI (env->regs[R_EDI])
|
2008-05-25 21:26:41 +04:00
|
|
|
#define EIP (env->eip)
|
2003-10-01 00:34:21 +04: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)
|
2005-01-08 21:58:29 +03:00
|
|
|
#define ST0 (env->fpregs[env->fpstt].d)
|
|
|
|
#define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d)
|
2003-10-01 00:34:21 +04:00
|
|
|
#define ST1 ST(1)
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "exec-all.h"
|
|
|
|
|
x86 cleanup
Remove some unnecessary includes, add needed includes, move prototypes to
cpu.h to suppress missing prototype warnings.
Remove unused functions and prototypes (cpu_x86_flush_tlb, cpu_lock,
cpu_unlock, restore_native_fp_state, save_native_fp_state).
Make some functions and data static (f15rk, parity_table, rclw_table,
rclb_table, raise_interrupt, fpu_raise_exception), they are not used
outside op_helper.c anymore.
Make some x86_64 and user only code conditional to avoid warnings.
Document where each function is implemented in cpu.h and exec.h.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6005 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-13 14:49:17 +03:00
|
|
|
/* op_helper.c */
|
2007-09-17 01:08:06 +04:00
|
|
|
void do_interrupt(int intno, int is_int, int error_code,
|
2005-01-04 02:50:08 +03:00
|
|
|
target_ulong next_eip, int is_hw);
|
2007-09-17 01:08:06 +04:00
|
|
|
void do_interrupt_user(int intno, int is_int, int error_code,
|
2005-01-04 02:50:08 +03:00
|
|
|
target_ulong next_eip);
|
2009-02-02 01:19:27 +03:00
|
|
|
void QEMU_NORETURN raise_exception_err(int exception_index, int error_code);
|
|
|
|
void QEMU_NORETURN raise_exception(int exception_index);
|
2006-09-24 22:41:56 +04:00
|
|
|
void do_smm_enter(void);
|
2003-10-01 00:34:21 +04:00
|
|
|
|
2008-05-17 16:44:31 +04:00
|
|
|
/* n must be a constant to be efficient */
|
|
|
|
static inline target_long lshift(target_long x, int n)
|
|
|
|
{
|
|
|
|
if (n >= 0)
|
|
|
|
return x << n;
|
|
|
|
else
|
|
|
|
return x >> (-n);
|
|
|
|
}
|
|
|
|
|
2008-02-01 13:50:11 +03:00
|
|
|
#include "helper.h"
|
|
|
|
|
2008-05-15 20:46:30 +04:00
|
|
|
static inline void svm_check_intercept(uint32_t type)
|
|
|
|
{
|
|
|
|
helper_svm_check_intercept_param(type, 0);
|
|
|
|
}
|
2003-11-13 03:13:08 +03:00
|
|
|
|
2003-10-29 02:06:17 +03:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
|
2005-10-30 21:16:26 +03:00
|
|
|
#include "softmmu_exec.h"
|
2003-10-29 02:06:17 +03:00
|
|
|
|
|
|
|
#endif /* !defined(CONFIG_USER_ONLY) */
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
#ifdef USE_X86LDOUBLE
|
|
|
|
/* use long double functions */
|
2005-03-13 20:01:47 +03:00
|
|
|
#define floatx_to_int32 floatx80_to_int32
|
|
|
|
#define floatx_to_int64 floatx80_to_int64
|
2006-04-24 01:54:01 +04:00
|
|
|
#define floatx_to_int32_round_to_zero floatx80_to_int32_round_to_zero
|
|
|
|
#define floatx_to_int64_round_to_zero floatx80_to_int64_round_to_zero
|
2008-05-12 23:10:44 +04:00
|
|
|
#define int32_to_floatx int32_to_floatx80
|
|
|
|
#define int64_to_floatx int64_to_floatx80
|
|
|
|
#define float32_to_floatx float32_to_floatx80
|
|
|
|
#define float64_to_floatx float64_to_floatx80
|
|
|
|
#define floatx_to_float32 floatx80_to_float32
|
|
|
|
#define floatx_to_float64 floatx80_to_float64
|
2005-03-13 20:01:47 +03:00
|
|
|
#define floatx_abs floatx80_abs
|
|
|
|
#define floatx_chs floatx80_chs
|
|
|
|
#define floatx_round_to_int floatx80_round_to_int
|
2005-03-20 13:39:24 +03:00
|
|
|
#define floatx_compare floatx80_compare
|
|
|
|
#define floatx_compare_quiet floatx80_compare_quiet
|
2004-05-12 23:32:15 +04:00
|
|
|
#else
|
2005-03-13 20:01:47 +03:00
|
|
|
#define floatx_to_int32 float64_to_int32
|
|
|
|
#define floatx_to_int64 float64_to_int64
|
2006-04-24 01:54:01 +04:00
|
|
|
#define floatx_to_int32_round_to_zero float64_to_int32_round_to_zero
|
|
|
|
#define floatx_to_int64_round_to_zero float64_to_int64_round_to_zero
|
2008-05-12 23:10:44 +04:00
|
|
|
#define int32_to_floatx int32_to_float64
|
|
|
|
#define int64_to_floatx int64_to_float64
|
|
|
|
#define float32_to_floatx float32_to_float64
|
|
|
|
#define float64_to_floatx(x, e) (x)
|
|
|
|
#define floatx_to_float32 float64_to_float32
|
|
|
|
#define floatx_to_float64(x, e) (x)
|
2005-03-13 20:01:47 +03:00
|
|
|
#define floatx_abs float64_abs
|
|
|
|
#define floatx_chs float64_chs
|
|
|
|
#define floatx_round_to_int float64_round_to_int
|
2005-03-20 13:39:24 +03:00
|
|
|
#define floatx_compare float64_compare
|
|
|
|
#define floatx_compare_quiet float64_compare_quiet
|
2004-05-12 23:32:15 +04:00
|
|
|
#endif
|
2005-03-13 20:01:47 +03:00
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
#define RC_MASK 0xc00
|
|
|
|
#define RC_NEAR 0x000
|
|
|
|
#define RC_DOWN 0x400
|
|
|
|
#define RC_UP 0x800
|
|
|
|
#define RC_CHOP 0xc00
|
|
|
|
|
|
|
|
#define MAXTAN 9223372036854775808.0
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
|
|
|
typedef union {
|
|
|
|
double d;
|
|
|
|
#if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
|
|
|
|
struct {
|
|
|
|
uint32_t lower;
|
|
|
|
int32_t upper;
|
|
|
|
} l;
|
|
|
|
#else
|
|
|
|
struct {
|
|
|
|
int32_t upper;
|
|
|
|
uint32_t lower;
|
|
|
|
} l;
|
|
|
|
#endif
|
|
|
|
#ifndef __arm__
|
|
|
|
int64_t ll;
|
|
|
|
#endif
|
|
|
|
} 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)
|
|
|
|
#ifdef __arm__
|
|
|
|
#define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
|
|
|
|
#else
|
|
|
|
#define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
|
|
|
|
#endif
|
|
|
|
#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
|
2005-01-04 02:50:08 +03:00
|
|
|
static inline CPU86_LDouble helper_fldt(target_ulong ptr)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
|
|
|
int upper, e;
|
|
|
|
uint64_t ll;
|
|
|
|
|
|
|
|
/* mantissa */
|
|
|
|
upper = lduw(ptr + 8);
|
|
|
|
/* XXX: handle overflow ? */
|
|
|
|
e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */
|
|
|
|
e |= (upper >> 4) & 0x800; /* sign */
|
|
|
|
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
|
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
2005-01-08 21:58:29 +03:00
|
|
|
static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2003-10-29 02:06:17 +03:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* we use memory access macros */
|
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
static inline CPU86_LDouble helper_fldt(target_ulong ptr)
|
2003-10-29 02:06:17 +03:00
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
|
|
|
|
|
|
|
temp.l.lower = ldq(ptr);
|
|
|
|
temp.l.upper = lduw(ptr + 8);
|
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
|
2003-10-29 02:06:17 +03:00
|
|
|
{
|
|
|
|
CPU86_LDoubleU temp;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2003-10-29 02:06:17 +03:00
|
|
|
temp.d = f;
|
|
|
|
stq(ptr, temp.l.lower);
|
|
|
|
stw(ptr + 8, temp.l.upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_X86LDOUBLE */
|
2003-10-01 00:34:21 +04:00
|
|
|
|
2004-05-09 01:08:41 +04:00
|
|
|
#define FPUS_IE (1 << 0)
|
|
|
|
#define FPUS_DE (1 << 1)
|
|
|
|
#define FPUS_ZE (1 << 2)
|
|
|
|
#define FPUS_OE (1 << 3)
|
|
|
|
#define FPUS_UE (1 << 4)
|
|
|
|
#define FPUS_PE (1 << 5)
|
|
|
|
#define FPUS_SF (1 << 6)
|
|
|
|
#define FPUS_SE (1 << 7)
|
|
|
|
#define FPUS_B (1 << 15)
|
|
|
|
|
|
|
|
#define FPUC_EM 0x3f
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
static inline uint32_t compute_eflags(void)
|
|
|
|
{
|
2008-11-17 17:43:54 +03:00
|
|
|
return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
|
|
|
|
static inline void load_eflags(int eflags, int update_mask)
|
|
|
|
{
|
|
|
|
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
|
|
|
DF = 1 - (2 * ((eflags >> 10) & 1));
|
2007-09-17 01:08:06 +04:00
|
|
|
env->eflags = (env->eflags & ~update_mask) |
|
2008-05-28 20:25:20 +04:00
|
|
|
(eflags & update_mask) | 0x2;
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
|
2004-10-13 02:01:28 +04:00
|
|
|
static inline void env_to_regs(void)
|
|
|
|
{
|
|
|
|
#ifdef reg_EAX
|
|
|
|
EAX = env->regs[R_EAX];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ECX
|
|
|
|
ECX = env->regs[R_ECX];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EDX
|
|
|
|
EDX = env->regs[R_EDX];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EBX
|
|
|
|
EBX = env->regs[R_EBX];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ESP
|
|
|
|
ESP = env->regs[R_ESP];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EBP
|
|
|
|
EBP = env->regs[R_EBP];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ESI
|
|
|
|
ESI = env->regs[R_ESI];
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EDI
|
|
|
|
EDI = env->regs[R_EDI];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void regs_to_env(void)
|
|
|
|
{
|
|
|
|
#ifdef reg_EAX
|
|
|
|
env->regs[R_EAX] = EAX;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ECX
|
|
|
|
env->regs[R_ECX] = ECX;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EDX
|
|
|
|
env->regs[R_EDX] = EDX;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EBX
|
|
|
|
env->regs[R_EBX] = EBX;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ESP
|
|
|
|
env->regs[R_ESP] = ESP;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EBP
|
|
|
|
env->regs[R_EBP] = EBP;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_ESI
|
|
|
|
env->regs[R_ESI] = ESI;
|
|
|
|
#endif
|
|
|
|
#ifdef reg_EDI
|
|
|
|
env->regs[R_EDI] = EDI;
|
|
|
|
#endif
|
|
|
|
}
|
2007-06-03 21:44:37 +04:00
|
|
|
|
2009-04-24 22:03:20 +04:00
|
|
|
static inline int cpu_has_work(CPUState *env)
|
|
|
|
{
|
|
|
|
int work;
|
|
|
|
|
|
|
|
work = (env->interrupt_request & CPU_INTERRUPT_HARD) &&
|
|
|
|
(env->eflags & IF_MASK);
|
|
|
|
work |= env->interrupt_request & CPU_INTERRUPT_NMI;
|
2009-06-18 00:26:59 +04:00
|
|
|
work |= env->interrupt_request & CPU_INTERRUPT_INIT;
|
|
|
|
work |= env->interrupt_request & CPU_INTERRUPT_SIPI;
|
2009-04-24 22:03:20 +04:00
|
|
|
|
|
|
|
return work;
|
|
|
|
}
|
|
|
|
|
2007-06-03 21:44:37 +04:00
|
|
|
static inline int cpu_halted(CPUState *env) {
|
|
|
|
/* handle exit of HALTED state */
|
2008-05-28 21:14:10 +04:00
|
|
|
if (!env->halted)
|
2007-06-03 21:44:37 +04:00
|
|
|
return 0;
|
|
|
|
/* disable halt condition */
|
2009-04-24 22:03:20 +04:00
|
|
|
if (cpu_has_work(env)) {
|
2008-05-28 21:14:10 +04:00
|
|
|
env->halted = 0;
|
2007-06-03 21:44:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return EXCP_HALTED;
|
|
|
|
}
|
2007-09-23 19:28:04 +04:00
|
|
|
|
2008-06-04 17:35:58 +04:00
|
|
|
/* load efer and update the corresponding hflags. XXX: do consistency
|
|
|
|
checks with cpuid bits ? */
|
|
|
|
static inline void cpu_load_efer(CPUState *env, uint64_t val)
|
|
|
|
{
|
|
|
|
env->efer = val;
|
|
|
|
env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK);
|
|
|
|
if (env->efer & MSR_EFER_LMA)
|
|
|
|
env->hflags |= HF_LMA_MASK;
|
|
|
|
if (env->efer & MSR_EFER_SVME)
|
|
|
|
env->hflags |= HF_SVME_MASK;
|
|
|
|
}
|