2 * This provides the callbacks and functions that KGDB needs to share between
3 * the core, I/O and arch-specific portions.
5 * Author: Amit Kale <amitkale@linsyssoft.com> and
6 * Tom Rini <trini@kernel.crashing.org>
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.
16 #include <linux/serial_8250.h>
17 #include <linux/linkage.h>
18 #include <linux/init.h>
20 #include <asm/atomic.h>
26 * kgdb_skipexception - Bail out of KGDB when we've been triggered.
27 * @exception: Exception vector number
28 * @regs: Current &struct pt_regs.
30 * On some architectures we need to skip a breakpoint exception when
31 * it occurs after a breakpoint has been removed.
33 extern int kgdb_skipexception(int exception, struct pt_regs *regs);
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.
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.
45 extern void kgdb_post_primary_code(struct pt_regs *regs, int e_vector,
49 * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
50 * @regs: Current &struct pt_regs.
52 * This function will be called if the particular architecture must
53 * disable hardware debugging while it is processing gdb packets or
56 extern void kgdb_disable_hw_debug(struct pt_regs *regs);
58 struct tasklet_struct;
62 /* To enter the debugger explicitly. */
63 void kgdb_breakpoint(void);
65 extern int kgdb_connected;
67 extern atomic_t kgdb_setting_breakpoint;
68 extern atomic_t kgdb_cpu_doing_single_step;
70 extern struct task_struct *kgdb_usethread;
71 extern struct task_struct *kgdb_contthread;
75 BP_HARDWARE_BREAKPOINT,
89 unsigned long bpt_addr;
90 unsigned char saved_instr[BREAK_INSTR_SIZE];
91 enum kgdb_bptype type;
92 enum kgdb_bpstate state;
95 #ifndef KGDB_MAX_BREAKPOINTS
96 # define KGDB_MAX_BREAKPOINTS 1000
99 #define KGDB_HW_BREAKPOINT 1
102 * Functions each KGDB-supporting architecture must provide:
106 * kgdb_arch_init - Perform any architecture specific initalization.
108 * This function will handle the initalization of any architecture
109 * specific callbacks.
111 extern int kgdb_arch_init(void);
114 * kgdb_arch_exit - Perform any architecture specific uninitalization.
116 * This function will handle the uninitalization of any architecture
117 * specific callbacks, for dynamic registration and unregistration.
119 extern void kgdb_arch_exit(void);
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.
126 * Convert the pt_regs in @regs into the format for registers that
127 * GDB expects, stored in @gdb_regs.
129 extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
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.
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.
144 sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
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.
151 * Convert the GDB regs in @gdb_regs into the pt_regs, and store them
154 extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
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.
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
173 kgdb_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);
179 * kgdb_roundup_cpus - Get other CPUs into a holding pattern
180 * @flags: Current IRQ state
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().
192 * On non-SMP systems, this is not called.
194 extern void kgdb_roundup_cpus(unsigned long flags);
196 /* Optional functions. */
197 extern int kgdb_validate_break_address(unsigned long addr);
198 extern int kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr);
199 extern int kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle);
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
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
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.
219 unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
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);
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
239 * @post_exception: Pointer to a function that will do any cleanup work
240 * for the I/O driver.
244 int (*read_char) (void);
245 void (*write_char) (u8);
246 void (*flush) (void);
248 void (*pre_exception) (void);
249 void (*post_exception) (void);
252 extern struct kgdb_arch arch_kgdb_ops;
254 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
255 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
257 extern int kgdb_hex2long(char **ptr, long *long_val);
258 extern int kgdb_mem2hex(char *mem, char *buf, int count);
259 extern int kgdb_hex2mem(char *buf, char *mem, int count);
261 extern int kgdb_isremovedbreak(unsigned long addr);
264 kgdb_handle_exception(int ex_vector, int signo, int err_code,
265 struct pt_regs *regs);
266 extern int kgdb_nmicallback(int cpu, void *regs);
268 extern int kgdb_single_step;
269 extern atomic_t kgdb_active;
271 #endif /* _KGDB_H_ */