diff --git a/as/k-as.py b/as/k-as.py index 178c1c9..425caa2 100755 --- a/as/k-as.py +++ b/as/k-as.py @@ -9,6 +9,8 @@ import subprocess from array import array from tempfile import TemporaryFile +WANT_DISASM = False + if len(sys.argv) != 4: print("Usage: {} (output file) (memory entry point) (source file)" .format(sys.argv[0])) @@ -679,8 +681,10 @@ special_syms = { def gentext(): instrs.seek(0) - print(instrs.read()) - instrs.seek(0) + + if WANT_DISASM: + int(instrs.read()) + instrs.seek(0) text_start = 0x100000 data_start = text_start + ptext diff --git a/ka/dos.k b/ka/dos.k index 5717c6c..ae068b5 100644 --- a/ka/dos.k +++ b/ka/dos.k @@ -8,9 +8,6 @@ _start: mov rsp, 0x200000 xor rbp, rbp - __push 11 - __pop rbi - call main .1: diff --git a/ka/main.k b/ka/main.k index 6f49754..ba7d567 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,7 +5,8 @@ ; Main function ; main: - jmp ramdev_test + call movzx_test + ret ramdev_test: call DevGetMemOff diff --git a/vm/in/INSTRS b/vm/in/INSTRS index a96359e..99799a6 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -314,9 +314,6 @@ cmpxchg rm rim # PUSH(RIP) # JMP(RIP) # -# Throws: -# See PUSH and JMP -# call rim # @@ -324,9 +321,6 @@ call rim # # POP(RIP) # -# Throws: -# See POP -# ret # @@ -336,10 +330,6 @@ ret # RBP = RSP # RSP = RSP - $1 # -# Throws: -# See PUSH -# -enter enter i # diff --git a/vm/in/instrs.h b/vm/in/instrs.h index 7d48e97..a8f0026 100644 --- a/vm/in/instrs.h +++ b/vm/in/instrs.h @@ -73,10 +73,10 @@ bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *r1, ulong *r2) \ } \ } while (0) -#define CHK_STACK() \ - if (rsp % 8 > 0 || rbp % 8 > 0) { \ +#define CHK_STACK() /* \ + if (__builtin_expect((rsp % 8 != 0), 0) { \ _except(ctx, E_STA, "Misaligned stack REGS"); \ - } + }*/ //----------------------------------------------------------------------------// diff --git a/vm/in/stack.c b/vm/in/stack.c index 8063036..0d88eb4 100644 --- a/vm/in/stack.c +++ b/vm/in/stack.c @@ -9,68 +9,46 @@ IMPL_START_1(push) { - CHK_STACK(); - PUSH(v1); + rsp -= 8; + writemem(ctx, v1, rsp, 8); } IMPL_END; IMPL_START_1(pop) { - CHK_STACK(); - POP(v1); + v1 = readmem(ctx, rsp, 8); + rsp += 8; } IMPL_OUT; IMPL_START_1(call) { - CHK_STACK(); - PUSH(rip); + rsp -= 8; + writemem(ctx, rip, rsp, 8); + JUMP(v1); } IMPL_END; IMPL_START_0(ret) { - CHK_STACK(); - POP(rip); + rip = readmem(ctx, rsp, 8); + rsp += 8; } IMPL_END; IMPL_START_0(enter) { - CHK_STACK(); - - PUSH(rbp); - rbp = rsp; - - if (p1) { - rsp -= p1->val * 8; - } + writemem(ctx, rbp, rsp - 8, 8); + rbp = rsp - 8; + rsp -= (p1->val + 1) * 8; } IMPL_END; IMPL_START_0(leave) { - rsp = rbp; - POP(rbp); -} -IMPL_END; - -IMPL_START_0(pushf) -{ - CHK_STACK(); - PUSH(flg); -} -IMPL_END; - -IMPL_START_0(popf) -{ - CHK_STACK(); - - // XXX - CHK_SUPERV(); - - POP(flg); + rsp = rbp + 8; + rbp = readmem(ctx, rbp, 8); } IMPL_END; diff --git a/vm/pc/regs.c b/vm/pc/regs.c index 45aea87..22082ff 100644 --- a/vm/pc/regs.c +++ b/vm/pc/regs.c @@ -99,7 +99,7 @@ void dumpregs(ctx_t *ctx) assert(inv == 0); - DUMPREGS(RAX, RSI); + DUMPREGS(RAX, RDI); DUMPREGS(AX0, AX3); DUMPREGS(LX0, LX3);