Shenghou Ma | 56e8f8e | 2014-12-26 01:07:10 -0500 | [diff] [blame] | 1 | // Copyright 2014 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_darwin(SB),7,$-4 |
| 8 | // prepare arguments for main (_rt0_go) |
| 9 | MOVW (R13), R0 // argc |
| 10 | MOVW $4(R13), R1 // argv |
| 11 | MOVW $main(SB), R4 |
| 12 | B (R4) |
| 13 | |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 14 | // When linking with -buildmode=c-archive or -buildmode=c-shared, |
| 15 | // this symbol is called from a global initialization function. |
| 16 | // |
| 17 | // Note that all currently shipping darwin/arm platforms require |
| 18 | // cgo and do not support c-shared. |
Elias Naur | ea4b785 | 2016-03-12 12:13:11 +0100 | [diff] [blame] | 19 | TEXT _rt0_arm_darwin_lib(SB),NOSPLIT,$32 |
| 20 | // Preserve callee-save registers. |
| 21 | MOVW R4, 12(R13) |
| 22 | MOVW R5, 16(R13) |
| 23 | MOVW R6, 20(R13) |
| 24 | MOVW R7, 24(R13) |
| 25 | MOVW R8, 28(R13) |
| 26 | MOVW R11, 32(R13) |
| 27 | |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 28 | MOVW R0, _rt0_arm_darwin_lib_argc<>(SB) |
| 29 | MOVW R1, _rt0_arm_darwin_lib_argv<>(SB) |
| 30 | |
Ian Lance Taylor | 21b4f23 | 2015-12-26 09:51:59 -0800 | [diff] [blame] | 31 | // Synchronous initialization. |
| 32 | MOVW $runtime·libpreinit(SB), R3 |
| 33 | CALL (R3) |
| 34 | |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 35 | // Create a new thread to do the runtime initialization and return. |
David Crawshaw | fb30270 | 2015-09-15 13:40:24 -0400 | [diff] [blame] | 36 | MOVW _cgo_sys_thread_create(SB), R3 |
| 37 | CMP $0, R3 |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 38 | B.EQ nocgo |
| 39 | MOVW $_rt0_arm_darwin_lib_go(SB), R0 |
| 40 | MOVW $0, R1 |
David Crawshaw | fb30270 | 2015-09-15 13:40:24 -0400 | [diff] [blame] | 41 | BL (R3) |
Elias Naur | ea4b785 | 2016-03-12 12:13:11 +0100 | [diff] [blame] | 42 | B rr |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 43 | nocgo: |
| 44 | MOVW $0x400000, R0 |
David Crawshaw | fb30270 | 2015-09-15 13:40:24 -0400 | [diff] [blame] | 45 | MOVW R0, (R13) // stacksize |
| 46 | MOVW $_rt0_arm_darwin_lib_go(SB), R0 |
| 47 | MOVW R0, 4(R13) // fn |
| 48 | MOVW $0, R0 |
| 49 | MOVW R0, 8(R13) // fnarg |
| 50 | MOVW $runtime·newosproc0(SB), R3 |
David Crawshaw | fb30270 | 2015-09-15 13:40:24 -0400 | [diff] [blame] | 51 | BL (R3) |
Elias Naur | ea4b785 | 2016-03-12 12:13:11 +0100 | [diff] [blame] | 52 | rr: |
| 53 | // Restore callee-save registers and return. |
| 54 | MOVW 12(R13), R4 |
| 55 | MOVW 16(R13), R5 |
| 56 | MOVW 20(R13), R6 |
| 57 | MOVW 24(R13), R7 |
| 58 | MOVW 28(R13), R8 |
| 59 | MOVW 32(R13), R11 |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 60 | RET |
| 61 | |
Elias Naur | ea4b785 | 2016-03-12 12:13:11 +0100 | [diff] [blame] | 62 | |
David Crawshaw | 6e3a6c4 | 2015-04-10 13:07:04 -0400 | [diff] [blame] | 63 | TEXT _rt0_arm_darwin_lib_go(SB),NOSPLIT,$0 |
| 64 | MOVW _rt0_arm_darwin_lib_argc<>(SB), R0 |
| 65 | MOVW _rt0_arm_darwin_lib_argv<>(SB), R1 |
| 66 | MOVW R0, (R13) |
| 67 | MOVW R1, 4(R13) |
| 68 | MOVW $runtime·rt0_go(SB), R4 |
| 69 | B (R4) |
| 70 | |
| 71 | DATA _rt0_arm_darwin_lib_argc<>(SB)/4, $0 |
| 72 | GLOBL _rt0_arm_darwin_lib_argc<>(SB),NOPTR, $4 |
| 73 | DATA _rt0_arm_darwin_lib_argv<>(SB)/4, $0 |
| 74 | GLOBL _rt0_arm_darwin_lib_argv<>(SB),NOPTR, $4 |
| 75 | |
Shenghou Ma | 56e8f8e | 2014-12-26 01:07:10 -0500 | [diff] [blame] | 76 | TEXT main(SB),NOSPLIT,$-8 |
| 77 | // save argc and argv onto stack |
| 78 | MOVM.DB.W [R0-R1], (R13) |
| 79 | MOVW $runtime·rt0_go(SB), R4 |
| 80 | B (R4) |