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);
41 #include <asm/pgalloc.h>
43 void (*pm_power_off)(void);
44 EXPORT_SYMBOL(pm_power_off);
46 struct task_struct *alloc_task_struct_node(int node)
48 struct task_struct *p = kmalloc_node(THREAD_SIZE, GFP_KERNEL, node);
51 atomic_set((atomic_t *)(p+1), 1);
55 void free_task_struct(struct task_struct *p)
57 if (atomic_dec_and_test((atomic_t *)(p+1)))
61 static void core_sleep_idle(void)
63 #ifdef LED_DEBUG_SLEEP
64 /* Show that we're sleeping... */
68 #ifdef LED_DEBUG_SLEEP
69 /* ... and that we woke up */
75 void (*idle)(void) = core_sleep_idle;
78 * The idle thread. There's no useful work to be
79 * done, so just try to conserve power and have a
80 * low exit latency (ie sit in a loop waiting for
81 * somebody to say that they'd like to reschedule)
85 /* endless idle loop with no priority at all */
87 while (!need_resched()) {
90 if (!frv_dma_inprogress && idle)
94 schedule_preempt_disabled();
98 void machine_restart(char * __unused)
100 unsigned long reset_addr;
101 #ifdef CONFIG_GDBSTUB
105 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
106 reset_addr = 0xfefff500;
108 reset_addr = 0xfeff0500;
110 /* Software reset. */
111 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
113 " nop ! nop ! nop ! nop ! nop ! "
114 " nop ! nop ! nop ! nop ! nop ! "
115 " nop ! nop ! nop ! nop ! nop ! "
116 " nop ! nop ! nop ! nop ! nop ! "
117 : : "r" (reset_addr), "r" (1) );
123 void machine_halt(void)
125 #ifdef CONFIG_GDBSTUB
132 void machine_power_off(void)
134 #ifdef CONFIG_GDBSTUB
141 void flush_thread(void)
146 inline unsigned long user_stack(const struct pt_regs *regs)
148 while (regs->next_frame)
149 regs = regs->next_frame;
150 return user_mode(regs) ? regs->sp : 0;
153 asmlinkage int sys_fork(void)
156 /* fork almost works, enough to trick you into looking elsewhere:-( */
159 return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
163 asmlinkage int sys_vfork(void)
165 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
169 /*****************************************************************************/
172 * - tlsptr is retrieved by copy_thread()
174 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
175 int __user *parent_tidptr, int __user *child_tidptr,
179 newsp = user_stack(__frame);
180 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
181 } /* end sys_clone() */
183 /*****************************************************************************/
185 * This gets called before we allocate a new thread and copy
186 * the current task into it.
188 void prepare_to_copy(struct task_struct *tsk)
191 } /* end prepare_to_copy() */
193 /*****************************************************************************/
195 * set up the kernel stack and exception frames for a new process
197 int copy_thread(unsigned long clone_flags,
198 unsigned long usp, unsigned long topstk,
199 struct task_struct *p, struct pt_regs *regs)
201 struct pt_regs *childregs0, *childregs, *regs0;
203 regs0 = __kernel_frame0_ptr;
204 childregs0 = (struct pt_regs *)
205 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
206 childregs = childregs0;
208 /* set up the userspace frame (the only place that the USP is stored) */
209 *childregs0 = *regs0;
212 childregs0->sp = usp;
213 childregs0->next_frame = NULL;
215 /* set up the return kernel frame if called from kernel_thread() */
219 childregs->sp = (unsigned long) childregs0;
220 childregs->next_frame = childregs0;
221 childregs->gr15 = (unsigned long) task_thread_info(p);
222 childregs->gr29 = (unsigned long) p;
225 p->set_child_tid = p->clear_child_tid = NULL;
227 p->thread.frame = childregs;
229 p->thread.sp = (unsigned long) childregs;
232 p->thread.pc = (unsigned long) ret_from_fork;
233 p->thread.frame0 = childregs0;
235 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
236 if (clone_flags & CLONE_SETTLS)
237 childregs->gr29 = childregs->gr12;
239 save_user_regs(p->thread.user);
242 } /* end copy_thread() */
245 * sys_execve() executes a new program.
247 asmlinkage int sys_execve(const char __user *name,
248 const char __user *const __user *argv,
249 const char __user *const __user *envp)
254 filename = getname(name);
255 error = PTR_ERR(filename);
256 if (IS_ERR(filename))
258 error = do_execve(filename, argv, envp, __frame);
263 unsigned long get_wchan(struct task_struct *p)
265 struct pt_regs *regs0;
266 unsigned long fp, pc;
267 unsigned long stack_limit;
269 if (!p || p == current || p->state == TASK_RUNNING)
272 stack_limit = (unsigned long) (p + 1);
274 regs0 = p->thread.frame0;
277 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
280 pc = ((unsigned long *) fp)[2];
282 /* FIXME: This depends on the order of these functions. */
283 if (!in_sched_functions(pc))
286 fp = *(unsigned long *) fp;
287 } while (count++ < 16);
292 unsigned long thread_saved_pc(struct task_struct *tsk)
294 /* Check whether the thread is blocked in resume() */
295 if (in_sched_functions(tsk->thread.pc))
296 return ((unsigned long *)tsk->thread.fp)[2];
298 return tsk->thread.pc;
301 int elf_check_arch(const struct elf32_hdr *hdr)
303 unsigned long hsr0 = __get_HSR(0);
304 unsigned long psr = __get_PSR();
306 if (hdr->e_machine != EM_FRV)
309 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
311 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
320 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
322 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
325 case EF_FRV_FPR_NONE:
332 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
333 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
334 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
337 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
338 case EF_FRV_CPU_GENERIC:
340 case EF_FRV_CPU_FR300:
341 case EF_FRV_CPU_SIMPLE:
342 case EF_FRV_CPU_TOMCAT:
345 case EF_FRV_CPU_FR400:
346 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
347 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
348 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
349 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
352 case EF_FRV_CPU_FR450:
353 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
356 case EF_FRV_CPU_FR500:
357 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
360 case EF_FRV_CPU_FR550:
361 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
369 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
372 ¤t->thread.user->f,
373 sizeof(current->thread.user->f));