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/mm_types.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/bug.h>
26 
27 #include <asm/irq.h>
28 #include <asm/traps.h>
29 #include <asm/page.h>
30 
31 static DEFINE_SPINLOCK(die_lock);
32 
33 /*
34  * this must be called very early as the kernel might
35  * use some instruction that are emulated on the 060
36  */
37 
base_trap_init(void)38 void __init base_trap_init(void)
39 {
40 }
41 
set_esp0(unsigned long ssp)42 asmlinkage void set_esp0(unsigned long ssp)
43 {
44 	current->thread.esp0 = ssp;
45 }
46 
47 /*
48  *	Generic dumping code. Used for panic and debug.
49  */
50 
dump(struct pt_regs * fp)51 static void dump(struct pt_regs *fp)
52 {
53 	unsigned long	*sp;
54 	unsigned char	*tp;
55 	int		i;
56 
57 	pr_info("\nCURRENT PROCESS:\n\n");
58 	pr_info("COMM=%s PID=%d\n", current->comm, current->pid);
59 	if (current->mm) {
60 		pr_info("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
61 			(int) current->mm->start_code,
62 			(int) current->mm->end_code,
63 			(int) current->mm->start_data,
64 			(int) current->mm->end_data,
65 			(int) current->mm->end_data,
66 			(int) current->mm->brk);
67 		pr_info("USER-STACK=%08x  KERNEL-STACK=%08lx\n\n",
68 			(int) current->mm->start_stack,
69 			(int) PAGE_SIZE+(unsigned long)current);
70 	}
71 
72 	show_regs(fp);
73 	pr_info("\nCODE:");
74 	tp = ((unsigned char *) fp->pc) - 0x20;
75 	for (sp = (unsigned long *) tp, i = 0; (i < 0x40);  i += 4) {
76 		if ((i % 0x10) == 0)
77 			pr_info("\n%08x: ", (int) (tp + i));
78 		pr_info("%08x ", (int) *sp++);
79 	}
80 	pr_info("\n");
81 
82 	pr_info("\nKERNEL STACK:");
83 	tp = ((unsigned char *) fp) - 0x40;
84 	for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
85 		if ((i % 0x10) == 0)
86 			pr_info("\n%08x: ", (int) (tp + i));
87 		pr_info("%08x ", (int) *sp++);
88 	}
89 	pr_info("\n");
90 	if (STACK_MAGIC != *(unsigned long *)((unsigned long)current+PAGE_SIZE))
91 		pr_info("(Possibly corrupted stack page??)\n");
92 
93 	pr_info("\n\n");
94 }
95 
die(const char * str,struct pt_regs * fp,unsigned long err)96 void die(const char *str, struct pt_regs *fp, unsigned long err)
97 {
98 	static int diecount;
99 
100 	oops_enter();
101 
102 	console_verbose();
103 	spin_lock_irq(&die_lock);
104 	report_bug(fp->pc, fp);
105 	pr_crit("%s: %04lx [#%d] ", str, err & 0xffff, ++diecount);
106 	dump(fp);
107 
108 	spin_unlock_irq(&die_lock);
109 	do_exit(SIGSEGV);
110 }
111 
112 static int kstack_depth_to_print = 24;
113 
show_stack(struct task_struct * task,unsigned long * esp,const char * loglvl)114 void show_stack(struct task_struct *task, unsigned long *esp, const char *loglvl)
115 {
116 	unsigned long *stack,  addr;
117 	int i;
118 
119 	if (esp == NULL)
120 		esp = (unsigned long *) &esp;
121 
122 	stack = esp;
123 
124 	printk("%sStack from %08lx:", loglvl, (unsigned long)stack);
125 	for (i = 0; i < kstack_depth_to_print; i++) {
126 		if (((unsigned long)stack & (THREAD_SIZE - 1)) >=
127 		    THREAD_SIZE-4)
128 			break;
129 		if (i % 8 == 0)
130 			printk("%s ", loglvl);
131 		pr_cont(" %08lx", *stack++);
132 	}
133 
134 	printk("%s\nCall Trace:\n", loglvl);
135 	i = 0;
136 	stack = esp;
137 	while (((unsigned long)stack & (THREAD_SIZE - 1)) < THREAD_SIZE-4) {
138 		addr = *stack++;
139 		/*
140 		 * If the address is either in the text segment of the
141 		 * kernel, or in the region which contains vmalloc'ed
142 		 * memory, it *may* be the address of a calling
143 		 * routine; if so, print it so that someone tracing
144 		 * down the cause of the crash will be able to figure
145 		 * out the call path that was taken.
146 		 */
147 		if (check_kernel_text(addr)) {
148 			if (i % 4 == 0)
149 				printk("%s       ", loglvl);
150 			pr_cont(" [<%08lx>]", addr);
151 			i++;
152 		}
153 	}
154 	printk("%s\n", loglvl);
155 }
156