Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.

Slides:



Advertisements
Similar presentations
Intermediate x86 Part 3 Xeno Kovah – 2010 xkovah at gmail.
Advertisements

Processor Privilege-Levels
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Intel MP.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Facilities for x86 debugging
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Processor Privilege-Levels How the x86 processor accomplishes transitions among its four distinct privilege-levels.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’ for the program-segments in an ELF executable file.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Facilities for x86 debugging Introduction to Pentium features that can assist programmers in their debugging of software.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
Linux Operating System
Linux Operating System
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’
Venturing into protected-mode
Introduction to Interrupts
80x86 Processor Architecture
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
UNIT 2 Memory Management Unit and Segment Description and Paging
Intel IA32 OS Support -Refresh
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
80386DX.
Windows Kernel Internals Traps, Interrupts, Exceptions
The Pentium Processor.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
1 COMPUTER ARCHITECTURE (for Erasmus students) Assoc.Prof. Stasys Maciulevičius Computer Dept.
Interrupts in the guest VM A look at the steps needed to “reflect” hardware interrupts back into the ROM-BIOS for servicing.
System Address Registers/Memory Management Registers Four memory management registers are used to specify the locations of data structures which control.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
80386DX. Programming Model The basic programming model consists of the following aspects: – Registers – Instruction Set – Addressing Modes – Data Types.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
6. HAL and IDT ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section  Hardware Abstraction Layer ◦ Section
Assembly 08 Interrupts. Introduction Interrupts are similar to procedures –They are used to alter a program’s control flow –The interrupt service is also.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
Microprocessor system architectures – IA32 security
Information Security - 2. Task Switching Every process has an associated Task State Segment, whose starting point is stored in the Task register. A task.
Memory Management Unit and Segment Description and Paging
Internal Programming Architecture or Model
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Descriptor Table & Register
MICROPROCESSOR BASED SYSTEM DESIGN
Exceptional Control Flow
Microprocessor Systems Design I
Anton Burtsev February, 2017
x86 segmentation, page tables, and interrupts
System Segment Descriptor
Exceptions Control Flow
CNET 315 Microprocessor & Assembly Language
CS-401 Computer Architecture & Assembly Language Programming
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts

‘Before-the-fact’ errors The CPU may fetch an instruction which it cannot correctly execute (due to an invalid operand or insufficient privilege-level, or to the instruction’s opcode not being defined) A few examples are: –Attempting to perform division by zero –Attempting to exceed memory-segment limits –Attempting to modify a ‘read-only’ segment

‘After-the-fact’ errors Also the cpu may perform some operation that results in an incorrect or illegal value (due to limits on the CPU register-sizes or to limits on the supported data-formats) A few examples: –Add positive numbers, but get a negative total –Store an array-entry beyond the array-bounds –Take square-root of a real value less than 0.0

“privileged” instructions In Protected-Mode the instructions below can only be executed at ring0 (i.e., if the CPU’s Current Privilege Level is zero): –‘MOV’ to/from a control-register (e.g., CR0) –‘MOV’ to/from a debug-register (e.g., DR7) –Modifying a system segment-register (i.e., ‘LGDT’ / ’LIDT’ / ’LLDT’ / ’LTR’ / ’LMSW’ ) –Cache-invalidates: ‘INVD’/‘INVLPG’/ WBINVD’ –‘CLTS’ or ‘HLT’

What happens if…? If protection rules are violated, or if errors result from computations, the processor will generate an ‘exception’ (i.e., it will save some information on the stack and transfer control to an ‘exception-handler’) Different kinds of exceptions will trigger different exception-handling procedures Gates in the IDT define the ‘entry-points’

Faults, traps, and aborts Intel classifies exceptions into categories, (according to whether or not it may be possible to ‘recover’ from the ‘error’): – ‘Faults’ are detected ‘before-the-fact’ (and generally indicate ‘recoverable’ errors) –‘Traps’ are detected ‘after-the-fact’ (and indicate some corrective action is needed) –‘Aborts’ are unrecoverable error-conditions

