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