Text file src/runtime/cgo/asm_riscv64.s

     1  // Copyright 2020 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_riscv64.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  // Use a local trampoline, to avoid taking the address of a dynamically exported
    11  // function.
    12  TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
    13  	MOV	_crosscall2_ptr(SB), X7
    14  	MOV	$crosscall2_trampoline<>(SB), X8
    15  	MOV	X8, (X7)
    16  	RET
    17  
    18  TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
    19  	JMP	crosscall2(SB)
    20  
    21  // Called by C code generated by cmd/cgo.
    22  // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
    23  // Saves C callee-saved registers and calls cgocallback with three arguments.
    24  // fn is the PC of a func(a unsafe.Pointer) function.
    25  TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
    26  	/*
    27  	 * Push arguments for fn (X10, X11, X13), along with all callee-save
    28  	 * registers. Note that at procedure entry the first argument is at
    29  	 * 8(X2).
    30  	 */
    31  	ADD	$(-8*29), X2
    32  	MOV	X10, (8*1)(X2) // fn unsafe.Pointer
    33  	MOV	X11, (8*2)(X2) // a unsafe.Pointer
    34  	MOV	X13, (8*3)(X2) // ctxt uintptr
    35  
    36  	SAVE_GPR((8*4))
    37  	MOV	X1, (8*16)(X2)
    38  	SAVE_FPR((8*17))
    39  
    40  	// Initialize Go ABI environment
    41  	CALL	runtime·load_g(SB)
    42  	CALL	runtime·cgocallback(SB)
    43  
    44  	RESTORE_GPR((8*4))
    45  	MOV	(8*16)(X2), X1
    46  	RESTORE_FPR((8*17))
    47  
    48  	ADD	$(8*29), X2
    49  
    50  	RET
    51  

View as plain text