Blame view

include/linux/kgdb.h 10.7 KB
dc7d55270   Jason Wessel   kgdb: core
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * This provides the callbacks and functions that KGDB needs to share between
   * the core, I/O and arch-specific portions.
   *
   * Author: Amit Kale <amitkale@linsyssoft.com> and
   *         Tom Rini <trini@kernel.crashing.org>
   *
   * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
   * This file is licensed under the terms of the GNU General Public License
   * version 2. This program is licensed "as is" without any warranty of any
   * kind, whether express or implied.
   */
  #ifndef _KGDB_H_
  #define _KGDB_H_
dc7d55270   Jason Wessel   kgdb: core
15
16
  #include <linux/linkage.h>
  #include <linux/init.h>
60063497a   Arun Sharma   atomic: use <linu...
17
  #include <linux/atomic.h>
dcc787112   Jason Wessel   kgdb: core change...
18
  #ifdef CONFIG_HAVE_ARCH_KGDB
dc7d55270   Jason Wessel   kgdb: core
19
  #include <asm/kgdb.h>
dcc787112   Jason Wessel   kgdb: core change...
20
  #endif
dc7d55270   Jason Wessel   kgdb: core
21

dcc787112   Jason Wessel   kgdb: core change...
22
  #ifdef CONFIG_KGDB
dc7d55270   Jason Wessel   kgdb: core
23
  struct pt_regs;
e3e2aaf7d   Jason Wessel   kgdb: add documen...
24
25
  /**
   *	kgdb_skipexception - (optional) exit kgdb_handle_exception early
dc7d55270   Jason Wessel   kgdb: core
26
27
28
   *	@exception: Exception vector number
   *	@regs: Current &struct pt_regs.
   *
e3e2aaf7d   Jason Wessel   kgdb: add documen...
29
30
   *	On some architectures it is required to skip a breakpoint
   *	exception when it occurs after a breakpoint has been removed.
b11e1eca7   Randy Dunlap   kgdb: Fix kernel-...
31
   *	This can be implemented in the architecture specific portion of kgdb.
dc7d55270   Jason Wessel   kgdb: core
32
33
   */
  extern int kgdb_skipexception(int exception, struct pt_regs *regs);
dc7d55270   Jason Wessel   kgdb: core
34
35
36
  struct tasklet_struct;
  struct task_struct;
  struct uart_port;
e3e2aaf7d   Jason Wessel   kgdb: add documen...
37
38
39
  /**
   *	kgdb_breakpoint - compiled in breakpoint
   *
b11e1eca7   Randy Dunlap   kgdb: Fix kernel-...
40
   *	This will be implemented as a static inline per architecture.  This
e3e2aaf7d   Jason Wessel   kgdb: add documen...
41
42
43
44
   *	function is called by the kgdb core to execute an architecture
   *	specific trap to cause kgdb to enter the exception processing.
   *
   */
dc7d55270   Jason Wessel   kgdb: core
45
46
47
  void kgdb_breakpoint(void);
  
  extern int kgdb_connected;
f503b5ae5   Jason Wessel   x86,kgdb: Add low...
48
  extern int kgdb_io_module_registered;
dc7d55270   Jason Wessel   kgdb: core
49
50
51
52
53
54
55
56
57
58
59
60
  
  extern atomic_t			kgdb_setting_breakpoint;
  extern atomic_t			kgdb_cpu_doing_single_step;
  
  extern struct task_struct	*kgdb_usethread;
  extern struct task_struct	*kgdb_contthread;
  
  enum kgdb_bptype {
  	BP_BREAKPOINT = 0,
  	BP_HARDWARE_BREAKPOINT,
  	BP_WRITE_WATCHPOINT,
  	BP_READ_WATCHPOINT,
3751d3e85   Jason Wessel   x86,kgdb: Fix DEB...
61
62
  	BP_ACCESS_WATCHPOINT,
  	BP_POKE_BREAKPOINT,
dc7d55270   Jason Wessel   kgdb: core
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  };
  
  enum kgdb_bpstate {
  	BP_UNDEFINED = 0,
  	BP_REMOVED,
  	BP_SET,
  	BP_ACTIVE
  };
  
  struct kgdb_bkpt {
  	unsigned long		bpt_addr;
  	unsigned char		saved_instr[BREAK_INSTR_SIZE];
  	enum kgdb_bptype	type;
  	enum kgdb_bpstate	state;
  };
