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