xref: /linux/arch/sh/include/asm/switch_to_32.h (revision b2441318)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2e839ca52SDavid Howells #ifndef __ASM_SH_SWITCH_TO_32_H
3e839ca52SDavid Howells #define __ASM_SH_SWITCH_TO_32_H
4e839ca52SDavid Howells 
5e839ca52SDavid Howells #ifdef CONFIG_SH_DSP
6e839ca52SDavid Howells 
7e839ca52SDavid Howells #define is_dsp_enabled(tsk)						\
8e839ca52SDavid Howells 	(!!(tsk->thread.dsp_status.status & SR_DSP))
9e839ca52SDavid Howells 
10e839ca52SDavid Howells #define __restore_dsp(tsk)						\
11e839ca52SDavid Howells do {									\
12e839ca52SDavid Howells 	register u32 *__ts2 __asm__ ("r2") =				\
13e839ca52SDavid Howells 			(u32 *)&tsk->thread.dsp_status;			\
14e839ca52SDavid Howells 	__asm__ __volatile__ (						\
15e839ca52SDavid Howells 		".balign 4\n\t"						\
16e839ca52SDavid Howells 		"movs.l	@r2+, a0\n\t"					\
17e839ca52SDavid Howells 		"movs.l	@r2+, a1\n\t"					\
18e839ca52SDavid Howells 		"movs.l	@r2+, a0g\n\t"					\
19e839ca52SDavid Howells 		"movs.l	@r2+, a1g\n\t"					\
20e839ca52SDavid Howells 		"movs.l	@r2+, m0\n\t"					\
21e839ca52SDavid Howells 		"movs.l	@r2+, m1\n\t"					\
22e839ca52SDavid Howells 		"movs.l	@r2+, x0\n\t"					\
23e839ca52SDavid Howells 		"movs.l	@r2+, x1\n\t"					\
24e839ca52SDavid Howells 		"movs.l	@r2+, y0\n\t"					\
25e839ca52SDavid Howells 		"movs.l	@r2+, y1\n\t"					\
26e839ca52SDavid Howells 		"lds.l	@r2+, dsr\n\t"					\
27e839ca52SDavid Howells 		"ldc.l	@r2+, rs\n\t"					\
28e839ca52SDavid Howells 		"ldc.l	@r2+, re\n\t"					\
29e839ca52SDavid Howells 		"ldc.l	@r2+, mod\n\t"					\
30e839ca52SDavid Howells 		: : "r" (__ts2));					\
31e839ca52SDavid Howells } while (0)
32e839ca52SDavid Howells 
33e839ca52SDavid Howells #define __save_dsp(tsk)							\
34e839ca52SDavid Howells do {									\
35e839ca52SDavid Howells 	register u32 *__ts2 __asm__ ("r2") =				\
36e839ca52SDavid Howells 			(u32 *)&tsk->thread.dsp_status + 14;		\
37e839ca52SDavid Howells 									\
38e839ca52SDavid Howells 	__asm__ __volatile__ (						\
39e839ca52SDavid Howells 		".balign 4\n\t"						\
40e839ca52SDavid Howells 		"stc.l	mod, @-r2\n\t"					\
41e839ca52SDavid Howells 		"stc.l	re, @-r2\n\t"					\
42e839ca52SDavid Howells 		"stc.l	rs, @-r2\n\t"					\
43e839ca52SDavid Howells 		"sts.l	dsr, @-r2\n\t"					\
44e839ca52SDavid Howells 		"movs.l	y1, @-r2\n\t"					\
45e839ca52SDavid Howells 		"movs.l	y0, @-r2\n\t"					\
46e839ca52SDavid Howells 		"movs.l	x1, @-r2\n\t"					\
47e839ca52SDavid Howells 		"movs.l	x0, @-r2\n\t"					\
48e839ca52SDavid Howells 		"movs.l	m1, @-r2\n\t"					\
49e839ca52SDavid Howells 		"movs.l	m0, @-r2\n\t"					\
50e839ca52SDavid Howells 		"movs.l	a1g, @-r2\n\t"					\
51e839ca52SDavid Howells 		"movs.l	a0g, @-r2\n\t"					\
52e839ca52SDavid Howells 		"movs.l	a1, @-r2\n\t"					\
53e839ca52SDavid Howells 		"movs.l	a0, @-r2\n\t"					\
54e839ca52SDavid Howells 		: : "r" (__ts2));					\
55e839ca52SDavid Howells } while (0)
56e839ca52SDavid Howells 
57e839ca52SDavid Howells #else
58e839ca52SDavid Howells 
59e839ca52SDavid Howells #define is_dsp_enabled(tsk)	(0)
60e839ca52SDavid Howells #define __save_dsp(tsk)		do { } while (0)
61e839ca52SDavid Howells #define __restore_dsp(tsk)	do { } while (0)
62e839ca52SDavid Howells #endif
63e839ca52SDavid Howells 
64e839ca52SDavid Howells struct task_struct *__switch_to(struct task_struct *prev,
65e839ca52SDavid Howells 				struct task_struct *next);
66e839ca52SDavid Howells 
67e839ca52SDavid Howells /*
68e839ca52SDavid Howells  *	switch_to() should switch tasks to task nr n, first
69e839ca52SDavid Howells  */
70e839ca52SDavid Howells #define switch_to(prev, next, last)				\
71e839ca52SDavid Howells do {								\
72e839ca52SDavid Howells 	register u32 *__ts1 __asm__ ("r1");			\
73e839ca52SDavid Howells 	register u32 *__ts2 __asm__ ("r2");			\
74e839ca52SDavid Howells 	register u32 *__ts4 __asm__ ("r4");			\
75e839ca52SDavid Howells 	register u32 *__ts5 __asm__ ("r5");			\
76e839ca52SDavid Howells 	register u32 *__ts6 __asm__ ("r6");			\
77e839ca52SDavid Howells 	register u32 __ts7 __asm__ ("r7");			\
78e839ca52SDavid Howells 	struct task_struct *__last;				\
79e839ca52SDavid Howells 								\
80e839ca52SDavid Howells 	if (is_dsp_enabled(prev))				\
81e839ca52SDavid Howells 		__save_dsp(prev);				\
82b31fdac2SPeter Zijlstra 	if (is_dsp_enabled(next))				\
83b31fdac2SPeter Zijlstra 		__restore_dsp(next);				\
84e839ca52SDavid Howells 								\
85e839ca52SDavid Howells 	__ts1 = (u32 *)&prev->thread.sp;			\
86e839ca52SDavid Howells 	__ts2 = (u32 *)&prev->thread.pc;			\
87e839ca52SDavid Howells 	__ts4 = (u32 *)prev;					\
88e839ca52SDavid Howells 	__ts5 = (u32 *)next;					\
89e839ca52SDavid Howells 	__ts6 = (u32 *)&next->thread.sp;			\
90e839ca52SDavid Howells 	__ts7 = next->thread.pc;				\
91e839ca52SDavid Howells 								\
92e839ca52SDavid Howells 	__asm__ __volatile__ (					\
93e839ca52SDavid Howells 		".balign 4\n\t"					\
94e839ca52SDavid Howells 		"stc.l	gbr, @-r15\n\t"				\
95e839ca52SDavid Howells 		"sts.l	pr, @-r15\n\t"				\
96e839ca52SDavid Howells 		"mov.l	r8, @-r15\n\t"				\
97e839ca52SDavid Howells 		"mov.l	r9, @-r15\n\t"				\
98e839ca52SDavid Howells 		"mov.l	r10, @-r15\n\t"				\
99e839ca52SDavid Howells 		"mov.l	r11, @-r15\n\t"				\
100e839ca52SDavid Howells 		"mov.l	r12, @-r15\n\t"				\
101e839ca52SDavid Howells 		"mov.l	r13, @-r15\n\t"				\
102e839ca52SDavid Howells 		"mov.l	r14, @-r15\n\t"				\
103e839ca52SDavid Howells 		"mov.l	r15, @r1\t! save SP\n\t"		\
104e839ca52SDavid Howells 		"mov.l	@r6, r15\t! change to new stack\n\t"	\
105e839ca52SDavid Howells 		"mova	1f, %0\n\t"				\
106e839ca52SDavid Howells 		"mov.l	%0, @r2\t! save PC\n\t"			\
107e839ca52SDavid Howells 		"mov.l	2f, %0\n\t"				\
108e839ca52SDavid Howells 		"jmp	@%0\t! call __switch_to\n\t"		\
109e839ca52SDavid Howells 		" lds	r7, pr\t!  with return to new PC\n\t"	\
110e839ca52SDavid Howells 		".balign	4\n"				\
111e839ca52SDavid Howells 		"2:\n\t"					\
112e839ca52SDavid Howells 		".long	__switch_to\n"				\
113e839ca52SDavid Howells 		"1:\n\t"					\
114e839ca52SDavid Howells 		"mov.l	@r15+, r14\n\t"				\
115e839ca52SDavid Howells 		"mov.l	@r15+, r13\n\t"				\
116e839ca52SDavid Howells 		"mov.l	@r15+, r12\n\t"				\
117e839ca52SDavid Howells 		"mov.l	@r15+, r11\n\t"				\
118e839ca52SDavid Howells 		"mov.l	@r15+, r10\n\t"				\
119e839ca52SDavid Howells 		"mov.l	@r15+, r9\n\t"				\
120e839ca52SDavid Howells 		"mov.l	@r15+, r8\n\t"				\
121e839ca52SDavid Howells 		"lds.l	@r15+, pr\n\t"				\
122e839ca52SDavid Howells 		"ldc.l	@r15+, gbr\n\t"				\
123e839ca52SDavid Howells 		: "=z" (__last)					\
124e839ca52SDavid Howells 		: "r" (__ts1), "r" (__ts2), "r" (__ts4),	\
125e839ca52SDavid Howells 		  "r" (__ts5), "r" (__ts6), "r" (__ts7)		\
126e839ca52SDavid Howells 		: "r3", "t");					\
127e839ca52SDavid Howells 								\
128e839ca52SDavid Howells 	last = __last;						\
129e839ca52SDavid Howells } while (0)
130e839ca52SDavid Howells 
131e839ca52SDavid Howells #endif /* __ASM_SH_SWITCH_TO_32_H */
132