S2.13.2 Interrupt or Exception

EasyImplement12 minIcarus Verilog · serverReview the topic

Sort six events into exceptions and interrupts. Then follow a program through two traps, and say what the CSRs hold.

Hardware context: A small model of a RISC-V processor with traps, as test code: seven machine CSRs, the entry of a trap and mret; every program also runs on the real core ap_rv32. Writing start-up code and trap handlers, and reading a trap in a trace

The first seven entries are about kinds of event. The others are about the program below. It runs on a processor with the trap rules of the lesson, in machine mode, and mtvec holds 0 until the program writes it.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification

For a kind of event, enter 1 for an exception and 2 for an interrupt.

The program
The handler is at 40 in hex. It adds the cause to x10, then returns behind the instruction that trapped.
Address, in hexInstruction
00addi x5, x0, 64
04csrw mtvec, x5
08addi x10, x0, 3
0cecall
10addi x10, x10, 1
14.word 0x00000000
18addi x10, x10, 1
1cjal x0, 0x1c
40csrr x6, mcause
44add x10, x10, x6
48csrr x7, mepc
4caddi x7, x7, 4
50csrw mepc, x7
54mret

Enter every address and every value in decimal. The address 40 in hex is 64.

EntryYour decision
WORD_THAT_IS_NO_INSTRUCTIONThe decoder finds a word that is no instruction. Which kind?
TIMER_REACHES_ITS_VALUEThe timer reaches its compare value. Which kind?
MEPC_AT_THE_FIRST_TRAPWhat does mepc hold right after the first trap of the program?
ECALLThe instruction ecall is executed. Which kind?
BYTE_ARRIVES_AT_THE_UARTA byte arrives at the UART, and the UART raises its line. Which kind?
LOAD_WITH_NO_MEMORYA load uses an address where no memory is. Which kind?
SAME_INSTRUCTION_IN_EVERY_RUNWhich kind happens at the same instruction in every run of the same program?
MCAUSE_AT_THE_FIRST_TRAPWhat does mcause hold right after the first trap?
MEPC_AT_THE_SECOND_TRAPWhat does mepc hold right after the second trap?
MCAUSE_AT_THE_SECOND_TRAPWhat does mcause hold right after the second trap?
SECOND_RETURN_ADDRESSTo which address does the second mret go?
HANDLER_INSTRUCTIONSHow many instructions of the handler are executed in the whole run?
X10_AT_STOPWhat does x10 hold when the program stops?
X10_FOR_KThe instruction at 08 becomes addi x10, x0, K. Give x10 at the stop as an expression in K.

Examples

Example 1

WORD THAT IS NO INSTRUCTION
Input
The decoder finds a word that is no instruction. Which kind?
Output
matches = 1

The instruction itself is the cause.

Example 2

TIMER REACHES ITS VALUE
Input
The timer reaches its compare value. Which kind?
Output
matches = 1

The signal comes from outside the program.

Example 3

MEPC AT THE FIRST TRAP
Input
What does mepc hold right after the first trap of the program?
Output
matches = 1

The ecall is at 0c in hex. mepc takes the address of the instruction that trapped.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For X10_FOR_K, enter a constant expression using K. Only this entry changes with the parameter. The supported integer range is 3 through 12, inclusive.

Hints

Hint 1

Ask of each event: does the instruction cause it, or does it come from outside?

Hint 2

Find the first instruction that cannot simply run. Its address goes to mepc, and its kind gives mcause.

Hint 3

Follow the six rows of the handler once. They are the same for both traps.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

14 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 3 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

WORD THAT IS NO INSTRUCTION

Input
The decoder finds a word that is no instruction. Which kind?
Expected output
matches = 1

The instruction itself is the cause.

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

Icarus Verilog · server