blob: ba034d421ec27933f54d4950a3e7d3cec2761cc2 [file] [log] [blame]
Michal Simek65bc6092009-03-27 14:25:29 +01001/*
2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/kernel.h>
12#include <linux/kallsyms.h>
13#include <linux/module.h>
14#include <linux/sched.h>
15#include <linux/debug_locks.h>
16
17#include <asm/exceptions.h>
18#include <asm/system.h>
Steven J. Magnanice3266c2010-04-27 12:37:54 -050019#include <asm/unwind.h>
Michal Simek65bc6092009-03-27 14:25:29 +010020
21void trap_init(void)
22{
23 __enable_hw_exceptions();
24}
25
Steven J. Magnanice3266c2010-04-27 12:37:54 -050026static unsigned long kstack_depth_to_print; /* 0 == entire stack */
Michal Simek65bc6092009-03-27 14:25:29 +010027
28static int __init kstack_setup(char *s)
29{
Steven J. Magnani0c4ec162010-02-24 14:54:15 -060030 return !strict_strtoul(s, 0, &kstack_depth_to_print);
Michal Simek65bc6092009-03-27 14:25:29 +010031}
32__setup("kstack=", kstack_setup);
33
Steven J. Magnanice3266c2010-04-27 12:37:54 -050034void show_stack(struct task_struct *task, unsigned long *sp)
Michal Simek65bc6092009-03-27 14:25:29 +010035{
Steven J. Magnanice3266c2010-04-27 12:37:54 -050036 unsigned long words_to_show;
37 u32 fp = (u32) sp;
Michal Simek65bc6092009-03-27 14:25:29 +010038
Steven J. Magnanice3266c2010-04-27 12:37:54 -050039 if (fp == 0) {
40 if (task) {
41 fp = ((struct thread_info *)
42 (task->stack))->cpu_context.r1;
43 } else {
44 /* Pick up caller of dump_stack() */
45 fp = (u32)&sp - 8;
46 }
Michal Simek65bc6092009-03-27 14:25:29 +010047 }
Steven J. Magnanice3266c2010-04-27 12:37:54 -050048
49 words_to_show = (THREAD_SIZE - (fp & (THREAD_SIZE - 1))) >> 2;
50 if (kstack_depth_to_print && (words_to_show > kstack_depth_to_print))
51 words_to_show = kstack_depth_to_print;
52
53 pr_info("Kernel Stack:\n");
54
55 /*
56 * Make the first line an 'odd' size if necessary to get
57 * remaining lines to start at an address multiple of 0x10
58 */
59 if (fp & 0xF) {
60 unsigned long line1_words = (0x10 - (fp & 0xF)) >> 2;
61 if (line1_words < words_to_show) {
62 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32,
63 4, (void *)fp, line1_words << 2, 0);
64 fp += line1_words << 2;
65 words_to_show -= line1_words;
66 }
67 }
68 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32, 4, (void *)fp,
69 words_to_show << 2, 0);
70 printk(KERN_INFO "\n\n");
71
72 pr_info("Call Trace:\n");
73 microblaze_unwind(task, NULL);
74 pr_info("\n");
Michal Simek65bc6092009-03-27 14:25:29 +010075
76 if (!task)
77 task = current;
78
79 debug_show_held_locks(task);
80}
81
Michal Simek65bc6092009-03-27 14:25:29 +010082void dump_stack(void)
83{
84 show_stack(NULL, NULL);
85}
86EXPORT_SYMBOL(dump_stack);