1//===-- xray_trampoline_mips64.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 MIPS64-specific assembler for the trampolines.
12//
13//===----------------------------------------------------------------------===//
14
15  .text
16  .file "xray_trampoline_mips64.S"
17  .globl __xray_FunctionEntry
18  .p2align 2
19  .type __xray_FunctionEntry,@function
20__xray_FunctionEntry:
21  .cfi_startproc
22  // Save argument registers before doing any actual work.
23  .cfi_def_cfa_offset 144
24  daddiu  $sp, $sp, -144
25  sd      $ra, 136($sp)
26  .cfi_offset 31, -8
27  sd      $gp, 128($sp)
28  sd      $a7, 120($sp)
29  sd      $a6, 112($sp)
30  sd      $a5, 104($sp)
31  sd      $a4, 96($sp)
32  sd      $a3, 88($sp)
33  sd      $a2, 80($sp)
34  sd      $a1, 72($sp)
35  sd      $a0, 64($sp)
36  sdc1    $f19, 56($sp)
37  sdc1    $f18, 48($sp)
38  sdc1    $f17, 40($sp)
39  sdc1    $f16, 32($sp)
40  sdc1    $f15, 24($sp)
41  sdc1    $f14, 16($sp)
42  sdc1    $f13, 8($sp)
43  sdc1    $f12, 0($sp)
44
45  lui     $gp, %hi(%neg(%gp_rel(__xray_FunctionEntry)))
46  daddu   $gp, $gp, $t9
47  daddiu  $gp ,$gp, %lo(%neg(%gp_rel(__xray_FunctionEntry)))
48
49  dla     $t9, _ZN6__xray19XRayPatchedFunctionE
50  ld      $t9, 0($t9)
51
52  beqz    $t9, FunctionEntry_restore
53
54  // a1=0 means that we are tracing an entry event
55  move    $a1, $zero
56  // Function ID is in t0 (the first parameter).
57  move    $a0, $t0
58  jalr    $t9
59
60FunctionEntry_restore:
61  // Restore argument registers
62  ldc1    $f12, 0($sp)
63  ldc1    $f13, 8($sp)
64  ldc1    $f14, 16($sp)
65  ldc1    $f15, 24($sp)
66  ldc1    $f16, 32($sp)
67  ldc1    $f17, 40($sp)
68  ldc1    $f18, 48($sp)
69  ldc1    $f19, 56($sp)
70  ld      $a0, 64($sp)
71  ld      $a1, 72($sp)
72  ld      $a2, 80($sp)
73  ld      $a3, 88($sp)
74  ld      $a4, 96($sp)
75  ld      $a5, 104($sp)
76  ld      $a6, 112($sp)
77  ld      $a7, 120($sp)
78  ld      $gp, 128($sp)
79  ld      $ra, 136($sp)
80  daddiu  $sp, $sp, 144
81  jr      $ra
82FunctionEntry_end:
83  .size __xray_FunctionEntry, FunctionEntry_end-__xray_FunctionEntry
84  .cfi_endproc
85
86  .text
87  .globl __xray_FunctionExit
88  .p2align 2
89  .type __xray_FunctionExit,@function
90__xray_FunctionExit:
91  .cfi_startproc
92  // Save return registers before doing any actual work.
93  .cfi_def_cfa_offset 64
94  daddiu  $sp, $sp, -64
95  sd      $ra, 56($sp)
96  .cfi_offset 31, -8
97  sd      $gp, 48($sp)
98  sd      $a0, 40($sp)
99  sd      $v1, 32($sp)
100  sd      $v0, 24($sp)
101  sdc1    $f2, 16($sp)
102  sdc1    $f1, 8($sp)
103  sdc1    $f0, 0($sp)
104
105  lui     $gp, %hi(%neg(%gp_rel(__xray_FunctionExit)))
106  daddu   $gp, $gp, $t9
107  daddiu  $gp ,$gp, %lo(%neg(%gp_rel(__xray_FunctionExit)))
108
109  dla     $t9, _ZN6__xray19XRayPatchedFunctionE
110  ld      $t9, 0($t9)
111
112  beqz    $t9, FunctionExit_restore
113
114  // a1=1 means that we are tracing an exit event
115  li      $a1, 1
116  // Function ID is in t0 (the first parameter).
117  move    $a0, $t0
118  jalr    $t9
119
120FunctionExit_restore:
121  // Restore return registers
122  ldc1    $f0, 0($sp)
123  ldc1    $f1, 8($sp)
124  ldc1    $f2, 16($sp)
125  ld      $v0, 24($sp)
126  ld      $v1, 32($sp)
127  ld      $a0, 40($sp)
128  ld      $gp, 48($sp)
129  ld      $ra, 56($sp)
130  daddiu  $sp, $sp, 64
131  jr      $ra
132
133FunctionExit_end:
134  .size __xray_FunctionExit, FunctionExit_end-__xray_FunctionExit
135  .cfi_endproc
136