Page 1 of 1

which interrupt?

Posted: Sun Sep 14, 2003 1:08 pm
by mastermesh
how do i know which interrupt is firing?

i'm asking because i want to have a single function for all exceptions.

Re:which interrupt?

Posted: Mon Sep 15, 2003 1:17 am
by Pype.Clicker
you cannot tell if you have one single function. One thing you can do, however, is to have several "ISR points" that will push the number of the exception on the stack and then jump to the "common function".

Code: Select all

EXC0:
     push dword 0
     jmp _exception_handler
EXC1:
     push dword 1
     jmp _exception_handler
...
_exception_handler
     pushad
     ;; save data selectors and set them to a well-known value
     
     ;; here comes your "real" exception handler. It could for instance be
     push esp 
     call _C_written_exception_handler
     add esp,4

     ;; restore data registers
     popad
     add esp,4 ;; <-- remove the interrupt number from the stack.
     iretd
Please note that this will *not* work properly this way. Some exception have an error code, other doesn't. One thing you can do is to push first a "fake" 0 error code for exceptions that has no error code and replace "add esp,4" with "add esp,8".