Import 2.3.18pre1
[davej-history.git] / include / asm-m68k / system.h
blob7d1afa286b89eafa6f51025b5c41dda487211749
1 #ifndef _M68K_SYSTEM_H
2 #define _M68K_SYSTEM_H
4 #include <linux/config.h> /* get configuration macros */
5 #include <linux/linkage.h>
6 #include <asm/segment.h>
8 #define prepare_to_switch() do { } while(0)
11 * switch_to(n) should switch tasks to task ptr, first checking that
12 * ptr isn't the current task, in which case it does nothing. This
13 * also clears the TS-flag if the task we switched to has used the
14 * math co-processor latest.
17 * switch_to() saves the extra registers, that are not saved
18 * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
19 * a0-a1. Some of these are used by schedule() and its predecessors
20 * and so we might get see unexpected behaviors when a task returns
21 * with unexpected register values.
23 * syscall stores these registers itself and none of them are used
24 * by syscall after the function in the syscall has been called.
26 * Beware that resume now expects *next to be in d1 and the offset of
27 * tss to be in a1. This saves a few instructions as we no longer have
28 * to push them onto the stack and read them back right after.
30 * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
32 * Changed 96/09/19 by Andreas Schwab
33 * pass prev in a0, next in a1, offset of tss in d1, and whether
34 * the mm structures are shared in d2 (to avoid atc flushing).
36 asmlinkage void resume(void);
37 #define switch_to(prev,next,last) { \
38 register void *_prev __asm__ ("a0") = (prev); \
39 register void *_next __asm__ ("a1") = (next); \
40 register void *_last __asm__ ("d1"); \
41 __asm__ __volatile__("jbsr " SYMBOL_NAME_STR(resume) \
42 : "=d" (_last) : "a" (_prev), "a" (_next) \
43 : "d0", "d1", "d2", "d3", "d4", "d5", "a0", "a1"); \
44 (last) = _last; \
47 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
48 #define tas(ptr) (xchg((ptr),1))
50 struct __xchg_dummy { unsigned long a[100]; };
51 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
53 #if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES)
54 /* block out HSYNC on the atari */
55 #define __sti() __asm__ __volatile__ ("andiw #0xfbff,%/sr": : : "memory")
56 #else /* portable version */
57 #define __sti() __asm__ __volatile__ ("andiw #0xf8ff,%/sr": : : "memory")
58 #endif /* machine compilation types */
59 #define __cli() __asm__ __volatile__ ("oriw #0x0700,%/sr": : : "memory")
60 #define nop() __asm__ __volatile__ ("nop"::)
61 #define mb() __asm__ __volatile__ ("" : : :"memory")
62 #define rmb() __asm__ __volatile__ ("" : : :"memory")
63 #define wmb() __asm__ __volatile__ ("" : : :"memory")
65 #define __save_flags(x) \
66 __asm__ __volatile__("movew %/sr,%0":"=d" (x) : /* no input */ :"memory")
68 #define __restore_flags(x) \
69 __asm__ __volatile__("movew %0,%/sr": /* no outputs */ :"d" (x) : "memory")
71 #define cli() __cli()
72 #define sti() __sti()
73 #define save_flags(x) __save_flags(x)
74 #define restore_flags(x) __restore_flags(x)
75 #define save_and_cli(flags) do { save_flags(flags); cli(); } while(0)
77 #ifndef CONFIG_RMW_INSNS
78 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
80 unsigned long tmp, flags;
82 save_flags(flags);
83 cli();
85 switch (size) {
86 case 1:
87 __asm__ __volatile__
88 ("moveb %2,%0\n\t"
89 "moveb %1,%2"
90 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
91 break;
92 case 2:
93 __asm__ __volatile__
94 ("movew %2,%0\n\t"
95 "movew %1,%2"
96 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
97 break;
98 case 4:
99 __asm__ __volatile__
100 ("movel %2,%0\n\t"
101 "movel %1,%2"
102 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
103 break;
105 restore_flags(flags);
106 return tmp;
108 #else
109 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
111 switch (size) {
112 case 1:
113 __asm__ __volatile__
114 ("moveb %2,%0\n\t"
115 "1:\n\t"
116 "casb %0,%1,%2\n\t"
117 "jne 1b"
118 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
119 break;
120 case 2:
121 __asm__ __volatile__
122 ("movew %2,%0\n\t"
123 "1:\n\t"
124 "casw %0,%1,%2\n\t"
125 "jne 1b"
126 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
127 break;
128 case 4:
129 __asm__ __volatile__
130 ("movel %2,%0\n\t"
131 "1:\n\t"
132 "casl %0,%1,%2\n\t"
133 "jne 1b"
134 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
135 break;
137 return x;
139 #endif
141 #endif /* _M68K_SYSTEM_H */