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
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
For a kind of event, enter 1 for an exception and 2 for an interrupt.
| Address, in hex | Instruction |
|---|---|
| 00 | addi x5, x0, 64 |
| 04 | csrw mtvec, x5 |
| 08 | addi x10, x0, 3 |
| 0c | ecall |
| 10 | addi x10, x10, 1 |
| 14 | .word 0x00000000 |
| 18 | addi x10, x10, 1 |
| 1c | jal x0, 0x1c |
| 40 | csrr x6, mcause |
| 44 | add x10, x10, x6 |
| 48 | csrr x7, mepc |
| 4c | addi x7, x7, 4 |
| 50 | csrw mepc, x7 |
| 54 | mret |
Enter every address and every value in decimal. The address 40 in hex is 64.
| Entry | Your decision |
|---|---|
| WORD_THAT_IS_NO_INSTRUCTION | The decoder finds a word that is no instruction. Which kind? |
| TIMER_REACHES_ITS_VALUE | The timer reaches its compare value. Which kind? |
| MEPC_AT_THE_FIRST_TRAP | What does mepc hold right after the first trap of the program? |
| ECALL | The instruction ecall is executed. Which kind? |
| BYTE_ARRIVES_AT_THE_UART | A byte arrives at the UART, and the UART raises its line. Which kind? |
| LOAD_WITH_NO_MEMORY | A load uses an address where no memory is. Which kind? |
| SAME_INSTRUCTION_IN_EVERY_RUN | Which kind happens at the same instruction in every run of the same program? |
| MCAUSE_AT_THE_FIRST_TRAP | What does mcause hold right after the first trap? |
| MEPC_AT_THE_SECOND_TRAP | What does mepc hold right after the second trap? |
| MCAUSE_AT_THE_SECOND_TRAP | What does mcause hold right after the second trap? |
| SECOND_RETURN_ADDRESS | To which address does the second mret go? |
| HANDLER_INSTRUCTIONS | How many instructions of the handler are executed in the whole run? |
| X10_AT_STOP | What does x10 hold when the program stops? |
| X10_FOR_K | The 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