github.com/dorkamotorka/go/src@v0.0.0-20230614113921-187095f0e316/runtime/cgo/asm_ppc64x.s (about) 1 // Copyright 2014 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 //go:build ppc64 || ppc64le 6 7 #include "textflag.h" 8 #include "asm_ppc64x.h" 9 #include "abi_ppc64x.h" 10 11 #ifdef GO_PPC64X_HAS_FUNCDESC 12 // crosscall2 is marked with go:cgo_export_static. On AIX, this creates and exports 13 // the symbol name and descriptor as the AIX linker expects, but does not work if 14 // referenced from within Go. Create and use an aliased descriptor of crosscall2 15 // to workaround this. 16 DEFINE_PPC64X_FUNCDESC(_crosscall2<>, crosscall2) 17 #define CROSSCALL2_FPTR $_crosscall2<>(SB) 18 #else 19 #define CROSSCALL2_FPTR $crosscall2(SB) 20 #endif 21 22 // Set the x_crosscall2_ptr C function pointer variable point to crosscall2. 23 // It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2 24 TEXT ·set_crosscall2(SB),NOSPLIT,$0-0 25 MOVD _crosscall2_ptr(SB), R5 26 MOVD CROSSCALL2_FPTR, R6 27 MOVD R6, (R5) 28 RET 29 30 // Called by C code generated by cmd/cgo. 31 // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr) 32 // Saves C callee-saved registers and calls cgocallback with three arguments. 33 // fn is the PC of a func(a unsafe.Pointer) function. 34 // The value of R2 is saved on the new stack frame, and not 35 // the caller's frame due to issue #43228. 36 TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0 37 // Start with standard C stack frame layout and linkage, allocate 38 // 32 bytes of argument space, save callee-save regs, and set R0 to $0. 39 STACK_AND_SAVE_HOST_TO_GO_ABI(32) 40 // The above will not preserve R2 (TOC). Save it in case Go is 41 // compiled without a TOC pointer (e.g -buildmode=default). 42 MOVD R2, 24(R1) 43 44 // Load the current g. 45 BL runtime·load_g(SB) 46 47 #ifdef GO_PPC64X_HAS_FUNCDESC 48 // Load the real entry address from the first slot of the function descriptor. 49 // The first argument fn might be null, that means dropm in pthread key destructor. 50 CMP R3, $0 51 BEQ nil_fn 52 MOVD 8(R3), R2 53 MOVD (R3), R3 54 nil_fn: 55 #endif 56 MOVD R3, FIXED_FRAME+0(R1) // fn unsafe.Pointer 57 MOVD R4, FIXED_FRAME+8(R1) // a unsafe.Pointer 58 // Skip R5 = n uint32 59 MOVD R6, FIXED_FRAME+16(R1) // ctxt uintptr 60 BL runtime·cgocallback(SB) 61 62 // Restore the old frame, and R2. 63 MOVD 24(R1), R2 64 UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(32) 65 RET