system.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #ifndef _M68K_SYSTEM_H
  2. #define _M68K_SYSTEM_H
  3. #include <linux/config.h> /* get configuration macros */
  4. #include <linux/linkage.h>
  5. #include <linux/kernel.h>
  6. #include <asm/segment.h>
  7. #include <asm/entry.h>
  8. #ifdef __KERNEL__
  9. /*
  10. * switch_to(n) should switch tasks to task ptr, first checking that
  11. * ptr isn't the current task, in which case it does nothing. This
  12. * also clears the TS-flag if the task we switched to has used the
  13. * math co-processor latest.
  14. */
  15. /*
  16. * switch_to() saves the extra registers, that are not saved
  17. * automatically by SAVE_SWITCH_STACK in resume(), ie. d0-d5 and
  18. * a0-a1. Some of these are used by schedule() and its predecessors
  19. * and so we might get see unexpected behaviors when a task returns
  20. * with unexpected register values.
  21. *
  22. * syscall stores these registers itself and none of them are used
  23. * by syscall after the function in the syscall has been called.
  24. *
  25. * Beware that resume now expects *next to be in d1 and the offset of
  26. * tss to be in a1. This saves a few instructions as we no longer have
  27. * to push them onto the stack and read them back right after.
  28. *
  29. * 02/17/96 - Jes Sorensen (jds@kom.auc.dk)
  30. *
  31. * Changed 96/09/19 by Andreas Schwab
  32. * pass prev in a0, next in a1
  33. */
  34. asmlinkage void resume(void);
  35. #define switch_to(prev,next,last) do { \
  36. register void *_prev __asm__ ("a0") = (prev); \
  37. register void *_next __asm__ ("a1") = (next); \
  38. register void *_last __asm__ ("d1"); \
  39. __asm__ __volatile__("jbsr resume" \
  40. : "=a" (_prev), "=a" (_next), "=d" (_last) \
  41. : "0" (_prev), "1" (_next) \
  42. : "d0", "d2", "d3", "d4", "d5"); \
  43. (last) = _last; \
  44. } while (0)
  45. /* interrupt control.. */
  46. #if 0
  47. #define local_irq_enable() asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory")
  48. #else
  49. #include <linux/hardirq.h>
  50. #define local_irq_enable() ({ \
  51. if (MACH_IS_Q40 || !hardirq_count()) \
  52. asm volatile ("andiw %0,%%sr": : "i" (ALLOWINT) : "memory"); \
  53. })
  54. #endif
  55. #define local_irq_disable() asm volatile ("oriw #0x0700,%%sr": : : "memory")
  56. #define local_save_flags(x) asm volatile ("movew %%sr,%0":"=d" (x) : : "memory")
  57. #define local_irq_restore(x) asm volatile ("movew %0,%%sr": :"d" (x) : "memory")
  58. static inline int irqs_disabled(void)
  59. {
  60. unsigned long flags;
  61. local_save_flags(flags);
  62. return flags & ~ALLOWINT;
  63. }
  64. /* For spinlocks etc */
  65. #define local_irq_save(x) ({ local_save_flags(x); local_irq_disable(); })
  66. /*
  67. * Force strict CPU ordering.
  68. * Not really required on m68k...
  69. */
  70. #define nop() do { asm volatile ("nop"); barrier(); } while (0)
  71. #define mb() barrier()
  72. #define rmb() barrier()
  73. #define wmb() barrier()
  74. #define read_barrier_depends() do { } while(0)
  75. #define set_mb(var, value) do { xchg(&var, value); } while (0)
  76. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  77. #define smp_mb() barrier()
  78. #define smp_rmb() barrier()
  79. #define smp_wmb() barrier()
  80. #define smp_read_barrier_depends() do { } while(0)
  81. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  82. #define tas(ptr) (xchg((ptr),1))
  83. struct __xchg_dummy { unsigned long a[100]; };
  84. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  85. #ifndef CONFIG_RMW_INSNS
  86. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  87. {
  88. unsigned long flags, tmp;
  89. local_irq_save(flags);
  90. switch (size) {
  91. case 1:
  92. tmp = *(u8 *)ptr;
  93. *(u8 *)ptr = x;
  94. x = tmp;
  95. break;
  96. case 2:
  97. tmp = *(u16 *)ptr;
  98. *(u16 *)ptr = x;
  99. x = tmp;
  100. break;
  101. case 4:
  102. tmp = *(u32 *)ptr;
  103. *(u32 *)ptr = x;
  104. x = tmp;
  105. break;
  106. default:
  107. BUG();
  108. }
  109. local_irq_restore(flags);
  110. return x;
  111. }
  112. #else
  113. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  114. {
  115. switch (size) {
  116. case 1:
  117. __asm__ __volatile__
  118. ("moveb %2,%0\n\t"
  119. "1:\n\t"
  120. "casb %0,%1,%2\n\t"
  121. "jne 1b"
  122. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  123. break;
  124. case 2:
  125. __asm__ __volatile__
  126. ("movew %2,%0\n\t"
  127. "1:\n\t"
  128. "casw %0,%1,%2\n\t"
  129. "jne 1b"
  130. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  131. break;
  132. case 4:
  133. __asm__ __volatile__
  134. ("movel %2,%0\n\t"
  135. "1:\n\t"
  136. "casl %0,%1,%2\n\t"
  137. "jne 1b"
  138. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  139. break;
  140. }
  141. return x;
  142. }
  143. #endif
  144. /*
  145. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  146. * store NEW in MEM. Return the initial value in MEM. Success is
  147. * indicated by comparing RETURN with OLD.
  148. */
  149. #ifdef CONFIG_RMW_INSNS
  150. #define __HAVE_ARCH_CMPXCHG 1
  151. static inline unsigned long __cmpxchg(volatile void *p, unsigned long old,
  152. unsigned long new, int size)
  153. {
  154. switch (size) {
  155. case 1:
  156. __asm__ __volatile__ ("casb %0,%2,%1"
  157. : "=d" (old), "=m" (*(char *)p)
  158. : "d" (new), "0" (old), "m" (*(char *)p));
  159. break;
  160. case 2:
  161. __asm__ __volatile__ ("casw %0,%2,%1"
  162. : "=d" (old), "=m" (*(short *)p)
  163. : "d" (new), "0" (old), "m" (*(short *)p));
  164. break;
  165. case 4:
  166. __asm__ __volatile__ ("casl %0,%2,%1"
  167. : "=d" (old), "=m" (*(int *)p)
  168. : "d" (new), "0" (old), "m" (*(int *)p));
  169. break;
  170. }
  171. return old;
  172. }
  173. #define cmpxchg(ptr,o,n)\
  174. ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
  175. (unsigned long)(n),sizeof(*(ptr))))
  176. #endif
  177. #define arch_align_stack(x) (x)
  178. #endif /* __KERNEL__ */
  179. #endif /* _M68K_SYSTEM_H */