blob: 4becc1bcced98712a9799c42383ce14f78d98768 [file] [log] [blame]
Mikael Starvik059163ca2005-07-27 11:44:32 -07001/* $Id: traps.c,v 1.4 2005/04/24 18:47:55 starvik Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/ptrace.h>
15#include <asm/uaccess.h>
16#include <asm/arch/sv_addr_ag.h>
17
Mikael Starvik059163ca2005-07-27 11:44:32 -070018extern int raw_printk(const char *fmt, ...);
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020void
21show_registers(struct pt_regs * regs)
22{
23 /* We either use rdusp() - the USP register, which might not
24 correspond to the current process for all cases we're called,
25 or we use the current->thread.usp, which is not up to date for
26 the current process. Experience shows we want the USP
27 register. */
28 unsigned long usp = rdusp();
29
Mikael Starvik059163ca2005-07-27 11:44:32 -070030 raw_printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 regs->irp, regs->srp, regs->dccr, usp, regs->mof );
Mikael Starvik059163ca2005-07-27 11:44:32 -070032 raw_printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 regs->r0, regs->r1, regs->r2, regs->r3);
Mikael Starvik059163ca2005-07-27 11:44:32 -070034 raw_printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 regs->r4, regs->r5, regs->r6, regs->r7);
Mikael Starvik059163ca2005-07-27 11:44:32 -070036 raw_printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 regs->r8, regs->r9, regs->r10, regs->r11);
Mikael Starvik059163ca2005-07-27 11:44:32 -070038 raw_printk("r12: %08lx r13: %08lx oR10: %08lx sp: %08lx\n",
39 regs->r12, regs->r13, regs->orig_r10, regs);
40 raw_printk("R_MMU_CAUSE: %08lx\n", (unsigned long)*R_MMU_CAUSE);
41 raw_printk("Process %s (pid: %d, stackpage=%08lx)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 current->comm, current->pid, (unsigned long)current);
43
44 /*
45 * When in-kernel, we also print out the stack and code at the
46 * time of the fault..
47 */
48 if (! user_mode(regs)) {
49 int i;
50
51 show_stack(NULL, (unsigned long*)usp);
52
53 /* Dump kernel stack if the previous dump wasn't one. */
54 if (usp != 0)
55 show_stack (NULL, NULL);
56
Mikael Starvik059163ca2005-07-27 11:44:32 -070057 raw_printk("\nCode: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if(regs->irp < PAGE_OFFSET)
59 goto bad;
60
61 /* Often enough the value at regs->irp does not point to
62 the interesting instruction, which is most often the
63 _previous_ instruction. So we dump at an offset large
64 enough that instruction decoding should be in sync at
65 the interesting point, but small enough to fit on a row
66 (sort of). We point out the regs->irp location in a
67 ksymoops-friendly way by wrapping the byte for that
68 address in parentheses. */
69 for(i = -12; i < 12; i++)
70 {
71 unsigned char c;
72 if(__get_user(c, &((unsigned char*)regs->irp)[i])) {
73bad:
Mikael Starvik059163ca2005-07-27 11:44:32 -070074 raw_printk(" Bad IP value.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 break;
76 }
77
78 if (i == 0)
Mikael Starvik059163ca2005-07-27 11:44:32 -070079 raw_printk("(%02x) ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 else
Mikael Starvik059163ca2005-07-27 11:44:32 -070081 raw_printk("%02x ", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
Mikael Starvik059163ca2005-07-27 11:44:32 -070083 raw_printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85}
86
87/* Called from entry.S when the watchdog has bitten
88 * We print out something resembling an oops dump, and if
89 * we have the nice doggy development flag set, we halt here
90 * instead of rebooting.
91 */
92
93extern void reset_watchdog(void);
94extern void stop_watchdog(void);
95
96
97void
98watchdog_bite_hook(struct pt_regs *regs)
99{
100#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
101 local_irq_disable();
102 stop_watchdog();
103 show_registers(regs);
104 while(1) /* nothing */;
105#else
106 show_registers(regs);
107#endif
108}
109
110/* This is normally the 'Oops' routine */
111void
112die_if_kernel(const char * str, struct pt_regs * regs, long err)
113{
114 if(user_mode(regs))
115 return;
116
117#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
118 /* This printout might take too long and trigger the
119 * watchdog normally. If we're in the nice doggy
120 * development mode, stop the watchdog during printout.
121 */
122 stop_watchdog();
123#endif
124
Mikael Starvik059163ca2005-07-27 11:44:32 -0700125 raw_printk("%s: %04lx\n", str, err & 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 show_registers(regs);
128
129#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
130 reset_watchdog();
131#endif
132 do_exit(SIGSEGV);
133}
Mikael Starvik059163ca2005-07-27 11:44:32 -0700134
135void arch_enable_nmi(void)
136{
137 asm volatile("setf m");
138}