kgdb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Microblaze KGDB support
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. */
  8. #include <linux/kgdb.h>
  9. #include <linux/kdebug.h>
  10. #include <linux/irq.h>
  11. #include <linux/io.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/pvr.h>
  15. #define GDB_REG 0
  16. #define GDB_PC 32
  17. #define GDB_MSR 33
  18. #define GDB_EAR 34
  19. #define GDB_ESR 35
  20. #define GDB_FSR 36
  21. #define GDB_BTR 37
  22. #define GDB_PVR 38
  23. #define GDB_REDR 50
  24. #define GDB_RPID 51
  25. #define GDB_RZPR 52
  26. #define GDB_RTLBX 53
  27. #define GDB_RTLBSX 54 /* mfs can't read it */
  28. #define GDB_RTLBLO 55
  29. #define GDB_RTLBHI 56
  30. /* keep pvr separately because it is unchangeble */
  31. struct pvr_s pvr;
  32. void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  33. {
  34. int i;
  35. unsigned long *pt_regb = (unsigned long *)regs;
  36. int temp;
  37. /* registers r0 - r31, pc, msr, ear, esr, fsr + do not save pt_mode */
  38. for (i = 0; i < (sizeof(struct pt_regs) / 4) - 1; i++)
  39. gdb_regs[i] = pt_regb[i];
  40. /* Branch target register can't be changed */
  41. __asm__ __volatile__ ("mfs %0, rbtr;" : "=r"(temp) : );
  42. gdb_regs[GDB_BTR] = temp;
  43. /* pvr part - we have 11 pvr regs */
  44. for (i = 0; i < sizeof(struct pvr_s)/4; i++)
  45. gdb_regs[GDB_PVR + i] = pvr.pvr[i];
  46. /* read special registers - can't be changed */
  47. __asm__ __volatile__ ("mfs %0, redr;" : "=r"(temp) : );
  48. gdb_regs[GDB_REDR] = temp;
  49. __asm__ __volatile__ ("mfs %0, rpid;" : "=r"(temp) : );
  50. gdb_regs[GDB_RPID] = temp;
  51. __asm__ __volatile__ ("mfs %0, rzpr;" : "=r"(temp) : );
  52. gdb_regs[GDB_RZPR] = temp;
  53. __asm__ __volatile__ ("mfs %0, rtlbx;" : "=r"(temp) : );
  54. gdb_regs[GDB_RTLBX] = temp;
  55. __asm__ __volatile__ ("mfs %0, rtlblo;" : "=r"(temp) : );
  56. gdb_regs[GDB_RTLBLO] = temp;
  57. __asm__ __volatile__ ("mfs %0, rtlbhi;" : "=r"(temp) : );
  58. gdb_regs[GDB_RTLBHI] = temp;
  59. }
  60. void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  61. {
  62. int i;
  63. unsigned long *pt_regb = (unsigned long *)regs;
  64. /* pt_regs and gdb_regs have the same 37 values.
  65. * The rest of gdb_regs are unused and can't be changed.
  66. * r0 register value can't be changed too. */
  67. for (i = 1; i < (sizeof(struct pt_regs) / 4) - 1; i++)
  68. pt_regb[i] = gdb_regs[i];
  69. }
  70. void microblaze_kgdb_break(struct pt_regs *regs)
  71. {
  72. if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0)
  73. return;
  74. /* Jump over the first arch_kgdb_breakpoint which is barrier to
  75. * get kgdb work. The same solution is used for powerpc */
  76. if (*(u32 *) (regs->pc) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
  77. regs->pc += BREAK_INSTR_SIZE;
  78. }
  79. /* untested */
  80. void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
  81. {
  82. int i;
  83. unsigned long *pt_regb = (unsigned long *)(p->thread.regs);
  84. /* registers r0 - r31, pc, msr, ear, esr, fsr + do not save pt_mode */
  85. for (i = 0; i < (sizeof(struct pt_regs) / 4) - 1; i++)
  86. gdb_regs[i] = pt_regb[i];
  87. /* pvr part - we have 11 pvr regs */
  88. for (i = 0; i < sizeof(struct pvr_s)/4; i++)
  89. gdb_regs[GDB_PVR + i] = pvr.pvr[i];
  90. }
  91. void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
  92. {
  93. regs->pc = ip;
  94. }
  95. int kgdb_arch_handle_exception(int vector, int signo, int err_code,
  96. char *remcom_in_buffer, char *remcom_out_buffer,
  97. struct pt_regs *regs)
  98. {
  99. char *ptr;
  100. unsigned long address;
  101. switch (remcom_in_buffer[0]) {
  102. case 'c':
  103. /* handle the optional parameter */
  104. ptr = &remcom_in_buffer[1];
  105. if (kgdb_hex2long(&ptr, &address))
  106. regs->pc = address;
  107. return 0;
  108. }
  109. return -1; /* this means that we do not want to exit from the handler */
  110. }
  111. int kgdb_arch_init(void)
  112. {
  113. get_pvr(&pvr); /* Fill PVR structure */
  114. return 0;
  115. }
  116. void kgdb_arch_exit(void)
  117. {
  118. /* Nothing to do */
  119. }
  120. /*
  121. * Global data
  122. */
  123. struct kgdb_arch arch_kgdb_ops = {
  124. #ifdef __MICROBLAZEEL__
  125. .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
  126. #else
  127. .gdb_bpt_instr = {0xba, 0x0c, 0x00, 0x18}, /* brki r16, 0x18 */
  128. #endif
  129. };