1 /* process.c: FRV specific parts of process handling
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
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 <linux/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);
41 asmlinkage void ret_from_kernel_thread(void);
43 #include <asm/pgalloc.h>
45 void (*pm_power_off)(void);
46 EXPORT_SYMBOL(pm_power_off);
48 static void core_sleep_idle(void)
50 #ifdef LED_DEBUG_SLEEP
51 /* Show that we're sleeping... */
55 #ifdef LED_DEBUG_SLEEP
56 /* ... and that we woke up */
62 void arch_cpu_idle(void)
64 if (!frv_dma_inprogress)
70 void machine_restart(char * __unused)
72 unsigned long reset_addr;
77 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
78 reset_addr = 0xfefff500;
80 reset_addr = 0xfeff0500;
83 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
85 " nop ! nop ! nop ! nop ! nop ! "
86 " nop ! nop ! nop ! nop ! nop ! "
87 " nop ! nop ! nop ! nop ! nop ! "
88 " nop ! nop ! nop ! nop ! nop ! "
89 : : "r" (reset_addr), "r" (1) );
95 void machine_halt(void)
104 void machine_power_off(void)
106 #ifdef CONFIG_GDBSTUB
113 void flush_thread(void)
118 inline unsigned long user_stack(const struct pt_regs *regs)
120 while (regs->next_frame)
121 regs = regs->next_frame;
122 return user_mode(regs) ? regs->sp : 0;
126 * set up the kernel stack and exception frames for a new process
128 int copy_thread(unsigned long clone_flags,
129 unsigned long usp, unsigned long arg,
130 struct task_struct *p)
132 struct pt_regs *childregs;
134 childregs = (struct pt_regs *)
135 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
137 /* set up the userspace frame (the only place that the USP is stored) */
138 *childregs = *current_pt_regs();
140 p->thread.frame = childregs;
142 p->thread.sp = (unsigned long) childregs;
145 p->thread.frame0 = childregs;
147 if (unlikely(p->flags & PF_KTHREAD)) {
148 childregs->gr9 = usp; /* function */
149 childregs->gr8 = arg;
150 p->thread.pc = (unsigned long) ret_from_kernel_thread;
151 save_user_regs(p->thread.user);
156 childregs->next_frame = NULL;
158 p->thread.pc = (unsigned long) ret_from_fork;
160 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
161 if (clone_flags & CLONE_SETTLS)
162 childregs->gr29 = childregs->gr12;
164 save_user_regs(p->thread.user);
167 } /* end copy_thread() */
169 unsigned long get_wchan(struct task_struct *p)
171 struct pt_regs *regs0;
172 unsigned long fp, pc;
173 unsigned long stack_limit;
175 if (!p || p == current || p->state == TASK_RUNNING)
178 stack_limit = (unsigned long) (p + 1);
180 regs0 = p->thread.frame0;
183 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
186 pc = ((unsigned long *) fp)[2];
188 /* FIXME: This depends on the order of these functions. */
189 if (!in_sched_functions(pc))
192 fp = *(unsigned long *) fp;
193 } while (count++ < 16);
198 unsigned long thread_saved_pc(struct task_struct *tsk)
200 /* Check whether the thread is blocked in resume() */
201 if (in_sched_functions(tsk->thread.pc))
202 return ((unsigned long *)tsk->thread.fp)[2];
204 return tsk->thread.pc;
207 int elf_check_arch(const struct elf32_hdr *hdr)
209 unsigned long hsr0 = __get_HSR(0);
210 unsigned long psr = __get_PSR();
212 if (hdr->e_machine != EM_FRV)
215 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
217 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
226 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
228 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
231 case EF_FRV_FPR_NONE:
238 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
239 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
240 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
243 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
244 case EF_FRV_CPU_GENERIC:
246 case EF_FRV_CPU_FR300:
247 case EF_FRV_CPU_SIMPLE:
248 case EF_FRV_CPU_TOMCAT:
251 case EF_FRV_CPU_FR400:
252 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
253 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
254 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
255 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
258 case EF_FRV_CPU_FR450:
259 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
262 case EF_FRV_CPU_FR500:
263 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
266 case EF_FRV_CPU_FR550:
267 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
275 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
278 ¤t->thread.user->f,
279 sizeof(current->thread.user->f));