Docsity

Exceptions in MIPS architecture, Lecture notes of Computer Science

Toggle sidebar
bg1
What are Exception and Interrupts?
MIPS terminology
โ€ขException: any unexpected change in the internal
control flow
โ€“Invoking an operating system service from user program
โ€“Integer arithmetic overflow
โ€“Using an undefined or unimplemented instruction
โ€“Hardware malfunctions
โ€ขInterrupt: event is externally caused
โ€“I/O device request
โ€“Tracing instruction execution
โ€“Breakpoint (programmer-requested interrupt)
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Exceptions in MIPS architecture and more Lecture notes Computer Science in PDF only on Docsity!

What are Exception and Interrupts?

MIPS terminology

Exception: any unexpected change in the internal

control flow

  • Invoking an operating system service from user program
  • Integer arithmetic overflow
  • Using an undefined or unimplemented instruction
  • Hardware malfunctions

Interrupt: event is externally caused

I/O device request

Tracing instruction execution

Breakpoint (programmer-requested interrupt)

Exceptions in MIPS

stage Problem exceptions

occurring

IF Page fault on IF, misaligned memory

access, memory protection violation

ID Undefined or illegal opcode

EX Arithmetic exception

MEM Page fault on data fetch, misaligned

memory access, memory protection

violation

WB None

normal control flow:

sequential, jumps, branches, calls, returns

Exception

System

Exception

Handler

return from

exception

user program

Exception Handling in Multi-Cycle MIPS

Consider two types of exceptions:

  • arithmetic overflow
  • undefined instruction

First save the address of the offending instruction in

Exception Program Counter ( EPC ).

Transfer control to the operating system ( OS ) to

some specified address.

OS provides some service.

OS can stop the program or restart the program using

EPC.

Non Vectored Exceptions

A single entry point 8000 0180

hex

is used for all

exceptions.

The OS is decoding the status register to find the

cause.

Two registers are added to the data-path

EPC : 32-bit holding the address of the affected instruction.

It is required for vectored exceptions too.

Cause : 32-bit recording the exception cause (some bits

unused).

In this example LSB of Cause encodes the exception.

EPC must trim 4 from PC.

Exceptions Handling in Multi-Cycle MIPS

Exception in pipelined architecture

Force a trap instruction into the pipeline on

the next IF

Flush the pipeline for the faulting instruction

and all instructions that follow

After exception handling routine finishes,

restore the PC of the saved PC and delay

branches if exist

Additions to MIPS ISA

EPC (Exceptional Program Counter)

A 32-bit register

Holds the address of the offending instruction

Cause

A 32-bit register

Records the cause of the exception

Status

interrupts mask and enable bits that determines

what exceptions can occur.

Additions to MIPS ISA

Exceptions example

40 hex sub $11, $2, $

44 hex and $12, $2, $

48 hex or $13, $2, $

4Chex add $1, $2, $1; // arithmetic overflow

50 hex slt $15, $6, $

54 hex lw $16, 50($7)

80000240 hex sw $25, 1000($0)

80000244 hex sw $12, 1004($0)

: Exception handling program

Clock 6

overflow detected

flush ID

flush IF

nop

deasserting add

flush EX

Clock 7

first instruction of

exception routine

Precise Exceptions

If the pipeline can be stopped so that the

instructions just before the faulting instruction

are completed and the faulting instruction can

be restarted from scratch.

MIPS Exception Mechanism

The processor operates in

user mode

kernel mode

Access to additional set of registers and to

user mode restricted memory space available

when the processor operates in kernel mode.

The MIPS architecture includes the notion of

co-processors.