From 93644c9118dfcd5c7b46d22fbe6b7f1cb1f1b696 Mon Sep 17 00:00:00 2001 From: Srdjan Petrovic Date: Fri, 3 Apr 2015 09:40:10 -0700 Subject: runtime: shared library runtime init for arm Adds the runtime initialization flow for arm akin to amd64. In particular,we use the library initialization entry point to: - create a new OS thread and run the "regular" runtime init stack on that thread - return immediately from the main (i.e., loader) thread - at the first CGO invocation, we wait for the runtime initialization to complete. Verified to work on a Raspberry Pi and an Android phone. Change-Id: I32f39228ae30a03ce9569287f234b305790fecf6 Reviewed-on: https://go-review.googlesource.com/8455 Reviewed-by: David Crawshaw Run-TryBot: Srdjan Petrovic --- src/runtime/sys_linux_arm.s | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/runtime/sys_linux_arm.s') diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s index db9fcb90cf..d422f95f08 100644 --- a/src/runtime/sys_linux_arm.s +++ b/src/runtime/sys_linux_arm.s @@ -310,12 +310,43 @@ TEXT runtime·clone(SB),NOSPLIT,$0 MOVW R0, (R1) // int32 clone0(int32 flags, void *stack, void* fn, void* fnarg); -TEXT runtime·clone0(SB),NOSPLIT,$0 - // TODO(spetrovic): Implement this method. - MOVW $-1, R0 +TEXT runtime·clone0(SB),NOSPLIT,$0-20 + MOVW flags+0(FP), R0 + MOVW stack+4(FP), R1 + // Update child's future stack and save fn and fnarg on it. + MOVW $-8(R1), R1 + MOVW fn+8(FP), R6 + MOVW R6, 0(R1) + MOVW fnarg+12(FP), R6 + MOVW R6, 4(R1) + MOVW $0, R2 // parent tid ptr + MOVW $0, R3 // tls_val + MOVW $0, R4 // child tid ptr + MOVW $0, R5 + MOVW $SYS_clone, R7 + SWI $0 + + // In parent, return. + CMP $0, R0 + BEQ 3(PC) MOVW R0, ret+16(FP) RET + // In child. + MOVW 0(R13), R6 // fn + MOVW 4(R13), R0 // fnarg + MOVW $8(R13), R13 + BL (R6) + + MOVW $0, R0 + MOVW R0, 4(R13) + BL runtime·exit1(SB) + + // It shouldn't return + MOVW $1234, R0 + MOVW $1005, R1 + MOVW R0, (R1) + TEXT runtime·sigaltstack(SB),NOSPLIT,$0 MOVW new+0(FP), R0 MOVW old+4(FP), R1 -- cgit v1.3-5-g45d5