diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-25 21:00:16 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-25 21:00:16 +0300 |
| commit | 6d0e7c5eba49efc171e63ff2631722a5c7f95460 (patch) | |
| tree | 9159d22c6ee1ee2949dcf8455998405b031cb351 | |
| parent | fecb86f6093c1e8aed6ab05c29c5af9d0cb93157 (diff) | |
| download | gran-6d0e7c5eba49efc171e63ff2631722a5c7f95460.tar.gz gran-6d0e7c5eba49efc171e63ff2631722a5c7f95460.zip | |
technically speaking deadlock free, but starves
28 files changed, 277 insertions, 379 deletions
diff --git a/include/gran/cpu/riscv/simple_riscv64.h b/include/gran/cpu/riscv/simple_riscv64.h index fe6e686..142c619 100644 --- a/include/gran/cpu/riscv/simple_riscv64.h +++ b/include/gran/cpu/riscv/simple_riscv64.h @@ -6,7 +6,7 @@ #include <gran/component.h> -struct component *create_simple_riscv64(uint64_t rcv, uint32_t start_pc, +struct component *create_simple_riscv64(uint64_t rcv, uint64_t start_pc, struct component *imem, struct component *dmem); diff --git a/include/gran/grid/node.h b/include/gran/grid/node.h index 16116d2..db617f8 100644 --- a/include/gran/grid/node.h +++ b/include/gran/grid/node.h @@ -4,30 +4,26 @@ #include <gran/component.h> #include <stdint.h> -struct component *create_grid_node(uint8_t u, uint8_t v, uint8_t x, uint8_t y); +struct component *create_grid_node(uint16_t x, uint16_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); + struct component *lower); -static inline uint64_t grid_addr(uint8_t u, uint8_t v, uint8_t x, uint8_t y, uint32_t off) +static inline uint64_t grid_addr(uint16_t x, uint16_t y, uint32_t off) { return off | ((uint64_t)x << 32) - | ((uint64_t)y << 40) - | ((uint64_t)u << 48) - | ((uint64_t)v << 56) + | ((uint64_t)y << 48) ; } -static inline void addr_grid(uint64_t addr, uint32_t *off, uint8_t *x, uint8_t *y, uint8_t *u, uint8_t *v) +static inline void addr_grid(uint64_t addr, uint32_t *off, uint16_t *x, uint16_t *y) { if (off) *off = addr & 0xffffffff; - if (x) *x = (addr >> 32) & 0xff; - if (y) *y = (addr >> 40) & 0xff; - if (u) *u = (addr >> 48) & 0xff; - if (v) *v = (addr >> 56) & 0xff; + if (x) *x = (addr >> 32) & 0xffff; + if (y) *y = (addr >> 48) & 0xffff; } #endif /* GRAN_GRID_NODE_H */ diff --git a/include/gran/grid/router.h b/include/gran/grid/router.h deleted file mode 100644 index cff0fa1..0000000 --- a/include/gran/grid/router.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef GRAN_NODE_ROUTER_H -#define GRAN_NODE_ROUTER_H - -#include <gran/component.h> - -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/src/components/bus/simple_bus.c b/src/bus/simple_bus.c index 1932419..1932419 100644 --- a/src/components/bus/simple_bus.c +++ b/src/bus/simple_bus.c diff --git a/src/bus/source.mk b/src/bus/source.mk new file mode 100644 index 0000000..e812785 --- /dev/null +++ b/src/bus/source.mk @@ -0,0 +1 @@ +SOURCES += src/bus/simple_bus.c diff --git a/src/components/bus/source.mk b/src/components/bus/source.mk deleted file mode 100644 index 98a10b6..0000000 --- a/src/components/bus/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/components/bus/simple_bus.c diff --git a/src/components/cpu/riscv/source.mk b/src/components/cpu/riscv/source.mk deleted file mode 100644 index da1cef6..0000000 --- a/src/components/cpu/riscv/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/components/cpu/riscv/simple_riscv64.c diff --git a/src/components/cpu/source.mk b/src/components/cpu/source.mk deleted file mode 100644 index ef808f6..0000000 --- a/src/components/cpu/source.mk +++ /dev/null @@ -1 +0,0 @@ -include src/components/cpu/*/source.mk diff --git a/src/components/grid/node.c b/src/components/grid/node.c deleted file mode 100644 index 57ef7ed..0000000 --- a/src/components/grid/node.c +++ /dev/null @@ -1,133 +0,0 @@ -/* very simple grid node with 32bit private region, does not currently signal - * being busy or anything. I think I might have to refine the message passing - * interface I have, but this is good enough. - * - * Each node should have a router beneath it, just to simplify my life. A router - * is basically a bus with a fallback ascension path. - */ -#include <stdbool.h> - -#include <gran/grid/node.h> - -struct grid_node { - struct component component; - uint8_t u, v, x, y; - struct component *left, *right, *up, *down, *ascend, *lower; - - struct component *send; - struct packet pkt; - bool busy; -}; - -static stat grid_clock(struct grid_node *grid) -{ - if (!grid->busy) - return OK; - - stat r = SEND(grid, grid->send, grid->pkt); - if (r == EBUSY) - return OK; - - grid->busy = false; - return r; -} - -static stat grid_receive(struct grid_node *grid, struct component *from, struct packet pkt) -{ - if (grid->busy) - return EBUSY; - - uint8_t u; - uint8_t v; - uint8_t x; - uint8_t y; - uint64_t addr = pkt.to; - addr_grid(addr, NULL, &x, &y, &u, &v); - - grid->busy = true; - grid->pkt = pkt; - - if (grid->u == u && grid->v == v && grid->x == x && grid->y == y) { - if (!grid->lower) - goto nosuch; - - grid->send = grid->lower; - return OK; - } - - if (grid->u != u || grid->v != v) { - if (!grid->ascend) - goto nosuch; - - grid->send = grid->ascend; - return OK; - } - - if (y < grid->y) { - if (!grid->down) - goto nosuch; - - grid->send = grid->down; - return OK; - } - - if (y > grid->y) { - if (!grid->up) - goto nosuch; - - grid->send = grid->up; - return OK; - } - - if (x < grid->x) { - if (!grid->left) - goto nosuch; - - grid->send = grid->left; - return OK; - } - - if (x > grid->x) { - if (!grid->right) - return EBUS; - - grid->send = grid->right; - return OK; - } - -nosuch: - grid->send = from; - grid->pkt = response(pkt); - set_flags(&grid->pkt, PACKET_ERROR); - return OK; -} - -struct component *create_grid_node(uint8_t u, uint8_t v, uint8_t x, uint8_t y) -{ - struct grid_node *node = calloc(1, sizeof(struct grid_node)); - if (!node) - return NULL; - - node->component.receive = (receive_callback)grid_receive; - node->component.clock = (clock_callback)grid_clock; - node->u = u; - node->v = v; - node->x = x; - node->y = y; - return (struct component *)node; -} - -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) -{ - struct grid_node *n = (struct grid_node *)node; - n->left = left; - n->right = right; - n->up = up; - n->down = down; - n->lower = lower; - n->ascend = ascend; - return OK; -} diff --git a/src/components/grid/router.c b/src/components/grid/router.c deleted file mode 100644 index 63c4011..0000000 --- a/src/components/grid/router.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <stdbool.h> - -#include <gran/grid/node.h> -#include <gran/grid/router.h> -#include <gran/vec.h> - -struct router_region { - uint32_t addr; - uint32_t size; - struct component *component; -}; - -struct node_router { - struct component component; - struct component *ascend; - struct vec regions; - uint8_t u, v, x, y; - - struct component *send; - struct packet pkt; - bool busy; -}; - -static struct router_region *find_region(struct node_router *router, uint32_t addr) -{ - for (size_t i = 0; i < vec_len(&router->regions); ++i) { - struct router_region *region = vec_at(&router->regions, i); - - if (addr >= region->addr && addr < region->addr + region->size) - return region; - } - - return NULL; -} - -static stat router_clock(struct node_router *router) -{ - if (!router->busy) - return OK; - - stat r = SEND(router, router->send, router->pkt); - if (r == EBUSY) - return OK; - - router->busy = false; - return OK; -} - -static stat router_receive(struct node_router *router, struct component *from, struct packet pkt) -{ - if (router->busy) - return EBUSY; - - router->busy = true; - - uint64_t addr = pkt.to; - uint8_t u; - uint8_t v; - uint8_t x; - uint8_t y; - addr_grid(addr, NULL, &x, &y, &u, &v); - - router->pkt = pkt; - - if (router->u != u || router->v != v || router->x != x || router->y != y) { - if (!router->ascend) - goto nosuch; - - router->send = router->ascend; - return OK; - } - - struct router_region *region = find_region(router, addr); - if (!region) - goto nosuch; - - router->send = region->component; - return OK; - -nosuch: - router->send = from; - router->pkt = response(pkt); - set_flags(&router->pkt, PACKET_ERROR); - return OK; -} - -struct component *create_node_router(uint8_t u, uint8_t v, uint8_t x, uint8_t y) -{ - struct node_router *router = calloc(1, sizeof(struct node_router)); - if (!router) - return NULL; - - router->u = u; - router->v = v; - router->x = x; - router->y = y; - - router->component.receive = (receive_callback)router_receive; - router->component.clock = (clock_callback)router_clock; - router->regions = vec_create(sizeof(struct router_region)); - - return (struct component *)router; -} - -stat node_router_add(struct component *router, struct component *component, uint32_t addr, uint32_t size) -{ - struct node_router *nr = (struct node_router *)router; - struct router_region *found = find_region(nr, addr); - if (!found) found = find_region(nr, addr + size); - - if (found) { - error("%s overlaps with %s at %x", - found->component->name, - component->name, - found->addr - ); - - return EEXISTS; - } - - struct router_region r = (struct router_region){ - .addr = addr, - .size = size, - .component = component - }; - vect_append(struct node_region, nr->regions, &r); - - return OK; -} - -stat node_router_ascend(struct component *router, struct component *node) -{ - struct node_router *nr = (struct node_router *)router; - nr->ascend = node; - return OK; -} diff --git a/src/components/grid/source.mk b/src/components/grid/source.mk deleted file mode 100644 index 4fb44ec..0000000 --- a/src/components/grid/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/components/grid/node.c src/components/grid/router.c diff --git a/src/components/mem/source.mk b/src/components/mem/source.mk deleted file mode 100644 index 9c339ba..0000000 --- a/src/components/mem/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/components/mem/simple_mem.c diff --git a/src/components/source.mk b/src/components/source.mk deleted file mode 100644 index c45f391..0000000 --- a/src/components/source.mk +++ /dev/null @@ -1 +0,0 @@ -include src/components/*/source.mk diff --git a/src/components/uart/source.mk b/src/components/uart/source.mk deleted file mode 100644 index af26289..0000000 --- a/src/components/uart/source.mk +++ /dev/null @@ -1 +0,0 @@ -SOURCES += src/components/uart/simple_uart.c diff --git a/src/components/cpu/riscv/simple_riscv64.c b/src/cpu/riscv/simple_riscv64.c index 987838e..1c4e810 100644 --- a/src/components/cpu/riscv/simple_riscv64.c +++ b/src/cpu/riscv/simple_riscv64.c @@ -149,7 +149,7 @@ static void set_reg(struct simple_riscv64 *cpu, size_t i, uint64_t v) #define EXTEND_IMM12(x) ((int32_t)((x) << 20) >> 20) #define EXTEND_IMM20(x) ((int32_t)((x) << 12) >> 12) -#define SHAMT(x) ((x) & 0b11111) +#define SHAMT(x) ((x) & 0b111111) static stat op_imm(struct simple_riscv64 *cpu, union rv_insn insn) { @@ -545,6 +545,8 @@ static stat simple_riscv64_receive(struct simple_riscv64 *cpu, struct component static stat simple_riscv64_clock(struct simple_riscv64 *cpu) { + stat ret = OK; + /* there's an active data transfer we should handle */ if (cpu->dls.state != LDST_IDLE) { assert(!is_set(&cpu->dls.pkt, PACKET_ERROR)); @@ -569,15 +571,15 @@ static stat simple_riscv64_clock(struct simple_riscv64 *cpu) return OK; } - if (cpu->ils.state == LDST_BLOCKED) { - stat ret = SEND(cpu, cpu->imem, cpu->ils.pkt); - if (ret == EBUSY) - return OK; + if (cpu->ils.state == LDST_BLOCKED) + goto send; + if (cpu->ils.state == LDST_SENT) return OK; - } - uint32_t insn = 0; + /* this effectively encodes a NOP */ + uint32_t insn = OP_IMM; + if (cpu->ils.state == LDST_DONE) { assert(!is_set(&cpu->dls.pkt, PACKET_ERROR)); @@ -585,24 +587,9 @@ static stat simple_riscv64_clock(struct simple_riscv64 *cpu) cpu->ils.state = LDST_IDLE; } - if (cpu->ils.state == LDST_IDLE) { - cpu->ils.pkt = create_packet(cpu->rcv + 64, - cpu->pc, - sizeof(uint32_t), - NULL, - PACKET_READ); - cpu->ils.state = LDST_SENT; - stat ret = SEND(cpu, cpu->imem, cpu->ils.pkt); - if (ret == EBUSY) { - cpu->ils.state = LDST_BLOCKED; - return ret; - } - } - // for now assume little endian emulated and host cpu union rv_insn i = {.val = insn}; - stat ret = OK; // all formats have identical opcodes, use whatever switch (i.rtype.op) { case OP_IMM: ret = op_imm(cpu, i); break; @@ -625,17 +612,30 @@ static stat simple_riscv64_clock(struct simple_riscv64 *cpu) return ENOSUCH; } - return ret; -} + if (cpu->ils.state == LDST_IDLE) { + cpu->ils.pkt = create_packet(cpu->rcv + 64, + cpu->pc, + sizeof(uint32_t), + NULL, + PACKET_READ); + cpu->ils.state = LDST_BLOCKED; + } -static void simple_riscv64_destroy(struct simple_riscv64 *cpu) -{ - destroy(cpu->imem); - destroy(cpu->dmem); - free(cpu); +send: + if (cpu->ils.state == LDST_BLOCKED) { + stat ret = SEND(cpu, cpu->imem, cpu->ils.pkt); + if (ret == EBUSY) { + cpu->ils.state = LDST_BLOCKED; + return ret; + } + + cpu->ils.state = LDST_SENT; + } + + return ret; } -struct component *create_simple_riscv64(uint64_t rcv, uint32_t start_pc, +struct component *create_simple_riscv64(uint64_t rcv, uint64_t start_pc, struct component *imem, struct component *dmem) { @@ -645,12 +645,20 @@ struct component *create_simple_riscv64(uint64_t rcv, uint32_t start_pc, new->component.receive = (receive_callback)simple_riscv64_receive; new->component.clock = (clock_callback)simple_riscv64_clock; - new->component.destroy = (destroy_callback)simple_riscv64_destroy; new->pc = start_pc; new->rcv = rcv; new->imem = imem; new->dmem = dmem; + + /* fetch new instruction at start */ + new->ils.state = LDST_BLOCKED; + new->ils.pkt = create_packet(new->rcv + 64, + new->pc, + sizeof(uint32_t), + NULL, + PACKET_READ); + return (struct component *)new; } diff --git a/src/cpu/riscv/source.mk b/src/cpu/riscv/source.mk new file mode 100644 index 0000000..aa11801 --- /dev/null +++ b/src/cpu/riscv/source.mk @@ -0,0 +1 @@ +SOURCES += src/cpu/riscv/simple_riscv64.c diff --git a/src/cpu/source.mk b/src/cpu/source.mk new file mode 100644 index 0000000..47dcc3e --- /dev/null +++ b/src/cpu/source.mk @@ -0,0 +1 @@ +include src/cpu/*/source.mk diff --git a/src/grid/node.c b/src/grid/node.c new file mode 100644 index 0000000..16cce1b --- /dev/null +++ b/src/grid/node.c @@ -0,0 +1,145 @@ +/* very simple grid node with 32bit private region, does not currently signal + * being busy or anything. I think I might have to refine the message passing + * interface I have, but this is good enough. + * + * Each node should have a router beneath it, just to simplify my life. A router + * is basically a bus with a fallback ascension path. + */ +#include <stdbool.h> + +#include <gran/grid/node.h> + +struct port { + struct component *send; + struct packet pkt; + bool busy; +}; + +struct grid_node { + struct component component; + uint16_t x, y; + + struct port left, right, up, down, lower; +}; + +static void port_clock(struct grid_node *grid, struct port *port) +{ + if (!port->busy) + return; + + stat r = SEND(grid, port->send, port->pkt); + if (r == EBUSY) + return; + + port->busy = false; +} + +static stat grid_clock(struct grid_node *grid) +{ + port_clock(grid, &grid->left); + port_clock(grid, &grid->right); + port_clock(grid, &grid->up); + port_clock(grid, &grid->down); + port_clock(grid, &grid->lower); + return OK; +} + +static stat port_receive(struct port *port, struct packet pkt) +{ + if (port->busy) + return EBUSY; + + port->pkt = pkt; + port->busy = true; + return OK; +} + +static stat grid_receive(struct grid_node *grid, struct component *from, struct packet pkt) +{ + uint16_t x; + uint16_t y; + uint64_t addr = pkt.to; + addr_grid(addr, NULL, &x, &y); + + if (grid->x == x && grid->y == y) { + if (!grid->lower.send) + goto nosuch; + + return port_receive(&grid->lower, pkt); + } + + if (y < grid->y) { + if (!grid->down.send) + goto nosuch; + + return port_receive(&grid->down, pkt); + } + + if (y > grid->y) { + if (!grid->up.send) + goto nosuch; + + return port_receive(&grid->up, pkt); + } + + if (x < grid->x) { + if (!grid->left.send) + goto nosuch; + + return port_receive(&grid->left, pkt); + } + + if (x > grid->x) { + if (!grid->right.send) + goto nosuch; + + return port_receive(&grid->right, pkt); + } + +nosuch: + set_flags(&pkt, PACKET_ERROR); + if (from == grid->lower.send) + return port_receive(&grid->lower, pkt); + + if (from == grid->left.send) + return port_receive(&grid->left, pkt); + + if (from == grid->right.send) + return port_receive(&grid->right, pkt); + + if (from == grid->down.send) + return port_receive(&grid->down, pkt); + + if (from == grid->up.send) + return port_receive(&grid->up, pkt); + + abort(); + return OK; +} + +struct component *create_grid_node(uint16_t x, uint16_t y) +{ + struct grid_node *node = calloc(1, sizeof(struct grid_node)); + if (!node) + return NULL; + + node->component.receive = (receive_callback)grid_receive; + node->component.clock = (clock_callback)grid_clock; + node->x = x; + node->y = y; + return (struct component *)node; +} + +stat grid_node_connect(struct component *node, + struct component *left, struct component *right, + struct component *up, struct component *down, + struct component *lower) +{ + struct grid_node *n = (struct grid_node *)node; + n->left.send = left; + n->right.send = right; + n->up.send = up; + n->down.send = down; + n->lower.send = lower; + return OK; +} diff --git a/src/grid/source.mk b/src/grid/source.mk new file mode 100644 index 0000000..e23d7db --- /dev/null +++ b/src/grid/source.mk @@ -0,0 +1 @@ +SOURCES += src/grid/node.c diff --git a/src/components/mem/simple_mem.c b/src/mem/simple_mem.c index e435ea5..0a3a3ce 100644 --- a/src/components/mem/simple_mem.c +++ b/src/mem/simple_mem.c @@ -19,7 +19,7 @@ struct simple_mem { static stat simple_mem_clock(struct simple_mem *mem) { - if (mem->busy) + if (!mem->busy) return OK; stat r = SEND(mem, mem->send, mem->pkt); @@ -35,6 +35,7 @@ static stat simple_mem_receive(struct simple_mem *mem, struct component *from, s if (mem->busy) return EBUSY; + mem->busy = true; mem->send = from; uint64_t offset = pkt.to % mem->size; diff --git a/src/mem/source.mk b/src/mem/source.mk new file mode 100644 index 0000000..7d1a717 --- /dev/null +++ b/src/mem/source.mk @@ -0,0 +1 @@ +SOURCES += src/mem/simple_mem.c diff --git a/src/source.mk b/src/source.mk index db585ee..dd92722 100644 --- a/src/source.mk +++ b/src/source.mk @@ -1,6 +1,4 @@ -include src/components/source.mk +include src/*/source.mk -# everything except main -SRC_LOCAL != echo src/*.c | sed 's|src/main.c||g' -SOURCES += $(SRC_LOCAL) -MAIN_SRC = src/main.c +SOURCES += src/root.c src/clock_domain.c src/vec.c +MAIN_SRC += src/main.c diff --git a/src/components/uart/simple_uart.c b/src/uart/simple_uart.c index 1528a70..e640ae1 100644 --- a/src/components/uart/simple_uart.c +++ b/src/uart/simple_uart.c @@ -38,6 +38,7 @@ static stat simple_uart_receive(struct simple_uart *uart, struct component *from } putchar(packet_convu8(&pkt)); + fflush(stdout); set_flags(&uart->pkt, PACKET_DONE); return OK; } diff --git a/src/uart/source.mk b/src/uart/source.mk new file mode 100644 index 0000000..cdc0bc9 --- /dev/null +++ b/src/uart/source.mk @@ -0,0 +1 @@ +SOURCES += src/uart/simple_uart.c diff --git a/tests/simple_grid/sim.c b/tests/simple_grid/sim.c index f11be21..519599e 100644 --- a/tests/simple_grid/sim.c +++ b/tests/simple_grid/sim.c @@ -8,30 +8,33 @@ #include <gran/bus/simple_bus.h> #include <gran/uart/simple_uart.h> #include <gran/grid/node.h> -#include <gran/grid/router.h> #include <gran/cpu/riscv/simple_riscv64.h> -unsigned char test_grid[] = { - 0xb3, 0x67, 0xb5, 0x00, 0x63, 0x9a, 0x07, 0x0a, 0xb7, 0x17, 0x00, 0x00, - 0x23, 0xb0, 0x07, 0x00, 0x1b, 0x57, 0x35, 0x00, 0xb7, 0x27, 0x00, 0x00, - 0x93, 0x06, 0x80, 0x02, 0x13, 0x77, 0x77, 0x00, 0x23, 0x80, 0xd7, 0x00, - 0x13, 0x07, 0x07, 0x03, 0x93, 0x76, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, - 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, 0x93, 0x06, 0xc0, 0x02, - 0x1b, 0xd7, 0x35, 0x00, 0x23, 0x80, 0xd7, 0x00, 0x13, 0x77, 0x77, 0x00, - 0x93, 0x06, 0x00, 0x02, 0x23, 0x80, 0xd7, 0x00, 0x13, 0x07, 0x07, 0x03, - 0x93, 0xf6, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x87, 0x06, 0x03, - 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x90, 0x02, 0x23, 0x80, 0xe7, 0x00, - 0x93, 0x06, 0xa0, 0x00, 0x23, 0x80, 0xd7, 0x00, 0x1b, 0x87, 0x15, 0x00, - 0x93, 0x06, 0xf0, 0x03, 0x93, 0x77, 0xf7, 0x0f, 0x63, 0x98, 0xd5, 0x00, - 0x1b, 0x05, 0x15, 0x00, 0x13, 0x75, 0xf5, 0x0f, 0x93, 0x07, 0x00, 0x00, - 0x13, 0x15, 0x85, 0x00, 0x33, 0x65, 0xf5, 0x00, 0xb7, 0x17, 0x00, 0x00, - 0x23, 0xb0, 0xa7, 0x00, 0xb7, 0x16, 0x00, 0x00, 0x37, 0x47, 0x00, 0x00, - 0x83, 0xb7, 0x06, 0x00, 0xe3, 0x9e, 0xe7, 0xfe, 0x73, 0x00, 0x10, 0x00, - 0x67, 0x80, 0x00, 0x00, 0x13, 0x17, 0x85, 0x00, 0x33, 0x67, 0xb7, 0x00, - 0xb7, 0x16, 0x00, 0x00, 0x83, 0xb7, 0x06, 0x00, 0xe3, 0x9e, 0xe7, 0xfe, - 0x6f, 0xf0, 0x5f, 0xf4 +unsigned char _tmp_test_bin[] = { + 0x1b, 0x86, 0x05, 0x00, 0x63, 0x18, 0x05, 0x00, 0x93, 0x07, 0x10, 0x00, + 0x1b, 0x86, 0x05, 0x00, 0x63, 0x88, 0xf5, 0x0c, 0x93, 0x16, 0x85, 0x00, + 0x37, 0x17, 0x00, 0x10, 0xb3, 0xe6, 0xb6, 0x00, 0x13, 0x17, 0x47, 0x01, + 0x83, 0x37, 0x07, 0x00, 0xe3, 0x9e, 0xd7, 0xfe, 0x1b, 0x57, 0x35, 0x00, + 0xb7, 0x17, 0x00, 0x00, 0x93, 0x06, 0x80, 0x02, 0x13, 0x77, 0x77, 0x00, + 0x23, 0x80, 0xd7, 0x00, 0x13, 0x07, 0x07, 0x03, 0x93, 0x76, 0x75, 0x00, + 0x23, 0x80, 0xe7, 0x00, 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, + 0x93, 0x06, 0xc0, 0x02, 0x1b, 0xd7, 0x35, 0x00, 0x23, 0x80, 0xd7, 0x00, + 0x13, 0x77, 0x77, 0x00, 0x93, 0x06, 0x00, 0x02, 0x23, 0x80, 0xd7, 0x00, + 0x13, 0x07, 0x07, 0x03, 0x93, 0xf6, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, + 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x90, 0x02, + 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xa0, 0x00, 0x23, 0x80, 0xe7, 0x00, + 0x93, 0x07, 0xf0, 0x03, 0x63, 0x0c, 0xf6, 0x02, 0x9b, 0x85, 0x15, 0x00, + 0x93, 0x95, 0x05, 0x03, 0x93, 0xd5, 0x05, 0x03, 0x13, 0x15, 0x85, 0x00, + 0x37, 0x17, 0x00, 0x10, 0x33, 0x65, 0xb5, 0x00, 0x13, 0x17, 0x47, 0x01, + 0x23, 0x30, 0xa7, 0x00, 0xb7, 0x46, 0x00, 0x00, 0x83, 0x37, 0x07, 0x00, + 0xe3, 0x9e, 0xd7, 0xfe, 0x73, 0x00, 0x10, 0x00, 0x67, 0x80, 0x00, 0x00, + 0x1b, 0x05, 0x15, 0x00, 0x13, 0x15, 0x05, 0x03, 0x13, 0x55, 0x05, 0x03, + 0x93, 0x05, 0x00, 0x00, 0x6f, 0xf0, 0x9f, 0xfc, 0xb7, 0x17, 0x00, 0x10, + 0x93, 0x97, 0x47, 0x01, 0x23, 0xb0, 0x07, 0x00, 0x13, 0x07, 0x00, 0x03, + 0xb7, 0x17, 0x00, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xa0, 0x00, + 0x23, 0x80, 0xe7, 0x00, 0x6f, 0xf0, 0xdf, 0xf2 }; -unsigned int test_grid_len = 208; +unsigned int _tmp_test_bin_len = 260; static struct component *get_grid(struct component **grid, int i, int j, uint8_t x, uint8_t y) { @@ -55,45 +58,61 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) struct component **grid = calloc(x * y, sizeof(struct component *)); assert(grid); - struct component **routers = calloc(x * y, sizeof(struct component *)); - assert(routers); + struct component **pes = calloc(x * y, sizeof(struct component *)); + assert(pes); for (size_t i = 0; i < x; ++i) for (size_t j = 0; j < y; ++j) { - struct component *imem = create_simple_mem(4096); - init_simple_mem(imem, 0, test_grid_len, test_grid); + struct component *node = create_grid_node(i, j); + clock_domain_add(clk, node); + grid[i * x + j] = node; + + if (i == 0 && j == 0) + continue; - struct component *dmem = create_simple_mem(4096); - struct component *router = create_node_router(0, 0, i, j); - node_router_add(router, dmem, 4096, 4096); + if (i == 1 && j == 1) + continue; + + struct component *imem = create_simple_mem(4096); + init_simple_mem(imem, 0, _tmp_test_bin_len, _tmp_test_bin); - uint64_t rcv = grid_addr(0, 0, i, j, 16384); - struct component *rv64 = create_simple_riscv64(rcv, 0, imem, router); + uint64_t rcv = grid_addr(i, j, 0); + struct component *rv64 = create_simple_riscv64(rcv, 0, imem, node); simple_riscv64_set_reg(rv64, 10, i); /* a0 */ simple_riscv64_set_reg(rv64, 11, j); /* a1 */ clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); - routers[i * x + j] = router; - grid[i * x + j] = create_grid_node(0, 0, i, j); + pes[i * x + j] = rv64; } struct component *uart = create_simple_uart(); - node_router_add(routers[0], uart, 8192, 1); + clock_domain_add(clk, uart); + grid_node_connect(grid[0], NULL, grid[x], grid[1], NULL, uart); + + struct component *dmem = create_simple_mem(4096); + clock_domain_add(clk, dmem); + grid_node_connect(grid[x + 1], grid[1], grid[2 * x + 1], grid[x + 2], grid[x], dmem); for (int i = 0; i < x; ++i) for (int j = 0; j < y; ++j) { + if (i == 0 && j == 0) + continue; + + if (i == 1 && j == 1) + continue; + struct component *node = grid[i * x + j]; - struct component *lower = routers[i * x + j]; + struct component *lower = pes[i * x + j]; struct component *left = get_grid(grid, i - 1, j , x, y); struct component *right = get_grid(grid, i + 1, j , x, y); struct component *up = get_grid(grid, i , j + 1, x, y); struct component *down = get_grid(grid, i , j - 1, x, y); - grid_node_connect(node, left, right, up, down, lower, NULL); - node_router_ascend(lower, node); + grid_node_connect(node, left, right, up, down, lower); } - free(routers); + free(pes); free(grid); return OK; } diff --git a/tests/simple_grid/test.c b/tests/simple_grid/test.c index 782062d..07f1123 100644 --- a/tests/simple_grid/test.c +++ b/tests/simple_grid/test.c @@ -1,14 +1,17 @@ #define X 64 #define Y 64 -void _start(unsigned char x, unsigned char y) +void _start(unsigned short x, unsigned short y) { - volatile unsigned long *counter = (unsigned long *)4096; - volatile char *uart = (char *)8192; + volatile unsigned long *counter = (unsigned long *)((1ULL << 48) | (1ULL << 32)); + volatile char *uart = (char *)4096; /* very hacky, not recommended but good enough for testing */ - if (x == 0 && y == 0) + if (x == 0 && y == 1) { *counter = 0; + *uart = '0'; + *uart = '\n'; + } else while (*counter != ((x << 8) | y)) ; diff --git a/tests/simple_riscv64/sim.c b/tests/simple_riscv64/sim.c index ae3cad4..f92be96 100644 --- a/tests/simple_riscv64/sim.c +++ b/tests/simple_riscv64/sim.c @@ -17,17 +17,19 @@ unsigned int simple_sum_len = 36; int main() { - const size_t size = 100000; + const size_t size = 4096; struct component *imem = create_simple_mem(size); /* This works for simple memory, but feels kind of hacky */ init_simple_mem(imem, 0, simple_sum_len, simple_sum); struct component *dmem = create_simple_mem(size); - struct component *rv64 = create_simple_riscv64(0, imem, dmem); + struct component *rv64 = create_simple_riscv64(4096, 0, imem, dmem); struct clock_domain *clk = create_clock_domain(NS(1)); clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); + clock_domain_add(clk, dmem); struct gran_root *root = create_root(); root_add_clock(root, clk); diff --git a/tests/simple_uart/sim.c b/tests/simple_uart/sim.c index 762b591..c0d1f82 100644 --- a/tests/simple_uart/sim.c +++ b/tests/simple_uart/sim.c @@ -31,10 +31,15 @@ int main() simple_bus_add(bus, dmem, 0, size); simple_bus_add(bus, uart, size, 1); - struct component *rv64 = create_simple_riscv64(0, imem, bus); + struct component *rv64 = create_simple_riscv64(8192, 0, imem, bus); + simple_bus_add(bus, rv64, 8192, 4096); struct clock_domain *clk = create_clock_domain(NS(1)); clock_domain_add(clk, rv64); + clock_domain_add(clk, dmem); + clock_domain_add(clk, imem); + clock_domain_add(clk, bus); + clock_domain_add(clk, uart); struct gran_root *root = create_root(); root_add_clock(root, clk); |
