aboutsummaryrefslogtreecommitdiff
path: root/machine/mtrap.c
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-03-10 00:13:32 -0800
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-03-10 00:21:15 -0800
commit82382a1290739068dd38dda8fac29a498f8987a7 (patch)
tree865564e464b058e36d8d8448f2463d9637fc6ce1 /machine/mtrap.c
parentccf79891f0f1fcb570f9a63c15270b52477fe7c0 (diff)
downloadriscv-pk-82382a1290739068dd38dda8fac29a498f8987a7.zip
riscv-pk-82382a1290739068dd38dda8fac29a498f8987a7.tar.gz
riscv-pk-82382a1290739068dd38dda8fac29a498f8987a7.tar.bz2
Set time comparator correctly on RV32
The old code truncated the upper 32 bits, and even if it got that right, it would have generated spurious interrupts.
Diffstat (limited to 'machine/mtrap.c')
-rw-r--r--machine/mtrap.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/machine/mtrap.c b/machine/mtrap.c
index 6fc5476..44023b2 100644
--- a/machine/mtrap.c
+++ b/machine/mtrap.c
@@ -134,13 +134,14 @@ static uintptr_t mcall_shutdown()
poweroff();
}
-static uintptr_t mcall_set_timer(unsigned long long when)
+static uintptr_t mcall_set_timer(uint64_t when)
{
// bbl/pk don't use the timer, so there's no need to virtualize it
- write_csr(mtimecmp, when);
-#ifndef __riscv64
- write_csr(mtimecmph, when >> 32);
+#ifdef __riscv32
+ write_csr(mtimecmp, -1);
+ write_csr(mtimecmph, (uintptr_t)(when >> 32));
#endif
+ write_csr(mtimecmp, (uintptr_t)when);
clear_csr(mip, MIP_STIP);
set_csr(mie, MIP_MTIP);
return 0;
@@ -225,7 +226,11 @@ void mcall_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
retval = mcall_shutdown();
break;
case MCALL_SET_TIMER:
+#ifdef __riscv32
+ retval = mcall_set_timer(arg0 + ((uint64_t)arg1 << 32));
+#else
retval = mcall_set_timer(arg0);
+#endif
break;
case MCALL_REMOTE_SFENCE_VM:
retval = mcall_remote_sfence_vm((uintptr_t*)arg0, arg1);