- // 手动设置进程上下文:用于第一次调度
- 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");
-
- // 加载x87默认配置
- asm volatile("fninit\n"
- "fxsave (%%eax)" ::"a"(proc0->fxstate)
- : "memory");
+ struct exec_param* execp =
+ (struct exec_param*)(KSTACK_TOP - sizeof(struct exec_param));
+ isr_param* isrp = (isr_param*)((ptr_t)execp - sizeof(isr_param));
+
+ *execp = (struct exec_param){ .cs = KCODE_SEG,
+ .eip = (ptr_t)__proc0,
+ .ss = KDATA_SEG,
+ .eflags = cpu_reflags() };
+ *isrp = (isr_param){ .registers = { .ds = KDATA_SEG,
+ .es = KDATA_SEG,
+ .fs = KDATA_SEG,
+ .gs = KDATA_SEG },
+ .execp = execp };
+
+ proc0->intr_ctx = isrp;