Files
gasm-sdk/verify/trampoline_loong64.s
2026-09-19 19:17:07 +02:00

34 lines
1.2 KiB
ArmAsm

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: BSD-3-Clause
#include "textflag.h"
// ABI0 JIT trampoline for LoongArch 64.
//
// enterJIT saves Go SP and RA (R1), switches to the prepared stack, and
// jumps to the JIT function. When the function RETs (JMP (R1), the toolchain's spelling for jirl zero, ra, 0),
// control lands in leaveJIT.
// func enterJIT(fn uintptr, stack uintptr)
TEXT ·enterJIT(SB), NOSPLIT, $0-16
MOVV fn+0(FP), R4 // target function address (A0)
MOVV R1, savedRA(SB) // save return address (RA)
MOVV R3, savedSP(SB) // save Go stack pointer (SP)
MOVV stack+8(FP), R5 // load prepared stack pointer (A1)
MOVV 0(R5), R1 // load leaveJIT address into RA
MOVV R5, R3 // switch to the prepared stack: SP stays on
// the leave slot, so the kernel reads its
// first argument at SP+8
JMP (R4) // jump to JIT function
// func leaveJIT()
TEXT ·leaveJIT(SB), NOSPLIT, $0-0
MOVV savedSP(SB), R5 // restore Go stack pointer
MOVV R5, R3 // restore SP
MOVV savedRA(SB), R1 // restore return address
JMP (R1) // return to Go caller
GLOBL savedRA(SB), NOPTR, $8
GLOBL savedSP(SB), NOPTR, $8