; 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 rbp, TRAP0_STACK jmp TrapHandlers.prolog .text: mov ax0, r12 mov ax1, $rax call RFS.LoadReg call RFS.LoadArgs b.z rax, Sys.HLT, .handle_HLT 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 .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, 0 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 xor ax0, ax0 mov ax1, $rip mov ax2, 0x100000 call RFS.StoreReg ; No flags set mov ax1, $rfx xor ax2, ax2 call RFS.StoreReg ; Usermode mov ax1, $cr0 mov ax2, 3 call RFS.StoreReg mov rcx, CMDCOM_LOADP sub 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], 0 jmp .fini .cmdcom = "command.com" ; ; Disk API ; .handle_FindFirst: add ax0, nx0 call DISK.FindFirst jmp .fini .handle_FindNext: add ax0, nx0 call DISK.FindNext jmp .fini ; ; Misc. ; .handle_Shutdown: stop .handle_HLT: hlt .HLT.loop: xpause scan rax b.z rax, 0, .HLT.loop prn rax jmp .HLT.loop