]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: change amd64 startup convention
authorRuss Cox <rsc@golang.org>
Wed, 6 Mar 2013 20:03:04 +0000 (15:03 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 6 Mar 2013 20:03:04 +0000 (15:03 -0500)
Now the default startup is that the program begins at _rt0_amd64_$GOOS,
which sets DI = argc, SI = argv and jumps to _rt0_amd64.

This makes the _rt0_amd64 entry match the expected semantics for
the standard C "main" function, which we can now provide for use when
linking against a standard C library.

R=golang-dev, devon.odell, minux.ma
CC=golang-dev
https://golang.org/cl/7525043

src/pkg/runtime/asm_amd64.s
src/pkg/runtime/rt0_darwin_amd64.s
src/pkg/runtime/rt0_freebsd_amd64.s
src/pkg/runtime/rt0_linux_amd64.s
src/pkg/runtime/rt0_netbsd_amd64.s
src/pkg/runtime/rt0_openbsd_amd64.s
src/pkg/runtime/rt0_plan9_amd64.s
src/pkg/runtime/rt0_windows_amd64.s

index 696befd6e4dc93995621deb54f1bd30a9d0dc3e9..a671f39925c282927f711a4f0eb368488aeeed50 100644 (file)
@@ -6,8 +6,8 @@
 
 TEXT _rt0_amd64(SB),7,$-8
        // copy arguments forward on an even stack
-       MOVQ    0(DI), AX               // argc
-       LEAQ    8(DI), BX               // argv
+       MOVQ    DI, AX          // argc
+       MOVQ    SI, BX          // argv
        SUBQ    $(4*8+7), SP            // 2args 2auto
        ANDQ    $~15, SP
        MOVQ    AX, 16(SP)
index 4cfab587644e9fb67d7b669fa9597921afde35e5..45e69a01596a4a313865a788ff73bbb38c760583 100644 (file)
@@ -2,9 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Darwin and Linux use the same linkage to main
-
 TEXT _rt0_amd64_darwin(SB),7,$-8
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
        MOVQ    $_rt0_amd64(SB), AX
-       MOVQ    SP, DI
        JMP     AX
index 5d2eeeefff4315b31361bcad80f56b0c15ee4f7d..e6c6fb9cac77b725df7dc40979d544772b8e6918 100644 (file)
@@ -2,8 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Darwin and Linux use the same linkage to main
-
 TEXT _rt0_amd64_freebsd(SB),7,$-8
-       MOVQ    $_rt0_amd64(SB), DX
-       JMP     DX
+       LEAQ    8(DI), SI // argv
+       MOVQ    0(DI), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
+       MOVQ    $_rt0_amd64(SB), AX
+       JMP     AX
index dac9ae181b04ad00fc775d5af147b9582b33312f..dfc9c0421bd6401562d0f19b93a729bddba0ee63 100644 (file)
@@ -2,9 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Darwin and Linux use the same linkage to main
-
 TEXT _rt0_amd64_linux(SB),7,$-8
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
        MOVQ    $_rt0_amd64(SB), AX
-       MOVQ    SP, DI
        JMP     AX
index 85482b98db2795b924e7b8fd819646fe9627c6fb..245a4c0f9b497401127e0eda663c352ff54bd7d2 100644 (file)
@@ -2,7 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-TEXT _rt0_amd64_netbsd(SB),7,$-8
-       MOVQ    $_rt0_amd64(SB), DX
-       MOVQ    SP, DI
-       JMP     DX
+TEXT _rt0_amd64_openbsd(SB),7,$-8
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
+       MOVQ    $_rt0_amd64(SB), AX
+       JMP     AX
index e7fce59696826258db3105204d768e652f19ca36..245a4c0f9b497401127e0eda663c352ff54bd7d2 100644 (file)
@@ -3,6 +3,11 @@
 // license that can be found in the LICENSE file.
 
 TEXT _rt0_amd64_openbsd(SB),7,$-8
-       MOVQ    $_rt0_amd64(SB), DX
-       MOVQ    SP, DI
-       JMP     DX
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
+       MOVQ    $_rt0_amd64(SB), AX
+       JMP     AX
index 2b1fa2ae1dd032ad33721674a7b2e167fe1c448c..16e5e82b755f3c97d10048edbecc932807e2708d 100644 (file)
@@ -2,9 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-TEXT _rt0_amd64_plan9(SB),7, $0
+TEXT _rt0_amd64_plan9(SB),7,$-8
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
        MOVQ    $_rt0_amd64(SB), AX
-       MOVQ    SP, DI
        JMP     AX
 
 DATA runtime·isplan9(SB)/4, $1
index dc1408adc352f066806782d72140a130fa079fb1..4fc61dc687bcfadc485452d31de6427b0e7a94b9 100644 (file)
@@ -4,9 +4,14 @@
 
 #include "zasm_GOOS_GOARCH.h"
 
-TEXT   _rt0_amd64_windows(SB),7,$-8
+TEXT _rt0_amd64_darwin(SB),7,$-8
+       LEAQ    8(SP), SI // argv
+       MOVQ    0(SP), DI // argc
+       MOVQ    $main(SB), AX
+       JMP     AX
+
+TEXT main(SB),7,$-8
        MOVQ    $_rt0_amd64(SB), AX
-       MOVQ    SP, DI
        JMP     AX
 
 DATA  runtime·iswindows(SB)/4, $1