#include <irq/i8259a.h>
/* This table will hold pointers to our interrupt handlers. */
-static int (*int_handler_table[256])(void);
+static int (*int_handler_table[256])(struct interrupt_frame *);
-void int_handler(int interrupt)
+void int_handler(struct interrupt_frame *frame)
{
+ int interrupt = frame->interrupt;
if (int_handler_table[interrupt] == NULL) {
kprint("WARNING: Unhandled interrupt ", 0);
kprintb(interrupt);
kprint(" occurred!\n", 0);
} else {
- int ret = (*int_handler_table[interrupt])();
+ int ret = (*int_handler_table[interrupt])(frame);
if (ret) {
kprint("WARNING: Error while handling interrupt ", 0);
kprintb(interrupt);
}
}
-int register_interrupt(int irq, int (*handler)(void))
+int register_interrupt(int irq, int (*handler)(struct interrupt_frame *))
{
int_handler_table[irq] = handler;
if (irq >= 32 && irq < 48) {
struct idtr idtr __attribute__((aligned(0x10)));
extern void (*_int_handler_table[48])(void);
+/* Small handler for double faults. Will be put elsewhere eventually. */
+int double_fault_handler(struct interrupt_frame *frame)
+{
+ kprint("PANIC: Double fault occurred!\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EAX: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->eax);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EBX: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->ebx);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("ECX: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->ecx);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EDX: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->edx);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EBP: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->ebp);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("ESP: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->esp);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("ESI: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->esi);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EDI: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->edi);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EIP: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->eip);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+ kprint("EFLAGS: ", VGA_COLOR_BRIGHT_RED);
+ kprintd(frame->eflags);
+ kprint("\n", VGA_COLOR_BRIGHT_RED);
+
+ /* IF has already been cleared for us */
+halt:
+ asm("hlt");
+ goto halt;
+}
+
void kmain(void)
{
int ps2_success;
populate_idtr(&idtr, idt);
load_idt(idtr);
kprint("Setting up interrupts...\n", 0);
+ register_interrupt(8, &double_fault_handler);
pic_init(0x20, 0x28);
pic_mask_all();
ps2_success = ps2_initialize();