]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/xray/xray_trampoline_AArch64.S
Merge from vendor branch importing dtc 1.4.3
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / xray / xray_trampoline_AArch64.S
1     .text
2     /* The variable containing the handler function pointer */
3     .global _ZN6__xray19XRayPatchedFunctionE
4     /* Word-aligned function entry point */
5     .p2align 2
6     /* Let C/C++ see the symbol */
7     .global __xray_FunctionEntry
8     .type __xray_FunctionEntry, %function
9     /* In C++ it is void extern "C" __xray_FunctionEntry(uint32_t FuncId) with
10          FuncId passed in W0 register. */
11 __xray_FunctionEntry:
12     /* Move the return address beyond the end of sled data. The 12 bytes of
13          data are inserted in the code of the runtime patch, between the call
14          instruction and the instruction returned into. The data contains 32
15          bits of instrumented function ID and 64 bits of the address of
16          the current trampoline. */
17     ADD X30, X30, #12
18     /* Push the registers which may be modified by the handler function */
19     STP X1, X2, [SP, #-16]!
20     STP X3, X4, [SP, #-16]!
21     STP X5, X6, [SP, #-16]!
22     STP X7, X30, [SP, #-16]!
23     STP Q0, Q1, [SP, #-32]!
24     STP Q2, Q3, [SP, #-32]!
25     STP Q4, Q5, [SP, #-32]!
26     STP Q6, Q7, [SP, #-32]!
27     /* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
28     LDR X1, =_ZN6__xray19XRayPatchedFunctionE
29     /* Load the handler function pointer into X2 */
30     LDR X2, [X1]
31     /* Handler address is nullptr if handler is not set */
32     CMP X2, #0
33     BEQ FunctionEntry_restore
34     /* Function ID is already in W0 (the first parameter).
35          X1=0 means that we are tracing an entry event */
36     MOV X1, #0
37     /* Call the handler with 2 parameters in W0 and X1 */
38     BLR X2
39 FunctionEntry_restore:
40     /* Pop the saved registers */
41     LDP Q6, Q7, [SP], #32
42     LDP Q4, Q5, [SP], #32
43     LDP Q2, Q3, [SP], #32
44     LDP Q0, Q1, [SP], #32
45     LDP X7, X30, [SP], #16
46     LDP X5, X6, [SP], #16
47     LDP X3, X4, [SP], #16
48     LDP X1, X2, [SP], #16
49     RET
50
51     /* Word-aligned function entry point */
52     .p2align 2
53     /* Let C/C++ see the symbol */
54     .global __xray_FunctionExit
55     .type __xray_FunctionExit, %function
56     /* In C++ it is void extern "C" __xray_FunctionExit(uint32_t FuncId) with
57          FuncId passed in W0 register. */
58 __xray_FunctionExit:
59     /* Move the return address beyond the end of sled data. The 12 bytes of
60          data are inserted in the code of the runtime patch, between the call
61          instruction and the instruction returned into. The data contains 32
62          bits of instrumented function ID and 64 bits of the address of
63          the current trampoline. */
64     ADD X30, X30, #12
65     /* Push the registers which may be modified by the handler function */
66     STP X1, X2, [SP, #-16]!
67     STP X3, X4, [SP, #-16]!
68     STP X5, X6, [SP, #-16]!
69     STP X7, X30, [SP, #-16]!
70     STR Q0, [SP, #-16]!
71     /* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
72     LDR X1, =_ZN6__xray19XRayPatchedFunctionE
73     /* Load the handler function pointer into X2 */
74     LDR X2, [X1]
75     /* Handler address is nullptr if handler is not set */
76     CMP X2, #0
77     BEQ FunctionExit_restore
78     /* Function ID is already in W0 (the first parameter).
79          X1=1 means that we are tracing an exit event */
80     MOV X1, #1
81     /* Call the handler with 2 parameters in W0 and X1 */
82     BLR X2
83 FunctionExit_restore:
84     LDR Q0, [SP], #16
85     LDP X7, X30, [SP], #16
86     LDP X5, X6, [SP], #16
87     LDP X3, X4, [SP], #16
88     LDP X1, X2, [SP], #16
89     RET