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