Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
thread_info.h
Go to the documentation of this file.
1 /* MN10300 Low-level thread information
2  *
3  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells ([email protected])
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public Licence
8  * as published by the Free Software Foundation; either version
9  * 2 of the Licence, or (at your option) any later version.
10  */
11 
12 #ifndef _ASM_THREAD_INFO_H
13 #define _ASM_THREAD_INFO_H
14 
15 #ifdef __KERNEL__
16 
17 #include <asm/page.h>
18 
19 #define PREEMPT_ACTIVE 0x10000000
20 
21 #ifdef CONFIG_4KSTACKS
22 #define THREAD_SIZE (4096)
23 #define THREAD_SIZE_ORDER (0)
24 #else
25 #define THREAD_SIZE (8192)
26 #define THREAD_SIZE_ORDER (1)
27 #endif
28 
29 #define STACK_WARN (THREAD_SIZE / 8)
30 
31 /*
32  * low level task data that entry.S needs immediate access to
33  * - this struct should fit entirely inside of one cache line
34  * - this struct shares the supervisor stack pages
35  * - if the contents of this structure are changed, the assembly constants
36  * must also be changed
37  */
38 #ifndef __ASSEMBLY__
39 typedef struct {
40  unsigned long seg;
41 } mm_segment_t;
42 
43 struct thread_info {
44  struct task_struct *task; /* main task structure */
45  struct exec_domain *exec_domain; /* execution domain */
46  struct pt_regs *frame; /* current exception frame */
47  unsigned long flags; /* low level flags */
48  __u32 cpu; /* current CPU */
49  __s32 preempt_count; /* 0 => preemptable, <0 => BUG */
50 
51  mm_segment_t addr_limit; /* thread address space:
52  0-0xBFFFFFFF for user-thead
53  0-0xFFFFFFFF for kernel-thread
54  */
56 
58 };
59 
60 #define thread_info_to_uregs(ti) \
61  ((struct pt_regs *) \
62  ((unsigned long)ti + THREAD_SIZE - sizeof(struct pt_regs)))
63 
64 #else /* !__ASSEMBLY__ */
65 
66 #ifndef __ASM_OFFSETS_H__
67 #include <asm/asm-offsets.h>
68 #endif
69 
70 #endif
71 
72 /*
73  * macros/functions for gaining access to the thread information structure
74  */
75 #ifndef __ASSEMBLY__
76 
77 #define INIT_THREAD_INFO(tsk) \
78 { \
79  .task = &tsk, \
80  .exec_domain = &default_exec_domain, \
81  .flags = 0, \
82  .cpu = 0, \
83  .preempt_count = INIT_PREEMPT_COUNT, \
84  .addr_limit = KERNEL_DS, \
85  .restart_block = { \
86  .fn = do_no_restart_syscall, \
87  }, \
88 }
89 
90 #define init_thread_info (init_thread_union.thread_info)
91 #define init_stack (init_thread_union.stack)
92 #define init_uregs \
93  ((struct pt_regs *) \
94  ((unsigned long) init_stack + THREAD_SIZE - sizeof(struct pt_regs)))
95 
96 extern struct thread_info *__current_ti;
97 
98 /* how to get the thread information struct from C */
99 static inline __attribute__((const))
101 {
102  struct thread_info *ti;
103  asm("mov sp,%0\n"
104  "and %1,%0\n"
105  : "=d" (ti)
106  : "i" (~(THREAD_SIZE - 1))
107  : "cc");
108  return ti;
109 }
110 
111 static inline __attribute__((const))
112 struct pt_regs *current_frame(void)
113 {
114  return current_thread_info()->frame;
115 }
116 
117 /* how to get the current stack pointer from C */
118 static inline unsigned long current_stack_pointer(void)
119 {
120  unsigned long sp;
121  asm("mov sp,%0; ":"=r" (sp));
122  return sp;
123 }
124 
125 #ifndef CONFIG_KGDB
126 void arch_release_thread_info(struct thread_info *ti);
127 #endif
128 #define get_thread_info(ti) get_task_struct((ti)->task)
129 #define put_thread_info(ti) put_task_struct((ti)->task)
130 
131 #else /* !__ASSEMBLY__ */
132 
133 #ifndef __VMLINUX_LDS__
134 /* how to get the thread information struct from ASM */
135 .macro GET_THREAD_INFO reg
136  mov sp,\reg
138 .endm
139 #endif
140 #endif
141 
142 /*
143  * thread information flags
144  * - these are process state flags that various assembly files may need to
145  * access
146  * - pending work-to-be-done flags are in LSW
147  * - other flags in MSW
148  */
149 #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
150 #define TIF_NOTIFY_RESUME 1 /* resumption notification requested */
151 #define TIF_SIGPENDING 2 /* signal pending */
152 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
153 #define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
154 #define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
155 #define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
156 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
157 
158 #define _TIF_SYSCALL_TRACE +(1 << TIF_SYSCALL_TRACE)
159 #define _TIF_NOTIFY_RESUME +(1 << TIF_NOTIFY_RESUME)
160 #define _TIF_SIGPENDING +(1 << TIF_SIGPENDING)
161 #define _TIF_NEED_RESCHED +(1 << TIF_NEED_RESCHED)
162 #define _TIF_SINGLESTEP +(1 << TIF_SINGLESTEP)
163 #define _TIF_POLLING_NRFLAG +(1 << TIF_POLLING_NRFLAG)
164 
165 #define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */
166 #define _TIF_ALLWORK_MASK 0x0000FFFF /* work to do on any return to u-space */
167 
168 #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG)
169 
170 #endif /* __KERNEL__ */
171 
172 #endif /* _ASM_THREAD_INFO_H */