• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License.  See the file "COPYING" in the main directory of this archive
5 * for more details.
6 *
7 * Copyright (C) 2020 Loongson Technology Corporation Limited
8 */
9#include <asm/asm.h>
10#include <asm/loongarchregs.h>
11#include <asm/asm-offsets.h>
12#include <asm/regdef.h>
13#include <asm/stackframe.h>
14#include <asm/thread_info.h>
15
16#include <asm/asmmacro.h>
17
18/*
19 * task_struct *__switch_to(task_struct *prev, task_struct *next,
20 *			    struct thread_info *next_ti,
21 *			    void *sched_ra, void *sched_cfa)
22 */
23	.align	5
24SYM_FUNC_START(__switch_to)
25	csrrd	t1, LOONGARCH_CSR_PRMD
26	stptr.d	t1, a0, THREAD_CSRPRMD
27
28	cpu_save_nonscratch a0
29	stptr.d	ra, a0, THREAD_REG01
30	stptr.d a3, a0, THREAD_SCHED_RA
31	stptr.d a4, a0, THREAD_SCHED_CFA
32#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
33	la	t7, __stack_chk_guard
34	LONG_L	t8, a1, TASK_STACK_CANARY
35	LONG_S	t8, t7, 0
36#endif
37	move	tp, a2
38	cpu_restore_nonscratch a1
39
40	li.w	t0, _THREAD_SIZE
41	PTR_ADD	t0, t0, tp
42	set_saved_sp	t0, t1, t2
43
44	ldptr.d	t1, a1, THREAD_CSRPRMD
45	csrwr	t1, LOONGARCH_CSR_PRMD
46
47	jr	ra
48SYM_FUNC_END(__switch_to)
49