Linux Audio

Check our new training course

Loading...
v5.9
  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	.macro SAVE_ABI_STATE
 17#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 18	addi    sp, sp, -48
 19	sd      s0, 32(sp)
 20	sd      ra, 40(sp)
 21	addi    s0, sp, 48
 22	sd      t0, 24(sp)
 23	sd      t1, 16(sp)
 24#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
 25	sd      t2, 8(sp)
 26#endif
 27#else
 28	addi	sp, sp, -16
 29	sd	s0, 0(sp)
 30	sd	ra, 8(sp)
 31	addi	s0, sp, 16
 32#endif
 
 
 
 
 
 
 
 
 
 33	.endm
 34
 35	.macro RESTORE_ABI_STATE
 36#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 37	ld	s0, 32(sp)
 38	ld	ra, 40(sp)
 39	addi	sp, sp, 48
 40#else
 41	ld	ra, 8(sp)
 42	ld	s0, 0(sp)
 43	addi	sp, sp, 16
 44#endif
 45	.endm
 46
 47	.macro RESTORE_GRAPH_ARGS
 48	ld	a0, 24(sp)
 49	ld	a1, 16(sp)
 50#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
 51	ld	a2, 8(sp)
 52#endif
 53	.endm
 54
 55ENTRY(ftrace_graph_caller)
 56	addi	sp, sp, -16
 57	sd	s0, 0(sp)
 58	sd	ra, 8(sp)
 59	addi	s0, sp, 16
 60ftrace_graph_call:
 61	.global ftrace_graph_call
 62	/*
 63	 * Calling ftrace_enable/disable_ftrace_graph_caller would overwrite the
 64	 * call below.  Check ftrace_modify_all_code for details.
 65	 */
 66	call	ftrace_stub
 67	ld	ra, 8(sp)
 68	ld	s0, 0(sp)
 69	addi	sp, sp, 16
 70	ret
 71ENDPROC(ftrace_graph_caller)
 72
 73ENTRY(ftrace_caller)
 74	/*
 75	 * a0: the address in the caller when calling ftrace_caller
 76	 * a1: the caller's return address
 77	 * a2: the address of global variable function_trace_op
 78	 */
 79	ld	a1, -8(s0)
 80	addi	a0, ra, -MCOUNT_INSN_SIZE
 81	la	t5, function_trace_op
 82	ld	a2, 0(t5)
 83
 84#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 85	/*
 86	 * the graph tracer (specifically, prepare_ftrace_return) needs these
 87	 * arguments but for now the function tracer occupies the regs, so we
 88	 * save them in temporary regs to recover later.
 89	 */
 90	addi	t0, s0, -8
 91	mv	t1, a0
 92#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
 93	ld	t2, -16(s0)
 94#endif
 95#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 96
 97	SAVE_ABI_STATE
 98ftrace_call:
 99	.global ftrace_call
