kgdb_64.c 4.2 KB

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