Merge branch 'master' into prog-loader
[lunaix-os.git] / lunaix-os / kernel / k_init.c
index e98be8883cd3bbeb3ca161ed8071fd016a594c52..a2edf1a9d5c66007b5ada75b4e93aa0e80ad92cb 100644 (file)
@@ -127,11 +127,7 @@ spawn_proc0()
     proc0->intr_ctx = (isr_param){ .registers = { .ds = KDATA_SEG,
                                                   .es = KDATA_SEG,
                                                   .fs = KDATA_SEG,
-                                                  .gs = KDATA_SEG },
-                                   .cs = KCODE_SEG,
-                                   .eip = (void*)__proc0,
-                                   .ss = KDATA_SEG,
-                                   .eflags = cpu_reflags() };
+                                                  .gs = KDATA_SEG } };
     proc0->parent = proc0;
 
     // 方案1:必须在读取eflags之后禁用。否则当进程被调度时,中断依然是关闭的!
@@ -155,19 +151,14 @@ spawn_proc0()
                         VMAP_NULL);
     }
 
-    // 手动设置进程上下文:用于第一次调度
-    asm volatile("movl %%esp, %%ebx\n"
-                 "movl %1, %%esp\n"
-                 "pushf\n"
-                 "pushl %2\n"
-                 "pushl %3\n"
-                 "pushl $0\n"
-                 "pushl $0\n"
-                 "movl %%esp, %0\n"
-                 "movl %%ebx, %%esp\n"
-                 : "=m"(proc0->intr_ctx.registers.esp)
-                 : "i"(KSTACK_TOP), "i"(KCODE_SEG), "r"(proc0->intr_ctx.eip)
-                 : "%ebx", "memory");
+    struct exec_param* execp =
+      (struct exec_param*)(KSTACK_TOP - sizeof(struct exec_param));
+
+    *execp = (struct exec_param){ .cs = KCODE_SEG,
+                                  .eip = (void*)__proc0,
+                                  .ss = KDATA_SEG,
+                                  .eflags = cpu_reflags() };
+    proc0->intr_ctx.execp = execp;
 
     // 加载x87默认配置
     asm volatile("fninit\n"