100	/*
101	 * For the dynamic ftrace to work, here we should reserve at least
102	 * 8 bytes for a functional auipc-jalr pair.  The following call
103	 * serves this purpose.
104	 *
105	 * Calling ftrace_update_ftrace_func would overwrite the nops below.
106	 * Check ftrace_modify_all_code for details.
107	 */
108	call	ftrace_stub
109
110#ifdef CONFIG_FUNCTION_GRAPH_TRACER
111	RESTORE_GRAPH_ARGS
112	call	ftrace_graph_caller
113#endif
114
115	RESTORE_ABI_STATE
116	ret
117ENDPROC(ftrace_caller)
118
119#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
120	.macro SAVE_ALL
121	addi	sp, sp, -(PT_SIZE_ON_STACK+16)
122	sd	s0, (PT_SIZE_ON_STACK)(sp)
123	sd	ra, (PT_SIZE_ON_STACK+8)(sp)
124	addi	s0, sp, (PT_SIZE_ON_STACK+16)
125
126	sd x1,  PT_RA(sp)
127	sd x2,  PT_SP(sp)
128	sd x3,  PT_GP(sp)
129	sd x4,  PT_TP(sp)
130	sd x5,  PT_T0(sp)
131	sd x6,  PT_T1(sp)
132	sd x7,  PT_T2(sp)
133	sd x8,  PT_S0(sp)
134	sd x9,  PT_S1(sp)
135	sd x10, PT_A0(sp)
136	sd x11, PT_A1(sp)
137	sd x12, PT_A2(sp)
138	sd x13, PT_A3(sp)
139	sd x14, PT_A4(sp)
140	sd x15, PT_A5(sp)
141	sd x16, PT_A6(sp)
142	sd x17, PT_A7(sp)
143	sd x18, PT_S2(sp)
144	sd x19, PT_S3(sp)
145	sd x20, PT_S4(sp)
146	sd x21, PT_S5(sp)
147	sd x22, PT_S6(sp)
148	sd x23, PT_S7(sp)
149	sd x24, PT_S8(sp)
150	sd x25, PT_S9(sp)
151	sd x26, PT_S10(sp)
152	sd x27, PT_S11(sp)
153	sd x28, PT_T3(sp)
154	sd x29, PT_T4(sp)
155	sd x30, PT_T5(sp)
156	sd x31, PT_T6(sp)
157	.endm
158
159	.macro RESTORE_ALL
160	ld x1,  PT_RA(sp)
161	ld x2,  PT_SP(sp)
162	ld x3,  PT_GP(sp)
163	ld x4,  PT_TP(sp)
164	ld x5,  PT_T0(sp)
165	ld x6,  PT_T1(sp)
166	ld x7,  PT_T2(sp)
167	ld x8,  PT_S0(sp)
168	ld x9,  PT_S1(sp)
169	ld x10, PT_A0(sp)
170	ld x11, PT_A1(sp)
171	ld x12, PT_A2(sp)
172	ld x13, PT_A3(sp)
173	ld x14, PT_A4(sp)
174	ld x15, PT_A5(sp)
175	ld x16, PT_A6(sp)
176	ld x17, PT_A7(sp)
177	ld x18, PT_S2(sp)
178	ld x19, PT_S3(sp)
179	ld x20, PT_S4(sp)
180	ld x21, PT_S5(sp)
181	ld x22, PT_S6(sp)
182	ld x23, PT_S7(sp)
183	ld x24, PT_S8(sp)
184	ld x25, PT_S9(sp)
185	ld x26, PT_S10(sp)
186	ld x27, PT_S11(sp)
187	ld x28, PT_T3(sp)
188	ld x29, PT_T4(sp)
189	ld x30, PT_T5(sp)
190	ld x31, PT_T6(sp)
191
192	ld	s0, (PT_SIZE_ON_STACK)(sp)
193	ld	ra, (PT_SIZE_ON_STACK+8)(sp)
194	addi	sp, sp, (PT_SIZE_ON_STACK+16)
195	.endm
196
197	.macro RESTORE_GRAPH_REG_ARGS
198	ld	a0, PT_T0(sp)
199	ld	a1, PT_T1(sp)
200#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
201	ld	a2, PT_T2(sp)
202#endif
 
 
203	.endm
204
205/*
206 * Most of the contents are the same as ftrace_caller.
207 */
208ENTRY(ftrace_regs_caller)
209	/*
210	 * a3: the address of all registers in the stack
211	 */
212	ld	a1, -8(s0)
213	addi	a0, ra, -MCOUNT_INSN_SIZE
214	la	t5, function_trace_op
215	ld	a2, 0(t5)
216	addi	a3, sp, -(PT_SIZE_ON_STACK+16)
 
 
 
 
 
 
 
 
 
 
217
218#ifdef CONFIG_FUNCTION_GRAPH_TRACER
219	addi	t0, s0, -8
220	mv	t1, a0
 
