GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / frv / kernel / process.c
blob843b0bb11c0677ab1446d41dd2de4fe42e61e2be
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>
17 #include <linux/mm.h>
18 #include <linux/smp.h>
19 #include <linux/smp_lock.h>
20 #include <linux/stddef.h>
21 #include <linux/unistd.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/user.h>
25 #include <linux/elf.h>
26 #include <linux/reboot.h>
27 #include <linux/interrupt.h>
28 #include <linux/pagemap.h>
30 #include <asm/asm-offsets.h>
31 #include <asm/uaccess.h>
32 #include <asm/system.h>
33 #include <asm/setup.h>
34 #include <asm/pgtable.h>
35 #include <asm/tlb.h>
36 #include <asm/gdb-stub.h>
37 #include <asm/mb-regs.h>
39 #include "local.h"
41 asmlinkage void ret_from_fork(void);
43 #include <asm/pgalloc.h>
45 void (*pm_power_off)(void);
46 EXPORT_SYMBOL(pm_power_off);
48 struct task_struct *alloc_task_struct(void)
50 struct task_struct *p = kmalloc(THREAD_SIZE, GFP_KERNEL);
51 if (p)
52 atomic_set((atomic_t *)(p+1), 1);
53 return p;
56 void free_task_struct(struct task_struct *p)
58 if (atomic_dec_and_test((atomic_t *)(p+1)))
59 kfree(p);
62 static void core_sleep_idle(void)
64 #ifdef LED_DEBUG_SLEEP
65 /* Show that we're sleeping... */
66 __set_LEDS(0x55aa);
67 #endif
68 frv_cpu_core_sleep();
69 #ifdef LED_DEBUG_SLEEP
70 /* ... and that we woke up */
71 __set_LEDS(0);
72 #endif
73 mb();
76 void (*idle)(void) = core_sleep_idle;
79 * The idle thread. There's no useful work to be
80 * done, so just try to conserve power and have a
81 * low exit latency (ie sit in a loop waiting for
82 * somebody to say that they'd like to reschedule)
84 void cpu_idle(void)
86 /* endless idle loop with no priority at all */
87 while (1) {
88 while (!need_resched()) {
89 check_pgt_cache();
91 if (!frv_dma_inprogress && idle)
92 idle();
95 preempt_enable_no_resched();
96 schedule();
97 preempt_disable();
101 void machine_restart(char * __unused)
103 unsigned long reset_addr;
104 #ifdef CONFIG_GDBSTUB
105 gdbstub_exit(0);
106 #endif
108 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
109 reset_addr = 0xfefff500;
110 else
111 reset_addr = 0xfeff0500;
113 /* Software reset. */
114 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
115 " sti %1,@(%0,0) !"
116 " nop ! nop ! nop ! nop ! nop ! "
117 " nop ! nop ! nop ! nop ! nop ! "
118 " nop ! nop ! nop ! nop ! nop ! "
119 " nop ! nop ! nop ! nop ! nop ! "
120 : : "r" (reset_addr), "r" (1) );
122 for (;;)
126 void machine_halt(void)
128 #ifdef CONFIG_GDBSTUB
129 gdbstub_exit(0);
130 #endif
132 for (;;);
135 void machine_power_off(void)
137 #ifdef CONFIG_GDBSTUB
138 gdbstub_exit(0);
139 #endif
141 for (;;);
144 void flush_thread(void)
146 set_fs(USER_DS);
149 inline unsigned long user_stack(const struct pt_regs *regs)
151 while (regs->next_frame)
152 regs = regs->next_frame;
153 return user_mode(regs) ? regs->sp : 0;
156 asmlinkage int sys_fork(void)
158 #ifndef CONFIG_MMU
159 /* fork almost works, enough to trick you into looking elsewhere:-( */
160 return -EINVAL;
161 #else
162 return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
163 #endif
166 asmlinkage int sys_vfork(void)
168 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
169 NULL, NULL);
172 /*****************************************************************************/
174 * clone a process
175 * - tlsptr is retrieved by copy_thread()
177 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
178 int __user *parent_tidptr, int __user *child_tidptr,
179 int __user *tlsptr)
181 if (!newsp)
182 newsp = user_stack(__frame);
183 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
184 } /* end sys_clone() */
186 /*****************************************************************************/
188 * This gets called before we allocate a new thread and copy
189 * the current task into it.
191 void prepare_to_copy(struct task_struct *tsk)
193 //unlazy_fpu(tsk);
194 } /* end prepare_to_copy() */
196 /*****************************************************************************/
198 * set up the kernel stack and exception frames for a new process
200 int copy_thread(unsigned long clone_flags,
201 unsigned long usp, unsigned long topstk,
202 struct task_struct *p, struct pt_regs *regs)
204 struct pt_regs *childregs0, *childregs, *regs0;
206 regs0 = __kernel_frame0_ptr;
207 childregs0 = (struct pt_regs *)
208 (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
209 childregs = childregs0;
211 /* set up the userspace frame (the only place that the USP is stored) */
212 *childregs0 = *regs0;
214 childregs0->gr8 = 0;
215 childregs0->sp = usp;
216 childregs0->next_frame = NULL;
218 /* set up the return kernel frame if called from kernel_thread() */
219 if (regs != regs0) {
220 childregs--;
221 *childregs = *regs;
222 childregs->sp = (unsigned long) childregs0;
223 childregs->next_frame = childregs0;
224 childregs->gr15 = (unsigned long) task_thread_info(p);
225 childregs->gr29 = (unsigned long) p;
228 p->set_child_tid = p->clear_child_tid = NULL;
230 p->thread.frame = childregs;
231 p->thread.curr = p;
232 p->thread.sp = (unsigned long) childregs;
233 p->thread.fp = 0;
234 p->thread.lr = 0;
235 p->thread.pc = (unsigned long) ret_from_fork;
236 p->thread.frame0 = childregs0;
238 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
239 if (clone_flags & CLONE_SETTLS)
240 childregs->gr29 = childregs->gr12;
242 save_user_regs(p->thread.user);
244 return 0;
245 } /* end copy_thread() */
248 * sys_execve() executes a new program.
250 asmlinkage int sys_execve(const char __user *name,
251 const char __user *const __user *argv,
252 const char __user *const __user *envp)
254 int error;
255 char * filename;
257 filename = getname(name);
258 error = PTR_ERR(filename);
259 if (IS_ERR(filename))
260 return error;
261 error = do_execve(filename, argv, envp, __frame);
262 putname(filename);
263 return error;
266 unsigned long get_wchan(struct task_struct *p)
268 struct pt_regs *regs0;
269 unsigned long fp, pc;
270 unsigned long stack_limit;
271 int count = 0;
272 if (!p || p == current || p->state == TASK_RUNNING)
273 return 0;
275 stack_limit = (unsigned long) (p + 1);
276 fp = p->thread.fp;
277 regs0 = p->thread.frame0;
279 do {
280 if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
281 return 0;
283 pc = ((unsigned long *) fp)[2];
285 if (!in_sched_functions(pc))
286 return pc;
288 fp = *(unsigned long *) fp;
289 } while (count++ < 16);
291 return 0;
294 unsigned long thread_saved_pc(struct task_struct *tsk)
296 /* Check whether the thread is blocked in resume() */
297 if (in_sched_functions(tsk->thread.pc))
298 return ((unsigned long *)tsk->thread.fp)[2];
299 else
300 return tsk->thread.pc;
303 int elf_check_arch(const struct elf32_hdr *hdr)
305 unsigned long hsr0 = __get_HSR(0);
306 unsigned long psr = __get_PSR();
308 if (hdr->e_machine != EM_FRV)
309 return 0;
311 switch (hdr->e_flags & EF_FRV_GPR_MASK) {
312 case EF_FRV_GPR64:
313 if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
314 return 0;
315 case EF_FRV_GPR32:
316 case 0:
317 break;
318 default:
319 return 0;
322 switch (hdr->e_flags & EF_FRV_FPR_MASK) {
323 case EF_FRV_FPR64:
324 if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
325 return 0;
326 case EF_FRV_FPR32:
327 case EF_FRV_FPR_NONE:
328 case 0:
329 break;
330 default:
331 return 0;
334 if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
335 if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
336 PSR_IMPLE(psr) != PSR_IMPLE_FR451)
337 return 0;
339 switch (hdr->e_flags & EF_FRV_CPU_MASK) {
340 case EF_FRV_CPU_GENERIC:
341 break;
342 case EF_FRV_CPU_FR300:
343 case EF_FRV_CPU_SIMPLE:
344 case EF_FRV_CPU_TOMCAT:
345 default:
346 return 0;
347 case EF_FRV_CPU_FR400:
348 if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
349 PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
350 PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
351 PSR_IMPLE(psr) != PSR_IMPLE_FR551)
352 return 0;
353 break;
354 case EF_FRV_CPU_FR450:
355 if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
356 return 0;
357 break;
358 case EF_FRV_CPU_FR500:
359 if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
360 return 0;
361 break;
362 case EF_FRV_CPU_FR550:
363 if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
364 return 0;
365 break;
368 return 1;
371 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
373 memcpy(fpregs,
374 &current->thread.user->f,
375 sizeof(current->thread.user->f));
376 return 1;