blob: 64c64432bbb80248c44ddfc34a6cc98beff938e1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _M68KNOMMU_SYSTEM_H
2#define _M68KNOMMU_SYSTEM_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/linkage.h>
5#include <asm/segment.h>
6#include <asm/entry.h>
7
8/*
9 * switch_to(n) should switch tasks to task ptr, first checking that
10 * ptr isn't the current task, in which case it does nothing. This
11 * also clears the TS-flag if the task we switched to has used the
12 * math co-processor latest.
13 */
14/*
15 * switch_to() saves the extra registers, that are not saved
16 * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
17 * a0-a1. Some of these are used by schedule() and its predecessors
18 * and so we might get see unexpected behaviors when a task returns
19 * with unexpected register values.
20 *
21 * syscall stores these registers itself and none of them are used
22 * by syscall after the function in the syscall has been called.
23 *
24 * Beware that resume now expects *next to be in d1 and the offset of
25 * tss to be in a1. This saves a few instructions as we no longer have
26 * to push them onto the stack and read them back right after.
27 *
28 * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
29 *
30 * Changed 96/09/19 by Andreas Schwab
31 * pass prev in a0, next in a1, offset of tss in d1, and whether
32 * the mm structures are shared in d2 (to avoid atc flushing).
33 */
34asmlinkage void resume(void);
35#define switch_to(prev,next,last) \
36{ \
37 void *_last; \
38 __asm__ __volatile__( \
39 "movel %1, %%a0\n\t" \
40 "movel %2, %%a1\n\t" \
41 "jbsr resume\n\t" \
42 "movel %%d1, %0\n\t" \
43 : "=d" (_last) \
44 : "d" (prev), "d" (next) \
45 : "cc", "d0", "d1", "d2", "d3", "d4", "d5", "a0", "a1"); \
46 (last) = _last; \
47}
48
49#ifdef CONFIG_COLDFIRE
50#define local_irq_enable() __asm__ __volatile__ ( \
51 "move %/sr,%%d0\n\t" \
52 "andi.l #0xf8ff,%%d0\n\t" \
53 "move %%d0,%/sr\n" \
54 : /* no outputs */ \
55 : \
56 : "cc", "%d0", "memory")
57#define local_irq_disable() __asm__ __volatile__ ( \
58 "move %/sr,%%d0\n\t" \
Greg Ungerer9c2aba42005-09-13 11:14:08 +100059 "ori.l #0x0700,%%d0\n\t" \
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 "move %%d0,%/sr\n" \
Greg Ungerer9c2aba42005-09-13 11:14:08 +100061 : /* no outputs */ \
62 : \
63 : "cc", "%d0", "memory")
64/* For spinlocks etc */
65#define local_irq_save(x) __asm__ __volatile__ ( \
66 "movew %%sr,%0\n\t" \
67 "movew #0x0700,%%d0\n\t" \
68 "or.l %0,%%d0\n\t" \
69 "movew %%d0,%/sr" \
70 : "=d" (x) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 : \
72 : "cc", "%d0", "memory")
73#else
74
75/* portable version */ /* FIXME - see entry.h*/
76#define ALLOWINT 0xf8ff
77
78#define local_irq_enable() asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory")
79#define local_irq_disable() asm volatile ("oriw #0x0700,%%sr": : : "memory")
80#endif
81
82#define local_save_flags(x) asm volatile ("movew %%sr,%0":"=d" (x) : : "memory")
83#define local_irq_restore(x) asm volatile ("movew %0,%%sr": :"d" (x) : "memory")
84
85/* For spinlocks etc */
Greg Ungerer9c2aba42005-09-13 11:14:08 +100086#ifndef local_irq_save
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define local_irq_save(x) do { local_save_flags(x); local_irq_disable(); } while (0)
Greg Ungerer9c2aba42005-09-13 11:14:08 +100088#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#define irqs_disabled() \
91({ \
92 unsigned long flags; \
93 local_save_flags(flags); \
94 ((flags & 0x0700) == 0x0700); \
95})
96
97#define iret() __asm__ __volatile__ ("rte": : :"memory", "sp", "cc")
98
99/*
100 * Force strict CPU ordering.
101 * Not really required on m68k...
102 */
103#define nop() asm volatile ("nop"::)
104#define mb() asm volatile ("" : : :"memory")
105#define rmb() asm volatile ("" : : :"memory")
106#define wmb() asm volatile ("" : : :"memory")
Greg Ungerer091b76d2008-02-14 19:31:25 -0800107#define set_mb(var, value) ({ (var) = (value); wmb(); })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#ifdef CONFIG_SMP
110#define smp_mb() mb()
111#define smp_rmb() rmb()
112#define smp_wmb() wmb()
113#define smp_read_barrier_depends() read_barrier_depends()
114#else
115#define smp_mb() barrier()
116#define smp_rmb() barrier()
117#define smp_wmb() barrier()
118#define smp_read_barrier_depends() do { } while(0)
119#endif
120
121#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123struct __xchg_dummy { unsigned long a[100]; };
124#define __xg(x) ((volatile struct __xchg_dummy *)(x))
125
126#ifndef CONFIG_RMW_INSNS
127static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
128{
129 unsigned long tmp, flags;
130
131 local_irq_save(flags);
132
133 switch (size) {
134 case 1:
135 __asm__ __volatile__
136 ("moveb %2,%0\n\t"
137 "moveb %1,%2"
138 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
139 break;
140 case 2:
141 __asm__ __volatile__
142 ("movew %2,%0\n\t"
143 "movew %1,%2"
144 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
145 break;
146 case 4:
147 __asm__ __volatile__
148 ("movel %2,%0\n\t"
149 "movel %1,%2"
150 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
151 break;
152 }
153 local_irq_restore(flags);
154 return tmp;
155}
156#else
157static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
158{
159 switch (size) {
160 case 1:
161 __asm__ __volatile__
162 ("moveb %2,%0\n\t"
163 "1:\n\t"
164 "casb %0,%1,%2\n\t"
165 "jne 1b"
166 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
167 break;
168 case 2:
169 __asm__ __volatile__
170 ("movew %2,%0\n\t"
171 "1:\n\t"
172 "casw %0,%1,%2\n\t"
173 "jne 1b"
174 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
175 break;
176 case 4:
177 __asm__ __volatile__
178 ("movel %2,%0\n\t"
179 "1:\n\t"
180 "casl %0,%1,%2\n\t"
181 "jne 1b"
182 : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
183 break;
184 }
185 return x;
186}
187#endif
188
Mathieu Desnoyers027bcc22008-02-07 00:16:20 -0800189#include <asm-generic/cmpxchg-local.h>
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/*
Mathieu Desnoyers027bcc22008-02-07 00:16:20 -0800192 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
193 * them available.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 */
Mathieu Desnoyers027bcc22008-02-07 00:16:20 -0800195#define cmpxchg_local(ptr, o, n) \
196 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
197 (unsigned long)(n), sizeof(*(ptr))))
198#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Mathieu Desnoyers027bcc22008-02-07 00:16:20 -0800200#ifndef CONFIG_SMP
201#include <asm-generic/cmpxchg.h>
202#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#if defined( CONFIG_M68328 ) || defined( CONFIG_M68EZ328 ) || \
205 defined (CONFIG_M68360) || defined( CONFIG_M68VZ328 )
206#define HARD_RESET_NOW() ({ \
207 local_irq_disable(); \
208 asm(" \
209 moveal #0x10c00000, %a0; \
210 moveb #0, 0xFFFFF300; \
211 moveal 0(%a0), %sp; \
212 moveal 4(%a0), %a0; \
213 jmp (%a0); \
214 "); \
215})
216#endif
217
218#ifdef CONFIG_COLDFIRE
219#if defined(CONFIG_M5272) && defined(CONFIG_NETtel)
220/*
Greg Ungerer9c2aba42005-09-13 11:14:08 +1000221 * Need to account for broken early mask of 5272 silicon. So don't
222 * jump through the original start address. Jump strait into the
223 * known start of the FLASH code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 */
225#define HARD_RESET_NOW() ({ \
226 asm(" \
227 movew #0x2700, %sr; \
228 jmp 0xf0000400; \
229 "); \
230})
Greg Ungerer9c2aba42005-09-13 11:14:08 +1000231#elif defined(CONFIG_NETtel) || defined(CONFIG_eLIA) || \
Greg Ungererfabc7f62007-10-16 01:26:30 -0700232 defined(CONFIG_SECUREEDGEMP3) || defined(CONFIG_CLEOPATRA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define HARD_RESET_NOW() ({ \
234 asm(" \
235 movew #0x2700, %sr; \
236 moveal #0x10000044, %a0; \
237 movel #0xffffffff, (%a0); \
238 moveal #0x10000001, %a0; \
239 moveb #0x00, (%a0); \
240 moveal #0xf0000004, %a0; \
241 moveal (%a0), %a0; \
242 jmp (%a0); \
243 "); \
244})
Greg Ungerer9c2aba42005-09-13 11:14:08 +1000245#elif defined(CONFIG_M5272)
246/*
247 * Retrieve the boot address in flash using CSBR0 and CSOR0
248 * find the reset vector at flash_address + 4 (e.g. 0x400)
249 * remap it in the flash's current location (e.g. 0xf0000400)
250 * and jump there.
251 */
252#define HARD_RESET_NOW() ({ \
253 asm(" \
254 movew #0x2700, %%sr; \
255 move.l %0+0x40,%%d0; \
256 and.l %0+0x44,%%d0; \
257 andi.l #0xfffff000,%%d0; \
258 mov.l %%d0,%%a0; \
259 or.l 4(%%a0),%%d0; \
260 mov.l %%d0,%%a0; \
261 jmp (%%a0);" \
262 : /* No output */ \
263 : "o" (*(char *)MCF_MBAR) ); \
264})
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#elif defined(CONFIG_M528x)
266/*
267 * The MCF528x has a bit (SOFTRST) in memory (Reset Control Register RCR),
268 * that when set, resets the MCF528x.
269 */
270#define HARD_RESET_NOW() \
271({ \
272 unsigned char volatile *reset; \
273 asm("move.w #0x2700, %sr"); \
Greg Ungerer020f9e12007-07-25 22:07:20 +1000274 reset = ((volatile unsigned char *)(MCF_IPSBAR + 0x110000)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 while(1) \
276 *reset |= (0x01 << 7);\
277})
Greg Ungerer9c2aba42005-09-13 11:14:08 +1000278#elif defined(CONFIG_M523x)
279#define HARD_RESET_NOW() ({ \
280 asm(" \
281 movew #0x2700, %sr; \
282 movel #0x01000000, %sp; \
283 moveal #0x40110000, %a0; \
284 moveb #0x80, (%a0); \
285 "); \
286})
Greg Ungerer01824852005-11-02 15:12:42 +1000287#elif defined(CONFIG_M520x)
288 /*
289 * The MCF5208 has a bit (SOFTRST) in memory (Reset Control Register
290 * RCR), that when set, resets the MCF5208.
291 */
292#define HARD_RESET_NOW() \
293({ \
294 unsigned char volatile *reset; \
295 asm("move.w #0x2700, %sr"); \
Greg Ungerer020f9e12007-07-25 22:07:20 +1000296 reset = ((volatile unsigned char *)(MCF_IPSBAR + 0xA0000)); \
Greg Ungerer01824852005-11-02 15:12:42 +1000297 while(1) \
298 *reset |= 0x80; \
299})
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#else
301#define HARD_RESET_NOW() ({ \
302 asm(" \
303 movew #0x2700, %sr; \
304 moveal #0x4, %a0; \
305 moveal (%a0), %a0; \
306 jmp (%a0); \
307 "); \
308})
309#endif
310#endif
311#define arch_align_stack(x) (x)
312
313#endif /* _M68KNOMMU_SYSTEM_H */