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>
29 #include <asm/asm-offsets.h>
30 #include <asm/uaccess.h>
31 #include <asm/setup.h>
32 #include <asm/pgtable.h>
34 #include <asm/gdb-stub.h>
35 #include <asm/mb-regs.h>
39 asmlinkage void ret_from_fork(void);
40 asmlinkage void ret_from_kernel_thread(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 */
73 while (!need_resched()) {
76 if (!frv_dma_inprogress && idle)
80 schedule_preempt_disabled();
84 void machine_restart(char * __unused)
86 unsigned long reset_addr;
91 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
92 reset_addr = 0xfefff500;
94 reset_addr = 0xfeff0500;
97 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
99 " nop ! nop ! nop ! nop ! nop ! "
100 " nop ! nop ! nop ! nop ! nop ! "
101 " nop ! nop ! nop ! nop ! nop ! "
102 " nop ! nop ! nop ! nop ! nop ! "
103 : : "r" (reset_addr), "r" (1) );
109 void machine_halt(void)
111 #ifdef CONFIG_GDBSTUB
118 void machine_power_off(void)
120 #ifdef CONFIG_GDBSTUB
127 void flush_thread(void)
132 inline unsigned long user_stack(const struct pt_regs *regs)
134 while (regs->next_frame)
135 regs = regs->next_frame;
136 return user_mode(regs) ? regs->sp : 0;
139 asmlinkage int sys_fork(void)
142 /* fork almost works, enough to trick you into looking elsewhere:-( */
145 return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
149 asmlinkage int sys_vfork(void)
151 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
155 /*****************************************************************************/
158 * - tlsptr is retrieved by copy_thread()
160 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
161 int __user *parent_tidptr, int __user *child_tidptr,
165 newsp = user_stack(__frame);
166 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
167 } /* end sys_clone() */
170 * set up the kernel stack and exception frames for a new process
172 int copy_thread(unsigned long clone_flags,
173 unsigned long usp, unsigned long arg,
174 struct task_struct *p, struct pt_regs *regs)
176 struct pt_regs *childregs;
178 childregs = (struct pt_regs *)
179 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
181 p->set_child_tid = p->clear_child_tid = NULL;
183 p->thread.frame = childregs;
185 p->thread.sp = (unsigned long) childregs;
188 p->thread.frame0 = childregs;
190 if (unlikely(!regs)) {
191 memset(childregs, 0, sizeof(struct pt_regs));
192 childregs->gr9 = usp; /* function */
193 childregs->gr8 = arg;
194 chilregs->psr = PSR_S;
195 p->thread.pc = (unsigned long) ret_from_kernel_thread;
196 save_user_regs(p->thread.user);
200 /* set up the userspace frame (the only place that the USP is stored) */
204 childregs->next_frame = NULL;
206 p->thread.pc = (unsigned long) ret_from_fork;
208 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
209 if (clone_flags & CLONE_SETTLS)
210 childregs->gr29 = childregs->gr12;
212 save_user_regs(p->thread.user);
215 } /* end copy_thread() */
217 unsigned long get_wchan(struct task_struct *p)
219 struct pt_regs *regs0;
220 unsigned long fp, pc;
221 unsigned long stack_limit;
223 if (!p || p == current || p->state == TASK_RUNNING)
226 stack_limit = (unsigned long) (p + 1);
228 regs0 = p->thread.frame0;
231 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
234 pc = ((unsigned long *) fp)[2];
236 /* FIXME: This depends on the order of these functions. */
237 if (!in_sched_functions(pc))
240 fp = *(unsigned long *) fp;
241 } while (count++ < 16);
246 unsigned long thread_saved_pc(struct task_struct *tsk)
248 /* Check whether the thread is blocked in resume() */
249 if (in_sched_functions(tsk->thread.pc))
250 return ((unsigned long *)tsk->thread.fp)[2];
252 return tsk->thread.pc;
255 int elf_check_arch(const struct elf32_hdr *hdr)
257 unsigned long hsr0 = __get_HSR(0);
258 unsigned long psr = __get_PSR();
260 if (hdr->e_machine != EM_FRV)
263 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
265 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
274 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
276 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
279 case EF_FRV_FPR_NONE:
286 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
287 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
288 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
291 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
292 case EF_FRV_CPU_GENERIC:
294 case EF_FRV_CPU_FR300:
295 case EF_FRV_CPU_SIMPLE:
296 case EF_FRV_CPU_TOMCAT:
299 case EF_FRV_CPU_FR400:
300 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
301 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
302 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
303 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
306 case EF_FRV_CPU_FR450:
307 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
310 case EF_FRV_CPU_FR500:
311 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
314 case EF_FRV_CPU_FR550:
315 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
323 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
326 ¤t->thread.user->f,
327 sizeof(current->thread.user->f));