]> Zhao Yanbai Git Server - kernel.git/commitdiff
支持两种指定sysenter的esp的方式
authoracevest <zhaoyanbai@126.com>
Mon, 15 May 2023 15:41:33 +0000 (23:41 +0800)
committeracevest <zhaoyanbai@126.com>
Mon, 15 May 2023 15:41:33 +0000 (23:41 +0800)
Makefile
kernel/sched.c
kernel/setup.c
kernel/syscall.S
kernel/syscall.c

index a12c79e816f9c36fe4b0f8fe6405d5a98969ff7e..c4903f07989a6ae7f99929105667a07017339ac6 100644 (file)
--- 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
index 819fa3c33c5dfc5c0211aca9e4d4bd791ae8fa5f..1309aa4fe15efd0c3a59557c1bd4ff6c74e5ec09 100644 (file)
@@ -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);
         }
index 2c29d1b88138ee3209235e926da25c0903a8c25e..aff660db27ffccfe94ffa22ea0d2a01f5813e79e 100644 (file)
@@ -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);
index f813627993289ccf64b2203447011b932b3a807c..b11cdee51bcd528d5b2127d81a8d75347b74cfaa 100644 (file)
@@ -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)
index 2a25a9f996c793444b87b5ed0f3b279f5a509965..c837488586a76e3e7b04ad3da1a11ba820e1bfc8 100644 (file)
@@ -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();
 }