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/sys/intr/trap0.k
julianb0 3559d69b61
ka
2019-08-05 15:55:46 +02:00

140 lines
2.5 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:
call RFS.LoadReg, r14, $rax
call RFS.LoadArgs, r14
jmp.axz .handle_Shutdown
b.z rax, Sys.Exit, .handle_Exit
b.z rax, Sys.ReadFile, .handle_ReadFile
b.z rax, Sys.OpenFile, .handle_OpenFile
b.z rax, Sys.CloseFile, .handle_CloseFile
b.z rax, Sys.CreateFile, .handle_CreateFile
b.z rax, Sys.RemoveFile, .handle_RemoveFile
b.z rax, Sys.FindNext, .handle_FindNext
b.z rax, Sys.FindFirst, .handle_FindFirst
b.z rax, Sys.EnterHaltMode, .handle_HaltMode
mov rax, 1 << 63
mov rcx, 1 << 63
mov rdx, 1 << 63
.fini.savecx:
mov ax2, rcx
call RFS.StoreReg, r14, $rcx
.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
b.l rax, 0x1000, abort
; 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
dec 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:
inc ax0, r12
call DISK.FindFirst
jmp .fini.savecx
.handle_FindNext:
inc ax0, r12
call DISK.FindNext
jmp .fini.savecx
.handle_OpenFile:
inc ax0, r12
call DISK.OpenFile
jmp .fini
.handle_CreateFile:
inc ax0, r12
call DISK.CreateFile
jmp .fini
.handle_RemoveFile:
inc ax0, r12
call DISK.RemoveFile
jmp .fini
.handle_CloseFile:
call DISK.CloseFile
jmp .fini
.handle_ReadFile:
inc ax1, r12
call DISK.ReadFile
jmp .fini
;
; Misc.
;
.handle_Shutdown:
stop
.handle_HaltMode:
mov rcx, -1
hlt.rep
stop