Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
kgdb.h
Go to the documentation of this file.
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 <[email protected]> and
6  * Tom Rini <[email protected]>
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 
16 #include <linux/serial_8250.h>
17 #include <linux/linkage.h>
18 #include <linux/init.h>
19 #include <linux/atomic.h>
20 #ifdef CONFIG_HAVE_ARCH_KGDB
21 #include <asm/kgdb.h>
22 #endif
23 
24 #ifdef CONFIG_KGDB
25 struct pt_regs;
26 
36 extern int kgdb_skipexception(int exception, struct pt_regs *regs);
37 
38 struct tasklet_struct;
39 struct task_struct;
40 struct uart_port;
41 
50 void kgdb_breakpoint(void);
51 
52 extern int kgdb_connected;
53 extern int kgdb_io_module_registered;
54 
57 
58 extern struct task_struct *kgdb_usethread;
59 extern struct task_struct *kgdb_contthread;
60 
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  BP_POKE_BREAKPOINT,
68 };
69 
70 enum kgdb_bpstate {
71  BP_UNDEFINED = 0,
72  BP_REMOVED,
73  BP_SET,
74  BP_ACTIVE
75 };
76 
77 struct kgdb_bkpt {
78  unsigned long bpt_addr;
79  unsigned char saved_instr[BREAK_INSTR_SIZE];
80  enum kgdb_bptype type;
81  enum kgdb_bpstate state;
82 };
83 
84 struct dbg_reg_def_t {
85  char *name;
86  int size;
87  int offset;
88 };
89 
90 #ifndef DBG_MAX_REG_NUM
91 #define DBG_MAX_REG_NUM 0
92 #else
93 extern struct dbg_reg_def_t dbg_reg_def[];
94 extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs);
95 extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs);
96 #endif
97 #ifndef KGDB_MAX_BREAKPOINTS
98 # define KGDB_MAX_BREAKPOINTS 1000
99 #endif
100 
101 #define KGDB_HW_BREAKPOINT 1
102 
103 /*
104  * Functions each KGDB-supporting architecture must provide:
105  */
106 
113 extern int kgdb_arch_init(void);
114 
121 extern void kgdb_arch_exit(void);
122 
131 extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
132 
145 extern void
146 sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
147 
156 extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
157 
174 extern int
175 kgdb_arch_handle_exception(int vector, int signo, int err_code,
176  char *remcom_in_buffer,
177  char *remcom_out_buffer,
178  struct pt_regs *regs);
179 
196 extern void kgdb_roundup_cpus(unsigned long flags);
197 
206 extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
207 
208 
209 /* Optional functions. */
210 extern int kgdb_validate_break_address(unsigned long addr);
211 extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
212 extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
213 
222 extern void kgdb_arch_late(void);
223 
224 
245 struct kgdb_arch {
246  unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
247  unsigned long flags;
248 
249  int (*set_breakpoint)(unsigned long, char *);
250  int (*remove_breakpoint)(unsigned long, char *);
251  int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
252  int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
253  void (*disable_hw_break)(struct pt_regs *regs);
254  void (*remove_all_hw_break)(void);
255  void (*correct_hw_break)(void);
256 
257  void (*enable_nmi)(bool on);
258 };
259 
274 struct kgdb_io {
275  const char *name;
276  int (*read_char) (void);
277  void (*write_char) (u8);
278  void (*flush) (void);
279  int (*init) (void);
280  void (*pre_exception) (void);
281  void (*post_exception) (void);
282  int is_console;
283 };
284 
285 extern struct kgdb_arch arch_kgdb_ops;
286 
287 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
288 
289 #ifdef CONFIG_SERIAL_KGDB_NMI
290 extern int kgdb_register_nmi_console(void);
291 extern int kgdb_unregister_nmi_console(void);
292 extern bool kgdb_nmi_poll_knock(void);
293 #else
294 static inline int kgdb_register_nmi_console(void) { return 0; }
295 static inline int kgdb_unregister_nmi_console(void) { return 0; }
296 static inline bool kgdb_nmi_poll_knock(void) { return 1; }
297 #endif
298 
299 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
300 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
301 extern struct kgdb_io *dbg_io_ops;
302 
303 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
304 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
305 extern int kgdb_hex2mem(char *buf, char *mem, int count);
306 
307 extern int kgdb_isremovedbreak(unsigned long addr);
308 extern void kgdb_schedule_breakpoint(void);
309 
310 extern int
311 kgdb_handle_exception(int ex_vector, int signo, int err_code,
312  struct pt_regs *regs);
313 extern int kgdb_nmicallback(int cpu, void *regs);
314 extern void gdbstub_exit(int status);
315 
316 extern int kgdb_single_step;
317 extern atomic_t kgdb_active;
318 #define in_dbg_master() \
319  (raw_smp_processor_id() == atomic_read(&kgdb_active))
320 extern bool dbg_is_early;
321 extern void __init dbg_late_init(void);
322 #else /* ! CONFIG_KGDB */
323 #define in_dbg_master() (0)
324 #define dbg_late_init()
325 #endif /* ! CONFIG_KGDB */
326 #endif /* _KGDB_H_ */