sys_unix_loong64.s raw

   1  // SPDX-License-Identifier: Apache-2.0
   2  // SPDX-FileCopyrightText: 2025 The Ebitengine Authors
   3  
   4  //go:build linux
   5  
   6  #include "textflag.h"
   7  #include "go_asm.h"
   8  #include "funcdata.h"
   9  #include "abi_loong64.h"
  10  
  11  TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
  12  	NO_LOCAL_POINTERS
  13  
  14  	SUBV $(16*8), R3, R14
  15  	MOVD F0, 0(R14)
  16  	MOVD F1, 8(R14)
  17  	MOVD F2, 16(R14)
  18  	MOVD F3, 24(R14)
  19  	MOVD F4, 32(R14)
  20  	MOVD F5, 40(R14)
  21  	MOVD F6, 48(R14)
  22  	MOVD F7, 56(R14)
  23  	MOVV R4, 64(R14)
  24  	MOVV R5, 72(R14)
  25  	MOVV R6, 80(R14)
  26  	MOVV R7, 88(R14)
  27  	MOVV R8, 96(R14)
  28  	MOVV R9, 104(R14)
  29  	MOVV R10, 112(R14)
  30  	MOVV R11, 120(R14)
  31  
  32  	// Adjust SP by frame size.
  33  	SUBV $(22*8), R3
  34  
  35  	// It is important to save R30 because the go assembler
  36  	// uses it for move instructions for a variable.
  37  	// This line:
  38  	// MOVV ·callbackWrap_call(SB), R4
  39  	// Creates the instructions:
  40  	// PCALAU12I	off1(PC), R30
  41  	// MOVV		off2(R30), R4
  42  	// R30 is a callee saved register so we are responsible
  43  	// for ensuring its value doesn't change. So save it and
  44  	// restore it at the end of this function.
  45  	// R1 is the link register. crosscall2 doesn't save it
  46  	// so it's saved here.
  47  	MOVV R1, 0(R3)
  48  	MOVV R30, 8(R3)
  49  
  50  	// Create a struct callbackArgs on our stack.
  51  	MOVV $(callbackArgs__size)(R3), R13
  52  	MOVV R12, callbackArgs_index(R13)   // callback index
  53  	MOVV R14, callbackArgs_args(R13)    // address of args vector
  54  	MOVV $0, callbackArgs_result(R13)   // result
  55  
  56  	// Move parameters into registers
  57  	// Get the ABIInternal function pointer
  58  	// without <ABIInternal> by using a closure.
  59  	MOVV ·callbackWrap_call(SB), R4
  60  	MOVV (R4), R4                   // fn unsafe.Pointer
  61  	MOVV R13, R5                    // frame (&callbackArgs{...})
  62  	MOVV $0, R7                     // ctxt uintptr
  63  
  64  	JAL crosscall2(SB)
  65  
  66  	// Get callback result.
  67  	MOVV $(callbackArgs__size)(R3), R13
  68  	MOVV callbackArgs_result(R13), R4
  69  
  70  	// Restore LR and R30
  71  	MOVV 0(R3), R1
  72  	MOVV 8(R3), R30
  73  	ADDV $(22*8), R3
  74  
  75  	RET
  76