// Copyright (c) 2026 Petr Balvín (https://petrbalvin.org) // SPDX-License-Identifier: BSD-3-Clause #include "textflag.h" // ABI0 JIT trampoline for RISC-V 64. // // enterJIT saves Go SP and RA, switches to the prepared stack, and jumps // to the JIT function. When the function RETs (JALR zero, ra, 0), control // lands in leaveJIT. // func enterJIT(fn uintptr, stack uintptr) TEXT ·enterJIT(SB), NOSPLIT, $0-16 MOV fn+0(FP), X5 // target function address (T0) MOV X1, savedRA(SB) // save return address MOV X2, savedSP(SB) // save Go stack pointer MOV stack+8(FP), X6 // load prepared stack pointer (T1) LD 0(X6), X1 // load leaveJIT address into RA MOV X6, X2 // switch to the prepared stack: SP stays on // the leave slot, so the kernel reads its // first argument at SP+8 JALR X0, 0(X5) // jump to JIT function // func leaveJIT() TEXT ·leaveJIT(SB), NOSPLIT, $0-0 MOV savedSP(SB), X6 // restore Go stack pointer MOV X6, X2 // restore SP MOV savedRA(SB), X1 // restore return address JALR X0, 0(X1) // return to Go caller GLOBL savedRA(SB), NOPTR, $8 GLOBL savedSP(SB), NOPTR, $8