Skip to content

Commit

Permalink
fix(rv32): adapt sbi timer extension to 32-bit
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Martins <[email protected]>
  • Loading branch information
josecm committed May 23, 2024
1 parent 4a7f2c3 commit 1a6dc2b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/arch/riscv/sbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ struct sbiret sbi_send_ipi(const unsigned long hart_mask, unsigned long hart_mas

struct sbiret sbi_set_timer(uint64_t stime_value)
{
return sbi_ecall(SBI_EXTID_TIME, SBI_SET_TIMER_FID, stime_value, 0, 0, 0, 0, 0);
unsigned long a0 = (unsigned long)stime_value;
unsigned long a1 = 0;
if (RV32) {
a1 = (unsigned long)(stime_value >> 32);
}
return sbi_ecall(SBI_EXTID_TIME, SBI_SET_TIMER_FID, a0, a1, 0, 0, 0, 0);
}

struct sbiret sbi_remote_fence_i(const unsigned long hart_mask, unsigned long hart_mask_base)
Expand Down Expand Up @@ -205,6 +210,10 @@ static struct sbiret sbi_time_handler(unsigned long fid)
}

uint64_t stime_value = vcpu_readreg(cpu()->vcpu, REG_A0);
if (RV32) {
stime_value |= ((uint64_t)vcpu_readreg(cpu()->vcpu, REG_A1)) << 32;
}

if (CPU_HAS_EXTENSION(CPU_EXT_SSTC)) {
csrs_vstimecmp_write(stime_value);
} else {
Expand Down

0 comments on commit 1a6dc2b

Please sign in to comment.