thread_info_64.h 7.7 KB

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