Skip to content

Commit

Permalink
Make mtime writable
Browse files Browse the repository at this point in the history
According to the priv. spec. mtime should be readable & writable:

> Platforms provide a real-time counter, exposed as a memory-mapped machine-mode read-write register, mtime.

However, the model currently does not allow writes to mtime. This commit modifies clint_store in order to support writes to the mtime memory-mapped register.
  • Loading branch information
defermelowie authored Jul 25, 2024
1 parent 3ad92a4 commit 7de3d70
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions model/riscv_platform.sail
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ function clint_store(addr, width, data) = {
mtimecmp = vector_update_subrange(mtimecmp, 63, 32, sail_zero_extend(data, 32)); /* FIXME: Redundant zero_extend currently required by Lem backend */
clint_dispatch();
MemValue(true)
} else if addr == MTIME_BASE & 'n == 8 then {
if get_config_print_platform()
then print_platform("clint<8>[" ^ BitStr(addr) ^ "] <- " ^ BitStr(data) ^ " (mtime)");
mtime = data;
clint_dispatch();
MemValue(true)
} else if addr == MTIME_BASE & 'n == 4 then {
if get_config_print_platform()
then print_platform("clint<4>[" ^ BitStr(addr) ^ "] <- " ^ BitStr(data) ^ " (mtime)");
mtime[31 .. 0] = data;
clint_dispatch();
MemValue(true)
} else if addr == MTIME_BASE_HI & 'n == 4 then {
if get_config_print_platform()
then print_platform("clint<4>[" ^ BitStr(addr) ^ "] <- " ^ BitStr(data) ^ " (mtime)");
mtime[63 .. 32] = data;
clint_dispatch();
MemValue(true)
} else {
if get_config_print_platform()
then print_platform("clint[" ^ BitStr(addr) ^ "] <- " ^ BitStr(data) ^ " (<unmapped>)");
Expand Down

0 comments on commit 7de3d70

Please sign in to comment.