- assert_msg(
- vmm_alloc_pages(KERNEL_PID, &__proc_table, pg_size, PG_PREM_RW, PP_FGPERSIST),
- "Fail to allocate proc table"
- );
-
- sched_ctx = (struct scheduler) {
- ._procs = (struct proc_info*) &__proc_table,
- .ptable_len = 0,
- .procs_index = 0
- };
+ assert_msg(vmm_alloc_pages(
+ KERNEL_PID, &__proc_table, pg_size, PG_PREM_RW, PP_FGPERSIST),
+ "Fail to allocate proc table");
+
+ sched_ctx = (struct scheduler){ ._procs = (struct proc_info*)&__proc_table,
+ .ptable_len = 0,
+ .procs_index = 0 };
+}
+
+void
+run(struct proc_info* proc)
+{
+ if (!(__current->state & ~PROC_RUNNING)) {
+ __current->state = PROC_STOPPED;
+ }
+ proc->state = PROC_RUNNING;
+
+ // FIXME: 这里还是得再考虑一下。
+ // tss_update_esp(__current->intr_ctx.esp);
+
+ if (__current->page_table != proc->page_table) {
+ __current = proc;
+ cpu_lcr3(__current->page_table);
+ // from now on, the we are in the kstack of another process
+ } else {
+ __current = proc;
+ }
+
+ apic_done_servicing();
+
+ asm volatile("pushl %0\n"
+ "jmp soft_iret\n" ::"r"(&__current->intr_ctx)
+ : "memory");