在中断服务程序(ISR)中是否可能在不返回到调用代码的情况下退出?

huangapple go评论79阅读模式
英文:

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

问题

我正在尝试在汇编语言中创建一个中断服务例程(Interrupt Service Routine),它不返回到调用中断的位置,而是返回到一个标签。

我应该直接跳转到该标签,而不使用iret(或其他与中断相关的指令),还是有特定的方法可以实现这一点?

例如:

[org 0x7c00]

; 为 int 69h 设置 ISR(isr69h 是 ISR)
; (我已经完成了这一步,并且使用 IRET 运行良好,但我不想返回给调用者)
; ...

int 69h ; 测试
; 从这里不要继续执行代码

; 更多代码...

continue_from_here:
    jmp $

isr69h:
    ; 做一些操作
    jmp continue_from_here ; 这样足够了吗?还是我应该在这里放置更多的代码?(例如:恢复 FLAGS 等)

times 510-($-$$) db 0 ; 填充
dw 0xAA55 ; 引导标志

(我使用的是 Netwide Assembler)

英文:

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)

答案1

得分: 4

当然,没有规定你必须使用IRET指令。一旦进入中断处理程序,它就控制着CPU,可以执行任何操作。

以下是一些建议:

  • 你可能需要清理堆栈,删除返回地址和标志位,以及中断代码使用的堆栈数据,因为这些数据将不会被恢复。你可以将堆栈指针重置为堆栈空间的顶部地址,从而清空整个堆栈。

  • 如果这是一个硬件中断,那么CPU在进入处理程序时会禁用中断。通常,IRET指令会在恢复FLAGS时重新启用中断,所以如果你不使用IRET指令,当适当时你需要手动使用STI指令重新启用中断。

英文:

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.

huangapple
  • 本文由 发表于 2023年8月9日 01:28:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定