Exceptions: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
(Added hex numbers for exceptions. Make cross referencing easier) |
||
Line 18: | Line 18: | ||
|- |
|- |
||
! [[#Divide-by-zero Error|Divide-by-zero Error]] |
! [[#Divide-by-zero Error|Divide-by-zero Error]] |
||
| 0 |
| 0 (0x0) |
||
| Fault |
| Fault |
||
| #DE |
| #DE |
||
Line 24: | Line 24: | ||
|- |
|- |
||
! [[#Debug|Debug]] |
! [[#Debug|Debug]] |
||
| 1 |
| 1 (0x1) |
||
| Fault/Trap |
| Fault/Trap |
||
| #DB |
| #DB |
||
Line 30: | Line 30: | ||
|- |
|- |
||
! [[Non Maskable Interrupt|Non-maskable Interrupt]] |
! [[Non Maskable Interrupt|Non-maskable Interrupt]] |
||
| 2 |
| 2 (0x2) |
||
| Interrupt |
| Interrupt |
||
| - |
| - |
||
Line 36: | Line 36: | ||
|- |
|- |
||
! [[#Breakpoint|Breakpoint]] |
! [[#Breakpoint|Breakpoint]] |
||
| 3 |
| 3 (0x3) |
||
| Trap |
| Trap |
||
| #BP |
| #BP |
||
Line 42: | Line 42: | ||
|- |
|- |
||
! [[#Overflow|Overflow]] |
! [[#Overflow|Overflow]] |
||
| 4 |
| 4 (0x4) |
||
| Trap |
| Trap |
||
| #OF |
| #OF |
||
Line 48: | Line 48: | ||
|- |
|- |
||
! [[#Bound Range Exceeded|Bound Range Exceeded]] |
! [[#Bound Range Exceeded|Bound Range Exceeded]] |
||
| 5 |
| 5 (0x5) |
||
| Fault |
| Fault |
||
| #BR |
| #BR |
||
Line 54: | Line 54: | ||
|- |
|- |
||
! [[#Invalid Opcode|Invalid Opcode]] |
! [[#Invalid Opcode|Invalid Opcode]] |
||
| 6 |
| 6 (0x6) |
||
| Fault |
| Fault |
||
| #UD |
| #UD |
||
Line 60: | Line 60: | ||
|- |
|- |
||
! [[#Device Not Available|Device Not Available]] |
! [[#Device Not Available|Device Not Available]] |
||
| 7 |
| 7 (0x7) |
||
| Fault |
| Fault |
||
| #NM |
| #NM |
||
Line 66: | Line 66: | ||
|- |
|- |
||
! [[#Double Fault|Double Fault]] |
! [[#Double Fault|Double Fault]] |
||
| 8 |
| 8 (0x8) |
||
| Abort |
| Abort |
||
| #DF |
| #DF |
||
Line 72: | Line 72: | ||
|- |
|- |
||
! Coprocessor Segment Overrun |
! Coprocessor Segment Overrun |
||
| 9 |
| 9 (0x9) |
||
| Fault |
| Fault |
||
| - |
| - |
||
Line 78: | Line 78: | ||
|- |
|- |
||
! [[#Invalid TSS|Invalid TSS]] |
! [[#Invalid TSS|Invalid TSS]] |
||
| 10 |
| 10 (0xA) |
||
| Fault |
| Fault |
||
| #TS |
| #TS |
||
Line 84: | Line 84: | ||
|- |
|- |
||
! [[#Segment Not Present|Segment Not Present]] |
! [[#Segment Not Present|Segment Not Present]] |
||
| 11 |
| 11 (0xB) |
||
| Fault |
| Fault |
||
| #NP |
| #NP |
||
Line 90: | Line 90: | ||
|- |
|- |
||
! [[#Stack-Segment Fault|Stack-Segment Fault]] |
! [[#Stack-Segment Fault|Stack-Segment Fault]] |
||
| 12 |
| 12 (0xC) |
||
| Fault |
| Fault |
||
| #SS |
| #SS |
||
Line 96: | Line 96: | ||
|- |
|- |
||
! [[#General Protection Fault|General Protection Fault]] |
! [[#General Protection Fault|General Protection Fault]] |
||
| 13 |
| 13 (0xD) |
||
| Fault |
| Fault |
||
| #GP |
| #GP |
||
Line 102: | Line 102: | ||
|- |
|- |
||
! [[#Page Fault|Page Fault]] |
! [[#Page Fault|Page Fault]] |
||
| 14 |
| 14 (0xE) |
||
| Fault |
| Fault |
||
| #PF |
| #PF |
||
Line 108: | Line 108: | ||
|- |
|- |
||
! Reserved |
! Reserved |
||
| 15 |
| 15 (0xF) |
||
| - |
| - |
||
| - |
| - |
||
Line 114: | Line 114: | ||
|- |
|- |
||
! [[#x87 Floating-Point Exception|x87 Floating-Point Exception]] |
! [[#x87 Floating-Point Exception|x87 Floating-Point Exception]] |
||
| 16 |
| 16 (0x10) |
||
| Fault |
| Fault |
||
| #MF |
| #MF |
||
Line 120: | Line 120: | ||
|- |
|- |
||
! [[#Alignment Check|Alignment Check]] |
! [[#Alignment Check|Alignment Check]] |
||
| 17 |
| 17 (0x11) |
||
| Fault |
| Fault |
||
| #AC |
| #AC |
||
Line 126: | Line 126: | ||
|- |
|- |
||
! [[#Machine Check|Machine Check]] |
! [[#Machine Check|Machine Check]] |
||
| 18 |
| 18 (0x12) |
||
| Abort |
| Abort |
||
| #MC |
| #MC |
||
Line 132: | Line 132: | ||
|- |
|- |
||
! [[#SIMD Floating-Point Exception|SIMD Floating-Point Exception]] |
! [[#SIMD Floating-Point Exception|SIMD Floating-Point Exception]] |
||
| 19 |
| 19 (0x13) |
||
| Fault |
| Fault |
||
| #XM/#XF |
| #XM/#XF |
||
Line 138: | Line 138: | ||
|- |
|- |
||
! Reserved |
! Reserved |
||
| 20-29 |
| 20-29 (0x14-0x1D) |
||
| - |
| - |
||
| - |
| - |
||
Line 144: | Line 144: | ||
|- |
|- |
||
! [[#Security Exception|Security Exception]] |
! [[#Security Exception|Security Exception]] |
||
| 30 |
| 30 (0x1E) |
||
| - |
| - |
||
| #SX |
| #SX |
||
Line 150: | Line 150: | ||
|- |
|- |
||
! Reserved |
! Reserved |
||
| 31 |
| 31 (0x1F) |
||
| - |
| - |
||
| - |
| - |
Revision as of 19:02, 20 December 2012
Exceptions as described in this article are generated by the CPU when an 'error' occurs. Some exceptions are not really errors in most cases, such as page faults. Exceptions are a type of interrupt.
Exceptions are classified as:
- Faults: These can be corrected and the program may continue as if nothing happened.
- Traps: Traps are reported immediately after the execution of the trapping instruction.
- Aborts: Some severe unrecoverable error.
Name | Vector nr. | Type | Mnemonic | Error code? |
---|---|---|---|---|
Divide-by-zero Error | 0 (0x0) | Fault | #DE | No |
Debug | 1 (0x1) | Fault/Trap | #DB | No |
Non-maskable Interrupt | 2 (0x2) | Interrupt | - | No |
Breakpoint | 3 (0x3) | Trap | #BP | No |
Overflow | 4 (0x4) | Trap | #OF | No |
Bound Range Exceeded | 5 (0x5) | Fault | #BR | No |
Invalid Opcode | 6 (0x6) | Fault | #UD | No |
Device Not Available | 7 (0x7) | Fault | #NM | No |
Double Fault | 8 (0x8) | Abort | #DF | Yes |
Coprocessor Segment Overrun | 9 (0x9) | Fault | - | No |
Invalid TSS | 10 (0xA) | Fault | #TS | Yes |
Segment Not Present | 11 (0xB) | Fault | #NP | Yes |
Stack-Segment Fault | 12 (0xC) | Fault | #SS | Yes |
General Protection Fault | 13 (0xD) | Fault | #GP | Yes |
Page Fault | 14 (0xE) | Fault | #PF | Yes |
Reserved | 15 (0xF) | - | - | No |
x87 Floating-Point Exception | 16 (0x10) | Fault | #MF | No |
Alignment Check | 17 (0x11) | Fault | #AC | Yes |
Machine Check | 18 (0x12) | Abort | #MC | No |
SIMD Floating-Point Exception | 19 (0x13) | Fault | #XM/#XF | No |
Reserved | 20-29 (0x14-0x1D) | - | - | No |
Security Exception | 30 (0x1E) | - | #SX | No |
Reserved | 31 (0x1F) | - | - | No |
Triple Fault | - | - | - | No |
Exceptions
Faults
Divide-by-zero Error
The Divide-by-zero Error occurs when dividing any number by 0 using the DIV or IDIV instruction. Many OS developers use this exception to test whether their exception handling code works. This exception may also occur when the result is too large to be represented in the destination.
The saved instruction pointer points to the DIV or IDIV instruction which caused the exception.
Bound Range Exceeded
This exception can occur when the BOUND instruction is executed. The BOUND instruction compares an array index with the lower and upper bounds of an array. When the index is out of bounds, the Bound Range Exceeded exception occurs.
The saved instruction pointer points to the BOUND instruction which caused the exception.
Invalid Opcode
The Invalid Opcode exception occurs when the processor tries to execute an invalid or undefined opcode, or an instruction with invalid prefixes. It also occurs when an instruction exceeds 15 bytes, but this only occurs with redundant prefixes.
The saved instruction pointer points to the instruction which caused the exception.
Device Not Available
The Device Not Available exception occurs when an FPU instruction is attempted but there is no FPU. This is not likely, as modern processors have built-in FPUs. However, there are flags in the CR0 register that disable the FPU/MMX/SSE instructions, causing this exception when they are attempted. This feature is useful because the operating system can detect when a user program uses the FPU or XMM registers and then save/restore them appropriately when multitasking.
The saved instruction pointer points to the instruction that caused the exception.
Invalid TSS
An Invalid TSS exception occurs when an invalid segment selector is referenced as part of a task which, or as a result of a control transfer through a gate descriptor, which results in an invalid stack-segment reference using an SS selector in the TSS.
When the exception occurred before loading the segment selectors from the TSS, the saved instruction pointer points to the instruction which caused the exception. Otherwise, and this is more common, it points to the first instruction in the new task.
Error code: The Invalid TSS exception sets an error code, which is a selector index.
Segment Not Present
The Segment Not Present exception occurs when trying to load a segment or gate which has it's Present-bit set to 0. However when loading a stack-segment selector which references a descriptor which is not present, a Stack-Segment Fault occurs.
The saved instruction pointer points to the instruction which caused the exception.
Error code: The Segment Not Present exception sets an error code, which is the segment selector index of the segment descriptor which caused the exception.
Stack-Segment Fault
The Stack-Segment Fault occurs when:
- Loading a stack-segment referencing a segment descriptor which is not present.
- Any PUSH or POP instruction or any instruction using ESP or EBP as a base register is executed, while the stack address is not in canonical form.
- When the stack-limit check fails.
The saved instruction pointer points to the instruction which caused the exception.
Error code: The Stack-Segment Fault sets an error code, which is the stack segment selector index when a non-present segment descriptor was referenced. Otherwise, 0.
General Protection Fault
A General Protection Fault may occur for various reasons. The most common are:
- Segment error (privilege, type, limit, read/write rights).
- Executing a privileged instruction while CPL != 0.
- Writing a 1 in a reserved register field.
- Referencing or accessing a null-descriptor.
The saved instruction pointer points to the instruction which caused the exception.
Error code: The General Protection Fault sets an error code, which is the segment selector index when the exception is segment related. Otherwise, 0.
Page Fault
- Main article: Page fault
A Page Fault occurs when:
- A page directory or table entry is not present in physical memory.
- Attempting to load the instruction TLB with a translation for a non-executable page.
- A protection check (privileges, read/write) failed.
- A reserved bit in the page directory or table entries is set to 1.
The saved instruction pointer points to the instruction which caused the exception.
Error code
The Page Fault sets an error code:
31 4 0 +---+-- --+---+---+---+---+---+---+ | Reserved | I | R | U | W | P | +---+-- --+---+---+---+---+---+---+
Length | Name | Description | |
---|---|---|---|
P | 1 bit | Present | When set, the page fault was caused by a page-protection violation. When not set, it was caused by a non-present page. |
W | 1 bit | Write | When set, the page fault was caused by a page write. When not set, it was caused by a page read. |
U | 1 bit | User | When set, the page fault was caused while CPL = 3. This does not necessarily mean that the page fault was a privilege violation. |
R | 1 bit | Reserved write | When set, the page fault was caused by reading a 1 in a reserved field. |
I | 1 bit | Instruction Fetch | When set, the page fault was caused by an instruction fetch. |
In addition, it sets the value of the CR2 register to the virtual address which caused the Page Fault.
x87 Floating-Point Exception
The x87 Floating-Point Exception occurs when the FWAIT or WAIT instruction, or any waiting floating-point instruction is executed, and the following conditions are true:
- CR0.NE is 1;
- an unmasked x87 floating point exception is pending (i.e. the exception bit in the x87 floating point status-word register is set to 1).
The saved instruction pointer points to the instruction which is about to be executed when the exception occurred. The x87 instruction pointer register contains the address of the last instruction which caused the exception.
Error Code: The exception does not push an error code. However, exception information is available in the x87 status word register.
Alignment Check
An Alignment Check exception occurs when alignment checking is enabled and an unaligned memory data reference is performed. Alignment checking is only performed in CPL 3.
Alignment checking is disabled by default. To enable it, set the CR0.AM and RFLAGS.AC bits both to 1.
The saved instruction pointer points to the instruction which caused the exception.
SIMD Floating-Point Exception
The SIMD Floating-Point Exception occurs when an unmasked 128-bit media floating-point exception occurs and the CR4.OSXMMEXCPT bit is set to 1. If the OSXMMEXCPT flag is not set, then SIMD floating-point exceptions will cause an Undefined Opcode exception instead of this.
The saved instruction pointer points to the instruction which caused the exception.
Error Code: The exception does not push an error code. However, exception information is available in the MXCSR register.
Traps
Debug
The Debug exception occurs on the following conditions:
- Instruction fetch breakpoint (Fault)
- General detect condition (Fault)
- Data read or write breakpoint (Trap)
- I/O read or write breakpoint (Trap)
- Single-step (Trap)
- Task-switch (Trap)
When the exception is a fault, the saved instruction pointer points to the instruction which caused the exception. When the exception is a trap, the saved instruction pointer points to the instruction after the instruction which caused the exception.
Error code: The Debug exception does not set an error code. However, exception information is provided in the debug registers.
Breakpoint
A Breakpoint exception occurs at the execution of the INT3 instruction. Some debug software replace an instruction by the INT3 instruction. When the breakpoint is trapped, it replaces the INT3 instruction with the original instruction, and decrements the instruction pointer by one.
The saved instruction pointer points to the byte after the INT3 instruction.
Overflow
An Overflow exception is raised when the INTO instruction is executed while the overflow bit in RFLAGS is set to 1.
The saved instruction pointer points to the instruction after the INTO instruction.
Aborts
Double Fault
A Double Fault occurs when an exception is unhandled or when an exception occurs while the CPU is trying to call an exception handler. Normally, two exception at the same time are handled one after another, but in some cases that is not possible. For example, if a page fault occurs, but the exception handler is located in a not-present page, two page faults would occur and neither can be handled. A double fault would occur.
The saved instruction pointer is undefined. A double fault cannot be recovered. The faulting process must be terminated.
Machine Check
The Machine Check exception is model specific and processor implementations are not required to support it. It uses model-specific registers to provide error information. It is disabled by default. To enable it, set the CR4.MCE bit to 1.
Machine check exceptions occur when the processor detects internal errors, such as bad memory, bus errors, cache errors, etc.
The value of the saved instruction pointer depends on the implementation and the exception.
Triple Fault
- Main article: Triple Fault
The Triple Fault is not really an exception, because it does not have an associated vector number. Nonetheless, a triple fault occurs when an exception is generated when attempt to call the double fault exception handler. It results in the processor resetting. See the main article for more information about possible causes and how to avoid them.
Selector Error Code
31 16 15 3 2 1 0 +---+-- --+---+---+-- --+---+---+---+---+ | Reserved | Index | Tbl | E | +---+-- --+---+---+-- --+---+---+---+---+
Length | Name | Description | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
E | 1 bit | External | When set, the exception originated externally to the processor. | ||||||||||
Tbl | 2 bits | IDT/GDT/LDT table | This is one of the following values:
| ||||||||||
Index | 13 bits | Selector Index | The index in the GDT, IDT or LDT. |
See Also
Threads
External Links
- [http://www.intel.com/Assets/PDF/manual/325384.pdf Intel® 64 and IA-32 Architectures Software Developer's Manual
Combined Volumes 3A and 3B: System Programming Guide, Parts 1 and 2]