Search code examples
assemblynasminterruptx86-16

Is it possible to exit from an ISR without returning to the calling code?


I am trying to create an Interrupt Service Routine in Assembly, which returns not to the location from the interrupt was called, but to an label.

Should i just jump to the label and not use iret (and any other interrupt-related instruction), or there is a specific method to do this?

For example:

[org 0x7c00]

; setting up ISR for int 69h (isr69h is the ISR)
; (i did it already, and worked fine with IRET, but i dont want to return to the caller)
; ...

int 69h ; test
; don't continue code from here

; some more code...

continue_from_here:
    jmp $

isr69h:
    ; do something
    jmp continue_from_here ; is it enough, or should i place here more code? (for example: restoring FLAGS etc.)

times 510-($-$$) db 0 ; padding
dw 0xAA55 ; boot signature

(i use netwide assembler)


Solution

  • Sure, there is no rule that you have to IRET. Once the interrupt handler is entered, it has control of the CPU and can do whatever it likes.

    Just a couple notes:

    • You will probably want to clean up the stack, removing the return address and flags, as well as perhaps whatever stack data was being used by the interrupted code that will not be resumed. You may want to simply reset the stack pointer to the top address of your stack space, effectively clearing the entire stack.

    • If this is a hardware interrupt, then the CPU disabled interrupts on entry to the handler. Normally the IRET would re-enable them as it restores FLAGS, so if you are not going to IRET, you will have to manually STI to re-enable interrupts when it is appropriate to do so.