lib: sbi: Fix writes to emulated 32-bit htimedelta CSR

Writes to the low half CSR should not affect the high half of the value.
Make this separation explicit by writing to the delta in memory as two
adjacent XLEN-sized values.

Fixes: 1e9f88889f ("lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSR")
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-08-29 13:08:10 -07:00
committed by Anup Patel
parent 65f04badf7
commit ebfaf1974e
2 changed files with 10 additions and 7 deletions

View File

@@ -114,20 +114,21 @@ u64 sbi_timer_get_delta(void)
void sbi_timer_set_delta(ulong delta)
{
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
ulong *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
*time_delta = (u64)delta;
*time_delta = delta;
}
#if __riscv_xlen == 32
void sbi_timer_set_delta_upper(ulong delta_upper)
{
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
ulong *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
*time_delta &= 0xffffffffULL;
*time_delta |= ((u64)delta_upper << 32);
*(time_delta + 1) = delta_upper;
}
#endif
void sbi_timer_event_start(u64 next_event)
{