1 // Copyright 2009 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 "textflag.h" 6 7 TEXT _rt0_amd64_linux(SB),NOSPLIT,$-8 8 LEAQ 8(SP), SI // argv 9 MOVQ 0(SP), DI // argc 10 MOVQ $main(SB), AX 11 JMP AX 12 13 // When building with -buildmode=c-shared, this symbol is called when the shared 14 // library is loaded. 15 // Note: This function calls external C code, which might required 16-byte stack 16 // alignment after cmd/internal/obj applies its transformations. 17 TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$0x50 18 MOVQ SP, AX 19 ANDQ $-16, SP 20 MOVQ BX, 0x10(SP) 21 MOVQ BP, 0x18(SP) 22 MOVQ R12, 0x20(SP) 23 MOVQ R13, 0x28(SP) 24 MOVQ R14, 0x30(SP) 25 MOVQ R15, 0x38(SP) 26 MOVQ AX, 0x40(SP) 27 28 MOVQ DI, _rt0_amd64_linux_lib_argc<>(SB) 29 MOVQ SI, _rt0_amd64_linux_lib_argv<>(SB) 30 31 // Synchronous initialization. 32 MOVQ $runtimelibpreinit(SB), AX 33 CALL AX 34 35 // Create a new thread to do the runtime initialization and return. 36 MOVQ _cgo_sys_thread_create(SB), AX 37 TESTQ AX, AX 38 JZ nocgo 39 MOVQ $_rt0_amd64_linux_lib_go(SB), DI 40 MOVQ $0, SI 41 CALL AX 42 JMP restore 43 44 nocgo: 45 MOVQ $8388608, 0(SP) // stacksize 46 MOVQ $_rt0_amd64_linux_lib_go(SB), AX 47 MOVQ AX, 8(SP) // fn 48 MOVQ $runtimenewosproc0(SB), AX 49 CALL AX 50 51 restore: 52 MOVQ 0x10(SP), BX 53 MOVQ 0x18(SP), BP 54 MOVQ 0x20(SP), R12 55 MOVQ 0x28(SP), R13 56 MOVQ 0x30(SP), R14 57 MOVQ 0x38(SP), R15 58 MOVQ 0x40(SP), SP 59 RET 60 61 TEXT _rt0_amd64_linux_lib_go(SB),NOSPLIT,$0 62 MOVQ _rt0_amd64_linux_lib_argc<>(SB), DI 63 MOVQ _rt0_amd64_linux_lib_argv<>(SB), SI 64 MOVQ $runtimert0_go(SB), AX 65 JMP AX 66 67 DATA _rt0_amd64_linux_lib_argc<>(SB)/8, $0 68 GLOBL _rt0_amd64_linux_lib_argc<>(SB),NOPTR, $8 69 DATA _rt0_amd64_linux_lib_argv<>(SB)/8, $0 70 GLOBL _rt0_amd64_linux_lib_argv<>(SB),NOPTR, $8 71 72 TEXT main(SB),NOSPLIT,$-8 73 MOVQ $runtimert0_go(SB), AX 74 JMP AX 75