diff --git a/arch/linux/tui/main.c b/arch/linux/tui/main.c index f0d85fb..bbf95b3 100644 --- a/arch/linux/tui/main.c +++ b/arch/linux/tui/main.c @@ -23,7 +23,8 @@ u32 syscall(u32 id, u32 size, u32 mem_ptr) { USED(size); switch(id) { case SYSCALL_DBG_PRINT: { - printf("%d\n", mem[mem_ptr]); + u32 val = READ_U32(mem_ptr); + printf("%d\n", val); return 0; } } @@ -64,6 +65,7 @@ void test_fibonacci() { code[cp++] = ENCODE_A(OP_SYSCALL, SYSCALL_DBG_PRINT, 1, 2); code[cp++] = ENCODE_A(OP_HALT, 0, 0, 0); /* function fib (int n) int */ + //code[cp++] = ENCODE_A(OP_SYSCALL, SYSCALL_DBG_PRINT, 1, 0); code[cp++] = ENCODE_B(OP_LOAD_IMM, 8, fib); code[cp++] = ENCODE_B(OP_LOAD_IMM, 1, 2); code[cp++] = ENCODE_B(OP_LOAD_IMM, 2, base_case); diff --git a/vm/vm.c b/vm/vm.c index ea51468..79db954 100644 --- a/vm/vm.c +++ b/vm/vm.c @@ -30,6 +30,7 @@ bool step_vm() { u32 r2 = fp + (src2 * 4);/* local child return value to*/ fn_ptr = READ_U32(rd); + sp = 0; /* push parents frame value to reset the heap to */ WRITE_U32(mp, fp); @@ -41,7 +42,7 @@ bool step_vm() { WRITE_U32(mp, r2); mp += 4; /* now set the frame pointer, where the locals start */ - fp = mp; + fp = mp; /* move mp forward by count many locals */ mp += (4 * r1); /* jump to dest_ptr */ @@ -96,6 +97,22 @@ bool step_vm() { flag = syscall(id, size, rd); return true; } + case OP_PUSH: { + DECODE_B(instruction) + u32 rd = fp + (dest * 4); + u32 val = READ_U32(rd); + USED(imm); + WRITE_U32((mp + ((4 * sp) + FRAME_HEADER_SIZE)), val); + sp++; + return true; + } + case OP_POP: { + DECODE_C(instruction) + USED(imm); + mp -= 4; + sp--; + return true; + } case OP_LOAD_IMM: { DECODE_B(instruction) u32 rd = fp + (dest * 4); @@ -335,21 +352,6 @@ bool step_vm() { WRITE_U32(rd, value); return true; } - case OP_PUSH: { - DECODE_B(instruction) - u32 rd = fp + (dest * 4); - u32 val = READ_U32(rd); - USED(imm); - WRITE_U32((mp + (4 * (sp + 3))), val); - sp++; - return true; - } - case OP_POP: { - DECODE_C(instruction) - USED(imm); - mp -= 4; - return true; - } case OP_ADD_INT: { MATH_OP(i32, +); }