|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | +/* |
| 3 | + * Function tracing support for ARC |
| 4 | + * |
| 5 | + * Copyright (C) 2023 Synopsys, Inc. (www.synopsys.com) |
| 6 | + */ |
| 7 | + |
| 8 | +#include <linux/linkage.h> |
| 9 | +#include <asm-generic/export.h> |
| 10 | + |
| 11 | +; ftrace placeholder, just return to caller |
| 12 | +ENTRY(ftrace_stub) |
| 13 | + j_s [blink] |
| 14 | +ENDPROC(ftrace_stub) |
| 15 | + |
| 16 | +.macro SAVE_ABI |
| 17 | + push blink |
| 18 | +.endm |
| 19 | + |
| 20 | +.macro LOAD_ABI |
| 21 | + pop blink |
| 22 | +.endm |
| 23 | + |
| 24 | +.macro SAVE_ABI_RET |
| 25 | + push r0 |
| 26 | + push r1 |
| 27 | +.endm |
| 28 | + |
| 29 | +.macro LOAD_ABI_RET |
| 30 | + pop r1 |
| 31 | + pop r0 |
| 32 | +.endm |
| 33 | + |
| 34 | +; r0 has the frompc (targets parent ip) |
| 35 | +; blink has the selfpc (target ip) |
| 36 | +ENTRY(_mcount) |
| 37 | + |
| 38 | +#ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 39 | + |
| 40 | + ; *ftrace_graph_return != ftrace_stub |
| 41 | + ld r3, [ftrace_graph_return] |
| 42 | + brne r3, @ftrace_stub, @do_ftrace_graph_caller |
| 43 | + ; *ftrace_graph_entry != *ftrace_graph_entry_stub |
| 44 | + ld r3, [ftrace_graph_entry] |
| 45 | + brne r3, @ftrace_graph_entry_stub, @do_ftrace_graph_caller |
| 46 | + |
| 47 | +#endif |
| 48 | + |
| 49 | + ; *ftrace_trace_function != ftrace_stub |
| 50 | + ld r2, [ftrace_trace_function] |
| 51 | + brne r2, @ftrace_stub, @do_trace |
| 52 | + ; Return |
| 53 | + j_s [blink] |
| 54 | + |
| 55 | +ENDPROC(_mcount) |
| 56 | + |
| 57 | +#ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 58 | + |
| 59 | +; Return to the actual caller |
| 60 | +ENTRY(return_to_handler) |
| 61 | + ; Save return value (if any) from handled routine |
| 62 | + SAVE_ABI_RET |
| 63 | + ; Will return true blink on r0 |
| 64 | + jl ftrace_return_to_handler |
| 65 | + mov r2, r0 |
| 66 | + LOAD_ABI_RET |
| 67 | + j [r2] |
| 68 | + |
| 69 | +ENDPROC(return_to_handler) |
| 70 | + |
| 71 | +do_ftrace_graph_caller: |
| 72 | + ; ABI does not allow us to infer blink location |
| 73 | + ; ARC GCC port inserts into r1 the delta between the pushed blink and |
| 74 | + ; the sp at call time |
| 75 | + ; We perform calculation before any push (sp change) happens |
| 76 | + add r0, r1, sp |
| 77 | + SAVE_ABI |
| 78 | + sub r0, r0, 4 |
| 79 | + mov r1, blink |
| 80 | + jl prepare_ftrace_return |
| 81 | + LOAD_ABI |
| 82 | + j_s [blink] |
| 83 | +#endif |
| 84 | + |
| 85 | +do_trace: |
| 86 | + SAVE_ABI |
| 87 | + mov r1, r0 |
| 88 | + mov r0, blink |
| 89 | + jl [r2] |
| 90 | + ; load ABI state and jump to blink (in stack) |
| 91 | + LOAD_ABI |
| 92 | + j_s [blink] |
| 93 | + |
| 94 | +EXPORT_SYMBOL(_mcount) |
0 commit comments