summaryrefslogtreecommitdiff
path: root/emulator/csr.h
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-05-13 00:04:44 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-05-13 00:04:44 +0200
commitf95a85de0082010e4af83e26e99299d601bb48d6 (patch)
tree0b70ff8fa990ceeb18c2522ea80f2599d50ebae4 /emulator/csr.h
parentf9541157b62ec44deff0b906757c223ca0220102 (diff)
Some work on CSR
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);