125 lines · plain
1//===-- xray_trampoline_loongarch64.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-exception6//7//===----------------------------------------------------------------------===//8//9// This file is a part of XRay, a dynamic runtime instrumentation system.10//11// This implements the loongarch-specific assembler for the trampolines.12//13//===----------------------------------------------------------------------===//14 15#include "../sanitizer_common/sanitizer_asm.h"16 17#define FROM_0_TO_7 0,1,2,3,4,5,6,718#define FROM_7_TO_0 7,6,5,4,3,2,1,019 20.macro SAVE_ARG_REGISTERS21 .irp i,FROM_7_TO_022 st.d $a\i, $sp, (8 * 8 + 8 * \i)23 .endr24 .irp i,FROM_7_TO_025 fst.d $f\i, $sp, (8 * \i)26 .endr27.endm28 29.macro RESTORE_ARG_REGISTERS30 .irp i,FROM_0_TO_731 fld.d $f\i, $sp, (8 * \i)32 .endr33 .irp i,FROM_0_TO_734 ld.d $a\i, $sp, (8 * 8 + 8 * \i)35 .endr36.endm37 38.macro SAVE_RET_REGISTERS39 st.d $a1, $sp, 2440 st.d $a0, $sp, 1641 fst.d $f1, $sp, 842 fst.d $f0, $sp, 043.endm44 45.macro RESTORE_RET_REGISTERS46 fld.d $f0, $sp, 047 fld.d $f1, $sp, 848 ld.d $a0, $sp, 1649 ld.d $a1, $sp, 2450.endm51 52 .text53 .file "xray_trampoline_loongarch64.S"54 .globl ASM_SYMBOL(__xray_FunctionEntry)55 ASM_HIDDEN(__xray_FunctionEntry)56 .p2align 257 ASM_TYPE_FUNCTION(__xray_FunctionEntry)58ASM_SYMBOL(__xray_FunctionEntry):59 .cfi_startproc60 // Save argument registers before doing any actual work.61 .cfi_def_cfa_offset 13662 addi.d $sp, $sp, -13663 st.d $ra, $sp, 12864 .cfi_offset 1, -865 SAVE_ARG_REGISTERS66 67 la.got $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)68 ld.d $t2, $t2, 069 70 beqz $t2, FunctionEntry_restore71 72 // a1=0 means that we are tracing an entry event.73 move $a1, $zero74 // Function ID is in t1 (the first parameter).75 move $a0, $t176 jirl $ra, $t2, 077 78FunctionEntry_restore:79 // Restore argument registers.80 RESTORE_ARG_REGISTERS81 ld.d $ra, $sp, 12882 addi.d $sp, $sp, 13683 ret84FunctionEntry_end:85 ASM_SIZE(__xray_FunctionEntry)86 .cfi_endproc87 88 .text89 .globl ASM_SYMBOL(__xray_FunctionExit)90 ASM_HIDDEN(__xray_FunctionExit)91 .p2align 292 ASM_TYPE_FUNCTION(__xray_FunctionExit)93ASM_SYMBOL(__xray_FunctionExit):94 .cfi_startproc95 // Save return registers before doing any actual work.96 .cfi_def_cfa_offset 4897 addi.d $sp, $sp, -4898 st.d $ra, $sp, 4099 .cfi_offset 1, -8100 st.d $fp, $sp, 32101 SAVE_RET_REGISTERS102 103 la.got $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)104 ld.d $t2, $t2, 0105 106 beqz $t2, FunctionExit_restore107 108 // a1=1 means that we are tracing an exit event.109 li.w $a1, 1110 // Function ID is in t1 (the first parameter).111 move $a0, $t1112 jirl $ra, $t2, 0113 114FunctionExit_restore:115 // Restore return registers.116 RESTORE_RET_REGISTERS117 ld.d $fp, $sp, 32118 ld.d $ra, $sp, 40119 addi.d $sp, $sp, 48120 ret121 122FunctionExit_end:123 ASM_SIZE(__xray_FunctionExit)124 .cfi_endproc125