diff --git a/ka/main.k b/ka/main.k index b44b2a7..920fa06 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,8 +5,9 @@ ; Main function ; main: - enter + ret +itoa_test: mov ax0, .buf mov ax1, -9223372036854775807 mov ax2, 10 @@ -28,7 +29,6 @@ main: mov rdi, 8 lea rbi, b[rdi + rsi * 2 + 1] - leave ret .buf = [32] diff --git a/vm/in/INSTRS b/vm/in/INSTRS index bc3a0f6..34a9f5c 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -359,17 +359,19 @@ ret # # PUSH(RBP) # RBP = RSP +# RSP = RSP - $1 # # Throws: # See PUSH # enter +enter i # # Leave stack frame (LEAVE) # -# RBP = *RSP -# RSP = RSP + 8 +# RSP = RBP +# POP(RBP) # leave @@ -377,7 +379,6 @@ leave # Supervisor only instructions # #---------------------------------------------------------------------------# - pushf popf @@ -455,7 +456,7 @@ cla cln # -# Send a character to standard output +# Send a character to standard output (PRN) # # Throws: # #PRN if DV text mode enabled diff --git a/vm/in/stack.c b/vm/in/stack.c index 007515c..18201e3 100644 --- a/vm/in/stack.c +++ b/vm/in/stack.c @@ -41,8 +41,14 @@ IMPL_START_0(enter) // We don't CHK_STACK(<) here because ENTER // (should) always be preceded by a CALL, // which already checks the stack + PUSH(rbp); rbp = rsp; + + if (p1) { + GETV(v1, p1); + rsp -= v1 * 8; + } } IMPL_END; @@ -50,6 +56,7 @@ IMPL_START_0(leave) { // Do NOT check stack here // (it would always fail) + rsp = rbp; POP(rbp); } IMPL_END; diff --git a/vm/pc/decd.c b/vm/pc/decd.c index 4996072..c93d024 100644 --- a/vm/pc/decd.c +++ b/vm/pc/decd.c @@ -289,11 +289,14 @@ static bool eval_cond(ctx_t *ctx, uint cond) // // Executes an instruction // -void exec_instr( - ctx_t *ctx, instr_t *in, - acc_t *p1, acc_t *p2, - bool lock, bool rep, - uint cond, ulong pc) +void exec_instr(ctx_t *ctx, + instr_t *in, + acc_t *p1, + acc_t *p2, + bool lock, + bool rep, + uint cond, + ulong pc) { bool out; ulong r1 = 0, r2 = 0; diff --git a/vm/pc/dump.c b/vm/pc/dump.c index c6b3407..ddd75dc 100644 --- a/vm/pc/dump.c +++ b/vm/pc/dump.c @@ -64,11 +64,14 @@ static void dump_acc(ctx_t *ctx, acc_t *p) } } -void dump_instr( - ctx_t *ctx, instr_t *in, - acc_t *p1, acc_t *p2, - bool lock, bool rep, - uint cond, ulong pc) +void dump_instr(ctx_t *ctx, + instr_t *in, + acc_t *p1, + acc_t *p2, + bool lock, + bool rep, + uint cond, + ulong pc) { log("0x%lX: ", pc);