kgdb_32.c 3.8 KB

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