1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/sched.h>
22#include <linux/types.h>
23#include <linux/module.h>
24#include <linux/tick.h>
25#include <linux/uaccess.h>
26#include <linux/slab.h>
27
28
29
30
31
32
33static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *))
34{
35 do_exit(fn(arg));
36}
37
38int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
39{
40 struct pt_regs regs;
41
42 memset(®s, 0, sizeof(regs));
43
44
45
46 regs.r00 = (unsigned long) arg;
47 regs.r01 = (unsigned long) fn;
48 pt_set_elr(®s, (unsigned long)kernel_thread_helper);
49 pt_set_kmode(®s);
50
51 return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, ®s, 0, NULL, NULL);
52}
53EXPORT_SYMBOL(kernel_thread);
54
55
56
57
58
59
60
61
62
63
64void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
65{
66
67 set_fs(USER_DS);
68
69 memset(regs, 0, sizeof(*regs));
70
71 pt_set_usermode(regs);
72 pt_set_elr(regs, pc);
73 pt_set_rte_sp(regs, sp);
74}
75
76
77
78
79
80
81static void default_idle(void)
82{
83 __vmwait();
84}
85
86void (*idle_sleep)(void) = default_idle;
87
88void cpu_idle(void)
89{
90 while (1) {
91 tick_nohz_stop_sched_tick(1);
92 local_irq_disable();
93 while (!need_resched()) {
94 idle_sleep();
95
96 local_irq_enable();
97 local_irq_disable();
98 }
99 local_irq_enable();
100 tick_nohz_restart_sched_tick();
101 schedule();
102 }
103}
104
105
106
107
108unsigned long thread_saved_pc(struct task_struct *tsk)
109{
110 return 0;
111}
112
113
114
115
116int copy_thread(unsigned long clone_flags, unsigned long usp,
117 unsigned long unused, struct task_struct *p,
118 struct pt_regs *regs)
119{
120 struct thread_info *ti = task_thread_info(p);
121 struct hexagon_switch_stack *ss;
122 struct pt_regs *childregs;
123 asmlinkage void ret_from_fork(void);
124
125 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
126 sizeof(*childregs));
127
128 memcpy(childregs, regs, sizeof(*childregs));
129 ti->regs = childregs;
130
131
132
133
134 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
135 sizeof(*ss));
136 ss->lr = (unsigned long)ret_from_fork;
137 p->thread.switch_sp = ss;
138
139
140 if (user_mode(childregs)) {
141 pt_set_rte_sp(childregs, usp);
142
143
144 childregs->r00 = 0;
145
146
147
148
149
150
151
152
153
154
155 if (clone_flags & CLONE_SETTLS)
156 childregs->ugp = childregs->r04;
157
158
159
160
161
162
163 } else {
164
165
166
167
168 pt_set_rte_sp(childregs, (unsigned long)(childregs + 1));
169
170
171
172
173
174
175 childregs->THREADINFO_REG = (unsigned long) ti;
176 }
177
178
179
180
181
182 p->stack = (void *)ti;
183
184 return 0;
185}
186
187
188
189
190void release_thread(struct task_struct *dead_task)
191{
192}
193
194
195
196
197void exit_thread(void)
198{
199}
200
201
202
203
204void flush_thread(void)
205{
206}
207
208
209
210
211
212
213unsigned long get_wchan(struct task_struct *p)
214{
215 unsigned long fp, pc;
216 unsigned long stack_page;
217 int count = 0;
218 if (!p || p == current || p->state == TASK_RUNNING)
219 return 0;
220
221 stack_page = (unsigned long)task_stack_page(p);
222 fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
223 do {
224 if (fp < (stack_page + sizeof(struct thread_info)) ||
225 fp >= (THREAD_SIZE - 8 + stack_page))
226 return 0;
227 pc = ((unsigned long *)fp)[1];
228 if (!in_sched_functions(pc))
229 return pc;
230 fp = *(unsigned long *) fp;
231 } while (count++ < 16);
232
233 return 0;
234}
235
236
237
238
239
240#if THREAD_SHIFT < PAGE_SHIFT
241
242static struct kmem_cache *thread_info_cache;
243
244struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
245{
246 struct thread_info *ti;
247
248 ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
249 if (unlikely(ti == NULL))
250 return NULL;
251#ifdef CONFIG_DEBUG_STACK_USAGE
252 memset(ti, 0, THREAD_SIZE);
253#endif
254 return ti;
255}
256
257void free_thread_info(struct thread_info *ti)
258{
259 kmem_cache_free(thread_info_cache, ti);
260}
261
262
263
264void thread_info_cache_init(void)
265{
266 thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
267 THREAD_SIZE, 0, NULL);
268 BUG_ON(thread_info_cache == NULL);
269}
270
271#endif
272
273
274
275
276int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
277{
278 return 0;
279}
280