COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.

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 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
I/O Unit.
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.
Chapter 6 Limited Direct Execution
Interfacing. This Week In DIG II  Basic communications terminology  Communications protocols  Microprocessor interfacing: I/O addressing  Port and.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 7 Interupts DMA Channels Context Switching.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
1 COMP541 Interrupts, DMA, Serial I/O Montek Singh April 24, 2007.
Exceptions, Interrupts & Traps
The Processor Data Path & Control Chapter 5 Part 4 – Exception Handling N. Guydosh 3/1/04+
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
System Calls 1.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
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.
MICROPROCESSOR INPUT/OUTPUT
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
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,
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
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.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
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.
1 Input / Output. Today: I/O Systems How does I/O hardware influence the OS? What I/O services does the OS provide? How does the OS implement those services?
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
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
Interrupts and signals
Microprocessor Systems Design I
Chapter 10 And, Finally... The Stack
Chapter 10 The Stack.
Arithmetic using a stack
Exceptions Control Flow
Architectural Support for OS
Interrupts.
Chapter 10 And, Finally... The Stack
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.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Interrupts and exceptions
Presentation transcript:

COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran and William D. Leahy Jr.

4Interrupts, Traps and Exceptions Interrupts, traps and exceptions are discontinuities in program flow Students asking a teacher questions in a classroom is a good analogy to the handling of discontinuities in program flow

4.1 Discontinuities in program execution We must first understand – Synchronous events: Occur at well defined points aligned with activity of the system Making a phone call Opening a file – Asynchronous events: Occur unexpectedly with respect to ongoing activity of the system Receiving a phone call A user presses a key on a keyboard

4.1 Discontinuities in program execution There is no universally accepted set of definitions for interrupts, traps and exceptions so we will use these – Interrupts: Asynchronous events usually produced by I/O devices which must be handled by the processor by interrupting execution of the currently running process – Traps: Synchronous events produced by special instructions typically used to allow secure entry into operating system code – Exceptions: Synchronous events usually associated with software requesting something the hardware can’t perform i.e. illegal addressing, illegal op code, etc.

4.1 Discontinuities in program execution TypeSync/AsyncSourceIntentional?Examples ExceptionSyncInternalNoOverflow, Divide by zero, Illegal memory address TrapSyncInternalYes and NoSystem call, Page fault, Emulated instructions InterruptAsyncExternalYesI/O device completion

4.2 Dealing with program discontinuities Can happen anywhere even in the middle of an instruction execution. Unplanned for and forced by the hardware. Hardware has to save the program counter since we are jumping to the handler. Address of the handler is unknown. Therefore, hardware must manufacture address. Since hardware saved PC, handler has to discover where to return upon completion.

4.3 Architectural enhancements to handle program discontinuities When should the processor handle an interrupt? How does the processor know there is an interrupt? How do we save the return address? How do we manufacture the handler address? How do we handle multiple cascaded interrupts? How do we return from the interrupt

4.3.1 Modifications to FSM FetchExecute Decode INT int = N int = Y $k0 ← PC PC ← new PC

4.3.2 A simple interrupt handler Handler: save processor registers; execute device code; restore processor registers; return to original program;

What happens if an interrupt arrives during handling an interrupt? FetchExecute Decode INT int = N int = Y $k0 ← PC PC ← new PC Disable Ints Add new instruction Enable Ints

4.3.2 A simple interrupt handler Handler: save processor registers; execute device code; restore processor registers; enable ints return to original program;

4.3.3 Handling cascaded interrupts First Interrupt Handler Second Interrupt Handler Original Program $k0← Original Return Address $k0← First Handler Return Address

4.3.3 Handling cascaded interrupts FetchExecute Decode INT int = N int = Y $k0 ← PC PC ← new PC Disable Ints Add 2 new instructions Enable Ints Disable Ints

4.3.3 Handling cascaded interrupts Handler: /* The interrupts are disabled when we enter */ save $k0; enable interrupts; save processor registers; execute device code; restore processor registers; disable interrupts; restore $k0; enable interrupts return to original program;

Yay! It works perfectly!!! Handler: /* The interrupts are disabled when we enter */ save $k0; enable interrupts; save processor registers; execute device code; restore processor registers; disable interrupts; restore $k0; enable interrupts return to original program; Or does it? What happens if an interrupt occurs here?

4.3.4 Returning from the handler Returning involves jumping to the address in $k0 which can be accomplished with jalr $k0 $zero But as we have just seen an interrupt at precisely the wrong moment would destroy $k0 and cause a failure What do we need? restore $k0; enable interrupts return to original program;

4.3.5 Summary of architectural enhancements to LC-2200 to handle interrupts Three new instructions to LC-2200: – Enable interrupts – Disable interrupts – Return from interrupt Upon an interrupt, store the current PC implicitly into a special register $k0.

4.4 Hardware details for handling external interrupts What we have presented thus far is what is required for interrupts, traps and exceptions What do we need specifically for enternal interrupts?

4.4.1 Datapath details for interrupts Processor Data Bus Address Bus Device 1 Device 2 INT INTA Processor Device 1 Device 2 INT1 INTA 1 Device 1 Device 2 INT8 INTA Priority Encoder INT INTA

4.4.2 Details of receiving the address of the handler

Handshake between Processor and Device Device asserts INT line Processor upon completion of the current instruction, checks the INT line If interrupt pending, then processor enters INT macro- state and asserts INTA line on bus Device upon receiving the INTA from the processor, places its vector on the data bus. Processor receives vector and looks up entry in interrupt vector table for this vector. Entry is address of handler so we put it in PC The processor saves the current PC in $k0, and loads PC with value from interrupt vector table

4.4.3 Stack for saving/restoring Hardware has no guarantee for stack behavior by user program (register/conventions) Equip processor with 2 stack pointers (User/System) On interrupt swap stack pointers $sp SSPUSP 12

4.4.3 Stack for saving/restoring Use system stack for saving all necessary information Upon completion of interrupt restore registers, etc. The restore user stack pointer by reversing earlier swap $sp SSPUSP 21

4.5 Putting it all together inst inst CONT ADDR Executing instruction at The PC has already been incremented. Device signals interrupt in middle of instruction. $sp points to user stack $sp user stack $k0300 Register File PC20000 INT Enable1 INT ACK0 INT REQ1 A. Vector TableSystem StackHandler CodeOriginal Program MODEUSER

4.5 Putting it all together inst inst CONT ADDR Interrupt has been sensed. $k0 gets PC. Interrupts are disabled. Interrupt is acknowledged. Device puts vector on bus. $sp user stack $k Register File PC20000 INT Enable0 INT ACK1 INT REQ1 B. Vector TableSystem StackHandler CodeOriginal Program BUS40 MODEUSER

4.5 Putting it all together inst inst CONT ADDR Handler address is put into PC; Current mode is saved in system stack; New mode is set to kernel; $sp now points to system stack; Interrupt code at 1000 is set to handle the interrupt. $sp299 $k Register File PC1000 INT Enable0 INT ACK0 INT REQ0 C. Vector TableSystem StackHandler CodeOriginal Program MODEKERNEL

4.5 Putting it all together inst inst CONT ADDR RETI instruction restores mode from system stack; since returning to user program in this example, $sp now points to user stack; also, copies $k0 into PC, re-enables interrupts and sets Mode to User $sp user stack $k Register File PC20000 INT Enable1 INT ACK0 INT REQ0 D. Vector TableSystem StackHandler CodeOriginal Program MODEUSER

4.6 Summary Interrupts help a processor communicate with the outside world. An interrupt is a specific instance of program discontinuity. Processor/Bus enhancements included – Three new instructions – User stack and system stack – Mode bit – INT macro state – Control lines called INT and INTA

4.6 Summary Software mechanism needed to handle interrupts, traps and exceptions is similar. Discussed how to write a generic interrupt handler that can handle nested interrupts. Intentionally simplified. Interrupt mechanisms in modern processors are considerably more complex. For example, modern processors categorize interrupts into two groups: maskable and non-maskable. – maskable: Interrupts that can be temporarily turned off – Non-maskable: Interrupts that cannot be turned off

4.6 Summary Presented mode as a characterization of the internal state of a processor. Intentionally simplistic view. Processor state may have a number of other attributes available as discrete bits of information (similar to the mode bit). – Modern processors aggregate all of these bits into one register called processor status word (PSW). – Upon an interrupt and its return, the hardware implicitly pushes and pops, respectively, both the PC and the PSW on the system stack. The interested reader is referred to more advanced textbooks on computer architecture for details on how the interrupt architecture is implemented in modern processors.

4.6 Summary Presented simple treatment of the interrupt handler code to understand what needs to be done in the processor architecture to deal with interrupts. The handler would typically do a lot more than save processor registers. LC-2200 designates a register $k0 for saving PC in the INT macro state. In modern processors, there is no need for this since the hardware automatically saves the PC on the system stack.

Questions?