backtrace32.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/device.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/kallsyms.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/sched.h>
  8. #include <asm/signal.h>
  9. #include <mt-plat/sync_write.h>
  10. #include <mtk_ram_console.h>
  11. #include "backtrace.h"
  12. void dump_backtrace_entry_ramconsole_print(unsigned long where, unsigned long from, unsigned long frame)
  13. {
  14. char str_buf[256];
  15. #ifdef CONFIG_KALLSYMS
  16. snprintf(str_buf, sizeof(str_buf),
  17. "[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
  18. #else
  19. snprintf(str_buf, sizeof(str_buf), "Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
  20. #endif
  21. aee_sram_fiq_log(str_buf);
  22. }
  23. void dump_regs(const char *fmt, const char v1, const unsigned int reg, const unsigned int reg_val)
  24. {
  25. char str_buf[256];
  26. snprintf(str_buf, sizeof(str_buf), fmt, v1, reg, reg_val);
  27. aee_sram_fiq_log(str_buf);
  28. }
  29. static int verify_stack(unsigned long sp)
  30. {
  31. if (sp < PAGE_OFFSET || (sp > (unsigned long)high_memory && high_memory != NULL))
  32. return -EFAULT;
  33. return 0;
  34. }
  35. void aee_dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
  36. {
  37. char str_buf[256];
  38. unsigned int fp, mode;
  39. int ok = 1;
  40. snprintf(str_buf, sizeof(str_buf), "PC is 0x%lx, LR is 0x%lx\n", regs->ARM_pc, regs->ARM_lr);
  41. aee_sram_fiq_log(str_buf);
  42. if (!tsk)
  43. tsk = current;
  44. if (regs) {
  45. fp = regs->ARM_fp;
  46. mode = processor_mode(regs);
  47. } else if (tsk != current) {
  48. fp = thread_saved_fp(tsk);
  49. mode = 0x10;
  50. } else {
  51. asm("mov %0, fp" : "=r" (fp) : : "cc");
  52. mode = 0x10;
  53. }
  54. if (!fp) {
  55. aee_sram_fiq_log("no frame pointer");
  56. ok = 0;
  57. } else if (verify_stack(fp)) {
  58. aee_sram_fiq_log("invalid frame pointer");
  59. ok = 0;
  60. } else if (fp < (unsigned long)end_of_stack(tsk))
  61. aee_sram_fiq_log("frame pointer underflow");
  62. aee_sram_fiq_log("\n");
  63. if (ok)
  64. c_backtrace_ramconsole_print(fp, mode);
  65. }