sparc32: remove all uses of ARCH_SUN4C
[cascardo/linux.git] / arch / sparc / kernel / process_32.c
1 /*  linux/arch/sparc/kernel/process.c
2  *
3  *  Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
4  *  Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
5  */
6
7 /*
8  * This file handles the architecture-dependent parts of process handling..
9  */
10
11 #include <stdarg.h>
12
13 #include <linux/errno.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/stddef.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.h>
21 #include <linux/smp.h>
22 #include <linux/reboot.h>
23 #include <linux/delay.h>
24 #include <linux/pm.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27
28 #include <asm/auxio.h>
29 #include <asm/oplib.h>
30 #include <asm/uaccess.h>
31 #include <asm/page.h>
32 #include <asm/pgalloc.h>
33 #include <asm/pgtable.h>
34 #include <asm/delay.h>
35 #include <asm/processor.h>
36 #include <asm/psr.h>
37 #include <asm/elf.h>
38 #include <asm/prom.h>
39 #include <asm/unistd.h>
40 #include <asm/setup.h>
41
42 /* 
43  * Power management idle function 
44  * Set in pm platform drivers (apc.c and pmc.c)
45  */
46 void (*pm_idle)(void);
47 EXPORT_SYMBOL(pm_idle);
48
49 /* 
50  * Power-off handler instantiation for pm.h compliance
51  * This is done via auxio, but could be used as a fallback
52  * handler when auxio is not present-- unused for now...
53  */
54 void (*pm_power_off)(void) = machine_power_off;
55 EXPORT_SYMBOL(pm_power_off);
56
57 /*
58  * sysctl - toggle power-off restriction for serial console 
59  * systems in machine_power_off()
60  */
61 int scons_pwroff = 1;
62
63 extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
64
65 struct task_struct *last_task_used_math = NULL;
66 struct thread_info *current_set[NR_CPUS];
67
68 #ifndef CONFIG_SMP
69
70 /*
71  * the idle loop on a Sparc... ;)
72  */
73 void cpu_idle(void)
74 {
75         /* endless idle loop with no priority at all */
76         for (;;) {
77                 if (pm_idle) {
78                         while (!need_resched())
79                                 (*pm_idle)();
80                 } else {
81                         while (!need_resched())
82                                 cpu_relax();
83                 }
84                 schedule_preempt_disabled();
85                 check_pgt_cache();
86         }
87 }
88
89 #else
90
91 /* This is being executed in task 0 'user space'. */
92 void cpu_idle(void)
93 {
94         set_thread_flag(TIF_POLLING_NRFLAG);
95         /* endless idle loop with no priority at all */
96         while(1) {
97 #ifdef CONFIG_SPARC_LEON
98                 if (pm_idle) {
99                         while (!need_resched())
100                                 (*pm_idle)();
101                 } else
102 #endif
103                 {
104                         while (!need_resched())
105                                 cpu_relax();
106                 }
107                 schedule_preempt_disabled();
108                 check_pgt_cache();
109         }
110 }
111
112 #endif
113
114 /* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
115 void machine_halt(void)
116 {
117         local_irq_enable();
118         mdelay(8);
119         local_irq_disable();
120         prom_halt();
121         panic("Halt failed!");
122 }
123
124 void machine_restart(char * cmd)
125 {
126         char *p;
127         
128         local_irq_enable();
129         mdelay(8);
130         local_irq_disable();
131
132         p = strchr (reboot_command, '\n');
133         if (p) *p = 0;
134         if (cmd)
135                 prom_reboot(cmd);
136         if (*reboot_command)
137                 prom_reboot(reboot_command);
138         prom_feval ("reset");
139         panic("Reboot failed!");
140 }
141
142 void machine_power_off(void)
143 {
144         if (auxio_power_register &&
145             (strcmp(of_console_device->type, "serial") || scons_pwroff))
146                 *auxio_power_register |= AUXIO_POWER_OFF;
147         machine_halt();
148 }
149
150 #if 0
151
152 static DEFINE_SPINLOCK(sparc_backtrace_lock);
153
154 void __show_backtrace(unsigned long fp)
155 {
156         struct reg_window32 *rw;
157         unsigned long flags;
158         int cpu = smp_processor_id();
159
160         spin_lock_irqsave(&sparc_backtrace_lock, flags);
161
162         rw = (struct reg_window32 *)fp;
163         while(rw && (((unsigned long) rw) >= PAGE_OFFSET) &&
164             !(((unsigned long) rw) & 0x7)) {
165                 printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] "
166                        "FP[%08lx] CALLER[%08lx]: ", cpu,
167                        rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
168                        rw->ins[4], rw->ins[5],
169                        rw->ins[6],
170                        rw->ins[7]);
171                 printk("%pS\n", (void *) rw->ins[7]);
172                 rw = (struct reg_window32 *) rw->ins[6];
173         }
174         spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
175 }
176
177 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
178 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
179 #define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))
180
181 void show_backtrace(void)
182 {
183         unsigned long fp;
184
185         __SAVE; __SAVE; __SAVE; __SAVE;
186         __SAVE; __SAVE; __SAVE; __SAVE;
187         __RESTORE; __RESTORE; __RESTORE; __RESTORE;
188         __RESTORE; __RESTORE; __RESTORE; __RESTORE;
189
190         __GET_FP(fp);
191
192         __show_backtrace(fp);
193 }
194
195 #ifdef CONFIG_SMP
196 void smp_show_backtrace_all_cpus(void)
197 {
198         xc0((smpfunc_t) show_backtrace);
199         show_backtrace();
200 }
201 #endif
202
203 void show_stackframe(struct sparc_stackf *sf)
204 {
205         unsigned long size;
206         unsigned long *stk;
207         int i;
208
209         printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
210                "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n",
211                sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
212                sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
213         printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
214                "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n",
215                sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
216                sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
217         printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx "
218                "x3: %08lx x4: %08lx x5: %08lx xx: %08lx\n",
219                (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
220                sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
221                sf->xxargs[0]);
222         size = ((unsigned long)sf->fp) - ((unsigned long)sf);
223         size -= STACKFRAME_SZ;
224         stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
225         i = 0;
226         do {
227                 printk("s%d: %08lx\n", i++, *stk++);
228         } while ((size -= sizeof(unsigned long)));
229 }
230 #endif
231
232 void show_regs(struct pt_regs *r)
233 {
234         struct reg_window32 *rw = (struct reg_window32 *) r->u_regs[14];
235
236         printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx    %s\n",
237                r->psr, r->pc, r->npc, r->y, print_tainted());
238         printk("PC: <%pS>\n", (void *) r->pc);
239         printk("%%G: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
240                r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
241                r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
242         printk("%%O: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
243                r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
244                r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
245         printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
246
247         printk("%%L: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
248                rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
249                rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
250         printk("%%I: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
251                rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
252                rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
253 }
254
255 /*
256  * The show_stack is an external API which we do not use ourselves.
257  * The oops is printed in die_if_kernel.
258  */
259 void show_stack(struct task_struct *tsk, unsigned long *_ksp)
260 {
261         unsigned long pc, fp;
262         unsigned long task_base;
263         struct reg_window32 *rw;
264         int count = 0;
265
266         if (tsk != NULL)
267                 task_base = (unsigned long) task_stack_page(tsk);
268         else
269                 task_base = (unsigned long) current_thread_info();
270
271         fp = (unsigned long) _ksp;
272         do {
273                 /* Bogus frame pointer? */
274                 if (fp < (task_base + sizeof(struct thread_info)) ||
275                     fp >= (task_base + (PAGE_SIZE << 1)))
276                         break;
277                 rw = (struct reg_window32 *) fp;
278                 pc = rw->ins[7];
279                 printk("[%08lx : ", pc);
280                 printk("%pS ] ", (void *) pc);
281                 fp = rw->ins[6];
282         } while (++count < 16);
283         printk("\n");
284 }
285
286 void dump_stack(void)
287 {
288         unsigned long *ksp;
289
290         __asm__ __volatile__("mov       %%fp, %0"
291                              : "=r" (ksp));
292         show_stack(current, ksp);
293 }
294
295 EXPORT_SYMBOL(dump_stack);
296
297 /*
298  * Note: sparc64 has a pretty intricated thread_saved_pc, check it out.
299  */
300 unsigned long thread_saved_pc(struct task_struct *tsk)
301 {
302         return task_thread_info(tsk)->kpc;
303 }
304
305 /*
306  * Free current thread data structures etc..
307  */
308 void exit_thread(void)
309 {
310 #ifndef CONFIG_SMP
311         if(last_task_used_math == current) {
312 #else
313         if (test_thread_flag(TIF_USEDFPU)) {
314 #endif
315                 /* Keep process from leaving FPU in a bogon state. */
316                 put_psr(get_psr() | PSR_EF);
317                 fpsave(&current->thread.float_regs[0], &current->thread.fsr,
318                        &current->thread.fpqueue[0], &current->thread.fpqdepth);
319 #ifndef CONFIG_SMP
320                 last_task_used_math = NULL;
321 #else
322                 clear_thread_flag(TIF_USEDFPU);
323 #endif
324         }
325 }
326
327 void flush_thread(void)
328 {
329         current_thread_info()->w_saved = 0;
330
331 #ifndef CONFIG_SMP
332         if(last_task_used_math == current) {
333 #else
334         if (test_thread_flag(TIF_USEDFPU)) {
335 #endif
336                 /* Clean the fpu. */
337                 put_psr(get_psr() | PSR_EF);
338                 fpsave(&current->thread.float_regs[0], &current->thread.fsr,
339                        &current->thread.fpqueue[0], &current->thread.fpqdepth);
340 #ifndef CONFIG_SMP
341                 last_task_used_math = NULL;
342 #else
343                 clear_thread_flag(TIF_USEDFPU);
344 #endif
345         }
346
347         /* This task is no longer a kernel thread. */
348         if (current->thread.flags & SPARC_FLAG_KTHREAD) {
349                 current->thread.flags &= ~SPARC_FLAG_KTHREAD;
350
351                 /* We must fixup kregs as well. */
352                 /* XXX This was not fixed for ti for a while, worked. Unused? */
353                 current->thread.kregs = (struct pt_regs *)
354                     (task_stack_page(current) + (THREAD_SIZE - TRACEREG_SZ));
355         }
356 }
357
358 static inline struct sparc_stackf __user *
359 clone_stackframe(struct sparc_stackf __user *dst,
360                  struct sparc_stackf __user *src)
361 {
362         unsigned long size, fp;
363         struct sparc_stackf *tmp;
364         struct sparc_stackf __user *sp;
365
366         if (get_user(tmp, &src->fp))
367                 return NULL;
368
369         fp = (unsigned long) tmp;
370         size = (fp - ((unsigned long) src));
371         fp = (unsigned long) dst;
372         sp = (struct sparc_stackf __user *)(fp - size); 
373
374         /* do_fork() grabs the parent semaphore, we must release it
375          * temporarily so we can build the child clone stack frame
376          * without deadlocking.
377          */
378         if (__copy_user(sp, src, size))
379                 sp = NULL;
380         else if (put_user(fp, &sp->fp))
381                 sp = NULL;
382
383         return sp;
384 }
385
386 asmlinkage int sparc_do_fork(unsigned long clone_flags,
387                              unsigned long stack_start,
388                              struct pt_regs *regs,
389                              unsigned long stack_size)
390 {
391         unsigned long parent_tid_ptr, child_tid_ptr;
392         unsigned long orig_i1 = regs->u_regs[UREG_I1];
393         long ret;
394
395         parent_tid_ptr = regs->u_regs[UREG_I2];
396         child_tid_ptr = regs->u_regs[UREG_I4];
397
398         ret = do_fork(clone_flags, stack_start,
399                       regs, stack_size,
400                       (int __user *) parent_tid_ptr,
401                       (int __user *) child_tid_ptr);
402
403         /* If we get an error and potentially restart the system
404          * call, we're screwed because copy_thread() clobbered
405          * the parent's %o1.  So detect that case and restore it
406          * here.
407          */
408         if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
409                 regs->u_regs[UREG_I1] = orig_i1;
410
411         return ret;
412 }
413
414 /* Copy a Sparc thread.  The fork() return value conventions
415  * under SunOS are nothing short of bletcherous:
416  * Parent -->  %o0 == childs  pid, %o1 == 0
417  * Child  -->  %o0 == parents pid, %o1 == 1
418  *
419  * NOTE: We have a separate fork kpsr/kwim because
420  *       the parent could change these values between
421  *       sys_fork invocation and when we reach here
422  *       if the parent should sleep while trying to
423  *       allocate the task_struct and kernel stack in
424  *       do_fork().
425  * XXX See comment above sys_vfork in sparc64. todo.
426  */
427 extern void ret_from_fork(void);
428
429 int copy_thread(unsigned long clone_flags, unsigned long sp,
430                 unsigned long unused,
431                 struct task_struct *p, struct pt_regs *regs)
432 {
433         struct thread_info *ti = task_thread_info(p);
434         struct pt_regs *childregs;
435         char *new_stack;
436
437 #ifndef CONFIG_SMP
438         if(last_task_used_math == current) {
439 #else
440         if (test_thread_flag(TIF_USEDFPU)) {
441 #endif
442                 put_psr(get_psr() | PSR_EF);
443                 fpsave(&p->thread.float_regs[0], &p->thread.fsr,
444                        &p->thread.fpqueue[0], &p->thread.fpqdepth);
445 #ifdef CONFIG_SMP
446                 clear_thread_flag(TIF_USEDFPU);
447 #endif
448         }
449
450         /*
451          *  p->thread_info         new_stack   childregs
452          *  !                      !           !             {if(PSR_PS) }
453          *  V                      V (stk.fr.) V  (pt_regs)  { (stk.fr.) }
454          *  +----- - - - - - ------+===========+============={+==========}+
455          */
456         new_stack = task_stack_page(p) + THREAD_SIZE;
457         if (regs->psr & PSR_PS)
458                 new_stack -= STACKFRAME_SZ;
459         new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
460         memcpy(new_stack, (char *)regs - STACKFRAME_SZ, STACKFRAME_SZ + TRACEREG_SZ);
461         childregs = (struct pt_regs *) (new_stack + STACKFRAME_SZ);
462
463         /*
464          * A new process must start with interrupts closed in 2.5,
465          * because this is how Mingo's scheduler works (see schedule_tail
466          * and finish_arch_switch). If we do not do it, a timer interrupt hits
467          * before we unlock, attempts to re-take the rq->lock, and then we die.
468          * Thus, kpsr|=PSR_PIL.
469          */
470         ti->ksp = (unsigned long) new_stack;
471         ti->kpc = (((unsigned long) ret_from_fork) - 0x8);
472         ti->kpsr = current->thread.fork_kpsr | PSR_PIL;
473         ti->kwim = current->thread.fork_kwim;
474
475         if(regs->psr & PSR_PS) {
476                 extern struct pt_regs fake_swapper_regs;
477
478                 p->thread.kregs = &fake_swapper_regs;
479                 new_stack += STACKFRAME_SZ + TRACEREG_SZ;
480                 childregs->u_regs[UREG_FP] = (unsigned long) new_stack;
481                 p->thread.flags |= SPARC_FLAG_KTHREAD;
482                 p->thread.current_ds = KERNEL_DS;
483                 memcpy(new_stack, (void *)regs->u_regs[UREG_FP], STACKFRAME_SZ);
484                 childregs->u_regs[UREG_G6] = (unsigned long) ti;
485         } else {
486                 p->thread.kregs = childregs;
487                 childregs->u_regs[UREG_FP] = sp;
488                 p->thread.flags &= ~SPARC_FLAG_KTHREAD;
489                 p->thread.current_ds = USER_DS;
490
491                 if (sp != regs->u_regs[UREG_FP]) {
492                         struct sparc_stackf __user *childstack;
493                         struct sparc_stackf __user *parentstack;
494
495                         /*
496                          * This is a clone() call with supplied user stack.
497                          * Set some valid stack frames to give to the child.
498                          */
499                         childstack = (struct sparc_stackf __user *)
500                                 (sp & ~0xfUL);
501                         parentstack = (struct sparc_stackf __user *)
502                                 regs->u_regs[UREG_FP];
503
504 #if 0
505                         printk("clone: parent stack:\n");
506                         show_stackframe(parentstack);
507 #endif
508
509                         childstack = clone_stackframe(childstack, parentstack);
510                         if (!childstack)
511                                 return -EFAULT;
512
513 #if 0
514                         printk("clone: child stack:\n");
515                         show_stackframe(childstack);
516 #endif
517
518                         childregs->u_regs[UREG_FP] = (unsigned long)childstack;
519                 }
520         }
521
522 #ifdef CONFIG_SMP
523         /* FPU must be disabled on SMP. */
524         childregs->psr &= ~PSR_EF;
525 #endif
526
527         /* Set the return value for the child. */
528         childregs->u_regs[UREG_I0] = current->pid;
529         childregs->u_regs[UREG_I1] = 1;
530
531         /* Set the return value for the parent. */
532         regs->u_regs[UREG_I1] = 0;
533
534         if (clone_flags & CLONE_SETTLS)
535                 childregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3];
536
537         return 0;
538 }
539
540 /*
541  * fill in the fpu structure for a core dump.
542  */
543 int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
544 {
545         if (used_math()) {
546                 memset(fpregs, 0, sizeof(*fpregs));
547                 fpregs->pr_q_entrysize = 8;
548                 return 1;
549         }
550 #ifdef CONFIG_SMP
551         if (test_thread_flag(TIF_USEDFPU)) {
552                 put_psr(get_psr() | PSR_EF);
553                 fpsave(&current->thread.float_regs[0], &current->thread.fsr,
554                        &current->thread.fpqueue[0], &current->thread.fpqdepth);
555                 if (regs != NULL) {
556                         regs->psr &= ~(PSR_EF);
557                         clear_thread_flag(TIF_USEDFPU);
558                 }
559         }
560 #else
561         if (current == last_task_used_math) {
562                 put_psr(get_psr() | PSR_EF);
563                 fpsave(&current->thread.float_regs[0], &current->thread.fsr,
564                        &current->thread.fpqueue[0], &current->thread.fpqdepth);
565                 if (regs != NULL) {
566                         regs->psr &= ~(PSR_EF);
567                         last_task_used_math = NULL;
568                 }
569         }
570 #endif
571         memcpy(&fpregs->pr_fr.pr_regs[0],
572                &current->thread.float_regs[0],
573                (sizeof(unsigned long) * 32));
574         fpregs->pr_fsr = current->thread.fsr;
575         fpregs->pr_qcnt = current->thread.fpqdepth;
576         fpregs->pr_q_entrysize = 8;
577         fpregs->pr_en = 1;
578         if(fpregs->pr_qcnt != 0) {
579                 memcpy(&fpregs->pr_q[0],
580                        &current->thread.fpqueue[0],
581                        sizeof(struct fpq) * fpregs->pr_qcnt);
582         }
583         /* Zero out the rest. */
584         memset(&fpregs->pr_q[fpregs->pr_qcnt], 0,
585                sizeof(struct fpq) * (32 - fpregs->pr_qcnt));
586         return 1;
587 }
588
589 /*
590  * sparc_execve() executes a new program after the asm stub has set
591  * things up for us.  This should basically do what I want it to.
592  */
593 asmlinkage int sparc_execve(struct pt_regs *regs)
594 {
595         int error, base = 0;
596         char *filename;
597
598         /* Check for indirect call. */
599         if(regs->u_regs[UREG_G1] == 0)
600                 base = 1;
601
602         filename = getname((char __user *)regs->u_regs[base + UREG_I0]);
603         error = PTR_ERR(filename);
604         if(IS_ERR(filename))
605                 goto out;
606         error = do_execve(filename,
607                           (const char __user *const  __user *)
608                           regs->u_regs[base + UREG_I1],
609                           (const char __user *const  __user *)
610                           regs->u_regs[base + UREG_I2],
611                           regs);
612         putname(filename);
613 out:
614         return error;
615 }
616
617 /*
618  * This is the mechanism for creating a new kernel thread.
619  *
620  * NOTE! Only a kernel-only process(ie the swapper or direct descendants
621  * who haven't done an "execve()") should use this: it will work within
622  * a system call from a "real" process, but the process memory space will
623  * not be freed until both the parent and the child have exited.
624  */
625 pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
626 {
627         long retval;
628
629         __asm__ __volatile__("mov %4, %%g2\n\t"    /* Set aside fn ptr... */
630                              "mov %5, %%g3\n\t"    /* and arg. */
631                              "mov %1, %%g1\n\t"
632                              "mov %2, %%o0\n\t"    /* Clone flags. */
633                              "mov 0, %%o1\n\t"     /* usp arg == 0 */
634                              "t 0x10\n\t"          /* Linux/Sparc clone(). */
635                              "cmp %%o1, 0\n\t"
636                              "be 1f\n\t"           /* The parent, just return. */
637                              " nop\n\t"            /* Delay slot. */
638                              "jmpl %%g2, %%o7\n\t" /* Call the function. */
639                              " mov %%g3, %%o0\n\t" /* Get back the arg in delay. */
640                              "mov %3, %%g1\n\t"
641                              "t 0x10\n\t"          /* Linux/Sparc exit(). */
642                              /* Notreached by child. */
643                              "1: mov %%o0, %0\n\t" :
644                              "=r" (retval) :
645                              "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
646                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
647                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
648         return retval;
649 }
650 EXPORT_SYMBOL(kernel_thread);
651
652 unsigned long get_wchan(struct task_struct *task)
653 {
654         unsigned long pc, fp, bias = 0;
655         unsigned long task_base = (unsigned long) task;
656         unsigned long ret = 0;
657         struct reg_window32 *rw;
658         int count = 0;
659
660         if (!task || task == current ||
661             task->state == TASK_RUNNING)
662                 goto out;
663
664         fp = task_thread_info(task)->ksp + bias;
665         do {
666                 /* Bogus frame pointer? */
667                 if (fp < (task_base + sizeof(struct thread_info)) ||
668                     fp >= (task_base + (2 * PAGE_SIZE)))
669                         break;
670                 rw = (struct reg_window32 *) fp;
671                 pc = rw->ins[7];
672                 if (!in_sched_functions(pc)) {
673                         ret = pc;
674                         goto out;
675                 }
676                 fp = rw->ins[6] + bias;
677         } while (++count < 16);
678
679 out:
680         return ret;
681 }
682