t_error ia32_thread_init(void) { THREAD_ENTER(thread); o_as* as; t_vaddr int_stack; /* * 1) */ if (as_get(kasid, &as) != ERROR_NONE) THREAD_LEAVE(thread, ERROR_UNKNOWN); /* * 2) */ if (map_reserve(kasid, MAP_OPT_PRIVILEGED, 3 * PAGESZ, PERM_READ | PERM_WRITE, (t_vaddr*)&thread->machdep.tss) != ERROR_NONE) THREAD_LEAVE(thread, ERROR_UNKNOWN); memset(thread->machdep.tss, 0x0, sizeof(t_ia32_tss)); /* * 3) */ if (map_reserve(kasid, MAP_OPT_PRIVILEGED, 2 * PAGESZ, PERM_READ | PERM_WRITE, &int_stack) != ERROR_NONE) THREAD_LEAVE(thread, ERROR_UNKNOWN); /* * 4) */ if (tss_load(thread->machdep.tss, SEGSEL(PMODE_GDT_CORE_DS, PRIV_RING0), int_stack + 2 * PAGESZ - 16, 0x68) != ERROR_NONE) THREAD_LEAVE(thread, ERROR_UNKNOWN); gl_stack_int = int_stack + 2 * PAGESZ - 16; /* * 5) */ if (tss_init(thread->machdep.tss) != ERROR_NONE) THREAD_LEAVE(thread, ERROR_UNKNOWN); THREAD_LEAVE(thread, ERROR_NONE); }
/* * ³õʼ»¯tss */ void tss_init() { int i = gdt_add(desc_create((u32)&tss,sizeof(tss),DA_386TSS)); gdt_load(); tss.iobase = (u16)(u32)&tss.iomap; tss.end = 0xff; tss.ss0 = GdtGetSel(KERNEL_DATA,0); tss.esp0 = 0x80000; tss_sel = GdtGetSel(i,0); tss_load(tss_sel); }
void tss_switch(uint32_t new_tss_ss) { if (cur_tss_ss != -1) tss_save(cur_tss_ss); cur_tss_ss = new_tss_ss; tss_load(cur_tss_ss); }