traps.c 1.9 KB

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