1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * AArch64 KGDB support
4 *
5 * Based on arch/arm/include/kgdb.h
6 *
7 * Copyright (C) 2013 Cavium Inc.
8 * Author: Vijaya Kumar K <vijaya.kumar@caviumnetworks.com>
9 */
10
11 #ifndef __ARM_KGDB_H
12 #define __ARM_KGDB_H
13
14 #include <linux/ptrace.h>
15 #include <asm/debug-monitors.h>
16
17 #ifndef __ASSEMBLY__
18
arch_kgdb_breakpoint(void)19 static inline void arch_kgdb_breakpoint(void)
20 {
21 asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM));
22 }
23
24 extern void kgdb_handle_bus_error(void);
25 extern int kgdb_fault_expected;
26
27 int kgdb_brk_handler(struct pt_regs *regs, unsigned long esr);
28 int kgdb_compiled_brk_handler(struct pt_regs *regs, unsigned long esr);
29 #ifdef CONFIG_KGDB
30 int kgdb_single_step_handler(struct pt_regs *regs, unsigned long esr);
31 #else
kgdb_single_step_handler(struct pt_regs * regs,unsigned long esr)32 static inline int kgdb_single_step_handler(struct pt_regs *regs,
33 unsigned long esr)
34 {
35 return DBG_HOOK_ERROR;
36 }
37 #endif
38
39 #endif /* !__ASSEMBLY__ */
40
41 /*
42 * gdb remote procotol (well most versions of it) expects the following
43 * register layout.
44 *
45 * General purpose regs:
46 * r0-r30: 64 bit
47 * sp,pc : 64 bit
48 * pstate : 32 bit
49 * Total: 33 + 1
50 * FPU regs:
51 * f0-f31: 128 bit
52 * fpsr & fpcr: 32 bit
53 * Total: 32 + 2
54 *
55 * To expand a little on the "most versions of it"... when the gdb remote
56 * protocol for AArch64 was developed it depended on a statement in the
57 * Architecture Reference Manual that claimed "SPSR_ELx is a 32-bit register".
58 * and, as a result, allocated only 32-bits for the PSTATE in the remote
59 * protocol. In fact this statement is still present in ARM DDI 0487A.i.
60 *
61 * Unfortunately "is a 32-bit register" has a very special meaning for
62 * system registers. It means that "the upper bits, bits[63:32], are
63 * RES0.". RES0 is heavily used in the ARM architecture documents as a
64 * way to leave space for future architecture changes. So to translate a
65 * little for people who don't spend their spare time reading ARM architecture
66 * manuals, what "is a 32-bit register" actually means in this context is
67 * "is a 64-bit register but one with no meaning allocated to any of the
68 * upper 32-bits... *yet*".
69 *
70 * Perhaps then we should not be surprised that this has led to some
71 * confusion. Specifically a patch, influenced by the above translation,
72 * that extended PSTATE to 64-bit was accepted into gdb-7.7 but the patch
73 * was reverted in gdb-7.8.1 and all later releases, when this was
74 * discovered to be an undocumented protocol change.
75 *
76 * So... it is *not* wrong for us to only allocate 32-bits to PSTATE
77 * here even though the kernel itself allocates 64-bits for the same
78 * state. That is because this bit of code tells the kernel how the gdb
79 * remote protocol (well most versions of it) describes the register state.
80 *
81 * Note that if you are using one of the versions of gdb that supports
82 * the gdb-7.7 version of the protocol you cannot use kgdb directly
83 * without providing a custom register description (gdb can load new
84 * protocol descriptions at runtime).
85 */
86
87 #define _GP_REGS 33
88 #define _FP_REGS 32
89 #define _EXTRA_REGS 3
90 /*
91 * general purpose registers size in bytes.
92 * pstate is only 4 bytes. subtract 4 bytes
93 */
94 #define GP_REG_BYTES (_GP_REGS * 8)
95 #define DBG_MAX_REG_NUM (_GP_REGS + _FP_REGS + _EXTRA_REGS)
96
97 /*
98 * Size of I/O buffer for gdb packet.
99 * considering to hold all register contents, size is set
100 */
101
102 #define BUFMAX 2048
103
104 /*
105 * Number of bytes required for gdb_regs buffer.
106 * _GP_REGS: 8 bytes, _FP_REGS: 16 bytes and _EXTRA_REGS: 4 bytes each
107 * GDB fails to connect for size beyond this with error
108 * "'g' packet reply is too long"
109 */
110
111 #define NUMREGBYTES ((_GP_REGS * 8) + (_FP_REGS * 16) + \
112 (_EXTRA_REGS * 4))
113
114 #endif /* __ASM_KGDB_H */
115