1be769645SHuacai Chen/* SPDX-License-Identifier: GPL-2.0 */ 2be769645SHuacai Chen/* 3be769645SHuacai Chen * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 4be769645SHuacai Chen * 5be769645SHuacai Chen * Derived from MIPS: 6be769645SHuacai Chen * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle 7be769645SHuacai Chen * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 8be769645SHuacai Chen * Copyright (C) 2001 MIPS Technologies, Inc. 9be769645SHuacai Chen */ 10be769645SHuacai Chen 11be769645SHuacai Chen#include <asm/asm.h> 12be769645SHuacai Chen#include <asm/asmmacro.h> 13be769645SHuacai Chen#include <asm/loongarch.h> 14be769645SHuacai Chen#include <asm/regdef.h> 15be769645SHuacai Chen#include <asm/stackframe.h> 16be769645SHuacai Chen#include <asm/thread_info.h> 17*cb8a2ef0STiezhu Yang#include <asm/unwind_hints.h> 18be769645SHuacai Chen 19be769645SHuacai Chen .text 20be769645SHuacai Chen .cfi_sections .debug_frame 21be769645SHuacai Chen .align 5 2200c2ca84STiezhu YangSYM_CODE_START(handle_syscall) 23*cb8a2ef0STiezhu Yang UNWIND_HINT_UNDEFINED 24be769645SHuacai Chen csrrd t0, PERCPU_BASE_KS 25f733f119SXi Ruoyao la.pcrel t1, kernelsp 26be769645SHuacai Chen add.d t1, t1, t0 27be769645SHuacai Chen move t2, sp 28be769645SHuacai Chen ld.d sp, t1, 0 29be769645SHuacai Chen 30be769645SHuacai Chen addi.d sp, sp, -PT_SIZE 31be769645SHuacai Chen cfi_st t2, PT_R3 32be769645SHuacai Chen cfi_rel_offset sp, PT_R3 33be769645SHuacai Chen st.d zero, sp, PT_R0 34be769645SHuacai Chen csrrd t2, LOONGARCH_CSR_PRMD 35be769645SHuacai Chen st.d t2, sp, PT_PRMD 36be769645SHuacai Chen csrrd t2, LOONGARCH_CSR_CRMD 37be769645SHuacai Chen st.d t2, sp, PT_CRMD 38be769645SHuacai Chen csrrd t2, LOONGARCH_CSR_EUEN 39be769645SHuacai Chen st.d t2, sp, PT_EUEN 40be769645SHuacai Chen csrrd t2, LOONGARCH_CSR_ECFG 41be769645SHuacai Chen st.d t2, sp, PT_ECFG 42be769645SHuacai Chen csrrd t2, LOONGARCH_CSR_ESTAT 43be769645SHuacai Chen st.d t2, sp, PT_ESTAT 44be769645SHuacai Chen cfi_st ra, PT_R1 45be769645SHuacai Chen cfi_st a0, PT_R4 46be769645SHuacai Chen cfi_st a1, PT_R5 47be769645SHuacai Chen cfi_st a2, PT_R6 48be769645SHuacai Chen cfi_st a3, PT_R7 49be769645SHuacai Chen cfi_st a4, PT_R8 50be769645SHuacai Chen cfi_st a5, PT_R9 51be769645SHuacai Chen cfi_st a6, PT_R10 52be769645SHuacai Chen cfi_st a7, PT_R11 53be769645SHuacai Chen csrrd ra, LOONGARCH_CSR_ERA 54be769645SHuacai Chen st.d ra, sp, PT_ERA 55be769645SHuacai Chen cfi_rel_offset ra, PT_ERA 56be769645SHuacai Chen 57be769645SHuacai Chen cfi_st tp, PT_R2 58be769645SHuacai Chen cfi_st u0, PT_R21 59be769645SHuacai Chen cfi_st fp, PT_R22 60be769645SHuacai Chen 61be769645SHuacai Chen SAVE_STATIC 62*cb8a2ef0STiezhu Yang UNWIND_HINT_REGS 63be769645SHuacai Chen 64e14dd076SQing Zhang#ifdef CONFIG_KGDB 65e14dd076SQing Zhang li.w t1, CSR_CRMD_WE 66e14dd076SQing Zhang csrxchg t1, t1, LOONGARCH_CSR_CRMD 67e14dd076SQing Zhang#endif 68e14dd076SQing Zhang 69be769645SHuacai Chen move u0, t0 70be769645SHuacai Chen li.d tp, ~_THREAD_MASK 71be769645SHuacai Chen and tp, tp, sp 72be769645SHuacai Chen 73be769645SHuacai Chen move a0, sp 74be769645SHuacai Chen bl do_syscall 75be769645SHuacai Chen 76be769645SHuacai Chen RESTORE_ALL_AND_RET 7700c2ca84STiezhu YangSYM_CODE_END(handle_syscall) 78fcf77d01STiezhu Yang_ASM_NOKPROBE(handle_syscall) 79be769645SHuacai Chen 80be769645SHuacai ChenSYM_CODE_START(ret_from_fork) 81*cb8a2ef0STiezhu Yang UNWIND_HINT_REGS 82be769645SHuacai Chen bl schedule_tail # a0 = struct task_struct *prev 83be769645SHuacai Chen move a0, sp 84be769645SHuacai Chen bl syscall_exit_to_user_mode 85be769645SHuacai Chen RESTORE_STATIC 86be769645SHuacai Chen RESTORE_SOME 87be769645SHuacai Chen RESTORE_SP_AND_RET 88be769645SHuacai ChenSYM_CODE_END(ret_from_fork) 89be769645SHuacai Chen 90be769645SHuacai ChenSYM_CODE_START(ret_from_kernel_thread) 91*cb8a2ef0STiezhu Yang UNWIND_HINT_REGS 92be769645SHuacai Chen bl schedule_tail # a0 = struct task_struct *prev 93be769645SHuacai Chen move a0, s1 94be769645SHuacai Chen jirl ra, s0, 0 95be769645SHuacai Chen move a0, sp 96be769645SHuacai Chen bl syscall_exit_to_user_mode 97be769645SHuacai Chen RESTORE_STATIC 98be769645SHuacai Chen RESTORE_SOME 99be769645SHuacai Chen RESTORE_SP_AND_RET 100be769645SHuacai ChenSYM_CODE_END(ret_from_kernel_thread) 101