1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Copyright (C) 2017 Andes Technology Corporation */ 3 4#include <linux/init.h> 5#include <linux/linkage.h> 6#include <asm/asm.h> 7#include <asm/csr.h> 8#include <asm/unistd.h> 9#include <asm/thread_info.h> 10#include <asm/asm-offsets.h> 11#include <asm-generic/export.h> 12#include <asm/ftrace.h> 13 14 .text 15 16#define FENTRY_RA_OFFSET 8 17#define ABI_SIZE_ON_STACK 80 18#define ABI_A0 0 19#define ABI_A1 8 20#define ABI_A2 16 21#define ABI_A3 24 22#define ABI_A4 32 23#define ABI_A5 40 24#define ABI_A6 48 25#define ABI_A7 56 26#define ABI_T0 64 27#define ABI_RA 72 28 29 .macro SAVE_ABI 30 addi sp, sp, -ABI_SIZE_ON_STACK 31 32 REG_S a0, ABI_A0(sp) 33 REG_S a1, ABI_A1(sp) 34 REG_S a2, ABI_A2(sp) 35 REG_S a3, ABI_A3(sp) 36 REG_S a4, ABI_A4(sp) 37 REG_S a5, ABI_A5(sp) 38 REG_S a6, ABI_A6(sp) 39 REG_S a7, ABI_A7(sp) 40 REG_S t0, ABI_T0(sp) 41 REG_S ra, ABI_RA(sp) 42 .endm 43 44 .macro RESTORE_ABI 45 REG_L a0, ABI_A0(sp) 46 REG_L a1, ABI_A1(sp) 47 REG_L a2, ABI_A2(sp) 48 REG_L a3, ABI_A3(sp) 49 REG_L a4, ABI_A4(sp) 50 REG_L a5, ABI_A5(sp) 51 REG_L a6, ABI_A6(sp) 52 REG_L a7, ABI_A7(sp) 53 REG_L t0, ABI_T0(sp) 54 REG_L ra, ABI_RA(sp) 55 56 addi sp, sp, ABI_SIZE_ON_STACK 57 .endm 58 59#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 60 .macro SAVE_ALL 61 addi sp, sp, -PT_SIZE_ON_STACK 62 63 REG_S t0, PT_EPC(sp) 64 REG_S x1, PT_RA(sp) 65 REG_S x2, PT_SP(sp) 66 REG_S x3, PT_GP(sp) 67 REG_S x4, PT_TP(sp) 68 REG_S x5, PT_T0(sp) 69 REG_S x6, PT_T1(sp) 70 REG_S x7, PT_T2(sp) 71 REG_S x8, PT_S0(sp) 72 REG_S x9, PT_S1(sp) 73 REG_S x10, PT_A0(sp) 74 REG_S x11, PT_A1(sp) 75 REG_S x12, PT_A2(sp) 76 REG_S x13, PT_A3(sp) 77 REG_S x14, PT_A4(sp) 78 REG_S x15, PT_A5(sp) 79 REG_S x16, PT_A6(sp) 80 REG_S x17, PT_A7(sp) 81 REG_S x18, PT_S2(sp) 82 REG_S x19, PT_S3(sp) 83 REG_S x20, PT_S4(sp) 84 REG_S x21, PT_S5(sp) 85 REG_S x22, PT_S6(sp) 86 REG_S x23, PT_S7(sp) 87 REG_S x24, PT_S8(sp) 88 REG_S x25, PT_S9(sp) 89 REG_S x26, PT_S10(sp) 90 REG_S x27, PT_S11(sp) 91 REG_S x28, PT_T3(sp) 92 REG_S x29, PT_T4(sp) 93 REG_S x30, PT_T5(sp) 94 REG_S x31, PT_T6(sp) 95 .endm 96 97 .macro RESTORE_ALL 98 REG_L t0, PT_EPC(sp) 99 REG_L x1, PT_RA(sp) 100 REG_L x2, PT_SP(sp) 101 REG_L x3, PT_GP(sp) 102 REG_L x4, PT_TP(sp) 103 REG_L x6, PT_T1(sp) 104 REG_L x7, PT_T2(sp) 105 REG_L x8, PT_S0(sp) 106 REG_L x9, PT_S1(sp) 107 REG_L x10, PT_A0(sp) 108 REG_L x11, PT_A1(sp) 109 REG_L x12, PT_A2(sp) 110 REG_L x13, PT_A3(sp) 111 REG_L x14, PT_A4(sp) 112 REG_L x15, PT_A5(sp) 113 REG_L x16, PT_A6(sp) 114 REG_L x17, PT_A7(sp) 115 REG_L x18, PT_S2(sp) 116 REG_L x19, PT_S3(sp) 117 REG_L x20, PT_S4(sp) 118 REG_L x21, PT_S5(sp) 119 REG_L x22, PT_S6(sp) 120 REG_L x23, PT_S7(sp) 121 REG_L x24, PT_S8(sp) 122 REG_L x25, PT_S9(sp) 123 REG_L x26, PT_S10(sp) 124 REG_L x27, PT_S11(sp) 125 REG_L x28, PT_T3(sp) 126 REG_L x29, PT_T4(sp) 127 REG_L x30, PT_T5(sp) 128 REG_L x31, PT_T6(sp) 129 130 addi sp, sp, PT_SIZE_ON_STACK 131 .endm 132#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ 133 134ENTRY(ftrace_caller) 135 SAVE_ABI 136 137 addi a0, t0, -FENTRY_RA_OFFSET 138 la a1, function_trace_op 139 REG_L a2, 0(a1) 140 mv a1, ra 141 mv a3, sp 142 143ftrace_call: 144 .global ftrace_call 145 call ftrace_stub 146 147#ifdef CONFIG_FUNCTION_GRAPH_TRACER 148 addi a0, sp, ABI_RA 149 REG_L a1, ABI_T0(sp) 150 addi a1, a1, -FENTRY_RA_OFFSET 151#ifdef HAVE_FUNCTION_GRAPH_FP_TEST 152 mv a2, s0 153#endif 154ftrace_graph_call: 155 .global ftrace_graph_call 156 call ftrace_stub 157#endif 158 RESTORE_ABI 159 jr t0 160ENDPROC(ftrace_caller) 161 162#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 163ENTRY(ftrace_regs_caller) 164 SAVE_ALL 165 166 addi a0, t0, -FENTRY_RA_OFFSET 167 la a1, function_trace_op 168 REG_L a2, 0(a1) 169 mv a1, ra 170 mv a3, sp 171 172ftrace_regs_call: 173 .global ftrace_regs_call 174 call ftrace_stub 175 176#ifdef CONFIG_FUNCTION_GRAPH_TRACER 177 addi a0, sp, PT_RA 178 REG_L a1, PT_EPC(sp) 179 addi a1, a1, -FENTRY_RA_OFFSET 180#ifdef HAVE_FUNCTION_GRAPH_FP_TEST 181 mv a2, s0 182#endif 183ftrace_graph_regs_call: 184 .global ftrace_graph_regs_call 185 call ftrace_stub 186#endif 187 188 RESTORE_ALL 189 jr t0 190ENDPROC(ftrace_regs_caller) 191#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ 192