xen: cleancache shim to Xen Transcendent Memory
[linux-2.6/next.git] / arch / m68k / kernel / process_mm.c
blobc2a1fc23dd758e69a49bb45d6e62247f4adf68ce
1 /*
2 * linux/arch/m68k/kernel/process.c
4 * Copyright (C) 1995 Hamish Macdonald
6 * 68060 fixes by Jesper Skov
7 */
9 /*
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>
17 #include <linux/mm.h>
18 #include <linux/slab.h>
19 #include <linux/fs.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
40 * setup.
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];
65 else
66 return sw->retpc;
70 * The idle loop on an m68k..
72 static void default_idle(void)
74 if (!need_resched())
75 #if defined(MACH_ATARI_ONLY)
76 /* block out HSYNC on the atari (falcon) */
77 __asm__("stop #0x2200" : : : "cc");
78 #else
79 __asm__("stop #0x2000" : : : "cc");
80 #endif
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)
91 void cpu_idle(void)
93 /* endless idle loop with no priority at all */
94 while (1) {
95 while (!need_resched())
96 idle();
97 preempt_enable_no_resched();
98 schedule();
99 preempt_disable();
103 void machine_restart(char * __unused)
105 if (mach_reset)
106 mach_reset();
107 for (;;);
110 void machine_halt(void)
112 if (mach_halt)
113 mach_halt();
114 for (;;);
117 void machine_power_off(void)
119 if (mach_power_off)
120 mach_power_off();
121 for (;;);
124 void (*pm_power_off)(void) = machine_power_off;
125 EXPORT_SYMBOL(pm_power_off);
127 void show_regs(struct pt_regs * regs)
129 printk("\n");
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)
147 int pid;
148 mm_segment_t fs;
150 fs = get_fs();
151 set_fs (KERNEL_DS);
154 register long retval __asm__ ("d0");
155 register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
157 retval = __NR_clone;
158 __asm__ __volatile__
159 ("clrl %%d2\n\t"
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 */
164 "movel %6@,%6\n\t"
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 */
169 "trap #0\n"
170 "1:"
171 : "+d" (retval)
172 : "i" (__NR_clone), "i" (__NR_exit),
173 "r" (arg), "a" (fn), "d" (clone_arg), "r" (current),
174 "i" (-THREAD_SIZE)
175 : "d2");
177 pid = retval;
180 set_fs (fs);
181 return pid;
183 EXPORT_SYMBOL(kernel_thread);
185 void flush_thread(void)
187 unsigned long zero = 0;
188 set_fs(USER_DS);
189 current->thread.fs = __USER_DS;
190 if (!FPU_IS_EMU)
191 asm volatile (".chip 68k/68881\n\t"
192 "frestore %0@\n\t"
193 ".chip 68k" : : "a" (&zero));
197 * "m68k_fork()".. By the time we get here, the
198 * non-volatile registers have also been saved on the
199 * stack. We do some ugly pointer stuff here.. (see
200 * also copy_thread)
203 asmlinkage int m68k_fork(struct pt_regs *regs)
205 return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
208 asmlinkage int m68k_vfork(struct pt_regs *regs)
210 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
211 NULL, NULL);
214 asmlinkage int m68k_clone(struct pt_regs *regs)
216 unsigned long clone_flags;
217 unsigned long newsp;
218 int __user *parent_tidptr, *child_tidptr;
220 /* syscall2 puts clone_flags in d1 and usp in d2 */
221 clone_flags = regs->d1;
222 newsp = regs->d2;
223 parent_tidptr = (int __user *)regs->d3;
224 child_tidptr = (int __user *)regs->d4;
225 if (!newsp)
226 newsp = rdusp();
227 return do_fork(clone_flags, newsp, regs, 0,
228 parent_tidptr, child_tidptr);
231 int copy_thread(unsigned long clone_flags, unsigned long usp,
232 unsigned long unused,
233 struct task_struct * p, struct pt_regs * regs)
235 struct pt_regs * childregs;
236 struct switch_stack * childstack, *stack;
237 unsigned long *retp;
239 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
241 *childregs = *regs;
242 childregs->d0 = 0;
244 retp = ((unsigned long *) regs);
245 stack = ((struct switch_stack *) retp) - 1;
247 childstack = ((struct switch_stack *) childregs) - 1;
248 *childstack = *stack;
249 childstack->retpc = (unsigned long)ret_from_fork;
251 p->thread.usp = usp;
252 p->thread.ksp = (unsigned long)childstack;
254 if (clone_flags & CLONE_SETTLS)
255 task_thread_info(p)->tp_value = regs->d5;
258 * Must save the current SFC/DFC value, NOT the value when
259 * the parent was last descheduled - RGH 10-08-96
261 p->thread.fs = get_fs().seg;
263 if (!FPU_IS_EMU) {
264 /* Copy the current fpu state */
265 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
267 if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2])
268 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
269 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
270 : : "m" (p->thread.fp[0]), "m" (p->thread.fpcntl[0])
271 : "memory");
272 /* Restore the state in case the fpu was busy */
273 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
276 return 0;
279 /* Fill in the fpu structure for a core dump. */
281 int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
283 char fpustate[216];
285 if (FPU_IS_EMU) {
286 int i;
288 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
289 memcpy(fpu->fpregs, current->thread.fp, 96);
290 /* Convert internal fpu reg representation
291 * into long double format
293 for (i = 0; i < 24; i += 3)
294 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
295 ((fpu->fpregs[i] & 0x0000ffff) << 16);
296 return 1;
299 /* First dump the fpu context to avoid protocol violation. */
300 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
301 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
302 return 0;
304 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
305 :: "m" (fpu->fpcntl[0])
306 : "memory");
307 asm volatile ("fmovemx %/fp0-%/fp7,%0"
308 :: "m" (fpu->fpregs[0])
309 : "memory");
310 return 1;
312 EXPORT_SYMBOL(dump_fpu);
315 * sys_execve() executes a new program.
317 asmlinkage int sys_execve(const char __user *name,
318 const char __user *const __user *argv,
319 const char __user *const __user *envp)
321 int error;
322 char * filename;
323 struct pt_regs *regs = (struct pt_regs *) &name;
325 filename = getname(name);
326 error = PTR_ERR(filename);
327 if (IS_ERR(filename))
328 return error;
329 error = do_execve(filename, argv, envp, regs);
330 putname(filename);
331 return error;
334 unsigned long get_wchan(struct task_struct *p)
336 unsigned long fp, pc;
337 unsigned long stack_page;
338 int count = 0;
339 if (!p || p == current || p->state == TASK_RUNNING)
340 return 0;
342 stack_page = (unsigned long)task_stack_page(p);
343 fp = ((struct switch_stack *)p->thread.ksp)->a6;
344 do {
345 if (fp < stack_page+sizeof(struct thread_info) ||
346 fp >= 8184+stack_page)
347 return 0;
348 pc = ((unsigned long *)fp)[1];
349 if (!in_sched_functions(pc))
350 return pc;
351 fp = *(unsigned long *) fp;
352 } while (count++ < 16);
353 return 0;