; 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, r12 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 mov ax0, .cmdcom call DISK.OpenFile ; Crash on failure cmp rax, zero crash.l ; Load at CMDCOM_LOADP mov ax0, rax mov ax1, CMDCOM_LOADP mov ax2, CMDCOM_MAXSZ call DISK.ReadFile ; Assume that COMMAND.COM being ; less then 4KB means something ; went wrong cmp rax, 0x1000 crash.b ; Close the handle mov ax0, rax call DISK.CloseFile ; Code address mov ax0, zero mov ax1, $rip mov ax2, 0x100000 call RFS.StoreReg ; Usermode mov ax1, $cr0 mov ax2, 3 call RFS.StoreReg mov rcx, CMDCOM_LOADP sub rcx, rcx, 0x100000 ; Code offset mov ax1, $cr1 mov ax2, rcx call RFS.StoreReg ; Data offset mov ax1, $cr2 mov ax2, rcx call RFS.StoreReg ; Return frame mov q[rbp-16], zero jmp .fini .cmdcom = "command.com" ; ; Disk API ; .handle_FindFirst: add ax0, ax0, nx0 call DISK.FindFirst jmp .fini .handle_FindNext: add ax0, ax0, nx0 call DISK.FindNext jmp .fini .handle_OpenFile: add ax0, ax0, nx0 call DISK.OpenFile jmp .fini .handle_CloseFile: call DISK.CloseFile jmp .fini .handle_ReadFile: add ax1, ax0, nx0 call DISK.ReadFile jmp .fini ; ; Misc. ; .handle_Shutdown: mov nx0, zero stop .handle_HaltMode: hlt .HLT.loop: xpause scan rax b.z rax, zero, .HLT.loop prn rax jmp .HLT.loop