1//===-- xray_trampoline_riscv_common.s --------------------------*- ASM -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of XRay, a dynamic runtime instrumentation system.
10//
11// This implements the trampolines code shared between riscv32 and riscv64.
12//
13//===----------------------------------------------------------------------===//
14
15#include "../builtins/assembly.h"
16
17 .text
18 .p2align 2
19 .global ASM_SYMBOL(__xray_FunctionEntry)
20 ASM_TYPE_FUNCTION(__xray_FunctionEntry)
21ASM_SYMBOL(__xray_FunctionEntry):
22 CFI_STARTPROC
23 SAVE_ARG_REGISTERS
24
25 // Load the handler function pointer into a2
26 la a2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)
27 LOAD_XLEN a2, 0(a2)
28
29 // Handler address will be null if it is not set
30 beq a2, x0, 1f
31
32 // If we reach here, we are tracing an event
33 // a0 already contains function id
34 // a1 = 0 means we are tracing an entry event
35 li a1, 0
36 jalr a2
37
381:
39 RESTORE_ARG_REGISTERS
40 jr ra
41 ASM_SIZE(__xray_FunctionEntry)
42 CFI_ENDPROC
43
44 .text
45 .p2align 2
46 .global ASM_SYMBOL(__xray_FunctionExit)
47 ASM_TYPE_FUNCTION(__xray_FunctionExit)
48ASM_SYMBOL(__xray_FunctionExit):
49 CFI_STARTPROC
50 SAVE_RET_REGISTERS
51
52 // Load the handler function pointer into a2
53 la a2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)
54 LOAD_XLEN a2, 0(a2)
55
56 // Handler address will be null if it is not set
57 beq a2, x0, 1f
58
59 // If we reach here, we are tracing an event
60 // a0 already contains function id
61 // a1 = 1 means we are tracing an exit event
62 li a1, 1
63 jalr a2
64
651:
66 RESTORE_RET_REGISTERS
67 jr ra
68 ASM_SIZE(__xray_FunctionExit)
69 CFI_ENDPROC
70
71 .text
72 .p2align 2
73 .global ASM_SYMBOL(__xray_FunctionTailExit)
74 ASM_TYPE_FUNCTION(__xray_FunctionTailExit)
75ASM_SYMBOL(__xray_FunctionTailExit):
76 CFI_STARTPROC
77 SAVE_ARG_REGISTERS
78
79 // Load the handler function pointer into a2
80 la a2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)
81 LOAD_XLEN a2, 0(a2)
82
83 // Handler address will be null if it is not set
84 beq a2, x0, 1f
85
86 // If we reach here, we are tracing an event
87 // a0 already contains function id
88 // a1 = 2 means we are tracing a tail exit event
89 li a1, 2
90 jalr a2
91
921:
93 RESTORE_ARG_REGISTERS
94 jr ra
95 ASM_SIZE(__xray_FunctionTailExit)
96 CFI_ENDPROC
97

source code of compiler-rt/lib/xray/xray_trampoline_riscv_common.S