GNU Linux-libre 4.14.251-gnu1
[releases.git] / arch / powerpc / kernel / trace / ftrace_64.S
1 /*
2  * Split from entry_64.S
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9
10 #include <linux/magic.h>
11 #include <asm/ppc_asm.h>
12 #include <asm/asm-offsets.h>
13 #include <asm/ftrace.h>
14 #include <asm/ppc-opcode.h>
15 #include <asm/export.h>
16
17 #ifdef CONFIG_DYNAMIC_FTRACE
18 _GLOBAL(mcount)
19 _GLOBAL(_mcount)
20 EXPORT_SYMBOL(_mcount)
21         mflr    r12
22         mtctr   r12
23         mtlr    r0
24         bctr
25
26 #else /* CONFIG_DYNAMIC_FTRACE */
27 _GLOBAL_TOC(_mcount)
28 EXPORT_SYMBOL(_mcount)
29         /* Taken from output of objdump from lib64/glibc */
30         mflr    r3
31         ld      r11, 0(r1)
32         stdu    r1, -112(r1)
33         std     r3, 128(r1)
34         ld      r4, 16(r11)
35
36         subi    r3, r3, MCOUNT_INSN_SIZE
37         LOAD_REG_ADDR(r5,ftrace_trace_function)
38         ld      r5,0(r5)
39         ld      r5,0(r5)
40         mtctr   r5
41         bctrl
42         nop
43
44 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
45         b       ftrace_graph_caller
46 #endif
47         ld      r0, 128(r1)
48         mtlr    r0
49         addi    r1, r1, 112
50 _GLOBAL(ftrace_stub)
51         blr
52 #endif /* CONFIG_DYNAMIC_FTRACE */
53
54 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
55 _GLOBAL(return_to_handler)
56         /* need to save return values */
57         std     r4,  -32(r1)
58         std     r3,  -24(r1)
59         /* save TOC */
60         std     r2,  -16(r1)
61         std     r31, -8(r1)
62         mr      r31, r1
63         stdu    r1, -112(r1)
64
65         /*
66          * We might be called from a module.
67          * Switch to our TOC to run inside the core kernel.
68          */
69         ld      r2, PACATOC(r13)
70
71         bl      ftrace_return_to_handler
72         nop
73
74         /* return value has real return address */
75         mtlr    r3
76
77         ld      r1, 0(r1)
78         ld      r4,  -32(r1)
79         ld      r3,  -24(r1)
80         ld      r2,  -16(r1)
81         ld      r31, -8(r1)
82
83         /* Jump back to real return address */
84         blr
85 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */