github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/runtime/cgo/asm_loong64.s (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  #include "abi_loong64.h"
     7  
     8  // Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
     9  // It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
    10  TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
    11  	MOVV	_crosscall2_ptr(SB), R5
    12  	MOVV	$crosscall2(SB), R6
    13  	MOVV	R6, (R5)
    14  	RET
    15  
    16  // Called by C code generated by cmd/cgo.
    17  // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
    18  // Saves C callee-saved registers and calls cgocallback with three arguments.
    19  // fn is the PC of a func(a unsafe.Pointer) function.
    20  TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
    21  	/*
    22  	 * We still need to save all callee save register as before, and then
    23  	 * push 3 args for fn (R4, R5, R7), skipping R6.
    24  	 * Also note that at procedure entry in gc world, 8(R29) will be the
    25  	 *  first arg.
    26  	 */
    27  
    28  	ADDV	$(-23*8), R3
    29  	MOVV	R4, (1*8)(R3) // fn unsafe.Pointer
    30  	MOVV	R5, (2*8)(R3) // a unsafe.Pointer
    31  	MOVV	R7, (3*8)(R3) // ctxt uintptr
    32  
    33  	SAVE_R22_TO_R31((4*8))
    34  	SAVE_F24_TO_F31((14*8))
    35  	MOVV	R1, (22*8)(R3)
    36  
    37  	// Initialize Go ABI environment
    38  	JAL	runtime·load_g(SB)
    39  
    40  	JAL	runtime·cgocallback(SB)
    41  
    42  	RESTORE_R22_TO_R31((4*8))
    43  	RESTORE_F24_TO_F31((14*8))
    44  	MOVV	(22*8)(R3), R1
    45  
    46  	ADDV	$(23*8), R3
    47  
    48  	RET