18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_KPROBES_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_KPROBES_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm-generic/kprobes.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifdef __KERNEL__
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci *  Kernel Probes (KProbes)
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Copyright (C) IBM Corporation, 2002, 2004
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * 2002-Oct	Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
148c2ecf20Sopenharmony_ci *		Probes initial implementation ( includes suggestions from
158c2ecf20Sopenharmony_ci *		Rusty Russell).
168c2ecf20Sopenharmony_ci * 2004-Nov	Modified for PPC64 by Ananth N Mavinakayanahalli
178c2ecf20Sopenharmony_ci *		<ananth@in.ibm.com>
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci#include <linux/types.h>
208c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
218c2ecf20Sopenharmony_ci#include <linux/percpu.h>
228c2ecf20Sopenharmony_ci#include <linux/module.h>
238c2ecf20Sopenharmony_ci#include <asm/probes.h>
248c2ecf20Sopenharmony_ci#include <asm/code-patching.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_KPROBES
278c2ecf20Sopenharmony_ci#define  __ARCH_WANT_KPROBES_INSN_SLOT
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistruct pt_regs;
308c2ecf20Sopenharmony_cistruct kprobe;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_citypedef ppc_opcode_t kprobe_opcode_t;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciextern kprobe_opcode_t optinsn_slot;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Optinsn template address */
378c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_entry[];
388c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_op_address[];
398c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_call_handler[];
408c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_insn[];
418c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_call_emulate[];
428c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_ret[];
438c2ecf20Sopenharmony_ciextern kprobe_opcode_t optprobe_template_end[];
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Fixed instruction size for powerpc */
468c2ecf20Sopenharmony_ci#define MAX_INSN_SIZE		2
478c2ecf20Sopenharmony_ci#define MAX_OPTIMIZED_LENGTH	sizeof(kprobe_opcode_t)	/* 4 bytes */
488c2ecf20Sopenharmony_ci#define MAX_OPTINSN_SIZE	(optprobe_template_end - optprobe_template_entry)
498c2ecf20Sopenharmony_ci#define RELATIVEJUMP_SIZE	sizeof(kprobe_opcode_t)	/* 4 bytes */
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define flush_insn_slot(p)	do { } while (0)
528c2ecf20Sopenharmony_ci#define kretprobe_blacklist_size 0
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_civoid kretprobe_trampoline(void);
558c2ecf20Sopenharmony_ciextern void arch_remove_kprobe(struct kprobe *p);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Architecture specific copy of original instruction */
588c2ecf20Sopenharmony_cistruct arch_specific_insn {
598c2ecf20Sopenharmony_ci	/* copy of original instruction */
608c2ecf20Sopenharmony_ci	kprobe_opcode_t *insn;
618c2ecf20Sopenharmony_ci	/*
628c2ecf20Sopenharmony_ci	 * Set in kprobes code, initially to 0. If the instruction can be
638c2ecf20Sopenharmony_ci	 * eumulated, this is set to 1, if not, to -1.
648c2ecf20Sopenharmony_ci	 */
658c2ecf20Sopenharmony_ci	int boostable;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct prev_kprobe {
698c2ecf20Sopenharmony_ci	struct kprobe *kp;
708c2ecf20Sopenharmony_ci	unsigned long status;
718c2ecf20Sopenharmony_ci	unsigned long saved_msr;
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* per-cpu kprobe control block */
758c2ecf20Sopenharmony_cistruct kprobe_ctlblk {
768c2ecf20Sopenharmony_ci	unsigned long kprobe_status;
778c2ecf20Sopenharmony_ci	unsigned long kprobe_saved_msr;
788c2ecf20Sopenharmony_ci	struct prev_kprobe prev_kprobe;
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct arch_optimized_insn {
828c2ecf20Sopenharmony_ci	kprobe_opcode_t copied_insn[1];
838c2ecf20Sopenharmony_ci	/* detour buffer */
848c2ecf20Sopenharmony_ci	kprobe_opcode_t *insn;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciextern int kprobe_exceptions_notify(struct notifier_block *self,
888c2ecf20Sopenharmony_ci					unsigned long val, void *data);
898c2ecf20Sopenharmony_ciextern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
908c2ecf20Sopenharmony_ciextern int kprobe_handler(struct pt_regs *regs);
918c2ecf20Sopenharmony_ciextern int kprobe_post_handler(struct pt_regs *regs);
928c2ecf20Sopenharmony_ci#else
938c2ecf20Sopenharmony_cistatic inline int kprobe_handler(struct pt_regs *regs) { return 0; }
948c2ecf20Sopenharmony_cistatic inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
958c2ecf20Sopenharmony_ci#endif /* CONFIG_KPROBES */
968c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
978c2ecf20Sopenharmony_ci#endif	/* _ASM_POWERPC_KPROBES_H */
98