system.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _M68K_SYSTEM_H
  2. #define _M68K_SYSTEM_H
  3. #include <linux/linkage.h>
  4. #include <linux/kernel.h>
  5. #include <linux/irqflags.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. /*
  46. * Force strict CPU ordering.
  47. * Not really required on m68k...
  48. */
  49. #define nop() do { asm volatile ("nop"); barrier(); } while (0)
  50. #define mb() barrier()
  51. #define rmb() barrier()
  52. #define wmb() barrier()
  53. #define read_barrier_depends() ((void)0)
  54. #define set_mb(var, value) ({ (var) = (value); wmb(); })
  55. #define smp_mb() barrier()
  56. #define smp_rmb() barrier()
  57. #define smp_wmb() barrier()
  58. #define smp_read_barrier_depends() ((void)0)
  59. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  60. struct __xchg_dummy { unsigned long a[100]; };
  61. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  62. #ifndef CONFIG_RMW_INSNS
  63. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  64. {
  65. unsigned long flags, tmp;
  66. local_irq_save(flags);
  67. switch (size) {
  68. case 1:
  69. tmp = *(u8 *)ptr;
  70. *(u8 *)ptr = x;
  71. x = tmp;
  72. break;
  73. case 2:
  74. tmp = *(u16 *)ptr;
  75. *(u16 *)ptr = x;
  76. x = tmp;
  77. break;
  78. case 4:
  79. tmp = *(u32 *)ptr;
  80. *(u32 *)ptr = x;
  81. x = tmp;
  82. break;
  83. default:
  84. BUG();
  85. }
  86. local_irq_restore(flags);
  87. return x;
  88. }
  89. #else
  90. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  91. {
  92. switch (size) {
  93. case 1:
  94. __asm__ __volatile__
  95. ("moveb %2,%0\n\t"
  96. "1:\n\t"
  97. "casb %0,%1,%2\n\t"
  98. "jne 1b"
  99. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  100. break;
  101. case 2:
  102. __asm__ __volatile__
  103. ("movew %2,%0\n\t"
  104. "1:\n\t"
  105. "casw %0,%1,%2\n\t"
  106. "jne 1b"
  107. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  108. break;
  109. case 4:
  110. __asm__ __volatile__
  111. ("movel %2,%0\n\t"
  112. "1:\n\t"
  113. "casl %0,%1,%2\n\t"
  114. "jne 1b"
  115. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  116. break;
  117. }
  118. return x;
  119. }
  120. #endif
  121. #include <asm-generic/cmpxchg-local.h>
  122. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  123. /*
  124. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  125. * store NEW in MEM. Return the initial value in MEM. Success is
  126. * indicated by comparing RETURN with OLD.
  127. */
  128. #ifdef CONFIG_RMW_INSNS
  129. #define __HAVE_ARCH_CMPXCHG 1
  130. static inline unsigned long __cmpxchg(volatile void *p, unsigned long old,
  131. unsigned long new, int size)
  132. {
  133. switch (size) {
  134. case 1:
  135. __asm__ __volatile__ ("casb %0,%2,%1"
  136. : "=d" (old), "=m" (*(char *)p)
  137. : "d" (new), "0" (old), "m" (*(char *)p));
  138. break;
  139. case 2:
  140. __asm__ __volatile__ ("casw %0,%2,%1"
  141. : "=d" (old), "=m" (*(short *)p)
  142. : "d" (new), "0" (old), "m" (*(short *)p));
  143. break;
  144. case 4:
  145. __asm__ __volatile__ ("casl %0,%2,%1"
  146. : "=d" (old), "=m" (*(int *)p)
  147. : "d" (new), "0" (old), "m" (*(int *)p));
  148. break;
  149. }
  150. return old;
  151. }
  152. #define cmpxchg(ptr, o, n) \
  153. ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
  154. (unsigned long)(n), sizeof(*(ptr))))
  155. #define cmpxchg_local(ptr, o, n) \
  156. ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
  157. (unsigned long)(n), sizeof(*(ptr))))
  158. #else
  159. /*
  160. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  161. * them available.
  162. */
  163. #define cmpxchg_local(ptr, o, n) \
  164. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  165. (unsigned long)(n), sizeof(*(ptr))))
  166. #include <asm-generic/cmpxchg.h>
  167. #endif
  168. #define arch_align_stack(x) (x)
  169. #endif /* __KERNEL__ */
  170. #endif /* _M68K_SYSTEM_H */