Skip to content

Commit bcf5763

Browse files
Vijaya Kumar Kctmarinas
authored andcommitted
arm64: KGDB: Add Basic KGDB support
Add KGDB debug support for kernel debugging. With this patch, basic KGDB debugging is possible.GDB register layout is updated and GDB tool can establish connection with target and can set/clear breakpoints. Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@caviumnetworks.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent c7db4ff commit bcf5763

File tree

4 files changed

+420
-0
lines changed

4 files changed

+420
-0
lines changed

arch/arm64/include/asm/debug-monitors.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,53 @@
2626
#define DBG_ESR_EVT_HWWP 0x2
2727
#define DBG_ESR_EVT_BRK 0x6
2828

29+
/*
30+
* Break point instruction encoding
31+
*/
32+
#define BREAK_INSTR_SIZE 4
33+
34+
/*
35+
* ESR values expected for dynamic and compile time BRK instruction
36+
*/
37+
#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xfffff))
38+
39+
/*
40+
* #imm16 values used for BRK instruction generation
41+
* Allowed values for kgbd are 0x400 - 0x7ff
42+
* 0x400: for dynamic BRK instruction
43+
* 0x401: for compile time BRK instruction
44+
*/
45+
#define KGDB_DYN_DGB_BRK_IMM 0x400
46+
#define KDBG_COMPILED_DBG_BRK_IMM 0x401
47+
48+
/*
49+
* BRK instruction encoding
50+
* The #imm16 value should be placed at bits[20:5] within BRK ins
51+
*/
52+
#define AARCH64_BREAK_MON 0xd4200000
53+
54+
/*
55+
* Extract byte from BRK instruction
56+
*/
57+
#define KGDB_DYN_DGB_BRK_INS_BYTE(x) \
58+
((((AARCH64_BREAK_MON) & 0xffe0001f) >> (x * 8)) & 0xff)
59+
60+
/*
61+
* Extract byte from BRK #imm16
62+
*/
63+
#define KGBD_DYN_DGB_BRK_IMM_BYTE(x) \
64+
(((((KGDB_DYN_DGB_BRK_IMM) & 0xffff) << 5) >> (x * 8)) & 0xff)
65+
66+
#define KGDB_DYN_DGB_BRK_BYTE(x) \
67+
(KGDB_DYN_DGB_BRK_INS_BYTE(x) | KGBD_DYN_DGB_BRK_IMM_BYTE(x))
68+
69+
#define KGDB_DYN_BRK_INS_BYTE0 KGDB_DYN_DGB_BRK_BYTE(0)
70+
#define KGDB_DYN_BRK_INS_BYTE1 KGDB_DYN_DGB_BRK_BYTE(1)
71+
#define KGDB_DYN_BRK_INS_BYTE2 KGDB_DYN_DGB_BRK_BYTE(2)
72+
#define KGDB_DYN_BRK_INS_BYTE3 KGDB_DYN_DGB_BRK_BYTE(3)
73+
74+
#define CACHE_FLUSH_IS_SAFE 1
75+
2976
enum debug_el {
3077
DBG_ACTIVE_EL0 = 0,
3178
DBG_ACTIVE_EL1,

arch/arm64/include/asm/kgdb.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* AArch64 KGDB support
3+
*
4+
* Based on arch/arm/include/kgdb.h
5+
*
6+
* Copyright (C) 2013 Cavium Inc.
7+
* Author: Vijaya Kumar K <vijaya.kumar@caviumnetworks.com>
8+
*
9+
* This program is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License version 2 as
11+
* published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#ifndef __ARM_KGDB_H
23+
#define __ARM_KGDB_H
24+
25+
#include <linux/ptrace.h>
26+
#include <asm/debug-monitors.h>
27+
28+
#ifndef __ASSEMBLY__
29+
30+
static inline void arch_kgdb_breakpoint(void)
31+
{
32+
asm ("brk %0" : : "I" (KDBG_COMPILED_DBG_BRK_IMM));
33+
}
34+
35+
extern void kgdb_handle_bus_error(void);
36+
extern int kgdb_fault_expected;
37+
38+
#endif /* !__ASSEMBLY__ */
39+
40+
/*
41+
* gdb is expecting the following registers layout.
42+
*
43+
* General purpose regs:
44+
* r0-r30: 64 bit
45+
* sp,pc : 64 bit
46+
* pstate : 64 bit
47+
* Total: 34
48+
* FPU regs:
49+
* f0-f31: 128 bit
50+
* Total: 32
51+
* Extra regs
52+
* fpsr & fpcr: 32 bit
53+
* Total: 2
54+
*
55+
*/
56+
57+
#define _GP_REGS 34
58+
#define _FP_REGS 32
59+
#define _EXTRA_REGS 2
60+
/*
61+
* general purpose registers size in bytes.
62+
* pstate is only 4 bytes. subtract 4 bytes
63+
*/
64+
#define GP_REG_BYTES (_GP_REGS * 8)
65+
#define DBG_MAX_REG_NUM (_GP_REGS + _FP_REGS + _EXTRA_REGS)
66+
67+
/*
68+
* Size of I/O buffer for gdb packet.
69+
* considering to hold all register contents, size is set
70+
*/
71+
72+
#define BUFMAX 2048
73+
74+
/*
75+
* Number of bytes required for gdb_regs buffer.
76+
* _GP_REGS: 8 bytes, _FP_REGS: 16 bytes and _EXTRA_REGS: 4 bytes each
77+
* GDB fails to connect for size beyond this with error
78+
* "'g' packet reply is too long"
79+
*/
80+
81+
#define NUMREGBYTES ((_GP_REGS * 8) + (_FP_REGS * 16) + \
82+
(_EXTRA_REGS * 4))
83+
84+
#endif /* __ASM_KGDB_H */

arch/arm64/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o
2020
arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
2121
arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o
2222
arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
23+
arm64-obj-$(CONFIG_KGDB) += kgdb.o
2324

2425
obj-y += $(arm64-obj-y) vdso/
2526
obj-m += $(arm64-obj-m)

0 commit comments

Comments
 (0)