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/config.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.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>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
31 #include <asm/setup.h>
32 #include <asm/pgtable.h>
33 #include <asm/gdb-stub.h>
34 #include <asm/mb-regs.h>
38 asmlinkage
void ret_from_fork(void);
40 #include <asm/pgalloc.h>
42 struct task_struct
*alloc_task_struct(void)
44 struct task_struct
*p
= kmalloc(THREAD_SIZE
, GFP_KERNEL
);
46 atomic_set((atomic_t
*)(p
+1), 1);
50 void free_task_struct(struct task_struct
*p
)
52 if (atomic_dec_and_test((atomic_t
*)(p
+1)))
56 static void core_sleep_idle(void)
58 #ifdef LED_DEBUG_SLEEP
59 /* Show that we're sleeping... */
63 #ifdef LED_DEBUG_SLEEP
64 /* ... and that we woke up */
70 void (*idle
)(void) = core_sleep_idle
;
73 * The idle thread. There's no useful work to be
74 * done, so just try to conserve power and have a
75 * low exit latency (ie sit in a loop waiting for
76 * somebody to say that they'd like to reschedule)
80 /* endless idle loop with no priority at all */
82 while (!need_resched()) {
83 irq_stat
[smp_processor_id()].idle_timestamp
= jiffies
;
85 if (!frv_dma_inprogress
&& idle
)
93 void machine_restart(char * __unused
)
95 unsigned long reset_addr
;
100 if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551
)
101 reset_addr
= 0xfefff500;
103 reset_addr
= 0xfeff0500;
105 /* Software reset. */
106 asm volatile(" dcef @(gr0,gr0),1 ! membar !"
108 " nop ! nop ! nop ! nop ! nop ! "
109 " nop ! nop ! nop ! nop ! nop ! "
110 " nop ! nop ! nop ! nop ! nop ! "
111 " nop ! nop ! nop ! nop ! nop ! "
112 : : "r" (reset_addr
), "r" (1) );
118 void machine_halt(void)
120 #ifdef CONFIG_GDBSTUB
127 void machine_power_off(void)
129 #ifdef CONFIG_GDBSTUB
136 void flush_thread(void)
139 unsigned long zero
= 0;
144 inline unsigned long user_stack(const struct pt_regs
*regs
)
146 while (regs
->next_frame
)
147 regs
= regs
->next_frame
;
148 return user_mode(regs
) ? regs
->sp
: 0;
151 asmlinkage
int sys_fork(void)
154 /* fork almost works, enough to trick you into looking elsewhere:-( */
157 return do_fork(SIGCHLD
, user_stack(__frame
), __frame
, 0, NULL
, NULL
);
161 asmlinkage
int sys_vfork(void)
163 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, user_stack(__frame
), __frame
, 0,
167 /*****************************************************************************/
170 * - tlsptr is retrieved by copy_thread()
172 asmlinkage
int sys_clone(unsigned long clone_flags
, unsigned long newsp
,
173 int __user
*parent_tidptr
, int __user
*child_tidptr
,
177 newsp
= user_stack(__frame
);
178 return do_fork(clone_flags
, newsp
, __frame
, 0, parent_tidptr
, child_tidptr
);
179 } /* end sys_clone() */
181 /*****************************************************************************/
183 * This gets called before we allocate a new thread and copy
184 * the current task into it.
186 void prepare_to_copy(struct task_struct
*tsk
)
189 } /* end prepare_to_copy() */
191 /*****************************************************************************/
193 * set up the kernel stack and exception frames for a new process
195 int copy_thread(int nr
, unsigned long clone_flags
,
196 unsigned long usp
, unsigned long topstk
,
197 struct task_struct
*p
, struct pt_regs
*regs
)
199 struct pt_regs
*childregs0
, *childregs
, *regs0
;
201 regs0
= __kernel_frame0_ptr
;
202 childregs0
= (struct pt_regs
*)
203 ((unsigned long) p
->thread_info
+ THREAD_SIZE
- USER_CONTEXT_SIZE
);
204 childregs
= childregs0
;
206 /* set up the userspace frame (the only place that the USP is stored) */
207 *childregs0
= *regs0
;
210 childregs0
->sp
= usp
;
211 childregs0
->next_frame
= NULL
;
213 /* set up the return kernel frame if called from kernel_thread() */
217 childregs
->sp
= (unsigned long) childregs0
;
218 childregs
->next_frame
= childregs0
;
219 childregs
->gr15
= (unsigned long) p
->thread_info
;
220 childregs
->gr29
= (unsigned long) p
;
223 p
->set_child_tid
= p
->clear_child_tid
= NULL
;
225 p
->thread
.frame
= childregs
;
227 p
->thread
.sp
= (unsigned long) childregs
;
230 p
->thread
.pc
= (unsigned long) ret_from_fork
;
231 p
->thread
.frame0
= childregs0
;
233 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
234 if (clone_flags
& CLONE_SETTLS
)
235 childregs
->gr29
= childregs
->gr12
;
237 save_user_regs(p
->thread
.user
);
240 } /* end copy_thread() */
243 * fill in the user structure for a core dump..
245 void dump_thread(struct pt_regs
*regs
, struct user
*dump
)
248 /* changed the size calculations - should hopefully work better. lbt */
249 dump
->magic
= CMAGIC
;
250 dump
->start_code
= 0;
251 dump
->start_stack
= user_stack(regs
) & ~(PAGE_SIZE
- 1);
252 dump
->u_tsize
= ((unsigned long) current
->mm
->end_code
) >> PAGE_SHIFT
;
253 dump
->u_dsize
= ((unsigned long) (current
->mm
->brk
+ (PAGE_SIZE
-1))) >> PAGE_SHIFT
;
254 dump
->u_dsize
-= dump
->u_tsize
;
257 if (dump
->start_stack
< TASK_SIZE
)
258 dump
->u_ssize
= ((unsigned long) (TASK_SIZE
- dump
->start_stack
)) >> PAGE_SHIFT
;
260 dump
->regs
= *(struct user_context
*) regs
;
265 * sys_execve() executes a new program.
267 asmlinkage
int sys_execve(char *name
, char **argv
, char **envp
)
273 filename
= getname(name
);
274 error
= PTR_ERR(filename
);
275 if (IS_ERR(filename
))
277 error
= do_execve(filename
, argv
, envp
, __frame
);
284 unsigned long get_wchan(struct task_struct
*p
)
286 struct pt_regs
*regs0
;
287 unsigned long fp
, pc
;
288 unsigned long stack_limit
;
290 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
293 stack_limit
= (unsigned long) (p
+ 1);
295 regs0
= p
->thread
.frame0
;
298 if (fp
< stack_limit
|| fp
>= (unsigned long) regs0
|| fp
& 3)
301 pc
= ((unsigned long *) fp
)[2];
303 /* FIXME: This depends on the order of these functions. */
304 if (!in_sched_functions(pc
))
307 fp
= *(unsigned long *) fp
;
308 } while (count
++ < 16);
313 unsigned long thread_saved_pc(struct task_struct
*tsk
)
315 /* Check whether the thread is blocked in resume() */
316 if (in_sched_functions(tsk
->thread
.pc
))
317 return ((unsigned long *)tsk
->thread
.fp
)[2];
319 return tsk
->thread
.pc
;
322 int elf_check_arch(const struct elf32_hdr
*hdr
)
324 unsigned long hsr0
= __get_HSR(0);
325 unsigned long psr
= __get_PSR();
327 if (hdr
->e_machine
!= EM_FRV
)
330 switch (hdr
->e_flags
& EF_FRV_GPR_MASK
) {
332 if ((hsr0
& HSR0_GRN
) == HSR0_GRN_32
)
341 switch (hdr
->e_flags
& EF_FRV_FPR_MASK
) {
343 if ((hsr0
& HSR0_FRN
) == HSR0_FRN_32
)
346 case EF_FRV_FPR_NONE
:
353 if ((hdr
->e_flags
& EF_FRV_MULADD
) == EF_FRV_MULADD
)
354 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
355 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
358 switch (hdr
->e_flags
& EF_FRV_CPU_MASK
) {
359 case EF_FRV_CPU_GENERIC
:
361 case EF_FRV_CPU_FR300
:
362 case EF_FRV_CPU_SIMPLE
:
363 case EF_FRV_CPU_TOMCAT
:
366 case EF_FRV_CPU_FR400
:
367 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR401
&&
368 PSR_IMPLE(psr
) != PSR_IMPLE_FR405
&&
369 PSR_IMPLE(psr
) != PSR_IMPLE_FR451
&&
370 PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)
373 case EF_FRV_CPU_FR450
:
374 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR451
)
377 case EF_FRV_CPU_FR500
:
378 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR501
)
381 case EF_FRV_CPU_FR550
:
382 if (PSR_IMPLE(psr
) != PSR_IMPLE_FR551
)