Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 1 | #include <linux/bug.h> |
| 2 | #include <linux/io.h> |
| 3 | #include <linux/types.h> |
| 4 | #include <linux/kdebug.h> |
Paul Mundt | 47a3eb9 | 2007-11-26 18:17:51 +0900 | [diff] [blame] | 5 | #include <linux/signal.h> |
| 6 | #include <linux/sched.h> |
Paul Mundt | 9a33fc2 | 2008-05-19 19:32:07 +0900 | [diff] [blame] | 7 | #include <linux/uaccess.h> |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 8 | #include <asm/system.h> |
| 9 | |
| 10 | #ifdef CONFIG_BUG |
| 11 | static void handle_BUG(struct pt_regs *regs) |
| 12 | { |
| 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 | |
| 23 | int is_valid_bugaddr(unsigned long addr) |
| 24 | { |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 25 | insn_size_t opcode; |
Paul Mundt | 9a33fc2 | 2008-05-19 19:32:07 +0900 | [diff] [blame] | 26 | |
| 27 | if (addr < PAGE_OFFSET) |
| 28 | return 0; |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 29 | if (probe_kernel_address((insn_size_t *)addr, opcode)) |
Paul Mundt | 9a33fc2 | 2008-05-19 19:32:07 +0900 | [diff] [blame] | 30 | return 0; |
| 31 | |
| 32 | return opcode == TRAPA_BUG_OPCODE; |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 33 | } |
| 34 | #endif |
| 35 | |
| 36 | /* |
| 37 | * Generic trap handler. |
| 38 | */ |
| 39 | BUILD_TRAP_HANDLER(debug) |
| 40 | { |
| 41 | TRAP_HANDLER_DECL; |
| 42 | |
| 43 | /* Rewind */ |
| 44 | regs->pc -= instruction_size(ctrl_inw(regs->pc - 4)); |
| 45 | |
| 46 | if (notify_die(DIE_TRAP, "debug trap", regs, 0, vec & 0xff, |
| 47 | SIGTRAP) == NOTIFY_STOP) |
| 48 | return; |
| 49 | |
| 50 | force_sig(SIGTRAP, current); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Special handler for BUG() traps. |
| 55 | */ |
| 56 | BUILD_TRAP_HANDLER(bug) |
| 57 | { |
| 58 | TRAP_HANDLER_DECL; |
| 59 | |
| 60 | /* Rewind */ |
| 61 | regs->pc -= instruction_size(ctrl_inw(regs->pc - 4)); |
| 62 | |
| 63 | if (notify_die(DIE_TRAP, "bug trap", regs, 0, TRAPA_BUG_OPCODE & 0xff, |
| 64 | SIGTRAP) == NOTIFY_STOP) |
| 65 | return; |
| 66 | |
| 67 | #ifdef CONFIG_BUG |
| 68 | if (__kernel_text_address(instruction_pointer(regs))) { |
Paul Mundt | 2bcfffa | 2009-05-09 16:02:08 +0900 | [diff] [blame] | 69 | insn_size_t insn = *(insn_size_t *)instruction_pointer(regs); |
Paul Mundt | 5a4f7c6 | 2007-11-20 18:08:06 +0900 | [diff] [blame] | 70 | if (insn == TRAPA_BUG_OPCODE) |
| 71 | handle_BUG(regs); |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | force_sig(SIGTRAP, current); |
| 76 | } |