rsc.io/go@v0.0.0-20150416155037-e040fd465409/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 and darwin, runtime.tlsg is a normal variable. 19 // TLS offset is computed in x_cgo_inittls. 20 #ifdef GOOS_android 21 #define TLSG_IS_VARIABLE 22 #endif 23 #ifdef GOOS_darwin 24 #define TLSG_IS_VARIABLE 25 #endif 26 27 // save_g saves the g register into pthread-provided 28 // thread-local memory, so that we can call externally compiled 29 // ARM code that will overwrite those registers. 30 // NOTE: runtime.gogo assumes that R1 is preserved by this function. 31 // runtime.mcall assumes this function only clobbers R0 and R11. 32 // Returns with g in R0. 33 TEXT runtime·save_g(SB),NOSPLIT,$-4 34 #ifdef GOOS_nacl 35 // nothing to do as nacl/arm does not use TLS at all. 36 MOVW g, R0 // preserve R0 across call to setg<> 37 RET 38 #endif 39 // If the host does not support MRC the linker will replace it with 40 // a call to runtime.read_tls_fallback which jumps to __kuser_get_tls. 41 // The replacement function saves LR in R11 over the call to read_tls_fallback. 42 MRC 15, 0, R0, C13, C0, 3 // fetch TLS base pointer 43 BIC $3, R0 // Darwin/ARM might return unaligned pointer 44 // $runtime.tlsg(SB) is a special linker symbol. 45 // It is the offset from the TLS base pointer to our 46 // thread-local storage for g. 47 #ifdef TLSG_IS_VARIABLE 48 MOVW runtime·tlsg(SB), R11 49 #else 50 MOVW $runtime·tlsg(SB), R11 51 #endif 52 ADD R11, R0 53 MOVW g, 0(R0) 54 MOVW g, R0 // preserve R0 across call to setg<> 55 RET 56 57 // load_g loads the g register from pthread-provided 58 // thread-local memory, for use after calling externally compiled 59 // ARM code that overwrote those registers. 60 TEXT runtime·load_g(SB),NOSPLIT,$0 61 #ifdef GOOS_nacl 62 // nothing to do as nacl/arm does not use TLS at all. 63 RET 64 #endif 65 // See save_g 66 MRC 15, 0, R0, C13, C0, 3 // fetch TLS base pointer 67 BIC $3, R0 // Darwin/ARM might return unaligned pointer 68 // $runtime.tlsg(SB) is a special linker symbol. 69 // It is the offset from the TLS base pointer to our 70 // thread-local storage for g. 71 #ifdef TLSG_IS_VARIABLE 72 MOVW runtime·tlsg(SB), R11 73 #else 74 MOVW $runtime·tlsg(SB), R11 75 #endif 76 ADD R11, R0 77 MOVW 0(R0), g 78 RET 79 80 TEXT runtime·_initcgo(SB),NOSPLIT,$0 81 #ifndef GOOS_nacl 82 // if there is an _cgo_init, call it. 83 MOVW _cgo_init(SB), R4 84 CMP $0, R4 85 B.EQ nocgo 86 MRC 15, 0, R0, C13, C0, 3 // load TLS base pointer 87 MOVW R0, R3 // arg 3: TLS base pointer 88 MOVW $runtime·tlsg(SB), R2 // arg 2: tlsg 89 MOVW $setg_gcc<>(SB), R1 // arg 1: setg 90 MOVW g, R0 // arg 0: G 91 BL (R4) // will clobber R0-R3 92 #endif 93 nocgo: 94 RET 95 96 // void setg_gcc(G*); set g called from gcc. 97 TEXT setg_gcc<>(SB),NOSPLIT,$0 98 MOVW R0, g 99 B runtime·save_g(SB) 100 101 #ifdef TLSG_IS_VARIABLE 102 GLOBL runtime·tlsg+0(SB), NOPTR, $4 103 #endif