The timer and entropy seed CSRs will, by design, return different
values each time they are read.
Add the missing volatile qualifiers on the inline assembly to prevent
gcc from assuming that repeated invocations may be elided.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
unsigned long time;
/* Read low XLEN bits of current time */
- __asm__ ( "rdtime %0" : "=r" ( time ) );
+ __asm__ __volatile__ ( "rdtime %0" : "=r" ( time ) );
return time;
}
/* Read full current time */
#if __riscv_xlen >= 64
- __asm__ ( "rdtime %0" : "=r" ( u.time ) );
+ __asm__ __volatile__ ( "rdtime %0" : "=r" ( u.time ) );
#else
- __asm__ ( "1:\n\t"
- "rdtimeh %1\n\t"
- "rdtime %0\n\t"
- "rdtimeh %2\n\t"
- "bne %1, %2, 1b\n\t"
- : "=r" ( u.low ), "=r" ( u.high ), "=r" ( tmp ) );
+ __asm__ __volatile__ ( "1:\n\t"
+ "rdtimeh %1\n\t"
+ "rdtime %0\n\t"
+ "rdtimeh %2\n\t"
+ "bne %1, %2, 1b\n\t"
+ : "=r" ( u.low ), "=r" ( u.high ),
+ "=r" ( tmp ) );
#endif
/* Scale time to avoid XLEN-bit rollover */
for ( i = 0 ; i < ZKR_SEED_MAX_RETRY ; i++ ) {
/* Read seed CSR */
- __asm__ ( "csrrw %0, seed, zero" : "=r" ( seed ) );
+ __asm__ __volatile__ ( "csrrw %0, seed, zero" :
+ "=r" ( seed ) );
/* Check operationsl state */
if ( ( seed & ZKR_SEED_OPST_MASK ) == ZKR_SEED_OPST_ES16 ) {