mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
vm
This commit is contained in:
parent
2a610f2d7a
commit
5b315ad46a
@ -11,7 +11,7 @@ FILE_LOADP := 0x141000 ; 4KB above stack
|
|||||||
start:
|
start:
|
||||||
mov rsp, 0x140000
|
mov rsp, 0x140000
|
||||||
mov rbp, zero
|
mov rbp, zero
|
||||||
|
|
||||||
cls
|
cls
|
||||||
cld
|
cld
|
||||||
call main
|
call main
|
||||||
|
@ -10,8 +10,14 @@
|
|||||||
; <0 if the first character that does not match has a lower value in str1 than in str2
|
; <0 if the first character that does not match has a lower value in str1 than in str2
|
||||||
;
|
;
|
||||||
strcmp:
|
strcmp:
|
||||||
mov ax2, STRLEN_MAX
|
mov rcx, STRLEN_MAX
|
||||||
jmp strncmp
|
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)
|
; int strncmp(const char *str1, const char *str2, int maxn)
|
||||||
|
@ -114,7 +114,7 @@ trap0_handler:
|
|||||||
jmp .fini
|
jmp .fini
|
||||||
|
|
||||||
.handle_ReadFile:
|
.handle_ReadFile:
|
||||||
add ax1, ax0, nx0
|
add ax1, ax1, nx0
|
||||||
call DISK.ReadFile
|
call DISK.ReadFile
|
||||||
jmp .fini
|
jmp .fini
|
||||||
|
|
||||||
|
@ -130,6 +130,12 @@ main:
|
|||||||
call strcmp
|
call strcmp
|
||||||
b.z rax, 0, .handle_DIR
|
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"
|
.builtin_echo = "echo"
|
||||||
mov ax0, argv0
|
mov ax0, argv0
|
||||||
mov ax1, .builtin_echo
|
mov ax1, .builtin_echo
|
||||||
@ -198,6 +204,10 @@ main:
|
|||||||
call builtins.dir
|
call builtins.dir
|
||||||
jmp .print_prompt
|
jmp .print_prompt
|
||||||
|
|
||||||
|
.handle_DUMP:
|
||||||
|
dump
|
||||||
|
jmp .print_prompt
|
||||||
|
|
||||||
.handle_ECHO:
|
.handle_ECHO:
|
||||||
mov rdx, q[argv1pos]
|
mov rdx, q[argv1pos]
|
||||||
b.z rdx, 0, .echo.end
|
b.z rdx, 0, .echo.end
|
||||||
@ -275,6 +285,8 @@ main:
|
|||||||
prns.rep.nz rdx
|
prns.rep.nz rdx
|
||||||
mov rdx, .helpmsg.dir
|
mov rdx, .helpmsg.dir
|
||||||
prns.rep.nz rdx
|
prns.rep.nz rdx
|
||||||
|
mov rdx, .helpmsg.dump
|
||||||
|
prns.rep.nz rdx
|
||||||
mov rdx, .helpmsg.echo
|
mov rdx, .helpmsg.echo
|
||||||
prns.rep.nz rdx
|
prns.rep.nz rdx
|
||||||
mov rdx, .helpmsg.exit
|
mov rdx, .helpmsg.exit
|
||||||
@ -294,6 +306,7 @@ main:
|
|||||||
.helpmsg.cls = " CLS Clear screen\n"
|
.helpmsg.cls = " CLS Clear screen\n"
|
||||||
.helpmsg.date = " DATE Display current date\n"
|
.helpmsg.date = " DATE Display current date\n"
|
||||||
.helpmsg.dir = " DIR Print contents of current directory\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.echo = " ECHO Write arguments to standard output\n"
|
||||||
.helpmsg.exit = " EXIT Initiate machine shutdown\n"
|
.helpmsg.exit = " EXIT Initiate machine shutdown\n"
|
||||||
.helpmsg.help = " HELP Display these messages\n"
|
.helpmsg.help = " HELP Display these messages\n"
|
||||||
|
13
vm/in/ALU
13
vm/in/ALU
@ -23,7 +23,6 @@ not r r
|
|||||||
#
|
#
|
||||||
or r r ri
|
or r r ri
|
||||||
# $dest = $src1 OR NOT($src2)
|
# $dest = $src1 OR NOT($src2)
|
||||||
orn r ri
|
|
||||||
orn r r ri
|
orn r r ri
|
||||||
# $dest = NOT($src1 OR $src2)
|
# $dest = NOT($src1 OR $src2)
|
||||||
nor r r ri
|
nor r r ri
|
||||||
@ -149,18 +148,6 @@ add r r ri
|
|||||||
addf r r ri
|
addf r r ri
|
||||||
addo 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
|
# Arithmetical SUB operation
|
||||||
#
|
#
|
||||||
|
10
vm/in/MISC
10
vm/in/MISC
@ -14,15 +14,11 @@
|
|||||||
break
|
break
|
||||||
|
|
||||||
#
|
#
|
||||||
# Enable/disable instruction dumping (DUMP)
|
# Toggles instruction dumping (DUMP)
|
||||||
#
|
#
|
||||||
# IF $1 == 0 THEN
|
# (toggles instruction dumping)
|
||||||
# (disable instruction dumping)
|
|
||||||
# ELSE
|
|
||||||
# (enable instruction dumping)
|
|
||||||
# FI
|
|
||||||
#
|
#
|
||||||
dump ri
|
dump
|
||||||
|
|
||||||
#---------------------------------------------------------------------------#
|
#---------------------------------------------------------------------------#
|
||||||
# Misc. instructions #
|
# Misc. instructions #
|
||||||
|
@ -39,7 +39,6 @@ IMPL_START_1(dec) { v1--; } IMPL_OUT;
|
|||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
IMPL_START_3(add) { v1 = v2 + v3; } 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(addf) { COMPARE(v2, ~v3+1); v1 = v2 + v3; } IMPL_OUT;
|
||||||
IMPL_START_3(addo) { COMPARE(v2, ~v3+1); v1 = v2 + v3; INTO(); } IMPL_OUT;
|
IMPL_START_3(addo) { COMPARE(v2, ~v3+1); v1 = v2 + v3; INTO(); } IMPL_OUT;
|
||||||
|
|
||||||
|
11
vm/in/misc.c
11
vm/in/misc.c
@ -30,20 +30,17 @@ IMPL_START_0(break)
|
|||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
|
||||||
IMPL_START_1(dump)
|
IMPL_START_0(dump)
|
||||||
{
|
{
|
||||||
(void)v1;
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (ctx->dumpsw && !v1)
|
if (ctx->dumpsw)
|
||||||
trace("0x%lX:\t...\n", rpc);
|
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);
|
dump_instr(ctx, ctx->cur_in, p1, p2, p3, 0, 0);
|
||||||
|
|
||||||
ctx->dumpsw = !!v1;
|
ctx->dumpsw = !ctx->dumpsw;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user