File: xray_trampoline_loongarch64.S

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (124 lines) | stat: -rw-r--r-- 3,070 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//===-- xray_trampoline_loongarch64.s ---------------------------*- ASM -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of XRay, a dynamic runtime instrumentation system.
//
// This implements the loongarch-specific assembler for the trampolines.
//
//===----------------------------------------------------------------------===//

#include "../sanitizer_common/sanitizer_asm.h"

#define FROM_0_TO_7 0,1,2,3,4,5,6,7
#define FROM_7_TO_0 7,6,5,4,3,2,1,0

.macro SAVE_ARG_REGISTERS
  .irp i,FROM_7_TO_0
    st.d  $a\i, $sp, (8 * 8 + 8 * \i)
  .endr
  .irp i,FROM_7_TO_0
    fst.d $f\i, $sp, (8 * \i)
  .endr
.endm

.macro RESTORE_ARG_REGISTERS
  .irp i,FROM_0_TO_7
    fld.d $f\i, $sp, (8 * \i)
  .endr
  .irp i,FROM_0_TO_7
    ld.d  $a\i, $sp, (8 * 8 + 8 * \i)
  .endr
.endm

.macro SAVE_RET_REGISTERS
  st.d    $a1, $sp, 24
  st.d    $a0, $sp, 16
  fst.d   $f1, $sp, 8
  fst.d   $f0, $sp, 0
.endm

.macro RESTORE_RET_REGISTERS
  fld.d   $f0, $sp, 0
  fld.d   $f1, $sp, 8
  ld.d    $a0, $sp, 16
  ld.d    $a1, $sp, 24
.endm

  .text
  .file "xray_trampoline_loongarch64.S"
  .globl ASM_SYMBOL(__xray_FunctionEntry)
  ASM_HIDDEN(__xray_FunctionEntry)
  .p2align 2
  ASM_TYPE_FUNCTION(__xray_FunctionEntry)
ASM_SYMBOL(__xray_FunctionEntry):
  .cfi_startproc
  // Save argument registers before doing any actual work.
  .cfi_def_cfa_offset 136
  addi.d  $sp, $sp, -136
  st.d    $ra, $sp, 128
  .cfi_offset 1, -8
  SAVE_ARG_REGISTERS

  la.got  $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)
  ld.d    $t2, $t2, 0

  beqz    $t2, FunctionEntry_restore

  // a1=0 means that we are tracing an entry event.
  move    $a1, $zero
  // Function ID is in t1 (the first parameter).
  move    $a0, $t1
  jirl    $ra, $t2, 0

FunctionEntry_restore:
  // Restore argument registers.
  RESTORE_ARG_REGISTERS
  ld.d    $ra, $sp, 128
  addi.d  $sp, $sp, 136
  ret
FunctionEntry_end:
  ASM_SIZE(__xray_FunctionEntry)
  .cfi_endproc

  .text
  .globl ASM_SYMBOL(__xray_FunctionExit)
  ASM_HIDDEN(__xray_FunctionExit)
  .p2align 2
  ASM_TYPE_FUNCTION(__xray_FunctionExit)
ASM_SYMBOL(__xray_FunctionExit):
  .cfi_startproc
  // Save return registers before doing any actual work.
  .cfi_def_cfa_offset 48
  addi.d  $sp, $sp, -48
  st.d    $ra, $sp, 40
  .cfi_offset 1, -8
  st.d    $fp, $sp, 32
  SAVE_RET_REGISTERS

  la.got  $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)
  ld.d    $t2, $t2, 0

  beqz    $t2, FunctionExit_restore

  // a1=1 means that we are tracing an exit event.
  li.w    $a1, 1
  // Function ID is in t1 (the first parameter).
  move    $a0, $t1
  jirl    $ra, $t2, 0

FunctionExit_restore:
  // Restore return registers.
  RESTORE_RET_REGISTERS
  ld.d    $fp, $sp, 32
  ld.d    $ra, $sp, 40
  addi.d  $sp, $sp, 48
  ret

FunctionExit_end:
  ASM_SIZE(__xray_FunctionExit)
  .cfi_endproc