• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * linux/arch/h8300/boot/traps.c -- general exception handling code
3  * H8/300 support Yoshinori Sato <ysato@users.sourceforge.jp>
4  *
5  * Cloned from Linux/m68k.
6  *
7  * No original Copyright holder listed,
8  * Probable original (C) Roman Zippel (assigned DJD, 1999)
9  *
10  * Copyright 1999-2000 D. Jeff Dionne, <jeff@rt-control.com>
11  *
12  * This file is subject to the terms and conditions of the GNU General Public
13  * License.  See the file COPYING in the main directory of this archive
14  * for more details.
15  */
16 
17 #include <linux/types.h>
18 #include <linux/sched.h>
19 #include <linux/sched/debug.h>
20 #include <linux/sched/task.h>
21 #include <linux/mm_types.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/bug.h>
27 
28 #include <asm/irq.h>
29 #include <asm/traps.h>
30 #include <asm/page.h>
31 
32 static DEFINE_SPINLOCK(die_lock);
33 
34 /*
35  * this must be called very early as the kernel might
36  * use some instruction that are emulated on the 060
37  */
38 
base_trap_init(void)39 void __init base_trap_init(void)
40 {
41 }
42 
trap_init(void)43 void __init trap_init(void)
44 {
45 }
46 
set_esp0(unsigned long ssp)47 asmlinkage void set_esp0(unsigned long ssp)
48 {
49 	current->thread.esp0 = ssp;
50 }
51 
52 /*
53  *	Generic dumping code. Used for panic and debug.
54  */
55 
dump(struct pt_regs * fp)56 static void dump(struct pt_regs *fp)
57 {
58 	unsigned long	*sp;
59 	unsigned char	*tp;
60 	int		i;
61 
62 	pr_info("\nCURRENT PROCESS:\n\n");
63 	pr_info("COMM=%s PID=%d\n", current->comm, current->pid);
64 	if (current->mm) {
65 		pr_info("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
66 			(int) current->mm->start_code,
67 			(int) current->mm->end_code,
68 			(int) current->mm->start_data,
69 			(int) current->mm->end_data,
70 			(int) current->mm->end_data,
71 			(int) current->mm->brk);
72 		pr_info("USER-STACK=%08x  KERNEL-STACK=%08lx\n\n",
73 			(int) current->mm->start_stack,
74 			(int) PAGE_SIZE+(unsigned long)current);
75 	}
76 
77 	show_regs(fp);
78 	pr_info("\nCODE:");
79 	tp = ((unsigned char *) fp->pc) - 0x20;
80 	for (sp = (unsigned long *) tp, i = 0; (i < 0x40);  i += 4) {
81 		if ((i % 0x10) == 0)
82 			pr_info("\n%08x: ", (int) (tp + i));
83 		pr_info("%08x ", (int) *sp++);
84 	}
85 	pr_info("\n");
86 
87 	pr_info("\nKERNEL STACK:");
88 	tp = ((unsigned char *) fp) - 0x40;
89 	for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
90 		if ((i % 0x10) == 0)
91 			pr_info("\n%08x: ", (int) (tp + i));
92 		pr_info("%08x ", (int) *sp++);
93 	}
94 	pr_info("\n");
95 	if (STACK_MAGIC != *(unsigned long *)((unsigned long)current+PAGE_SIZE))
96 		pr_info("(Possibly corrupted stack page??)\n");
97 
98 	pr_info("\n\n");
99 }
100 
die(const char * str,struct pt_regs * fp,unsigned long err)101 void die(const char *str, struct pt_regs *fp, unsigned long err)
102 {
103 	static int diecount;
104 
105 	oops_enter();
106 
107 	console_verbose();
108 	spin_lock_irq(&die_lock);
109 	report_bug(fp->pc, fp);
110 	pr_crit("%s: %04lx [#%d] ", str, err & 0xffff, ++diecount);
111 	dump(fp);
112 
113 	spin_unlock_irq(&die_lock);
114 	make_task_dead(SIGSEGV);
115 }
116 
117 static int kstack_depth_to_print = 24;
118 
show_stack(struct task_struct * task,unsigned long * esp,const char * loglvl)119 void show_stack(struct task_struct *task, unsigned long *esp, const char *loglvl)
120 {
121 	unsigned long *stack,  addr;
122 	int i;
123 
124 	if (esp == NULL)
125 		esp = (unsigned long *) &esp;
126 
127 	stack = esp;
128 
129 	printk("%sStack from %08lx:", loglvl, (unsigned long)stack);
130 	for (i = 0; i < kstack_depth_to_print; i++) {
131 		if (((unsigned long)stack & (THREAD_SIZE - 1)) >=
132 		    THREAD_SIZE-4)
133 			break;
134 		if (i % 8 == 0)
135 			printk("%s ", loglvl);
136 		pr_cont(" %08lx", *stack++);
137 	}
138 
139 	printk("%s\nCall Trace:\n", loglvl);
140 	i = 0;
141 	stack = esp;
142 	while (((unsigned long)stack & (THREAD_SIZE - 1)) < THREAD_SIZE-4) {
143 		addr = *stack++;
144 		/*
145 		 * If the address is either in the text segment of the
146 		 * kernel, or in the region which contains vmalloc'ed
147 		 * memory, it *may* be the address of a calling
148 		 * routine; if so, print it so that someone tracing
149 		 * down the cause of the crash will be able to figure
150 		 * out the call path that was taken.
151 		 */
152 		if (check_kernel_text(addr)) {
153 			if (i % 4 == 0)
154 				printk("%s       ", loglvl);
155 			pr_cont(" [<%08lx>]", addr);
156 			i++;
157 		}
158 	}
159 	printk("%s\n", loglvl);
160 }
161