Chapter 9 Exceptions and Interrupts

9章 异常和中断

Interrupts and exceptions are special kinds of control transfer; they work somewhat like unprogrammed CALLs. They alter the normal program flow to handle external events or to report errors or exceptional conditions. The difference between interrupts and exceptions is that interrupts are used to handle asynchronous events external to the processor, but exceptions handle conditions detected by the processor itself in the course of executing instructions.

中断和异常是特殊的控制转移;他们的工作方式有点象不是预先编程好的CALL调用。他们改变程序流程来处理外部事件或来报告错误和异常的环境。中断和异常的不同之处在于中断被用来处理处理器外部的异步事件,而异常处理的是处理器自身在执行指令期间侦测到的状况。

There are two sources for external interrupts and two sources for exceptions:

外部中断和异常的两个来源:

  1. Interrupts 中断
  • Maskable interrupts, which are signalled via the INTR pin.

可屏蔽的中断,通过INTR引脚来发送信号。

  • Nonmaskable interrupts, which are signalled via the NMI (Non-Maskable Interrupt) pin.

不可屏蔽中断,通过NMI引脚来发送信号。

  1. Exceptions 异常
  • Processor detected. These are further classified as faults, traps, and aborts.

处理器侦测到的。进一步分类为错误、陷阱和忽略。

  • Programmed. The instructions INTOINT 3, INT n, and BOUND can trigger exceptions. These instructions are often called "software interrupts", but the processor handles them as exceptions.

程序化的。指令INT0、INT3、INTn以及BOUND,可以触发异常。这些指令经常被叫做“软件中断”,但处理器把它们做为异常处理。

This chapter explains the features that the 80386 offers for controlling and responding to interrupts when it is executing in protected mode.

本章解释当在保护模式下运行时,80386提供的用来控制和回应中断的特性。

9.1 Identifying Interrupts 标识中断

The processor associates an identifying number with each different type of interrupt or exception.

处理器将每个不同类型的中断或异常和标识数值联系起来。

The NMI and the exceptions recognized by the processor are assigned predetermined identifiers in the range 0 through 31. Not all of these numbers are currently used by the 80386; unassigned identifiers in this range are reserved by Intel for possible future expansion.

处理器识别的NMI和异常被用预先定义的0到31个数值来标识。当前80386没有使用所有的这些数值;在这个范围中未分配的标识被保留给将来使用。

