aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_uart
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-09-22 22:45:18 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-09-22 22:45:18 +0300
commitb1d67364b4b4832b8efed112f7b0ead1a0b3cd3b (patch)
tree7926bfb428703515438c08b98c61cbffd34b3cbb /tests/simple_uart
parent32f9719e29762001f73460acd31f2a6da8fd6298 (diff)
downloadgran-b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b.tar.gz
gran-b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b.zip
start experimenting with processor grids
Diffstat (limited to 'tests/simple_uart')
-rw-r--r--tests/simple_uart/hello.c18
-rw-r--r--tests/simple_uart/sim.c45
-rw-r--r--tests/simple_uart/source.mk6
3 files changed, 69 insertions, 0 deletions
diff --git a/tests/simple_uart/hello.c b/tests/simple_uart/hello.c
new file mode 100644
index 0000000..30719e0
--- /dev/null
+++ b/tests/simple_uart/hello.c
@@ -0,0 +1,18 @@
+/* compile with
+ * riscv64-unknown-elf-gcc -ffreestanding -nostdlib -Wl,-Ttext=0 -march=rv64i -mabi=lp64 -O2 hello.c -o simple_hello
+ * xxd --include simple_hello
+ */
+void _start()
+{
+ /* relies on hard-coded system, good enough for this simple test */
+ volatile char *uart = (char *)4096;
+ *uart = 'H';
+ *uart = 'e';
+ *uart = 'l';
+ *uart = 'l';
+ *uart = 'o';
+ *uart = '!';
+ *uart = '\n';
+
+ asm ("ebreak\n");
+}
diff --git a/tests/simple_uart/sim.c b/tests/simple_uart/sim.c
new file mode 100644
index 0000000..762b591
--- /dev/null
+++ b/tests/simple_uart/sim.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: copyleft-next-0.3.1 */
+/* Copyright 2023 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */
+
+#include <assert.h>
+
+#include <gran/root.h>
+#include <gran/mem/simple_mem.h>
+#include <gran/bus/simple_bus.h>
+#include <gran/uart/simple_uart.h>
+#include <gran/cpu/riscv/simple_riscv64.h>
+
+unsigned char simple_hello[] = {
+ 0xb7, 0x17, 0x00, 0x00, 0x13, 0x07, 0x80, 0x04, 0x23, 0x80, 0xe7, 0x00,
+ 0x13, 0x07, 0x50, 0x06, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xc0, 0x06,
+ 0x23, 0x80, 0xe7, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xf0, 0x06,
+ 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x10, 0x02, 0x23, 0x80, 0xe7, 0x00,
+ 0x13, 0x07, 0xa0, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x73, 0x00, 0x10, 0x00,
+ 0x67, 0x80, 0x00, 0x00
+};
+unsigned int simple_hello_len = 64;
+
+int main()
+{
+ const size_t size = 4096;
+ struct component *imem = create_simple_mem(size);
+ init_simple_mem(imem, 0, simple_hello_len, simple_hello);
+
+ struct component *dmem = create_simple_mem(size);
+ struct component *uart = create_simple_uart();
+ struct component *bus = create_simple_bus();
+ simple_bus_add(bus, dmem, 0, size);
+ simple_bus_add(bus, uart, size, 1);
+
+ struct component *rv64 = create_simple_riscv64(0, imem, bus);
+
+ struct clock_domain *clk = create_clock_domain(NS(1));
+ clock_domain_add(clk, rv64);
+
+ struct gran_root *root = create_root();
+ root_add_clock(root, clk);
+
+ assert(root_run(root) == OK);
+
+ destroy_root(root);
+}
diff --git a/tests/simple_uart/source.mk b/tests/simple_uart/source.mk
new file mode 100644
index 0000000..a42a447
--- /dev/null
+++ b/tests/simple_uart/source.mk
@@ -0,0 +1,6 @@
+UART_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_uart/sim.c"
+
+TEST_PROGS += build/tests/simple_uart/sim
+
+build/tests/simple_uart/sim: $(UART_TEST_OBJ) $(OBJS)
+ $(COMPILE) $(UART_TEST_OBJ) $(TEST_OBJS) $(OBJS) -o $@