thread_info.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* $Id: thread_info.h,v 1.1 2002/02/10 00:00:58 davem Exp $
  2. * thread_info.h: sparc64 low-level thread information
  3. *
  4. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  5. */
  6. #ifndef _ASM_THREAD_INFO_H
  7. #define _ASM_THREAD_INFO_H
  8. #ifdef __KERNEL__
  9. #define NSWINS 7
  10. #define TI_FLAG_BYTE_FAULT_CODE 0
  11. #define TI_FLAG_FAULT_CODE_SHIFT 56
  12. #define TI_FLAG_BYTE_WSTATE 1
  13. #define TI_FLAG_WSTATE_SHIFT 48
  14. #define TI_FLAG_BYTE_CWP 2
  15. #define TI_FLAG_CWP_SHIFT 40
  16. #define TI_FLAG_BYTE_CURRENT_DS 3
  17. #define TI_FLAG_CURRENT_DS_SHIFT 32
  18. #define TI_FLAG_BYTE_FPDEPTH 4
  19. #define TI_FLAG_FPDEPTH_SHIFT 24
  20. #define TI_FLAG_BYTE_WSAVED 5
  21. #define TI_FLAG_WSAVED_SHIFT 16
  22. #include <asm/page.h>
  23. #ifndef __ASSEMBLY__
  24. #include <asm/ptrace.h>
  25. #include <asm/types.h>
  26. struct task_struct;
  27. struct exec_domain;
  28. struct thread_info {
  29. /* D$ line 1 */
  30. struct task_struct *task;
  31. unsigned long flags;
  32. __u8 cpu;
  33. __u8 fpsaved[7];
  34. unsigned long ksp;
  35. /* D$ line 2 */
  36. unsigned long fault_address;
  37. struct pt_regs *kregs;
  38. struct exec_domain *exec_domain;
  39. int preempt_count; /* 0 => preemptable, <0 => BUG */
  40. int __pad;
  41. unsigned long *utraps;
  42. struct reg_window reg_window[NSWINS];
  43. unsigned long rwbuf_stkptrs[NSWINS];
  44. unsigned long gsr[7];
  45. unsigned long xfsr[7];
  46. __u64 __user *user_cntd0;
  47. __u64 __user *user_cntd1;
  48. __u64 kernel_cntd0, kernel_cntd1;
  49. __u64 pcr_reg;
  50. __u64 cee_stuff;
  51. struct restart_block restart_block;
  52. unsigned long fpregs[0] __attribute__ ((aligned(64)));
  53. };
  54. #endif /* !(__ASSEMBLY__) */
  55. /* offsets into the thread_info struct for assembly code access */
  56. #define TI_TASK 0x00000000
  57. #define TI_FLAGS 0x00000008
  58. #define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
  59. #define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
  60. #define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP)
  61. #define TI_CURRENT_DS (TI_FLAGS + TI_FLAG_BYTE_CURRENT_DS)
  62. #define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
  63. #define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
  64. #define TI_CPU 0x00000010
  65. #define TI_FPSAVED 0x00000011
  66. #define TI_KSP 0x00000018
  67. #define TI_FAULT_ADDR 0x00000020
  68. #define TI_KREGS 0x00000028
  69. #define TI_EXEC_DOMAIN 0x00000030
  70. #define TI_PRE_COUNT 0x00000038
  71. #define TI_UTRAPS 0x00000040
  72. #define TI_REG_WINDOW 0x00000048
  73. #define TI_RWIN_SPTRS 0x000003c8
  74. #define TI_GSR 0x00000400
  75. #define TI_XFSR 0x00000438
  76. #define TI_USER_CNTD0 0x00000470
  77. #define TI_USER_CNTD1 0x00000478
  78. #define TI_KERN_CNTD0 0x00000480
  79. #define TI_KERN_CNTD1 0x00000488
  80. #define TI_PCR 0x00000490
  81. #define TI_CEE_STUFF 0x00000498
  82. #define TI_RESTART_BLOCK 0x000004a0
  83. #define TI_FPREGS 0x00000500
  84. /* We embed this in the uppermost byte of thread_info->flags */
  85. #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
  86. #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
  87. #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
  88. #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
  89. #define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
  90. #if PAGE_SHIFT == 13
  91. #define THREAD_SIZE (2*PAGE_SIZE)
  92. #define THREAD_SHIFT (PAGE_SHIFT + 1)
  93. #else /* PAGE_SHIFT == 13 */
  94. #define THREAD_SIZE PAGE_SIZE
  95. #define THREAD_SHIFT PAGE_SHIFT
  96. #endif /* PAGE_SHIFT == 13 */
  97. #define PREEMPT_ACTIVE 0x4000000
  98. /*
  99. * macros/functions for gaining access to the thread information structure
  100. *
  101. * preempt_count needs to be 1 initially, until the scheduler is functional.
  102. */
  103. #ifndef __ASSEMBLY__
  104. #define INIT_THREAD_INFO(tsk) \
  105. { \
  106. .task = &tsk, \
  107. .flags = ((unsigned long)ASI_P) << TI_FLAG_CURRENT_DS_SHIFT, \
  108. .exec_domain = &default_exec_domain, \
  109. .preempt_count = 1, \
  110. .restart_block = { \
  111. .fn = do_no_restart_syscall, \
  112. }, \
  113. }
  114. #define init_thread_info (init_thread_union.thread_info)
  115. #define init_stack (init_thread_union.stack)
  116. /* how to get the thread information struct from C */
  117. register struct thread_info *current_thread_info_reg asm("g6");
  118. #define current_thread_info() (current_thread_info_reg)
  119. /* thread information allocation */
  120. #if PAGE_SHIFT == 13
  121. #define __THREAD_INFO_ORDER 1
  122. #else /* PAGE_SHIFT == 13 */
  123. #define __THREAD_INFO_ORDER 0
  124. #endif /* PAGE_SHIFT == 13 */
  125. #ifdef CONFIG_DEBUG_STACK_USAGE
  126. #define alloc_thread_info(tsk) \
  127. ({ \
  128. struct thread_info *ret; \
  129. \
  130. ret = (struct thread_info *) \
  131. __get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER); \
  132. if (ret) \
  133. memset(ret, 0, PAGE_SIZE<<__THREAD_INFO_ORDER); \
  134. ret; \
  135. })
  136. #else
  137. #define alloc_thread_info(tsk) \
  138. ((struct thread_info *)__get_free_pages(GFP_KERNEL, __THREAD_INFO_ORDER))
  139. #endif
  140. #define free_thread_info(ti) \
  141. free_pages((unsigned long)(ti),__THREAD_INFO_ORDER)
  142. #define __thread_flag_byte_ptr(ti) \
  143. ((unsigned char *)(&((ti)->flags)))
  144. #define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info())
  145. #define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
  146. #define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
  147. #define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
  148. #define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
  149. #define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
  150. #define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
  151. #define get_thread_current_ds() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS])
  152. #define set_thread_current_ds(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS] = (val))
  153. #define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
  154. #define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
  155. #define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
  156. #define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
  157. #endif /* !(__ASSEMBLY__) */
  158. /*
  159. * Thread information flags, only 16 bits are available as we encode
  160. * other values into the upper 6 bytes.
  161. *
  162. * On trap return we need to test several values:
  163. *
  164. * user: need_resched, notify_resume, sigpending, wsaved, perfctr
  165. * kernel: fpdepth
  166. *
  167. * So to check for work in the kernel case we simply load the fpdepth
  168. * byte out of the flags and test it. For the user case we encode the
  169. * lower 3 bytes of flags as follows:
  170. * ----------------------------------------
  171. * | wsaved | flags byte 1 | flags byte 2 |
  172. * ----------------------------------------
  173. * This optimizes the user test into:
  174. * ldx [%g6 + TI_FLAGS], REG1
  175. * sethi %hi(_TIF_USER_WORK_MASK), REG2
  176. * or REG2, %lo(_TIF_USER_WORK_MASK), REG2
  177. * andcc REG1, REG2, %g0
  178. * be,pt no_work_to_do
  179. * nop
  180. */
  181. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  182. #define TIF_NOTIFY_RESUME 1 /* resumption notification requested */
  183. #define TIF_SIGPENDING 2 /* signal pending */
  184. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  185. #define TIF_PERFCTR 4 /* performance counters active */
  186. #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
  187. #define TIF_NEWSIGNALS 6 /* wants new-style signals */
  188. #define TIF_32BIT 7 /* 32-bit binary */
  189. #define TIF_NEWCHILD 8 /* just-spawned child process */
  190. /* TIF_* value 9 is available */
  191. #define TIF_POLLING_NRFLAG 10
  192. #define TIF_SYSCALL_SUCCESS 11
  193. /* NOTE: Thread flags >= 12 should be ones we have no interest
  194. * in using in assembly, else we can't use the mask as
  195. * an immediate value in instructions such as andcc.
  196. */
  197. #define TIF_ABI_PENDING 12
  198. #define TIF_MEMDIE 13
  199. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  200. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  201. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  202. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  203. #define _TIF_PERFCTR (1<<TIF_PERFCTR)
  204. #define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
  205. #define _TIF_NEWSIGNALS (1<<TIF_NEWSIGNALS)
  206. #define _TIF_32BIT (1<<TIF_32BIT)
  207. #define _TIF_NEWCHILD (1<<TIF_NEWCHILD)
  208. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  209. #define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
  210. #define _TIF_SYSCALL_SUCCESS (1<<TIF_SYSCALL_SUCCESS)
  211. #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
  212. (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | \
  213. _TIF_NEED_RESCHED | _TIF_PERFCTR))
  214. #endif /* __KERNEL__ */
  215. #endif /* _ASM_THREAD_INFO_H */