2017-12-18 17:52:48 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Copyright (C) 2017 Andes Technology Corporation */
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/linkage.h>
|
2023-07-11 02:35:47 +08:00
|
|
|
#include <linux/cfi_types.h>
|
2023-12-15 03:19:22 +08:00
|
|
|
#include <linux/export.h>
|
2017-12-18 17:52:48 +08:00
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/csr.h>
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
#include <asm/thread_info.h>
|
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
#include <asm/ftrace.h>
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
.macro SAVE_ABI_STATE
|
|
|
|
addi sp, sp, -16
|
2022-11-16 04:08:30 +08:00
|
|
|
REG_S s0, 0*SZREG(sp)
|
|
|
|
REG_S ra, 1*SZREG(sp)
|
2017-12-18 17:52:48 +08:00
|
|
|
addi s0, sp, 16
|
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The call to ftrace_return_to_handler would overwrite the return
|
|
|
|
* register if a0 was not saved.
|
|
|
|
*/
|
|
|
|
.macro SAVE_RET_ABI_STATE
|
2022-11-16 04:08:30 +08:00
|
|
|
addi sp, sp, -4*SZREG
|
|
|
|
REG_S s0, 2*SZREG(sp)
|
|
|
|
REG_S ra, 3*SZREG(sp)
|
|
|
|
REG_S a0, 1*SZREG(sp)
|
2022-11-16 04:08:31 +08:00
|
|
|
REG_S a1, 0*SZREG(sp)
|
2022-11-16 04:08:30 +08:00
|
|
|
addi s0, sp, 4*SZREG
|
2017-12-18 17:52:48 +08:00
|
|
|
.endm
|
|
|
|
|
2018-02-13 13:13:17 +08:00
|
|
|
.macro RESTORE_ABI_STATE
|
2022-11-16 04:08:30 +08:00
|
|
|
REG_L ra, 1*SZREG(sp)
|
|
|
|
REG_L s0, 0*SZREG(sp)
|
2017-12-18 17:52:48 +08:00
|
|
|
addi sp, sp, 16
|
|
|
|
.endm
|
|
|
|
|
2018-02-13 13:13:17 +08:00
|
|
|
.macro RESTORE_RET_ABI_STATE
|
2022-11-16 04:08:30 +08:00
|
|
|
REG_L ra, 3*SZREG(sp)
|
|
|
|
REG_L s0, 2*SZREG(sp)
|
|
|
|
REG_L a0, 1*SZREG(sp)
|
2022-11-16 04:08:31 +08:00
|
|
|
REG_L a1, 0*SZREG(sp)
|
2022-11-16 04:08:30 +08:00
|
|
|
addi sp, sp, 4*SZREG
|
2017-12-18 17:52:48 +08:00
|
|
|
.endm
|
|
|
|
|
2023-07-11 02:35:47 +08:00
|
|
|
SYM_TYPED_FUNC_START(ftrace_stub)
|
2018-02-13 13:13:17 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
2024-01-26 06:55:13 +08:00
|
|
|
.global _mcount
|
|
|
|
.set _mcount, ftrace_stub
|
2018-02-13 13:13:17 +08:00
|
|
|
#endif
|
2017-12-18 17:52:48 +08:00
|
|
|
ret
|
2023-07-11 02:35:47 +08:00
|
|
|
SYM_FUNC_END(ftrace_stub)
|
2017-12-18 17:52:48 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
2023-07-11 02:35:48 +08:00
|
|
|
SYM_TYPED_FUNC_START(ftrace_stub_graph)
|
|
|
|
ret
|
|
|
|
SYM_FUNC_END(ftrace_stub_graph)
|
|
|
|
|
2023-10-24 21:26:52 +08:00
|
|
|
SYM_FUNC_START(return_to_handler)
|
2017-12-18 17:52:48 +08:00
|
|
|
/*
|
|
|
|
* On implementing the frame point test, the ideal way is to compare the
|
|
|
|
* s0 (frame pointer, if enabled) on entry and the sp (stack pointer) on return.
|
|
|
|
* However, the psABI of variable-length-argument functions does not allow this.
|
|
|
|
*
|
|
|
|
* So alternatively we check the *old* frame pointer position, that is, the
|
|
|
|
* value stored in -16(s0) on entry, and the s0 on return.
|
|
|
|
*/
|
|
|
|
SAVE_RET_ABI_STATE
|
2023-04-08 20:42:19 +08:00
|
|
|
mv a0, sp
|
2018-02-13 13:13:17 +08:00
|
|
|
call ftrace_return_to_handler
|
2022-11-16 04:08:31 +08:00
|
|
|
mv a2, a0
|
2018-02-13 13:13:17 +08:00
|
|
|
RESTORE_RET_ABI_STATE
|
2022-11-16 04:08:31 +08:00
|
|
|
jalr a2
|
2023-10-24 21:26:52 +08:00
|
|
|
SYM_FUNC_END(return_to_handler)
|
2017-12-18 17:52:48 +08:00
|
|
|
#endif
|
|
|
|
|
2018-02-13 13:13:17 +08:00
|
|
|
#ifndef CONFIG_DYNAMIC_FTRACE
|
2024-01-26 06:55:13 +08:00
|
|
|
SYM_FUNC_START(_mcount)
|
2017-12-18 17:52:48 +08:00
|
|
|
la t4, ftrace_stub
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
|
|
|
la t0, ftrace_graph_return
|
2022-11-16 04:08:29 +08:00
|
|
|
REG_L t1, 0(t0)
|
2023-10-24 21:26:51 +08:00
|
|
|
bne t1, t4, .Ldo_ftrace_graph_caller
|
2017-12-18 17:52:48 +08:00
|
|
|
|
|
|
|
la t3, ftrace_graph_entry
|
2022-11-16 04:08:29 +08:00
|
|
|
REG_L t2, 0(t3)
|
2017-12-18 17:52:48 +08:00
|
|
|
la t6, ftrace_graph_entry_stub
|
2023-10-24 21:26:51 +08:00
|
|
|
bne t2, t6, .Ldo_ftrace_graph_caller
|
2017-12-18 17:52:48 +08:00
|
|
|
#endif
|
|
|
|
la t3, ftrace_trace_function
|
2022-11-16 04:08:29 +08:00
|
|
|
REG_L t5, 0(t3)
|
2023-10-24 21:26:51 +08:00
|
|
|
bne t5, t4, .Ldo_trace
|
2017-12-18 17:52:48 +08:00
|
|
|
ret
|
|
|
|
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
|
|
|
/*
|
|
|
|
* A pseudo representation for the function graph tracer:
|
|
|
|
* prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
|
|
|
|
*/
|
2023-10-24 21:26:51 +08:00
|
|
|
.Ldo_ftrace_graph_caller:
|
2022-11-16 04:08:30 +08:00
|
|
|
addi a0, s0, -SZREG
|
2017-12-18 17:52:48 +08:00
|
|
|
mv a1, ra
|
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
|
2022-11-16 04:08:30 +08:00
|
|
|
REG_L a2, -2*SZREG(s0)
|
2017-12-18 17:52:48 +08:00
|
|
|
#endif
|
|
|
|
SAVE_ABI_STATE
|
2018-02-13 13:13:17 +08:00
|
|
|
call prepare_ftrace_return
|
|
|
|
RESTORE_ABI_STATE
|
2017-12-18 17:52:48 +08:00
|
|
|
ret
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A pseudo representation for the function tracer:
|
|
|
|
* (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
|
|
|
|
*/
|
2023-10-24 21:26:51 +08:00
|
|
|
.Ldo_trace:
|
2022-11-16 04:08:30 +08:00
|
|
|
REG_L a1, -SZREG(s0)
|
2017-12-18 17:52:48 +08:00
|
|
|
mv a0, ra
|
|
|
|
|
|
|
|
SAVE_ABI_STATE
|
|
|
|
jalr t5
|
2018-02-13 13:13:17 +08:00
|
|
|
RESTORE_ABI_STATE
|
2017-12-18 17:52:48 +08:00
|
|
|
ret
|
2024-01-26 06:55:13 +08:00
|
|
|
SYM_FUNC_END(_mcount)
|
2018-02-13 13:13:17 +08:00
|
|
|
#endif
|
2024-01-26 06:55:13 +08:00
|
|
|
EXPORT_SYMBOL(_mcount)
|