which interrupt?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mastermesh

which interrupt?

Post by mastermesh »

how do i know which interrupt is firing?

i'm asking because i want to have a single function for all exceptions.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:which interrupt?

Post 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".
Post Reply