system.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (C) 1994 - 1999 by Ralf Baechle
  3. * Copyright (C) 1996 by Paul M. Antoine
  4. * Copyright (C) 1994 - 1999 by Ralf Baechle
  5. *
  6. * Changed set_except_vector declaration to allow return of previous
  7. * vector address value - necessary for "borrowing" vectors.
  8. *
  9. * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000 MIPS Technologies, Inc.
  11. *
  12. * SPDX-License-Identifier: GPL-2.0
  13. */
  14. #ifndef _ASM_SYSTEM_H
  15. #define _ASM_SYSTEM_H
  16. #include <asm/sgidefs.h>
  17. #include <asm/ptrace.h>
  18. #if 0
  19. #include <linux/kernel.h>
  20. #endif
  21. static __inline__ void
  22. __sti(void)
  23. {
  24. __asm__ __volatile__(
  25. ".set\tpush\n\t"
  26. ".set\treorder\n\t"
  27. ".set\tnoat\n\t"
  28. "mfc0\t$1,$12\n\t"
  29. "ori\t$1,0x1f\n\t"
  30. "xori\t$1,0x1e\n\t"
  31. "mtc0\t$1,$12\n\t"
  32. ".set\tpop\n\t"
  33. : /* no outputs */
  34. : /* no inputs */
  35. : "$1", "memory");
  36. }
  37. /*
  38. * For cli() we have to insert nops to make shure that the new value
  39. * has actually arrived in the status register before the end of this
  40. * macro.
  41. * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
  42. * no nops at all.
  43. */
  44. static __inline__ void
  45. __cli(void)
  46. {
  47. __asm__ __volatile__(
  48. ".set\tpush\n\t"
  49. ".set\treorder\n\t"
  50. ".set\tnoat\n\t"
  51. "mfc0\t$1,$12\n\t"
  52. "ori\t$1,1\n\t"
  53. "xori\t$1,1\n\t"
  54. ".set\tnoreorder\n\t"
  55. "mtc0\t$1,$12\n\t"
  56. "nop\n\t"
  57. "nop\n\t"
  58. "nop\n\t"
  59. ".set\tpop\n\t"
  60. : /* no outputs */
  61. : /* no inputs */
  62. : "$1", "memory");
  63. }
  64. #define __save_flags(x) \
  65. __asm__ __volatile__( \
  66. ".set\tpush\n\t" \
  67. ".set\treorder\n\t" \
  68. "mfc0\t%0,$12\n\t" \
  69. ".set\tpop\n\t" \
  70. : "=r" (x))
  71. #define __save_and_cli(x) \
  72. __asm__ __volatile__( \
  73. ".set\tpush\n\t" \
  74. ".set\treorder\n\t" \
  75. ".set\tnoat\n\t" \
  76. "mfc0\t%0,$12\n\t" \
  77. "ori\t$1,%0,1\n\t" \
  78. "xori\t$1,1\n\t" \
  79. ".set\tnoreorder\n\t" \
  80. "mtc0\t$1,$12\n\t" \
  81. "nop\n\t" \
  82. "nop\n\t" \
  83. "nop\n\t" \
  84. ".set\tpop\n\t" \
  85. : "=r" (x) \
  86. : /* no inputs */ \
  87. : "$1", "memory")
  88. #define __restore_flags(flags) \
  89. do { \
  90. unsigned long __tmp1; \
  91. \
  92. __asm__ __volatile__( \
  93. ".set\tnoreorder\t\t\t# __restore_flags\n\t" \
  94. ".set\tnoat\n\t" \
  95. "mfc0\t$1, $12\n\t" \
  96. "andi\t%0, 1\n\t" \
  97. "ori\t$1, 1\n\t" \
  98. "xori\t$1, 1\n\t" \
  99. "or\t%0, $1\n\t" \
  100. "mtc0\t%0, $12\n\t" \
  101. "nop\n\t" \
  102. "nop\n\t" \
  103. "nop\n\t" \
  104. ".set\tat\n\t" \
  105. ".set\treorder" \
  106. : "=r" (__tmp1) \
  107. : "0" (flags) \
  108. : "$1", "memory"); \
  109. } while(0)
  110. #ifdef CONFIG_SMP
  111. extern void __global_sti(void);
  112. extern void __global_cli(void);
  113. extern unsigned long __global_save_flags(void);
  114. extern void __global_restore_flags(unsigned long);
  115. # define sti() __global_sti()
  116. # define cli() __global_cli()
  117. # define save_flags(x) do { x = __global_save_flags(); } while (0)
  118. # define restore_flags(x) __global_restore_flags(x)
  119. # define save_and_cli(x) do { save_flags(x); cli(); } while(0)
  120. #else /* Single processor */
  121. # define sti() __sti()
  122. # define cli() __cli()
  123. # define save_flags(x) __save_flags(x)
  124. # define save_and_cli(x) __save_and_cli(x)
  125. # define restore_flags(x) __restore_flags(x)
  126. #endif /* SMP */
  127. /* For spinlocks etc */
  128. #define local_irq_save(x) __save_and_cli(x);
  129. #define local_irq_restore(x) __restore_flags(x);
  130. #define local_irq_disable() __cli();
  131. #define local_irq_enable() __sti();
  132. /*
  133. * These are probably defined overly paranoid ...
  134. */
  135. #ifdef CONFIG_CPU_HAS_WB
  136. #include <asm/wbflush.h>
  137. #define rmb() do { } while(0)
  138. #define wmb() wbflush()
  139. #define mb() wbflush()
  140. #else /* CONFIG_CPU_HAS_WB */
  141. #define mb() \
  142. __asm__ __volatile__( \
  143. "# prevent instructions being moved around\n\t" \
  144. ".set\tnoreorder\n\t" \
  145. "# 8 nops to fool the R4400 pipeline\n\t" \
  146. "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
  147. ".set\treorder" \
  148. : /* no output */ \
  149. : /* no input */ \
  150. : "memory")
  151. #define rmb() mb()
  152. #define wmb() mb()
  153. #endif /* CONFIG_CPU_HAS_WB */
  154. #ifdef CONFIG_SMP
  155. #define smp_mb() mb()
  156. #define smp_rmb() rmb()
  157. #define smp_wmb() wmb()
  158. #else
  159. #define smp_mb() barrier()
  160. #define smp_rmb() barrier()
  161. #define smp_wmb() barrier()
  162. #endif
  163. #define set_mb(var, value) \
  164. do { var = value; mb(); } while (0)
  165. #define set_wmb(var, value) \
  166. do { var = value; wmb(); } while (0)
  167. #if !defined (_LANGUAGE_ASSEMBLY)
  168. /*
  169. * switch_to(n) should switch tasks to task nr n, first
  170. * checking that n isn't the current task, in which case it does nothing.
  171. */
  172. #if 0
  173. extern asmlinkage void *resume(void *last, void *next);
  174. #endif
  175. #endif /* !defined (_LANGUAGE_ASSEMBLY) */
  176. #define prepare_to_switch() do { } while(0)
  177. #define switch_to(prev,next,last) \
  178. do { \
  179. (last) = resume(prev, next); \
  180. } while(0)
  181. /*
  182. * For 32 and 64 bit operands we can take advantage of ll and sc.
  183. * FIXME: This doesn't work for R3000 machines.
  184. */
  185. static __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
  186. {
  187. #ifdef CONFIG_CPU_HAS_LLSC
  188. unsigned long dummy;
  189. __asm__ __volatile__(
  190. ".set\tnoreorder\t\t\t# xchg_u32\n\t"
  191. ".set\tnoat\n\t"
  192. "ll\t%0, %3\n"
  193. "1:\tmove\t$1, %2\n\t"
  194. "sc\t$1, %1\n\t"
  195. "beqzl\t$1, 1b\n\t"
  196. " ll\t%0, %3\n\t"
  197. ".set\tat\n\t"
  198. ".set\treorder"
  199. : "=r" (val), "=o" (*m), "=r" (dummy)
  200. : "o" (*m), "2" (val)
  201. : "memory");
  202. return val;
  203. #else
  204. unsigned long flags, retval;
  205. save_flags(flags);
  206. cli();
  207. retval = *m;
  208. *m = val;
  209. restore_flags(flags);
  210. return retval;
  211. #endif /* Processor-dependent optimization */
  212. }
  213. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  214. #define tas(ptr) (xchg((ptr),1))
  215. static __inline__ unsigned long
  216. __xchg(unsigned long x, volatile void * ptr, int size)
  217. {
  218. switch (size) {
  219. case 4:
  220. return xchg_u32(ptr, x);
  221. }
  222. return x;
  223. }
  224. extern void *set_except_vector(int n, void *addr);
  225. extern void __die(const char *, struct pt_regs *, const char *where,
  226. unsigned long line) __attribute__((noreturn));
  227. extern void __die_if_kernel(const char *, struct pt_regs *, const char *where,
  228. unsigned long line);
  229. #define die(msg, regs) \
  230. __die(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
  231. #define die_if_kernel(msg, regs) \
  232. __die_if_kernel(msg, regs, __FILE__ ":"__FUNCTION__, __LINE__)
  233. static inline void execution_hazard_barrier(void)
  234. {
  235. __asm__ __volatile__(
  236. ".set noreorder\n"
  237. "ehb\n"
  238. ".set reorder");
  239. }
  240. #endif /* _ASM_SYSTEM_H */