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> |
Ingo Molnar | b17b015 | 2017-02-08 18:51:35 +0100 | [diff] [blame] | 15 | #include <linux/sched/debug.h> |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 16 | #include <linux/debug_locks.h> |
| 17 | |
| 18 | #include <asm/exceptions.h> |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 19 | #include <asm/unwind.h> |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 20 | |
| 21 | void trap_init(void) |
| 22 | { |
| 23 | __enable_hw_exceptions(); |
| 24 | } |
| 25 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 26 | static unsigned long kstack_depth_to_print; /* 0 == entire stack */ |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 27 | |
| 28 | static int __init kstack_setup(char *s) |
| 29 | { |
Michal Simek | 6bd55f0 | 2012-12-27 10:40:38 +0100 | [diff] [blame] | 30 | return !kstrtoul(s, 0, &kstack_depth_to_print); |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 31 | } |
| 32 | __setup("kstack=", kstack_setup); |
| 33 | |
Dmitry Safonov | 9cb8f06 | 2020-06-08 21:32:29 -0700 | [diff] [blame] | 34 | void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl) |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 35 | { |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 36 | unsigned long words_to_show; |
| 37 | u32 fp = (u32) sp; |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 38 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 39 | 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 Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 47 | } |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 48 | |
| 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 | |
Dmitry Safonov | 35f3968 | 2020-06-08 21:30:56 -0700 | [diff] [blame] | 53 | printk("%sKernel Stack:\n", loglvl); |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 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 | } |
Dmitry Safonov | 35f3968 | 2020-06-08 21:30:56 -0700 | [diff] [blame] | 68 | print_hex_dump(loglvl, "", DUMP_PREFIX_ADDRESS, 32, 4, (void *)fp, |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 69 | words_to_show << 2, 0); |
Dmitry Safonov | 35f3968 | 2020-06-08 21:30:56 -0700 | [diff] [blame] | 70 | printk("%s\n\nCall Trace:\n", loglvl); |
| 71 | microblaze_unwind(task, NULL, loglvl); |
| 72 | printk("%s\n", loglvl); |
Michal Simek | 65bc609 | 2009-03-27 14:25:29 +0100 | [diff] [blame] | 73 | |
| 74 | if (!task) |
| 75 | task = current; |
| 76 | |
| 77 | debug_show_held_locks(task); |
| 78 | } |