Exceptions: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
Line 192: | Line 192: | ||
===== Error code ===== |
===== Error code ===== |
||
The Invalid TSS sets an error code, which is either a TSS selector index, LDT selector index or segment selector index. |
The Invalid TSS exception sets an error code, which is either a TSS selector index, LDT selector index or segment selector index. |
||
==== Segment Not Present ==== |
==== Segment Not Present ==== |
||
The Segment Not Present exception accours when trying to load a segment or gate which has it's Present-bit set to 0. |
|||
{{stub}} |
|||
However wen loading a stack-segment selector which references a descriptor which is not present, a [[#Stack-Segment Fault|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 ==== |
==== Stack-Segment Fault ==== |
||
The Stack-Segment Fault occurs when: |
|||
{{stub}} |
|||
* 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 stack segment selector index when a non-present segment descriptor was referenced. Otherwise, 0. |
|||
==== General Protection Fault ==== |
==== General Protection Fault ==== |
||
A General Protection Fault may occur for various reasons. The most common are: |
|||
{{stub}} |
|||
* 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 stack segment selector index when the exception is segment related. Otherwise, 0. |
|||
==== Page Fault ==== |
==== Page Fault ==== |
||
{{main|Page fault}} |
{{main|Page fault}} |
||
A Page Fault occurs when: |
|||
{{stub}} |
|||
* A [[Paging|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: |
|||
<pre> |
|||
31 4 0 |
|||
+---+-- --+---+---+---+---+---+---+ |
|||
| Reserved | I | R | U | W | P | |
|||
+---+-- --+---+---+---+---+---+---+ |
|||
</pre> |
|||
{| {{wikitable}} |
|||
! |
|||
! 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 ==== |
==== x87 Floating-Point Exception ==== |
Revision as of 14:55, 27 October 2008
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 classified as:
- Faults: These can be corrected and the program may continue as if nothing happend.
- 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 | Fault | #DE | No |
Debug | 1 | Fault/Trap | #DB | No |
Non-maskable Interrupt | 2 | Interrupt | #NMI | No |
Breakpoint | 3 | Trap | #BP | No |
Overflow | 4 | Trap | #OF | No |
Bound Range Exceeded | 5 | Fault | #BR | No |
Invalid Opcode | 6 | Fault | #UD | No |
Device Not Available | 7 | Fault | #NM | No |
Double Fault | 8 | Abort | #NM | Yes |
Coprocessor Segment Overrun | 9 | Fault | - | No |
Invalid TSS | 10 | Fault | #TS | Yes |
Segment Not Present | 11 | Fault | #NP | Yes |
Stack-Segment Fault | 12 | Fault | #SS | Yes |
General Protection Fault | 13 | Fault | #SS | Yes |
Page Fault | 14 | Fault | #SS | Yes |
Reserved | 15 | - | - | No |
x87 Floating-Point Exception | 16 | Fault | #MF | No |
Alignment Check | 17 | Fault | #AC | Yes |
Machine Check | 18 | Abort | #MC | No |
SIMD Floating-Point Exception | 19 | Fault | #XM/#XF | No |
Reserved | 20-29 | - | - | No |
Security Exception | 30 | - | #SX | No |
Reserved | 31 | - | - | 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.
The saved instruction pointer pionts to the instruction which caused the exception.
Device Not Available
The Device Not Available exception mainly occurs when working with x87 instructions.
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 occured 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 either a TSS selector index, LDT selector index or segment selector index.
Segment Not Present
The Segment Not Present exception accours when trying to load a segment or gate which has it's Present-bit set to 0. However wen 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 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 stack 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
Alignment Check
SIMD Floating-Point Exception
Traps
Debug
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
The most common reason a Double Fault occurs, is when an exception is unhandled or when an exception occurs within an exception handler.
The saved instruction pointer is undefined.
Machine Check
Triple Fault
- Main article: Triple Fault