system.h 6.3 KB

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