Software-Generated Exceptions

General

Software-generated exceptions fall into two categories:

  • Software exceptions generated as a result of an error condition detected while attempting execution of an instruction. The type of error condition defines the IDT entry that is vectored to.

  • Software exceptions deliberately generated by execution of special instruction types (e.g., INT and BOUND). Special exceptions are also generated by the INT nn, INTO, and INT3 instructions:

    - Execution of an INT nn instruction vectors to entry nn in the IDT.

    - Execution of an INTO instruction vectors to IDT entry four if EFlags[OF] = 1.

    - Execution of the INT3 instruction (the breakpoint instruction) vectors to IDT entry three.

    - Conditionally generated by the BOUND instruction if the indicated array index is not within the bounds of the indicated memory array (this causes the processor to vector to IDT entry five).

Faults, Traps, and Aborts

Due to a problem with the instruction itself or with an operand it attempts to access, the attempted execution of an instruction may result in the detection of an error condition. Problems of this nature are referred to as software exception conditions. When such a problem is detected, the processor invokes a special exception handler routine designed to attempt a graceful recovery from the respective exception condition.

The pointers to the various exception handlers are stored in dedicated entries in the IDT. Software exceptions are categorized as faults, traps, or aborts. These terms are defined in Table 14-2 on page 260. Table 14-3 on page 261 defines each software exception and identifies it as a fault, trap, or abort.

Table 14-2. Software Exception Types
TypeDefinition
FaultA fault is an exception reported at the start of the instruction that caused the exception. The fault is reported with the processor restored to a state that permits the instruction to be restarted (i.e., when all registers are restored to their original state prior to the attempted execution of the instruction). The return address stored in the stack points to the instruction that caused the fault, rather than to the next instruction.
TrapA trap is reported after the instruction that caused it has completed. The return address in the stack points to the instruction that follows the one that caused the exception. If the trap occurs during execution of an instruction that alters program flow (e.g., a jump instruction), the return address points to the branch target address (e.g., the address being jumped to). If the instruction is a string instruction and has a repeat prefix and the count has not been exhausted, the return address points to the same instruction and the values in the other registers related to the instruction contain the values for the next iteration.
AbortAn abort does not always reliably supply the address of the instruction that caused the exception. This makes it impossible for the exception handler to fix the problem and resume program execution.

Table 14-3. Exception Categories
VectorDescriptionType
0A Divide-By-Zero exception can be generated during execution of the DIV or IDIV instruction. A detailed description of this exception can be found in “Divide-by-Zero Exception (0)” on page 291.fault
1A debug exception caused by the detection of an instruction address breakpoint. A detailed description of this exception can be found in “Debug Exception (1)” on page 292.fault
A debug exception caused by the detection of a data address breakpoint.trap
A Debug exception caused by a General Detect condition. This occurs when an attempt is made to use the processor's debug registers when they are already in use by an in-circuit emulator (ICE).fault
A Debug exception caused by the single-step interrupt.trap
A Debug exception caused by a task-switch breakpoint.trap
2NMI is not a software exception.trap
3The INT3 instruction is also referred to as the Breakpoint instruction. Unlike the two-byte INT nn instruction, it is one byte long. A detailed description of this exception can be found in “Breakpoint Exception (3)” on page 294.trap
4Generated by the execution of the INTO instruction if EFlags[OF] = 1. Useful because the signed and unsigned arithmetic instructions cannot detect an overflow of the result. A detailed description of this exception can be found in “Overflow Exception (4)” on page 295.trap
5Generated by the BOUND instruction if the specified array index is not within the bounds of the specified memory array. A detailed description of this exception can be found in “Array Bounds Check Exception (5)” on page 296.fault
6Generated when an invalid opcode is detected upon the attempted execution of the instruction (instruction prefetch cannot cause this exception). Also generated when an invalid operand is used with an instruction (e.g., specifying a register as the target of a jump). Use of the LOCK prefix with instructions for which locking is not supported also causes this exception. A detailed description of this exception can be found in “Invalid OpCode Exception (6)” on page 297.fault
7The Device Not Available (DNA) exception is generated under two circumstances:
  • CR0[EM] = 1 (indicating that FPU is not present) and the ESC instruction is encountered (i.e., a FP instruction). This exception handler can be used to emulate the execution of FP instructions.

  • CR0[TS] = 1, CR0[MP] = 1, and a WAIT or ESC instruction is encountered. The FPU is about to execute an instruction associated with a new task after a task switch has occurred.

