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