/* gdt_init - initialize the default GDT and TSS */ static void gdt_init(void) { // set boot kernel stack and default SS0 load_rsp0((uintptr_t) bootstacktop); ts.ts_ss0 = KERNEL_DS; // initialize the TSS filed of the gdt gdt[SEG_TSS] = SEGTSS(STS_T32A, (uintptr_t) & ts, sizeof(ts), DPL_KERNEL); // reload all segment registers lgdt(&gdt_pd); // load the TSS ltr(GD_TSS); }
// proc_run - make process "proc" running on cpu // NOTE: before call switch_to, should load base addr of "proc"'s new PDT void proc_run(struct proc_struct *proc) { if (proc != current) { bool intr_flag; struct proc_struct *prev = current, *next = proc; // kprintf("(%d) => %d\n", lapic_id, next->pid); local_intr_save(intr_flag); { pls_write(current, proc); load_rsp0(next->kstack + KSTACKSIZE); mp_set_mm_pagetable(next->mm); switch_to(&(prev->context), &(next->context)); } local_intr_restore(intr_flag); } }
// proc_run - make process "proc" running on cpu // NOTE: before call switch_to, should load base addr of "proc"'s new PDT void proc_run(struct proc_struct *proc) { if (proc != current) { bool intr_flag; struct proc_struct *prev = current, *next = proc; // kprintf("(%d) => %d\n", lapic_id, next->pid); local_intr_save(intr_flag); { current = proc; load_rsp0(next->kstack + KSTACKSIZE); mp_set_mm_pagetable(next->mm); #ifdef UCONFIG_BIONIC_LIBC // for tls switch tls_switch(next); #endif //UCONFIG_BIONIC_LIBC switch_to(&(prev->context), &(next->context)); } local_intr_restore(intr_flag); } }