// Copyright (c) 2026 Petr Balvín (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 (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 ADDV $8, R5, R5 // advance past return address MOVV R5, R3 // switch to prepared stack (SP) JIRL R0, R4, 0 // 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 JIRL R0, R1, 0 // return to Go caller GLOBL savedRA(SB), NOPTR, $8 GLOBL savedSP(SB), NOPTR, $8