18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _H8300_SWITCH_TO_H
38c2ecf20Sopenharmony_ci#define _H8300_SWITCH_TO_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * switch_to(n) should switch tasks to task ptr, first checking that
78c2ecf20Sopenharmony_ci * ptr isn't the current task, in which case it does nothing.  This
88c2ecf20Sopenharmony_ci * also clears the TS-flag if the task we switched to has used the
98c2ecf20Sopenharmony_ci * math co-processor latest.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * switch_to() saves the extra registers, that are not saved
138c2ecf20Sopenharmony_ci * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
148c2ecf20Sopenharmony_ci * a0-a1. Some of these are used by schedule() and its predecessors
158c2ecf20Sopenharmony_ci * and so we might get see unexpected behaviors when a task returns
168c2ecf20Sopenharmony_ci * with unexpected register values.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * syscall stores these registers itself and none of them are used
198c2ecf20Sopenharmony_ci * by syscall after the function in the syscall has been called.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Beware that resume now expects *next to be in d1 and the offset of
228c2ecf20Sopenharmony_ci * tss to be in a1. This saves a few instructions as we no longer have
238c2ecf20Sopenharmony_ci * to push them onto the stack and read them back right after.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Changed 96/09/19 by Andreas Schwab
288c2ecf20Sopenharmony_ci * pass prev in a0, next in a1, offset of tss in d1, and whether
298c2ecf20Sopenharmony_ci * the mm structures are shared in d2 (to avoid atc flushing).
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * H8/300 Porting 2002/09/04 Yoshinori Sato
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciasmlinkage void resume(void);
358c2ecf20Sopenharmony_ci#define switch_to(prev, next, last) \
368c2ecf20Sopenharmony_cido {			     \
378c2ecf20Sopenharmony_ci	void *_last;					    \
388c2ecf20Sopenharmony_ci	__asm__ __volatile__(				    \
398c2ecf20Sopenharmony_ci		"mov.l	%1, er0\n\t"			    \
408c2ecf20Sopenharmony_ci		"mov.l	%2, er1\n\t"			    \
418c2ecf20Sopenharmony_ci		"mov.l	%3, er2\n\t"			    \
428c2ecf20Sopenharmony_ci		"jsr @_resume\n\t"			    \
438c2ecf20Sopenharmony_ci		"mov.l	er2,%0\n\t"			    \
448c2ecf20Sopenharmony_ci		: "=r" (_last)				    \
458c2ecf20Sopenharmony_ci		: "r" (&(prev->thread)),		    \
468c2ecf20Sopenharmony_ci		  "r" (&(next->thread)),		    \
478c2ecf20Sopenharmony_ci		  "g" (prev)				    \
488c2ecf20Sopenharmony_ci		: "cc", "er0", "er1", "er2", "er3");	    \
498c2ecf20Sopenharmony_ci	(last) = _last;					    \
508c2ecf20Sopenharmony_ci} while (0)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#endif /* _H8300_SWITCH_TO_H */
53