]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/sh/kernel/process.c
1 /* $Id: process.c,v 1.28 2004/05/05 16:54:23 lethal Exp $
3 * linux/arch/sh/kernel/process.c
5 * Copyright (C) 1995 Linus Torvalds
7 * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
11 * This file handles the architecture-dependent parts of process handling..
14 #include <linux/module.h>
15 #include <linux/unistd.h>
17 #include <linux/elfcore.h>
18 #include <linux/a.out.h>
19 #include <linux/slab.h>
21 #include <linux/ptrace.h>
22 #include <linux/kallsyms.h>
23 #include <linux/kexec.h>
26 #include <asm/uaccess.h>
27 #include <asm/mmu_context.h>
31 static int hlt_counter
=0;
35 #define HARD_IDLE_TIMEOUT (HZ / 3)
37 void (*pm_idle
)(void);
39 void (*pm_power_off
)(void);
40 EXPORT_SYMBOL(pm_power_off
);
42 void disable_hlt(void)
47 EXPORT_SYMBOL(disable_hlt
);
54 EXPORT_SYMBOL(enable_hlt
);
56 void default_idle(void)
66 /* endless idle loop with no priority at all */
68 void (*idle
)(void) = pm_idle
;
73 while (!need_resched())
76 preempt_enable_no_resched();
82 void machine_restart(char * __unused
)
84 /* SR.BL=1 and invoke address error to let CPU reset (manual reset) */
85 asm volatile("ldc %0, sr\n\t"
86 "mov.l @%1, %0" : : "r" (0x10000000), "r" (0x80000001));
89 void machine_halt(void)
97 void machine_power_off(void)
103 void show_regs(struct pt_regs
* regs
)
106 printk("Pid : %d, Comm: %20s\n", current
->pid
, current
->comm
);
107 print_symbol("PC is at %s\n", regs
->pc
);
108 printk("PC : %08lx SP : %08lx SR : %08lx ",
109 regs
->pc
, regs
->regs
[15], regs
->sr
);
111 printk("TEA : %08x ", ctrl_inl(MMU_TEA
));
115 printk("%s\n", print_tainted());
117 printk("R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
118 regs
->regs
[0],regs
->regs
[1],
119 regs
->regs
[2],regs
->regs
[3]);
120 printk("R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
121 regs
->regs
[4],regs
->regs
[5],
122 regs
->regs
[6],regs
->regs
[7]);
123 printk("R8 : %08lx R9 : %08lx R10 : %08lx R11 : %08lx\n",
124 regs
->regs
[8],regs
->regs
[9],
125 regs
->regs
[10],regs
->regs
[11]);
126 printk("R12 : %08lx R13 : %08lx R14 : %08lx\n",
127 regs
->regs
[12],regs
->regs
[13],
129 printk("MACH: %08lx MACL: %08lx GBR : %08lx PR : %08lx\n",
130 regs
->mach
, regs
->macl
, regs
->gbr
, regs
->pr
);
133 * If we're in kernel mode, dump the stack too..
135 if (!user_mode(regs
)) {
136 extern void show_task(unsigned long *sp
);
137 unsigned long sp
= regs
->regs
[15];
139 show_task((unsigned long *)sp
);
144 * Create a kernel thread
148 * This is the mechanism for creating a new kernel thread.
151 extern void kernel_thread_helper(void);
153 "kernel_thread_helper:\n\t"
162 int kernel_thread(int (*fn
)(void *), void * arg
, unsigned long flags
)
163 { /* Don't use this in BL=1(cli). Or else, CPU resets! */
166 memset(®s
, 0, sizeof(regs
));
167 regs
.regs
[4] = (unsigned long) arg
;
168 regs
.regs
[5] = (unsigned long) fn
;
170 regs
.pc
= (unsigned long) kernel_thread_helper
;
173 /* Ok, create the new process.. */
174 return do_fork(flags
| CLONE_VM
| CLONE_UNTRACED
, 0, ®s
, 0, NULL
, NULL
);
178 * Free current thread data structures etc..
180 void exit_thread(void)
182 if (current
->thread
.ubc_pc
) {
183 current
->thread
.ubc_pc
= 0;
188 void flush_thread(void)
190 #if defined(CONFIG_SH_FPU)
191 struct task_struct
*tsk
= current
;
192 /* Forget lazy FPU state */
193 clear_fpu(tsk
, task_pt_regs(tsk
));
198 void release_thread(struct task_struct
*dead_task
)
203 /* Fill in the fpu structure for a core dump.. */
204 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
208 #if defined(CONFIG_SH_FPU)
209 struct task_struct
*tsk
= current
;
211 fpvalid
= !!tsk_used_math(tsk
);
213 unlazy_fpu(tsk
, regs
);
214 memcpy(fpu
, &tsk
->thread
.fpu
.hard
, sizeof(*fpu
));
222 * Capture the user space registers if the task is not running (in user space)
224 int dump_task_regs(struct task_struct
*tsk
, elf_gregset_t
*regs
)
226 struct pt_regs ptregs
;
228 ptregs
= *task_pt_regs(tsk
);
229 elf_core_copy_regs(regs
, &ptregs
);
235 dump_task_fpu (struct task_struct
*tsk
, elf_fpregset_t
*fpu
)
239 #if defined(CONFIG_SH_FPU)
240 fpvalid
= !!tsk_used_math(tsk
);
242 unlazy_fpu(tsk
, task_pt_regs(tsk
));
243 memcpy(fpu
, &tsk
->thread
.fpu
.hard
, sizeof(*fpu
));
250 asmlinkage
void ret_from_fork(void);
252 int copy_thread(int nr
, unsigned long clone_flags
, unsigned long usp
,
253 unsigned long unused
,
254 struct task_struct
*p
, struct pt_regs
*regs
)
256 struct thread_info
*ti
= task_thread_info(p
);
257 struct pt_regs
*childregs
;
258 #if defined(CONFIG_SH_FPU)
259 struct task_struct
*tsk
= current
;
261 unlazy_fpu(tsk
, regs
);
262 p
->thread
.fpu
= tsk
->thread
.fpu
;
263 copy_to_stopped_child_used_math(p
);
266 childregs
= task_pt_regs(p
);
269 if (user_mode(regs
)) {
270 childregs
->regs
[15] = usp
;
271 ti
->addr_limit
= USER_DS
;
273 childregs
->regs
[15] = (unsigned long)task_stack_page(p
) + THREAD_SIZE
;
274 ti
->addr_limit
= KERNEL_DS
;
276 if (clone_flags
& CLONE_SETTLS
) {
277 childregs
->gbr
= childregs
->regs
[0];
279 childregs
->regs
[0] = 0; /* Set return value for child */
281 p
->thread
.sp
= (unsigned long) childregs
;
282 p
->thread
.pc
= (unsigned long) ret_from_fork
;
284 p
->thread
.ubc_pc
= 0;
289 /* Tracing by user break controller. */
291 ubc_set_tracing(int asid
, unsigned long pc
)
293 ctrl_outl(pc
, UBC_BARA
);
296 /* We don't have any ASID settings for the SH-2! */
297 if (cpu_data
->type
!= CPU_SH7604
)
298 ctrl_outb(asid
, UBC_BASRA
);
301 ctrl_outl(0, UBC_BAMRA
);
303 if (cpu_data
->type
== CPU_SH7729
|| cpu_data
->type
== CPU_SH7710
) {
304 ctrl_outw(BBR_INST
| BBR_READ
| BBR_CPU
, UBC_BBRA
);
305 ctrl_outl(BRCR_PCBA
| BRCR_PCTE
, UBC_BRCR
);
307 ctrl_outw(BBR_INST
| BBR_READ
, UBC_BBRA
);
308 ctrl_outw(BRCR_PCBA
, UBC_BRCR
);
313 * switch_to(x,y) should switch tasks from x to y.
316 struct task_struct
*__switch_to(struct task_struct
*prev
, struct task_struct
*next
)
318 #if defined(CONFIG_SH_FPU)
319 unlazy_fpu(prev
, task_pt_regs(prev
));
322 #ifdef CONFIG_PREEMPT
325 struct pt_regs
*regs
;
327 local_irq_save(flags
);
328 regs
= task_pt_regs(prev
);
329 if (user_mode(regs
) && regs
->regs
[15] >= 0xc0000000) {
330 int offset
= (int)regs
->regs
[15];
332 /* Reset stack pointer: clear critical region mark */
333 regs
->regs
[15] = regs
->regs
[1];
334 if (regs
->pc
< regs
->regs
[0])
335 /* Go to rewind point */
336 regs
->pc
= regs
->regs
[0] + offset
;
338 local_irq_restore(flags
);
344 * Restore the kernel mode register
347 asm volatile("ldc %0, r7_bank"
349 : "r" (task_thread_info(next
)));
352 /* If no tasks are using the UBC, we're done */
353 if (ubc_usercnt
== 0)
354 /* If no tasks are using the UBC, we're done */;
355 else if (next
->thread
.ubc_pc
&& next
->mm
) {
358 asid
|= next
->mm
->context
.id
& MMU_CONTEXT_ASID_MASK
;
360 ubc_set_tracing(asid
, next
->thread
.ubc_pc
);
362 ctrl_outw(0, UBC_BBRA
);
363 ctrl_outw(0, UBC_BBRB
);
369 asmlinkage
int sys_fork(unsigned long r4
, unsigned long r5
,
370 unsigned long r6
, unsigned long r7
,
374 return do_fork(SIGCHLD
, regs
.regs
[15], ®s
, 0, NULL
, NULL
);
376 /* fork almost works, enough to trick you into looking elsewhere :-( */
381 asmlinkage
int sys_clone(unsigned long clone_flags
, unsigned long newsp
,
382 unsigned long parent_tidptr
,
383 unsigned long child_tidptr
,
387 newsp
= regs
.regs
[15];
388 return do_fork(clone_flags
, newsp
, ®s
, 0,
389 (int __user
*)parent_tidptr
, (int __user
*)child_tidptr
);
393 * This is trivial, and on the face of it looks like it
394 * could equally well be done in user mode.
396 * Not so, for quite unobvious reasons - register pressure.
397 * In user mode vfork() cannot have a stack frame, and if
398 * done by calling the "clone()" system call directly, you
399 * do not have enough call-clobbered registers to hold all
400 * the information you need.
402 asmlinkage
int sys_vfork(unsigned long r4
, unsigned long r5
,
403 unsigned long r6
, unsigned long r7
,
406 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, regs
.regs
[15], ®s
,
411 * sys_execve() executes a new program.
413 asmlinkage
int sys_execve(char *ufilename
, char **uargv
,
414 char **uenvp
, unsigned long r7
,
420 filename
= getname((char __user
*)ufilename
);
421 error
= PTR_ERR(filename
);
422 if (IS_ERR(filename
))
425 error
= do_execve(filename
,
426 (char __user
* __user
*)uargv
,
427 (char __user
* __user
*)uenvp
,
431 current
->ptrace
&= ~PT_DTRACE
;
432 task_unlock(current
);
439 unsigned long get_wchan(struct task_struct
*p
)
441 unsigned long schedule_frame
;
444 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
448 * The same comment as on the Alpha applies here, too ...
450 pc
= thread_saved_pc(p
);
451 if (in_sched_functions(pc
)) {
452 schedule_frame
= ((unsigned long *)(long)p
->thread
.sp
)[1];
453 return (unsigned long)((unsigned long *)schedule_frame
)[1];
458 asmlinkage
void break_point_trap(unsigned long r4
, unsigned long r5
,
459 unsigned long r6
, unsigned long r7
,
463 ctrl_outw(0, UBC_BBRA
);
464 ctrl_outw(0, UBC_BBRB
);
465 current
->thread
.ubc_pc
= 0;
468 force_sig(SIGTRAP
, current
);
471 asmlinkage
void break_point_trap_software(unsigned long r4
, unsigned long r5
,
472 unsigned long r6
, unsigned long r7
,
476 force_sig(SIGTRAP
, current
);