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");
2
#include "process_mm.c"
79
__asm__("stop #0x2000" : : : "cc");
4
#include "process_no.c"
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;
189
current->thread.fs = __USER_DS;
191
asm volatile (".chip 68k/68881\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
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,
214
asmlinkage int m68k_clone(struct pt_regs *regs)
216
unsigned long clone_flags;
218
int __user *parent_tidptr, *child_tidptr;
220
/* syscall2 puts clone_flags in d1 and usp in d2 */
221
clone_flags = regs->d1;
223
parent_tidptr = (int __user *)regs->d3;
224
child_tidptr = (int __user *)regs->d4;
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;
239
childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
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;
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;
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])
272
/* Restore the state in case the fpu was busy */
273
asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
279
/* Fill in the fpu structure for a core dump. */
281
int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
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);
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])
304
asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
305
:: "m" (fpu->fpcntl[0])
307
asm volatile ("fmovemx %/fp0-%/fp7,%0"
308
:: "m" (fpu->fpregs[0])
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)
323
struct pt_regs *regs = (struct pt_regs *) &name;
325
filename = getname(name);
326
error = PTR_ERR(filename);
327
if (IS_ERR(filename))
329
error = do_execve(filename, argv, envp, regs);
334
unsigned long get_wchan(struct task_struct *p)
336
unsigned long fp, pc;
337
unsigned long stack_page;
339
if (!p || p == current || p->state == TASK_RUNNING)
342
stack_page = (unsigned long)task_stack_page(p);
343
fp = ((struct switch_stack *)p->thread.ksp)->a6;
345
if (fp < stack_page+sizeof(struct thread_info) ||
346
fp >= 8184+stack_page)
348
pc = ((unsigned long *)fp)[1];
349
if (!in_sched_functions(pc))
351
fp = *(unsigned long *) fp;
352
} while (count++ < 16);