1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Split from entry_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#ifdef CONFIG_PPC64
14.pushsection ".tramp.ftrace.text","aw",@progbits;
15.globl ftrace_tramp_text
16ftrace_tramp_text:
17	.space 64
18.popsection
19
20.pushsection ".tramp.ftrace.init","aw",@progbits;
21.globl ftrace_tramp_init
22ftrace_tramp_init:
23	.space 64
24.popsection
25#endif
26
27_GLOBAL(mcount)
28_GLOBAL(_mcount)
29EXPORT_SYMBOL(_mcount)
30	mflr	r12
31	mtctr	r12
32	mtlr	r0
33	bctr
34
35#ifdef CONFIG_FUNCTION_GRAPH_TRACER
36_GLOBAL(return_to_handler)
37	/* need to save return values */
38#ifdef CONFIG_PPC64
39	std	r4,  -32(r1)
40	std	r3,  -24(r1)
41	/* save TOC */
42	std	r2,  -16(r1)
43	std	r31, -8(r1)
44	mr	r31, r1
45	stdu	r1, -112(r1)
46
47	/*
48	 * We might be called from a module.
49	 * Switch to our TOC to run inside the core kernel.
50	 */
51	ld	r2, PACATOC(r13)
52#else
53	stwu	r1, -16(r1)
54	stw	r3, 8(r1)
55	stw	r4, 12(r1)
56#endif
57
58	bl	ftrace_return_to_handler
59	nop
60
61	/* return value has real return address */
62	mtlr	r3
63
64#ifdef CONFIG_PPC64
65	ld	r1, 0(r1)
66	ld	r4,  -32(r1)
67	ld	r3,  -24(r1)
68	ld	r2,  -16(r1)
69	ld	r31, -8(r1)
70#else
71	lwz	r3, 8(r1)
72	lwz	r4, 12(r1)
73	addi	r1, r1, 16
74#endif
75
76	/* Jump back to real return address */
77	blr
78#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
79