kgdb_32.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* kgdb.c: KGDB support for 32-bit sparc.
  2. *
  3. * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <linux/kgdb.h>
  6. #include <linux/kdebug.h>
  7. #include <asm/kdebug.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/irq.h>
  10. #include <asm/cacheflush.h>
  11. extern unsigned long trapbase;
  12. void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  13. {
  14. struct reg_window32 *win;
  15. int i;
  16. gdb_regs[GDB_G0] = 0;
  17. for (i = 0; i < 15; i++)
  18. gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
  19. win = (struct reg_window32 *) regs->u_regs[UREG_FP];
  20. for (i = 0; i < 8; i++)
  21. gdb_regs[GDB_L0 + i] = win->locals[i];
  22. for (i = 0; i < 8; i++)
  23. gdb_regs[GDB_I0 + i] = win->ins[i];
  24. for (i = GDB_F0; i <= GDB_F31; i++)
  25. gdb_regs[i] = 0;
  26. gdb_regs[GDB_Y] = regs->y;
  27. gdb_regs[GDB_PSR] = regs->psr;
  28. gdb_regs[GDB_WIM] = 0;
  29. gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
  30. gdb_regs[GDB_PC] = regs->pc;
  31. gdb_regs[GDB_NPC] = regs->npc;
  32. gdb_regs[GDB_FSR] = 0;
  33. gdb_regs[GDB_CSR] = 0;
  34. }
  35. void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
  36. {
  37. struct thread_info *t = task_thread_info(p);
  38. struct reg_window32 *win;
  39. int i;
  40. for (i = GDB_G0; i < GDB_G6; i++)
  41. gdb_regs[i] = 0;
  42. gdb_regs[GDB_G6] = (unsigned long) t;
  43. gdb_regs[GDB_G7] = 0;
  44. for (i = GDB_O0; i < GDB_SP; i++)
  45. gdb_regs[i] = 0;
  46. gdb_regs[GDB_SP] = t->ksp;
  47. gdb_regs[GDB_O7] = 0;
  48. win = (struct reg_window32 *) t->ksp;
  49. for (i = 0; i < 8; i++)
  50. gdb_regs[GDB_L0 + i] = win->locals[i];
  51. for (i = 0; i < 8; i++)
  52. gdb_regs[GDB_I0 + i] = win->ins[i];
  53. for (i = GDB_F0; i <= GDB_F31; i++)
  54. gdb_regs[i] = 0;
  55. gdb_regs[GDB_Y] = 0;
  56. gdb_regs[GDB_PSR] = t->kpsr;
  57. gdb_regs[GDB_WIM] = t->kwim;
  58. gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
  59. gdb_regs[GDB_PC] = t->kpc;
  60. gdb_regs[GDB_NPC] = t->kpc + 4;
  61. gdb_regs[GDB_FSR] = 0;
  62. gdb_regs[GDB_CSR] = 0;
  63. }
  64. void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  65. {
  66. struct reg_window32 *win;
  67. int i;
  68. for (i = 0; i < 15; i++)
  69. regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
  70. /* If the PSR register is changing, we have to preserve
  71. * the CWP field, otherwise window save/restore explodes.
  72. */
  73. if (regs->psr != gdb_regs[GDB_PSR]) {
  74. unsigned long cwp = regs->psr & PSR_CWP;
  75. regs->psr = (gdb_regs[GDB_PSR] & ~PSR_CWP) | cwp;
  76. }
  77. regs->pc = gdb_regs[GDB_PC];
  78. regs->npc = gdb_regs[GDB_NPC];
  79. regs->y = gdb_regs[GDB_Y];
  80. win = (struct reg_window32 *) regs->u_regs[UREG_FP];
  81. for (i = 0; i < 8; i++)
  82. win->locals[i] = gdb_regs[GDB_L0 + i];
  83. for (i = 0; i < 8; i++)
  84. win->ins[i] = gdb_regs[GDB_I0 + i];
  85. }
  86. int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
  87. char *remcomInBuffer, char *remcomOutBuffer,
  88. struct pt_regs *linux_regs)
  89. {
  90. unsigned long addr;
  91. char *ptr;
  92. switch (remcomInBuffer[0]) {
  93. case 'c':
  94. /* try to read optional parameter, pc unchanged if no parm */
  95. ptr = &remcomInBuffer[1];
  96. if (kgdb_hex2long(&ptr, &addr)) {
  97. linux_regs->pc = addr;
  98. linux_regs->npc = addr + 4;
  99. }
  100. /* fallthru */
  101. case 'D':
  102. case 'k':
  103. if (linux_regs->pc == (unsigned long) arch_kgdb_breakpoint) {
  104. linux_regs->pc = linux_regs->npc;
  105. linux_regs->npc += 4;
  106. }
  107. return 0;
  108. }
  109. return -1;
  110. }
  111. extern void do_hw_interrupt(struct pt_regs *regs, unsigned long type);
  112. asmlinkage void kgdb_trap(struct pt_regs *regs)
  113. {
  114. unsigned long flags;
  115. if (user_mode(regs)) {
  116. do_hw_interrupt(regs, 0xfd);
  117. return;
  118. }
  119. flushw_all();
  120. local_irq_save(flags);
  121. kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
  122. local_irq_restore(flags);
  123. }
  124. int kgdb_arch_init(void)
  125. {
  126. return 0;
  127. }
  128. void kgdb_arch_exit(void)
  129. {
  130. }
  131. void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
  132. {
  133. regs->pc = ip;
  134. regs->npc = regs->pc + 4;
  135. }
  136. struct kgdb_arch arch_kgdb_ops = {
  137. /* Breakpoint instruction: ta 0x7d */
  138. .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
  139. };