/* * Backtrace support for Microblaze * * Copyright (C) 2010 Digital Design Corporation * * Based on arch/sh/kernel/cpu/sh5/unwind.c code which is: * Copyright (C) 2004 Paul Mundt * Copyright (C) 2004 Richard Curnow * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details.
*/
/* * On Microblaze, finding the previous stack frame is a little tricky. * At this writing (3/2010), Microblaze does not support CONFIG_FRAME_POINTERS, * and even if it did, gcc (4.1.2) does not store the frame pointer at * a consistent offset within each frame. To determine frame size, it is * necessary to search for the assembly instruction that creates or reclaims * the frame and extract the size from it. * * Microblaze stores the stack pointer in r1, and creates a frame via * * addik r1, r1, -FRAME_SIZE * * The frame is reclaimed via * * addik r1, r1, FRAME_SIZE * * Frame creation occurs at or near the top of a function. * Depending on the compiler, reclaim may occur at the end, or before * a mid-function return. * * A stack frame is usually not created in a leaf function. *
*/
/** * get_frame_size - Extract the stack adjustment from an * "addik r1, r1, adjust" instruction * @instr : Microblaze instruction * * Return - Number of stack bytes the instruction reserves or reclaims
*/ staticinlinelong get_frame_size(unsignedlong instr)
{ return abs((s16)(instr & 0xFFFF));
}
/** * find_frame_creation - Search backward to find the instruction that creates * the stack frame (hopefully, for the same function the * initial PC is in). * @pc : Program counter at which to begin the search * * Return - PC at which stack frame creation occurs * NULL if this cannot be found, i.e. a leaf function
*/ staticunsignedlong *find_frame_creation(unsignedlong *pc)
{ int i;
/* NOTE: Distance to search is arbitrary * 250 works well for most things, * 750 picks up things like tcp_recvmsg(), * 1000 needed for fat_fill_super()
*/ for (i = 0; i < 1000; i++, pc--) { unsignedlong instr;
s16 frame_size;
if (!kernel_text_address((unsignedlong) pc)) return NULL;
instr = *pc;
/* addik r1, r1, foo ? */ if ((instr & 0xFFFF0000) != 0x30210000) continue; /* No */
pr_debug(" Found frame creation at 0x%p, size %d\n", pc,
frame_size); return pc;
}
return NULL;
}
/** * lookup_prev_stack_frame - Find the stack frame of the previous function. * @fp : Frame (stack) pointer for current function * @pc : Program counter within current function * @leaf_return : r15 value within current function. If the current function * is a leaf, this is the caller's return address. * @pprev_fp : On exit, set to frame (stack) pointer for previous function * @pprev_pc : On exit, set to current function caller's return address * * Return - 0 on success, -EINVAL if the previous frame cannot be found
*/ staticint lookup_prev_stack_frame(unsignedlong fp, unsignedlong pc, unsignedlong leaf_return, unsignedlong *pprev_fp, unsignedlong *pprev_pc)
{ unsignedlong *prologue = NULL;
/* _switch_to is a special leaf function */ if (pc != (unsignedlong) &_switch_to)
prologue = find_frame_creation((unsignedlong *)pc);
if (prologue) { long frame_size = get_frame_size(*prologue);
/** * unwind_trap - Unwind through a system trap, that stored previous state * on the stack.
*/ staticinlinevoid unwind_trap(struct task_struct *task, unsignedlong pc, unsignedlong fp, struct stack_trace *trace, constchar *loglvl)
{ /* To be implemented */
}
/** * microblaze_unwind_inner - Unwind the stack from the specified point * @task : Task whose stack we are to unwind (may be NULL) * @pc : Program counter from which we start unwinding * @fp : Frame (stack) pointer from which we start unwinding * @leaf_return : Value of r15 at pc. If the function is a leaf, this is * the caller's return address. * @trace : Where to store stack backtrace (PC values). * NULL == print backtrace to kernel log * @loglvl : Used for printk log level if (trace == NULL).
*/ staticvoid microblaze_unwind_inner(struct task_struct *task, unsignedlong pc, unsignedlong fp, unsignedlong leaf_return, struct stack_trace *trace, constchar *loglvl)
{ int ofs = 0;
pr_debug(" Unwinding with PC=%p, FP=%p\n", (void *)pc, (void *)fp); if (!pc || !fp || (pc & 3) || (fp & 3)) {
pr_debug(" Invalid state for unwind, aborting\n"); return;
} for (; pc != 0;) { unsignedlong next_fp, next_pc = 0; unsignedlong return_to = pc + 2 * sizeof(unsignedlong); conststruct trap_handler_info *handler =
µblaze_trap_handlers;
/* Is previous function the HW exception handler? */ if ((return_to >= (unsignedlong)&_hw_exception_handler)
&&(return_to < (unsignedlong)&ex_handler_unhandled)) { /* * HW exception handler doesn't save all registers, * so we open-code a special case of unwind_trap()
*/
printk("%sHW EXCEPTION\n", loglvl); return;
}
/* Is previous function a trap handler? */ for (; handler->start_addr; ++handler) { if ((return_to >= handler->start_addr)
&& (return_to <= handler->end_addr)) { if (!trace)
printk("%s%s\n", loglvl, handler->trap_name);
unwind_trap(task, pc, fp, trace, loglvl); return;
}
}
pc -= ofs;
if (trace) { #ifdef CONFIG_STACKTRACE if (trace->skip > 0)
trace->skip--; else
trace->entries[trace->nr_entries++] = pc;
if (trace->nr_entries >= trace->max_entries) break; #endif
} else { /* Have we reached userland? */ if (unlikely(pc == task_pt_regs(task)->pc)) {
printk("%s[<%p>] PID %lu [%s]\n",
loglvl, (void *) pc,
(unsignedlong) task->pid,
task->comm); break;
} else
print_ip_sym(loglvl, pc);
}
/* Stop when we reach anything not part of the kernel */ if (!kernel_text_address(pc)) break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.