18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_PROBES_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_PROBES_H
48c2ecf20Sopenharmony_ci#ifdef __KERNEL__
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * Definitions common to probes files
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright IBM Corporation, 2012
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#include <linux/types.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_citypedef u32 ppc_opcode_t;
138c2ecf20Sopenharmony_ci#define BREAKPOINT_INSTRUCTION	0x7fe00008	/* trap */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* Trap definitions per ISA */
168c2ecf20Sopenharmony_ci#define IS_TW(instr)		(((instr) & 0xfc0007fe) == 0x7c000008)
178c2ecf20Sopenharmony_ci#define IS_TD(instr)		(((instr) & 0xfc0007fe) == 0x7c000088)
188c2ecf20Sopenharmony_ci#define IS_TDI(instr)		(((instr) & 0xfc000000) == 0x08000000)
198c2ecf20Sopenharmony_ci#define IS_TWI(instr)		(((instr) & 0xfc000000) == 0x0c000000)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64
228c2ecf20Sopenharmony_ci#define is_trap(instr)		(IS_TW(instr) || IS_TD(instr) || \
238c2ecf20Sopenharmony_ci				IS_TWI(instr) || IS_TDI(instr))
248c2ecf20Sopenharmony_ci#else
258c2ecf20Sopenharmony_ci#define is_trap(instr)		(IS_TW(instr) || IS_TWI(instr))
268c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC64 */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_ADV_DEBUG_REGS
298c2ecf20Sopenharmony_ci#define MSR_SINGLESTEP	(MSR_DE)
308c2ecf20Sopenharmony_ci#else
318c2ecf20Sopenharmony_ci#define MSR_SINGLESTEP	(MSR_SE)
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Enable single stepping for the current task */
358c2ecf20Sopenharmony_cistatic inline void enable_single_step(struct pt_regs *regs)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	regs->msr |= MSR_SINGLESTEP;
388c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_ADV_DEBUG_REGS
398c2ecf20Sopenharmony_ci	/*
408c2ecf20Sopenharmony_ci	 * We turn off Critical Input Exception(CE) to ensure that the single
418c2ecf20Sopenharmony_ci	 * step will be for the instruction we have the probe on; if we don't,
428c2ecf20Sopenharmony_ci	 * it is possible we'd get the single step reported for CE.
438c2ecf20Sopenharmony_ci	 */
448c2ecf20Sopenharmony_ci	regs->msr &= ~MSR_CE;
458c2ecf20Sopenharmony_ci	mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
468c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_47x
478c2ecf20Sopenharmony_ci	isync();
488c2ecf20Sopenharmony_ci#endif
498c2ecf20Sopenharmony_ci#endif
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
548c2ecf20Sopenharmony_ci#endif	/* _ASM_POWERPC_PROBES_H */
55