From f95a85de0082010e4af83e26e99299d601bb48d6 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 13 May 2024 00:04:44 +0200 Subject: Some work on CSR --- emulator/csr_unpriv_counter_timer.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 emulator/csr_unpriv_counter_timer.c (limited to 'emulator/csr_unpriv_counter_timer.c') 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; +} -- cgit