提交 e441570f 编写于 作者: B balrog

use target_mmap() to allocate idt, gdt and ldt (Kirill A. Shutemov).

env->*dt.base should fit target address space, so we should use
target_mmap to allocate them.
Signed-off-by: NKirill A. Shutemov <kirill@shutemov.name>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5666 c046a42c-6fe2-441c-8c8c-71466251a162
上级 8ce0f869
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h>
#include "qemu.h" #include "qemu.h"
#include "qemu-common.h" #include "qemu-common.h"
...@@ -282,9 +283,8 @@ static void write_dt(void *ptr, unsigned long addr, unsigned long limit, ...@@ -282,9 +283,8 @@ static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
p[1] = tswap32(e2); p[1] = tswap32(e2);
} }
static uint64_t *idt_table;
#ifdef TARGET_X86_64 #ifdef TARGET_X86_64
static uint64_t idt_table[512];
static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
uint64_t addr, unsigned int sel) uint64_t addr, unsigned int sel)
{ {
...@@ -303,8 +303,6 @@ static void set_idt(int n, unsigned int dpl) ...@@ -303,8 +303,6 @@ static void set_idt(int n, unsigned int dpl)
set_gate64(idt_table + n * 2, 0, dpl, 0, 0); set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
} }
#else #else
static uint64_t idt_table[256];
static void set_gate(void *ptr, unsigned int type, unsigned int dpl, static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
uint32_t addr, unsigned int sel) uint32_t addr, unsigned int sel)
{ {
...@@ -2465,8 +2463,15 @@ int main(int argc, char **argv) ...@@ -2465,8 +2463,15 @@ int main(int argc, char **argv)
#endif #endif
/* linux interrupt setup */ /* linux interrupt setup */
env->idt.base = h2g(idt_table); #ifndef TARGET_ABI32
env->idt.limit = sizeof(idt_table) - 1; env->idt.limit = 511;
#else
env->idt.limit = 255;
#endif
env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1),
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
idt_table = g2h(env->idt.base);
set_idt(0, 0); set_idt(0, 0);
set_idt(1, 0); set_idt(1, 0);
set_idt(2, 0); set_idt(2, 0);
...@@ -2492,9 +2497,11 @@ int main(int argc, char **argv) ...@@ -2492,9 +2497,11 @@ int main(int argc, char **argv)
/* linux segment setup */ /* linux segment setup */
{ {
uint64_t *gdt_table; uint64_t *gdt_table;
gdt_table = qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRIES); env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES,
env->gdt.base = h2g((unsigned long)gdt_table); PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
gdt_table = g2h(env->gdt.base);
#ifdef TARGET_ABI32 #ifdef TARGET_ABI32
write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
......
...@@ -2565,12 +2565,16 @@ static abi_long write_ldt(CPUX86State *env, ...@@ -2565,12 +2565,16 @@ static abi_long write_ldt(CPUX86State *env,
} }
/* allocate the LDT */ /* allocate the LDT */
if (!ldt_table) { if (!ldt_table) {
ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); env->ldt.base = target_mmap(0,
if (!ldt_table) TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE,
PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (env->ldt.base == -1)
return -TARGET_ENOMEM; return -TARGET_ENOMEM;
memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); memset(g2h(env->ldt.base), 0,
env->ldt.base = h2g((unsigned long)ldt_table); TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
env->ldt.limit = 0xffff; env->ldt.limit = 0xffff;
ldt_table = g2h(env->ldt.base);
} }
/* NOTE: same code as Linux kernel */ /* NOTE: same code as Linux kernel */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册