blob: 4688b890aef835d31db5c2dac2c0fb5d3445bfec [file] [log] [blame]
Paul Mundtaec5e0e2006-12-25 09:51:47 +09001/*
2 * arch/sh/kernel/process.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Paul Mundtaec5e0e2006-12-25 09:51:47 +09004 * This file handles the architecture-dependent parts of process handling..
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Copyright (C) 1995 Linus Torvalds
7 *
8 * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +09009 * Copyright (C) 2006 Lineo Solutions Inc. support SH4A UBC
Paul Mundt3a2e1172007-05-01 16:33:10 +090010 * Copyright (C) 2002 - 2007 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/mm.h>
14#include <linux/elfcore.h>
Paul Mundta3310bb2006-02-01 03:06:08 -080015#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kallsyms.h>
Paul Mundta3310bb2006-02-01 03:06:08 -080017#include <linux/kexec.h>
Paul Mundt3a2e1172007-05-01 16:33:10 +090018#include <asm/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/uaccess.h>
20#include <asm/mmu_context.h>
Paul Mundt5f8c9902007-05-08 11:55:21 +090021#include <asm/pgalloc.h>
Paul Mundtb5233d02006-09-20 03:25:34 +090022#include <asm/ubc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Paul Mundtaec5e0e2006-12-25 09:51:47 +090024static int hlt_counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025int ubc_usercnt = 0;
26
27#define HARD_IDLE_TIMEOUT (HZ / 3)
28
Paul Mundta3310bb2006-02-01 03:06:08 -080029void (*pm_idle)(void);
Paul Mundta3310bb2006-02-01 03:06:08 -080030void (*pm_power_off)(void);
31EXPORT_SYMBOL(pm_power_off);
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033void disable_hlt(void)
34{
35 hlt_counter++;
36}
Linus Torvalds1da177e2005-04-16 15:20:36 -070037EXPORT_SYMBOL(disable_hlt);
38
39void enable_hlt(void)
40{
41 hlt_counter--;
42}
Linus Torvalds1da177e2005-04-16 15:20:36 -070043EXPORT_SYMBOL(enable_hlt);
44
Paul Mundta3310bb2006-02-01 03:06:08 -080045void default_idle(void)
46{
47 if (!hlt_counter)
48 cpu_sleep();
49 else
50 cpu_relax();
51}
52
Nick Piggin64c7c8f2005-11-08 21:39:04 -080053void cpu_idle(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 /* endless idle loop with no priority at all */
56 while (1) {
Paul Mundta3310bb2006-02-01 03:06:08 -080057 void (*idle)(void) = pm_idle;
58
59 if (!idle)
60 idle = default_idle;
61
62 while (!need_resched())
63 idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Nick Piggin5bfb5d62005-11-08 21:39:01 -080065 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -080067 preempt_disable();
Paul Mundt5f8c9902007-05-08 11:55:21 +090068 check_pgt_cache();
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072void machine_restart(char * __unused)
73{
74 /* SR.BL=1 and invoke address error to let CPU reset (manual reset) */
75 asm volatile("ldc %0, sr\n\t"
76 "mov.l @%1, %0" : : "r" (0x10000000), "r" (0x80000001));
77}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079void machine_halt(void)
80{
Paul Mundta3310bb2006-02-01 03:06:08 -080081 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 while (1)
84 cpu_sleep();
85}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087void machine_power_off(void)
88{
Paul Mundta3310bb2006-02-01 03:06:08 -080089 if (pm_power_off)
90 pm_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093void show_regs(struct pt_regs * regs)
94{
95 printk("\n");
96 printk("Pid : %d, Comm: %20s\n", current->pid, current->comm);
Paul Mundt6b002232006-10-12 17:07:45 +090097 print_symbol("PC is at %s\n", instruction_pointer(regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 printk("PC : %08lx SP : %08lx SR : %08lx ",
99 regs->pc, regs->regs[15], regs->sr);
100#ifdef CONFIG_MMU
101 printk("TEA : %08x ", ctrl_inl(MMU_TEA));
102#else
103 printk(" ");
104#endif
105 printk("%s\n", print_tainted());
106
107 printk("R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
108 regs->regs[0],regs->regs[1],
109 regs->regs[2],regs->regs[3]);
110 printk("R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
111 regs->regs[4],regs->regs[5],
112 regs->regs[6],regs->regs[7]);
113 printk("R8 : %08lx R9 : %08lx R10 : %08lx R11 : %08lx\n",
114 regs->regs[8],regs->regs[9],
115 regs->regs[10],regs->regs[11]);
116 printk("R12 : %08lx R13 : %08lx R14 : %08lx\n",
117 regs->regs[12],regs->regs[13],
118 regs->regs[14]);
119 printk("MACH: %08lx MACL: %08lx GBR : %08lx PR : %08lx\n",
120 regs->mach, regs->macl, regs->gbr, regs->pr);
121
Paul Mundt6b002232006-10-12 17:07:45 +0900122 show_trace(NULL, (unsigned long *)regs->regs[15], regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
125/*
126 * Create a kernel thread
127 */
128
129/*
130 * This is the mechanism for creating a new kernel thread.
131 *
132 */
133extern void kernel_thread_helper(void);
134__asm__(".align 5\n"
135 "kernel_thread_helper:\n\t"
136 "jsr @r5\n\t"
137 " nop\n\t"
138 "mov.l 1f, r1\n\t"
139 "jsr @r1\n\t"
140 " mov r0, r4\n\t"
141 ".align 2\n\t"
142 "1:.long do_exit");
143
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900144/* Don't use this in BL=1(cli). Or else, CPU resets! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900146{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 struct pt_regs regs;
148
149 memset(&regs, 0, sizeof(regs));
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900150 regs.regs[4] = (unsigned long)arg;
151 regs.regs[5] = (unsigned long)fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900153 regs.pc = (unsigned long)kernel_thread_helper;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 regs.sr = (1 << 30);
155
156 /* Ok, create the new process.. */
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900157 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
158 &regs, 0, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161/*
162 * Free current thread data structures etc..
163 */
164void exit_thread(void)
165{
166 if (current->thread.ubc_pc) {
167 current->thread.ubc_pc = 0;
168 ubc_usercnt -= 1;
169 }
170}
171
172void flush_thread(void)
173{
174#if defined(CONFIG_SH_FPU)
175 struct task_struct *tsk = current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 /* Forget lazy FPU state */
Al Viro3cf0f4e2006-01-12 01:05:44 -0800177 clear_fpu(tsk, task_pt_regs(tsk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 clear_used_math();
179#endif
180}
181
182void release_thread(struct task_struct *dead_task)
183{
184 /* do nothing */
185}
186
187/* Fill in the fpu structure for a core dump.. */
188int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
189{
190 int fpvalid = 0;
191
192#if defined(CONFIG_SH_FPU)
193 struct task_struct *tsk = current;
194
195 fpvalid = !!tsk_used_math(tsk);
196 if (fpvalid) {
197 unlazy_fpu(tsk, regs);
198 memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
199 }
200#endif
201
202 return fpvalid;
203}
204
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900205/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 * Capture the user space registers if the task is not running (in user space)
207 */
208int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
209{
210 struct pt_regs ptregs;
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900211
Al Viro3cf0f4e2006-01-12 01:05:44 -0800212 ptregs = *task_pt_regs(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 elf_core_copy_regs(regs, &ptregs);
214
215 return 1;
216}
217
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900218int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 int fpvalid = 0;
221
222#if defined(CONFIG_SH_FPU)
223 fpvalid = !!tsk_used_math(tsk);
224 if (fpvalid) {
Al Viro3cf0f4e2006-01-12 01:05:44 -0800225 unlazy_fpu(tsk, task_pt_regs(tsk));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
227 }
228#endif
229
230 return fpvalid;
231}
232
233asmlinkage void ret_from_fork(void);
234
235int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
236 unsigned long unused,
237 struct task_struct *p, struct pt_regs *regs)
238{
Paul Mundt2991be72006-09-27 17:07:07 +0900239 struct thread_info *ti = task_thread_info(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 struct pt_regs *childregs;
241#if defined(CONFIG_SH_FPU)
242 struct task_struct *tsk = current;
243
244 unlazy_fpu(tsk, regs);
245 p->thread.fpu = tsk->thread.fpu;
246 copy_to_stopped_child_used_math(p);
247#endif
248
Al Viro3cf0f4e2006-01-12 01:05:44 -0800249 childregs = task_pt_regs(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *childregs = *regs;
251
252 if (user_mode(regs)) {
253 childregs->regs[15] = usp;
Paul Mundt2991be72006-09-27 17:07:07 +0900254 ti->addr_limit = USER_DS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 } else {
Hideo Saitoe6bcf562007-02-28 18:35:42 +0900256 childregs->regs[15] = (unsigned long)childregs;
Paul Mundt2991be72006-09-27 17:07:07 +0900257 ti->addr_limit = KERNEL_DS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900259
Hideo Saitoe6bcf562007-02-28 18:35:42 +0900260 if (clone_flags & CLONE_SETTLS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 childregs->gbr = childregs->regs[0];
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 childregs->regs[0] = 0; /* Set return value for child */
264
265 p->thread.sp = (unsigned long) childregs;
266 p->thread.pc = (unsigned long) ret_from_fork;
267
268 p->thread.ubc_pc = 0;
269
270 return 0;
271}
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/* Tracing by user break controller. */
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900274static void ubc_set_tracing(int asid, unsigned long pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900276#if defined(CONFIG_CPU_SH4A)
277 unsigned long val;
278
279 val = (UBC_CBR_ID_INST | UBC_CBR_RW_READ | UBC_CBR_CE);
280 val |= (UBC_CBR_AIE | UBC_CBR_AIV_SET(asid));
281
282 ctrl_outl(val, UBC_CBR0);
283 ctrl_outl(pc, UBC_CAR0);
284 ctrl_outl(0x0, UBC_CAMR0);
285 ctrl_outl(0x0, UBC_CBCR);
286
287 val = (UBC_CRR_RES | UBC_CRR_PCB | UBC_CRR_BIE);
288 ctrl_outl(val, UBC_CRR0);
289
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900290 /* Read UBC register that we wrote last, for checking update */
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900291 val = ctrl_inl(UBC_CRR0);
292
293#else /* CONFIG_CPU_SH4A */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 ctrl_outl(pc, UBC_BARA);
295
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900296#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /* We don't have any ASID settings for the SH-2! */
Paul Mundt11c19652006-12-25 10:19:56 +0900298 if (current_cpu_data.type != CPU_SH7604)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 ctrl_outb(asid, UBC_BASRA);
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900300#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 ctrl_outl(0, UBC_BAMRA);
303
Paul Mundt11c19652006-12-25 10:19:56 +0900304 if (current_cpu_data.type == CPU_SH7729 ||
Paul Mundt3a2e1172007-05-01 16:33:10 +0900305 current_cpu_data.type == CPU_SH7710 ||
306 current_cpu_data.type == CPU_SH7712) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 ctrl_outw(BBR_INST | BBR_READ | BBR_CPU, UBC_BBRA);
308 ctrl_outl(BRCR_PCBA | BRCR_PCTE, UBC_BRCR);
309 } else {
310 ctrl_outw(BBR_INST | BBR_READ, UBC_BBRA);
311 ctrl_outw(BRCR_PCBA, UBC_BRCR);
312 }
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900313#endif /* CONFIG_CPU_SH4A */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316/*
317 * switch_to(x,y) should switch tasks from x to y.
318 *
319 */
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900320struct task_struct *__switch_to(struct task_struct *prev,
321 struct task_struct *next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323#if defined(CONFIG_SH_FPU)
Al Viro3cf0f4e2006-01-12 01:05:44 -0800324 unlazy_fpu(prev, task_pt_regs(prev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#endif
326
327#ifdef CONFIG_PREEMPT
328 {
329 unsigned long flags;
330 struct pt_regs *regs;
331
332 local_irq_save(flags);
Al Viro3cf0f4e2006-01-12 01:05:44 -0800333 regs = task_pt_regs(prev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (user_mode(regs) && regs->regs[15] >= 0xc0000000) {
335 int offset = (int)regs->regs[15];
336
337 /* Reset stack pointer: clear critical region mark */
338 regs->regs[15] = regs->regs[1];
339 if (regs->pc < regs->regs[0])
340 /* Go to rewind point */
341 regs->pc = regs->regs[0] + offset;
342 }
343 local_irq_restore(flags);
344 }
345#endif
346
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900347#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 /*
349 * Restore the kernel mode register
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900350 * k7 (r7_bank1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 */
352 asm volatile("ldc %0, r7_bank"
353 : /* no output */
Al Virocafcfca2006-01-12 01:05:45 -0800354 : "r" (task_thread_info(next)));
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900355#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 /* If no tasks are using the UBC, we're done */
358 if (ubc_usercnt == 0)
359 /* If no tasks are using the UBC, we're done */;
360 else if (next->thread.ubc_pc && next->mm) {
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900361 int asid = 0;
362#ifdef CONFIG_MMU
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900363 asid |= cpu_asid(smp_processor_id(), next->mm);
Yoshinori Satoa2d1a5f2006-09-27 17:25:07 +0900364#endif
365 ubc_set_tracing(asid, next->thread.ubc_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 } else {
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900367#if defined(CONFIG_CPU_SH4A)
368 ctrl_outl(UBC_CBR_INIT, UBC_CBR0);
369 ctrl_outl(UBC_CRR_INIT, UBC_CRR0);
370#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 ctrl_outw(0, UBC_BBRA);
372 ctrl_outw(0, UBC_BBRB);
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 return prev;
377}
378
379asmlinkage int sys_fork(unsigned long r4, unsigned long r5,
380 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900381 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900383 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#ifdef CONFIG_MMU
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900385 return do_fork(SIGCHLD, regs->regs[15], regs, 0, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#else
387 /* fork almost works, enough to trick you into looking elsewhere :-( */
388 return -EINVAL;
389#endif
390}
391
392asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
393 unsigned long parent_tidptr,
394 unsigned long child_tidptr,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900395 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900397 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!newsp)
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900399 newsp = regs->regs[15];
400 return do_fork(clone_flags, newsp, regs, 0,
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900401 (int __user *)parent_tidptr,
402 (int __user *)child_tidptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
405/*
406 * This is trivial, and on the face of it looks like it
407 * could equally well be done in user mode.
408 *
409 * Not so, for quite unobvious reasons - register pressure.
410 * In user mode vfork() cannot have a stack frame, and if
411 * done by calling the "clone()" system call directly, you
412 * do not have enough call-clobbered registers to hold all
413 * the information you need.
414 */
415asmlinkage int sys_vfork(unsigned long r4, unsigned long r5,
416 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900417 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900419 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
420 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->regs[15], regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 0, NULL, NULL);
422}
423
424/*
425 * sys_execve() executes a new program.
426 */
427asmlinkage int sys_execve(char *ufilename, char **uargv,
428 char **uenvp, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900429 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900431 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 int error;
433 char *filename;
434
435 filename = getname((char __user *)ufilename);
436 error = PTR_ERR(filename);
437 if (IS_ERR(filename))
438 goto out;
439
440 error = do_execve(filename,
441 (char __user * __user *)uargv,
442 (char __user * __user *)uenvp,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900443 regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (error == 0) {
445 task_lock(current);
446 current->ptrace &= ~PT_DTRACE;
447 task_unlock(current);
448 }
449 putname(filename);
450out:
451 return error;
452}
453
454unsigned long get_wchan(struct task_struct *p)
455{
456 unsigned long schedule_frame;
457 unsigned long pc;
458
459 if (!p || p == current || p->state == TASK_RUNNING)
460 return 0;
461
462 /*
463 * The same comment as on the Alpha applies here, too ...
464 */
465 pc = thread_saved_pc(p);
466 if (in_sched_functions(pc)) {
Paul Mundtb652c232006-12-08 17:46:29 +0900467 schedule_frame = (unsigned long)p->thread.sp;
468 return ((unsigned long *)schedule_frame)[21];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
Paul Mundtb652c232006-12-08 17:46:29 +0900470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return pc;
472}
473
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900474asmlinkage void break_point_trap(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 /* Clear tracing. */
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900477#if defined(CONFIG_CPU_SH4A)
478 ctrl_outl(UBC_CBR_INIT, UBC_CBR0);
479 ctrl_outl(UBC_CRR_INIT, UBC_CRR0);
480#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 ctrl_outw(0, UBC_BBRA);
482 ctrl_outw(0, UBC_BBRB);
Ryusuke Sakato8ae91b92006-10-12 12:16:13 +0900483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 current->thread.ubc_pc = 0;
485 ubc_usercnt -= 1;
486
487 force_sig(SIGTRAP, current);
488}
489
Paul Mundtf413d0d2006-12-13 17:40:05 +0900490/*
491 * Generic trap handler.
492 */
493asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5,
494 unsigned long r6, unsigned long r7,
495 struct pt_regs __regs)
496{
497 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
498
499 /* Rewind */
500 regs->pc -= 2;
501
Paul Mundt3a2e1172007-05-01 16:33:10 +0900502 if (notify_die(DIE_TRAP, regs, regs->tra & 0xff,
503 SIGTRAP) == NOTIFY_STOP)
504 return;
505
Paul Mundtf413d0d2006-12-13 17:40:05 +0900506 force_sig(SIGTRAP, current);
507}
508
509/*
510 * Special handler for BUG() traps.
511 */
512asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5,
513 unsigned long r6, unsigned long r7,
514 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900516 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
517
Paul Mundtdc34d312006-12-08 17:41:43 +0900518 /* Rewind */
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900519 regs->pc -= 2;
Paul Mundtdc34d312006-12-08 17:41:43 +0900520
Paul Mundt3a2e1172007-05-01 16:33:10 +0900521 if (notify_die(DIE_TRAP, regs, TRAPA_BUG_OPCODE & 0xff,
522 SIGTRAP) == NOTIFY_STOP)
523 return;
524
Paul Mundtdc34d312006-12-08 17:41:43 +0900525#ifdef CONFIG_BUG
526 if (__kernel_text_address(instruction_pointer(regs))) {
527 u16 insn = *(u16 *)instruction_pointer(regs);
528 if (insn == TRAPA_BUG_OPCODE)
529 handle_BUG(regs);
530 }
531#endif
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 force_sig(SIGTRAP, current);
534}