2 * linux/arch/x86_64/mcount_64.S
4 * Copyright (C) 2014 Steven Rostedt, Red Hat Inc
7 #include <linux/linkage.h>
8 #include <asm/ptrace.h>
9 #include <asm/ftrace.h>
13 .section .entry.text, "ax"
16 #ifdef CONFIG_FUNCTION_TRACER
18 #ifdef CC_USING_FENTRY
19 # define function_hook __fentry__
21 # define function_hook mcount
24 #ifdef CONFIG_DYNAMIC_FTRACE
30 /* skip is set if stack has been adjusted */
31 .macro ftrace_caller_setup skip=0
32 MCOUNT_SAVE_FRAME \skip
34 /* Load the ftrace_ops into the 3rd parameter */
35 movq function_trace_op(%rip), %rdx
37 /* Load ip into the first parameter */
39 subq $MCOUNT_INSN_SIZE, %rdi
40 /* Load the parent_ip into the second parameter */
41 #ifdef CC_USING_FENTRY
42 movq SS+16(%rsp), %rsi
49 /* Check if tracing was disabled (quick check) */
50 cmpl $0, function_trace_stop
54 /* regs go into 4th parameter (but make it NULL) */
63 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64 GLOBAL(ftrace_graph_call)
72 ENTRY(ftrace_regs_caller)
73 /* Save the current flags before compare (in SS location)*/
76 /* Check if tracing was disabled (quick check) */
77 cmpl $0, function_trace_stop
78 jne ftrace_restore_flags
80 /* skip=8 to skip flags saved in SS */
83 /* Save the rest of pt_regs */
92 /* Copy saved flags */
94 movq %rcx, EFLAGS(%rsp)
96 movq $__KERNEL_DS, %rcx
98 movq $__KERNEL_CS, %rcx
100 /* Stack - skipping return address */
101 leaq SS+16(%rsp), %rcx
104 /* regs go into 4th parameter */
107 GLOBAL(ftrace_regs_call)
110 /* Copy flags back to SS, to restore them */
111 movq EFLAGS(%rsp), %rax
114 /* Handlers can change the RIP */
116 movq %rax, SS+8(%rsp)
118 /* restore the rest of pt_regs */
127 /* skip=8 to skip flags saved in SS */
128 MCOUNT_RESTORE_FRAME 8
134 ftrace_restore_flags:
138 END(ftrace_regs_caller)
141 #else /* ! CONFIG_DYNAMIC_FTRACE */
144 cmpl $0, function_trace_stop
147 cmpq $ftrace_stub, ftrace_trace_function
150 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
151 cmpq $ftrace_stub, ftrace_graph_return
152 jnz ftrace_graph_caller
154 cmpq $ftrace_graph_entry_stub, ftrace_graph_entry
155 jnz ftrace_graph_caller
165 #ifdef CC_USING_FENTRY
166 movq SS+16(%rsp), %rsi
170 subq $MCOUNT_INSN_SIZE, %rdi
172 call *ftrace_trace_function
178 #endif /* CONFIG_DYNAMIC_FTRACE */
179 #endif /* CONFIG_FUNCTION_TRACER */
181 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
182 ENTRY(ftrace_graph_caller)
185 #ifdef CC_USING_FENTRY
186 leaq SS+16(%rsp), %rdi
187 movq $0, %rdx /* No framepointers needed */
193 subq $MCOUNT_INSN_SIZE, %rsi
195 call prepare_ftrace_return
200 END(ftrace_graph_caller)
202 GLOBAL(return_to_handler)
205 /* Save the return values */
210 call ftrace_return_to_handler