blob: f2497585cac00ca2b48fa9d8c1613452c8aadf8a [file] [log] [blame]
Paul Mundt6b002232006-10-12 17:07:45 +09001/*
2 * 'traps.c' handles hardware traps and faults after we have saved some
3 * state in 'entry.S'.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * SuperH version: Copyright (C) 1999 Niibe Yutaka
6 * Copyright (C) 2000 Philipp Rumpf
7 * Copyright (C) 2000 David Howells
Paul Mundt3a2e1172007-05-01 16:33:10 +09008 * Copyright (C) 2002 - 2007 Paul Mundt
Paul Mundt6b002232006-10-12 17:07:45 +09009 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/spinlock.h>
18#include <linux/module.h>
19#include <linux/kallsyms.h>
Paul Mundt1f666582006-10-19 16:20:25 +090020#include <linux/io.h>
Paul Mundtfa691512007-03-08 19:41:21 +090021#include <linux/bug.h>
Paul Mundt9b8c90e2006-12-06 11:07:51 +090022#include <linux/debug_locks.h>
Paul Mundtb118ca52007-05-09 10:55:38 +090023#include <linux/kdebug.h>
Paul Mundte1132762007-05-15 08:36:36 +090024#include <linux/kexec.h>
Paul Mundtdc34d312006-12-08 17:41:43 +090025#include <linux/limits.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/system.h>
27#include <asm/uaccess.h>
Andrew Mortonfad0f902008-04-16 02:03:51 +090028#include <asm/fpu.h>
Chris Smithd39f5452008-09-05 17:15:39 +090029#include <asm/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#ifdef CONFIG_SH_KGDB
32#include <asm/kgdb.h>
Stuart Menefyf0bc8142006-11-21 11:16:57 +090033#define CHK_REMOTE_DEBUG(regs) \
34{ \
Takashi YOSHII4b565682006-09-27 17:15:32 +090035 if (kgdb_debug_hook && !user_mode(regs))\
36 (*kgdb_debug_hook)(regs); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38#else
39#define CHK_REMOTE_DEBUG(regs)
40#endif
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#ifdef CONFIG_CPU_SH2
Yoshinori Sato0983b312006-11-05 15:58:47 +090043# define TRAP_RESERVED_INST 4
44# define TRAP_ILLEGAL_SLOT_INST 6
45# define TRAP_ADDRESS_ERROR 9
46# ifdef CONFIG_CPU_SH2A
Yoshinori Sato6e80f5e2008-07-10 01:20:03 +090047# define TRAP_FPU_ERROR 13
Yoshinori Sato0983b312006-11-05 15:58:47 +090048# define TRAP_DIVZERO_ERROR 17
49# define TRAP_DIVOVF_ERROR 18
50# endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#else
52#define TRAP_RESERVED_INST 12
53#define TRAP_ILLEGAL_SLOT_INST 13
54#endif
55
Paul Mundt6b002232006-10-12 17:07:45 +090056static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
57{
58 unsigned long p;
59 int i;
60
61 printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
62
63 for (p = bottom & ~31; p < top; ) {
64 printk("%04lx: ", p & 0xffff);
65
66 for (i = 0; i < 8; i++, p += 4) {
67 unsigned int val;
68
69 if (p < bottom || p >= top)
70 printk(" ");
71 else {
72 if (__get_user(val, (unsigned int __user *)p)) {
73 printk("\n");
74 return;
75 }
76 printk("%08x ", val);
77 }
78 }
79 printk("\n");
80 }
81}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Paul Mundt3a2e1172007-05-01 16:33:10 +090083static DEFINE_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85void die(const char * str, struct pt_regs * regs, long err)
86{
87 static int die_counter;
88
Paul Mundt55273982007-06-18 18:57:13 +090089 oops_enter();
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 console_verbose();
92 spin_lock_irq(&die_lock);
Paul Mundt6b002232006-10-12 17:07:45 +090093 bust_spinlocks(1);
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
Paul Mundt6b002232006-10-12 17:07:45 +090096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 CHK_REMOTE_DEBUG(regs);
Paul Mundt6b002232006-10-12 17:07:45 +090098 print_modules();
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 show_regs(regs);
Paul Mundt6b002232006-10-12 17:07:45 +0900100
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700101 printk("Process: %s (pid: %d, stack limit = %p)\n", current->comm,
102 task_pid_nr(current), task_stack_page(current) + 1);
Paul Mundt6b002232006-10-12 17:07:45 +0900103
104 if (!user_mode(regs) || in_interrupt())
105 dump_mem("Stack: ", regs->regs[15], THREAD_SIZE +
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900106 (unsigned long)task_stack_page(current));
Paul Mundt6b002232006-10-12 17:07:45 +0900107
Paul Mundtc9306f02008-10-21 18:33:36 +0900108 notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV);
109
Paul Mundt6b002232006-10-12 17:07:45 +0900110 bust_spinlocks(0);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700111 add_taint(TAINT_DIE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 spin_unlock_irq(&die_lock);
Paul Mundte1132762007-05-15 08:36:36 +0900113
114 if (kexec_should_crash(current))
115 crash_kexec(regs);
116
117 if (in_interrupt())
118 panic("Fatal exception in interrupt");
119
120 if (panic_on_oops)
121 panic("Fatal exception");
122
Paul Mundt55273982007-06-18 18:57:13 +0900123 oops_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 do_exit(SIGSEGV);
125}
126
Paul Mundt6b002232006-10-12 17:07:45 +0900127static inline void die_if_kernel(const char *str, struct pt_regs *regs,
128 long err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 if (!user_mode(regs))
131 die(str, regs, err);
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/*
135 * try and fix up kernelspace address errors
136 * - userspace errors just cause EFAULT to be returned, resulting in SEGV
137 * - kernel/userspace interfaces cause a jump to an appropriate handler
138 * - other kernel errors are bad
139 * - return 0 if fixed-up, -EFAULT if non-fatal (to the kernel) fault
140 */
141static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
142{
Paul Mundt6b002232006-10-12 17:07:45 +0900143 if (!user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 const struct exception_table_entry *fixup;
145 fixup = search_exception_tables(regs->pc);
146 if (fixup) {
147 regs->pc = fixup->fixup;
148 return 0;
149 }
150 die(str, regs, err);
151 }
152 return -EFAULT;
153}
154
Magnus Damm86c01792008-02-07 00:02:50 +0900155static inline void sign_extend(unsigned int count, unsigned char *dst)
156{
157#ifdef __LITTLE_ENDIAN__
Magnus Damm4252c652008-02-07 19:58:46 +0900158 if ((count == 1) && dst[0] & 0x80) {
159 dst[1] = 0xff;
160 dst[2] = 0xff;
161 dst[3] = 0xff;
162 }
Magnus Damm86c01792008-02-07 00:02:50 +0900163 if ((count == 2) && dst[1] & 0x80) {
164 dst[2] = 0xff;
165 dst[3] = 0xff;
166 }
167#else
Magnus Damm4252c652008-02-07 19:58:46 +0900168 if ((count == 1) && dst[3] & 0x80) {
169 dst[2] = 0xff;
Magnus Damm86c01792008-02-07 00:02:50 +0900170 dst[1] = 0xff;
Magnus Damm4252c652008-02-07 19:58:46 +0900171 dst[0] = 0xff;
172 }
173 if ((count == 2) && dst[2] & 0x80) {
174 dst[1] = 0xff;
175 dst[0] = 0xff;
Magnus Damm86c01792008-02-07 00:02:50 +0900176 }
177#endif
178}
179
Magnus Damme7cc9a72008-02-07 20:18:21 +0900180static struct mem_access user_mem_access = {
181 copy_from_user,
182 copy_to_user,
183};
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/*
186 * handle an instruction that does an unaligned memory access by emulating the
187 * desired behaviour
188 * - note that PC _may not_ point to the faulting instruction
189 * (if that instruction is in a branch delay slot)
190 * - return 0 if emulation okay, -EFAULT on existential error
191 */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900192static int handle_unaligned_ins(opcode_t instruction, struct pt_regs *regs,
193 struct mem_access *ma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 int ret, index, count;
196 unsigned long *rm, *rn;
197 unsigned char *src, *dst;
Paul Mundtfa439722008-09-04 18:53:58 +0900198 unsigned char __user *srcu, *dstu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 index = (instruction>>8)&15; /* 0x0F00 */
201 rn = &regs->regs[index];
202
203 index = (instruction>>4)&15; /* 0x00F0 */
204 rm = &regs->regs[index];
205
206 count = 1<<(instruction&3);
207
208 ret = -EFAULT;
209 switch (instruction>>12) {
210 case 0: /* mov.[bwl] to/from memory via r0+rn */
211 if (instruction & 8) {
212 /* from memory */
Paul Mundtfa439722008-09-04 18:53:58 +0900213 srcu = (unsigned char __user *)*rm;
214 srcu += regs->regs[0];
215 dst = (unsigned char *)rn;
216 *(unsigned long *)dst = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Magnus Damm86c01792008-02-07 00:02:50 +0900218#if !defined(__LITTLE_ENDIAN__)
219 dst += 4-count;
220#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900221 if (ma->from(dst, srcu, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 goto fetch_fault;
223
Magnus Damm86c01792008-02-07 00:02:50 +0900224 sign_extend(count, dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 } else {
226 /* to memory */
Paul Mundtfa439722008-09-04 18:53:58 +0900227 src = (unsigned char *)rm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#if !defined(__LITTLE_ENDIAN__)
229 src += 4-count;
230#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900231 dstu = (unsigned char __user *)*rn;
232 dstu += regs->regs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Paul Mundtfa439722008-09-04 18:53:58 +0900234 if (ma->to(dstu, src, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 goto fetch_fault;
236 }
237 ret = 0;
238 break;
239
240 case 1: /* mov.l Rm,@(disp,Rn) */
241 src = (unsigned char*) rm;
Paul Mundtfa439722008-09-04 18:53:58 +0900242 dstu = (unsigned char __user *)*rn;
243 dstu += (instruction&0x000F)<<2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Paul Mundtfa439722008-09-04 18:53:58 +0900245 if (ma->to(dstu, src, 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 goto fetch_fault;
247 ret = 0;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900248 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 case 2: /* mov.[bwl] to memory, possibly with pre-decrement */
251 if (instruction & 4)
252 *rn -= count;
253 src = (unsigned char*) rm;
Paul Mundtfa439722008-09-04 18:53:58 +0900254 dstu = (unsigned char __user *)*rn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#if !defined(__LITTLE_ENDIAN__)
256 src += 4-count;
257#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900258 if (ma->to(dstu, src, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 goto fetch_fault;
260 ret = 0;
261 break;
262
263 case 5: /* mov.l @(disp,Rm),Rn */
Paul Mundtfa439722008-09-04 18:53:58 +0900264 srcu = (unsigned char __user *)*rm;
265 srcu += (instruction & 0x000F) << 2;
266 dst = (unsigned char *)rn;
267 *(unsigned long *)dst = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Paul Mundtfa439722008-09-04 18:53:58 +0900269 if (ma->from(dst, srcu, 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto fetch_fault;
271 ret = 0;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900272 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 case 6: /* mov.[bwl] from memory, possibly with post-increment */
Paul Mundtfa439722008-09-04 18:53:58 +0900275 srcu = (unsigned char __user *)*rm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (instruction & 4)
277 *rm += count;
278 dst = (unsigned char*) rn;
279 *(unsigned long*)dst = 0;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900280
Magnus Damm86c01792008-02-07 00:02:50 +0900281#if !defined(__LITTLE_ENDIAN__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 dst += 4-count;
Magnus Damm86c01792008-02-07 00:02:50 +0900283#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900284 if (ma->from(dst, srcu, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 goto fetch_fault;
Magnus Damm86c01792008-02-07 00:02:50 +0900286 sign_extend(count, dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ret = 0;
288 break;
289
290 case 8:
291 switch ((instruction&0xFF00)>>8) {
292 case 0x81: /* mov.w R0,@(disp,Rn) */
Paul Mundtfa439722008-09-04 18:53:58 +0900293 src = (unsigned char *) &regs->regs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#if !defined(__LITTLE_ENDIAN__)
295 src += 2;
296#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900297 dstu = (unsigned char __user *)*rm; /* called Rn in the spec */
298 dstu += (instruction & 0x000F) << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Paul Mundtfa439722008-09-04 18:53:58 +0900300 if (ma->to(dstu, src, 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 goto fetch_fault;
302 ret = 0;
303 break;
304
305 case 0x85: /* mov.w @(disp,Rm),R0 */
Paul Mundtfa439722008-09-04 18:53:58 +0900306 srcu = (unsigned char __user *)*rm;
307 srcu += (instruction & 0x000F) << 1;
308 dst = (unsigned char *) &regs->regs[0];
309 *(unsigned long *)dst = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311#if !defined(__LITTLE_ENDIAN__)
312 dst += 2;
313#endif
Paul Mundtfa439722008-09-04 18:53:58 +0900314 if (ma->from(dst, srcu, 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 goto fetch_fault;
Magnus Damm86c01792008-02-07 00:02:50 +0900316 sign_extend(2, dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 ret = 0;
318 break;
319 }
320 break;
321 }
322 return ret;
323
324 fetch_fault:
325 /* Argh. Address not only misaligned but also non-existent.
326 * Raise an EFAULT and see if it's trapped
327 */
328 return die_if_no_fixup("Fault in unaligned fixup", regs, 0);
329}
330
331/*
332 * emulate the instruction in the delay slot
333 * - fetches the instruction from PC+2
334 */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900335static inline int handle_delayslot(struct pt_regs *regs,
336 opcode_t old_instruction,
337 struct mem_access *ma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900339 opcode_t instruction;
Paul Mundtfa439722008-09-04 18:53:58 +0900340 void __user *addr = (void __user *)(regs->pc +
341 instruction_size(old_instruction));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900343 if (copy_from_user(&instruction, addr, sizeof(instruction))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* the instruction-fetch faulted */
345 if (user_mode(regs))
346 return -EFAULT;
347
348 /* kernel */
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900349 die("delay-slot-insn faulting in handle_unaligned_delayslot",
350 regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
Magnus Damme7cc9a72008-02-07 20:18:21 +0900353 return handle_unaligned_ins(instruction, regs, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356/*
357 * handle an instruction that does an unaligned memory access
358 * - have to be careful of branch delay-slot instructions that fault
359 * SH3:
360 * - if the branch would be taken PC points to the branch
361 * - if the branch would not be taken, PC points to delay-slot
362 * SH4:
363 * - PC always points to delayed branch
364 * - return 0 if handled, -EFAULT if failed (may not return if in kernel)
365 */
366
367/* Macros to determine offset from current PC for branch instructions */
368/* Explicit type coercion is used to force sign extension where needed */
369#define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4)
370#define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4)
371
Paul Mundt710ee0c2006-11-05 16:48:42 +0900372/*
373 * XXX: SH-2A needs this too, but it needs an overhaul thanks to mixed 32-bit
374 * opcodes..
375 */
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900376
Paul Mundt710ee0c2006-11-05 16:48:42 +0900377static int handle_unaligned_notify_count = 10;
378
Magnus Damme7cc9a72008-02-07 20:18:21 +0900379int handle_unaligned_access(opcode_t instruction, struct pt_regs *regs,
380 struct mem_access *ma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
382 u_int rm;
383 int ret, index;
384
385 index = (instruction>>8)&15; /* 0x0F00 */
386 rm = regs->regs[index];
387
388 /* shout about the first ten userspace fixups */
389 if (user_mode(regs) && handle_unaligned_notify_count>0) {
390 handle_unaligned_notify_count--;
391
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900392 printk(KERN_NOTICE "Fixing up unaligned userspace access "
393 "in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700394 current->comm, task_pid_nr(current),
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900395 (void *)regs->pc, instruction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397
398 ret = -EFAULT;
399 switch (instruction&0xF000) {
400 case 0x0000:
401 if (instruction==0x000B) {
402 /* rts */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900403 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (ret==0)
405 regs->pc = regs->pr;
406 }
407 else if ((instruction&0x00FF)==0x0023) {
408 /* braf @Rm */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900409 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (ret==0)
411 regs->pc += rm + 4;
412 }
413 else if ((instruction&0x00FF)==0x0003) {
414 /* bsrf @Rm */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900415 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (ret==0) {
417 regs->pr = regs->pc + 4;
418 regs->pc += rm + 4;
419 }
420 }
421 else {
422 /* mov.[bwl] to/from memory via r0+rn */
423 goto simple;
424 }
425 break;
426
427 case 0x1000: /* mov.l Rm,@(disp,Rn) */
428 goto simple;
429
430 case 0x2000: /* mov.[bwl] to memory, possibly with pre-decrement */
431 goto simple;
432
433 case 0x4000:
434 if ((instruction&0x00FF)==0x002B) {
435 /* jmp @Rm */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900436 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (ret==0)
438 regs->pc = rm;
439 }
440 else if ((instruction&0x00FF)==0x000B) {
441 /* jsr @Rm */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900442 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (ret==0) {
444 regs->pr = regs->pc + 4;
445 regs->pc = rm;
446 }
447 }
448 else {
449 /* mov.[bwl] to/from memory via r0+rn */
450 goto simple;
451 }
452 break;
453
454 case 0x5000: /* mov.l @(disp,Rm),Rn */
455 goto simple;
456
457 case 0x6000: /* mov.[bwl] from memory, possibly with post-increment */
458 goto simple;
459
460 case 0x8000: /* bf lab, bf/s lab, bt lab, bt/s lab */
461 switch (instruction&0x0F00) {
462 case 0x0100: /* mov.w R0,@(disp,Rm) */
463 goto simple;
464 case 0x0500: /* mov.w @(disp,Rm),R0 */
465 goto simple;
466 case 0x0B00: /* bf lab - no delayslot*/
467 break;
468 case 0x0F00: /* bf/s lab */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900469 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (ret==0) {
471#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
472 if ((regs->sr & 0x00000001) != 0)
473 regs->pc += 4; /* next after slot */
474 else
475#endif
476 regs->pc += SH_PC_8BIT_OFFSET(instruction);
477 }
478 break;
479 case 0x0900: /* bt lab - no delayslot */
480 break;
481 case 0x0D00: /* bt/s lab */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900482 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 if (ret==0) {
484#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
485 if ((regs->sr & 0x00000001) == 0)
486 regs->pc += 4; /* next after slot */
487 else
488#endif
489 regs->pc += SH_PC_8BIT_OFFSET(instruction);
490 }
491 break;
492 }
493 break;
494
495 case 0xA000: /* bra label */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900496 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (ret==0)
498 regs->pc += SH_PC_12BIT_OFFSET(instruction);
499 break;
500
501 case 0xB000: /* bsr label */
Magnus Damme7cc9a72008-02-07 20:18:21 +0900502 ret = handle_delayslot(regs, instruction, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (ret==0) {
504 regs->pr = regs->pc + 4;
505 regs->pc += SH_PC_12BIT_OFFSET(instruction);
506 }
507 break;
508 }
509 return ret;
510
511 /* handle non-delay-slot instruction */
512 simple:
Magnus Damme7cc9a72008-02-07 20:18:21 +0900513 ret = handle_unaligned_ins(instruction, regs, ma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (ret==0)
Paul Mundt53f983a2007-05-08 15:31:48 +0900515 regs->pc += instruction_size(instruction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 return ret;
517}
518
519/*
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900520 * Handle various address error exceptions:
521 * - instruction address error:
522 * misaligned PC
523 * PC >= 0x80000000 in user mode
524 * - data address error (read and write)
525 * misaligned data access
526 * access to >= 0x80000000 is user mode
527 * Unfortuntaly we can't distinguish between instruction address error
Simon Arlotte868d612007-05-14 08:15:10 +0900528 * and data address errors caused by read accesses.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 */
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900530asmlinkage void do_address_error(struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 unsigned long writeaccess,
532 unsigned long address)
533{
Yoshinori Sato0983b312006-11-05 15:58:47 +0900534 unsigned long error_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 mm_segment_t oldfs;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900536 siginfo_t info;
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900537 opcode_t instruction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 int tmp;
539
Yoshinori Sato0983b312006-11-05 15:58:47 +0900540 /* Intentional ifdef */
541#ifdef CONFIG_CPU_HAS_SR_RB
Paul Mundt4c59e292008-09-21 12:00:23 +0900542 error_code = lookup_exception_vector();
Yoshinori Sato0983b312006-11-05 15:58:47 +0900543#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 oldfs = get_fs();
546
547 if (user_mode(regs)) {
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900548 int si_code = BUS_ADRERR;
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 /* bad PC is not something we can fix */
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900553 if (regs->pc & 1) {
554 si_code = BUS_ADRALN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 goto uspace_segv;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 set_fs(USER_DS);
Paul Mundtfa439722008-09-04 18:53:58 +0900559 if (copy_from_user(&instruction, (void __user *)(regs->pc),
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900560 sizeof(instruction))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 /* Argh. Fault on the instruction itself.
562 This should never happen non-SMP
563 */
564 set_fs(oldfs);
565 goto uspace_segv;
566 }
567
Magnus Damme7cc9a72008-02-07 20:18:21 +0900568 tmp = handle_unaligned_access(instruction, regs,
569 &user_mem_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 set_fs(oldfs);
571
572 if (tmp==0)
573 return; /* sorted */
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900574uspace_segv:
575 printk(KERN_NOTICE "Sending SIGBUS to \"%s\" due to unaligned "
576 "access (PC %lx PR %lx)\n", current->comm, regs->pc,
577 regs->pr);
578
579 info.si_signo = SIGBUS;
580 info.si_errno = 0;
581 info.si_code = si_code;
Paul Mundte08f4572007-05-14 12:52:56 +0900582 info.si_addr = (void __user *)address;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900583 force_sig_info(SIGBUS, &info, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 } else {
585 if (regs->pc & 1)
586 die("unaligned program counter", regs, error_code);
587
588 set_fs(KERNEL_DS);
Paul Mundtfa439722008-09-04 18:53:58 +0900589 if (copy_from_user(&instruction, (void __user *)(regs->pc),
Magnus Damm4b5a9ef2008-02-07 20:04:12 +0900590 sizeof(instruction))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /* Argh. Fault on the instruction itself.
592 This should never happen non-SMP
593 */
594 set_fs(oldfs);
595 die("insn faulting in do_address_error", regs, 0);
596 }
597
Magnus Damme7cc9a72008-02-07 20:18:21 +0900598 handle_unaligned_access(instruction, regs, &user_mem_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 set_fs(oldfs);
600 }
601}
602
603#ifdef CONFIG_SH_DSP
604/*
605 * SH-DSP support gerg@snapgear.com.
606 */
607int is_dsp_inst(struct pt_regs *regs)
608{
Paul Mundt882c12c2007-05-14 17:26:34 +0900609 unsigned short inst = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900611 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 * Safe guard if DSP mode is already enabled or we're lacking
613 * the DSP altogether.
614 */
Paul Mundt11c19652006-12-25 10:19:56 +0900615 if (!(current_cpu_data.flags & CPU_HAS_DSP) || (regs->sr & SR_DSP))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return 0;
617
618 get_user(inst, ((unsigned short *) regs->pc));
619
620 inst &= 0xf000;
621
622 /* Check for any type of DSP or support instruction */
623 if ((inst == 0xf000) || (inst == 0x4000))
624 return 1;
625
626 return 0;
627}
628#else
629#define is_dsp_inst(regs) (0)
630#endif /* CONFIG_SH_DSP */
631
Yoshinori Sato0983b312006-11-05 15:58:47 +0900632#ifdef CONFIG_CPU_SH2A
633asmlinkage void do_divide_error(unsigned long r4, unsigned long r5,
634 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900635 struct pt_regs __regs)
Yoshinori Sato0983b312006-11-05 15:58:47 +0900636{
637 siginfo_t info;
638
Yoshinori Sato0983b312006-11-05 15:58:47 +0900639 switch (r4) {
640 case TRAP_DIVZERO_ERROR:
641 info.si_code = FPE_INTDIV;
642 break;
643 case TRAP_DIVOVF_ERROR:
644 info.si_code = FPE_INTOVF;
645 break;
646 }
647
648 force_sig_info(SIGFPE, &info, current);
649}
650#endif
651
Takashi YOSHII4b565682006-09-27 17:15:32 +0900652asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
653 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900654 struct pt_regs __regs)
Takashi YOSHII4b565682006-09-27 17:15:32 +0900655{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900656 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900657 unsigned long error_code;
658 struct task_struct *tsk = current;
659
660#ifdef CONFIG_SH_FPU_EMU
Yoshinori Sato0983b312006-11-05 15:58:47 +0900661 unsigned short inst = 0;
Takashi YOSHII4b565682006-09-27 17:15:32 +0900662 int err;
663
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900664 get_user(inst, (unsigned short*)regs->pc);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900665
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900666 err = do_fpu_inst(inst, regs);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900667 if (!err) {
Paul Mundt53f983a2007-05-08 15:31:48 +0900668 regs->pc += instruction_size(inst);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900669 return;
670 }
671 /* not a FPU inst. */
672#endif
673
674#ifdef CONFIG_SH_DSP
675 /* Check if it's a DSP instruction */
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900676 if (is_dsp_inst(regs)) {
Takashi YOSHII4b565682006-09-27 17:15:32 +0900677 /* Enable DSP mode, and restart instruction. */
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900678 regs->sr |= SR_DSP;
Takashi YOSHII4b565682006-09-27 17:15:32 +0900679 return;
680 }
681#endif
682
Paul Mundt4c59e292008-09-21 12:00:23 +0900683 error_code = lookup_exception_vector();
Yoshinori Sato0983b312006-11-05 15:58:47 +0900684
Takashi YOSHII4b565682006-09-27 17:15:32 +0900685 local_irq_enable();
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900686 CHK_REMOTE_DEBUG(regs);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900687 force_sig(SIGILL, tsk);
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900688 die_if_no_fixup("reserved instruction", regs, error_code);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900689}
690
691#ifdef CONFIG_SH_FPU_EMU
Paul Mundtedfd6da2008-11-26 13:06:04 +0900692static int emulate_branch(unsigned short inst, struct pt_regs *regs)
Takashi YOSHII4b565682006-09-27 17:15:32 +0900693{
694 /*
695 * bfs: 8fxx: PC+=d*2+4;
696 * bts: 8dxx: PC+=d*2+4;
697 * bra: axxx: PC+=D*2+4;
698 * bsr: bxxx: PC+=D*2+4 after PR=PC+4;
699 * braf:0x23: PC+=Rn*2+4;
700 * bsrf:0x03: PC+=Rn*2+4 after PR=PC+4;
701 * jmp: 4x2b: PC=Rn;
702 * jsr: 4x0b: PC=Rn after PR=PC+4;
703 * rts: 000b: PC=PR;
704 */
Paul Mundtedfd6da2008-11-26 13:06:04 +0900705 if (((inst & 0xf000) == 0xb000) || /* bsr */
706 ((inst & 0xf0ff) == 0x0003) || /* bsrf */
707 ((inst & 0xf0ff) == 0x400b)) /* jsr */
708 regs->pr = regs->pc + 4;
709
710 if ((inst & 0xfd00) == 0x8d00) { /* bfs, bts */
Takashi YOSHII4b565682006-09-27 17:15:32 +0900711 regs->pc += SH_PC_8BIT_OFFSET(inst);
712 return 0;
713 }
714
Paul Mundtedfd6da2008-11-26 13:06:04 +0900715 if ((inst & 0xe000) == 0xa000) { /* bra, bsr */
Takashi YOSHII4b565682006-09-27 17:15:32 +0900716 regs->pc += SH_PC_12BIT_OFFSET(inst);
717 return 0;
718 }
719
Paul Mundtedfd6da2008-11-26 13:06:04 +0900720 if ((inst & 0xf0df) == 0x0003) { /* braf, bsrf */
Takashi YOSHII4b565682006-09-27 17:15:32 +0900721 regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4;
722 return 0;
723 }
724
Paul Mundtedfd6da2008-11-26 13:06:04 +0900725 if ((inst & 0xf0df) == 0x400b) { /* jmp, jsr */
Takashi YOSHII4b565682006-09-27 17:15:32 +0900726 regs->pc = regs->regs[(inst & 0x0f00) >> 8];
727 return 0;
728 }
729
Paul Mundtedfd6da2008-11-26 13:06:04 +0900730 if ((inst & 0xffff) == 0x000b) { /* rts */
Takashi YOSHII4b565682006-09-27 17:15:32 +0900731 regs->pc = regs->pr;
732 return 0;
733 }
734
735 return 1;
736}
737#endif
738
739asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5,
740 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900741 struct pt_regs __regs)
Takashi YOSHII4b565682006-09-27 17:15:32 +0900742{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900743 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Paul Mundtb3d765f2008-09-17 23:12:11 +0900744 unsigned long inst;
Takashi YOSHII4b565682006-09-27 17:15:32 +0900745 struct task_struct *tsk = current;
Chris Smithd39f5452008-09-05 17:15:39 +0900746
747 if (kprobe_handle_illslot(regs->pc) == 0)
748 return;
749
Takashi YOSHII4b565682006-09-27 17:15:32 +0900750#ifdef CONFIG_SH_FPU_EMU
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900751 get_user(inst, (unsigned short *)regs->pc + 1);
752 if (!do_fpu_inst(inst, regs)) {
753 get_user(inst, (unsigned short *)regs->pc);
754 if (!emulate_branch(inst, regs))
Takashi YOSHII4b565682006-09-27 17:15:32 +0900755 return;
756 /* fault in branch.*/
757 }
758 /* not a FPU inst. */
759#endif
760
Paul Mundt4c59e292008-09-21 12:00:23 +0900761 inst = lookup_exception_vector();
Yoshinori Sato0983b312006-11-05 15:58:47 +0900762
Takashi YOSHII4b565682006-09-27 17:15:32 +0900763 local_irq_enable();
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900764 CHK_REMOTE_DEBUG(regs);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900765 force_sig(SIGILL, tsk);
Paul Mundtb3d765f2008-09-17 23:12:11 +0900766 die_if_no_fixup("illegal slot instruction", regs, inst);
Takashi YOSHII4b565682006-09-27 17:15:32 +0900767}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769asmlinkage void do_exception_error(unsigned long r4, unsigned long r5,
770 unsigned long r6, unsigned long r7,
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900771 struct pt_regs __regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900773 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 long ex;
Yoshinori Sato0983b312006-11-05 15:58:47 +0900775
Paul Mundt4c59e292008-09-21 12:00:23 +0900776 ex = lookup_exception_vector();
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900777 die_if_kernel("exception", regs, ex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
780#if defined(CONFIG_SH_STANDARD_BIOS)
781void *gdb_vbr_vector;
782
783static inline void __init gdb_vbr_init(void)
784{
785 register unsigned long vbr;
786
787 /*
788 * Read the old value of the VBR register to initialise
789 * the vector through which debug and BIOS traps are
790 * delegated by the Linux trap handler.
791 */
792 asm volatile("stc vbr, %0" : "=r" (vbr));
793
794 gdb_vbr_vector = (void *)(vbr + 0x100);
795 printk("Setting GDB trap vector to 0x%08lx\n",
796 (unsigned long)gdb_vbr_vector);
797}
798#endif
799
Paul Mundtaba10302007-09-21 18:32:32 +0900800void __cpuinit per_cpu_trap_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
802 extern void *vbr_base;
803
804#ifdef CONFIG_SH_STANDARD_BIOS
Paul Mundtaba10302007-09-21 18:32:32 +0900805 if (raw_smp_processor_id() == 0)
806 gdb_vbr_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#endif
808
809 /* NOTE: The VBR value should be at P1
810 (or P2, virtural "fixed" address space).
811 It's definitely should not in physical address. */
812
813 asm volatile("ldc %0, vbr"
814 : /* no output */
815 : "r" (&vbr_base)
816 : "memory");
817}
818
Paul Mundt1f666582006-10-19 16:20:25 +0900819void *set_exception_table_vec(unsigned int vec, void *handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 extern void *exception_handling_table[];
Paul Mundt1f666582006-10-19 16:20:25 +0900822 void *old_handler;
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900823
Paul Mundt1f666582006-10-19 16:20:25 +0900824 old_handler = exception_handling_table[vec];
825 exception_handling_table[vec] = handler;
826 return old_handler;
827}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Paul Mundt1f666582006-10-19 16:20:25 +0900829void __init trap_init(void)
830{
831 set_exception_table_vec(TRAP_RESERVED_INST, do_reserved_inst);
832 set_exception_table_vec(TRAP_ILLEGAL_SLOT_INST, do_illegal_slot_inst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Takashi YOSHII4b565682006-09-27 17:15:32 +0900834#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \
835 defined(CONFIG_SH_FPU_EMU)
836 /*
837 * For SH-4 lacking an FPU, treat floating point instructions as
838 * reserved. They'll be handled in the math-emu case, or faulted on
839 * otherwise.
840 */
Paul Mundt1f666582006-10-19 16:20:25 +0900841 set_exception_table_evt(0x800, do_reserved_inst);
842 set_exception_table_evt(0x820, do_illegal_slot_inst);
843#elif defined(CONFIG_SH_FPU)
Paul Mundte0a36472007-08-01 16:55:07 +0900844#ifdef CONFIG_CPU_SUBTYPE_SHX3
Paul Mundt74d99a52007-11-26 20:38:36 +0900845 set_exception_table_evt(0xd80, fpu_state_restore_trap_handler);
846 set_exception_table_evt(0xda0, fpu_state_restore_trap_handler);
Paul Mundte0a36472007-08-01 16:55:07 +0900847#else
Paul Mundt74d99a52007-11-26 20:38:36 +0900848 set_exception_table_evt(0x800, fpu_state_restore_trap_handler);
849 set_exception_table_evt(0x820, fpu_state_restore_trap_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850#endif
Paul Mundte0a36472007-08-01 16:55:07 +0900851#endif
Yoshinori Sato0983b312006-11-05 15:58:47 +0900852
853#ifdef CONFIG_CPU_SH2
Paul Mundt5a4f7c62007-11-20 18:08:06 +0900854 set_exception_table_vec(TRAP_ADDRESS_ERROR, address_error_trap_handler);
Yoshinori Sato0983b312006-11-05 15:58:47 +0900855#endif
856#ifdef CONFIG_CPU_SH2A
857 set_exception_table_vec(TRAP_DIVZERO_ERROR, do_divide_error);
858 set_exception_table_vec(TRAP_DIVOVF_ERROR, do_divide_error);
Yoshinori Sato6e80f5e2008-07-10 01:20:03 +0900859#ifdef CONFIG_SH_FPU
860 set_exception_table_vec(TRAP_FPU_ERROR, fpu_error_trap_handler);
861#endif
Yoshinori Sato0983b312006-11-05 15:58:47 +0900862#endif
Stuart Menefyb5a1bcb2006-11-21 13:34:04 +0900863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 /* Setup VBR for boot cpu */
865 per_cpu_trap_init();
866}
867
Paul Mundt6b002232006-10-12 17:07:45 +0900868void show_trace(struct task_struct *tsk, unsigned long *sp,
869 struct pt_regs *regs)
870{
871 unsigned long addr;
872
873 if (regs && user_mode(regs))
874 return;
875
876 printk("\nCall trace: ");
877#ifdef CONFIG_KALLSYMS
878 printk("\n");
879#endif
880
881 while (!kstack_end(sp)) {
882 addr = *sp++;
883 if (kernel_text_address(addr))
884 print_ip_sym(addr);
885 }
886
887 printk("\n");
Paul Mundt9b8c90e2006-12-06 11:07:51 +0900888
889 if (!tsk)
890 tsk = current;
891
892 debug_show_held_locks(tsk);
Paul Mundt6b002232006-10-12 17:07:45 +0900893}
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895void show_stack(struct task_struct *tsk, unsigned long *sp)
896{
Paul Mundt6b002232006-10-12 17:07:45 +0900897 unsigned long stack;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Paul Mundta6a311392006-09-27 18:22:14 +0900899 if (!tsk)
900 tsk = current;
901 if (tsk == current)
902 sp = (unsigned long *)current_stack_pointer;
903 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 sp = (unsigned long *)tsk->thread.sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Paul Mundt6b002232006-10-12 17:07:45 +0900906 stack = (unsigned long)sp;
907 dump_mem("Stack: ", stack, THREAD_SIZE +
908 (unsigned long)task_stack_page(tsk));
909 show_trace(tsk, sp, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
912void dump_stack(void)
913{
914 show_stack(NULL, NULL);
915}
916EXPORT_SYMBOL(dump_stack);