1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/ka/usr/cmd-exec.k
2019-08-21 16:57:32 +02:00

57 lines
1.0 KiB
Plaintext

; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
.try_exec:
; try without appending ".com"
mov rax, Sys.OpenFile
mov ax0, argv0
trap 0
; we good?
blte zero, rax, .do_exec
; nope, append ".com" and try again
sub rcx, argbuf.size, 5
scasb ax0, zero ; find null-term
mov b[ax0+0], '.' ; ".com"
mov b[ax0+1], 'c'
mov b[ax0+2], 'o'
mov b[ax0+3], 'm'
nul b[ax0+4]
; try again
mov rax, Sys.OpenFile
mov ax0, argv0
trap 0
; still no good?
bltz rax, .exec_not_found
.do_exec:
; load file into memory
mov ax0, rax
mov ax1, FILE_LOADP
mov ax2, FILE_MAXSZ
mov rax, Sys.ReadFile
trap 0
; save load address
mov rcx, rax
; close file
mov rax, Sys.CloseFile
trap 0
; read anything?
bltz rcx, .couldnt_read
jrcxz .empty_file
; all good, let's go
mov rax, Sys.ExecuteInFrame
mov ax0, FILE_LOADP
mov ax1, 5
trap 0
; unreachable
jmp abort