mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
133 lines
2.3 KiB
Plaintext
133 lines
2.3 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.
|
|
|
|
trap0_handler:
|
|
|
|
.init:
|
|
mov rcx, .text
|
|
mov rsp, TRAP0_STACK
|
|
jmp TrapHandlers.prolog
|
|
|
|
.text:
|
|
mov ax0, r14
|
|
mov ax1, $rax
|
|
call RFS.LoadReg
|
|
call RFS.LoadArgs
|
|
|
|
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
|
|
|
|
;------------------------------------------------;
|
|
; Syscall implementations ;
|
|
;------------------------------------------------;
|
|
|
|
;
|
|
; Pass control to COMMAND.COM in frame 0
|
|
;
|
|
.handle_Exit:
|
|
|
|
; Open COMMAND.COM
|
|
call DISK.OpenFile, .cmdcom
|
|
|
|
; Crash on failure
|
|
cmp rax, zero
|
|
crash.l
|
|
|
|
; Load at CMDCOM_LOADP
|
|
mov ax1, CMDCOM_LOADP
|
|
mov ax2, CMDCOM_MAXSZ
|
|
call DISK.ReadFile, rax
|
|
|
|
; Assume that COMMAND.COM being
|
|
; less then 4KB means something
|
|
; went wrong
|
|
cmp rax, 0x1000
|
|
crash.b
|
|
|
|
; Close the handle
|
|
call DISK.CloseFile, rax
|
|
|
|
; Code address
|
|
mov ax2, 0x100000
|
|
call RFS.StoreReg, zero, $rip
|
|
|
|
; Usermode
|
|
mov ax2, 3
|
|
call RFS.StoreReg, zero, $cr0
|
|
|
|
mov rcx, CMDCOM_LOADP
|
|
sub rcx, rcx, 0x100000
|
|
|
|
; Code offset
|
|
mov ax2, rcx
|
|
call RFS.StoreReg, zero, $cr1
|
|
|
|
; Data offset
|
|
mov ax2, rcx
|
|
call RFS.StoreReg, zero, $cr2
|
|
|
|
; Return frame
|
|
mov q[rbp-16], zero
|
|
|
|
jmp .fini
|
|
|
|
.cmdcom = "command.com"
|
|
|
|
;
|
|
; Disk API
|
|
;
|
|
.handle_FindFirst:
|
|
add ax0, ax0, r12
|
|
call DISK.FindFirst
|
|
jmp .fini
|
|
|
|
.handle_FindNext:
|
|
add ax0, ax0, r12
|
|
call DISK.FindNext
|
|
jmp .fini
|
|
|
|
.handle_OpenFile:
|
|
add ax0, ax0, r12
|
|
call DISK.OpenFile
|
|
jmp .fini
|
|
|
|
.handle_CloseFile:
|
|
call DISK.CloseFile
|
|
jmp .fini
|
|
|
|
.handle_ReadFile:
|
|
add ax1, ax1, r12
|
|
call DISK.ReadFile
|
|
jmp .fini
|
|
|
|
;
|
|
; Misc.
|
|
;
|
|
.handle_Shutdown:
|
|
mov r12, zero
|
|
stop
|
|
|
|
.handle_HaltMode:
|
|
hlt
|
|
.HLT.loop:
|
|
pause
|
|
pause
|
|
pause
|
|
|
|
scan rax
|
|
b.z rax, zero, .HLT.loop
|
|
|
|
prn rax
|
|
jmp .HLT.loop
|
|
|