Exceptions: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
No edit summary
Line 151: Line 151:
! Reserved
! Reserved
| 31
| 31
| -
| -
| No
|-
! [[#Triple Fault|Triple Fault]]
| -
| -
| -
| -
| -
Line 163: Line 169:
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 '''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 instruction pointer points to the DIV or IDIV instruction which caused the exception.
The saved instruction pointer points to the DIV or IDIV instruction which caused the exception.


==== Bound Range Exceeded ====
==== 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.
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 instruction pointer points to the BOUND instruction which caused the exception.
The saved instruction pointer points to the BOUND instruction which caused the exception.


==== Invalid Opcode ====
==== 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 ====
==== 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 ====
==== 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 sets an error code, which is either a TSS selector index, LDT selector index or segment selector index.

==== Segment Not Present ====
==== Segment Not Present ====
{{stub}}
==== Stack-Segment Fault ====
==== Stack-Segment Fault ====
{{stub}}
==== General Protection Fault ====
==== General Protection Fault ====
{{stub}}

==== Page Fault ====
==== Page Fault ====
{{main|Page fault}}
{{stub}}

==== x87 Floating-Point Exception ====
==== x87 Floating-Point Exception ====
{{stub}}

==== Alignment Check ====
==== Alignment Check ====
{{stub}}

==== SIMD Floating-Point Exception ====
==== SIMD Floating-Point Exception ====
{{stub}}


=== Traps ===
=== Traps ===
Line 189: Line 222:
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.
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 instruction pointer points to the byte after the INT3 instruction.
The saved instruction pointer points to the byte after the INT3 instruction.


==== Overflow ====
==== Overflow ====
An Overflow exception is raised when the INTO instruction is executed while the overflow bit in [[RFLAGS]] is set to 1.
An Overflow exception is raised when the INTO instruction is executed while the overflow bit in [[RFLAGS]] is set to 1.


The instruction pointer points to the instruction after the INTO instruction.
The saved instruction pointer points to the instruction after the INTO instruction.


=== Aborts ===
=== Aborts ===
==== Double Fault ====
==== 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 ====
==== Machine Check ====
{{stub}}


==== Triple Fault ====
{{main|Triple Fault}}
{{stub}}


=== Misc ===
=== Misc ===

Revision as of 14:25, 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 sets an error code, which is either a TSS selector index, LDT selector index or segment selector index.

Segment Not Present

This page is a stub.
You can help the wiki by accurately adding more contents to it.

Stack-Segment Fault

This page is a stub.
You can help the wiki by accurately adding more contents to it.

General Protection Fault

This page is a stub.
You can help the wiki by accurately adding more contents to it.

Page Fault

Main article: Page fault
This page is a stub.
You can help the wiki by accurately adding more contents to it.

x87 Floating-Point Exception

This page is a stub.
You can help the wiki by accurately adding more contents to it.

Alignment Check

This page is a stub.
You can help the wiki by accurately adding more contents to it.

SIMD Floating-Point Exception

This page is a stub.
You can help the wiki by accurately adding more contents to it.

Traps

Debug

This page is a stub.
You can help the wiki by accurately adding more contents to it.

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

This page is a stub.
You can help the wiki by accurately adding more contents to it.

Triple Fault

Main article: Triple Fault
This page is a stub.
You can help the wiki by accurately adding more contents to it.

Misc

Non-maskable Interrupt

This page is a stub.
You can help the wiki by accurately adding more contents to it.