diff options
Diffstat (limited to 'arch/arm26/kernel/process.c')
-rw-r--r-- | arch/arm26/kernel/process.c | 401 |
1 files changed, 401 insertions, 0 deletions
diff --git a/arch/arm26/kernel/process.c b/arch/arm26/kernel/process.c new file mode 100644 index 000000000000..46aea6ac194d --- /dev/null +++ b/arch/arm26/kernel/process.c | |||
@@ -0,0 +1,401 @@ | |||
1 | /* | ||
2 | * linux/arch/arm26/kernel/process.c | ||
3 | * | ||
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 | ||
7 | * | ||
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. | ||
11 | */ | ||
12 | #include <stdarg.h> | ||
13 | |||
14 | #include <linux/config.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/mm.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> | ||
29 | |||
30 | #include <asm/system.h> | ||
31 | #include <asm/io.h> | ||
32 | #include <asm/leds.h> | ||
33 | #include <asm/processor.h> | ||
34 | #include <asm/uaccess.h> | ||
35 | |||
36 | extern const char *processor_modes[]; | ||
37 | extern void setup_mm_for_reboot(char mode); | ||
38 | |||
39 | static volatile int hlt_counter; | ||
40 | |||
41 | void disable_hlt(void) | ||
42 | { | ||
43 | hlt_counter++; | ||
44 | } | ||
45 | |||
46 | EXPORT_SYMBOL(disable_hlt); | ||
47 | |||
48 | void enable_hlt(void) | ||
49 | { | ||
50 | hlt_counter--; | ||
51 | } | ||
52 | |||
53 | EXPORT_SYMBOL(enable_hlt); | ||
54 | |||
55 | static int __init nohlt_setup(char *__unused) | ||
56 | { | ||
57 | hlt_counter = 1; | ||
58 | return 1; | ||
59 | } | ||
60 | |||
61 | static int __init hlt_setup(char *__unused) | ||
62 | { | ||
63 | hlt_counter = 0; | ||
64 | return 1; | ||
65 | } | ||
66 | |||
67 | __setup("nohlt", nohlt_setup); | ||
68 | __setup("hlt", hlt_setup); | ||
69 | |||
70 | /* | ||
71 | * This is our default idle handler. We need to disable | ||
72 | * interrupts here to ensure we don't miss a wakeup call. | ||
73 | */ | ||
74 | void cpu_idle(void) | ||
75 | { | ||
76 | /* endless idle loop with no priority at all */ | ||
77 | preempt_disable(); | ||
78 | while (1) { | ||
79 | while (!need_resched()) { | ||
80 | local_irq_disable(); | ||
81 | if (!need_resched() && !hlt_counter) | ||
82 | local_irq_enable(); | ||
83 | } | ||
84 | } | ||
85 | schedule(); | ||
86 | } | ||
87 | |||
88 | static char reboot_mode = 'h'; | ||
89 | |||
90 | int __init reboot_setup(char *str) | ||
91 | { | ||
92 | reboot_mode = str[0]; | ||
93 | return 1; | ||
94 | } | ||
95 | |||
96 | __setup("reboot=", reboot_setup); | ||
97 | |||
98 | /* ARM26 cant do these but we still need to define them. */ | ||
99 | void machine_halt(void) | ||
100 | { | ||
101 | } | ||
102 | void machine_power_off(void) | ||
103 | { | ||
104 | } | ||
105 | |||
106 | EXPORT_SYMBOL(machine_halt); | ||
107 | EXPORT_SYMBOL(machine_power_off); | ||
108 | |||
109 | void machine_restart(char * __unused) | ||
110 | { | ||
111 | /* | ||
112 | * Clean and disable cache, and turn off interrupts | ||
113 | */ | ||
114 | cpu_proc_fin(); | ||
115 | |||
116 | /* | ||
117 | * Tell the mm system that we are going to reboot - | ||
118 | * we may need it to insert some 1:1 mappings so that | ||
119 | * soft boot works. | ||
120 | */ | ||
121 | setup_mm_for_reboot(reboot_mode); | ||
122 | |||
123 | /* | ||
124 | * copy branch instruction to reset location and call it | ||
125 | */ | ||
126 | |||
127 | *(unsigned long *)0 = *(unsigned long *)0x03800000; | ||
128 | ((void(*)(void))0)(); | ||
129 | |||
130 | /* | ||
131 | * Whoops - the architecture was unable to reboot. | ||
132 | * Tell the user! Should never happen... | ||
133 | */ | ||
134 | mdelay(1000); | ||
135 | printk("Reboot failed -- System halted\n"); | ||
136 | while (1); | ||
137 | } | ||
138 | |||
139 | EXPORT_SYMBOL(machine_restart); | ||
140 | |||
141 | void show_regs(struct pt_regs * regs) | ||
142 | { | ||
143 | unsigned long flags; | ||
144 | |||
145 | flags = condition_codes(regs); | ||
146 | |||
147 | printk("pc : [<%08lx>] lr : [<%08lx>] %s\n" | ||
148 | "sp : %08lx ip : %08lx fp : %08lx\n", | ||
149 | instruction_pointer(regs), | ||
150 | regs->ARM_lr, print_tainted(), regs->ARM_sp, | ||
151 | regs->ARM_ip, regs->ARM_fp); | ||
152 | printk("r10: %08lx r9 : %08lx r8 : %08lx\n", | ||
153 | regs->ARM_r10, regs->ARM_r9, | ||
154 | regs->ARM_r8); | ||
155 | printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n", | ||
156 | regs->ARM_r7, regs->ARM_r6, | ||
157 | regs->ARM_r5, regs->ARM_r4); | ||
158 | printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n", | ||
159 | regs->ARM_r3, regs->ARM_r2, | ||
160 | regs->ARM_r1, regs->ARM_r0); | ||
161 | printk("Flags: %c%c%c%c", | ||
162 | flags & PSR_N_BIT ? 'N' : 'n', | ||
163 | flags & PSR_Z_BIT ? 'Z' : 'z', | ||
164 | flags & PSR_C_BIT ? 'C' : 'c', | ||
165 | flags & PSR_V_BIT ? 'V' : 'v'); | ||
166 | printk(" IRQs o%s FIQs o%s Mode %s Segment %s\n", | ||
167 | interrupts_enabled(regs) ? "n" : "ff", | ||
168 | fast_interrupts_enabled(regs) ? "n" : "ff", | ||
169 | processor_modes[processor_mode(regs)], | ||
170 | get_fs() == get_ds() ? "kernel" : "user"); | ||
171 | } | ||
172 | |||
173 | void show_fpregs(struct user_fp *regs) | ||
174 | { | ||
175 | int i; | ||
176 | |||
177 | for (i = 0; i < 8; i++) { | ||
178 | unsigned long *p; | ||
179 | char type; | ||
180 | |||
181 | p = (unsigned long *)(regs->fpregs + i); | ||
182 | |||
183 | switch (regs->ftype[i]) { | ||
184 | case 1: type = 'f'; break; | ||
185 | case 2: type = 'd'; break; | ||
186 | case 3: type = 'e'; break; | ||
187 | default: type = '?'; break; | ||
188 | } | ||
189 | if (regs->init_flag) | ||
190 | type = '?'; | ||
191 | |||
192 | printk(" f%d(%c): %08lx %08lx %08lx%c", | ||
193 | i, type, p[0], p[1], p[2], i & 1 ? '\n' : ' '); | ||
194 | } | ||
195 | |||
196 | |||
197 | printk("FPSR: %08lx FPCR: %08lx\n", | ||
198 | (unsigned long)regs->fpsr, | ||
199 | (unsigned long)regs->fpcr); | ||
200 | } | ||
201 | |||
202 | /* | ||
203 | * Task structure and kernel stack allocation. | ||
204 | */ | ||
205 | static unsigned long *thread_info_head; | ||
206 | static unsigned int nr_thread_info; | ||
207 | |||
208 | extern unsigned long get_page_8k(int priority); | ||
209 | extern void free_page_8k(unsigned long page); | ||
210 | |||
211 | // FIXME - is this valid? | ||
212 | #define EXTRA_TASK_STRUCT 0 | ||
213 | #define ll_alloc_task_struct() ((struct thread_info *)get_page_8k(GFP_KERNEL)) | ||
214 | #define ll_free_task_struct(p) free_page_8k((unsigned long)(p)) | ||
215 | |||
216 | //FIXME - do we use *task param below looks like we dont, which is ok? | ||
217 | //FIXME - if EXTRA_TASK_STRUCT is zero we can optimise the below away permanently. *IF* its supposed to be zero. | ||
218 | struct thread_info *alloc_thread_info(struct task_struct *task) | ||
219 | { | ||
220 | struct thread_info *thread = NULL; | ||
221 | |||
222 | if (EXTRA_TASK_STRUCT) { | ||
223 | unsigned long *p = thread_info_head; | ||
224 | |||
225 | if (p) { | ||
226 | thread_info_head = (unsigned long *)p[0]; | ||
227 | nr_thread_info -= 1; | ||
228 | } | ||
229 | thread = (struct thread_info *)p; | ||
230 | } | ||
231 | |||
232 | if (!thread) | ||
233 | thread = ll_alloc_task_struct(); | ||
234 | |||
235 | #ifdef CONFIG_MAGIC_SYSRQ | ||
236 | /* | ||
237 | * The stack must be cleared if you want SYSRQ-T to | ||
238 | * give sensible stack usage information | ||
239 | */ | ||
240 | if (thread) { | ||
241 | char *p = (char *)thread; | ||
242 | memzero(p+KERNEL_STACK_SIZE, KERNEL_STACK_SIZE); | ||
243 | } | ||
244 | #endif | ||
245 | return thread; | ||
246 | } | ||
247 | |||
248 | void free_thread_info(struct thread_info *thread) | ||
249 | { | ||
250 | if (EXTRA_TASK_STRUCT && nr_thread_info < EXTRA_TASK_STRUCT) { | ||
251 | unsigned long *p = (unsigned long *)thread; | ||
252 | p[0] = (unsigned long)thread_info_head; | ||
253 | thread_info_head = p; | ||
254 | nr_thread_info += 1; | ||
255 | } else | ||
256 | ll_free_task_struct(thread); | ||
257 | } | ||
258 | |||
259 | /* | ||
260 | * Free current thread data structures etc.. | ||
261 | */ | ||
262 | void exit_thread(void) | ||
263 | { | ||
264 | } | ||
265 | |||
266 | void flush_thread(void) | ||
267 | { | ||
268 | struct thread_info *thread = current_thread_info(); | ||
269 | struct task_struct *tsk = current; | ||
270 | |||
271 | memset(&tsk->thread.debug, 0, sizeof(struct debug_info)); | ||
272 | memset(&thread->fpstate, 0, sizeof(union fp_state)); | ||
273 | |||
274 | clear_used_math(); | ||
275 | } | ||
276 | |||
277 | void release_thread(struct task_struct *dead_task) | ||
278 | { | ||
279 | } | ||
280 | |||
281 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); | ||
282 | |||
283 | int | ||
284 | copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start, | ||
285 | unsigned long unused, struct task_struct *p, struct pt_regs *regs) | ||
286 | { | ||
287 | struct thread_info *thread = p->thread_info; | ||
288 | struct pt_regs *childregs; | ||
289 | |||
290 | childregs = __get_user_regs(thread); | ||
291 | *childregs = *regs; | ||
292 | childregs->ARM_r0 = 0; | ||
293 | childregs->ARM_sp = stack_start; | ||
294 | |||
295 | memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save)); | ||
296 | thread->cpu_context.sp = (unsigned long)childregs; | ||
297 | thread->cpu_context.pc = (unsigned long)ret_from_fork | MODE_SVC26 | PSR_I_BIT; | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | /* | ||
303 | * fill in the fpe structure for a core dump... | ||
304 | */ | ||
305 | int dump_fpu (struct pt_regs *regs, struct user_fp *fp) | ||
306 | { | ||
307 | struct thread_info *thread = current_thread_info(); | ||
308 | int used_math = !!used_math(); | ||
309 | |||
310 | if (used_math) | ||
311 | memcpy(fp, &thread->fpstate.soft, sizeof (*fp)); | ||
312 | |||
313 | return used_math; | ||
314 | } | ||
315 | |||
316 | /* | ||
317 | * fill in the user structure for a core dump.. | ||
318 | */ | ||
319 | void dump_thread(struct pt_regs * regs, struct user * dump) | ||
320 | { | ||
321 | struct task_struct *tsk = current; | ||
322 | |||
323 | dump->magic = CMAGIC; | ||
324 | dump->start_code = tsk->mm->start_code; | ||
325 | dump->start_stack = regs->ARM_sp & ~(PAGE_SIZE - 1); | ||
326 | |||
327 | dump->u_tsize = (tsk->mm->end_code - tsk->mm->start_code) >> PAGE_SHIFT; | ||
328 | dump->u_dsize = (tsk->mm->brk - tsk->mm->start_data + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
329 | dump->u_ssize = 0; | ||
330 | |||
331 | dump->u_debugreg[0] = tsk->thread.debug.bp[0].address; | ||
332 | dump->u_debugreg[1] = tsk->thread.debug.bp[1].address; | ||
333 | dump->u_debugreg[2] = tsk->thread.debug.bp[0].insn; | ||
334 | dump->u_debugreg[3] = tsk->thread.debug.bp[1].insn; | ||
335 | dump->u_debugreg[4] = tsk->thread.debug.nsaved; | ||
336 | |||
337 | if (dump->start_stack < 0x04000000) | ||
338 | dump->u_ssize = (0x04000000 - dump->start_stack) >> PAGE_SHIFT; | ||
339 | |||
340 | dump->regs = *regs; | ||
341 | dump->u_fpvalid = dump_fpu (regs, &dump->u_fp); | ||
342 | } | ||
343 | |||
344 | /* | ||
345 | * Shuffle the argument into the correct register before calling the | ||
346 | * thread function. r1 is the thread argument, r2 is the pointer to | ||
347 | * the thread function, and r3 points to the exit function. | ||
348 | * FIXME - make sure this is right - the older code used to zero fp | ||
349 | * and cause the parent to call sys_exit (do_exit in this version) | ||
350 | */ | ||
351 | extern void kernel_thread_helper(void); | ||
352 | |||
353 | asm( ".section .text\n" | ||
354 | " .align\n" | ||
355 | " .type kernel_thread_helper, #function\n" | ||
356 | "kernel_thread_helper:\n" | ||
357 | " mov r0, r1\n" | ||
358 | " mov lr, r3\n" | ||
359 | " mov pc, r2\n" | ||
360 | " .size kernel_thread_helper, . - kernel_thread_helper\n" | ||
361 | " .previous"); | ||
362 | |||
363 | /* | ||
364 | * Create a kernel thread. | ||
365 | */ | ||
366 | pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) | ||
367 | { | ||
368 | struct pt_regs regs; | ||
369 | |||
370 | memset(®s, 0, sizeof(regs)); | ||
371 | |||
372 | regs.ARM_r1 = (unsigned long)arg; | ||
373 | regs.ARM_r2 = (unsigned long)fn; | ||
374 | regs.ARM_r3 = (unsigned long)do_exit; | ||
375 | regs.ARM_pc = (unsigned long)kernel_thread_helper | MODE_SVC26; | ||
376 | |||
377 | return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, ®s, 0, NULL, NULL); | ||
378 | } | ||
379 | EXPORT_SYMBOL(kernel_thread); | ||
380 | |||
381 | |||
382 | unsigned long get_wchan(struct task_struct *p) | ||
383 | { | ||
384 | unsigned long fp, lr; | ||
385 | unsigned long stack_page; | ||
386 | int count = 0; | ||
387 | if (!p || p == current || p->state == TASK_RUNNING) | ||
388 | return 0; | ||
389 | |||
390 | stack_page = 4096 + (unsigned long)p; | ||
391 | fp = thread_saved_fp(p); | ||
392 | do { | ||
393 | if (fp < stack_page || fp > 4092+stack_page) | ||
394 | return 0; | ||
395 | lr = pc_pointer (((unsigned long *)fp)[-1]); | ||
396 | if (!in_sched_functions(lr)) | ||
397 | return lr; | ||
398 | fp = *(unsigned long *) (fp - 12); | ||
399 | } while (count ++ < 16); | ||
400 | return 0; | ||
401 | } | ||