kgdb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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/linkage.h>
  16. #include <linux/init.h>
  17. #include <linux/atomic.h>
  18. #ifdef CONFIG_HAVE_ARCH_KGDB
  19. #include <asm/kgdb.h>
  20. #endif
  21. #ifdef CONFIG_KGDB
  22. struct pt_regs;
  23. /**
  24. * kgdb_skipexception - (optional) exit kgdb_handle_exception early
  25. * @exception: Exception vector number
  26. * @regs: Current &struct pt_regs.
  27. *
  28. * On some architectures it is required to skip a breakpoint
  29. * exception when it occurs after a breakpoint has been removed.
  30. * This can be implemented in the architecture specific portion of kgdb.
  31. */
  32. extern int kgdb_skipexception(int exception, struct pt_regs *regs);
  33. struct tasklet_struct;
  34. struct task_struct;
  35. struct uart_port;
  36. /**
  37. * kgdb_breakpoint - compiled in breakpoint
  38. *
  39. * This will be implemented as a static inline per architecture. This
  40. * function is called by the kgdb core to execute an architecture
  41. * specific trap to cause kgdb to enter the exception processing.
  42. *
  43. */
  44. void kgdb_breakpoint(void);
  45. extern int kgdb_connected;
  46. extern int kgdb_io_module_registered;
  47. extern atomic_t kgdb_setting_breakpoint;
  48. extern atomic_t kgdb_cpu_doing_single_step;
  49. extern struct task_struct *kgdb_usethread;
  50. extern struct task_struct *kgdb_contthread;
  51. enum kgdb_bptype {
  52. BP_BREAKPOINT = 0,
  53. BP_HARDWARE_BREAKPOINT,
  54. BP_WRITE_WATCHPOINT,
  55. BP_READ_WATCHPOINT,
  56. BP_ACCESS_WATCHPOINT,
  57. BP_POKE_BREAKPOINT,
  58. };
  59. enum kgdb_bpstate {
  60. BP_UNDEFINED = 0,
  61. BP_REMOVED,
  62. BP_SET,
  63. BP_ACTIVE
  64. };
  65. struct kgdb_bkpt {
  66. unsigned long bpt_addr;
  67. unsigned char saved_instr[BREAK_INSTR_SIZE];
  68. enum kgdb_bptype type;
  69. enum kgdb_bpstate state;
  70. };
  71. struct dbg_reg_def_t {
  72. char *name;
  73. int size;
  74. int offset;
  75. };
  76. #ifndef DBG_MAX_REG_NUM
  77. #define DBG_MAX_REG_NUM 0
  78. #else
  79. extern struct dbg_reg_def_t dbg_reg_def[];
  80. extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs);
  81. extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs);
  82. #endif
  83. #ifndef KGDB_MAX_BREAKPOINTS
  84. # define KGDB_MAX_BREAKPOINTS 1000
  85. #endif
  86. #define KGDB_HW_BREAKPOINT 1
  87. /*
  88. * Functions each KGDB-supporting architecture must provide:
  89. */
  90. /**
  91. * kgdb_arch_init - Perform any architecture specific initalization.
  92. *
  93. * This function will handle the initalization of any architecture
  94. * specific callbacks.
  95. */
  96. extern int kgdb_arch_init(void);
  97. /**
  98. * kgdb_arch_exit - Perform any architecture specific uninitalization.
  99. *
  100. * This function will handle the uninitalization of any architecture
  101. * specific callbacks, for dynamic registration and unregistration.
  102. */
  103. extern void kgdb_arch_exit(void);
  104. /**
  105. * pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
  106. * @gdb_regs: A pointer to hold the registers in the order GDB wants.
  107. * @regs: The &struct pt_regs of the current process.
  108. *
  109. * Convert the pt_regs in @regs into the format for registers that
  110. * GDB expects, stored in @gdb_regs.
  111. */
  112. extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
  113. /**
  114. * sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
  115. * @gdb_regs: A pointer to hold the registers in the order GDB wants.
  116. * @p: The &struct task_struct of the desired process.
  117. *
  118. * Convert the register values of the sleeping process in @p to
  119. * the format that GDB expects.
  120. * This function is called when kgdb does not have access to the
  121. * &struct pt_regs and therefore it should fill the gdb registers
  122. * @gdb_regs with what has been saved in &struct thread_struct
  123. * thread field during switch_to.
  124. */
  125. extern void
  126. sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
  127. /**
  128. * gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
  129. * @gdb_regs: A pointer to hold the registers we've received from GDB.
  130. * @regs: A pointer to a &struct pt_regs to hold these values in.
  131. *
  132. * Convert the GDB regs in @gdb_regs into the pt_regs, and store them
  133. * in @regs.
  134. */
  135. extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
  136. /**
  137. * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
  138. * @vector: The error vector of the exception that happened.
  139. * @signo: The signal number of the exception that happened.
  140. * @err_code: The error code of the exception that happened.
  141. * @remcom_in_buffer: The buffer of the packet we have read.
  142. * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
  143. * @regs: The &struct pt_regs of the current process.
  144. *
  145. * This function MUST handle the 'c' and 's' command packets,
  146. * as well packets to set / remove a hardware breakpoint, if used.
  147. * If there are additional packets which the hardware needs to handle,
  148. * they are handled here. The code should return -1 if it wants to
  149. * process more packets, and a %0 or %1 if it wants to exit from the
  150. * kgdb callback.
  151. */
  152. extern int
  153. kgdb_arch_handle_exception(int vector, int signo, int err_code,
  154. char *remcom_in_buffer,
  155. char *remcom_out_buffer,
  156. struct pt_regs *regs);
  157. /**
  158. * kgdb_roundup_cpus - Get other CPUs into a holding pattern
  159. * @flags: Current IRQ state
  160. *
  161. * On SMP systems, we need to get the attention of the other CPUs
  162. * and get them into a known state. This should do what is needed
  163. * to get the other CPUs to call kgdb_wait(). Note that on some arches,
  164. * the NMI approach is not used for rounding up all the CPUs. For example,
  165. * in case of MIPS, smp_call_function() is used to roundup CPUs. In
  166. * this case, we have to make sure that interrupts are enabled before
  167. * calling smp_call_function(). The argument to this function is
  168. * the flags that will be used when restoring the interrupts. There is
  169. * local_irq_save() call before kgdb_roundup_cpus().
  170. *
  171. * On non-SMP systems, this is not called.
  172. */
  173. extern void kgdb_roundup_cpus(unsigned long flags);
  174. /**
  175. * kgdb_arch_set_pc - Generic call back to the program counter
  176. * @regs: Current &struct pt_regs.
  177. * @pc: The new value for the program counter
  178. *
  179. * This function handles updating the program counter and requires an
  180. * architecture specific implementation.
  181. */
  182. extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
  183. /* Optional functions. */
  184. extern int kgdb_validate_break_address(unsigned long addr);
  185. extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
  186. extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
  187. /**
  188. * kgdb_arch_late - Perform any architecture specific initalization.
  189. *
  190. * This function will handle the late initalization of any
  191. * architecture specific callbacks. This is an optional function for
  192. * handling things like late initialization of hw breakpoints. The
  193. * default implementation does nothing.
  194. */
  195. extern void kgdb_arch_late(void);
  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. * @disable_hw_break: Allow an architecture to specify how to disable
  209. * hardware breakpoints for a single cpu.
  210. * @remove_all_hw_break: Allow an architecture to specify how to remove all
  211. * hardware breakpoints.
  212. * @correct_hw_break: Allow an architecture to specify how to correct the
  213. * hardware debug registers.
  214. * @enable_nmi: Manage NMI-triggered entry to KGDB
  215. */
  216. struct kgdb_arch {
  217. unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
  218. unsigned long flags;
  219. int (*set_breakpoint)(unsigned long, char *);
  220. int (*remove_breakpoint)(unsigned long, char *);
  221. int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
  222. int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
  223. void (*disable_hw_break)(struct pt_regs *regs);
  224. void (*remove_all_hw_break)(void);
  225. void (*correct_hw_break)(void);
  226. void (*enable_nmi)(bool on);
  227. };
  228. /**
  229. * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
  230. * @name: Name of the I/O driver.
  231. * @read_char: Pointer to a function that will return one char.
  232. * @write_char: Pointer to a function that will write one char.
  233. * @flush: Pointer to a function that will flush any pending writes.
  234. * @init: Pointer to a function that will initialize the device.
  235. * @pre_exception: Pointer to a function that will do any prep work for
  236. * the I/O driver.
  237. * @post_exception: Pointer to a function that will do any cleanup work
  238. * for the I/O driver.
  239. * @is_console: 1 if the end device is a console 0 if the I/O device is
  240. * not a console
  241. */
  242. struct kgdb_io {
  243. const char *name;
  244. int (*read_char) (void);
  245. void (*write_char) (u8);
  246. void (*flush) (void);
  247. int (*init) (void);
  248. void (*pre_exception) (void);
  249. void (*post_exception) (void);
  250. int is_console;
  251. };
  252. extern struct kgdb_arch arch_kgdb_ops;
  253. extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
  254. #ifdef CONFIG_SERIAL_KGDB_NMI
  255. extern int kgdb_register_nmi_console(void);
  256. extern int kgdb_unregister_nmi_console(void);
  257. extern bool kgdb_nmi_poll_knock(void);
  258. #else
  259. static inline int kgdb_register_nmi_console(void) { return 0; }
  260. static inline int kgdb_unregister_nmi_console(void) { return 0; }
  261. static inline bool kgdb_nmi_poll_knock(void) { return 1; }
  262. #endif
  263. extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
  264. extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
  265. extern struct kgdb_io *dbg_io_ops;
  266. extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
  267. extern char *kgdb_mem2hex(char *mem, char *buf, int count);
  268. extern int kgdb_hex2mem(char *buf, char *mem, int count);
  269. extern int kgdb_isremovedbreak(unsigned long addr);
  270. extern void kgdb_schedule_breakpoint(void);
  271. extern int
  272. kgdb_handle_exception(int ex_vector, int signo, int err_code,
  273. struct pt_regs *regs);
  274. extern int kgdb_nmicallback(int cpu, void *regs);
  275. extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
  276. atomic_t *snd_rdy);
  277. extern void gdbstub_exit(int status);
  278. extern int kgdb_single_step;
  279. extern atomic_t kgdb_active;
  280. #define in_dbg_master() \
  281. (raw_smp_processor_id() == atomic_read(&kgdb_active))
  282. extern bool dbg_is_early;
  283. extern void __init dbg_late_init(void);
  284. #else /* ! CONFIG_KGDB */
  285. #define in_dbg_master() (0)
  286. #define dbg_late_init()
  287. #endif /* ! CONFIG_KGDB */
  288. #endif /* _KGDB_H_ */