diff --git a/ka/command.k b/ka/command.k index 93d58e7..d2bce5f 100644 --- a/ka/command.k +++ b/ka/command.k @@ -11,7 +11,7 @@ FILE_LOADP := 0x141000 ; 4KB above stack start: mov rsp, 0x140000 mov rbp, zero - + cls cld call main diff --git a/ka/crt/str/strcmp.k b/ka/crt/str/strcmp.k index cb847a1..e2dfb01 100644 --- a/ka/crt/str/strcmp.k +++ b/ka/crt/str/strcmp.k @@ -10,8 +10,14 @@ ; <0 if the first character that does not match has a lower value in str1 than in str2 ; strcmp: - mov ax2, STRLEN_MAX - jmp strncmp + mov rcx, STRLEN_MAX + cmpzsb.rep.z ax0, ax1 + + mov rax, b[ax0-1] + mov rcx, b[ax1-1] + sub rax, rax, rcx + + ret ; ; int strncmp(const char *str1, const char *str2, int maxn) diff --git a/ka/sys/intr/trap0.k b/ka/sys/intr/trap0.k index c4f1d34..f87ea9b 100644 --- a/ka/sys/intr/trap0.k +++ b/ka/sys/intr/trap0.k @@ -114,7 +114,7 @@ trap0_handler: jmp .fini .handle_ReadFile: - add ax1, ax0, nx0 + add ax1, ax1, nx0 call DISK.ReadFile jmp .fini diff --git a/ka/usr/cmd/main.k b/ka/usr/cmd/main.k index ea27139..4846ff9 100644 --- a/ka/usr/cmd/main.k +++ b/ka/usr/cmd/main.k @@ -130,6 +130,12 @@ main: call strcmp b.z rax, 0, .handle_DIR +.builtin_dump = "dump" + mov ax0, argv0 + mov ax1, .builtin_dump + call strcmp + b.z rax, 0, .handle_DUMP + .builtin_echo = "echo" mov ax0, argv0 mov ax1, .builtin_echo @@ -198,6 +204,10 @@ main: call builtins.dir jmp .print_prompt +.handle_DUMP: + dump + jmp .print_prompt + .handle_ECHO: mov rdx, q[argv1pos] b.z rdx, 0, .echo.end @@ -275,6 +285,8 @@ main: prns.rep.nz rdx mov rdx, .helpmsg.dir prns.rep.nz rdx + mov rdx, .helpmsg.dump + prns.rep.nz rdx mov rdx, .helpmsg.echo prns.rep.nz rdx mov rdx, .helpmsg.exit @@ -294,6 +306,7 @@ main: .helpmsg.cls = " CLS Clear screen\n" .helpmsg.date = " DATE Display current date\n" .helpmsg.dir = " DIR Print contents of current directory\n" +.helpmsg.dump = " DUMP Toggles debug instruction dumping\n" .helpmsg.echo = " ECHO Write arguments to standard output\n" .helpmsg.exit = " EXIT Initiate machine shutdown\n" .helpmsg.help = " HELP Display these messages\n" diff --git a/vm/in/ALU b/vm/in/ALU index ffc487f..b3d07e9 100644 --- a/vm/in/ALU +++ b/vm/in/ALU @@ -23,7 +23,6 @@ not r r # or r r ri # $dest = $src1 OR NOT($src2) -orn r ri orn r r ri # $dest = NOT($src1 OR $src2) nor r r ri @@ -149,18 +148,6 @@ add r r ri addf r r ri addo r r ri -# -# Atomic exchange and add (XADD) -# -# $tmp = $1 -# $1 = $1 + $2 -# $2 = $1 -# -# Preserves all flags -# -xadd r rm -xadd m r - # # Arithmetical SUB operation # diff --git a/vm/in/MISC b/vm/in/MISC index a056dbc..56d2646 100644 --- a/vm/in/MISC +++ b/vm/in/MISC @@ -14,15 +14,11 @@ break # -# Enable/disable instruction dumping (DUMP) +# Toggles instruction dumping (DUMP) # -# IF $1 == 0 THEN -# (disable instruction dumping) -# ELSE -# (enable instruction dumping) -# FI +# (toggles instruction dumping) # -dump ri +dump #---------------------------------------------------------------------------# # Misc. instructions # diff --git a/vm/in/alu.c b/vm/in/alu.c index 6582c06..e1d2378 100644 --- a/vm/in/alu.c +++ b/vm/in/alu.c @@ -39,7 +39,6 @@ IMPL_START_1(dec) { v1--; } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_3(add) { v1 = v2 + v3; } IMPL_OUT; -IMPL_START_2(xadd) { ulong tmp = v1; v1 += v2; v2 = tmp; } IMPL_OUT_2; IMPL_START_3(addf) { COMPARE(v2, ~v3+1); v1 = v2 + v3; } IMPL_OUT; IMPL_START_3(addo) { COMPARE(v2, ~v3+1); v1 = v2 + v3; INTO(); } IMPL_OUT; diff --git a/vm/in/misc.c b/vm/in/misc.c index 9065a68..905fd6c 100644 --- a/vm/in/misc.c +++ b/vm/in/misc.c @@ -30,20 +30,17 @@ IMPL_START_0(break) } IMPL_END; -IMPL_START_1(dump) +IMPL_START_0(dump) { - (void)v1; - #ifndef NDEBUG - if (ctx->dumpsw && !v1) + if (ctx->dumpsw) trace("0x%lX:\t...\n", rpc); - else if (!ctx->dumpsw && v1) + else if (!ctx->dumpsw) dump_instr(ctx, ctx->cur_in, p1, p2, p3, 0, 0); - ctx->dumpsw = !!v1; + ctx->dumpsw = !ctx->dumpsw; #endif - } IMPL_END;