.. | .. |
---|
1 | | -/* |
---|
2 | | - * This program is free software; you can redistribute it and/or modify |
---|
3 | | - * it under the terms of the GNU General Public License version 2 as |
---|
4 | | - * published by the Free Software Foundation. |
---|
5 | | - */ |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
6 | 2 | |
---|
7 | 3 | #include <asm/assembler.h> |
---|
8 | 4 | #include <asm/ftrace.h> |
---|
.. | .. |
---|
15 | 11 | * start of every function. In mcount, apart from the function's address (in |
---|
16 | 12 | * lr), we need to get hold of the function's caller's address. |
---|
17 | 13 | * |
---|
18 | | - * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this: |
---|
19 | | - * |
---|
20 | | - * bl mcount |
---|
21 | | - * |
---|
22 | | - * These versions have the limitation that in order for the mcount routine to |
---|
23 | | - * be able to determine the function's caller's address, an APCS-style frame |
---|
24 | | - * pointer (which is set up with something like the code below) is required. |
---|
25 | | - * |
---|
26 | | - * mov ip, sp |
---|
27 | | - * push {fp, ip, lr, pc} |
---|
28 | | - * sub fp, ip, #4 |
---|
29 | | - * |
---|
30 | | - * With EABI, these frame pointers are not available unless -mapcs-frame is |
---|
31 | | - * specified, and if building as Thumb-2, not even then. |
---|
32 | | - * |
---|
33 | | - * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount, |
---|
34 | | - * with call sites like: |
---|
| 14 | + * Newer GCCs (4.4+) solve this problem by using a version of mcount with call |
---|
| 15 | + * sites like: |
---|
35 | 16 | * |
---|
36 | 17 | * push {lr} |
---|
37 | 18 | * bl __gnu_mcount_nc |
---|
.. | .. |
---|
41 | 22 | * mcount can be thought of as a function called in the middle of a subroutine |
---|
42 | 23 | * call. As such, it needs to be transparent for both the caller and the |
---|
43 | 24 | * callee: the original lr needs to be restored when leaving mcount, and no |
---|
44 | | - * registers should be clobbered. (In the __gnu_mcount_nc implementation, we |
---|
45 | | - * clobber the ip register. This is OK because the ARM calling convention |
---|
46 | | - * allows it to be clobbered in subroutines and doesn't use it to hold |
---|
47 | | - * parameters.) |
---|
| 25 | + * registers should be clobbered. |
---|
48 | 26 | * |
---|
49 | | - * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0" |
---|
50 | | - * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see |
---|
51 | | - * arch/arm/kernel/ftrace.c). |
---|
| 27 | + * When using dynamic ftrace, we patch out the mcount call by a "pop {lr}" |
---|
| 28 | + * instead of the __gnu_mcount_nc call (see arch/arm/kernel/ftrace.c). |
---|
52 | 29 | */ |
---|
53 | | - |
---|
54 | | -#ifndef CONFIG_OLD_MCOUNT |
---|
55 | | -#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) |
---|
56 | | -#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0. |
---|
57 | | -#endif |
---|
58 | | -#endif |
---|
59 | 30 | |
---|
60 | 31 | .macro mcount_adjust_addr rd, rn |
---|
61 | 32 | bic \rd, \rn, #1 @ clear the Thumb bit if present |
---|
.. | .. |
---|
96 | 67 | |
---|
97 | 68 | .macro __ftrace_regs_caller |
---|
98 | 69 | |
---|
99 | | - sub sp, sp, #8 @ space for PC and CPSR OLD_R0, |
---|
| 70 | + str lr, [sp, #-8]! @ store LR as PC and make space for CPSR/OLD_R0, |
---|
100 | 71 | @ OLD_R0 will overwrite previous LR |
---|
101 | 72 | |
---|
102 | | - add ip, sp, #12 @ move in IP the value of SP as it was |
---|
103 | | - @ before the push {lr} of the mcount mechanism |
---|
104 | | - |
---|
105 | | - str lr, [sp, #0] @ store LR instead of PC |
---|
106 | | - |
---|
107 | | - ldr lr, [sp, #8] @ get previous LR |
---|
| 73 | + ldr lr, [sp, #8] @ get previous LR |
---|
108 | 74 | |
---|
109 | 75 | str r0, [sp, #8] @ write r0 as OLD_R0 over previous LR |
---|
110 | 76 | |
---|
111 | | - stmdb sp!, {ip, lr} |
---|
112 | | - stmdb sp!, {r0-r11, lr} |
---|
| 77 | + str lr, [sp, #-4]! @ store previous LR as LR |
---|
| 78 | + |
---|
| 79 | + add lr, sp, #16 @ move in LR the value of SP as it was |
---|
| 80 | + @ before the push {lr} of the mcount mechanism |
---|
| 81 | + |
---|
| 82 | + push {r0-r11, ip, lr} |
---|
113 | 83 | |
---|
114 | 84 | @ stack content at this point: |
---|
115 | 85 | @ 0 4 48 52 56 60 64 68 72 |
---|
116 | | - @ R0 | R1 | ... | LR | SP + 4 | previous LR | LR | PSR | OLD_R0 | |
---|
| 86 | + @ R0 | R1 | ... | IP | SP + 4 | previous LR | LR | PSR | OLD_R0 | |
---|
117 | 87 | |
---|
118 | | - mov r3, sp @ struct pt_regs* |
---|
| 88 | + mov r3, sp @ struct pt_regs* |
---|
119 | 89 | |
---|
120 | 90 | ldr r2, =function_trace_op |
---|
121 | 91 | ldr r2, [r2] @ pointer to the current |
---|
.. | .. |
---|
138 | 108 | #endif |
---|
139 | 109 | |
---|
140 | 110 | @ pop saved regs |
---|
141 | | - ldmia sp!, {r0-r12} @ restore r0 through r12 |
---|
142 | | - ldr ip, [sp, #8] @ restore PC |
---|
143 | | - ldr lr, [sp, #4] @ restore LR |
---|
144 | | - ldr sp, [sp, #0] @ restore SP |
---|
145 | | - mov pc, ip @ return |
---|
| 111 | + pop {r0-r11, ip, lr} @ restore r0 through r12 |
---|
| 112 | + ldr lr, [sp], #4 @ restore LR |
---|
| 113 | + ldr pc, [sp], #12 |
---|
146 | 114 | .endm |
---|
147 | 115 | |
---|
148 | 116 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
---|
.. | .. |
---|
158 | 126 | bl prepare_ftrace_return |
---|
159 | 127 | |
---|
160 | 128 | @ pop registers saved in ftrace_regs_caller |
---|
161 | | - ldmia sp!, {r0-r12} @ restore r0 through r12 |
---|
162 | | - ldr ip, [sp, #8] @ restore PC |
---|
163 | | - ldr lr, [sp, #4] @ restore LR |
---|
164 | | - ldr sp, [sp, #0] @ restore SP |
---|
165 | | - mov pc, ip @ return |
---|
| 129 | + pop {r0-r11, ip, lr} @ restore r0 through r12 |
---|
| 130 | + ldr lr, [sp], #4 @ restore LR |
---|
| 131 | + ldr pc, [sp], #12 |
---|
166 | 132 | |
---|
167 | 133 | .endm |
---|
168 | 134 | #endif |
---|
.. | .. |
---|
209 | 175 | mcount_exit |
---|
210 | 176 | .endm |
---|
211 | 177 | |
---|
212 | | -#ifdef CONFIG_OLD_MCOUNT |
---|
213 | | -/* |
---|
214 | | - * mcount |
---|
215 | | - */ |
---|
216 | | - |
---|
217 | | -.macro mcount_enter |
---|
218 | | - stmdb sp!, {r0-r3, lr} |
---|
219 | | -.endm |
---|
220 | | - |
---|
221 | | -.macro mcount_get_lr reg |
---|
222 | | - ldr \reg, [fp, #-4] |
---|
223 | | -.endm |
---|
224 | | - |
---|
225 | | -.macro mcount_exit |
---|
226 | | - ldr lr, [fp, #-4] |
---|
227 | | - ldmia sp!, {r0-r3, pc} |
---|
228 | | -.endm |
---|
229 | | - |
---|
230 | | -ENTRY(mcount) |
---|
231 | | -#ifdef CONFIG_DYNAMIC_FTRACE |
---|
232 | | - stmdb sp!, {lr} |
---|
233 | | - ldr lr, [fp, #-4] |
---|
234 | | - ldmia sp!, {pc} |
---|
235 | | -#else |
---|
236 | | - __mcount _old |
---|
237 | | -#endif |
---|
238 | | -ENDPROC(mcount) |
---|
239 | | - |
---|
240 | | -#ifdef CONFIG_DYNAMIC_FTRACE |
---|
241 | | -ENTRY(ftrace_caller_old) |
---|
242 | | - __ftrace_caller _old |
---|
243 | | -ENDPROC(ftrace_caller_old) |
---|
244 | | -#endif |
---|
245 | | - |
---|
246 | | -#ifdef CONFIG_FUNCTION_GRAPH_TRACER |
---|
247 | | -ENTRY(ftrace_graph_caller_old) |
---|
248 | | - __ftrace_graph_caller |
---|
249 | | -ENDPROC(ftrace_graph_caller_old) |
---|
250 | | -#endif |
---|
251 | | - |
---|
252 | | -.purgem mcount_enter |
---|
253 | | -.purgem mcount_get_lr |
---|
254 | | -.purgem mcount_exit |
---|
255 | | -#endif |
---|
256 | | - |
---|
257 | 178 | /* |
---|
258 | 179 | * __gnu_mcount_nc |
---|
259 | 180 | */ |
---|
.. | .. |
---|
273 | 194 | .endm |
---|
274 | 195 | |
---|
275 | 196 | .macro mcount_exit |
---|
276 | | - ldmia sp!, {r0-r3, ip, lr} |
---|
277 | | - ret ip |
---|
| 197 | + ldmia sp!, {r0-r3} |
---|
| 198 | + ldr lr, [sp, #4] |
---|
| 199 | + ldr pc, [sp], #8 |
---|
278 | 200 | .endm |
---|
279 | 201 | |
---|
280 | 202 | ENTRY(__gnu_mcount_nc) |
---|
281 | 203 | UNWIND(.fnstart) |
---|
282 | 204 | #ifdef CONFIG_DYNAMIC_FTRACE |
---|
283 | | - mov ip, lr |
---|
284 | | - ldmia sp!, {lr} |
---|
285 | | - ret ip |
---|
| 205 | + push {lr} |
---|
| 206 | + ldr lr, [sp, #4] |
---|
| 207 | + ldr pc, [sp], #8 |
---|
286 | 208 | #else |
---|
287 | 209 | __mcount |
---|
288 | 210 | #endif |
---|