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)  * Backtrace support for Microblaze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2010  Digital Design Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Based on arch/sh/kernel/cpu/sh5/unwind.c code which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2004  Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2004  Richard Curnow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /* #define DEBUG 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/stacktrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/exceptions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/unwind.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct stack_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * On Microblaze, finding the previous stack frame is a little tricky.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * At this writing (3/2010), Microblaze does not support CONFIG_FRAME_POINTERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * and even if it did, gcc (4.1.2) does not store the frame pointer at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * a consistent offset within each frame. To determine frame size, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * necessary to search for the assembly instruction that creates or reclaims
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * the frame and extract the size from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * Microblaze stores the stack pointer in r1, and creates a frame via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *     addik r1, r1, -FRAME_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * The frame is reclaimed via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *     addik r1, r1, FRAME_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Frame creation occurs at or near the top of a function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Depending on the compiler, reclaim may occur at the end, or before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * a mid-function return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * A stack frame is usually not created in a leaf function.
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * get_frame_size - Extract the stack adjustment from an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *                  "addik r1, r1, adjust" instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @instr : Microblaze instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * Return - Number of stack bytes the instruction reserves or reclaims
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static inline long get_frame_size(unsigned long instr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return abs((s16)(instr & 0xFFFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * find_frame_creation - Search backward to find the instruction that creates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *                       the stack frame (hopefully, for the same function the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *                       initial PC is in).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * @pc : Program counter at which to begin the search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Return - PC at which stack frame creation occurs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *          NULL if this cannot be found, i.e. a leaf function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static unsigned long *find_frame_creation(unsigned long *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* NOTE: Distance to search is arbitrary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 *	 250 works well for most things,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 *	 750 picks up things like tcp_recvmsg(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 *	1000 needed for fat_fill_super()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	for (i = 0; i < 1000; i++, pc--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		unsigned long instr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		s16 frame_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (!kernel_text_address((unsigned long) pc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		instr = *pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		/* addik r1, r1, foo ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if ((instr & 0xFFFF0000) != 0x30210000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			continue;	/* No */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		frame_size = get_frame_size(instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if ((frame_size < 8) || (frame_size & 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			pr_debug("    Invalid frame size %d at 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				 frame_size, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		pr_debug("    Found frame creation at 0x%p, size %d\n", pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			 frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * lookup_prev_stack_frame - Find the stack frame of the previous function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @fp          : Frame (stack) pointer for current function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @pc          : Program counter within current function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @leaf_return : r15 value within current function. If the current function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *		  is a leaf, this is the caller's return address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @pprev_fp    : On exit, set to frame (stack) pointer for previous function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @pprev_pc    : On exit, set to current function caller's return address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * Return - 0 on success, -EINVAL if the previous frame cannot be found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int lookup_prev_stack_frame(unsigned long fp, unsigned long pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				   unsigned long leaf_return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				   unsigned long *pprev_fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				   unsigned long *pprev_pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	unsigned long *prologue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* _switch_to is a special leaf function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (pc != (unsigned long) &_switch_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		prologue = find_frame_creation((unsigned long *)pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (prologue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		long frame_size = get_frame_size(*prologue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		*pprev_fp = fp + frame_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		*pprev_pc = *(unsigned long *)fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (!leaf_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		*pprev_pc = leaf_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		*pprev_fp = fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/* NOTE: don't check kernel_text_address here, to allow display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 *	 of userland return address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return (!*pprev_pc || (*pprev_pc & 3)) ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void microblaze_unwind_inner(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				    unsigned long pc, unsigned long fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				    unsigned long leaf_return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				    struct stack_trace *trace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				    const char *loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * unwind_trap - Unwind through a system trap, that stored previous state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *		 on the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static inline void unwind_trap(struct task_struct *task, unsigned long pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				unsigned long fp, struct stack_trace *trace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* To be implemented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static inline void unwind_trap(struct task_struct *task, unsigned long pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				unsigned long fp, struct stack_trace *trace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	const struct pt_regs *regs = (const struct pt_regs *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	microblaze_unwind_inner(task, regs->pc, regs->r1, regs->r15, trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * microblaze_unwind_inner - Unwind the stack from the specified point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @task  : Task whose stack we are to unwind (may be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * @pc    : Program counter from which we start unwinding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @fp    : Frame (stack) pointer from which we start unwinding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * @leaf_return : Value of r15 at pc. If the function is a leaf, this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *				  the caller's return address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * @trace : Where to store stack backtrace (PC values).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *	    NULL == print backtrace to kernel log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * @loglvl : Used for printk log level if (trace == NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void microblaze_unwind_inner(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			     unsigned long pc, unsigned long fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			     unsigned long leaf_return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			     struct stack_trace *trace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			     const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int ofs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	pr_debug("    Unwinding with PC=%p, FP=%p\n", (void *)pc, (void *)fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (!pc || !fp || (pc & 3) || (fp & 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		pr_debug("    Invalid state for unwind, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	for (; pc != 0;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		unsigned long next_fp, next_pc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		unsigned long return_to = pc +  2 * sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		const struct trap_handler_info *handler =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			&microblaze_trap_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		/* Is previous function the HW exception handler? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		if ((return_to >= (unsigned long)&_hw_exception_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		    &&(return_to < (unsigned long)&ex_handler_unhandled)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			 * HW exception handler doesn't save all registers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			 * so we open-code a special case of unwind_trap()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			const struct pt_regs *regs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				(const struct pt_regs *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			printk("%sHW EXCEPTION\n", loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			microblaze_unwind_inner(task, regs->r17 - 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 						fp + EX_HANDLER_STACK_SIZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 						regs->r15, trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		/* Is previous function a trap handler? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		for (; handler->start_addr; ++handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			if ((return_to >= handler->start_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			    && (return_to <= handler->end_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				if (!trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 					printk("%s%s\n", loglvl, handler->trap_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				unwind_trap(task, pc, fp, trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		pc -= ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (trace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #ifdef CONFIG_STACKTRACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			if (trace->skip > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				trace->skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				trace->entries[trace->nr_entries++] = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			if (trace->nr_entries >= trace->max_entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			/* Have we reached userland? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			if (unlikely(pc == task_pt_regs(task)->pc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				printk("%s[<%p>] PID %lu [%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 					loglvl, (void *) pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 					(unsigned long) task->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					task->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				print_ip_sym(loglvl, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		/* Stop when we reach anything not part of the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (!kernel_text_address(pc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (lookup_prev_stack_frame(fp, pc, leaf_return, &next_fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 					    &next_pc) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			ofs = sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			pc = next_pc & ~3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			fp = next_fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			leaf_return = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			pr_debug("    Failed to find previous stack frame\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		pr_debug("    Next PC=%p, next FP=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			 (void *)next_pc, (void *)next_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * microblaze_unwind - Stack unwinder for Microblaze (external entry point)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * @task  : Task whose stack we are to unwind (NULL == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * @trace : Where to store stack backtrace (PC values).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  *	    NULL == print backtrace to kernel log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * @loglvl : Used for printk log level if (trace == NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) void microblaze_unwind(struct task_struct *task, struct stack_trace *trace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		       const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (task) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (task == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			const struct pt_regs *regs = task_pt_regs(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			microblaze_unwind_inner(task, regs->pc, regs->r1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 						regs->r15, trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			struct thread_info *thread_info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				(struct thread_info *)(task->stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			const struct cpu_context *cpu_context =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 				&thread_info->cpu_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			microblaze_unwind_inner(task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 						(unsigned long) &_switch_to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 						cpu_context->r1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 						cpu_context->r15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 						trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		unsigned long pc, fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		__asm__ __volatile__ ("or %0, r1, r0" : "=r" (fp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		__asm__ __volatile__ (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			"brlid %0, 0f;"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			"nop;"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			"0:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			: "=r" (pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		/* Since we are not a leaf function, use leaf_return = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		microblaze_unwind_inner(current, pc, fp, 0, trace, loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)