aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/asm_amd64.s
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2021-04-13 23:30:19 -0400
committerAustin Clements <austin@google.com>2021-04-15 12:38:13 +0000
commit7ad496b6f5300131d6f1fbafe44ac882897889e4 (patch)
tree99f5c84ae8cebe176f35097effee24bc5e93e4bb /src/runtime/asm_amd64.s
parentdba2eab8267599f5f59f1f586b47f31b6552938c (diff)
downloadgo-7ad496b6f5300131d6f1fbafe44ac882897889e4.tar.gz
go-7ad496b6f5300131d6f1fbafe44ac882897889e4.zip
runtime: unify C->Go ABI transitions
The previous CL introduced macros for transitions from the Windows ABI to the Go ABI. This CL does the same for SysV and uses them in almost all places where we transition from the C ABI to the Go ABI. Compared to Windows, this transition is much simpler and I didn't find any places that were getting it wrong. But this does let us unify a lot of code nicely and introduces some degree of abstraction around these ABI transitions. Change-Id: Ib6bdecafce587ce18fca4c8300fcf401284a2bcd Reviewed-on: https://go-review.googlesource.com/c/go/+/309930 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/asm_amd64.s')
-rw-r--r--src/runtime/asm_amd64.s21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s
index 1c74d70d36..ca6b1501d1 100644
--- a/src/runtime/asm_amd64.s
+++ b/src/runtime/asm_amd64.s
@@ -6,6 +6,7 @@
#include "go_tls.h"
#include "funcdata.h"
#include "textflag.h"
+#include "cgo/abi_amd64.h"
// _rt0_amd64 is common startup code for most amd64 systems when using
// internal linking. This is the entry point for the program from the
@@ -28,14 +29,9 @@ TEXT main(SB),NOSPLIT,$-8
// 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
// DI and SI.
-TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x40
- // Save C ABI callee-saved registers, as caller may need them.
- MOVQ BX, 0x10(SP)
- MOVQ BP, 0x18(SP)
- MOVQ R12, 0x20(SP)
- MOVQ R13, 0x28(SP)
- MOVQ R14, 0x30(SP)
- MOVQ R15, 0x38(SP)
+TEXT _rt0_amd64_lib(SB),NOSPLIT,$0
+ // Transition from C ABI to Go ABI.
+ PUSH_REGS_HOST_TO_ABI0()
MOVQ DI, _rt0_amd64_lib_argc<>(SB)
MOVQ SI, _rt0_amd64_lib_argv<>(SB)
@@ -59,18 +55,15 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x40
JMP restore
nocgo:
+ ADJSP $16
MOVQ $0x800000, 0(SP) // stacksize
MOVQ $_rt0_amd64_lib_go(SB), AX
MOVQ AX, 8(SP) // fn
CALL runtime·newosproc0(SB)
+ ADJSP $-16
restore:
- MOVQ 0x10(SP), BX
- MOVQ 0x18(SP), BP
- MOVQ 0x20(SP), R12
- MOVQ 0x28(SP), R13
- MOVQ 0x30(SP), R14
- MOVQ 0x38(SP), R15
+ POP_REGS_HOST_TO_ABI0()
RET
// _rt0_amd64_lib_go initializes the Go runtime.