534af1082   Jason Wessel   kgdb,kdb: individ...
78
79
80
81
82
83
84
85
86
87
88
89
90
  struct dbg_reg_def_t {
  	char *name;
  	int size;
  	int offset;
  };
  
  #ifndef DBG_MAX_REG_NUM
  #define DBG_MAX_REG_NUM 0
  #else
  extern struct dbg_reg_def_t dbg_reg_def[];
  extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs);
  extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs);
  #endif
dc7d55270   Jason Wessel   kgdb: core
91
92
93
94
95
96
97
98
99
  #ifndef KGDB_MAX_BREAKPOINTS
  # define KGDB_MAX_BREAKPOINTS	1000
  #endif
  
  #define KGDB_HW_BREAKPOINT	1
  
  /*
   * Functions each KGDB-supporting architecture must provide:
   */
e3e2aaf7d   Jason Wessel   kgdb: add documen...
100
  /**
dc7d55270   Jason Wessel   kgdb: core
101
102
103
104
105
106
   *	kgdb_arch_init - Perform any architecture specific initalization.
   *
   *	This function will handle the initalization of any architecture
   *	specific callbacks.
   */
  extern int kgdb_arch_init(void);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
107
  /**
dc7d55270   Jason Wessel   kgdb: core
108
109
110
111
112
113
   *	kgdb_arch_exit - Perform any architecture specific uninitalization.
   *
   *	This function will handle the uninitalization of any architecture
   *	specific callbacks, for dynamic registration and unregistration.
   */
  extern void kgdb_arch_exit(void);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
114
  /**
dc7d55270   Jason Wessel   kgdb: core
115
116
117
118
119
120
121
122
   *	pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
   *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
   *	@regs: The &struct pt_regs of the current process.
   *
   *	Convert the pt_regs in @regs into the format for registers that
   *	GDB expects, stored in @gdb_regs.
   */
  extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
123
  /**
dc7d55270   Jason Wessel   kgdb: core
124
125
126
127
128
129
130
131
132
133
134
135
136
   *	sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
   *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
   *	@p: The &struct task_struct of the desired process.
   *
   *	Convert the register values of the sleeping process in @p to
   *	the format that GDB expects.
   *	This function is called when kgdb does not have access to the
   *	&struct pt_regs and therefore it should fill the gdb registers
   *	@gdb_regs with what has	been saved in &struct thread_struct
   *	thread field during switch_to.
   */
  extern void
  sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
137
  /**
dc7d55270   Jason Wessel   kgdb: core
138
139
140
141
142
143
144
145
   *	gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
   *	@gdb_regs: A pointer to hold the registers we've received from GDB.
   *	@regs: A pointer to a &struct pt_regs to hold these values in.
   *
   *	Convert the GDB regs in @gdb_regs into the pt_regs, and store them
   *	in @regs.
   */
  extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
146
  /**
dc7d55270   Jason Wessel   kgdb: core
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
   *	kgdb_arch_handle_exception - Handle architecture specific GDB packets.
   *	@vector: The error vector of the exception that happened.
   *	@signo: The signal number of the exception that happened.
   *	@err_code: The error code of the exception that happened.
   *	@remcom_in_buffer: The buffer of the packet we have read.
   *	@remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
   *	@regs: The &struct pt_regs of the current process.
   *
   *	This function MUST handle the 'c' and 's' command packets,
   *	as well packets to set / remove a hardware breakpoint, if used.
   *	If there are additional packets which the hardware needs to handle,
   *	they are handled here.  The code should return -1 if it wants to
   *	process more packets, and a %0 or %1 if it wants to exit from the
   *	kgdb callback.
   */
  extern int
  kgdb_arch_handle_exception(int vector, int signo, int err_code,
  			   char *remcom_in_buffer,
  			   char *remcom_out_buffer,
  			   struct pt_regs *regs);
