diff --git a/bsps/riscv/riscv/clock/clockdrv.c b/bsps/riscv/riscv/clock/clockdrv.c index e6d0568908..6769057bae 100644 --- a/bsps/riscv/riscv/clock/clockdrv.c +++ b/bsps/riscv/riscv/clock/clockdrv.c @@ -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( diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h index d47cac920b..212acdc1fe 100644 --- a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h +++ b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h @@ -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 )