forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/arch/arm/kernel/entry-ftrace.S
....@@ -1,8 +1,4 @@
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 */
62
73 #include <asm/assembler.h>
84 #include <asm/ftrace.h>
....@@ -15,23 +11,8 @@
1511 * start of every function. In mcount, apart from the function's address (in
1612 * lr), we need to get hold of the function's caller's address.
1713 *
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:
3516 *
3617 * push {lr}
3718 * bl __gnu_mcount_nc
....@@ -41,21 +22,11 @@
4122 * mcount can be thought of as a function called in the middle of a subroutine
4223 * call. As such, it needs to be transparent for both the caller and the
4324 * 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.
4826 *
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).
5229 */
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
5930
6031 .macro mcount_adjust_addr rd, rn
6132 bic \rd, \rn, #1 @ clear the Thumb bit if present
....@@ -96,26 +67,25 @@
9667
9768 .macro __ftrace_regs_caller
9869
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,
10071 @ OLD_R0 will overwrite previous LR
10172
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
10874
10975 str r0, [sp, #8] @ write r0 as OLD_R0 over previous LR
11076
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}
11383
11484 @ stack content at this point:
11585 @ 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 |
11787
118
- mov r3, sp @ struct pt_regs*
88
+ mov r3, sp @ struct pt_regs*
11989
12090 ldr r2, =function_trace_op
12191 ldr r2, [r2] @ pointer to the current
....@@ -138,11 +108,9 @@
138108 #endif
139109
140110 @ 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
146114 .endm
147115
148116 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
....@@ -158,11 +126,9 @@
158126 bl prepare_ftrace_return
159127
160128 @ 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
166132
167133 .endm
168134 #endif
....@@ -209,51 +175,6 @@
209175 mcount_exit
210176 .endm
211177
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
-
257178 /*
258179 * __gnu_mcount_nc
259180 */
....@@ -273,16 +194,17 @@
273194 .endm
274195
275196 .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
278200 .endm
279201
280202 ENTRY(__gnu_mcount_nc)
281203 UNWIND(.fnstart)
282204 #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
286208 #else
287209 __mcount
288210 #endif