What should an operating system interrupt handler do for interrupts related to coding mistakes?
For example, I tried to divide by 0 for testing my interrupt and my interrupt handler got called. However, because the div instruction was not successfully executed, EIP is not updated to the next instruction after it and after returning from the interrupt handler with iret
, it goes back to the erroneous div
instruction again.
mov ax, 3
mov dl, 0
div dl ; go back here again and again
What is the correct way to handle this interrupt? A few ways I thought of:
Change
dl
to something else other than 0. However, I'm not sure ifdl
can keep if something happens, and interrupt routine is supposed to restore registers after exit, and I don't think silently correct an error by providing wrong computation is good.Retrieve the next instruction after
div
. However, I haven't thought of any simple and reliable way to get the next instruction.Modify the top of the stack that is currently containing the return address to the address of some other code. So, we do not go back to
div
instruction anymore.
floating point exception
(compiled withgcc
) and stop the program. – Tu Do