This commit is contained in:
julianb0 2019-08-05 15:55:46 +02:00
parent 7a4324f12d
commit 3559d69b61
No known key found for this signature in database
GPG Key ID: 9C7ACF0C053FB8A1
12 changed files with 159 additions and 42 deletions

View File

@ -2,6 +2,7 @@
# See the LICENSE file in the project root for more information. # See the LICENSE file in the project root for more information.
KODIR=fs KODIR=fs
KSDIR=vm/ob
KVVM=$(KODIR)/kvisc.exe KVVM=$(KODIR)/kvisc.exe
@ -16,12 +17,10 @@ kas: kpc as/regs.lst as/k-as.py
dos: kas dosclean dos: kas dosclean
@cd ka && make --no-print-directory -s @cd ka && make --no-print-directory -s
#@as/k-as.py ka/dos.k 0x100000 $(AOUT) $(ASYM)
.PHONY: clean dosclean .PHONY: clean dosclean
dosclean: dosclean:
@rm -f $(KODIR)/*.com $(KODIR)/*.sym @rm -f $(KODIR)/*.com $(KSDIR)/*.sym
inclean: inclean:
@rm -f vm/ob/arch_i.h vm/ob/instrs.lst vm/ob/in/*.o @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 @rm -f $(KVVM) as/instrs.lst
test: dos test: dos
@$(KVVM) $(KODIR)/doskrnl.com $(KODIR)/doskrnl.sym @$(KVVM) $(KODIR)/doskrnl.com $(KSDIR)/doskrnl.sym
@rm -f $(AOUT) $(ASYM)
wc: clean wc: clean
@cat $(shell find -type f -name '*' ! -path './.git/*' | egrep '(ka|vm)/*') | wc -l @cat $(shell find -type f -name '*' ! -path './.git/*' | egrep '(ka|vm)/*') | wc -l

View File

View File

@ -4,12 +4,13 @@
all: dos all: dos
KODIR=../fs KODIR=../fs
KSDIR=../vm/ob
KSRC = $(shell ls *.k) KSRC = $(shell ls *.k)
KCOM = $(patsubst %.k,$(KODIR)/%.com,$(KSRC)) KCOM = $(patsubst %.k,$(KODIR)/%.com,$(KSRC))
$(KODIR)/%.com: %.k $(KODIR)/%.com: %.k
@../as/k-as.py $< 0x100000 $@ $(patsubst %.k,$(KODIR)/%.sym,$<) @../as/k-as.py $< 0x100000 $@ $(patsubst %.k,$(KSDIR)/%.sym,$<)
dos: $(KCOM) dos: $(KCOM)

View File

@ -30,6 +30,7 @@ nprintf:
; ;
; Print a string ; Print a string
; Guaranteed to only affect rcx and ax0
; ;
print: print:
mov rcx, STRLEN_MAX mov rcx, STRLEN_MAX

View File

@ -32,7 +32,7 @@ Sys.FindFirst := 0x20
Sys.FindNext := 0x21 Sys.FindNext := 0x21
; ;
; OPEN/CREATE syscalls ; OPEN syscall
; ;
; IN ; IN
; ax0 = name string ; ax0 = name string
@ -41,8 +41,29 @@ Sys.FindNext := 0x21
; rax = handle of file, or <0 if couldn't open ; rax = handle of file, or <0 if couldn't open
; ;
Sys.OpenFile := 0x30 Sys.OpenFile := 0x30
;
; CREATE syscall
;
; IN
; ax0 = name string
;
; OUT
; rax = 0 on success, or <0 if couldn't open
;
Sys.CreateFile := 0x31 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 ; CLOSE syscall
; ;

View File

@ -25,6 +25,10 @@ DISK.CreateFile:
iocall DISKDEV, 27 iocall DISKDEV, 27
ret ret
DISK.RemoveFile:
iocall DISKDEV, 28
ret
DISK.ReadFile: DISK.ReadFile:
iocall DISKDEV, 32 iocall DISKDEV, 32
ret ret

View File

@ -14,14 +14,18 @@ trap0_handler:
jmp.axz .handle_Shutdown jmp.axz .handle_Shutdown
b.z rax, Sys.Exit, .handle_Exit 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.FindNext, .handle_FindNext
b.z rax, Sys.FindFirst, .handle_FindFirst 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 b.z rax, Sys.EnterHaltMode, .handle_HaltMode
mov rax, 1 << 63 mov rax, 1 << 63
mov rcx, 1 << 63
mov rdx, 1 << 63
.fini.savecx: .fini.savecx:
mov ax2, rcx mov ax2, rcx
@ -108,6 +112,11 @@ trap0_handler:
call DISK.CreateFile call DISK.CreateFile
jmp .fini jmp .fini
.handle_RemoveFile:
inc ax0, r12
call DISK.RemoveFile
jmp .fini
.handle_CloseFile: .handle_CloseFile:
call DISK.CloseFile call DISK.CloseFile
jmp .fini jmp .fini

View File

@ -9,8 +9,12 @@ builtins.dir:
push r12 push r12
push r13 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 call print, .dirmsg
@ -29,16 +33,17 @@ builtins.dir:
trap 0 trap 0
.list: .list:
mov r13, rcx # file size
jmp.axz .end jmp.axz .end
; found something mov r15, rcx # file size
inc r12, 1 inc r14, rcx
; directory? ; directory?
jmp.dxnz .is_dir jmp.dxnz .is_dir
; found a file
inc r12, 1
; separate extension from file name ; separate extension from file name
mov rcx, FNAME_MAX mov rcx, FNAME_MAX
mov rsi, .buf mov rsi, .buf
@ -89,10 +94,10 @@ builtins.dir:
mov rcx, 3 mov rcx, 3
prn.rep ' ' prn.rep ' '
shr rax, r13, 10 shr rax, r15, 10
and r13, r13, 1023 and r15, r15, 1023
push r13 push r15
push rax push rax
call printf, .bytesstr call printf, .bytesstr
inc rsp, 16 inc rsp, 16
@ -103,12 +108,24 @@ builtins.dir:
jmp .next jmp .next
.end: .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 push r12
call printf, .endstr1 call printf, .endstr1
inc rsp, 8 inc rsp, 16
call print, .endstr2
pop r15
pop r14
pop r13 pop r13
pop r12 pop r12
@ -117,24 +134,26 @@ builtins.dir:
; special case: direcory ; special case: direcory
.is_dir: .is_dir:
inc r13, 1
mov rcx, STRLEN_MAX mov rcx, STRLEN_MAX
mov rdx, .buf mov rdx, .buf
prns.rep.nz rdx prns.rep.nz rdx
sub rcx, STRLEN_MAX, rcx sub rcx, STRLEN_MAX, rcx
b.ae rcx, N, .is_dir.print_ext
sub rcx, N, rcx sub rcx, N, rcx
prn.rep ' ' prn.rep ' '
.is_dir.print_ext:
call print, .dir_ext call print, .dir_ext
jmp .print_bytes jmp .print_bytes
.buf = [FNAME_MAX] .buf = [FNAME_MAX]
.dir_ext = " <DIR>" .dir_ext = " <DIR>"
.endstr1 = " %d file(s)\n" .endstr0 = " total %dMB + %dKB + %dB\n"
.endstr2 = " 0 dir(s)\n" .endstr1 = " found %d file(s), %d dir(s)\n"
.dirmsg = "Directory of C:\\\n\n" .dirmsg = "Directory of C:\\\n\n"
.bytesstr = "%d kilobytes + %d bytes"
.bytesstr = "%d kilobytes + %d bytes"
# .bytesstr = "%dMB + %dKB + %dB" # too soon

View File

@ -146,6 +146,10 @@ main:
call strcmp, argv0, .builtin_echo call strcmp, argv0, .builtin_echo
jmp.axz .handle_ECHO jmp.axz .handle_ECHO
.builtin_erase = "erase"
call strcmp, argv0, .builtin_erase
jmp.axz .handle_ERASE
.builtin_exit = "exit" .builtin_exit = "exit"
call strcmp, argv0, .builtin_exit call strcmp, argv0, .builtin_exit
jmp.axz .handle_EXIT jmp.axz .handle_EXIT
@ -170,13 +174,17 @@ main:
call strcmp, argv0, .builtin_prompt call strcmp, argv0, .builtin_prompt
jmp.axz .handle_PROMPT jmp.axz .handle_PROMPT
.builtin_remove = "remove"
call strcmp, argv0, .builtin_remove
jmp.axz .handle_REMOVE
.builtin_time = "time" .builtin_time = "time"
call strcmp, argv0, .builtin_time call strcmp, argv0, .builtin_time
jmp.axz .handle_TIME jmp.axz .handle_TIME
.builtin_ver = "ver" .builtin_vers = "vers"
call strcmp, argv0, .builtin_ver call strcmp, argv0, .builtin_vers
jmp.axz .handle_VER jmp.axz .handle_VERS
jmp .command_not_found jmp .command_not_found
@ -222,6 +230,16 @@ main:
prn 10 prn 10
jmp .print_prompt jmp .print_prompt
.handle_ERASE:
mov rax, Sys.RemoveFile
mov ax0, q[argv1pos]
b.z ax0, zero, .need_params
trap 0
b.l rax, zero, .couldnt_remove
jmp .handle_MAKE ; re-create it back
.handle_EXIT: .handle_EXIT:
mov rax, Sys.Shutdown mov rax, Sys.Shutdown
trap 0 trap 0
@ -278,6 +296,16 @@ main:
jmp .print_prompt jmp .print_prompt
.handle_REMOVE:
mov rax, Sys.RemoveFile
mov ax0, q[argv1pos]
b.z ax0, zero, .need_params
trap 0
b.l rax, zero, .couldnt_remove
jmp .print_prompt
.handle_TIME: .handle_TIME:
call GetTimeUTC call GetTimeUTC
@ -291,7 +319,7 @@ main:
.timefmt = "%d:%d:%d\n" .timefmt = "%d:%d:%d\n"
.handle_VER: .handle_VERS:
call print, cmd.versionstr call print, cmd.versionstr
prn 10 prn 10
@ -304,12 +332,14 @@ main:
call print, .helpmsg.dir call print, .helpmsg.dir
call print, .helpmsg.dump call print, .helpmsg.dump
call print, .helpmsg.echo call print, .helpmsg.echo
call print, .helpmsg.erase
call print, .helpmsg.exit call print, .helpmsg.exit
call print, .helpmsg.help call print, .helpmsg.help
call print, .helpmsg.halt call print, .helpmsg.halt
call print, .helpmsg.make call print, .helpmsg.make
call print, .helpmsg.print call print, .helpmsg.print
call print, .helpmsg.prompt call print, .helpmsg.prompt
call print, .helpmsg.remove
call print, .helpmsg.time call print, .helpmsg.time
call print, .helpmsg.ver call print, .helpmsg.ver
@ -321,14 +351,16 @@ main:
.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.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.erase = " ERASE Empties a file, making it blank\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"
.helpmsg.halt = " HALT Put processor in halt mode\n" .helpmsg.halt = " HALT Put processor in halt mode\n"
.helpmsg.make = " MAKE Create an empty file\n" .helpmsg.make = " MAKE Create an empty file\n"
.helpmsg.print = " PRINT Display contents of text file\n" .helpmsg.print = " PRINT Display contents of text file\n"
.helpmsg.prompt = " PROMPT Change the command line prompt\n" .helpmsg.prompt = " PROMPT Change the command line prompt\n"
.helpmsg.remove = " REMOVE Deletes a file (permanently)\n"
.helpmsg.time = " TIME Display current time of day\n" .helpmsg.time = " TIME Display current time of day\n"
.helpmsg.ver = " VER Display current COMMAND.COM version\n" .helpmsg.ver = " VERS Display current COMMAND.COM version\n"
.command_not_found: .command_not_found:
call print, argv0 call print, argv0
@ -367,6 +399,16 @@ main:
.cno_errmsg = "%s: %s: an error occured while opening file\n" .cno_errmsg = "%s: %s: an error occured while opening file\n"
.couldnt_remove:
push q[argv1pos]
push argv0
call printf, .cne_errmsg
inc rsp, 16
jmp .print_prompt
.cne_errmsg = "%s: %s: an error occured while removing file\n"
.couldnt_read: .couldnt_read:
push q[argv1pos] push q[argv1pos]
push argv0 push argv0

View File

@ -112,6 +112,23 @@ long diskdev_open(dev_t *dev)
return 0; return 0;
} }
long diskdev_close(dev_t *dev)
{
GETDISK();
if (R(AX0) >= MAXOPEN)
return -1;
if (disk->table[R(AX0)] <= 0)
return -1;
close(disk->table[R(AX0)]);
return 0;
}
//----------------------------------------------------------------------------//
long diskdev_create(dev_t *dev) long diskdev_create(dev_t *dev)
{ {
int tmp; int tmp;
@ -133,18 +150,22 @@ long diskdev_create(dev_t *dev)
return 0; return 0;
} }
long diskdev_close(dev_t *dev) long diskdev_remove(dev_t *dev)
{ {
GETDISK(); int tmp;
char buf[NAME_MAX+4] = { 'f', 's', '/', 0 };
if (R(AX0) >= MAXOPEN) readstr(R(AX0), NAME_MAX, buf+3);
tmp = remove(buf);
if (tmp < 0)
{
perror("diskdev: remove");
return -1; return -1;
}
if (disk->table[R(AX0)] <= 0) R(RAX) = 0;
return -1;
close(disk->table[R(AX0)]);
return 0; return 0;
} }
@ -201,6 +222,7 @@ long diskdev_poweron(dev_t *dev)
dev->fslots[25] = diskdev_open; dev->fslots[25] = diskdev_open;
dev->fslots[26] = diskdev_close; dev->fslots[26] = diskdev_close;
dev->fslots[27] = diskdev_create; dev->fslots[27] = diskdev_create;
dev->fslots[28] = diskdev_remove;
dev->fslots[32] = diskdev_read; dev->fslots[32] = diskdev_read;

View File

@ -13,8 +13,8 @@
# define _MULT 2 # define _MULT 2
#endif #endif
#define CONSOLE_WIDTH (80) #define CONSOLE_WIDTH (90)
#define CONSOLE_HEIGHT (25) #define CONSOLE_HEIGHT (30)
#define CONSOLE_FONT_SIZE (16 * _MULT) #define CONSOLE_FONT_SIZE (16 * _MULT)
#define SCREEN_WIDTH (9 * CONSOLE_WIDTH * _MULT) #define SCREEN_WIDTH (9 * CONSOLE_WIDTH * _MULT)
#define SCREEN_HEIGHT (16 * CONSOLE_HEIGHT * _MULT) #define SCREEN_HEIGHT (16 * CONSOLE_HEIGHT * _MULT)