Interrupt handling
Interrupt handling
In x86 assembly, how do you handle interrupts called by the CPU? Same principles of a try...catch statement in C. For instance, how would I catch the int 0h (divide by zero) thrown by the CPU?
IDT
[EDIT:]It's not really the same as try..catch - your program flow will be redirected and may then return after the exception. For exception handling of the try...catch type, you will need to port libstdc++ or something similar.
@Mods: This should be in the OS development forum
[/EDIT]
[EDIT:]It's not really the same as try..catch - your program flow will be redirected and may then return after the exception. For exception handling of the try...catch type, you will need to port libstdc++ or something similar.
@Mods: This should be in the OS development forum
[/EDIT]
Sorry to semi-hijack this thread, seems wrong to create a new thread with pretty much the same title and the reply to my question might be useful to the OP anyway...
Are there any decent tutorials on x86-64 interrupts? Or does anyone have links to some code that works? I'm playing about with the div-by-zero exception but I can't get it to return using iret. Bochs gives me an error about having a null code segment. AFAIK the CS is pushed onto the stack when the interrupt handler is called, and then the iret should pop it off again before returning. When I step through up until the iret instruction and look at the stack memory, everything seems fine. I can see the correct CS value on the stack. A Bochs bug maybe?
Note: I realise I need more code in the handler to set the correct return address, at the moment I'm just trying to get it to throw the exception infinitely as a test.
Are there any decent tutorials on x86-64 interrupts? Or does anyone have links to some code that works? I'm playing about with the div-by-zero exception but I can't get it to return using iret. Bochs gives me an error about having a null code segment. AFAIK the CS is pushed onto the stack when the interrupt handler is called, and then the iret should pop it off again before returning. When I step through up until the iret instruction and look at the stack memory, everything seems fine. I can see the correct CS value on the stack. A Bochs bug maybe?
Note: I realise I need more code in the handler to set the correct return address, at the moment I'm just trying to get it to throw the exception infinitely as a test.
Hi,
I only consider myself to be a 64 bit newbie, but have a look at http://www.amd.com/us-en/assets/content ... erview.pdf if you haven't seen it already.
Cheers,
Adam
I only consider myself to be a 64 bit newbie, but have a look at http://www.amd.com/us-en/assets/content ... erview.pdf if you haven't seen it already.
Cheers,
Adam
Double check that you remove the error-code from the stack before attempting to IRET.didroe wrote: Are there any decent tutorials on x86-64 interrupts? Or does anyone have links to some code that works? I'm playing about with the div-by-zero exception but I can't get it to return using iret. Bochs gives me an error about having a null code segment. AFAIK the CS is pushed onto the stack when the interrupt handler is called, and then the iret should pop it off again before returning. When I step through up until the iret instruction and look at the stack memory, everything seems fine. I can see the correct CS value on the stack. A Bochs bug maybe?
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
I've fixed it now, turned out the compiler I was using was inserting a 32 bit iret instruction. I switched to something different and then got an error in Bochs saying "SS AR must be writable data segment" (or words to that effect). Ended up having to fix a bug in Bochs. It's been a long day just fixing one line of code!