162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * ARM KGDB support
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Author: Deepak Saxena <dsaxena@mvista.com>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2002 MontaVista Software Inc.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __ARM_KGDB_H__
1262306a36Sopenharmony_ci#define __ARM_KGDB_H__
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/ptrace.h>
1562306a36Sopenharmony_ci#include <asm/opcodes.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/*
1862306a36Sopenharmony_ci * GDB assumes that we're a user process being debugged, so
1962306a36Sopenharmony_ci * it will send us an SWI command to write into memory as the
2062306a36Sopenharmony_ci * debug trap. When an SWI occurs, the next instruction addr is
2162306a36Sopenharmony_ci * placed into R14_svc before jumping to the vector trap.
2262306a36Sopenharmony_ci * This doesn't work for kernel debugging as we are already in SVC
2362306a36Sopenharmony_ci * we would loose the kernel's LR, which is a bad thing. This
2462306a36Sopenharmony_ci * is  bad thing.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * By doing this as an undefined instruction trap, we force a mode
2762306a36Sopenharmony_ci * switch from SVC to UND mode, allowing us to save full kernel state.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * We also define a KGDB_COMPILED_BREAK which can be used to compile
3062306a36Sopenharmony_ci * in breakpoints. This is important for things like sysrq-G and for
3162306a36Sopenharmony_ci * the initial breakpoint from trap_init().
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * Note to ARM HW designers: Add real trap support like SH && PPC to
3462306a36Sopenharmony_ci * make our lives much much simpler. :)
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_ci#define BREAK_INSTR_SIZE	4
3762306a36Sopenharmony_ci#define GDB_BREAKINST		0xef9f0001
3862306a36Sopenharmony_ci#define KGDB_BREAKINST		0xe7ffdefe
3962306a36Sopenharmony_ci#define KGDB_COMPILED_BREAK	0xe7ffdeff
4062306a36Sopenharmony_ci#define CACHE_FLUSH_IS_SAFE	1
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#ifndef	__ASSEMBLY__
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistatic inline void arch_kgdb_breakpoint(void)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	asm(__inst_arm(0xe7ffdeff));
4762306a36Sopenharmony_ci}
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ciextern void kgdb_handle_bus_error(void);
5062306a36Sopenharmony_ciextern int kgdb_fault_expected;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/*
5562306a36Sopenharmony_ci * From Kevin Hilman:
5662306a36Sopenharmony_ci *
5762306a36Sopenharmony_ci * gdb is expecting the following registers layout.
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci * r0-r15: 1 long word each
6062306a36Sopenharmony_ci * f0-f7:  unused, 3 long words each !!
6162306a36Sopenharmony_ci * fps:    unused, 1 long word
6262306a36Sopenharmony_ci * cpsr:   1 long word
6362306a36Sopenharmony_ci *
6462306a36Sopenharmony_ci * Even though f0-f7 and fps are not used, they need to be
6562306a36Sopenharmony_ci * present in the registers sent for correct processing in
6662306a36Sopenharmony_ci * the host-side gdb.
6762306a36Sopenharmony_ci *
6862306a36Sopenharmony_ci * In particular, it is crucial that CPSR is in the right place,
6962306a36Sopenharmony_ci * otherwise gdb will not be able to correctly interpret stepping over
7062306a36Sopenharmony_ci * conditional branches.
7162306a36Sopenharmony_ci */
7262306a36Sopenharmony_ci#define _GP_REGS		16
7362306a36Sopenharmony_ci#define _FP_REGS		8
7462306a36Sopenharmony_ci#define _EXTRA_REGS		2
7562306a36Sopenharmony_ci#define GDB_MAX_REGS		(_GP_REGS + (_FP_REGS * 3) + _EXTRA_REGS)
7662306a36Sopenharmony_ci#define DBG_MAX_REG_NUM		(_GP_REGS + _FP_REGS + _EXTRA_REGS)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define KGDB_MAX_NO_CPUS	1
7962306a36Sopenharmony_ci#define BUFMAX			400
8062306a36Sopenharmony_ci#define NUMREGBYTES		(GDB_MAX_REGS << 2)
8162306a36Sopenharmony_ci#define NUMCRITREGBYTES		(32 << 2)
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define _R0			0
8462306a36Sopenharmony_ci#define _R1			1
8562306a36Sopenharmony_ci#define _R2			2
8662306a36Sopenharmony_ci#define _R3			3
8762306a36Sopenharmony_ci#define _R4			4
8862306a36Sopenharmony_ci#define _R5			5
8962306a36Sopenharmony_ci#define _R6			6
9062306a36Sopenharmony_ci#define _R7			7
9162306a36Sopenharmony_ci#define _R8			8
9262306a36Sopenharmony_ci#define _R9			9
9362306a36Sopenharmony_ci#define _R10			10
9462306a36Sopenharmony_ci#define _FP			11
9562306a36Sopenharmony_ci#define _IP			12
9662306a36Sopenharmony_ci#define _SPT			13
9762306a36Sopenharmony_ci#define _LR			14
9862306a36Sopenharmony_ci#define _PC			15
9962306a36Sopenharmony_ci#define _CPSR			(GDB_MAX_REGS - 1)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/*
10262306a36Sopenharmony_ci * So that we can denote the end of a frame for tracing,
10362306a36Sopenharmony_ci * in the simple case:
10462306a36Sopenharmony_ci */
10562306a36Sopenharmony_ci#define CFI_END_FRAME(func)	__CFI_END_FRAME(_PC, _SPT, func)
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#endif /* __ASM_KGDB_H__ */
108