xref: /OK3568_Linux_fs/kernel/arch/nios2/include/asm/switch_to.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2004 Microtronix Datacom Ltd.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
5*4882a593Smuzhiyun  * License. See the file "COPYING" in the main directory of this archive
6*4882a593Smuzhiyun  * for more details.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef _ASM_NIOS2_SWITCH_TO_H
9*4882a593Smuzhiyun #define _ASM_NIOS2_SWITCH_TO_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun  * switch_to(n) should switch tasks to task ptr, first checking that
13*4882a593Smuzhiyun  * ptr isn't the current task, in which case it does nothing.  This
14*4882a593Smuzhiyun  * also clears the TS-flag if the task we switched to has used the
15*4882a593Smuzhiyun  * math co-processor latest.
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun #define switch_to(prev, next, last)			\
18*4882a593Smuzhiyun {							\
19*4882a593Smuzhiyun 	void *_last;					\
20*4882a593Smuzhiyun 	__asm__ __volatile__ (				\
21*4882a593Smuzhiyun 		"mov	r4, %1\n"			\
22*4882a593Smuzhiyun 		"mov	r5, %2\n"			\
23*4882a593Smuzhiyun 		"call	resume\n"			\
24*4882a593Smuzhiyun 		"mov	%0,r4\n"			\
25*4882a593Smuzhiyun 		: "=r" (_last)				\
26*4882a593Smuzhiyun 		: "r" (prev), "r" (next)		\
27*4882a593Smuzhiyun 		: "r4", "r5", "r7", "r8", "ra");	\
28*4882a593Smuzhiyun 	(last) = _last;					\
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #endif /* _ASM_NIOS2_SWITCH_TO_H */
32