traps.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <linux/cpu.h>
  11. #include <linux/export.h>
  12. #include <linux/kernel.h>
  13. #include <linux/kallsyms.h>
  14. #include <linux/sched.h>
  15. #include <linux/sched/debug.h>
  16. #include <linux/debug_locks.h>
  17. #include <asm/exceptions.h>
  18. #include <asm/unwind.h>
  19. void trap_init(void)
  20. {
  21. __enable_hw_exceptions();
  22. }
  23. static unsigned long kstack_depth_to_print; /* 0 == entire stack */
  24. static int __init kstack_setup(char *s)
  25. {
  26. return !kstrtoul(s, 0, &kstack_depth_to_print);
  27. }
  28. __setup("kstack=", kstack_setup);
  29. void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
  30. {
  31. unsigned long words_to_show;
  32. u32 fp = (u32) sp;
  33. if (fp == 0) {
  34. if (task) {
  35. fp = ((struct thread_info *)
  36. (task->stack))->cpu_context.r1;
  37. } else {
  38. /* Pick up caller of dump_stack() */
  39. fp = (u32)&sp - 8;
  40. }
  41. }
  42. words_to_show = (THREAD_SIZE - (fp & (THREAD_SIZE - 1))) >> 2;
  43. if (kstack_depth_to_print && (words_to_show > kstack_depth_to_print))
  44. words_to_show = kstack_depth_to_print;
  45. printk("%sKernel Stack:\n", loglvl);
  46. /*
  47. * Make the first line an 'odd' size if necessary to get
  48. * remaining lines to start at an address multiple of 0x10
  49. */
  50. if (fp & 0xF) {
  51. unsigned long line1_words = (0x10 - (fp & 0xF)) >> 2;
  52. if (line1_words < words_to_show) {
  53. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32,
  54. 4, (void *)fp, line1_words << 2, 0);
  55. fp += line1_words << 2;
  56. words_to_show -= line1_words;
  57. }
  58. }
  59. print_hex_dump(loglvl, "", DUMP_PREFIX_ADDRESS, 32, 4, (void *)fp,
  60. words_to_show << 2, 0);
  61. printk("%s\n\nCall Trace:\n", loglvl);
  62. microblaze_unwind(task, NULL, loglvl);
  63. printk("%s\n", loglvl);
  64. if (!task)
  65. task = current;
  66. debug_show_held_locks(task);
  67. }