1 /* process.c: FRV specific parts of process handling
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/process.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
18 #include <linux/smp.h>
19 #include <linux/stddef.h>
20 #include <linux/unistd.h>
21 #include <linux/ptrace.h>
22 #include <linux/slab.h>
23 #include <linux/user.h>
24 #include <linux/elf.h>
25 #include <linux/reboot.h>
26 #include <linux/interrupt.h>
27 #include <linux/pagemap.h>
28 #include <linux/rcupdate.h>
30 #include <asm/asm-offsets.h>
31 #include <asm/uaccess.h>
32 #include <asm/setup.h>
33 #include <asm/pgtable.h>
35 #include <asm/gdb-stub.h>
36 #include <asm/mb-regs.h>
40 asmlinkage void ret_from_fork(void);
42 #include <asm/pgalloc.h>
44 void (*pm_power_off)(void);
45 EXPORT_SYMBOL(pm_power_off);
47 static void core_sleep_idle(void)
49 #ifdef LED_DEBUG_SLEEP
50 /* Show that we're sleeping... */
54 #ifdef LED_DEBUG_SLEEP
55 /* ... and that we woke up */
61 void (*idle)(void) = core_sleep_idle;
64 * The idle thread. There's no useful work to be
65 * done, so just try to conserve power and have a
66 * low exit latency (ie sit in a loop waiting for
67 * somebody to say that they'd like to reschedule)
71 /* endless idle loop with no priority at all */
74 while (!need_resched()) {
77 if (!frv_dma_inprogress && idle)
82 schedule_preempt_disabled();
86 void machine_restart(char * __unused)
88 unsigned long reset_addr;
93 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
94 reset_addr = 0xfefff500;
96 reset_addr = 0xfeff0500;
99 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
101 " nop ! nop ! nop ! nop ! nop ! "
102 " nop ! nop ! nop ! nop ! nop ! "
103 " nop ! nop ! nop ! nop ! nop ! "
104 " nop ! nop ! nop ! nop ! nop ! "
105 : : "r" (reset_addr), "r" (1) );
111 void machine_halt(void)
113 #ifdef CONFIG_GDBSTUB
120 void machine_power_off(void)
122 #ifdef CONFIG_GDBSTUB
129 void flush_thread(void)
134 inline unsigned long user_stack(const struct pt_regs *regs)
136 while (regs->next_frame)
137 regs = regs->next_frame;
138 return user_mode(regs) ? regs->sp : 0;
141 asmlinkage int sys_fork(void)
144 /* fork almost works, enough to trick you into looking elsewhere:-( */
147 return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
151 asmlinkage int sys_vfork(void)
153 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
157 /*****************************************************************************/
160 * - tlsptr is retrieved by copy_thread()
162 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
163 int __user *parent_tidptr, int __user *child_tidptr,
167 newsp = user_stack(__frame);
168 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
169 } /* end sys_clone() */
172 * set up the kernel stack and exception frames for a new process
174 int copy_thread(unsigned long clone_flags,
175 unsigned long usp, unsigned long topstk,
176 struct task_struct *p, struct pt_regs *regs)
178 struct pt_regs *childregs0, *childregs, *regs0;
180 regs0 = __kernel_frame0_ptr;
181 childregs0 = (struct pt_regs *)
182 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
183 childregs = childregs0;
185 /* set up the userspace frame (the only place that the USP is stored) */
186 *childregs0 = *regs0;
189 childregs0->sp = usp;
190 childregs0->next_frame = NULL;
192 /* set up the return kernel frame if called from kernel_thread() */
196 childregs->sp = (unsigned long) childregs0;
197 childregs->next_frame = childregs0;
198 childregs->gr15 = (unsigned long) task_thread_info(p);
199 childregs->gr29 = (unsigned long) p;
202 p->set_child_tid = p->clear_child_tid = NULL;
204 p->thread.frame = childregs;
206 p->thread.sp = (unsigned long) childregs;
209 p->thread.pc = (unsigned long) ret_from_fork;
210 p->thread.frame0 = childregs0;
212 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
213 if (clone_flags & CLONE_SETTLS)
214 childregs->gr29 = childregs->gr12;
216 save_user_regs(p->thread.user);
219 } /* end copy_thread() */
222 * sys_execve() executes a new program.
224 asmlinkage int sys_execve(const char __user *name,
225 const char __user *const __user *argv,
226 const char __user *const __user *envp)
231 filename = getname(name);
232 error = PTR_ERR(filename);
233 if (IS_ERR(filename))
235 error = do_execve(filename, argv, envp, __frame);
240 unsigned long get_wchan(struct task_struct *p)
242 struct pt_regs *regs0;
243 unsigned long fp, pc;
244 unsigned long stack_limit;
246 if (!p || p == current || p->state == TASK_RUNNING)
249 stack_limit = (unsigned long) (p + 1);
251 regs0 = p->thread.frame0;
254 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
257 pc = ((unsigned long *) fp)[2];
259 /* FIXME: This depends on the order of these functions. */
260 if (!in_sched_functions(pc))
263 fp = *(unsigned long *) fp;
264 } while (count++ < 16);
269 unsigned long thread_saved_pc(struct task_struct *tsk)
271 /* Check whether the thread is blocked in resume() */
272 if (in_sched_functions(tsk->thread.pc))
273 return ((unsigned long *)tsk->thread.fp)[2];
275 return tsk->thread.pc;
278 int elf_check_arch(const struct elf32_hdr *hdr)
280 unsigned long hsr0 = __get_HSR(0);
281 unsigned long psr = __get_PSR();
283 if (hdr->e_machine != EM_FRV)
286 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
288 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
297 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
299 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
302 case EF_FRV_FPR_NONE:
309 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
310 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
311 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
314 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
315 case EF_FRV_CPU_GENERIC:
317 case EF_FRV_CPU_FR300:
318 case EF_FRV_CPU_SIMPLE:
319 case EF_FRV_CPU_TOMCAT:
322 case EF_FRV_CPU_FR400:
323 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
324 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
325 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
326 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
329 case EF_FRV_CPU_FR450:
330 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
333 case EF_FRV_CPU_FR500:
334 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
337 case EF_FRV_CPU_FR550:
338 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
346 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
349 ¤t->thread.user->f,
350 sizeof(current->thread.user->f));