kgdb.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * This provides the callbacks and functions that KGDB needs to share between
  3. * the core, I/O and arch-specific portions.
  4. *
  5. * Author: Amit Kale <amitkale@linsyssoft.com> and
  6. * Tom Rini <trini@kernel.crashing.org>
  7. *
  8. * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
  9. * This file is licensed under the terms of the GNU General Public License
  10. * version 2. This program is licensed "as is" without any warranty of any
  11. * kind, whether express or implied.
  12. */
  13. #ifndef _KGDB_H_
  14. #define _KGDB_H_
  15. #include <linux/serial_8250.h>
  16. #include <linux/linkage.h>
  17. #include <linux/init.h>
  18. #include <asm/atomic.h>
  19. #ifdef CONFIG_HAVE_ARCH_KGDB
  20. #include <asm/kgdb.h>
  21. #endif
  22. #ifdef CONFIG_KGDB
  23. struct pt_regs;
  24. /**
  25. * kgdb_skipexception - (optional) exit kgdb_handle_exception early
  26. * @exception: Exception vector number
  27. * @regs: Current &struct pt_regs.
  28. *
  29. * On some architectures it is required to skip a breakpoint
  30. * exception when it occurs after a breakpoint has been removed.
  31. * This can be implemented in the architecture specific portion of kgdb.
  32. */
  33. extern int kgdb_skipexception(int exception, struct pt_regs *regs);
  34. /**
  35. * kgdb_disable_hw_debug - (optional) Disable hardware debugging hook
  36. * @regs: Current &struct pt_regs.
  37. *
  38. * This function will be called if the particular architecture must
  39. * disable hardware debugging while it is processing gdb packets or
  40. * handling exception.
  41. */
  42. extern void kgdb_disable_hw_debug(struct pt_regs *regs);
  43. struct tasklet_struct;
  44. struct task_struct;
  45. struct uart_port;
  46. /**
  47. * kgdb_breakpoint - compiled in breakpoint
  48. *
  49. * This will be implemented as a static inline per architecture. This
  50. * function is called by the kgdb core to execute an architecture
  51. * specific trap to cause kgdb to enter the exception processing.
  52. *
  53. */
  54. void kgdb_breakpoint(void);
  55. extern int kgdb_connected;
  56. extern int kgdb_io_module_registered;
  57. extern atomic_t kgdb_setting_breakpoint;
  58. extern atomic_t kgdb_cpu_doing_single_step;
  59. extern struct task_struct *kgdb_usethread;
  60. extern struct task_struct *kgdb_contthread;
  61. enum kgdb_bptype {
  62. BP_BREAKPOINT = 0,
  63. BP_HARDWARE_BREAKPOINT,
  64. BP_WRITE_WATCHPOINT,
  65. BP_READ_WATCHPOINT,
  66. BP_ACCESS_WATCHPOINT
  67. };
  68. enum kgdb_bpstate {
  69. BP_UNDEFINED = 0,
  70. BP_REMOVED,
  71. BP_SET,
  72. BP_ACTIVE
  73. };
  74. struct kgdb_bkpt {
  75. unsigned long bpt_addr;
  76. unsigned char saved_instr[BREAK_INSTR_SIZE];
  77. enum kgdb_bptype type;
  78. enum kgdb_bpstate state;
  79. };
  80. #ifndef KGDB_MAX_BREAKPOINTS
  81. # define KGDB_MAX_BREAKPOINTS 1000
  82. #endif
  83. #define KGDB_HW_BREAKPOINT 1
  84. /*
  85. * Functions each KGDB-supporting architecture must provide:
  86. */
  87. /**
  88. * kgdb_arch_init - Perform any architecture specific initalization.
  89. *
  90. * This function will handle the initalization of any architecture
  91. * specific callbacks.
  92. */
  93. extern int kgdb_arch_init(void);
  94. /**
  95. * kgdb_arch_exit - Perform any architecture specific uninitalization.
  96. *
  97. * This function will handle the uninitalization of any architecture
  98. * specific callbacks, for dynamic registration and unregistration.
  99. */
  100. extern void kgdb_arch_exit(void);
  101. /**
  102. * pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
  103. * @gdb_regs: A pointer to hold the registers in the order GDB wants.
  104. * @regs: The &struct pt_regs of the current process.
  105. *
  106. * Convert the pt_regs in @regs into the format for registers that
  107. * GDB expects, stored in @gdb_regs.
  108. */
  109. extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
  110. /**
  111. * sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
  112. * @gdb_regs: A pointer to hold the registers in the order GDB wants.
  113. * @p: The &struct task_struct of the desired process.
  114. *
  115. * Convert the register values of the sleeping process in @p to
  116. * the format that GDB expects.
  117. * This function is called when kgdb does not have access to the
  118. * &struct pt_regs and therefore it should fill the gdb registers
  119. * @gdb_regs with what has been saved in &struct thread_struct
  120. * thread field during switch_to.
  121. */
  122. extern void
  123. sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
  124. /**
  125. * gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
  126. * @gdb_regs: A pointer to hold the registers we've received from GDB.
  127. * @regs: A pointer to a &struct pt_regs to hold these values in.
  128. *
  129. * Convert the GDB regs in @gdb_regs into the pt_regs, and store them
  130. * in @regs.
  131. */
  132. extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
  133. /**
  134. * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
  135. * @vector: The error vector of the exception that happened.
  136. * @signo: The signal number of the exception that happened.
  137. * @err_code: The error code of the exception that happened.
  138. * @remcom_in_buffer: The buffer of the packet we have read.
  139. * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
  140. * @regs: The &struct pt_regs of the current process.
  141. *
  142. * This function MUST handle the 'c' and 's' command packets,
  143. * as well packets to set / remove a hardware breakpoint, if used.
  144. * If there are additional packets which the hardware needs to handle,
  145. * they are handled here. The code should return -1 if it wants to
  146. * process more packets, and a %0 or %1 if it wants to exit from the
  147. * kgdb callback.
  148. */
  149. extern int
  150. kgdb_arch_handle_exception(int vector, int signo, int err_code,
  151. char *remcom_in_buffer,
  152. char *remcom_out_buffer,
  153. struct pt_regs *regs);
  154. /**
  155. * kgdb_roundup_cpus - Get other CPUs into a holding pattern
  156. * @flags: Current IRQ state
  157. *
  158. * On SMP systems, we need to get the attention of the other CPUs
  159. * and get them into a known state. This should do what is needed
  160. * to get the other CPUs to call kgdb_wait(). Note that on some arches,
  161. * the NMI approach is not used for rounding up all the CPUs. For example,
  162. * in case of MIPS, smp_call_function() is used to roundup CPUs. In
  163. * this case, we have to make sure that interrupts are enabled before
  164. * calling smp_call_function(). The argument to this function is
  165. * the flags that will be used when restoring the interrupts. There is
  166. * local_irq_save() call before kgdb_roundup_cpus().
  167. *
  168. * On non-SMP systems, this is not called.
  169. */
  170. extern void kgdb_roundup_cpus(unsigned long flags);
  171. /**
  172. * kgdb_arch_set_pc - Generic call back to the program counter
  173. * @regs: Current &struct pt_regs.
  174. * @pc: The new value for the program counter
  175. *
  176. * This function handles updating the program counter and requires an
  177. * architecture specific implementation.
  178. */
  179. extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
  180. /* Optional functions. */
  181. extern int kgdb_validate_break_address(unsigned long addr);
  182. extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);
  183. extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);
  184. /**
  185. * struct kgdb_arch - Describe architecture specific values.
  186. * @gdb_bpt_instr: The instruction to trigger a breakpoint.
  187. * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
  188. * @set_breakpoint: Allow an architecture to specify how to set a software
  189. * breakpoint.
  190. * @remove_breakpoint: Allow an architecture to specify how to remove a
  191. * software breakpoint.
  192. * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
  193. * breakpoint.
  194. * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
  195. * hardware breakpoint.
  196. * @remove_all_hw_break: Allow an architecture to specify how to remove all
  197. * hardware breakpoints.
  198. * @correct_hw_break: Allow an architecture to specify how to correct the
  199. * hardware debug registers.
  200. */
  201. struct kgdb_arch {
  202. unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
  203. unsigned long flags;
  204. int (*set_breakpoint)(unsigned long, char *);
  205. int (*remove_breakpoint)(unsigned long, char *);
  206. int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
  207. int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
  208. void (*remove_all_hw_break)(void);
  209. void (*correct_hw_break)(void);
  210. };
  211. /**
  212. * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
  213. * @name: Name of the I/O driver.
  214. * @read_char: Pointer to a function that will return one char.
  215. * @write_char: Pointer to a function that will write one char.
  216. * @flush: Pointer to a function that will flush any pending writes.
  217. * @init: Pointer to a function that will initialize the device.
  218. * @pre_exception: Pointer to a function that will do any prep work for
  219. * the I/O driver.
  220. * @post_exception: Pointer to a function that will do any cleanup work
  221. * for the I/O driver.
  222. */
  223. struct kgdb_io {
  224. const char *name;
  225. int (*read_char) (void);
  226. void (*write_char) (u8);
  227. void (*flush) (void);
  228. int (*init) (void);
  229. void (*pre_exception) (void);
  230. void (*post_exception) (void);
  231. };
  232. extern struct kgdb_arch arch_kgdb_ops;
  233. extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
  234. extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
  235. extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
  236. extern struct kgdb_io *dbg_io_ops;
  237. extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
  238. extern int kgdb_mem2hex(char *mem, char *buf, int count);
  239. extern int kgdb_hex2mem(char *buf, char *mem, int count);
  240. extern int kgdb_isremovedbreak(unsigned long addr);
  241. extern void kgdb_schedule_breakpoint(void);
  242. extern int
  243. kgdb_handle_exception(int ex_vector, int signo, int err_code,
  244. struct pt_regs *regs);
  245. extern int kgdb_nmicallback(int cpu, void *regs);
  246. extern int kgdb_single_step;
  247. extern atomic_t kgdb_active;
  248. #define in_dbg_master() \
  249. (raw_smp_processor_id() == atomic_read(&kgdb_active))
  250. #else /* ! CONFIG_KGDB */
  251. #define in_dbg_master() (0)
  252. #endif /* ! CONFIG_KGDB */
  253. #endif /* _KGDB_H_ */