From c60dfb47fc448fc2da19bf9e295554ef65a65ce9 Mon Sep 17 00:00:00 2001 From: julianb0 Date: Wed, 10 Jul 2019 20:11:35 +0200 Subject: [PATCH] command.com --- ka/doskrnl.k | 1 - ka/sys/fileapi.k | 0 ka/sys/intr/common.k | 13 ++++--- ka/sys/intr/trap0.k | 6 ++-- ka/usr/cmd/main.k | 86 ++++++++++++++++++++++++++++++++++++++++++-- vm/in/STRING | 8 ++--- 6 files changed, 97 insertions(+), 17 deletions(-) delete mode 100644 ka/sys/fileapi.k diff --git a/ka/doskrnl.k b/ka/doskrnl.k index 4067430..b07f897 100644 --- a/ka/doskrnl.k +++ b/ka/doskrnl.k @@ -44,6 +44,5 @@ include "sys/drv/diskdev.k" include "sys/intr/common.k" include "sys/intr/trap0.k" -include "sys/tests.k" include "sys/main.k" diff --git a/ka/sys/fileapi.k b/ka/sys/fileapi.k deleted file mode 100644 index e69de29..0000000 diff --git a/ka/sys/intr/common.k b/ka/sys/intr/common.k index 93d5773..130b461 100644 --- a/ka/sys/intr/common.k +++ b/ka/sys/intr/common.k @@ -6,17 +6,19 @@ TrapHandlers.prolog: mov q[rbp-16], r12 mov q[rbp-24], r13 sub rsp, rbp, 24 - xor rdx, rdx + + mov rdx, cr2 ; nx0 = caller's cr2 - push cr2 mov ax0, r12 mov ax1, $cr2 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: mov r13, q[rbp-24] @@ -36,5 +38,6 @@ TrapHandlers.epilog: mov ax0, r11 call IDT.DoneHandling + iret diff --git a/ka/sys/intr/trap0.k b/ka/sys/intr/trap0.k index 9d36cb6..bab4589 100644 --- a/ka/sys/intr/trap0.k +++ b/ka/sys/intr/trap0.k @@ -22,9 +22,9 @@ trap0_handler: .fini: jmp TrapHandlers.epilog -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Syscall implementations ;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;------------------------------------------------; +; Syscall implementations ; +;------------------------------------------------; ; ; Pass control to COMMAND.COM in frame 0 diff --git a/ka/usr/cmd/main.k b/ka/usr/cmd/main.k index 6a0e2b9..010985b 100644 --- a/ka/usr/cmd/main.k +++ b/ka/usr/cmd/main.k @@ -1,8 +1,90 @@ ; The OS/K Team licenses this file to you under the MIT license. ; 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: + +.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 - - ret + jmp .print_prompt diff --git a/vm/in/STRING b/vm/in/STRING index f05ae66..4dd3f08 100644 --- a/vm/in/STRING +++ b/vm/in/STRING @@ -15,10 +15,6 @@ # %str = %str - sizeof(x) # 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 stosw r ri stosl r ri @@ -97,7 +93,7 @@ cmpsq r r # Behaves precisely like CMPSx, except in the following case: # - 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 # cmpzsb r r @@ -108,7 +104,7 @@ cmpzsq r r # # Move value from string to string (MOVSx) # -# [%1] = [%1] +# [%1] = [%2] # IF (DF == 0) THEN # %1 = %1 + sizeof(x) # %2 = %2 + sizeof(x)