kgdb.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* kgdb support for MN10300
  2. *
  3. * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/ptrace.h>
  12. #include <linux/kgdb.h>
  13. #include <linux/uaccess.h>
  14. #include <unit/leds.h>
  15. #include <unit/serial.h>
  16. #include <asm/debugger.h>
  17. #include <asm/serial-regs.h>
  18. #include "internal.h"
  19. /*
  20. * Copy kernel exception frame registers to the GDB register file
  21. */
  22. void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  23. {
  24. unsigned long ssp = (unsigned long) (regs + 1);
  25. gdb_regs[GDB_FR_D0] = regs->d0;
  26. gdb_regs[GDB_FR_D1] = regs->d1;
  27. gdb_regs[GDB_FR_D2] = regs->d2;
  28. gdb_regs[GDB_FR_D3] = regs->d3;
  29. gdb_regs[GDB_FR_A0] = regs->a0;
  30. gdb_regs[GDB_FR_A1] = regs->a1;
  31. gdb_regs[GDB_FR_A2] = regs->a2;
  32. gdb_regs[GDB_FR_A3] = regs->a3;
  33. gdb_regs[GDB_FR_SP] = (regs->epsw & EPSW_nSL) ? regs->sp : ssp;
  34. gdb_regs[GDB_FR_PC] = regs->pc;
  35. gdb_regs[GDB_FR_MDR] = regs->mdr;
  36. gdb_regs[GDB_FR_EPSW] = regs->epsw;
  37. gdb_regs[GDB_FR_LIR] = regs->lir;
  38. gdb_regs[GDB_FR_LAR] = regs->lar;
  39. gdb_regs[GDB_FR_MDRQ] = regs->mdrq;
  40. gdb_regs[GDB_FR_E0] = regs->e0;
  41. gdb_regs[GDB_FR_E1] = regs->e1;
  42. gdb_regs[GDB_FR_E2] = regs->e2;
  43. gdb_regs[GDB_FR_E3] = regs->e3;
  44. gdb_regs[GDB_FR_E4] = regs->e4;
  45. gdb_regs[GDB_FR_E5] = regs->e5;
  46. gdb_regs[GDB_FR_E6] = regs->e6;
  47. gdb_regs[GDB_FR_E7] = regs->e7;
  48. gdb_regs[GDB_FR_SSP] = ssp;
  49. gdb_regs[GDB_FR_MSP] = 0;
  50. gdb_regs[GDB_FR_USP] = regs->sp;
  51. gdb_regs[GDB_FR_MCRH] = regs->mcrh;
  52. gdb_regs[GDB_FR_MCRL] = regs->mcrl;
  53. gdb_regs[GDB_FR_MCVF] = regs->mcvf;
  54. gdb_regs[GDB_FR_DUMMY0] = 0;
  55. gdb_regs[GDB_FR_DUMMY1] = 0;
  56. gdb_regs[GDB_FR_FS0] = 0;
  57. }
  58. /*
  59. * Extracts kernel SP/PC values understandable by gdb from the values
  60. * saved by switch_to().
  61. */
  62. void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
  63. {
  64. gdb_regs[GDB_FR_SSP] = p->thread.sp;
  65. gdb_regs[GDB_FR_PC] = p->thread.pc;
  66. gdb_regs[GDB_FR_A3] = p->thread.a3;
  67. gdb_regs[GDB_FR_USP] = p->thread.usp;
  68. gdb_regs[GDB_FR_FPCR] = p->thread.fpu_state.fpcr;
  69. }
  70. /*
  71. * Fill kernel exception frame registers from the GDB register file
  72. */
  73. void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
  74. {
  75. regs->d0 = gdb_regs[GDB_FR_D0];
  76. regs->d1 = gdb_regs[GDB_FR_D1];
  77. regs->d2 = gdb_regs[GDB_FR_D2];
  78. regs->d3 = gdb_regs[GDB_FR_D3];
  79. regs->a0 = gdb_regs[GDB_FR_A0];
  80. regs->a1 = gdb_regs[GDB_FR_A1];
  81. regs->a2 = gdb_regs[GDB_FR_A2];
  82. regs->a3 = gdb_regs[GDB_FR_A3];
  83. regs->sp = gdb_regs[GDB_FR_SP];
  84. regs->pc = gdb_regs[GDB_FR_PC];
  85. regs->mdr = gdb_regs[GDB_FR_MDR];
  86. regs->epsw = gdb_regs[GDB_FR_EPSW];
  87. regs->lir = gdb_regs[GDB_FR_LIR];
  88. regs->lar = gdb_regs[GDB_FR_LAR];
  89. regs->mdrq = gdb_regs[GDB_FR_MDRQ];
  90. regs->e0 = gdb_regs[GDB_FR_E0];
  91. regs->e1 = gdb_regs[GDB_FR_E1];
  92. regs->e2 = gdb_regs[GDB_FR_E2];
  93. regs->e3 = gdb_regs[GDB_FR_E3];
  94. regs->e4 = gdb_regs[GDB_FR_E4];
  95. regs->e5 = gdb_regs[GDB_FR_E5];
  96. regs->e6 = gdb_regs[GDB_FR_E6];
  97. regs->e7 = gdb_regs[GDB_FR_E7];
  98. regs->sp = gdb_regs[GDB_FR_SSP];
  99. /* gdb_regs[GDB_FR_MSP]; */
  100. // regs->usp = gdb_regs[GDB_FR_USP];
  101. regs->mcrh = gdb_regs[GDB_FR_MCRH];
  102. regs->mcrl = gdb_regs[GDB_FR_MCRL];
  103. regs->mcvf = gdb_regs[GDB_FR_MCVF];
  104. /* gdb_regs[GDB_FR_DUMMY0]; */
  105. /* gdb_regs[GDB_FR_DUMMY1]; */
  106. // regs->fpcr = gdb_regs[GDB_FR_FPCR];
  107. // regs->fs0 = gdb_regs[GDB_FR_FS0];
  108. }
  109. struct kgdb_arch arch_kgdb_ops = {
  110. .gdb_bpt_instr = { 0xff },
  111. .flags = KGDB_HW_BREAKPOINT,
  112. };
  113. /*
  114. * Handle unknown packets and [Ccs] packets
  115. */
  116. int kgdb_arch_handle_exception(int vector, int signo, int err_code,
  117. char *remcom_in_buffer, char *remcom_out_buffer,
  118. struct pt_regs *regs)
  119. {
  120. long addr;
  121. char *ptr;
  122. switch (remcom_in_buffer[0]) {
  123. case 'c':
  124. if (kgdb_contthread && kgdb_contthread != current) {
  125. strcpy(remcom_out_buffer, "E00");
  126. break;
  127. }
  128. kgdb_contthread = NULL;
  129. /* try to read optional parameter, pc unchanged if no parm */
  130. ptr = &remcom_in_buffer[1];
  131. if (kgdb_hex2long(&ptr, &addr))
  132. regs->pc = addr;
  133. return 0;
  134. case 's':
  135. break; /* we don't do hardware single stepping */
  136. }
  137. return -1; /* this means that we do not want to exit from the handler */
  138. }
  139. /*
  140. * Handle event interception
  141. * - returns 0 if the exception should be skipped, -ERROR otherwise.
  142. */
  143. int debugger_intercept(enum exception_code excep, int signo, int si_code,
  144. struct pt_regs *regs)
  145. {
  146. int ret;
  147. ret = kgdb_handle_exception(excep, signo, si_code, regs);
  148. debugger_local_cache_flushinv();
  149. return ret;
  150. }
  151. /*
  152. * Determine if we've hit a debugger special breakpoint
  153. */
  154. int at_debugger_breakpoint(struct pt_regs *regs)
  155. {
  156. return regs->pc == (unsigned long)&__arch_kgdb_breakpoint;
  157. }
  158. /*
  159. * Initialise kgdb
  160. */
  161. int kgdb_arch_init(void)
  162. {
  163. return 0;
  164. }
  165. /*
  166. * Do something, perhaps, but don't know what.
  167. */
  168. void kgdb_arch_exit(void)
  169. {
  170. }
  171. #ifdef CONFIG_SMP
  172. void debugger_nmi_interrupt(struct pt_regs *regs, enum exception_code code)
  173. {
  174. kgdb_nmicallback(arch_smp_processor_id(), regs);
  175. debugger_local_cache_flushinv();
  176. }
  177. void kgdb_roundup_cpus(unsigned long flags)
  178. {
  179. smp_jump_to_debugger();
  180. }
  181. #endif