aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/simple_fat_bfly/sim.c73
-rw-r--r--tests/simple_fat_bfly/source.mk18
-rw-r--r--tests/simple_fat_bfly/test.c52
3 files changed, 143 insertions, 0 deletions
diff --git a/tests/simple_fat_bfly/sim.c b/tests/simple_fat_bfly/sim.c
new file mode 100644
index 0000000..7d7b166
--- /dev/null
+++ b/tests/simple_fat_bfly/sim.c
@@ -0,0 +1,73 @@
+#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/bfly/fat_bfly.h>
+#include <gran/cpu/riscv/simple_riscv64.h>
+
+#include "../build/tests/simple_fat_bfly/test.inc"
+
+static stat build_ideal_noc(struct clock_domain *clk, uint32_t x)
+{
+ struct component **pes = calloc(x, sizeof(struct component *));
+ assert(pes);
+
+ struct component *noc = create_fat_bfly(x);
+ clock_domain_add(clk, noc);
+
+ for (uint32_t i = 0; i < x; ++i) {
+ if (i == 0 || i == 1)
+ continue;
+
+ struct component *imem = create_simple_mem(4096);
+ init_simple_mem(imem, 0,
+ build_tests_simple_fat_bfly_test_bin_len,
+ build_tests_simple_fat_bfly_test_bin);
+
+ uint64_t rcv = fat_bfly_addr(i, 0);
+ struct component *rv64 = create_simple_riscv64(rcv, 0, imem, noc);
+ simple_riscv64_set_reg(rv64, 10, i); /* a0 */
+ simple_riscv64_set_reg(rv64, 11, x); /* a1 */
+
+ clock_domain_add(clk, rv64);
+ clock_domain_add(clk, imem);
+
+ pes[i] = rv64;
+ }
+
+ struct component *uart = create_simple_uart();
+ clock_domain_add(clk, uart);
+ fat_bfly_connect(noc, uart, 0);
+
+ struct component *dmem = create_simple_mem(4096);
+ clock_domain_add(clk, dmem);
+ fat_bfly_connect(noc, dmem, 1);
+
+ for (size_t i = 0; i < x; ++i) {
+ if (i == 0 || i == 1)
+ continue;
+
+ fat_bfly_connect(noc, pes[i], i);
+ }
+
+ free(pes);
+ return OK;
+}
+
+int main()
+{
+ struct clock_domain *clk = create_clock_domain(NS(1));
+
+ stat r = build_ideal_noc(clk, 64);
+ assert(r == OK);
+
+ struct gran_root *root = create_root();
+ root_add_clock(root, clk);
+
+ r = root_run(root);
+ assert(r == OK);
+
+ destroy_root(root);
+}
diff --git a/tests/simple_fat_bfly/source.mk b/tests/simple_fat_bfly/source.mk
new file mode 100644
index 0000000..9aae373
--- /dev/null
+++ b/tests/simple_fat_bfly/source.mk
@@ -0,0 +1,18 @@
+FAT_BFLY_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_fat_bfly/sim.c"
+TEST_PROGS += build/tests/simple_fat_bfly/sim
+
+build/tests/simple_fat_bfly/test.inc: tests/simple_fat_bfly/test.c
+ riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \
+ -march=rv64i -mabi=lp64 \
+ -o build/tests/simple_fat_bfly/test \
+ tests/simple_fat_bfly/test.c
+ riscv64-unknown-elf-objcopy -Obinary \
+ build/tests/simple_fat_bfly/test \
+ build/tests/simple_fat_bfly/test.bin
+ xxd -i build/tests/simple_fat_bfly/test.bin \
+ > build/tests/simple_fat_bfly/test.inc
+
+build/tests/simple_fat_bfly/sim.o: build/tests/simple_fat_bfly/test.inc
+
+build/tests/simple_fat_bfly/sim: $(FAT_BFLY_TEST_OBJ) $(OBJS)
+ $(COMPILE) $(FAT_BFLY_TEST_OBJ) $(OBJS) -o $@
diff --git a/tests/simple_fat_bfly/test.c b/tests/simple_fat_bfly/test.c
new file mode 100644
index 0000000..2e4a22c
--- /dev/null
+++ b/tests/simple_fat_bfly/test.c
@@ -0,0 +1,52 @@
+__attribute__((always_inline))
+static inline char hex_char(unsigned x)
+{
+ if (x <= 9)
+ return x + '0';
+
+ return (x - 10) + 'a';
+}
+
+__attribute__((always_inline))
+static inline void print_int32(volatile char *uart, unsigned x)
+{
+ *uart = hex_char((x >> 28) & 0xf);
+ *uart = hex_char((x >> 24) & 0xf);
+ *uart = hex_char((x >> 20) & 0xf);
+ *uart = hex_char((x >> 16) & 0xf);
+ *uart = hex_char((x >> 12) & 0xf);
+ *uart = hex_char((x >> 8) & 0xf);
+ *uart = hex_char((x >> 4) & 0xf);
+ *uart = hex_char((x >> 0) & 0xf);
+}
+
+__attribute__((always_inline))
+static inline void print_addr(volatile char *uart, unsigned x)
+{
+ *uart = '(';
+ print_int32(uart, x);
+ *uart = ')';
+ *uart = '\n';
+}
+
+void _start(unsigned x, unsigned X)
+{
+ volatile char *uart = (char *)4096;
+ volatile unsigned *control = (unsigned *)(1ULL << 32);
+
+ if (x == 2) {
+ goto do_work;
+ } else {
+ while (*control != x) {}
+ }
+
+do_work:
+ print_addr(uart, x);
+ *control = x + 1;
+
+ if (x == X - 1)
+ asm("ebreak");
+
+ /* otherwise just loop */
+ while (1) {}
+}