A ‘fault’ example Suppose an instruction tries to read from a ‘not-present’ data-segment: mov ax, [si] The CPU generate exception-number 0xB In case the corresponding IDT-descriptor is a 32-bit interrupt-gate (or trap-gate), the CPU will push at least four 32-bit values: –Current contents of the EFLAGS register –Current contents of registers CS and EIP –An ‘error-code’ (with info about DS register)

‘Fault’ example (continued) If it is necessary to switch stacks (due to a change in the exception-handler’s code-segment privilege-level), the ‘old’ stack’s address (i.e., registers SS and ESP) will also get pushed onto the ‘new’ stack The fault-handler can take whatever actions are necessary to resolve the ‘not-present’ condition, then mark the data-segment as being ‘present’ and ‘restart’ execution of the prior instruction

What about ‘not-present’ gates? If an exception is generated, but the IDT’s gate-descriptor for that type of exception isn’t ‘present’, then the CPU generates a General Protection exception (INT-0x0D) So by supplying one exception-handler for this ‘catch all’ exception, we can ‘service’ nearly all of the various error-conditions

Error-Code Formats The format of the error-code that the CPU pushes onto its stack depends upon which type of exception has been encountered For General Protection exceptions, the error-code format looks like this: segment selector index EXTEXT INTINT TITI TI=Table Indicator (0=GDT, 1=LDT) INT=Interrupt (1=yes, 0=no) EXT=External-to-CPU event was cause of the exception (1=yes, 0=no)

Stack Frame Layout (32bit) ESP EFLAGS EIP SS CS Error Code points to the faulting instruction points to the old stack’s top SS:ESP = the new stack’s top When the ‘fault’ exception uses a 32-bit Interrupt-Gate (or Trap-Gate)

Stack Frame Layout (16bit) SP FLAGS IP SS CS Error Code points to the faulting instruction points to the old stack’s top SS:SP = the new stack’s top When the ‘fault’ exception uses a 16-bit Interrupt-Gate (or Trap-Gate)

Catalog of x86 exceptions 0x00: divide-overflow fault 0x01: single-step trap or debug fault 0x02: non-maskable interrupt (NMI) trap 0x03: breakpoint trap 0x04: integer overflow trap 0x05: array bounds fault 0x06: invalid opcode fault 0x07: coprocessor unavailable fault

Catalog (continue) 0x08: double-fault abort 0x09: (reserved) 0x0A: invalid TSS fault/abort 0x0B: segment not present fault 0x0C: stack fault 0x0D: general protection exception fault 0x0E: page fault 0x0F: (reserved)

Catalog (continued again) 0x10: FPU floating-point error fault 0x11: operand alignment-check fault 0x12: machine-check exception abort 0x13: SIMD floating-point exception fault 0x14-0x1F: (reserved) 0x20-0xFF: (user-defined interrupts) NOTE: Only the following exceptions have error-codes: 0x8, 0xA, 0xB, 0xC, 0xD, 0xE

Demo program: ‘whycrash.s’ To illustrate the processor’s response to exceptions, we created this short demo It displays some diagnostic information (including the ‘error-code’) when the CPU triggers any exception-condition (all get routed through the IDT-gate for General Protection exceptions in this demo) Can help us identify causes for a ‘crash’

In-class exercise #1 Try experimenting with your own examples of impermissible instructions What if you try to store a value to the vram memory-segment using an address-offset larger than the 32KB segment-limit? What if you try to load a segment-register with a selector-value that exceeds the size of your descriptor-table? What if you try to ‘call’ to ring3 from ring0?

In-class exercise #2 If your ‘solution’ to midterm Question V caused a system-crash, can you find out why, by adding this exception-handler to your program’s source-text? Some useful programming techniques: –Using the as86 ‘INCLUDE’ directive (to include a separate source-text file –Using the as86 ‘-l’ command-line option (to generate an assembler ‘listing’ file)