xref: /linux/arch/alpha/include/asm/thread_info.h (revision f4cdf7ca9a1fdcca413157df19753f388a5a224e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ALPHA_THREAD_INFO_H
3 #define _ALPHA_THREAD_INFO_H
4 
5 #ifdef __KERNEL__
6 
7 #ifndef __ASSEMBLER__
8 #include <asm/processor.h>
9 #include <asm/types.h>
10 #include <asm/hwrpb.h>
11 #include <asm/sysinfo.h>
12 #endif
13 
14 #ifndef __ASSEMBLER__
15 struct thread_info {
16 	struct pcb_struct	pcb;		/* palcode state */
17 
18 	struct task_struct	*task;		/* main task structure */
19 	unsigned int		flags;		/* low level flags */
20 	unsigned int		ieee_state;	/* see fpu.h */
21 
22 	unsigned		cpu;		/* current CPU */
23 	int			preempt_count; /* 0 => preemptable, <0 => BUG */
24 	unsigned int		status;		/* thread-synchronous flags */
25 
26 	int bpt_nsaved;
27 	unsigned long bpt_addr[2];		/* breakpoint handling  */
28 	unsigned int bpt_insn[2];
29 	unsigned long fp[32];
30 };
31 
32 /*
33  * Macros/functions for gaining access to the thread information structure.
34  */
35 #define INIT_THREAD_INFO(tsk)			\
36 {						\
37 	.task		= &tsk,			\
38 	.preempt_count	= INIT_PREEMPT_COUNT,	\
39 }
40 
41 /* How to get the thread information struct from C.  */
42 register struct thread_info *__current_thread_info __asm__("$8");
43 #define current_thread_info()  __current_thread_info
44 
45 register unsigned long *current_stack_pointer __asm__ ("$30");
46 
47 #endif /* __ASSEMBLER__ */
48 
49 /* Thread information allocation.  */
50 #define THREAD_SIZE_ORDER 1
51 #define THREAD_SIZE (2*PAGE_SIZE)
52 
53 /*
54  * Thread information flags:
55  * - these are process state flags and used from assembly
56  * - pending work-to-be-done flags come first and must be assigned to be
57  *   within bits 0 to 7 to fit in and immediate operand.
58  *
59  * (Historically TIF_SYSCALL_TRACE was known to be 0 via blbs, but we may
60  *  also test multiple bits via masks now.)
61  */
62 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
63 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
64 #define TIF_SIGPENDING		2	/* signal pending */
65 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
66 #define TIF_SYSCALL_AUDIT	4	/* syscall audit active */
67 #define TIF_NOTIFY_SIGNAL	5	/* signal notifications exist */
68 #define TIF_SECCOMP		6	/* seccomp syscall filtering active */
69 #define	TIF_SYSCALL_TRACEPOINT	7	/* syscall tracepoint instrumentation */
70 #define TIF_DIE_IF_KERNEL	9	/* dik recursion lock */
71 #define TIF_MEMDIE		13	/* is terminating due to OOM killer */
72 #define TIF_POLLING_NRFLAG	14	/* idle is polling for TIF_NEED_RESCHED */
73 
74 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
75 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
76 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
77 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
78 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
79 #define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
80 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
81 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
82 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
83 
84 /*
85  * Work to do on syscall entry (in entry.S).
86  * If you want this to exactly mirror what entry.S checks, keep it aligned
87  * with the mask used before branching to syscall_trace_enter().
88  */
89 #ifdef CONFIG_AUDITSYSCALL
90 # define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP \
91 				| _TIF_SYSCALL_TRACEPOINT)
92 #else
93 # define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
94 #endif
95 
96 /* Work to do on interrupt/exception return.  */
97 #define _TIF_WORK_MASK		(_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
98 				 _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
99 
100 #define TS_UAC_NOPRINT		0x0001	/* ! Preserve the following three */
101 #define TS_UAC_NOFIX		0x0002	/* ! flags as they match          */
102 #define TS_UAC_SIGBUS		0x0004	/* ! userspace part of 'osf_sysinfo' */
103 
104 #define TS_SAVED_FP		0x0008
105 #define TS_RESTORE_FP		0x0010
106 
107 #define SET_UNALIGN_CTL(task,value)	({				\
108 	__u32 status = task_thread_info(task)->status & ~UAC_BITMASK;	\
109 	if (value & PR_UNALIGN_NOPRINT)					\
110 		status |= TS_UAC_NOPRINT;				\
111 	if (value & PR_UNALIGN_SIGBUS)					\
112 		status |= TS_UAC_SIGBUS;				\
113 	if (value & 4)	/* alpha-specific */				\
114 		status |= TS_UAC_NOFIX;					\
115 	task_thread_info(task)->status = status;			\
116 	0; })
117 
118 #define GET_UNALIGN_CTL(task,value)	({				\
119 	__u32 status = task_thread_info(task)->status & ~UAC_BITMASK;	\
120 	__u32 res = 0;							\
121 	if (status & TS_UAC_NOPRINT)					\
122 		res |= PR_UNALIGN_NOPRINT;				\
123 	if (status & TS_UAC_SIGBUS)					\
124 		res |= PR_UNALIGN_SIGBUS;				\
125 	if (status & TS_UAC_NOFIX)					\
126 		res |= 4;						\
127 	put_user(res, (int __user *)(value));				\
128 	})
129 
130 #ifndef __ASSEMBLER__
131 extern void __save_fpu(void);
132 
133 static inline void save_fpu(void)
134 {
135 	if (!(current_thread_info()->status & TS_SAVED_FP)) {
136 		current_thread_info()->status |= TS_SAVED_FP;
137 		__save_fpu();
138 	}
139 }
140 #endif
141 
142 #endif /* __KERNEL__ */
143 #endif /* _ALPHA_THREAD_INFO_H */
144