system.h 4.9 KB

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