exec.h 3.6 KB
Newer Older
B
bellard 已提交
1
/*
2
 *  i386 execution defines
B
bellard 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 *  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
17
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
B
bellard 已提交
18
 */
B
bellard 已提交
19
#include "config.h"
B
bellard 已提交
20 21
#include "dyngen-exec.h"

B
bellard 已提交
22 23 24 25 26 27 28
/* XXX: factorize this mess */
#ifdef TARGET_X86_64
#define TARGET_LONG_BITS 64
#else
#define TARGET_LONG_BITS 32
#endif

B
bellard 已提交
29 30
#include "cpu-defs.h"

B
bellard 已提交
31
register struct CPUX86State *env asm(AREG0);
B
bellard 已提交
32

B
blueswir1 已提交
33
#include "qemu-common.h"
34
#include "qemu-log.h"
B
bellard 已提交
35 36 37 38

#include "cpu.h"
#include "exec-all.h"

B
blueswir1 已提交
39
/* op_helper.c */
M
malc 已提交
40 41
void QEMU_NORETURN raise_exception_err(int exception_index, int error_code);
void QEMU_NORETURN raise_exception(int exception_index);
42
void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv);
B
bellard 已提交
43

44 45 46 47 48 49 50 51 52
/* 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);
}

B
bellard 已提交
53 54
#include "helper.h"

55 56
#if !defined(CONFIG_USER_ONLY)

57
#include "softmmu_exec.h"
58 59 60

#endif /* !defined(CONFIG_USER_ONLY) */

B
bellard 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#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;
}

89
static inline floatx80 helper_fldt(target_ulong ptr)
B
bellard 已提交
90
{
91
    CPU_LDoubleU temp;
92 93 94 95 96 97

    temp.l.lower = ldq(ptr);
    temp.l.upper = lduw(ptr + 8);
    return temp.d;
}

98
static inline void helper_fstt(floatx80 f, target_ulong ptr)
99
{
100
    CPU_LDoubleU temp;
101

102 103 104 105 106
    temp.d = f;
    stq(ptr, temp.l.lower);
    stw(ptr + 8, temp.l.upper);
}

B
bellard 已提交
107 108 109 110 111 112 113 114 115 116 117 118
#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

B
bellard 已提交
119 120
static inline uint32_t compute_eflags(void)
{
P
pbrook 已提交
121
    return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
B
bellard 已提交
122 123 124 125 126 127 128
}

/* 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));
129
    env->eflags = (env->eflags & ~update_mask) |
B
bellard 已提交
130
        (eflags & update_mask) | 0x2;
B
bellard 已提交
131 132
}

B
bellard 已提交
133 134 135 136 137 138 139 140 141 142 143
/* 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;
}