18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _M68K_SWITCH_TO_H
38c2ecf20Sopenharmony_ci#define _M68K_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
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ciasmlinkage void resume(void);
318c2ecf20Sopenharmony_ci#define switch_to(prev,next,last) do { \
328c2ecf20Sopenharmony_ci  register void *_prev __asm__ ("a0") = (prev); \
338c2ecf20Sopenharmony_ci  register void *_next __asm__ ("a1") = (next); \
348c2ecf20Sopenharmony_ci  register void *_last __asm__ ("d1"); \
358c2ecf20Sopenharmony_ci  __asm__ __volatile__("jbsr resume" \
368c2ecf20Sopenharmony_ci		       : "=a" (_prev), "=a" (_next), "=d" (_last) \
378c2ecf20Sopenharmony_ci		       : "0" (_prev), "1" (_next) \
388c2ecf20Sopenharmony_ci		       : "d0", "d2", "d3", "d4", "d5"); \
398c2ecf20Sopenharmony_ci  (last) = _last; \
408c2ecf20Sopenharmony_ci} while (0)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#endif /* _M68K_SWITCH_TO_H */
43