从中断返回的地方 [英] Where to return from an interrupt

查看:258
本文介绍了从中断返回的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读(并研究了)有关中断处理的信息.
我总是不明白的是,我们如何知道从中断处理程序返回到(PC/IP)的位置.
据我了解:

I've read (and studied) about Interrupt Handling.
What I always fail to understand, is how do we know where to return to (PC / IP) from the Interrupt Handler.
As I understand it:

  1. 中断是由设备(例如键盘)引起的
  2. 相关的处理程序称为-在运行过程中.即,不执行到OS的上下文切换.
  3. 中断处理程序完成,并将控制权传递回正在运行的应用程序.

上面描述的过程是我对中断处理的理解,发生在当前正在运行的过程的上下文中.因此,它类似于方法调用,而不是上下文切换.
但是,由于我们实际上没有向中断处理程序发出CALL,因此我们没有机会将当前IP推送到堆栈.
那么我们如何知道从中断跳回哪里.我很困惑.

The process depicted above, which is my understanding of Interrupt Handling, takes place within the current running process' context. So it's akin to a method call, rather than to a context switch.
However, being that we didn't actually make the CALL to the Interrupt Handler, we didn't have a chance to push the current IP to the stack.
So how do we know where to jump back from an Interrupt. I'm confused.

希望您能提供任何解释,包括单行代码,它们只是指向一个很好的pdf/ppt,专门用于解决此问题.
[我通常指的是Linux和C代码下的上述过程-但欢迎所有好的答案]

Would appreciate any explanation, including one-liners that simply point to a good pdf/ppt addressing this question specifically.
[I'm generally referring to above process under Linux and C code - but all good answers are welcomed]

推荐答案

触发中断时,CPU将几个寄存器压入堆栈,包括在中断之前执行的代码的指令指针(EIP).您可以在iret和ISR的末尾放置这些值,并恢复EIP(以及CS,EFLAGS,SS和ESP).

When an interrupt is triggered, the CPU pushes several registers onto the stack, including the instruction pointer (EIP) of the code that was executing before the interrupt. You can put iret and the end of your ISR to pop these values, and restore EIP (as well as CS, EFLAGS, SS and ESP).

顺便说一句,中断不一定是由设备触发的.在Linux和DOS中,用户空间程序使用中断(通过int)进行系统调用.一些内核代码使用中断,例如,故意三重错误以强制关闭.

By the way, interrupts aren't necessarily triggered by devices. In Linux and DOS, user space programs use interrupts (via int) to make system calls. Some kernel code uses interrupts, for example intentionally triple faulting in order to force a shutdown.

这篇关于从中断返回的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