github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/tls_arm.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  #include "zasm_GOOS_GOARCH.h"
     6  #include "funcdata.h"
     7  #include "textflag.h"
     8  
     9  // We have to resort to TLS variable to save g(R10).
    10  // One reason is that external code might trigger
    11  // SIGSEGV, and our runtime.sigtramp don't even know we
    12  // are in external code, and will continue to use R10,
    13  // this might as well result in another SIGSEGV.
    14  // Note: both functions will clobber R0 and R11 and
    15  // can be called from 5c ABI code.
    16  
    17  // On android, runtime.tlsg is a normal variable.
    18  // TLS offset is computed in x_cgo_inittls.
    19  
    20  // save_g saves the g register into pthread-provided
    21  // thread-local memory, so that we can call externally compiled
    22  // ARM code that will overwrite those registers.
    23  // NOTE: runtime.gogo assumes that R1 is preserved by this function.
    24  //       runtime.mcall assumes this function only clobbers R0 and R11.
    25  // Returns with g in R0.
    26  TEXT runtime·save_g(SB),NOSPLIT,$-4
    27  #ifdef GOOS_nacl
    28  	// nothing to do as nacl/arm does not use TLS at all.
    29  	MOVW	g, R0 // preserve R0 across call to setg<>
    30  	RET
    31  #endif
    32  	// If the host does not support MRC the linker will replace it with
    33  	// a call to runtime.read_tls_fallback which jumps to __kuser_get_tls.
    34  	// The replacement function saves LR in R11 over the call to read_tls_fallback.
    35  	MRC	15, 0, R0, C13, C0, 3 // fetch TLS base pointer
    36  	// $runtime.tlsg(SB) is a special linker symbol.
    37  	// It is the offset from the TLS base pointer to our
    38  	// thread-local storage for g.
    39  #ifdef GOOS_android
    40  	MOVW	runtime·tlsg(SB), R11
    41  #else
    42  	MOVW	$runtime·tlsg(SB), R11
    43  #endif
    44  	ADD	R11, R0
    45  	MOVW	g, 0(R0)
    46  	MOVW	g, R0 // preserve R0 across call to setg<>
    47  	RET
    48  
    49  // load_g loads the g register from pthread-provided
    50  // thread-local memory, for use after calling externally compiled
    51  // ARM code that overwrote those registers.
    52  TEXT runtime·load_g(SB),NOSPLIT,$0
    53  #ifdef GOOS_nacl
    54  	// nothing to do as nacl/arm does not use TLS at all.
    55  	RET
    56  #endif
    57  	// See save_g
    58  	MRC	15, 0, R0, C13, C0, 3 // fetch TLS base pointer
    59  	// $runtime.tlsg(SB) is a special linker symbol.
    60  	// It is the offset from the TLS base pointer to our
    61  	// thread-local storage for g.
    62  #ifdef GOOS_android
    63  	MOVW	runtime·tlsg(SB), R11
    64  #else
    65  	MOVW	$runtime·tlsg(SB), R11
    66  #endif
    67  	ADD	R11, R0
    68  	MOVW	0(R0), g
    69  	RET