exceptions - basavaraj talawar · breakpoint (programmer-requested interrupt) ... processor state,...

38
Exceptions

Upload: others

Post on 26-Sep-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions

Page 2: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Outline

● Exception Handling● Precise and Imprecise exceptions● Exceptions in OoO pipelines

Page 3: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions

Events that requestattention of the processor

Events that requestattention of the processor

Page 4: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request

Events that requestattention of the processor

Events that requestattention of the processor

Page 5: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program

Events that requestattention of the processor

Events that requestattention of the processor

Page 6: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program● Breakpoint (programmer-requested interrupt)

Events that requestattention of the processor

Events that requestattention of the processor

Page 7: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program● Breakpoint (programmer-requested interrupt)● Integer arithmetic overflow/FP arithmetic anomaly

Events that requestattention of the processor

Events that requestattention of the processor

Page 8: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program● Breakpoint (programmer-requested interrupt)● Integer arithmetic overflow/FP arithmetic anomaly● Page fault

Events that requestattention of the processor

Events that requestattention of the processor

Page 9: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program● Breakpoint (programmer-requested interrupt)● Integer arithmetic overflow/FP arithmetic anomaly● Page fault● Undefined or unimplemented instruction

Events that requestattention of the processor

Events that requestattention of the processor

Page 10: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions● I/O device request● Invoking OS service from a user program● Breakpoint (programmer-requested interrupt)● Integer arithmetic overflow/FP arithmetic anomaly● Page fault● Undefined or unimplemented instruction● Hardware malfunctions, Power failure

Events that requestattention of the processor

Events that requestattention of the processor

Page 11: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exceptions

Page 12: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Precise Exception Handling

LD

Page 13: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Precise Exception Handling

LD

On exception, flush all prior stagesOn exception, flush all prior stages

Page 14: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling

Page 15: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling● Save the address of the offending instruction in

the exception program counter (EPC)– SEPC in RISC-V

Page 16: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling● Save the address of the offending instruction in

the exception program counter (EPC)● Transfer control to the operating system at some

specified address.

Page 17: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling● Save the address of the offending instruction in

the exception program counter (EPC)● Transfer control to the operating system at some

specified address.● Handle the exception

– Providing some service to the user program– Taking some predefined action in response to an

overflow– Stopping the execution of the program and reporting

an error

Page 18: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling● Save the address of the offending instruction in the

exception program counter (EPC)● Transfer control to the operating system at some

specified address.● Handle the exception

– Providing some service to the user program– Taking some predefined action in response to an overflow– Stopping the execution of the program and reporting an

error● OS can terminate or may use EPC to restart

program

Page 19: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Communicating Exception Cause to OS

● A register records the cause of exception– Supervisor Exception Cause (SCAUSE) Register

Page 20: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Communicating Exception Cause to OS

● A register records the cause of exception– Supervisor Exception Cause (SCAUSE) Register

● Vectored Interrupts

Page 21: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Communicating Exception Cause to OS

● A register records the cause of exception– Supervisor Exception Cause (SCAUSE) Register

● Vectored Interrupts– Cause of the exception determines offset to jump– Added to a Vector Table Base register

Page 22: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Communicating Exception Cause to OS

● A register records the cause of exception– Supervisor Exception Cause (SCAUSE) Register

● Vectored Interrupts– Cause of the exception determines offset to jump– Added to a Vector Table Base register

Page 23: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

RISC-V Exception Handling● SEPC, SCAUSE● Single entry point for Exception handler

– 0000 0000 1C09 0000hex

Page 24: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

RISC-V Exception Handling● SEPC, SCAUSE● Single entry point for Exception handler

– 0000 0000 1C09 0000hex

● For the pipeline, handling Exceptions are similar to handling Control Hazards–

Page 25: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

RISC-V Exception Handling● SEPC, SCAUSE● Single entry point for Exception handler

– 0000 0000 1C09 0000hex

● For the pipeline, handling Exceptions are similar to handling Control Hazards– SEPC saves instruction causing Exception’s PC – SCAUSE is filled– Flush all previous stages and the exception instruction– Load Exception handler address to PC

Page 26: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

RISC-V Exception Handling Pipeline

Page 27: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

RISC-V Exception Handling Pipeline

Page 28: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling Example

Hardware malfunction exception occurs in the add instruction.

Page 29: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling Example

IF ID

IF

Page 30: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling Example

IF ID EX MEM WB

IF ID EX MEM WB

IF ID EX MEM WB

IF ID

IF ID

IF

IF ID

IF

E

Page 31: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling Example

Page 32: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Exception Handling Example

Page 33: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Outline

● Exception Handling● Precise and Imprecise exceptions

Page 34: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Multi-cycle Operations Pipeline

Page 35: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Precise Exceptions

● Out of order completion● Can't ignore exceptions

– Virtual Memory, IEEE 754● Fast mode vs. Slow mode with precise

exceptions● Store results of earlier operations in a buffer

– History file, Future file.

DIV.D F0, F2, F4

ADD.D F10, F10, F8

SUB.D F12, F12, F14

Page 36: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Stopping and Restarting Execution● Trap instruction, Turn off writes, Save PC, Save

processor state, (Disable Exceptions), Exception handler, RFE

● Precise exceptions

Pipeline stage Problem exceptions occurring

IFPage fault on IF, misaligned memory access; memory protection violation

ID Undefined or illegal opcode

EX Arithmetic exception

MEMPage fault on data fetch; misaligned memory access; memory protection violation

WB None

Page 37: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Precise Exceptions

LD IF ID EX MEM WB

DADD IF ID EX MEM WB

● Multiple exceptions in the same cycle● Early exception by a later instruction● Instruction Status Vector: Check before commit

Page 38: Exceptions - Basavaraj Talawar · Breakpoint (programmer-requested interrupt) ... processor state, (Disable Exceptions), Exception handler, RFE Precise exceptions Pipeline stage Problem

Precise Exceptions

● Instruction Status Vector: Check before commit