![]() |
|
|||
0001 /* 0002 * This provides the callbacks and functions that KGDB needs to share between 0003 * the core, I/O and arch-specific portions. 0004 * 0005 * Author: Amit Kale <amitkale@linsyssoft.com> and 0006 * Tom Rini <trini@kernel.crashing.org> 0007 * 0008 * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc. 0009 * This file is licensed under the terms of the GNU General Public License 0010 * version 2. This program is licensed "as is" without any warranty of any 0011 * kind, whether express or implied. 0012 */ 0013 #ifndef _KGDB_H_ 0014 #define _KGDB_H_ 0015 0016 #include <linux/linkage.h> 0017 #include <linux/init.h> 0018 #include <linux/atomic.h> 0019 #include <linux/kprobes.h> 0020 #ifdef CONFIG_HAVE_ARCH_KGDB 0021 #include <asm/kgdb.h> 0022 #endif 0023 0024 #ifdef CONFIG_KGDB 0025 struct pt_regs; 0026 0027 /** 0028 * kgdb_skipexception - (optional) exit kgdb_handle_exception early 0029 * @exception: Exception vector number 0030 * @regs: Current &struct pt_regs. 0031 * 0032 * On some architectures it is required to skip a breakpoint 0033 * exception when it occurs after a breakpoint has been removed. 0034 * This can be implemented in the architecture specific portion of kgdb. 0035 */ 0036 extern int kgdb_skipexception(int exception, struct pt_regs *regs); 0037 0038 struct tasklet_struct; 0039 struct task_struct; 0040 struct uart_port; 0041 0042 /** 0043 * kgdb_breakpoint - compiled in breakpoint 0044 * 0045 * This will be implemented as a static inline per architecture. This 0046 * function is called by the kgdb core to execute an architecture 0047 * specific trap to cause kgdb to enter the exception processing. 0048 * 0049 */ 0050 void kgdb_breakpoint(void); 0051 0052 extern int kgdb_connected; 0053 extern int kgdb_io_module_registered; 0054 0055 extern atomic_t kgdb_setting_breakpoint; 0056 extern atomic_t kgdb_cpu_doing_single_step; 0057 0058 extern struct task_struct *kgdb_usethread; 0059 extern struct task_struct *kgdb_contthread; 0060 0061 enum kgdb_bptype { 0062 BP_BREAKPOINT = 0, 0063 BP_HARDWARE_BREAKPOINT, 0064 BP_WRITE_WATCHPOINT, 0065 BP_READ_WATCHPOINT, 0066 BP_ACCESS_WATCHPOINT, 0067 BP_POKE_BREAKPOINT, 0068 }; 0069 0070 enum kgdb_bpstate { 0071 BP_UNDEFINED = 0, 0072 BP_REMOVED, 0073 BP_SET, 0074 BP_ACTIVE 0075 }; 0076 0077 struct kgdb_bkpt { 0078 unsigned long bpt_addr; 0079 unsigned char saved_instr[BREAK_INSTR_SIZE]; 0080 enum kgdb_bptype type; 0081 enum kgdb_bpstate state; 0082 }; 0083 0084 struct dbg_reg_def_t { 0085 char *name; 0086 int size; 0087 int offset; 0088 }; 0089 0090 #ifndef DBG_MAX_REG_NUM 0091 #define DBG_MAX_REG_NUM 0 0092 #else 0093 extern struct dbg_reg_def_t dbg_reg_def[]; 0094 extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs); 0095 extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs); 0096 #endif 0097 #ifndef KGDB_MAX_BREAKPOINTS 0098 # define KGDB_MAX_BREAKPOINTS 1000 0099 #endif 0100 0101 #define KGDB_HW_BREAKPOINT 1 0102 0103 /* 0104 * Functions each KGDB-supporting architecture must provide: 0105 */ 0106 0107 /** 0108 * kgdb_arch_init - Perform any architecture specific initialization. 0109 * 0110 * This function will handle the initialization of any architecture 0111 * specific callbacks. 0112 */ 0113 extern int kgdb_arch_init(void); 0114 0115 /** 0116 * kgdb_arch_exit - Perform any architecture specific uninitalization. 0117 * 0118 * This function will handle the uninitalization of any architecture 0119 * specific callbacks, for dynamic registration and unregistration. 0120 */ 0121 extern void kgdb_arch_exit(void); 0122 0123 /** 0124 * pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs 0125 * @gdb_regs: A pointer to hold the registers in the order GDB wants. 0126 * @regs: The &struct pt_regs of the current process. 0127 * 0128 * Convert the pt_regs in @regs into the format for registers that 0129 * GDB expects, stored in @gdb_regs. 0130 */ 0131 extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs); 0132 0133 /** 0134 * sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs 0135 * @gdb_regs: A pointer to hold the registers in the order GDB wants. 0136 * @p: The &struct task_struct of the desired process. 0137 * 0138 * Convert the register values of the sleeping process in @p to 0139 * the format that GDB expects. 0140 * This function is called when kgdb does not have access to the 0141 * &struct pt_regs and therefore it should fill the gdb registers 0142 * @gdb_regs with what has been saved in &struct thread_struct 0143 * thread field during switch_to. 0144 */ 0145 extern void 0146 sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p); 0147 0148 /** 0149 * gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs. 0150 * @gdb_regs: A pointer to hold the registers we've received from GDB. 0151 * @regs: A pointer to a &struct pt_regs to hold these values in. 0152 * 0153 * Convert the GDB regs in @gdb_regs into the pt_regs, and store them 0154 * in @regs. 0155 */ 0156 extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs); 0157 0158 /** 0159 * kgdb_arch_handle_exception - Handle architecture specific GDB packets. 0160 * @vector: The error vector of the exception that happened. 0161 * @signo: The signal number of the exception that happened. 0162 * @err_code: The error code of the exception that happened. 0163 * @remcom_in_buffer: The buffer of the packet we have read. 0164 * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into. 0165 * @regs: The &struct pt_regs of the current process. 0166 * 0167 * This function MUST handle the 'c' and 's' command packets, 0168 * as well packets to set / remove a hardware breakpoint, if used. 0169 * If there are additional packets which the hardware needs to handle, 0170 * they are handled here. The code should return -1 if it wants to 0171 * process more packets, and a %0 or %1 if it wants to exit from the 0172 * kgdb callback. 0173 */ 0174 extern int 0175 kgdb_arch_handle_exception(int vector, int signo, int err_code, 0176 char *remcom_in_buffer, 0177 char *remcom_out_buffer, 0178 struct pt_regs *regs); 0179 0180 /** 0181 * kgdb_arch_handle_qxfer_pkt - Handle architecture specific GDB XML 0182 * packets. 0183 * @remcom_in_buffer: The buffer of the packet we have read. 0184 * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into. 0185 */ 0186 0187 extern void 0188 kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer, 0189 char *remcom_out_buffer); 0190 0191 /** 0192 * kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU 0193 * @ignored: This parameter is only here to match the prototype. 0194 * 0195 * If you're using the default implementation of kgdb_roundup_cpus() 0196 * this function will be called per CPU. If you don't implement 0197 * kgdb_call_nmi_hook() a default will be used. 0198 */ 0199 0200 extern void kgdb_call_nmi_hook(void *ignored); 0201 0202 /** 0203 * kgdb_roundup_cpus - Get other CPUs into a holding pattern 0204 * 0205 * On SMP systems, we need to get the attention of the other CPUs 0206 * and get them into a known state. This should do what is needed 0207 * to get the other CPUs to call kgdb_wait(). Note that on some arches, 0208 * the NMI approach is not used for rounding up all the CPUs. Normally 0209 * those architectures can just not implement this and get the default. 0210 * 0211 * On non-SMP systems, this is not called. 0212 */ 0213 extern void kgdb_roundup_cpus(void); 0214 0215 /** 0216 * kgdb_arch_set_pc - Generic call back to the program counter 0217 * @regs: Current &struct pt_regs. 0218 * @pc: The new value for the program counter 0219 * 0220 * This function handles updating the program counter and requires an 0221 * architecture specific implementation. 0222 */ 0223 extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc); 0224 0225 0226 /* Optional functions. */ 0227 extern int kgdb_validate_break_address(unsigned long addr); 0228 extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt); 0229 extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt); 0230 0231 /** 0232 * kgdb_arch_late - Perform any architecture specific initialization. 0233 * 0234 * This function will handle the late initialization of any 0235 * architecture specific callbacks. This is an optional function for 0236 * handling things like late initialization of hw breakpoints. The 0237 * default implementation does nothing. 0238 */ 0239 extern void kgdb_arch_late(void); 0240 0241 0242 /** 0243 * struct kgdb_arch - Describe architecture specific values. 0244 * @gdb_bpt_instr: The instruction to trigger a breakpoint. 0245 * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT. 0246 * @set_breakpoint: Allow an architecture to specify how to set a software 0247 * breakpoint. 0248 * @remove_breakpoint: Allow an architecture to specify how to remove a 0249 * software breakpoint. 0250 * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware 0251 * breakpoint. 0252 * @remove_hw_breakpoint: Allow an architecture to specify how to remove a 0253 * hardware breakpoint. 0254 * @disable_hw_break: Allow an architecture to specify how to disable 0255 * hardware breakpoints for a single cpu. 0256 * @remove_all_hw_break: Allow an architecture to specify how to remove all 0257 * hardware breakpoints. 0258 * @correct_hw_break: Allow an architecture to specify how to correct the 0259 * hardware debug registers. 0260 * @enable_nmi: Manage NMI-triggered entry to KGDB 0261 */ 0262 struct kgdb_arch { 0263 unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE]; 0264 unsigned long flags; 0265 0266 int (*set_breakpoint)(unsigned long, char *); 0267 int (*remove_breakpoint)(unsigned long, char *); 0268 int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype); 0269 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype); 0270 void (*disable_hw_break)(struct pt_regs *regs); 0271 void (*remove_all_hw_break)(void); 0272 void (*correct_hw_break)(void); 0273 0274 void (*enable_nmi)(bool on); 0275 }; 0276 0277 /** 0278 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB. 0279 * @name: Name of the I/O driver. 0280 * @read_char: Pointer to a function that will return one char. 0281 * @write_char: Pointer to a function that will write one char. 0282 * @flush: Pointer to a function that will flush any pending writes. 0283 * @init: Pointer to a function that will initialize the device. 0284 * @deinit: Pointer to a function that will deinit the device. Implies that 0285 * this I/O driver is temporary and expects to be replaced. Called when 0286 * an I/O driver is replaced or explicitly unregistered. 0287 * @pre_exception: Pointer to a function that will do any prep work for 0288 * the I/O driver. 0289 * @post_exception: Pointer to a function that will do any cleanup work 0290 * for the I/O driver. 0291 * @cons: valid if the I/O device is a console; else NULL. 0292 */ 0293 struct kgdb_io { 0294 const char *name; 0295 int (*read_char) (void); 0296 void (*write_char) (u8); 0297 void (*flush) (void); 0298 int (*init) (void); 0299 void (*deinit) (void); 0300 void (*pre_exception) (void); 0301 void (*post_exception) (void); 0302 struct console *cons; 0303 }; 0304 0305 extern const struct kgdb_arch arch_kgdb_ops; 0306 0307 extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs); 0308 0309 #ifdef CONFIG_SERIAL_KGDB_NMI 0310 extern int kgdb_register_nmi_console(void); 0311 extern int kgdb_unregister_nmi_console(void); 0312 extern bool kgdb_nmi_poll_knock(void); 0313 #else 0314 static inline int kgdb_register_nmi_console(void) { return 0; } 0315 static inline int kgdb_unregister_nmi_console(void) { return 0; } 0316 static inline bool kgdb_nmi_poll_knock(void) { return true; } 0317 #endif 0318 0319 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops); 0320 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops); 0321 extern struct kgdb_io *dbg_io_ops; 0322 0323 extern int kgdb_hex2long(char **ptr, unsigned long *long_val); 0324 extern char *kgdb_mem2hex(char *mem, char *buf, int count); 0325 extern int kgdb_hex2mem(char *buf, char *mem, int count); 0326 0327 extern int kgdb_isremovedbreak(unsigned long addr); 0328 extern int kgdb_has_hit_break(unsigned long addr); 0329 0330 extern int 0331 kgdb_handle_exception(int ex_vector, int signo, int err_code, 0332 struct pt_regs *regs); 0333 extern int kgdb_nmicallback(int cpu, void *regs); 0334 extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, 0335 atomic_t *snd_rdy); 0336 extern void gdbstub_exit(int status); 0337 0338 /* 0339 * kgdb and kprobes both use the same (kprobe) blocklist (which makes sense 0340 * given they are both typically hooked up to the same trap meaning on most 0341 * architectures one cannot be used to debug the other) 0342 * 0343 * However on architectures where kprobes is not (yet) implemented we permit 0344 * breakpoints everywhere rather than blocking everything by default. 0345 */ 0346 static inline bool kgdb_within_blocklist(unsigned long addr) 0347 { 0348 #ifdef CONFIG_KGDB_HONOUR_BLOCKLIST 0349 return within_kprobe_blacklist(addr); 0350 #else 0351 return false; 0352 #endif 0353 } 0354 0355 extern int kgdb_single_step; 0356 extern atomic_t kgdb_active; 0357 #define in_dbg_master() \ 0358 (irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active))) 0359 extern bool dbg_is_early; 0360 extern void __init dbg_late_init(void); 0361 extern void kgdb_panic(const char *msg); 0362 extern void kgdb_free_init_mem(void); 0363 #else /* ! CONFIG_KGDB */ 0364 #define in_dbg_master() (0) 0365 #define dbg_late_init() 0366 static inline void kgdb_panic(const char *msg) {} 0367 static inline void kgdb_free_init_mem(void) { } 0368 #endif /* ! CONFIG_KGDB */ 0369 #endif /* _KGDB_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |