aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-04-30 17:47:00 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-04-30 17:47:00 +0300
commitd133cc70b125efc1d6c992cb49ce1bca41cf580e (patch)
tree0f7c2352f6a83b6603304a877f9c02de21ba5fab
parent3e74b081dba17f12a1661e9e4db6b41a02a78861 (diff)
downloadgran-d133cc70b125efc1d6c992cb49ce1bca41cf580e.tar.gz
gran-d133cc70b125efc1d6c992cb49ce1bca41cf580e.zip
refactor component tree
-rw-r--r--include/gran/bus/simple_bus.h (renamed from include/gran/components/bus/simple_bus.h)6
-rw-r--r--include/gran/clock_domain.h6
-rw-r--r--include/gran/common.h6
-rw-r--r--include/gran/component.h6
-rw-r--r--include/gran/components/mem/simple_mem.h8
-rw-r--r--include/gran/cpu/riscv/simple_riscv32.h8
-rw-r--r--include/gran/mem/simple_mem.h8
-rw-r--r--include/gran/root.h6
-rw-r--r--src/components/bus/simple_bus.c2
-rw-r--r--src/components/cpu/riscv/simple_riscv32.c58
-rw-r--r--src/components/mem/simple_mem.c2
-rw-r--r--tests/simple_mem/bus.c4
-rw-r--r--tests/simple_mem/many.c2
-rw-r--r--tests/simple_mem/no_bus.c2
-rw-r--r--tests/simple_mem/traffic_gen.h6
15 files changed, 98 insertions, 32 deletions
diff --git a/include/gran/components/bus/simple_bus.h b/include/gran/bus/simple_bus.h
index 3a5f814..c569e8a 100644
--- a/include/gran/components/bus/simple_bus.h
+++ b/include/gran/bus/simple_bus.h
@@ -1,5 +1,5 @@
-#ifndef EXSIM_SIMPLE_BUS_H
-#define EXSIM_SIMPLE_BUS_H
+#ifndef GRAN_SIMPLE_BUS_H
+#define GRAN_SIMPLE_BUS_H
#include <stdint.h>
@@ -7,4 +7,4 @@ struct component *create_simple_bus();
stat simple_bus_add(struct component *bus, struct component *component,
uintptr_t addr, size_t size);
-#endif /* EXSIM_SIMPLE_BUS_H */
+#endif /* GRAN_SIMPLE_BUS_H */
diff --git a/include/gran/clock_domain.h b/include/gran/clock_domain.h
index 3f960ae..9fb04a4 100644
--- a/include/gran/clock_domain.h
+++ b/include/gran/clock_domain.h
@@ -1,5 +1,5 @@
-#ifndef EXSIM_CLOCK_DOMAIN_H
-#define EXSIM_CLOCK_DOMAIN_H
+#ifndef GRAN_CLOCK_DOMAIN_H
+#define GRAN_CLOCK_DOMAIN_H
#include <stdint.h>
#include <stdbool.h>
@@ -37,4 +37,4 @@ bool le_time(struct clock_time a, struct clock_time b);
struct clock_time max_time(struct clock_time a, struct clock_time b);
struct clock_time domain_time(struct clock_domain *);
-#endif /* EXSIM_CLOCK_DOMAIN_H */
+#endif /* GRAN_CLOCK_DOMAIN_H */
diff --git a/include/gran/common.h b/include/gran/common.h
index c012c49..b4b8978 100644
--- a/include/gran/common.h
+++ b/include/gran/common.h
@@ -1,5 +1,5 @@
-#ifndef EXSIM_COMMON_H
-#define EXSIM_COMMON_H
+#ifndef GRAN_COMMON_H
+#define GRAN_COMMON_H
#include <stdio.h>
@@ -31,4 +31,4 @@ typedef enum {
#define debug(x, ...)
#endif
-#endif /* EXSIM_COMMON_H */
+#endif /* GRAN_COMMON_H */
diff --git a/include/gran/component.h b/include/gran/component.h
index cd21a6b..498d7c0 100644
--- a/include/gran/component.h
+++ b/include/gran/component.h
@@ -1,5 +1,5 @@
-#ifndef EXSIM_COMPONENT_H
-#define EXSIM_COMPONENT_H
+#ifndef GRAN_COMPONENT_H
+#define GRAN_COMPONENT_H
#include <stdint.h>
#include <stdio.h>
@@ -104,4 +104,4 @@ static inline stat swap_u8(struct component *component, uintptr_t addr,
return swap(component, addr, sizeof(uint8_t), c, sizeof(uint8_t), c);
}
-#endif /* EXSIM_COMPONENT_H */
+#endif /* GRAN_COMPONENT_H */
diff --git a/include/gran/components/mem/simple_mem.h b/include/gran/components/mem/simple_mem.h
deleted file mode 100644
index 8e0845c..0000000
--- a/include/gran/components/mem/simple_mem.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef EXSIM_SIMPLE_MEM_H
-#define EXSIM_SIMPLE_MEM_H
-
-#include <gran/component.h>
-
-struct component *create_simple_mem(size_t size);
-
-#endif /* EXSIM_SIMPLE_MEM_H */
diff --git a/include/gran/cpu/riscv/simple_riscv32.h b/include/gran/cpu/riscv/simple_riscv32.h
new file mode 100644
index 0000000..054c76d
--- /dev/null
+++ b/include/gran/cpu/riscv/simple_riscv32.h
@@ -0,0 +1,8 @@
+#ifndef GRAN_SIMPLE_RISCV32
+#define GRAN_SIMPLE_RISCV32
+
+#include <gran/component.h>
+
+struct component *create_simple_riscv32(uint32_t start_pc, struct component *imem, struct component *dmem);
+
+#endif /* GRAN_SIMPLE_RISCV */
diff --git a/include/gran/mem/simple_mem.h b/include/gran/mem/simple_mem.h
new file mode 100644
index 0000000..984dbf6
--- /dev/null
+++ b/include/gran/mem/simple_mem.h
@@ -0,0 +1,8 @@
+#ifndef GRAN_SIMPLE_MEM_H
+#define GRAN_SIMPLE_MEM_H
+
+#include <gran/component.h>
+
+struct component *create_simple_mem(size_t size);
+
+#endif /* GRAN_SIMPLE_MEM_H */
diff --git a/include/gran/root.h b/include/gran/root.h
index d158b04..32ca1cf 100644
--- a/include/gran/root.h
+++ b/include/gran/root.h
@@ -1,5 +1,5 @@
-#ifndef EXSIM_ROOT_H
-#define EXSIM_ROOT_H
+#ifndef GRAN_ROOT_H
+#define GRAN_ROOT_H
#include <gran/common.h>
#include <gran/clock_domain.h>
@@ -11,4 +11,4 @@ stat root_add_clock(struct gran_root *, struct clock_domain *);
stat root_run(struct gran_root *);
void destroy_root(struct gran_root *);
-#endif /* EXSIM_ROOT_H */
+#endif /* GRAN_ROOT_H */
diff --git a/src/components/bus/simple_bus.c b/src/components/bus/simple_bus.c
index 23a6bc2..58e4132 100644
--- a/src/components/bus/simple_bus.c
+++ b/src/components/bus/simple_bus.c
@@ -5,7 +5,7 @@
#include <gran/common.h>
#include <gran/component.h>
-#include <gran/components/bus/simple_bus.h>
+#include <gran/bus/simple_bus.h>
struct mem_region {
uintptr_t addr;
diff --git a/src/components/cpu/riscv/simple_riscv32.c b/src/components/cpu/riscv/simple_riscv32.c
new file mode 100644
index 0000000..1f19b1f
--- /dev/null
+++ b/src/components/cpu/riscv/simple_riscv32.c
@@ -0,0 +1,58 @@
+#include <gran/cpu/riscv/simple_riscv32.h>
+
+struct simple_riscv32 {
+ struct component component;
+
+ struct component *imem;
+ struct component *dmem;
+
+ /* have to be careful with x0 */
+ uint32_t regs[32];
+ uint32_t pc;
+};
+
+static uint32_t get_reg(struct simple_riscv32 *cpu, size_t i)
+{
+ assert(i < 32);
+
+ if (i == 0)
+ return 0;
+
+ return cpu->regs[i];
+}
+
+static void set_reg(struct simple_riscv32 *cpu, size_t i, uint32_t v)
+{
+ assert(i < 32);
+
+ if (i == 0)
+ return;
+
+ cpu->regs[i] = v;
+}
+
+static stat simple_riscv32_clock(struct simple_riscv32 *cpu)
+{
+ uint32_t insn = 0;
+ stat ret = read(cpu->imem, cpu->pc, sizeof(insn), &insn);
+ if (ret)
+ return ret;
+
+ /* @todo instruction decode and execution, not sure if this is too early
+ * to start thinking about how to modularise stuff */
+ return OK;
+}
+
+struct componen *create_simple_riscv32(uint32_t start_pc, struct component *imem, struct component *dmem)
+{
+ struct component *new = calloc(1, sizeof(simple_riscv32));
+ if (!new)
+ return NULL;
+
+ new->component.clock = (clock_callback)simple_riscv32_clock;
+
+ new->pc = start_pc;
+ new->imem = imem;
+ new->dmem = dmem;
+ return new;
+}
diff --git a/src/components/mem/simple_mem.c b/src/components/mem/simple_mem.c
index bea68ed..52606e2 100644
--- a/src/components/mem/simple_mem.c
+++ b/src/components/mem/simple_mem.c
@@ -1,7 +1,7 @@
#include <string.h>
#include <stdlib.h>
-#include <gran/components/mem/simple_mem.h>
+#include <gran/mem/simple_mem.h>
struct simple_mem {
struct component component;
diff --git a/tests/simple_mem/bus.c b/tests/simple_mem/bus.c
index fa2ffad..67fb53b 100644
--- a/tests/simple_mem/bus.c
+++ b/tests/simple_mem/bus.c
@@ -2,8 +2,8 @@
#include <gran/root.h>
#include <gran/clock_domain.h>
-#include <gran/components/mem/simple_mem.h>
-#include <gran/components/bus/simple_bus.h>
+#include <gran/mem/simple_mem.h>
+#include <gran/bus/simple_bus.h>
#include "traffic_gen.h"
diff --git a/tests/simple_mem/many.c b/tests/simple_mem/many.c
index 6754ebb..254b49f 100644
--- a/tests/simple_mem/many.c
+++ b/tests/simple_mem/many.c
@@ -2,7 +2,7 @@
#include <gran/root.h>
#include <gran/clock_domain.h>
-#include <gran/components/mem/simple_mem.h>
+#include <gran/mem/simple_mem.h>
#include "traffic_gen.h"
diff --git a/tests/simple_mem/no_bus.c b/tests/simple_mem/no_bus.c
index df7888e..8a5b05b 100644
--- a/tests/simple_mem/no_bus.c
+++ b/tests/simple_mem/no_bus.c
@@ -2,7 +2,7 @@
#include <gran/root.h>
#include <gran/clock_domain.h>
-#include <gran/components/mem/simple_mem.h>
+#include <gran/mem/simple_mem.h>
#include "traffic_gen.h"
diff --git a/tests/simple_mem/traffic_gen.h b/tests/simple_mem/traffic_gen.h
index 9875bae..1975e48 100644
--- a/tests/simple_mem/traffic_gen.h
+++ b/tests/simple_mem/traffic_gen.h
@@ -1,9 +1,9 @@
-#ifndef EXSIM_TRAFFIC_GEN_H
-#define EXSIM_TRAFFIC_GEN_H
+#ifndef GRAN_TRAFFIC_GEN_H
+#define GRAN_TRAFFIC_GEN_H
#include <stdint.h>
#include <stddef.h>
struct component *create_traffic_gen(struct component *, uintptr_t, size_t);
-#endif /* EXSIM_TRAFFIC_GEN_H */
+#endif /* GRAN_TRAFFIC_GEN_H */