summaryrefslogtreecommitdiff
path: root/emulator/csr.h
diff options
context:
space:
mode:
Diffstat (limited to 'emulator/csr.h')
-rw-r--r--emulator/csr.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/emulator/csr.h b/emulator/csr.h
new file mode 100644
index 0000000..89452b0
--- /dev/null
+++ b/emulator/csr.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <stdint.h>
+
+typedef struct Hart Hart;
+
+#define CSR_CYCLE 0xC00
+#define CSR_CYCLEH 0xC80
+#define CSR_INSTRET 0xC02
+#define CSR_INSTRETH 0xC82
+#define CSR_TIME 0xC01
+#define CSR_TIMEH 0xC81
+
+#define CSR_MVENDORID 0xF11
+#define CSR_MARCHID 0xF12
+#define CSR_MIMPID 0xF13
+#define CSR_MHARTID 0xF14
+
+#define CSR_MISA 0x301
+
+enum CsrAction
+{
+ CSR_R = 0,
+ CSR_W = 1,
+ CSR_RW = 3,
+ CSR_RC = 5,
+ CSR_RS = 7,
+};
+
+struct Csr
+{
+ uint32_t (*action)(Hart* hart, uint32_t value_mask, enum CsrAction action);
+};
+typedef struct Csr Csr;
+
+uint32_t csr_action(Hart* hart, uint16_t id, uint32_t value, enum CsrAction action);