From 3db1d2433bd212a1a09eae936752c3374a783ac0 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Mon, 8 Dec 2025 23:39:13 +0000 Subject: [PATCH] Update to use mandel --- host-mini/Makefile | 2 +- host-mini/host-mini.c | 44 +++++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/host-mini/Makefile b/host-mini/Makefile index 778761a..26b105f 100644 --- a/host-mini/Makefile +++ b/host-mini/Makefile @@ -1,5 +1,5 @@ all: - gcc -Wall -DUVM32_MEMORY_SIZE=512 -I../uvm32 -I../common -o host-mini ../uvm32/uvm32.c host-mini.c + 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-mini/host-mini.c b/host-mini/host-mini.c index e113c02..025b1ed 100644 --- a/host-mini/host-mini.c +++ b/host-mini/host-mini.c @@ -7,20 +7,39 @@ // Precompiled binary program to print integers // This code expects to print via syscall 0x13C (UVM32_SYSCALL_PRINTD in common/uvm32_common_custom.h) uint8_t rom[] = { - 0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0x00, 0x01, 0x93, 0x08, 0x80, 0x13, - 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x05, 0x00, 0x00, - 0x93, 0x07, 0xa0, 0x00, 0x93, 0x08, 0xc0, 0x13, 0x73, 0x00, 0x00, 0x00, - 0x13, 0x05, 0x15, 0x00, 0xe3, 0x1a, 0xf5, 0xfe, 0x67, 0x80, 0x00, 0x00 + 0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x00, 0xb7, 0x08, 0x00, 0x01, + 0x73, 0x00, 0x00, 0x00, 0x37, 0xf5, 0xff, 0xff, 0xb7, 0x15, 0x00, 0x00, + 0x37, 0xe6, 0xff, 0xff, 0x13, 0x07, 0xf0, 0x01, 0xb7, 0x47, 0x00, 0x00, + 0xb7, 0x06, 0x00, 0x01, 0x13, 0x08, 0xd5, 0xcc, 0x93, 0x82, 0x35, 0x33, + 0x13, 0x03, 0x76, 0xe6, 0x93, 0x83, 0x35, 0xb3, 0x13, 0x86, 0x16, 0x00, + 0x63, 0xc8, 0x02, 0x09, 0x13, 0x0e, 0x03, 0x00, 0x63, 0xca, 0x63, 0x06, + 0x93, 0x0e, 0x00, 0x00, 0x93, 0x05, 0x00, 0x00, 0x13, 0x0f, 0x00, 0x00, + 0x93, 0x0f, 0x00, 0x00, 0x93, 0x06, 0x00, 0x02, 0x13, 0x85, 0x06, 0xfe, + 0x63, 0x62, 0xa7, 0x04, 0x33, 0x85, 0xd5, 0x01, 0x63, 0xee, 0xa7, 0x02, + 0x13, 0x05, 0x00, 0x00, 0x93, 0x08, 0x06, 0x00, 0x33, 0x8f, 0xef, 0x03, + 0xb3, 0x8f, 0xd5, 0x41, 0x73, 0x00, 0x00, 0x00, 0x13, 0x5f, 0xbf, 0x40, + 0xb3, 0x8f, 0xcf, 0x01, 0x33, 0x0f, 0x0f, 0x01, 0xb3, 0x85, 0xff, 0x03, + 0x93, 0xd5, 0xc5, 0x00, 0x33, 0x05, 0xef, 0x03, 0x93, 0x5e, 0xc5, 0x00, + 0x93, 0x86, 0x16, 0x00, 0x6f, 0xf0, 0xdf, 0xfb, 0x13, 0x85, 0x06, 0x00, + 0x93, 0x08, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x13, 0x0e, 0x1e, 0x09, + 0xe3, 0xda, 0xc3, 0xf9, 0x13, 0x05, 0xa0, 0x00, 0x93, 0x08, 0x00, 0x00, + 0x73, 0x00, 0x00, 0x00, 0x13, 0x08, 0x98, 0x19, 0xe3, 0xdc, 0x02, 0xf7, + 0x37, 0x05, 0x00, 0x80, 0x13, 0x05, 0x05, 0x0e, 0x93, 0x08, 0x30, 0x00, + 0x73, 0x00, 0x00, 0x00, 0x67, 0x80, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, + 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00 }; // Create an identifier for our host handler +// syscalls exposed to vm environement typedef enum { - F_PRINTDEC, + F_PUTC, + F_PRINTLN, } f_code_t; -// Map VM syscall UVM32_SYSCALL_PRINTD (0x13C) to F_PRINTD, tell VM to expect write of a U32 +// Map exposed syscalls to syscalls const uvm32_mapping_t env[] = { - { .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC }, + { .syscall = UVM32_SYSCALL_PRINTLN, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINTLN }, + { .syscall = UVM32_SYSCALL_PUTC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PUTC }, }; int main(int argc, char *argv[]) { @@ -40,12 +59,17 @@ int main(int argc, char *argv[]) { break; case UVM32_EVT_SYSCALL: // vm has paused to handle UVM32_SYSCALL switch((f_code_t)evt.data.syscall.code) { - case F_PRINTDEC: - // Type of F_PRINTDEC is UVM32_SYSCALL_TYP_U32_WR, so expect value in evt.data.syscall.val.u32 - printf("%d\n", evt.data.syscall.val.u32); + case F_PUTC: + printf("%c", evt.data.syscall.val.u32); + break; + case F_PRINTLN: + printf("%.*s\n", evt.data.syscall.val.buf.len, evt.data.syscall.val.buf.ptr); 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; }