Merge remote-tracking branch 'remotes/powerpc/topic/xive' into kvm-ppc-next
[linux/fpc-iii.git] / arch / frv / kernel / process.c
blob5a4c92abc99ec320b54ef80841bc6f3333a9d3dd
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/sched/debug.h>
17 #include <linux/sched/task.h>
18 #include <linux/sched/task_stack.h>
19 #include <linux/kernel.h>
20 #include <linux/mm.h>
21 #include <linux/smp.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/elf.h>
28 #include <linux/reboot.h>
29 #include <linux/interrupt.h>
30 #include <linux/pagemap.h>
31 #include <linux/rcupdate.h>
33 #include <asm/asm-offsets.h>
34 #include <linux/uaccess.h>
35 #include <asm/setup.h>
36 #include <asm/pgtable.h>
37 #include <asm/tlb.h>
38 #include <asm/gdb-stub.h>
39 #include <asm/mb-regs.h>
41 #include "local.h"
43 asmlinkage void ret_from_fork(void);
44 asmlinkage void ret_from_kernel_thread(void);
46 #include <asm/pgalloc.h>
48 void (*pm_power_off)(void);
49 EXPORT_SYMBOL(pm_power_off);
51 static void core_sleep_idle(void)
53 #ifdef LED_DEBUG_SLEEP
54 /* Show that we're sleeping... */
55 __set_LEDS(0x55aa);
56 #endif
57 frv_cpu_core_sleep();
58 #ifdef LED_DEBUG_SLEEP
59 /* ... and that we woke up */
60 __set_LEDS(0);
61 #endif
62 mb();
65 void arch_cpu_idle(void)
67 if (!frv_dma_inprogress)
68 core_sleep_idle();
69 else
70 local_irq_enable();
73 void machine_restart(char * __unused)
75 unsigned long reset_addr;
76 #ifdef CONFIG_GDBSTUB
77 gdbstub_exit(0);
78 #endif
80 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
81 reset_addr = 0xfefff500;
82 else
83 reset_addr = 0xfeff0500;
85 /* Software reset. */
86 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
87 " sti %1,@(%0,0) !"
88 " nop ! nop ! nop ! nop ! nop ! "
89 " nop ! nop ! nop ! nop ! nop ! "
90 " nop ! nop ! nop ! nop ! nop ! "
91 " nop ! nop ! nop ! nop ! nop ! "
92 : : "r" (reset_addr), "r" (1) );
94 for (;;)
98 void machine_halt(void)
100 #ifdef CONFIG_GDBSTUB
101 gdbstub_exit(0);
102 #endif
104 for (;;);
107 void machine_power_off(void)
109 #ifdef CONFIG_GDBSTUB
110 gdbstub_exit(0);
111 #endif
113 for (;;);
116 void flush_thread(void)
118 /* nothing */
121 inline unsigned long user_stack(const struct pt_regs *regs)
123 while (regs->next_frame)
124 regs = regs->next_frame;
125 return user_mode(regs) ? regs->sp : 0;
129 * set up the kernel stack and exception frames for a new process
131 int copy_thread(unsigned long clone_flags,
132 unsigned long usp, unsigned long arg,
133 struct task_struct *p)
135 struct pt_regs *childregs;
137 childregs = (struct pt_regs *)
138 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
140 /* set up the userspace frame (the only place that the USP is stored) */
141 *childregs = *current_pt_regs();
143 p->thread.frame = childregs;
144 p->thread.curr = p;
145 p->thread.sp = (unsigned long) childregs;
146 p->thread.fp = 0;
147 p->thread.lr = 0;
148 p->thread.frame0 = childregs;
150 if (unlikely(p->flags & PF_KTHREAD)) {
151 childregs->gr9 = usp; /* function */
152 childregs->gr8 = arg;
153 p->thread.pc = (unsigned long) ret_from_kernel_thread;
154 save_user_regs(p->thread.user);
155 return 0;
157 if (usp)
158 childregs->sp = usp;
159 childregs->next_frame = NULL;
161 p->thread.pc = (unsigned long) ret_from_fork;
163 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
164 if (clone_flags & CLONE_SETTLS)
165 childregs->gr29 = childregs->gr12;
167 save_user_regs(p->thread.user);
169 return 0;
170 } /* end copy_thread() */
172 unsigned long get_wchan(struct task_struct *p)
174 struct pt_regs *regs0;
175 unsigned long fp, pc;
176 unsigned long stack_limit;
177 int count = 0;
178 if (!p || p == current || p->state == TASK_RUNNING)
179 return 0;
181 stack_limit = (unsigned long) (p + 1);
182 fp = p->thread.fp;
183 regs0 = p->thread.frame0;
185 do {
186 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
187 return 0;
189 pc = ((unsigned long *) fp)[2];
191 /* FIXME: This depends on the order of these functions. */
192 if (!in_sched_functions(pc))
193 return pc;
195 fp = *(unsigned long *) fp;
196 } while (count++ < 16);
198 return 0;
201 unsigned long thread_saved_pc(struct task_struct *tsk)
203 /* Check whether the thread is blocked in resume() */
204 if (in_sched_functions(tsk->thread.pc))
205 return ((unsigned long *)tsk->thread.fp)[2];
206 else
207 return tsk->thread.pc;
210 int elf_check_arch(const struct elf32_hdr *hdr)
212 unsigned long hsr0 = __get_HSR(0);
213 unsigned long psr = __get_PSR();
215 if (hdr->e_machine != EM_FRV)
216 return 0;
218 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
219 case EF_FRV_GPR64:
220 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
221 return 0;
222 case EF_FRV_GPR32:
223 case 0:
224 break;
225 default:
226 return 0;
229 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
230 case EF_FRV_FPR64:
231 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
232 return 0;
233 case EF_FRV_FPR32:
234 case EF_FRV_FPR_NONE:
235 case 0:
236 break;
237 default:
238 return 0;
241 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
242 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
243 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
244 return 0;
246 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
247 case EF_FRV_CPU_GENERIC:
248 break;
249 case EF_FRV_CPU_FR300:
250 case EF_FRV_CPU_SIMPLE:
251 case EF_FRV_CPU_TOMCAT:
252 default:
253 return 0;
254 case EF_FRV_CPU_FR400:
255 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
256 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
257 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
258 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
259 return 0;
260 break;
261 case EF_FRV_CPU_FR450:
262 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
263 return 0;
264 break;
265 case EF_FRV_CPU_FR500:
266 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
267 return 0;
268 break;
269 case EF_FRV_CPU_FR550:
270 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
271 return 0;
272 break;
275 return 1;
278 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
280 memcpy(fpregs,
281 &current->thread.user->f,
282 sizeof(current->thread.user->f));
283 return 1;