2 * File: arch/blackfin/kernel/process.c
7 * Description: Blackfin architecture-dependent process handling.
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/module.h>
31 #include <linux/smp_lock.h>
32 #include <linux/unistd.h>
33 #include <linux/user.h>
34 #include <linux/a.out.h>
36 #include <asm/blackfin.h>
37 #include <asm/uaccess.h>
42 asmlinkage
void ret_from_fork(void);
44 /* Points to the SDRAM backup memory for the stack that is currently in
45 * L1 scratchpad memory.
47 void *current_l1_stack_save
;
49 /* The number of tasks currently using a L1 stack area. The SRAM is
50 * allocated/deallocated whenever this changes from/to zero.
54 /* Start and length of the area in L1 scratchpad memory which we've allocated
58 unsigned long l1_stack_len
;
61 * Powermanagement idle function, if any..
63 void (*pm_idle
)(void) = NULL
;
64 EXPORT_SYMBOL(pm_idle
);
66 void (*pm_power_off
)(void) = NULL
;
67 EXPORT_SYMBOL(pm_power_off
);
70 * We are using a different LED from the one used to indicate timer interrupt.
72 #if defined(CONFIG_BFIN_IDLE_LED)
73 static inline void leds_switch(int flag
)
75 unsigned short tmp
= 0;
77 tmp
= bfin_read_CONFIG_BFIN_IDLE_LED_PORT();
81 tmp
&= ~CONFIG_BFIN_IDLE_LED_PIN
; /* light on */
83 tmp
|= CONFIG_BFIN_IDLE_LED_PIN
; /* light off */
85 bfin_write_CONFIG_BFIN_IDLE_LED_PORT(tmp
);
90 static inline void leds_switch(int flag
)
96 * The idle loop on BFIN
99 void default_idle(void)__attribute__((l1_text
));
100 void cpu_idle(void)__attribute__((l1_text
));
103 void default_idle(void)
105 while (!need_resched()) {
106 leds_switch(LED_OFF
);
108 if (likely(!need_resched()))
109 idle_with_irq_disabled();
115 void (*idle
)(void) = default_idle
;
118 * The idle thread. There's no useful work to be
119 * done, so just try to conserve power and have a
120 * low exit latency (ie sit in a loop waiting for
121 * somebody to say that they'd like to reschedule)
125 /* endless idle loop with no priority at all */
128 preempt_enable_no_resched();
134 void machine_restart(char *__unused
)
136 #if defined(CONFIG_BLKFIN_CACHE)
137 bfin_write_IMEM_CONTROL(0x01);
141 /* Dont do anything till the reset occurs */
147 void machine_halt(void)
150 asm volatile ("idle");
153 void machine_power_off(void)
156 asm volatile ("idle");
159 void show_regs(struct pt_regs
*regs
)
161 printk(KERN_NOTICE
"\n");
163 "PC: %08lu Status: %04lu SysStatus: %04lu RETS: %08lu\n",
164 regs
->pc
, regs
->astat
, regs
->seqstat
, regs
->rets
);
166 "A0.x: %08lx A0.w: %08lx A1.x: %08lx A1.w: %08lx\n",
167 regs
->a0x
, regs
->a0w
, regs
->a1x
, regs
->a1w
);
168 printk(KERN_NOTICE
"P0: %08lx P1: %08lx P2: %08lx P3: %08lx\n",
169 regs
->p0
, regs
->p1
, regs
->p2
, regs
->p3
);
170 printk(KERN_NOTICE
"P4: %08lx P5: %08lx\n", regs
->p4
, regs
->p5
);
171 printk(KERN_NOTICE
"R0: %08lx R1: %08lx R2: %08lx R3: %08lx\n",
172 regs
->r0
, regs
->r1
, regs
->r2
, regs
->r3
);
173 printk(KERN_NOTICE
"R4: %08lx R5: %08lx R6: %08lx R7: %08lx\n",
174 regs
->r4
, regs
->r5
, regs
->r6
, regs
->r7
);
177 printk("USP: %08lx\n", rdusp());
180 /* Fill in the fpu structure for a core dump. */
182 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
* fpregs
)
188 * This gets run with P1 containing the
189 * function to call, and R1 containing
190 * the "args". Note P0 is clobbered on the way here.
192 void kernel_thread_helper(void);
193 __asm__(".section .text\n"
195 "_kernel_thread_helper:\n\t"
197 "\tr0 = r1;\n\t" "\tcall (p1);\n\t" "\tcall _do_exit;\n" ".previous");
200 * Create a kernel thread.
202 pid_t
kernel_thread(int (*fn
) (void *), void *arg
, unsigned long flags
)
206 memset(®s
, 0, sizeof(regs
));
208 regs
.r1
= (unsigned long)arg
;
209 regs
.p1
= (unsigned long)fn
;
210 regs
.pc
= (unsigned long)kernel_thread_helper
;
212 /* Set bit 2 to tell ret_from_fork we should be returning to kernel
215 __asm__
__volatile__("%0 = syscfg;":"=da"(regs
.syscfg
):);
216 return do_fork(flags
| CLONE_VM
| CLONE_UNTRACED
, 0, ®s
, 0, NULL
,
220 void flush_thread(void)
224 asmlinkage
int bfin_vfork(struct pt_regs
*regs
)
226 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, rdusp(), regs
, 0, NULL
,
230 asmlinkage
int bfin_clone(struct pt_regs
*regs
)
232 unsigned long clone_flags
;
235 /* syscall2 puts clone_flags in r0 and usp in r1 */
236 clone_flags
= regs
->r0
;
242 return do_fork(clone_flags
, newsp
, regs
, 0, NULL
, NULL
);
246 copy_thread(int nr
, unsigned long clone_flags
,
247 unsigned long usp
, unsigned long topstk
,
248 struct task_struct
*p
, struct pt_regs
*regs
)
250 struct pt_regs
*childregs
;
252 childregs
= (struct pt_regs
*) (task_stack_page(p
) + THREAD_SIZE
) - 1;
257 p
->thread
.ksp
= (unsigned long)childregs
;
258 p
->thread
.pc
= (unsigned long)ret_from_fork
;
264 * fill in the user structure for a core dump..
266 void dump_thread(struct pt_regs
*regs
, struct user
*dump
)
268 dump
->magic
= CMAGIC
;
269 dump
->start_code
= 0;
270 dump
->start_stack
= rdusp() & ~(PAGE_SIZE
- 1);
271 dump
->u_tsize
= ((unsigned long)current
->mm
->end_code
) >> PAGE_SHIFT
;
272 dump
->u_dsize
= ((unsigned long)(current
->mm
->brk
+
273 (PAGE_SIZE
- 1))) >> PAGE_SHIFT
;
274 dump
->u_dsize
-= dump
->u_tsize
;
277 if (dump
->start_stack
< TASK_SIZE
)
279 ((unsigned long)(TASK_SIZE
-
280 dump
->start_stack
)) >> PAGE_SHIFT
;
282 dump
->u_ar0
= (struct user_regs_struct
*)((int)&dump
->regs
- (int)dump
);
284 dump
->regs
.r0
= regs
->r0
;
285 dump
->regs
.r1
= regs
->r1
;
286 dump
->regs
.r2
= regs
->r2
;
287 dump
->regs
.r3
= regs
->r3
;
288 dump
->regs
.r4
= regs
->r4
;
289 dump
->regs
.r5
= regs
->r5
;
290 dump
->regs
.r6
= regs
->r6
;
291 dump
->regs
.r7
= regs
->r7
;
292 dump
->regs
.p0
= regs
->p0
;
293 dump
->regs
.p1
= regs
->p1
;
294 dump
->regs
.p2
= regs
->p2
;
295 dump
->regs
.p3
= regs
->p3
;
296 dump
->regs
.p4
= regs
->p4
;
297 dump
->regs
.p5
= regs
->p5
;
298 dump
->regs
.orig_p0
= regs
->orig_p0
;
299 dump
->regs
.a0w
= regs
->a0w
;
300 dump
->regs
.a1w
= regs
->a1w
;
301 dump
->regs
.a0x
= regs
->a0x
;
302 dump
->regs
.a1x
= regs
->a1x
;
303 dump
->regs
.rets
= regs
->rets
;
304 dump
->regs
.astat
= regs
->astat
;
305 dump
->regs
.pc
= regs
->pc
;
309 * sys_execve() executes a new program.
312 asmlinkage
int sys_execve(char *name
, char **argv
, char **envp
)
316 struct pt_regs
*regs
= (struct pt_regs
*)((&name
) + 6);
319 filename
= getname(name
);
320 error
= PTR_ERR(filename
);
321 if (IS_ERR(filename
))
323 error
= do_execve(filename
, argv
, envp
, regs
);
330 unsigned long get_wchan(struct task_struct
*p
)
332 unsigned long fp
, pc
;
333 unsigned long stack_page
;
335 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
338 stack_page
= (unsigned long)p
;
341 if (fp
< stack_page
+ sizeof(struct thread_info
) ||
342 fp
>= 8184 + stack_page
)
344 pc
= ((unsigned long *)fp
)[1];
345 if (!in_sched_functions(pc
))
347 fp
= *(unsigned long *)fp
;
349 while (count
++ < 16);
353 #if defined(CONFIG_ACCESS_CHECK)
354 int _access_ok(unsigned long addr
, unsigned long size
)
357 if (addr
> (addr
+ size
))
359 if (segment_eq(get_fs(),KERNEL_DS
))
361 #ifdef CONFIG_MTD_UCLINUX
362 if (addr
>= memory_start
&& (addr
+ size
) <= memory_end
)
364 if (addr
>= memory_mtd_end
&& (addr
+ size
) <= physical_mem_end
)
367 if (addr
>= memory_start
&& (addr
+ size
) <= physical_mem_end
)
370 if (addr
>= (unsigned long)__init_begin
&&
371 addr
+ size
<= (unsigned long)__init_end
)
373 if (addr
>= L1_SCRATCH_START
374 && addr
+ size
<= L1_SCRATCH_START
+ L1_SCRATCH_LENGTH
)
376 #if L1_CODE_LENGTH != 0
377 if (addr
>= L1_CODE_START
+ (_etext_l1
- _stext_l1
)
378 && addr
+ size
<= L1_CODE_START
+ L1_CODE_LENGTH
)
381 #if L1_DATA_A_LENGTH != 0
382 if (addr
>= L1_DATA_A_START
+ (_ebss_l1
- _sdata_l1
)
383 && addr
+ size
<= L1_DATA_A_START
+ L1_DATA_A_LENGTH
)
386 #if L1_DATA_B_LENGTH != 0
387 if (addr
>= L1_DATA_B_START
388 && addr
+ size
<= L1_DATA_B_START
+ L1_DATA_B_LENGTH
)
393 EXPORT_SYMBOL(_access_ok
);
394 #endif /* CONFIG_ACCESS_CHECK */