Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 1 | /* $Id: traps.c,v 1.4 2005/04/24 18:47:55 starvik Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * linux/arch/cris/arch-v10/traps.c |
| 4 | * |
| 5 | * Heler functions for trap handlers |
| 6 | * |
| 7 | * Copyright (C) 2000-2002 Axis Communications AB |
| 8 | * |
| 9 | * Authors: Bjorn Wesen |
| 10 | * Hans-Peter Nilsson |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/config.h> |
| 15 | #include <linux/ptrace.h> |
| 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/arch/sv_addr_ag.h> |
| 18 | |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 19 | extern int raw_printk(const char *fmt, ...); |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | void |
| 22 | show_registers(struct pt_regs * regs) |
| 23 | { |
| 24 | /* We either use rdusp() - the USP register, which might not |
| 25 | correspond to the current process for all cases we're called, |
| 26 | or we use the current->thread.usp, which is not up to date for |
| 27 | the current process. Experience shows we want the USP |
| 28 | register. */ |
| 29 | unsigned long usp = rdusp(); |
| 30 | |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 31 | raw_printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | regs->irp, regs->srp, regs->dccr, usp, regs->mof ); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 33 | raw_printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | regs->r0, regs->r1, regs->r2, regs->r3); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 35 | raw_printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | regs->r4, regs->r5, regs->r6, regs->r7); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 37 | raw_printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | regs->r8, regs->r9, regs->r10, regs->r11); |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 39 | raw_printk("r12: %08lx r13: %08lx oR10: %08lx sp: %08lx\n", |
| 40 | regs->r12, regs->r13, regs->orig_r10, regs); |
| 41 | raw_printk("R_MMU_CAUSE: %08lx\n", (unsigned long)*R_MMU_CAUSE); |
| 42 | raw_printk("Process %s (pid: %d, stackpage=%08lx)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | current->comm, current->pid, (unsigned long)current); |
| 44 | |
| 45 | /* |
| 46 | * When in-kernel, we also print out the stack and code at the |
| 47 | * time of the fault.. |
| 48 | */ |
| 49 | if (! user_mode(regs)) { |
| 50 | int i; |
| 51 | |
| 52 | show_stack(NULL, (unsigned long*)usp); |
| 53 | |
| 54 | /* Dump kernel stack if the previous dump wasn't one. */ |
| 55 | if (usp != 0) |
| 56 | show_stack (NULL, NULL); |
| 57 | |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 58 | raw_printk("\nCode: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if(regs->irp < PAGE_OFFSET) |
| 60 | goto bad; |
| 61 | |
| 62 | /* Often enough the value at regs->irp does not point to |
| 63 | the interesting instruction, which is most often the |
| 64 | _previous_ instruction. So we dump at an offset large |
| 65 | enough that instruction decoding should be in sync at |
| 66 | the interesting point, but small enough to fit on a row |
| 67 | (sort of). We point out the regs->irp location in a |
| 68 | ksymoops-friendly way by wrapping the byte for that |
| 69 | address in parentheses. */ |
| 70 | for(i = -12; i < 12; i++) |
| 71 | { |
| 72 | unsigned char c; |
| 73 | if(__get_user(c, &((unsigned char*)regs->irp)[i])) { |
| 74 | bad: |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 75 | raw_printk(" Bad IP value."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | break; |
| 77 | } |
| 78 | |
| 79 | if (i == 0) |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 80 | raw_printk("(%02x) ", c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | else |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 82 | raw_printk("%02x ", c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 84 | raw_printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | /* Called from entry.S when the watchdog has bitten |
| 89 | * We print out something resembling an oops dump, and if |
| 90 | * we have the nice doggy development flag set, we halt here |
| 91 | * instead of rebooting. |
| 92 | */ |
| 93 | |
| 94 | extern void reset_watchdog(void); |
| 95 | extern void stop_watchdog(void); |
| 96 | |
| 97 | |
| 98 | void |
| 99 | watchdog_bite_hook(struct pt_regs *regs) |
| 100 | { |
| 101 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 102 | local_irq_disable(); |
| 103 | stop_watchdog(); |
| 104 | show_registers(regs); |
| 105 | while(1) /* nothing */; |
| 106 | #else |
| 107 | show_registers(regs); |
| 108 | #endif |
| 109 | } |
| 110 | |
| 111 | /* This is normally the 'Oops' routine */ |
| 112 | void |
| 113 | die_if_kernel(const char * str, struct pt_regs * regs, long err) |
| 114 | { |
| 115 | if(user_mode(regs)) |
| 116 | return; |
| 117 | |
| 118 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 119 | /* This printout might take too long and trigger the |
| 120 | * watchdog normally. If we're in the nice doggy |
| 121 | * development mode, stop the watchdog during printout. |
| 122 | */ |
| 123 | stop_watchdog(); |
| 124 | #endif |
| 125 | |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 126 | raw_printk("%s: %04lx\n", str, err & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | show_registers(regs); |
| 129 | |
| 130 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY |
| 131 | reset_watchdog(); |
| 132 | #endif |
| 133 | do_exit(SIGSEGV); |
| 134 | } |
Mikael Starvik | 059163ca | 2005-07-27 11:44:32 -0700 | [diff] [blame] | 135 | |
| 136 | void arch_enable_nmi(void) |
| 137 | { |
| 138 | asm volatile("setf m"); |
| 139 | } |