traps.c 2.0 KB

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