e3e2aaf7d   Jason Wessel   kgdb: add documen...
167
  /**
dc7d55270   Jason Wessel   kgdb: core
168
169
170
171
   *	kgdb_roundup_cpus - Get other CPUs into a holding pattern
   *	@flags: Current IRQ state
   *
   *	On SMP systems, we need to get the attention of the other CPUs
b11e1eca7   Randy Dunlap   kgdb: Fix kernel-...
172
   *	and get them into a known state.  This should do what is needed
dc7d55270   Jason Wessel   kgdb: core
173
174
175
176
177
178
179
180
181
182
183
   *	to get the other CPUs to call kgdb_wait(). Note that on some arches,
   *	the NMI approach is not used for rounding up all the CPUs. For example,
   *	in case of MIPS, smp_call_function() is used to roundup CPUs. In
   *	this case, we have to make sure that interrupts are enabled before
   *	calling smp_call_function(). The argument to this function is
   *	the flags that will be used when restoring the interrupts. There is
   *	local_irq_save() call before kgdb_roundup_cpus().
   *
   *	On non-SMP systems, this is not called.
   */
  extern void kgdb_roundup_cpus(unsigned long flags);
84c08fd61   Jason Wessel   kgdb,docs: Update...
184
185
186
187
188
189
190
191
192
  /**
   *	kgdb_arch_set_pc - Generic call back to the program counter
   *	@regs: Current &struct pt_regs.
   *  @pc: The new value for the program counter
   *
   *	This function handles updating the program counter and requires an
   *	architecture specific implementation.
   */
  extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
dc7d55270   Jason Wessel   kgdb: core
193
194
  /* Optional functions. */
  extern int kgdb_validate_break_address(unsigned long addr);
98b54aa1a   Jason Wessel   kgdb,debug_core: ...
195
196
  extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
  extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
dc7d55270   Jason Wessel   kgdb: core
197

