diff options
Diffstat (limited to 'emulator/csr_unpriv_counter_timer.c')
-rw-r--r-- | emulator/csr_unpriv_counter_timer.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/emulator/csr_unpriv_counter_timer.c b/emulator/csr_unpriv_counter_timer.c new file mode 100644 index 0000000..e474520 --- /dev/null +++ b/emulator/csr_unpriv_counter_timer.c @@ -0,0 +1,33 @@ +#include "emulator/csr.h"
+
+#include "emulator/hart.h"
+
+static uint32_t csr_cycle(Hart* hart, uint32_t v, enum CsrAction a)
+{
+ return hart->instret & 0xFFFFFFFF;
+}
+
+static uint32_t csr_cycleh(Hart* hart, uint32_t v, enum CsrAction a)
+{
+ return hart->instret >> 32;
+}
+
+static uint32_t csr_time(Hart* hart, uint32_t v, enum CsrAction a)
+{
+ return hart->time & 0xFFFFFFFF;
+}
+
+static uint32_t csr_timeh(Hart* hart, uint32_t v, enum CsrAction a)
+{
+ return hart->time >> 32;
+}
+
+void csr_init_unpriv_counter_timer(Hart* hart)
+{
+ hart->csrs[CSR_CYCLE].action = csr_cycle;
+ hart->csrs[CSR_CYCLEH].action = csr_cycleh;
+ hart->csrs[CSR_INSTRET].action = csr_cycle;
+ hart->csrs[CSR_INSTRETH].action = csr_cycleh;
+ hart->csrs[CSR_TIME].action = csr_time;
+ hart->csrs[CSR_TIMEH].action = csr_timeh;
+}
|