ECE 232 L23.Exceptions.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 23 Exceptions.

Slides:



Advertisements
Similar presentations
1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Advertisements

COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
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.
1 Chapter Five The Processor: Datapath and Control.
ECE 232 L22.Pipeline3.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 22 Pipelining,
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.
CSCE 212 Chapter 5 The Processor: Datapath and Control Instructor: Jason D. Bakos.
ECE 232 L15.Miulticycle.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 15 Multi-cycle.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
ECE 232 L19.Pipeline2.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 19 Pipelining,
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
EECC550 - Shaaban #1 Lec # 6 Winter Control may be designed using one of several initial representations. The choice of sequence control,
The Processor Data Path & Control Chapter 5 Part 4 – Exception Handling N. Guydosh 3/1/04+
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
ECE/CS 552: Microprogramming and Exceptions Instructor: Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes based on set created by.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
Lecture 5: Pipelining Implementation Kai Bu
Implementing Precise Interrupts in Pipelined Processors James E. Smith Andrew R.Pleszkun Presented By: Ravikumar Source:
Exam 2 Review Two’s Complement Arithmetic Ripple carry ALU logic and performance Look-ahead techniques Basic multiplication and division ( non- restoring)
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.
Implementing Precise Interrupts in Pipelined Processors James E. Smith Andrew R.Pleszkun Presented By: Shrikant G.
Multicycle Implementation
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.
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.
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.
CS 152: Computer Architecture and Engineering Lecture 11 Multicycle Controller Design Exceptions Randy H. Katz, Instructor Satrajit Chatterjee, Teaching.
Exceptions Another form of control hazard Could be caused by…
Computer Organization CS224
Microprocessor Systems Design I
Basic Processor Structure/design
MIPS I/O and Interrupt.
Morgan Kaufmann Publishers The Processor
Processor (I).
MIPS I/O and Interrupt.
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
ECE/CS 552: Microprogramming and Exceptions
Architectural Support for OS
Guest Lecturer TA: Shreyas Chand
Project Instruction Scheduler Assembler for DLX
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.
MIPS I/O and Interrupt.
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
Control Implementation Alternatives For Multi-Cycle CPUs
COMS 361 Computer Organization
CMSC 611: Advanced Computer Architecture
Presentation transcript:

ECE 232 L23.Exceptions.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 23 Exceptions and Interrupts Maciej Ciesielski

ECE 232 L23.Exceptions.2 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Outline °Exceptions, classification °Interrupts °Exceptions/Traps °Exceptions in multi-cycle processor °Exceptions in pipelined processor.

ECE 232 L23.Exceptions.3 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers The Big Picture: Where are We Now? °The Five Classic Components of a Computer °Today’s Topics: Exceptions What happens when something goes wrong with program execution, computation. Control Datapath Memory Processor Input Output

ECE 232 L23.Exceptions.4 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Exceptions °Exception = unprogrammed control transfer system takes action to handle the exception -must record the address of the offending instruction returns control to user must save & restore user state Normal control flow: sequential, jumps, branches, calls, returns user program Exception: System Exception Handler return from exception

ECE 232 L23.Exceptions.5 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers What happens to Instruction with Exception? °MIPS architecture defines the instruction as having no effect if the instruction causes an exception. °When get to virtual memory we will see that certain classes of exceptions must prevent the instruction from changing the machine state. °This aspect of handling exceptions becomes complex and potentially limits performance => why it is hard

ECE 232 L23.Exceptions.6 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Two Types of Exceptions °Interrupts caused by external events asynchronous to program execution may be handled between instructions simply suspend and resume user program °Traps caused by internal events -exceptional conditions (overflow) -errors (parity) -faults (non-resident page) synchronous to program execution condition must be remedied by the handler instruction may be retried or simulated and program continued or program may be aborted

ECE 232 L23.Exceptions.7 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers MIPS convention: °Exception means any unexpected change in control flow, without distinguishing internal or external; use the term interrupt only when the event is externally caused. Type of eventFrom where?MIPS terminology I/O device requestExternalInterrupt Invoke OS from user programInternalException Arithmetic overflow InternalException Using an undefined instructionInternalException Hardware malfunctionsEitherException or Interrupt

ECE 232 L23.Exceptions.8 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Addressing the Exception Handler °Traditional Approach: Interupt Vector PC <- MEM[ IV_base + cause || 00] 370, 68000, Vax, 80x86,... °RISC Handler Table PC <– IT_base + cause || 0000 saves state and jumps Sparc, PA, M88K,... °MIPS Approach: fixed entry PC <– EXC_addr Actually very small table -RESET entry -TLB -other iv_base cause handler code iv_base cause handler entry code

ECE 232 L23.Exceptions.9 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Saving State °Push it onto the stack Vax, 68k, 80x86 °Save it in special registers MIPS EPC, BadVaddr, Status, Cause °Shadow Registers M88k Save state in a shadow of the internal pipeline registers

ECE 232 L23.Exceptions.10 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Additions to MIPS ISA to support Exceptions? °EPC–a 32-bit register used to hold the address of the affected instruction (register 14 of coprocessor 0). °Cause–a register used to record the cause of the exception. In the MIPS architecture this register is 32 bits, though some bits are currently unused. Assume that bits 5 to 2 of this register encodes the two possible exception sources mentioned above: undefined instruction=0 and arithmetic overflow=1 (register 13 of coprocessor 0). °BadVAddr - register contained memory address at which memory reference occurred (register 8 of coprocessor 0) °Status - interrupt mask and enable bits (register 12 of coprocessor 0) °Control signals to write EPC, Cause, BadVAddr, and Status °Be able to write exception address into PC, increase mux to add as input two ( hex ) °May have to undo PC = PC + 4, since want EPC to point to offending instruction (not its successor); PC = PC - 4

