Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* thread_info.h: sparc64 low-level thread information
0003  *
0004  * Copyright (C) 2002  David S. Miller (davem@redhat.com)
0005  */
0006 
0007 #ifndef _ASM_THREAD_INFO_H
0008 #define _ASM_THREAD_INFO_H
0009 
0010 #ifdef __KERNEL__
0011 
0012 #define NSWINS      7
0013 
0014 #define TI_FLAG_BYTE_FAULT_CODE     0
0015 #define TI_FLAG_FAULT_CODE_SHIFT    56
0016 #define TI_FLAG_BYTE_WSTATE     1
0017 #define TI_FLAG_WSTATE_SHIFT        48
0018 #define TI_FLAG_BYTE_NOERROR        2
0019 #define TI_FLAG_BYTE_NOERROR_SHIFT  40
0020 #define TI_FLAG_BYTE_FPDEPTH        3
0021 #define TI_FLAG_FPDEPTH_SHIFT       32
0022 #define TI_FLAG_BYTE_CWP        4
0023 #define TI_FLAG_CWP_SHIFT       24
0024 #define TI_FLAG_BYTE_WSAVED     5
0025 #define TI_FLAG_WSAVED_SHIFT        16
0026 
0027 #include <asm/page.h>
0028 
0029 #ifndef __ASSEMBLY__
0030 
0031 #include <asm/ptrace.h>
0032 #include <asm/types.h>
0033 
0034 struct task_struct;
0035 
0036 struct thread_info {
0037     /* D$ line 1 */
0038     struct task_struct  *task;
0039     unsigned long       flags;
0040     __u8            fpsaved[7];
0041     __u8            status;
0042     unsigned long       ksp;
0043 
0044     /* D$ line 2 */
0045     unsigned long       fault_address;
0046     struct pt_regs      *kregs;
0047     int         preempt_count;  /* 0 => preemptable, <0 => BUG */
0048     __u8            new_child;
0049     __u8            __pad;
0050     __u16           cpu;
0051 
0052     unsigned long       *utraps;
0053 
0054     struct reg_window   reg_window[NSWINS];
0055     unsigned long       rwbuf_stkptrs[NSWINS];
0056 
0057     unsigned long       gsr[7];
0058     unsigned long       xfsr[7];
0059 
0060     struct pt_regs      *kern_una_regs;
0061     unsigned int        kern_una_insn;
0062 
0063     unsigned long       fpregs[(7 * 256) / sizeof(unsigned long)]
0064         __attribute__ ((aligned(64)));
0065 };
0066 
0067 #endif /* !(__ASSEMBLY__) */
0068 
0069 /* offsets into the thread_info struct for assembly code access */
0070 #define TI_TASK     0x00000000
0071 #define TI_FLAGS    0x00000008
0072 #define TI_FAULT_CODE   (TI_FLAGS + TI_FLAG_BYTE_FAULT_CODE)
0073 #define TI_WSTATE   (TI_FLAGS + TI_FLAG_BYTE_WSTATE)
0074 #define TI_CWP      (TI_FLAGS + TI_FLAG_BYTE_CWP)
0075 #define TI_FPDEPTH  (TI_FLAGS + TI_FLAG_BYTE_FPDEPTH)
0076 #define TI_WSAVED   (TI_FLAGS + TI_FLAG_BYTE_WSAVED)
0077 #define TI_SYS_NOERROR  (TI_FLAGS + TI_FLAG_BYTE_NOERROR)
0078 #define TI_FPSAVED  0x00000010
0079 #define TI_KSP      0x00000018
0080 #define TI_FAULT_ADDR   0x00000020
0081 #define TI_KREGS    0x00000028
0082 #define TI_PRE_COUNT    0x00000030
0083 #define TI_NEW_CHILD    0x00000034
0084 #define TI_CPU      0x00000036
0085 #define TI_UTRAPS   0x00000038
0086 #define TI_REG_WINDOW   0x00000040
0087 #define TI_RWIN_SPTRS   0x000003c0
0088 #define TI_GSR      0x000003f8
0089 #define TI_XFSR     0x00000430
0090 #define TI_KUNA_REGS    0x00000468
0091 #define TI_KUNA_INSN    0x00000470
0092 #define TI_FPREGS   0x00000480
0093 
0094 /* We embed this in the uppermost byte of thread_info->flags */
0095 #define FAULT_CODE_WRITE    0x01    /* Write access, implies D-TLB     */
0096 #define FAULT_CODE_DTLB     0x02    /* Miss happened in D-TLB      */
0097 #define FAULT_CODE_ITLB     0x04    /* Miss happened in I-TLB      */
0098 #define FAULT_CODE_WINFIXUP 0x08    /* Miss happened during spill/fill */
0099 #define FAULT_CODE_BLKCOMMIT    0x10    /* Use blk-commit ASI in copy_page */
0100 #define FAULT_CODE_BAD_RA   0x20    /* Bad RA for sun4v        */
0101 
0102 #if PAGE_SHIFT == 13
0103 #define THREAD_SIZE (2*PAGE_SIZE)
0104 #define THREAD_SHIFT (PAGE_SHIFT + 1)
0105 #else /* PAGE_SHIFT == 13 */
0106 #define THREAD_SIZE PAGE_SIZE
0107 #define THREAD_SHIFT PAGE_SHIFT
0108 #endif /* PAGE_SHIFT == 13 */
0109 
0110 /*
0111  * macros/functions for gaining access to the thread information structure
0112  */
0113 #ifndef __ASSEMBLY__
0114 
0115 #define INIT_THREAD_INFO(tsk)               \
0116 {                           \
0117     .task       =   &tsk,           \
0118     .preempt_count  =   INIT_PREEMPT_COUNT, \
0119     .kregs      =   (struct pt_regs *)(init_stack+THREAD_SIZE)-1 \
0120 }
0121 
0122 /* how to get the thread information struct from C */
0123 #ifndef BUILD_VDSO
0124 register struct thread_info *current_thread_info_reg asm("g6");
0125 #define current_thread_info()   (current_thread_info_reg)
0126 #else
0127 extern struct thread_info *current_thread_info(void);
0128 #endif
0129 
0130 /* thread information allocation */
0131 #if PAGE_SHIFT == 13
0132 #define THREAD_SIZE_ORDER   1
0133 #else /* PAGE_SHIFT == 13 */
0134 #define THREAD_SIZE_ORDER   0
0135 #endif /* PAGE_SHIFT == 13 */
0136 
0137 #define __thread_flag_byte_ptr(ti)  \
0138     ((unsigned char *)(&((ti)->flags)))
0139 #define __cur_thread_flag_byte_ptr  __thread_flag_byte_ptr(current_thread_info())
0140 
0141 #define get_thread_fault_code()     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE])
0142 #define set_thread_fault_code(val)  (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FAULT_CODE] = (val))
0143 #define get_thread_wstate()     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE])
0144 #define set_thread_wstate(val)      (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSTATE] = (val))
0145 #define get_thread_cwp()        (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP])
0146 #define set_thread_cwp(val)     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_CWP] = (val))
0147 #define get_thread_noerror()        (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR])
0148 #define set_thread_noerror(val)     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_NOERROR] = (val))
0149 #define get_thread_fpdepth()        (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH])
0150 #define set_thread_fpdepth(val)     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_FPDEPTH] = (val))
0151 #define get_thread_wsaved()     (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED])
0152 #define set_thread_wsaved(val)      (__cur_thread_flag_byte_ptr[TI_FLAG_BYTE_WSAVED] = (val))
0153 #endif /* !(__ASSEMBLY__) */
0154 
0155 /*
0156  * Thread information flags, only 16 bits are available as we encode
0157  * other values into the upper 6 bytes.
0158  *
0159  * On trap return we need to test several values:
0160  *
0161  * user:    need_resched, notify_resume, sigpending, wsaved
0162  * kernel:  fpdepth
0163  *
0164  * So to check for work in the kernel case we simply load the fpdepth
0165  * byte out of the flags and test it.  For the user case we encode the
0166  * lower 3 bytes of flags as follows:
0167  *  ----------------------------------------
0168  *  | wsaved | flags byte 1 | flags byte 2 |
0169  *  ----------------------------------------
0170  * This optimizes the user test into:
0171  *  ldx     [%g6 + TI_FLAGS], REG1
0172  *  sethi       %hi(_TIF_USER_WORK_MASK), REG2
0173  *  or      REG2, %lo(_TIF_USER_WORK_MASK), REG2
0174  *  andcc       REG1, REG2, %g0
0175  *  be,pt       no_work_to_do
0176  *   nop
0177  */
0178 #define TIF_SYSCALL_TRACE   0   /* syscall trace active */
0179 #define TIF_NOTIFY_RESUME   1   /* callback before returning to user */
0180 #define TIF_SIGPENDING      2   /* signal pending */
0181 #define TIF_NEED_RESCHED    3   /* rescheduling necessary */
0182 #define TIF_NOTIFY_SIGNAL   4   /* signal notifications exist */
0183 #define TIF_UNALIGNED       5   /* allowed to do unaligned accesses */
0184 #define TIF_UPROBE      6   /* breakpointed or singlestepped */
0185 #define TIF_32BIT       7   /* 32-bit binary */
0186 #define TIF_NOHZ        8   /* in adaptive nohz mode */
0187 #define TIF_SECCOMP     9   /* secure computing */
0188 #define TIF_SYSCALL_AUDIT   10  /* syscall auditing active */
0189 #define TIF_SYSCALL_TRACEPOINT  11  /* syscall tracepoint instrumentation */
0190 /* NOTE: Thread flags >= 12 should be ones we have no interest
0191  *       in using in assembly, else we can't use the mask as
0192  *       an immediate value in instructions such as andcc.
0193  */
0194 #define TIF_MCDPER      12  /* Precise MCD exception */
0195 #define TIF_MEMDIE      13  /* is terminating due to OOM killer */
0196 #define TIF_POLLING_NRFLAG  14
0197 
0198 #define _TIF_SYSCALL_TRACE  (1<<TIF_SYSCALL_TRACE)
0199 #define _TIF_NOTIFY_RESUME  (1<<TIF_NOTIFY_RESUME)
0200 #define _TIF_SIGPENDING     (1<<TIF_SIGPENDING)
0201 #define _TIF_NEED_RESCHED   (1<<TIF_NEED_RESCHED)
0202 #define _TIF_NOTIFY_SIGNAL  (1<<TIF_NOTIFY_SIGNAL)
0203 #define _TIF_UNALIGNED      (1<<TIF_UNALIGNED)
0204 #define _TIF_UPROBE     (1<<TIF_UPROBE)
0205 #define _TIF_32BIT      (1<<TIF_32BIT)
0206 #define _TIF_NOHZ       (1<<TIF_NOHZ)
0207 #define _TIF_SECCOMP        (1<<TIF_SECCOMP)
0208 #define _TIF_SYSCALL_AUDIT  (1<<TIF_SYSCALL_AUDIT)
0209 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
0210 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
0211 
0212 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
0213                  _TIF_DO_NOTIFY_RESUME_MASK | \
0214                  _TIF_NEED_RESCHED)
0215 #define _TIF_DO_NOTIFY_RESUME_MASK  (_TIF_NOTIFY_RESUME | \
0216                      _TIF_SIGPENDING | _TIF_UPROBE | \
0217                      _TIF_NOTIFY_SIGNAL)
0218 
0219 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
0220 
0221 /*
0222  * Thread-synchronous status.
0223  *
0224  * This is different from the flags in that nobody else
0225  * ever touches our thread-synchronous status, so we don't
0226  * have to worry about atomic accesses.
0227  *
0228  * Note that there are only 8 bits available.
0229  */
0230 
0231 #ifndef __ASSEMBLY__
0232 
0233 #define thread32_stack_is_64bit(__SP) (((__SP) & 0x1) != 0)
0234 #define test_thread_64bit_stack(__SP) \
0235     ((test_thread_flag(TIF_32BIT) && !thread32_stack_is_64bit(__SP)) ? \
0236      false : true)
0237 
0238 #endif  /* !__ASSEMBLY__ */
0239 
0240 #endif /* __KERNEL__ */
0241 
0242 #endif /* _ASM_THREAD_INFO_H */