1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Split from ftrace_64.S
4 */
5
6#include <linux/magic.h>
7#include <asm/ppc_asm.h>
8#include <asm/asm-offsets.h>
9#include <asm/ftrace.h>
10#include <asm/ppc-opcode.h>
11#include <asm/export.h>
12
13_GLOBAL_TOC(ftrace_caller)
14	lbz	r3, PACA_FTRACE_ENABLED(r13)
15	cmpdi	r3, 0
16	beqlr
17
18	/* Taken from output of objdump from lib64/glibc */
19	mflr	r3
20	ld	r11, 0(r1)
21	stdu	r1, -112(r1)
22	std	r3, 128(r1)
23	ld	r4, 16(r11)
24	subi	r3, r3, MCOUNT_INSN_SIZE
25.globl ftrace_call
26ftrace_call:
27	bl	ftrace_stub
28	nop
29#ifdef CONFIG_FUNCTION_GRAPH_TRACER
30.globl ftrace_graph_call
31ftrace_graph_call:
32	b	ftrace_graph_stub
33_GLOBAL(ftrace_graph_stub)
34#endif
35	ld	r0, 128(r1)
36	mtlr	r0
37	addi	r1, r1, 112
38
39_GLOBAL(ftrace_stub)
40	blr
41
42#ifdef CONFIG_FUNCTION_GRAPH_TRACER
43_GLOBAL(ftrace_graph_caller)
44	addi	r5, r1, 112
45	/* load r4 with local address */
46	ld	r4, 128(r1)
47	subi	r4, r4, MCOUNT_INSN_SIZE
48
49	/* Grab the LR out of the caller stack frame */
50	ld	r11, 112(r1)
51	ld	r3, 16(r11)
52
53	bl	prepare_ftrace_return
54	nop
55
56	/*
57	 * prepare_ftrace_return gives us the address we divert to.
58	 * Change the LR in the callers stack frame to this.
59	 */
60	ld	r11, 112(r1)
61	std	r3, 16(r11)
62
63	ld	r0, 128(r1)
64	mtlr	r0
65	addi	r1, r1, 112
66	blr
67#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
68