发csdn没人鸟我,- -,求助啊,tss切换的问题
问题是这样的,我定义了两个tss选择子是#define SELECTOR_TSS 0x20
#define SELECTOR_TSS_NEXT 0x28
情况是这样的,我在ring0下
ltr SELECTOR_TSS
然后
jmp SELECTOR_TSS_NEXT : 0
但bochs弹出的错误指示是
00018540031e[CPU0 ] task_switch(exception after commit point): SS not valid or writeable segment
00018540031e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0a)
00018540031e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
它们的初始化是这样的
memset(&tss, 0, sizeof(struct tss));
tss.ss0 = SELECTOR_KERNEL_DS;
tss.ldt = 0;
init_desc(&gdt[INDEX_TSS], (u32)&tss, sizeof(struct tss) - 1, DA_386TSS);
= 0x40000000;
memset(&tss_next, 0, sizeof(struct tss));
tss_next.ldt = 0;
init_desc(&gdt[INDEX_TSS_NEXT], (u32)&tss_next, sizeof(struct tss) - 1, DA_386TSS);
tss_ = 0x40000000;
tss_next.eip = (u32)TestA;
tss_next.ss = 0x10;
tss_next.esp = (u32)task_stack + STACK_SIZE_TOTAL;
其中
0x10所代表的gdt是数据段
base为0,limit为0fffffh,type是c093h
init_desc是用来初始化gdt的,代码是
PUBLIC void init_desc(DESCRIPTOR* p_desc, unsigned int base, unsigned int limit, u16 attr)
{
p_desc->limit_low = limit & 0xFFFF;
p_desc->base_low = base & 0xFFFF;
p_desc->base_mid = (base >> 16) & 0xFF;
p_desc->attr1 = attr & 0xFF;
p_desc->attr2_limit_high = (((limit >> 16) & 0x0F) | (attr >> 8)) & 0xF0;
p_desc->base_high = (base >> 24) & 0xFF;
}
DESCRIPTOR结构是
typedef struct descriptor {
u16 limit_low;
u16 base_low;
u8 base_mid;
u8 attr1;
u8 attr2_limit_high;
u8 base_high;
}DESCRIPTOR;
tss结构是
typedef struct tss {
u32 backline;
u32 esp0;
u32 ss0;
u32 esp1;
u32 ss1;
u32 esp2;
u32 ss2;
u32 cr3;
u32 eip;
u32 flags;
u32 eax;
u32 ecx;
u32 edx;
u32 ebx;
u32 esp;
u32 ebp;
u32 esi;
u32 edi;
u32 es;
u32 cs;
u32 ss;
u32 ds;
u32 fs;
u32 gs;
u32 ldt;
u32 iomap;
}TSS;