关于操作系统TSS的问题
最近在做操作系统,已经实现了r0到r3的跳转,但是在中断的时候cpu又触发了无效TSS的异常,然后系统直接挂掉重启,有那个大佬帮忙看看是哪里出了问题{:10_266:}TASK_STATE_SEGMENT tss;
void init_tss()
{
/* Initialize TSS and TR */
memset_w((word*)&tss, 0, sizeof(TASK_STATE_SEGMENT) >> 1);
tss.ss0 = KERNEL_DS;
tss.io_bitmap_base = sizeof(tss); /* No IO bitmap */
load_tr(add_tss_descriptor((dword)&tss, sizeof(TASK_STATE_SEGMENT)));
}
word add_tss_descriptor(dword seg_base, dword seg_limit)
{
return add_global_descriptor(seg_base, seg_limit,
SEG_PRESENT | DPL_RING0 | SYSTEM_DESCPRITOR | AVAILABLE_386TSS, USE_32BITS_OPERAND);
}
word add_global_descriptor(dword seg_base, dword seg_limit, byte authority, byte attr)
{
if (avl_gdt_index > NUM_OF_GDT_DESC)
return 0;
seg_limit--;
gdt.seg_limit_low = LOWORD(seg_limit);
gdt.seg_limit_high = HIWORD(seg_limit) & 0xf;
gdt.seg_base_low = LOWORD(seg_base);
gdt.seg_base_mid = LOBYTE(HIWORD(seg_base));
gdt.seg_base_high = HIBYTE(HIWORD(seg_base));
gdt.access_authority = authority;
gdt.attribute = attr;
/* Next available index */
avl_gdt_index++;
return (avl_gdt_index - 1) << 3;
}
_load_tr:
push ebp
mov ebp, esp
ltr
leave
ret 找到问题了,原来是KERNEL_DS的值设置错误导致CPU在切换特权级的检查里发现SS的值是无效的,直接无效TSS异常{:10_247:}
页:
[1]