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>
12 #define OPT_SLOT_SIZE 65536
17 * Reserve an area to allocate slots for detour buffer.
18 * This is part of .text section (rather than vmalloc area)
19 * as this needs to be within 32MB of the probed address.
27 * This template gets copied into one of the slots in optinsn_slot
28 * and gets fixed up with real optprobe structures et al.
30 .global optprobe_template_entry
31 optprobe_template_entry:
32 /* Create an in-memory pt_regs */
33 stdu r1,-INT_FRAME_SIZE(r1)
35 /* Save the previous SP into stack */
36 addi r0,r1,INT_FRAME_SIZE
57 lbz r5,PACAIRQSOFTMASK(r13)
61 * We may get here from a module, so load the kernel TOC in r2.
62 * The original TOC gets restored when pt_regs is restored
67 .global optprobe_template_op_address
68 optprobe_template_op_address:
70 * Parameters to optimized_callback():
71 * 1. optimized_kprobe structure in r3
78 /* 2. pt_regs pointer in r4 */
79 addi r4,r1,STACK_FRAME_OVERHEAD
81 .global optprobe_template_call_handler
82 optprobe_template_call_handler:
83 /* Branch to optimized_callback() */
87 * Parameters for instruction emulation:
88 * 1. Pass SP in register r3.
90 addi r3,r1,STACK_FRAME_OVERHEAD
92 .global optprobe_template_insn
93 optprobe_template_insn:
94 /* 2, Pass instruction to be emulated in r4 */
98 .global optprobe_template_call_emulate
99 optprobe_template_call_emulate:
100 /* Branch to emulate_step() */
105 * Now, restore the registers...
121 /* Restore the previous SP */
122 addi r1,r1,INT_FRAME_SIZE
124 .global optprobe_template_ret
125 optprobe_template_ret:
126 /* ... and jump back from trampoline */
129 .global optprobe_template_end
130 optprobe_template_end: