162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _M68K_SWITCH_TO_H
362306a36Sopenharmony_ci#define _M68K_SWITCH_TO_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci * switch_to(n) should switch tasks to task ptr, first checking that
762306a36Sopenharmony_ci * ptr isn't the current task, in which case it does nothing.  This
862306a36Sopenharmony_ci * also clears the TS-flag if the task we switched to has used the
962306a36Sopenharmony_ci * math co-processor latest.
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci * switch_to() saves the extra registers, that are not saved
1362306a36Sopenharmony_ci * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
1462306a36Sopenharmony_ci * a0-a1. Some of these are used by schedule() and its predecessors
1562306a36Sopenharmony_ci * and so we might get see unexpected behaviors when a task returns
1662306a36Sopenharmony_ci * with unexpected register values.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * syscall stores these registers itself and none of them are used
1962306a36Sopenharmony_ci * by syscall after the function in the syscall has been called.
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * Beware that resume now expects *next to be in d1 and the offset of
2262306a36Sopenharmony_ci * tss to be in a1. This saves a few instructions as we no longer have
2362306a36Sopenharmony_ci * to push them onto the stack and read them back right after.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * Changed 96/09/19 by Andreas Schwab
2862306a36Sopenharmony_ci * pass prev in a0, next in a1
2962306a36Sopenharmony_ci */
3062306a36Sopenharmony_ciasmlinkage void resume(void);
3162306a36Sopenharmony_ci#define switch_to(prev,next,last) do { \
3262306a36Sopenharmony_ci  register void *_prev __asm__ ("a0") = (prev); \
3362306a36Sopenharmony_ci  register void *_next __asm__ ("a1") = (next); \
3462306a36Sopenharmony_ci  register void *_last __asm__ ("d1"); \
3562306a36Sopenharmony_ci  __asm__ __volatile__("jbsr resume" \
3662306a36Sopenharmony_ci		       : "=a" (_prev), "=a" (_next), "=d" (_last) \
3762306a36Sopenharmony_ci		       : "0" (_prev), "1" (_next) \
3862306a36Sopenharmony_ci		       : "d0", "d2", "d3", "d4", "d5"); \
3962306a36Sopenharmony_ci  (last) = _last; \
4062306a36Sopenharmony_ci} while (0)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#endif /* _M68K_SWITCH_TO_H */
43