aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Thompson <daniel.thompson@linaro.org>2016-06-16 11:51:52 -0400
committerWill Deacon <will.deacon@arm.com>2016-06-16 14:20:51 -0400
commit0d15ef677839dab8313fbb86c007c3175b638d03 (patch)
tree2f4ce061dff3ceb19bea76fee7a1266a6c2c5976
parentc56bdcac153e60d96a619a59c7981f2a78cba598 (diff)
arm64: kgdb: Match pstate size with gdbserver protocol
Current versions of gdb do not interoperate cleanly with kgdb on arm64 systems because gdb and kgdb do not use the same register description. This patch modifies kgdb to work with recent releases of gdb (>= 7.8.1). Compatibility with gdb (after the patch is applied) is as follows: gdb-7.6 and earlier Ok gdb-7.7 series Works if user provides custom target description gdb-7.8(.0) Works if user provides custom target description gdb-7.8.1 and later Ok When commit 44679a4f142b ("arm64: KGDB: Add step debugging support") was introduced it was paired with a gdb patch that made an incompatible change to the gdbserver protocol. This patch was eventually merged into the gdb sources: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=a4d9ba85ec5597a6a556afe26b712e878374b9dd The change to the protocol was mostly made to simplify big-endian support inside the kernel gdb stub. Unfortunately the gdb project released gdb-7.7.x and gdb-7.8.0 before the protocol incompatibility was identified and reversed: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bdc144174bcb11e808b4e73089b850cf9620a7ee This leaves us in a position where kgdb still uses the no-longer-used protocol; gdb-7.8.1, which restored the original behaviour, was released on 2014-10-29. I don't believe it is possible to detect/correct the protocol incompatiblity which means the kernel must take a view about which version of the gdb remote protocol is "correct". This patch takes the view that the original/current version of the protocol is correct and that version found in gdb-7.7.x and gdb-7.8.0 is anomalous. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--arch/arm64/include/asm/kgdb.h45
-rw-r--r--arch/arm64/kernel/kgdb.c14
2 files changed, 50 insertions, 9 deletions
diff --git a/arch/arm64/include/asm/kgdb.h b/arch/arm64/include/asm/kgdb.h
index f69f69c8120c..da84645525b9 100644
--- a/arch/arm64/include/asm/kgdb.h
+++ b/arch/arm64/include/asm/kgdb.h
@@ -38,25 +38,54 @@ extern int kgdb_fault_expected;
38#endif /* !__ASSEMBLY__ */ 38#endif /* !__ASSEMBLY__ */
39 39
40/* 40/*
41 * gdb is expecting the following registers layout. 41 * gdb remote procotol (well most versions of it) expects the following
42 * register layout.
42 * 43 *
43 * General purpose regs: 44 * General purpose regs:
44 * r0-r30: 64 bit 45 * r0-r30: 64 bit
45 * sp,pc : 64 bit 46 * sp,pc : 64 bit
46 * pstate : 64 bit 47 * pstate : 32 bit
47 * Total: 34 48 * Total: 33 + 1
48 * FPU regs: 49 * FPU regs:
49 * f0-f31: 128 bit 50 * f0-f31: 128 bit
50 * Total: 32
51 * Extra regs
52 * fpsr & fpcr: 32 bit 51 * fpsr & fpcr: 32 bit
53 * Total: 2 52 * Total: 32 + 2
54 * 53 *
54 * To expand a little on the "most versions of it"... when the gdb remote
55 * protocol for AArch64 was developed it depended on a statement in the
56 * Architecture Reference Manual that claimed "SPSR_ELx is a 32-bit register".
57 * and, as a result, allocated only 32-bits for the PSTATE in the remote
58 * protocol. In fact this statement is still present in ARM DDI 0487A.i.
59 *
60 * Unfortunately "is a 32-bit register" has a very special meaning for
61 * system registers. It means that "the upper bits, bits[63:32], are
62 * RES0.". RES0 is heavily used in the ARM architecture documents as a
63 * way to leave space for future architecture changes. So to translate a
64 * little for people who don't spend their spare time reading ARM architecture
65 * manuals, what "is a 32-bit register" actually means in this context is
66 * "is a 64-bit register but one with no meaning allocated to any of the
67 * upper 32-bits... *yet*".
68 *
69 * Perhaps then we should not be surprised that this has led to some
70 * confusion. Specifically a patch, influenced by the above translation,
71 * that extended PSTATE to 64-bit was accepted into gdb-7.7 but the patch
72 * was reverted in gdb-7.8.1 and all later releases, when this was
73 * discovered to be an undocumented protocol change.
74 *
75 * So... it is *not* wrong for us to only allocate 32-bits to PSTATE
76 * here even though the kernel itself allocates 64-bits for the same
77 * state. That is because this bit of code tells the kernel how the gdb
78 * remote protocol (well most versions of it) describes the register state.
79 *
80 * Note that if you are using one of the versions of gdb that supports
81 * the gdb-7.7 version of the protocol you cannot use kgdb directly
82 * without providing a custom register description (gdb can load new
83 * protocol descriptions at runtime).
55 */ 84 */
56 85
57#define _GP_REGS 34 86#define _GP_REGS 33
58#define _FP_REGS 32 87#define _FP_REGS 32
59#define _EXTRA_REGS 2 88#define _EXTRA_REGS 3
60/* 89/*
61 * general purpose registers size in bytes. 90 * general purpose registers size in bytes.
62 * pstate is only 4 bytes. subtract 4 bytes 91 * pstate is only 4 bytes. subtract 4 bytes
diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c
index b67531a13136..b5f063e5eff7 100644
--- a/arch/arm64/kernel/kgdb.c
+++ b/arch/arm64/kernel/kgdb.c
@@ -58,7 +58,17 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
58 { "x30", 8, offsetof(struct pt_regs, regs[30])}, 58 { "x30", 8, offsetof(struct pt_regs, regs[30])},
59 { "sp", 8, offsetof(struct pt_regs, sp)}, 59 { "sp", 8, offsetof(struct pt_regs, sp)},
60 { "pc", 8, offsetof(struct pt_regs, pc)}, 60 { "pc", 8, offsetof(struct pt_regs, pc)},
61 { "pstate", 8, offsetof(struct pt_regs, pstate)}, 61 /*
62 * struct pt_regs thinks PSTATE is 64-bits wide but gdb remote
63 * protocol disagrees. Therefore we must extract only the lower
64 * 32-bits. Look for the big comment in asm/kgdb.h for more
65 * detail.
66 */
67 { "pstate", 4, offsetof(struct pt_regs, pstate)
68#ifdef CONFIG_CPU_BIG_ENDIAN
69 + 4
70#endif
71 },
62 { "v0", 16, -1 }, 72 { "v0", 16, -1 },
63 { "v1", 16, -1 }, 73 { "v1", 16, -1 },
64 { "v2", 16, -1 }, 74 { "v2", 16, -1 },
@@ -128,6 +138,8 @@ sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
128 memset((char *)gdb_regs, 0, NUMREGBYTES); 138 memset((char *)gdb_regs, 0, NUMREGBYTES);
129 thread_regs = task_pt_regs(task); 139 thread_regs = task_pt_regs(task);
130 memcpy((void *)gdb_regs, (void *)thread_regs->regs, GP_REG_BYTES); 140 memcpy((void *)gdb_regs, (void *)thread_regs->regs, GP_REG_BYTES);
141 /* Special case for PSTATE (check comments in asm/kgdb.h for details) */
142 dbg_get_reg(33, gdb_regs + GP_REG_BYTES, thread_regs);
131} 143}
132 144
133void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) 145void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)