This commit is contained in:
julianb0 2019-07-17 22:40:13 +02:00
parent 2a610f2d7a
commit 5b315ad46a
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
8 changed files with 30 additions and 32 deletions

View File

@ -11,7 +11,7 @@ FILE_LOADP := 0x141000 ; 4KB above stack
start:
mov rsp, 0x140000
mov rbp, zero
cls
cld
call main

View File

@ -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)

View File

@ -114,7 +114,7 @@ trap0_handler:
jmp .fini
.handle_ReadFile:
add ax1, ax0, nx0
add ax1, ax1, nx0
call DISK.ReadFile
jmp .fini

View File

@ -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"

View File

@ -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
#

View File

@ -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 #

View File

@ -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;

View File

@ -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;