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