traps.c 2.0 KB
Newer Older
M
Michal Simek 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
 * Copyright (C) 2007-2009 PetaLogix
 * Copyright (C) 2006 Atmark Techno, Inc.
 *
 * 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.
 */

#include <linux/kernel.h>
#include <linux/kallsyms.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/debug_locks.h>

#include <asm/exceptions.h>
18
#include <asm/unwind.h>
M
Michal Simek 已提交
19 20 21 22 23 24

void trap_init(void)
{
	__enable_hw_exceptions();
}

25
static unsigned long kstack_depth_to_print;	/* 0 == entire stack */
M
Michal Simek 已提交
26 27 28

static int __init kstack_setup(char *s)
{
29
	return !kstrtoul(s, 0, &kstack_depth_to_print);
M
Michal Simek 已提交
30 31 32
}
__setup("kstack=", kstack_setup);

33
void show_stack(struct task_struct *task, unsigned long *sp)
M
Michal Simek 已提交
34
{
35 36 37 38 39 40 41 42 43 44 45 46
	unsigned long words_to_show;
	u32 fp = (u32) sp;

	if (fp == 0) {
		if (task) {
			fp = ((struct thread_info *)
				(task->stack))->cpu_context.r1;
		} else {
			/* Pick up caller of dump_stack() */
			fp = (u32)&sp - 8;
		}
	}
M
Michal Simek 已提交
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	words_to_show = (THREAD_SIZE - (fp & (THREAD_SIZE - 1))) >> 2;
	if (kstack_depth_to_print && (words_to_show > kstack_depth_to_print))
		words_to_show = kstack_depth_to_print;

	pr_info("Kernel Stack:\n");

	/*
	 * Make the first line an 'odd' size if necessary to get
	 * remaining lines to start at an address multiple of 0x10
	 */
	if (fp & 0xF) {
		unsigned long line1_words = (0x10 - (fp & 0xF)) >> 2;
		if (line1_words < words_to_show) {
			print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32,
				       4, (void *)fp, line1_words << 2, 0);
			fp += line1_words << 2;
			words_to_show -= line1_words;
		}
M
Michal Simek 已提交
66
	}
67 68
	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32, 4, (void *)fp,
		       words_to_show << 2, 0);
69
	pr_info("\n\nCall Trace:\n");
70 71
	microblaze_unwind(task, NULL);
	pr_info("\n");
M
Michal Simek 已提交
72 73 74 75 76 77 78 79 80 81 82 83

	if (!task)
		task = current;

	debug_show_held_locks(task);
}

void dump_stack(void)
{
	show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);