]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/frv/kernel/process.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal
[mirror_ubuntu-zesty-kernel.git] / arch / frv / kernel / process.c
1 /* process.c: FRV specific parts of process handling
2 *
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
6 *
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.
11 */
12
13 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.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>
29
30 #include <asm/asm-offsets.h>
31 #include <asm/uaccess.h>
32 #include <asm/setup.h>
33 #include <asm/pgtable.h>
34 #include <asm/tlb.h>
35 #include <asm/gdb-stub.h>
36 #include <asm/mb-regs.h>
37
38 #include "local.h"
39
40 asmlinkage void ret_from_fork(void);
41 asmlinkage void ret_from_kernel_thread(void);
42
43 #include <asm/pgalloc.h>
44
45 void (*pm_power_off)(void);
46 EXPORT_SYMBOL(pm_power_off);
47
48 static void core_sleep_idle(void)
49 {
50 #ifdef LED_DEBUG_SLEEP
51 /* Show that we're sleeping... */
52 __set_LEDS(0x55aa);
53 #endif
54 frv_cpu_core_sleep();
55 #ifdef LED_DEBUG_SLEEP
56 /* ... and that we woke up */
57 __set_LEDS(0);
58 #endif
59 mb();
60 }
61
62 void (*idle)(void) = core_sleep_idle;
63
64 /*
65 * The idle thread. There's no useful work to be
66 * done, so just try to conserve power and have a
67 * low exit latency (ie sit in a loop waiting for
68 * somebody to say that they'd like to reschedule)
69 */
70 void cpu_idle(void)
71 {
72 /* endless idle loop with no priority at all */
73 while (1) {
74 rcu_idle_enter();
75 while (!need_resched()) {
76 check_pgt_cache();
77
78 if (!frv_dma_inprogress && idle)
79 idle();
80 }
81 rcu_idle_exit();
82
83 schedule_preempt_disabled();
84 }
85 }
86
87 void machine_restart(char * __unused)
88 {
89 unsigned long reset_addr;
90 #ifdef CONFIG_GDBSTUB
91 gdbstub_exit(0);
92 #endif
93
94 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
95 reset_addr = 0xfefff500;
96 else
97 reset_addr = 0xfeff0500;
98
99 /* Software reset. */
100 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
101 " sti %1,@(%0,0) !"
102 " nop ! nop ! nop ! nop ! nop ! "
103 " nop ! nop ! nop ! nop ! nop ! "
104 " nop ! nop ! nop ! nop ! nop ! "
105 " nop ! nop ! nop ! nop ! nop ! "
106 : : "r" (reset_addr), "r" (1) );
107
108 for (;;)
109 ;
110 }
111
112 void machine_halt(void)
113 {
114 #ifdef CONFIG_GDBSTUB
115 gdbstub_exit(0);
116 #endif
117
118 for (;;);
119 }
120
121 void machine_power_off(void)
122 {
123 #ifdef CONFIG_GDBSTUB
124 gdbstub_exit(0);
125 #endif
126
127 for (;;);
128 }
129
130 void flush_thread(void)
131 {
132 /* nothing */
133 }
134
135 inline unsigned long user_stack(const struct pt_regs *regs)
136 {
137 while (regs->next_frame)
138 regs = regs->next_frame;
139 return user_mode(regs) ? regs->sp : 0;
140 }
141
142 asmlinkage int sys_fork(void)
143 {
144 #ifndef CONFIG_MMU
145 /* fork almost works, enough to trick you into looking elsewhere:-( */
146 return -EINVAL;
147 #else
148 return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
149 #endif
150 }
151
152 asmlinkage int sys_vfork(void)
153 {
154 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
155 NULL, NULL);
156 }
157
158 /*****************************************************************************/
159 /*
160 * clone a process
161 * - tlsptr is retrieved by copy_thread()
162 */
163 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
164 int __user *parent_tidptr, int __user *child_tidptr,
165 int __user *tlsptr)
166 {
167 if (!newsp)
168 newsp = user_stack(__frame);
169 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
170 } /* end sys_clone() */
171
172 /*
173 * set up the kernel stack and exception frames for a new process
174 */
175 int copy_thread(unsigned long clone_flags,
176 unsigned long usp, unsigned long arg,
177 struct task_struct *p, struct pt_regs *regs)
178 {
179 struct pt_regs *childregs;
180
181 childregs = (struct pt_regs *)
182 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
183
184 p->set_child_tid = p->clear_child_tid = NULL;
185
186 p->thread.frame = childregs;
187 p->thread.curr = p;
188 p->thread.sp = (unsigned long) childregs;
189 p->thread.fp = 0;
190 p->thread.lr = 0;
191 p->thread.frame0 = childregs;
192
193 if (unlikely(!regs)) {
194 memset(childregs, 0, sizeof(struct pt_regs));
195 childregs->gr9 = usp; /* function */
196 childregs->gr8 = arg;
197 chilregs->psr = PSR_S;
198 p->thread.pc = (unsigned long) ret_from_kernel_thread;
199 save_user_regs(p->thread.user);
200 return 0;
201 }
202
203 /* set up the userspace frame (the only place that the USP is stored) */
204 *childregs = *regs;
205
206 childregs->sp = usp;
207 childregs->next_frame = NULL;
208
209 p->thread.pc = (unsigned long) ret_from_fork;
210
211 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
212 if (clone_flags & CLONE_SETTLS)
213 childregs->gr29 = childregs->gr12;
214
215 save_user_regs(p->thread.user);
216
217 return 0;
218 } /* end copy_thread() */
219
220 unsigned long get_wchan(struct task_struct *p)
221 {
222 struct pt_regs *regs0;
223 unsigned long fp, pc;
224 unsigned long stack_limit;
225 int count = 0;
226 if (!p || p == current || p->state == TASK_RUNNING)
227 return 0;
228
229 stack_limit = (unsigned long) (p + 1);
230 fp = p->thread.fp;
231 regs0 = p->thread.frame0;
232
233 do {
234 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
235 return 0;
236
237 pc = ((unsigned long *) fp)[2];
238
239 /* FIXME: This depends on the order of these functions. */
240 if (!in_sched_functions(pc))
241 return pc;
242
243 fp = *(unsigned long *) fp;
244 } while (count++ < 16);
245
246 return 0;
247 }
248
249 unsigned long thread_saved_pc(struct task_struct *tsk)
250 {
251 /* Check whether the thread is blocked in resume() */
252 if (in_sched_functions(tsk->thread.pc))
253 return ((unsigned long *)tsk->thread.fp)[2];
254 else
255 return tsk->thread.pc;
256 }
257
258 int elf_check_arch(const struct elf32_hdr *hdr)
259 {
260 unsigned long hsr0 = __get_HSR(0);
261 unsigned long psr = __get_PSR();
262
263 if (hdr->e_machine != EM_FRV)
264 return 0;
265
266 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
267 case EF_FRV_GPR64:
268 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
269 return 0;
270 case EF_FRV_GPR32:
271 case 0:
272 break;
273 default:
274 return 0;
275 }
276
277 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
278 case EF_FRV_FPR64:
279 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
280 return 0;
281 case EF_FRV_FPR32:
282 case EF_FRV_FPR_NONE:
283 case 0:
284 break;
285 default:
286 return 0;
287 }
288
289 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
290 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
291 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
292 return 0;
293
294 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
295 case EF_FRV_CPU_GENERIC:
296 break;
297 case EF_FRV_CPU_FR300:
298 case EF_FRV_CPU_SIMPLE:
299 case EF_FRV_CPU_TOMCAT:
300 default:
301 return 0;
302 case EF_FRV_CPU_FR400:
303 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
304 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
305 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
306 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
307 return 0;
308 break;
309 case EF_FRV_CPU_FR450:
310 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
311 return 0;
312 break;
313 case EF_FRV_CPU_FR500:
314 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
315 return 0;
316 break;
317 case EF_FRV_CPU_FR550:
318 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
319 return 0;
320 break;
321 }
322
323 return 1;
324 }
325
326 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
327 {
328 memcpy(fpregs,
329 &current->thread.user->f,
330 sizeof(current->thread.user->f));
331 return 1;
332 }