thread_info_64.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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_NOERROR 4
  18. #define TI_FLAG_BYTE_NOERROR_SHIFT 24
  19. #define TI_FLAG_BYTE_FPDEPTH 5
  20. #define TI_FLAG_FPDEPTH_SHIFT 16
  21. #define TI_FLAG_BYTE_WSAVED 6
  22. #define TI_FLAG_WSAVED_SHIFT 8
  23. #include <asm/page.h>
  24. #ifndef __ASSEMBLY__
  25. #include <asm/ptrace.h>
  26. #include <asm/types.h>
  27. struct task_struct;
  28. struct exec_domain;
  29. struct thread_info {
  30. /* D$ line 1 */
  31. struct task_struct *task;
  32. unsigned long flags;
  33. __u8 fpsaved[7];
  34. __u8 status;
  35. unsigned long ksp;
  36. /* D$ line 2 */
  37. unsigned long fault_address;
  38. struct pt_regs *kregs;
  39. struct exec_domain *exec_domain;
  40. int preempt_count; /* 0 => preemptable, <0 => BUG */
  41. __u8 new_child;
  42. __u8 __pad;
  43. __u16 cpu;
  44. unsigned long *utraps;
  45. struct reg_window reg_window[NSWINS];
  46. unsigned long rwbuf_stkptrs[NSWINS];
  47. unsigned long gsr[7];
  48. unsigned long xfsr[7];
  49. struct restart_block restart_block;
  50. struct pt_regs *kern_una_regs;
  51. unsigned int kern_una_insn;
  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_SYS_NOERROR (TI_FLAGS + TI_FLAG_BYTE_NOERROR)
  65. #define TI_FPSAVED 0x00000010
  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_NEW_CHILD 0x0000003c
  72. #define TI_CPU 0x0000003e
  73. #define TI_UTRAPS 0x00000040
  74. #define TI_REG_WINDOW 0x00000048
  75. #define TI_RWIN_SPTRS 0x000003c8
  76. #define TI_GSR 0x00000400
  77. #define TI_XFSR 0x00000438
  78. #define TI_RESTART_BLOCK 0x00000470
  79. #define TI_KUNA_REGS 0x000004a0
  80. #define TI_KUNA_INSN 0x000004a8
  81. #define TI_FPREGS 0x000004c0
  82. /* We embed this in the uppermost byte of thread_info->flags */
  83. #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
  84. #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
  85. #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
  86. #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
  87. #define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
  88. #if PAGE_SHIFT == 13
  89. #define THREAD_SIZE (2*PAGE_SIZE)
  90. #define THREAD_SHIFT (PAGE_SHIFT + 1)
  91. #else /* PAGE_SHIFT == 13 */
  92. #define THREAD_SIZE PAGE_SIZE
  93. #define THREAD_SHIFT PAGE_SHIFT
  94. #endif /* PAGE_SHIFT == 13 */
  95. #define PREEMPT_ACTIVE 0x10000000
  96. /*
  97. * macros/functions for gaining access to the thread information structure
  98. */
  99. #ifndef __ASSEMBLY__
  100. #define INIT_THREAD_INFO(tsk) \
  101. { \
  102. .task = &tsk, \
  103. .flags = ((unsigned long)ASI_P) << TI_FLAG_CURRENT_DS_SHIFT, \
  104. .exec_domain = &default_exec_domain, \
  105. .preempt_count = INIT_PREEMPT_COUNT, \
  106. .restart_block = { \
  107. .fn = do_no_restart_syscall, \
  108. }, \
  109. }
  110. #define init_thread_info (init_thread_union.thread_info)
  111. #define init_stack (init_thread_union.stack)
  112. /* how to get the thread information struct from C */
  113. register struct thread_info *current_thread_info_reg asm("g6");
  114. #define current_thread_info() (current_thread_info_reg)
  115. /* thread information allocation */
  116. #if PAGE_SHIFT == 13
  117. #define THREAD_SIZE_ORDER 1
  118. #else /* PAGE_SHIFT == 13 */
  119. #define THREAD_SIZE_ORDER 0
  120. #endif /* PAGE_SHIFT == 13 */
  121. #define __thread_flag_byte_ptr(ti) \
  122. ((unsigned char *)(&((ti)->flags)))
  123. #define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info())
  124. #define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
  125. #define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
  126. #define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
  127. #define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
  128. #define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
  129. #define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
  130. #define get_thread_current_ds() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS])
  131. #define set_thread_current_ds(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CURRENT_DS] = (val))
  132. #define get_thread_noerror() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR])
  133. #define set_thread_noerror(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR] = (val))
  134. #define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
  135. #define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
  136. #define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
  137. #define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
  138. #endif /* !(__ASSEMBLY__) */
  139. /*
  140. * Thread information flags, only 16 bits are available as we encode
  141. * other values into the upper 6 bytes.
  142. *
  143. * On trap return we need to test several values:
  144. *
  145. * user: need_resched, notify_resume, sigpending, wsaved
  146. * kernel: fpdepth
  147. *
  148. * So to check for work in the kernel case we simply load the fpdepth
  149. * byte out of the flags and test it. For the user case we encode the
  150. * lower 3 bytes of flags as follows:
  151. * ----------------------------------------
  152. * | wsaved | flags byte 1 | flags byte 2 |
  153. * ----------------------------------------
  154. * This optimizes the user test into:
  155. * ldx [%g6 + TI_FLAGS], REG1
  156. * sethi %hi(_TIF_USER_WORK_MASK), REG2
  157. * or REG2, %lo(_TIF_USER_WORK_MASK), REG2
  158. * andcc REG1, REG2, %g0
  159. * be,pt no_work_to_do
  160. * nop
  161. */
  162. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  163. #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
  164. #define TIF_SIGPENDING 2 /* signal pending */
  165. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  166. /* flag bit 4 is available */
  167. #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
  168. /* flag bit 6 is available */
  169. #define TIF_32BIT 7 /* 32-bit binary */
  170. /* flag bit 8 is available */
  171. #define TIF_SECCOMP 9 /* secure computing */
  172. #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
  173. #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
  174. /* NOTE: Thread flags >= 12 should be ones we have no interest
  175. * in using in assembly, else we can't use the mask as
  176. * an immediate value in instructions such as andcc.
  177. */
  178. /* flag bit 12 is available */
  179. #define TIF_MEMDIE 13 /* is terminating due to OOM killer */
  180. #define TIF_POLLING_NRFLAG 14
  181. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  182. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  183. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  184. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  185. #define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
  186. #define _TIF_32BIT (1<<TIF_32BIT)
  187. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  188. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  189. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  190. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  191. #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
  192. _TIF_DO_NOTIFY_RESUME_MASK | \
  193. _TIF_NEED_RESCHED)
  194. #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
  195. /*
  196. * Thread-synchronous status.
  197. *
  198. * This is different from the flags in that nobody else
  199. * ever touches our thread-synchronous status, so we don't
  200. * have to worry about atomic accesses.
  201. *
  202. * Note that there are only 8 bits available.
  203. */
  204. #define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
  205. #ifndef __ASSEMBLY__
  206. #define HAVE_SET_RESTORE_SIGMASK 1
  207. static inline void set_restore_sigmask(void)
  208. {
  209. struct thread_info *ti = current_thread_info();
  210. ti->status |= TS_RESTORE_SIGMASK;
  211. WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
  212. }
  213. static inline void clear_restore_sigmask(void)
  214. {
  215. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  216. }
  217. static inline bool test_restore_sigmask(void)
  218. {
  219. return current_thread_info()->status & TS_RESTORE_SIGMASK;
  220. }
  221. static inline bool test_and_clear_restore_sigmask(void)
  222. {
  223. struct thread_info *ti = current_thread_info();
  224. if (!(ti->status & TS_RESTORE_SIGMASK))
  225. return false;
  226. ti->status &= ~TS_RESTORE_SIGMASK;
  227. return true;
  228. }
  229. #endif /* !__ASSEMBLY__ */
  230. #endif /* __KERNEL__ */
  231. #endif /* _ASM_THREAD_INFO_H */