system_no.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #ifndef _M68KNOMMU_SYSTEM_H
  2. #define _M68KNOMMU_SYSTEM_H
  3. #include <linux/linkage.h>
  4. #include <linux/irqflags.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. #define iret() __asm__ __volatile__ ("rte": : :"memory", "sp", "cc")
  48. /*
  49. * Force strict CPU ordering.
  50. * Not really required on m68k...
  51. */
  52. #define nop() asm volatile ("nop"::)
  53. #define mb() asm volatile ("" : : :"memory")
  54. #define rmb() asm volatile ("" : : :"memory")
  55. #define wmb() asm volatile ("" : : :"memory")
  56. #define set_mb(var, value) ({ (var) = (value); wmb(); })
  57. #ifdef CONFIG_SMP
  58. #define smp_mb() mb()
  59. #define smp_rmb() rmb()
  60. #define smp_wmb() wmb()
  61. #define smp_read_barrier_depends() read_barrier_depends()
  62. #else
  63. #define smp_mb() barrier()
  64. #define smp_rmb() barrier()
  65. #define smp_wmb() barrier()
  66. #define smp_read_barrier_depends() do { } while(0)
  67. #endif
  68. #define read_barrier_depends() ((void)0)
  69. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  70. struct __xchg_dummy { unsigned long a[100]; };
  71. #define __xg(x) ((volatile struct __xchg_dummy *)(x))
  72. #ifndef CONFIG_RMW_INSNS
  73. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  74. {
  75. unsigned long tmp, flags;
  76. local_irq_save(flags);
  77. switch (size) {
  78. case 1:
  79. __asm__ __volatile__
  80. ("moveb %2,%0\n\t"
  81. "moveb %1,%2"
  82. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  83. break;
  84. case 2:
  85. __asm__ __volatile__
  86. ("movew %2,%0\n\t"
  87. "movew %1,%2"
  88. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  89. break;
  90. case 4:
  91. __asm__ __volatile__
  92. ("movel %2,%0\n\t"
  93. "movel %1,%2"
  94. : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
  95. break;
  96. }
  97. local_irq_restore(flags);
  98. return tmp;
  99. }
  100. #else
  101. static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
  102. {
  103. switch (size) {
  104. case 1:
  105. __asm__ __volatile__
  106. ("moveb %2,%0\n\t"
  107. "1:\n\t"
  108. "casb %0,%1,%2\n\t"
  109. "jne 1b"
  110. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  111. break;
  112. case 2:
  113. __asm__ __volatile__
  114. ("movew %2,%0\n\t"
  115. "1:\n\t"
  116. "casw %0,%1,%2\n\t"
  117. "jne 1b"
  118. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  119. break;
  120. case 4:
  121. __asm__ __volatile__
  122. ("movel %2,%0\n\t"
  123. "1:\n\t"
  124. "casl %0,%1,%2\n\t"
  125. "jne 1b"
  126. : "=&d" (x) : "d" (x), "m" (*__xg(ptr)) : "memory");
  127. break;
  128. }
  129. return x;
  130. }
  131. #endif
  132. #include <asm-generic/cmpxchg-local.h>
  133. /*
  134. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  135. * them available.
  136. */
  137. #define cmpxchg_local(ptr, o, n) \
  138. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  139. (unsigned long)(n), sizeof(*(ptr))))
  140. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  141. #ifndef CONFIG_SMP
  142. #include <asm-generic/cmpxchg.h>
  143. #endif
  144. #define arch_align_stack(x) (x)
  145. #endif /* _M68KNOMMU_SYSTEM_H */