1171173Smlaier#include "../builtins/assembly.h"
2171173Smlaier
3171173Smlaier    .syntax unified
4171173Smlaier    .arch armv6t2
5171173Smlaier    .fpu vfpv2
6171173Smlaier    .code 32
7171173Smlaier    .global _ZN6__xray19XRayPatchedFunctionE
8171173Smlaier
9171173Smlaier    @ Word-aligned function entry point
10171173Smlaier    .p2align 2
11171173Smlaier    @ Let C/C++ see the symbol
12171173Smlaier    .global __xray_FunctionEntry
13171173Smlaier    .hidden __xray_FunctionEntry
14171173Smlaier    @ It preserves all registers except r0, r12(ip), r14(lr) and r15(pc)
15171173Smlaier    @ Assume that "q" part of the floating-point registers is not used
16171173Smlaier    @   for passing parameters to C/C++ functions.
17171173Smlaier    .type __xray_FunctionEntry, %function
18171173Smlaier    @ In C++ it is void extern "C" __xray_FunctionEntry(uint32_t FuncId) with
19171173Smlaier    @   FuncId passed in r0 register.
20171173Smlaier__xray_FunctionEntry:
21171173Smlaier    PUSH {r1-r3,lr}
22171173Smlaier    @ Save floating-point parameters of the instrumented function
23171173Smlaier    VPUSH {d0-d7}
24171173Smlaier    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
25171173Smlaier    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
26171173Smlaier    LDR r2, [pc, r1]
27171173Smlaier    @ Handler address is nullptr if handler is not set
28171173Smlaier    CMP r2, #0
29171173Smlaier    BEQ FunctionEntry_restore
30171173Smlaier    @ Function ID is already in r0 (the first parameter).
31171173Smlaier    @ r1=0 means that we are tracing an entry event
32171173Smlaier    MOV r1, #0
33171173Smlaier    @ Call the handler with 2 parameters in r0 and r1
34171173Smlaier    BLX r2
35171173SmlaierFunctionEntry_restore:
36171173Smlaier    @ Restore floating-point parameters of the instrumented function
37171173Smlaier    VPOP {d0-d7}
38171173Smlaier    POP {r1-r3,pc}
39171173Smlaier
40223637Sbz    @ Word-aligned function entry point
41223637Sbz    .p2align 2
42278843Sglebius    @ Let C/C++ see the symbol
43171173Smlaier	.global __xray_FunctionExit
44171173Smlaier	.hidden __xray_FunctionExit
45171173Smlaier	@ Assume that d1-d7 are not used for the return value.
46223637Sbz    @ Assume that "q" part of the floating-point registers is not used for the
47284777Seri    @   return value in C/C++.
48171173Smlaier	.type __xray_FunctionExit, %function
49171173Smlaier	@ In C++ it is extern "C" void __xray_FunctionExit(uint32_t FuncId) with
50171173Smlaier    @   FuncId passed in r0 register.
51171173Smlaier__xray_FunctionExit:
52171173Smlaier    PUSH {r1-r3,lr}
53171173Smlaier    @ Save the floating-point return value of the instrumented function
54171173Smlaier    VPUSH {d0}
55171173Smlaier    @ Load the handler address
56171173Smlaier    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
57171173Smlaier    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
58171173Smlaier    LDR r2, [pc, r1]
59171173Smlaier    @ Handler address is nullptr if handler is not set
60171173Smlaier    CMP r2, #0
61171173Smlaier    BEQ FunctionExit_restore
62171173Smlaier    @ Function ID is already in r0 (the first parameter).
63171173Smlaier    @ 1 means that we are tracing an exit event
64171173Smlaier    MOV r1, #1
65    @ Call the handler with 2 parameters in r0 and r1
66    BLX r2
67FunctionExit_restore:
68    @ Restore the floating-point return value of the instrumented function
69    VPOP {d0}
70    POP {r1-r3,pc}
71
72    @ Word-aligned function entry point
73    .p2align 2
74    @ Let C/C++ see the symbol
75    .global __xray_FunctionTailExit
76    .hidden __xray_FunctionTailExit
77    @ It preserves all registers except r0, r12(ip), r14(lr) and r15(pc)
78    @ Assume that "q" part of the floating-point registers is not used
79    @   for passing parameters to C/C++ functions.
80    .type __xray_FunctionTailExit, %function
81    @ In C++ it is void extern "C" __xray_FunctionTailExit(uint32_t FuncId)
82    @   with FuncId passed in r0 register.
83__xray_FunctionTailExit:
84    PUSH {r1-r3,lr}
85    @ Save floating-point parameters of the instrumented function
86    VPUSH {d0-d7}
87    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
88    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
89    LDR r2, [pc, r1]
90    @ Handler address is nullptr if handler is not set
91    CMP r2, #0
92    BEQ FunctionTailExit_restore
93    @ Function ID is already in r0 (the first parameter).
94    @ r1=2 means that we are tracing a tail exit event
95    @ But before the logging part of XRay is ready, we pretend that here a
96    @   normal function exit happens, so we give the handler code 1
97    MOV r1, #1
98    @ Call the handler with 2 parameters in r0 and r1
99    BLX r2
100FunctionTailExit_restore:
101    @ Restore floating-point parameters of the instrumented function
102    VPOP {d0-d7}
103    POP {r1-r3,pc}
104
105NO_EXEC_STACK_DIRECTIVE
106