1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Copyright IBM Corp. 2008, 2009 4 * 5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, 6 * 7 */ 8 9#include <linux/linkage.h> 10#include <asm/asm-offsets.h> 11#include <asm/ftrace.h> 12#include <asm/nospec-insn.h> 13#include <asm/ptrace.h> 14#include <asm/export.h> 15 16 GEN_BR_THUNK %r1 17 GEN_BR_THUNK %r14 18 19 .section .kprobes.text, "ax" 20 21ENTRY(ftrace_stub) 22 BR_EX %r14 23ENDPROC(ftrace_stub) 24 25#define STACK_FRAME_SIZE (STACK_FRAME_OVERHEAD + __PT_SIZE) 26#define STACK_PTREGS (STACK_FRAME_OVERHEAD) 27#define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS) 28#define STACK_PTREGS_PSW (STACK_PTREGS + __PT_PSW) 29 30ENTRY(_mcount) 31 BR_EX %r14 32ENDPROC(_mcount) 33EXPORT_SYMBOL(_mcount) 34 35ENTRY(ftrace_caller) 36 .globl ftrace_regs_caller 37 .set ftrace_regs_caller,ftrace_caller 38 stg %r14,(__SF_GPRS+8*8)(%r15) # save traced function caller 39 lgr %r1,%r15 40#if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT)) 41 aghi %r0,MCOUNT_RETURN_FIXUP 42#endif 43 aghi %r15,-STACK_FRAME_SIZE 44 stg %r1,__SF_BACKCHAIN(%r15) 45 stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15) 46 stg %r0,(STACK_PTREGS_PSW+8)(%r15) 47 stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15) 48#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES 49 aghik %r2,%r0,-MCOUNT_INSN_SIZE 50 lgrl %r4,function_trace_op 51 lgrl %r1,ftrace_trace_function 52#else 53 lgr %r2,%r0 54 aghi %r2,-MCOUNT_INSN_SIZE 55 larl %r4,function_trace_op 56 lg %r4,0(%r4) 57 larl %r1,ftrace_trace_function 58 lg %r1,0(%r1) 59#endif 60 lgr %r3,%r14 61 la %r5,STACK_PTREGS(%r15) 62 BASR_EX %r14,%r1 63#ifdef CONFIG_FUNCTION_GRAPH_TRACER 64# The j instruction gets runtime patched to a nop instruction. 65# See ftrace_enable_ftrace_graph_caller. 66 .globl ftrace_graph_caller 67ftrace_graph_caller: 68 j ftrace_graph_caller_end 69 lmg %r2,%r3,(STACK_PTREGS_GPRS+14*8)(%r15) 70 lg %r4,(STACK_PTREGS_PSW+8)(%r15) 71 brasl %r14,prepare_ftrace_return 72 stg %r2,(STACK_PTREGS_GPRS+14*8)(%r15) 73ftrace_graph_caller_end: 74 .globl ftrace_graph_caller_end 75#endif 76 lg %r1,(STACK_PTREGS_PSW+8)(%r15) 77 lmg %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15) 78 BR_EX %r1 79ENDPROC(ftrace_caller) 80 81#ifdef CONFIG_FUNCTION_GRAPH_TRACER 82 83ENTRY(return_to_handler) 84 stmg %r2,%r5,32(%r15) 85 lgr %r1,%r15 86 aghi %r15,-STACK_FRAME_OVERHEAD 87 stg %r1,__SF_BACKCHAIN(%r15) 88 brasl %r14,ftrace_return_to_handler 89 aghi %r15,STACK_FRAME_OVERHEAD 90 lgr %r14,%r2 91 lmg %r2,%r5,32(%r15) 92 BR_EX %r14 93ENDPROC(return_to_handler) 94 95#endif 96