Microprogramming and Exceptions Spring 2005 Ilam University Microprogramming

  • Slides: 16
Download presentation
Microprogramming and Exceptions Spring 2005 Ilam University

Microprogramming and Exceptions Spring 2005 Ilam University

Microprogramming l FSM l l l State – bubble Control signals in bubble Next

Microprogramming l FSM l l l State – bubble Control signals in bubble Next state given by signals on arc Not a great language for specifying complex events Instead, treat as a programming problem

Microprogramming l l l Datapath remains the same Control is specified differently but does

Microprogramming l l l Datapath remains the same Control is specified differently but does the same Each cycle a microprogram field specifies required control signals Label Alu Src 1 Src 2 Reg Memory Pcwrite Next? Fetch Add Pc 4 Read pc ALU +1 Add Pc Extshft Read Add A Extend Mem 1 Dispatch 2 Lw 2 Read ALU +1 Write mdr SW 2 Rformat fetch Write ALU Func code A B +1 Write ALU Beq 1 Subt A B Fetch ALUout-Cond Fetch

FSM vs. Microprogramming

FSM vs. Microprogramming

Benefits of Microprogramming l More disciplined control logic l l l Easier to debug

Benefits of Microprogramming l More disciplined control logic l l l Easier to debug Enables family of machines with same ISA Enables more complex ISA (benefit? ) Writeable control store allows late fixes But, in the 1990’s l l CAD tools and PLAs offer similar discipline Caches make memory almost as fast as control store

State of the Art l Specify control l l FSM – does not scale

State of the Art l Specify control l l FSM – does not scale easily Microprogram – works VHDL/Verilog – preferred Specify control in VHDL/Verilog l l CAD compile to PLA Could use ROM or RAM

Exceptions l What happens? l l l l Instruction fetch page fault Illegal opcode

Exceptions l What happens? l l l l Instruction fetch page fault Illegal opcode Privileged opcode Arithmetic overflow Data page fault I/O device status change Power-on/reset Solution: l “procedure call”

Exceptions: Big Picture l Two types: l l Interrupt (asynchronous) or Trap (synchronous) Hardware

Exceptions: Big Picture l Two types: l l Interrupt (asynchronous) or Trap (synchronous) Hardware handles initial reaction Then invokes a software exception handler l l By convention, at e. g. 0 x. C 00 O/S kernel provides code at the handler address

Exceptions: Hardware l Sets state that identifies cause of exception l l l Changes

Exceptions: Hardware l Sets state that identifies cause of exception l l l Changes to kernel mode for dangerous work ahead Disables interrupts l l MIPS: recorded in status register Saves current PC l l MIPS: in exception_code field of Cause register MIPS: Exception PC Jumps to specific address l l MIPS: 0 x 80000080 Like a surprise JAL – so can’t clobber $31

Exceptions: Software l Exception handler: l l Set flag to detect incorrect entry l

Exceptions: Software l Exception handler: l l Set flag to detect incorrect entry l l l Nested exception while in handler Save some registers Find exception type l l MIPS: . ktext at 0 x 80000080 E. g. I/O interrupt or syscall Jump to specific exception handler

Exceptions: Software, cont’d l l l Handle specific exception Jump to clean-up to resume

Exceptions: Software, cont’d l l l Handle specific exception Jump to clean-up to resume user program Restore registers Reset flag that detects incorrect entry Atomically l l l Restore previous mode (user vs. supervisor) Enable interrupts Jump back to program (using EPC)

Implementing Exceptions l l We worry only about hardware, not s/w Int. Cause l

Implementing Exceptions l l We worry only about hardware, not s/w Int. Cause l l l Changes to the datapath l l 0 undefined instruction 1 arithmetic overflow Detect exception Additional source for next PC Storage for exception cause, return address, spare register New states in control FSM

FSM With Exceptions (F 5. 50)

FSM With Exceptions (F 5. 50)

Implementing Exceptions l l New arcs in FSM just like regular arcs FSM more

Implementing Exceptions l l New arcs in FSM just like regular arcs FSM more complex if must add many arcs Critical path may get worse Alternative: vectored interrupts l l PC = base = f(cause) E. g. PC = 0 x 80 + intcause << 7 # 32 instrs Faster More hardware, more space

Review Type Control Datapath Time (CPI, cycle time) Single- Combinational cycle No reuse 1

Review Type Control Datapath Time (CPI, cycle time) Single- Combinational cycle No reuse 1 cycle, (imem + reg + ALU + dmem) Multicycle Combinational + FSM Reuse [3, 5] cycles, Max(imem, reg, ALU, dmem) We want? ? ? ~1 cycle, Max(imem, reg, ALU, dmem) l We will use pipelining to achieve last row