github.com/aloncn/graphics-go@v0.0.1/src/runtime/rt0_linux_arm.s (about)

     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_arm_linux(SB),NOSPLIT,$-4
     8  	MOVW	(R13), R0	// argc
     9  	MOVW	$4(R13), R1		// argv
    10  	MOVW	$_rt0_arm_linux1(SB), R4
    11  	B		(R4)
    12  
    13  // When building with -buildmode=c-shared, this symbol is called when the shared
    14  // library is loaded.
    15  TEXT _rt0_arm_linux_lib(SB),NOSPLIT,$32
    16  	// Preserve callee-save registers.  Raspberry Pi's dlopen(), for example,
    17  	// actually cares that R11 is preserved.
    18  	MOVW	R4, 12(R13)
    19  	MOVW	R5, 16(R13)
    20  	MOVW	R6, 20(R13)
    21  	MOVW	R7, 24(R13)
    22  	MOVW	R8, 28(R13)
    23  	MOVW	R11, 32(R13)
    24  
    25  	// Save argc/argv.
    26  	MOVW	R0, _rt0_arm_linux_lib_argc<>(SB)
    27  	MOVW	R1, _rt0_arm_linux_lib_argv<>(SB)
    28  
    29  	// Synchronous initialization.
    30  	MOVW	$runtime·libpreinit(SB), R2
    31  	CALL	(R2)
    32  
    33  	// Create a new thread to do the runtime initialization.
    34  	MOVW	_cgo_sys_thread_create(SB), R2
    35  	CMP	$0, R2
    36  	BEQ	nocgo
    37  	MOVW	$_rt0_arm_linux_lib_go<>(SB), R0
    38  	MOVW	$0, R1
    39  	BL	(R2)
    40  	B	rr
    41  nocgo:
    42  	MOVW	$0x800000, R0                     // stacksize = 8192KB
    43  	MOVW	$_rt0_arm_linux_lib_go<>(SB), R1  // fn
    44  	MOVW	R0, 4(R13)
    45  	MOVW	R1, 8(R13)
    46  	BL	runtime·newosproc0(SB)
    47  rr:
    48  	// Restore callee-save registers and return.
    49  	MOVW	12(R13), R4
    50  	MOVW	16(R13), R5
    51  	MOVW	20(R13), R6
    52  	MOVW	24(R13), R7
    53  	MOVW	28(R13), R8
    54  	MOVW	32(R13), R11
    55  	RET
    56  
    57  TEXT _rt0_arm_linux_lib_go<>(SB),NOSPLIT,$8
    58  	MOVW	_rt0_arm_linux_lib_argc<>(SB), R0
    59  	MOVW	_rt0_arm_linux_lib_argv<>(SB), R1
    60  	MOVW	R0, 0(R13)
    61  	MOVW	R1, 4(R13)
    62  	B	runtime·rt0_go(SB)
    63  
    64  DATA _rt0_arm_linux_lib_argc<>(SB)/4,$0
    65  GLOBL _rt0_arm_linux_lib_argc<>(SB),NOPTR,$4
    66  DATA _rt0_arm_linux_lib_argv<>(SB)/4,$0
    67  GLOBL _rt0_arm_linux_lib_argv<>(SB),NOPTR,$4
    68  
    69  TEXT _rt0_arm_linux1(SB),NOSPLIT,$-4
    70  	// We first need to detect the kernel ABI, and warn the user
    71  	// if the system only supports OABI
    72  	// The strategy here is to call some EABI syscall to see if
    73  	// SIGILL is received.
    74  	// To catch SIGILL, we have to first setup sigaction, this is
    75  	// a chicken-and-egg problem, because we can't do syscall if
    76  	// we don't know the kernel ABI... Oh, not really, we can do
    77  	// syscall in Thumb mode.
    78  
    79  	// Save argc and argv
    80  	MOVM.DB.W [R0-R1], (R13)
    81  
    82  	// Thumb mode OABI check disabled because there are some
    83  	// EABI systems that do not support Thumb execution.
    84  	// We can run on them except for this check!
    85  
    86  	// // set up sa_handler
    87  	// MOVW	$bad_abi<>(SB), R0 // sa_handler
    88  	// MOVW	$0, R1 // sa_flags
    89  	// MOVW	$0, R2 // sa_restorer
    90  	// MOVW	$0, R3 // sa_mask
    91  	// MOVM.DB.W [R0-R3], (R13)
    92  	// MOVW	$4, R0 // SIGILL
    93  	// MOVW	R13, R1 // sa
    94  	// SUB	$16, R13
    95  	// MOVW	R13, R2 // old_sa
    96  	// MOVW	$8, R3 // c
    97  	// MOVW	$174, R7 // sys_sigaction
    98  	// BL	oabi_syscall<>(SB)
    99  
   100  	// do an EABI syscall
   101  	MOVW	$20, R7 // sys_getpid
   102  	SWI	$0 // this will trigger SIGILL on OABI systems
   103  	
   104  	// MOVW	$4, R0  // SIGILL
   105  	// MOVW	R13, R1 // sa
   106  	// MOVW	$0, R2 // old_sa
   107  	// MOVW	$8, R3 // c
   108  	// MOVW	$174, R7 // sys_sigaction
   109  	// SWI	$0 // restore signal handler
   110  	// ADD	$32, R13
   111  
   112  	B	runtime·rt0_go(SB)
   113  
   114  TEXT bad_abi<>(SB),NOSPLIT,$-4
   115  	// give diagnosis and exit
   116  	MOVW	$2, R0 // stderr
   117  	MOVW	$bad_abi_msg(SB), R1 // data
   118  	MOVW	$45, R2 // len
   119  	MOVW	$4, R7 // sys_write
   120  	BL	oabi_syscall<>(SB)
   121  	MOVW	$1, R0
   122  	MOVW	$1, R7 // sys_exit
   123  	BL	oabi_syscall<>(SB)
   124  	B  	0(PC)
   125  
   126  DATA bad_abi_msg+0x00(SB)/8, $"This pro"
   127  DATA bad_abi_msg+0x08(SB)/8, $"gram can"
   128  DATA bad_abi_msg+0x10(SB)/8, $" only be"
   129  DATA bad_abi_msg+0x18(SB)/8, $" run on "
   130  DATA bad_abi_msg+0x20(SB)/8, $"EABI ker"
   131  DATA bad_abi_msg+0x28(SB)/4, $"nels"
   132  DATA bad_abi_msg+0x2c(SB)/1, $0xa
   133  GLOBL bad_abi_msg(SB), RODATA, $45
   134  
   135  TEXT oabi_syscall<>(SB),NOSPLIT,$-4
   136  	ADD $1, R15, R4 // R15 is hardware PC
   137  	WORD $0xe12fff14 //BX	(R4) // enter thumb mode
   138  	// TODO(minux): only supports little-endian CPUs
   139  	WORD $0x4770df01 // swi $1; bx lr
   140  
   141  TEXT main(SB),NOSPLIT,$-4
   142  	MOVW	$_rt0_arm_linux1(SB), R4
   143  	B		(R4)
   144