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#ifdef __PACK_STACK 30/* allocate just enough for r14, r15 and backchain */ 31#define TRACED_FUNC_FRAME_SIZE 24 32#else 33#define TRACED_FUNC_FRAME_SIZE STACK_FRAME_OVERHEAD 34#endif 35 36ENTRY(ftrace_caller) 37 .globl ftrace_regs_caller 38 .set ftrace_regs_caller,ftrace_caller 39 stg %r14,(__SF_GPRS+8*8)(%r15) # save traced function caller 40 lghi %r14,0 # save condition code 41 ipm %r14 # don't put any instructions 42 sllg %r14,%r14,16 # clobbering CC before this point 43 lgr %r1,%r15 44 # allocate stack frame for ftrace_caller to contain traced function 45 aghi %r15,-TRACED_FUNC_FRAME_SIZE 46 stg %r1,__SF_BACKCHAIN(%r15) 47 stg %r0,(__SF_GPRS+8*8)(%r15) 48 stg %r15,(__SF_GPRS+9*8)(%r15) 49 # allocate pt_regs and stack frame for ftrace_trace_function 50 aghi %r15,-STACK_FRAME_SIZE 51 stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15) 52 stg %r14,(STACK_PTREGS_PSW)(%r15) 53 lg %r14,(__SF_GPRS+8*8)(%r1) # restore original return address 54 stosm (STACK_PTREGS_PSW)(%r15),0 55 aghi %r1,-TRACED_FUNC_FRAME_SIZE 56 stg %r1,__SF_BACKCHAIN(%r15) 57 stg %r0,(STACK_PTREGS_PSW+8)(%r15) 58 stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15) 59#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES 60 aghik %r2,%r0,-MCOUNT_INSN_SIZE 61 lgrl %r4,function_trace_op 62 lgrl %r1,ftrace_trace_function 63#else 64 lgr %r2,%r0 65 aghi %r2,-MCOUNT_INSN_SIZE 66 larl %r4,function_trace_op 67 lg %r4,0(%r4) 68 larl %r1,ftrace_trace_function 69 lg %r1,0(%r1) 70#endif 71 lgr %r3,%r14 72 la %r5,STACK_PTREGS(%r15) 73 BASR_EX %r14,%r1 74#ifdef CONFIG_FUNCTION_GRAPH_TRACER 75# The j instruction gets runtime patched to a nop instruction. 76# See ftrace_enable_ftrace_graph_caller. 77 .globl ftrace_graph_caller 78ftrace_graph_caller: 79 j ftrace_graph_caller_end 80 lmg %r2,%r3,(STACK_PTREGS_GPRS+14*8)(%r15) 81 lg %r4,(STACK_PTREGS_PSW+8)(%r15) 82 brasl %r14,prepare_ftrace_return 83 stg %r2,(STACK_PTREGS_GPRS+14*8)(%r15) 84ftrace_graph_caller_end: 85 .globl ftrace_graph_caller_end 86#endif 87 lg %r1,(STACK_PTREGS_PSW+8)(%r15) 88 lmg %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15) 89 BR_EX %r1 90ENDPROC(ftrace_caller) 91 92#ifdef CONFIG_FUNCTION_GRAPH_TRACER 93 94ENTRY(return_to_handler) 95 stmg %r2,%r5,32(%r15) 96 lgr %r1,%r15 97 aghi %r15,-STACK_FRAME_OVERHEAD 98 stg %r1,__SF_BACKCHAIN(%r15) 99 brasl %r14,ftrace_return_to_handler 100 aghi %r15,STACK_FRAME_OVERHEAD 101 lgr %r14,%r2 102 lmg %r2,%r5,32(%r15) 103 BR_EX %r14 104ENDPROC(return_to_handler) 105 106#endif 107