From: acevest Date: Tue, 16 May 2023 13:09:04 +0000 (+0800) Subject: 挪动tss相关代码 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=38375bab9e7814f4a676cefb610a31f2d85ee7a8;p=kernel.git 挪动tss相关代码 --- diff --git a/include/processor.h b/include/processor.h index eda56f2..56d6b9d 100644 --- a/include/processor.h +++ b/include/processor.h @@ -144,7 +144,7 @@ static inline void set_idt_gate(u32 vec, u32 handler, u8 type, u8 DPL) { idt[vec set_idt_gate(vect, (u32)handler, type, DPL); \ } while (0) -typedef struct { +typedef struct tss { u16 backlink, _backlink; u32 esp0; u16 ss0, _ss0; @@ -171,25 +171,8 @@ typedef struct { u16 gs, _gs; u16 ldt, _ldt; u16 T : 1, _T : 15, iomap_base; -} TSS, *pTSS; -static inline void set_tss_gate(u32 vec, u32 addr) { -#if 1 - pSeg p = (pSeg)(gdt + vec); - _init_desc((pDesc)p); - p->limitL = 0xFFFF & sizeof(TSS); - p->limitH = 0x0F & (sizeof(TSS) >> 16); - p->baseL = 0xFFFF & addr; - p->baseM = 0xFF & (addr >> 16); - p->baseH = 0xFF & (addr >> 24); - - p->P = 1; - p->DPL = PRIVILEGE_USER; - p->S = 0; - - p->type = TSS_DESC; -#endif -} +} TSS_t; -extern TSS tss; +extern TSS_t tss; #endif //_DESCRIPTOR_H diff --git a/kernel/system.c b/kernel/system.c index f5efd71..fa0d783 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -131,9 +131,26 @@ void setup_irqs() { open_irq(0x01); open_irq(0x0E); } + +void set_tss_gate(u32 vec, u32 addr, u32 limit) { + pSeg p = (pSeg)(gdt + vec); + _init_desc((pDesc)p); + p->limitL = 0xFFFF & limit; + p->limitH = 0x0F & (limit >> 16); + p->baseL = 0xFFFF & addr; + p->baseM = 0xFF & (addr >> 16); + p->baseH = 0xFF & (addr >> 24); + + p->P = 1; + p->DPL = PRIVILEGE_USER; + p->S = 0; + + p->type = TSS_DESC; +} + void set_tss() { - pTSS p = &tss; - memset((void *)p, sizeof(TSS), 0); + TSS_t *p = &tss; + memset((void *)p, sizeof(TSS_t), 0); p->esp0 = 0; // delay to init root_task p->ss0 = SELECTOR_KRNL_DS; p->ss = SELECTOR_KRNL_DS; @@ -143,8 +160,12 @@ void set_tss() { p->ds = SELECTOR_KRNL_DS; p->cs = SELECTOR_KRNL_CS; p->eflags = 0x1200; - p->iomap_base = sizeof(TSS); - set_tss_gate(INDEX_TSS, (u32)p); + p->iomap_base = sizeof(TSS_t); + + // tss的iomap_base=sizeof(TSS_t) > TSS_GATE.LIMIT - 1 + // 因此表示没有I/O位图 + set_tss_gate(INDEX_TSS, (u32)p, sizeof(TSS_t)); + asm("ltr %%ax" ::"a"((INDEX_TSS << 3) + 3)); } @@ -165,7 +186,7 @@ int sysc_reboot(int mode) { } System system; -TSS tss; +TSS_t tss; Desc idt[NIDT] __attribute__((__aligned__(8))); Desc gdt[NGDT] __attribute__((__aligned__(8))); char gdtr[6] __attribute__((__aligned__(4)));