processor.h 6.7 KB

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