bfin: remove inline keyword
[xenomai-head.git] / include / asm-sh / switch.h
blob5c07d1e4c18473562f2fabaf86615ea50922b610
1 /*
2 * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
4 * Xenomai is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * Xenomai is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Xenomai; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #ifndef _XENO_ASM_SH_SWITCH_H
21 #define _XENO_ASM_SH_SWITCH_H
23 #ifndef __KERNEL__
24 #error "Pure kernel header included from user-space!"
25 #endif
27 #include <asm/system.h>
30 * Most of this code was lifted from the regular Linux task switching
31 * code. A provision for handling Xenomai-originated kernel threads
32 * (aka "hybrid scheduling" is added).
34 #define xnarch_switch_threads(otcb, itcb, prev, next) \
35 ({ \
36 register u32 *__ts1 __asm__ ("r1"); \
37 register u32 *__ts2 __asm__ ("r2"); \
38 register u32 *__ts4 __asm__ ("r4"); \
39 register u32 *__ts5 __asm__ ("r5"); \
40 register u32 *__ts6 __asm__ ("r6"); \
41 register u32 __ts7 __asm__ ("r7"); \
42 struct task_struct *__last = prev; \
43 struct xnarchtcb *__ltcb = otcb; \
45 if (otcb->tsp == &prev->thread && \
46 is_dsp_enabled(prev)) \
47 __save_dsp(prev); \
49 __ts1 = (u32 *)&otcb->tsp->sp; \
50 __ts2 = (u32 *)&otcb->tsp->pc; \
51 __ts4 = (u32 *)prev; \
52 __ts5 = (u32 *)next; \
53 __ts6 = (u32 *)&itcb->tsp->sp; \
54 __ts7 = itcb->tsp->pc; \
56 __asm__ __volatile__ ( \
57 ".balign 4\n\t" \
58 "stc.l gbr, @-r15\n\t" \
59 "sts.l pr, @-r15\n\t" \
60 "mov.l r8, @-r15\n\t" \
61 "mov.l r9, @-r15\n\t" \
62 "mov.l r10, @-r15\n\t" \
63 "mov.l r11, @-r15\n\t" \
64 "mov.l r12, @-r15\n\t" \
65 "mov.l r13, @-r15\n\t" \
66 "mov.l r14, @-r15\n\t" \
67 "mov.l r15, @r1\t! save SP\n\t" \
68 "mov.l @r6, r15\t! change to new stack\n\t" \
69 "mova 1f, %0\n\t" \
70 "mov.l %0, @r2\t! save PC\n\t" \
71 "mov #0, r8\n\t" \
72 "cmp/eq r5, r8\n\t" \
73 "bt/s 3f\n\t" \
74 " lds r7, pr\t! return to saved PC\n\t" \
75 "mov.l 2f, %0\n\t" \
76 "jmp @%0\t! call __switch_to\n\t" \
77 " nop\t\n\t" \
78 "3:\n\t" \
79 "rts\n\t" \
80 ".balign 4\n" \
81 "2:\n\t" \
82 ".long __switch_to\n" \
83 "1:\n\t" \
84 "mov.l @r15+, r14\n\t" \
85 "mov.l @r15+, r13\n\t" \
86 "mov.l @r15+, r12\n\t" \
87 "mov.l @r15+, r11\n\t" \
88 "mov.l @r15+, r10\n\t" \
89 "mov.l @r15+, r9\n\t" \
90 "mov.l @r15+, r8\n\t" \
91 "lds.l @r15+, pr\n\t" \
92 "ldc.l @r15+, gbr\n\t" \
93 : "=z" (__last) \
94 : "r" (__ts1), "r" (__ts2), "r" (__ts4), \
95 "r" (__ts5), "r" (__ts6), "r" (__ts7) \
96 : "r3", "t"); \
98 if (__ltcb->tsp == &__last->thread && \
99 is_dsp_enabled(__last)) \
100 __restore_dsp(__last); \
102 __last; \
105 #endif /* _XENO_ASM_SH_SWITCH_H */