From b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 22 Sep 2024 22:45:18 +0300 Subject: start experimenting with processor grids --- include/gran/bus/simple_bus.h | 2 +- include/gran/cpu/riscv/simple_riscv32.h | 13 ---------- include/gran/cpu/riscv/simple_riscv64.h | 15 +++++++++++ include/gran/grid/node.h | 14 ++++++++++ include/gran/grid/router.h | 10 +++++++ include/gran/packet.h | 2 +- include/gran/uart/simple_uart.h | 8 ++++++ include/gran/vec.h | 46 +++++++++++++++++++++++++++++++++ 8 files changed, 95 insertions(+), 15 deletions(-) delete mode 100644 include/gran/cpu/riscv/simple_riscv32.h create mode 100644 include/gran/cpu/riscv/simple_riscv64.h create mode 100644 include/gran/grid/node.h create mode 100644 include/gran/grid/router.h create mode 100644 include/gran/uart/simple_uart.h create mode 100644 include/gran/vec.h (limited to 'include') diff --git a/include/gran/bus/simple_bus.h b/include/gran/bus/simple_bus.h index 41a8d2e..62dd7d2 100644 --- a/include/gran/bus/simple_bus.h +++ b/include/gran/bus/simple_bus.h @@ -8,6 +8,6 @@ struct component *create_simple_bus(); stat simple_bus_add(struct component *bus, struct component *component, - uintptr_t addr, size_t size); + uint64_t addr, uint64_t size); #endif /* GRAN_SIMPLE_BUS_H */ diff --git a/include/gran/cpu/riscv/simple_riscv32.h b/include/gran/cpu/riscv/simple_riscv32.h deleted file mode 100644 index 3cbd842..0000000 --- a/include/gran/cpu/riscv/simple_riscv32.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: copyleft-next-0.3.1 */ -/* Copyright 2023 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ - -#ifndef GRAN_SIMPLE_RISCV32 -#define GRAN_SIMPLE_RISCV32 - -#include - -struct component *create_simple_riscv32(uint32_t start_pc, - struct component *imem, - struct component *dmem); - -#endif /* GRAN_SIMPLE_RISCV */ diff --git a/include/gran/cpu/riscv/simple_riscv64.h b/include/gran/cpu/riscv/simple_riscv64.h new file mode 100644 index 0000000..8f66013 --- /dev/null +++ b/include/gran/cpu/riscv/simple_riscv64.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ +/* Copyright 2023 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ + +#ifndef GRAN_SIMPLE_RISCV64 +#define GRAN_SIMPLE_RISCV64 + +#include + +struct component *create_simple_riscv64(uint32_t start_pc, + struct component *imem, + struct component *dmem); + +void simple_riscv64_set_reg(struct component *cpu, size_t reg, uint64_t val); + +#endif /* GRAN_SIMPLE_RISCV */ diff --git a/include/gran/grid/node.h b/include/gran/grid/node.h new file mode 100644 index 0000000..637ac91 --- /dev/null +++ b/include/gran/grid/node.h @@ -0,0 +1,14 @@ +#ifndef GRAN_GRID_NODE_H +#define GRAN_GRID_NODE_H + +#include +#include + +struct component *create_grid_node(uint8_t u, uint8_t v, uint8_t x, uint8_t y); + +stat grid_node_connect(struct component *node, + struct component *left, struct component *right, + struct component *up, struct component *down, + struct component *lower, struct component *ascend); + +#endif /* GRAN_GRID_NODE_H */ diff --git a/include/gran/grid/router.h b/include/gran/grid/router.h new file mode 100644 index 0000000..cff0fa1 --- /dev/null +++ b/include/gran/grid/router.h @@ -0,0 +1,10 @@ +#ifndef GRAN_NODE_ROUTER_H +#define GRAN_NODE_ROUTER_H + +#include + +struct component *create_node_router(uint8_t u, uint8_t v, uint8_t x, uint8_t y); +stat node_router_add(struct component *router, struct component *component, uint32_t addr, uint32_t size); +stat node_router_ascend(struct component *router, struct component *node); + +#endif /* GRAN_NODE_ROUTER_H */ diff --git a/include/gran/packet.h b/include/gran/packet.h index d18dfd6..ab07b56 100644 --- a/include/gran/packet.h +++ b/include/gran/packet.h @@ -39,7 +39,7 @@ enum packet_state packet_state(struct packet *pkt); void packet_set_state(struct packet *pkt, enum packet_state state); size_t packet_size(struct packet *pkt); -uintptr_t packet_addr(struct packet *pkt); +uint64_t packet_addr(struct packet *pkt); void *packet_data(struct packet *pkt); void destroy_packet(struct packet *pkt); diff --git a/include/gran/uart/simple_uart.h b/include/gran/uart/simple_uart.h new file mode 100644 index 0000000..75906fa --- /dev/null +++ b/include/gran/uart/simple_uart.h @@ -0,0 +1,8 @@ +#ifndef GRAN_SIMPLE_UART_H +#define GRAN_SIMPLE_UART_H + +#include + +struct component *create_simple_uart(); + +#endif /* GRAN_SIMPLE_UART_H */ diff --git a/include/gran/vec.h b/include/gran/vec.h new file mode 100644 index 0000000..08a608a --- /dev/null +++ b/include/gran/vec.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ + +#ifndef VEC_H +#define VEC_H + +#include + +struct vec { + size_t n; + size_t s; + size_t ns; + void *buf; +}; + +struct vec vec_create(size_t s); +void vec_destroy(struct vec *v); +void vec_reset(struct vec *v); + +size_t vec_len(struct vec *v); +void *vec_at(struct vec *v, size_t i); +void *vec_back(struct vec *v); +void *vec_pop(struct vec *v); +void vec_append(struct vec *v, void *n); + +typedef int (*vec_comp_t)(const void *, const void *); +void vec_sort(struct vec *v, vec_comp_t comp); + +#define foreach_vec(iter, v) \ + for (size_t iter = 0; iter < vec_len(&v); ++iter) + +#define vect_at(type, v, i) \ + *(type *)vec_at(&v, i) + +#define vect_append(type, v, e) \ + vec_append(&v, (type *)(e)) + +#define vect_back(type, v) \ + *(type *)vec_back(&v) + +#define vect_pop(type, v) \ + *(type *)vec_pop(&v) + +#define vec_uninit(v) \ + (v.buf == NULL) + +#endif /* VEC_H */ -- cgit v1.3