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>
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>
29 #include <asm/asm-offsets.h>
30 #include <asm/uaccess.h>
31 #include <asm/setup.h>
32 #include <asm/pgtable.h>
34 #include <asm/gdb-stub.h>
35 #include <asm/mb-regs.h>
39 asmlinkage
void ret_from_fork(void);
41 #include <asm/pgalloc.h>
43 void (*pm_power_off
)(void);
44 EXPORT_SYMBOL(pm_power_off
);
46 static void core_sleep_idle(void)
48 #ifdef LED_DEBUG_SLEEP
49 /* Show that we're sleeping... */
53 #ifdef LED_DEBUG_SLEEP
54 /* ... and that we woke up */
60 void (*idle
)(void) = core_sleep_idle
;
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)
70 /* endless idle loop with no priority at all */
72 while (!need_resched()) {
75 if (!frv_dma_inprogress
&& idle
)
79 schedule_preempt_disabled();
83 void machine_restart(char * __unused
)
85 unsigned long reset_addr
;
90 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551
)
91 reset_addr
= 0xfefff500;
93 reset_addr
= 0xfeff0500;
96 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
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) );
108 void machine_halt(void)
110 #ifdef CONFIG_GDBSTUB
117 void machine_power_off(void)
119 #ifdef CONFIG_GDBSTUB
126 void flush_thread(void)
131 inline unsigned long user_stack(const struct pt_regs
*regs
)
133 while (regs
->next_frame
)
134 regs
= regs
->next_frame
;
135 return user_mode(regs
) ? regs
->sp
: 0;
138 asmlinkage
int sys_fork(void)
141 /* fork almost works, enough to trick you into looking elsewhere:-( */
144 return do_fork(SIGCHLD
, user_stack(__frame
), __frame
, 0, NULL
, NULL
);
148 asmlinkage
int sys_vfork(void)
150 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, user_stack(__frame
), __frame
, 0,
154 /*****************************************************************************/
157 * - tlsptr is retrieved by copy_thread()
159 asmlinkage
int sys_clone(unsigned long clone_flags
, unsigned long newsp
,
160 int __user
*parent_tidptr
, int __user
*child_tidptr
,
164 newsp
= user_stack(__frame
);
165 return do_fork(clone_flags
, newsp
, __frame
, 0, parent_tidptr
, child_tidptr
);
166 } /* end sys_clone() */
169 * set up the kernel stack and exception frames for a new process
171 int copy_thread(unsigned long clone_flags
,
172 unsigned long usp
, unsigned long topstk
,
173 struct task_struct
*p
, struct pt_regs
*regs
)
175 struct pt_regs
*childregs0
, *childregs
, *regs0
;
177 regs0
= __kernel_frame0_ptr
;
178 childregs0
= (struct pt_regs
*)
179 (task_stack_page(p
) + THREAD_SIZE
- FRV_FRAME0_SIZE
);
180 childregs
= childregs0
;
182 /* set up the userspace frame (the only place that the USP is stored) */
183 *childregs0
= *regs0
;
186 childregs0
->sp
= usp
;
187 childregs0
->next_frame
= NULL
;
189 /* set up the return kernel frame if called from kernel_thread() */
193 childregs
->sp
= (unsigned long) childregs0
;
194 childregs
->next_frame
= childregs0
;
195 childregs
->gr15
= (unsigned long) task_thread_info(p
);
196 childregs
->gr29
= (unsigned long) p
;
199 p
->set_child_tid
= p
->clear_child_tid
= NULL
;
201 p
->thread
.frame
= childregs
;
203 p
->thread
.sp
= (unsigned long) childregs
;
206 p
->thread
.pc
= (unsigned long) ret_from_fork
;
207 p
->thread
.frame0
= childregs0
;
209 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
210 if (clone_flags
& CLONE_SETTLS
)
211 childregs
->gr29
= childregs
->gr12
;
213 save_user_regs(p
->thread
.user
);
216 } /* end copy_thread() */
219 * sys_execve() executes a new program.
221 asmlinkage
int sys_execve(const char __user
*name
,
222 const char __user
*const __user
*argv
,
223 const char __user
*const __user
*envp
)
228 filename
= getname(name
);
229 error
= PTR_ERR(filename
);
230 if (IS_ERR(filename
))
232 error
= do_execve(filename
, argv
, envp
, __frame
);
237 unsigned long get_wchan(struct task_struct
*p
)
239 struct pt_regs
*regs0
;
240 unsigned long fp
, pc
;
241 unsigned long stack_limit
;
243 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
246 stack_limit
= (unsigned long) (p
+ 1);
248 regs0
= p
->thread
.frame0
;
251 if (fp
< stack_limit
|| fp
>= (unsigned long) regs0
|| fp
& 3)
254 pc
= ((unsigned long *) fp
)[2];
256 /* FIXME: This depends on the order of these functions. */
257 if (!in_sched_functions(pc
))
260 fp
= *(unsigned long *) fp
;
261 } while (count
++ < 16);
266 unsigned long thread_saved_pc(struct task_struct
*tsk
)
268 /* Check whether the thread is blocked in resume() */
269 if (in_sched_functions(tsk
->thread
.pc
))
270 return ((unsigned long *)tsk
->thread
.fp
)[2];
272 return tsk
->thread
.pc
;
275 int elf_check_arch(const struct elf32_hdr
*hdr
)
277 unsigned long hsr0
= __get_HSR(0);
278 unsigned long psr
= __get_PSR();
280 if (hdr
->e_machine
!= EM_FRV
)
283 switch (hdr
->e_flags
& EF_FRV_GPR_MASK
) {
285 if ((hsr0
& HSR0_GRN
) == HSR0_GRN_32
)
294 switch (hdr
->e_flags
& EF_FRV_FPR_MASK
) {
296 if ((hsr0
& HSR0_FRN
) == HSR0_FRN_32
)
299 case EF_FRV_FPR_NONE
:
306 if ((hdr
->e_flags
& EF_FRV_MULADD
) == EF_FRV_MULADD
)
307 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
308 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
311 switch (hdr
->e_flags
& EF_FRV_CPU_MASK
) {
312 case EF_FRV_CPU_GENERIC
:
314 case EF_FRV_CPU_FR300
:
315 case EF_FRV_CPU_SIMPLE
:
316 case EF_FRV_CPU_TOMCAT
:
319 case EF_FRV_CPU_FR400
:
320 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR401
&&
321 PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
322 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
&&
323 PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
326 case EF_FRV_CPU_FR450
:
327 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
330 case EF_FRV_CPU_FR500
:
331 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR501
)
334 case EF_FRV_CPU_FR550
:
335 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
343 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpregs
)
346 ¤t
->thread
.user
->f
,
347 sizeof(current
->thread
.user
->f
));
This page took 0.055489 seconds and 5 git commands to generate.