thread_info.h 8.3 KB

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