From dfc22e29ec2f687375d32c9f7662416d0c9f97d3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 7 Mar 2013 19:57:10 -0800 Subject: [PATCH] runtime: change 386 startup convention Now the default startup is that the program begins at _rt0_386_$GOOS, which behaves as if calling main(argc, argv). Main jumps to _rt0_386. This makes the _rt0_386 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. 386 analogue of https://golang.org/cl/7525043 R=golang-dev, r CC=golang-dev https://golang.org/cl/7551045 --- src/pkg/runtime/asm_386.s | 4 ++-- src/pkg/runtime/rt0_darwin_386.s | 10 ++++++++-- src/pkg/runtime/rt0_freebsd_386.s | 11 ++++++++--- src/pkg/runtime/rt0_linux_386.s | 14 ++++++++++---- src/pkg/runtime/rt0_netbsd_386.s | 12 ++++++++++-- src/pkg/runtime/rt0_openbsd_386.s | 12 ++++++++++-- src/pkg/runtime/rt0_plan9_386.s | 7 +++++++ src/pkg/runtime/rt0_windows_386.s | 11 ++++++++++- src/pkg/runtime/signal_linux_386.c | 3 +-- 9 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/pkg/runtime/asm_386.s b/src/pkg/runtime/asm_386.s index 96f04e0ae90..375274e0b3a 100644 --- a/src/pkg/runtime/asm_386.s +++ b/src/pkg/runtime/asm_386.s @@ -6,8 +6,8 @@ TEXT _rt0_386(SB),7,$0 // copy arguments forward on an even stack - MOVL 0(SP), AX // argc - LEAL 4(SP), BX // argv + MOVL argc+0(FP), AX + MOVL argv+4(FP), BX SUBL $128, SP // plenty of scratch ANDL $~15, SP MOVL AX, 120(SP) // save argc, argv away diff --git a/src/pkg/runtime/rt0_darwin_386.s b/src/pkg/runtime/rt0_darwin_386.s index 30b497f5e74..4b4c1f29422 100644 --- a/src/pkg/runtime/rt0_darwin_386.s +++ b/src/pkg/runtime/rt0_darwin_386.s @@ -2,7 +2,13 @@ // 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_386_darwin(SB),7,$8 + MOVL 8(SP), AX + LEAL 12(SP), BX + MOVL AX, 0(SP) + MOVL BX, 4(SP) + CALL main(SB) + INT $3 -TEXT _rt0_386_darwin(SB),7,$0 +TEXT main(SB),7,$0 JMP _rt0_386(SB) diff --git a/src/pkg/runtime/rt0_freebsd_386.s b/src/pkg/runtime/rt0_freebsd_386.s index 3ca981b3a31..c84482cdbfe 100644 --- a/src/pkg/runtime/rt0_freebsd_386.s +++ b/src/pkg/runtime/rt0_freebsd_386.s @@ -2,8 +2,13 @@ // 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_386_freebsd(SB),7,$8 + MOVL 8(SP), AX + LEAL 12(SP), BX + MOVL AX, 0(SP) + MOVL BX, 4(SP) + CALL main(SB) + INT $3 -TEXT _rt0_386_freebsd(SB),7,$0 +TEXT main(SB),7,$0 JMP _rt0_386(SB) - diff --git a/src/pkg/runtime/rt0_linux_386.s b/src/pkg/runtime/rt0_linux_386.s index 83149540ec4..73cca5d9805 100644 --- a/src/pkg/runtime/rt0_linux_386.s +++ b/src/pkg/runtime/rt0_linux_386.s @@ -2,11 +2,17 @@ // 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_386_linux(SB),7,$0 +TEXT _rt0_386_linux(SB),7,$8 + MOVL 8(SP), AX + LEAL 12(SP), BX + MOVL AX, 0(SP) + MOVL BX, 4(SP) CALL runtime·linux_setup_vdso(SB) - JMP _rt0_386(SB) + CALL main(SB) + INT $3 + +TEXT main(SB),7,$0 + JMP _rt0_386(SB) TEXT _fallback_vdso(SB),7,$0 INT $0x80 diff --git a/src/pkg/runtime/rt0_netbsd_386.s b/src/pkg/runtime/rt0_netbsd_386.s index 829e4133b8b..b4c029c538d 100644 --- a/src/pkg/runtime/rt0_netbsd_386.s +++ b/src/pkg/runtime/rt0_netbsd_386.s @@ -2,5 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -TEXT _rt0_386_netbsd(SB),7,$0 - JMP _rt0_386(SB) +TEXT _rt0_386_netbsd(SB),7,$8 + MOVL 8(SP), AX + LEAL 12(SP), BX + MOVL AX, 0(SP) + MOVL BX, 4(SP) + CALL main(SB) + INT $3 + +TEXT main(SB),7,$0 + JMP _rt0_386(SB) diff --git a/src/pkg/runtime/rt0_openbsd_386.s b/src/pkg/runtime/rt0_openbsd_386.s index e7e0da78f2f..9c00a733408 100644 --- a/src/pkg/runtime/rt0_openbsd_386.s +++ b/src/pkg/runtime/rt0_openbsd_386.s @@ -2,5 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -TEXT _rt0_386_openbsd(SB),7,$0 - JMP _rt0_386(SB) +TEXT _rt0_386_openbsd(SB),7,$8 + MOVL 8(SP), AX + LEAL 12(SP), BX + MOVL AX, 0(SP) + MOVL BX, 4(SP) + CALL main(SB) + INT $3 + +TEXT main(SB),7,$0 + JMP _rt0_386(SB) diff --git a/src/pkg/runtime/rt0_plan9_386.s b/src/pkg/runtime/rt0_plan9_386.s index 56f3a0f6c72..7af1eae7cb9 100644 --- a/src/pkg/runtime/rt0_plan9_386.s +++ b/src/pkg/runtime/rt0_plan9_386.s @@ -26,6 +26,13 @@ argv_fix: LOOP argv_fix CALL runtime·asminit(SB) + + MOVL 0(SP), AX + LEAL 4(SP), BX + PUSHL BX + PUSHL AX + PUSHL $-1 + JMP _rt0_386(SB) DATA runtime·isplan9(SB)/4, $1 diff --git a/src/pkg/runtime/rt0_windows_386.s b/src/pkg/runtime/rt0_windows_386.s index a06aa787e2e..6e34c6c172a 100644 --- a/src/pkg/runtime/rt0_windows_386.s +++ b/src/pkg/runtime/rt0_windows_386.s @@ -2,8 +2,17 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -TEXT _rt0_386_windows(SB),7,$0 +TEXT _rt0_386_windows(SB),7,$12 + MOVL 12(SP), AX + LEAL 16(SP), BX + MOVL AX, 4(SP) + MOVL BX, 8(SP) + MOVL $-1, 0(SP) // return PC for main + JMP main(SB) + +TEXT main(SB),7,$0 JMP _rt0_386(SB) + DATA runtime·iswindows(SB)/4, $1 GLOBL runtime·iswindows(SB), $4 diff --git a/src/pkg/runtime/signal_linux_386.c b/src/pkg/runtime/signal_linux_386.c index 9b45ec3bd2e..ed9ae3a8e54 100644 --- a/src/pkg/runtime/signal_linux_386.c +++ b/src/pkg/runtime/signal_linux_386.c @@ -155,9 +155,8 @@ extern uint32 runtime·_vdso; #pragma textflag 7 void -runtime·linux_setup_vdso(int32 argc, void *argv_list) +runtime·linux_setup_vdso(int32 argc, byte **argv) { - byte **argv = &argv_list; byte **envp; uint32 *auxv;