1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
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.
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

View File

View File

@ -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)

View File

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

View File

@ -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
;

View File

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

View File

@ -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

View File

@ -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 = " <DIR>"
.endstr1 = " %d file(s)\n"
.endstr2 = " 0 dir(s)\n"
.endstr0 = " total %dMB + %dKB + %dB\n"
.endstr1 = " found %d file(s), %d dir(s)\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
jmp.axz .handle_ECHO
.builtin_erase = "erase"
call strcmp, argv0, .builtin_erase
jmp.axz .handle_ERASE
.builtin_exit = "exit"
call strcmp, argv0, .builtin_exit
jmp.axz .handle_EXIT
@ -170,13 +174,17 @@ main:
call strcmp, argv0, .builtin_prompt
jmp.axz .handle_PROMPT
.builtin_remove = "remove"
call strcmp, argv0, .builtin_remove
jmp.axz .handle_REMOVE
.builtin_time = "time"
call strcmp, argv0, .builtin_time
jmp.axz .handle_TIME
.builtin_ver = "ver"
call strcmp, argv0, .builtin_ver
jmp.axz .handle_VER
.builtin_vers = "vers"
call strcmp, argv0, .builtin_vers
jmp.axz .handle_VERS
jmp .command_not_found
@ -222,6 +230,16 @@ main:
prn 10
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:
mov rax, Sys.Shutdown
trap 0
@ -278,6 +296,16 @@ main:
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:
call GetTimeUTC
@ -291,7 +319,7 @@ main:
.timefmt = "%d:%d:%d\n"
.handle_VER:
.handle_VERS:
call print, cmd.versionstr
prn 10
@ -304,12 +332,14 @@ main:
call print, .helpmsg.dir
call print, .helpmsg.dump
call print, .helpmsg.echo
call print, .helpmsg.erase
call print, .helpmsg.exit
call print, .helpmsg.help
call print, .helpmsg.halt
call print, .helpmsg.make
call print, .helpmsg.print
call print, .helpmsg.prompt
call print, .helpmsg.remove
call print, .helpmsg.time
call print, .helpmsg.ver
@ -321,14 +351,16 @@ main:
.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.erase = " ERASE Empties a file, making it blank\n"
.helpmsg.exit = " EXIT Initiate machine shutdown\n"
.helpmsg.help = " HELP Display these messages\n"
.helpmsg.halt = " HALT Put processor in halt mode\n"
.helpmsg.make = " MAKE Create an empty file\n"
.helpmsg.print = " PRINT Display contents of text file\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.ver = " VER Display current COMMAND.COM version\n"
.helpmsg.ver = " VERS Display current COMMAND.COM version\n"
.command_not_found:
call print, argv0
@ -367,6 +399,16 @@ main:
.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:
push q[argv1pos]
push argv0

View File

@ -112,6 +112,23 @@ long diskdev_open(dev_t *dev)
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)
{
int tmp;
@ -133,18 +150,22 @@ long diskdev_create(dev_t *dev)
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;
}
if (disk->table[R(AX0)] <= 0)
return -1;
close(disk->table[R(AX0)]);
R(RAX) = 0;
return 0;
}
@ -201,6 +222,7 @@ long diskdev_poweron(dev_t *dev)
dev->fslots[25] = diskdev_open;
dev->fslots[26] = diskdev_close;
dev->fslots[27] = diskdev_create;
dev->fslots[28] = diskdev_remove;
dev->fslots[32] = diskdev_read;

View File

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