kvisc/ka/usr/cmd-exec.k

62 lines
1.1 KiB
Plaintext
Raw Normal View History

2019-08-21 16:57:32 +02:00
; 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"
2019-09-07 16:45:03 +02:00
mov eax, Sys.OpenFile
2019-08-21 16:57:32 +02:00
mov ax0, argv0
trap 0
; we good?
2019-09-07 16:45:03 +02:00
blte zero, eax, .do_exec
2019-08-21 16:57:32 +02:00
; nope, append ".com" and try again
2019-09-09 08:12:02 +02:00
mov esi, argv0
2019-09-07 16:45:03 +02:00
sub ecx, argbuf.size, 5
2019-09-09 08:12:02 +02:00
scasb esi, zero ; find null-term
mov b[esi], '.' ; ".com"
mov b[esi+1], 'c'
mov b[esi+2], 'o'
mov b[esi+3], 'm'
nul b[esi+4]
2019-08-21 16:57:32 +02:00
; try again
2019-09-07 16:45:03 +02:00
mov eax, Sys.OpenFile
2019-08-21 16:57:32 +02:00
mov ax0, argv0
trap 0
2019-09-09 08:12:02 +02:00
; we good?
blte 0, eax, .do_exec
nul b[esi] ; erase ".com"
jmp .exec_not_found
2019-08-21 16:57:32 +02:00
.do_exec:
; load file into memory
2019-09-07 16:45:03 +02:00
mov ax0, eax
2019-08-21 16:57:32 +02:00
mov ax1, FILE_LOADP
mov ax2, FILE_MAXSZ
2019-09-07 16:45:03 +02:00
mov eax, Sys.ReadFile
2019-08-21 16:57:32 +02:00
trap 0
; save load address
2019-09-07 16:45:03 +02:00
mov ecx, eax
2019-08-21 16:57:32 +02:00
; close file
2019-09-07 16:45:03 +02:00
mov eax, Sys.CloseFile
2019-08-21 16:57:32 +02:00
trap 0
; read anything?
2019-09-07 16:45:03 +02:00
bltz ecx, .couldnt_read
2019-09-08 19:04:07 +02:00
jecxz .empty_file
2019-08-21 16:57:32 +02:00
; all good, let's go
2019-09-07 16:45:03 +02:00
mov eax, Sys.ExecuteInFrame
2019-08-21 16:57:32 +02:00
mov ax0, FILE_LOADP
mov ax1, 5
trap 0
; unreachable
jmp abort
2019-08-21 18:47:03 +02:00