From 7353810199e7c9d9766c44020a5a207cc85686db Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Thu, 11 Dec 2025 12:57:59 +0000 Subject: [PATCH] Move all host examples under host/ --- Makefile | 10 +- apps/makefile.common | 2 +- host-mini/Makefile | 6 - host-parallel/Makefile | 5 - host-parallel/host-parallel.c | 111 ------------------ host/Makefile | 5 - {host-arduino => hosts/host-arduino}/Makefile | 14 ++- {host-arduino => hosts/host-arduino}/config.h | 0 .../host-arduino}/host-arduino.ino | 2 +- hosts/host-mini/Makefile | 8 ++ {host-mini => hosts/host-mini}/host-mini.c | 0 {host-mini => hosts/host-mini}/mandel.h | 0 hosts/host-parallel/Makefile | 7 ++ hosts/host-parallel/host-parallel.c | 70 +++++++++++ hosts/host/Makefile | 7 ++ {host => hosts/host}/host.c | 0 16 files changed, 104 insertions(+), 143 deletions(-) delete mode 100644 host-mini/Makefile delete mode 100644 host-parallel/Makefile delete mode 100644 host-parallel/host-parallel.c delete mode 100644 host/Makefile rename {host-arduino => hosts/host-arduino}/Makefile (55%) rename {host-arduino => hosts/host-arduino}/config.h (100%) rename {host-arduino => hosts/host-arduino}/host-arduino.ino (96%) create mode 100644 hosts/host-mini/Makefile rename {host-mini => hosts/host-mini}/host-mini.c (100%) rename {host-mini => hosts/host-mini}/mandel.h (100%) create mode 100644 hosts/host-parallel/Makefile create mode 100644 hosts/host-parallel/host-parallel.c create mode 100644 hosts/host/Makefile rename {host => hosts/host}/host.c (100%) diff --git a/Makefile b/Makefile index f1eeba4..b4f911c 100644 --- a/Makefile +++ b/Makefile @@ -2,18 +2,12 @@ all: make -C test - (cd host && make) - (cd host-mini && make) - (cd host-parallel && make) - (cd host-arduino && make) + (cd hosts && make) (cd apps && make) clean: make -C test clean - (cd host && make clean) - (cd host-mini && make clean) - (cd host-parallel && make clean) - (cd host-arduino && make clean) + (cd hosts && make clean) (cd apps && make clean) test: diff --git a/apps/makefile.common b/apps/makefile.common index 1551ef5..69fc9e5 100644 --- a/apps/makefile.common +++ b/apps/makefile.common @@ -29,7 +29,7 @@ disasm_common: all $(PREFIX)objdump -S -d -f ${PROJECT}.elf test_common: all - ${TOPDIR}/host/host ${PWD}/${PROJECT}.bin + ${TOPDIR}/hosts/host/host ${PWD}/${PROJECT}.bin clean_common: rm -f ${PROJECT}.o ${PROJECT}.elf ${PROJECT}.bin diff --git a/host-mini/Makefile b/host-mini/Makefile deleted file mode 100644 index a462722..0000000 --- a/host-mini/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: - xxd -n mandel -i ../precompiled/mandel.bin | sed -e "s/unsigned char/const unsigned char/" > mandel.h - gcc -Wall -DUVM32_MEMORY_SIZE=512 -O2 -I../uvm32 -I../common -o host-mini ../uvm32/uvm32.c host-mini.c - -clean: - rm -f host-mini diff --git a/host-parallel/Makefile b/host-parallel/Makefile deleted file mode 100644 index d757173..0000000 --- a/host-parallel/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - gcc -Wall -DUVM32_MEMORY_SIZE=16386 -I../uvm32 -I../common -o host-parallel ../uvm32/uvm32.c host-parallel.c - -clean: - rm -f host-parallel diff --git a/host-parallel/host-parallel.c b/host-parallel/host-parallel.c deleted file mode 100644 index d2d3fd7..0000000 --- a/host-parallel/host-parallel.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include "uvm32.h" -#include "../common/uvm32_common_custom.h" - -// Run multiple scheduled VMs in parallel until all have ended -#define NUM_VM 4 // number of vms -#define SCHEDULE SCHEDULE_RANDOM // scheduling algorithm - -// scheduling algorithms -#define SCHEDULE_ROUNDROBIN() scheduler_index = (scheduler_index + 1) % NUM_VM -#define SCHEDULE_RANDOM() scheduler_index = rand()%NUM_VM - -uint8_t rom[] = { // fib.bin - 0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x16, 0xb7, 0x08, 0x00, 0x01, - 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00, - 0x93, 0x08, 0x40, 0x00, 0x73, 0x00, 0x00, 0x00, 0x37, 0x05, 0x00, 0x80, - 0x13, 0x05, 0x05, 0x1c, 0x93, 0x08, 0x30, 0x00, 0x73, 0x00, 0x00, 0x00, - 0x67, 0x80, 0x00, 0x00, 0x13, 0x01, 0x01, 0xfe, 0x23, 0x2c, 0x81, 0x00, - 0x13, 0x04, 0x10, 0x00, 0x23, 0x2a, 0x91, 0x00, 0x23, 0x28, 0x21, 0x01, - 0x23, 0x26, 0x31, 0x01, 0x23, 0x22, 0x51, 0x01, 0x23, 0x20, 0x61, 0x01, - 0x23, 0x2e, 0x11, 0x00, 0x23, 0x24, 0x41, 0x01, 0x13, 0x09, 0x05, 0x00, - 0x93, 0x09, 0x00, 0x00, 0x93, 0x04, 0x04, 0x00, 0x93, 0x0a, 0x20, 0x00, - 0x13, 0x0b, 0x04, 0x00, 0x63, 0x56, 0x89, 0x02, 0x83, 0x20, 0xc1, 0x01, - 0x03, 0x24, 0x81, 0x01, 0x83, 0x24, 0x41, 0x01, 0x03, 0x29, 0x01, 0x01, - 0x83, 0x29, 0xc1, 0x00, 0x03, 0x2a, 0x81, 0x00, 0x83, 0x2a, 0x41, 0x00, - 0x03, 0x2b, 0x01, 0x00, 0x13, 0x01, 0x01, 0x02, 0x67, 0x80, 0x00, 0x00, - 0x63, 0xd0, 0x8a, 0x02, 0x33, 0x8a, 0x34, 0x01, 0x13, 0x05, 0x0a, 0x00, - 0xef, 0xf0, 0xdf, 0xf6, 0x93, 0x89, 0x04, 0x00, 0x13, 0x04, 0x14, 0x00, - 0x93, 0x04, 0x0a, 0x00, 0x6f, 0xf0, 0x9f, 0xfb, 0x13, 0x85, 0x09, 0x00, - 0x63, 0x04, 0x64, 0x01, 0x13, 0x85, 0x04, 0x00, 0xef, 0xf0, 0xdf, 0xf4, - 0x13, 0x8a, 0x04, 0x00, 0x6f, 0xf0, 0x1f, 0xfe, 0x13, 0x01, 0x01, 0xfe, - 0x23, 0x2c, 0x81, 0x00, 0x23, 0x2a, 0x91, 0x00, 0x23, 0x26, 0x31, 0x01, - 0x23, 0x2e, 0x11, 0x00, 0x23, 0x28, 0x21, 0x01, 0x93, 0x04, 0x05, 0x00, - 0x13, 0x04, 0x06, 0x00, 0x93, 0x09, 0x20, 0x00, 0x63, 0xd0, 0x99, 0x02, - 0x33, 0x89, 0x85, 0x00, 0x13, 0x05, 0x09, 0x00, 0xef, 0xf0, 0x1f, 0xf1, - 0x93, 0x05, 0x04, 0x00, 0x93, 0x84, 0xf4, 0xff, 0x13, 0x04, 0x09, 0x00, - 0x6f, 0xf0, 0x5f, 0xfe, 0x83, 0x20, 0xc1, 0x01, 0x03, 0x24, 0x81, 0x01, - 0x83, 0x24, 0x41, 0x01, 0x03, 0x29, 0x01, 0x01, 0x83, 0x29, 0xc1, 0x00, - 0x13, 0x01, 0x01, 0x02, 0x67, 0x80, 0x00, 0x00, 0x13, 0x01, 0x01, 0xff, - 0x23, 0x24, 0x81, 0x00, 0x13, 0x04, 0x05, 0x00, 0x13, 0x05, 0x00, 0x00, - 0x23, 0x26, 0x11, 0x00, 0xef, 0xf0, 0xdf, 0xec, 0x13, 0x05, 0x10, 0x00, - 0xef, 0xf0, 0x5f, 0xec, 0x13, 0x05, 0x04, 0x00, 0x03, 0x24, 0x81, 0x00, - 0x83, 0x20, 0xc1, 0x00, 0x13, 0x06, 0x10, 0x00, 0x93, 0x05, 0x00, 0x00, - 0x13, 0x01, 0x01, 0x01, 0x6f, 0xf0, 0x9f, 0xf6, 0x13, 0x01, 0x01, 0xff, - 0x37, 0x05, 0x00, 0x80, 0x23, 0x26, 0x11, 0x00, 0x13, 0x05, 0x45, 0x1c, - 0x93, 0x05, 0x00, 0x00, 0x93, 0x08, 0x30, 0x00, 0x73, 0x00, 0x00, 0x00, - 0x13, 0x05, 0x80, 0x02, 0xef, 0xf0, 0x5f, 0xea, 0x37, 0x05, 0x00, 0x80, - 0x13, 0x05, 0x05, 0x1d, 0x93, 0x05, 0x00, 0x00, 0x93, 0x08, 0x30, 0x00, - 0x73, 0x00, 0x00, 0x00, 0x83, 0x20, 0xc1, 0x00, 0x13, 0x05, 0x80, 0x02, - 0x13, 0x01, 0x01, 0x01, 0x6f, 0xf0, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x69, 0x62, 0x28, - 0x29, 0x20, 0x6c, 0x6f, 0x6f, 0x70, 0x00, 0x00, 0x66, 0x69, 0x62, 0x28, - 0x29, 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x00 -}; - -int main(int argc, char *argv[]) { - uvm32_state_t vmst[NUM_VM]; - uvm32_evt_t evt; - int numVmRunning = NUM_VM; - int scheduler_index = 0; - - for (int i=0;i 0) { - if (uvm32_hasEnded(&vmst[scheduler_index])) { - // this vm has already completed, pick another - SCHEDULE(); - continue; - } - uvm32_run(&vmst[scheduler_index], &evt, 100); // num instructions before vm considered hung - - switch(evt.typ) { - case UVM32_EVT_END: - printf("[VM %d ended]\n", scheduler_index); - numVmRunning--; - break; - case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL - switch(evt.data.syscall.code) { - case UVM32_SYSCALL_YIELD: - break; - case UVM32_SYSCALL_PRINTLN: { - const char *str = uvm32_getcstr(&vmst[scheduler_index], &evt, ARG0); - if (str[0] != 0) { - printf("[VM %d] %s\n", scheduler_index, str); - } - } break; - case UVM32_SYSCALL_PRINTDEC: - printf("[VM %d] %d\n", scheduler_index, uvm32_getval(&vmst[scheduler_index], &evt, ARG0)); - break; - default: - printf("Unhandled syscall 0x%08x\n", evt.data.syscall.code); - break; - } - break; - case UVM32_EVT_ERR: - printf("UVM32_EVT_ERR '%s' (%d)\n", evt.data.err.errstr, (int)evt.data.err.errcode); - break; - default: - break; - } - - SCHEDULE(); - } - - return 0; -} diff --git a/host/Makefile b/host/Makefile deleted file mode 100644 index 9b15a49..0000000 --- a/host/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - gcc -Wall -Werror -pedantic -std=c99 -O2 -DUVM32_MEMORY_SIZE=65536 -I../uvm32 -I../common -o host ../uvm32/uvm32.c host.c - -clean: - rm -f host diff --git a/host-arduino/Makefile b/hosts/host-arduino/Makefile similarity index 55% rename from host-arduino/Makefile rename to hosts/host-arduino/Makefile index 58804ad..8012bc2 100644 --- a/host-arduino/Makefile +++ b/hosts/host-arduino/Makefile @@ -1,3 +1,5 @@ +TOPDIR=../../ + # Auto-generate the Arduino example # Arduino cannot set -DUVM32_MEMORY_SIZE, so add a config file # Arduino expects .cpp files @@ -6,12 +8,12 @@ all: echo '#include "config.h"' > uvm32.cpp - cat ../uvm32/uvm32.c >> uvm32.cpp - cp ../uvm32/uvm32.h uvm32.h - cp ../uvm32/mini-rv32ima.h mini-rv32ima.h - cp ../common/uvm32_common_custom.h uvm32_common_custom.h - cp ../common/uvm32_sys.h uvm32_sys.h - xxd -i ../precompiled/mandel.bin | sed -e "s/unsigned char/const unsigned char/" > mandel.h + cat ${TOPDIR}/uvm32/uvm32.c >> uvm32.cpp + cp ${TOPDIR}/uvm32/uvm32.h uvm32.h + cp ${TOPDIR}/uvm32/mini-rv32ima.h mini-rv32ima.h + cp ${TOPDIR}/common/uvm32_common_custom.h uvm32_common_custom.h + cp ${TOPDIR}/common/uvm32_sys.h uvm32_sys.h + xxd -n mandel -i ${TOPDIR}/precompiled/mandel.bin | sed -e "s/unsigned char/const unsigned char/" > mandel.h arduino-cli compile -b arduino:avr:uno -e test: all diff --git a/host-arduino/config.h b/hosts/host-arduino/config.h similarity index 100% rename from host-arduino/config.h rename to hosts/host-arduino/config.h diff --git a/host-arduino/host-arduino.ino b/hosts/host-arduino/host-arduino.ino similarity index 96% rename from host-arduino/host-arduino.ino rename to hosts/host-arduino/host-arduino.ino index b566227..f38096e 100644 --- a/host-arduino/host-arduino.ino +++ b/hosts/host-arduino/host-arduino.ino @@ -67,7 +67,7 @@ void loop(void) { Serial.println("Running VM"); // setup vm uvm32_init(&vmst); - uvm32_load(&vmst, ___precompiled_mandel_bin, ___precompiled_mandel_bin_len); + uvm32_load(&vmst, mandel, mandel_len); isrunning = true; } } diff --git a/hosts/host-mini/Makefile b/hosts/host-mini/Makefile new file mode 100644 index 0000000..ae8a889 --- /dev/null +++ b/hosts/host-mini/Makefile @@ -0,0 +1,8 @@ +TOPDIR=../../ + +all: + xxd -n mandel -i ${TOPDIR}/precompiled/mandel.bin | sed -e "s/unsigned char/const unsigned char/" > mandel.h + gcc -Wall -DUVM32_MEMORY_SIZE=512 -O2 -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host-mini ${TOPDIR}/uvm32/uvm32.c host-mini.c + +clean: + rm -f host-mini diff --git a/host-mini/host-mini.c b/hosts/host-mini/host-mini.c similarity index 100% rename from host-mini/host-mini.c rename to hosts/host-mini/host-mini.c diff --git a/host-mini/mandel.h b/hosts/host-mini/mandel.h similarity index 100% rename from host-mini/mandel.h rename to hosts/host-mini/mandel.h diff --git a/hosts/host-parallel/Makefile b/hosts/host-parallel/Makefile new file mode 100644 index 0000000..78c7952 --- /dev/null +++ b/hosts/host-parallel/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../ +all: + xxd -n fib -i ${TOPDIR}/precompiled/fib.bin | sed -e "s/unsigned char/const unsigned char/" > fib.h + gcc -Wall -DUVM32_MEMORY_SIZE=16386 -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host-parallel ${TOPDIR}/uvm32/uvm32.c host-parallel.c + +clean: + rm -f host-parallel diff --git a/hosts/host-parallel/host-parallel.c b/hosts/host-parallel/host-parallel.c new file mode 100644 index 0000000..1866c91 --- /dev/null +++ b/hosts/host-parallel/host-parallel.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include "uvm32.h" +#include "../common/uvm32_common_custom.h" + +// Run multiple scheduled VMs in parallel until all have ended +#define NUM_VM 4 // number of vms +#define SCHEDULE SCHEDULE_RANDOM // scheduling algorithm + +// scheduling algorithms +#define SCHEDULE_ROUNDROBIN() scheduler_index = (scheduler_index + 1) % NUM_VM +#define SCHEDULE_RANDOM() scheduler_index = rand()%NUM_VM + +#include "fib.h" + +int main(int argc, char *argv[]) { + uvm32_state_t vmst[NUM_VM]; + uvm32_evt_t evt; + int numVmRunning = NUM_VM; + int scheduler_index = 0; + + for (int i=0;i 0) { + if (uvm32_hasEnded(&vmst[scheduler_index])) { + // this vm has already completed, pick another + SCHEDULE(); + continue; + } + uvm32_run(&vmst[scheduler_index], &evt, 100); // num instructions before vm considered hung + + switch(evt.typ) { + case UVM32_EVT_END: + printf("[VM %d ended]\n", scheduler_index); + numVmRunning--; + break; + case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL + switch(evt.data.syscall.code) { + case UVM32_SYSCALL_YIELD: + break; + case UVM32_SYSCALL_PRINTLN: { + const char *str = uvm32_getcstr(&vmst[scheduler_index], &evt, ARG0); + if (str[0] != 0) { + printf("[VM %d] %s\n", scheduler_index, str); + } + } break; + case UVM32_SYSCALL_PRINTDEC: + printf("[VM %d] %d\n", scheduler_index, uvm32_getval(&vmst[scheduler_index], &evt, ARG0)); + break; + default: + printf("Unhandled syscall 0x%08x\n", evt.data.syscall.code); + break; + } + break; + case UVM32_EVT_ERR: + printf("UVM32_EVT_ERR '%s' (%d)\n", evt.data.err.errstr, (int)evt.data.err.errcode); + break; + default: + break; + } + + SCHEDULE(); + } + + return 0; +} diff --git a/hosts/host/Makefile b/hosts/host/Makefile new file mode 100644 index 0000000..19331f2 --- /dev/null +++ b/hosts/host/Makefile @@ -0,0 +1,7 @@ +TOPDIR=../../ + +all: + gcc -Wall -Werror -pedantic -std=c99 -O2 -DUVM32_MEMORY_SIZE=65536 -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host ${TOPDIR}/uvm32/uvm32.c host.c + +clean: + rm -f host diff --git a/host/host.c b/hosts/host/host.c similarity index 100% rename from host/host.c rename to hosts/host/host.c