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