Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?

Slides:



Advertisements
Similar presentations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Memory Management and Protection Part 3:Virtual memory, mode switching,
Advertisements

Chapter 12: Interrupts. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel Microprocessors:
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Computer Organization and Architecture
Computer Organization and Architecture
Exceptions and Interrupts
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.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Interrupts (contd..) Multiple I/O devices may be connected to the processor and the memory via a bus. Some or all of these devices may be capable of generating.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
What about ‘interrupts’? An introduction to the basic issues affecting the design of code that performs servicing of interrupts.
1 CE6105 Linux 作業系統 Linux Operating System 許 富 皓.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: internal fault (e.g.. divide by.
Linux Operating System
OS Spring’03 Introduction Operating Systems Spring 2003.
Linux Operating System
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
Introduction to Interrupts
On handling interrupts An introduction to the basic issues affecting the design of code that performs servicing of interrupts.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Interrupts – (Chapter 12)
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
UNIT 2 Memory Management Unit and Segment Description and Paging
Intel IA32 OS Support -Refresh
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Intel 945 Motherboard architecture GMCH ICH7 (8254,8259,8237) Interrupt & io-apic IDT, GDT Multiprocessor.
Exceptions and Interrupts 2
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
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 Useful in dealing with: The interface: Random processes;
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
6. HAL and IDT ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section  Hardware Abstraction Layer ◦ Section
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.
Information Security - 2. Task Switching Every process has an associated Task State Segment, whose starting point is stored in the Task register. A task.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 Interrupts A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Interrupts and exceptions
Descriptor Table & Register
Interrupts and signals
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Microprocessor Systems Design I
Anton Burtsev February, 2017
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
x86 segmentation, page tables, and interrupts
CNET 315 Microprocessor & Assembly Language
CS-401 Computer Architecture & Assembly Language Programming
Chapter 11 Processor Structure and function
Interrupts and System Calls
Presentation transcript:

Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?

The ‘fetch-execute’ cycle Normal programming assumes this ‘cycle’: 1) Fetch the next instruction from ram 2) Interpret the instruction just fetched 3) Execute this instruction as decoded 4) Advance the cpu instruction-pointer 5) Go back to step 1

But ‘departures’ may occur Circumstances may arise under which it would be inappropriate for the cpu to proceed with this fetch-execute cycle Examples: An ‘external device’ may ask for service An interpreted instruction may be ‘illegal’ An instruction ‘trap’ may have been set

Faults If the cpu detects that an instruction it has just decoded would be illegal to execute, it cannot proceed with the fetch-execute cycle This type of situation is known as a ‘fault’ It is detected BEFORE incrementing the IP The cpu will react by: 1) saving some info on its stack, then 2) switching control to a special fault-handling routine

Fault-Handling The causes of ‘faults’ may often be fixed A few examples: 1) Writing to a ‘read-only’ segment 2) Reading from a ‘not present’ segment 3) Executing an out-of-bounds instruction 4) Executing a ‘privileged’ instruction If the problem can be remedied, the cpu can resume executing from where it left off

Traps The cpu may have been programmed to automatically switch control to a ‘debugger’ Program after it has executed an instruction This type of situation is known as a ‘trap’ It is activated AFTER incrementing the IP It is accomplished by setting the TF flag Just as with faults, the cpu will react: save return-info, and jump to trap-handler

Faults versus Traps Both ‘faults’ and ‘traps’ occur at points within a computer program which are ‘predictible’ (i.e., triggered by pre-planned instructions), so they are ‘in sync’ with the program (and thus are called ‘synchronous’ interruptions in the normal fetch-execute cycle) The cpu responds in a similar way to faults and to traps – yet what gets saved differs!

Faults vs Traps (continued) With a ‘fault’: the saved address is for the instruction that was the cause of the fault – so that instruction will get re-fetched after the cause of the problem has been fixed With a ‘trap’: the saved address is for the instruction following the one which triggered the trap

