218 lines
4 KiB
ArmAsm
218 lines
4 KiB
ArmAsm
/* 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
|
|
|
|
.macro exception nr
|
|
.global _exception_\nr
|
|
_exception_\nr:
|
|
push 0
|
|
push \nr
|
|
jmp exception_common
|
|
.endm
|
|
|
|
.macro exception_err nr
|
|
.global _exception_\nr
|
|
_exception_\nr:
|
|
push \nr
|
|
jmp exception_common
|
|
.endm
|
|
|
|
.macro irq nr
|
|
.global _irq_\nr
|
|
_irq_\nr:
|
|
push \nr
|
|
jmp irq_common
|
|
.endm
|
|
|
|
exception_common:
|
|
test qword ptr [rsp + 24], 3 /* is this from userspace? */
|
|
jz 1f
|
|
swapgs
|
|
1:
|
|
push_all /* pushes 15 registers */
|
|
mov rdi, [rsp + 120] /* vector: 15 regs up = 120 */
|
|
mov rsi, [rsp + 128] /* error code we pushed in the macro */
|
|
|
|
/* we skip storing the user stack in these interrupt entries because
|
|
* the iretq frame stores it
|
|
*/
|
|
|
|
call exception_handler
|
|
pop_all
|
|
test qword ptr [rsp + 24], 3 /* from userspace? */
|
|
jz 2f
|
|
swapgs
|
|
2:
|
|
add rsp, 16 /* the two pushed items, from the macro */
|
|
iretq
|
|
|
|
/* same as exception_common, but we don't get the error code */
|
|
irq_common:
|
|
test qword ptr [rsp + 24], 3 /* is this from userspace? */
|
|
jz 1f
|
|
swapgs
|
|
1:
|
|
push_all /* pushes 15 registers */
|
|
mov rdi, [rsp + 120] /* irq no */
|
|
|
|
call irq_handler
|
|
pop_all
|
|
test qword ptr [rsp + 24], 3 /* from userspace? */
|
|
jz 2f
|
|
swapgs
|
|
2:
|
|
add rsp, 8
|
|
iretq
|
|
|
|
.global sched_save_state
|
|
sched_save_state:
|
|
push_all
|
|
mov [rdi + 8], rsp /* save RSP to thread->kstack_ptr */
|
|
ret
|
|
|
|
.global sched_restore_state
|
|
sched_restore_state:
|
|
mov rsp, [rdi + 8] /* load RSP from thread->kstack_ptr */
|
|
pop_all
|
|
ret
|
|
|
|
.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 qword ptr gs:[16] /* save user RSP */
|
|
push_all
|
|
|
|
mov rdi, rsp
|
|
call syscall
|
|
/* restore registers */
|
|
pop_all
|
|
pop rsp
|
|
|
|
swapgs
|
|
sysretq
|
|
|
|
/* return path after a process was execed */
|
|
.global _enter_userspace_init
|
|
_enter_userspace_init:
|
|
mov rcx, rdi
|
|
mov r11, rsi
|
|
mov rsp, rdx
|
|
|
|
xor rax, rax
|
|
xor rbx, rbx
|
|
xor rdx, rdx
|
|
xor rdi, rdi
|
|
xor rsi, rsi
|
|
xor rbp, rbp
|
|
xor r8, r8
|
|
xor r9, r9
|
|
xor r10, r10
|
|
xor r12, r12
|
|
xor r13, r13
|
|
xor r14, r14
|
|
xor r15, r15
|
|
|
|
swapgs
|
|
|
|
sysretq
|
|
|
|
/* set as entrypoint for a new process that was just forked */
|
|
.global fork_trampoline
|
|
fork_trampoline:
|
|
mov rsp, rdx
|
|
swapgs
|
|
sysretq
|
|
|
|
|
|
/* 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
|