system.h 7.3 KB

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