kgdb_32.c 3.7 KB

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