kgdb_64.c 4.3 KB

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