kgdb.h 9.9 KB

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