github.com/aloncn/graphics-go@v0.0.1/src/runtime/tls_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  // +build ppc64 ppc64le
     6  
     7  #include "go_asm.h"
     8  #include "go_tls.h"
     9  #include "funcdata.h"
    10  #include "textflag.h"
    11  
    12  // We have to resort to TLS variable to save g (R30).
    13  // One reason is that external code might trigger
    14  // SIGSEGV, and our runtime.sigtramp don't even know we
    15  // are in external code, and will continue to use R30,
    16  // this might well result in another SIGSEGV.
    17  
    18  // save_g saves the g register into pthread-provided
    19  // thread-local memory, so that we can call externally compiled
    20  // ppc64 code that will overwrite this register.
    21  //
    22  // If !iscgo, this is a no-op.
    23  //
    24  // NOTE: setg_gcc<> assume this clobbers only R31.
    25  TEXT runtime·save_g(SB),NOSPLIT|NOFRAME,$0-0
    26  	MOVB	runtime·iscgo(SB), R31
    27  	CMP	R31, $0
    28  	BEQ	nocgo
    29  	MOVD	runtime·tls_g(SB), R31
    30  	MOVD	g, 0(R13)(R31*1)
    31  
    32  nocgo:
    33  	RET
    34  
    35  // load_g loads the g register from pthread-provided
    36  // thread-local memory, for use after calling externally compiled
    37  // ppc64 code that overwrote those registers.
    38  //
    39  // This is never called directly from C code (it doesn't have to
    40  // follow the C ABI), but it may be called from a C context, where the
    41  // usual Go registers aren't set up.
    42  //
    43  // NOTE: _cgo_topofstack assumes this only clobbers g (R30), and R31.
    44  TEXT runtime·load_g(SB),NOSPLIT|NOFRAME,$0-0
    45  	MOVD	runtime·tls_g(SB), R31
    46  	MOVD	0(R13)(R31*1), g
    47  	RET
    48  
    49  GLOBL runtime·tls_g+0(SB), TLSBSS, $8