mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
cmd
This commit is contained in:
parent
cec0afb0ee
commit
3ab03703f4
11
as/k-as.py
11
as/k-as.py
@ -332,13 +332,18 @@ def parse_preproc(line):
|
||||
leave()
|
||||
sys.exit(1)
|
||||
|
||||
written = b_data.write(ord(c).to_bytes(1, byteorder='little', signed=False))
|
||||
b_data.write(ord(c).to_bytes(1, byteorder='little', signed=False))
|
||||
real_len += 1
|
||||
pdata += 1
|
||||
|
||||
b_data.write(int(0).to_bytes(1, byteorder='little', signed=False))
|
||||
pdata += 1
|
||||
|
||||
l = real_len + 1 # s + null-term
|
||||
|
||||
# align
|
||||
if (len(s) % 8) != 0:
|
||||
for i in range(8 - len(s) % 8):
|
||||
if (l % 8) != 0:
|
||||
for i in range(8 - l % 8):
|
||||
written = b_data.write(int(0).to_bytes(1, byteorder='little', signed=False))
|
||||
pdata += 1
|
||||
|
||||
|
@ -6,6 +6,8 @@ __cmdstart:
|
||||
|
||||
include "crt/crt.k"
|
||||
|
||||
FILE_LOADP := 0x141000 ; 4KB above stack
|
||||
|
||||
start:
|
||||
mov rsp, 0x140000
|
||||
xor rbp, rbp
|
||||
@ -14,7 +16,7 @@ start:
|
||||
cld
|
||||
call main
|
||||
|
||||
mov rax, Sys.HLT
|
||||
mov rax, Sys.EnterHaltMode
|
||||
trap 0
|
||||
|
||||
crash
|
||||
|
@ -22,3 +22,4 @@ QWORD_MAX := 0xFFFFFFFFFFFFFFFF
|
||||
|
||||
STRLEN_MAX := 0xFFFFFFFF
|
||||
|
||||
FILE_MAXSZ := 0x8000 ; 512KB
|
||||
|
47
ka/crt/sys.k
47
ka/crt/sys.k
@ -1,6 +1,20 @@
|
||||
; The OS/K Team licenses this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
;
|
||||
; EXIT syscall
|
||||
;
|
||||
; Return to COMMAND.COM
|
||||
;
|
||||
Sys.Exit := 0x00
|
||||
|
||||
;
|
||||
; SHUTDOWN syscall
|
||||
;
|
||||
; End virtual machine
|
||||
;
|
||||
Sys.Shutdown := 0x01
|
||||
|
||||
; FIND syscalls
|
||||
;
|
||||
; Find file on disk
|
||||
@ -18,19 +32,38 @@ Sys.FindFirst := 0x20
|
||||
Sys.FindNext := 0x21
|
||||
|
||||
;
|
||||
; EXIT syscall
|
||||
; OPEN/CREATE syscalls
|
||||
;
|
||||
; Return to COMMAND.COM
|
||||
; IN
|
||||
; ax0 = name string
|
||||
;
|
||||
Sys.Exit := 0x00
|
||||
; OUT
|
||||
; rax = handle of file, or <0 if couldn't open
|
||||
;
|
||||
Sys.OpenFile := 0x30
|
||||
Sys.CreateFile := 0x31
|
||||
|
||||
;
|
||||
; SHUTDOWN syscall
|
||||
; CLOSE syscall
|
||||
;
|
||||
; End virtual machine
|
||||
; IN
|
||||
; ax0 = file handle
|
||||
;
|
||||
Sys.Shutdown := 0x01
|
||||
Sys.CloseFile := 0x35
|
||||
|
||||
;
|
||||
; READ syscall
|
||||
;
|
||||
; IN
|
||||
; ax0 = file handle
|
||||
; ax1 = buffer address
|
||||
; ax2 = buffer size
|
||||
;
|
||||
; OUT
|
||||
; rax = number of bytes read, <0 on error
|
||||
;
|
||||
Sys.ReadFile := 0x38
|
||||
|
||||
; Halt mode
|
||||
Sys.HLT := 0x99
|
||||
Sys.EnterHaltMode := 0x999
|
||||
|
||||
|
@ -14,11 +14,15 @@ trap0_handler:
|
||||
call RFS.LoadReg
|
||||
call RFS.LoadArgs
|
||||
|
||||
b.z rax, Sys.HLT, .handle_HLT
|
||||
b.z rax, Sys.Exit, .handle_Exit
|
||||
b.z rax, Sys.Shutdown, .handle_Shutdown
|
||||
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.CloseFile, .handle_CloseFile
|
||||
b.z rax, Sys.ReadFile, .handle_ReadFile
|
||||
b.z rax, Sys.EnterHaltMode, .handle_HaltMode
|
||||
mov rax, 1 << 63
|
||||
|
||||
.fini:
|
||||
jmp TrapHandlers.epilog
|
||||
@ -105,13 +109,27 @@ trap0_handler:
|
||||
call DISK.FindNext
|
||||
jmp .fini
|
||||
|
||||
.handle_OpenFile:
|
||||
add ax0, nx0
|
||||
call DISK.OpenFile
|
||||
jmp .fini
|
||||
|
||||
.handle_CloseFile:
|
||||
call DISK.CloseFile
|
||||
jmp .fini
|
||||
|
||||
.handle_ReadFile:
|
||||
add ax1, nx0
|
||||
call DISK.ReadFile
|
||||
jmp .fini
|
||||
|
||||
;
|
||||
; Misc.
|
||||
;
|
||||
.handle_Shutdown:
|
||||
stop
|
||||
|
||||
.handle_HLT:
|
||||
.handle_HaltMode:
|
||||
hlt
|
||||
.HLT.loop:
|
||||
xpause
|
||||
|
@ -25,6 +25,8 @@ main:
|
||||
; iterator through argbuf
|
||||
xor rcx, rcx
|
||||
|
||||
mov q[argv1pos], 0
|
||||
|
||||
.input_loop:
|
||||
pause
|
||||
pause
|
||||
@ -163,23 +165,7 @@ main:
|
||||
call strcmp
|
||||
b.z rax, 0, .handle_VER
|
||||
|
||||
; fallthrough
|
||||
|
||||
.exec_prog:
|
||||
|
||||
; fallthrough
|
||||
|
||||
.not_found:
|
||||
mov rcx, STRLEN_MAX
|
||||
mov rdx, argv0
|
||||
prns.rep.nz rdx
|
||||
|
||||
mov rdx, .errmsg
|
||||
prns.rep.nz rdx
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.errmsg = " : command not found\n"
|
||||
jmp .command_not_found
|
||||
|
||||
;
|
||||
; call builtins
|
||||
@ -201,7 +187,7 @@ main:
|
||||
mov ax0, .datefmt
|
||||
call printf
|
||||
|
||||
add rsp, 8*5
|
||||
add rsp, 5*8
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
@ -227,6 +213,31 @@ main:
|
||||
trap 0
|
||||
|
||||
.handle_PRINT:
|
||||
mov rax, Sys.OpenFile
|
||||
mov ax0, q[argv1pos]
|
||||
b.z ax0, 0, .need_params
|
||||
trap 0
|
||||
|
||||
b.l rax, 0, .file_not_found
|
||||
|
||||
mov ax0, rax
|
||||
mov ax1, FILE_LOADP
|
||||
mov ax2, FILE_MAXSZ
|
||||
|
||||
mov rax, Sys.ReadFile
|
||||
trap 0
|
||||
|
||||
mov rcx, rax
|
||||
|
||||
mov rax, Sys.CloseFile
|
||||
trap 0
|
||||
|
||||
b.l rax, 0, .couldnt_read
|
||||
b.z rax, 0, .empty_file
|
||||
|
||||
mov rdx, FILE_LOADP
|
||||
prns.rep rdx
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.handle_TIME:
|
||||
@ -289,3 +300,60 @@ main:
|
||||
.helpmsg.time = " TIME Display current time of day\n"
|
||||
.helpmsg.ver = " VER Display current COMMAND.COM and DOS kernel versions\n"
|
||||
|
||||
.command_not_found:
|
||||
mov rcx, STRLEN_MAX
|
||||
mov rdx, argv0
|
||||
prns.rep.nz rdx
|
||||
|
||||
mov rdx, .cnf_errmsg
|
||||
prns.rep.nz rdx
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.cnf_errmsg = ": command not found\n"
|
||||
|
||||
.file_not_found:
|
||||
mov ax0, .fnf_errmsg
|
||||
push q[argv1pos]
|
||||
push argv0
|
||||
call printf
|
||||
add rsp, 16
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.fnf_errmsg = "%s: %s: file not found\n"
|
||||
|
||||
.empty_file:
|
||||
mov ax0, .ef_errmsg
|
||||
push q[argv1pos]
|
||||
push argv0
|
||||
call printf
|
||||
add rsp, 16
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.ef_errmsg = "%s: %s: file is empty\n"
|
||||
|
||||
.couldnt_read:
|
||||
mov ax0, .cno_errmsg
|
||||
push q[argv1pos]
|
||||
push argv0
|
||||
call printf
|
||||
add rsp, 16
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.cno_errmsg = "%s: %s: an error occured while reading file\n"
|
||||
|
||||
.need_params:
|
||||
mov rcx, STRLEN_MAX
|
||||
mov rdx, argv0
|
||||
prns.rep.nz rdx
|
||||
|
||||
mov rdx, .np_errmsg
|
||||
prns.rep.nz rdx
|
||||
|
||||
jmp .print_prompt
|
||||
|
||||
.np_errmsg = ": need more parameters\n"
|
||||
|
||||
|
@ -20,7 +20,7 @@ Disk device function slots:
|
||||
|
||||
18-21 - - - - (reserved) (reserved)
|
||||
|
||||
25 p i - - open
|
||||
25 p - - - open
|
||||
- open file whose name is stored in string *ax0
|
||||
- rax = -1 if couldn't open file, rax = file handle otherwise
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user