1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Code to prepare detour buffer for optprobes in Kernel.
5 * Copyright 2017, Anju T, IBM Corp.
8 #include <asm/ppc_asm.h>
9 #include <asm/ptrace.h>
10 #include <asm/asm-offsets.h>
13 #define SAVE_30GPRS(base) SAVE_GPRS(2, 31, base)
14 #define REST_30GPRS(base) REST_GPRS(2, 31, base)
15 #define TEMPLATE_FOR_IMM_LOAD_INSNS nop; nop; nop; nop; nop
17 #define SAVE_30GPRS(base) stmw r2, GPR2(base)
18 #define REST_30GPRS(base) lmw r2, GPR2(base)
19 #define TEMPLATE_FOR_IMM_LOAD_INSNS nop; nop; nop
22 #define OPT_SLOT_SIZE 65536
27 * Reserve an area to allocate slots for detour buffer.
28 * This is part of .text section (rather than vmalloc area)
29 * as this needs to be within 32MB of the probed address.
37 * This template gets copied into one of the slots in optinsn_slot
38 * and gets fixed up with real optprobe structures et al.
40 .global optprobe_template_entry
41 optprobe_template_entry:
42 /* Create an in-memory pt_regs */
43 PPC_STLU r1,-INT_FRAME_SIZE(r1)
45 /* Save the previous SP into stack */
46 addi r0,r1,INT_FRAME_SIZE
55 PPC_STL r5,ORIG_GPR3(r1)
66 lbz r5,PACAIRQSOFTMASK(r13)
71 * We may get here from a module, so load the kernel TOC in r2.
72 * The original TOC gets restored when pt_regs is restored
79 .global optprobe_template_op_address
80 optprobe_template_op_address:
82 * Parameters to optimized_callback():
83 * 1. optimized_kprobe structure in r3
85 TEMPLATE_FOR_IMM_LOAD_INSNS
87 /* 2. pt_regs pointer in r4 */
88 addi r4,r1,STACK_INT_FRAME_REGS
90 .global optprobe_template_call_handler
91 optprobe_template_call_handler:
92 /* Branch to optimized_callback() */
96 * Parameters for instruction emulation:
97 * 1. Pass SP in register r3.
99 addi r3,r1,STACK_INT_FRAME_REGS
101 .global optprobe_template_insn
102 optprobe_template_insn:
103 /* 2, Pass instruction to be emulated in r4 */
104 TEMPLATE_FOR_IMM_LOAD_INSNS
106 .global optprobe_template_call_emulate
107 optprobe_template_call_emulate:
108 /* Branch to emulate_step() */
113 * Now, restore the registers...
127 /* Restore the previous SP */
128 addi r1,r1,INT_FRAME_SIZE
130 .global optprobe_template_ret
131 optprobe_template_ret:
132 /* ... and jump back from trampoline */
135 .global optprobe_template_end
136 optprobe_template_end: