blob: 881b9a32b7de25607bbafef418e4fbf707fe7563 [file] [log] [blame]
Paul Mundt5a4f7c62007-11-20 18:08:06 +09001#include <linux/bug.h>
2#include <linux/io.h>
3#include <linux/types.h>
4#include <linux/kdebug.h>
Paul Mundt47a3eb92007-11-26 18:17:51 +09005#include <linux/signal.h>
6#include <linux/sched.h>
Paul Mundt9a33fc22008-05-19 19:32:07 +09007#include <linux/uaccess.h>
Paul Mundt5a4f7c62007-11-20 18:08:06 +09008#include <asm/system.h>
9
10#ifdef CONFIG_BUG
Matt Flemingb344e24a2009-08-16 21:54:48 +010011void handle_BUG(struct pt_regs *regs)
Paul Mundt5a4f7c62007-11-20 18:08:06 +090012{
13 enum bug_trap_type tt;
14 tt = report_bug(regs->pc, regs);
15 if (tt == BUG_TRAP_TYPE_WARN) {
16 regs->pc += instruction_size(regs->pc);
17 return;
18 }
19
20 die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);
21}
22
23int is_valid_bugaddr(unsigned long addr)
24{
Paul Mundt2bcfffa2009-05-09 16:02:08 +090025 insn_size_t opcode;
Paul Mundt9a33fc22008-05-19 19:32:07 +090026
27 if (addr < PAGE_OFFSET)
28 return 0;
Paul Mundt2bcfffa2009-05-09 16:02:08 +090029 if (probe_kernel_address((insn_size_t *)addr, opcode))
Paul Mundt9a33fc22008-05-19 19:32:07 +090030 return 0;
31
Matt Flemingb344e24a2009-08-16 21:54:48 +010032 if (opcode == TRAPA_BUG_OPCODE || opcode == TRAPA_UNWINDER_BUG_OPCODE)
33 return 1;
34
35 return 0;
Paul Mundt5a4f7c62007-11-20 18:08:06 +090036}
37#endif
38
39/*
40 * Generic trap handler.
41 */
42BUILD_TRAP_HANDLER(debug)
43{
44 TRAP_HANDLER_DECL;
45
46 /* Rewind */
47 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
48
49 if (notify_die(DIE_TRAP, "debug trap", regs, 0, vec & 0xff,
50 SIGTRAP) == NOTIFY_STOP)
51 return;
52
53 force_sig(SIGTRAP, current);
54}
55
56/*
57 * Special handler for BUG() traps.
58 */
59BUILD_TRAP_HANDLER(bug)
60{
61 TRAP_HANDLER_DECL;
62
63 /* Rewind */
64 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
65
66 if (notify_die(DIE_TRAP, "bug trap", regs, 0, TRAPA_BUG_OPCODE & 0xff,
67 SIGTRAP) == NOTIFY_STOP)
68 return;
69
70#ifdef CONFIG_BUG
71 if (__kernel_text_address(instruction_pointer(regs))) {
Paul Mundt2bcfffa2009-05-09 16:02:08 +090072 insn_size_t insn = *(insn_size_t *)instruction_pointer(regs);
Paul Mundt5a4f7c62007-11-20 18:08:06 +090073 if (insn == TRAPA_BUG_OPCODE)
74 handle_BUG(regs);
Magnus Damm0ec39882009-06-17 04:48:20 +000075 return;
Paul Mundt5a4f7c62007-11-20 18:08:06 +090076 }
77#endif
78
79 force_sig(SIGTRAP, current);
80}