system_32.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. #ifndef __SPARC_SYSTEM_H
  2. #define __SPARC_SYSTEM_H
  3. #include <linux/kernel.h>
  4. #include <linux/threads.h> /* NR_CPUS */
  5. #include <linux/thread_info.h>
  6. #include <asm/page.h>
  7. #include <asm/psr.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/btfixup.h>
  10. #include <asm/smp.h>
  11. #ifndef __ASSEMBLY__
  12. #include <linux/irqflags.h>
  13. /*
  14. * Sparc (general) CPU types
  15. */
  16. enum sparc_cpu {
  17. sun4 = 0x00,
  18. sun4c = 0x01,
  19. sun4m = 0x02,
  20. sun4d = 0x03,
  21. sun4e = 0x04,
  22. sun4u = 0x05, /* V8 ploos ploos */
  23. sun_unknown = 0x06,
  24. ap1000 = 0x07, /* almost a sun4m */
  25. };
  26. /* Really, userland should not be looking at any of this... */
  27. #ifdef __KERNEL__
  28. extern enum sparc_cpu sparc_cpu_model;
  29. #define ARCH_SUN4C (sparc_cpu_model==sun4c)
  30. #define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
  31. extern char reboot_command[];
  32. extern struct thread_info *current_set[NR_CPUS];
  33. extern unsigned long empty_bad_page;
  34. extern unsigned long empty_bad_page_table;
  35. extern unsigned long empty_zero_page;
  36. extern void sun_do_break(void);
  37. extern int serial_console;
  38. extern int stop_a_enabled;
  39. extern int scons_pwroff;
  40. static inline int con_is_present(void)
  41. {
  42. return serial_console ? 0 : 1;
  43. }
  44. /* When a context switch happens we must flush all user windows so that
  45. * the windows of the current process are flushed onto its stack. This
  46. * way the windows are all clean for the next process and the stack
  47. * frames are up to date.
  48. */
  49. extern void flush_user_windows(void);
  50. extern void kill_user_windows(void);
  51. extern void synchronize_user_stack(void);
  52. extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
  53. void *fpqueue, unsigned long *fpqdepth);
  54. #ifdef CONFIG_SMP
  55. #define SWITCH_ENTER(prv) \
  56. do { \
  57. if (test_tsk_thread_flag(prv, TIF_USEDFPU)) { \
  58. put_psr(get_psr() | PSR_EF); \
  59. fpsave(&(prv)->thread.float_regs[0], &(prv)->thread.fsr, \
  60. &(prv)->thread.fpqueue[0], &(prv)->thread.fpqdepth); \
  61. clear_tsk_thread_flag(prv, TIF_USEDFPU); \
  62. (prv)->thread.kregs->psr &= ~PSR_EF; \
  63. } \
  64. } while(0)
  65. #define SWITCH_DO_LAZY_FPU(next) /* */
  66. #else
  67. #define SWITCH_ENTER(prv) /* */
  68. #define SWITCH_DO_LAZY_FPU(nxt) \
  69. do { \
  70. if (last_task_used_math != (nxt)) \
  71. (nxt)->thread.kregs->psr&=~PSR_EF; \
  72. } while(0)
  73. #endif
  74. extern void flushw_all(void);
  75. /*
  76. * Flush windows so that the VM switch which follows
  77. * would not pull the stack from under us.
  78. *
  79. * SWITCH_ENTER and SWITH_DO_LAZY_FPU do not work yet (e.g. SMP does not work)
  80. * XXX WTF is the above comment? Found in late teen 2.4.x.
  81. */
  82. #define prepare_arch_switch(next) do { \
  83. __asm__ __volatile__( \
  84. ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
  85. "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
  86. "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
  87. "save %sp, -0x40, %sp\n\t" \
  88. "restore; restore; restore; restore; restore; restore; restore"); \
  89. } while(0)
  90. /* Much care has gone into this code, do not touch it.
  91. *
  92. * We need to loadup regs l0/l1 for the newly forked child
  93. * case because the trap return path relies on those registers
  94. * holding certain values, gcc is told that they are clobbered.
  95. * Gcc needs registers for 3 values in and 1 value out, so we
  96. * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
  97. *
  98. * Hey Dave, that do not touch sign is too much of an incentive
  99. * - Anton & Pete
  100. */
  101. #define switch_to(prev, next, last) do { \
  102. SWITCH_ENTER(prev); \
  103. SWITCH_DO_LAZY_FPU(next); \
  104. cpu_set(smp_processor_id(), next->active_mm->cpu_vm_mask); \
  105. __asm__ __volatile__( \
  106. "sethi %%hi(here - 0x8), %%o7\n\t" \
  107. "mov %%g6, %%g3\n\t" \
  108. "or %%o7, %%lo(here - 0x8), %%o7\n\t" \
  109. "rd %%psr, %%g4\n\t" \
  110. "std %%sp, [%%g6 + %4]\n\t" \
  111. "rd %%wim, %%g5\n\t" \
  112. "wr %%g4, 0x20, %%psr\n\t" \
  113. "nop\n\t" \
  114. "std %%g4, [%%g6 + %3]\n\t" \
  115. "ldd [%2 + %3], %%g4\n\t" \
  116. "mov %2, %%g6\n\t" \
  117. ".globl patchme_store_new_current\n" \
  118. "patchme_store_new_current:\n\t" \
  119. "st %2, [%1]\n\t" \
  120. "wr %%g4, 0x20, %%psr\n\t" \
  121. "nop\n\t" \
  122. "nop\n\t" \
  123. "nop\n\t" /* LEON needs all 3 nops: load to %sp depends on CWP. */ \
  124. "ldd [%%g6 + %4], %%sp\n\t" \
  125. "wr %%g5, 0x0, %%wim\n\t" \
  126. "ldd [%%sp + 0x00], %%l0\n\t" \
  127. "ldd [%%sp + 0x38], %%i6\n\t" \
  128. "wr %%g4, 0x0, %%psr\n\t" \
  129. "nop\n\t" \
  130. "nop\n\t" \
  131. "jmpl %%o7 + 0x8, %%g0\n\t" \
  132. " ld [%%g3 + %5], %0\n\t" \
  133. "here:\n" \
  134. : "=&r" (last) \
  135. : "r" (&(current_set[hard_smp_processor_id()])), \
  136. "r" (task_thread_info(next)), \
  137. "i" (TI_KPSR), \
  138. "i" (TI_KSP), \
  139. "i" (TI_TASK) \
  140. : "g1", "g2", "g3", "g4", "g5", "g7", \
  141. "l0", "l1", "l3", "l4", "l5", "l6", "l7", \
  142. "i0", "i1", "i2", "i3", "i4", "i5", \
  143. "o0", "o1", "o2", "o3", "o7"); \
  144. } while(0)
  145. /* XXX Change this if we ever use a PSO mode kernel. */
  146. #define mb() __asm__ __volatile__ ("" : : : "memory")
  147. #define rmb() mb()
  148. #define wmb() mb()
  149. #define read_barrier_depends() do { } while(0)
  150. #define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
  151. #define smp_mb() __asm__ __volatile__("":::"memory")
  152. #define smp_rmb() __asm__ __volatile__("":::"memory")
  153. #define smp_wmb() __asm__ __volatile__("":::"memory")
  154. #define smp_read_barrier_depends() do { } while(0)
  155. #define nop() __asm__ __volatile__ ("nop")
  156. /* This has special calling conventions */
  157. #ifndef CONFIG_SMP
  158. BTFIXUPDEF_CALL(void, ___xchg32, void)
  159. #endif
  160. static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
  161. {
  162. #ifdef CONFIG_SMP
  163. __asm__ __volatile__("swap [%2], %0"
  164. : "=&r" (val)
  165. : "0" (val), "r" (m)
  166. : "memory");
  167. return val;
  168. #else
  169. register unsigned long *ptr asm("g1");
  170. register unsigned long ret asm("g2");
  171. ptr = (unsigned long *) m;
  172. ret = val;
  173. /* Note: this is magic and the nop there is
  174. really needed. */
  175. __asm__ __volatile__(
  176. "mov %%o7, %%g4\n\t"
  177. "call ___f____xchg32\n\t"
  178. " nop\n\t"
  179. : "=&r" (ret)
  180. : "0" (ret), "r" (ptr)
  181. : "g3", "g4", "g7", "memory", "cc");
  182. return ret;
  183. #endif
  184. }
  185. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  186. extern void __xchg_called_with_bad_pointer(void);
  187. static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
  188. {
  189. switch (size) {
  190. case 4:
  191. return xchg_u32(ptr, x);
  192. };
  193. __xchg_called_with_bad_pointer();
  194. return x;
  195. }
  196. /* Emulate cmpxchg() the same way we emulate atomics,
  197. * by hashing the object address and indexing into an array
  198. * of spinlocks to get a bit of performance...
  199. *
  200. * See arch/sparc/lib/atomic32.c for implementation.
  201. *
  202. * Cribbed from <asm-parisc/atomic.h>
  203. */
  204. #define __HAVE_ARCH_CMPXCHG 1
  205. /* bug catcher for when unsupported size is used - won't link */
  206. extern void __cmpxchg_called_with_bad_pointer(void);
  207. /* we only need to support cmpxchg of a u32 on sparc */
  208. extern unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
  209. /* don't worry...optimizer will get rid of most of this */
  210. static inline unsigned long
  211. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
  212. {
  213. switch (size) {
  214. case 4:
  215. return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
  216. default:
  217. __cmpxchg_called_with_bad_pointer();
  218. break;
  219. }
  220. return old;
  221. }
  222. #define cmpxchg(ptr, o, n) \
  223. ({ \
  224. __typeof__(*(ptr)) _o_ = (o); \
  225. __typeof__(*(ptr)) _n_ = (n); \
  226. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  227. (unsigned long)_n_, sizeof(*(ptr))); \
  228. })
  229. #include <asm-generic/cmpxchg-local.h>
  230. /*
  231. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  232. * them available.
  233. */
  234. #define cmpxchg_local(ptr, o, n) \
  235. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  236. (unsigned long)(n), sizeof(*(ptr))))
  237. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  238. extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
  239. #endif /* __KERNEL__ */
  240. #endif /* __ASSEMBLY__ */
  241. #define arch_align_stack(x) (x)
  242. #endif /* !(__SPARC_SYSTEM_H) */