软件生成的中断和软件生成的异常之间有什么区别? [英] What's the difference between Software-Generated Interrupt and Software-Generated Exception?

查看:122
本文介绍了软件生成的中断和软件生成的异常之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读英特尔手册3A第6章中断和异常处理.

I am reading the Intel Manual 3A Chapter 6 Interrupt and Exception Handling.

Interrupt和Exception分别具有3个来源.

Interrupt and Exception have 3 sources respectively.

对于软件产生的中断,它说:

For Software-Generated Interrupt, it says:

INT n指令允许从内部生成中断 软件通过提供一个中断向量号作为操作数来实现.为了 例如,INT 35指令强制隐式调用 中断35的中断处理程序.来自的任何中断向量 0至255可用作该指令中的参数.如果 使用了处理器的预定义NMI向量,但是, 处理器将与来自NMI的处理器不同 中断以正常方式生成.如果向量2(NMI 向量)用于此指令,则NMI中断处理程序为 被调用,但是处理器的NMI处理硬件未激活. 用INT n指令在软件中生成的中断不能 被EFLAGS寄存器中的IF标志掩盖.

The INT n instruction permits interrupts to be generated from within software by supplying an interrupt vector number as an operand. For example, the INT 35 instruction forces an implicit call to the interrupt handler for interrupt 35. Any of the interrupt vectors from 0 to 255 can be used as a parameter in this instruction. If the processor’s predefined NMI vector is used, however, the response of the processor will not be the same as it would be from an NMI interrupt generated in the normal manner. If vector number 2 (the NMI vector) is used in this instruction, the NMI interrupt handler is called, but the processor’s NMI-handling hardware is not activated. Interrupts generated in software with the INT n instruction cannot be masked by the IF flag in the EFLAGS register.

对于软件生成的异常,它表示:

For Software-Generated Exceptions, it says:

INTO,INT 3和BOUND指令允许例外 用软件生成.这些说明允许检查异常 指令流中各点要执行的条件.为了 例如,INT 3导致生成断点异常.廉政局 n指令可用于模拟软件中的异常;但是那里 是一个限制. 如果INT n为以下项之一提供向量 根据架构定义的异常,处理器会生成一个 中断到正确的向量(以访问异常处理程序),但是 不会将错误代码压入堆栈.即使 关联的硬件生成的异常通常会产生错误 代码.异常处理程序仍将尝试弹出错误代码 从堆栈中处理异常.因为没有错误代码 推送后,处理程序将弹出并丢弃EIP(原地 缺少的错误代码).这将错误返回 位置.

The INTO, INT 3, and BOUND instructions permit exceptions to be generated in software. These instructions allow checks for exception conditions to be performed at points in the instruction stream. For example, INT 3 causes a breakpoint exception to be generated. The INT n instruction can be used to emulate exceptions in software; but there is a limitation. If INT n provides a vector for one of the architecturally-defined exceptions, the processor generates an interrupt to the correct vector (to access the exception handler) but does not push an error code on the stack. This is true even if the associated hardware-generated exception normally produces an error code. The exception handler will still attempt to pop an error code from the stack while handling the exception. Because no error code was pushed, the handler will pop off and discard the EIP instead (in place of the missing error code). This sends the return to the wrong location.

那么,有什么区别?似乎两者都利用了int n指令.我怎么知道它是在一段汇编代码中生成异常还是中断?

So, what's the difference? Seems both leverage the int n instruction. How can I tell whether it generates an exception or an interrupt in a piece of assembly code?

推荐答案

在x86体系结构中,异常通常作为中断处理,使用中断处理程序处理.
因此,中断和异常是重叠的术语,后者是前者的一种.

In the x86 architecture an exception is handled as an interrupt, nominally with an interrupt handler.
So interrupts and exceptions are terms that overlaps, the latter are a kind of the former.

从0到31的中断号是为CPU异常保留的,例如,中断号0是#DE(除法错误),中断号13是#GP(常规保护).

Interrupt numbers from 0 to 31 are reserved for CPU exceptions, for example interrupt number 0 is the #DE (Divide error), interrupt number 13 is the #GP (General Protection).

当CPU检测到应该引发异常的条件(例如访问不存在的页面)时,它将执行一系列任务.

When the CPU detect a condition that should rise an exception (like an access to a non present page) it performs a series of tasks.

首先,如果需要,它会推送错误代码,某些异常(例如#PF和#GP)会出现,某些异常(例如#DE)不会.
英特尔的第6.15节手册2 列出了所有异常及其最终的错误代码.

First it pushes an error code if needed, some exceptions (like #PF and #GP) do, some (like #DE) don't.
The Section 6.15 of the Intel manual 2 lists all the exceptions with their eventual error code.

其次,它调用"适当的中断处理程序,这类似于远程调用,但将 EFLAGS 压入堆栈.

Secondly it "call" the appropriate interrupt handler which is like a far call but with EFLAGS pushed on the stack.

int n仅执行第二步,它调用中断,但不推送任何错误代码,因为首先硬件中没有错误情况(并且因为int n错误代码).
因此,它可以用来模拟异常,该软件最终必须推送适当的错误代码.

int n does only the second step, it calls an interrupt but doesn't push any error code as there is no error condition in the hardware in the first place (and because int n was there before the concept of error codes).
So it can be used to emulate exceptions, the software has to eventually push an appropriate error code.

当您在代码中看到int n时,它是从不,并且是异常.这是一个中断,最终用于将控制流引导到特定的OS异常处理程序中.

When you see int n in the code, it is never and exception. It is an interrupt, that eventually is used to steer the control flow into a particular OS exception handler.

琐事:int 3是特殊的,因为它被编码为CC,它只有一个字节(正常的int nCD imm8).这对于调试很有用,因为调试器可以将其放在代码段中的任何位置. into仅在 OF = 1 时生成#OF异常.

Trivia: int 3 is special because it is encoded as CC which is only one byte (normal int n is CD imm8). This is useful for debugging, since the debugger can put it anywhere in the code segment.
into only generate the #OF exception if OF = 1.

这篇关于软件生成的中断和软件生成的异常之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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