X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Fproc.asm;h=e6db3ce23d211d52aeac45f718101c149385d69f;hb=d01b7e1a4924a41a5219eedfd2f6d32b310368cd;hp=541abd6cb6790210e5ceb721c8439426a6d8ef69;hpb=3d0a53a04f9f156147db11a09c70046484926570;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/proc.asm b/Kernel/arch/x86_64/proc.asm index 541abd6c..e6db3ce2 100644 --- a/Kernel/arch/x86_64/proc.asm +++ b/Kernel/arch/x86_64/proc.asm @@ -47,26 +47,84 @@ NewTaskHeader: .hlt: jmp .hlt +[extern MM_Clone] +[extern MM_DumpTables] +[global Proc_CloneInt] +Proc_CloneInt: + PUSH_GPR + ; Save RSP + mov [rdi], rsp + call MM_Clone + ; Save CR3 + mov rsi, [rsp+0x30] ; Saved version of RSI + mov [rsi], rax + ; Undo the PUSH_GPR + add rsp, 0x80 + mov rax, .newTask + ret +.newTask: +; mov rdi, 0 +; mov rsi, 0x800000000000 +; call MM_DumpTables + POP_GPR + xor eax, eax + ret + [global SaveState] SaveState: ; Save regs to RSI - xchg bx, bx add rsi, 0x80 SAVE_GPR rsi - sub rsi, 0x80 + ; Save return addr + mov rax, [rsp] + mov [rsi], rax ; Return RSI as the RSP value + sub rsi, 0x80 mov [rdi], rsi - call GetRIP - cmp eax, 0x80000000 - ja .fastret + ; Check for + mov rax, .restore + ret .restore: - ; RSP = RSI from call - xchg bx, bx + ; RSP = RSI now POP_GPR + mov rax, [rsp] mov rsp, [rsp-0x60] ; Restore RSP from the saved value + mov [rsp], rax ; Restore return address xor eax, eax ret -.fastret: - ; RAX is still the return addr - ret + +[global SwitchTasks] +; rdi = New RSP +; rsi = Old RSP save loc +; rdx = New RIP +; rcx = Old RIP save loc +; r8 = CR3 +SwitchTasks: + PUSH_GPR + + ; Save state RIP and RSP + lea rax, [rel .restore] + mov [rcx], rax + mov [rsi], rsp + + ; Change CR3 if requested + test r8, r8 + jz .setState + mov cr3, r8 + + ; Make sure the stack is valid before jumping + invlpg [rdi] + invlpg [rdi+0x1000] + ; Go to new state +.setState: + mov rsp, rdi + jmp rdx + + ; Restore point for saved state +.restore: + POP_GPR + xor eax, eax ; Return zero + ret + +; vim: ft=nasm