2022-05-31 10:04:11 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
|
|
*
|
|
|
|
* Derived from MIPS:
|
|
|
|
* Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
|
|
|
|
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
|
|
|
|
* Copyright (C) 2001 MIPS Technologies, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/asmmacro.h>
|
|
|
|
#include <asm/loongarch.h>
|
|
|
|
#include <asm/regdef.h>
|
|
|
|
#include <asm/stackframe.h>
|
|
|
|
#include <asm/thread_info.h>
|
2024-03-11 14:23:47 +00:00
|
|
|
#include <asm/unwind_hints.h>
|
2022-05-31 10:04:11 +00:00
|
|
|
|
|
|
|
.text
|
|
|
|
.cfi_sections .debug_frame
|
|
|
|
.align 5
|
2023-10-18 00:42:52 +00:00
|
|
|
SYM_CODE_START(handle_syscall)
|
2024-03-11 14:23:47 +00:00
|
|
|
UNWIND_HINT_UNDEFINED
|
2023-02-25 07:52:56 +00:00
|
|
|
csrrd t0, PERCPU_BASE_KS
|
|
|
|
la.pcrel t1, kernelsp
|
|
|
|
add.d t1, t1, t0
|
|
|
|
move t2, sp
|
|
|
|
ld.d sp, t1, 0
|
2022-05-31 10:04:11 +00:00
|
|
|
|
2023-02-25 07:52:56 +00:00
|
|
|
addi.d sp, sp, -PT_SIZE
|
|
|
|
cfi_st t2, PT_R3
|
2022-07-26 15:57:22 +00:00
|
|
|
cfi_rel_offset sp, PT_R3
|
2023-02-25 07:52:56 +00:00
|
|
|
st.d zero, sp, PT_R0
|
|
|
|
csrrd t2, LOONGARCH_CSR_PRMD
|
|
|
|
st.d t2, sp, PT_PRMD
|
|
|
|
csrrd t2, LOONGARCH_CSR_CRMD
|
|
|
|
st.d t2, sp, PT_CRMD
|
|
|
|
csrrd t2, LOONGARCH_CSR_EUEN
|
|
|
|
st.d t2, sp, PT_EUEN
|
|
|
|
csrrd t2, LOONGARCH_CSR_ECFG
|
|
|
|
st.d t2, sp, PT_ECFG
|
|
|
|
csrrd t2, LOONGARCH_CSR_ESTAT
|
|
|
|
st.d t2, sp, PT_ESTAT
|
|
|
|
cfi_st ra, PT_R1
|
|
|
|
cfi_st a0, PT_R4
|
|
|
|
cfi_st a1, PT_R5
|
|
|
|
cfi_st a2, PT_R6
|
|
|
|
cfi_st a3, PT_R7
|
|
|
|
cfi_st a4, PT_R8
|
|
|
|
cfi_st a5, PT_R9
|
|
|
|
cfi_st a6, PT_R10
|
|
|
|
cfi_st a7, PT_R11
|
|
|
|
csrrd ra, LOONGARCH_CSR_ERA
|
|
|
|
st.d ra, sp, PT_ERA
|
2022-07-26 15:57:22 +00:00
|
|
|
cfi_rel_offset ra, PT_ERA
|
2022-05-31 10:04:11 +00:00
|
|
|
|
2023-02-25 07:52:56 +00:00
|
|
|
cfi_st tp, PT_R2
|
|
|
|
cfi_st u0, PT_R21
|
|
|
|
cfi_st fp, PT_R22
|
2022-05-31 10:04:11 +00:00
|
|
|
|
|
|
|
SAVE_STATIC
|
2024-03-11 14:23:47 +00:00
|
|
|
UNWIND_HINT_REGS
|
2022-05-31 10:04:11 +00:00
|
|
|
|
2023-09-06 14:53:55 +00:00
|
|
|
#ifdef CONFIG_KGDB
|
|
|
|
li.w t1, CSR_CRMD_WE
|
|
|
|
csrxchg t1, t1, LOONGARCH_CSR_CRMD
|
|
|
|
#endif
|
|
|
|
|
2023-02-25 07:52:56 +00:00
|
|
|
move u0, t0
|
|
|
|
li.d tp, ~_THREAD_MASK
|
|
|
|
and tp, tp, sp
|
2022-05-31 10:04:11 +00:00
|
|
|
|
2023-02-25 07:52:56 +00:00
|
|
|
move a0, sp
|
|
|
|
bl do_syscall
|
2022-05-31 10:04:11 +00:00
|
|
|
|
|
|
|
RESTORE_ALL_AND_RET
|
2023-10-18 00:42:52 +00:00
|
|
|
SYM_CODE_END(handle_syscall)
|
2023-02-25 07:52:57 +00:00
|
|
|
_ASM_NOKPROBE(handle_syscall)
|
2022-05-31 10:04:11 +00:00
|
|
|
|
|
|
|
SYM_CODE_START(ret_from_fork)
|
2024-03-11 14:23:47 +00:00
|
|
|
UNWIND_HINT_REGS
|
2023-02-25 07:52:56 +00:00
|
|
|
bl schedule_tail # a0 = struct task_struct *prev
|
|
|
|
move a0, sp
|
|
|
|
bl syscall_exit_to_user_mode
|
2022-05-31 10:04:11 +00:00
|
|
|
RESTORE_STATIC
|
|
|
|
RESTORE_SOME
|
|
|
|
RESTORE_SP_AND_RET
|
|
|
|
SYM_CODE_END(ret_from_fork)
|
|
|
|
|
|
|
|
SYM_CODE_START(ret_from_kernel_thread)
|
2024-03-11 14:23:47 +00:00
|
|
|
UNWIND_HINT_REGS
|
2023-02-25 07:52:56 +00:00
|
|
|
bl schedule_tail # a0 = struct task_struct *prev
|
|
|
|
move a0, s1
|
|
|
|
jirl ra, s0, 0
|
|
|
|
move a0, sp
|
|
|
|
bl syscall_exit_to_user_mode
|
2022-05-31 10:04:11 +00:00
|
|
|
RESTORE_STATIC
|
|
|
|
RESTORE_SOME
|
|
|
|
RESTORE_SP_AND_RET
|
|
|
|
SYM_CODE_END(ret_from_kernel_thread)
|