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