aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Ungerer <gerg@uclinux.org>2012-02-08 23:18:46 -0500
committerGreg Ungerer <gerg@uclinux.org>2012-03-04 18:43:05 -0500
commitfde3944141c70b264aace92334b297a05233e179 (patch)
tree67beaef85f76516b07d13ccefeec4d4e10114743
parent9657a87205a367bddd802cbf439531697597fd8b (diff)
m68k: merge the MMU and non-MMU versions of process.c
The MMU and non-MMU varients of the m68k arch process.c code are pretty much the same. Only a few minor details differ between the two. The majority of the difference is to deal with having or wanting hardware FPU support. So merge them back into a single process.c file. Signed-off-by: Greg Ungerer <gerg@uclinux.org> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
-rw-r--r--arch/m68k/kernel/process.c379
-rw-r--r--arch/m68k/kernel/process_mm.c369
-rw-r--r--arch/m68k/kernel/process_no.c406
3 files changed, 377 insertions, 777 deletions
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 6cf4bd6e34f8..f053e245bd40 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -1,5 +1,380 @@
1/*
2 * linux/arch/m68k/kernel/process.c
3 *
4 * Copyright (C) 1995 Hamish Macdonald
5 *
6 * 68060 fixes by Jesper Skov
7 */
8
9/*
10 * This file handles the architecture-dependent parts of process handling..
11 */
12
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>
28
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>
35
36
37asmlinkage void ret_from_fork(void);
38
39
40/*
41 * Return saved PC from a blocked thread
42 */
43unsigned long thread_saved_pc(struct task_struct *tsk)
44{
45 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
46 /* Check whether the thread is blocked in resume() */
47 if (in_sched_functions(sw->retpc))
48 return ((unsigned long *)sw->a6)[1];
49 else
50 return sw->retpc;
51}
52
53/*
54 * The idle loop on an m68k..
55 */
56static void default_idle(void)
57{
58 if (!need_resched())
59#if defined(MACH_ATARI_ONLY)
60 /* block out HSYNC on the atari (falcon) */
61 __asm__("stop #0x2200" : : : "cc");
62#else
63 __asm__("stop #0x2000" : : : "cc");
64#endif
65}
66
67void (*idle)(void) = default_idle;
68
69/*
70 * The idle thread. There's no useful work to be
71 * done, so just try to conserve power and have a
72 * low exit latency (ie sit in a loop waiting for
73 * somebody to say that they'd like to reschedule)
74 */
75void cpu_idle(void)
76{
77 /* endless idle loop with no priority at all */
78 while (1) {
79 while (!need_resched())
80 idle();
81 preempt_enable_no_resched();
82 schedule();
83 preempt_disable();
84 }
85}
86
87void machine_restart(char * __unused)
88{
89 if (mach_reset)
90 mach_reset();
91 for (;;);
92}
93
94void machine_halt(void)
95{
96 if (mach_halt)
97 mach_halt();
98 for (;;);
99}
100
101void machine_power_off(void)
102{
103 if (mach_power_off)
104 mach_power_off();
105 for (;;);
106}
107
108void (*pm_power_off)(void) = machine_power_off;
109EXPORT_SYMBOL(pm_power_off);
110
111void show_regs(struct pt_regs * regs)
112{
113 printk("\n");
114 printk("Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
115 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
116 printk("ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
117 regs->orig_d0, regs->d0, regs->a2, regs->a1);
118 printk("A0: %08lx D5: %08lx D4: %08lx\n",
119 regs->a0, regs->d5, regs->d4);
120 printk("D3: %08lx D2: %08lx D1: %08lx\n",
121 regs->d3, regs->d2, regs->d1);
122 if (!(regs->sr & PS_S))
123 printk("USP: %08lx\n", rdusp());
124}
125
126/*
127 * Create a kernel thread
128 */
129int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
130{
131 int pid;
132 mm_segment_t fs;
133
134 fs = get_fs();
135 set_fs (KERNEL_DS);
136
137 {
138 register long retval __asm__ ("d0");
139 register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
140
141 retval = __NR_clone;
142 __asm__ __volatile__
143 ("clrl %%d2\n\t"
144 "trap #0\n\t" /* Linux/m68k system call */
145 "tstl %0\n\t" /* child or parent */
146 "jne 1f\n\t" /* parent - jump */
147#ifdef CONFIG_MMU
148 "lea %%sp@(%c7),%6\n\t" /* reload current */
149 "movel %6@,%6\n\t"
150#endif
151 "movel %3,%%sp@-\n\t" /* push argument */
152 "jsr %4@\n\t" /* call fn */
153 "movel %0,%%d1\n\t" /* pass exit value */
154 "movel %2,%%d0\n\t" /* exit */
155 "trap #0\n"
156 "1:"
157 : "+d" (retval)
158 : "i" (__NR_clone), "i" (__NR_exit),
159 "r" (arg), "a" (fn), "d" (clone_arg), "r" (current),
160 "i" (-THREAD_SIZE)
161 : "d2");
162
163 pid = retval;
164 }
165
166 set_fs (fs);
167 return pid;
168}
169EXPORT_SYMBOL(kernel_thread);
170
171void flush_thread(void)
172{
173 current->thread.fs = __USER_DS;
174#ifdef CONFIG_FPU
175 if (!FPU_IS_EMU) {
176 unsigned long zero = 0;
177 asm volatile("frestore %0": :"m" (zero));
178 }
179#endif
180}
181
182/*
183 * "m68k_fork()".. By the time we get here, the
184 * non-volatile registers have also been saved on the
185 * stack. We do some ugly pointer stuff here.. (see
186 * also copy_thread)
187 */
188
189asmlinkage int m68k_fork(struct pt_regs *regs)
190{
1#ifdef CONFIG_MMU 191#ifdef CONFIG_MMU
2#include "process_mm.c" 192 return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
3#else 193#else
4#include "process_no.c" 194 return -EINVAL;
5#endif 195#endif
196}
197
198asmlinkage int m68k_vfork(struct pt_regs *regs)
199{
200 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
201 NULL, NULL);
202}
203
204asmlinkage int m68k_clone(struct pt_regs *regs)
205{
206 unsigned long clone_flags;
207 unsigned long newsp;
208 int __user *parent_tidptr, *child_tidptr;
209
210 /* syscall2 puts clone_flags in d1 and usp in d2 */
211 clone_flags = regs->d1;
212 newsp = regs->d2;
213 parent_tidptr = (int __user *)regs->d3;
214 child_tidptr = (int __user *)regs->d4;
215 if (!newsp)
216 newsp = rdusp();
217 return do_fork(clone_flags, newsp, regs, 0,
218 parent_tidptr, child_tidptr);
219}
220
221int copy_thread(unsigned long clone_flags, unsigned long usp,
222 unsigned long unused,
223 struct task_struct * p, struct pt_regs * regs)
224{
225 struct pt_regs * childregs;
226 struct switch_stack * childstack, *stack;
227 unsigned long *retp;
228
229 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
230
231 *childregs = *regs;
232 childregs->d0 = 0;
233
234 retp = ((unsigned long *) regs);
235 stack = ((struct switch_stack *) retp) - 1;
236
237 childstack = ((struct switch_stack *) childregs) - 1;
238 *childstack = *stack;
239 childstack->retpc = (unsigned long)ret_from_fork;
240
241 p->thread.usp = usp;
242 p->thread.ksp = (unsigned long)childstack;
243
244 if (clone_flags & CLONE_SETTLS)
245 task_thread_info(p)->tp_value = regs->d5;
246
247 /*
248 * Must save the current SFC/DFC value, NOT the value when
249 * the parent was last descheduled - RGH 10-08-96
250 */
251 p->thread.fs = get_fs().seg;
252
253#ifdef CONFIG_FPU
254 if (!FPU_IS_EMU) {
255 /* Copy the current fpu state */
256 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
257
258 if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2]) {
259 if (CPU_IS_COLDFIRE) {
260 asm volatile ("fmovemd %/fp0-%/fp7,%0\n\t"
261 "fmovel %/fpiar,%1\n\t"
262 "fmovel %/fpcr,%2\n\t"
263 "fmovel %/fpsr,%3"
264 :
265 : "m" (p->thread.fp[0]),
266 "m" (p->thread.fpcntl[0]),
267 "m" (p->thread.fpcntl[1]),
268 "m" (p->thread.fpcntl[2])
269 : "memory");
270 } else {
271 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
272 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
273 :
274 : "m" (p->thread.fp[0]),
275 "m" (p->thread.fpcntl[0])
276 : "memory");
277 }
278 }
279
280 /* Restore the state in case the fpu was busy */
281 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
282 }
283#endif /* CONFIG_FPU */
284
285 return 0;
286}
287
288/* Fill in the fpu structure for a core dump. */
289#ifdef CONFIG_FPU
290int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
291{
292 char fpustate[216];
293
294 if (FPU_IS_EMU) {
295 int i;
296
297 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
298 memcpy(fpu->fpregs, current->thread.fp, 96);
299 /* Convert internal fpu reg representation
300 * into long double format
301 */
302 for (i = 0; i < 24; i += 3)
303 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
304 ((fpu->fpregs[i] & 0x0000ffff) << 16);
305 return 1;
306 }
307
308 /* First dump the fpu context to avoid protocol violation. */
309 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
310 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
311 return 0;
312
313 if (CPU_IS_COLDFIRE) {
314 asm volatile ("fmovel %/fpiar,%0\n\t"
315 "fmovel %/fpcr,%1\n\t"
316 "fmovel %/fpsr,%2\n\t"
317 "fmovemd %/fp0-%/fp7,%3"
318 :
319 : "m" (fpu->fpcntl[0]),
320 "m" (fpu->fpcntl[1]),
321 "m" (fpu->fpcntl[2]),
322 "m" (fpu->fpregs[0])
323 : "memory");
324 } else {
325 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
326 :
327 : "m" (fpu->fpcntl[0])
328 : "memory");
329 asm volatile ("fmovemx %/fp0-%/fp7,%0"
330 :
331 : "m" (fpu->fpregs[0])
332 : "memory");
333 }
334
335 return 1;
336}
337EXPORT_SYMBOL(dump_fpu);
338#endif /* CONFIG_FPU */
339
340/*
341 * sys_execve() executes a new program.
342 */
343asmlinkage int sys_execve(const char __user *name,
344 const char __user *const __user *argv,
345 const char __user *const __user *envp)
346{
347 int error;
348 char * filename;
349 struct pt_regs *regs = (struct pt_regs *) &name;
350
351 filename = getname(name);
352 error = PTR_ERR(filename);
353 if (IS_ERR(filename))
354 return error;
355 error = do_execve(filename, argv, envp, regs);
356 putname(filename);
357 return error;
358}
359
360unsigned long get_wchan(struct task_struct *p)
361{
362 unsigned long fp, pc;
363 unsigned long stack_page;
364 int count = 0;
365 if (!p || p == current || p->state == TASK_RUNNING)
366 return 0;
367
368 stack_page = (unsigned long)task_stack_page(p);
369 fp = ((struct switch_stack *)p->thread.ksp)->a6;
370 do {
371 if (fp < stack_page+sizeof(struct thread_info) ||
372 fp >= 8184+stack_page)
373 return 0;
374 pc = ((unsigned long *)fp)[1];
375 if (!in_sched_functions(pc))
376 return pc;
377 fp = *(unsigned long *) fp;
378 } while (count++ < 16);
379 return 0;
380}
diff --git a/arch/m68k/kernel/process_mm.c b/arch/m68k/kernel/process_mm.c
deleted file mode 100644
index 099283ee1a8f..000000000000
--- a/arch/m68k/kernel/process_mm.c
+++ /dev/null
@@ -1,369 +0,0 @@
1/*
2 * linux/arch/m68k/kernel/process.c
3 *
4 * Copyright (C) 1995 Hamish Macdonald
5 *
6 * 68060 fixes by Jesper Skov
7 */
8
9/*
10 * This file handles the architecture-dependent parts of process handling..
11 */
12
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>
28
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>
35
36
37asmlinkage void ret_from_fork(void);
38
39
40/*
41 * Return saved PC from a blocked thread
42 */
43unsigned long thread_saved_pc(struct task_struct *tsk)
44{
45 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
46 /* Check whether the thread is blocked in resume() */
47 if (in_sched_functions(sw->retpc))
48 return ((unsigned long *)sw->a6)[1];
49 else
50 return sw->retpc;
51}
52
53/*
54 * The idle loop on an m68k..
55 */
56static void default_idle(void)
57{
58 if (!need_resched())
59#if defined(MACH_ATARI_ONLY)
60 /* block out HSYNC on the atari (falcon) */
61 __asm__("stop #0x2200" : : : "cc");
62#else
63 __asm__("stop #0x2000" : : : "cc");
64#endif
65}
66
67void (*idle)(void) = default_idle;
68
69/*
70 * The idle thread. There's no useful work to be
71 * done, so just try to conserve power and have a
72 * low exit latency (ie sit in a loop waiting for
73 * somebody to say that they'd like to reschedule)
74 */
75void cpu_idle(void)
76{
77 /* endless idle loop with no priority at all */
78 while (1) {
79 while (!need_resched())
80 idle();
81 preempt_enable_no_resched();
82 schedule();
83 preempt_disable();
84 }
85}
86
87void machine_restart(char * __unused)
88{
89 if (mach_reset)
90 mach_reset();
91 for (;;);
92}
93
94void machine_halt(void)
95{
96 if (mach_halt)
97 mach_halt();
98 for (;;);
99}
100
101void machine_power_off(void)
102{
103 if (mach_power_off)
104 mach_power_off();
105 for (;;);
106}
107
108void (*pm_power_off)(void) = machine_power_off;
109EXPORT_SYMBOL(pm_power_off);
110
111void show_regs(struct pt_regs * regs)
112{
113 printk("\n");
114 printk("Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
115 regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
116 printk("ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
117 regs->orig_d0, regs->d0, regs->a2, regs->a1);
118 printk("A0: %08lx D5: %08lx D4: %08lx\n",
119 regs->a0, regs->d5, regs->d4);
120 printk("D3: %08lx D2: %08lx D1: %08lx\n",
121 regs->d3, regs->d2, regs->d1);
122 if (!(regs->sr & PS_S))
123 printk("USP: %08lx\n", rdusp());
124}
125
126/*
127 * Create a kernel thread
128 */
129int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
130{
131 int pid;
132 mm_segment_t fs;
133
134 fs = get_fs();
135 set_fs (KERNEL_DS);
136
137 {
138 register long retval __asm__ ("d0");
139 register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
140
141 retval = __NR_clone;
142 __asm__ __volatile__
143 ("clrl %%d2\n\t"
144 "trap #0\n\t" /* Linux/m68k system call */
145 "tstl %0\n\t" /* child or parent */
146 "jne 1f\n\t" /* parent - jump */
147 "lea %%sp@(%c7),%6\n\t" /* reload current */
148 "movel %6@,%6\n\t"
149 "movel %3,%%sp@-\n\t" /* push argument */
150 "jsr %4@\n\t" /* call fn */
151 "movel %0,%%d1\n\t" /* pass exit value */
152 "movel %2,%%d0\n\t" /* exit */
153 "trap #0\n"
154 "1:"
155 : "+d" (retval)
156 : "i" (__NR_clone), "i" (__NR_exit),
157 "r" (arg), "a" (fn), "d" (clone_arg), "r" (current),
158 "i" (-THREAD_SIZE)
159 : "d2");
160
161 pid = retval;
162 }
163
164 set_fs (fs);
165 return pid;
166}
167EXPORT_SYMBOL(kernel_thread);
168
169void flush_thread(void)
170{
171 unsigned long zero = 0;
172
173 current->thread.fs = __USER_DS;
174 if (!FPU_IS_EMU)
175 asm volatile("frestore %0": :"m" (zero));
176}
177
178/*
179 * "m68k_fork()".. By the time we get here, the
180 * non-volatile registers have also been saved on the
181 * stack. We do some ugly pointer stuff here.. (see
182 * also copy_thread)
183 */
184
185asmlinkage int m68k_fork(struct pt_regs *regs)
186{
187 return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
188}
189
190asmlinkage int m68k_vfork(struct pt_regs *regs)
191{
192 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
193 NULL, NULL);
194}
195
196asmlinkage int m68k_clone(struct pt_regs *regs)
197{
198 unsigned long clone_flags;
199 unsigned long newsp;
200 int __user *parent_tidptr, *child_tidptr;
201
202 /* syscall2 puts clone_flags in d1 and usp in d2 */
203 clone_flags = regs->d1;
204 newsp = regs->d2;
205 parent_tidptr = (int __user *)regs->d3;
206 child_tidptr = (int __user *)regs->d4;
207 if (!newsp)
208 newsp = rdusp();
209 return do_fork(clone_flags, newsp, regs, 0,
210 parent_tidptr, child_tidptr);
211}
212
213int copy_thread(unsigned long clone_flags, unsigned long usp,
214 unsigned long unused,
215 struct task_struct * p, struct pt_regs * regs)
216{
217 struct pt_regs * childregs;
218 struct switch_stack * childstack, *stack;
219 unsigned long *retp;
220
221 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
222
223 *childregs = *regs;
224 childregs->d0 = 0;
225
226 retp = ((unsigned long *) regs);
227 stack = ((struct switch_stack *) retp) - 1;
228
229 childstack = ((struct switch_stack *) childregs) - 1;
230 *childstack = *stack;
231 childstack->retpc = (unsigned long)ret_from_fork;
232
233 p->thread.usp = usp;
234 p->thread.ksp = (unsigned long)childstack;
235
236 if (clone_flags & CLONE_SETTLS)
237 task_thread_info(p)->tp_value = regs->d5;
238
239 /*
240 * Must save the current SFC/DFC value, NOT the value when
241 * the parent was last descheduled - RGH 10-08-96
242 */
243 p->thread.fs = get_fs().seg;
244
245 if (!FPU_IS_EMU) {
246 /* Copy the current fpu state */
247 asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
248
249 if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2]) {
250 if (CPU_IS_COLDFIRE) {
251 asm volatile ("fmovemd %/fp0-%/fp7,%0\n\t"
252 "fmovel %/fpiar,%1\n\t"
253 "fmovel %/fpcr,%2\n\t"
254 "fmovel %/fpsr,%3"
255 :
256 : "m" (p->thread.fp[0]),
257 "m" (p->thread.fpcntl[0]),
258 "m" (p->thread.fpcntl[1]),
259 "m" (p->thread.fpcntl[2])
260 : "memory");
261 } else {
262 asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
263 "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
264 :
265 : "m" (p->thread.fp[0]),
266 "m" (p->thread.fpcntl[0])
267 : "memory");
268 }
269 }
270
271 /* Restore the state in case the fpu was busy */
272 asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
273 }
274
275 return 0;
276}
277
278/* Fill in the fpu structure for a core dump. */
279
280int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
281{
282 char fpustate[216];
283
284 if (FPU_IS_EMU) {
285 int i;
286
287 memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
288 memcpy(fpu->fpregs, current->thread.fp, 96);
289 /* Convert internal fpu reg representation
290 * into long double format
291 */
292 for (i = 0; i < 24; i += 3)
293 fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
294 ((fpu->fpregs[i] & 0x0000ffff) << 16);
295 return 1;
296 }
297
298 /* First dump the fpu context to avoid protocol violation. */
299 asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
300 if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
301 return 0;
302
303 if (CPU_IS_COLDFIRE) {
304 asm volatile ("fmovel %/fpiar,%0\n\t"
305 "fmovel %/fpcr,%1\n\t"
306 "fmovel %/fpsr,%2\n\t"
307 "fmovemd %/fp0-%/fp7,%3"
308 :
309 : "m" (fpu->fpcntl[0]),
310 "m" (fpu->fpcntl[1]),
311 "m" (fpu->fpcntl[2]),
312 "m" (fpu->fpregs[0])
313 : "memory");
314 } else {
315 asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
316 :
317 : "m" (fpu->fpcntl[0])
318 : "memory");
319 asm volatile ("fmovemx %/fp0-%/fp7,%0"
320 :
321 : "m" (fpu->fpregs[0])
322 : "memory");
323 }
324
325 return 1;
326}
327EXPORT_SYMBOL(dump_fpu);
328
329/*
330 * sys_execve() executes a new program.
331 */
332asmlinkage int sys_execve(const char __user *name,
333 const char __user *const __user *argv,
334 const char __user *const __user *envp)
335{
336 int error;
337 char * filename;
338 struct pt_regs *regs = (struct pt_regs *) &name;
339
340 filename = getname(name);
341 error = PTR_ERR(filename);
342 if (IS_ERR(filename))
343 return error;
344 error = do_execve(filename, argv, envp, regs);
345 putname(filename);
346 return error;
347}
348
349unsigned long get_wchan(struct task_struct *p)
350{
351 unsigned long fp, pc;
352 unsigned long stack_page;
353 int count = 0;
354 if (!p || p == current || p->state == TASK_RUNNING)
355 return 0;
356
357 stack_page = (unsigned long)task_stack_page(p);
358 fp = ((struct switch_stack *)p->thread.ksp)->a6;
359 do {
360 if (fp < stack_page+sizeof(struct thread_info) ||
361 fp >= 8184+stack_page)
362 return 0;
363 pc = ((unsigned long *)fp)[1];
364 if (!in_sched_functions(pc))
365 return pc;
366 fp = *(unsigned long *) fp;
367 } while (count++ < 16);
368 return 0;
369}
diff --git a/arch/m68k/kernel/process_no.c b/arch/m68k/kernel/process_no.c
deleted file mode 100644
index 5e1078cabe0e..000000000000
--- a/arch/m68k/kernel/process_no.c
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 * linux/arch/m68knommu/kernel/process.c
3 *
4 * Copyright (C) 1995 Hamish Macdonald
5 *
6 * 68060 fixes by Jesper Skov
7 *
8 * uClinux changes
9 * Copyright (C) 2000-2002, David McCullough <davidm@snapgear.com>
10 */
11
12/*
13 * This file handles the architecture-dependent parts of process handling..
14 */
15
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>
30
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>
37
38asmlinkage void ret_from_fork(void);
39
40/*
41 * The following aren't currently used.
42 */
43void (*pm_idle)(void);
44EXPORT_SYMBOL(pm_idle);
45
46void (*pm_power_off)(void);
47EXPORT_SYMBOL(pm_power_off);
48
49/*
50 * The idle loop on an m68knommu..
51 */
52static void default_idle(void)
53{
54 local_irq_disable();
55 while (!need_resched()) {
56 /* This stop will re-enable interrupts */
57 __asm__("stop #0x2000" : : : "cc");
58 local_irq_disable();
59 }
60 local_irq_enable();
61}
62
63void (*idle)(void) = default_idle;
64
65/*
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)
70 */
71void cpu_idle(void)
72{
73 /* endless idle loop with no priority at all */
74 while (1) {
75 idle();
76 preempt_enable_no_resched();
77 schedule();
78 preempt_disable();
79 }
80}
81
82void machine_restart(char * __unused)
83{
84 if (mach_reset)
85 mach_reset();
86 for (;;);
87}
88
89void machine_halt(void)
90{
91 if (mach_halt)
92 mach_halt();
93 for (;;);
94}
95
96void machine_power_off(void)
97{
98 if (mach_power_off)
99 mach_power_off();
100 for (;;);
101}
102
103void show_regs(struct pt_regs * regs)
104{
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());
116}
117
118/*
119 * Create a kernel thread
120 */
121int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
122{
123 int retval;
124 long clone_arg = flags | CLONE_VM;
125 mm_segment_t fs;
126
127 fs = get_fs();
128 set_fs(KERNEL_DS);
129
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");
150
151 set_fs(fs);
152 return retval;
153}
154EXPORT_SYMBOL(kernel_thread);
155
156void flush_thread(void)
157{
158#ifdef CONFIG_FPU
159 unsigned long zero = 0;
160#endif
161
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
169}
170
171/*
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)
176 */
177
178asmlinkage int m68k_fork(struct pt_regs *regs)
179{
180 /* fork almost works, enough to trick you into looking elsewhere :-( */
181 return(-EINVAL);
182}
183
184asmlinkage int m68k_vfork(struct pt_regs *regs)
185{
186 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
187}
188
189asmlinkage int m68k_clone(struct pt_regs *regs)
190{
191 unsigned long clone_flags;
192 unsigned long newsp;
193
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);
200}
201
202int copy_thread(unsigned long clone_flags,
203 unsigned long usp, unsigned long topstk,
204 struct task_struct * p, struct pt_regs * regs)
205{
206 struct pt_regs * childregs;
207 struct switch_stack * childstack, *stack;
208 unsigned long *retp;
209
210 childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
211
212 *childregs = *regs;
213 childregs->d0 = 0;
214
215 retp = ((unsigned long *) regs);
216 stack = ((struct switch_stack *) retp) - 1;
217
218 childstack = ((struct switch_stack *) childregs) - 1;
219 *childstack = *stack;
220 childstack->retpc = (unsigned long)ret_from_fork;
221
222 p->thread.usp = usp;
223 p->thread.ksp = (unsigned long)childstack;
224
225 if (clone_flags & CLONE_SETTLS)
226 task_thread_info(p)->tp_value = regs->d5;
227
228 /*
229 * Must save the current SFC/DFC value, NOT the value when
230 * the parent was last descheduled - RGH 10-08-96
231 */
232 p->thread.fs = get_fs().seg;
233
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");
238
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]));
246 }
247#endif
248
249 return 0;
250}
251
252/* Fill in the fpu structure for a core dump. */
253
254int dump_fpu(struct pt_regs *regs, struct user_m68kfp_struct *fpu)
255{
256#ifdef CONFIG_FPU
257 char fpustate[216];
258
259 if (FPU_IS_EMU) {
260 int i;
261
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
266 */
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;
271 }
272
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;
277
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;
286}
287EXPORT_SYMBOL(dump_fpu);
288
289/*
290 * Generic dumping code. Used for panic and debug.
291 */
292void dump(struct pt_regs *fp)
293{
294 unsigned long *sp;
295 unsigned char *tp;
296 int i;
297
298 printk(KERN_EMERG "\nCURRENT PROCESS:\n\n");
299 printk(KERN_EMERG "COMM=%s PID=%d\n", current->comm, current->pid);
300
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));
312 }
313
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);
322
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++);
329 }
330 printk(KERN_EMERG "\n");
331
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++);
338 }
339 printk(KERN_EMERG "\n");
340
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++);
347 }
348 printk(KERN_EMERG "\n");
349}
350
351/*
352 * sys_execve() executes a new program.
353 */
354asmlinkage int sys_execve(const char *name,
355 const char *const *argv,
356 const char *const *envp)
357{
358 int error;
359 char * filename;
360 struct pt_regs *regs = (struct pt_regs *) &name;
361
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;
369}
370
371unsigned long get_wchan(struct task_struct *p)
372{
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;
378
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;
391}
392
393/*
394 * Return saved PC of a blocked thread.
395 */
396unsigned long thread_saved_pc(struct task_struct *tsk)
397{
398 struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
399
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;
405}
406