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