Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
0003 
0004 #include <linux/linkage.h>
0005 #include <asm/ftrace.h>
0006 #include <abi/entry.h>
0007 #include <asm/asm-offsets.h>
0008 
0009 /*
0010  * csky-gcc with -pg will put the following asm after prologue:
0011  *      push    r15
0012  *      jsri    _mcount
0013  *
0014  * stack layout after mcount_enter in _mcount():
0015  *
0016  * current sp => 0:+-------+
0017  *                 | a0-a3 | -> must save all argument regs
0018  *             +16:+-------+
0019  *                 | lr    | -> _mcount lr (instrumente function's pc)
0020  *             +20:+-------+
0021  *                 | fp=r8 | -> instrumented function fp
0022  *             +24:+-------+
0023  *                 | plr   | -> instrumented function lr (parent's pc)
0024  *                 +-------+
0025  */
0026 
0027 .macro mcount_enter
0028     subi    sp, 24
0029     stw a0, (sp, 0)
0030     stw a1, (sp, 4)
0031     stw a2, (sp, 8)
0032     stw a3, (sp, 12)
0033     stw lr, (sp, 16)
0034     stw r8, (sp, 20)
0035 .endm
0036 
0037 .macro mcount_exit
0038     ldw a0, (sp, 0)
0039     ldw a1, (sp, 4)
0040     ldw a2, (sp, 8)
0041     ldw a3, (sp, 12)
0042     ldw t1, (sp, 16)
0043     ldw r8, (sp, 20)
0044     ldw lr, (sp, 24)
0045     addi    sp, 28
0046     jmp t1
0047 .endm
0048 
0049 .macro mcount_enter_regs
0050     subi    sp, 8
0051     stw lr, (sp, 0)
0052     stw r8, (sp, 4)
0053     SAVE_REGS_FTRACE
0054 .endm
0055 
0056 .macro mcount_exit_regs
0057     RESTORE_REGS_FTRACE
0058     subi    sp, 152
0059     ldw t1, (sp, 4)
0060     addi    sp, 152
0061     ldw r8, (sp, 4)
0062     ldw lr, (sp, 8)
0063     addi    sp, 12
0064     jmp t1
0065 .endm
0066 
0067 .macro save_return_regs
0068     subi    sp, 16
0069     stw a0, (sp, 0)
0070     stw a1, (sp, 4)
0071     stw a2, (sp, 8)
0072     stw a3, (sp, 12)
0073 .endm
0074 
0075 .macro restore_return_regs
0076     mov lr, a0
0077     ldw a0, (sp, 0)
0078     ldw a1, (sp, 4)
0079     ldw a2, (sp, 8)
0080     ldw a3, (sp, 12)
0081     addi    sp, 16
0082 .endm
0083 
0084 .macro nop32_stub
0085     nop32
0086     nop32
0087     nop32
0088 .endm
0089 
0090 ENTRY(ftrace_stub)
0091     jmp lr
0092 END(ftrace_stub)
0093 
0094 #ifndef CONFIG_DYNAMIC_FTRACE
0095 ENTRY(_mcount)
0096     mcount_enter
0097 
0098     /* r26 is link register, only used with jsri translation */
0099     lrw r26, ftrace_trace_function
0100     ldw r26, (r26, 0)
0101     lrw a1, ftrace_stub
0102     cmpne   r26, a1
0103     bf  skip_ftrace
0104 
0105     mov a0, lr
0106     subi    a0, 4
0107     ldw a1, (sp, 24)
0108     lrw a2, function_trace_op
0109     ldw a2, (a2, 0)
0110 
0111     jsr r26
0112 
0113 #ifndef CONFIG_FUNCTION_GRAPH_TRACER
0114 skip_ftrace:
0115     mcount_exit
0116 #else
0117 skip_ftrace:
0118     lrw a0, ftrace_graph_return
0119     ldw a0, (a0, 0)
0120     lrw a1, ftrace_stub
0121     cmpne   a0, a1
0122     bt  ftrace_graph_caller
0123 
0124     lrw a0, ftrace_graph_entry
0125     ldw a0, (a0, 0)
0126     lrw a1, ftrace_graph_entry_stub
0127     cmpne   a0, a1
0128     bt  ftrace_graph_caller
0129 
0130     mcount_exit
0131 #endif
0132 END(_mcount)
0133 #else /* CONFIG_DYNAMIC_FTRACE */
0134 ENTRY(_mcount)
0135     mov t1, lr
0136     ldw lr, (sp, 0)
0137     addi    sp, 4
0138     jmp t1
0139 ENDPROC(_mcount)
0140 
0141 ENTRY(ftrace_caller)
0142     mcount_enter
0143 
0144     ldw a0, (sp, 16)
0145     subi    a0, 4
0146     ldw a1, (sp, 24)
0147     lrw a2, function_trace_op
0148     ldw a2, (a2, 0)
0149 
0150     nop
0151 GLOBAL(ftrace_call)
0152     nop32_stub
0153 
0154 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
0155     nop
0156 GLOBAL(ftrace_graph_call)
0157     nop32_stub
0158 #endif
0159 
0160     mcount_exit
0161 ENDPROC(ftrace_caller)
0162 #endif /* CONFIG_DYNAMIC_FTRACE */
0163 
0164 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
0165 ENTRY(ftrace_graph_caller)
0166     mov a0, sp
0167     addi    a0, 24
0168     ldw a1, (sp, 16)
0169     subi    a1, 4
0170     mov a2, r8
0171     lrw r26, prepare_ftrace_return
0172     jsr r26
0173     mcount_exit
0174 END(ftrace_graph_caller)
0175 
0176 ENTRY(return_to_handler)
0177     save_return_regs
0178     mov a0, r8
0179     jsri    ftrace_return_to_handler
0180     restore_return_regs
0181     jmp lr
0182 END(return_to_handler)
0183 #endif
0184 
0185 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
0186 ENTRY(ftrace_regs_caller)
0187     mcount_enter_regs
0188 
0189     lrw t1, PT_FRAME_SIZE
0190     add t1, sp
0191 
0192     ldw a0, (t1, 0)
0193     subi    a0, 4
0194     ldw a1, (t1, 8)
0195     lrw a2, function_trace_op
0196     ldw a2, (a2, 0)
0197     mov a3, sp
0198 
0199     nop
0200 GLOBAL(ftrace_regs_call)
0201     nop32_stub
0202 
0203 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
0204     nop
0205 GLOBAL(ftrace_graph_regs_call)
0206     nop32_stub
0207 #endif
0208 
0209     mcount_exit_regs
0210 ENDPROC(ftrace_regs_caller)
0211 #endif /* CONFIG_DYNAMIC_FTRACE */