microblaze: Add KGDB support
A message that is not in the archive (sent off-list or not yet received): [email protected]
Michal Simek
maintainerPATCH 1/1 microblaze: Add KGDB support
Kgdb uses brki r16, 0x18 instruction to call
low level _debug_exception function which save current state to pt_regs and call microblaze_kgdb_break function. _debug_exception should be called only from the kernel space. User space calling is not supported because user application debugging uses different handling.
pt_regs_to_gdb_regs loads additional special registers which can't be changed
* Enable KGDB in Kconfig
* Remove ancient not-tested KGDB support
* Remove ancient _debug_exception code from entry.S
Only MMU KGDB support is supported.
--- arch/microblaze/Kconfig | 1 + arch/microblaze/include/asm/exceptions.h | 16 -- arch/microblaze/include/asm/kgdb.h | 28 ++++ arch/microblaze/kernel/Makefile | 1 + arch/microblaze/kernel/entry.S | 226 ++++++++++++------------------ arch/microblaze/kernel/exceptions.c | 1 - arch/microblaze/kernel/kgdb.c | 149 ++++++++++++++++++++ arch/microblaze/mm/fault.c | 15 -- 8 files changed, 272 insertions(+), 165 deletions(-) create mode 100644 arch/microblaze/include/asm/kgdb.h create mode 100644 arch/microblaze/kernel/kgdb.c
arch/microblaze/Kconfig +1 -0
@@ -14,6 +14,7 @@ config MICROBLAZE select USB_ARCH_HAS_EHCI select ARCH_WANT_OPTIONAL_GPIOLIB select HAVE_OPROFILE + select HAVE_ARCH_KGDB select HAVE_DMA_ATTRS select HAVE_DMA_API_DEBUG select TRACING_SUPPORT
arch/microblaze/include/asm/exceptions.h +0 -16
@@ -69,22 +69,6 @@ asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,void die (const char *str,struct pt_regs *fp,long err);void _exception (int signr,struct pt_regs *regs,int code,unsigned long addr); -#if defined(CONFIG_KGDB ) -void (*debugger)(struct pt_regs *regs); -int (*debugger_bpt)(struct pt_regs *regs); -int (*debugger_sstep)(struct pt_regs *regs); -int (*debugger_iabr_match)(struct pt_regs *regs); -int (*debugger_dabr_match)(struct pt_regs *regs); -void (*debugger_fault_handler)(struct pt_regs *regs); -#else -#define debugger (regs) do { } while (0) -#define debugger_bpt (regs) 0 -#define debugger_sstep (regs) 0 -#define debugger_iabr_match (regs) 0 -#define debugger_dabr_match (regs) 0 -#define debugger_fault_handler ((void (*)(struct pt_regs *))0) -#endif -#endif /*__ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* _ASM_MICROBLAZE_EXCEPTIONS_H */
arch/microblaze/include/asm/kgdb.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifdef __KERNEL__ +#ifndef __MICROBLAZE_KGDB_H__ +#define __MICROBLAZE_KGDB_H__ + +#ifndef __ASSEMBLY__ + +#define CACHE_FLUSH_IS_SAFE 1 +#define BUFMAX 2048 + +/* +* 32 32-bit general purpose registers (r0-r31) +* 6 32-bit special registers (pc, msr, ear, esr, fsr, btr) +* 12 32-bit PVR +* 7 32-bit MMU Regs (redr, rpid, rzpr, rtlbx, rtlbsx, rtlblo, rtlbhi) +* ------ +* 57 registers +*/ +#define NUMREGBYTES (57 * 4) + +#define BREAK_INSTR_SIZE 4 +static inline void arch_kgdb_breakpoint (void ) +{ + __asm__ __volatile__("brki r16, 0x18;" ); +} + +#endif /* __ASSEMBLY__ */ +#endif /* __MICROBLAZE_KGDB_H__ */ +#endif /* __KERNEL__ */
arch/microblaze/kernel/Makefile +1 -0
@@ -28,5 +28,6 @@ obj-$(CONFIG_MODULES) += microblaze_ksyms.o module.o obj-$(CONFIG_MMU) += misc.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o mcount.o +obj-$(CONFIG_KGDB) += kgdb.o obj-y += entry$(MMU).o
arch/microblaze/kernel/entry.S +93 -133
260 lines not on this page · raw message
arch/microblaze/kernel/exceptions.c +0 -1
@@ -53,7 +53,6 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)siginfo_t info;if (kernel_mode (regs)) { -debugger (regs);die ("Exception in kernel mode" , regs, signr); } info.si_signo = signr;
arch/microblaze/kernel/kgdb.c new file +149 -0
149 lines not on this page · raw message
arch/microblaze/mm/fault.c +0 -15
@@ -37,10 +37,6 @@#include <linux/uaccess.h> #include <asm/exceptions.h> -#if defined(CONFIG_KGDB ) -int debugger_kernel_faults =1 ; -#endif -static unsigned long pte_misses;/* updated by do_page_fault() */ static unsigned long pte_errors;/* updated by do_page_fault() */
@@ -81,10 +77,6 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig) }/* kernel has accessed a bad area */ -#if defined(CONFIG_KGDB ) -if (debugger_kernel_faults) -debugger (regs); -#endif die ("kernel access of bad area" , regs, sig); }
@@ -115,13 +107,6 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,if ((error_code &0x13 ) ==0x13 || (error_code &0x11 ) ==0x11 ) is_write =0 ; -#if defined(CONFIG_KGDB ) -if (debugger_fault_handler && regs->trap ==0x300 ) { -debugger_fault_handler (regs); -return ; - } -#endif /* CONFIG_KGDB */ -if (unlikely (in_atomic () || !mm)) {if (kernel_mode (regs)) goto bad_area_nosemaphore;
Signature · 1 line
1.5.5.6
Quoted 7 lines · Michal Simek
Kgdb uses brki r16,
0x18instruction to call
low level_debug_exceptionfunction which save current state topt_regsand callmicroblaze_kgdb_breakfunction._debug_exceptionshould be called only from the kernel space. User space calling is not supported because user application debugging uses different handling.
Quoted 10 lines
pt_regs_to_gdb_regsloads additional special registers which can't be changed* Enable KGDB in
Kconfig
* Remove ancient not-tested KGDB support
* Remove ancient_debug_exceptioncode fromentry.SOnly MMU KGDB support is supported.
There is only one place I saw a problem and if you fix it, you can add:
Quoted 13 lines
arch/microblaze/kernel/kgdb.c new file +12
-0+ +int kgdb_arch_handle_exception (int vector,int signo,int err_code, +char *remcom_in_buffer,char *remcom_out_buffer, +struct pt_regs *regs) +{ +char *ptr; +unsigned long address; +int cpu =smp_processor_id (); + +switch (remcom_in_buffer[0 ]) { +case 's' : +case 'c' :
arch/microblaze/kernel/kgdb.c line 129
Quoted 10 lines
arch/microblaze/kernel/kgdb.c new file +10
-0+/* handle the optional parameter */ + ptr = &remcom_in_buffer[1 ]; +if (kgdb_hex2long (&ptr, &address)) + regs->pc = address; +atomic_set (&kgdb_cpu_doing_single_step,-1 ); +if (remcom_in_buffer[0 ] =='s' ) +atomic_set (&kgdb_cpu_doing_single_step, cpu); + +return 0 ; + }
As far as I can see there is no code in the arch specific portion to make use of single stepping. It needs to be implemented using hardware assist, or a software breakpoint strategy, else you simply omit the 's' case from statement so that kdb will not enable single stepping at run time.
Example:
switch (remcom_in_buffer[0]) {
case 'c':
/* handle the optional parameter */
ptr = &remcom_in_buffer[1];
if (kgdb_hex2long(&ptr, &address))
regs->pc = address;
return 0;
}You can also remove the kgdb_cpu_doing_single_step operations because this arch does not currently implement the kgdb single stepping.
Cheers,
Jason.
Michal Simek
maintainerQuoted 64 lines · Jason Wessel
Quoted 7 lines · Michal Simek
Kgdb uses brki r16,
0x18instruction to call
low level_debug_exceptionfunction which save current state topt_regsand callmicroblaze_kgdb_breakfunction._debug_exceptionshould be called only from the kernel space. User space calling is not supported because user application debugging uses different handling.Quoted 10 lines
pt_regs_to_gdb_regsloads additional special registers which can't be changed* Enable KGDB in
Kconfig
* Remove ancient not-tested KGDB support
* Remove ancient_debug_exceptioncode fromentry.SOnly MMU KGDB support is supported.
There is only one place I saw a problem and if you fix it, you can add:
Acked-by Jason Wessel <[email protected]>Quoted 13 lines
arch/microblaze/kernel/kgdb.c new file +12
-0+ +int kgdb_arch_handle_exception (int vector,int signo,int err_code, +char *remcom_in_buffer,char *remcom_out_buffer, +struct pt_regs *regs) +{ +char *ptr; +unsigned long address; +int cpu =smp_processor_id (); + +switch (remcom_in_buffer[0 ]) { +case 's' : +case 'c' :arch/microblaze/kernel/kgdb.c line 129
Quoted 10 lines
arch/microblaze/kernel/kgdb.c new file +10
-0+/* handle the optional parameter */ + ptr = &remcom_in_buffer[1 ]; +if (kgdb_hex2long (&ptr, &address)) + regs->pc = address; +atomic_set (&kgdb_cpu_doing_single_step,-1 ); +if (remcom_in_buffer[0 ] =='s' ) +atomic_set (&kgdb_cpu_doing_single_step, cpu); + +return 0 ; + }As far as I can see there is no code in the arch specific portion to make use of single stepping. It needs to be implemented using hardware assist, or a software breakpoint strategy, else you simply omit the 's' case from statement so that kdb will not enable single stepping at run time.
Example:
switch (remcom_in_buffer[0]) { case 'c': /* handle the optional parameter */ ptr = &remcom_in_buffer[1]; if (kgdb_hex2long(&ptr, &address)) regs->pc = address; return 0; }
Quoted 2 lines
You can also remove the
kgdb_cpu_doing_single_stepoperations because this arch does not currently implement the kgdb single stepping.
Ok. I will remove it. I copied this part of the code from somewhere.
gdb handle single stepping and always send Z0 packet to the next instruction or two breakpoints for branches.
Thanks,
Michal
Quoted 4 lines
Cheers,
Jason.
Signature · 4 lines
Michal Simek, Ing. (M.Eng) w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/ Microblaze U-BOOT custodian