proc: add context switching
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
c01b1d7eee
commit
a73fc47664
4 changed files with 46 additions and 17 deletions
|
|
@ -1,6 +1,42 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
.intel_syntax noprefix
|
||||
|
||||
.macro push_all
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rbp
|
||||
push rsi
|
||||
push rdi
|
||||
push rdx
|
||||
push rcx
|
||||
push rbx
|
||||
push rax
|
||||
.endm
|
||||
|
||||
.macro pop_all
|
||||
pop rax
|
||||
pop rbx
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rbp
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
.endm
|
||||
|
||||
.global _syscall_enter
|
||||
_syscall_enter:
|
||||
swapgs
|
||||
|
|
@ -9,40 +45,25 @@ _syscall_enter:
|
|||
/* load kernel stack */
|
||||
mov rsp, gs:[8]
|
||||
|
||||
/* save registers */
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rsi
|
||||
push rdi
|
||||
push rdx
|
||||
push rbx
|
||||
push rax
|
||||
/* save registers into struct pt_regs */
|
||||
push gs:[16] /* save user RSP */
|
||||
push_all
|
||||
|
||||
mov rdi, rsp
|
||||
call syscall
|
||||
|
||||
/* restore registers */
|
||||
pop rax
|
||||
pop rbx
|
||||
pop rdx
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
|
||||
/* restore user stack */
|
||||
mov rsp, gs:[16]
|
||||
pop_all
|
||||
add rsp, 8
|
||||
mov rsp, [rsp] /* load user RSP */
|
||||
|
||||
swapgs
|
||||
sysretq
|
||||
|
||||
.global switch_to
|
||||
switch_to:
|
||||
push_all
|
||||
/* 8: struct thread stack_addr offset */
|
||||
mov [rdi + 8], rsp
|
||||
mov rsp, [rsi + 8]
|
||||
pop_all
|
||||
ret
|
||||
|
|
|
|||
Loading…
Reference in a new issue