]> Zhao Yanbai Git Server - kernel.git/commitdiff
准备降级到ring3
authoracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 09:10:01 +0000 (17:10 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 09:10:01 +0000 (17:10 +0800)
kernel/init.c
kernel/syscall.S

index 7f1bcf817c3da61ea39e53fc9bd5931c3eb17cbb..cb9f1e1e3c24060f53480e013aca09a087640d10 100644 (file)
@@ -22,15 +22,25 @@ char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__((__aligned
 
 int debug_wait_queue_get();
 
-extern void *ring3;
-extern void *ring3_stack_top;
+// #define __ring3section__ __attribute__((__section__(".ring3")))
+
+// char __attribute__((__section__(".ring3.data"))) ring3_stack[PAGE_SIZE] = {0};
+// void __ring3section__ ring3_entry() {
+//     while (1) {
+//         systest();
+//     }
+// }
+
 void user_task_entry() {
-    printk("user_task_entry: %08x %08x\n", ring3_stack_top, &ring3_stack_top);
-#if 0
-    asm("sti;sysexit;"::"d"(&ring3), "c"(&ring3_stack_top));
-#else
-    sysc_exec("/bin/shell", 0);
-#endif
+    // printk("user_task_entry: %08x\n", ring3_entry);
+
+    // 现在要准备返回用户态
+    // eip --> edx
+    // esp --> ecx
+    // asm("sysexit;" ::"d"(ring3_entry), "c"(ring3_stack + PAGE_SIZE));
+    while (1) {
+        asm("hlt;");
+    }
 }
 
 void init_task_entry() {
@@ -56,7 +66,6 @@ void init_task_entry() {
     }
 }
 
-extern void ret_from_fork_krnl();
 void kernel_task(char *name, void *entry) {
     pt_regs_t regs;
 
@@ -67,6 +76,7 @@ void kernel_task(char *name, void *entry) {
 
     // 创建内核任务的时候就直接指定其在fork后走的路径
     // 就不用走sysexit那个路径了
+    extern void ret_from_fork_krnl();
     regs.eip = (unsigned long)ret_from_fork_krnl;
     regs.cs = SELECTOR_KRNL_CS;
     regs.ds = SELECTOR_KRNL_DS;
@@ -85,7 +95,7 @@ void root_task_entry() {
 
     kernel_task("init", init_task_entry);
     kernel_task("test", init_task_entry);
-    // kernel_task(user_task_entry);
+    kernel_task("user", user_task_entry);
 
     int cnt = 0;
     while (1) {
index 21f8b43f6c757bce2909347eab0f76a41b99d1ab..0a6f29068324fbc30cc1afd195810aba467e7d43 100644 (file)
@@ -108,35 +108,4 @@ sysexit:
     popl    %ebp;
     popl    %edx;
     popl    %ecx;
-    ret
-
-.global ring3
-.global ring3_stack_top
-ring3:
-    nop;
-    nop;
-
-    #movl $(ring3_stack+100), %esp
-
-    movl $11, %eax;
-
-    pushl $1f;
-    pushl %ecx;
-    pushl %edx;
-    pushl %ebp;
-    movl %esp,%ebp;
-    sysenter;
-    1:
-
-    nop;
-    nop;
-
-    jmp ring3
-
-ring3_stack:
-    .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-    .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-    .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-    .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-ring3_stack_top:
-    .long   0x12345678
+    ret
\ No newline at end of file