Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Michal Simek | d64af91 | 2013-02-01 13:10:35 +0100 | [diff] [blame] | 11 | #include <linux/export.h> |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/kallsyms.h> |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 14 | #include <linux/sched.h> |
| 15 | #include <linux/debug_locks.h> |
| 16 | |
| 17 | #include <asm/exceptions.h> |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 18 | #include <asm/unwind.h> |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 19 | |
| 20 | void trap_init(void) |
| 21 | { |
| 22 | __enable_hw_exceptions(); |
| 23 | } |
| 24 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 25 | static unsigned long kstack_depth_to_print; /* 0 == entire stack */ |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 26 | |
| 27 | static int __init kstack_setup(char *s) |
| 28 | { |
Michal Simek | 6bd55f0 | 2012-12-27 10:40:38 +0100 | [diff] [blame] | 29 | return !kstrtoul(s, 0, &kstack_depth_to_print); |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 30 | } |
| 31 | __setup("kstack=", kstack_setup); |
| 32 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 33 | void show_stack(struct task_struct *task, unsigned long *sp) |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 34 | { |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 35 | unsigned long words_to_show; |
| 36 | u32 fp = (u32) sp; |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 37 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 38 | if (fp == 0) { |
| 39 | if (task) { |
| 40 | fp = ((struct thread_info *) |
| 41 | (task->stack))->cpu_context.r1; |
| 42 | } else { |
| 43 | /* Pick up caller of dump_stack() */ |
| 44 | fp = (u32)&sp - 8; |
| 45 | } |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 46 | } |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 47 | |
| 48 | words_to_show = (THREAD_SIZE - (fp & (THREAD_SIZE - 1))) >> 2; |
| 49 | if (kstack_depth_to_print && (words_to_show > kstack_depth_to_print)) |
| 50 | words_to_show = kstack_depth_to_print; |
| 51 | |
| 52 | pr_info("Kernel Stack:\n"); |
| 53 | |
| 54 | /* |
| 55 | * Make the first line an 'odd' size if necessary to get |
| 56 | * remaining lines to start at an address multiple of 0x10 |
| 57 | */ |
| 58 | if (fp & 0xF) { |
| 59 | unsigned long line1_words = (0x10 - (fp & 0xF)) >> 2; |
| 60 | if (line1_words < words_to_show) { |
| 61 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32, |
| 62 | 4, (void *)fp, line1_words << 2, 0); |
| 63 | fp += line1_words << 2; |
| 64 | words_to_show -= line1_words; |
| 65 | } |
| 66 | } |
| 67 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32, 4, (void *)fp, |
| 68 | words_to_show << 2, 0); |
Michal Simek | 6bd55f0 | 2012-12-27 10:40:38 +0100 | [diff] [blame] | 69 | pr_info("\n\nCall Trace:\n"); |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 70 | microblaze_unwind(task, NULL); |
| 71 | pr_info("\n"); |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 72 | |
| 73 | if (!task) |
| 74 | task = current; |
| 75 | |
| 76 | debug_show_held_locks(task); |
| 77 | } |
| 78 | |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 79 | void dump_stack(void) |
| 80 | { |
| 81 | show_stack(NULL, NULL); |
| 82 | } |
| 83 | EXPORT_SYMBOL(dump_stack); |