Synchronous vs Asynchronous Devices which are ‘external’ to the cpu may under go certain changes-of-state that the system needs to take notice of These changes occur independently of what the cpu is doing, and so cannot be predicted from reading a program’s code They are ‘asynchronous’ to the program, and are known as ‘interrupts’

Interrupt Handling As with faults and traps, the cpu responds to interrupt-requests by saving some info on the stack and then jumping to a special ‘interrupt-handler’ routine designed to take appropriate action for the particular device which caused the interrupt to occur

The ‘Interrupt Controller’ Special hardware is responsible for telling the cpu when an external device wants to ‘interrupt’ the current program This hardware is the ‘Interrupt Controller’ It needs to let the cpu know which among several devices is the one needing attention It also needs to prioritize multiple requests

Cascaded 8259 PICs CPU INTR Master PIC INTA Slave PIC IRQ0 IRQ1 IRQ2 IRQ3 IRQ4 IRQ5 IRQ6 IRQ7 IRQ8 IRQ9 IRQ10 IRQ11 IRQ12 IRQ13 IRQ14 IRQ15 PC Design (for single-processor systems)

Two Crucial Data Tables The Global Descriptor Table (GDT) defines memory segments, and enforces their access-privileges (by using ‘segment descriptors’) The Interrupt Descriptor Table (IDT) defines entry-points for the code-routines which handle ‘interrupts’ and ‘exceptions’

How does CPU find GDT/IDT? Two dedicated registers: GDTR and IDTR Both have identical 48-bit format: Segment Base AddressSegment Limit Privileged instructions: LGDT and LIDT used to set these register-values Unprivileged instructions: SGDT and SIDT used for reading register-values Kernel must setup these registers during system startup (set-and-forget)

Segment-Descriptor Format Base[ 15 … 0 ]Limit[ ] Base[31…24] Limit [19..16] Access attributes Base[23…16] Quadword (64-bits)

Gate-Descriptor Format Entrypoint Offset[ 31…16 ] Code-segment SelectorEntrypoint Offset[ 15…0 ] Quadword (64-bits) Gate type code (Reserved)

Intel-Reserved ID-Numbers Of the 256 possible interrupt ID-numbers, Intel reserves the first 32 for ‘exceptions’ Operating systems such as Linux are free to use the remaing 224 available interrupt ID-numbers for their own purposes (e.g., for service-requests from external devices, or for other purposes such as system-calls

Some Intel-defined exceptions 0: divide-overflow fault 1: debug traps and faults 2: non-maskable interrupts 3: debug breakpoint trap 4: INTO detected overflow 5: BOUND range exceeded 6: Undefined Opcode 7: Coprocessor Not Available 8: Double-Fault 9: (reserved) 10: Invalid Task-State Segment 11: Segment-Not-Present fault 12: Stack fault 13: General Protection Exception 14: Page-Fault Exception 15: (reserved)

Error-Codes A few of the Intel-defined exceptions also push a diagnostic ‘error-code’ onto the cpu stack (in addition to pushing the EFLAGS, CS and EIP register-values); the ‘handler’ must discard that error-code before it can execute the ‘iret’ instruction to resume the program that got interrupted (Exceptions 8 and 10 through 14 generate error-codes)

Using our ‘physmem’ driver We can look at the kernel’s GDT/IDT tables 1)We can find them (using ‘sgdt’ and ‘sidt’) 2)We can ‘read’ them by using ‘physmem’ Demo program on course website: showidt.cpp It prints out the 256 IDT Gate-Descriptors

In-Class Exercise Write a similar program (showgdt.cpp) Two ‘big’ issues: size of GDT isn’t known in advance (whereas the IDT is of a known size) labeling for GDT entries is by offset (whereas the IDT entries use index) There could be some ‘other’ issues as well

Some Questions How many “non-null” descriptors in GDT? (There’s always at least one that’s “null”) What kinds of descriptors does Linux use? Sizes? Access-rights? Code/Data? TSS?