Interrupts and exceptions

Slides:



Advertisements
Similar presentations
计算机系 信息处理实验室 Lecture 3 System Mechanisms (1)
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
CSCI 4717/5717 Computer Architecture
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.
Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
Computer System Organization S H Srinivasan
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
Interrupts, Buses Chapter 6.2.5, Introduction to Interrupts Interrupts are a mechanism by which other modules (e.g. I/O) may interrupt normal.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
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.
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Input / Output Chapter 9.
Computer System Structures Interrupts
OPERATING SYSTEM CONCEPT AND PRACTISE
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Operating Systems Lecture 2.
CHAPTER 9: Input / Output
Interrupts and signals
MICROPROCESSOR BASED SYSTEM DESIGN
Exceptional Control Flow
Microprocessor Systems Design I
Basic Processor Structure/design
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Timer and Interrupts.
Anton Burtsev February, 2017
Exceptional Control Flow
Computer Architecture
Day 08 Processes.
Day 09 Processes.
Chapter 10 And, Finally... The Stack
Overview Introduction General Register Organization Stack Organization
Intro to Processes CSSE 332 Operating Systems
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Chapter 10 The Stack.
Computer System Overview
Computer-System Architecture
Processor Fundamentals
Direct Memory Access Disk and Network transfers: awkward timing:
Operating Systems Lecture 2.
BIC 10503: COMPUTER ARCHITECTURE
COMPUTER PERIPHERALS AND INTERFACES
Exceptions Control Flow
Architectural Support for OS
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Chapter 10 And, Finally... The Stack
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupts and Exception Handling
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer System Overview
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Computer System Overview
Architectural Support for OS
Chapter 11 Processor Structure and function
COMP3221: Microprocessors and Embedded Systems
Interrupts and Exception Handling
Presentation transcript:

Interrupts and exceptions

Interrupts and exceptions Exceptions: Result from unexpected situations (from within the CPU) Interrupts: Result from external events, e.g. keyboard. Similar effect. Need to: Save current CPU state Execute some appropriate set of instructions Resume normal execution (sometimes)

Interrupt and exception Type of event MIPS terminology From Where ? Interrupt External I/O device request ------------------------------------------------------------------------------------ Invoke Operation system Internal Exception From user program ------------------------------------------------------------------------------------- Arithmetic Overflow Internal Exception Using an undefined Instruction Internal Exception -------------------------------------------------------------------------------------- Hardware malfunctions Either Exception or interrupt חובר בספטמבר 2001

Handling exceptions Address 40000040: Fixed location of exception Handling procedure

Handling exceptions

Exception Handling procedure Save on the stack all register values and internal CPU state (taken from the most recent pipeline register) Lookup the value written in the cause register Call the appropriate exception handling subroutine. When subroutine returns: Upload back all the registers and inernal CPU state Return to execute interrupted program

Faults Instruction would be illegal to execute Examples: Writing to a memory segment marked ‘read-only’ Reading from an unavailable memory segment (on disk) Executing a ‘privileged’ instruction Detected before incrementing the PC The causes of ‘faults’ can often be ‘fixed’ If a ‘problem’ can be remedied, then the CPU can just resume its execution-cycle

Error Exceptions Most error exceptions — divide by zero, invalid operation, illegal memory reference, etc. — translate directly into CPU signals Exceptions are handled by the operating system. Usually the job is fairly simple: send the appropriate signal to the current process force_sig(sig_number, current); That will probably kill the process, but that’s not the concern of the exception handler One important exception: page fault An exception can (infrequently) happen in the kernel die(); // kernel oops

Traps A CPU might have been programmed to automatically switch control to a ‘debugger’ program after it has executed a specific instruction That type of situation is known as a ‘trap’ It is activated after incrementing the PC

Interrupts Motivation: Utility of a general-purpose computer depends on its ability to interact with I/O devices attached to it (e.g., keyboard, display, disk-drives, network, etc.) Devices require a prompt response from the CPU when various events occur, even when the CPU is busy running a program Need a mechanism for a device to “gain CPU’s attention” Interrupts provide a way doing this

Simplified Architecture Diagram Central Processing Unit Main Memory system bus I/O device I/O device I/O device I/O device

Programmable Interval-Timer Interrupt Hardware IRQs Slave PIC (8259) Master PIC (8259) x86 CPU Ethernet INTR SCSI Disk Real-Time Clock Keyboard Controller Programmable Interval-Timer I/O devices have (unique or shared) Interrupt Request Lines (IRQs) IRQs are mapped by special hardware to interrupt vectors, and passed to the CPU This hardware is called a Programmable Interrupt Controller (PIC)

The `Interrupt Controller’ Responsible for telling the CPU when a specific external device wishes to ‘interrupt’ Needs to tell the CPU which one among several devices is the one needing service PIC translates IRQ to vector Raises interrupt to CPU Vector available in register Waits for ack from CPU Interrupts can have varying priorities PIC also needs to prioritize multiple requests Possible to “mask” (disable) interrupts at PIC or CPU

CPU’s ‘fetch-execute’ cycle User Program Fetch instruction at PC ld add st mul sub bne jmp … PC Decode the fetched instruction Save context Get INTR ID Execute the decoded instruction Lookup ISR Advance PC to next instruction Execute ISR Interrupt? yes IRET no

Handling interrupts Similar to exception handling, except: Interrupt information are held in two registers: Interrupt Cause and Interrupt Status Interrupts have priorities During execution of handling code for interrupt of level L, only interrupts of level > L can create new interrupt

Putting It All Together Memory Bus IRQs PIC CPU idtr IDT INTR cause N handler Mask points 255