Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_trampoline_loongarch64.S
35263 views
//===-- xray_trampoline_loongarch64.s ---------------------------*- ASM -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of XRay, a dynamic runtime instrumentation system.9//10// This implements the loongarch-specific assembler for the trampolines.11//12//===----------------------------------------------------------------------===//1314#include "../sanitizer_common/sanitizer_asm.h"1516#define FROM_0_TO_7 0,1,2,3,4,5,6,717#define FROM_7_TO_0 7,6,5,4,3,2,1,01819.macro SAVE_ARG_REGISTERS20.irp i,FROM_7_TO_021st.d $a\i, $sp, (8 * 8 + 8 * \i)22.endr23.irp i,FROM_7_TO_024fst.d $f\i, $sp, (8 * \i)25.endr26.endm2728.macro RESTORE_ARG_REGISTERS29.irp i,FROM_0_TO_730fld.d $f\i, $sp, (8 * \i)31.endr32.irp i,FROM_0_TO_733ld.d $a\i, $sp, (8 * 8 + 8 * \i)34.endr35.endm3637.macro SAVE_RET_REGISTERS38st.d $a1, $sp, 2439st.d $a0, $sp, 1640fst.d $f1, $sp, 841fst.d $f0, $sp, 042.endm4344.macro RESTORE_RET_REGISTERS45fld.d $f0, $sp, 046fld.d $f1, $sp, 847ld.d $a0, $sp, 1648ld.d $a1, $sp, 2449.endm5051.text52.file "xray_trampoline_loongarch64.S"53.globl ASM_SYMBOL(__xray_FunctionEntry)54ASM_HIDDEN(__xray_FunctionEntry)55.p2align 256ASM_TYPE_FUNCTION(__xray_FunctionEntry)57ASM_SYMBOL(__xray_FunctionEntry):58.cfi_startproc59// Save argument registers before doing any actual work.60.cfi_def_cfa_offset 13661addi.d $sp, $sp, -13662st.d $ra, $sp, 12863.cfi_offset 1, -864SAVE_ARG_REGISTERS6566la.got $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)67ld.d $t2, $t2, 06869beqz $t2, FunctionEntry_restore7071// a1=0 means that we are tracing an entry event.72move $a1, $zero73// Function ID is in t1 (the first parameter).74move $a0, $t175jirl $ra, $t2, 07677FunctionEntry_restore:78// Restore argument registers.79RESTORE_ARG_REGISTERS80ld.d $ra, $sp, 12881addi.d $sp, $sp, 13682ret83FunctionEntry_end:84ASM_SIZE(__xray_FunctionEntry)85.cfi_endproc8687.text88.globl ASM_SYMBOL(__xray_FunctionExit)89ASM_HIDDEN(__xray_FunctionExit)90.p2align 291ASM_TYPE_FUNCTION(__xray_FunctionExit)92ASM_SYMBOL(__xray_FunctionExit):93.cfi_startproc94// Save return registers before doing any actual work.95.cfi_def_cfa_offset 4896addi.d $sp, $sp, -4897st.d $ra, $sp, 4098.cfi_offset 1, -899st.d $fp, $sp, 32100SAVE_RET_REGISTERS101102la.got $t2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)103ld.d $t2, $t2, 0104105beqz $t2, FunctionExit_restore106107// a1=1 means that we are tracing an exit event.108li.w $a1, 1109// Function ID is in t1 (the first parameter).110move $a0, $t1111jirl $ra, $t2, 0112113FunctionExit_restore:114// Restore return registers.115RESTORE_RET_REGISTERS116ld.d $fp, $sp, 32117ld.d $ra, $sp, 40118addi.d $sp, $sp, 48119ret120121FunctionExit_end:122ASM_SIZE(__xray_FunctionExit)123.cfi_endproc124125126