CS152 Lec12.1 CS 152 Computer Architecture and Engineering Lecture 12 Multicycle Controller Design Exceptions.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Computer Organization and Architecture
Computer Organization and Architecture
Computer Organization and Architecture
CSCI 4717/5717 Computer Architecture
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.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
CS152 / Kubiatowicz Lec12.1 2/27/01©UCB Spring 2001 CS152 Computer Architecture and Engineering Lecture 12 Introduction to Pipelining February 27, 2001.
OS Spring’03 Introduction Operating Systems Spring 2003.
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,
S. Barua – CPSC 440 CHAPTER 5 THE PROCESSOR: DATAPATH AND CONTROL Goals – Understand how the various.
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.
COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.
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.
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.
CS 152 Lec 12.1 CS 152: Computer Architecture and Engineering Lecture 12 Multicycle Controller Design Pipelining Randy H. Katz, Instructor Satrajit Chatterjee,
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.
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.
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.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
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.
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.
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
Interrupts and exceptions
CS 152: Computer Architecture and Engineering Lecture 11 Multicycle Controller Design Exceptions Randy H. Katz, Instructor Satrajit Chatterjee, Teaching.
Computer Organization CS224
Interrupts and signals
Microprocessor Systems Design I
Basic Processor Structure/design
Control Unit Lecture 6.
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
BIC 10503: COMPUTER ARCHITECTURE
Exceptions Control Flow
Architectural Support for OS
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)
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
Presentation transcript:

CS152 Lec12.1 CS 152 Computer Architecture and Engineering Lecture 12 Multicycle Controller Design Exceptions

CS152 Lec12.2 The Big Picture: Where are We Now? °The Five Classic Components of a Computer °Today’s Topics: Microprogramed control Administrivia; Courses Microprogram it yourself Exceptions Intro to Pipelining (if time permits) Control Datapath Memory Processor Input Output

CS152 Lec12.3 Test benches °Idea: wrap testing infrastructure around devices under test (DUT) °Include test vectors that are supposed to detect errors in implementation. Even strange ones… °Can (and probably should in later labs) include assert statements to check for “things that should never happen” Test Bench Device Under Test Inline vectors Assert Statements File IO (either for patterns or output diagnostics) Inline Monitor Output in readable format (disassembly) Assert Statements Complete Top-Level Design

CS152 Lec12.4 Exceptions °Exception = unprogrammed control transfer system takes action to handle the exception -must record the address of the offending instruction -record any other information necessary to return afterwards returns control to user must save & restore user state °Allows constuction of a “user virtual machine” normal control flow: sequential, jumps, branches, calls, returns user program System Exception Handler Exception: return from exception

CS152 Lec12.5 Two Types of Exceptions: Interrupts and Traps °Interrupts caused by external events: -Network, Keyboard, Disk I/O, Timer asynchronous to program execution -Most interrupts can be disabled for brief periods of time -Some (like “Power Failing”) are non-maskable (NMI) 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

CS152 Lec12.6 Traps and Interrupts °exception means any unexpected change in control flow, without distinguishing internal or external; Type of eventFrom where?terminology I/O device requestExternalInterrupt Invoke OS from user programInternalTrap Arithmetic overflow InternalTrap Using an undefined instructionInternalTrap Hardware malfunctionsEitherTrap or Interrupt

CS152 Lec12.7 What happens to Instruction with Exception? °MIPS architecture defines the instruction as having no effect if the instruction causes an exception. °When we 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

CS152 Lec12.8 Precise Interrupts °Precise  state of the machine is preserved as if program executed up to the offending instruction All previous instructions completed Offending instruction and all following instructions act as if they have not even started Same system code will work on different implementations 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 not implement precise interrupts system software developers, user, markets etc. usually wish they had not done this °Modern techniques for out-of-order execution and branch prediction help implement precise interrupts

CS152 Lec12.9 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 resources -files vs. disk sectors -virtual memory vs physical memory protects each user program from others protects system from malicious users. OS is assumed to “know best”, and is trusted code, so enter system mode on exception. °Exceptions allow the system to taken action in response to events that occur while user program is executing: Might provide supplemental behavior (dealing with denormal floating-point numbers for instance). “Unimplemented instruction” used to emulate instructions that were not included in hardware

CS152 Lec12.10 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

CS152 Lec12.11 Saving State °Push it onto the stack 68k, 80x86 °Shadow Registers M88k Save state in a shadow of the internal pipeline registers °Save it in special registers MIPS EPC, BadVaddr, Status, Cause

CS152 Lec12.12 Additions to MIPS ISA to support Exceptions? °Exception state is kept in “coprocessor 0”. Use mfc0 read contents of these registers Every register is 32 bits, but may be only partially defined BadVAddr (register 8) register contains memory address at which memory reference occurred Status (register 12) interrupt mask and enable bits Cause (register 13) the cause of the exception Bits 5 to 2 of this register encodes the exception type (e.g undefined instruction=10 and arithmetic overflow=12) EPC (register 14) address of the affected instruction (register 14 of coprocessor 0). °Control signals to write BadVAddr, Status, Cause, and EPC °Be able to write exception address into PC ( hex ) °May have to undo PC = PC + 4, since want EPC to point to offending instruction (not its successor): PC = PC - 4

CS152 Lec12.13 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 kekeke Mask oldprev current

CS152 Lec12.14 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

CS152 Lec12.15 Example: How Control Handles Traps 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–detected on ALU ops such as signed add Used to save PC and enter exception handler °External Interrupt – flagged by asserted interrupt line Again, must save PC and enter exception handler °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

CS152 Lec12.16 How to add traps and interrupts to state diagram IR <= MEM[PC] PC <= PC + 4 R-type 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 “instruction fetch” “decode” BEQ 0010 If A = B then PC <= S S<= PC +SX undefined instruction EPC <= PC - 4 PC <= exp_addr cause <= 10 (RI) other S <= A - B overflow EPC <= PC - 4 PC <= exp_addr cause <= 12 (Ovf) EPC <= PC - 4 PC <= exp_addr cause <= 0(INT) Handle Interrupt Pending INT

CS152 Lec12.17 But: What has to change in our  -sequencer? °Need concept of branch at micro-code level R-type S <= A fun B 0100 overflow EPC <= PC - 4 PC <= exp_addr cause <= 12 (Ovf) µAddress Select Logic Opcode microPC 1 Adder Dispatch ROM Mux overflow pending interrupt 4? N? Cond Select Do  -branch  -offset Seq Select

CS152 Lec12.18 Summary °Microprogramming is a fundamental concept implement an instruction set by building a very simple processor and interpreting the instructions essential for very complex instructions and when few register transfers are possible Control design reduces to Microprogramming °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 Providing clean interrupt model gets hard with pipelining! °Precise Exception  state of the machine is preserved as if program executed up to the offending instruction All previous instructions completed Offending instruction and all following instructions act as if they have not even started