mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
command.com
This commit is contained in:
parent
a352bd7465
commit
c60dfb47fc
@ -44,6 +44,5 @@ include "sys/drv/diskdev.k"
|
|||||||
include "sys/intr/common.k"
|
include "sys/intr/common.k"
|
||||||
include "sys/intr/trap0.k"
|
include "sys/intr/trap0.k"
|
||||||
|
|
||||||
include "sys/tests.k"
|
|
||||||
include "sys/main.k"
|
include "sys/main.k"
|
||||||
|
|
||||||
|
@ -6,17 +6,19 @@ TrapHandlers.prolog:
|
|||||||
mov q[rbp-16], r12
|
mov q[rbp-16], r12
|
||||||
mov q[rbp-24], r13
|
mov q[rbp-24], r13
|
||||||
sub rsp, rbp, 24
|
sub rsp, rbp, 24
|
||||||
xor rdx, rdx
|
|
||||||
|
mov rdx, cr2
|
||||||
|
|
||||||
; nx0 = caller's cr2
|
; nx0 = caller's cr2
|
||||||
push cr2
|
|
||||||
mov ax0, r12
|
mov ax0, r12
|
||||||
mov ax1, $cr2
|
mov ax1, $cr2
|
||||||
iocall CPUDEV, RFS.LoadReg.slot
|
iocall CPUDEV, RFS.LoadReg.slot
|
||||||
mov nx0, cr2
|
|
||||||
pop cr2
|
|
||||||
|
|
||||||
jmp rcx ; go back
|
mov nx0, cr2
|
||||||
|
mov cr2, rdx
|
||||||
|
xor rdx, rdx
|
||||||
|
|
||||||
|
jmp rcx
|
||||||
|
|
||||||
TrapHandlers.epilog:
|
TrapHandlers.epilog:
|
||||||
mov r13, q[rbp-24]
|
mov r13, q[rbp-24]
|
||||||
@ -36,5 +38,6 @@ TrapHandlers.epilog:
|
|||||||
|
|
||||||
mov ax0, r11
|
mov ax0, r11
|
||||||
call IDT.DoneHandling
|
call IDT.DoneHandling
|
||||||
|
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ trap0_handler:
|
|||||||
.fini:
|
.fini:
|
||||||
jmp TrapHandlers.epilog
|
jmp TrapHandlers.epilog
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;------------------------------------------------;
|
||||||
;;; Syscall implementations ;;;
|
; Syscall implementations ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;------------------------------------------------;
|
||||||
|
|
||||||
;
|
;
|
||||||
; Pass control to COMMAND.COM in frame 0
|
; Pass control to COMMAND.COM in frame 0
|
||||||
|
@ -1,8 +1,90 @@
|
|||||||
; The OS/K Team licenses this file to you under the MIT license.
|
; The OS/K Team licenses this file to you under the MIT license.
|
||||||
; See the LICENSE file in the project root for more information.
|
; See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
argbuf.size := 256
|
||||||
|
argbuf = [argbuf.size]
|
||||||
|
argv0 = [argbuf.size]
|
||||||
|
argv1pos = 0
|
||||||
|
|
||||||
|
stdin_echoing = 1
|
||||||
|
|
||||||
|
ps1 = "C:\\> "
|
||||||
|
|
||||||
main:
|
main:
|
||||||
|
|
||||||
|
.print_prompt:
|
||||||
|
mov rcx, STRLEN_MAX
|
||||||
|
mov rdx, ps1
|
||||||
|
prns.rep.nz rdx
|
||||||
|
|
||||||
|
; empty argbuf
|
||||||
|
mov rcx, argbuf.size
|
||||||
|
mov rdx, argbuf
|
||||||
|
stosb.rep rdx, 0
|
||||||
|
|
||||||
|
; iterator through argbuf
|
||||||
|
xor rcx, rcx
|
||||||
|
|
||||||
|
.input_loop:
|
||||||
|
pause
|
||||||
|
pause
|
||||||
|
|
||||||
|
; Fill .buf with user input
|
||||||
|
scan rax
|
||||||
|
b.z rax, 0, .input_loop
|
||||||
|
|
||||||
|
cmp b[stdin_echoing], 1
|
||||||
|
prn.z rax
|
||||||
|
b.z rax, 10, .extract_argv0
|
||||||
|
|
||||||
|
; when max line length is reached,
|
||||||
|
; force a newline
|
||||||
|
b.z rcx, argbuf.size, .extract_argv0
|
||||||
|
|
||||||
|
; add character to buffer and increase iterator (rcx)
|
||||||
|
add rdx, rcx, argbuf
|
||||||
|
mov b[rdx], rax
|
||||||
|
inc rcx
|
||||||
|
|
||||||
|
; another one
|
||||||
|
jmp .input_loop
|
||||||
|
|
||||||
|
.extract_argv0:
|
||||||
|
|
||||||
|
; find first whitespace or null-terminator
|
||||||
|
mov rcx, argbuf.size
|
||||||
|
mov rdx, argbuf
|
||||||
|
scasb.rep.nz rdx, ' '
|
||||||
|
|
||||||
|
; argv1 exists? if so, save its position
|
||||||
|
; (to do)
|
||||||
|
|
||||||
|
; extract argv0
|
||||||
|
sub rcx, argbuf.size, rcx
|
||||||
|
mov rdx, argbuf
|
||||||
|
mov rax, argv0
|
||||||
|
movsb.rep rax, rdx
|
||||||
|
|
||||||
|
; null-terminate argv0
|
||||||
|
mov b[rax], 0
|
||||||
|
|
||||||
|
.detect_builtin:
|
||||||
|
|
||||||
|
.builtin_dir = "dir"
|
||||||
|
mov ax0, argv0
|
||||||
|
mov ax1, .builtin_dir
|
||||||
|
call strcmp
|
||||||
|
b.z rax, 0, .handle_DIR
|
||||||
|
|
||||||
|
; fallthrough
|
||||||
|
|
||||||
|
.exec_prog:
|
||||||
|
jmp .print_prompt
|
||||||
|
|
||||||
|
;
|
||||||
|
; call builtins
|
||||||
|
;
|
||||||
|
.handle_DIR:
|
||||||
call builtins.dir
|
call builtins.dir
|
||||||
|
jmp .print_prompt
|
||||||
ret
|
|
||||||
|
|
||||||
|
@ -15,10 +15,6 @@
|
|||||||
# %str = %str - sizeof(x)
|
# %str = %str - sizeof(x)
|
||||||
# FI
|
# FI
|
||||||
#
|
#
|
||||||
# When no parameters are given, %str = RDI and $val = RAX
|
|
||||||
# When one parameter is given, %str = RDI and $val = $1
|
|
||||||
# When two parameters are given, %str = $1 and $val = $2
|
|
||||||
#
|
|
||||||
stosb r ri
|
stosb r ri
|
||||||
stosw r ri
|
stosw r ri
|
||||||
stosl r ri
|
stosl r ri
|
||||||
@ -97,7 +93,7 @@ cmpsq r r
|
|||||||
# Behaves precisely like CMPSx, except in the following case:
|
# Behaves precisely like CMPSx, except in the following case:
|
||||||
# - If both [%1] and [%2] are zero, clears ZF (indicating NOT EQUAL)
|
# - If both [%1] and [%2] are zero, clears ZF (indicating NOT EQUAL)
|
||||||
#
|
#
|
||||||
# This prevents 'CMPZSx.REP.Z' from looping infinitely when both strings
|
# This prevents 'CMPZSx.REP.Z' from ignoring null-terminators when both strings
|
||||||
# have the exact same content; this allows for short strcmp's
|
# have the exact same content; this allows for short strcmp's
|
||||||
#
|
#
|
||||||
cmpzsb r r
|
cmpzsb r r
|
||||||
@ -108,7 +104,7 @@ cmpzsq r r
|
|||||||
#
|
#
|
||||||
# Move value from string to string (MOVSx)
|
# Move value from string to string (MOVSx)
|
||||||
#
|
#
|
||||||
# [%1] = [%1]
|
# [%1] = [%2]
|
||||||
# IF (DF == 0) THEN
|
# IF (DF == 0) THEN
|
||||||
# %1 = %1 + sizeof(x)
|
# %1 = %1 + sizeof(x)
|
||||||
# %2 = %2 + sizeof(x)
|
# %2 = %2 + sizeof(x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user