kgdb_64.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* kgdb.c: KGDB support for 64-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/ftrace.h>
  8. #include <linux/context_tracking.h>
  9. #include <asm/cacheflush.h>
  10. #include <asm/kdebug.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/irq.h>
  13. #include "kernel.h"
  14. void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  15. {
  16. struct reg_window *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_window *) (regs->u_regs[UREG_FP] + STACK_BIAS);
  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_F62; i++)
  27. gdb_regs[i] = 0;
  28. gdb_regs[GDB_PC] = regs->tpc;
  29. gdb_regs[GDB_NPC] = regs->tnpc;
  30. gdb_regs[GDB_STATE] = regs->tstate;
  31. gdb_regs[GDB_FSR] = 0;
  32. gdb_regs[GDB_FPRS] = 0;
  33. gdb_regs[GDB_Y] = regs->y;
  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. extern unsigned int switch_to_pc;
  39. extern unsigned int ret_from_fork;
  40. struct reg_window *win;
  41. unsigned long pc, cwp;
  42. int i;
  43. for (i = GDB_G0; i < GDB_G6; i++)
  44. gdb_regs[i] = 0;
  45. gdb_regs[GDB_G6] = (unsigned long) t;
  46. gdb_regs[GDB_G7] = (unsigned long) p;
  47. for (i = GDB_O0; i < GDB_SP; i++)
  48. gdb_regs[i] = 0;
  49. gdb_regs[GDB_SP] = t->ksp;
  50. gdb_regs[GDB_O7] = 0;
  51. win = (struct reg_window *) (t->ksp + STACK_BIAS);
  52. for (i = 0; i < 8; i++)
  53. gdb_regs[GDB_L0 + i] = win->locals[i];
  54. for (i = 0; i < 8; i++)
  55. gdb_regs[GDB_I0 + i] = win->ins[i];
  56. for (i = GDB_F0; i <= GDB_F62; i++)
  57. gdb_regs[i] = 0;
  58. if (t->new_child)
  59. pc = (unsigned long) &ret_from_fork;
  60. else
  61. pc = (unsigned long) &switch_to_pc;
  62. gdb_regs[GDB_PC] = pc;
  63. gdb_regs[GDB_NPC] = pc + 4;
  64. cwp = __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP];
  65. gdb_regs[GDB_STATE] = (TSTATE_PRIV | TSTATE_IE | cwp);
  66. gdb_regs[GDB_FSR] = 0;
  67. gdb_regs[GDB_FPRS] = 0;
  68. gdb_regs[GDB_Y] = 0;
  69. }
  70. void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  71. {
  72. struct reg_window *win;
  73. int i;
  74. for (i = 0; i < 15; i++)
  75. regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
  76. /* If the TSTATE register is changing, we have to preserve
  77. * the CWP field, otherwise window save/restore explodes.
  78. */
  79. if (regs->tstate != gdb_regs[GDB_STATE]) {
  80. unsigned long cwp = regs->tstate & TSTATE_CWP;
  81. regs->tstate = (gdb_regs[GDB_STATE] & ~TSTATE_CWP) | cwp;
  82. }
  83. regs->tpc = gdb_regs[GDB_PC];
  84. regs->tnpc = gdb_regs[GDB_NPC];
  85. regs->y = gdb_regs[GDB_Y];
  86. win = (struct reg_window *) (regs->u_regs[UREG_FP] + STACK_BIAS);
  87. for (i = 0; i < 8; i++)
  88. win->locals[i] = gdb_regs[GDB_L0 + i];
  89. for (i = 0; i < 8; i++)
  90. win->ins[i] = gdb_regs[GDB_I0 + i];
  91. }
  92. #ifdef CONFIG_SMP
  93. void __irq_entry smp_kgdb_capture_client(int irq, struct pt_regs *regs)
  94. {
  95. unsigned long flags;
  96. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  97. "wrpr %0, %1, %%pstate"
  98. : "=r" (flags)
  99. : "i" (PSTATE_IE));
  100. flushw_all();
  101. if (atomic_read(&kgdb_active) != -1)
  102. kgdb_nmicallback(raw_smp_processor_id(), regs);
  103. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  104. : : "r" (flags));
  105. }
  106. #endif
  107. int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
  108. char *remcomInBuffer, char *remcomOutBuffer,
  109. struct pt_regs *linux_regs)
  110. {
  111. unsigned long addr;
  112. char *ptr;
  113. switch (remcomInBuffer[0]) {
  114. case 'c':
  115. /* try to read optional parameter, pc unchanged if no parm */
  116. ptr = &remcomInBuffer[1];
  117. if (kgdb_hex2long(&ptr, &addr)) {
  118. linux_regs->tpc = addr;
  119. linux_regs->tnpc = addr + 4;
  120. }
  121. /* fallthru */
  122. case 'D':
  123. case 'k':
  124. if (linux_regs->tpc == (unsigned long) arch_kgdb_breakpoint) {
  125. linux_regs->tpc = linux_regs->tnpc;
  126. linux_regs->tnpc += 4;
  127. }
  128. return 0;
  129. }
  130. return -1;
  131. }
  132. asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs)
  133. {
  134. enum ctx_state prev_state = exception_enter();
  135. unsigned long flags;
  136. if (user_mode(regs)) {
  137. bad_trap(regs, trap_level);
  138. goto out;
  139. }
  140. flushw_all();
  141. local_irq_save(flags);
  142. kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
  143. local_irq_restore(flags);
  144. out:
  145. exception_exit(prev_state);
  146. }
  147. int kgdb_arch_init(void)
  148. {
  149. return 0;
  150. }
  151. void kgdb_arch_exit(void)
  152. {
  153. }
  154. void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
  155. {
  156. regs->tpc = ip;
  157. regs->tnpc = regs->tpc + 4;
  158. }
  159. struct kgdb_arch arch_kgdb_ops = {
  160. /* Breakpoint instruction: ta 0x72 */
  161. .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
  162. };