18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ARM KGDB support
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Author: Deepak Saxena <dsaxena@mvista.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2002 MontaVista Software Inc.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __ARM_KGDB_H__
128c2ecf20Sopenharmony_ci#define __ARM_KGDB_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
158c2ecf20Sopenharmony_ci#include <asm/opcodes.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * GDB assumes that we're a user process being debugged, so
198c2ecf20Sopenharmony_ci * it will send us an SWI command to write into memory as the
208c2ecf20Sopenharmony_ci * debug trap. When an SWI occurs, the next instruction addr is
218c2ecf20Sopenharmony_ci * placed into R14_svc before jumping to the vector trap.
228c2ecf20Sopenharmony_ci * This doesn't work for kernel debugging as we are already in SVC
238c2ecf20Sopenharmony_ci * we would loose the kernel's LR, which is a bad thing. This
248c2ecf20Sopenharmony_ci * is  bad thing.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * By doing this as an undefined instruction trap, we force a mode
278c2ecf20Sopenharmony_ci * switch from SVC to UND mode, allowing us to save full kernel state.
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * We also define a KGDB_COMPILED_BREAK which can be used to compile
308c2ecf20Sopenharmony_ci * in breakpoints. This is important for things like sysrq-G and for
318c2ecf20Sopenharmony_ci * the initial breakpoint from trap_init().
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci * Note to ARM HW designers: Add real trap support like SH && PPC to
348c2ecf20Sopenharmony_ci * make our lives much much simpler. :)
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci#define BREAK_INSTR_SIZE	4
378c2ecf20Sopenharmony_ci#define GDB_BREAKINST		0xef9f0001
388c2ecf20Sopenharmony_ci#define KGDB_BREAKINST		0xe7ffdefe
398c2ecf20Sopenharmony_ci#define KGDB_COMPILED_BREAK	0xe7ffdeff
408c2ecf20Sopenharmony_ci#define CACHE_FLUSH_IS_SAFE	1
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#ifndef	__ASSEMBLY__
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline void arch_kgdb_breakpoint(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	asm(__inst_arm(0xe7ffdeff));
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciextern void kgdb_handle_bus_error(void);
508c2ecf20Sopenharmony_ciextern int kgdb_fault_expected;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/*
558c2ecf20Sopenharmony_ci * From Kevin Hilman:
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * gdb is expecting the following registers layout.
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * r0-r15: 1 long word each
608c2ecf20Sopenharmony_ci * f0-f7:  unused, 3 long words each !!
618c2ecf20Sopenharmony_ci * fps:    unused, 1 long word
628c2ecf20Sopenharmony_ci * cpsr:   1 long word
638c2ecf20Sopenharmony_ci *
648c2ecf20Sopenharmony_ci * Even though f0-f7 and fps are not used, they need to be
658c2ecf20Sopenharmony_ci * present in the registers sent for correct processing in
668c2ecf20Sopenharmony_ci * the host-side gdb.
678c2ecf20Sopenharmony_ci *
688c2ecf20Sopenharmony_ci * In particular, it is crucial that CPSR is in the right place,
698c2ecf20Sopenharmony_ci * otherwise gdb will not be able to correctly interpret stepping over
708c2ecf20Sopenharmony_ci * conditional branches.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_ci#define _GP_REGS		16
738c2ecf20Sopenharmony_ci#define _FP_REGS		8
748c2ecf20Sopenharmony_ci#define _EXTRA_REGS		2
758c2ecf20Sopenharmony_ci#define GDB_MAX_REGS		(_GP_REGS + (_FP_REGS * 3) + _EXTRA_REGS)
768c2ecf20Sopenharmony_ci#define DBG_MAX_REG_NUM		(_GP_REGS + _FP_REGS + _EXTRA_REGS)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define KGDB_MAX_NO_CPUS	1
798c2ecf20Sopenharmony_ci#define BUFMAX			400
808c2ecf20Sopenharmony_ci#define NUMREGBYTES		(GDB_MAX_REGS << 2)
818c2ecf20Sopenharmony_ci#define NUMCRITREGBYTES		(32 << 2)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define _R0			0
848c2ecf20Sopenharmony_ci#define _R1			1
858c2ecf20Sopenharmony_ci#define _R2			2
868c2ecf20Sopenharmony_ci#define _R3			3
878c2ecf20Sopenharmony_ci#define _R4			4
888c2ecf20Sopenharmony_ci#define _R5			5
898c2ecf20Sopenharmony_ci#define _R6			6
908c2ecf20Sopenharmony_ci#define _R7			7
918c2ecf20Sopenharmony_ci#define _R8			8
928c2ecf20Sopenharmony_ci#define _R9			9
938c2ecf20Sopenharmony_ci#define _R10			10
948c2ecf20Sopenharmony_ci#define _FP			11
958c2ecf20Sopenharmony_ci#define _IP			12
968c2ecf20Sopenharmony_ci#define _SPT			13
978c2ecf20Sopenharmony_ci#define _LR			14
988c2ecf20Sopenharmony_ci#define _PC			15
998c2ecf20Sopenharmony_ci#define _CPSR			(GDB_MAX_REGS - 1)
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*
1028c2ecf20Sopenharmony_ci * So that we can denote the end of a frame for tracing,
1038c2ecf20Sopenharmony_ci * in the simple case:
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_ci#define CFI_END_FRAME(func)	__CFI_END_FRAME(_PC, _SPT, func)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#endif /* __ASM_KGDB_H__ */
108