1
2
3
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 #include <asm/thread_info.h>
13 #include <asm/bug.h>
14 #include <asm/ptrace.h>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 _GLOBAL(ftrace_regs_caller)
36
37 std r0,LRSAVE(r1)
38
39
40 stdu r1,-SWITCH_FRAME_SIZE(r1)
41
42
43 SAVE_GPR(0, r1)
44 SAVE_10GPRS(2, r1)
45
46
47 lbz r3, PACA_FTRACE_ENABLED(r13)
48 cmpdi r3, 0
49 beq ftrace_no_trace
50
51 SAVE_10GPRS(12, r1)
52 SAVE_10GPRS(22, r1)
53
54
55 addi r8, r1, SWITCH_FRAME_SIZE
56 std r8, GPR1(r1)
57
58
59 mfmsr r8
60 mfctr r9
61 mfxer r10
62 mfcr r11
63
64
65 mflr r7
66
67 std r7, _NIP(r1)
68
69 std r0, _LINK(r1)
70
71
72 std r2, 24(r1)
73 ld r2,PACATOC(r13)
74
75 addis r3,r2,function_trace_op@toc@ha
76 addi r3,r3,function_trace_op@toc@l
77 ld r5,0(r3)
78
79 #ifdef CONFIG_LIVEPATCH
80 mr r14,r7
81 #endif
82
83 subi r3, r7, MCOUNT_INSN_SIZE
84
85
86 mr r4, r0
87
88
89 std r8, _MSR(r1)
90 std r9, _CTR(r1)
91 std r10, _XER(r1)
92 std r11, _CCR(r1)
93
94
95 addi r6, r1 ,STACK_FRAME_OVERHEAD
96
97
98 .globl ftrace_regs_call
99 ftrace_regs_call:
100 bl ftrace_stub
101 nop
102
103
104 ld r3, _NIP(r1)
105 mtctr r3
106 #ifdef CONFIG_LIVEPATCH
107 cmpd r14, r3
108 #endif
109
110
111 REST_GPR(0,r1)
112 REST_10GPRS(2,r1)
113 REST_10GPRS(12,r1)
114 REST_10GPRS(22,r1)
115
116
117 ld r0, _LINK(r1)
118 mtlr r0
119
120
121 ld r2, 24(r1)
122
123
124 addi r1, r1, SWITCH_FRAME_SIZE
125
126 #ifdef CONFIG_LIVEPATCH
127
128 bne- livepatch_handler
129 #endif
130
131 ftrace_caller_common:
132 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
133 .globl ftrace_graph_call
134 ftrace_graph_call:
135 b ftrace_graph_stub
136 _GLOBAL(ftrace_graph_stub)
137 #endif
138
139 bctr
140
141 _GLOBAL(ftrace_stub)
142 blr
143
144 ftrace_no_trace:
145 mflr r3
146 mtctr r3
147 REST_GPR(3, r1)
148 addi r1, r1, SWITCH_FRAME_SIZE
149 mtlr r0
150 bctr
151
152 _GLOBAL(ftrace_caller)
153
154 std r0, LRSAVE(r1)
155
156
157 stdu r1, -SWITCH_FRAME_SIZE(r1)
158
159
160 SAVE_8GPRS(3, r1)
161
162 lbz r3, PACA_FTRACE_ENABLED(r13)
163 cmpdi r3, 0
164 beq ftrace_no_trace
165
166
167 mflr r7
168 std r7, _NIP(r1)
169
170
171 std r2, 24(r1)
172 ld r2, PACATOC(r13)
173
174 addis r3, r2, function_trace_op@toc@ha
175 addi r3, r3, function_trace_op@toc@l
176 ld r5, 0(r3)
177
178
179 subi r3, r7, MCOUNT_INSN_SIZE
180
181
182 mr r4, r0
183
184
185 li r6, 0
186
187
188 .globl ftrace_call
189 ftrace_call:
190 bl ftrace_stub
191 nop
192
193 ld r3, _NIP(r1)
194 mtctr r3
195
196
197 REST_8GPRS(3,r1)
198
199
200 ld r2, 24(r1)
201
202
203 addi r1, r1, SWITCH_FRAME_SIZE
204
205
206 ld r0, LRSAVE(r1)
207 mtlr r0
208
209
210 b ftrace_caller_common
211
212 #ifdef CONFIG_LIVEPATCH
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 livepatch_handler:
228 ld r12, PACA_THREAD_INFO(r13)
229
230
231 ld r11, TI_livepatch_sp(r12)
232 addi r11, r11, 24
233 std r11, TI_livepatch_sp(r12)
234
235
236 std r2, -24(r11)
237 mflr r12
238 std r12, -16(r11)
239
240
241 lis r12, STACK_END_MAGIC@h
242 ori r12, r12, STACK_END_MAGIC@l
243 std r12, -8(r11)
244
245
246 mfctr r12
247 bctrl
248
249
250
251
252
253
254
255 ld r12, PACA_THREAD_INFO(r13)
256
257 ld r11, TI_livepatch_sp(r12)
258
259
260 lis r2, STACK_END_MAGIC@h
261 ori r2, r2, STACK_END_MAGIC@l
262 ld r12, -8(r11)
263 1: tdne r12, r2
264 EMIT_BUG_ENTRY 1b, __FILE__, __LINE__ - 1, 0
265
266
267 ld r12, -16(r11)
268 mtlr r12
269 ld r2, -24(r11)
270
271
272 ld r12, PACA_THREAD_INFO(r13)
273 subi r11, r11, 24
274 std r11, TI_livepatch_sp(r12)
275
276
277 blr
278 #endif
279
280 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
281 _GLOBAL(ftrace_graph_caller)
282 stdu r1, -112(r1)
283
284 std r10, 104(r1)
285 std r9, 96(r1)
286 std r8, 88(r1)
287 std r7, 80(r1)
288 std r6, 72(r1)
289 std r5, 64(r1)
290 std r4, 56(r1)
291 std r3, 48(r1)
292
293
294 std r2, 24(r1)
295 ld r2, PACATOC(r13)
296
297 addi r5, r1, 112
298 mfctr r4
299 std r4, 40(r1)
300 mflr r3
301 subi r4, r4, MCOUNT_INSN_SIZE
302
303 bl prepare_ftrace_return
304 nop
305
306
307
308
309
310 mtlr r3
311
312 ld r0, 40(r1)
313 mtctr r0
314 ld r10, 104(r1)
315 ld r9, 96(r1)
316 ld r8, 88(r1)
317 ld r7, 80(r1)
318 ld r6, 72(r1)
319 ld r5, 64(r1)
320 ld r4, 56(r1)
321 ld r3, 48(r1)
322
323
324 ld r2, 24(r1)
325
326 addi r1, r1, 112
327 mflr r0
328 std r0, LRSAVE(r1)
329 bctr
330 #endif