1 /* thread_info.h: Meta low-level thread information
2  *
3  * Copyright (C) 2002  David Howells (dhowells@redhat.com)
4  * - Incorporating suggestions made by Linus Torvalds and Dave Miller
5  *
6  * Meta port by Imagination Technologies
7  */
8 
9 #ifndef _ASM_THREAD_INFO_H
10 #define _ASM_THREAD_INFO_H
11 
12 #include <linux/compiler.h>
13 #include <asm/page.h>
14 
15 #ifndef __ASSEMBLY__
16 #include <asm/processor.h>
17 #endif
18 
19 /*
20  * low level task data that entry.S needs immediate access to
21  * - this struct should fit entirely inside of one cache line
22  * - this struct shares the supervisor stack pages
23  * - if the contents of this structure are changed, the assembly constants must
24  *   also be changed
25  */
26 #ifndef __ASSEMBLY__
27 
28 /* This must be 8 byte aligned so we can ensure stack alignment. */
29 struct thread_info {
30 	struct task_struct *task;	/* main task structure */
31 	unsigned long flags;	/* low level flags */
32 	unsigned long status;	/* thread-synchronous flags */
33 	u32 cpu;		/* current CPU */
34 	int preempt_count;	/* 0 => preemptable, <0 => BUG */
35 
36 	mm_segment_t addr_limit;	/* thread address space */
37 
38 	u8 supervisor_stack[0] __aligned(8);
39 };
40 
41 #else /* !__ASSEMBLY__ */
42 
43 #include <generated/asm-offsets.h>
44 
45 #endif
46 
47 #ifdef CONFIG_4KSTACKS
48 #define THREAD_SHIFT		12
49 #else
50 #define THREAD_SHIFT		13
51 #endif
52 
53 #if THREAD_SHIFT >= PAGE_SHIFT
54 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
55 #else
56 #define THREAD_SIZE_ORDER	0
57 #endif
58 
59 #define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
60 
61 #define STACK_WARN		(THREAD_SIZE/8)
62 /*
63  * macros/functions for gaining access to the thread information structure
64  */
65 #ifndef __ASSEMBLY__
66 
67 #define INIT_THREAD_INFO(tsk)			\
68 {						\
69 	.task		= &tsk,			\
70 	.flags		= 0,			\
71 	.cpu		= 0,			\
72 	.preempt_count	= INIT_PREEMPT_COUNT,	\
73 	.addr_limit	= KERNEL_DS,		\
74 }
75 
76 #define init_thread_info	(init_thread_union.thread_info)
77 #define init_stack		(init_thread_union.stack)
78 
79 /* how to get the current stack pointer from C */
80 register unsigned long current_stack_pointer asm("A0StP") __used;
81 
82 /* how to get the thread information struct from C */
current_thread_info(void)83 static inline struct thread_info *current_thread_info(void)
84 {
85 	return (struct thread_info *)(current_stack_pointer &
86 				      ~(THREAD_SIZE - 1));
87 }
88 
89 #define __HAVE_ARCH_KSTACK_END
kstack_end(void * addr)90 static inline int kstack_end(void *addr)
91 {
92 	return addr == (void *) (((unsigned long) addr & ~(THREAD_SIZE - 1))
93 				 + sizeof(struct thread_info));
94 }
95 
96 #endif
97 
98 /*
99  * thread information flags
100  * - these are process state flags that various assembly files may need to
101  *   access
102  * - pending work-to-be-done flags are in LSW
103  * - other flags in MSW
104  */
105 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
106 #define TIF_SIGPENDING		1	/* signal pending */
107 #define TIF_NEED_RESCHED	2	/* rescheduling necessary */
108 #define TIF_SINGLESTEP		3	/* restore singlestep on return to user
109 					   mode */
110 #define TIF_SYSCALL_AUDIT	4	/* syscall auditing active */
111 #define TIF_SECCOMP		5	/* secure computing */
112 #define TIF_RESTORE_SIGMASK	6	/* restore signal mask in do_signal() */
113 #define TIF_NOTIFY_RESUME	7	/* callback before returning to user */
114 #define TIF_MEMDIE		8	/* is terminating due to OOM killer */
115 #define TIF_SYSCALL_TRACEPOINT	9	/* syscall tracepoint instrumentation */
116 
117 
118 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
119 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
120 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
121 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
122 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
123 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
124 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
125 #define _TIF_RESTORE_SIGMASK	(1<<TIF_RESTORE_SIGMASK)
126 #define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
127 
128 /* work to do in syscall trace */
129 #define _TIF_WORK_SYSCALL_MASK	(_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
130 				 _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
131 				 _TIF_SYSCALL_TRACEPOINT)
132 
133 /* work to do on any return to u-space */
134 #define _TIF_ALLWORK_MASK	(_TIF_SYSCALL_TRACE | _TIF_SIGPENDING      | \
135 				 _TIF_NEED_RESCHED  | _TIF_SYSCALL_AUDIT   | \
136 				 _TIF_SINGLESTEP    | _TIF_RESTORE_SIGMASK | \
137 				 _TIF_NOTIFY_RESUME)
138 
139 /* work to do on interrupt/exception return */
140 #define _TIF_WORK_MASK		(_TIF_ALLWORK_MASK & ~(_TIF_SYSCALL_TRACE | \
141 				 _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP))
142 
143 #endif /* _ASM_THREAD_INFO_H */
144