diff --git a/Makefile b/Makefile index b6c1bf2..eff4fa9 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ # See the LICENSE file in the project root for more information. KODIR=fs +KSDIR=vm/ob KVVM=$(KODIR)/kvisc.exe @@ -16,12 +17,10 @@ kas: kpc as/regs.lst as/k-as.py dos: kas dosclean @cd ka && make --no-print-directory -s -#@as/k-as.py ka/dos.k 0x100000 $(AOUT) $(ASYM) - .PHONY: clean dosclean dosclean: - @rm -f $(KODIR)/*.com $(KODIR)/*.sym + @rm -f $(KODIR)/*.com $(KSDIR)/*.sym inclean: @rm -f vm/ob/arch_i.h vm/ob/instrs.lst vm/ob/in/*.o @@ -31,8 +30,7 @@ clean: dosclean @rm -f $(KVVM) as/instrs.lst test: dos - @$(KVVM) $(KODIR)/doskrnl.com $(KODIR)/doskrnl.sym - @rm -f $(AOUT) $(ASYM) + @$(KVVM) $(KODIR)/doskrnl.com $(KSDIR)/doskrnl.sym wc: clean @cat $(shell find -type f -name '*' ! -path './.git/*' | egrep '(ka|vm)/*') | wc -l diff --git a/fs/empty.txt b/fs/empty.txt deleted file mode 100644 index e69de29..0000000 diff --git a/fs/dir/file b/fs/test/file similarity index 100% rename from fs/dir/file rename to fs/test/file diff --git a/ka/Makefile b/ka/Makefile index 362cfca..4305ee5 100644 --- a/ka/Makefile +++ b/ka/Makefile @@ -4,12 +4,13 @@ all: dos KODIR=../fs +KSDIR=../vm/ob KSRC = $(shell ls *.k) KCOM = $(patsubst %.k,$(KODIR)/%.com,$(KSRC)) $(KODIR)/%.com: %.k - @../as/k-as.py $< 0x100000 $@ $(patsubst %.k,$(KODIR)/%.sym,$<) + @../as/k-as.py $< 0x100000 $@ $(patsubst %.k,$(KSDIR)/%.sym,$<) dos: $(KCOM) diff --git a/ka/crt/fmt/printf.k b/ka/crt/fmt/printf.k index d476ab6..9e76e01 100644 --- a/ka/crt/fmt/printf.k +++ b/ka/crt/fmt/printf.k @@ -30,6 +30,7 @@ nprintf: ; ; Print a string +; Guaranteed to only affect rcx and ax0 ; print: mov rcx, STRLEN_MAX diff --git a/ka/crt/sys.k b/ka/crt/sys.k index 614e000..0cfb4c6 100644 --- a/ka/crt/sys.k +++ b/ka/crt/sys.k @@ -32,7 +32,7 @@ Sys.FindFirst := 0x20 Sys.FindNext := 0x21 ; -; OPEN/CREATE syscalls +; OPEN syscall ; ; IN ; ax0 = name string @@ -41,8 +41,29 @@ Sys.FindNext := 0x21 ; rax = handle of file, or <0 if couldn't open ; Sys.OpenFile := 0x30 + +; +; CREATE syscall +; +; IN +; ax0 = name string +; +; OUT +; rax = 0 on success, or <0 if couldn't open +; Sys.CreateFile := 0x31 +; +; REMOVE syscall +; +; IN +; ax0 = name string +; +; OUT +; rax = 0 on success, or <0 if couldn't open +; +Sys.RemoveFile := 0x32 + ; ; CLOSE syscall ; diff --git a/ka/sys/drv/diskdev.k b/ka/sys/drv/diskdev.k index c6c6fb1..7deb013 100644 --- a/ka/sys/drv/diskdev.k +++ b/ka/sys/drv/diskdev.k @@ -25,6 +25,10 @@ DISK.CreateFile: iocall DISKDEV, 27 ret +DISK.RemoveFile: + iocall DISKDEV, 28 + ret + DISK.ReadFile: iocall DISKDEV, 32 ret diff --git a/ka/sys/intr/trap0.k b/ka/sys/intr/trap0.k index 4ff210d..ed8f393 100644 --- a/ka/sys/intr/trap0.k +++ b/ka/sys/intr/trap0.k @@ -14,14 +14,18 @@ trap0_handler: jmp.axz .handle_Shutdown b.z rax, Sys.Exit, .handle_Exit + b.z rax, Sys.ReadFile, .handle_ReadFile + b.z rax, Sys.OpenFile, .handle_OpenFile + b.z rax, Sys.CloseFile, .handle_CloseFile + b.z rax, Sys.CreateFile, .handle_CreateFile + b.z rax, Sys.RemoveFile, .handle_RemoveFile b.z rax, Sys.FindNext, .handle_FindNext b.z rax, Sys.FindFirst, .handle_FindFirst - b.z rax, Sys.OpenFile, .handle_OpenFile - b.z rax, Sys.CreateFile, .handle_CreateFile - b.z rax, Sys.CloseFile, .handle_CloseFile - b.z rax, Sys.ReadFile, .handle_ReadFile b.z rax, Sys.EnterHaltMode, .handle_HaltMode + mov rax, 1 << 63 + mov rcx, 1 << 63 + mov rdx, 1 << 63 .fini.savecx: mov ax2, rcx @@ -108,6 +112,11 @@ trap0_handler: call DISK.CreateFile jmp .fini +.handle_RemoveFile: + inc ax0, r12 + call DISK.RemoveFile + jmp .fini + .handle_CloseFile: call DISK.CloseFile jmp .fini diff --git a/ka/usr/cmd/dir.k b/ka/usr/cmd/dir.k index 9d2e624..05dcae6 100644 --- a/ka/usr/cmd/dir.k +++ b/ka/usr/cmd/dir.k @@ -9,8 +9,12 @@ builtins.dir: push r12 push r13 + push r14 + push r15 - mov r12, zero # no. of files found + mov r12, zero # no. of files found + mov r13, zero # no. of directories found + mov r14, zero # total amount of bytes found call print, .dirmsg @@ -29,16 +33,17 @@ builtins.dir: trap 0 .list: - mov r13, rcx # file size - jmp.axz .end - ; found something - inc r12, 1 + mov r15, rcx # file size + inc r14, rcx ; directory? jmp.dxnz .is_dir + ; found a file + inc r12, 1 + ; separate extension from file name mov rcx, FNAME_MAX mov rsi, .buf @@ -89,10 +94,10 @@ builtins.dir: mov rcx, 3 prn.rep ' ' - shr rax, r13, 10 - and r13, r13, 1023 + shr rax, r15, 10 + and r15, r15, 1023 - push r13 + push r15 push rax call printf, .bytesstr inc rsp, 16 @@ -103,12 +108,24 @@ builtins.dir: jmp .next .end: + shr rax, r14, 10 + shr rdx, rax, 10 + and rax, rax, 1023 + and r14, r14, 1023 + + push r14 + push rax + push rdx + call printf, .endstr0 + inc rsp, 24 + + push r13 push r12 call printf, .endstr1 - inc rsp, 8 - - call print, .endstr2 + inc rsp, 16 + pop r15 + pop r14 pop r13 pop r12 @@ -117,24 +134,26 @@ builtins.dir: ; special case: direcory .is_dir: + inc r13, 1 + mov rcx, STRLEN_MAX mov rdx, .buf prns.rep.nz rdx sub rcx, STRLEN_MAX, rcx - b.ae rcx, N, .is_dir.print_ext sub rcx, N, rcx prn.rep ' ' -.is_dir.print_ext: call print, .dir_ext jmp .print_bytes .buf = [FNAME_MAX] .dir_ext = "