mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-06 06:53:39 +00:00
Move all host examples under host/
This commit is contained in:
parent
1213c5673f
commit
7353810199
16 changed files with 104 additions and 143 deletions
48
hosts/host-mini/host-mini.c
Normal file
48
hosts/host-mini/host-mini.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "uvm32.h"
|
||||
#include "../common/uvm32_common_custom.h"
|
||||
#include "mandel.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
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:
|
||||
printf("%c", uvm32_getval(&vmst, &evt, ARG0));
|
||||
break;
|
||||
case UVM32_SYSCALL_PRINTLN: {
|
||||
const char *str = uvm32_getcstr(&vmst, &evt, ARG0);
|
||||
printf("%s\n", str);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue