kgdb_64.c 4.3 KB

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