2003-10-01 00:34:21 +04:00
|
|
|
/*
|
|
|
|
* i386 helpers (without register variable usage)
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "exec-all.h"
|
2007-09-23 19:28:04 +04:00
|
|
|
#include "svm.h"
|
2003-10-01 00:34:21 +04:00
|
|
|
|
|
|
|
//#define DEBUG_MMU
|
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
static int cpu_x86_register (CPUX86State *env, const char *cpu_model);
|
2007-11-08 16:28:47 +03:00
|
|
|
|
|
|
|
static void add_flagname_to_bitmaps(char *flagname, uint32_t *features,
|
|
|
|
uint32_t *ext_features,
|
|
|
|
uint32_t *ext2_features,
|
|
|
|
uint32_t *ext3_features)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* feature flags taken from "Intel Processor Identification and the CPUID
|
|
|
|
* Instruction" and AMD's "CPUID Specification". In cases of disagreement
|
|
|
|
* about feature names, the Linux name is used. */
|
|
|
|
const char *feature_name[] = {
|
|
|
|
"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
|
|
|
|
"cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
|
|
|
|
"pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */, NULL, "ds" /* Intel dts */, "acpi", "mmx",
|
|
|
|
"fxsr", "sse", "sse2", "ss", "ht" /* Intel htt */, "tm", "ia64", "pbe",
|
|
|
|
};
|
|
|
|
const char *ext_feature_name[] = {
|
|
|
|
"pni" /* Intel,AMD sse3 */, NULL, NULL, "monitor", "ds_cpl", "vmx", NULL /* Linux smx */, "est",
|
|
|
|
"tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
|
|
|
|
NULL, NULL, "dca", NULL, NULL, NULL, NULL, "popcnt",
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
};
|
|
|
|
const char *ext2_feature_name[] = {
|
|
|
|
"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
|
|
|
|
"cx8" /* AMD CMPXCHG8B */, "apic", NULL, "syscall", "mttr", "pge", "mca", "cmov",
|
|
|
|
"pat", "pse36", NULL, NULL /* Linux mp */, "nx" /* Intel xd */, NULL, "mmxext", "mmx",
|
|
|
|
"fxsr", "fxsr_opt" /* AMD ffxsr */, "pdpe1gb" /* AMD Page1GB */, "rdtscp", NULL, "lm" /* Intel 64 */, "3dnowext", "3dnow",
|
|
|
|
};
|
|
|
|
const char *ext3_feature_name[] = {
|
|
|
|
"lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */, "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
|
|
|
|
"3dnowprefetch", "osvw", NULL /* Linux ibs */, NULL, "skinit", "wdt", NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 32 ; i++ )
|
|
|
|
if (feature_name[i] && !strcmp (flagname, feature_name[i])) {
|
|
|
|
*features |= 1 << i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( i = 0 ; i < 32 ; i++ )
|
|
|
|
if (ext_feature_name[i] && !strcmp (flagname, ext_feature_name[i])) {
|
|
|
|
*ext_features |= 1 << i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( i = 0 ; i < 32 ; i++ )
|
|
|
|
if (ext2_feature_name[i] && !strcmp (flagname, ext2_feature_name[i])) {
|
|
|
|
*ext2_features |= 1 << i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( i = 0 ; i < 32 ; i++ )
|
|
|
|
if (ext3_features[i] && !strcmp (flagname, ext3_feature_name[i])) {
|
|
|
|
*ext3_features |= 1 << i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "CPU feature %s not found\n", flagname);
|
|
|
|
}
|
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
CPUX86State *cpu_x86_init(const char *cpu_model)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
|
|
|
CPUX86State *env;
|
|
|
|
static int inited;
|
|
|
|
|
2005-11-22 02:32:20 +03:00
|
|
|
env = qemu_mallocz(sizeof(CPUX86State));
|
2003-10-01 00:34:21 +04:00
|
|
|
if (!env)
|
|
|
|
return NULL;
|
2005-11-22 02:32:20 +03:00
|
|
|
cpu_exec_init(env);
|
|
|
|
|
2004-06-20 17:01:25 +04:00
|
|
|
/* init various static tables */
|
|
|
|
if (!inited) {
|
|
|
|
inited = 1;
|
|
|
|
optimize_flags_init();
|
|
|
|
}
|
2007-11-10 18:15:54 +03:00
|
|
|
if (cpu_x86_register(env, cpu_model) < 0) {
|
|
|
|
cpu_x86_close(env);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-08 16:28:47 +03:00
|
|
|
cpu_reset(env);
|
|
|
|
#ifdef USE_KQEMU
|
|
|
|
kqemu_init(env);
|
2005-01-04 02:50:08 +03:00
|
|
|
#endif
|
2007-11-08 16:28:47 +03:00
|
|
|
return env;
|
|
|
|
}
|
2005-07-23 21:41:26 +04:00
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
typedef struct x86_def_t {
|
2007-11-08 16:28:47 +03:00
|
|
|
const char *name;
|
|
|
|
uint32_t vendor1, vendor2, vendor3;
|
|
|
|
int family;
|
|
|
|
int model;
|
|
|
|
int stepping;
|
|
|
|
uint32_t features, ext_features, ext2_features, ext3_features;
|
|
|
|
uint32_t xlevel;
|
2007-11-10 18:15:54 +03:00
|
|
|
} x86_def_t;
|
2007-11-08 16:28:47 +03:00
|
|
|
|
|
|
|
#define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
|
|
|
|
CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
|
|
|
|
CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
|
|
|
|
CPUID_PAE | CPUID_SEP | CPUID_APIC)
|
|
|
|
static x86_def_t x86_defs[] = {
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
{
|
|
|
|
.name = "qemu64",
|
|
|
|
.vendor1 = 0x68747541, /* "Auth" */
|
|
|
|
.vendor2 = 0x69746e65, /* "enti" */
|
|
|
|
.vendor3 = 0x444d4163, /* "cAMD" */
|
|
|
|
.family = 6,
|
|
|
|
.model = 2,
|
|
|
|
.stepping = 3,
|
|
|
|
.features = PPRO_FEATURES |
|
2005-07-23 21:41:26 +04:00
|
|
|
/* these features are needed for Win64 and aren't fully implemented */
|
2007-11-08 16:28:47 +03:00
|
|
|
CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
|
2006-09-27 23:52:41 +04:00
|
|
|
/* this feature is needed for Solaris and isn't fully implemented */
|
2007-11-08 16:28:47 +03:00
|
|
|
CPUID_PSE36,
|
|
|
|
.ext_features = CPUID_EXT_SSE3,
|
|
|
|
.ext2_features = (PPRO_FEATURES & 0x0183F3FF) |
|
|
|
|
CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
|
|
|
|
.ext3_features = CPUID_EXT3_SVM,
|
|
|
|
.xlevel = 0x80000008,
|
|
|
|
},
|
2005-01-04 02:50:08 +03:00
|
|
|
#endif
|
2007-11-08 16:28:47 +03:00
|
|
|
{
|
|
|
|
.name = "qemu32",
|
|
|
|
.family = 6,
|
|
|
|
.model = 3,
|
|
|
|
.stepping = 3,
|
|
|
|
.features = PPRO_FEATURES,
|
|
|
|
.ext_features = CPUID_EXT_SSE3,
|
|
|
|
.xlevel = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "486",
|
|
|
|
.family = 4,
|
|
|
|
.model = 0,
|
|
|
|
.stepping = 0,
|
|
|
|
.features = 0x0000000B,
|
|
|
|
.xlevel = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "pentium",
|
|
|
|
.family = 5,
|
|
|
|
.model = 4,
|
|
|
|
.stepping = 3,
|
|
|
|
.features = 0x008001BF,
|
|
|
|
.xlevel = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "pentium2",
|
|
|
|
.family = 6,
|
|
|
|
.model = 5,
|
|
|
|
.stepping = 2,
|
|
|
|
.features = 0x0183F9FF,
|
|
|
|
.xlevel = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "pentium3",
|
|
|
|
.family = 6,
|
|
|
|
.model = 7,
|
|
|
|
.stepping = 3,
|
|
|
|
.features = 0x0383F9FF,
|
|
|
|
.xlevel = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
|
2007-11-08 16:28:47 +03:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2007-11-10 18:15:54 +03:00
|
|
|
x86_def_t *def;
|
2007-11-08 16:28:47 +03:00
|
|
|
|
|
|
|
char *s = strdup(cpu_model);
|
|
|
|
char *featurestr, *name = strtok(s, ",");
|
|
|
|
uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0;
|
|
|
|
uint32_t minus_features = 0, minus_ext_features = 0, minus_ext2_features = 0, minus_ext3_features = 0;
|
|
|
|
int family = -1, model = -1, stepping = -1;
|
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
def = NULL;
|
2007-11-08 16:28:47 +03:00
|
|
|
for (i = 0; i < sizeof(x86_defs) / sizeof(x86_def_t); i++) {
|
|
|
|
if (strcmp(name, x86_defs[i].name) == 0) {
|
2007-11-10 18:15:54 +03:00
|
|
|
def = &x86_defs[i];
|
2007-11-08 16:28:47 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2007-11-10 18:15:54 +03:00
|
|
|
if (!def)
|
2007-11-08 16:28:47 +03:00
|
|
|
goto error;
|
2007-11-10 18:15:54 +03:00
|
|
|
memcpy(x86_cpu_def, def, sizeof(*def));
|
2007-11-08 16:28:47 +03:00
|
|
|
|
|
|
|
featurestr = strtok(NULL, ",");
|
|
|
|
|
|
|
|
while (featurestr) {
|
|
|
|
char *val;
|
|
|
|
if (featurestr[0] == '+') {
|
|
|
|
add_flagname_to_bitmaps(featurestr + 1, &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features);
|
|
|
|
} else if (featurestr[0] == '-') {
|
|
|
|
add_flagname_to_bitmaps(featurestr + 1, &minus_features, &minus_ext_features, &minus_ext2_features, &minus_ext3_features);
|
|
|
|
} else if ((val = strchr(featurestr, '='))) {
|
|
|
|
*val = 0; val++;
|
|
|
|
if (!strcmp(featurestr, "family")) {
|
|
|
|
char *err;
|
|
|
|
family = strtol(val, &err, 10);
|
|
|
|
if (!*val || *err || family < 0) {
|
|
|
|
fprintf(stderr, "bad numerical value %s\n", val);
|
|
|
|
x86_cpu_def = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
x86_cpu_def->family = family;
|
|
|
|
} else if (!strcmp(featurestr, "model")) {
|
|
|
|
char *err;
|
|
|
|
model = strtol(val, &err, 10);
|
|
|
|
if (!*val || *err || model < 0 || model > 0xf) {
|
|
|
|
fprintf(stderr, "bad numerical value %s\n", val);
|
|
|
|
x86_cpu_def = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
x86_cpu_def->model = model;
|
|
|
|
} else if (!strcmp(featurestr, "stepping")) {
|
|
|
|
char *err;
|
|
|
|
stepping = strtol(val, &err, 10);
|
|
|
|
if (!*val || *err || stepping < 0 || stepping > 0xf) {
|
|
|
|
fprintf(stderr, "bad numerical value %s\n", val);
|
|
|
|
x86_cpu_def = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
x86_cpu_def->stepping = stepping;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "unregnized feature %s\n", featurestr);
|
|
|
|
x86_cpu_def = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
|
|
|
|
x86_cpu_def = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
featurestr = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
x86_cpu_def->features |= plus_features;
|
|
|
|
x86_cpu_def->ext_features |= plus_ext_features;
|
|
|
|
x86_cpu_def->ext2_features |= plus_ext2_features;
|
|
|
|
x86_cpu_def->ext3_features |= plus_ext3_features;
|
|
|
|
x86_cpu_def->features &= ~minus_features;
|
|
|
|
x86_cpu_def->ext_features &= ~minus_ext_features;
|
|
|
|
x86_cpu_def->ext2_features &= ~minus_ext2_features;
|
|
|
|
x86_cpu_def->ext3_features &= ~minus_ext3_features;
|
2007-11-10 18:15:54 +03:00
|
|
|
free(s);
|
|
|
|
return 0;
|
2007-11-08 16:28:47 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
free(s);
|
2007-11-10 18:15:54 +03:00
|
|
|
return -1;
|
2007-11-08 16:28:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(x86_defs) / sizeof(x86_def_t); i++)
|
|
|
|
(*cpu_fprintf)(f, "x86 %16s\n", x86_defs[i].name);
|
|
|
|
}
|
|
|
|
|
2007-11-10 18:15:54 +03:00
|
|
|
static int cpu_x86_register (CPUX86State *env, const char *cpu_model)
|
2007-11-08 16:28:47 +03:00
|
|
|
{
|
2007-11-10 18:15:54 +03:00
|
|
|
x86_def_t def1, *def = &def1;
|
|
|
|
|
|
|
|
if (cpu_x86_find_by_name(def, cpu_model) < 0)
|
|
|
|
return -1;
|
2007-11-08 16:28:47 +03:00
|
|
|
if (def->vendor1) {
|
|
|
|
env->cpuid_vendor1 = def->vendor1;
|
|
|
|
env->cpuid_vendor2 = def->vendor2;
|
|
|
|
env->cpuid_vendor3 = def->vendor3;
|
|
|
|
} else {
|
|
|
|
env->cpuid_vendor1 = 0x756e6547; /* "Genu" */
|
|
|
|
env->cpuid_vendor2 = 0x49656e69; /* "ineI" */
|
|
|
|
env->cpuid_vendor3 = 0x6c65746e; /* "ntel" */
|
|
|
|
}
|
|
|
|
env->cpuid_level = 2;
|
|
|
|
env->cpuid_version = (def->family << 8) | (def->model << 4) | def->stepping;
|
|
|
|
env->cpuid_features = def->features;
|
|
|
|
env->pat = 0x0007040600070406ULL;
|
|
|
|
env->cpuid_ext_features = def->ext_features;
|
|
|
|
env->cpuid_ext2_features = def->ext2_features;
|
|
|
|
env->cpuid_xlevel = def->xlevel;
|
|
|
|
env->cpuid_ext3_features = def->ext3_features;
|
|
|
|
{
|
|
|
|
const char *model_id = "QEMU Virtual CPU version " QEMU_VERSION;
|
|
|
|
int c, len, i;
|
|
|
|
len = strlen(model_id);
|
|
|
|
for(i = 0; i < 48; i++) {
|
|
|
|
if (i >= len)
|
|
|
|
c = '\0';
|
|
|
|
else
|
|
|
|
c = model_id[i];
|
|
|
|
env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2004-06-20 17:01:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: must be called outside the CPU execute loop */
|
|
|
|
void cpu_reset(CPUX86State *env)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(env, 0, offsetof(CPUX86State, breakpoints));
|
2004-02-04 02:28:30 +03:00
|
|
|
|
|
|
|
tlb_flush(env, 1);
|
2004-06-20 17:01:25 +04:00
|
|
|
|
2007-08-01 03:09:18 +04:00
|
|
|
env->old_exception = -1;
|
|
|
|
|
2004-06-20 17:01:25 +04:00
|
|
|
/* init to reset state */
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
#ifdef CONFIG_SOFTMMU
|
|
|
|
env->hflags |= HF_SOFTMMU_MASK;
|
|
|
|
#endif
|
2007-09-23 19:28:04 +04:00
|
|
|
env->hflags |= HF_GIF_MASK;
|
2004-02-04 02:28:30 +03:00
|
|
|
|
|
|
|
cpu_x86_update_cr0(env, 0x60000010);
|
|
|
|
env->a20_mask = 0xffffffff;
|
2006-09-24 22:41:56 +04:00
|
|
|
env->smbase = 0x30000;
|
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
env->idt.limit = 0xffff;
|
|
|
|
env->gdt.limit = 0xffff;
|
|
|
|
env->ldt.limit = 0xffff;
|
|
|
|
env->ldt.flags = DESC_P_MASK;
|
|
|
|
env->tr.limit = 0xffff;
|
|
|
|
env->tr.flags = DESC_P_MASK;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
cpu_x86_load_seg_cache(env, R_CS, 0xf000, 0xffff0000, 0xffff, 0);
|
2005-01-04 02:50:08 +03:00
|
|
|
cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff, 0);
|
|
|
|
cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff, 0);
|
|
|
|
cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff, 0);
|
|
|
|
cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffff, 0);
|
|
|
|
cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffff, 0);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
env->eip = 0xfff0;
|
2007-11-08 16:28:47 +03:00
|
|
|
env->regs[R_EDX] = env->cpuid_version;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
env->eflags = 0x2;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
/* FPU init */
|
|
|
|
for(i = 0;i < 8; i++)
|
|
|
|
env->fptags[i] = 1;
|
|
|
|
env->fpuc = 0x37f;
|
2005-01-08 21:58:29 +03:00
|
|
|
|
|
|
|
env->mxcsr = 0x1f80;
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_x86_close(CPUX86State *env)
|
|
|
|
{
|
|
|
|
free(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* x86 debug */
|
|
|
|
|
|
|
|
static const char *cc_op_str[] = {
|
|
|
|
"DYNAMIC",
|
|
|
|
"EFLAGS",
|
2005-01-04 02:50:08 +03:00
|
|
|
|
2004-01-04 18:20:25 +03:00
|
|
|
"MULB",
|
|
|
|
"MULW",
|
|
|
|
"MULL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"MULQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"ADDB",
|
|
|
|
"ADDW",
|
|
|
|
"ADDL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"ADDQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"ADCB",
|
|
|
|
"ADCW",
|
|
|
|
"ADCL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"ADCQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"SUBB",
|
|
|
|
"SUBW",
|
|
|
|
"SUBL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"SUBQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"SBBB",
|
|
|
|
"SBBW",
|
|
|
|
"SBBL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"SBBQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"LOGICB",
|
|
|
|
"LOGICW",
|
|
|
|
"LOGICL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"LOGICQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"INCB",
|
|
|
|
"INCW",
|
|
|
|
"INCL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"INCQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"DECB",
|
|
|
|
"DECW",
|
|
|
|
"DECL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"DECQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"SHLB",
|
|
|
|
"SHLW",
|
|
|
|
"SHLL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"SHLQ",
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
"SARB",
|
|
|
|
"SARW",
|
|
|
|
"SARL",
|
2005-01-04 02:50:08 +03:00
|
|
|
"SARQ",
|
2003-10-01 00:34:21 +04:00
|
|
|
};
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
void cpu_dump_state(CPUState *env, FILE *f,
|
2004-10-09 22:08:01 +04:00
|
|
|
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
|
|
|
|
int flags)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
2005-07-04 01:29:17 +04:00
|
|
|
int eflags, i, nb;
|
2003-10-01 00:34:21 +04:00
|
|
|
char cc_op_name[32];
|
2003-11-13 02:55:40 +03:00
|
|
|
static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
|
2003-10-01 00:34:21 +04:00
|
|
|
|
|
|
|
eflags = env->eflags;
|
2005-01-04 02:50:08 +03:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_CS64_MASK) {
|
2007-09-17 01:08:06 +04:00
|
|
|
cpu_fprintf(f,
|
2006-06-25 22:15:32 +04:00
|
|
|
"RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" PRIx64 " RDX=%016" PRIx64 "\n"
|
|
|
|
"RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " RSP=%016" PRIx64 "\n"
|
|
|
|
"R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " R11=%016" PRIx64 "\n"
|
|
|
|
"R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " R15=%016" PRIx64 "\n"
|
2006-09-24 22:41:56 +04:00
|
|
|
"RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
env->regs[R_EAX],
|
|
|
|
env->regs[R_EBX],
|
|
|
|
env->regs[R_ECX],
|
|
|
|
env->regs[R_EDX],
|
|
|
|
env->regs[R_ESI],
|
|
|
|
env->regs[R_EDI],
|
|
|
|
env->regs[R_EBP],
|
|
|
|
env->regs[R_ESP],
|
|
|
|
env->regs[8],
|
|
|
|
env->regs[9],
|
|
|
|
env->regs[10],
|
|
|
|
env->regs[11],
|
|
|
|
env->regs[12],
|
|
|
|
env->regs[13],
|
|
|
|
env->regs[14],
|
|
|
|
env->regs[15],
|
2005-01-04 02:50:08 +03:00
|
|
|
env->eip, eflags,
|
|
|
|
eflags & DF_MASK ? 'D' : '-',
|
|
|
|
eflags & CC_O ? 'O' : '-',
|
|
|
|
eflags & CC_S ? 'S' : '-',
|
|
|
|
eflags & CC_Z ? 'Z' : '-',
|
|
|
|
eflags & CC_A ? 'A' : '-',
|
|
|
|
eflags & CC_P ? 'P' : '-',
|
|
|
|
eflags & CC_C ? 'C' : '-',
|
2007-09-17 01:08:06 +04:00
|
|
|
env->hflags & HF_CPL_MASK,
|
2005-01-04 02:50:08 +03:00
|
|
|
(env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
|
2005-11-24 00:02:10 +03:00
|
|
|
(env->a20_mask >> 20) & 1,
|
2006-09-24 22:41:56 +04:00
|
|
|
(env->hflags >> HF_SMM_SHIFT) & 1,
|
2005-11-24 00:02:10 +03:00
|
|
|
(env->hflags >> HF_HALTED_SHIFT) & 1);
|
2007-09-17 01:08:06 +04:00
|
|
|
} else
|
2005-01-04 02:50:08 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
cpu_fprintf(f, "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
|
|
|
|
"ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
|
2006-09-24 22:41:56 +04:00
|
|
|
"EIP=%08x EFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
(uint32_t)env->regs[R_EAX],
|
|
|
|
(uint32_t)env->regs[R_EBX],
|
|
|
|
(uint32_t)env->regs[R_ECX],
|
|
|
|
(uint32_t)env->regs[R_EDX],
|
|
|
|
(uint32_t)env->regs[R_ESI],
|
|
|
|
(uint32_t)env->regs[R_EDI],
|
|
|
|
(uint32_t)env->regs[R_EBP],
|
|
|
|
(uint32_t)env->regs[R_ESP],
|
2005-01-04 02:50:08 +03:00
|
|
|
(uint32_t)env->eip, eflags,
|
|
|
|
eflags & DF_MASK ? 'D' : '-',
|
|
|
|
eflags & CC_O ? 'O' : '-',
|
|
|
|
eflags & CC_S ? 'S' : '-',
|
|
|
|
eflags & CC_Z ? 'Z' : '-',
|
|
|
|
eflags & CC_A ? 'A' : '-',
|
|
|
|
eflags & CC_P ? 'P' : '-',
|
|
|
|
eflags & CC_C ? 'C' : '-',
|
2007-09-17 01:08:06 +04:00
|
|
|
env->hflags & HF_CPL_MASK,
|
2005-01-04 02:50:08 +03:00
|
|
|
(env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
|
2005-11-24 00:02:10 +03:00
|
|
|
(env->a20_mask >> 20) & 1,
|
2006-09-24 22:41:56 +04:00
|
|
|
(env->hflags >> HF_SMM_SHIFT) & 1,
|
2005-11-24 00:02:10 +03:00
|
|
|
(env->hflags >> HF_HALTED_SHIFT) & 1);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_LMA_MASK) {
|
|
|
|
for(i = 0; i < 6; i++) {
|
|
|
|
SegmentCache *sc = &env->segs[i];
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "%s =%04x %016" PRIx64 " %08x %08x\n",
|
2005-01-04 02:50:08 +03:00
|
|
|
seg_name[i],
|
|
|
|
sc->selector,
|
|
|
|
sc->base,
|
|
|
|
sc->limit,
|
|
|
|
sc->flags);
|
|
|
|
}
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "LDT=%04x %016" PRIx64 " %08x %08x\n",
|
2005-01-04 02:50:08 +03:00
|
|
|
env->ldt.selector,
|
|
|
|
env->ldt.base,
|
|
|
|
env->ldt.limit,
|
|
|
|
env->ldt.flags);
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "TR =%04x %016" PRIx64 " %08x %08x\n",
|
2005-01-04 02:50:08 +03:00
|
|
|
env->tr.selector,
|
|
|
|
env->tr.base,
|
|
|
|
env->tr.limit,
|
|
|
|
env->tr.flags);
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "GDT= %016" PRIx64 " %08x\n",
|
2005-01-04 02:50:08 +03:00
|
|
|
env->gdt.base, env->gdt.limit);
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "IDT= %016" PRIx64 " %08x\n",
|
2005-01-04 02:50:08 +03:00
|
|
|
env->idt.base, env->idt.limit);
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " CR4=%08x\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
(uint32_t)env->cr[0],
|
|
|
|
env->cr[2],
|
|
|
|
env->cr[3],
|
2005-01-04 02:50:08 +03:00
|
|
|
(uint32_t)env->cr[4]);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
for(i = 0; i < 6; i++) {
|
|
|
|
SegmentCache *sc = &env->segs[i];
|
|
|
|
cpu_fprintf(f, "%s =%04x %08x %08x %08x\n",
|
|
|
|
seg_name[i],
|
|
|
|
sc->selector,
|
|
|
|
(uint32_t)sc->base,
|
|
|
|
sc->limit,
|
|
|
|
sc->flags);
|
|
|
|
}
|
|
|
|
cpu_fprintf(f, "LDT=%04x %08x %08x %08x\n",
|
|
|
|
env->ldt.selector,
|
|
|
|
(uint32_t)env->ldt.base,
|
|
|
|
env->ldt.limit,
|
|
|
|
env->ldt.flags);
|
|
|
|
cpu_fprintf(f, "TR =%04x %08x %08x %08x\n",
|
|
|
|
env->tr.selector,
|
|
|
|
(uint32_t)env->tr.base,
|
|
|
|
env->tr.limit,
|
|
|
|
env->tr.flags);
|
|
|
|
cpu_fprintf(f, "GDT= %08x %08x\n",
|
|
|
|
(uint32_t)env->gdt.base, env->gdt.limit);
|
|
|
|
cpu_fprintf(f, "IDT= %08x %08x\n",
|
|
|
|
(uint32_t)env->idt.base, env->idt.limit);
|
|
|
|
cpu_fprintf(f, "CR0=%08x CR2=%08x CR3=%08x CR4=%08x\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
(uint32_t)env->cr[0],
|
|
|
|
(uint32_t)env->cr[2],
|
|
|
|
(uint32_t)env->cr[3],
|
2005-01-04 02:50:08 +03:00
|
|
|
(uint32_t)env->cr[4]);
|
2003-11-13 02:55:40 +03:00
|
|
|
}
|
2003-10-01 00:34:21 +04:00
|
|
|
if (flags & X86_DUMP_CCOP) {
|
|
|
|
if ((unsigned)env->cc_op < CC_OP_NB)
|
2004-06-19 21:23:39 +04:00
|
|
|
snprintf(cc_op_name, sizeof(cc_op_name), "%s", cc_op_str[env->cc_op]);
|
2003-10-01 00:34:21 +04:00
|
|
|
else
|
|
|
|
snprintf(cc_op_name, sizeof(cc_op_name), "[%d]", env->cc_op);
|
2005-01-04 02:50:08 +03:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_CS64_MASK) {
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "CCS=%016" PRIx64 " CCD=%016" PRIx64 " CCO=%-8s\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
env->cc_src, env->cc_dst,
|
2005-01-04 02:50:08 +03:00
|
|
|
cc_op_name);
|
2007-09-17 01:08:06 +04:00
|
|
|
} else
|
2005-01-04 02:50:08 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
cpu_fprintf(f, "CCS=%08x CCD=%08x CCO=%-8s\n",
|
2007-09-17 01:08:06 +04:00
|
|
|
(uint32_t)env->cc_src, (uint32_t)env->cc_dst,
|
2005-01-04 02:50:08 +03:00
|
|
|
cc_op_name);
|
|
|
|
}
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
if (flags & X86_DUMP_FPU) {
|
2005-07-04 01:29:17 +04:00
|
|
|
int fptag;
|
|
|
|
fptag = 0;
|
|
|
|
for(i = 0; i < 8; i++) {
|
|
|
|
fptag |= ((!env->fptags[i]) << i);
|
|
|
|
}
|
|
|
|
cpu_fprintf(f, "FCW=%04x FSW=%04x [ST=%d] FTW=%02x MXCSR=%08x\n",
|
|
|
|
env->fpuc,
|
|
|
|
(env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11,
|
|
|
|
env->fpstt,
|
|
|
|
fptag,
|
|
|
|
env->mxcsr);
|
|
|
|
for(i=0;i<8;i++) {
|
|
|
|
#if defined(USE_X86LDOUBLE)
|
|
|
|
union {
|
|
|
|
long double d;
|
|
|
|
struct {
|
|
|
|
uint64_t lower;
|
|
|
|
uint16_t upper;
|
|
|
|
} l;
|
|
|
|
} tmp;
|
|
|
|
tmp.d = env->fpregs[i].d;
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "FPR%d=%016" PRIx64 " %04x",
|
2005-07-04 01:29:17 +04:00
|
|
|
i, tmp.l.lower, tmp.l.upper);
|
|
|
|
#else
|
2006-06-25 22:15:32 +04:00
|
|
|
cpu_fprintf(f, "FPR%d=%016" PRIx64,
|
2005-07-04 01:29:17 +04:00
|
|
|
i, env->fpregs[i].mmx.q);
|
|
|
|
#endif
|
|
|
|
if ((i & 1) == 1)
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
else
|
|
|
|
cpu_fprintf(f, " ");
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
if (env->hflags & HF_CS64_MASK)
|
2005-07-04 01:29:17 +04:00
|
|
|
nb = 16;
|
|
|
|
else
|
|
|
|
nb = 8;
|
|
|
|
for(i=0;i<nb;i++) {
|
|
|
|
cpu_fprintf(f, "XMM%02d=%08x%08x%08x%08x",
|
2007-09-17 01:08:06 +04:00
|
|
|
i,
|
2005-07-04 01:29:17 +04:00
|
|
|
env->xmm_regs[i].XMM_L(3),
|
|
|
|
env->xmm_regs[i].XMM_L(2),
|
|
|
|
env->xmm_regs[i].XMM_L(1),
|
|
|
|
env->xmm_regs[i].XMM_L(0));
|
|
|
|
if ((i & 1) == 1)
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
else
|
|
|
|
cpu_fprintf(f, " ");
|
|
|
|
}
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* x86 mmu */
|
|
|
|
/* XXX: add PGE support */
|
|
|
|
|
2003-11-05 02:34:23 +03:00
|
|
|
void cpu_x86_set_a20(CPUX86State *env, int a20_state)
|
|
|
|
{
|
|
|
|
a20_state = (a20_state != 0);
|
2004-02-04 02:28:30 +03:00
|
|
|
if (a20_state != ((env->a20_mask >> 20) & 1)) {
|
2004-01-04 18:20:25 +03:00
|
|
|
#if defined(DEBUG_MMU)
|
|
|
|
printf("A20 update: a20=%d\n", a20_state);
|
|
|
|
#endif
|
2003-11-24 02:26:39 +03:00
|
|
|
/* if the cpu is currently executing code, we must unlink it and
|
|
|
|
all the potentially executing TB */
|
2004-02-17 01:08:32 +03:00
|
|
|
cpu_interrupt(env, CPU_INTERRUPT_EXITTB);
|
2003-11-24 02:26:39 +03:00
|
|
|
|
2003-11-05 02:34:23 +03:00
|
|
|
/* when a20 is changed, all the MMU mappings are invalid, so
|
|
|
|
we must flush everything */
|
2004-02-04 02:28:30 +03:00
|
|
|
tlb_flush(env, 1);
|
|
|
|
env->a20_mask = 0xffefffff | (a20_state << 20);
|
2003-11-05 02:34:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
2004-02-04 02:28:30 +03:00
|
|
|
int pe_state;
|
2003-10-01 00:34:21 +04:00
|
|
|
|
2004-01-04 18:20:25 +03:00
|
|
|
#if defined(DEBUG_MMU)
|
2004-02-04 02:28:30 +03:00
|
|
|
printf("CR0 update: CR0=0x%08x\n", new_cr0);
|
2003-10-01 00:34:21 +04:00
|
|
|
#endif
|
2004-02-04 02:28:30 +03:00
|
|
|
if ((new_cr0 & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK)) !=
|
|
|
|
(env->cr[0] & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK))) {
|
|
|
|
tlb_flush(env, 1);
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (!(env->cr[0] & CR0_PG_MASK) && (new_cr0 & CR0_PG_MASK) &&
|
|
|
|
(env->efer & MSR_EFER_LME)) {
|
|
|
|
/* enter in long mode */
|
|
|
|
/* XXX: generate an exception */
|
|
|
|
if (!(env->cr[4] & CR4_PAE_MASK))
|
|
|
|
return;
|
|
|
|
env->efer |= MSR_EFER_LMA;
|
|
|
|
env->hflags |= HF_LMA_MASK;
|
|
|
|
} else if ((env->cr[0] & CR0_PG_MASK) && !(new_cr0 & CR0_PG_MASK) &&
|
|
|
|
(env->efer & MSR_EFER_LMA)) {
|
|
|
|
/* exit long mode */
|
|
|
|
env->efer &= ~MSR_EFER_LMA;
|
|
|
|
env->hflags &= ~(HF_LMA_MASK | HF_CS64_MASK);
|
|
|
|
env->eip &= 0xffffffff;
|
|
|
|
}
|
|
|
|
#endif
|
2004-05-09 01:05:19 +04:00
|
|
|
env->cr[0] = new_cr0 | CR0_ET_MASK;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-01-04 20:26:31 +03:00
|
|
|
/* update PE flag in hidden flags */
|
|
|
|
pe_state = (env->cr[0] & CR0_PE_MASK);
|
|
|
|
env->hflags = (env->hflags & ~HF_PE_MASK) | (pe_state << HF_PE_SHIFT);
|
|
|
|
/* ensure that ADDSEG is always set in real mode */
|
|
|
|
env->hflags |= ((pe_state ^ 1) << HF_ADDSEG_SHIFT);
|
2004-02-26 02:15:55 +03:00
|
|
|
/* update FPU flags */
|
|
|
|
env->hflags = (env->hflags & ~(HF_MP_MASK | HF_EM_MASK | HF_TS_MASK)) |
|
|
|
|
((new_cr0 << (HF_MP_SHIFT - 1)) & (HF_MP_MASK | HF_EM_MASK | HF_TS_MASK));
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
|
2005-02-11 01:06:29 +03:00
|
|
|
/* XXX: in legacy PAE mode, generate a GPF if reserved bits are set in
|
|
|
|
the PDPT */
|
2005-01-04 02:50:08 +03:00
|
|
|
void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
2004-02-04 02:28:30 +03:00
|
|
|
env->cr[3] = new_cr3;
|
2003-10-01 00:34:21 +04:00
|
|
|
if (env->cr[0] & CR0_PG_MASK) {
|
|
|
|
#if defined(DEBUG_MMU)
|
2005-01-04 02:50:08 +03:00
|
|
|
printf("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3);
|
2003-10-01 00:34:21 +04:00
|
|
|
#endif
|
2004-02-04 02:28:30 +03:00
|
|
|
tlb_flush(env, 0);
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
2004-02-04 02:28:30 +03:00
|
|
|
#if defined(DEBUG_MMU)
|
2005-01-04 02:50:08 +03:00
|
|
|
printf("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]);
|
2004-02-04 02:28:30 +03:00
|
|
|
#endif
|
|
|
|
if ((new_cr4 & (CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK)) !=
|
|
|
|
(env->cr[4] & (CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK))) {
|
|
|
|
tlb_flush(env, 1);
|
|
|
|
}
|
2005-01-08 21:58:29 +03:00
|
|
|
/* SSE handling */
|
|
|
|
if (!(env->cpuid_features & CPUID_SSE))
|
|
|
|
new_cr4 &= ~CR4_OSFXSR_MASK;
|
|
|
|
if (new_cr4 & CR4_OSFXSR_MASK)
|
|
|
|
env->hflags |= HF_OSFXSR_MASK;
|
|
|
|
else
|
|
|
|
env->hflags &= ~HF_OSFXSR_MASK;
|
|
|
|
|
2004-02-04 02:28:30 +03:00
|
|
|
env->cr[4] = new_cr4;
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: also flush 4MB pages */
|
2005-07-23 21:41:26 +04:00
|
|
|
void cpu_x86_flush_tlb(CPUX86State *env, target_ulong addr)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
|
|
|
tlb_flush_page(env, addr);
|
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
2005-01-04 02:50:08 +03:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
|
2007-10-14 11:07:08 +04:00
|
|
|
int is_write, int mmu_idx, int is_softmmu)
|
2005-01-04 02:50:08 +03:00
|
|
|
{
|
2005-01-29 01:37:22 +03:00
|
|
|
/* user mode only emulation */
|
|
|
|
is_write &= 1;
|
|
|
|
env->cr[2] = addr;
|
|
|
|
env->error_code = (is_write << PG_ERROR_W_BIT);
|
|
|
|
env->error_code |= PG_ERROR_U_MASK;
|
2005-12-04 21:46:06 +03:00
|
|
|
env->exception_index = EXCP0E_PAGE;
|
2005-01-29 01:37:22 +03:00
|
|
|
return 1;
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
|
|
|
|
2007-04-07 15:21:28 +04:00
|
|
|
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
|
2005-01-04 02:50:08 +03:00
|
|
|
{
|
2005-01-29 01:37:22 +03:00
|
|
|
return addr;
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
|
|
|
|
2005-01-29 01:37:22 +03:00
|
|
|
#else
|
|
|
|
|
2005-11-29 00:19:42 +03:00
|
|
|
#define PHYS_ADDR_MASK 0xfffff000
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
/* return value:
|
2007-09-17 01:08:06 +04:00
|
|
|
-1 = cannot handle fault
|
|
|
|
0 = nothing more to do
|
2003-10-01 00:34:21 +04:00
|
|
|
1 = generate PF fault
|
|
|
|
2 = soft MMU activation required for this block
|
|
|
|
*/
|
2007-09-17 01:08:06 +04:00
|
|
|
int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
|
2007-10-14 11:07:08 +04:00
|
|
|
int is_write1, int mmu_idx, int is_softmmu)
|
2003-10-01 00:34:21 +04:00
|
|
|
{
|
2005-11-29 00:19:42 +03:00
|
|
|
uint64_t ptep, pte;
|
2005-01-04 02:50:08 +03:00
|
|
|
uint32_t pdpe_addr, pde_addr, pte_addr;
|
2007-10-14 11:07:08 +04:00
|
|
|
int error_code, is_dirty, prot, page_size, ret, is_write, is_user;
|
2005-01-04 02:50:08 +03:00
|
|
|
unsigned long paddr, page_offset;
|
|
|
|
target_ulong vaddr, virt_addr;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-10-14 11:07:08 +04:00
|
|
|
is_user = mmu_idx == MMU_USER_IDX;
|
2004-01-04 20:26:31 +03:00
|
|
|
#if defined(DEBUG_MMU)
|
2007-09-17 01:08:06 +04:00
|
|
|
printf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n",
|
2005-11-29 00:19:42 +03:00
|
|
|
addr, is_write1, is_user, env->eip);
|
2003-10-01 00:34:21 +04:00
|
|
|
#endif
|
2005-11-29 00:19:42 +03:00
|
|
|
is_write = is_write1 & 1;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
if (!(env->cr[0] & CR0_PG_MASK)) {
|
|
|
|
pte = addr;
|
2003-11-05 02:34:23 +03:00
|
|
|
virt_addr = addr & TARGET_PAGE_MASK;
|
2005-11-29 00:19:42 +03:00
|
|
|
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
2003-10-01 00:34:21 +04:00
|
|
|
page_size = 4096;
|
|
|
|
goto do_mapping;
|
|
|
|
}
|
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
if (env->cr[4] & CR4_PAE_MASK) {
|
2005-11-29 00:19:42 +03:00
|
|
|
uint64_t pde, pdpe;
|
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
/* XXX: we only use 32 bit physical addresses */
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_LMA_MASK) {
|
2005-11-29 00:19:42 +03:00
|
|
|
uint32_t pml4e_addr;
|
|
|
|
uint64_t pml4e;
|
2005-01-04 02:50:08 +03:00
|
|
|
int32_t sext;
|
|
|
|
|
|
|
|
/* test virtual address sign extension */
|
|
|
|
sext = (int64_t)addr >> 47;
|
|
|
|
if (sext != 0 && sext != -1) {
|
2005-12-04 21:46:06 +03:00
|
|
|
env->error_code = 0;
|
|
|
|
env->exception_index = EXCP0D_GPF;
|
|
|
|
return 1;
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-11-29 00:19:42 +03:00
|
|
|
pml4e = ldq_phys(pml4e_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pml4e & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
if (!(env->efer & MSR_EFER_NXE) && (pml4e & PG_NX_MASK)) {
|
|
|
|
error_code = PG_ERROR_RSVD_MASK;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pml4e & PG_ACCESSED_MASK)) {
|
|
|
|
pml4e |= PG_ACCESSED_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pml4e_addr, pml4e);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
ptep = pml4e ^ PG_NX_MASK;
|
2007-09-17 01:08:06 +04:00
|
|
|
pdpe_addr = ((pml4e & PHYS_ADDR_MASK) + (((addr >> 30) & 0x1ff) << 3)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-11-29 00:19:42 +03:00
|
|
|
pdpe = ldq_phys(pdpe_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
if (!(env->efer & MSR_EFER_NXE) && (pdpe & PG_NX_MASK)) {
|
|
|
|
error_code = PG_ERROR_RSVD_MASK;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
|
|
|
ptep &= pdpe ^ PG_NX_MASK;
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pdpe & PG_ACCESSED_MASK)) {
|
|
|
|
pdpe |= PG_ACCESSED_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pdpe_addr, pdpe);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
} else
|
2005-01-04 02:50:08 +03:00
|
|
|
#endif
|
|
|
|
{
|
2005-11-29 00:19:42 +03:00
|
|
|
/* XXX: load them when cr3 is loaded ? */
|
2007-09-17 01:08:06 +04:00
|
|
|
pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-11-29 00:19:42 +03:00
|
|
|
pdpe = ldq_phys(pdpe_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
ptep = PG_NX_MASK | PG_USER_MASK | PG_RW_MASK;
|
2004-01-24 18:29:03 +03:00
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
|
2005-11-29 00:19:42 +03:00
|
|
|
pde_addr = ((pdpe & PHYS_ADDR_MASK) + (((addr >> 21) & 0x1ff) << 3)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-11-29 00:19:42 +03:00
|
|
|
pde = ldq_phys(pde_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pde & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
if (!(env->efer & MSR_EFER_NXE) && (pde & PG_NX_MASK)) {
|
|
|
|
error_code = PG_ERROR_RSVD_MASK;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
|
|
|
ptep &= pde ^ PG_NX_MASK;
|
2005-01-04 02:50:08 +03:00
|
|
|
if (pde & PG_PSE_MASK) {
|
|
|
|
/* 2 MB page */
|
|
|
|
page_size = 2048 * 1024;
|
2005-11-29 00:19:42 +03:00
|
|
|
ptep ^= PG_NX_MASK;
|
|
|
|
if ((ptep & PG_NX_MASK) && is_write1 == 2)
|
|
|
|
goto do_fault_protect;
|
|
|
|
if (is_user) {
|
|
|
|
if (!(ptep & PG_USER_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
if (is_write && !(ptep & PG_RW_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
} else {
|
2007-09-17 01:08:06 +04:00
|
|
|
if ((env->cr[0] & CR0_WP_MASK) &&
|
|
|
|
is_write && !(ptep & PG_RW_MASK))
|
2005-11-29 00:19:42 +03:00
|
|
|
goto do_fault_protect;
|
|
|
|
}
|
|
|
|
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
|
|
|
|
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
|
|
|
|
pde |= PG_ACCESSED_MASK;
|
|
|
|
if (is_dirty)
|
|
|
|
pde |= PG_DIRTY_MASK;
|
|
|
|
stl_phys_notdirty(pde_addr, pde);
|
|
|
|
}
|
|
|
|
/* align to page_size */
|
2007-09-17 01:08:06 +04:00
|
|
|
pte = pde & ((PHYS_ADDR_MASK & ~(page_size - 1)) | 0xfff);
|
2005-11-29 00:19:42 +03:00
|
|
|
virt_addr = addr & ~(page_size - 1);
|
2005-01-04 02:50:08 +03:00
|
|
|
} else {
|
|
|
|
/* 4 KB page */
|
|
|
|
if (!(pde & PG_ACCESSED_MASK)) {
|
|
|
|
pde |= PG_ACCESSED_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pde_addr, pde);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
pte_addr = ((pde & PHYS_ADDR_MASK) + (((addr >> 12) & 0x1ff) << 3)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-11-29 00:19:42 +03:00
|
|
|
pte = ldq_phys(pte_addr);
|
|
|
|
if (!(pte & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
|
|
|
if (!(env->efer & MSR_EFER_NXE) && (pte & PG_NX_MASK)) {
|
|
|
|
error_code = PG_ERROR_RSVD_MASK;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
|
|
|
/* combine pde and pte nx, user and rw protections */
|
|
|
|
ptep &= pte ^ PG_NX_MASK;
|
|
|
|
ptep ^= PG_NX_MASK;
|
|
|
|
if ((ptep & PG_NX_MASK) && is_write1 == 2)
|
2007-09-17 01:08:06 +04:00
|
|
|
goto do_fault_protect;
|
2005-11-29 00:19:42 +03:00
|
|
|
if (is_user) {
|
|
|
|
if (!(ptep & PG_USER_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
if (is_write && !(ptep & PG_RW_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
} else {
|
|
|
|
if ((env->cr[0] & CR0_WP_MASK) &&
|
2007-09-17 01:08:06 +04:00
|
|
|
is_write && !(ptep & PG_RW_MASK))
|
2005-11-29 00:19:42 +03:00
|
|
|
goto do_fault_protect;
|
|
|
|
}
|
|
|
|
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
|
|
|
|
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
|
|
|
|
pte |= PG_ACCESSED_MASK;
|
|
|
|
if (is_dirty)
|
|
|
|
pte |= PG_DIRTY_MASK;
|
|
|
|
stl_phys_notdirty(pte_addr, pte);
|
|
|
|
}
|
|
|
|
page_size = 4096;
|
|
|
|
virt_addr = addr & ~0xfff;
|
|
|
|
pte = pte & (PHYS_ADDR_MASK | 0xfff);
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
} else {
|
2005-11-29 00:19:42 +03:00
|
|
|
uint32_t pde;
|
|
|
|
|
2003-10-01 00:34:21 +04:00
|
|
|
/* page directory entry */
|
2007-09-17 01:08:06 +04:00
|
|
|
pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pde = ldl_phys(pde_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pde & PG_PRESENT_MASK)) {
|
2003-10-01 00:34:21 +04:00
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
2005-01-04 02:50:08 +03:00
|
|
|
/* if PSE bit is set, then we use a 4MB page */
|
|
|
|
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
|
|
|
|
page_size = 4096 * 1024;
|
|
|
|
if (is_user) {
|
|
|
|
if (!(pde & PG_USER_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
if (is_write && !(pde & PG_RW_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
} else {
|
2007-09-17 01:08:06 +04:00
|
|
|
if ((env->cr[0] & CR0_WP_MASK) &&
|
|
|
|
is_write && !(pde & PG_RW_MASK))
|
2005-01-04 02:50:08 +03:00
|
|
|
goto do_fault_protect;
|
|
|
|
}
|
|
|
|
is_dirty = is_write && !(pde & PG_DIRTY_MASK);
|
|
|
|
if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
|
|
|
|
pde |= PG_ACCESSED_MASK;
|
|
|
|
if (is_dirty)
|
|
|
|
pde |= PG_DIRTY_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pde_addr, pde);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2005-01-04 02:50:08 +03:00
|
|
|
pte = pde & ~( (page_size - 1) & ~0xfff); /* align to page_size */
|
|
|
|
ptep = pte;
|
|
|
|
virt_addr = addr & ~(page_size - 1);
|
2003-10-01 00:34:21 +04:00
|
|
|
} else {
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pde & PG_ACCESSED_MASK)) {
|
|
|
|
pde |= PG_ACCESSED_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pde_addr, pde);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* page directory entry */
|
2007-09-17 01:08:06 +04:00
|
|
|
pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
|
2005-01-04 02:50:08 +03:00
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pte = ldl_phys(pte_addr);
|
2005-01-04 02:50:08 +03:00
|
|
|
if (!(pte & PG_PRESENT_MASK)) {
|
|
|
|
error_code = 0;
|
|
|
|
goto do_fault;
|
|
|
|
}
|
|
|
|
/* combine pde and pte user and rw protections */
|
|
|
|
ptep = pte & pde;
|
|
|
|
if (is_user) {
|
|
|
|
if (!(ptep & PG_USER_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
if (is_write && !(ptep & PG_RW_MASK))
|
|
|
|
goto do_fault_protect;
|
|
|
|
} else {
|
|
|
|
if ((env->cr[0] & CR0_WP_MASK) &&
|
2007-09-17 01:08:06 +04:00
|
|
|
is_write && !(ptep & PG_RW_MASK))
|
2005-01-04 02:50:08 +03:00
|
|
|
goto do_fault_protect;
|
|
|
|
}
|
|
|
|
is_dirty = is_write && !(pte & PG_DIRTY_MASK);
|
|
|
|
if (!(pte & PG_ACCESSED_MASK) || is_dirty) {
|
|
|
|
pte |= PG_ACCESSED_MASK;
|
|
|
|
if (is_dirty)
|
|
|
|
pte |= PG_DIRTY_MASK;
|
2005-01-29 01:37:22 +03:00
|
|
|
stl_phys_notdirty(pte_addr, pte);
|
2005-01-04 02:50:08 +03:00
|
|
|
}
|
|
|
|
page_size = 4096;
|
|
|
|
virt_addr = addr & ~0xfff;
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
}
|
|
|
|
/* the page can be put in the TLB */
|
|
|
|
prot = PAGE_READ;
|
|
|
|
if (!(ptep & PG_NX_MASK))
|
|
|
|
prot |= PAGE_EXEC;
|
|
|
|
if (pte & PG_DIRTY_MASK) {
|
|
|
|
/* only set write access if already dirty... otherwise wait
|
|
|
|
for dirty access */
|
|
|
|
if (is_user) {
|
|
|
|
if (ptep & PG_RW_MASK)
|
|
|
|
prot |= PAGE_WRITE;
|
|
|
|
} else {
|
|
|
|
if (!(env->cr[0] & CR0_WP_MASK) ||
|
|
|
|
(ptep & PG_RW_MASK))
|
|
|
|
prot |= PAGE_WRITE;
|
2004-01-13 03:00:25 +03:00
|
|
|
}
|
2003-10-01 00:34:21 +04:00
|
|
|
}
|
|
|
|
do_mapping:
|
2004-02-04 02:28:30 +03:00
|
|
|
pte = pte & env->a20_mask;
|
2003-10-01 00:34:21 +04:00
|
|
|
|
2004-01-04 20:26:31 +03:00
|
|
|
/* Even if 4MB pages, we map only one 4KB page in the cache to
|
|
|
|
avoid filling it too fast */
|
|
|
|
page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
|
|
|
|
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
|
|
|
|
vaddr = virt_addr + page_offset;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-10-14 11:07:08 +04:00
|
|
|
ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
|
2003-10-01 00:34:21 +04:00
|
|
|
return ret;
|
|
|
|
do_fault_protect:
|
|
|
|
error_code = PG_ERROR_P_MASK;
|
|
|
|
do_fault:
|
2005-11-29 00:19:42 +03:00
|
|
|
error_code |= (is_write << PG_ERROR_W_BIT);
|
2003-10-01 00:34:21 +04:00
|
|
|
if (is_user)
|
2005-11-29 00:19:42 +03:00
|
|
|
error_code |= PG_ERROR_U_MASK;
|
2007-09-17 01:08:06 +04:00
|
|
|
if (is_write1 == 2 &&
|
|
|
|
(env->efer & MSR_EFER_NXE) &&
|
2005-11-29 00:19:42 +03:00
|
|
|
(env->cr[4] & CR4_PAE_MASK))
|
|
|
|
error_code |= PG_ERROR_I_D_MASK;
|
2007-09-23 19:28:04 +04:00
|
|
|
if (INTERCEPTEDl(_exceptions, 1 << EXCP0E_PAGE)) {
|
|
|
|
stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2), addr);
|
|
|
|
} else {
|
|
|
|
env->cr[2] = addr;
|
|
|
|
}
|
2005-11-29 00:19:42 +03:00
|
|
|
env->error_code = error_code;
|
2005-12-04 21:46:06 +03:00
|
|
|
env->exception_index = EXCP0E_PAGE;
|
2007-09-23 19:28:04 +04:00
|
|
|
/* the VMM will handle this */
|
|
|
|
if (INTERCEPTEDl(_exceptions, 1 << EXCP0E_PAGE))
|
|
|
|
return 2;
|
2003-10-01 00:34:21 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2004-01-24 18:29:03 +03:00
|
|
|
|
2007-04-07 15:21:28 +04:00
|
|
|
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
|
2004-01-24 18:29:03 +03:00
|
|
|
{
|
2005-01-26 01:35:05 +03:00
|
|
|
uint32_t pde_addr, pte_addr;
|
2004-01-24 18:29:03 +03:00
|
|
|
uint32_t pde, pte, paddr, page_offset, page_size;
|
|
|
|
|
2005-01-26 01:35:05 +03:00
|
|
|
if (env->cr[4] & CR4_PAE_MASK) {
|
|
|
|
uint32_t pdpe_addr, pde_addr, pte_addr;
|
|
|
|
uint32_t pdpe;
|
|
|
|
|
|
|
|
/* XXX: we only use 32 bit physical addresses */
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_LMA_MASK) {
|
|
|
|
uint32_t pml4e_addr, pml4e;
|
|
|
|
int32_t sext;
|
|
|
|
|
|
|
|
/* test virtual address sign extension */
|
|
|
|
sext = (int64_t)addr >> 47;
|
|
|
|
if (sext != 0 && sext != -1)
|
|
|
|
return -1;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
|
2005-01-26 01:35:05 +03:00
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pml4e = ldl_phys(pml4e_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
if (!(pml4e & PG_PRESENT_MASK))
|
|
|
|
return -1;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
pdpe_addr = ((pml4e & ~0xfff) + (((addr >> 30) & 0x1ff) << 3)) &
|
2005-01-26 01:35:05 +03:00
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pdpe = ldl_phys(pdpe_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK))
|
|
|
|
return -1;
|
2007-09-17 01:08:06 +04:00
|
|
|
} else
|
2005-01-26 01:35:05 +03:00
|
|
|
#endif
|
|
|
|
{
|
2007-09-17 01:08:06 +04:00
|
|
|
pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
|
2005-01-26 01:35:05 +03:00
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pdpe = ldl_phys(pdpe_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pde_addr = ((pdpe & ~0xfff) + (((addr >> 21) & 0x1ff) << 3)) &
|
|
|
|
env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pde = ldl_phys(pde_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
if (!(pde & PG_PRESENT_MASK)) {
|
2004-01-24 18:29:03 +03:00
|
|
|
return -1;
|
2005-01-26 01:35:05 +03:00
|
|
|
}
|
|
|
|
if (pde & PG_PSE_MASK) {
|
|
|
|
/* 2 MB page */
|
|
|
|
page_size = 2048 * 1024;
|
|
|
|
pte = pde & ~( (page_size - 1) & ~0xfff); /* align to page_size */
|
|
|
|
} else {
|
|
|
|
/* 4 KB page */
|
|
|
|
pte_addr = ((pde & ~0xfff) + (((addr >> 12) & 0x1ff) << 3)) &
|
|
|
|
env->a20_mask;
|
|
|
|
page_size = 4096;
|
2005-01-29 01:37:22 +03:00
|
|
|
pte = ldl_phys(pte_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(env->cr[0] & CR0_PG_MASK)) {
|
|
|
|
pte = addr;
|
|
|
|
page_size = 4096;
|
2004-01-24 18:29:03 +03:00
|
|
|
} else {
|
|
|
|
/* page directory entry */
|
2007-04-18 03:08:56 +04:00
|
|
|
pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pde = ldl_phys(pde_addr);
|
2007-09-17 01:08:06 +04:00
|
|
|
if (!(pde & PG_PRESENT_MASK))
|
2004-01-24 18:29:03 +03:00
|
|
|
return -1;
|
2005-01-26 01:35:05 +03:00
|
|
|
if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
|
|
|
|
pte = pde & ~0x003ff000; /* align to 4MB */
|
|
|
|
page_size = 4096 * 1024;
|
|
|
|
} else {
|
|
|
|
/* page directory entry */
|
|
|
|
pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
|
2005-01-29 01:37:22 +03:00
|
|
|
pte = ldl_phys(pte_addr);
|
2005-01-26 01:35:05 +03:00
|
|
|
if (!(pte & PG_PRESENT_MASK))
|
|
|
|
return -1;
|
|
|
|
page_size = 4096;
|
|
|
|
}
|
2004-01-24 18:29:03 +03:00
|
|
|
}
|
2005-01-26 01:35:05 +03:00
|
|
|
pte = pte & env->a20_mask;
|
2004-01-24 18:29:03 +03:00
|
|
|
}
|
2005-01-26 01:35:05 +03:00
|
|
|
|
2004-01-24 18:29:03 +03:00
|
|
|
page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
|
|
|
|
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
|
|
|
|
return paddr;
|
|
|
|
}
|
2005-01-29 01:37:22 +03:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|