221#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
222	ld	t2, -16(s0)
223#endif
 
 
224#endif
225	SAVE_ALL
 
 
 
 
 
 
 
 
226
227ftrace_regs_call:
228	.global ftrace_regs_call
229	call	ftrace_stub
230
231#ifdef CONFIG_FUNCTION_GRAPH_TRACER
232	RESTORE_GRAPH_REG_ARGS
233	call	ftrace_graph_caller
234#endif
 
 
 
 
 
 
 
 
 
235
236	RESTORE_ALL
237	ret
238ENDPROC(ftrace_regs_caller)
239#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
v6.9.4
  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 <linux/export.h>
  7#include <asm/asm.h>
  8#include <asm/csr.h>
  9#include <asm/unistd.h>
 10#include <asm/thread_info.h>
 11#include <asm/asm-offsets.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
 61/**
 62* SAVE_ABI_REGS - save regs against the pt_regs struct
 63*
 64* @all: tell if saving all the regs
 65*
 66* If all is set, all the regs will be saved, otherwise only ABI
 67* related regs (a0-a7,epc,ra and optional s0) will be saved.
 68*
 69* After the stack is established,
 70*
 71* 0(sp) stores the PC of the traced function which can be accessed
 72* by &(fregs)->regs->epc in tracing function. Note that the real
 73* function entry address should be computed with -FENTRY_RA_OFFSET.
 74*
 75* 8(sp) stores the function return address (i.e. parent IP) that
 76* can be accessed by &(fregs)->regs->ra in tracing function.
 77*
 78* The other regs are saved at the respective localtion and accessed
 79* by the respective pt_regs member.
 80*
 81* Here is the layout of stack for your reference.
 82*
 83* PT_SIZE_ON_STACK  ->  +++++++++
 84*                       + ..... +
 85*                       + t3-t6 +
 86*                       + s2-s11+
 87*                       + a0-a7 + --++++-> ftrace_caller saved
 88*                       + s1    +   +
 89*                       + s0    + --+
 90*                       + t0-t2 +   +
 91*                       + tp    +   +
 92*                       + gp    +   +
 93*                       + sp    +   +
 94*                       + ra    + --+ // parent IP
 95*               sp  ->  + epc   + --+ // PC
 96*                       +++++++++
 97**/
 98	.macro SAVE_ABI_REGS, all=0
 99	addi	sp, sp, -PT_SIZE_ON_STACK
100
101	REG_S	t0,  PT_EPC(sp)
102	REG_S	x1,  PT_RA(sp)
103
104	// save the ABI regs
105
106	REG_S	x10, PT_A0(sp)
107	REG_S	x11, PT_A1(sp)
108	REG_S	x12, PT_A2(sp)
109	REG_S	x13, PT_A3(sp)
110	REG_S	x14, PT_A4(sp)
111	REG_S	x15, PT_A5(sp)
112	REG_S	x16, PT_A6(sp)
113	REG_S	x17, PT_A7(sp)
114
115	// save the leftover regs
116
117	.if \all == 1
118	REG_S	x2, PT_SP(sp)
119	REG_S	x3, PT_GP(sp)
120	REG_S	x4, PT_TP(sp)
121	REG_S	x5, PT_T0(sp)
122	REG_S	x6, PT_T1(sp)
123	REG_S	x7, PT_T2(sp)
124	REG_S	x8, PT_S0(sp)
125	REG_S	x9, PT_S1(sp)
126	REG_S	x18, PT_S2(sp)
127	REG_S	x19, PT_S3(sp)
128	REG_S	x20, PT_S4(sp)
129	REG_S	x21, PT_S5(sp)
130	REG_S	x22, PT_S6(sp)
131	REG_S	x23, PT_S7(sp)
132	REG_S	x24, PT_S8(sp)
133	REG_S	x25, PT_S9(sp)
134	REG_S	x26, PT_S10(sp)
135	REG_S	x27, PT_S11(sp)
136	REG_S	x28, PT_T3(sp)
137	REG_S	x29, PT_T4(sp)
138	REG_S	x30, PT_T5(sp)
139	REG_S	x31, PT_T6(sp)
140
141	// save s0 if FP_TEST defined
 
 
 
 
 
 
 
 
 
 
 
