system.h 8.9 KB

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