1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
6 * -Moved core context switch macro out of entry.S into this file.
7 * -This is the more "natural" hand written assembler
10 #include <linux/linkage.h>
11 #include <asm/entry.h> /* For the SAVE_* macros */
12 #include <asm/asm-offsets.h>
14 #define KSP_WORD_OFF ((TASK_THREAD + THREAD_KSP) / 4)
16 ;################### Low Level Context Switch ##########################
18 .section .sched.text,"ax",@progbits
21 .type __switch_to, @function
25 /* Save regs on kernel mode stack of task */
28 SAVE_CALLEE_SAVED_KERNEL
30 /* Save the now KSP in task->thread.ksp */
31 #if KSP_WORD_OFF <= 255
32 st.as sp, [r0, KSP_WORD_OFF]
34 /* Workaround for NR_CPUS=4k as ST.as can only take s9 offset */
35 add2 r24, r0, KSP_WORD_OFF
39 * Return last task in r0 (return reg)
40 * On ARC, Return reg = First Arg reg = r0.
41 * Since we already have last task in r0,
42 * don't need to do anything special to return it
46 * switch to new task, contained in r1
47 * Temp reg r3 is required to get the ptr to store val
49 SET_CURR_TASK_ON_CPU r1, r3
51 /* reload SP with kernel mode stack pointer in task->thread.ksp */
52 ld.as sp, [r1, (TASK_THREAD + THREAD_KSP)/4]
54 /* restore the registers */
55 RESTORE_CALLEE_SAVED_KERNEL