2 * linux/arch/m68k/kernel/process.c
4 * Copyright (C) 1995 Hamish Macdonald
6 * 68060 fixes by Jesper Skov
10 * This file handles the architecture-dependent parts of process handling..
13 #include <linux/errno.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
18 #include <linux/slab.h>
20 #include <linux/smp.h>
21 #include <linux/stddef.h>
22 #include <linux/unistd.h>
23 #include <linux/ptrace.h>
24 #include <linux/user.h>
25 #include <linux/reboot.h>
26 #include <linux/init_task.h>
27 #include <linux/mqueue.h>
28 #include <linux/rcupdate.h>
30 #include <asm/uaccess.h>
31 #include <asm/traps.h>
32 #include <asm/machdep.h>
33 #include <asm/setup.h>
34 #include <asm/pgtable.h>
37 asmlinkage void ret_from_fork(void);
38 asmlinkage void ret_from_kernel_thread(void);
42 * Return saved PC from a blocked thread
44 unsigned long thread_saved_pc(struct task_struct *tsk)
46 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
47 /* Check whether the thread is blocked in resume() */
48 if (in_sched_functions(sw->retpc))
49 return ((unsigned long *)sw->a6)[1];
55 * The idle loop on an m68k..
57 static void default_idle(void)
60 #if defined(MACH_ATARI_ONLY)
61 /* block out HSYNC on the atari (falcon) */
62 __asm__("stop #0x2200" : : : "cc");
64 __asm__("stop #0x2000" : : : "cc");
68 void (*idle)(void) = default_idle;
71 * The idle thread. There's no useful work to be
72 * done, so just try to conserve power and have a
73 * low exit latency (ie sit in a loop waiting for
74 * somebody to say that they'd like to reschedule)
78 /* endless idle loop with no priority at all */
81 while (!need_resched())
84 schedule_preempt_disabled();
88 void machine_restart(char * __unused)
95 void machine_halt(void)
102 void machine_power_off(void)
109 void (*pm_power_off)(void) = machine_power_off;
110 EXPORT_SYMBOL(pm_power_off);
112 void show_regs(struct pt_regs * regs)
115 printk("Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
116 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
117 printk("ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
118 regs->orig_d0, regs->d0, regs->a2, regs->a1);
119 printk("A0: %08lx D5: %08lx D4: %08lx\n",
120 regs->a0, regs->d5, regs->d4);
121 printk("D3: %08lx D2: %08lx D1: %08lx\n",
122 regs->d3, regs->d2, regs->d1);
123 if (!(regs->sr & PS_S))
124 printk("USP: %08lx\n", rdusp());
127 void flush_thread(void)
129 current->thread.fs = __USER_DS;
132 unsigned long zero = 0;
133 asm volatile("frestore %0": :"m" (zero));
139 * "m68k_fork()".. By the time we get here, the
140 * non-volatile registers have also been saved on the
141 * stack. We do some ugly pointer stuff here.. (see
145 asmlinkage int m68k_fork(struct pt_regs *regs)
148 return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
154 asmlinkage int m68k_vfork(struct pt_regs *regs)
156 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
160 asmlinkage int m68k_clone(struct pt_regs *regs)
162 unsigned long clone_flags;
164 int __user *parent_tidptr, *child_tidptr;
166 /* syscall2 puts clone_flags in d1 and usp in d2 */
167 clone_flags = regs->d1;
169 parent_tidptr = (int __user *)regs->d3;
170 child_tidptr = (int __user *)regs->d4;
173 return do_fork(clone_flags, newsp, regs, 0,
174 parent_tidptr, child_tidptr);
177 int copy_thread(unsigned long clone_flags, unsigned long usp,
179 struct task_struct * p, struct pt_regs * regs)
181 struct pt_regs * childregs;
182 struct switch_stack *childstack;
184 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
185 childstack = ((struct switch_stack *) childregs) - 1;
188 p->thread.ksp = (unsigned long)childstack;
189 p->thread.esp0 = (unsigned long)childregs;
192 * Must save the current SFC/DFC value, NOT the value when
193 * the parent was last descheduled - RGH 10-08-96
195 p->thread.fs = get_fs().seg;
197 if (unlikely(!regs)) {
199 memset(childstack, 0,
200 sizeof(struct switch_stack) + sizeof(struct pt_regs));
201 childregs->sr = PS_S;
202 childstack->a3 = usp; /* function */
203 childstack->d7 = arg;
204 childstack->retpc = (unsigned long)ret_from_kernel_thread;
211 *childstack = ((struct switch_stack *) regs)[-1];
212 childstack->retpc = (unsigned long)ret_from_fork;
214 if (clone_flags & CLONE_SETTLS)
215 task_thread_info(p)->tp_value = regs->d5;
219 /* Copy the current fpu state */
220 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
222 if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2]) {
223 if (CPU_IS_COLDFIRE) {
224 asm volatile ("fmovemd %/fp0-%/fp7,%0\n\t"
225 "fmovel %/fpiar,%1\n\t"
226 "fmovel %/fpcr,%2\n\t"
229 : "m" (p->thread.fp[0]),
230 "m" (p->thread.fpcntl[0]),
231 "m" (p->thread.fpcntl[1]),
232 "m" (p->thread.fpcntl[2])
235 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
236 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
238 : "m" (p->thread.fp[0]),
239 "m" (p->thread.fpcntl[0])
244 /* Restore the state in case the fpu was busy */
245 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
247 #endif /* CONFIG_FPU */
252 /* Fill in the fpu structure for a core dump. */
254 int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
261 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
262 memcpy(fpu->fpregs, current->thread.fp, 96);
263 /* Convert internal fpu reg representation
264 * into long double format
266 for (i = 0; i < 24; i += 3)
267 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
268 ((fpu->fpregs[i] & 0x0000ffff) << 16);
272 /* First dump the fpu context to avoid protocol violation. */
273 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
274 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
277 if (CPU_IS_COLDFIRE) {
278 asm volatile ("fmovel %/fpiar,%0\n\t"
279 "fmovel %/fpcr,%1\n\t"
280 "fmovel %/fpsr,%2\n\t"
281 "fmovemd %/fp0-%/fp7,%3"
283 : "m" (fpu->fpcntl[0]),
284 "m" (fpu->fpcntl[1]),
285 "m" (fpu->fpcntl[2]),
289 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
291 : "m" (fpu->fpcntl[0])
293 asm volatile ("fmovemx %/fp0-%/fp7,%0"
295 : "m" (fpu->fpregs[0])
301 EXPORT_SYMBOL(dump_fpu);
302 #endif /* CONFIG_FPU */
304 unsigned long get_wchan(struct task_struct *p)
306 unsigned long fp, pc;
307 unsigned long stack_page;
309 if (!p || p == current || p->state == TASK_RUNNING)
312 stack_page = (unsigned long)task_stack_page(p);
313 fp = ((struct switch_stack *)p->thread.ksp)->a6;
315 if (fp < stack_page+sizeof(struct thread_info) ||
316 fp >= 8184+stack_page)
318 pc = ((unsigned long *)fp)[1];
319 if (!in_sched_functions(pc))
321 fp = *(unsigned long *) fp;
322 } while (count++ < 16);