Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * linux/arch/cris/traps.c |
| 3 | * |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 4 | * Here we handle the break vectors not used by the system call |
| 5 | * mechanism, as well as some general stack/register dumping |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * things. |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 7 | * |
| 8 | * Copyright (C) 2000-2007 Axis Communications AB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Authors: Bjorn Wesen |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 11 | * Hans-Peter Nilsson |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/pgtable.h> |
| 19 | #include <asm/uaccess.h> |
| 20 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 21 | extern void arch_enable_nmi(void); |
| 22 | extern void stop_watchdog(void); |
| 23 | extern void reset_watchdog(void); |
| 24 | extern void show_registers(struct pt_regs *regs); |
| 25 | |
| 26 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 27 | extern void handle_BUG(struct pt_regs *regs); |
| 28 | #else |
| 29 | #define handle_BUG(regs) |
| 30 | #endif |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int kstack_depth_to_print = 24; |
| 33 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 34 | void (*nmi_handler)(struct pt_regs *); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 35 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 36 | void |
| 37 | show_trace(unsigned long *stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
| 39 | unsigned long addr, module_start, module_end; |
| 40 | extern char _stext, _etext; |
| 41 | int i; |
| 42 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 43 | printk("\nCall Trace: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 45 | i = 1; |
| 46 | module_start = VMALLOC_START; |
| 47 | module_end = VMALLOC_END; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 49 | while (((long)stack & (THREAD_SIZE-1)) != 0) { |
| 50 | if (__get_user(addr, stack)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* This message matches "failing address" marked |
| 52 | s390 in ksymoops, so lines containing it will |
| 53 | not be filtered out by ksymoops. */ |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 54 | printk("Failing address 0x%lx\n", (unsigned long)stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | stack++; |
| 58 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 59 | /* |
| 60 | * If the address is either in the text segment of the |
| 61 | * kernel, or in the region which contains vmalloc'ed |
| 62 | * memory, it *may* be the address of a calling |
| 63 | * routine; if so, print it so that someone tracing |
| 64 | * down the cause of the crash will be able to figure |
| 65 | * out the call path that was taken. |
| 66 | */ |
| 67 | if (((addr >= (unsigned long)&_stext) && |
| 68 | (addr <= (unsigned long)&_etext)) || |
| 69 | ((addr >= module_start) && (addr <= module_end))) { |
| 70 | if (i && ((i % 8) == 0)) |
| 71 | printk("\n "); |
| 72 | printk("[<%08lx>] ", addr); |
| 73 | i++; |
| 74 | } |
| 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* |
| 79 | * These constants are for searching for possible module text |
| 80 | * segments. MODULE_RANGE is a guess of how much space is likely |
| 81 | * to be vmalloced. |
| 82 | */ |
| 83 | |
| 84 | #define MODULE_RANGE (8*1024*1024) |
| 85 | |
| 86 | /* |
| 87 | * The output (format, strings and order) is adjusted to be usable with |
| 88 | * ksymoops-2.4.1 with some necessary CRIS-specific patches. Please don't |
| 89 | * change it unless you're serious about adjusting ksymoops and syncing |
| 90 | * with the ksymoops maintainer. |
| 91 | */ |
| 92 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 93 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | show_stack(struct task_struct *task, unsigned long *sp) |
| 95 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 96 | unsigned long *stack, addr; |
| 97 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * debugging aid: "show_stack(NULL);" prints a |
| 101 | * back trace. |
| 102 | */ |
| 103 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 104 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (task) |
| 106 | sp = (unsigned long*)task->thread.ksp; |
| 107 | else |
| 108 | sp = (unsigned long*)rdsp(); |
| 109 | } |
| 110 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 111 | stack = sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 113 | printk("\nStack from %08lx:\n ", (unsigned long)stack); |
| 114 | for (i = 0; i < kstack_depth_to_print; i++) { |
| 115 | if (((long)stack & (THREAD_SIZE-1)) == 0) |
| 116 | break; |
| 117 | if (i && ((i % 8) == 0)) |
| 118 | printk("\n "); |
| 119 | if (__get_user(addr, stack)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* This message matches "failing address" marked |
| 121 | s390 in ksymoops, so lines containing it will |
| 122 | not be filtered out by ksymoops. */ |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 123 | printk("Failing address 0x%lx\n", (unsigned long)stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | break; |
| 125 | } |
| 126 | stack++; |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 127 | printk("%08lx ", addr); |
| 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | show_trace(sp); |
| 130 | } |
| 131 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 132 | #if 0 |
| 133 | /* displays a short stack trace */ |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 134 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 135 | int |
| 136 | show_stack(void) |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 137 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 138 | unsigned long *sp = (unsigned long *)rdusp(); |
| 139 | int i; |
| 140 | |
| 141 | printk("Stack dump [0x%08lx]:\n", (unsigned long)sp); |
| 142 | for (i = 0; i < 16; i++) |
| 143 | printk("sp + %d: 0x%08lx\n", i*4, sp[i]); |
| 144 | return 0; |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 145 | } |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 146 | #endif |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 147 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 148 | void |
| 149 | dump_stack(void) |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 150 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 151 | show_stack(NULL, NULL); |
| 152 | } |
| 153 | EXPORT_SYMBOL(dump_stack); |
| 154 | |
| 155 | void |
| 156 | set_nmi_handler(void (*handler)(struct pt_regs *)) |
| 157 | { |
| 158 | nmi_handler = handler; |
| 159 | arch_enable_nmi(); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | #ifdef CONFIG_DEBUG_NMI_OOPS |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 163 | void |
| 164 | oops_nmi_handler(struct pt_regs *regs) |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 165 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 166 | stop_watchdog(); |
| 167 | oops_in_progress = 1; |
| 168 | printk("NMI!\n"); |
| 169 | show_registers(regs); |
| 170 | oops_in_progress = 0; |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 173 | static int __init |
| 174 | oops_nmi_register(void) |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 175 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 176 | set_nmi_handler(oops_nmi_handler); |
| 177 | return 0; |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | __initcall(oops_nmi_register); |
| 181 | |
| 182 | #endif |
| 183 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 184 | /* |
| 185 | * This gets called from entry.S when the watchdog has bitten. Show something |
| 186 | * similiar to an Oops dump, and if the kernel is configured to be a nice |
| 187 | * doggy, then halt instead of reboot. |
| 188 | */ |
| 189 | void |
| 190 | watchdog_bite_hook(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 192 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 193 | local_irq_disable(); |
| 194 | stop_watchdog(); |
| 195 | show_registers(regs); |
| 196 | |
| 197 | while (1) |
| 198 | ; /* Do nothing. */ |
| 199 | #else |
| 200 | show_registers(regs); |
| 201 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 203 | |
| 204 | /* This is normally the Oops function. */ |
| 205 | void |
| 206 | die_if_kernel(const char *str, struct pt_regs *regs, long err) |
| 207 | { |
| 208 | if (user_mode(regs)) |
| 209 | return; |
| 210 | |
| 211 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 212 | /* |
| 213 | * This printout might take too long and could trigger |
| 214 | * the watchdog normally. If NICE_DOGGY is set, simply |
| 215 | * stop the watchdog during the printout. |
| 216 | */ |
| 217 | stop_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | #endif |
| 219 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 220 | handle_BUG(regs); |
| 221 | |
| 222 | printk("%s: %04lx\n", str, err & 0xffff); |
| 223 | |
| 224 | show_registers(regs); |
| 225 | |
| 226 | oops_in_progress = 0; |
| 227 | |
| 228 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 229 | reset_watchdog(); |
| 230 | #endif |
| 231 | do_exit(SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Jesper Nilsson | 1ddba02 | 2007-11-30 14:11:29 +0100 | [diff] [blame] | 234 | void __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | trap_init(void) |
| 236 | { |
| 237 | /* Nothing needs to be done */ |
| 238 | } |