2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-01-18 17:42:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*
|
|
|
|
* Vineetg: Aug 2009
|
|
|
|
* -"C" version of lowest level context switch asm macro called by schedular
|
|
|
|
* gcc doesn't generate the dward CFI info for hand written asm, hence can't
|
|
|
|
* backtrace out of it (e.g. tasks sleeping in kernel).
|
|
|
|
* So we cheat a bit by writing almost similar code in inline-asm.
|
|
|
|
* -This is a hacky way of doing things, but there is no other simple way.
|
|
|
|
* I don't want/intend to extend unwinding code to understand raw asm
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-09 01:51:35 +08:00
|
|
|
#include <linux/sched/debug.h>
|
2013-06-03 20:17:25 +08:00
|
|
|
#ifdef CONFIG_ARC_PLAT_EZNPS
|
|
|
|
#include <plat/ctop.h>
|
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
|
2013-11-01 13:16:40 +08:00
|
|
|
#define KSP_WORD_OFF ((TASK_THREAD + THREAD_KSP) / 4)
|
|
|
|
|
2013-01-18 17:42:18 +08:00
|
|
|
struct task_struct *__sched
|
|
|
|
__switch_to(struct task_struct *prev_task, struct task_struct *next_task)
|
|
|
|
{
|
|
|
|
unsigned int tmp;
|
|
|
|
unsigned int prev = (unsigned int)prev_task;
|
|
|
|
unsigned int next = (unsigned int)next_task;
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
/* FP/BLINK save generated by gcc (standard function prologue */
|
|
|
|
"st.a r13, [sp, -4] \n\t"
|
|
|
|
"st.a r14, [sp, -4] \n\t"
|
|
|
|
"st.a r15, [sp, -4] \n\t"
|
|
|
|
"st.a r16, [sp, -4] \n\t"
|
|
|
|
"st.a r17, [sp, -4] \n\t"
|
|
|
|
"st.a r18, [sp, -4] \n\t"
|
|
|
|
"st.a r19, [sp, -4] \n\t"
|
|
|
|
"st.a r20, [sp, -4] \n\t"
|
|
|
|
"st.a r21, [sp, -4] \n\t"
|
|
|
|
"st.a r22, [sp, -4] \n\t"
|
|
|
|
"st.a r23, [sp, -4] \n\t"
|
|
|
|
"st.a r24, [sp, -4] \n\t"
|
2013-02-11 22:22:57 +08:00
|
|
|
#ifndef CONFIG_ARC_CURR_IN_REG
|
2013-01-18 17:42:18 +08:00
|
|
|
"st.a r25, [sp, -4] \n\t"
|
2013-05-28 00:13:41 +08:00
|
|
|
#else
|
|
|
|
"sub sp, sp, 4 \n\t" /* usual r25 placeholder */
|
2013-02-11 22:22:57 +08:00
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
|
|
|
|
/* set ksp of outgoing task in tsk->thread.ksp */
|
2013-11-01 13:16:40 +08:00
|
|
|
#if KSP_WORD_OFF <= 255
|
2013-01-18 17:42:18 +08:00
|
|
|
"st.as sp, [%3, %1] \n\t"
|
2013-11-01 13:16:40 +08:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Workaround for NR_CPUS=4k
|
|
|
|
* %1 is bigger than 255 (S9 offset for st.as)
|
|
|
|
*/
|
|
|
|
"add2 r24, %3, %1 \n\t"
|
|
|
|
"st sp, [r24] \n\t"
|
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* setup _current_task with incoming tsk.
|
|
|
|
* optionally, set r25 to that as well
|
|
|
|
* For SMP extra work to get to &_current_task[cpu]
|
|
|
|
* (open coded SET_CURR_TASK_ON_CPU)
|
|
|
|
*/
|
2013-01-18 17:42:23 +08:00
|
|
|
#ifndef CONFIG_SMP
|
2013-01-18 17:42:18 +08:00
|
|
|
"st %2, [@_current_task] \n\t"
|
2013-06-03 20:17:25 +08:00
|
|
|
#else
|
|
|
|
#ifdef CONFIG_ARC_PLAT_EZNPS
|
|
|
|
"lr r24, [%4] \n\t"
|
|
|
|
#ifndef CONFIG_EZNPS_MTM_EXT
|
|
|
|
"lsr r24, r24, 4 \n\t"
|
|
|
|
#endif
|
2013-01-18 17:42:23 +08:00
|
|
|
#else
|
|
|
|
"lr r24, [identity] \n\t"
|
|
|
|
"lsr r24, r24, 8 \n\t"
|
|
|
|
"bmsk r24, r24, 7 \n\t"
|
2013-06-03 20:17:25 +08:00
|
|
|
#endif
|
2013-01-18 17:42:23 +08:00
|
|
|
"add2 r24, @_current_task, r24 \n\t"
|
|
|
|
"st %2, [r24] \n\t"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARC_CURR_IN_REG
|
|
|
|
"mov r25, %2 \n\t"
|
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
|
|
|
|
/* get ksp of incoming task from tsk->thread.ksp */
|
|
|
|
"ld.as sp, [%2, %1] \n\t"
|
|
|
|
|
|
|
|
/* start loading it's CALLEE reg file */
|
|
|
|
|
2013-02-11 22:22:57 +08:00
|
|
|
#ifndef CONFIG_ARC_CURR_IN_REG
|
2013-01-18 17:42:18 +08:00
|
|
|
"ld.ab r25, [sp, 4] \n\t"
|
2013-05-28 00:13:41 +08:00
|
|
|
#else
|
|
|
|
"add sp, sp, 4 \n\t"
|
2013-02-11 22:22:57 +08:00
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
"ld.ab r24, [sp, 4] \n\t"
|
|
|
|
"ld.ab r23, [sp, 4] \n\t"
|
|
|
|
"ld.ab r22, [sp, 4] \n\t"
|
|
|
|
"ld.ab r21, [sp, 4] \n\t"
|
|
|
|
"ld.ab r20, [sp, 4] \n\t"
|
|
|
|
"ld.ab r19, [sp, 4] \n\t"
|
|
|
|
"ld.ab r18, [sp, 4] \n\t"
|
|
|
|
"ld.ab r17, [sp, 4] \n\t"
|
|
|
|
"ld.ab r16, [sp, 4] \n\t"
|
|
|
|
"ld.ab r15, [sp, 4] \n\t"
|
|
|
|
"ld.ab r14, [sp, 4] \n\t"
|
|
|
|
"ld.ab r13, [sp, 4] \n\t"
|
|
|
|
|
|
|
|
/* last (ret value) = prev : although for ARC it mov r0, r0 */
|
|
|
|
"mov %0, %3 \n\t"
|
|
|
|
|
|
|
|
/* FP/BLINK restore generated by gcc (standard func epilogue */
|
|
|
|
|
|
|
|
: "=r"(tmp)
|
2013-11-01 13:16:40 +08:00
|
|
|
: "n"(KSP_WORD_OFF), "r"(next), "r"(prev)
|
2013-06-03 20:17:25 +08:00
|
|
|
#ifdef CONFIG_ARC_PLAT_EZNPS
|
|
|
|
, "i"(CTOP_AUX_LOGIC_GLOBAL_ID)
|
|
|
|
#endif
|
2013-01-18 17:42:18 +08:00
|
|
|
: "blink"
|
|
|
|
);
|
|
|
|
|
|
|
|
return (struct task_struct *)tmp;
|
|
|
|
}
|