142
143	.else
144#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
145	REG_S	x8, PT_S0(sp)
146#endif
147	.endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148	.endm
149
150	.macro RESTORE_ABI_REGS, all=0
151	REG_L	t0, PT_EPC(sp)
152	REG_L	x1, PT_RA(sp)
153	REG_L	x10, PT_A0(sp)
154	REG_L	x11, PT_A1(sp)
155	REG_L	x12, PT_A2(sp)
156	REG_L	x13, PT_A3(sp)
157	REG_L	x14, PT_A4(sp)
158	REG_L	x15, PT_A5(sp)
159	REG_L	x16, PT_A6(sp)
160	REG_L	x17, PT_A7(sp)
161
162	.if \all == 1
163	REG_L	x2, PT_SP(sp)
164	REG_L	x3, PT_GP(sp)
165	REG_L	x4, PT_TP(sp)
166	REG_L	x6, PT_T1(sp)
167	REG_L	x7, PT_T2(sp)
168	REG_L	x8, PT_S0(sp)
169	REG_L	x9, PT_S1(sp)
170	REG_L	x18, PT_S2(sp)
171	REG_L	x19, PT_S3(sp)
172	REG_L	x20, PT_S4(sp)
173	REG_L	x21, PT_S5(sp)
174	REG_L	x22, PT_S6(sp)
175	REG_L	x23, PT_S7(sp)
176	REG_L	x24, PT_S8(sp)
177	REG_L	x25, PT_S9(sp)
178	REG_L	x26, PT_S10(sp)
179	REG_L	x27, PT_S11(sp)
180	REG_L	x28, PT_T3(sp)
181	REG_L	x29, PT_T4(sp)
182	REG_L	x30, PT_T5(sp)
183	REG_L	x31, PT_T6(sp)
 
 
 
184
185	.else
 
 
186#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
187	REG_L	x8, PT_S0(sp)
188#endif
189	.endif
190	addi	sp, sp, PT_SIZE_ON_STACK
191	.endm
192
193	.macro PREPARE_ARGS
194	addi	a0, t0, -FENTRY_RA_OFFSET
195	la	a1, function_trace_op
196	REG_L	a2, 0(a1)
197	mv	a1, ra
198	mv	a3, sp
199	.endm
200
201#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
202
203#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS
204SYM_FUNC_START(ftrace_caller)
205	SAVE_ABI
206
207	addi	a0, t0, -FENTRY_RA_OFFSET
208	la	a1, function_trace_op
209	REG_L	a2, 0(a1)
210	mv	a1, ra
211	mv	a3, sp
212
213SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
214	call	ftrace_stub
215
216#ifdef CONFIG_FUNCTION_GRAPH_TRACER
217	addi	a0, sp, ABI_RA
218	REG_L	a1, ABI_T0(sp)
219	addi	a1, a1, -FENTRY_RA_OFFSET
220#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
221	mv	a2, s0
222#endif
223SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL)
224	call	ftrace_stub
225#endif
226	RESTORE_ABI
227	jr	t0
228SYM_FUNC_END(ftrace_caller)
229
230#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
231SYM_FUNC_START(ftrace_regs_caller)
232	mv	t1, zero
233	SAVE_ABI_REGS 1
234	PREPARE_ARGS
235
236SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL)
 
237	call	ftrace_stub
238
239	RESTORE_ABI_REGS 1
240	bnez	t1, .Ldirect
241	jr	t0
242.Ldirect:
243	jr	t1
244SYM_FUNC_END(ftrace_regs_caller)
245
246SYM_FUNC_START(ftrace_caller)
247	SAVE_ABI_REGS 0
248	PREPARE_ARGS
249
250SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
251	call	ftrace_stub
252
253	RESTORE_ABI_REGS 0
254	jr	t0
255SYM_FUNC_END(ftrace_caller)
256#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
257
258#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
259SYM_CODE_START(ftrace_stub_direct_tramp)
260	jr	t0
261SYM_CODE_END(ftrace_stub_direct_tramp)
262#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */