What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.

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

COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
Input and Output CS 215 Lecture #20.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
CIS429/529 Winter 2007 Pipelining II- 1 Additional pipelining topics Why pipelining is so hard: exception handling ILP techniques: loop unrolling.
1 Chapter Five The Processor: Datapath and Control.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
ECE 232 L15.Microprog.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 15 Microprogrammed.
Interrupts STOP!!! Do this!!!. CMPE12cGabriel Hugh Elkaim 2 Interrupts Have device tell OS/CPU it is ready Requires hardware to support. OS/CPU can then.
CSCE 212 Chapter 5 The Processor: Datapath and Control Instructor: Jason D. Bakos.
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
EECC551 - Shaaban #1 Lec # 4 winter Data Hazards Requiring Stall Cycles In some code sequence cases, potential data hazards cannot be handled.
The Processor Data Path & Control Chapter 5 Part 4 – Exception Handling N. Guydosh 3/1/04+
ECE 232 L23.Exceptions.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 23 Exceptions.
COMP201 Computer Systems Exceptions and Interrupts.
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
ECE/CS 552: Microprogramming and Exceptions Instructor: Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes based on set created by.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
Lecture 14 Today’s topics MARIE Architecture Registers Buses
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.
Microprogramming and Exceptions Spring 2005 Ilam University.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Exceptions and Interrputs CS 321 – Introduction to Computer Architecture and Machine-Level Programming Barry Britt, Systems Analyst II Department of Computer.
CS152 Lec12.1 CS 152 Computer Architecture and Engineering Lecture 12 Multicycle Controller Design Exceptions.
University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell CS352H: Computer Systems Architecture Topic 9: MIPS Pipeline.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 16 - Multi-Cycle.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
CSC 4250 Computer Architectures September 22, 2006 Appendix A. Pipelining.
MIPS Processor.
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.
CDA 3101 Spring 2016 Introduction to Computer Organization Microprogramming and Exceptions 08 March 2016.
ECE/CS 552: Pipeline Hazards © Prof. Mikko Lipasti Lecture notes based in part on slides created by Mark Hill, David Wood, Guri Sohi, John Shen and Jim.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
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
Exceptions Another form of control hazard Could be caused by…
Computer Organization CS224
Handling Exceptions In MIPS, exceptions managed by a System Control Coprocessor (CP0) Save PC of offending (or interrupted) instruction In MIPS: Exception.
Interrupts and signals
Basic Processor Structure/design
Extensions to the Multicycle CPU
Morgan Kaufmann Publishers The Processor
Exceptions & Multi-cycle Operations
Pipelining: Advanced ILP
The processor: Exceptions and Interrupts
CSCE 212 Chapter 5 The Processor: Datapath and Control
Processor: Finite State Machine & Microprogramming
Computer Architecture
The processor: Pipelining and Branching
Architectural Support for OS
Project Instruction Scheduler Assembler for DLX
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.
Chapter Four The Processor: Datapath and Control
ECE 445 – Computer Organization
Control Hazards Branches (conditional, unconditional, call-return)
Datapath and Control Exceptions
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
ECE/CS 552: Pipelining and Exceptions
Interrupts and exceptions
Interrupts and Exception Handling
CMSC 611: Advanced Computer Architecture
Presentation transcript:

What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service from user program – Integer arithmetic overflow – Using an undefined or unimplemented instruction – Hardware malfunctions Interrupt: event is externally caused – I/O device request – Tracing instruction execution – Breakpoint (programmer-requested interrupt) January

Exceptions in MIPS stageProblem exceptions occurring IFPage fault on IF, misaligned memory access, memory protection violation IDUndefined or illegal opcode EXArithmetic exception MEMPage fault on data fetch, misaligned memory access, memory protection violation WBNone January

What Happens During an Exception? An exception occurs Operating system trap Saving the PC where the exception happens Save the operating system state Run exception code Resume the last instruction before it traps, or terminate the program January

normal control flow: sequential, jumps, branches, calls, returns Exception System Exception Handler return from exception user program January

Exception Handling in Multi-Cycle MIPS Consider two types of exceptions: – arithmetic overflow – undefined instruction First save the address of the offending instruction in Exception Program Counter (EPC). Transfer control to the operating system (OS) to some specified address. OS provides some service. OS can stop the program or restart the program using EPC. January

