Interrupt handler looses state
Posted: Sat Aug 28, 2010 8:29 am
Hello,
I'm writing a kernel almost completely in C++ and for interrupt handling I defined the following classes:
Oxygen::Kernel::Processor::InterruptAdvisor (abstract) registering the IDT and holding an array of interrupt handlers
Oxygen::Kernel::Processor::InterruptHandler (abstract) can be registered to an interrupt advisor for one or more interrupt numbers
Oxygen::Kernel::Processor::X86::X86InterruptAdvisor: Implementation of InterruptAdvisor
The last one, X86InterruptAdvisor acts as a singleton. Handlers can be attached at anytime, as they are not directly written in the IDT, instead some proxy methods receive the original interrupt. Handlers are attached to an array InterruptHandler *handlers[256].
When my class is receiving an interrupt the instance of the X86InterruptAdvisor is fetched which will look whether there is a handler registered for the number of the fired interrupt. But the array is completely empty then, although it was filled before. Also a test property "int hello" which I set from zero to one before the interrupt fires is reset to zero.
A snippet of my code I use for interrupt handling, jumped to by _int_callNUMBER:
I'm writing a kernel almost completely in C++ and for interrupt handling I defined the following classes:
Oxygen::Kernel::Processor::InterruptAdvisor (abstract) registering the IDT and holding an array of interrupt handlers
Oxygen::Kernel::Processor::InterruptHandler (abstract) can be registered to an interrupt advisor for one or more interrupt numbers
Oxygen::Kernel::Processor::X86::X86InterruptAdvisor: Implementation of InterruptAdvisor
The last one, X86InterruptAdvisor acts as a singleton. Handlers can be attached at anytime, as they are not directly written in the IDT, instead some proxy methods receive the original interrupt. Handlers are attached to an array InterruptHandler *handlers[256].
When my class is receiving an interrupt the instance of the X86InterruptAdvisor is fetched which will look whether there is a handler registered for the number of the fired interrupt. But the array is completely empty then, although it was filled before. Also a test property "int hello" which I set from zero to one before the interrupt fires is reset to zero.
A snippet of my code I use for interrupt handling, jumped to by _int_callNUMBER:
Code: Select all
; Common interrupt handler
_int_call_common:
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call _int_handler
pop ebx ; Reload the original data segment descriptor
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
popa ; Pops edi,esi,ebp...
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
iretd ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP