uvm32/apps/self/self.c
Toby Jaffey 4e61e3bd4a
Some checks are pending
CI / test (ubuntu-latest) (push) Waiting to run
Make self and mandel examples a bit smaller
2025-12-15 01:12:47 +00:00

47 lines
1.4 KiB
C

#include "uvm32_target.h"
#include "uvm32.h"
#include "../common/uvm32_common_custom.h"
#include "mandel.h"
void main(void) {
uvm32_state_t vmst;
uvm32_evt_t evt;
bool isrunning = true;
uvm32_init(&vmst);
uvm32_load(&vmst, mandel, mandel_len);
while(isrunning) {
uvm32_run(&vmst, &evt, 100); // num instructions before vm considered hung
switch(evt.typ) {
case UVM32_EVT_END:
isrunning = false;
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_PUTC:
putc(uvm32_arg_getval(&vmst, &evt, ARG0));
break;
case UVM32_SYSCALL_PRINTLN: {
//const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
//println(str);
} break;
default:
// println("Unhandled syscall");
break;
}
break;
case UVM32_EVT_ERR:
// println("error: ");
// printdec(evt.data.err.errcode);
// println("");
break;
default:
break;
}
}
}