diff --git a/sortix/interrupt.cpp b/sortix/interrupt.cpp index 6f878a99..fc54bb6f 100644 --- a/sortix/interrupt.cpp +++ b/sortix/interrupt.cpp @@ -50,21 +50,26 @@ namespace Sortix "Bad TSS", "Segment not present", "Stack fault", "General protection fault", "Page fault", "Unknown interrupt", "Coprocessor fault", "Alignment check", "Machine check", - "SIMD Floating-Point" }; + "SIMD Floating-Point" }; - Handler interrupthandlers[256]; + const size_t NUM_INTERRUPTS = 256UL; + + Handler interrupthandlers[NUM_INTERRUPTS]; + void* interrupthandlerptr[NUM_INTERRUPTS]; void Init() { - for ( size_t i = 0; i < 256; i++ ) + for ( size_t i = 0; i < NUM_INTERRUPTS; i++ ) { interrupthandlers[i] = NULL; + interrupthandlerptr[i] = NULL; } } - void RegisterHandler(uint8_t n, Interrupt::Handler handler) + void RegisterHandler(uint8_t n, Interrupt::Handler handler, void* user) { interrupthandlers[n] = handler; + interrupthandlerptr[n] = user; } // This gets called from our ASM interrupt handler stub. @@ -105,7 +110,8 @@ namespace Sortix if ( interrupthandlers[regs->int_no] != NULL ) { - interrupthandlers[regs->int_no](regs); + void* user = interrupthandlerptr[regs->int_no]; + interrupthandlers[regs->int_no](regs, user); } } @@ -133,7 +139,8 @@ namespace Sortix if ( interrupthandlers[regs->int_no] ) { - interrupthandlers[regs->int_no](regs); + void* user = interrupthandlerptr[regs->int_no]; + interrupthandlers[regs->int_no](regs, user); } } diff --git a/sortix/interrupt.h b/sortix/interrupt.h index 62ca42ec..36fe1720 100644 --- a/sortix/interrupt.h +++ b/sortix/interrupt.h @@ -46,9 +46,9 @@ namespace Sortix const unsigned IRQ14 = 46; const unsigned IRQ15 = 47; - typedef void (*Handler)(CPU::InterruptRegisters* Registers); + typedef void (*Handler)(CPU::InterruptRegisters* regs, void* user); - void RegisterHandler(uint8_t n, Handler handler); + void RegisterHandler(uint8_t n, Handler handler, void* user); void Init(); } diff --git a/sortix/keyboard.cpp b/sortix/keyboard.cpp index 98ad2094..d49da226 100644 --- a/sortix/keyboard.cpp +++ b/sortix/keyboard.cpp @@ -652,7 +652,7 @@ namespace Sortix Layouts::Init(); // Register our keystroke callback. - Interrupt::RegisterHandler(Interrupt::IRQ1, OnIRQ1); + Interrupt::RegisterHandler(Interrupt::IRQ1, OnIRQ1, NULL); // If any scancodes were already pending, our interrupt handler // will never be called. Let's just discard anything pending. @@ -685,7 +685,7 @@ namespace Sortix return true; } - void OnIRQ1(CPU::InterruptRegisters* Regs) + void OnIRQ1(CPU::InterruptRegisters* Regs, void* user) { // Read the scancode from the data register. uint8_t Scancode = CPU::InPortB(0x60); diff --git a/sortix/keyboard.h b/sortix/keyboard.h index 2bde6be0..37937d2a 100644 --- a/sortix/keyboard.h +++ b/sortix/keyboard.h @@ -31,7 +31,7 @@ namespace Sortix { void Init(); void SetLEDs(uint8_t Toggle); - void OnIRQ1(CPU::InterruptRegisters* Regs); + void OnIRQ1(CPU::InterruptRegisters* Regs, void* user); bool QueueKeystroke(uint32_t keystroke); } } diff --git a/sortix/time.cpp b/sortix/time.cpp index 67f18ef0..36f44a7b 100644 --- a/sortix/time.cpp +++ b/sortix/time.cpp @@ -54,7 +54,7 @@ namespace Sortix return microsecondssinceboot; } - void OnInt177(CPU::InterruptRegisters* Regs) + void OnInt177(CPU::InterruptRegisters* Regs, void* /*user*/) { #ifdef PLATFORM_X86 Log::PrintF("ds=0x%x, edi=0x%x, esi=0x%x, ebp=0x%x, esp=0x%x, ebx=0x%x, edx=0x%x, ecx=0x%x, eax=0x%x, int_no=0x%x, err_code=0x%x, eip=0x%x, cs=0x%x, eflags=0x%x, useresp=0x%x, ss=0x%x\n", Regs->ds, Regs->edi, Regs->esi, Regs->ebp, Regs->esp, Regs->ebx, Regs->edx, Regs->ecx, Regs->eax, Regs->int_no, Regs->err_code, Regs->eip, Regs->cs, Regs->eflags, Regs->useresp, Regs->ss); @@ -99,8 +99,8 @@ namespace Sortix microsecondssinceboot = 0; // First, register our timer callback. - Interrupt::RegisterHandler(Interrupt::IRQ0, &OnIRQ0); - Interrupt::RegisterHandler(177, &OnInt177); + Interrupt::RegisterHandler(Interrupt::IRQ0, &OnIRQ0, NULL); + Interrupt::RegisterHandler(177, &OnInt177, NULL); Syscall::Register(SYSCALL_UPTIME, (void*) SysUptime); @@ -109,7 +109,7 @@ namespace Sortix RequestIQR0(); } - void OnIRQ0(CPU::InterruptRegisters* Regs) + void OnIRQ0(CPU::InterruptRegisters* Regs, void* /*user*/) { #ifdef PLATFORM_SERIAL SerialTerminal::OnTick(); diff --git a/sortix/time.h b/sortix/time.h index a6f33b3a..8ea3b509 100644 --- a/sortix/time.h +++ b/sortix/time.h @@ -31,7 +31,7 @@ namespace Sortix namespace Time { void Init(); - void OnIRQ0(CPU::InterruptRegisters* Registers); + void OnIRQ0(CPU::InterruptRegisters* Registers, void* user); float GetTimeSinceBoot(); uintmax_t MicrosecondsSinceBoot(); }