S2.14.2 Who May Touch This CSR

MediumImplement22 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
The CSRs of this worksheet
The names are those of RISC-V. Only the addresses matter here.
Address, in hexAddress, in binaryName
c001100 0000 0000cycle
1000001 0000 0000sstatus
3000011 0000 0000mstatus
3410011 0100 0001mepc
f141111 0001 0100mhartid
c011100 0000 0001time
3050011 0000 0101mtvec
7b00111 1011 0000dcsr

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.

EntryYour decision
LEVEL_OF_300Which is the lowest level that may use the CSR at 300?
F14_IS_READ_ONLYIs the CSR at f14 read-only?
USER_READS_341User code reads the CSR at 341. Runs or traps?
LEVEL_OF_100Which is the lowest level that may use the CSR at 100?
LEVEL_OF_C00Which is the lowest level that may use the CSR at c00?
C00_IS_READ_ONLYIs the CSR at c00 read-only?
USER_READS_C00User code reads the CSR at c00. Runs or traps?
MACHINE_WRITES_C00Machine code writes the CSR at c00. Runs or traps?
USER_READS_100User code reads the CSR at 100. Runs or traps?
SUPERVISOR_WRITES_100Supervisor code writes the CSR at 100. Runs or traps?
MACHINE_WRITES_100Machine code writes the CSR at 100. Runs or traps?
MACHINE_READS_F14Machine code reads the CSR at f14. Runs or traps?
MACHINE_WRITES_F14Machine code writes the CSR at f14. Runs or traps?
USER_WRITES_305User code writes the CSR at 305. Runs or traps?
LEVEL_OF_7B0Which is the lowest level that may use the CSR at 7b0?
READABLE_AT_LEVEL_LCode 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

Report a problem with this page

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

LEVEL OF 300

Input
Which is the lowest level that may use the CSR at 300?
Expected output
matches = 1

Bits 9 and 8 of 0011 0000 0000 are 11.

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

Icarus Verilog · server