A detailed description of this exception can be found in “Device Not Available Exception (7)” on page 298.
fault
8

Double-fault encountered. The processor has encountered a fault while attempting to call an exception handler for a previously-encountered fault. Most of the time this can be handled by servicing the two exceptions serially, but some combinations are unrecoverable. Such combinations result in a double-fault exception. If a third exception occurs while the processor is attempting to call the double-fault handler, the processor generates the Special transaction to broadcast a Shutdown message and then enters the Shutdown state. A detailed description of this exception can be found in “Double Fault Exception (8)” on page 300.

abort
9The Coprocessor segment overrun abort is reserved in the post-386 processors. It was only generated by the 386 when a page or segment violation was detected during the transfer of an operand to or from memory. The later processors generate exception 13h instead (General Protection). A detailed description of this exception can be found in “Coprocessor Segment Overrun Exception (9)” on page 303.abort
10[*]

Invalid TSS fault. Generated if a task switch is attempted to a task with an invalid TSS. A detailed description of this exception can be found in “Invalid TSS Exception (10)” on page 304.

fault
11[*]

Segment Not Present. Generated when the selected segment descriptor (CS, DS, ES, FS, GS) has its P bit = 0. An SS descriptor with P = 0 results in a stack exception (number 12). A detailed description of this exception can be found in “Segment Not Present Exception (11)” on page 307.

fault
12Stack exception occurs for one of two reasons:
  • A Stack Underflow or Overflow error (in other words, too many pops or pushes).

  • An attempt to load the SS register with a selector for a descriptor marked not present (P = 0).

A detailed description of this exception can be found in “Stack Exception (12)” on page 308.
fault
13General Protection (GP) exception. All protection violations that don't cause another exception cause a GP exception. A detailed description of this exception can be found in “General Protection (GP) Exception (13)” on page 310.fault or trap
14[*]Page Fault exception. Occurs for one the following reasons:
  • Page Table or page is not present in memory (Page Directory Entry's P = 0, or Page Table Entry's P = 0).

  • Current program's CPL has insufficient privilege to access the page.

A detailed description of this exception can be found in “Page Fault Exception (14)” on page 313.
fault
15Reserved.n/a
16FP error exception. Error generated by the attempted execution of a FP math instruction. It can only occur when CR0[NE] = 1. A detailed description of this exception can be found in “FPU Exception (16)” on page 317.fault
17-31

Intel® reserved. Do not use. Note that some of these were subsequently implemented in later IA32 processors.

n/a
32-255Available for use by maskable hardware interrupts and the INT nn instruction.traps

[*] Note: These exceptions do not occur in Real Mode but may occur in VM86 mode.

Instruction Restart

When the processor generates any of the fault exceptions, it restores all of its registers to the state that they were in prior to the attempted execution of the instruction. The return address pushed onto the stack by the exception is therefore the CS:EIP value that points to the instruction that caused the fault. This permits the fault handler to examine the instruction in question and determine whether or not it can correct the problem and then re-execute the instruction successfully.

A classic example would be a Page Fault exception. This occurs because the target page of information is not currently present in memory. In the exception handler, the programmer could take the following actions:

  1. Read the page from mass storage into a physical page in memory.

  2. Create a Page Table Entry (PTE) mapping any address within the linear page to that physical page.

  3. Resume execution of the interrupted program at the instruction that caused the Page Fault exception.

When the instruction is re-executed, the access takes place successfully because the target page is now present in memory, resulting in a successful Page Table lookup and therefore a successful address translation.

Software Interrupt Instructions

The software interrupt instruction (INT nn) emulates the hardware interrupt mechanism. Consider the following example instruction (assume that the system is a PC running DOS):

INT 13h ;call disk bios routine

When this instruction is executed by the processor, the following events take place:

  1. The processor uses the immediate operand, 13h, as an index into the IDT.

  2. The processor reads the contents of IDT entry 13h (19d) from memory.

  3. The processor pushes the contents of its CS, EIP and EFlags registers onto the stack. This is necessary to save its place in the interrupted program, as well as saving the state of the interrupt enable bit (EFlags[IF]).

  4. The processor sets EFlags[IF] = 0 to disable recognition of external hardware interrupts.

  5. The processor jumps to the device-specific interrupt service routine pointed to by the IDT entry.

  6. At the end of the routine, an interrupt return (IRET) instruction is executed, causing the processor to pop the original CS, EIP and EFlags values from the stack and into their respective registers.

  7. The processor resumes execution of the interrupted program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.246