riscv: support CPU counter in s-mode

Updates #3337
This commit is contained in:
Gedare Bloom authored and Kinsey Moore committed 2026-03-06 11:35:16 -06:00
1 parent 7f46d3ca7a
commit 7209cd44d1
2 files changed
+12

No files matched your search

+9
View File
@@ -264,11 +264,15 @@ static void riscv_clock_initialize(void)
rtems_timecounter_install(&tc->base);
}
#ifndef RISCV_USE_S_MODE
volatile uint32_t _RISCV_Counter_register;
#endif
static void riscv_counter_initialize(void)
{
#ifndef RISCV_USE_S_MODE
_RISCV_Counter_mutable = &riscv_clint->mtime.val_32[0];
#endif
}
uint32_t _CPU_Counter_frequency( void )
@@ -278,7 +282,12 @@ uint32_t _CPU_Counter_frequency( void )
CPU_Counter_ticks _CPU_Counter_read( void )
{
#ifdef RISCV_USE_S_MODE
uint64_t now = rdtime();
return (uint32_t) now;
#else
return *_RISCV_Counter;
#endif
}
RTEMS_SYSINIT_ITEM(
@@ -367,6 +367,7 @@ static inline uint32_t _RISCV_Read_FCSR( void )
return fcsr;
}
#ifndef RISCV_USE_S_MODE
/*
* The RISC-V ISA provides a rdtime instruction, however, it is implemented in
* most chips via a trap-and-emulate. Using this in machine mode makes no
@@ -405,6 +406,8 @@ extern volatile uint32_t *_RISCV_Counter_mutable;
*/
extern volatile uint32_t _RISCV_Counter_register;
#endif /* !RISCV_USE_S_MODE */
#ifdef RTEMS_SMP
static inline struct Per_CPU_Control *_RISCV_Get_current_per_CPU_control( void )