#include "../../../vm/vm.h" #include #include #define CODE_SIZE 8192 #define MEMORY_SIZE 65536 u8 lmem[MEMORY_SIZE] = {0}; u32 lcode[CODE_SIZE] = {0}; bool init_vm() { mem = lmem; memset(mem, 0, MEMORY_SIZE*sizeof(u8)); code = lcode; mp = 0; cp = 0; pc = 0; interrupt = 0; return true; } u32 syscall(u32 id, u32 args, u32 mem_ptr) { USED(args); switch(id) { case SYSCALL_DBG_PRINT: { printf("%d\n", mem[mem_ptr]); return 0; } } return 1; // generic error } i32 main() { init_vm(); // hardcoded add 2 numbers and print debug int a = mp; mp+=4; int b = mp; mp+=4; int c = mp; mp+=4; code[cp++] = ENCODE_B(OP_LOAD_IMM, a, 1); code[cp++] = ENCODE_B(OP_LOAD_IMM, b, 2); code[cp++] = ENCODE_A(OP_ADD_INT, c, b, a); code[cp++] = ENCODE_A(OP_SYSCALL, SYSCALL_DBG_PRINT, 1, c); code[cp++] = ENCODE_A(OP_HALT, 0, 0, 0); while(step_vm()) { // do stuff } return 0; }