2 * linux/arch/arm/kernel/process.c
4 * Copyright (C) 1996-2000 Russell King - Converted to ARM.
5 * Origional Copyright (C) 1995 Linus Torvalds
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
18 #include <linux/stddef.h>
19 #include <linux/unistd.h>
20 #include <linux/ptrace.h>
21 #include <linux/slab.h>
22 #include <linux/user.h>
23 #include <linux/a.out.h>
24 #include <linux/delay.h>
25 #include <linux/reboot.h>
26 #include <linux/interrupt.h>
27 #include <linux/kallsyms.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 #include <asm/arch/system.h>
43 void disable_hlt(void)
53 static int __init
nohlt_setup(char *__unused
)
59 static int __init
hlt_setup(char *__unused
)
65 __setup("nohlt", nohlt_setup
);
66 __setup("hlt", hlt_setup
);
69 * The following aren't currently used.
71 void (*pm_idle
)(void);
72 void (*pm_power_off
)(void);
75 * This is our default idle handler. We need to disable
76 * interrupts here to ensure we don't miss a wakeup call.
78 void default_idle(void)
81 if (!need_resched() && !hlt_counter
)
87 * The idle thread. We try to conserve power, while trying to keep
88 * overall latency low. The architecture specific idle is passed
89 * a value to indicate the level of "idleness" of the system.
93 /* endless idle loop with no priority at all */
95 void (*idle
)(void) = pm_idle
;
99 leds_event(led_idle_start
);
100 while (!need_resched())
102 leds_event(led_idle_end
);
108 static char reboot_mode
= 'h';
110 int __init
reboot_setup(char *str
)
112 reboot_mode
= str
[0];
116 __setup("reboot=", reboot_setup
);
118 void machine_halt(void)
120 leds_event(led_halted
);
123 void machine_power_off(void)
125 leds_event(led_halted
);
130 void machine_restart(char * __unused
)
133 * Clean and disable cache, and turn off interrupts
138 * Tell the mm system that we are going to reboot -
139 * we may need it to insert some 1:1 mappings so that
142 setup_mm_for_reboot(reboot_mode
);
145 * Now call the architecture specific reboot code.
147 arch_reset(reboot_mode
);
150 * Whoops - the architecture was unable to reboot.
154 printk("Reboot failed -- System halted\n");
158 void show_regs(struct pt_regs
* regs
)
162 flags
= condition_codes(regs
);
164 print_symbol("PC is at %s\n", instruction_pointer(regs
));
165 print_symbol("LR is at %s\n", regs
->ARM_lr
);
166 printk("pc : [<%08lx>] lr : [<%08lx>] %s\n"
167 "sp : %08lx ip : %08lx fp : %08lx\n",
168 instruction_pointer(regs
),
169 regs
->ARM_lr
, print_tainted(), regs
->ARM_sp
,
170 regs
->ARM_ip
, regs
->ARM_fp
);
171 printk("r10: %08lx r9 : %08lx r8 : %08lx\n",
172 regs
->ARM_r10
, regs
->ARM_r9
,
174 printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
175 regs
->ARM_r7
, regs
->ARM_r6
,
176 regs
->ARM_r5
, regs
->ARM_r4
);
177 printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
178 regs
->ARM_r3
, regs
->ARM_r2
,
179 regs
->ARM_r1
, regs
->ARM_r0
);
180 printk("Flags: %c%c%c%c",
181 flags
& PSR_N_BIT
? 'N' : 'n',
182 flags
& PSR_Z_BIT
? 'Z' : 'z',
183 flags
& PSR_C_BIT
? 'C' : 'c',
184 flags
& PSR_V_BIT
? 'V' : 'v');
185 printk(" IRQs o%s FIQs o%s Mode %s%s Segment %s\n",
186 interrupts_enabled(regs
) ? "n" : "ff",
187 fast_interrupts_enabled(regs
) ? "n" : "ff",
188 processor_modes
[processor_mode(regs
)],
189 thumb_mode(regs
) ? " (T)" : "",
190 get_fs() == get_ds() ? "kernel" : "user");
191 #if defined(CONFIG_CPU_32)
193 unsigned int ctrl
, transbase
, dac
;
195 " mrc p15, 0, %0, c1, c0\n"
196 " mrc p15, 0, %1, c2, c0\n"
197 " mrc p15, 0, %2, c3, c0\n"
198 : "=r" (ctrl
), "=r" (transbase
), "=r" (dac
));
199 printk("Control: %04X Table: %08X DAC: %08X\n",
200 ctrl
, transbase
, dac
);
205 void show_fpregs(struct user_fp
*regs
)
209 for (i
= 0; i
< 8; i
++) {
213 p
= (unsigned long *)(regs
->fpregs
+ i
);
215 switch (regs
->ftype
[i
]) {
216 case 1: type
= 'f'; break;
217 case 2: type
= 'd'; break;
218 case 3: type
= 'e'; break;
219 default: type
= '?'; break;
224 printk(" f%d(%c): %08lx %08lx %08lx%c",
225 i
, type
, p
[0], p
[1], p
[2], i
& 1 ? '\n' : ' ');
229 printk("FPSR: %08lx FPCR: %08lx\n",
230 (unsigned long)regs
->fpsr
,
231 (unsigned long)regs
->fpcr
);
235 * Task structure and kernel stack allocation.
237 static unsigned long *thread_info_head
;
238 static unsigned int nr_thread_info
;
241 #define EXTRA_TASK_STRUCT 4
242 #define ll_alloc_task_struct() ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
243 #define ll_free_task_struct(p) free_pages((unsigned long)(p),1)
245 extern unsigned long get_page_8k(int priority
);
246 extern void free_page_8k(unsigned long page
);
248 #define EXTRA_TASK_STRUCT 0
249 #define ll_alloc_task_struct() ((struct task_struct *)get_page_8k(GFP_KERNEL))
250 #define ll_free_task_struct(p) free_page_8k((unsigned long)(p))
253 struct thread_info
*alloc_thread_info(void)
255 struct thread_info
*thread
= NULL
;
257 if (EXTRA_TASK_STRUCT
) {
258 unsigned long *p
= thread_info_head
;
261 thread_info_head
= (unsigned long *)p
[0];
264 thread
= (struct thread_info
*)p
;
268 thread
= ll_alloc_task_struct();
272 * The stack must be cleared if you want SYSRQ-T to
273 * give sensible stack usage information
276 char *p
= (char *)thread
;
277 memzero(p
+KERNEL_STACK_SIZE
, KERNEL_STACK_SIZE
);
283 void free_thread_info(struct thread_info
*thread
)
285 if (EXTRA_TASK_STRUCT
&& nr_thread_info
< EXTRA_TASK_STRUCT
) {
286 unsigned long *p
= (unsigned long *)thread
;
287 p
[0] = (unsigned long)thread_info_head
;
288 thread_info_head
= p
;
291 ll_free_task_struct(thread
);
295 * Free current thread data structures etc..
297 void exit_thread(void)
301 static void default_fp_init(union fp_state
*fp
)
303 memset(fp
, 0, sizeof(union fp_state
));
306 void (*fp_init
)(union fp_state
*) = default_fp_init
;
308 void flush_thread(void)
310 struct thread_info
*thread
= current_thread_info();
311 struct task_struct
*tsk
= current
;
315 memset(&tsk
->thread
.debug
, 0, sizeof(struct debug_info
));
316 fp_init(&thread
->fpstate
);
319 void release_thread(struct task_struct
*dead_task
)
323 asmlinkage
void ret_from_fork(void) __asm__("ret_from_fork");
326 copy_thread(int nr
, unsigned long clone_flags
, unsigned long esp
,
327 unsigned long unused
, struct task_struct
*p
, struct pt_regs
*regs
)
329 struct thread_info
*thread
= p
->thread_info
;
330 struct pt_regs
*childregs
;
332 childregs
= ((struct pt_regs
*)((unsigned long)thread
+ THREAD_SIZE
- 8)) - 1;
334 childregs
->ARM_r0
= 0;
335 childregs
->ARM_sp
= esp
;
337 memset(&thread
->cpu_context
, 0, sizeof(struct cpu_context_save
));
338 thread
->cpu_context
.sp
= (unsigned long)childregs
;
339 thread
->cpu_context
.pc
= (unsigned long)ret_from_fork
;
345 * fill in the fpe structure for a core dump...
347 int dump_fpu (struct pt_regs
*regs
, struct user_fp
*fp
)
349 struct thread_info
*thread
= current_thread_info();
350 int used_math
= current
->used_math
;
353 memcpy(fp
, &thread
->fpstate
.soft
, sizeof (*fp
));
359 * fill in the user structure for a core dump..
361 void dump_thread(struct pt_regs
* regs
, struct user
* dump
)
363 struct task_struct
*tsk
= current
;
365 dump
->magic
= CMAGIC
;
366 dump
->start_code
= tsk
->mm
->start_code
;
367 dump
->start_stack
= regs
->ARM_sp
& ~(PAGE_SIZE
- 1);
369 dump
->u_tsize
= (tsk
->mm
->end_code
- tsk
->mm
->start_code
) >> PAGE_SHIFT
;
370 dump
->u_dsize
= (tsk
->mm
->brk
- tsk
->mm
->start_data
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
373 dump
->u_debugreg
[0] = tsk
->thread
.debug
.bp
[0].address
;
374 dump
->u_debugreg
[1] = tsk
->thread
.debug
.bp
[1].address
;
375 dump
->u_debugreg
[2] = tsk
->thread
.debug
.bp
[0].insn
.arm
;
376 dump
->u_debugreg
[3] = tsk
->thread
.debug
.bp
[1].insn
.arm
;
377 dump
->u_debugreg
[4] = tsk
->thread
.debug
.nsaved
;
379 if (dump
->start_stack
< 0x04000000)
380 dump
->u_ssize
= (0x04000000 - dump
->start_stack
) >> PAGE_SHIFT
;
383 dump
->u_fpvalid
= dump_fpu (regs
, &dump
->u_fp
);
387 * This is the mechanism for creating a new kernel thread.
389 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
390 * who haven't done an "execve()") should use this: it will work within
391 * a system call from a "real" process, but the process memory space will
392 * not be free'd until both the parent and the child have exited.
394 pid_t
kernel_thread(int (*fn
)(void *), void *arg
, unsigned long flags
)
396 register unsigned int r0
asm("r0") = flags
| CLONE_VM
| CLONE_UNTRACED
;
397 register unsigned int r1
asm("r1") = 0;
398 register pid_t __ret
asm("r0");
400 __asm__
__volatile__(
401 __syscall(clone
)" @ kernel_thread sys_clone \n\
402 movs %0, r0 @ if we are the child \n\
404 mov fp, #0 @ ensure that fp is zero \n\
411 : "0" (r0
), "r" (r1
), "r" (fn
), "r" (arg
)
417 * These bracket the sleeping functions..
419 extern void scheduling_functions_start_here(void);
420 extern void scheduling_functions_end_here(void);
421 #define first_sched ((unsigned long) scheduling_functions_start_here)
422 #define last_sched ((unsigned long) scheduling_functions_end_here)
424 unsigned long get_wchan(struct task_struct
*p
)
426 unsigned long fp
, lr
;
427 unsigned long stack_page
;
429 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
432 stack_page
= 4096 + (unsigned long)p
;
433 fp
= thread_saved_fp(p
);
435 if (fp
< stack_page
|| fp
> 4092+stack_page
)
437 lr
= pc_pointer (((unsigned long *)fp
)[-1]);
438 if (lr
< first_sched
|| lr
> last_sched
)
440 fp
= *(unsigned long *) (fp
- 12);
441 } while (count
++ < 16);