Read two fields from the address of a CSR. Then decide, for a level and a kind of access, whether the instruction runs or traps.
Hardware context: A small model of a RISC-V processor with a machine level and a user level, as test code; start-up code lowers the level and an application tries four things that only the machine level may do. The real core ap_rv32 v1.0 has machine level only. Planning which code runs at which level, and testing that protection really refuses
A CSR address has 12 bits. Bits 9 and 8 give the lowest privilege level that may use the CSR: 0 is user, 1 is supervisor, 3 is machine. Bits 11 and 10 at 11 mean that the CSR is read-only. An access that is not allowed traps as an illegal instruction. All CSRs below exist on the processor of this worksheet, and it has all three levels.
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
| Address, in hex | Address, in binary | Name |
|---|---|---|
| c00 | 1100 0000 0000 | cycle |
| 100 | 0001 0000 0000 | sstatus |
| 300 | 0011 0000 0000 | mstatus |
| 341 | 0011 0100 0001 | mepc |
| f14 | 1111 0001 0100 | mhartid |
| c01 | 1100 0000 0001 | time |
| 305 | 0011 0000 0101 | mtvec |
| 7b0 | 0111 1011 0000 | dcsr |
For a level, enter 0, 1 or 3. For a yes or no question, enter 1 for yes and 0 for no. For an access, enter 1 if the instruction runs and 2 if it traps.
| Entry | Your decision |
|---|---|
| LEVEL_OF_300 | Which is the lowest level that may use the CSR at 300? |
| F14_IS_READ_ONLY | Is the CSR at f14 read-only? |
| USER_READS_341 | User code reads the CSR at 341. Runs or traps? |
| LEVEL_OF_100 | Which is the lowest level that may use the CSR at 100? |
| LEVEL_OF_C00 | Which is the lowest level that may use the CSR at c00? |
| C00_IS_READ_ONLY | Is the CSR at c00 read-only? |
| USER_READS_C00 | User code reads the CSR at c00. Runs or traps? |
| MACHINE_WRITES_C00 | Machine code writes the CSR at c00. Runs or traps? |
| USER_READS_100 | User code reads the CSR at 100. Runs or traps? |
| SUPERVISOR_WRITES_100 | Supervisor code writes the CSR at 100. Runs or traps? |
| MACHINE_WRITES_100 | Machine code writes the CSR at 100. Runs or traps? |
| MACHINE_READS_F14 | Machine code reads the CSR at f14. Runs or traps? |
| MACHINE_WRITES_F14 | Machine code writes the CSR at f14. Runs or traps? |
| USER_WRITES_305 | User code writes the CSR at 305. Runs or traps? |
| LEVEL_OF_7B0 | Which is the lowest level that may use the CSR at 7b0? |
| READABLE_AT_LEVEL_L | Code runs at level L. How many of the first six CSRs of the table (c00, 100, 300, 341, f14, c01) can it read? Give an expression in L. |
Examples
Example 1
LEVEL OF 300- Input
Which is the lowest level that may use the CSR at 300?
- Output
matches = 1
Bits 9 and 8 of 0011 0000 0000 are 11.
Example 2
F14 IS READ ONLY- Input
Is the CSR at f14 read-only?
- Output
matches = 1
Bits 11 and 10 of 1111 0001 0100 are 11.
Example 3
USER READS 341- Input
User code reads the CSR at 341. Runs or traps?
- Output
matches = 1
Bits 9 and 8 are 11: machine only. A read is refused like a write.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For READABLE_AT_LEVEL_L, enter a constant expression using L. Only this entry changes with the parameter. The supported integer range is 0 through 3, inclusive.
Hints
Hint 1
Twelve bits. Mark bits 11 and 10, and bits 9 and 8.
Hint 2
Is the level of the code at least the number in bits 9 and 8? Is this a write to a read-only CSR?
Hint 3
If either test fails, the instruction traps.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
16 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 2 problems on this path