152 lines
2.4 KiB
ArmAsm
152 lines
2.4 KiB
ArmAsm
/* SPDX-License-Identifier: GPL-2.0 */
|
|
.intel_syntax noprefix
|
|
|
|
#define THREAD_RSP_OFF 8
|
|
|
|
.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
|
|
|
|
.macro gen_irq_entry name
|
|
.global \name
|
|
\name:
|
|
test qword ptr [rsp + 8], 3
|
|
jz 1f
|
|
swapgs
|
|
1:
|
|
.endm
|
|
|
|
.macro exception nr
|
|
gen_irq_entry _exception_\nr
|
|
mov rdi, \nr
|
|
call exception_handler
|
|
iretq
|
|
.endm
|
|
|
|
.macro exception_err nr
|
|
gen_irq_entry _exception_\nr
|
|
mov rdi, \nr
|
|
pop rsi
|
|
iretq
|
|
.endm
|
|
|
|
.macro irq nr
|
|
gen_irq_entry _irq_\nr
|
|
mov rdi, \nr
|
|
call irq_handler
|
|
iretq
|
|
.endm
|
|
|
|
.global _syscall_enter
|
|
_syscall_enter:
|
|
swapgs
|
|
|
|
/* save user stack */
|
|
mov gs:[16], rsp
|
|
/* load kernel stack */
|
|
mov rsp, gs:[8]
|
|
|
|
/* save registers into struct pt_regs */
|
|
push gs:[16] /* save user RSP */
|
|
push_all
|
|
|
|
mov rdi, rsp
|
|
call syscall
|
|
/* restore registers */
|
|
pop_all
|
|
add rsp, 8
|
|
mov rsp, [rsp] /* load user RSP */
|
|
|
|
swapgs
|
|
sysretq
|
|
|
|
.global switch_to
|
|
switch_to:
|
|
push_all
|
|
mov [rdi + THREAD_RSP_OFF], rsp
|
|
mov rsp, [rsi + THREAD_RSP_OFF]
|
|
pop_all
|
|
ret
|
|
|
|
/* exceptions */
|
|
exception 0x00
|
|
exception 0x01
|
|
exception 0x02
|
|
exception 0x03
|
|
exception 0x04
|
|
exception 0x05
|
|
exception 0x06
|
|
exception 0x07
|
|
exception_err 0x08
|
|
exception 0x09
|
|
exception_err 0x0A
|
|
exception_err 0x0B
|
|
exception_err 0x0C
|
|
exception_err 0x0D
|
|
exception_err 0x0E
|
|
exception 0x0F
|
|
exception 0x10
|
|
exception_err 0x11
|
|
exception 0x12
|
|
exception 0x13
|
|
exception 0x14
|
|
exception_err 0x15
|
|
exception 0x16
|
|
exception 0x17
|
|
exception 0x18
|
|
exception 0x19
|
|
exception 0x1A
|
|
exception 0x1B
|
|
exception 0x1C
|
|
exception_err 0x1D
|
|
exception_err 0x1E
|
|
exception 0x1F
|
|
|
|
irq 0x00
|
|
irq 0x01
|
|
irq 0x02
|
|
irq 0x03
|
|
irq 0x04
|
|
irq 0x05
|
|
irq 0x06
|
|
irq 0x07
|
|
irq 0x08
|
|
irq 0x09
|
|
irq 0x0A
|
|
irq 0x0B
|
|
irq 0x0C
|
|
irq 0x0D
|
|
irq 0x0E
|
|
irq 0x0F
|