blob: 065f5e7190587cf4e6a8122a34c64617523ab1cc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m32r/kernel/process.c
3 *
4 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
5 * Hitoshi Yamamoto
6 * Taken from sh version.
7 * Copyright (C) 1995 Linus Torvalds
8 * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
9 */
10
11#undef DEBUG_PROCESS
12#ifdef DEBUG_PROCESS
13#define DPRINTK(fmt, args...) printk("%s:%d:%s: " fmt, __FILE__, __LINE__, \
14 __FUNCTION__, ##args)
15#else
16#define DPRINTK(fmt, args...)
17#endif
18
19/*
20 * This file handles the architecture-dependent parts of process handling..
21 */
22
23#include <linux/fs.h>
24#include <linux/config.h>
25#include <linux/module.h>
26#include <linux/ptrace.h>
27#include <linux/unistd.h>
28#include <linux/slab.h>
29#include <linux/hardirq.h>
30
31#include <asm/io.h>
32#include <asm/uaccess.h>
33#include <asm/mmu_context.h>
34#include <asm/elf.h>
35#include <asm/m32r.h>
36
37#include <linux/err.h>
38
39static int hlt_counter=0;
40
41/*
42 * Return saved PC of a blocked thread.
43 */
44unsigned long thread_saved_pc(struct task_struct *tsk)
45{
46 return tsk->thread.lr;
47}
48
49/*
50 * Powermanagement idle function, if any..
51 */
52void (*pm_idle)(void) = NULL;
Eric W. Biederman5e382912006-01-08 01:03:46 -080053EXPORT_SYMBOL(pm_idle);
54
55void (*pm_power_off)(void) = NULL;
56EXPORT_SYMBOL(pm_power_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58void disable_hlt(void)
59{
60 hlt_counter++;
61}
62
63EXPORT_SYMBOL(disable_hlt);
64
65void enable_hlt(void)
66{
67 hlt_counter--;
68}
69
70EXPORT_SYMBOL(enable_hlt);
71
72/*
73 * We use this is we don't have any better
74 * idle routine..
75 */
76void default_idle(void)
77{
78 /* M32R_FIXME: Please use "cpu_sleep" mode. */
79 cpu_relax();
80}
81
82/*
83 * On SMP it's slightly faster (but much more power-consuming!)
84 * to poll the ->work.need_resched flag instead of waiting for the
85 * cross-CPU IPI to arrive. Use this option with caution.
86 */
87static void poll_idle (void)
88{
89 /* M32R_FIXME */
90 cpu_relax();
91}
92
93/*
94 * The idle thread. There's no useful work to be
95 * done, so just try to conserve power and have a
96 * low exit latency (ie sit in a loop waiting for
97 * somebody to say that they'd like to reschedule)
98 */
99void cpu_idle (void)
100{
101 /* endless idle loop with no priority at all */
102 while (1) {
103 while (!need_resched()) {
104 void (*idle)(void) = pm_idle;
105
106 if (!idle)
107 idle = default_idle;
108
109 idle();
110 }
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800111 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800113 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115}
116
117void machine_restart(char *__unused)
118{
Hirokazu Takata0d34c862006-04-18 22:21:30 -0700119#if defined(CONFIG_PLAT_MAPPI3)
120 outw(1, (unsigned long)PLD_REBOOT);
121#endif
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 printk("Please push reset button!\n");
124 while (1)
125 cpu_relax();
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128void machine_halt(void)
129{
130 printk("Please push reset button!\n");
131 while (1)
132 cpu_relax();
133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135void machine_power_off(void)
136{
137 /* M32R_FIXME */
138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static int __init idle_setup (char *str)
141{
142 if (!strncmp(str, "poll", 4)) {
143 printk("using poll in idle threads.\n");
144 pm_idle = poll_idle;
145 } else if (!strncmp(str, "sleep", 4)) {
146 printk("using sleep in idle threads.\n");
147 pm_idle = default_idle;
148 }
149
150 return 1;
151}
152
153__setup("idle=", idle_setup);
154
155void show_regs(struct pt_regs * regs)
156{
157 printk("\n");
158 printk("BPC[%08lx]:PSW[%08lx]:LR [%08lx]:FP [%08lx]\n", \
159 regs->bpc, regs->psw, regs->lr, regs->fp);
160 printk("BBPC[%08lx]:BBPSW[%08lx]:SPU[%08lx]:SPI[%08lx]\n", \
161 regs->bbpc, regs->bbpsw, regs->spu, regs->spi);
162 printk("R0 [%08lx]:R1 [%08lx]:R2 [%08lx]:R3 [%08lx]\n", \
163 regs->r0, regs->r1, regs->r2, regs->r3);
164 printk("R4 [%08lx]:R5 [%08lx]:R6 [%08lx]:R7 [%08lx]\n", \
165 regs->r4, regs->r5, regs->r6, regs->r7);
166 printk("R8 [%08lx]:R9 [%08lx]:R10[%08lx]:R11[%08lx]\n", \
167 regs->r8, regs->r9, regs->r10, regs->r11);
168 printk("R12[%08lx]\n", \
169 regs->r12);
170
171#if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
172 printk("ACC0H[%08lx]:ACC0L[%08lx]\n", \
173 regs->acc0h, regs->acc0l);
174 printk("ACC1H[%08lx]:ACC1L[%08lx]\n", \
175 regs->acc1h, regs->acc1l);
176#elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
177 printk("ACCH[%08lx]:ACCL[%08lx]\n", \
178 regs->acch, regs->accl);
179#else
180#error unknown isa configuration
181#endif
182}
183
184/*
185 * Create a kernel thread
186 */
187
188/*
189 * This is the mechanism for creating a new kernel thread.
190 *
191 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
192 * who haven't done an "execve()") should use this: it will work within
193 * a system call from a "real" process, but the process memory space will
194 * not be free'd until both the parent and the child have exited.
195 */
196static void kernel_thread_helper(void *nouse, int (*fn)(void *), void *arg)
197{
198 fn(arg);
199 do_exit(-1);
200}
201
202int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
203{
204 struct pt_regs regs;
205
206 memset(&regs, 0, sizeof (regs));
207 regs.r1 = (unsigned long)fn;
208 regs.r2 = (unsigned long)arg;
209
210 regs.bpc = (unsigned long)kernel_thread_helper;
211
212 regs.psw = M32R_PSW_BIE;
213
214 /* Ok, create the new process. */
215 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
216 NULL);
217}
218
219/*
220 * Free current thread data structures etc..
221 */
222void exit_thread(void)
223{
224 /* Nothing to do. */
225 DPRINTK("pid = %d\n", current->pid);
226}
227
228void flush_thread(void)
229{
230 DPRINTK("pid = %d\n", current->pid);
231 memset(&current->thread.debug_trap, 0, sizeof(struct debug_trap));
232}
233
234void release_thread(struct task_struct *dead_task)
235{
236 /* do nothing */
237 DPRINTK("pid = %d\n", dead_task->pid);
238}
239
240/* Fill in the fpu structure for a core dump.. */
241int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
242{
243 return 0; /* Task didn't use the fpu at all. */
244}
245
246int copy_thread(int nr, unsigned long clone_flags, unsigned long spu,
247 unsigned long unused, struct task_struct *tsk, struct pt_regs *regs)
248{
Al Viro6c3559fc2006-01-12 01:05:52 -0800249 struct pt_regs *childregs = task_pt_regs(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 extern void ret_from_fork(void);
251
252 /* Copy registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 *childregs = *regs;
254
255 childregs->spu = spu;
256 childregs->r0 = 0; /* Child gets zero as return value */
257 regs->r0 = tsk->pid;
258 tsk->thread.sp = (unsigned long)childregs;
259 tsk->thread.lr = (unsigned long)ret_from_fork;
260
261 return 0;
262}
263
264/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 * Capture the user space registers if the task is not running (in user space)
266 */
267int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
268{
269 /* M32R_FIXME */
270 return 1;
271}
272
273asmlinkage int sys_fork(unsigned long r0, unsigned long r1, unsigned long r2,
274 unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
275 struct pt_regs regs)
276{
277#ifdef CONFIG_MMU
278 return do_fork(SIGCHLD, regs.spu, &regs, 0, NULL, NULL);
279#else
280 return -EINVAL;
281#endif /* CONFIG_MMU */
282}
283
284asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
285 unsigned long parent_tidptr,
286 unsigned long child_tidptr,
287 unsigned long r4, unsigned long r5, unsigned long r6,
288 struct pt_regs regs)
289{
290 if (!newsp)
291 newsp = regs.spu;
292
293 return do_fork(clone_flags, newsp, &regs, 0,
294 (int __user *)parent_tidptr, (int __user *)child_tidptr);
295}
296
297/*
298 * This is trivial, and on the face of it looks like it
299 * could equally well be done in user mode.
300 *
301 * Not so, for quite unobvious reasons - register pressure.
302 * In user mode vfork() cannot have a stack frame, and if
303 * done by calling the "clone()" system call directly, you
304 * do not have enough call-clobbered registers to hold all
305 * the information you need.
306 */
307asmlinkage int sys_vfork(unsigned long r0, unsigned long r1, unsigned long r2,
308 unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
309 struct pt_regs regs)
310{
311 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.spu, &regs, 0,
312 NULL, NULL);
313}
314
315/*
316 * sys_execve() executes a new program.
317 */
318asmlinkage int sys_execve(char __user *ufilename, char __user * __user *uargv,
319 char __user * __user *uenvp,
320 unsigned long r3, unsigned long r4, unsigned long r5,
321 unsigned long r6, struct pt_regs regs)
322{
323 int error;
324 char *filename;
325
326 filename = getname(ufilename);
327 error = PTR_ERR(filename);
328 if (IS_ERR(filename))
329 goto out;
330
331 error = do_execve(filename, uargv, uenvp, &regs);
332 if (error == 0) {
333 task_lock(current);
334 current->ptrace &= ~PT_DTRACE;
335 task_unlock(current);
336 }
337 putname(filename);
338out:
339 return error;
340}
341
342/*
343 * These bracket the sleeping functions..
344 */
345#define first_sched ((unsigned long) scheduling_functions_start_here)
346#define last_sched ((unsigned long) scheduling_functions_end_here)
347
348unsigned long get_wchan(struct task_struct *p)
349{
350 /* M32R_FIXME */
351 return (0);
352}