system.h 7.4 KB

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