2026-06-11 23:23:39 -05:00
|
|
|
#include "lib/print.h"
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2026-06-13 13:27:39 -05:00
|
|
|
extern void send_eoi_master(void);
|
|
|
|
|
extern void send_eoi_slave(void);
|
2026-06-13 19:53:57 -04:00
|
|
|
extern uint8_t read_isr_master(void);
|
|
|
|
|
extern uint8_t read_isr_slave(void);
|
|
|
|
|
|
|
|
|
|
extern uint8_t ps2_read_data();
|
2026-06-11 23:23:39 -05:00
|
|
|
|
|
|
|
|
struct registers {
|
|
|
|
|
uint32_t edi, esi, ebp, esp_dummy, ebx, edx, ecx, eax;
|
|
|
|
|
|
|
|
|
|
uint32_t int_no;
|
|
|
|
|
uint32_t error_code;
|
|
|
|
|
|
|
|
|
|
uint32_t eip, cs, eflags, useresp, ss;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char* err_messages[32] = {
|
|
|
|
|
[0] = "Divide by 0",
|
|
|
|
|
[1] = "",
|
|
|
|
|
[8] = "",
|
2026-06-13 20:43:09 -04:00
|
|
|
[13] = "General Protection Fault",
|
2026-06-11 23:23:39 -05:00
|
|
|
[14] = "Page Fault",
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-13 19:53:57 -04:00
|
|
|
void common_interrupt_handler(struct registers *args) {
|
|
|
|
|
switch (args->int_no) {
|
2026-06-11 23:23:39 -05:00
|
|
|
case 0:
|
|
|
|
|
case 1:
|
2026-06-13 19:53:57 -04:00
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
case 4:
|
|
|
|
|
case 5:
|
|
|
|
|
case 6:
|
|
|
|
|
case 7:
|
2026-06-11 23:23:39 -05:00
|
|
|
case 8:
|
2026-06-13 19:53:57 -04:00
|
|
|
case 9:
|
|
|
|
|
case 10:
|
|
|
|
|
case 11:
|
|
|
|
|
case 12:
|
2026-06-11 23:23:39 -05:00
|
|
|
case 13:
|
2026-06-13 19:53:57 -04:00
|
|
|
case 15:
|
|
|
|
|
case 16:
|
2026-06-14 00:34:11 -05:00
|
|
|
kprintf("CPU Error: %s", err_messages[args->int_no]);
|
2026-06-11 23:23:39 -05:00
|
|
|
break;
|
2026-06-16 18:44:31 -05:00
|
|
|
case 14:{
|
|
|
|
|
uint32_t faulting_address;
|
|
|
|
|
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
|
|
|
|
|
kprintf("\n--- PAGE FAULT ---\n");
|
2026-06-16 21:53:38 -04:00
|
|
|
kprintf("Faulted Virtual Address: 0x%x\n", faulting_address);
|
2026-06-16 18:44:31 -05:00
|
|
|
kprintf("Error Code: 0x%x\n", args->error_code);
|
2026-06-16 21:53:38 -04:00
|
|
|
kprintf("Instruction Pointer: 0x%x\n", args->eip);
|
2026-06-16 18:44:31 -05:00
|
|
|
kprintf("Caused by: %s, %s, running in %s mode\n",
|
2026-06-16 21:53:38 -04:00
|
|
|
(args->error_code & 0x01) ? "Protection Violation" : "Page Not Present",
|
|
|
|
|
(args->error_code & 0x02) ? "Write" : "Read",
|
|
|
|
|
(args->error_code & 0x04) ? "User" : "Supervisor");
|
2026-06-16 18:44:31 -05:00
|
|
|
while(1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-06-11 23:23:39 -05:00
|
|
|
case 32:
|
2026-06-13 13:27:39 -05:00
|
|
|
// wake the PIT timer driver
|
|
|
|
|
send_eoi_master();
|
2026-06-11 23:23:39 -05:00
|
|
|
break;
|
2026-06-13 19:53:57 -04:00
|
|
|
case 33: {
|
|
|
|
|
uint8_t data = ps2_read_data();
|
2026-06-13 13:27:39 -05:00
|
|
|
send_eoi_master();
|
2026-06-11 23:23:39 -05:00
|
|
|
break;
|
2026-06-13 19:53:57 -04:00
|
|
|
}
|
2026-06-23 23:19:49 -05:00
|
|
|
case 46: { // IDE PRIMARY
|
|
|
|
|
send_eoi_slave();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 47: { // IDE SLAVE
|
|
|
|
|
send_eoi_slave();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-06-11 23:23:39 -05:00
|
|
|
default:
|
2026-06-14 00:34:11 -05:00
|
|
|
kprintf("Received unhandled interrupt: %d\n", args->int_no);
|
2026-06-11 23:23:39 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|