Skip to content

Commit 2da9dd7

Browse files
committed
Change datatype of csr_cycle from uint64_t into uint32_t array
1 parent f523c76 commit 2da9dd7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/emulate.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ static inline void update_time(riscv_t *rv)
9696
struct timeval tv;
9797
rv_gettimeofday(&tv);
9898

99-
rv->csr_time = (uint64_t) tv.tv_sec * 1e6 + (uint32_t) tv.tv_usec;
99+
uint64_t t = (uint64_t) tv.tv_sec * 1e6 + (uint32_t) tv.tv_usec;
100+
rv->csr_time[0] = t & 0xFFFFFFFF;
101+
rv->csr_time[1] = t >> 32;
100102
}
101103

102104
#if RV32_HAS(Zicsr)
@@ -132,11 +134,11 @@ static uint32_t *csr_get_ptr(riscv_t *rv, uint32_t csr)
132134
/* TIME/TIMEH - very roughly about 1 ms per tick */
133135
case CSR_TIME: { /* Timer for RDTIME instruction */
134136
update_time(rv);
135-
return (uint32_t *) (&rv->csr_time) + 0;
137+
return &rv->csr_time[0];
136138
}
137139
case CSR_TIMEH: { /* Upper 32 bits of time */
138140
update_time(rv);
139-
return (uint32_t *) (&rv->csr_time + 4);
141+
return &rv->csr_time[1];
140142
}
141143
case CSR_INSTRET: /* Number of Instructions Retired Counter */
142144
/* Number of Instructions Retired Counter, just use cycle */

src/riscv_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct riscv_internal {
102102

103103
/* csr registers */
104104
uint64_t csr_cycle;
105-
uint64_t csr_time;
105+
uint32_t csr_time[2];
106106
uint32_t csr_mstatus;
107107
uint32_t csr_mtvec;
108108
uint32_t csr_misa;

0 commit comments

Comments
 (0)