Professional Documents
Culture Documents
Computer Science 37 Lecture 18
Computer Science 37 Lecture 18
Microinstruction Format
ALU Control
What is done
ALU SRC1
ALU SRC2
Register Control
R or W Source for W
Memory
PCWrite Control
When to write
Sequencing
Operand sources
R or W Source for W
Microprogramming
Label: any string, direct targets for sequencing, or dispatch to jump tables. ALU Control: Add, Subt, or Func Code. SRC1: PC, register A.
26
Shift left 2
28
1 u
x 2
PC
0 M u x 1
Address
Memory MemData Write data
Instruction [2521] Instruction [2016] Instruction [150] Instruction register Instruction [150] Memory data register
Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A
0 M Instruction u x [1511] 1 0 M u x 1
0 M u x 1 0 4 1 M u 2 x 3
PC [31-28]
ALUOut
16
Sign extend
32
Shift left 2
ALU control
Instruction [50]
Question: What is dispatch i? Dispatch is an operation similar to a switch or case statement. There can be two dispatch tables, indicated by the i value, which can be either 1 or 2.
Address select logic
opcode, i
PC
to ROM
1) ALU Control, SRC1, SRC2: ALU = PC+4 Memory: IR = instruction PCWrite Control: PC = ALU Sequencing: next microinstruction 2) ALU Control, SRC1, SRC2: ALUOut = PC + sign extension (IR[15-0]) << 2 (just in case next instruction is a branch) Register control: A = rs, B = rt Sequencing: use opcode and dispatch table 1 to choose what comes next (will go to one of these labels Mem1, RFormat1, BEQ1, JUMP1)
1) Whether its lw or sw, I must compute the address referenced: addr = A + Extend lw: read from memory the data addressed by the output of the ALU and then write it to the MDR
3) sw: take the contents of register B and write the data to the memory position addressed by the output of the ALU Note: the microcode for every instruction ends with a jump to Fetch.
wake up calls
I/O device request Bus error Hardware malfunction
Something outside the CPU requires attention: control flow also changes unexpectedly
When an exception or an interrupt happens, the normal instruction flow is disrupted so that this unexpected event can be dealt with. User code is stopped, perhaps temporarily, and a branch happens to an interrupt handler. We must know what caused the interruption so we know what course of action it demands.
EPC
register
Cause
register
10
Question: how do we determine where to branch? a) We always branch to the same address (MIPS): 0xC0000000. b) The address of the branch is determined by the cause of the exception (vectored interrupts). Question: how do we put the address of this branch in the PC? Change the MUX to 4-way and add another control value to the selection control => PCSource =11. Complication: the PC has already been incremented by the fetch datapath. Hook up the data input of the EPC to the ALU, which is used to subtract 4 from the current value of the PC.
11
Modifying Control to Deal with Exceptions Basic types of exceptions in MIPS: 1) Undefined Instruction: no next state when inspecting opcode. 2) Arithmetic Overflow: information comes from the ALU. Modifications to the FSM for the Control Unit
(see Figure 5.50 for complete FSM)
11 IntCause = 1 CauseWrite ALUSrcA = 0 ALUSrcB = 01 ALUOp = 01 EPCWrite PCWrite PCSource = 11 PCSource = 11
10
12
PC
Address
Memory MemData Write data
% $ # ! "
0 M u x 1
Instruction [31-26] Instruction Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A
0 M Instruction u x 1 0 M u x 1
16
26
Shift left 2
28
1M
2 3 u x
% $ # ! "
0 M u x 1 0 4 1M u 2 x 3 B Sign extend
32
CO 00 00 00
PC [31-28]
ALUOut
EPC
0 M u x 1
Cause
13