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
50 /* regs go into 4th parameter (but make it NULL) */
59 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60 GLOBAL(ftrace_graph_call)
68 ENTRY(ftrace_regs_caller)
69 /* Save the current flags before compare (in SS location)*/
72 /* skip=8 to skip flags saved in SS */
75 /* Save the rest of pt_regs */
84 /* Copy saved flags */
86 movq %rcx, EFLAGS(%rsp)
88 movq $__KERNEL_DS, %rcx
90 movq $__KERNEL_CS, %rcx
92 /* Stack - skipping return address */
93 leaq SS+16(%rsp), %rcx
96 /* regs go into 4th parameter */
99 GLOBAL(ftrace_regs_call)
102 /* Copy flags back to SS, to restore them */
103 movq EFLAGS(%rsp), %rax
106 /* Handlers can change the RIP */
108 movq %rax, SS+8(%rsp)
110 /* restore the rest of pt_regs */
119 /* skip=8 to skip flags saved in SS */
120 MCOUNT_RESTORE_FRAME 8
130 END(ftrace_regs_caller)
133 #else /* ! CONFIG_DYNAMIC_FTRACE */
136 cmpq $ftrace_stub, ftrace_trace_function
139 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
140 cmpq $ftrace_stub, ftrace_graph_return
141 jnz ftrace_graph_caller
143 cmpq $ftrace_graph_entry_stub, ftrace_graph_entry
144 jnz ftrace_graph_caller
154 #ifdef CC_USING_FENTRY
155 movq SS+16(%rsp), %rsi
159 subq $MCOUNT_INSN_SIZE, %rdi
161 call *ftrace_trace_function
167 #endif /* CONFIG_DYNAMIC_FTRACE */
168 #endif /* CONFIG_FUNCTION_TRACER */
170 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
171 ENTRY(ftrace_graph_caller)
174 #ifdef CC_USING_FENTRY
175 leaq SS+16(%rsp), %rdi
176 movq $0, %rdx /* No framepointers needed */
182 subq $MCOUNT_INSN_SIZE, %rsi
184 call prepare_ftrace_return
189 END(ftrace_graph_caller)
191 GLOBAL(return_to_handler)
194 /* Save the return values */
199 call ftrace_return_to_handler