aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/asm_arm.s
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-10-13 13:52:57 -0700
committerIan Lance Taylor <iant@golang.org>2017-10-25 00:40:40 +0000
commitd92aaa970791472a1657e878bf686fe802943ebe (patch)
tree92c4fd495c5847ea382a5e53ecd075884e541dc2 /src/runtime/asm_arm.s
parent253e605af4533fd9f1276291225c27e972417e97 (diff)
downloadgo-d92aaa970791472a1657e878bf686fe802943ebe.tar.gz
go-d92aaa970791472a1657e878bf686fe802943ebe.zip
runtime: unify arm entry point code
Change-Id: Id51a2d63f7199b3ff71cedd415345ad20e5bd981 Reviewed-on: https://go-review.googlesource.com/70791 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/asm_arm.s')
-rw-r--r--src/runtime/asm_arm.s102
1 files changed, 100 insertions, 2 deletions
diff --git a/src/runtime/asm_arm.s b/src/runtime/asm_arm.s
index 9aea2a6e94..47fa565c52 100644
--- a/src/runtime/asm_arm.s
+++ b/src/runtime/asm_arm.s
@@ -7,14 +7,112 @@
#include "funcdata.h"
#include "textflag.h"
+// _rt0_arm is common startup code for most ARM systems when using
+// internal linking. This is the entry point for the program from the
+// kernel for an ordinary -buildmode=exe program. The stack holds the
+// number of arguments and the C-style argv.
+TEXT _rt0_arm(SB),NOSPLIT,$-4
+ MOVW (R13), R0 // argc
+ MOVW $4(R13), R1 // argv
+ B runtime·rt0_go(SB)
+
+// main is common startup code for most ARM systems when using
+// external linking. The C startup code will call the symbol "main"
+// passing argc and argv in the usual C ABI registers R0 and R1.
+TEXT main(SB),NOSPLIT,$-4
+ B runtime·rt0_go(SB)
+
+// _rt0_arm_lib is common startup code for most ARM systems when
+// using -buildmode=c-archive or -buildmode=c-shared. The linker will
+// arrange to invoke this function as a global constructor (for
+// c-archive) or when the shared library is loaded (for c-shared).
+// We expect argc and argv to be passed in the usual C ABI registers
+// R0 and R1.
+TEXT _rt0_arm_lib(SB),NOSPLIT,$104
+ // Preserve callee-save registers. Raspberry Pi's dlopen(), for example,
+ // actually cares that R11 is preserved.
+ MOVW R4, 12(R13)
+ MOVW R5, 16(R13)
+ MOVW R6, 20(R13)
+ MOVW R7, 24(R13)
+ MOVW R8, 28(R13)
+ MOVW R11, 32(R13)
+
+ // Skip floating point registers on GOARM < 6.
+ MOVB runtime·goarm(SB), R11
+ CMP $6, R11
+ BLT skipfpsave
+ MOVD F8, (32+8*1)(R13)
+ MOVD F9, (32+8*2)(R13)
+ MOVD F10, (32+8*3)(R13)
+ MOVD F11, (32+8*4)(R13)
+ MOVD F12, (32+8*5)(R13)
+ MOVD F13, (32+8*6)(R13)
+ MOVD F14, (32+8*7)(R13)
+ MOVD F15, (32+8*8)(R13)
+skipfpsave:
+ // Save argc/argv.
+ MOVW R0, _rt0_arm_lib_argc<>(SB)
+ MOVW R1, _rt0_arm_lib_argv<>(SB)
+
+ // Synchronous initialization.
+ CALL runtime·libpreinit(SB)
+
+ // Create a new thread to do the runtime initialization.
+ MOVW _cgo_sys_thread_create(SB), R2
+ CMP $0, R2
+ BEQ nocgo
+ MOVW $_rt0_arm_lib_go<>(SB), R0
+ MOVW $0, R1
+ BL (R2)
+ B rr
+nocgo:
+ MOVW $0x800000, R0 // stacksize = 8192KB
+ MOVW $_rt0_arm_lib_go<>(SB), R1 // fn
+ MOVW R0, 4(R13)
+ MOVW R1, 8(R13)
+ BL runtime·newosproc0(SB)
+rr:
+ // Restore callee-save registers and return.
+ MOVB runtime·goarm(SB), R11
+ CMP $6, R11
+ BLT skipfprest
+ MOVD (32+8*1)(R13), F8
+ MOVD (32+8*2)(R13), F9
+ MOVD (32+8*3)(R13), F10
+ MOVD (32+8*4)(R13), F11
+ MOVD (32+8*5)(R13), F12
+ MOVD (32+8*6)(R13), F13
+ MOVD (32+8*7)(R13), F14
+ MOVD (32+8*8)(R13), F15
+skipfprest:
+ MOVW 12(R13), R4
+ MOVW 16(R13), R5
+ MOVW 20(R13), R6
+ MOVW 24(R13), R7
+ MOVW 28(R13), R8
+ MOVW 32(R13), R11
+ RET
+
+// _rt0_arm_lib_go initializes the Go runtime.
+// This is started in a separate thread by _rt0_arm_lib.
+TEXT _rt0_arm_lib_go<>(SB),NOSPLIT,$8
+ MOVW _rt0_arm_lib_argc<>(SB), R0
+ MOVW _rt0_arm_lib_argv<>(SB), R1
+ B runtime·rt0_go(SB)
+
+DATA _rt0_arm_lib_argc<>(SB)/4,$0
+GLOBL _rt0_arm_lib_argc<>(SB),NOPTR,$4
+DATA _rt0_arm_lib_argv<>(SB)/4,$0
+GLOBL _rt0_arm_lib_argv<>(SB),NOPTR,$4
+
// using frame size $-4 means do not save LR on stack.
+// argc is in R0, argv is in R1.
TEXT runtime·rt0_go(SB),NOSPLIT,$-4
MOVW $0xcafebabe, R12
// copy arguments forward on an even stack
// use R13 instead of SP to avoid linker rewriting the offsets
- MOVW 0(R13), R0 // argc
- MOVW 4(R13), R1 // argv
SUB $64, R13 // plenty of scratch
AND $~7, R13
MOVW R0, 60(R13) // save argc, argv away