blob: 82de66e4db6d55ee223b44c19701f39b06751549 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ppc/kernel/process.c
3 *
4 * Derived from "arch/i386/kernel/process.c"
5 * Copyright (C) 1995 Linus Torvalds
6 *
7 * Updated and modified by Cort Dougan (cort@cs.nmt.edu) and
8 * Paul Mackerras (paulus@cs.anu.edu.au)
9 *
10 * PowerPC version
11 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 *
18 */
19
20#include <linux/config.h>
21#include <linux/errno.h>
22#include <linux/sched.h>
23#include <linux/kernel.h>
24#include <linux/mm.h>
25#include <linux/smp.h>
26#include <linux/smp_lock.h>
27#include <linux/stddef.h>
28#include <linux/unistd.h>
29#include <linux/ptrace.h>
30#include <linux/slab.h>
31#include <linux/user.h>
32#include <linux/elf.h>
33#include <linux/init.h>
34#include <linux/prctl.h>
35#include <linux/init_task.h>
36#include <linux/module.h>
37#include <linux/kallsyms.h>
38#include <linux/mqueue.h>
39#include <linux/hardirq.h>
40
41#include <asm/pgtable.h>
42#include <asm/uaccess.h>
43#include <asm/system.h>
44#include <asm/io.h>
45#include <asm/processor.h>
46#include <asm/mmu.h>
47#include <asm/prom.h>
48
49extern unsigned long _get_SP(void);
50
51struct task_struct *last_task_used_math = NULL;
52struct task_struct *last_task_used_altivec = NULL;
53struct task_struct *last_task_used_spe = NULL;
54
55static struct fs_struct init_fs = INIT_FS;
56static struct files_struct init_files = INIT_FILES;
57static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
58static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
59struct mm_struct init_mm = INIT_MM(init_mm);
60EXPORT_SYMBOL(init_mm);
61
62/* this is 8kB-aligned so we can get to the thread_info struct
63 at the base of it from the stack pointer with 1 integer instruction. */
64union thread_union init_thread_union
65 __attribute__((__section__(".data.init_task"))) =
66{ INIT_THREAD_INFO(init_task) };
67
68/* initial task structure */
69struct task_struct init_task = INIT_TASK(init_task);
70EXPORT_SYMBOL(init_task);
71
72/* only used to get secondary processor up */
73struct task_struct *current_set[NR_CPUS] = {&init_task, };
74
75#undef SHOW_TASK_SWITCHES
76#undef CHECK_STACK
77
78#if defined(CHECK_STACK)
79unsigned long
80kernel_stack_top(struct task_struct *tsk)
81{
82 return ((unsigned long)tsk) + sizeof(union task_union);
83}
84
85unsigned long
86task_top(struct task_struct *tsk)
87{
88 return ((unsigned long)tsk) + sizeof(struct thread_info);
89}
90
91/* check to make sure the kernel stack is healthy */
92int check_stack(struct task_struct *tsk)
93{
94 unsigned long stack_top = kernel_stack_top(tsk);
95 unsigned long tsk_top = task_top(tsk);
96 int ret = 0;
97
98#if 0
99 /* check thread magic */
100 if ( tsk->thread.magic != THREAD_MAGIC )
101 {
102 ret |= 1;
103 printk("thread.magic bad: %08x\n", tsk->thread.magic);
104 }
105#endif
106
107 if ( !tsk )
108 printk("check_stack(): tsk bad tsk %p\n",tsk);
109
110 /* check if stored ksp is bad */
111 if ( (tsk->thread.ksp > stack_top) || (tsk->thread.ksp < tsk_top) )
112 {
113 printk("stack out of bounds: %s/%d\n"
114 " tsk_top %08lx ksp %08lx stack_top %08lx\n",
115 tsk->comm,tsk->pid,
116 tsk_top, tsk->thread.ksp, stack_top);
117 ret |= 2;
118 }
119
120 /* check if stack ptr RIGHT NOW is bad */
121 if ( (tsk == current) && ((_get_SP() > stack_top ) || (_get_SP() < tsk_top)) )
122 {
123 printk("current stack ptr out of bounds: %s/%d\n"
124 " tsk_top %08lx sp %08lx stack_top %08lx\n",
125 current->comm,current->pid,
126 tsk_top, _get_SP(), stack_top);
127 ret |= 4;
128 }
129
130#if 0
131 /* check amount of free stack */
132 for ( i = (unsigned long *)task_top(tsk) ; i < kernel_stack_top(tsk) ; i++ )
133 {
134 if ( !i )
135 printk("check_stack(): i = %p\n", i);
136 if ( *i != 0 )
137 {
138 /* only notify if it's less than 900 bytes */
139 if ( (i - (unsigned long *)task_top(tsk)) < 900 )
140 printk("%d bytes free on stack\n",
141 i - task_top(tsk));
142 break;
143 }
144 }
145#endif
146
147 if (ret)
148 {
149 panic("bad kernel stack");
150 }
151 return(ret);
152}
153#endif /* defined(CHECK_STACK) */
154
155#ifdef CONFIG_ALTIVEC
156int
157dump_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs)
158{
159 if (regs->msr & MSR_VEC)
160 giveup_altivec(current);
161 memcpy(vrregs, &current->thread.vr[0], sizeof(*vrregs));
162 return 1;
163}
164
165void
166enable_kernel_altivec(void)
167{
168 WARN_ON(preemptible());
169
170#ifdef CONFIG_SMP
171 if (current->thread.regs && (current->thread.regs->msr & MSR_VEC))
172 giveup_altivec(current);
173 else
174 giveup_altivec(NULL); /* just enable AltiVec for kernel - force */
175#else
176 giveup_altivec(last_task_used_altivec);
177#endif /* __SMP __ */
178}
179EXPORT_SYMBOL(enable_kernel_altivec);
180#endif /* CONFIG_ALTIVEC */
181
182#ifdef CONFIG_SPE
183int
184dump_spe(struct pt_regs *regs, elf_vrregset_t *evrregs)
185{
186 if (regs->msr & MSR_SPE)
187 giveup_spe(current);
188 /* We copy u32 evr[32] + u64 acc + u32 spefscr -> 35 */
189 memcpy(evrregs, &current->thread.evr[0], sizeof(u32) * 35);
190 return 1;
191}
192
193void
194enable_kernel_spe(void)
195{
196 WARN_ON(preemptible());
197
198#ifdef CONFIG_SMP
199 if (current->thread.regs && (current->thread.regs->msr & MSR_SPE))
200 giveup_spe(current);
201 else
202 giveup_spe(NULL); /* just enable SPE for kernel - force */
203#else
204 giveup_spe(last_task_used_spe);
205#endif /* __SMP __ */
206}
207EXPORT_SYMBOL(enable_kernel_spe);
208#endif /* CONFIG_SPE */
209
210void
211enable_kernel_fp(void)
212{
213 WARN_ON(preemptible());
214
215#ifdef CONFIG_SMP
216 if (current->thread.regs && (current->thread.regs->msr & MSR_FP))
217 giveup_fpu(current);
218 else
219 giveup_fpu(NULL); /* just enables FP for kernel */
220#else
221 giveup_fpu(last_task_used_math);
222#endif /* CONFIG_SMP */
223}
224EXPORT_SYMBOL(enable_kernel_fp);
225
226int
227dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
228{
229 preempt_disable();
230 if (tsk->thread.regs && (tsk->thread.regs->msr & MSR_FP))
231 giveup_fpu(tsk);
232 preempt_enable();
233 memcpy(fpregs, &tsk->thread.fpr[0], sizeof(*fpregs));
234 return 1;
235}
236
237struct task_struct *__switch_to(struct task_struct *prev,
238 struct task_struct *new)
239{
240 struct thread_struct *new_thread, *old_thread;
241 unsigned long s;
242 struct task_struct *last;
243
244 local_irq_save(s);
245#ifdef CHECK_STACK
246 check_stack(prev);
247 check_stack(new);
248#endif
249
250#ifdef CONFIG_SMP
251 /* avoid complexity of lazy save/restore of fpu
252 * by just saving it every time we switch out if
253 * this task used the fpu during the last quantum.
254 *
255 * If it tries to use the fpu again, it'll trap and
256 * reload its fp regs. So we don't have to do a restore
257 * every switch, just a save.
258 * -- Cort
259 */
260 if (prev->thread.regs && (prev->thread.regs->msr & MSR_FP))
261 giveup_fpu(prev);
262#ifdef CONFIG_ALTIVEC
263 /*
264 * If the previous thread used altivec in the last quantum
265 * (thus changing altivec regs) then save them.
266 * We used to check the VRSAVE register but not all apps
267 * set it, so we don't rely on it now (and in fact we need
268 * to save & restore VSCR even if VRSAVE == 0). -- paulus
269 *
270 * On SMP we always save/restore altivec regs just to avoid the
271 * complexity of changing processors.
272 * -- Cort
273 */
274 if ((prev->thread.regs && (prev->thread.regs->msr & MSR_VEC)))
275 giveup_altivec(prev);
276#endif /* CONFIG_ALTIVEC */
277#ifdef CONFIG_SPE
278 /*
279 * If the previous thread used spe in the last quantum
280 * (thus changing spe regs) then save them.
281 *
282 * On SMP we always save/restore spe regs just to avoid the
283 * complexity of changing processors.
284 */
285 if ((prev->thread.regs && (prev->thread.regs->msr & MSR_SPE)))
286 giveup_spe(prev);
287#endif /* CONFIG_SPE */
288#endif /* CONFIG_SMP */
289
290 /* Avoid the trap. On smp this this never happens since
291 * we don't set last_task_used_altivec -- Cort
292 */
293 if (new->thread.regs && last_task_used_altivec == new)
294 new->thread.regs->msr |= MSR_VEC;
295#ifdef CONFIG_SPE
296 /* Avoid the trap. On smp this this never happens since
297 * we don't set last_task_used_spe
298 */
299 if (new->thread.regs && last_task_used_spe == new)
300 new->thread.regs->msr |= MSR_SPE;
301#endif /* CONFIG_SPE */
302 new_thread = &new->thread;
303 old_thread = &current->thread;
304 last = _switch(old_thread, new_thread);
305 local_irq_restore(s);
306 return last;
307}
308
309void show_regs(struct pt_regs * regs)
310{
311 int i, trap;
312
313 printk("NIP: %08lX LR: %08lX SP: %08lX REGS: %p TRAP: %04lx %s\n",
314 regs->nip, regs->link, regs->gpr[1], regs, regs->trap,
315 print_tainted());
316 printk("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
317 regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
318 regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
319 regs->msr&MSR_IR ? 1 : 0,
320 regs->msr&MSR_DR ? 1 : 0);
321 trap = TRAP(regs);
322 if (trap == 0x300 || trap == 0x600)
323 printk("DAR: %08lX, DSISR: %08lX\n", regs->dar, regs->dsisr);
324 printk("TASK = %p[%d] '%s' THREAD: %p\n",
325 current, current->pid, current->comm, current->thread_info);
326 printk("Last syscall: %ld ", current->thread.last_syscall);
327
328#ifdef CONFIG_SMP
329 printk(" CPU: %d", smp_processor_id());
330#endif /* CONFIG_SMP */
331
332 for (i = 0; i < 32; i++) {
333 long r;
334 if ((i % 8) == 0)
335 printk("\n" KERN_INFO "GPR%02d: ", i);
336 if (__get_user(r, &regs->gpr[i]))
337 break;
338 printk("%08lX ", r);
339 if (i == 12 && !FULL_REGS(regs))
340 break;
341 }
342 printk("\n");
343#ifdef CONFIG_KALLSYMS
344 /*
345 * Lookup NIP late so we have the best change of getting the
346 * above info out without failing
347 */
348 printk("NIP [%08lx] ", regs->nip);
349 print_symbol("%s\n", regs->nip);
350 printk("LR [%08lx] ", regs->link);
351 print_symbol("%s\n", regs->link);
352#endif
353 show_stack(current, (unsigned long *) regs->gpr[1]);
354}
355
356void exit_thread(void)
357{
358 if (last_task_used_math == current)
359 last_task_used_math = NULL;
360 if (last_task_used_altivec == current)
361 last_task_used_altivec = NULL;
362#ifdef CONFIG_SPE
363 if (last_task_used_spe == current)
364 last_task_used_spe = NULL;
365#endif
366}
367
368void flush_thread(void)
369{
370 if (last_task_used_math == current)
371 last_task_used_math = NULL;
372 if (last_task_used_altivec == current)
373 last_task_used_altivec = NULL;
374#ifdef CONFIG_SPE
375 if (last_task_used_spe == current)
376 last_task_used_spe = NULL;
377#endif
378}
379
380void
381release_thread(struct task_struct *t)
382{
383}
384
385/*
386 * This gets called before we allocate a new thread and copy
387 * the current task into it.
388 */
389void prepare_to_copy(struct task_struct *tsk)
390{
391 struct pt_regs *regs = tsk->thread.regs;
392
393 if (regs == NULL)
394 return;
395 preempt_disable();
396 if (regs->msr & MSR_FP)
397 giveup_fpu(current);
398#ifdef CONFIG_ALTIVEC
399 if (regs->msr & MSR_VEC)
400 giveup_altivec(current);
401#endif /* CONFIG_ALTIVEC */
402#ifdef CONFIG_SPE
403 if (regs->msr & MSR_SPE)
404 giveup_spe(current);
405#endif /* CONFIG_SPE */
406 preempt_enable();
407}
408
409/*
410 * Copy a thread..
411 */
412int
413copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
414 unsigned long unused,
415 struct task_struct *p, struct pt_regs *regs)
416{
417 struct pt_regs *childregs, *kregs;
418 extern void ret_from_fork(void);
419 unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE;
420 unsigned long childframe;
421
422 CHECK_FULL_REGS(regs);
423 /* Copy registers */
424 sp -= sizeof(struct pt_regs);
425 childregs = (struct pt_regs *) sp;
426 *childregs = *regs;
427 if ((childregs->msr & MSR_PR) == 0) {
428 /* for kernel thread, set `current' and stackptr in new task */
429 childregs->gpr[1] = sp + sizeof(struct pt_regs);
430 childregs->gpr[2] = (unsigned long) p;
431 p->thread.regs = NULL; /* no user register state */
432 } else {
433 childregs->gpr[1] = usp;
434 p->thread.regs = childregs;
435 if (clone_flags & CLONE_SETTLS)
436 childregs->gpr[2] = childregs->gpr[6];
437 }
438 childregs->gpr[3] = 0; /* Result from fork() */
439 sp -= STACK_FRAME_OVERHEAD;
440 childframe = sp;
441
442 /*
443 * The way this works is that at some point in the future
444 * some task will call _switch to switch to the new task.
445 * That will pop off the stack frame created below and start
446 * the new task running at ret_from_fork. The new task will
447 * do some house keeping and then return from the fork or clone
448 * system call, using the stack frame created above.
449 */
450 sp -= sizeof(struct pt_regs);
451 kregs = (struct pt_regs *) sp;
452 sp -= STACK_FRAME_OVERHEAD;
453 p->thread.ksp = sp;
454 kregs->nip = (unsigned long)ret_from_fork;
455
456 p->thread.last_syscall = -1;
457
458 return 0;
459}
460
461/*
462 * Set up a thread for executing a new program
463 */
464void start_thread(struct pt_regs *regs, unsigned long nip, unsigned long sp)
465{
466 set_fs(USER_DS);
467 memset(regs->gpr, 0, sizeof(regs->gpr));
468 regs->ctr = 0;
469 regs->link = 0;
470 regs->xer = 0;
471 regs->ccr = 0;
472 regs->mq = 0;
473 regs->nip = nip;
474 regs->gpr[1] = sp;
475 regs->msr = MSR_USER;
476 if (last_task_used_math == current)
477 last_task_used_math = NULL;
478 if (last_task_used_altivec == current)
479 last_task_used_altivec = NULL;
480#ifdef CONFIG_SPE
481 if (last_task_used_spe == current)
482 last_task_used_spe = NULL;
483#endif
484 memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
485 current->thread.fpscr = 0;
486#ifdef CONFIG_ALTIVEC
487 memset(current->thread.vr, 0, sizeof(current->thread.vr));
488 memset(&current->thread.vscr, 0, sizeof(current->thread.vscr));
489 current->thread.vrsave = 0;
490 current->thread.used_vr = 0;
491#endif /* CONFIG_ALTIVEC */
492#ifdef CONFIG_SPE
493 memset(current->thread.evr, 0, sizeof(current->thread.evr));
494 current->thread.acc = 0;
495 current->thread.spefscr = 0;
496 current->thread.used_spe = 0;
497#endif /* CONFIG_SPE */
498}
499
500#define PR_FP_ALL_EXCEPT (PR_FP_EXC_DIV | PR_FP_EXC_OVF | PR_FP_EXC_UND \
501 | PR_FP_EXC_RES | PR_FP_EXC_INV)
502
503int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
504{
505 struct pt_regs *regs = tsk->thread.regs;
506
507 /* This is a bit hairy. If we are an SPE enabled processor
508 * (have embedded fp) we store the IEEE exception enable flags in
509 * fpexc_mode. fpexc_mode is also used for setting FP exception
510 * mode (asyn, precise, disabled) for 'Classic' FP. */
511 if (val & PR_FP_EXC_SW_ENABLE) {
512#ifdef CONFIG_SPE
513 tsk->thread.fpexc_mode = val &
514 (PR_FP_EXC_SW_ENABLE | PR_FP_ALL_EXCEPT);
515#else
516 return -EINVAL;
517#endif
518 } else {
519 /* on a CONFIG_SPE this does not hurt us. The bits that
520 * __pack_fe01 use do not overlap with bits used for
521 * PR_FP_EXC_SW_ENABLE. Additionally, the MSR[FE0,FE1] bits
522 * on CONFIG_SPE implementations are reserved so writing to
523 * them does not change anything */
524 if (val > PR_FP_EXC_PRECISE)
525 return -EINVAL;
526 tsk->thread.fpexc_mode = __pack_fe01(val);
527 if (regs != NULL && (regs->msr & MSR_FP) != 0)
528 regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1))
529 | tsk->thread.fpexc_mode;
530 }
531 return 0;
532}
533
534int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
535{
536 unsigned int val;
537
538 if (tsk->thread.fpexc_mode & PR_FP_EXC_SW_ENABLE)
539#ifdef CONFIG_SPE
540 val = tsk->thread.fpexc_mode;
541#else
542 return -EINVAL;
543#endif
544 else
545 val = __unpack_fe01(tsk->thread.fpexc_mode);
546 return put_user(val, (unsigned int __user *) adr);
547}
548
549int sys_clone(unsigned long clone_flags, unsigned long usp,
550 int __user *parent_tidp, void __user *child_threadptr,
551 int __user *child_tidp, int p6,
552 struct pt_regs *regs)
553{
554 CHECK_FULL_REGS(regs);
555 if (usp == 0)
556 usp = regs->gpr[1]; /* stack pointer for child */
557 return do_fork(clone_flags, usp, regs, 0, parent_tidp, child_tidp);
558}
559
560int sys_fork(int p1, int p2, int p3, int p4, int p5, int p6,
561 struct pt_regs *regs)
562{
563 CHECK_FULL_REGS(regs);
564 return do_fork(SIGCHLD, regs->gpr[1], regs, 0, NULL, NULL);
565}
566
567int sys_vfork(int p1, int p2, int p3, int p4, int p5, int p6,
568 struct pt_regs *regs)
569{
570 CHECK_FULL_REGS(regs);
571 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gpr[1],
572 regs, 0, NULL, NULL);
573}
574
575int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
576 unsigned long a3, unsigned long a4, unsigned long a5,
577 struct pt_regs *regs)
578{
579 int error;
580 char * filename;
581
582 filename = getname((char __user *) a0);
583 error = PTR_ERR(filename);
584 if (IS_ERR(filename))
585 goto out;
586 preempt_disable();
587 if (regs->msr & MSR_FP)
588 giveup_fpu(current);
589#ifdef CONFIG_ALTIVEC
590 if (regs->msr & MSR_VEC)
591 giveup_altivec(current);
592#endif /* CONFIG_ALTIVEC */
593#ifdef CONFIG_SPE
594 if (regs->msr & MSR_SPE)
595 giveup_spe(current);
596#endif /* CONFIG_SPE */
597 preempt_enable();
598 error = do_execve(filename, (char __user *__user *) a1,
599 (char __user *__user *) a2, regs);
600 if (error == 0) {
601 task_lock(current);
602 current->ptrace &= ~PT_DTRACE;
603 task_unlock(current);
604 }
605 putname(filename);
606out:
607 return error;
608}
609
610void dump_stack(void)
611{
612 show_stack(current, NULL);
613}
614
615EXPORT_SYMBOL(dump_stack);
616
617void show_stack(struct task_struct *tsk, unsigned long *stack)
618{
619 unsigned long sp, stack_top, prev_sp, ret;
620 int count = 0;
621 unsigned long next_exc = 0;
622 struct pt_regs *regs;
623 extern char ret_from_except, ret_from_except_full, ret_from_syscall;
624
625 sp = (unsigned long) stack;
626 if (tsk == NULL)
627 tsk = current;
628 if (sp == 0) {
629 if (tsk == current)
630 asm("mr %0,1" : "=r" (sp));
631 else
632 sp = tsk->thread.ksp;
633 }
634
635 prev_sp = (unsigned long) (tsk->thread_info + 1);
636 stack_top = (unsigned long) tsk->thread_info + THREAD_SIZE;
637 while (count < 16 && sp > prev_sp && sp < stack_top && (sp & 3) == 0) {
638 if (count == 0) {
639 printk("Call trace:");
640#ifdef CONFIG_KALLSYMS
641 printk("\n");
642#endif
643 } else {
644 if (next_exc) {
645 ret = next_exc;
646 next_exc = 0;
647 } else
648 ret = *(unsigned long *)(sp + 4);
649 printk(" [%08lx] ", ret);
650#ifdef CONFIG_KALLSYMS
651 print_symbol("%s", ret);
652 printk("\n");
653#endif
654 if (ret == (unsigned long) &ret_from_except
655 || ret == (unsigned long) &ret_from_except_full
656 || ret == (unsigned long) &ret_from_syscall) {
657 /* sp + 16 points to an exception frame */
658 regs = (struct pt_regs *) (sp + 16);
659 if (sp + 16 + sizeof(*regs) <= stack_top)
660 next_exc = regs->nip;
661 }
662 }
663 ++count;
664 sp = *(unsigned long *)sp;
665 }
666#ifndef CONFIG_KALLSYMS
667 if (count > 0)
668 printk("\n");
669#endif
670}
671
672#if 0
673/*
674 * Low level print for debugging - Cort
675 */
676int __init ll_printk(const char *fmt, ...)
677{
678 va_list args;
679 char buf[256];
680 int i;
681
682 va_start(args, fmt);
683 i=vsprintf(buf,fmt,args);
684 ll_puts(buf);
685 va_end(args);
686 return i;
687}
688
689int lines = 24, cols = 80;
690int orig_x = 0, orig_y = 0;
691
692void puthex(unsigned long val)
693{
694 unsigned char buf[10];
695 int i;
696 for (i = 7; i >= 0; i--)
697 {
698 buf[i] = "0123456789ABCDEF"[val & 0x0F];
699 val >>= 4;
700 }
701 buf[8] = '\0';
702 prom_print(buf);
703}
704
705void __init ll_puts(const char *s)
706{
707 int x,y;
708 char *vidmem = (char *)/*(_ISA_MEM_BASE + 0xB8000) */0xD00B8000;
709 char c;
710 extern int mem_init_done;
711
712 if ( mem_init_done ) /* assume this means we can printk */
713 {
714 printk(s);
715 return;
716 }
717
718#if 0
719 if ( have_of )
720 {
721 prom_print(s);
722 return;
723 }
724#endif
725
726 /*
727 * can't ll_puts on chrp without openfirmware yet.
728 * vidmem just needs to be setup for it.
729 * -- Cort
730 */
731 if ( _machine != _MACH_prep )
732 return;
733 x = orig_x;
734 y = orig_y;
735
736 while ( ( c = *s++ ) != '\0' ) {
737 if ( c == '\n' ) {
738 x = 0;
739 if ( ++y >= lines ) {
740 /*scroll();*/
741 /*y--;*/
742 y = 0;
743 }
744 } else {
745 vidmem [ ( x + cols * y ) * 2 ] = c;
746 if ( ++x >= cols ) {
747 x = 0;
748 if ( ++y >= lines ) {
749 /*scroll();*/
750 /*y--;*/
751 y = 0;
752 }
753 }
754 }
755 }
756
757 orig_x = x;
758 orig_y = y;
759}
760#endif
761
762unsigned long get_wchan(struct task_struct *p)
763{
764 unsigned long ip, sp;
765 unsigned long stack_page = (unsigned long) p->thread_info;
766 int count = 0;
767 if (!p || p == current || p->state == TASK_RUNNING)
768 return 0;
769 sp = p->thread.ksp;
770 do {
771 sp = *(unsigned long *)sp;
772 if (sp < stack_page || sp >= stack_page + 8188)
773 return 0;
774 if (count > 0) {
775 ip = *(unsigned long *)(sp + 4);
776 if (!in_sched_functions(ip))
777 return ip;
778 }
779 } while (count++ < 16);
780 return 0;
781}