Update with fib sketch

This commit is contained in:
Toby Jaffey 2025-12-09 00:13:38 +00:00
parent c37286cf01
commit 136f7a30bd
2 changed files with 53 additions and 9 deletions

View file

@ -14,20 +14,59 @@
// 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
uint8_t rom[] = { // fib.bin
0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0x40, 0x17, 0xb7, 0x08, 0x00, 0x01,
0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x08, 0x05, 0x00,
0x13, 0x85, 0x05, 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, 0xd2, 0x8a, 0x02,
0x33, 0x8a, 0x34, 0x01, 0x93, 0x05, 0x0a, 0x00, 0x13, 0x05, 0x40, 0x00,
0xef, 0xf0, 0x9f, 0xf7, 0x93, 0x89, 0x04, 0x00, 0x13, 0x04, 0x14, 0x00,
0x93, 0x04, 0x0a, 0x00, 0x6f, 0xf0, 0x5f, 0xfb, 0x93, 0x85, 0x09, 0x00,
0x63, 0x04, 0x64, 0x01, 0x93, 0x85, 0x04, 0x00, 0x13, 0x05, 0x40, 0x00,
0xef, 0xf0, 0x5f, 0xf5, 0x13, 0x8a, 0x04, 0x00, 0x6f, 0xf0, 0xdf, 0xfd,
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, 0x93, 0x87, 0x05, 0x00, 0x13, 0x04, 0x06, 0x00,
0x93, 0x09, 0x20, 0x00, 0x63, 0xd2, 0x99, 0x02, 0x33, 0x89, 0x87, 0x00,
0x93, 0x05, 0x09, 0x00, 0x13, 0x05, 0x40, 0x00, 0xef, 0xf0, 0x1f, 0xf1,
0x93, 0x07, 0x04, 0x00, 0x93, 0x84, 0xf4, 0xff, 0x13, 0x04, 0x09, 0x00,
0x6f, 0xf0, 0x1f, 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, 0x93, 0x05, 0x00, 0x00, 0x13, 0x04, 0x05, 0x00,
0x13, 0x05, 0x40, 0x00, 0x23, 0x26, 0x11, 0x00, 0xef, 0xf0, 0x9f, 0xec,
0x93, 0x05, 0x10, 0x00, 0x13, 0x05, 0x40, 0x00, 0xef, 0xf0, 0xdf, 0xeb,
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, 0xf5, 0xb7, 0x05, 0x00, 0x80, 0x13, 0x01, 0x01, 0xff,
0x93, 0x85, 0x05, 0x1c, 0x13, 0x05, 0x30, 0x00, 0x23, 0x26, 0x11, 0x00,
0xef, 0xf0, 0x9f, 0xe8, 0x13, 0x05, 0x80, 0x02, 0xef, 0xf0, 0x1f, 0xe9,
0xb7, 0x05, 0x00, 0x80, 0x13, 0x05, 0x30, 0x00, 0x93, 0x85, 0xc5, 0x1c,
0xef, 0xf0, 0x1f, 0xe7, 0x83, 0x20, 0xc1, 0x00, 0x13, 0x05, 0x80, 0x02,
0x13, 0x01, 0x01, 0x01, 0x6f, 0xf0, 0x1f, 0xf8, 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
};
// Create an identifier for our host handler
// syscalls exposed to vm environement
typedef enum {
F_PRINTDEC,
F_PRINTLN,
} f_code_t;
// Map VM syscall UVM32_SYSCALL_PRINTDEC to F_PRINTDEC, tell VM to expect write of a U32
// Map exposed syscalls to syscalls
const uvm32_mapping_t env[] = {
{ .syscall = UVM32_SYSCALL_PRINTLN, .typ = UVM32_SYSCALL_TYP_BUF_TERMINATED_WR, .code = F_PRINTLN },
{ .syscall = UVM32_SYSCALL_PRINTDEC, .typ = UVM32_SYSCALL_TYP_U32_WR, .code = F_PRINTDEC },
};
@ -58,11 +97,16 @@ int main(int argc, char *argv[]) {
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("[VM %d]: %d\n", scheduler_index, evt.data.syscall.val.u32);
printf("[VM %d] %d\n", scheduler_index, evt.data.syscall.val.u32);
break;
case F_PRINTLN:
printf("[VM %d] %.*s\n", scheduler_index, 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;
}