Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
5a4f7c66 | 2 | * arch/sh/kernel/process_64.c |
1da177e4 | 3 | * |
5a4f7c66 | 4 | * This file handles the architecture-dependent parts of process handling.. |
1da177e4 LT |
5 | * |
6 | * Copyright (C) 2000, 2001 Paolo Alberelli | |
5a4f7c66 | 7 | * Copyright (C) 2003 - 2007 Paul Mundt |
1da177e4 LT |
8 | * Copyright (C) 2003, 2004 Richard Curnow |
9 | * | |
10 | * Started from SH3/4 version: | |
11 | * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima | |
12 | * | |
13 | * In turn started from i386 version: | |
14 | * Copyright (C) 1995 Linus Torvalds | |
15 | * | |
5a4f7c66 PM |
16 | * This file is subject to the terms and conditions of the GNU General Public |
17 | * License. See the file "COPYING" in the main directory of this archive | |
18 | * for more details. | |
1da177e4 | 19 | */ |
1da177e4 | 20 | #include <linux/mm.h> |
78d98277 | 21 | #include <linux/fs.h> |
1da177e4 | 22 | #include <linux/ptrace.h> |
1da177e4 LT |
23 | #include <linux/reboot.h> |
24 | #include <linux/init.h> | |
821278a7 | 25 | #include <linux/module.h> |
c26056bc | 26 | #include <linux/proc_fs.h> |
a7aa92d1 | 27 | #include <linux/io.h> |
1da177e4 LT |
28 | #include <asm/uaccess.h> |
29 | #include <asm/pgtable.h> | |
1da177e4 LT |
30 | |
31 | struct task_struct *last_task_used_math = NULL; | |
32 | ||
1da177e4 LT |
33 | static int hlt_counter = 1; |
34 | ||
35 | #define HARD_IDLE_TIMEOUT (HZ / 3) | |
36 | ||
37 | void disable_hlt(void) | |
38 | { | |
39 | hlt_counter++; | |
40 | } | |
41 | ||
42 | void enable_hlt(void) | |
43 | { | |
44 | hlt_counter--; | |
45 | } | |
46 | ||
47 | static int __init nohlt_setup(char *__unused) | |
48 | { | |
49 | hlt_counter = 1; | |
50 | return 1; | |
51 | } | |
52 | ||
53 | static int __init hlt_setup(char *__unused) | |
54 | { | |
55 | hlt_counter = 0; | |
56 | return 1; | |
57 | } | |
58 | ||
59 | __setup("nohlt", nohlt_setup); | |
60 | __setup("hlt", hlt_setup); | |
61 | ||
62 | static inline void hlt(void) | |
63 | { | |
1da177e4 LT |
64 | __asm__ __volatile__ ("sleep" : : : "memory"); |
65 | } | |
66 | ||
67 | /* | |
68 | * The idle loop on a uniprocessor SH.. | |
69 | */ | |
64c7c8f8 | 70 | void cpu_idle(void) |
1da177e4 LT |
71 | { |
72 | /* endless idle loop with no priority at all */ | |
73 | while (1) { | |
74 | if (hlt_counter) { | |
64c7c8f8 NP |
75 | while (!need_resched()) |
76 | cpu_relax(); | |
1da177e4 LT |
77 | } else { |
78 | local_irq_disable(); | |
79 | while (!need_resched()) { | |
80 | local_irq_enable(); | |
1da177e4 LT |
81 | hlt(); |
82 | local_irq_disable(); | |
83 | } | |
84 | local_irq_enable(); | |
85 | } | |
5bfb5d69 | 86 | preempt_enable_no_resched(); |
1da177e4 | 87 | schedule(); |
5bfb5d69 | 88 | preempt_disable(); |
1da177e4 | 89 | } |
1da177e4 | 90 | |
1da177e4 LT |
91 | } |
92 | ||
93 | void machine_restart(char * __unused) | |
94 | { | |
95 | extern void phys_stext(void); | |
96 | ||
97 | phys_stext(); | |
98 | } | |
99 | ||
100 | void machine_halt(void) | |
101 | { | |
102 | for (;;); | |
103 | } | |
104 | ||
105 | void machine_power_off(void) | |
106 | { | |
a7aa92d1 PM |
107 | #if 0 |
108 | /* Disable watchdog timer */ | |
109 | ctrl_outl(0xa5000000, WTCSR); | |
110 | /* Configure deep standby on sleep */ | |
111 | ctrl_outl(0x03, STBCR); | |
112 | #endif | |
113 | ||
114 | __asm__ __volatile__ ( | |
115 | "sleep\n\t" | |
116 | "synci\n\t" | |
117 | "nop;nop;nop;nop\n\t" | |
118 | ); | |
119 | ||
120 | panic("Unexpected wakeup!\n"); | |
1da177e4 LT |
121 | } |
122 | ||
1bb99a64 PM |
123 | void (*pm_power_off)(void) = machine_power_off; |
124 | EXPORT_SYMBOL(pm_power_off); | |
125 | ||
1da177e4 LT |
126 | void show_regs(struct pt_regs * regs) |
127 | { | |
128 | unsigned long long ah, al, bh, bl, ch, cl; | |
129 | ||
130 | printk("\n"); | |
131 | ||
132 | ah = (regs->pc) >> 32; | |
133 | al = (regs->pc) & 0xffffffff; | |
134 | bh = (regs->regs[18]) >> 32; | |
135 | bl = (regs->regs[18]) & 0xffffffff; | |
136 | ch = (regs->regs[15]) >> 32; | |
137 | cl = (regs->regs[15]) & 0xffffffff; | |
138 | printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n", | |
139 | ah, al, bh, bl, ch, cl); | |
140 | ||
141 | ah = (regs->sr) >> 32; | |
142 | al = (regs->sr) & 0xffffffff; | |
143 | asm volatile ("getcon " __TEA ", %0" : "=r" (bh)); | |
144 | asm volatile ("getcon " __TEA ", %0" : "=r" (bl)); | |
145 | bh = (bh) >> 32; | |
146 | bl = (bl) & 0xffffffff; | |
147 | asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch)); | |
148 | asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl)); | |
149 | ch = (ch) >> 32; | |
150 | cl = (cl) & 0xffffffff; | |
151 | printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n", | |
152 | ah, al, bh, bl, ch, cl); | |
153 | ||
154 | ah = (regs->regs[0]) >> 32; | |
155 | al = (regs->regs[0]) & 0xffffffff; | |
156 | bh = (regs->regs[1]) >> 32; | |
157 | bl = (regs->regs[1]) & 0xffffffff; | |
158 | ch = (regs->regs[2]) >> 32; | |
159 | cl = (regs->regs[2]) & 0xffffffff; | |
160 | printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n", | |
161 | ah, al, bh, bl, ch, cl); | |
162 | ||
163 | ah = (regs->regs[3]) >> 32; | |
164 | al = (regs->regs[3]) & 0xffffffff; | |
165 | bh = (regs->regs[4]) >> 32; | |
166 | bl = (regs->regs[4]) & 0xffffffff; | |
167 | ch = (regs->regs[5]) >> 32; | |
168 | cl = (regs->regs[5]) & 0xffffffff; | |
169 | printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n", | |
170 | ah, al, bh, bl, ch, cl); | |
171 | ||
172 | ah = (regs->regs[6]) >> 32; | |
173 | al = (regs->regs[6]) & 0xffffffff; | |
174 | bh = (regs->regs[7]) >> 32; | |
175 | bl = (regs->regs[7]) & 0xffffffff; | |
176 | ch = (regs->regs[8]) >> 32; | |
177 | cl = (regs->regs[8]) & 0xffffffff; | |
178 | printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n", | |
179 | ah, al, bh, bl, ch, cl); | |
180 | ||
181 | ah = (regs->regs[9]) >> 32; | |
182 | al = (regs->regs[9]) & 0xffffffff; | |
183 | bh = (regs->regs[10]) >> 32; | |
184 | bl = (regs->regs[10]) & 0xffffffff; | |
185 | ch = (regs->regs[11]) >> 32; | |
186 | cl = (regs->regs[11]) & 0xffffffff; | |
187 | printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n", | |
188 | ah, al, bh, bl, ch, cl); | |
189 | ||
190 | ah = (regs->regs[12]) >> 32; | |
191 | al = (regs->regs[12]) & 0xffffffff; | |
192 | bh = (regs->regs[13]) >> 32; | |
193 | bl = (regs->regs[13]) & 0xffffffff; | |
194 | ch = (regs->regs[14]) >> 32; | |
195 | cl = (regs->regs[14]) & 0xffffffff; | |
196 | printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n", | |
197 | ah, al, bh, bl, ch, cl); | |
198 | ||
199 | ah = (regs->regs[16]) >> 32; | |
200 | al = (regs->regs[16]) & 0xffffffff; | |
201 | bh = (regs->regs[17]) >> 32; | |
202 | bl = (regs->regs[17]) & 0xffffffff; | |
203 | ch = (regs->regs[19]) >> 32; | |
204 | cl = (regs->regs[19]) & 0xffffffff; | |
205 | printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n", | |
206 | ah, al, bh, bl, ch, cl); | |
207 | ||
208 | ah = (regs->regs[20]) >> 32; | |
209 | al = (regs->regs[20]) & 0xffffffff; | |
210 | bh = (regs->regs[21]) >> 32; | |
211 | bl = (regs->regs[21]) & 0xffffffff; | |
212 | ch = (regs->regs[22]) >> 32; | |
213 | cl = (regs->regs[22]) & 0xffffffff; | |
214 | printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n", | |
215 | ah, al, bh, bl, ch, cl); | |
216 | ||
217 | ah = (regs->regs[23]) >> 32; | |
218 | al = (regs->regs[23]) & 0xffffffff; | |
219 | bh = (regs->regs[24]) >> 32; | |
220 | bl = (regs->regs[24]) & 0xffffffff; | |
221 | ch = (regs->regs[25]) >> 32; | |
222 | cl = (regs->regs[25]) & 0xffffffff; | |
223 | printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n", | |
224 | ah, al, bh, bl, ch, cl); | |
225 | ||
226 | ah = (regs->regs[26]) >> 32; | |
227 | al = (regs->regs[26]) & 0xffffffff; | |
228 | bh = (regs->regs[27]) >> 32; | |
229 | bl = (regs->regs[27]) & 0xffffffff; | |
230 | ch = (regs->regs[28]) >> 32; | |
231 | cl = (regs->regs[28]) & 0xffffffff; | |
232 | printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n", | |
233 | ah, al, bh, bl, ch, cl); | |
234 | ||
235 | ah = (regs->regs[29]) >> 32; | |
236 | al = (regs->regs[29]) & 0xffffffff; | |
237 | bh = (regs->regs[30]) >> 32; | |
238 | bl = (regs->regs[30]) & 0xffffffff; | |
239 | ch = (regs->regs[31]) >> 32; | |
240 | cl = (regs->regs[31]) & 0xffffffff; | |
241 | printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n", | |
242 | ah, al, bh, bl, ch, cl); | |
243 | ||
244 | ah = (regs->regs[32]) >> 32; | |
245 | al = (regs->regs[32]) & 0xffffffff; | |
246 | bh = (regs->regs[33]) >> 32; | |
247 | bl = (regs->regs[33]) & 0xffffffff; | |
248 | ch = (regs->regs[34]) >> 32; | |
249 | cl = (regs->regs[34]) & 0xffffffff; | |
250 | printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n", | |
251 | ah, al, bh, bl, ch, cl); | |
252 | ||
253 | ah = (regs->regs[35]) >> 32; | |
254 | al = (regs->regs[35]) & 0xffffffff; | |
255 | bh = (regs->regs[36]) >> 32; | |
256 | bl = (regs->regs[36]) & 0xffffffff; | |
257 | ch = (regs->regs[37]) >> 32; | |
258 | cl = (regs->regs[37]) & 0xffffffff; | |
259 | printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n", | |
260 | ah, al, bh, bl, ch, cl); | |
261 | ||
262 | ah = (regs->regs[38]) >> 32; | |
263 | al = (regs->regs[38]) & 0xffffffff; | |
264 | bh = (regs->regs[39]) >> 32; | |
265 | bl = (regs->regs[39]) & 0xffffffff; | |
266 | ch = (regs->regs[40]) >> 32; | |
267 | cl = (regs->regs[40]) & 0xffffffff; | |
268 | printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n", | |
269 | ah, al, bh, bl, ch, cl); | |
270 | ||
271 | ah = (regs->regs[41]) >> 32; | |
272 | al = (regs->regs[41]) & 0xffffffff; | |
273 | bh = (regs->regs[42]) >> 32; | |
274 | bl = (regs->regs[42]) & 0xffffffff; | |
275 | ch = (regs->regs[43]) >> 32; | |
276 | cl = (regs->regs[43]) & 0xffffffff; | |
277 | printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n", | |
278 | ah, al, bh, bl, ch, cl); | |
279 | ||
280 | ah = (regs->regs[44]) >> 32; | |
281 | al = (regs->regs[44]) & 0xffffffff; | |
282 | bh = (regs->regs[45]) >> 32; | |
283 | bl = (regs->regs[45]) & 0xffffffff; | |
284 | ch = (regs->regs[46]) >> 32; | |
285 | cl = (regs->regs[46]) & 0xffffffff; | |
286 | printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n", | |
287 | ah, al, bh, bl, ch, cl); | |
288 | ||
289 | ah = (regs->regs[47]) >> 32; | |
290 | al = (regs->regs[47]) & 0xffffffff; | |
291 | bh = (regs->regs[48]) >> 32; | |
292 | bl = (regs->regs[48]) & 0xffffffff; | |
293 | ch = (regs->regs[49]) >> 32; | |
294 | cl = (regs->regs[49]) & 0xffffffff; | |
295 | printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n", | |
296 | ah, al, bh, bl, ch, cl); | |
297 | ||
298 | ah = (regs->regs[50]) >> 32; | |
299 | al = (regs->regs[50]) & 0xffffffff; | |
300 | bh = (regs->regs[51]) >> 32; | |
301 | bl = (regs->regs[51]) & 0xffffffff; | |
302 | ch = (regs->regs[52]) >> 32; | |
303 | cl = (regs->regs[52]) & 0xffffffff; | |
304 | printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n", | |
305 | ah, al, bh, bl, ch, cl); | |
306 | ||
307 | ah = (regs->regs[53]) >> 32; | |
308 | al = (regs->regs[53]) & 0xffffffff; | |
309 | bh = (regs->regs[54]) >> 32; | |
310 | bl = (regs->regs[54]) & 0xffffffff; | |
311 | ch = (regs->regs[55]) >> 32; | |
312 | cl = (regs->regs[55]) & 0xffffffff; | |
313 | printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n", | |
314 | ah, al, bh, bl, ch, cl); | |
315 | ||
316 | ah = (regs->regs[56]) >> 32; | |
317 | al = (regs->regs[56]) & 0xffffffff; | |
318 | bh = (regs->regs[57]) >> 32; | |
319 | bl = (regs->regs[57]) & 0xffffffff; | |
320 | ch = (regs->regs[58]) >> 32; | |
321 | cl = (regs->regs[58]) & 0xffffffff; | |
322 | printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n", | |
323 | ah, al, bh, bl, ch, cl); | |
324 | ||
325 | ah = (regs->regs[59]) >> 32; | |
326 | al = (regs->regs[59]) & 0xffffffff; | |
327 | bh = (regs->regs[60]) >> 32; | |
328 | bl = (regs->regs[60]) & 0xffffffff; | |
329 | ch = (regs->regs[61]) >> 32; | |
330 | cl = (regs->regs[61]) & 0xffffffff; | |
331 | printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n", | |
332 | ah, al, bh, bl, ch, cl); | |
333 | ||
334 | ah = (regs->regs[62]) >> 32; | |
335 | al = (regs->regs[62]) & 0xffffffff; | |
336 | bh = (regs->tregs[0]) >> 32; | |
337 | bl = (regs->tregs[0]) & 0xffffffff; | |
338 | ch = (regs->tregs[1]) >> 32; | |
339 | cl = (regs->tregs[1]) & 0xffffffff; | |
340 | printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n", | |
341 | ah, al, bh, bl, ch, cl); | |
342 | ||
343 | ah = (regs->tregs[2]) >> 32; | |
344 | al = (regs->tregs[2]) & 0xffffffff; | |
345 | bh = (regs->tregs[3]) >> 32; | |
346 | bl = (regs->tregs[3]) & 0xffffffff; | |
347 | ch = (regs->tregs[4]) >> 32; | |
348 | cl = (regs->tregs[4]) & 0xffffffff; | |
349 | printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n", | |
350 | ah, al, bh, bl, ch, cl); | |
351 | ||
352 | ah = (regs->tregs[5]) >> 32; | |
353 | al = (regs->tregs[5]) & 0xffffffff; | |
354 | bh = (regs->tregs[6]) >> 32; | |
355 | bl = (regs->tregs[6]) & 0xffffffff; | |
356 | ch = (regs->tregs[7]) >> 32; | |
357 | cl = (regs->tregs[7]) & 0xffffffff; | |
358 | printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n", | |
359 | ah, al, bh, bl, ch, cl); | |
360 | ||
361 | /* | |
362 | * If we're in kernel mode, dump the stack too.. | |
363 | */ | |
364 | if (!user_mode(regs)) { | |
365 | void show_stack(struct task_struct *tsk, unsigned long *sp); | |
366 | unsigned long sp = regs->regs[15] & 0xffffffff; | |
367 | struct task_struct *tsk = get_current(); | |
368 | ||
369 | tsk->thread.kregs = regs; | |
370 | ||
371 | show_stack(tsk, (unsigned long *)sp); | |
372 | } | |
373 | } | |
374 | ||
375 | struct task_struct * alloc_task_struct(void) | |
376 | { | |
377 | /* Get task descriptor pages */ | |
378 | return (struct task_struct *) | |
379 | __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE)); | |
380 | } | |
381 | ||
382 | void free_task_struct(struct task_struct *p) | |
383 | { | |
384 | free_pages((unsigned long) p, get_order(THREAD_SIZE)); | |
385 | } | |
386 | ||
387 | /* | |
388 | * Create a kernel thread | |
389 | */ | |
821278a7 AB |
390 | ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *)) |
391 | { | |
392 | do_exit(fn(arg)); | |
393 | } | |
1da177e4 LT |
394 | |
395 | /* | |
396 | * This is the mechanism for creating a new kernel thread. | |
397 | * | |
398 | * NOTE! Only a kernel-only process(ie the swapper or direct descendants | |
399 | * who haven't done an "execve()") should use this: it will work within | |
400 | * a system call from a "real" process, but the process memory space will | |
0a354775 | 401 | * not be freed until both the parent and the child have exited. |
1da177e4 LT |
402 | */ |
403 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) | |
404 | { | |
821278a7 | 405 | struct pt_regs regs; |
1da177e4 | 406 | |
821278a7 AB |
407 | memset(®s, 0, sizeof(regs)); |
408 | regs.regs[2] = (unsigned long)arg; | |
409 | regs.regs[3] = (unsigned long)fn; | |
1da177e4 | 410 | |
821278a7 AB |
411 | regs.pc = (unsigned long)kernel_thread_helper; |
412 | regs.sr = (1 << 30); | |
1da177e4 | 413 | |
821278a7 AB |
414 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, |
415 | ®s, 0, NULL, NULL); | |
1da177e4 LT |
416 | } |
417 | ||
418 | /* | |
419 | * Free current thread data structures etc.. | |
420 | */ | |
421 | void exit_thread(void) | |
422 | { | |
423 | /* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC. | |
424 | ||
425 | The SH-5 FPU save/restore approach relies on last_task_used_math | |
426 | pointing to a live task_struct. When another task tries to use the | |
427 | FPU for the 1st time, the FPUDIS trap handling (see | |
428 | arch/sh64/kernel/fpu.c) will save the existing FPU state to the | |
429 | FP regs field within last_task_used_math before re-loading the new | |
430 | task's FPU state (or initialising it if the FPU has been used | |
431 | before). So if last_task_used_math is stale, and its page has already been | |
432 | re-allocated for another use, the consequences are rather grim. Unless we | |
433 | null it here, there is no other path through which it would get safely | |
434 | nulled. */ | |
435 | ||
436 | #ifdef CONFIG_SH_FPU | |
437 | if (last_task_used_math == current) { | |
438 | last_task_used_math = NULL; | |
439 | } | |
440 | #endif | |
441 | } | |
442 | ||
443 | void flush_thread(void) | |
444 | { | |
445 | ||
446 | /* Called by fs/exec.c (flush_old_exec) to remove traces of a | |
447 | * previously running executable. */ | |
448 | #ifdef CONFIG_SH_FPU | |
449 | if (last_task_used_math == current) { | |
450 | last_task_used_math = NULL; | |
451 | } | |
452 | /* Force FPU state to be reinitialised after exec */ | |
453 | clear_used_math(); | |
454 | #endif | |
455 | ||
456 | /* if we are a kernel thread, about to change to user thread, | |
457 | * update kreg | |
458 | */ | |
459 | if(current->thread.kregs==&fake_swapper_regs) { | |
460 | current->thread.kregs = | |
461 | ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1); | |
462 | current->thread.uregs = current->thread.kregs; | |
463 | } | |
464 | } | |
465 | ||
466 | void release_thread(struct task_struct *dead_task) | |
467 | { | |
468 | /* do nothing */ | |
469 | } | |
470 | ||
471 | /* Fill in the fpu structure for a core dump.. */ | |
472 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) | |
473 | { | |
474 | #ifdef CONFIG_SH_FPU | |
475 | int fpvalid; | |
476 | struct task_struct *tsk = current; | |
477 | ||
478 | fpvalid = !!tsk_used_math(tsk); | |
479 | if (fpvalid) { | |
480 | if (current == last_task_used_math) { | |
600ee240 | 481 | enable_fpu(); |
1da177e4 | 482 | fpsave(&tsk->thread.fpu.hard); |
600ee240 | 483 | disable_fpu(); |
1da177e4 LT |
484 | last_task_used_math = 0; |
485 | regs->sr |= SR_FD; | |
486 | } | |
487 | ||
488 | memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu)); | |
489 | } | |
490 | ||
491 | return fpvalid; | |
492 | #else | |
493 | return 0; /* Task didn't use the fpu at all. */ | |
494 | #endif | |
495 | } | |
496 | ||
497 | asmlinkage void ret_from_fork(void); | |
498 | ||
499 | int copy_thread(int nr, unsigned long clone_flags, unsigned long usp, | |
500 | unsigned long unused, | |
501 | struct task_struct *p, struct pt_regs *regs) | |
502 | { | |
503 | struct pt_regs *childregs; | |
504 | unsigned long long se; /* Sign extension */ | |
505 | ||
506 | #ifdef CONFIG_SH_FPU | |
507 | if(last_task_used_math == current) { | |
600ee240 | 508 | enable_fpu(); |
1da177e4 | 509 | fpsave(¤t->thread.fpu.hard); |
600ee240 | 510 | disable_fpu(); |
1da177e4 LT |
511 | last_task_used_math = NULL; |
512 | regs->sr |= SR_FD; | |
513 | } | |
514 | #endif | |
515 | /* Copy from sh version */ | |
ee8c1dd4 | 516 | childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1; |
1da177e4 LT |
517 | |
518 | *childregs = *regs; | |
519 | ||
520 | if (user_mode(regs)) { | |
521 | childregs->regs[15] = usp; | |
522 | p->thread.uregs = childregs; | |
523 | } else { | |
ee8c1dd4 | 524 | childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE; |
1da177e4 LT |
525 | } |
526 | ||
527 | childregs->regs[9] = 0; /* Set return value for child */ | |
528 | childregs->sr |= SR_FD; /* Invalidate FPU flag */ | |
529 | ||
530 | p->thread.sp = (unsigned long) childregs; | |
531 | p->thread.pc = (unsigned long) ret_from_fork; | |
532 | ||
533 | /* | |
534 | * Sign extend the edited stack. | |
535 | * Note that thread.pc and thread.pc will stay | |
536 | * 32-bit wide and context switch must take care | |
537 | * of NEFF sign extension. | |
538 | */ | |
539 | ||
540 | se = childregs->regs[15]; | |
541 | se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se; | |
542 | childregs->regs[15] = se; | |
543 | ||
544 | return 0; | |
545 | } | |
546 | ||
1da177e4 LT |
547 | asmlinkage int sys_fork(unsigned long r2, unsigned long r3, |
548 | unsigned long r4, unsigned long r5, | |
549 | unsigned long r6, unsigned long r7, | |
550 | struct pt_regs *pregs) | |
551 | { | |
552 | return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0); | |
553 | } | |
554 | ||
555 | asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, | |
556 | unsigned long r4, unsigned long r5, | |
557 | unsigned long r6, unsigned long r7, | |
558 | struct pt_regs *pregs) | |
559 | { | |
560 | if (!newsp) | |
561 | newsp = pregs->regs[15]; | |
562 | return do_fork(clone_flags, newsp, pregs, 0, 0, 0); | |
563 | } | |
564 | ||
565 | /* | |
566 | * This is trivial, and on the face of it looks like it | |
567 | * could equally well be done in user mode. | |
568 | * | |
569 | * Not so, for quite unobvious reasons - register pressure. | |
570 | * In user mode vfork() cannot have a stack frame, and if | |
571 | * done by calling the "clone()" system call directly, you | |
572 | * do not have enough call-clobbered registers to hold all | |
573 | * the information you need. | |
574 | */ | |
575 | asmlinkage int sys_vfork(unsigned long r2, unsigned long r3, | |
576 | unsigned long r4, unsigned long r5, | |
577 | unsigned long r6, unsigned long r7, | |
578 | struct pt_regs *pregs) | |
579 | { | |
580 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0); | |
581 | } | |
582 | ||
583 | /* | |
584 | * sys_execve() executes a new program. | |
585 | */ | |
586 | asmlinkage int sys_execve(char *ufilename, char **uargv, | |
587 | char **uenvp, unsigned long r5, | |
588 | unsigned long r6, unsigned long r7, | |
589 | struct pt_regs *pregs) | |
590 | { | |
591 | int error; | |
592 | char *filename; | |
593 | ||
594 | lock_kernel(); | |
595 | filename = getname((char __user *)ufilename); | |
596 | error = PTR_ERR(filename); | |
597 | if (IS_ERR(filename)) | |
598 | goto out; | |
599 | ||
600 | error = do_execve(filename, | |
601 | (char __user * __user *)uargv, | |
602 | (char __user * __user *)uenvp, | |
603 | pregs); | |
604 | if (error == 0) { | |
605 | task_lock(current); | |
606 | current->ptrace &= ~PT_DTRACE; | |
607 | task_unlock(current); | |
608 | } | |
609 | putname(filename); | |
610 | out: | |
611 | unlock_kernel(); | |
612 | return error; | |
613 | } | |
614 | ||
615 | /* | |
616 | * These bracket the sleeping functions.. | |
617 | */ | |
618 | extern void interruptible_sleep_on(wait_queue_head_t *q); | |
619 | ||
620 | #define mid_sched ((unsigned long) interruptible_sleep_on) | |
621 | ||
622 | static int in_sh64_switch_to(unsigned long pc) | |
623 | { | |
624 | extern char __sh64_switch_to_end; | |
625 | /* For a sleeping task, the PC is somewhere in the middle of the function, | |
626 | so we don't have to worry about masking the LSB off */ | |
627 | return (pc >= (unsigned long) sh64_switch_to) && | |
628 | (pc < (unsigned long) &__sh64_switch_to_end); | |
629 | } | |
630 | ||
631 | unsigned long get_wchan(struct task_struct *p) | |
632 | { | |
633 | unsigned long schedule_fp; | |
634 | unsigned long sh64_switch_to_fp; | |
635 | unsigned long schedule_caller_pc; | |
636 | unsigned long pc; | |
637 | ||
638 | if (!p || p == current || p->state == TASK_RUNNING) | |
639 | return 0; | |
640 | ||
641 | /* | |
642 | * The same comment as on the Alpha applies here, too ... | |
643 | */ | |
644 | pc = thread_saved_pc(p); | |
645 | ||
646 | #ifdef CONFIG_FRAME_POINTER | |
647 | if (in_sh64_switch_to(pc)) { | |
648 | sh64_switch_to_fp = (long) p->thread.sp; | |
649 | /* r14 is saved at offset 4 in the sh64_switch_to frame */ | |
650 | schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4); | |
651 | ||
652 | /* and the caller of 'schedule' is (currently!) saved at offset 24 | |
653 | in the frame of schedule (from disasm) */ | |
654 | schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24); | |
655 | return schedule_caller_pc; | |
656 | } | |
657 | #endif | |
658 | return pc; | |
659 | } | |
660 | ||
661 | /* Provide a /proc/asids file that lists out the | |
662 | ASIDs currently associated with the processes. (If the DM.PC register is | |
663 | examined through the debug link, this shows ASID + PC. To make use of this, | |
664 | the PID->ASID relationship needs to be known. This is primarily for | |
665 | debugging.) | |
666 | */ | |
667 | ||
668 | #if defined(CONFIG_SH64_PROC_ASIDS) | |
1da177e4 LT |
669 | static int |
670 | asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data) | |
671 | { | |
672 | int len=0; | |
673 | struct task_struct *p; | |
674 | read_lock(&tasklist_lock); | |
675 | for_each_process(p) { | |
676 | int pid = p->pid; | |
677 | struct mm_struct *mm; | |
678 | if (!pid) continue; | |
679 | mm = p->mm; | |
680 | if (mm) { | |
681 | unsigned long asid, context; | |
682 | context = mm->context; | |
683 | asid = (context & 0xff); | |
684 | len += sprintf(buf+len, "%5d : %02lx\n", pid, asid); | |
685 | } else { | |
686 | len += sprintf(buf+len, "%5d : (none)\n", pid); | |
687 | } | |
688 | } | |
689 | read_unlock(&tasklist_lock); | |
690 | *eof = 1; | |
691 | return len; | |
692 | } | |
693 | ||
694 | static int __init register_proc_asids(void) | |
695 | { | |
c26056bc PM |
696 | create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL); |
697 | return 0; | |
1da177e4 | 698 | } |
1da177e4 LT |
699 | __initcall(register_proc_asids); |
700 | #endif |