2003-09-30 22:34:21 +02:00
|
|
|
/*
|
2007-09-16 23:08:06 +02:00
|
|
|
* i386 execution defines
|
2003-09-30 22:34:21 +02: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-16 22:47:01 +02:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2003-09-30 22:34:21 +02:00
|
|
|
*/
|
2004-05-12 21:32:15 +02:00
|
|
|
#include "config.h"
|
2003-09-30 22:34:21 +02:00
|
|
|
#include "dyngen-exec.h"
|
|
|
|
|
2005-01-04 00:50:08 +01:00
|
|
|
/* XXX: factorize this mess */
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
#define TARGET_LONG_BITS 64
|
|
|
|
#else
|
|
|
|
#define TARGET_LONG_BITS 32
|
|
|
|
#endif
|
|
|
|
|
2005-03-01 23:33:42 +01:00
|
|
|
#include "cpu-defs.h"
|
|
|
|
|
2003-09-30 22:34:21 +02:00
|
|
|
register struct CPUX86State *env asm(AREG0);
|
2005-01-04 00:50:08 +01:00
|
|
|
|
2009-01-14 20:00:36 +01:00
|
|
|
#include "qemu-common.h"
|
2008-08-30 11:51:20 +02:00
|
|
|
#include "qemu-log.h"
|
2003-09-30 22:34:21 +02:00
|
|
|
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EAX
|
2003-09-30 22:34:21 +02:00
|
|
|
#define EAX (env->regs[R_EAX])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef ECX
|
2003-09-30 22:34:21 +02:00
|
|
|
#define ECX (env->regs[R_ECX])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EDX
|
2003-09-30 22:34:21 +02:00
|
|
|
#define EDX (env->regs[R_EDX])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EBX
|
2003-09-30 22:34:21 +02:00
|
|
|
#define EBX (env->regs[R_EBX])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef ESP
|
2003-09-30 22:34:21 +02:00
|
|
|
#define ESP (env->regs[R_ESP])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EBP
|
2003-09-30 22:34:21 +02:00
|
|
|
#define EBP (env->regs[R_EBP])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef ESI
|
2003-09-30 22:34:21 +02:00
|
|
|
#define ESI (env->regs[R_ESI])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EDI
|
2003-09-30 22:34:21 +02:00
|
|
|
#define EDI (env->regs[R_EDI])
|
2009-09-12 14:36:11 +02:00
|
|
|
#undef EIP
|
2008-05-25 19:26:41 +02:00
|
|
|
#define EIP (env->eip)
|
2003-09-30 22:34:21 +02: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 19:58:29 +01:00
|
|
|
#define ST0 (env->fpregs[env->fpstt].d)
|
|
|
|
#define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d)
|
2003-09-30 22:34:21 +02: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 12:49:17 +01:00
|
|
|
/* op_helper.c */
|
2007-09-16 23:08:06 +02:00
|
|
|
void do_interrupt(int intno, int is_int, int error_code,
|
2005-01-04 00:50:08 +01:00
|
|
|
target_ulong next_eip, int is_hw);
|
2007-09-16 23:08:06 +02:00
|
|
|
void do_interrupt_user(int intno, int is_int, int error_code,
|
2005-01-04 00:50:08 +01:00
|
|
|
target_ulong next_eip);
|
2009-02-01 23:19:27 +01:00
|
|
|
void QEMU_NORETURN raise_exception_err(int exception_index, int error_code);
|
|
|
|
void QEMU_NORETURN raise_exception(int exception_index);
|
2010-01-26 23:29:50 +01:00
|
|
|
void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv);
|
2006-09-24 20:41:56 +02:00
|
|
|
void do_smm_enter(void);
|
2003-09-30 22:34:21 +02:00
|
|
|
|
2008-05-17 14:44:31 +02: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 11:50:11 +01:00
|
|
|
#include "helper.h"
|
|
|
|
|
2008-05-15 18:46:30 +02:00
|
|
|
static inline void svm_check_intercept(uint32_t type)
|
|
|
|
{
|
|
|
|
helper_svm_check_intercept_param(type, 0);
|
|
|
|
}
|
2003-11-13 01:13:08 +01:00
|
|
|
|
2003-10-29 00:06:17 +01:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
|
2005-10-30 19:16:26 +01:00
|
|
|
#include "softmmu_exec.h"
|
2003-10-29 00:06:17 +01:00
|
|
|
|
|
|
|
#endif /* !defined(CONFIG_USER_ONLY) */
|
|
|
|
|
2003-09-30 22:34:21 +02: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
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-15 14:09:18 +02:00
|
|
|
static inline floatx80 helper_fldt(target_ulong ptr)
|
2003-09-30 22:34:21 +02:00
|
|
|
{
|
2011-05-15 14:09:18 +02:00
|
|
|
CPU_LDoubleU temp;
|
2003-10-29 00:06:17 +01:00
|
|
|
|
|
|
|
temp.l.lower = ldq(ptr);
|
|
|
|
temp.l.upper = lduw(ptr + 8);
|
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
2011-05-15 14:09:18 +02:00
|
|
|
static inline void helper_fstt(floatx80 f, target_ulong ptr)
|
2003-10-29 00:06:17 +01:00
|
|
|
{
|
2011-05-15 14:09:18 +02:00
|
|
|
CPU_LDoubleU temp;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2003-10-29 00:06:17 +01:00
|
|
|
temp.d = f;
|
|
|
|
stq(ptr, temp.l.lower);
|
|
|
|
stw(ptr + 8, temp.l.upper);
|
|
|
|
}
|
|
|
|
|
2004-05-08 23:08:41 +02: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-09-30 22:34:21 +02:00
|
|
|
static inline uint32_t compute_eflags(void)
|
|
|
|
{
|
2008-11-17 15:43:54 +01:00
|
|
|
return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
|
2003-09-30 22:34:21 +02: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-16 23:08:06 +02:00
|
|
|
env->eflags = (env->eflags & ~update_mask) |
|
2008-05-28 18:25:20 +02:00
|
|
|
(eflags & update_mask) | 0x2;
|
2003-09-30 22:34:21 +02:00
|
|
|
}
|
|
|
|
|
2009-04-24 20:03:20 +02:00
|
|
|
static inline int cpu_has_work(CPUState *env)
|
|
|
|
{
|
2011-03-02 08:56:06 +01:00
|
|
|
return ((env->interrupt_request & CPU_INTERRUPT_HARD) &&
|
|
|
|
(env->eflags & IF_MASK)) ||
|
|
|
|
(env->interrupt_request & (CPU_INTERRUPT_NMI |
|
|
|
|
CPU_INTERRUPT_INIT |
|
|
|
|
CPU_INTERRUPT_SIPI |
|
|
|
|
CPU_INTERRUPT_MCE));
|
2009-04-24 20:03:20 +02:00
|
|
|
}
|
|
|
|
|
2008-06-04 15:35:58 +02: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;
|
|
|
|
}
|
2010-06-29 09:58:50 +02:00
|
|
|
|
|
|
|
static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
|
|
|
|
{
|
|
|
|
env->eip = tb->pc - tb->cs_base;
|
|
|
|
}
|
|
|
|
|