The identifiers of the maskable interrupts are determined by external interrupt controllers (such as Intel's 8259A Programmable Interrupt Controller) and communicated to the processor during the processor's interrupt-acknowledge sequence. The numbers assigned by an 8259A PIC can be specified by software. Any numbers in the range 32 through 255 can be used. Table 9-1 shows the assignment of interrupt and exception identifiers.

外部中断控制器(例如英特8259A可编程中断控制器)决定可屏蔽中断的标识,并在处理器的中断确认周期中与处理器通信。8259A PIC分配的数值可以被软件指定。任何32与255之间的数值都可以使用。表9-1展示了中断与异常标识的分配。

Table 9-1. Interrupt and Exception ID Assignments

Identifier   Description

0            Divide error 除法错误

1            Debug exceptions 调试异常

2            Nonmaskable interrupt 不可屏蔽中断

3            Breakpoint (one-byte INT 3 instruction) 断点(一个字节的INT3指令)

4            Overflow (INTO instruction) 溢出(INTO指令)

5            Bounds check (BOUND instruction)边界检验(BOUND指令)

6            Invalid opcode 非法操作符

7            Coprocessor not available 协处理器不可用

8            Double fault 双重错误

9            (reserved) (保留)

10           Invalid TSS 无效的TSS

11           Segment not present 段不存在

12           Stack exception 栈异常

13           General protection 一般性保护

14           Page fault 页错误

15           (reserved) (保留)

16           Coprecessor error 协处理器错误

17-31        (reserved) (保留)

32-255       Available for external interrupts via INTR pin 对通过INTR引脚触发的外部中断有效

Exceptions are classified as faults, traps, or aborts depending on the way they are reported and whether restart of the instruction that caused the exception is supported.

按照被报告方式和是否支持重新运行引起异常的指令,异常被分为错误、陷阱或忽略。

Faults 错误

Faults are exceptions that are reported "before" the instruction causing the exception. Faults are either detected before the instruction begins to execute, or during execution of the instruction. If detected during the instruction, the fault is reported with the machine restored to a state that permits the instruction to be restarted.

错误是指令引发异常之前就被报告的异常。错误即可以在指令执行前被侦测,也可以在执行执行期间被侦测。如果在执行期间侦测到,错误被报告时,机器保存状态以允许指令被重新执行。

Traps 陷阱

A trap is an exception that is reported at the instruction boundary immediately after the instruction in which the exception was detected.

(真不会翻译了。)

Aborts 忽略

An abort is an exception that permits neither precise location of the instruction causing the exception nor restart of the program that caused the exception. Aborts are used to report severe errors, such as hardware errors and inconsistent or illegal values in system tables.

忽略异常即不精确定位指点发异常的指令,也不重新运行引发异常的程序。忽略用来报告严重错误,如硬件错误和系统表中不一致或非法的值。

9.2 Enabling and Disabling Interrupts

The processor services interrupts and exceptions only between the end of one instruction and the beginning of the next. When the repeat prefix is used to repeat a string instruction, interrupts and exceptions may occur between repetitions. Thus, operations on long strings do not delay interrupt response.

处理器仅在一条指令结束与下一条指令开始前才响应中断和异常。(换言之,处理器仅在两条指令之间才响应中断和异常。)当使用重复前缀来重复一个字符串指令时,中断和异常可以发生在两个重复之间。这样,长的字符串操作不会延迟中断响应。

Certain conditions and flag settings cause the processor to inhibit certain interrupts and exceptions at instruction boundaries.

某此条件和标志的设定会导致处理器禁止某些特定中断和异常在指令边界发生。

9.2.1 NMI Masks Further NMIs 

NMI屏蔽进一步的NMI信号

While an NMI handler is executing, the processor ignores further interrupt signals at the NMI pin until the next IRET instruction is executed.

当NMI处理器运行时,处理器忽略NMI引脚上进一步的中断信号,直到下一个IRET指令被执行。(换言之,NMI不能嵌套处理。)

9.2.2 IF Masks INTR 

IF位屏蔽INTR

The IF (interrupt-enable flag) controls the acceptance of external interrupts signalled via the INTR pin. When IF=0, INTR interrupts are inhibited; when IF=1, INTR interrupts are enabled. As with the other flag bits, the processor clears IF in response to a RESET signal. The instructions CLI and STI alter the setting of IF.

IF(中断使能标志)控制着是否接受外部中断通过INTR引脚发送的信号。当IF为0时,INTR中断被禁止;当IF等于1时,INTR中断被激活。和其他标志位一起,处理器在响应REST信号时清除IF标志。指令CLI和STI变更IF的设置。

CLI (Clear Interrupt-Enable Flag) and STI (Set Interrupt-Enable Flag) explicitly alter IF (bit 9 in the flag register). These instructions may be executed only if CPL <= IOPL. A protection exception occurs if they are executed when CPL > IOPL.

CLI(清除中断使能标志)和STI(设置中断使能标志)仅更改IF(标志寄存器的第9位)。这些指令只能在CPL小于或等于IOPL时被执行。当CPL大于IOPL时这些指令的执行会引发保护异常。

The IF is also affected implicitly by the following operations:

IF也会隐式地受以下操作影响:

  • The instruction PUSHF stores all flags, including IF, in the stack where they can be examined.

指令PUSHF将所有标志(包括IF)保存在栈内(在那里他们可以被检查)。

  • Task switches and the instructions POPF and IRET load the flags register; therefore, they can be used to modify IF.

任务切换和指令POPF及IRET装入标志寄存器;因此,他们也用来修改IF。

  • Interrupts through interrupt gates automatically reset IF, disabling interrupts. (Interrupt gates are explained later in this chapter.)

通过中断门的中断自动重置IF位,关闭中断。(中断门在本章后面会解释。)

9.2.3 RF Masks Debug Faults RF屏蔽调试错误

The RF bit in EFLAGS controls the recognition of debug faults. This permits debug faults to be raised for a given instruction at most once, no matter how many times the instruction is restarted . (Refer to Chapter 12 for more information on debugging.)

EFLAGS中的RF位控制是否识别调试错误。这允许给定的指令最多引发一次调试错误,不管指令重复执行多少次。(参见第12章调试的更多信息)

9.2.4 MOV or POP to SS Masks Some Interrupts and Exceptions

对SS的MOV或POP屏蔽某此中断和异常

Software that needs to change stack segments often uses a pair of instructions; for example:

软件需要使用一对指令来修改栈段;例如:

MOV SS, AX 将AX的内容移给SS寄存器(修改栈段,指向一个新段)

MOV ESP, StackTop 将栈顶数据弹出给ESP(修改栈指针,以指向一个新段的栈顶)

If an interrupt or exception is processed after SS has been changed but before ESP has received the corresponding change, the two parts of the stack pointer SS:ESP are inconsistent for the duration of the interrupt handler or exception handler.

如果在SS被修改之后,ESP接收到一个相应的修改之前,中断或异常被处理,中断或异常处理期间,栈的SS:ESP这对指针将不再一致。

To prevent this situation, the 80386, after both a MOV to SS and a POP to SS instruction, inhibits NMI, INTR, debug exceptions, and single-step traps at the instruction boundary following the instruction that changes SS. Some exceptions may still occur; namely, page fault and general protection fault. Always use the 80386LSS instruction, and the problem will not occur.

为避免这种情况发生,在将栈段移入SS(使用MOV指令)和弹出栈数据到SS(使用POP指令)这两个指令之后,80386在下面修改SS的指令边界上,禁止NMI、INTR、调试异常和单步陷阱。一些异常依旧会发生;一般来说,页错误和一般保护性错误可以发生。80386总是使用LSS指令,这样这些问题不会发生。

9.3 Priority Among Simultaneous Interrupts and Exceptions

同时发生中断和异常时的优先级

If more than one interrupt or exception is pending at an instruction boundary, the processor services one of them at a time. The priority among classes of interrupt and exception sources is shown in Table 9-2. The processor first services a pending interrupt or exception from the class that has the highest priority, transferring control to the first instruction of the interrupt handler. Lower priority exceptions are discarded; lower priority interrupts are held pending. Discarded exceptions will be rediscovered when the interrupt handler returns control to the point of interruption.

如果在一个指令边界有多个中断或异常被挂起,处理器在一个时间里只能处理它们中的一个。表9-2展示了按来源分类的中断和异常的优先级。

Table 9-2. Priority Among Simultaneous Interrupts and Exceptions

Priority   Class of Interrupt or Exception

优先级中断或异常的分类

HIGHEST Faults except debug faults

最高级 错误异常 调试错误

Trap instructions INTO, INT n, INT 3

陷阱指令 INTO、INTn、INT3

Debug traps for this instruction

对指令使用的调试陷阱

Debug faults for next instruction

对下一条指令的调试错误

NMI interrupt

NMI中断

LOWEST      INTR interrupt

最低 INTR中断

【译】x86程序员手册31- 第9章 异常和中断的更多相关文章

  1. 【译】x86程序员手册10 - 第4章系统架构

    1.1.2 Part II -- Systems Programming 系统编程 This part presents those aspects of the architecture that ...

  2. 【译】x86程序员手册01

    Intel 80386 Reference Programmer's Manual 80386程序员参考手册 Chapter 1 -- Introduction to the 80386 第1章 - ...

  3. 【译】x86程序员手册38-10.2实在址模式下的软件初始化

    10.2 Software Initialization for Real-Address Mode   实地址模式的软件初始化 In real-address mode a few structur ...

  4. 【译】x86程序员手册30-8.2 I/O指令

    8.2 I/O Instructions I/O指令 The I/O instructions of the 80386 provide access to the processor's I/O p ...

  5. 【译】x86程序员手册20-6.3.4门描述符守卫程序入口

    6.3.4 Gate Descriptors Guard Procedure Entry Points 门描述符守卫程序入口 To provide protection for control tra ...

  6. 【译】x86程序员手册03 - 2.1内存组织和分段

    2.1 Memory Organization and Segmentation 内存组织和分段 The physical memory of an 80386 system is organized ...

  7. 【译】x86程序员手册26-7.5任务切换

    7.5 Task Switching 任务切换 The 80386 switches execution to another task in any of four cases: 80386在以下四 ...

  8. 【译】x86程序员手册19-6.3.2数据访问的约束

    6.3.2 Restricting Access to Data  数据访问的约束 To address operands in memory, an 80386 program must load ...

  9. 【译】x86程序员手册08 -2.6中断和异常

    2.6 Interrupts and Exceptions 中断和异常 The 80386 has two mechanisms for interrupting program execution: ...

随机推荐

  1. NA交换②

    虚拟局域网VLAN的核心目的:     将一个大的网络划分为小的网络,也称为网络分片(Segementation):一个VLAN对应着一个广播域,最好对应一个网络子网(为VLAN间的路由作准备).   ...

  2. struts1与struts2的差别

     Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架.其全新的Struts 2的体系结构与Struts 1的体系结 ...

  3. spring中编程式事务控制

    step1:配置xml文件 <!-- 事务管理bean --> <bean id="transactionManager" class="org.spr ...

  4. js 判断手机横竖屏的实现方法(不依赖任何其他库)

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  5. luogu 4429 染色

    bjoi 2018 染色 推了个错误结论得了60分? 题目大意: 一个无重边和自环的无向图,并且对每个点分别给了一个大小为2的颜色集合,只能从这个集合中选一种颜色给这个点染色 求一个染色方案使得没有两 ...

  6. window系统 查看端口 被哪个进程占用了

    一.在windows命令行窗口下执行:运行--cmdC:\>netstat -aon|findstr "8080" TCP     127.0.0.1:80       0. ...

  7. hdu4292 Food 最大流模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:水和饮料,建图跑最大流模板. 我用的是学长的模板,最然我还没有仔细理解,不过这都不重要直接 ...

  8. SQL常用指令集(Oracle)

    1. Select rownum(oracle) top(mysql): 用于规定返回指定数目的值 Where roenum < number 2. Like 用于在where子句搜索指定模式 ...

  9. Linux上安装禅道

    linux一键安装包内置了apache, php, mysql这些应用程序,只需要下载解压缩即可运行禅道. 从7.3版本开始,linux一键安装包分为32位和64位两个包,请大家根据操作系统的情况下载 ...

  10. Java多线程(二) synchronized 针对对象进行锁定

    http://www.cnblogs.com/QQParadise/articles/5059824.html 1.方法内的变量为线程安全的 2.实例变量非线程安全的 public class Has ...