MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / kernel / traps.c
blob14b7e4ca7013b321b36b7e63b70c09d6e42a769c
1 /*
2 * arch/niosnommu/kernel/traps.c
4 * Copyright 2004 Microtronix Datacom Ltd.
5 * Copyright 2001 Vic Phillips
6 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
8 * hacked from:
10 * arch/sparcnommu/kernel/traps.c
12 * All rights reserved.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
22 * NON INFRINGEMENT. See the GNU General Public License for more
23 * details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/sched.h> /* for jiffies */
32 #include <linux/kernel.h>
33 #include <linux/signal.h>
34 #include <linux/module.h>
36 #include <asm/delay.h>
37 #include <asm/system.h>
38 #include <asm/ptrace.h>
39 #include <asm/page.h>
40 #include <asm/pgtable.h>
41 #include <asm/unistd.h>
43 #include <asm/nios.h>
45 /* #define TRAP_DEBUG */
47 #if 0
48 void dumpit(unsigned long l1, unsigned long l2)
50 printk("0x%08x l1 0x%08x l2\n");
51 while(1);
54 struct trap_trace_entry {
55 unsigned long pc;
56 unsigned long type;
59 int trap_curbuf = 0;
60 struct trap_trace_entry trapbuf[1024];
62 void syscall_trace_entry(struct pt_regs *regs)
64 printk("%s[%d]: ", current->comm, current->pid);
65 printk("scall<%d> (could be %d)\n", (int) regs->r3,
66 (int) regs->r4);
69 void syscall_trace_exit(struct pt_regs *regs)
72 #endif
75 * The architecture-independent backtrace generator
77 void dump_stack(void)
79 unsigned long stack;
81 show_stack(current, &stack);
84 EXPORT_SYMBOL(dump_stack);
87 * The show_stack is an external API which we do not use ourselves.
88 * The oops is printed in die_if_kernel.
91 int kstack_depth_to_print = 48;
93 void show_stack(struct task_struct *task, unsigned long *stack)
95 unsigned long *endstack, addr;
96 extern char _start, _etext;
97 int i;
99 if (!stack) {
100 if (task)
101 stack = (unsigned long *)task->thread.ksp;
102 else
103 stack = (unsigned long *)&stack;
106 addr = (unsigned long) stack;
107 endstack = (unsigned long *) PAGE_ALIGN(addr);
109 printk(KERN_EMERG "Stack from %08lx:", (unsigned long)stack);
110 for (i = 0; i < kstack_depth_to_print; i++) {
111 if (stack + 1 > endstack)
112 break;
113 if (i % 8 == 0)
114 printk(KERN_EMERG "\n ");
115 printk(KERN_EMERG " %08lx", *stack++);
118 printk(KERN_EMERG "\nCall Trace:");
119 i = 0;
120 while (stack + 1 <= endstack) {
121 addr = *stack++;
123 * If the address is either in the text segment of the
124 * kernel, or in the region which contains vmalloc'ed
125 * memory, it *may* be the address of a calling
126 * routine; if so, print it so that someone tracing
127 * down the cause of the crash will be able to figure
128 * out the call path that was taken.
130 if (((addr >= (unsigned long) &_start) &&
131 (addr <= (unsigned long) &_etext))) {
132 if (i % 4 == 0)
133 printk(KERN_EMERG "\n ");
134 printk(KERN_EMERG " [<%08lx>]", addr);
135 i++;
138 printk(KERN_EMERG "\n");
141 void die_if_kernel(char *str, struct pt_regs *pregs)
143 unsigned long pc;
145 pc = pregs->ra;
146 printk("0x%08lx\n trapped to die_if_kernel\n",pregs->ra);
147 show_regs(pregs);
148 if(pregs->status_extension & PS_S)
149 do_exit(SIGKILL);
150 do_exit(SIGSEGV);
153 void do_hw_interrupt(unsigned long type, unsigned long psr, unsigned long pc)
155 if(type < 0x10) {
156 printk("Unimplemented Nios2 TRAP, type = %02lx\n", type);
157 die_if_kernel("Whee... Hello Mr. Penguin", current->thread.kregs);
161 #if 0
162 void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long psr)
164 #ifdef TRAP_DEBUG
165 printk("Watchpoint detected at PC %08lx PSR %08lx\n", pc, psr);
166 #endif
167 if(psr & PSR_SUPERVISOR)
168 panic("Tell me what a watchpoint trap is, and I'll then deal "
169 "with such a beast...");
171 #endif
173 void trap_init(void)
175 #ifdef DEBUG
176 printk("trap_init reached\n");
177 #endif