system.h 6.6 KB

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