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 trace_label skip=0
32 MCOUNT_SAVE_FRAME \skip
34 /* Save this location */
36 /* Load the ftrace_ops into the 3rd parameter */
37 movq function_trace_op(%rip), %rdx
39 /* Load ip into the first parameter */
41 subq $MCOUNT_INSN_SIZE, %rdi
42 /* Load the parent_ip into the second parameter */
43 #ifdef CC_USING_FENTRY
44 movq SS+16(%rsp), %rsi
51 ftrace_caller_setup ftrace_caller_op_ptr
52 /* regs go into 4th parameter (but make it NULL) */
61 * The copied trampoline must call ftrace_return as it
62 * still may need to call the function graph tracer.
64 GLOBAL(ftrace_caller_end)
68 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
69 GLOBAL(ftrace_graph_call)
77 ENTRY(ftrace_regs_caller)
78 /* Save the current flags before compare (in SS location)*/
81 /* skip=8 to skip flags saved in SS */
82 ftrace_caller_setup ftrace_regs_caller_op_ptr 8
84 /* Save the rest of pt_regs */
93 /* Copy saved flags */
95 movq %rcx, EFLAGS(%rsp)
97 movq $__KERNEL_DS, %rcx
99 movq $__KERNEL_CS, %rcx
101 /* Stack - skipping return address */
102 leaq SS+16(%rsp), %rcx
105 /* regs go into 4th parameter */
108 GLOBAL(ftrace_regs_call)
111 /* Copy flags back to SS, to restore them */
112 movq EFLAGS(%rsp), %rax
115 /* Handlers can change the RIP */
117 movq %rax, SS+8(%rsp)
119 /* restore the rest of pt_regs */
128 /* skip=8 to skip flags saved in SS */
129 MCOUNT_RESTORE_FRAME 8
135 * As this jmp to ftrace_return can be a short jump
136 * it must not be copied into the trampoline.
137 * The trampoline will add the code to jump
140 GLOBAL(ftrace_regs_caller_end)
147 END(ftrace_regs_caller)
150 #else /* ! CONFIG_DYNAMIC_FTRACE */
153 cmpq $ftrace_stub, ftrace_trace_function
156 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
157 cmpq $ftrace_stub, ftrace_graph_return
158 jnz ftrace_graph_caller
160 cmpq $ftrace_graph_entry_stub, ftrace_graph_entry
161 jnz ftrace_graph_caller
171 #ifdef CC_USING_FENTRY
172 movq SS+16(%rsp), %rsi
176 subq $MCOUNT_INSN_SIZE, %rdi
178 call *ftrace_trace_function
184 #endif /* CONFIG_DYNAMIC_FTRACE */
185 #endif /* CONFIG_FUNCTION_TRACER */
187 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
188 ENTRY(ftrace_graph_caller)
191 #ifdef CC_USING_FENTRY
192 leaq SS+16(%rsp), %rdi
193 movq $0, %rdx /* No framepointers needed */
199 subq $MCOUNT_INSN_SIZE, %rsi
201 call prepare_ftrace_return
206 END(ftrace_graph_caller)
208 GLOBAL(return_to_handler)
211 /* Save the return values */
216 call ftrace_return_to_handler