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.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Input and Output CS 215 Lecture #20.
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Computer System Overview
CSCI 4717/5717 Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
1 Computer System Overview OS-1 Course AA
OS Spring’03 Introduction Operating Systems Spring 2003.
Computer System Organization S H Srinivasan
OS Spring’04 Introduction Operating Systems Spring 2004.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 1. Introduction What is an Operating System? Mainframe Systems
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Computer System Overview Chapter 1. Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users.
Input and Output Computer Organization and Assembly Language: Module 9.
MICROPROCESSOR INPUT/OUTPUT
Operating system Structure and Operation by Dr. Amin Danial Asham.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
ECEG-3202 Computer Architecture and Organization Chapter 3 Top Level View of Computer Function and Interconnection.
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.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 4 Computer Systems Review.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
Lecture 1: Review of Computer Organization
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
Copyright © 2007 by Curt Hill Interrupts How the system responds.
بسم الله الرحمن الرحيم MEMORY AND I/O.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
CSCE451/851 Introduction to Operating Systems
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
Operating Systems CMPSC 473
Exceptional Control Flow
Exceptional Control Flow
Day 08 Processes.
Day 09 Processes.
Exceptional Control Flow
Computer System Overview
Module 2: Computer-System Structures
Exceptions Control Flow
Architectural Support for OS
Interrupts and Exception Handling
Architectural Support for OS
Module 2: Computer-System Structures
Interrupts and Exception Handling
Presentation transcript:

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 indicated by the contents of the PC (PC can be incremented at the same time) –Execute the instruction. External events cause a change in this flow –I/O device ready –Input done Internal events can cause a change in this flow –Divide by 0 –Overflow

Detecting Interrupt Bad choices –Spin Waiting Have a loop that checks for the event and waits until it happens –Checking periodically. Event may never happen Difficult to program to “catch” event. Want to keep I/O device working as much as possible since it is slowest.

Interrupt processor Use a separate computer dedicated to detecting and handling external events. But would need one for each device so that won’t have problems with multiple events. Now CPU only communicates with other processors (fast) not with devices (slow).

Exception Mechanism Using multiple computers (one for each device) is expensive. Allow the computer to execute more than one program at a time. –Of course cannot execute more than one instruction at a time (with one cpu) –Just looks like it because the cpu is switching from one program to another very quickly.

Exception Handling When an exception occurs, the state of the cpu must be saved. –Save registers (including PC) Jump to the section of code to handle the interrupt (the exception handler). Restore the state of the cpu before returning back to original program.

Components An interrupt is a change of the normal flow of a program. The hardware must determine when to interrupt the cpu and transfer program control to the exception handler (software). Since the exception handler can be called at any time, there cannot be any arguments passed or return value.

Operating System The operating system controls and allocates the use of all system resources, such as, the cpu, memory, I/O devices, etc This allocation is coordinated by interrupting running programs to handle asynchronous I/O requests. This allows multiple independent programs to share the computer (multiprogramming)

Efficiency When a program needs some input (from keyboard, disk, etc.) it will take a significant amount of cpu time to complete Rather than sitting idle, the cpu can work on another task. Allows for time sharing –Each process gets some time slice of cpu time. –Interrupt occurs at the end of the time slice –Operating system can switch to another process

Program Status Running – process is on the cpu and executing Blocked – process is waiting for an I/O request to complete Ready – No longer blocked, awaiting to become running A change in status occurs via an interrupt

Kernel The kernel is the part of the operating system that handles interrupts. There must be some instructions for the operating system that cannot be used by the user (such as access to I/O devices, special purpose registers, etc.) The OS uses registers $26 and $27 for servicing interrupts. Users can use them but their values will change at unpredictable times.

Types of Exceptions I/O Time slice complete – uses a hardware timer. Extraordinary conditions during execution –Divide by 0 –Overflow –Illegal instruction or memory address –This method is called a trap since generated internally, not externally to the program

Terms An exception is either a trap or an interrupt Trap –generated internal to the program – synchronous Interrupt –Generated external to the program –Asynchronous

Processor Modes The MIPS processor has 2 modes –Kernel –User Kernel mode allows access to the kernel registers (Not discussed yet) and the upper half of memory. Interrupt handlers and other operating system data is in the upper half of memory The operating system executes in kernel mode

Co-processors Coprocessor C1 has the floating point hardware. –Without C1, floating point instructions cause trap and the handler “fakes” the floating point instruction with several integer instructions. TAL uses the instructions mtc1(move to c1) and mfc1 (move from c1) to move data between floating point and general registers. –Similarly with coprocessor 0 (mtc0, mfc0)

Coprocessor C0 Accessible only in kernel mode. Register have special purposes. –Status Register (12) –Cause Registion (13) –Exception Program Counter (14)

Cause Register Gives information about what caused an exception. –Bits 2-6 give a 5 bit value (0-32) about the kind of exception Interrupt, load from illegal address, bus error on fetch, bus error on data reference, syscall instruction, break instruction, reserved instruction, coprocessor unusable, arithmetic overflow, trap, floating point. –Bits indicate external interrupt.

Status Register Bit 1 – kernel or user mode Bit 3 – mode when last interrupt occurred Many more

Exception Handler An exception is not invoked by a JAL, so what about the return address? When an exception occurs, the processor jumps to 0x The Exception Program Counter register is loaded with the address of the instruction being executed when the interrupt occurred. The interrupt handler can move this to a general register and save it.