processor.h 6.5 KB

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