xref: /linux/arch/loongarch/include/asm/kgdb.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2023 Loongson Technology Corporation Limited
4  */
5 
6 #ifndef _ASM_LOONGARCH_KGDB_H
7 #define _ASM_LOONGARCH_KGDB_H
8 
9 #define GDB_SIZEOF_REG		sizeof(u64)
10 
11 /* gdb remote procotol expects the following register layout. */
12 
13 /*
14  * General purpose registers:
15  *     r0-r31: 64 bit
16  *     orig_a0: 64 bit
17  *     pc : 64 bit
18  *     csr_badvaddr: 64 bit
19  */
20 #define DBG_PT_REGS_BASE	0
21 #define DBG_PT_REGS_NUM		35
22 #define DBG_PT_REGS_END		(DBG_PT_REGS_BASE + DBG_PT_REGS_NUM - 1)
23 
24 /*
25  * Floating point registers:
26  *     f0-f31: 64 bit
27  */
28 #define DBG_FPR_BASE		(DBG_PT_REGS_END + 1)
29 #define DBG_FPR_NUM		32
30 #define DBG_FPR_END		(DBG_FPR_BASE + DBG_FPR_NUM - 1)
31 
32 /*
33  * Condition Flag registers:
34  *     fcc0-fcc8: 8 bit
35  */
36 #define DBG_FCC_BASE		(DBG_FPR_END + 1)
37 #define DBG_FCC_NUM		8
38 #define DBG_FCC_END		(DBG_FCC_BASE + DBG_FCC_NUM - 1)
39 
40 /*
41  * Floating-point Control and Status registers:
42  *     fcsr: 32 bit
43  */
44 #define DBG_FCSR_NUM		1
45 #define DBG_FCSR		(DBG_FCC_END + 1)
46 
47 #define DBG_MAX_REG_NUM		(DBG_FCSR + 1)
48 
49 /*
50  * Size of I/O buffer for gdb packet.
51  * considering to hold all register contents, size is set
52  */
53 #define BUFMAX			2048
54 
55 /*
56  * Number of bytes required for gdb_regs buffer.
57  * PT_REGS and FPR: 8 bytes; FCSR: 4 bytes; FCC: 1 bytes.
58  * GDB fails to connect for size beyond this with error
59  * "'g' packet reply is too long"
60  */
61 #define NUMREGBYTES		((DBG_PT_REGS_NUM + DBG_FPR_NUM) * GDB_SIZEOF_REG + DBG_FCC_NUM * 1 + DBG_FCSR_NUM * 4)
62 
63 #define BREAK_INSTR_SIZE	4
64 #define CACHE_FLUSH_IS_SAFE	0
65 
66 /* Register numbers of various important registers. */
67 enum dbg_loongarch_regnum {
68 	DBG_LOONGARCH_ZERO = 0,
69 	DBG_LOONGARCH_RA,
70 	DBG_LOONGARCH_TP,
71 	DBG_LOONGARCH_SP,
72 	DBG_LOONGARCH_A0,
73 	DBG_LOONGARCH_FP = 22,
74 	DBG_LOONGARCH_S0,
75 	DBG_LOONGARCH_S1,
76 	DBG_LOONGARCH_S2,
77 	DBG_LOONGARCH_S3,
78 	DBG_LOONGARCH_S4,
79 	DBG_LOONGARCH_S5,
80 	DBG_LOONGARCH_S6,
81 	DBG_LOONGARCH_S7,
82 	DBG_LOONGARCH_S8,
83 	DBG_LOONGARCH_ORIG_A0,
84 	DBG_LOONGARCH_PC,
85 	DBG_LOONGARCH_BADV
86 };
87 
88 void kgdb_breakinst(void);
89 void arch_kgdb_breakpoint(void);
90 
91 #ifdef CONFIG_KGDB
92 bool kgdb_breakpoint_handler(struct pt_regs *regs);
93 #else /* !CONFIG_KGDB */
94 static inline bool kgdb_breakpoint_handler(struct pt_regs *regs) { return false; }
95 #endif /* CONFIG_KGDB */
96 
97 #endif /* __ASM_KGDB_H_ */
98