processor_64.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * include/asm/processor.h
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #ifndef __ASM_SPARC64_PROCESSOR_H
  7. #define __ASM_SPARC64_PROCESSOR_H
  8. /*
  9. * Sparc64 implementation of macro that returns current
  10. * instruction pointer ("program counter").
  11. */
  12. #define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
  13. #include <asm/asi.h>
  14. #include <asm/pstate.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/page.h>
  17. /* Don't hold the runqueue lock over context switch */
  18. #define __ARCH_WANT_UNLOCKED_CTXSW
  19. /* The sparc has no problems with write protection */
  20. #define wp_works_ok 1
  21. #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
  22. /*
  23. * User lives in his very own context, and cannot reference us. Note
  24. * that TASK_SIZE is a misnomer, it really gives maximum user virtual
  25. * address that the kernel will allocate out.
  26. *
  27. * XXX No longer using virtual page tables, kill this upper limit...
  28. */
  29. #define VA_BITS 44
  30. #ifndef __ASSEMBLY__
  31. #define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
  32. #else
  33. #define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
  34. #endif
  35. #define TASK_SIZE_OF(tsk) \
  36. (test_tsk_thread_flag(tsk,TIF_32BIT) ? \
  37. (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
  38. #define TASK_SIZE \
  39. (test_thread_flag(TIF_32BIT) ? \
  40. (1UL << 32UL) : ((unsigned long)-VPTE_SIZE))
  41. #ifdef __KERNEL__
  42. #define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
  43. #define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
  44. #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
  45. STACK_TOP32 : STACK_TOP64)
  46. #define STACK_TOP_MAX STACK_TOP64
  47. #endif
  48. #ifndef __ASSEMBLY__
  49. typedef struct {
  50. unsigned char seg;
  51. } mm_segment_t;
  52. /* The Sparc processor specific thread struct. */
  53. /* XXX This should die, everything can go into thread_info now. */
  54. struct thread_struct {
  55. #ifdef CONFIG_DEBUG_SPINLOCK
  56. /* How many spinlocks held by this thread.
  57. * Used with spin lock debugging to catch tasks
  58. * sleeping illegally with locks held.
  59. */
  60. int smp_lock_count;
  61. unsigned int smp_lock_pc;
  62. #else
  63. int dummy; /* f'in gcc bug... */
  64. #endif
  65. };
  66. #endif /* !(__ASSEMBLY__) */
  67. #ifndef CONFIG_DEBUG_SPINLOCK
  68. #define INIT_THREAD { \
  69. 0, \
  70. }
  71. #else /* CONFIG_DEBUG_SPINLOCK */
  72. #define INIT_THREAD { \
  73. /* smp_lock_count, smp_lock_pc, */ \
  74. 0, 0, \
  75. }
  76. #endif /* !(CONFIG_DEBUG_SPINLOCK) */
  77. #ifndef __ASSEMBLY__
  78. #include <linux/types.h>
  79. #include <asm/fpumacro.h>
  80. /* Return saved PC of a blocked thread. */
  81. struct task_struct;
  82. extern unsigned long thread_saved_pc(struct task_struct *);
  83. /* On Uniprocessor, even in RMO processes see TSO semantics */
  84. #ifdef CONFIG_SMP
  85. #define TSTATE_INITIAL_MM TSTATE_TSO
  86. #else
  87. #define TSTATE_INITIAL_MM TSTATE_RMO
  88. #endif
  89. /* Do necessary setup to start up a newly executed thread. */
  90. #define start_thread(regs, pc, sp) \
  91. do { \
  92. unsigned long __asi = ASI_PNF; \
  93. regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
  94. regs->tpc = ((pc & (~3)) - 4); \
  95. regs->tnpc = regs->tpc + 4; \
  96. regs->y = 0; \
  97. set_thread_wstate(1 << 3); \
  98. if (current_thread_info()->utraps) { \
  99. if (*(current_thread_info()->utraps) < 2) \
  100. kfree(current_thread_info()->utraps); \
  101. else \
  102. (*(current_thread_info()->utraps))--; \
  103. current_thread_info()->utraps = NULL; \
  104. } \
  105. __asm__ __volatile__( \
  106. "stx %%g0, [%0 + %2 + 0x00]\n\t" \
  107. "stx %%g0, [%0 + %2 + 0x08]\n\t" \
  108. "stx %%g0, [%0 + %2 + 0x10]\n\t" \
  109. "stx %%g0, [%0 + %2 + 0x18]\n\t" \
  110. "stx %%g0, [%0 + %2 + 0x20]\n\t" \
  111. "stx %%g0, [%0 + %2 + 0x28]\n\t" \
  112. "stx %%g0, [%0 + %2 + 0x30]\n\t" \
  113. "stx %%g0, [%0 + %2 + 0x38]\n\t" \
  114. "stx %%g0, [%0 + %2 + 0x40]\n\t" \
  115. "stx %%g0, [%0 + %2 + 0x48]\n\t" \
  116. "stx %%g0, [%0 + %2 + 0x50]\n\t" \
  117. "stx %%g0, [%0 + %2 + 0x58]\n\t" \
  118. "stx %%g0, [%0 + %2 + 0x60]\n\t" \
  119. "stx %%g0, [%0 + %2 + 0x68]\n\t" \
  120. "stx %1, [%0 + %2 + 0x70]\n\t" \
  121. "stx %%g0, [%0 + %2 + 0x78]\n\t" \
  122. "wrpr %%g0, (1 << 3), %%wstate\n\t" \
  123. : \
  124. : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
  125. "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
  126. fprs_write(0); \
  127. current_thread_info()->xfsr[0] = 0; \
  128. current_thread_info()->fpsaved[0] = 0; \
  129. regs->tstate &= ~TSTATE_PEF; \
  130. } while (0)
  131. #define start_thread32(regs, pc, sp) \
  132. do { \
  133. unsigned long __asi = ASI_PNF; \
  134. pc &= 0x00000000ffffffffUL; \
  135. sp &= 0x00000000ffffffffUL; \
  136. regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
  137. regs->tpc = ((pc & (~3)) - 4); \
  138. regs->tnpc = regs->tpc + 4; \
  139. regs->y = 0; \
  140. set_thread_wstate(2 << 3); \
  141. if (current_thread_info()->utraps) { \
  142. if (*(current_thread_info()->utraps) < 2) \
  143. kfree(current_thread_info()->utraps); \
  144. else \
  145. (*(current_thread_info()->utraps))--; \
  146. current_thread_info()->utraps = NULL; \
  147. } \
  148. __asm__ __volatile__( \
  149. "stx %%g0, [%0 + %2 + 0x00]\n\t" \
  150. "stx %%g0, [%0 + %2 + 0x08]\n\t" \
  151. "stx %%g0, [%0 + %2 + 0x10]\n\t" \
  152. "stx %%g0, [%0 + %2 + 0x18]\n\t" \
  153. "stx %%g0, [%0 + %2 + 0x20]\n\t" \
  154. "stx %%g0, [%0 + %2 + 0x28]\n\t" \
  155. "stx %%g0, [%0 + %2 + 0x30]\n\t" \
  156. "stx %%g0, [%0 + %2 + 0x38]\n\t" \
  157. "stx %%g0, [%0 + %2 + 0x40]\n\t" \
  158. "stx %%g0, [%0 + %2 + 0x48]\n\t" \
  159. "stx %%g0, [%0 + %2 + 0x50]\n\t" \
  160. "stx %%g0, [%0 + %2 + 0x58]\n\t" \
  161. "stx %%g0, [%0 + %2 + 0x60]\n\t" \
  162. "stx %%g0, [%0 + %2 + 0x68]\n\t" \
  163. "stx %1, [%0 + %2 + 0x70]\n\t" \
  164. "stx %%g0, [%0 + %2 + 0x78]\n\t" \
  165. "wrpr %%g0, (2 << 3), %%wstate\n\t" \
  166. : \
  167. : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
  168. "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
  169. fprs_write(0); \
  170. current_thread_info()->xfsr[0] = 0; \
  171. current_thread_info()->fpsaved[0] = 0; \
  172. regs->tstate &= ~TSTATE_PEF; \
  173. } while (0)
  174. /* Free all resources held by a thread. */
  175. #define release_thread(tsk) do { } while (0)
  176. extern unsigned long get_wchan(struct task_struct *task);
  177. #define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
  178. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
  179. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
  180. #define cpu_relax() barrier()
  181. /* Prefetch support. This is tuned for UltraSPARC-III and later.
  182. * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
  183. * a shallower prefetch queue than later chips.
  184. */
  185. #define ARCH_HAS_PREFETCH
  186. #define ARCH_HAS_PREFETCHW
  187. #define ARCH_HAS_SPINLOCK_PREFETCH
  188. static inline void prefetch(const void *x)
  189. {
  190. /* We do not use the read prefetch mnemonic because that
  191. * prefetches into the prefetch-cache which only is accessible
  192. * by floating point operations in UltraSPARC-III and later.
  193. * By contrast, "#one_write" prefetches into the L2 cache
  194. * in shared state.
  195. */
  196. __asm__ __volatile__("prefetch [%0], #one_write"
  197. : /* no outputs */
  198. : "r" (x));
  199. }
  200. static inline void prefetchw(const void *x)
  201. {
  202. /* The most optimal prefetch to use for writes is
  203. * "#n_writes". This brings the cacheline into the
  204. * L2 cache in "owned" state.
  205. */
  206. __asm__ __volatile__("prefetch [%0], #n_writes"
  207. : /* no outputs */
  208. : "r" (x));
  209. }
  210. #define spin_lock_prefetch(x) prefetchw(x)
  211. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  212. #endif /* !(__ASSEMBLY__) */
  213. #endif /* !(__ASM_SPARC64_PROCESSOR_H) */