From: acevest Date: Mon, 15 May 2023 15:41:33 +0000 (+0800) Subject: 支持两种指定sysenter的esp的方式 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-keygen.html?a=commitdiff_plain;h=1df4e3c87dcfd0593c3313955594b7b7316e9af6;p=kernel.git 支持两种指定sysenter的esp的方式 --- diff --git a/Makefile b/Makefile index a12c79e..c4903f0 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ else ifeq ($(OS), Linux) endif -CFLAGS = -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"' +CFLAGS = -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"' -DFIX_SYSENTER_ESP_MODE=1 SYSTEMMAP = System.map KERNELBIN = KERNEL.BIN LINKSCRIPT = scripts/link.ld diff --git a/kernel/sched.c b/kernel/sched.c index 819fa3c..1309aa4 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -71,8 +71,11 @@ void init_root_task() { root_task.cr3 = va2pa((unsigned long)(init_pgd)); tss.esp0 = root_task.esp0; - +#if FIX_SYSENTER_ESP_MODE + // do nothing +#else wrmsr(MSR_SYSENTER_ESP, root_task.esp0, 0); +#endif printk("init_root_task tss.esp0 %08x\n", tss.esp0); } @@ -100,7 +103,11 @@ task_union *alloc_task_union() { void switch_to() { LoadCR3(current->cr3); tss.esp0 = current->esp0; +#if FIX_SYSENTER_ESP_MODE + // do nothing +#else wrmsr(MSR_SYSENTER_ESP, current->esp0, 0); +#endif } void context_switch(task_union *prev, task_union *next) { @@ -208,7 +215,7 @@ unsigned long schedule() { // printk("switch to: %s:%d\n", next->name, next->pid); list_for_each_safe(pos, t, &all_tasks) { p = list_entry(pos, task_union, list); - printl(MPL_TASK_0 + p->pid * 2, " "); //清掉上一次显示的 '>' + printl(MPL_TASK_0 + p->pid * 2, " "); // 清掉上一次显示的 '>' printl(MPL_TASK_0 + p->pid * 2, "%s%4s:%d [%08x] state %s weight %03d sched %u", next == p ? ">" : " ", p->name, p->pid, p, task_state(p->state), p->weight, p->sched_cnt); } diff --git a/kernel/setup.c b/kernel/setup.c index 2c29d1b..aff660d 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -58,6 +58,14 @@ const char *version = "Kernel version " VERSION " @ " BUILDER void setup_kernel() { init_ttys(); + printk("sysenter esp mode: %s\n", +#if FIX_SYSENTER_ESP_MODE + "fixed to &tss.esp0" +#else + "use task union stack" +#endif + ); + init_mm(); // printk("kernel: %08x - %08x\n", system.kernel_begin, system.kernel_end); diff --git a/kernel/syscall.S b/kernel/syscall.S index f813627..b11cdee 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -30,6 +30,9 @@ //.global syscall_exit syscall_entry: +#if FIX_SYSENTER_ESP_MODE + movl (%esp),%esp +#endif // 这段代码纯是为了pt_regs_t准备的 // 后续看看直接优化掉 pushl $(SELECTOR_USER_SS) diff --git a/kernel/syscall.c b/kernel/syscall.c index 2a25a9f..c837488 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -27,8 +27,9 @@ unsigned long sysc_handler_table[SYSC_NUM]; void setup_sysc() { wrmsr(MSR_SYSENTER_CS, SELECTOR_KRNL_CS, 0); wrmsr(MSR_SYSENTER_EIP, syscall_entry, 0); - // wrmsr(MSR_SYSENTER_ESP, &(tss.esp0), 0); - +#if FIX_SYSENTER_ESP_MODE + wrmsr(MSR_SYSENTER_ESP, &(tss.esp0), 0); +#endif init_sysc_handler_table(); }