I am trying to set up interrupt handlers and get interrupts working in my operating system.
But I am having some problem due to which bochs restarts.
Following is the code for interrupt handlers
extern test_interrupt_handler
%macro isr 1
global int%1_handler
int%1_handler:
cli
pusha
push %1
call test_interrupt_handler
pop ax
popa
sti
iret
%endmacro
isr 0
isr 1
..
isr 31
I have defined handlers for all exceptions 0 through 31. Each handler pushes the interrupt number on stack and calls the function - test_interrupt_handler which is a C function that reads the interrupt number from stack and displays it.
The problem is that when I generate any exception from main using INT instruction , the corresponding handler runs but the system restarts after that. I thought that it must be one of the exceptions but none of handler gets called after the first handler. I know that the popping value into ax is causing the problem as when I comment it the code runs fine. But I was thinking that pusha and popa instructions should restore the ax back to its original value and there shouldn't be any problem. I am unable to understand the cause of the problem.void test_interrupt_handler(uint16 intrnum)
{
ConsoleWriteString("\nInterrupt Number: "); //print string
ConsoleWriteAsDec(intrnum); // print in decimal format
ConsoleWriteChar('\n'); //print character
}
Thanks