kgdb.c 4.0 KB

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