2 * linux/arch/m68knommu/kernel/process.c
4 * Copyright (C) 1995 Hamish Macdonald
6 * 68060 fixes by Jesper Skov
9 * Copyright (C) 2000-2002, David McCullough <davidm@snapgear.com>
13 * This file handles the architecture-dependent parts of process handling..
16 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/stddef.h>
25 #include <linux/unistd.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/user.h>
29 #include <linux/a.out.h>
30 #include <linux/interrupt.h>
31 #include <linux/reboot.h>
33 #include <asm/uaccess.h>
34 #include <asm/system.h>
35 #include <asm/traps.h>
36 #include <asm/machdep.h>
37 #include <asm/setup.h>
38 #include <asm/pgtable.h>
40 asmlinkage void ret_from_fork(void);
44 * The idle loop on an m68knommu..
46 void default_idle(void)
49 while (!need_resched()) {
50 /* This stop will re-enable interrupts */
51 __asm__("stop #0x2000" : : : "cc");
57 void (*idle)(void) = default_idle;
60 * The idle thread. There's no useful work to be
61 * done, so just try to conserve power and have a
62 * low exit latency (ie sit in a loop waiting for
63 * somebody to say that they'd like to reschedule)
67 /* endless idle loop with no priority at all */
70 preempt_enable_no_resched();
76 void machine_restart(char * __unused)
83 void machine_halt(void)
90 void machine_power_off(void)
97 void show_regs(struct pt_regs * regs)
99 printk(KERN_NOTICE "\n");
100 printk(KERN_NOTICE "Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
101 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
102 printk(KERN_NOTICE "ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
103 regs->orig_d0, regs->d0, regs->a2, regs->a1);
104 printk(KERN_NOTICE "A0: %08lx D5: %08lx D4: %08lx\n",
105 regs->a0, regs->d5, regs->d4);
106 printk(KERN_NOTICE "D3: %08lx D2: %08lx D1: %08lx\n",
107 regs->d3, regs->d2, regs->d1);
108 if (!(regs->sr & PS_S))
109 printk(KERN_NOTICE "USP: %08lx\n", rdusp());
113 * Create a kernel thread
115 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
118 long clone_arg = flags | CLONE_VM;
124 __asm__ __volatile__ (
125 "movel %%sp, %%d2\n\t"
129 "cmpl %%sp, %%d2\n\t"
131 "movel %3, %%sp@-\n\t"
143 : "cc", "%d0", "%d1", "%d2");
149 void flush_thread(void)
152 unsigned long zero = 0;
155 current->thread.fs = __USER_DS;
158 asm volatile (".chip 68k/68881\n\t"
160 ".chip 68k" : : "a" (&zero));
165 * "m68k_fork()".. By the time we get here, the
166 * non-volatile registers have also been saved on the
167 * stack. We do some ugly pointer stuff here.. (see
171 asmlinkage int m68k_fork(struct pt_regs *regs)
173 /* fork almost works, enough to trick you into looking elsewhere :-( */
177 asmlinkage int m68k_vfork(struct pt_regs *regs)
179 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
182 asmlinkage int m68k_clone(struct pt_regs *regs)
184 unsigned long clone_flags;
187 /* syscall2 puts clone_flags in d1 and usp in d2 */
188 clone_flags = regs->d1;
192 return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
195 int copy_thread(int nr, unsigned long clone_flags,
196 unsigned long usp, unsigned long topstk,
197 struct task_struct * p, struct pt_regs * regs)
199 struct pt_regs * childregs;
200 struct switch_stack * childstack, *stack;
201 unsigned long stack_offset, *retp;
203 stack_offset = THREAD_SIZE - sizeof(struct pt_regs);
204 childregs = (struct pt_regs *) ((unsigned long) p->thread_info + stack_offset);
209 retp = ((unsigned long *) regs);
210 stack = ((struct switch_stack *) retp) - 1;
212 childstack = ((struct switch_stack *) childregs) - 1;
213 *childstack = *stack;
214 childstack->retpc = (unsigned long)ret_from_fork;
217 p->thread.ksp = (unsigned long)childstack;
219 * Must save the current SFC/DFC value, NOT the value when
220 * the parent was last descheduled - RGH 10-08-96
222 p->thread.fs = get_fs().seg;
226 /* Copy the current fpu state */
227 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
229 if (p->thread.fpstate[0])
230 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
231 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
232 : : "m" (p->thread.fp[0]), "m" (p->thread.fpcntl[0])
234 /* Restore the state in case the fpu was busy */
235 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
242 /* Fill in the fpu structure for a core dump. */
244 int dump_fpu(struct pt_regs *regs, struct user_m68kfp_struct *fpu)
252 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
253 memcpy(fpu->fpregs, current->thread.fp, 96);
254 /* Convert internal fpu reg representation
255 * into long double format
257 for (i = 0; i < 24; i += 3)
258 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
259 ((fpu->fpregs[i] & 0x0000ffff) << 16);
263 /* First dump the fpu context to avoid protocol violation. */
264 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
268 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
269 :: "m" (fpu->fpcntl[0])
271 asm volatile ("fmovemx %/fp0-%/fp7,%0"
272 :: "m" (fpu->fpregs[0])
279 * fill in the user structure for a core dump..
281 void dump_thread(struct pt_regs * regs, struct user * dump)
283 struct switch_stack *sw;
285 /* changed the size calculations - should hopefully work better. lbt */
286 dump->magic = CMAGIC;
287 dump->start_code = 0;
288 dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
289 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
290 dump->u_dsize = ((unsigned long) (current->mm->brk +
291 (PAGE_SIZE-1))) >> PAGE_SHIFT;
292 dump->u_dsize -= dump->u_tsize;
295 if (dump->start_stack < TASK_SIZE)
296 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
298 dump->u_ar0 = (struct user_regs_struct *)((int)&dump->regs - (int)dump);
299 sw = ((struct switch_stack *)regs) - 1;
300 dump->regs.d1 = regs->d1;
301 dump->regs.d2 = regs->d2;
302 dump->regs.d3 = regs->d3;
303 dump->regs.d4 = regs->d4;
304 dump->regs.d5 = regs->d5;
305 dump->regs.d6 = sw->d6;
306 dump->regs.d7 = sw->d7;
307 dump->regs.a0 = regs->a0;
308 dump->regs.a1 = regs->a1;
309 dump->regs.a2 = regs->a2;
310 dump->regs.a3 = sw->a3;
311 dump->regs.a4 = sw->a4;
312 dump->regs.a5 = sw->a5;
313 dump->regs.a6 = sw->a6;
314 dump->regs.d0 = regs->d0;
315 dump->regs.orig_d0 = regs->orig_d0;
316 dump->regs.stkadj = regs->stkadj;
317 dump->regs.sr = regs->sr;
318 dump->regs.pc = regs->pc;
319 dump->regs.fmtvec = (regs->format << 12) | regs->vector;
320 /* dump floating point stuff */
321 dump->u_fpvalid = dump_fpu (regs, &dump->m68kfp);
325 * Generic dumping code. Used for panic and debug.
327 void dump(struct pt_regs *fp)
333 printk(KERN_EMERG "\nCURRENT PROCESS:\n\n");
334 printk(KERN_EMERG "COMM=%s PID=%d\n", current->comm, current->pid);
337 printk(KERN_EMERG "TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
338 (int) current->mm->start_code,
339 (int) current->mm->end_code,
340 (int) current->mm->start_data,
341 (int) current->mm->end_data,
342 (int) current->mm->end_data,
343 (int) current->mm->brk);
344 printk(KERN_EMERG "USER-STACK=%08x KERNEL-STACK=%08x\n\n",
345 (int) current->mm->start_stack,
346 (int)(((unsigned long) current) + THREAD_SIZE));
349 printk(KERN_EMERG "PC: %08lx\n", fp->pc);
350 printk(KERN_EMERG "SR: %08lx SP: %08lx\n", (long) fp->sr, (long) fp);
351 printk(KERN_EMERG "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
352 fp->d0, fp->d1, fp->d2, fp->d3);
353 printk(KERN_EMERG "d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
354 fp->d4, fp->d5, fp->a0, fp->a1);
355 printk(KERN_EMERG "\nUSP: %08x TRAPFRAME: %08x\n", (unsigned int) rdusp(),
358 printk(KERN_EMERG "\nCODE:");
359 tp = ((unsigned char *) fp->pc) - 0x20;
360 for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
362 printk(KERN_EMERG "\n%08x: ", (int) (tp + i));
363 printk(KERN_EMERG "%08x ", (int) *sp++);
365 printk(KERN_EMERG "\n");
367 printk(KERN_EMERG "\nKERNEL STACK:");
368 tp = ((unsigned char *) fp) - 0x40;
369 for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
371 printk(KERN_EMERG "\n%08x: ", (int) (tp + i));
372 printk(KERN_EMERG "%08x ", (int) *sp++);
374 printk(KERN_EMERG "\n");
375 printk(KERN_EMERG "\n");
377 printk(KERN_EMERG "\nUSER STACK:");
378 tp = (unsigned char *) (rdusp() - 0x10);
379 for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
381 printk(KERN_EMERG "\n%08x: ", (int) (tp + i));
382 printk(KERN_EMERG "%08x ", (int) *sp++);
384 printk(KERN_EMERG "\n\n");
388 * sys_execve() executes a new program.
390 asmlinkage int sys_execve(char *name, char **argv, char **envp)
394 struct pt_regs *regs = (struct pt_regs *) &name;
397 filename = getname(name);
398 error = PTR_ERR(filename);
399 if (IS_ERR(filename))
401 error = do_execve(filename, argv, envp, regs);
408 unsigned long get_wchan(struct task_struct *p)
410 unsigned long fp, pc;
411 unsigned long stack_page;
413 if (!p || p == current || p->state == TASK_RUNNING)
416 stack_page = (unsigned long)p;
417 fp = ((struct switch_stack *)p->thread.ksp)->a6;
419 if (fp < stack_page+sizeof(struct thread_info) ||
420 fp >= 8184+stack_page)
422 pc = ((unsigned long *)fp)[1];
423 if (!in_sched_functions(pc))
425 fp = *(unsigned long *) fp;
426 } while (count++ < 16);
431 * Return saved PC of a blocked thread.
433 unsigned long thread_saved_pc(struct task_struct *tsk)
435 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
437 /* Check whether the thread is blocked in resume() */
438 if (in_sched_functions(sw->retpc))
439 return ((unsigned long *)sw->a6)[1];