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/sched/debug.h>
17 #include <linux/sched/task.h>
18 #include <linux/sched/task_stack.h>
19 #include <linux/kernel.h>
21 #include <linux/smp.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/elf.h>
28 #include <linux/reboot.h>
29 #include <linux/interrupt.h>
30 #include <linux/pagemap.h>
31 #include <linux/rcupdate.h>
33 #include <asm/asm-offsets.h>
34 #include <linux/uaccess.h>
35 #include <asm/setup.h>
36 #include <asm/pgtable.h>
38 #include <asm/gdb-stub.h>
39 #include <asm/mb-regs.h>
43 asmlinkage
void ret_from_fork(void);
44 asmlinkage
void ret_from_kernel_thread(void);
46 #include <asm/pgalloc.h>
48 void (*pm_power_off
)(void);
49 EXPORT_SYMBOL(pm_power_off
);
51 static void core_sleep_idle(void)
53 #ifdef LED_DEBUG_SLEEP
54 /* Show that we're sleeping... */
58 #ifdef LED_DEBUG_SLEEP
59 /* ... and that we woke up */
65 void arch_cpu_idle(void)
67 if (!frv_dma_inprogress
)
73 void machine_restart(char * __unused
)
75 unsigned long reset_addr
;
80 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551
)
81 reset_addr
= 0xfefff500;
83 reset_addr
= 0xfeff0500;
86 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
88 " nop ! nop ! nop ! nop ! nop ! "
89 " nop ! nop ! nop ! nop ! nop ! "
90 " nop ! nop ! nop ! nop ! nop ! "
91 " nop ! nop ! nop ! nop ! nop ! "
92 : : "r" (reset_addr
), "r" (1) );
98 void machine_halt(void)
100 #ifdef CONFIG_GDBSTUB
107 void machine_power_off(void)
109 #ifdef CONFIG_GDBSTUB
116 void flush_thread(void)
121 inline unsigned long user_stack(const struct pt_regs
*regs
)
123 while (regs
->next_frame
)
124 regs
= regs
->next_frame
;
125 return user_mode(regs
) ? regs
->sp
: 0;
129 * set up the kernel stack and exception frames for a new process
131 int copy_thread(unsigned long clone_flags
,
132 unsigned long usp
, unsigned long arg
,
133 struct task_struct
*p
)
135 struct pt_regs
*childregs
;
137 childregs
= (struct pt_regs
*)
138 (task_stack_page(p
) + THREAD_SIZE
- FRV_FRAME0_SIZE
);
140 /* set up the userspace frame (the only place that the USP is stored) */
141 *childregs
= *current_pt_regs();
143 p
->thread
.frame
= childregs
;
145 p
->thread
.sp
= (unsigned long) childregs
;
148 p
->thread
.frame0
= childregs
;
150 if (unlikely(p
->flags
& PF_KTHREAD
)) {
151 childregs
->gr9
= usp
; /* function */
152 childregs
->gr8
= arg
;
153 p
->thread
.pc
= (unsigned long) ret_from_kernel_thread
;
154 save_user_regs(p
->thread
.user
);
159 childregs
->next_frame
= NULL
;
161 p
->thread
.pc
= (unsigned long) ret_from_fork
;
163 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
164 if (clone_flags
& CLONE_SETTLS
)
165 childregs
->gr29
= childregs
->gr12
;
167 save_user_regs(p
->thread
.user
);
170 } /* end copy_thread() */
172 unsigned long get_wchan(struct task_struct
*p
)
174 struct pt_regs
*regs0
;
175 unsigned long fp
, pc
;
176 unsigned long stack_limit
;
178 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
181 stack_limit
= (unsigned long) (p
+ 1);
183 regs0
= p
->thread
.frame0
;
186 if (fp
< stack_limit
|| fp
>= (unsigned long) regs0
|| fp
& 3)
189 pc
= ((unsigned long *) fp
)[2];
191 /* FIXME: This depends on the order of these functions. */
192 if (!in_sched_functions(pc
))
195 fp
= *(unsigned long *) fp
;
196 } while (count
++ < 16);
201 unsigned long thread_saved_pc(struct task_struct
*tsk
)
203 /* Check whether the thread is blocked in resume() */
204 if (in_sched_functions(tsk
->thread
.pc
))
205 return ((unsigned long *)tsk
->thread
.fp
)[2];
207 return tsk
->thread
.pc
;
210 int elf_check_arch(const struct elf32_hdr
*hdr
)
212 unsigned long hsr0
= __get_HSR(0);
213 unsigned long psr
= __get_PSR();
215 if (hdr
->e_machine
!= EM_FRV
)
218 switch (hdr
->e_flags
& EF_FRV_GPR_MASK
) {
220 if ((hsr0
& HSR0_GRN
) == HSR0_GRN_32
)
229 switch (hdr
->e_flags
& EF_FRV_FPR_MASK
) {
231 if ((hsr0
& HSR0_FRN
) == HSR0_FRN_32
)
234 case EF_FRV_FPR_NONE
:
241 if ((hdr
->e_flags
& EF_FRV_MULADD
) == EF_FRV_MULADD
)
242 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
243 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
246 switch (hdr
->e_flags
& EF_FRV_CPU_MASK
) {
247 case EF_FRV_CPU_GENERIC
:
249 case EF_FRV_CPU_FR300
:
250 case EF_FRV_CPU_SIMPLE
:
251 case EF_FRV_CPU_TOMCAT
:
254 case EF_FRV_CPU_FR400
:
255 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR401
&&
256 PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
257 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
&&
258 PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
261 case EF_FRV_CPU_FR450
:
262 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
265 case EF_FRV_CPU_FR500
:
266 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR501
)
269 case EF_FRV_CPU_FR550
:
270 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
278 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpregs
)
281 ¤t
->thread
.user
->f
,
282 sizeof(current
->thread
.user
->f
));