thread_info_64.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* thread_info.h: sparc64 low-level thread information
  2. *
  3. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  4. */
  5. #ifndef _ASM_THREAD_INFO_H
  6. #define _ASM_THREAD_INFO_H
  7. #ifdef __KERNEL__
  8. #define NSWINS 7
  9. #define TI_FLAG_BYTE_FAULT_CODE 0
  10. #define TI_FLAG_FAULT_CODE_SHIFT 56
  11. #define TI_FLAG_BYTE_WSTATE 1
  12. #define TI_FLAG_WSTATE_SHIFT 48
  13. #define TI_FLAG_BYTE_CWP 2
  14. #define TI_FLAG_CWP_SHIFT 40
  15. #define TI_FLAG_BYTE_CURRENT_DS 3
  16. #define TI_FLAG_CURRENT_DS_SHIFT 32
  17. #define TI_FLAG_BYTE_FPDEPTH 4
  18. #define TI_FLAG_FPDEPTH_SHIFT 24
  19. #define TI_FLAG_BYTE_WSAVED 5
  20. #define TI_FLAG_WSAVED_SHIFT 16
  21. #include <asm/page.h>
  22. #ifndef __ASSEMBLY__
  23. #include <asm/ptrace.h>
  24. #include <asm/types.h>
  25. struct task_struct;
  26. struct exec_domain;
  27. struct thread_info {
  28. /* D$ line 1 */
  29. struct task_struct *task;
  30. unsigned long flags;
  31. __u8 fpsaved[7];
  32. __u8 status;
  33. unsigned long ksp;
  34. /* D$ line 2 */
  35. unsigned long fault_address;
  36. struct pt_regs *kregs;
  37. struct exec_domain *exec_domain;
  38. int preempt_count; /* 0 => preemptable, <0 => BUG */
  39. __u8 new_child;
  40. __u8 syscall_noerror;
  41. __u16 cpu;
  42. unsigned long *utraps;
  43. struct reg_window reg_window[NSWINS];
  44. unsigned long rwbuf_stkptrs[NSWINS];
  45. unsigned long gsr[7];
  46. unsigned long xfsr[7];
  47. __u64 __user *user_cntd0;
  48. __u64 __user *user_cntd1;
  49. __u64 kernel_cntd0, kernel_cntd1;
  50. __u64 pcr_reg;
  51. struct restart_block restart_block;
  52. struct pt_regs *kern_una_regs;
  53. unsigned int kern_una_insn;
  54. unsigned long fpregs[0] __attribute__ ((aligned(64)));
  55. };
  56. #endif /* !(__ASSEMBLY__) */
  57. /* offsets into the thread_info struct for assembly code access */
  58. #define TI_TASK 0x00000000
  59. #define TI_FLAGS 0x00000008
  60. #define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
  61. #define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
  62. #define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP)
  63. #define TI_CURRENT_DS (TI_FLAGS + TI_FLAG_BYTE_CURRENT_DS)
  64. #define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
  65. #define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
  66. #define TI_FPSAVED 0x00000010
  67. #define TI_KSP 0x00000018
  68. #define TI_FAULT_ADDR 0x00000020
  69. #define TI_KREGS 0x00000028
  70. #define TI_EXEC_DOMAIN 0x00000030
  71. #define TI_PRE_COUNT 0x00000038
  72. #define TI_NEW_CHILD 0x0000003c
  73. #define TI_SYS_NOERROR 0x0000003d
  74. #define TI_CPU 0x0000003e
  75. #define TI_UTRAPS 0x00000040
  76. #define TI_REG_WINDOW 0x00000048
  77. #define TI_RWIN_SPTRS 0x000003c8
  78. #define TI_GSR 0x00000400
  79. #define TI_XFSR 0x00000438
  80. #define TI_USER_CNTD0 0x00000470
  81. #define TI_USER_CNTD1 0x00000478
  82. #define TI_KERN_CNTD0 0x00000480
  83. #define TI_KERN_CNTD1 0x00000488
  84. #define TI_PCR 0x00000490
  85. #define TI_RESTART_BLOCK 0x00000498
  86. #define TI_KUNA_REGS 0x000004c0
  87. #define TI_KUNA_INSN 0x000004c8
  88. #define TI_FPREGS 0x00000500
  89. /* We embed this in the uppermost byte of thread_info->flags */
  90. #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
  91. #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
  92. #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
  93. #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
  94. #define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
  95. #if PAGE_SHIFT == 13
  96. #define THREAD_SIZE (2*PAGE_SIZE)
  97. #define THREAD_SHIFT (PAGE_SHIFT + 1)
  98. #else /* PAGE_SHIFT == 13 */
  99. #define THREAD_SIZE PAGE_SIZE
  100. #define THREAD_SHIFT PAGE_SHIFT
  101. #endif /* PAGE_SHIFT == 13 */
  102. #define PREEMPT_ACTIVE 0x4000000
  103. /*
  104. * macros/functions for gaining access to the thread information structure
  105. *
  106. * preempt_count needs to be 1 initially, until the scheduler is functional.
  107. */
  108. #ifndef __ASSEMBLY__
  109. #define INIT_THREAD_INFO(tsk) \
  110. { \
  111. .task = &tsk, \
  112. .flags = ((unsigned long)ASI_P) << TI_FLAG_CURRENT_DS_SHIFT, \
  113. .exec_domain = &default_exec_domain, \
  114. .preempt_count = 1, \
  115. .restart_block = { \
  116. .fn = do_no_restart_syscall, \
  117. }, \
  118. }
  119. #define init_thread_info (init_thread_union.thread_info)
  120. #define init_stack (init_thread_union.stack)
  121. /* how to get the thread information struct from C */
  122. register struct thread_info *current_thread_info_reg asm("g6");
  123. #define current_thread_info() (current_thread_info_reg)
  124. /* thread information allocation */
  125. #if PAGE_SHIFT == 13
  126. #define __THREAD_INFO_ORDER 1
  127. #else /* PAGE_SHIFT == 13 */
  128. #define __THREAD_INFO_ORDER 0
  129. #endif /* PAGE_SHIFT == 13 */
  130. #define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
  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_NOTIFY_RESUME 1 /* callback before returning to user */
  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. /* flag bit 6 is available */
  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_FREEZE 15 /* is freezing for suspend */
  207. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  208. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  209. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  210. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  211. #define _TIF_PERFCTR (1<<TIF_PERFCTR)
  212. #define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
  213. #define _TIF_32BIT (1<<TIF_32BIT)
  214. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  215. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  216. #define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
  217. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  218. #define _TIF_FREEZE (1<<TIF_FREEZE)
  219. #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
  220. _TIF_DO_NOTIFY_RESUME_MASK | \
  221. _TIF_NEED_RESCHED | _TIF_PERFCTR)
  222. #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
  223. /*
  224. * Thread-synchronous status.
  225. *
  226. * This is different from the flags in that nobody else
  227. * ever touches our thread-synchronous status, so we don't
  228. * have to worry about atomic accesses.
  229. *
  230. * Note that there are only 8 bits available.
  231. */
  232. #define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
  233. #ifndef __ASSEMBLY__
  234. #define HAVE_SET_RESTORE_SIGMASK 1
  235. static inline void set_restore_sigmask(void)
  236. {
  237. struct thread_info *ti = current_thread_info();
  238. ti->status |= TS_RESTORE_SIGMASK;
  239. set_bit(TIF_SIGPENDING, &ti->flags);
  240. }
  241. #endif /* !__ASSEMBLY__ */
  242. #endif /* __KERNEL__ */
  243. #endif /* _ASM_THREAD_INFO_H */