xref: /freebsd/contrib/llvm-project/compiler-rt/lib/xray/xray_trampoline_mips.S (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1//===-- xray_trampoline_mips.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 MIPS-specific assembler for the trampolines.
12//
13//===----------------------------------------------------------------------===//
14
15  .text
16  .file "xray_trampoline_mips.S"
17  .globl __xray_FunctionEntry
18  .p2align 2
19  .type __xray_FunctionEntry,@function
20__xray_FunctionEntry:
21  .cfi_startproc
22  .set noreorder
23  .cpload $t9
24  .set reorder
25  // Save argument registers before doing any actual work
26  .cfi_def_cfa_offset 36
27  addiu  $sp, $sp, -36
28  sw     $ra, 32($sp)
29  .cfi_offset 31, -4
30  sw     $a3, 28($sp)
31  sw     $a2, 24($sp)
32  sw     $a1, 20($sp)
33  sw     $a0, 16($sp)
34  sdc1	 $f14, 8($sp)
35  sdc1	 $f12, 0($sp)
36
37  la     $t9, _ZN6__xray19XRayPatchedFunctionE
38  lw     $t9, 0($t9)
39
40  beqz   $t9, FunctionEntry_restore
41
42  // a1=0 means that we are tracing an entry event
43  move   $a1, $zero
44  // Function ID is in t0 (the first parameter).
45  move   $a0, $t0
46  jalr   $t9
47
48FunctionEntry_restore:
49  // Restore argument registers
50  ldc1   $f12, 0($sp)
51  ldc1   $f14, 8($sp)
52  lw     $a0, 16($sp)
53  lw     $a1, 20($sp)
54  lw     $a2, 24($sp)
55  lw     $a3, 28($sp)
56  lw     $ra, 32($sp)
57  addiu	 $sp, $sp, 36
58  jr     $ra
59FunctionEntry_end:
60  .size __xray_FunctionEntry, FunctionEntry_end-__xray_FunctionEntry
61  .cfi_endproc
62
63  .text
64  .globl __xray_FunctionExit
65  .p2align 2
66  .type __xray_FunctionExit,@function
67__xray_FunctionExit:
68  .cfi_startproc
69  .set noreorder
70  .cpload $t9
71  .set reorder
72  // Save return registers before doing any actual work.
73  .cfi_def_cfa_offset 36
74  addiu  $sp, $sp, -36
75  sw     $ra, 32($sp)
76  .cfi_offset 31, -4
77  sw     $a1, 28($sp)
78  sw     $a0, 24($sp)
79  sw     $v1, 20($sp)
80  sw     $v0, 16($sp)
81  sdc1   $f2, 8($sp)
82  sdc1   $f0, 0($sp)
83
84  la     $t9, _ZN6__xray19XRayPatchedFunctionE
85  lw     $t9, 0($t9)
86
87  beqz	 $t9, FunctionExit_restore
88
89  // a1=1 means that we are tracing an exit event
90  li     $a1, 1
91  // Function ID is in t0 (the first parameter).
92  move   $a0, $t0
93  jalr   $t9
94
95FunctionExit_restore:
96  // Restore return registers
97  ldc1   $f0, 0($sp)
98  ldc1   $f2, 8($sp)
99  lw     $v0, 16($sp)
100  lw     $v1, 20($sp)
101  lw     $a0, 24($sp)
102  lw     $a1, 28($sp)
103  lw     $ra, 32($sp)
104  addiu  $sp, $sp, 36
105  jr     $ra
106
107FunctionExit_end:
108  .size __xray_FunctionExit, FunctionExit_end-__xray_FunctionExit
109  .cfi_endproc
110