Files
Espresso/drivers/isr.c

43 lines
750 B
C
Raw Normal View History

2025-05-28 14:41:02 -05:00
#include <port_io.h>
#include <stdio.h>
#include <isr.h>
void (*irq_handlers[256])(isr_stack_t *r) = { 0 };
void register_interrupt_handler(uint8_t n, void (*handler)(isr_stack_t *))
{
irq_handlers[n] = handler;
}
void isr_handler(isr_stack_t *r)
{
if (irq_handlers[r->int_no]) {
irq_handlers[r->int_no](r);
} else {
printf("Unhandled interrupt: %d\n", r->int_no);
}
/* Send EOI to PIC */
if (r->int_no >= 40)
{
outb(0xA0, 0x20);
}
if (r->int_no >= 32)
{
outb(0x20, 0x20);
}
}
void syscall_handler(regs_t *r)
{
switch (r->eax) {
case 0: printf("Syscall: Hello world\n"); break;
case 1: printf("Syscall: value = %d\n", r->ebx); break;
default: printf("Unknown syscall %d\n", r->eax);
}
}