S6.4.1 Vectored Entry

MediumImplement20 minIcarus Verilog · serverReview the topic

Convert an RV32 machine trap record into the byte address of the first handler instruction.

Hardware context: ap_soc machine trap entry and return. Machine-mode firmware and deadline analysis

The trap has already been accepted. Read mtvec and mcause as raw 32-bit CSR values. The fixture accepts only direct and vectored mode and supports four-byte BASE alignment in both.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification

mtvec bits 1:0 encode mode (0 direct, 1 vectored). Its other bits encode the aligned address. mcause bit 31 marks interrupts. The remaining bits are an unsigned cause code.

Examples

Example 1

First Observation
Input
BASE=0x100, mode=1, interrupt=1, cause=11
Output
pc = 0x12c

The external interrupt selects slot eleven. Each slot is four bytes.

Example 2

Second Observation
Input
BASE=0x100, mode=1, interrupt=0, cause=2
Output
pc = 0x100

A synchronous exception goes to the common entry.

Example 3

Third Observation
Input
BASE=0x200, mode=0, interrupt=1, cause=7
Output
pc = 0x200

Direct mode sends the timer to BASE.

Constraints and Contract

  • Synchronous exceptions enter at BASE in both modes. Direct interrupts also enter there. For a vectored interrupt add four bytes per cause code. Return the low 32 address bits.

Hints

Hint 1

Separate mode and interrupt flag from their payloads.

Hint 2

Decide whether the cause selects an offset.

Hint 3

Convert slot number to an instruction address.

What the grader checks: Both modes, both trap classes, each significant address and cause bit, zero and 32-bit wraparound.

144 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 4 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

First Observation

Input
BASE=0x100, mode=1, interrupt=1, cause=11
Expected output
pc = 0x12c

The external interrupt selects slot eleven. Each slot is four bytes.

Run samples executes all 3 public checks. Check all tests runs 144 checks on the server.

Icarus Verilog · server