ECE 232 L23.Exceptions.11 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Details of Status register °Mask = 1 bit for each of 5 hardware and 3 software interrupt levels 1 => enables interrupts 0 => disables interrupts °k = kernel/user 0 => was in the kernel when interrupt occurred 1 => was running user mode °e = interrupt enable 0 => interrupts were disabled 1 => interrupts were enabled °When interrupt occurs, 6 LSB shifted left 2 bits, setting 2 LSB to 0 run in kernel mode with interrupts disabled Status k 4 e 3 k 2 e 1 k 0 e Mask oldprev current

ECE 232 L23.Exceptions.12 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Big Picture: user / system modes °By providing two modes of execution (user/system) it is possible for the computer to manage itself operating system is a special program that runs in the privileged mode and has access to all of the resources of the computer presents “virtual resources” to each user that are more convenient that the physical resurces -files vs. disk sectors -virtual memory vs physical memory protects each user program from others °Exceptions allow the system to take action in response to events that occur while user program is executing O/S begins at the handler

ECE 232 L23.Exceptions.13 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Details of Cause register °Pending interrupt 5 hardware levels: bit set if interrupt occurs but not yet serviced handles cases when more than one interrupt occurs at same time, or while records interrupt requests when interrupts disabled °Exception Code encodes reasons for interrupt 0 (INT) => external interrupt 4 (ADDRL) => address error exception (load or instr fetch) 5 (ADDRS) => address error exception (store) 6 (IBUS) => bus error on instruction fetch 7 (DBUS) => bus error on data fetch 8 (Syscall) => Syscall exception 9 (BKPT) => Breakpoint exception 10 (RI) => Reserved Instruction exception 12 (OVF) => Arithmetic overflow exception Status 1510 Pending 52 Code

ECE 232 L23.Exceptions.14 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Precise Interrupts °Precise => state of the machine is preserved as if program executed up to the offending instruction Same system code will work on different implementations of the architecture Position clearly established by IBM Difficult in the presence of pipelining, out-ot-order execution,... MIPS takes this position °Imprecise => system software has to figure out what is where and put it all back together °Performance goals often lead designers to forsake precise interrupts system software developers, user, markets etc. usually wish they had not done this

ECE 232 L23.Exceptions.15 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers How Control Detects Exceptions in our FSD °Undefined Instruction – detected when no next state is defined from state 1 for the op value. We handle this exception by defining the next state value for all op values other than lw, sw, 0 (R-type), jmp, beq, and ori as new state 12. Shown symbolically using “other” to indicate that the op field does not match any of the opcodes that label arcs out of state 1. °Arithmetic overflow: Chapter 4 included logic in the ALU to detect overflow (signal Overflow). This signal is used in the modified finite state machine to specify an additional possible next state °Note: Challenge in designing control of a real machine is to handle different interactions between instructions and other exception-causing events such that control logic remains small and fast. Complex interactions makes the control unit the most challenging aspect of hardware design

ECE 232 L23.Exceptions.16 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Modification to the Control Specification EPC <= PC - 4 PC <= exp_addr cause <= 10 (RI) IR <= MEM[PC] PC <= PC + 4 R-type A <= R[rs] B <= R[rt] S <= A fun B R[rd] <= S S <= A op ZX R[rt] <= S ORi S <= A + SX R[rt] <= M M <= MEM[S] LW S <= A + SX MEM[S] <= B SW other undefined instruction EPC <= PC - 4 PC <= exp_addr cause <= 12 (Ovf) overflow Additional condition from Datapath Equal BEQ PC <= PC + SX || S <= A - B ~Equal

ECE 232 L23.Exceptions.17 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Exceptions in Pipelined Processor °External Interrupts: Allow pipeline to drain, Load PC with interrupt address °Faults (within instruction, restartable) Force trap instruction into IF disable writes till trap hits WB must save multiple PCs or PC + state Refer to MIPS solution

ECE 232 L23.Exceptions.18 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Exception Handling npc I mem Regs B alu S D mem m IAU PC lw $2,20($5) Regs A imoprwn detect bad instruction address detect bad instruction detect overflow detect bad data address Allow exception to take effect

ECE 232 L23.Exceptions.19 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Exception Problem °Exceptions/Interrupts: 5 instructions executing in 5 stage pipeline How to stop the pipeline? Restart? Who caused the interrupt? StageProblem interrupts occurring IFPage fault on instruction fetch; misaligned memory access; memory-protection violation IDUndefined or illegal opcode EXArithmetic exception MEMPage fault on data fetch; misaligned memory access; memory-protection violation; memory error °Load with data page fault, Add with instruction page fault? °Solution 1: interrupt vector/instruction, check last stage °Solution 2: interrupt ASAP, restart everything incomplete

ECE 232 L23.Exceptions.20 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Resolution: Freeze above & Bubble Below npc I mem Regs B alu S D mem m IAU PC Regs A imoprwn oprwn oprwn op rw rs rt bubble freeze

ECE 232 L23.Exceptions.21 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Summary Exceptions are the hard part of control °Need to find convenient place to detect exceptions and to branch to state or microinstruction that saves PC and invokes the operating system °Exceptions stop the pipeline °As we get pipelined CPUs that support page faults on memory accesses which means that the instruction cannot complete AND you must be able to restart the program at exactly the instruction with the exception, it gets even harder