Communicating Exception Reason to OS Two methods: – Using a status register called Cause Register, holding the reason of exception – Using vectored interrupts. The control is transferred to an address determined by the interrupt cause. Vectored interrupts example: – The addresses are separated by 32 bytes (8 instructions). – OS performs some limited process. January Exception TypeException vector address (in hex) Undefined instructionC hex Arithmetic overflowC hex

Non Vectored Exceptions A single entry point hex is used for all exceptions. The OS is decoding the status register to find the cause. Two registers are added to the data-path – EPC: 32-bit holding the address of the affected instruction. It is required for vectored exceptions too. – Cause: 32-bit recording the exception cause (some bits unused). In this example LSB of Cause encodes the exception. EPC must trim 4 from PC. January

Exceptions Handling in Multi-Cycle MIPS January

9 ALU output overflow.

Exception in pipelined architecture Force a trap instruction into the pipeline on the next IF Flush the pipeline for the faulting instruction and all instructions that follow After exception handling routine finishes, restore the PC of the saved PC and delay branches if exist January

Additions to MIPS ISA EPC (Exceptional Program Counter) – A 32-bit register – Holds the address of the offending instruction Cause – A 32-bit register – Records the cause of the exception Status – interrupts mask and enable bits that determines what exceptions can occur. January

Control signals to write EPC, Cause, and Status Be able to write exception address into PC, increase mux set PC to exception address (MIPS uses hex ). May have to undo PC = PC + 4, since EPC should point to offending instruction (not to its successor); PC = PC - 4 What else? Flush all succeeding instructions in pipeline January

Additions to MIPS ISA January

Exceptions example 40 hex sub $11, $2, $4 44 hex and$12, $2, $5 48 hex or $13, $2, $6 4C hex add$1, $2, $1; // arithmetic overflow 50 hex stl $15, $6,$7 54 hex lw $16, 50($7) hex sw $25, 1000($0) hex sw$12, 1004($0) Exception handling program: January

January

16 Clock 6 overflow detected flush ID flush IF nop deasserting add flush EX January 2014

17 Clock 7 first instruction of exception routine January 2014

More on Exceptions January

Precise Exceptions If the pipeline can be stopped so that the instructions just before the faulting instruction are completed and the faulting instruction can be restarted from scratch. January

MIPS Exception Mechanism The processor operates in – user mode – kernel mode Access to additional set of registers and to user mode restricted memory space available when the processor operates in kernel mode. The MIPS architecture includes the notion of co-processors. January

Co-processor Contains registers useful for handling exceptions Not accessible in user mode. Includes the status register, cause register, BadVaddr, and EPC (Exception Program Counter). January

Cause Register The cause register contains information about pending interrupts and the kinds of exception that occurs. January

The contents of the cause register can be copied into an ordinary register and have the individual bits tested to determine what caused an exception to occur. mfc0 $26, $13 The above instruction moves data from coprocessor0 register $13 (cause register) to general purpose register $26 January

Status Register The status register contains information about the status of features of the computer that can be set by the processor while in kernel mode January

Exception Program Counter (EPC) Contains the address of the instruction that was executing when the exception was generated. Control can be made to return to this location to continue the program. The contents of EPC can be transferred to a general register via the following instruction mfc0 R t, $14 January

Exception Handler MIPS R32 fixes the starting address of the exception handler to 0x A jump table consists of a list of procedure addresses to be called to deal with the various exception conditions. In an interrupt, the PC had already been incremented and EPC would contain the correct return address. In a syscall, the EPC contains the address of the syscall itself, thus the exception handler must first increment the return address by one before the return. January

Handling an Exception An exception has occurred. What happens? The hardware – copies PC into EPC ($14 on cop0) and puts correct code into Cause Reg ($13 on cop0) – Sets PC to 0x – enters kernel mode Exception handler (software) – Checks cause register (bits 5 to 2 of $13 in cp0) – jumps to exception service routine for the current exception January

January As with any procedure, the exception handler must first save any registers it may modify, and then restore them before returning to the interrupted program. Saving registers in memory poses a problem in MIPS. Addressing the memory requires a register (base) to form an address. This means that a register must be modified before any register can be saved! The MIPS register usage convention reserves $26 ($k0) and $27 ($k1) for the use of the interrupt handler.

January This means that the interrupt handler can use those without saving them first. A user program that uses those may find them unexpectedly changed!