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>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
31 #include <asm/traps.h>
32 #include <asm/machdep.h>
33 #include <asm/setup.h>
34 #include <asm/pgtable.h>
37 * Initial task/thread structure. Make this a per-architecture thing,
38 * because different architectures tend to have different
39 * alignment requirements and potentially different initial
42 static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
43 static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
44 union thread_union init_thread_union __init_task_data
45 __attribute__((aligned(THREAD_SIZE))) =
46 { INIT_THREAD_INFO(init_task) };
48 /* initial task structure */
49 struct task_struct init_task = INIT_TASK(init_task);
51 EXPORT_SYMBOL(init_task);
53 asmlinkage void ret_from_fork(void);
57 * Return saved PC from a blocked thread
59 unsigned long thread_saved_pc(struct task_struct *tsk)
61 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
62 /* Check whether the thread is blocked in resume() */
63 if (in_sched_functions(sw->retpc))
64 return ((unsigned long *)sw->a6)[1];
70 * The idle loop on an m68k..
72 static void default_idle(void)
75 #if defined(MACH_ATARI_ONLY)
76 /* block out HSYNC on the atari (falcon) */
77 __asm__("stop #0x2200" : : : "cc");
79 __asm__("stop #0x2000" : : : "cc");
83 void (*idle)(void) = default_idle;
86 * The idle thread. There's no useful work to be
87 * done, so just try to conserve power and have a
88 * low exit latency (ie sit in a loop waiting for
89 * somebody to say that they'd like to reschedule)
93 /* endless idle loop with no priority at all */
95 while (!need_resched())
97 preempt_enable_no_resched();
103 void machine_restart(char * __unused)
110 void machine_halt(void)
117 void machine_power_off(void)
124 void (*pm_power_off)(void) = machine_power_off;
125 EXPORT_SYMBOL(pm_power_off);
127 void show_regs(struct pt_regs * regs)
130 printk("Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
131 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
132 printk("ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
133 regs->orig_d0, regs->d0, regs->a2, regs->a1);
134 printk("A0: %08lx D5: %08lx D4: %08lx\n",
135 regs->a0, regs->d5, regs->d4);
136 printk("D3: %08lx D2: %08lx D1: %08lx\n",
137 regs->d3, regs->d2, regs->d1);
138 if (!(regs->sr & PS_S))
139 printk("USP: %08lx\n", rdusp());
143 * Create a kernel thread
145 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
154 register long retval __asm__ ("d0");
155 register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
160 "trap #0\n\t" /* Linux/m68k system call */
161 "tstl %0\n\t" /* child or parent */
162 "jne 1f\n\t" /* parent - jump */
163 "lea %%sp@(%c7),%6\n\t" /* reload current */
165 "movel %3,%%sp@-\n\t" /* push argument */
166 "jsr %4@\n\t" /* call fn */
167 "movel %0,%%d1\n\t" /* pass exit value */
168 "movel %2,%%d0\n\t" /* exit */
172 : "i" (__NR_clone), "i" (__NR_exit),
173 "r" (arg), "a" (fn), "d" (clone_arg), "r" (current),
183 EXPORT_SYMBOL(kernel_thread);
185 void flush_thread(void)
187 unsigned long zero = 0;
190 #ifndef CONFIG_COLDFIRE
191 current->thread.fs = __USER_DS;
193 asm volatile (".chip 68k/68881\n\t"
195 ".chip 68k" : : "a" (&zero));
197 current->thread.fs = USER_DS;
201 asm volatile ("frestore %0@\n\t" : : "a" (&zero));
207 * "m68k_fork()".. By the time we get here, the
208 * non-volatile registers have also been saved on the
209 * stack. We do some ugly pointer stuff here.. (see
213 asmlinkage int m68k_fork(struct pt_regs *regs)
215 return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
218 asmlinkage int m68k_vfork(struct pt_regs *regs)
220 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
224 asmlinkage int m68k_clone(struct pt_regs *regs)
226 unsigned long clone_flags;
228 int __user *parent_tidptr, *child_tidptr;
230 /* syscall2 puts clone_flags in d1 and usp in d2 */
231 clone_flags = regs->d1;
233 parent_tidptr = (int __user *)regs->d3;
234 child_tidptr = (int __user *)regs->d4;
237 return do_fork(clone_flags, newsp, regs, 0,
238 parent_tidptr, child_tidptr);
241 int copy_thread(unsigned long clone_flags, unsigned long usp,
242 unsigned long unused,
243 struct task_struct * p, struct pt_regs * regs)
245 struct pt_regs * childregs;
246 struct switch_stack * childstack, *stack;
249 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
254 retp = ((unsigned long *) regs);
255 stack = ((struct switch_stack *) retp) - 1;
257 childstack = ((struct switch_stack *) childregs) - 1;
258 *childstack = *stack;
259 childstack->retpc = (unsigned long)ret_from_fork;
262 p->thread.ksp = (unsigned long)childstack;
264 if (clone_flags & CLONE_SETTLS)
265 task_thread_info(p)->tp_value = regs->d5;
268 * Must save the current SFC/DFC value, NOT the value when
269 * the parent was last descheduled - RGH 10-08-96
271 #ifndef CONFIG_COLDFIRE
272 p->thread.fs = get_fs().seg;
275 /* Copy the current fpu state */
276 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
278 if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2])
279 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
280 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
281 : : "m" (p->thread.fp[0]), "m" (p->thread.fpcntl[0])
283 /* Restore the state in case the fpu was busy */
284 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
287 p->thread.fs = get_fs();
288 #if defined(CONFIG_FPU)
290 /* Copy the current fpu state */
291 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0])
294 if (p->thread.fpstate[0]) {
295 asm volatile ("fmovemd %/fp0-%/fp7,%0"
296 : : "m" (p->thread.fp[0])
298 asm volatile ("fmovel %/fpiar,%0"
299 : : "m" (p->thread.fpcntl[0])
301 asm volatile ("fmovel %/fpcr,%0"
302 : : "m" (p->thread.fpcntl[1])
304 asm volatile ("fmovel %/fpsr,%0"
305 : : "m" (p->thread.fpcntl[2])
308 /* Restore the state in case the fpu was busy */
309 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
316 /* Fill in the fpu structure for a core dump. */
318 int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
325 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
326 memcpy(fpu->fpregs, current->thread.fp, 96);
327 /* Convert internal fpu reg representation
328 * into long double format
330 for (i = 0; i < 24; i += 3)
331 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
332 ((fpu->fpregs[i] & 0x0000ffff) << 16);
336 /* First dump the fpu context to avoid protocol violation. */
337 #ifndef CONFIG_COLDFIRE
338 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
339 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
342 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
343 :: "m" (fpu->fpcntl[0])
345 asm volatile ("fmovemx %/fp0-%/fp7,%0"
346 :: "m" (fpu->fpregs[0])
350 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
351 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
354 asm volatile ("fmovel %/fpiar,%0"
355 : : "m" (fpu->fpcntl[0])
357 asm volatile ("fmovel %/fpcr,%0"
358 : : "m" (fpu->fpcntl[1])
360 asm volatile ("fmovel %/fpsr,%0"
361 : : "m" (fpu->fpcntl[2])
363 asm volatile ("fmovemd %/fp0-%/fp7,%0"
364 : : "m" (fpu->fpregs[0])
369 EXPORT_SYMBOL(dump_fpu);
372 * sys_execve() executes a new program.
374 asmlinkage int sys_execve(const char __user *name,
375 const char __user *const __user *argv,
376 const char __user *const __user *envp)
380 struct pt_regs *regs = (struct pt_regs *) &name;
382 filename = getname(name);
383 error = PTR_ERR(filename);
384 if (IS_ERR(filename))
386 error = do_execve(filename, argv, envp, regs);
391 unsigned long get_wchan(struct task_struct *p)
393 unsigned long fp, pc;
394 unsigned long stack_page;
396 if (!p || p == current || p->state == TASK_RUNNING)
399 stack_page = (unsigned long)task_stack_page(p);
400 fp = ((struct switch_stack *)p->thread.ksp)->a6;
402 if (fp < stack_page+sizeof(struct thread_info) ||
403 fp >= 8184+stack_page)
405 pc = ((unsigned long *)fp)[1];
406 if (!in_sched_functions(pc))
408 fp = *(unsigned long *) fp;
409 } while (count++ < 16);