system.h 7.6 KB

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