diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-05-13 00:04:44 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-05-13 00:04:44 +0200 |
commit | f95a85de0082010e4af83e26e99299d601bb48d6 (patch) | |
tree | 0b70ff8fa990ceeb18c2522ea80f2599d50ebae4 /emulator/csr_unpriv_counter_timer.c | |
parent | f9541157b62ec44deff0b906757c223ca0220102 (diff) |
Some work on CSR
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;
+}
|