2 * linux/arch/arm26/kernel/process.c
4 * Copyright (C) 2003 Ian Molton - adapted for ARM26
5 * Copyright (C) 1996-2000 Russell King - Converted to ARM.
6 * Origional Copyright (C) 1995 Linus Torvalds
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.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/a.out.h>
25 #include <linux/delay.h>
26 #include <linux/reboot.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
30 #include <asm/system.h>
33 #include <asm/processor.h>
34 #include <asm/uaccess.h>
36 extern const char *processor_modes
[];
37 extern void setup_mm_for_reboot(char mode
);
39 static volatile int hlt_counter
;
41 void disable_hlt(void)
46 EXPORT_SYMBOL(disable_hlt
);
53 EXPORT_SYMBOL(enable_hlt
);
55 static int __init
nohlt_setup(char *__unused
)
61 static int __init
hlt_setup(char *__unused
)
67 __setup("nohlt", nohlt_setup
);
68 __setup("hlt", hlt_setup
);
71 * This is our default idle handler. We need to disable
72 * interrupts here to ensure we don't miss a wakeup call.
76 /* endless idle loop with no priority at all */
79 while (!need_resched()) {
81 if (!need_resched() && !hlt_counter
)
88 static char reboot_mode
= 'h';
90 int __init
reboot_setup(char *str
)
96 __setup("reboot=", reboot_setup
);
98 /* ARM26 cant do these but we still need to define them. */
99 void machine_halt(void)
102 void machine_power_off(void)
106 void machine_restart(char * __unused
)
109 * Clean and disable cache, and turn off interrupts
114 * Tell the mm system that we are going to reboot -
115 * we may need it to insert some 1:1 mappings so that
118 setup_mm_for_reboot(reboot_mode
);
121 * copy branch instruction to reset location and call it
124 *(unsigned long *)0 = *(unsigned long *)0x03800000;
125 ((void(*)(void))0)();
128 * Whoops - the architecture was unable to reboot.
129 * Tell the user! Should never happen...
132 printk("Reboot failed -- System halted\n");
136 void show_regs(struct pt_regs
* regs
)
140 flags
= condition_codes(regs
);
142 printk("pc : [<%08lx>] lr : [<%08lx>] %s\n"
143 "sp : %08lx ip : %08lx fp : %08lx\n",
144 instruction_pointer(regs
),
145 regs
->ARM_lr
, print_tainted(), regs
->ARM_sp
,
146 regs
->ARM_ip
, regs
->ARM_fp
);
147 printk("r10: %08lx r9 : %08lx r8 : %08lx\n",
148 regs
->ARM_r10
, regs
->ARM_r9
,
150 printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
151 regs
->ARM_r7
, regs
->ARM_r6
,
152 regs
->ARM_r5
, regs
->ARM_r4
);
153 printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
154 regs
->ARM_r3
, regs
->ARM_r2
,
155 regs
->ARM_r1
, regs
->ARM_r0
);
156 printk("Flags: %c%c%c%c",
157 flags
& PSR_N_BIT
? 'N' : 'n',
158 flags
& PSR_Z_BIT
? 'Z' : 'z',
159 flags
& PSR_C_BIT
? 'C' : 'c',
160 flags
& PSR_V_BIT
? 'V' : 'v');
161 printk(" IRQs o%s FIQs o%s Mode %s Segment %s\n",
162 interrupts_enabled(regs
) ? "n" : "ff",
163 fast_interrupts_enabled(regs
) ? "n" : "ff",
164 processor_modes
[processor_mode(regs
)],
165 get_fs() == get_ds() ? "kernel" : "user");
168 void show_fpregs(struct user_fp
*regs
)
172 for (i
= 0; i
< 8; i
++) {
176 p
= (unsigned long *)(regs
->fpregs
+ i
);
178 switch (regs
->ftype
[i
]) {
179 case 1: type
= 'f'; break;
180 case 2: type
= 'd'; break;
181 case 3: type
= 'e'; break;
182 default: type
= '?'; break;
187 printk(" f%d(%c): %08lx %08lx %08lx%c",
188 i
, type
, p
[0], p
[1], p
[2], i
& 1 ? '\n' : ' ');
192 printk("FPSR: %08lx FPCR: %08lx\n",
193 (unsigned long)regs
->fpsr
,
194 (unsigned long)regs
->fpcr
);
198 * Task structure and kernel stack allocation.
200 static unsigned long *thread_info_head
;
201 static unsigned int nr_thread_info
;
203 extern unsigned long get_page_8k(int priority
);
204 extern void free_page_8k(unsigned long page
);
206 // FIXME - is this valid?
207 #define EXTRA_TASK_STRUCT 0
208 #define ll_alloc_task_struct() ((struct thread_info *)get_page_8k(GFP_KERNEL))
209 #define ll_free_task_struct(p) free_page_8k((unsigned long)(p))
211 //FIXME - do we use *task param below looks like we dont, which is ok?
212 //FIXME - if EXTRA_TASK_STRUCT is zero we can optimise the below away permanently. *IF* its supposed to be zero.
213 struct thread_info
*alloc_thread_info(struct task_struct
*task
)
215 struct thread_info
*thread
= NULL
;
217 if (EXTRA_TASK_STRUCT
) {
218 unsigned long *p
= thread_info_head
;
221 thread_info_head
= (unsigned long *)p
[0];
224 thread
= (struct thread_info
*)p
;
228 thread
= ll_alloc_task_struct();
230 #ifdef CONFIG_MAGIC_SYSRQ
232 * The stack must be cleared if you want SYSRQ-T to
233 * give sensible stack usage information
236 char *p
= (char *)thread
;
237 memzero(p
+KERNEL_STACK_SIZE
, KERNEL_STACK_SIZE
);
243 void free_thread_info(struct thread_info
*thread
)
245 if (EXTRA_TASK_STRUCT
&& nr_thread_info
< EXTRA_TASK_STRUCT
) {
246 unsigned long *p
= (unsigned long *)thread
;
247 p
[0] = (unsigned long)thread_info_head
;
248 thread_info_head
= p
;
251 ll_free_task_struct(thread
);
255 * Free current thread data structures etc..
257 void exit_thread(void)
261 void flush_thread(void)
263 struct thread_info
*thread
= current_thread_info();
264 struct task_struct
*tsk
= current
;
266 memset(&tsk
->thread
.debug
, 0, sizeof(struct debug_info
));
267 memset(&thread
->fpstate
, 0, sizeof(union fp_state
));
272 void release_thread(struct task_struct
*dead_task
)
276 asmlinkage
void ret_from_fork(void) __asm__("ret_from_fork");
279 copy_thread(int nr
, unsigned long clone_flags
, unsigned long stack_start
,
280 unsigned long unused
, struct task_struct
*p
, struct pt_regs
*regs
)
282 struct thread_info
*thread
= p
->thread_info
;
283 struct pt_regs
*childregs
;
285 childregs
= __get_user_regs(thread
);
287 childregs
->ARM_r0
= 0;
288 childregs
->ARM_sp
= stack_start
;
290 memset(&thread
->cpu_context
, 0, sizeof(struct cpu_context_save
));
291 thread
->cpu_context
.sp
= (unsigned long)childregs
;
292 thread
->cpu_context
.pc
= (unsigned long)ret_from_fork
| MODE_SVC26
| PSR_I_BIT
;
298 * fill in the fpe structure for a core dump...
300 int dump_fpu (struct pt_regs
*regs
, struct user_fp
*fp
)
302 struct thread_info
*thread
= current_thread_info();
303 int used_math
= !!used_math();
306 memcpy(fp
, &thread
->fpstate
.soft
, sizeof (*fp
));
312 * fill in the user structure for a core dump..
314 void dump_thread(struct pt_regs
* regs
, struct user
* dump
)
316 struct task_struct
*tsk
= current
;
318 dump
->magic
= CMAGIC
;
319 dump
->start_code
= tsk
->mm
->start_code
;
320 dump
->start_stack
= regs
->ARM_sp
& ~(PAGE_SIZE
- 1);
322 dump
->u_tsize
= (tsk
->mm
->end_code
- tsk
->mm
->start_code
) >> PAGE_SHIFT
;
323 dump
->u_dsize
= (tsk
->mm
->brk
- tsk
->mm
->start_data
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
326 dump
->u_debugreg
[0] = tsk
->thread
.debug
.bp
[0].address
;
327 dump
->u_debugreg
[1] = tsk
->thread
.debug
.bp
[1].address
;
328 dump
->u_debugreg
[2] = tsk
->thread
.debug
.bp
[0].insn
;
329 dump
->u_debugreg
[3] = tsk
->thread
.debug
.bp
[1].insn
;
330 dump
->u_debugreg
[4] = tsk
->thread
.debug
.nsaved
;
332 if (dump
->start_stack
< 0x04000000)
333 dump
->u_ssize
= (0x04000000 - dump
->start_stack
) >> PAGE_SHIFT
;
336 dump
->u_fpvalid
= dump_fpu (regs
, &dump
->u_fp
);
340 * Shuffle the argument into the correct register before calling the
341 * thread function. r1 is the thread argument, r2 is the pointer to
342 * the thread function, and r3 points to the exit function.
343 * FIXME - make sure this is right - the older code used to zero fp
344 * and cause the parent to call sys_exit (do_exit in this version)
346 extern void kernel_thread_helper(void);
348 asm( ".section .text\n"
350 " .type kernel_thread_helper, #function\n"
351 "kernel_thread_helper:\n"
355 " .size kernel_thread_helper, . - kernel_thread_helper\n"
359 * Create a kernel thread.
361 pid_t
kernel_thread(int (*fn
)(void *), void *arg
, unsigned long flags
)
365 memset(®s
, 0, sizeof(regs
));
367 regs
.ARM_r1
= (unsigned long)arg
;
368 regs
.ARM_r2
= (unsigned long)fn
;
369 regs
.ARM_r3
= (unsigned long)do_exit
;
370 regs
.ARM_pc
= (unsigned long)kernel_thread_helper
| MODE_SVC26
;
372 return do_fork(flags
|CLONE_VM
|CLONE_UNTRACED
, 0, ®s
, 0, NULL
, NULL
);
374 EXPORT_SYMBOL(kernel_thread
);
377 unsigned long get_wchan(struct task_struct
*p
)
379 unsigned long fp
, lr
;
380 unsigned long stack_page
;
382 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
385 stack_page
= 4096 + (unsigned long)p
;
386 fp
= thread_saved_fp(p
);
388 if (fp
< stack_page
|| fp
> 4092+stack_page
)
390 lr
= pc_pointer (((unsigned long *)fp
)[-1]);
391 if (!in_sched_functions(lr
))
393 fp
= *(unsigned long *) (fp
- 12);
394 } while (count
++ < 16);