thread_info_64.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* thread_info.h: sparc64 low-level thread information
  2. *
  3. * Copyright (C) 2002 David S. Miller ([email protected])
  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_NOERROR 2
  14. #define TI_FLAG_BYTE_NOERROR_SHIFT 40
  15. #define TI_FLAG_BYTE_FPDEPTH 3
  16. #define TI_FLAG_FPDEPTH_SHIFT 32
  17. #define TI_FLAG_BYTE_CWP 4
  18. #define TI_FLAG_CWP_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 thread_info {
  27. /* D$ line 1 */
  28. struct task_struct *task;
  29. unsigned long flags;
  30. __u8 fpsaved[7];
  31. __u8 status;
  32. unsigned long ksp;
  33. /* D$ line 2 */
  34. unsigned long fault_address;
  35. struct pt_regs *kregs;
  36. int preempt_count; /* 0 => preemptable, <0 => BUG */
  37. __u8 new_child;
  38. __u8 current_ds;
  39. __u16 cpu;
  40. unsigned long *utraps;
  41. struct reg_window reg_window[NSWINS];
  42. unsigned long rwbuf_stkptrs[NSWINS];
  43. unsigned long gsr[7];
  44. unsigned long xfsr[7];
  45. struct pt_regs *kern_una_regs;
  46. unsigned int kern_una_insn;
  47. unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
  48. __attribute__ ((aligned(64)));
  49. };
  50. #endif /* !(__ASSEMBLY__) */
  51. /* offsets into the thread_info struct for assembly code access */
  52. #define TI_TASK 0x00000000
  53. #define TI_FLAGS 0x00000008
  54. #define TI_FAULT_CODE (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
  55. #define TI_WSTATE (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
  56. #define TI_CWP (TI_FLAGS + TI_FLAG_BYTE_CWP)
  57. #define TI_FPDEPTH (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
  58. #define TI_WSAVED (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
  59. #define TI_SYS_NOERROR (TI_FLAGS + TI_FLAG_BYTE_NOERROR)
  60. #define TI_FPSAVED 0x00000010
  61. #define TI_KSP 0x00000018
  62. #define TI_FAULT_ADDR 0x00000020
  63. #define TI_KREGS 0x00000028
  64. #define TI_PRE_COUNT 0x00000030
  65. #define TI_NEW_CHILD 0x00000034
  66. #define TI_CURRENT_DS 0x00000035
  67. #define TI_CPU 0x00000036
  68. #define TI_UTRAPS 0x00000038
  69. #define TI_REG_WINDOW 0x00000040
  70. #define TI_RWIN_SPTRS 0x000003c0
  71. #define TI_GSR 0x000003f8
  72. #define TI_XFSR 0x00000430
  73. #define TI_KUNA_REGS 0x00000468
  74. #define TI_KUNA_INSN 0x00000470
  75. #define TI_FPREGS 0x00000480
  76. /* We embed this in the uppermost byte of thread_info->flags */
  77. #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
  78. #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
  79. #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
  80. #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
  81. #define FAULT_CODE_BLKCOMMIT 0x10 /* Use blk-commit ASI in copy_page */
  82. #define FAULT_CODE_BAD_RA 0x20 /* Bad RA for sun4v */
  83. #if PAGE_SHIFT == 13
  84. #define THREAD_SIZE (2*PAGE_SIZE)
  85. #define THREAD_SHIFT (PAGE_SHIFT + 1)
  86. #else /* PAGE_SHIFT == 13 */
  87. #define THREAD_SIZE PAGE_SIZE
  88. #define THREAD_SHIFT PAGE_SHIFT
  89. #endif /* PAGE_SHIFT == 13 */
  90. /*
  91. * macros/functions for gaining access to the thread information structure
  92. */
  93. #ifndef __ASSEMBLY__
  94. #define INIT_THREAD_INFO(tsk) \
  95. { \
  96. .task = &tsk, \
  97. .current_ds = ASI_P, \
  98. .preempt_count = INIT_PREEMPT_COUNT, \
  99. }
  100. #define init_thread_info (init_thread_union.thread_info)
  101. #define init_stack (init_thread_union.stack)
  102. /* how to get the thread information struct from C */
  103. register struct thread_info *current_thread_info_reg asm("g6");
  104. #define current_thread_info() (current_thread_info_reg)
  105. /* thread information allocation */
  106. #if PAGE_SHIFT == 13
  107. #define THREAD_SIZE_ORDER 1
  108. #else /* PAGE_SHIFT == 13 */
  109. #define THREAD_SIZE_ORDER 0
  110. #endif /* PAGE_SHIFT == 13 */
  111. #define __thread_flag_byte_ptr(ti) \
  112. ((unsigned char *)(&((ti)->flags)))
  113. #define __cur_thread_flag_byte_ptr __thread_flag_byte_ptr(current_thread_info())
  114. #define get_thread_fault_code() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
  115. #define set_thread_fault_code(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
  116. #define get_thread_wstate() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
  117. #define set_thread_wstate(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
  118. #define get_thread_cwp() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
  119. #define set_thread_cwp(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
  120. #define get_thread_noerror() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR])
  121. #define set_thread_noerror(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR] = (val))
  122. #define get_thread_fpdepth() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
  123. #define set_thread_fpdepth(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
  124. #define get_thread_wsaved() (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
  125. #define set_thread_wsaved(val) (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
  126. #endif /* !(__ASSEMBLY__) */
  127. /*
  128. * Thread information flags, only 16 bits are available as we encode
  129. * other values into the upper 6 bytes.
  130. *
  131. * On trap return we need to test several values:
  132. *
  133. * user: need_resched, notify_resume, sigpending, wsaved
  134. * kernel: fpdepth
  135. *
  136. * So to check for work in the kernel case we simply load the fpdepth
  137. * byte out of the flags and test it. For the user case we encode the
  138. * lower 3 bytes of flags as follows:
  139. * ----------------------------------------
  140. * | wsaved | flags byte 1 | flags byte 2 |
  141. * ----------------------------------------
  142. * This optimizes the user test into:
  143. * ldx [%g6 + TI_FLAGS], REG1
  144. * sethi %hi(_TIF_USER_WORK_MASK), REG2
  145. * or REG2, %lo(_TIF_USER_WORK_MASK), REG2
  146. * andcc REG1, REG2, %g0
  147. * be,pt no_work_to_do
  148. * nop
  149. */
  150. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  151. #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
  152. #define TIF_SIGPENDING 2 /* signal pending */
  153. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  154. /* flag bit 4 is available */
  155. #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
  156. /* flag bit 6 is available */
  157. #define TIF_32BIT 7 /* 32-bit binary */
  158. #define TIF_NOHZ 8 /* in adaptive nohz mode */
  159. #define TIF_SECCOMP 9 /* secure computing */
  160. #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
  161. #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
  162. /* NOTE: Thread flags >= 12 should be ones we have no interest
  163. * in using in assembly, else we can't use the mask as
  164. * an immediate value in instructions such as andcc.
  165. */
  166. /* flag bit 12 is available */
  167. #define TIF_MEMDIE 13 /* is terminating due to OOM killer */
  168. #define TIF_POLLING_NRFLAG 14
  169. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  170. #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
  171. #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
  172. #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
  173. #define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
  174. #define _TIF_32BIT (1<<TIF_32BIT)
  175. #define _TIF_NOHZ (1<<TIF_NOHZ)
  176. #define _TIF_SECCOMP (1<<TIF_SECCOMP)
  177. #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
  178. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  179. #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
  180. #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
  181. _TIF_DO_NOTIFY_RESUME_MASK | \
  182. _TIF_NEED_RESCHED)
  183. #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
  184. #define is_32bit_task() (test_thread_flag(TIF_32BIT))
  185. /*
  186. * Thread-synchronous status.
  187. *
  188. * This is different from the flags in that nobody else
  189. * ever touches our thread-synchronous status, so we don't
  190. * have to worry about atomic accesses.
  191. *
  192. * Note that there are only 8 bits available.
  193. */
  194. #ifndef __ASSEMBLY__
  195. #define thread32_stack_is_64bit(__SP) (((__SP) & 0x1) != 0)
  196. #define test_thread_64bit_stack(__SP) \
  197. ((test_thread_flag(TIF_32BIT) && !thread32_stack_is_64bit(__SP)) ? \
  198. false : true)
  199. #endif /* !__ASSEMBLY__ */
  200. #endif /* __KERNEL__ */
  201. #endif /* _ASM_THREAD_INFO_H */