spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / arch / m68k / kernel / process_no.c
blob5e1078cabe0e54bf10d4537aa86eaa11c8b0e8a5
1 /*
2 * linux/arch/m68knommu/kernel/process.c
4 * Copyright (C) 1995 Hamish Macdonald
6 * 68060 fixes by Jesper Skov
8 * uClinux changes
9 * Copyright (C) 2000-2002, David McCullough <davidm@snapgear.com>
13 * This file handles the architecture-dependent parts of process handling..
16 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/mm.h>
21 #include <linux/smp.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/user.h>
26 #include <linux/interrupt.h>
27 #include <linux/reboot.h>
28 #include <linux/fs.h>
29 #include <linux/slab.h>
31 #include <asm/uaccess.h>
32 #include <asm/system.h>
33 #include <asm/traps.h>
34 #include <asm/machdep.h>
35 #include <asm/setup.h>
36 #include <asm/pgtable.h>
38 asmlinkage void ret_from_fork(void);
41 * The following aren't currently used.
43 void (*pm_idle)(void);
44 EXPORT_SYMBOL(pm_idle);
46 void (*pm_power_off)(void);
47 EXPORT_SYMBOL(pm_power_off);
50 * The idle loop on an m68knommu..
52 static void default_idle(void)
54 local_irq_disable();
55 while (!need_resched()) {
56 /* This stop will re-enable interrupts */
57 __asm__("stop #0x2000" : : : "cc");
58 local_irq_disable();
60 local_irq_enable();
63 void (*idle)(void) = default_idle;
66 * The idle thread. There's no useful work to be
67 * done, so just try to conserve power and have a
68 * low exit latency (ie sit in a loop waiting for
69 * somebody to say that they'd like to reschedule)
71 void cpu_idle(void)
73 /* endless idle loop with no priority at all */
74 while (1) {
75 idle();
76 preempt_enable_no_resched();
77 schedule();
78 preempt_disable();
82 void machine_restart(char * __unused)
84 if (mach_reset)
85 mach_reset();
86 for (;;);
89 void machine_halt(void)
91 if (mach_halt)
92 mach_halt();
93 for (;;);
96 void machine_power_off(void)
98 if (mach_power_off)
99 mach_power_off();
100 for (;;);
103 void show_regs(struct pt_regs * regs)
105 printk(KERN_NOTICE "\n");
106 printk(KERN_NOTICE "Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
107 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
108 printk(KERN_NOTICE "ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
109 regs->orig_d0, regs->d0, regs->a2, regs->a1);
110 printk(KERN_NOTICE "A0: %08lx D5: %08lx D4: %08lx\n",
111 regs->a0, regs->d5, regs->d4);
112 printk(KERN_NOTICE "D3: %08lx D2: %08lx D1: %08lx\n",
113 regs->d3, regs->d2, regs->d1);
114 if (!(regs->sr & PS_S))
115 printk(KERN_NOTICE "USP: %08lx\n", rdusp());
119 * Create a kernel thread
121 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
123 int retval;
124 long clone_arg = flags | CLONE_VM;
125 mm_segment_t fs;
127 fs = get_fs();
128 set_fs(KERNEL_DS);
130 __asm__ __volatile__ (
131 "movel %%sp, %%d2\n\t"
132 "movel %5, %%d1\n\t"
133 "movel %1, %%d0\n\t"
134 "trap #0\n\t"
135 "cmpl %%sp, %%d2\n\t"
136 "jeq 1f\n\t"
137 "movel %3, %%sp@-\n\t"
138 "jsr %4@\n\t"
139 "movel %2, %%d0\n\t"
140 "trap #0\n"
141 "1:\n\t"
142 "movel %%d0, %0\n"
143 : "=d" (retval)
144 : "i" (__NR_clone),
145 "i" (__NR_exit),
146 "a" (arg),
147 "a" (fn),
148 "a" (clone_arg)
149 : "cc", "%d0", "%d1", "%d2");
151 set_fs(fs);
152 return retval;
154 EXPORT_SYMBOL(kernel_thread);
156 void flush_thread(void)
158 #ifdef CONFIG_FPU
159 unsigned long zero = 0;
160 #endif
162 current->thread.fs = __USER_DS;
163 #ifdef CONFIG_FPU
164 if (!FPU_IS_EMU)
165 asm volatile (".chip 68k/68881\n\t"
166 "frestore %0\n\t"
167 ".chip 68k" : : "m" (zero));
168 #endif
172 * "m68k_fork()".. By the time we get here, the
173 * non-volatile registers have also been saved on the
174 * stack. We do some ugly pointer stuff here.. (see
175 * also copy_thread)
178 asmlinkage int m68k_fork(struct pt_regs *regs)
180 /* fork almost works, enough to trick you into looking elsewhere :-( */
181 return(-EINVAL);
184 asmlinkage int m68k_vfork(struct pt_regs *regs)
186 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
189 asmlinkage int m68k_clone(struct pt_regs *regs)
191 unsigned long clone_flags;
192 unsigned long newsp;
194 /* syscall2 puts clone_flags in d1 and usp in d2 */
195 clone_flags = regs->d1;
196 newsp = regs->d2;
197 if (!newsp)
198 newsp = rdusp();
199 return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
202 int copy_thread(unsigned long clone_flags,
203 unsigned long usp, unsigned long topstk,
204 struct task_struct * p, struct pt_regs * regs)
206 struct pt_regs * childregs;
207 struct switch_stack * childstack, *stack;
208 unsigned long *retp;
210 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
212 *childregs = *regs;
213 childregs->d0 = 0;
215 retp = ((unsigned long *) regs);
216 stack = ((struct switch_stack *) retp) - 1;
218 childstack = ((struct switch_stack *) childregs) - 1;
219 *childstack = *stack;
220 childstack->retpc = (unsigned long)ret_from_fork;
222 p->thread.usp = usp;
223 p->thread.ksp = (unsigned long)childstack;
225 if (clone_flags & CLONE_SETTLS)
226 task_thread_info(p)->tp_value = regs->d5;
229 * Must save the current SFC/DFC value, NOT the value when
230 * the parent was last descheduled - RGH 10-08-96
232 p->thread.fs = get_fs().seg;
234 #ifdef CONFIG_FPU
235 if (!FPU_IS_EMU) {
236 /* Copy the current fpu state */
237 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
239 if (p->thread.fpstate[0])
240 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
241 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
242 : : "m" (p->thread.fp[0]), "m" (p->thread.fpcntl[0])
243 : "memory");
244 /* Restore the state in case the fpu was busy */
245 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
247 #endif
249 return 0;
252 /* Fill in the fpu structure for a core dump. */
254 int dump_fpu(struct pt_regs *regs, struct user_m68kfp_struct *fpu)
256 #ifdef CONFIG_FPU
257 char fpustate[216];
259 if (FPU_IS_EMU) {
260 int i;
262 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
263 memcpy(fpu->fpregs, current->thread.fp, 96);
264 /* Convert internal fpu reg representation
265 * into long double format
267 for (i = 0; i < 24; i += 3)
268 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
269 ((fpu->fpregs[i] & 0x0000ffff) << 16);
270 return 1;
273 /* First dump the fpu context to avoid protocol violation. */
274 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
275 if (!fpustate[0])
276 return 0;
278 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
279 :: "m" (fpu->fpcntl[0])
280 : "memory");
281 asm volatile ("fmovemx %/fp0-%/fp7,%0"
282 :: "m" (fpu->fpregs[0])
283 : "memory");
284 #endif
285 return 1;
287 EXPORT_SYMBOL(dump_fpu);
290 * Generic dumping code. Used for panic and debug.
292 void dump(struct pt_regs *fp)
294 unsigned long *sp;
295 unsigned char *tp;
296 int i;
298 printk(KERN_EMERG "\nCURRENT PROCESS:\n\n");
299 printk(KERN_EMERG "COMM=%s PID=%d\n", current->comm, current->pid);
301 if (current->mm) {
302 printk(KERN_EMERG "TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
303 (int) current->mm->start_code,
304 (int) current->mm->end_code,
305 (int) current->mm->start_data,
306 (int) current->mm->end_data,
307 (int) current->mm->end_data,
308 (int) current->mm->brk);
309 printk(KERN_EMERG "USER-STACK=%08x KERNEL-STACK=%08x\n\n",
310 (int) current->mm->start_stack,
311 (int)(((unsigned long) current) + THREAD_SIZE));
314 printk(KERN_EMERG "PC: %08lx\n", fp->pc);
315 printk(KERN_EMERG "SR: %08lx SP: %08lx\n", (long) fp->sr, (long) fp);
316 printk(KERN_EMERG "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
317 fp->d0, fp->d1, fp->d2, fp->d3);
318 printk(KERN_EMERG "d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
319 fp->d4, fp->d5, fp->a0, fp->a1);
320 printk(KERN_EMERG "\nUSP: %08x TRAPFRAME: %p\n",
321 (unsigned int) rdusp(), fp);
323 printk(KERN_EMERG "\nCODE:");
324 tp = ((unsigned char *) fp->pc) - 0x20;
325 for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
326 if ((i % 0x10) == 0)
327 printk(KERN_EMERG "%p: ", tp + i);
328 printk("%08x ", (int) *sp++);
330 printk(KERN_EMERG "\n");
332 printk(KERN_EMERG "KERNEL STACK:");
333 tp = ((unsigned char *) fp) - 0x40;
334 for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
335 if ((i % 0x10) == 0)
336 printk(KERN_EMERG "%p: ", tp + i);
337 printk("%08x ", (int) *sp++);
339 printk(KERN_EMERG "\n");
341 printk(KERN_EMERG "USER STACK:");
342 tp = (unsigned char *) (rdusp() - 0x10);
343 for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
344 if ((i % 0x10) == 0)
345 printk(KERN_EMERG "%p: ", tp + i);
346 printk("%08x ", (int) *sp++);
348 printk(KERN_EMERG "\n");
352 * sys_execve() executes a new program.
354 asmlinkage int sys_execve(const char *name,
355 const char *const *argv,
356 const char *const *envp)
358 int error;
359 char * filename;
360 struct pt_regs *regs = (struct pt_regs *) &name;
362 filename = getname(name);
363 error = PTR_ERR(filename);
364 if (IS_ERR(filename))
365 return error;
366 error = do_execve(filename, argv, envp, regs);
367 putname(filename);
368 return error;
371 unsigned long get_wchan(struct task_struct *p)
373 unsigned long fp, pc;
374 unsigned long stack_page;
375 int count = 0;
376 if (!p || p == current || p->state == TASK_RUNNING)
377 return 0;
379 stack_page = (unsigned long)p;
380 fp = ((struct switch_stack *)p->thread.ksp)->a6;
381 do {
382 if (fp < stack_page+sizeof(struct thread_info) ||
383 fp >= THREAD_SIZE-8+stack_page)
384 return 0;
385 pc = ((unsigned long *)fp)[1];
386 if (!in_sched_functions(pc))
387 return pc;
388 fp = *(unsigned long *) fp;
389 } while (count++ < 16);
390 return 0;
394 * Return saved PC of a blocked thread.
396 unsigned long thread_saved_pc(struct task_struct *tsk)
398 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
400 /* Check whether the thread is blocked in resume() */
401 if (in_sched_functions(sw->retpc))
402 return ((unsigned long *)sw->a6)[1];
403 else
404 return sw->retpc;