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