Initial Representation Finite State Diagram Microprogram. Sequencing Control Explicit Next State Microprogram counter

Similar documents
Initial Representation Finite State Diagram. Logic Representation Logic Equations

CS152 Computer Architecture and Engineering Lecture 13: Microprogramming and Exceptions. Review of a Multiple Cycle Implementation

CS 152 Computer Architecture and Engineering. Lecture 12: Multicycle Controller Design

ECE468 Computer Organization and Architecture. Designing a Multiple Cycle Controller

CS152 Computer Architecture and Engineering. Lecture 8 Multicycle Design and Microcode John Lazzaro (

CpE 442. Designing a Multiple Cycle Controller

Major CPU Design Steps

CPU Design Steps. EECC550 - Shaaban

CC 311- Computer Architecture. The Processor - Control

Lecture 5 and 6. ICS 152 Computer Systems Architecture. Prof. Juan Luis Aragón

The Big Picture: Where are We Now? CS 152 Computer Architecture and Engineering Lecture 11. The Five Classic Components of a Computer

Designing a Multicycle Processor

Midterm I March 12, 2003 CS152 Computer Architecture and Engineering

ECE 361 Computer Architecture Lecture 11: Designing a Multiple Cycle Controller. Review of a Multiple Cycle Implementation

Midterm I October 6, 1999 CS152 Computer Architecture and Engineering

Systems Architecture I

Overview of Control. CS 152 Computer Architecture and Engineering Lecture 11. Multicycle Controller Design

Implementing the Control. Simple Questions

ENE 334 Microprocessors

CPE 335. Basic MIPS Architecture Part II

CS 152 Computer Architecture and Engineering. Lecture 10: Designing a Multicycle Processor

Multi-cycle Approach. Single cycle CPU. Multi-cycle CPU. Requires state elements to hold intermediate values. one clock cycle or instruction

ALUOut. Registers A. I + D Memory IR. combinatorial block. combinatorial block. combinatorial block MDR

The Processor: Datapath & Control

CPU Organization Datapath Design:

Midterm I March 1, 2001 CS152 Computer Architecture and Engineering

COMP303 Computer Architecture Lecture 9. Single Cycle Control

Midterm I March 12, 2003 CS152 Computer Architecture and Engineering

CPU Organization (Design)

RISC Processor Design

The Big Picture: Where are We Now? EEM 486: Computer Architecture. Lecture 3. Designing a Single Cycle Datapath

Microprogramming. Microprogramming

CPU Organization Datapath Design:

COMP303 - Computer Architecture Lecture 8. Designing a Single Cycle Datapath

Microprogrammed Control Approach

COMP303 - Computer Architecture Lecture 10. Multi-Cycle Design & Exceptions

Outline of today s lecture. EEL-4713 Computer Architecture Designing a Multiple-Cycle Processor. What s wrong with our CPI=1 processor?

Multicycle Approach. Designing MIPS Processor

Topic #6. Processor Design

Mapping Control to Hardware

RISC Design: Multi-Cycle Implementation

Chapter 4 The Processor (Part 2)

Lets Build a Processor

Inf2C - Computer Systems Lecture 12 Processor Design Multi-Cycle

CS3350B Computer Architecture Winter Lecture 5.7: Single-Cycle CPU: Datapath Control (Part 2)

ﻪﺘﻓﺮﺸﻴﭘ ﺮﺗﻮﻴﭙﻣﺎﻛ يرﺎﻤﻌﻣ MIPS يرﺎﻤﻌﻣ data path and ontrol control

Midterm I SOLUTIONS October 6, 1999 CS152 Computer Architecture and Engineering

CpE242 Computer Architecture and Engineering Designing a Single Cycle Datapath

361 datapath.1. Computer Architecture EECS 361 Lecture 8: Designing a Single Cycle Datapath

CSE 2021 COMPUTER ORGANIZATION

ECE468 Computer Organization and Architecture. Designing a Single Cycle Datapath

MIPS-Lite Single-Cycle Control

Processor: Multi- Cycle Datapath & Control

CO Computer Architecture and Programming Languages CAPL. Lecture 18 & 19

ECE369. Chapter 5 ECE369

Single Cycle CPU Design. Mehran Rezaei

361 multipath..1. EECS 361 Computer Architecture Lecture 10: Designing a Multiple Cycle Processor

CSE 2021 COMPUTER ORGANIZATION

RISC Architecture: Multi-Cycle Implementation

Multicycle conclusion

EEM 486: Computer Architecture. Lecture 3. Designing Single Cycle Control

CS 110 Computer Architecture Single-Cycle CPU Datapath & Control

LECTURE 6. Multi-Cycle Datapath and Control

Lecture #17: CPU Design II Control

Chapter 4. The Processor. Computer Architecture and IC Design Lab

Outline. EEL-4713 Computer Architecture Designing a Single Cycle Datapath

CS359: Computer Architecture. The Processor (A) Yanyan Shen Department of Computer Science and Engineering

CS61C : Machine Structures

Recap: A Single Cycle Datapath. CS 152 Computer Architecture and Engineering Lecture 8. Single-Cycle (Con t) Designing a Multicycle Processor

Review: Abstract Implementation View

ECE 313 Computer Organization FINAL EXAM December 14, This exam is open book and open notes. You have 2 hours.

The Processor: Datapath & Control

RISC Architecture: Multi-Cycle Implementation

CS 61C: Great Ideas in Computer Architecture. MIPS CPU Datapath, Control Introduction

5.7. Microprogramming: Simplifying Control Design 5.7

ECE 313 Computer Organization FINAL EXAM December 11, Multicycle Processor Design 30 Points

How to design a controller to produce signals to control the datapath

Chapter 5: The Processor: Datapath and Control

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

Points available Your marks Total 100

Review. N-bit adder-subtractor done using N 1- bit adders with XOR gates on input. Lecture #19 Designing a Single-Cycle CPU

Lecture 6 Datapath and Controller

CENG 3420 Lecture 06: Datapath

361 control.1. EECS 361 Computer Architecture Lecture 9: Designing Single Cycle Control

Hardwired Control Unit Ch 16

EECS150 - Digital Design Lecture 10- CPU Microarchitecture. Processor Microarchitecture Introduction

Working on the Pipeline

ECE170 Computer Architecture. Single Cycle Control. Review: 3b: Add & Subtract. Review: 3e: Store Operations. Review: 3d: Load Operations

Multiple Cycle Data Path

EECE 417 Computer Systems Architecture

Ch 5: Designing a Single Cycle Datapath

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

UC Berkeley CS61C : Machine Structures

EECE 417 Computer Systems Architecture

CS 61C: Great Ideas in Computer Architecture Datapath. Instructors: John Wawrzynek & Vladimir Stojanovic

Control Unit for Multiple Cycle Implementation

Processor (I) - datapath & control. Hwansoo Han

Hardwired Control Unit Ch 14

Transcription:

Control Implementation Alternatives Control may be designed using one of several initial representations. The choice of sequence control, and how logic is represented, can then be determined independently; the control can then be implemented with one of several methods using a structured logic technique. Initial Representation Finite State Diagram Microprogram Sequencing Control Explicit Next State Microprogram counter Function + Dispatch ROMs Logic Representation Logic Equations Truth Tables Implementation PLA ROM Technique hardwired control microprogrammed control #1 Lec # 6 Winter2000 1-8-2001

PCWr PC 32 32 32 Alternative datapath (Textbook): IorD 0 Mux 1 32 32 RAdr Multiple Cycle Datapath PCWrCond Zero MemWr 32 Ideal Memory WrAdr Din Dout 32 IRWr Instruction Reg 32 Mem Data Reg RegDst Rs Rt Rt 0 Mux 5 5 Rd 1 1 Mux 0 RegWr Ra Rb busa Reg File Rw buswbusb A B << 2 ALUSelA 32 4 32 PCSrc 0 Mux 1 0 1 2 3 1 Mux 0 32 32 32 ALU ALU Control Zero 32 ALU Out Imm 16 ExtOp Extend 32 MemtoReg ALUSelB ALUOp #2 Lec # 6 Winter2000 1-8-2001

Operations In Each Cycle R-Type Logic Immediate Load Store Branch Instruction Fetch IR Mem[PC] PC PC + 4 IR Mem[PC] PC PC + 4 IR Mem[PC] PC PC + 4 IR Mem[PC] PC PC + 4 IR Mem[PC] PC PC + 4 Instruction Decode A R[rs] B R[rt] ALUout PC + (SignExt(imm16) x4) A R[rs] B R[rt] ALUout PC + (SignExt(imm16) x4) A R[rs] B R[rt] ALUout PC + (SignExt(imm16) x4) A R[rs] B R[rt] ALUout PC + (SignExt(imm16) x4) A B R[rs] R[rt] ALUout PC + (SignExt(imm16) x4) Execution ALUout A + B ALUout A OR ZeroExt[imm16] ALUout A + SignEx(Im16) ALUout A + SignEx(Im16) If Equal = 1 PC ALUout Memory M Mem[ALUout] Mem[ALUout] B Write Back R[rd] ALUout R[rt] ALUout R[rd] Mem #3 Lec # 6 Winter2000 1-8-2001

Finite State Machine (FSM) Specification IR MEM[PC] PC PC + 4 0000 instruction fetch A R[rs] B R[rt] ALUout PC +SX 0001 decode Execute R-type ALUout A fun B 0100 ORi ALUout A op ZX 0110 LW ALUout A + SX 1000 SW ALUout A + SX 1011 BEQ If A = B then PC ALUout 0010 Memory R[rd] ALUout 0101 To instruction fetch R[rt] ALUout 0111 M MEM[ALUout] 1001 R[rt] M 1010 To instruction fetch MEM[ALUout] B 1100 To instruction fetch #4 Lec # 6 Winter2000 1-8-2001 Write-back

Microprogrammed Control Finite state machine control for a full set of instructions is very complex, and may involve a very large number of states: Slight microoperation changes require new FSM controller. Microprogramming: Designing the control as a program that implements the machine instructions. A microprogam for a given machine instruction is a symbolic representation of the control involved in executing the instruction and is comprised of a sequence of microinstructions. Each microinstruction defines the set of datapath control signals that must asserted (active) in a given state or cycle. The format of the microinstructions is defined by a number of fields each responsible for asserting a set of control signals. Microarchitecture: Logical structure and functional capabilities of the hardware as seen by the microprogrammer. #5 Lec # 6 Winter2000 1-8-2001

A Typical Microcode Controller Implementation ROM/ PLA #6 Lec # 6 Winter2000 1-8-2001

Macroinstruction Interpretation Main Memory CPU execution unit control memory Microprogram Storage ADD SUB AND... DATA User program plus Data one of these is mapped into one of these AND microsequence e.g., Fetch Calc Operand Addr Fetch Operand(s) Calculate Save Answer(s) #7 Lec # 6 Winter2000 1-8-2001

Variations on Microprogram Formats Horizontal Microcode: A control field for each control point in the machine. µseq µaddr A-mux B-mux bus enables register enables Vertical Microcode: A Compact microinstruction format for each class of control points. Local decode is used to generate all control points. Vertical Horizontal #8 Lec # 6 Winter2000 1-8-2001

More Vertical Microprogram Formats src dst other control fields next states inputs D E C D E C MUX Multiformat Microcode: 1 3 6 0 cond next address 1 3 3 3 1 dst src alu Branch Jump Register Xfer Operation D E C D E C #9 Lec # 6 Winter2000 1-8-2001

Microinstruction Format/Addressing Start with list of all control signals. Partition control signals with similar functions into a number of signal sets that share a single microinstruction field. A sequencing microinstruction field is used to indicate the next microinstruction to execute. Places fields in some logical order (e.g., ALU operation & ALU operands first and microinstruction sequencing last). Since microinstructions are placed in a ROM or PLA, addresses must be assigned to microinstructions, usually sequentially. Create a symbolic legend for the microinstruction format, showing name of field values and how they set the control signals. To minimize microinstruction width, operations that will never be used at the same time may be encoded. #10 Lec # 6 Winter2000 1-8-2001

Next Microinstruction Selection The next microinstruction to execute can be found by using the sequencing field: Branch to a microinstruction that begins execution of the next MIPS instruction. Fetch is placed in the sequencing field. Increment the address of the current instruction. Indicated in the microinstruction by putting Seq in the sequencing field. Choose the next microinstruction based on the control unit input (a dispatch). Dispatches are implemented by a look-up table stored in a ROM containing addresses of target microinstruction. The table is indexed by the control unit input. A dispatch operation is indicated by placing Dispatch i in the sequencing field; i is the dispatch table number. #11 Lec # 6 Winter2000 1-8-2001

Microprogrammed Control Unit Microprogram Storage ROM/PLA Outputs Control Signal Fields Multicycle Datapath 1 Adder Microinstruction Address Inputs State Reg Sequencing Control Field Types of branching Set state to 0 (fetch) Dispatch i (state 1) Use incremented address (seq) state number 2 Address Select Logic Microprogram Counter, MicroPC Opcode #12 Lec # 6 Winter2000 1-8-2001

Next State Function: Sequencing Field For next state function (next microinstruction address): Signal Name Value Effect Sequencing Fetch 00 Next µaddress = 0 Dispatch i 01 Next µaddress = dispatch ROM Seq 10 Next µaddress = µaddress + 1 1 Microprogram Storage Adder µaddress Select Logic micropc Mux 2 1 0 0 ROM Opcode Dispatch ROM #13 Lec # 6 Winter2000 1-8-2001

Single Bit Control Multiple Bit Control List of control Signals Grouped Into Fields Signal name Effect when deasserted Effect when asserted ALUSelA 1st ALU operand = PC 1st ALU operand = Reg[rs] RegWrite None Reg. is written MemtoReg Reg. write data input = ALU Reg. write data input = memory RegDst Reg. dest. no. = rt Reg. dest. no. = rd MemRead None Memory at address is read, MDR Mem[addr] MemWrite None Memory at address is written IorD Memory address = PC Memory address = S IRWrite None IR Memory PCWrite None PC PCSource PCWriteCond None IF ALUzero then PC PCSource PCSource PCSource = ALU PCSource = ALUout Signal name Value Effect ALUOp 00 ALU adds 01 ALU subtracts 10 ALU does function code 11 ALU does logical OR ALUSelB 000 2nd ALU input = Reg[rt] 001 2nd ALU input = 4 010 2nd ALU input = sign extended IR[15-0] 011 2nd ALU input = sign extended, shift left 2 IR[15-0] 100 2nd ALU input = zero extended IR[15-0] #14 Lec # 6 Winter2000 1-8-2001

Microinstruction Format Field Name Width Control Signals Set wide narrow ALU Control 4 2 ALUOp SRC1 2 1 ALUSelA SRC2 5 3 ALUSelB Destination 3 2 RegWrite, MemtoReg, RegDst Memory 4 3 MemRead, MemWrite, IorD Memory Register 1 1 IRWrite PCWrite Control 4 3 PCWrite, PCWriteCond, PCSource Sequencing 3 2 AddrCtl Total width 26 17 bits #15 Lec # 6 Winter2000 1-8-2001

Microinstruction Field Values Field Name Values for Field Function of Field with Specific Value ALU Add ALU adds Subt. ALU subtracts Func code ALU does function code Or ALU does logical OR SRC1 PC 1st ALU input = PC rs 1st ALU input = Reg[rs] SRC2 4 2nd ALU input = 4 Extend 2nd ALU input = sign ext. IR[15-0] Extend0 2nd ALU input = zero ext. IR[15-0] Extshft 2nd ALU input = sign ex., sl IR[15-0] rt 2nd ALU input = Reg[rt] destination rd ALU Reg[rd] ALUout rt ALU Reg[rt] ALUout rt Mem Reg[rt] Mem Memory Read PC Read memory using PC Read ALU Read memory using ALU output Write ALU Write memory using ALU output, value B Memory register IR IR Mem PC write ALU PC ALU ALUoutCond IF ALU Zero then PC ALUout Sequencing Seq Go to sequential µinstruction Fetch Go to the first microinstruction Dispatch i Dispatch using ROM. #16 Lec # 6 Winter2000 1-8-2001

Instruction Fetch/decode Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Fetch: Add PC 4 Read PC IR ALU Seq Add PC Extshft Dispatch First microinstruction: Fetch, increment PC Field Name Value for Field Function of Field ALU Add ALU adds SRC1 PC 1st ALU input = PC SRC2 4 2nd ALU input = 4 Memory Read PC Read memory using PC Memory register IR IR Mem PC write ALU PC ALU Sequencing Seq Go to sequential µinstruction Second microinstruction: Decode, calculate branch address Field Name Value for Field Function of Field ALU Add ALU adds result in ALUout SRC1 PC 1st ALU input = PC SRC2 Extshft 2nd ALU input = sign ex., sl IR[15-0] Sequencing Dispatch Dispatch using ROM according to opcode #17 Lec # 6 Winter2000 1-8-2001

LW Completion Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Lw: Add rs Extend Seq Read ALU Seq rt MEM Fetch First microinstruction: Execute, effective memory address calculation Field Name Value for Field Function of Field ALU Add ALU adds, result in ALUout SRC1 rs 1st ALU input = Reg[rs] SRC2 Extend 2nd ALU input = sign ext. IR[15-0] Sequencing Seq Go to sequential µinstruction Second microinstruction: Memory, read using ALUout Field Name Values for Field Function of Field Memory Read ALU Read memory using ALU output Sequencing Seq Go to sequential µinstruction Third microinstruction: Write Back, from memory to register rt Field Name Values for Field Function of Field destination rt Mem Reg[rt] Mem Sequencing Fetch Go to the first microinstruction (fetch) #18 Lec # 6 Winter2000 1-8-2001

SW Completion Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Sw: Add rs Extend Seq Write ALU Fetch First microinstruction: Execute, effective memory address calculation Field Name Value for Field Function of Field ALU Add ALU adds result in ALUout SRC1 rs 1st ALU input = Reg[rs] SRC2 Extend 2nd ALU input = sign ext. IR[15-0] Sequencing Seq Go to sequential µinstruction Second microinstruction: Memory, write to memory Field Name Values for Field Function of Field Memory Write ALU Write memory using ALU output, value B Sequencing Fetch Go to the first microinstruction (fetch) #19 Lec # 6 Winter2000 1-8-2001

R-Type Completion Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Rtype: Func rs rt Seq rd ALU Fetch First microinstruction: Execute, perform ALU function Field Name Value for Field Function of Field ALU Func code ALU does function code SRC1 rs 1st ALU input = Reg[rs] SRC2 rt 2nd ALU input = Reg[rt] Sequencing Seq Go to sequential µinstruction Second microinstruction: Write Back, ALU result in register rd Field Name Values for Field Function of Field destination rd ALU Reg[rd] ALUout Sequencing Fetch Go to the first microinstruction (fetch) #20 Lec # 6 Winter2000 1-8-2001

BEQ Completion Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Beq: Subt. rs rt ALUoutCond. Fetch First microinstruction: Execute, compute condition, update PC Field Name Values for Field Function of Field ALU Subt. ALU subtracts SRC1 rs 1st ALU input = Reg[rs] SRC2 rt 2nd ALU input = Reg[rt] PC write ALUoutCond IF ALU Zero then PC ALUout Sequencing Fetch Go to the first microinstruction (fetch) #21 Lec # 6 Winter2000 1-8-2001

ORI Completion Microcode Sequence Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Ori: Or rs Extend0 Seq rt ALU Fetch First microinstruction: Execute, rs OR immediate Field Name Value for Field Function of Field ALU Or ALU does logical OR result in ALUout SRC1 rs 1st ALU input = Reg[rs] SRC2 Extend0 2nd ALU input = zero ext. IR[15-0] Sequencing Seq Go to sequential µinstruction Second microinstruction: Write Back, ALU result in register rt Field Name Values for Field Function of Field destination rt ALU Reg[rt] ALUout Sequencing Fetch Go to the first microinstruction (fetch) #22 Lec # 6 Winter2000 1-8-2001

Microprogram for The Control Unit Label ALU SRC1 SRC2 Dest. Memory Mem. Reg. PC Write Sequencing Fetch: Add PC 4 Read PC IR ALU Seq Add PC Extshft Dispatch Lw: Add rs Extend Seq Read ALU Seq rt MEM Fetch Sw: Add rs Extend Seq Write ALU Fetch Rtype: Func rs rt Seq rd ALU Fetch Beq: Subt. rs rt ALUoutCond. Fetch Ori: Or rs Extend0 Seq rt ALU Fetch #23 Lec # 6 Winter2000 1-8-2001

Microprogramming Pros and Cons Ease of design. Flexibility: Easy to adapt to changes in organization, timing, technology. Can make changes late in design cycle, or even in the field. Can implement very powerful instruction sets (just more microprogram control memory is needed). Generality: Can implement multiple instruction sets on the same machine. Can tailor instruction set to application. Compatibility: Many organizations, same instruction set. Possibly more costly to implement than FSM control. Slower than FSM control. #24 Lec # 6 Winter2000 1-8-2001

Exceptions Handling in MIPS Exceptions: Events Other than branches or jumps that change the normal flow of instruction execution. Two main types: Interrupts, Traps. An interrupt usually comes from outside the processor (I/O devices) to get the CPU s attention to start a service routine. A trap usually originates from an event within the CPU (Arithmetic overflow, undefined instruction) and initiates an exception handling routine usually by the operating system. The current MIPS implementation being considered can be extended to handle exceptions by adding two additional registers and the associated control lines: EPC: A 32 bit register to hold the address of the affected instruction Cause: A register used to record the cause of the exception. In this implementation only the low-order bit is used to encode the two handled exceptions: undefined instruction = 0 overflow = 1 Two additional states are added to the control finite state machine to handle these exceptions. #25 Lec # 6 Winter2000 1-8-2001

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. #26 Lec # 6 Winter2000 1-8-2001

Exception Handling user program Exception: System Exception Handler return from exception Exception = an 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. #27 Lec # 6 Winter2000 1-8-2001

Addressing The Exception Handler Traditional Approach, Interrupt Vector: PC MEM[ IV_base + cause 00] Used in: 370, 68000, Vax, 80x86,... RISC Handler Table: PC IT_base + cause 0000 iv_base cause handler code saves state and jumps Used in: Sparc, HP-PA,... MIPS Approach: Fixed entry PC EXC_addr Actually a very small table: RESET entry TLB other iv_base handler entry code cause #28 Lec # 6 Winter2000 1-8-2001

Exception Handling: Saving The 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. #29 Lec # 6 Winter2000 1-8-2001

Additions to MIPS to Support Exceptions EPC: A 32-bit register used to hold the address of the affected instruction (in reality 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 encode the two possible exception sources mentioned above: Undefined instruction = 0 Arithmetic overflow = 1 (in reality, register 13 of coprocessor 0). BadVAddr: Register contains 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 01000000 00000000 00000000 01000000 two (8000 0080 hex ). May have to undo PC = PC + 4, since we want EPC to point to offending instruction (not its successor); PC = PC - 4 #30 Lec # 6 Winter2000 1-8-2001

Details of MIPS Status Register Status 15 8 5 Mask k 4 e 3 k 2 e 1 k 0 e old prev current 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 #31 Lec # 6 Winter2000 1-8-2001

Details of MIPS Cause register Status 15 10 Pending 5 2 Code 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. #32 Lec # 6 Winter2000 1-8-2001

The MIPS Multicycle Datapath With Exception Handling Added #33 Lec # 6 Winter2000 1-8-2001

Finite State Machine (FSM) Specification IR MEM[PC] PC PC + 4 0000 instruction fetch A R[rs] B R[rt] ALUout PC +SX 0001 decode Execute R-type ALUout A fun B 0100 ORi ALUout A op ZX 0110 LW ALUout A + SX 1000 SW ALUout A + SX 1011 BEQ If A = B then PC ALUout 0010 Memory R[rd] ALUout 0101 To instruction fetch R[rt] ALUout 0111 M MEM[ALUout] 1001 R[rt] M 1010 To instruction fetch MEM[ALUout] B 1100 To instruction fetch #34 Lec # 6 Winter2000 1-8-2001 Write-back

Exception Processing FSM Control States Arithmetic overflow Undefined Instruction #35 Lec # 6 Winter2000 1-8-2001

FSM Control Specification To Handle Exceptions Execute overflow EPC PC - 4 PC exp_addr cause 12 (Ovf) R-type ALUout A fun B 0100 ORi ALUout A op ZX 0110 A R[rs] B R[rt] IR MEM[PC] PC PC + 4 LW 0000 ALUout PC +SX 0001 ALUout A + SX 1000 SW instruction fetch decode ALUout A + SX 1011 undefined instruction BEQ EPC PC - 4 PC exp_addr cause 10 (RI) If A = B then PC ALUout 0010 Memory R[rd] ALUout 0101 To instruction fetch R[rt] ALUout 0111 M MEM[ALUout] 1001 R[rt] M 1010 To instruction fetch MEM[ALUout] B 1100 To instruction fetch #36 Lec # 6 Winter2000 1-8-2001 Write-back

Control Finite State Machine With Exception Detection Version In Textbook #37 Lec # 6 Winter2000 1-8-2001