Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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