interrupt: load GDT/IDT on the stack

We have to use a separate Assembly function to do that, but maybe with some effort we can make that inline too
This commit is contained in:
2021-10-14 15:51:50 +08:00
parent ebdc816d82
commit aa11d25fa8
4 changed files with 36 additions and 31 deletions

View File

@ -36,16 +36,9 @@ void interrupt_Init() {
assert(sizeof(interrupt_DescriptorTableReference) == 10 && "GDTR/IDTR size must be 10 bytes");
assert(offsetof(interrupt_DescriptorTableReference, base) == 2 && "GDTR/IDTR must be packed");
assert(KERNEL_IDTR_MAPPING % 4 == 0 && "IDTR not aligned to 4-byte");
assert(KERNEL_GDTR_MAPPING % 4 == 0 && "GDTR not aligned to 4-byte");
// allocate GDTR
io_WriteConsoleASCII("interrupt_Init() calling\n");
interrupt_GDTR = (interrupt_DescriptorTableReference *)KERNEL_GDTR_MAPPING;
interrupt_GDTR->length = 4 * GDT_SIZE_BYTES - 1;
interrupt_GDTR->base = (void *)KERNEL_GDT_MAPPING;
io_WriteConsoleASCII("GDTR Written\n");
// set the 2 dummy gdts
uint64_t *gdt = (uint64_t *)KERNEL_GDT_MAPPING;
@ -56,20 +49,13 @@ void interrupt_Init() {
gdt[4] = GDT_DATA_RING3;
io_WriteConsoleASCII("GDT Installed\n");
interrupt_LoadGDT(interrupt_GDTR); // set it!
interrupt_LoadGDT(4 * GDT_SIZE_BYTES - 1, (void *)KERNEL_GDT_MAPPING); // set it!
io_WriteConsoleASCII("GDT OK\n");
//interrupt_Testcode();
io_WriteConsoleASCII("Testcode OK\n");
// allocate IDTR
//interrupt_IDTR = kMalloc(sizeof(interrupt_DescriptorTableReference));
interrupt_IDTR = (interrupt_DescriptorTableReference *)KERNEL_IDTR_MAPPING;
interrupt_IDTR->length = KERNEL_IDT_SIZE - 1;
interrupt_IDTR->base = (void *)KERNEL_IDT_MAPPING;
io_WriteConsoleASCII("IDT Written\n");
interrupt_MapHandler(interrupt_Int0, 0);
interrupt_MapHandler(interrupt_Int1, 1);
interrupt_MapHandler(interrupt_Int2, 2);
@ -105,11 +91,10 @@ void interrupt_Init() {
interrupt_MapHandler(interrupt_Int128, 128);
io_WriteConsoleASCII("IDT Installed\n");
interrupt_LoadIDT(interrupt_IDTR); // set it!
interrupt_LoadIDT(KERNEL_IDT_SIZE - 1, (void *)KERNEL_IDT_MAPPING); // set it!
io_WriteConsoleASCII("IDT OK\n");
interrupt_Enabled = true;
asm volatile("sti");