Text file src/runtime/rt0_linux_ppc64le.s

     1  // Copyright 2016 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 "textflag.h"
     7  #include "asm_ppc64x.h"
     8  
     9  TEXT _rt0_ppc64le_linux(SB),NOSPLIT,$0
    10  	XOR R0, R0	  // Make sure R0 is zero before _main
    11  	BR _main<>(SB)
    12  
    13  TEXT _rt0_ppc64le_linux_lib(SB),NOSPLIT|NOFRAME,$0
    14  	JMP _rt0_ppc64x_lib(SB)
    15  
    16  TEXT _main<>(SB),NOSPLIT,$-8
    17  	// In a statically linked binary, the stack contains argc,
    18  	// argv as argc string pointers followed by a NULL, envv as a
    19  	// sequence of string pointers followed by a NULL, and auxv.
    20  	// The TLS pointer should be initialized to 0.
    21  	//
    22  	// In an ELFv2 compliant dynamically linked binary, R3 contains argc,
    23  	// R4 contains argv, R5 contains envp, R6 contains auxv, and R13
    24  	// contains the TLS pointer.
    25  	//
    26  	// When loading via glibc, the first doubleword on the stack points
    27  	// to NULL a value. (that is *(uintptr)(R1) == 0). This is used to
    28  	// differentiate static vs dynamically linked binaries.
    29  	//
    30  	// If loading with the musl loader, it doesn't follow the ELFv2 ABI. It
    31  	// passes argc/argv similar to the linux kernel, R13 (TLS) is
    32  	// initialized, and R3/R4 are undefined.
    33  	MOVD	(R1), R12
    34  	CMP	R12, $0
    35  	BEQ	tls_and_argcv_in_reg
    36  
    37  	// Arguments are passed via the stack (musl loader or a static binary)
    38  	MOVD	0(R1), R3 // argc
    39  	ADD	$8, R1, R4 // argv
    40  
    41  	// Did the TLS pointer get set? If so, don't change it (e.g musl).
    42  	CMP	R13, $0
    43  	BNE	tls_and_argcv_in_reg
    44  
    45  	MOVD	$runtimeĀ·m0+m_tls(SB), R13 // TLS
    46  	ADD	$0x7000, R13
    47  
    48  tls_and_argcv_in_reg:
    49  	BR	main(SB)
    50  
    51  TEXT main(SB),NOSPLIT,$-8
    52  	MOVD	$runtimeĀ·rt0_go(SB), R12
    53  	MOVD	R12, CTR
    54  	BR	(CTR)
    55  

View as plain text