e3e2aaf7d   Jason Wessel   kgdb: add documen...
198
  /**
0b4b3827d   Jason Wessel   x86, kgdb, init: ...
199
200
201
202
203
204
205
206
207
208
209
   *	kgdb_arch_late - Perform any architecture specific initalization.
   *
   *	This function will handle the late initalization of any
   *	architecture specific callbacks.  This is an optional function for
   *	handling things like late initialization of hw breakpoints.  The
   *	default implementation does nothing.
   */
  extern void kgdb_arch_late(void);
  
  
  /**
dc7d55270   Jason Wessel   kgdb: core
210
211
212
213
214
215
216
217
218
219
220
   * struct kgdb_arch - Describe architecture specific values.
   * @gdb_bpt_instr: The instruction to trigger a breakpoint.
   * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
   * @set_breakpoint: Allow an architecture to specify how to set a software
   * breakpoint.
   * @remove_breakpoint: Allow an architecture to specify how to remove a
   * software breakpoint.
   * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
   * breakpoint.
   * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
   * hardware breakpoint.
d7ba979d4   Dongdong Deng   debug_core,x86,bl...
221
222
   * @disable_hw_break: Allow an architecture to specify how to disable
   * hardware breakpoints for a single cpu.
dc7d55270   Jason Wessel   kgdb: core
223
224
225
226
   * @remove_all_hw_break: Allow an architecture to specify how to remove all
   * hardware breakpoints.
   * @correct_hw_break: Allow an architecture to specify how to correct the
   * hardware debug registers.
5a14fead0   Anton Vorontsov   kernel/debug: Mas...
227
   * @enable_nmi: Manage NMI-triggered entry to KGDB
dc7d55270   Jason Wessel   kgdb: core
228
229
230
231
232
233
234
235
236
   */
  struct kgdb_arch {
  	unsigned char		gdb_bpt_instr[BREAK_INSTR_SIZE];
  	unsigned long		flags;
  
  	int	(*set_breakpoint)(unsigned long, char *);
  	int	(*remove_breakpoint)(unsigned long, char *);
  	int	(*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
  	int	(*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
d7ba979d4   Dongdong Deng   debug_core,x86,bl...
237
  	void	(*disable_hw_break)(struct pt_regs *regs);
dc7d55270   Jason Wessel   kgdb: core
238
239
  	void	(*remove_all_hw_break)(void);
  	void	(*correct_hw_break)(void);
5a14fead0   Anton Vorontsov   kernel/debug: Mas...
240
241
  
  	void	(*enable_nmi)(bool on);
dc7d55270   Jason Wessel   kgdb: core
242
  };
e3e2aaf7d   Jason Wessel   kgdb: add documen...
243
  /**
dc7d55270   Jason Wessel   kgdb: core
244
245
246
247
248
249
250
251
252
253
   * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
   * @name: Name of the I/O driver.
   * @read_char: Pointer to a function that will return one char.
   * @write_char: Pointer to a function that will write one char.
   * @flush: Pointer to a function that will flush any pending writes.
   * @init: Pointer to a function that will initialize the device.
   * @pre_exception: Pointer to a function that will do any prep work for
   * the I/O driver.
   * @post_exception: Pointer to a function that will do any cleanup work
   * for the I/O driver.
efe2f29e3   Jason Wessel   kgdboc,kdb: Allow...
254
255
   * @is_console: 1 if the end device is a console 0 if the I/O device is
   * not a console
dc7d55270   Jason Wessel   kgdb: core
256
257
258
259
260
261
262
263
264
   */
  struct kgdb_io {
  	const char		*name;
  	int			(*read_char) (void);
  	void			(*write_char) (u8);
  	void			(*flush) (void);
  	int			(*init) (void);
  	void			(*pre_exception) (void);
  	void			(*post_exception) (void);
efe2f29e3   Jason Wessel   kgdboc,kdb: Allow...
265
  	int			is_console;
dc7d55270   Jason Wessel   kgdb: core
266
267
268
  };
  
  extern struct kgdb_arch		arch_kgdb_ops;
688b744d8   Harvey Harrison   kgdb: fix signedn...
269
  extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
0c57dfcc6   Anton Vorontsov   tty/serial: Add k...
270
271
272
273
274
275
276
277
278
  #ifdef CONFIG_SERIAL_KGDB_NMI
  extern int kgdb_register_nmi_console(void);
  extern int kgdb_unregister_nmi_console(void);
  extern bool kgdb_nmi_poll_knock(void);
  #else
  static inline int kgdb_register_nmi_console(void) { return 0; }
  static inline int kgdb_unregister_nmi_console(void) { return 0; }
  static inline bool kgdb_nmi_poll_knock(void) { return 1; }
  #endif
dc7d55270   Jason Wessel   kgdb: core
279
280
  extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
  extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
53197fc49   Jason Wessel   Separate the gdbs...
281
  extern struct kgdb_io *dbg_io_ops;
dc7d55270   Jason Wessel   kgdb: core
282

688b744d8   Harvey Harrison   kgdb: fix signedn...
283
  extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
55751145d   Jason Wessel   gdbstub: Implemen...
284
  extern char *kgdb_mem2hex(char *mem, char *buf, int count);
dc7d55270   Jason Wessel   kgdb: core
285
286
287
  extern int kgdb_hex2mem(char *buf, char *mem, int count);
  
  extern int kgdb_isremovedbreak(unsigned long addr);
1cee5e35f   Jason Wessel   kgdb: Add the abi...
288
  extern void kgdb_schedule_breakpoint(void);
dc7d55270   Jason Wessel   kgdb: core
289
290
291
292
293
  
  extern int
  kgdb_handle_exception(int ex_vector, int signo, int err_code,
  		      struct pt_regs *regs);
  extern int kgdb_nmicallback(int cpu, void *regs);
fc8b13740   Mike Travis   kgdb/kdb: Fix no ...
294
295
  extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
  			  atomic_t *snd_rdy);
d57f078b1   David Howells   KGDB: Notify GDB ...
296
  extern void gdbstub_exit(int status);
dc7d55270   Jason Wessel   kgdb: core
297
298
299
  
  extern int			kgdb_single_step;
  extern atomic_t			kgdb_active;
dcc787112   Jason Wessel   kgdb: core change...
300
301
  #define in_dbg_master() \
  	(raw_smp_processor_id() == atomic_read(&kgdb_active))
0b4b3827d   Jason Wessel   x86, kgdb, init: ...
302
303
  extern bool dbg_is_early;
  extern void __init dbg_late_init(void);
dcc787112   Jason Wessel   kgdb: core change...
304
305
  #else /* ! CONFIG_KGDB */
  #define in_dbg_master() (0)
0b4b3827d   Jason Wessel   x86, kgdb, init: ...
306
  #define dbg_late_init()
dcc787112   Jason Wessel   kgdb: core change...
307
  #endif /* ! CONFIG_KGDB */
dc7d55270   Jason Wessel   kgdb: core
308
  #endif /* _KGDB_H_ */