Renaming and documentating header

This commit is contained in:
Toby Jaffey 2025-12-12 20:42:26 +00:00
parent 9880eadf4f
commit 8158ac647c
19 changed files with 305 additions and 225 deletions

View file

@ -36,19 +36,19 @@ void loop(void) {
case UVM32_SYSCALL_YIELD:
break;
case UVM32_SYSCALL_PUTC:
Serial.print((char)uvm32_getval(&vmst, &evt, ARG0));
Serial.print((char)uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PRINTLN: {
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
Serial.print(str);
Serial.println("");
} break;
case UVM32_SYSCALL_PRINT: {
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
Serial.print(str);
} break;
case UVM32_SYSCALL_MILLIS: {
uvm32_setval(&vmst, &evt, RET, millis());
uvm32_arg_setval(&vmst, &evt, RET, millis());
} break;
default:
Serial.print("Unhandled syscall: ");
@ -59,7 +59,7 @@ void loop(void) {
break;
case UVM32_EVT_ERR:
Serial.print("Error: ");
Serial.println(evt.data.err.errstr);
Serial.println(evt.data.err.errcode);
isrunning = false;
break;
}

View file

@ -2,7 +2,7 @@ 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
gcc -Wall -DUVM32_ERROR_STRINGS -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

View file

@ -25,10 +25,10 @@ int main(int argc, char *argv[]) {
case UVM32_SYSCALL_YIELD:
break;
case UVM32_SYSCALL_PUTC:
printf("%c", uvm32_getval(&vmst, &evt, ARG0));
printf("%c", uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PRINTLN: {
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
printf("%s\n", str);
} break;
default:

View file

@ -1,7 +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
gcc -Wall -DUVM32_ERROR_STRINGS -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

View file

@ -43,13 +43,13 @@ int main(int argc, char *argv[]) {
case UVM32_SYSCALL_YIELD:
break;
case UVM32_SYSCALL_PRINTLN: {
const char *str = uvm32_getcstr(&vmst[scheduler_index], &evt, ARG0);
const char *str = uvm32_arg_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));
printf("[VM %d] %d\n", scheduler_index, uvm32_arg_getval(&vmst[scheduler_index], &evt, ARG0));
break;
default:
printf("Unhandled syscall 0x%08x\n", evt.data.syscall.code);

View file

@ -11,7 +11,7 @@ endif
CFLAGS += -Wall -Werror
CFLAGS += -pedantic -std=c99 -O3
CFLAGS += -DUVM32_MEMORY_SIZE=$(shell echo "1024 * 1024 * 8" | bc)
CFLAGS += -DUVM32_ERROR_STRINGS -DUVM32_MEMORY_SIZE=$(shell echo "1024 * 1024 * 8" | bc)
all:
gcc ${CFLAGS} -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host-sdl ${TOPDIR}/uvm32/uvm32.c host-sdl.c ${LIBS}

View file

@ -214,8 +214,8 @@ int main(int argc, char *argv[]) {
uvm32_clearError(vmst); // allow to continue
} else {
isrunning = false;
memdump("host-ram.dump", vmst->memory, UVM32_MEMORY_SIZE);
printf("memory dumped to host-ram.dump, pc=0x%08x\n", vmst->core.pc);
memdump("host-ram.dump", uvm32_getMemory(vmst), UVM32_MEMORY_SIZE);
printf("memory dumped to host-ram.dump, pc=0x%08x\n", uvm32_getProgramCounter(vmst));
if (extram_buf != NULL) {
memdump("host-extram.dump", (uint8_t *)extram_buf, extram_len);
printf("extram dumped to host-extram.dump\n");
@ -225,41 +225,41 @@ int main(int argc, char *argv[]) {
case UVM32_EVT_SYSCALL:
switch(evt.data.syscall.code) {
case UVM32_SYSCALL_PRINTBUF: {
uvm32_evt_syscall_buf_t buf = uvm32_getbuf(vmst, &evt, ARG0, ARG1);
uvm32_slice_t buf = uvm32_arg_getbuf(vmst, &evt, ARG0, ARG1);
while(buf.len--) {
printf("%02x", *buf.ptr++);
}
} break;
case UVM32_SYSCALL_YIELD: {
// uint32_t yield_typ = uvm32_getval(vmst, &evt, ARG0);
// uint32_t yield_typ = uvm32_arg_getval(vmst, &evt, ARG0);
// printf("YIELD type=%d\n", yield_typ);
// uvm32_setval(vmst, &evt, RET, 123);
// uvm32_arg_setval(vmst, &evt, RET, 123);
} break;
case UVM32_SYSCALL_PRINT: {
const char *str = uvm32_getcstr(vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(vmst, &evt, ARG0);
printf("%s", str);
} break;
case UVM32_SYSCALL_PRINTLN: {
const char *str = uvm32_getcstr(vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(vmst, &evt, ARG0);
printf("%s\n", str);
} break;
case UVM32_SYSCALL_PRINTDEC:
printf("%d", uvm32_getval(vmst, &evt, ARG0));
printf("%d", uvm32_arg_getval(vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PUTC:
printf("%c", uvm32_getval(vmst, &evt, ARG0));
printf("%c", uvm32_arg_getval(vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PRINTHEX:
printf("%08x", uvm32_getval(vmst, &evt, ARG0));
printf("%08x", uvm32_arg_getval(vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_MILLIS: {
uvm32_setval(vmst, &evt, RET, SDL_GetTicks());
uvm32_arg_setval(vmst, &evt, RET, SDL_GetTicks());
} break;
case UVM32_SYSCALL_GETC: {
uvm32_setval(vmst, &evt, RET, 0xFFFFFFFF);
uvm32_arg_setval(vmst, &evt, RET, 0xFFFFFFFF);
} break;
case UVM32_SYSCALL_RENDER: {
uvm32_evt_syscall_buf_t buf = uvm32_getbuf(vmst, &evt, ARG0, ARG1);
uvm32_slice_t buf = uvm32_arg_getbuf(vmst, &evt, ARG0, ARG1);
// copy into texture
void* dst;
@ -284,9 +284,9 @@ int main(int argc, char *argv[]) {
case UVM32_SYSCALL_GETKEY:
if (last_keyvalid) {
uint32_t code = (last_keypressed ? 0x80000000 : 0) | last_keyscancode;
uvm32_setval(vmst, &evt, RET, code);
uvm32_arg_setval(vmst, &evt, RET, code);
} else {
uvm32_setval(vmst, &evt, RET, 0xFFFFFFFF);
uvm32_arg_setval(vmst, &evt, RET, 0xFFFFFFFF);
}
last_keyvalid = false;
break;

View file

@ -1,7 +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
gcc -Wall -Werror -pedantic -std=c99 -O2 -DUVM32_ERROR_STRINGS -DUVM32_MEMORY_SIZE=65536 -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host ${TOPDIR}/uvm32/uvm32.c host.c
clean:
rm -f host

View file

@ -226,8 +226,8 @@ int main(int argc, char *argv[]) {
uvm32_clearError(&vmst); // allow to continue
} else {
isrunning = false;
memdump("host-ram.dump", vmst.memory, UVM32_MEMORY_SIZE);
printf("memory dumped to host-ram.dump, pc=0x%08x\n", vmst.core.pc);
memdump("host-ram.dump", uvm32_getMemory(&vmst), UVM32_MEMORY_SIZE);
printf("memory dumped to host-ram.dump, pc=0x%08x\n", uvm32_getProgramCounter(&vmst));
if (extram_buf != NULL) {
memdump("host-extram.dump", (uint8_t *)extram_buf, extram_len);
printf("extram dumped to host-extram.dump\n");
@ -237,43 +237,43 @@ int main(int argc, char *argv[]) {
case UVM32_EVT_SYSCALL:
switch(evt.data.syscall.code) {
case UVM32_SYSCALL_PRINTBUF: {
uvm32_evt_syscall_buf_t buf = uvm32_getbuf(&vmst, &evt, ARG0, ARG1);
uvm32_slice_t buf = uvm32_arg_getbuf(&vmst, &evt, ARG0, ARG1);
while(buf.len--) {
printf("%02x", *buf.ptr++);
}
} break;
case UVM32_SYSCALL_YIELD: {
// uint32_t yield_typ = uvm32_getval(&vmst, &evt, ARG0);
// uint32_t yield_typ = uvm32_arg_getval(&vmst, &evt, ARG0);
// printf("YIELD type=%d\n", yield_typ);
// uvm32_setval(&vmst, &evt, RET, 123);
// uvm32_arg_setval(&vmst, &evt, RET, 123);
} break;
case UVM32_SYSCALL_PRINT: {
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
printf("%s", str);
} break;
case UVM32_SYSCALL_PRINTLN: {
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
printf("%s\n", str);
} break;
case UVM32_SYSCALL_PRINTDEC:
printf("%d", uvm32_getval(&vmst, &evt, ARG0));
printf("%d", uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PUTC:
printf("%c", uvm32_getval(&vmst, &evt, ARG0));
printf("%c", uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PRINTHEX:
printf("%08x", uvm32_getval(&vmst, &evt, ARG0));
printf("%08x", uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_MILLIS: {
clock_t now = clock() / (CLOCKS_PER_SEC / 1000);
uvm32_setval(&vmst, &evt, RET, now - start_time);
uvm32_arg_setval(&vmst, &evt, RET, now - start_time);
} break;
case UVM32_SYSCALL_GETC: {
uint8_t c;
if (poll_getch(&c)) {
uvm32_setval(&vmst, &evt, RET, c);
uvm32_arg_setval(&vmst, &evt, RET, c);
} else {
uvm32_setval(&vmst, &evt, RET, 0xFFFFFFFF);
uvm32_arg_setval(&vmst, &evt, RET, 0xFFFFFFFF);
}
} break;
default: