Bit of code cleanup/documentation
This commit is contained in:
parent
c55b15cdfa
commit
492f20f74a
|
|
@ -19,8 +19,8 @@ bool init_vm() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 syscall(u32 id, u32 args, u32 mem_ptr) {
|
u32 syscall(u32 id, u32 size, u32 mem_ptr) {
|
||||||
USED(args);
|
USED(size);
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case SYSCALL_DBG_PRINT: {
|
case SYSCALL_DBG_PRINT: {
|
||||||
printf("%d\n", mem[mem_ptr]);
|
printf("%d\n", mem[mem_ptr]);
|
||||||
|
|
@ -70,8 +70,6 @@ void test_fibonacci() {
|
||||||
code[cp++] = ENCODE_B(OP_PUSH, 4, 0);
|
code[cp++] = ENCODE_B(OP_PUSH, 4, 0);
|
||||||
code[cp++] = ENCODE_A(OP_CALL, 2, 3, 2);
|
code[cp++] = ENCODE_A(OP_CALL, 2, 3, 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
code[cp++] = ENCODE_B(OP_RETURN, 0, 0);
|
code[cp++] = ENCODE_B(OP_RETURN, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
20
vm/vm.c
20
vm/vm.c
|
|
@ -25,9 +25,9 @@ bool step_vm() {
|
||||||
DECODE_A(instruction)
|
DECODE_A(instruction)
|
||||||
u32 fn_ptr;
|
u32 fn_ptr;
|
||||||
|
|
||||||
u32 rd = fp + (dest * 4);
|
u32 rd = fp + (dest * 4);/* function to jump to */
|
||||||
u32 r1 = src1;
|
u32 r1 = src1; /* locals count */
|
||||||
u32 r2 = fp + src2;
|
u32 r2 = fp + (src2 * 4);/* local child return value to*/
|
||||||
|
|
||||||
fn_ptr = READ_U32(rd);
|
fn_ptr = READ_U32(rd);
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ bool step_vm() {
|
||||||
mp += 4;
|
mp += 4;
|
||||||
/* now set the frame pointer, where the locals start */
|
/* now set the frame pointer, where the locals start */
|
||||||
fp = mp;
|
fp = mp;
|
||||||
/* move mp by count many locals */
|
/* move mp forward by count many locals */
|
||||||
mp += (4 * r1);
|
mp += (4 * r1);
|
||||||
/* jump to dest_ptr */
|
/* jump to dest_ptr */
|
||||||
pc = fn_ptr;
|
pc = fn_ptr;
|
||||||
|
|
@ -60,7 +60,7 @@ bool step_vm() {
|
||||||
u32 frame_start = fp - FRAME_HEADER_SIZE;
|
u32 frame_start = fp - FRAME_HEADER_SIZE;
|
||||||
u32 parent_fp = READ_U32(frame_start);
|
u32 parent_fp = READ_U32(frame_start);
|
||||||
u32 return_address = READ_U32(frame_start + 4);
|
u32 return_address = READ_U32(frame_start + 4);
|
||||||
u32 parent_local_return_address = 4 * READ_U32(frame_start + 8);
|
u32 parent_local_return_address = READ_U32(frame_start + 8);
|
||||||
|
|
||||||
USED(replaces_value);
|
USED(replaces_value);
|
||||||
/* reset memory to parents end of memory */
|
/* reset memory to parents end of memory */
|
||||||
|
|
@ -68,8 +68,8 @@ bool step_vm() {
|
||||||
/* reset the frame pointer */
|
/* reset the frame pointer */
|
||||||
fp = parent_fp;
|
fp = parent_fp;
|
||||||
|
|
||||||
/* copy value to end of mp if it is a pointer */
|
|
||||||
if (is_ptr) {
|
if (is_ptr) {
|
||||||
|
/* copy value to end of mp if it is a pointer */
|
||||||
WRITE_U32(parent_local_return_address, mp);
|
WRITE_U32(parent_local_return_address, mp);
|
||||||
size = READ_U32(return_value);
|
size = READ_U32(return_value);
|
||||||
WRITE_U32(mp, size);
|
WRITE_U32(mp, size);
|
||||||
|
|
@ -90,10 +90,10 @@ bool step_vm() {
|
||||||
}
|
}
|
||||||
case OP_SYSCALL: {
|
case OP_SYSCALL: {
|
||||||
DECODE_A(instruction)
|
DECODE_A(instruction)
|
||||||
u32 id = dest;
|
u32 id = dest; /* syscall id */
|
||||||
u32 args = src1;
|
u32 size = src1; /* size of heap at that pointer */
|
||||||
u32 rd = fp + (src2 * 4);
|
u32 rd = fp + (src2 * 4); /* the pointer */
|
||||||
flag = syscall(id, args, rd);
|
flag = syscall(id, size, rd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case OP_LOAD_IMM: {
|
case OP_LOAD_IMM: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue