2019-07-09 19:51:03 +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.
|
|
|
|
|
|
|
|
trap0_handler:
|
|
|
|
|
|
|
|
.init:
|
2019-07-10 12:28:20 +02:00
|
|
|
mov rcx, .text
|
2019-07-17 22:25:50 +02:00
|
|
|
mov rsp, TRAP0_STACK
|
2019-07-09 19:51:03 +02:00
|
|
|
jmp TrapHandlers.prolog
|
|
|
|
|
2019-07-10 12:28:20 +02:00
|
|
|
.text:
|
2019-08-03 17:41:44 +02:00
|
|
|
call RFS.LoadReg, r14, $rax
|
|
|
|
call RFS.LoadArgs, r14
|
2019-07-09 19:51:03 +02:00
|
|
|
|
2019-08-03 21:11:12 +02:00
|
|
|
jmp.axz .handle_Shutdown
|
2019-07-10 17:17:45 +02:00
|
|
|
b.z rax, Sys.Exit, .handle_Exit
|
2019-07-10 12:26:15 +02:00
|
|
|
b.z rax, Sys.FindNext, .handle_FindNext
|
|
|
|
b.z rax, Sys.FindFirst, .handle_FindFirst
|
2019-07-13 12:38:03 +02:00
|
|
|
b.z rax, Sys.OpenFile, .handle_OpenFile
|
2019-08-05 14:56:22 +02:00
|
|
|
b.z rax, Sys.CreateFile, .handle_CreateFile
|
2019-07-13 12:38:03 +02:00
|
|
|
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
|
2019-07-09 19:51:03 +02:00
|
|
|
|
2019-08-05 14:56:22 +02:00
|
|
|
.fini.savecx:
|
|
|
|
mov ax2, rcx
|
|
|
|
call RFS.StoreReg, r14, $rcx
|
|
|
|
|
2019-07-09 19:51:03 +02:00
|
|
|
.fini:
|
|
|
|
jmp TrapHandlers.epilog
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
;------------------------------------------------;
|
|
|
|
; Syscall implementations ;
|
|
|
|
;------------------------------------------------;
|
2019-07-10 17:17:45 +02:00
|
|
|
|
2019-07-09 19:51:03 +02:00
|
|
|
;
|
2019-07-10 17:17:45 +02:00
|
|
|
; Pass control to COMMAND.COM in frame 0
|
2019-07-09 19:51:03 +02:00
|
|
|
;
|
2019-07-10 17:17:45 +02:00
|
|
|
.handle_Exit:
|
|
|
|
|
|
|
|
; Open COMMAND.COM
|
2019-07-18 22:49:31 +02:00
|
|
|
call DISK.OpenFile, .cmdcom
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Crash on failure
|
2019-07-17 22:25:50 +02:00
|
|
|
cmp rax, zero
|
2019-07-10 17:17:45 +02:00
|
|
|
crash.l
|
|
|
|
|
|
|
|
; Load at CMDCOM_LOADP
|
|
|
|
mov ax1, CMDCOM_LOADP
|
|
|
|
mov ax2, CMDCOM_MAXSZ
|
2019-07-18 22:49:31 +02:00
|
|
|
call DISK.ReadFile, rax
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Assume that COMMAND.COM being
|
|
|
|
; less then 4KB means something
|
|
|
|
; went wrong
|
2019-08-03 21:11:12 +02:00
|
|
|
b.l rax, 0x1000, abort
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Close the handle
|
2019-07-18 22:49:31 +02:00
|
|
|
call DISK.CloseFile, rax
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Code address
|
|
|
|
mov ax2, 0x100000
|
2019-07-18 22:49:31 +02:00
|
|
|
call RFS.StoreReg, zero, $rip
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Usermode
|
|
|
|
mov ax2, 3
|
2019-07-18 22:49:31 +02:00
|
|
|
call RFS.StoreReg, zero, $cr0
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
mov rcx, CMDCOM_LOADP
|
2019-08-03 17:41:44 +02:00
|
|
|
dec rcx, 0x100000
|
2019-07-09 19:51:03 +02:00
|
|
|
|
2019-07-10 17:17:45 +02:00
|
|
|
; Code offset
|
|
|
|
mov ax2, rcx
|
2019-07-18 22:49:31 +02:00
|
|
|
call RFS.StoreReg, zero, $cr1
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Data offset
|
|
|
|
mov ax2, rcx
|
2019-07-18 22:49:31 +02:00
|
|
|
call RFS.StoreReg, zero, $cr2
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
; Return frame
|
2019-07-17 22:25:50 +02:00
|
|
|
mov q[rbp-16], zero
|
2019-07-10 17:17:45 +02:00
|
|
|
|
|
|
|
jmp .fini
|
|
|
|
|
|
|
|
.cmdcom = "command.com"
|
|
|
|
|
|
|
|
;
|
|
|
|
; Disk API
|
|
|
|
;
|
2019-07-10 12:26:15 +02:00
|
|
|
.handle_FindFirst:
|
2019-08-03 17:41:44 +02:00
|
|
|
inc ax0, r12
|
2019-07-10 12:26:15 +02:00
|
|
|
call DISK.FindFirst
|
2019-08-05 14:56:22 +02:00
|
|
|
jmp .fini.savecx
|
2019-07-10 12:26:15 +02:00
|
|
|
|
|
|
|
.handle_FindNext:
|
2019-08-03 17:41:44 +02:00
|
|
|
inc ax0, r12
|
2019-07-10 12:26:15 +02:00
|
|
|
call DISK.FindNext
|
2019-08-05 14:56:22 +02:00
|
|
|
jmp .fini.savecx
|
2019-07-09 19:51:03 +02:00
|
|
|
|
2019-07-13 12:38:03 +02:00
|
|
|
.handle_OpenFile:
|
2019-08-03 17:41:44 +02:00
|
|
|
inc ax0, r12
|
2019-07-13 12:38:03 +02:00
|
|
|
call DISK.OpenFile
|
|
|
|
jmp .fini
|
|
|
|
|
2019-08-05 14:56:22 +02:00
|
|
|
.handle_CreateFile:
|
|
|
|
inc ax0, r12
|
|
|
|
call DISK.CreateFile
|
|
|
|
jmp .fini
|
|
|
|
|
2019-07-13 12:38:03 +02:00
|
|
|
.handle_CloseFile:
|
|
|
|
call DISK.CloseFile
|
|
|
|
jmp .fini
|
|
|
|
|
|
|
|
.handle_ReadFile:
|
2019-08-03 17:41:44 +02:00
|
|
|
inc ax1, r12
|
2019-07-13 12:38:03 +02:00
|
|
|
call DISK.ReadFile
|
|
|
|
jmp .fini
|
|
|
|
|
2019-07-10 17:17:45 +02:00
|
|
|
;
|
|
|
|
; Misc.
|
|
|
|
;
|
2019-07-10 22:37:59 +02:00
|
|
|
.handle_Shutdown:
|
|
|
|
stop
|
|
|
|
|
2019-07-13 12:38:03 +02:00
|
|
|
.handle_HaltMode:
|
2019-07-24 16:52:26 +02:00
|
|
|
mov rcx, -1
|
|
|
|
hlt.rep
|
|
|
|
stop
|
2019-07-09 19:51:03 +02:00
|
|
|
|