]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/frv/kernel/process.c
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>
28 #include <linux/rcupdate.h>
30 #include <asm/asm-offsets.h>
31 #include <asm/uaccess.h>
32 #include <asm/setup.h>
33 #include <asm/pgtable.h>
35 #include <asm/gdb-stub.h>
36 #include <asm/mb-regs.h>
40 asmlinkage
void ret_from_fork(void);
41 asmlinkage
void ret_from_kernel_thread(void);
43 #include <asm/pgalloc.h>
45 void (*pm_power_off
)(void);
46 EXPORT_SYMBOL(pm_power_off
);
48 static void core_sleep_idle(void)
50 #ifdef LED_DEBUG_SLEEP
51 /* Show that we're sleeping... */
55 #ifdef LED_DEBUG_SLEEP
56 /* ... and that we woke up */
62 void (*idle
)(void) = core_sleep_idle
;
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)
72 /* endless idle loop with no priority at all */
75 while (!need_resched()) {
78 if (!frv_dma_inprogress
&& idle
)
83 schedule_preempt_disabled();
87 void machine_restart(char * __unused
)
89 unsigned long reset_addr
;
94 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551
)
95 reset_addr
= 0xfefff500;
97 reset_addr
= 0xfeff0500;
100 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
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) );
112 void machine_halt(void)
114 #ifdef CONFIG_GDBSTUB
121 void machine_power_off(void)
123 #ifdef CONFIG_GDBSTUB
130 void flush_thread(void)
135 inline unsigned long user_stack(const struct pt_regs
*regs
)
137 while (regs
->next_frame
)
138 regs
= regs
->next_frame
;
139 return user_mode(regs
) ? regs
->sp
: 0;
142 asmlinkage
int sys_fork(void)
145 /* fork almost works, enough to trick you into looking elsewhere:-( */
148 return do_fork(SIGCHLD
, user_stack(__frame
), __frame
, 0, NULL
, NULL
);
152 asmlinkage
int sys_vfork(void)
154 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, user_stack(__frame
), __frame
, 0,
158 /*****************************************************************************/
161 * - tlsptr is retrieved by copy_thread()
163 asmlinkage
int sys_clone(unsigned long clone_flags
, unsigned long newsp
,
164 int __user
*parent_tidptr
, int __user
*child_tidptr
,
168 newsp
= user_stack(__frame
);
169 return do_fork(clone_flags
, newsp
, __frame
, 0, parent_tidptr
, child_tidptr
);
170 } /* end sys_clone() */
173 * set up the kernel stack and exception frames for a new process
175 int copy_thread(unsigned long clone_flags
,
176 unsigned long usp
, unsigned long arg
,
177 struct task_struct
*p
, struct pt_regs
*regs
)
179 struct pt_regs
*childregs
;
181 childregs
= (struct pt_regs
*)
182 (task_stack_page(p
) + THREAD_SIZE
- FRV_FRAME0_SIZE
);
184 p
->set_child_tid
= p
->clear_child_tid
= NULL
;
186 p
->thread
.frame
= childregs
;
188 p
->thread
.sp
= (unsigned long) childregs
;
191 p
->thread
.frame0
= childregs
;
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
);
203 /* set up the userspace frame (the only place that the USP is stored) */
207 childregs
->next_frame
= NULL
;
209 p
->thread
.pc
= (unsigned long) ret_from_fork
;
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
;
215 save_user_regs(p
->thread
.user
);
218 } /* end copy_thread() */
220 unsigned long get_wchan(struct task_struct
*p
)
222 struct pt_regs
*regs0
;
223 unsigned long fp
, pc
;
224 unsigned long stack_limit
;
226 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
229 stack_limit
= (unsigned long) (p
+ 1);
231 regs0
= p
->thread
.frame0
;
234 if (fp
< stack_limit
|| fp
>= (unsigned long) regs0
|| fp
& 3)
237 pc
= ((unsigned long *) fp
)[2];
239 /* FIXME: This depends on the order of these functions. */
240 if (!in_sched_functions(pc
))
243 fp
= *(unsigned long *) fp
;
244 } while (count
++ < 16);
249 unsigned long thread_saved_pc(struct task_struct
*tsk
)
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];
255 return tsk
->thread
.pc
;
258 int elf_check_arch(const struct elf32_hdr
*hdr
)
260 unsigned long hsr0
= __get_HSR(0);
261 unsigned long psr
= __get_PSR();
263 if (hdr
->e_machine
!= EM_FRV
)
266 switch (hdr
->e_flags
& EF_FRV_GPR_MASK
) {
268 if ((hsr0
& HSR0_GRN
) == HSR0_GRN_32
)
277 switch (hdr
->e_flags
& EF_FRV_FPR_MASK
) {
279 if ((hsr0
& HSR0_FRN
) == HSR0_FRN_32
)
282 case EF_FRV_FPR_NONE
:
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
)
294 switch (hdr
->e_flags
& EF_FRV_CPU_MASK
) {
295 case EF_FRV_CPU_GENERIC
:
297 case EF_FRV_CPU_FR300
:
298 case EF_FRV_CPU_SIMPLE
:
299 case EF_FRV_CPU_TOMCAT
:
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
)
309 case EF_FRV_CPU_FR450
:
310 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
313 case EF_FRV_CPU_FR500
:
314 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR501
)
317 case EF_FRV_CPU_FR550
:
318 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
326 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpregs
)
329 ¤t
->thread
.user
->f
,
330 sizeof(current
->thread
.user
->f
));