Code: Select all
oid LoadIDT() {
??????idtreg.limit = &idt[0] - &idt[1] - 1;
??????idtreg.base = (unsigned long*) &idt[0];
??????asm volatile("LIDT %0 ": :"m" (idtreg));
??????
??????// Exceptions
??????SetInt(0, int00);
??????SetInt(0, int01);
??????SetInt(0, int02);
??????SetInt(0, int03);
??????SetInt(0, int04);
??????SetInt(0, int05);
??????SetInt(0, int06);
??????SetInt(0, int07);
??????SetInt(0, int08);
??????SetInt(0, int09);
??????SetInt(0, int10);
??????SetInt(0, int12);
??????SetInt(0, int13);
??????SetInt(0, int14);
??????SetInt(0, int16);
??????SetInt(0, int17);
??????SetInt(0, int18);
??????SetInt(0, int19);
??????
??????// IRQs
??????SetInt(0, int32); // PIT - Programmable Interval Timer IRQ
}
void SetInt(int number, void *handler) {
??????idt[number].low_offset = (unsigned int)handler;
??????idt[number].seg_selector = 0x08;
??????idt[number].settings = 0x8E00;
??????idt[number].high_offset = ((unsigned int)handler >> 16);
}
You only allocate enough space for 1 ISR.
Go ahead and use:
Try setting the exceptions to use the correct ISR, instead of all using ISR zero. No point in doing that.
Code: Select all
???init_pics();
???print("PICs remapped to 0x20 and 0x28.", white);
???
???LoadIDT();
Load the IDT before
init_pics().
Code: Select all
void init_pics() {
??????outb(0x20, 0x11);
??????outb(0xA0, 0x11);
??????outb(0x21, 0x20);
??????outb(0xA1, 0x28);
??????outb(0x21, 0x04);
??????outb(0xA1, 0x02);
??????outb(0x21, 0x01);
??????outb(0xA1, 0x01);
??????outb(0x21, 0xFF);
}
You maked all the interrupts with:
How is anything happening?
Code: Select all
[BITS 32]
[GLOBAL entry]
[EXTERN _k_main]
entry:
???call _k_main
???cli
???hlt
Where is your stack at? Does it have enough space? Try moving it somewhere else just to check.
Code: Select all
_int32:
mov byte [0xb800], 'a'
???mov byte [0xb801], 0x07
???;jmp $
???;hlt
???;cmp byte [_isrfunc], 1
???
???;je pitsleep
???;jmp pitwrong
???;pitsleep:
???;???call _pit_sleep
???;pitwrong:
???;mov al, 20h
???;out 20h, al
???iret
Try a:
Just to be sure, it is not crashing so fast BOCHS does not update the display with your vga code at the top.
Code: Select all
>>>> int_descriptor idt[1];
asm volatile ("int $0x1");
You are calling a interrupt that does not exist. See above, by setting all your ISRs to interrupt 0x0. You are calling 0x1. You never set a ISR for 0x1, only 0x0 multiple times in your code.
The PIC was remapped to 0x20.
Code: Select all
>>>>outb(0x21, 0x20);
>>>>outb(0xA1, 0x28);
asm volatile ("int $0x20") - calls the timer.
This sets the PIT correctly.
Code: Select all
SetInt(0x20, int32); // PIT - Programmable Interval Timer IRQ
That 0x1 could be causing the crash, but it might not be the original problem. You might have created a different problem trying to debug your kernel.