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>
This commit is contained in:
Austin Clements 2021-04-13 23:30:19 -04:00
parent dba2eab826
commit 7ad496b6f5
12 changed files with 143 additions and 229 deletions

View file

@ -6,6 +6,7 @@
#include "go_tls.h" #include "go_tls.h"
#include "funcdata.h" #include "funcdata.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
// _rt0_amd64 is common startup code for most amd64 systems when using // _rt0_amd64 is common startup code for most amd64 systems when using
// internal linking. This is the entry point for the program from the // 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). // 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 // We expect argc and argv to be passed in the usual C ABI registers
// DI and SI. // DI and SI.
TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x40 TEXT _rt0_amd64_lib(SB),NOSPLIT,$0
// Save C ABI callee-saved registers, as caller may need them. // Transition from C ABI to Go ABI.
MOVQ BX, 0x10(SP) PUSH_REGS_HOST_TO_ABI0()
MOVQ BP, 0x18(SP)
MOVQ R12, 0x20(SP)
MOVQ R13, 0x28(SP)
MOVQ R14, 0x30(SP)
MOVQ R15, 0x38(SP)
MOVQ DI, _rt0_amd64_lib_argc<>(SB) MOVQ DI, _rt0_amd64_lib_argc<>(SB)
MOVQ SI, _rt0_amd64_lib_argv<>(SB) MOVQ SI, _rt0_amd64_lib_argv<>(SB)
@ -59,18 +55,15 @@ TEXT _rt0_amd64_lib(SB),NOSPLIT,$0x40
JMP restore JMP restore
nocgo: nocgo:
ADJSP $16
MOVQ $0x800000, 0(SP) // stacksize MOVQ $0x800000, 0(SP) // stacksize
MOVQ $_rt0_amd64_lib_go(SB), AX MOVQ $_rt0_amd64_lib_go(SB), AX
MOVQ AX, 8(SP) // fn MOVQ AX, 8(SP) // fn
CALL runtime·newosproc0(SB) CALL runtime·newosproc0(SB)
ADJSP $-16
restore: restore:
MOVQ 0x10(SP), BX POP_REGS_HOST_TO_ABI0()
MOVQ 0x18(SP), BP
MOVQ 0x20(SP), R12
MOVQ 0x28(SP), R13
MOVQ 0x30(SP), R14
MOVQ 0x38(SP), R15
RET RET
// _rt0_amd64_lib_go initializes the Go runtime. // _rt0_amd64_lib_go initializes the Go runtime.

View file

@ -4,7 +4,9 @@
// Macros for transitioning from the host ABI to Go ABI0. // Macros for transitioning from the host ABI to Go ABI0.
// //
// TODO(austin): Define these for ELF platforms as well. // These save the frame pointer, so in general, functions that use
// these should have zero frame size to suppress the automatic frame
// pointer, though it's harmless to not do this.
#ifdef GOOS_windows #ifdef GOOS_windows
@ -66,4 +68,32 @@
ADJSP $-(REGS_HOST_TO_ABI0_STACK - 8) \ ADJSP $-(REGS_HOST_TO_ABI0_STACK - 8) \
POPFQ POPFQ
#else
// SysV ABI
#define REGS_HOST_TO_ABI0_STACK (6*8)
// SysV MXCSR matches the Go ABI, so we don't have to set that,
// and Go doesn't modify it, so we don't have to save it.
// Both SysV and Go require DF to be cleared, so that's already clear.
// The SysV and Go frame pointer conventions are compatible.
#define PUSH_REGS_HOST_TO_ABI0() \
ADJSP $(REGS_HOST_TO_ABI0_STACK) \
MOVQ BP, (5*8)(SP) \
LEAQ (5*8)(SP), BP \
MOVQ BX, (0*8)(SP) \
MOVQ R12, (1*8)(SP) \
MOVQ R13, (2*8)(SP) \
MOVQ R14, (3*8)(SP) \
MOVQ R15, (4*8)(SP)
#define POP_REGS_HOST_TO_ABI0() \
MOVQ (0*8)(SP), BX \
MOVQ (1*8)(SP), R12 \
MOVQ (2*8)(SP), R13 \
MOVQ (3*8)(SP), R14 \
MOVQ (4*8)(SP), R15 \
MOVQ (5*8)(SP), BP \
ADJSP $-(REGS_HOST_TO_ABI0_STACK)
#endif #endif

View file

@ -10,43 +10,25 @@
// Saves C callee-saved registers and calls cgocallback with three arguments. // Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function. // fn is the PC of a func(a unsafe.Pointer) function.
// This signature is known to SWIG, so we can't change it. // This signature is known to SWIG, so we can't change it.
#ifndef GOOS_windows
TEXT crosscall2(SB),NOSPLIT,$0x50-0 /* keeps stack pointer 32-byte aligned */
MOVQ BX, 0x18(SP)
MOVQ R12, 0x28(SP)
MOVQ R13, 0x30(SP)
MOVQ R14, 0x38(SP)
MOVQ R15, 0x40(SP)
MOVQ DI, 0x0(SP) /* fn */
MOVQ SI, 0x8(SP) /* arg */
// Skip n in DX.
MOVQ CX, 0x10(SP) /* ctxt */
CALL runtime·cgocallback(SB)
MOVQ 0x18(SP), BX
MOVQ 0x28(SP), R12
MOVQ 0x30(SP), R13
MOVQ 0x38(SP), R14
MOVQ 0x40(SP), R15
RET
#else
TEXT crosscall2(SB),NOSPLIT,$0-0 TEXT crosscall2(SB),NOSPLIT,$0-0
PUSH_REGS_HOST_TO_ABI0() PUSH_REGS_HOST_TO_ABI0()
// Make room for arguments to cgocallback. // Make room for arguments to cgocallback.
ADJSP $0x18 ADJSP $0x18
#ifndef GOOS_windows
MOVQ DI, 0x0(SP) /* fn */
MOVQ SI, 0x8(SP) /* arg */
// Skip n in DX.
MOVQ CX, 0x10(SP) /* ctxt */
#else
MOVQ CX, 0x0(SP) /* fn */ MOVQ CX, 0x0(SP) /* fn */
MOVQ DX, 0x8(SP) /* arg */ MOVQ DX, 0x8(SP) /* arg */
// Skip n in R8. // Skip n in R8.
MOVQ R9, 0x10(SP) /* ctxt */ MOVQ R9, 0x10(SP) /* ctxt */
#endif
CALL runtime·cgocallback(SB) CALL runtime·cgocallback(SB)
ADJSP $-0x18 ADJSP $-0x18
POP_REGS_HOST_TO_ABI0() POP_REGS_HOST_TO_ABI0()
RET RET
#endif

View file

@ -385,7 +385,7 @@ func mdestroy(mp *m) {
//#endif //#endif
func sigreturn() func sigreturn()
func sigtramp(sig uint32, info *siginfo, ctx unsafe.Pointer) func sigtramp() // Called via C ABI
func cgoSigtramp() func cgoSigtramp()
//go:noescape //go:noescape

View file

@ -8,6 +8,7 @@
#include "go_tls.h" #include "go_tls.h"
#include "funcdata.h" #include "funcdata.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
// The following thunks allow calling the gcc-compiled race runtime directly // The following thunks allow calling the gcc-compiled race runtime directly
// from Go code without going all the way through cgo. // from Go code without going all the way through cgo.
@ -441,7 +442,7 @@ call:
// See racecallback for command codes. // See racecallback for command codes.
// Defined as ABIInternal so as to avoid introducing a wrapper, // Defined as ABIInternal so as to avoid introducing a wrapper,
// because its address is passed to C via funcPC. // because its address is passed to C via funcPC.
TEXT runtime·racecallbackthunk<ABIInternal>(SB), NOSPLIT, $56-8 TEXT runtime·racecallbackthunk<ABIInternal>(SB), NOSPLIT, $0-0
// Handle command raceGetProcCmd (0) here. // Handle command raceGetProcCmd (0) here.
// First, code below assumes that we are on curg, while raceGetProcCmd // First, code below assumes that we are on curg, while raceGetProcCmd
// can be executed on g0. Second, it is called frequently, so will // can be executed on g0. Second, it is called frequently, so will
@ -457,16 +458,8 @@ TEXT runtime·racecallbackthunk<ABIInternal>(SB), NOSPLIT, $56-8
RET RET
rest: rest:
// Save callee-saved registers (Go code won't respect that). // Transition from C ABI to Go ABI.
// This is superset of darwin/linux/windows registers. PUSH_REGS_HOST_TO_ABI0()
PUSHQ BX
PUSHQ BP
PUSHQ DI
PUSHQ SI
PUSHQ R12
PUSHQ R13
PUSHQ R14
PUSHQ R15
// Set g = g0. // Set g = g0.
get_tls(R12) get_tls(R12)
MOVQ g(R12), R14 MOVQ g(R12), R14
@ -488,15 +481,7 @@ rest:
MOVQ m_curg(R13), R14 MOVQ m_curg(R13), R14
MOVQ R14, g(R12) // g = m->curg MOVQ R14, g(R12) // g = m->curg
ret: ret:
// Restore callee-saved registers. POP_REGS_HOST_TO_ABI0()
POPQ R15
POPQ R14
POPQ R13
POPQ R12
POPQ SI
POPQ DI
POPQ BP
POPQ BX
RET RET
noswitch: noswitch:

View file

@ -11,6 +11,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
@ -214,36 +215,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
// This is the function registered during sigaction and is invoked when // This is the function registered during sigaction and is invoked when
// a signal is received. It just redirects to the Go function sigtrampgo. // a signal is received. It just redirects to the Go function sigtrampgo.
// Called using C ABI.
TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$0 TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$0
// This runs on the signal stack, so we have lots of stack available. // Transition from C ABI to Go ABI.
// We allocate our own stack space, because if we tell the linker PUSH_REGS_HOST_TO_ABI0()
// how much we're using, the NOSPLIT check fails.
PUSHQ BP
MOVQ SP, BP
SUBQ $64, SP
// Save callee-save registers.
MOVQ BX, 24(SP)
MOVQ R12, 32(SP)
MOVQ R13, 40(SP)
MOVQ R14, 48(SP)
MOVQ R15, 56(SP)
// Call into the Go signal handler // Call into the Go signal handler
NOP SP // disable vet stack checking
ADJSP $24
MOVL DI, 0(SP) // sig MOVL DI, 0(SP) // sig
MOVQ SI, 8(SP) // info MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx MOVQ DX, 16(SP) // ctx
CALL runtime·sigtrampgo(SB) CALL ·sigtrampgo(SB)
ADJSP $-24
// Restore callee-save registers. POP_REGS_HOST_TO_ABI0()
MOVQ 24(SP), BX
MOVQ 32(SP), R12
MOVQ 40(SP), R13
MOVQ 48(SP), R14
MOVQ 56(SP), R15
MOVQ BP, SP
POPQ BP
RET RET
// Used instead of sigtramp in programs that use cgo. // Used instead of sigtramp in programs that use cgo.
@ -438,13 +424,8 @@ TEXT runtime·mstart_stub<ABIInternal>(SB),NOSPLIT,$0
// DI points to the m. // DI points to the m.
// We are already on m's g0 stack. // We are already on m's g0 stack.
// Save callee-save registers. // Transition from C ABI to Go ABI.
SUBQ $40, SP PUSH_REGS_HOST_TO_ABI0()
MOVQ BX, 0(SP)
MOVQ R12, 8(SP)
MOVQ R13, 16(SP)
MOVQ R14, 24(SP)
MOVQ R15, 32(SP)
MOVQ m_g0(DI), DX // g MOVQ m_g0(DI), DX // g
@ -452,24 +433,14 @@ TEXT runtime·mstart_stub<ABIInternal>(SB),NOSPLIT,$0
// See cmd/link/internal/ld/sym.go:computeTLSOffset. // See cmd/link/internal/ld/sym.go:computeTLSOffset.
MOVQ DX, 0x30(GS) MOVQ DX, 0x30(GS)
// Someday the convention will be D is always cleared.
CLD
CALL runtime·mstart(SB) CALL runtime·mstart(SB)
// Restore callee-save registers. POP_REGS_HOST_TO_ABI0()
MOVQ 0(SP), BX
MOVQ 8(SP), R12
MOVQ 16(SP), R13
MOVQ 24(SP), R14
MOVQ 32(SP), R15
// Go is all done with this OS thread. // Go is all done with this OS thread.
// Tell pthread everything is ok (we never join with this thread, so // Tell pthread everything is ok (we never join with this thread, so
// the value here doesn't really matter). // the value here doesn't really matter).
XORL AX, AX XORL AX, AX
ADDQ $40, SP
RET RET
// These trampolines help convert from Go calling convention to C calling convention. // These trampolines help convert from Go calling convention to C calling convention.

View file

@ -9,6 +9,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
TEXT runtime·sys_umtx_sleep(SB),NOSPLIT,$0 TEXT runtime·sys_umtx_sleep(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI // arg 1 - ptr MOVQ addr+0(FP), DI // arg 1 - ptr
@ -235,28 +236,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
POPQ BP POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$72 // Called using C ABI.
// Save callee-saved C registers, since the caller may be a C signal handler. TEXT runtime·sigtramp(SB),NOSPLIT,$0
MOVQ BX, bx-8(SP) // Transition from C ABI to Go ABI.
MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set PUSH_REGS_HOST_TO_ABI0()
MOVQ R12, r12-24(SP)
MOVQ R13, r13-32(SP)
MOVQ R14, r14-40(SP)
MOVQ R15, r15-48(SP)
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them.
MOVQ DX, ctx-56(SP) // Call into the Go signal handler
MOVQ SI, info-64(SP) NOP SP // disable vet stack checking
MOVQ DI, signum-72(SP) ADJSP $24
CALL runtime·sigtrampgo(SB) MOVQ DI, 0(SP) // sig
MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx
CALL ·sigtrampgo(SB)
ADJSP $-24
MOVQ r15-48(SP), R15 POP_REGS_HOST_TO_ABI0()
MOVQ r14-40(SP), R14
MOVQ r13-32(SP), R13
MOVQ r12-24(SP), R12
MOVQ bp-16(SP), BP
MOVQ bx-8(SP), BX
RET RET
TEXT runtime·mmap(SB),NOSPLIT,$0 TEXT runtime·mmap(SB),NOSPLIT,$0

View file

@ -9,6 +9,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0 TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI MOVQ addr+0(FP), DI
@ -237,28 +238,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
POPQ BP POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$72 // Called using C ABI.
// Save callee-saved C registers, since the caller may be a C signal handler. TEXT runtime·sigtramp(SB),NOSPLIT,$0
MOVQ BX, bx-8(SP) // Transition from C ABI to Go ABI.
MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set PUSH_REGS_HOST_TO_ABI0()
MOVQ R12, r12-24(SP)
MOVQ R13, r13-32(SP)
MOVQ R14, r14-40(SP)
MOVQ R15, r15-48(SP)
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them.
MOVQ DX, ctx-56(SP) // Call into the Go signal handler
MOVQ SI, info-64(SP) NOP SP // disable vet stack checking
MOVQ DI, signum-72(SP) ADJSP $24
CALL runtime·sigtrampgo(SB) MOVQ DI, 0(SP) // sig
MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx
CALL ·sigtrampgo(SB)
ADJSP $-24
MOVQ r15-48(SP), R15 POP_REGS_HOST_TO_ABI0()
MOVQ r14-40(SP), R14
MOVQ r13-32(SP), R13
MOVQ r12-24(SP), R12
MOVQ bp-16(SP), BP
MOVQ bx-8(SP), BX
RET RET
// Used instead of sigtramp in programs that use cgo. // Used instead of sigtramp in programs that use cgo.

View file

@ -412,6 +412,7 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
MOVL AX, SP MOVL AX, SP
RET RET
// Called using C ABI.
TEXT runtime·sigtramp(SB),NOSPLIT,$28 TEXT runtime·sigtramp(SB),NOSPLIT,$28
// Save callee-saved C registers, since the caller may be a C signal handler. // Save callee-saved C registers, since the caller may be a C signal handler.
MOVL BX, bx-4(SP) MOVL BX, bx-4(SP)
@ -421,11 +422,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$28
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't // We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them. // modify them.
MOVL sig+0(FP), BX MOVL (28+4)(SP), BX
MOVL BX, 0(SP) MOVL BX, 0(SP)
MOVL info+4(FP), BX MOVL (28+8)(SP), BX
MOVL BX, 4(SP) MOVL BX, 4(SP)
MOVL ctx+8(FP), BX MOVL (28+12)(SP), BX
MOVL BX, 8(SP) MOVL BX, 8(SP)
CALL runtime·sigtrampgo(SB) CALL runtime·sigtrampgo(SB)

View file

@ -9,6 +9,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
#define AT_FDCWD -100 #define AT_FDCWD -100
@ -397,29 +398,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
RET RET
// Defined as ABIInternal since it does not use the stack-based Go ABI. // Defined as ABIInternal since it does not use the stack-based Go ABI.
TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$72 // Called using C ABI.
// Save callee-saved C registers, since the caller may be a C signal handler. TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$0
MOVQ BX, bx-8(SP) // Transition from C ABI to Go ABI.
MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set PUSH_REGS_HOST_TO_ABI0()
MOVQ R12, r12-24(SP)
MOVQ R13, r13-32(SP)
MOVQ R14, r14-40(SP)
MOVQ R15, r15-48(SP)
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them.
MOVQ DX, ctx-56(SP) // Call into the Go signal handler
MOVQ SI, info-64(SP) NOP SP // disable vet stack checking
MOVQ DI, signum-72(SP) ADJSP $24
MOVQ $runtime·sigtrampgo(SB), AX MOVQ DI, 0(SP) // sig
CALL AX MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx
CALL ·sigtrampgo(SB)
ADJSP $-24
MOVQ r15-48(SP), R15 POP_REGS_HOST_TO_ABI0()
MOVQ r14-40(SP), R14
MOVQ r13-32(SP), R13
MOVQ r12-24(SP), R12
MOVQ bp-16(SP), BP
MOVQ bx-8(SP), BX
RET RET
// Used instead of sigtramp in programs that use cgo. // Used instead of sigtramp in programs that use cgo.

View file

@ -9,6 +9,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 3 #define CLOCK_MONOTONIC 3
@ -318,28 +319,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
POPQ BP POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$72 // Called using C ABI.
// Save callee-saved C registers, since the caller may be a C signal handler. TEXT runtime·sigtramp(SB),NOSPLIT,$0
MOVQ BX, bx-8(SP) // Transition from C ABI to Go ABI.
MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set PUSH_REGS_HOST_TO_ABI0()
MOVQ R12, r12-24(SP)
MOVQ R13, r13-32(SP)
MOVQ R14, r14-40(SP)
MOVQ R15, r15-48(SP)
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them.
MOVQ DX, ctx-56(SP) // Call into the Go signal handler
MOVQ SI, info-64(SP) NOP SP // disable vet stack checking
MOVQ DI, signum-72(SP) ADJSP $24
CALL runtime·sigtrampgo(SB) MOVQ DI, 0(SP) // sig
MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx
CALL ·sigtrampgo(SB)
ADJSP $-24
MOVQ r15-48(SP), R15 POP_REGS_HOST_TO_ABI0()
MOVQ r14-40(SP), R14
MOVQ r13-32(SP), R13
MOVQ r12-24(SP), R12
MOVQ bp-16(SP), BP
MOVQ bx-8(SP), BX
RET RET
TEXT runtime·mmap(SB),NOSPLIT,$0 TEXT runtime·mmap(SB),NOSPLIT,$0

View file

@ -11,6 +11,7 @@
#include "go_asm.h" #include "go_asm.h"
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#include "cgo/abi_amd64.h"
#define CLOCK_MONOTONIC $3 #define CLOCK_MONOTONIC $3
@ -25,39 +26,22 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$0
// DI points to the m. // DI points to the m.
// We are already on m's g0 stack. // We are already on m's g0 stack.
// Save callee-save registers. // Transition from C ABI to Go ABI.
SUBQ $48, SP PUSH_REGS_HOST_TO_ABI0()
MOVQ BX, 0(SP)
MOVQ BP, 8(SP)
MOVQ R12, 16(SP)
MOVQ R13, 24(SP)
MOVQ R14, 32(SP)
MOVQ R15, 40(SP)
// Load g and save to TLS entry. // Load g and save to TLS entry.
// See cmd/link/internal/ld/sym.go:computeTLSOffset. // See cmd/link/internal/ld/sym.go:computeTLSOffset.
MOVQ m_g0(DI), DX // g MOVQ m_g0(DI), DX // g
MOVQ DX, -8(FS) MOVQ DX, -8(FS)
// Someday the convention will be D is always cleared.
CLD
CALL runtime·mstart(SB) CALL runtime·mstart(SB)
// Restore callee-save registers. POP_REGS_HOST_TO_ABI0()
MOVQ 0(SP), BX
MOVQ 8(SP), BP
MOVQ 16(SP), R12
MOVQ 24(SP), R13
MOVQ 32(SP), R14
MOVQ 40(SP), R15
// Go is all done with this OS thread. // Go is all done with this OS thread.
// Tell pthread everything is ok (we never join with this thread, so // Tell pthread everything is ok (we never join with this thread, so
// the value here doesn't really matter). // the value here doesn't really matter).
XORL AX, AX XORL AX, AX
ADDQ $48, SP
RET RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
@ -73,28 +57,21 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
POPQ BP POPQ BP
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$72 // Called using C ABI.
// Save callee-saved C registers, since the caller may be a C signal handler. TEXT runtime·sigtramp<ABIInternal>(SB),NOSPLIT,$0
MOVQ BX, bx-8(SP) // Transition from C ABI to Go ABI.
MOVQ BP, bp-16(SP) // save in case GOEXPERIMENT=noframepointer is set PUSH_REGS_HOST_TO_ABI0()
MOVQ R12, r12-24(SP)
MOVQ R13, r13-32(SP)
MOVQ R14, r14-40(SP)
MOVQ R15, r15-48(SP)
// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
// modify them.
MOVQ DX, ctx-56(SP) // Call into the Go signal handler
MOVQ SI, info-64(SP) NOP SP // disable vet stack checking
MOVQ DI, signum-72(SP) ADJSP $24
CALL runtime·sigtrampgo(SB) MOVQ DI, 0(SP) // sig
MOVQ SI, 8(SP) // info
MOVQ DX, 16(SP) // ctx
CALL ·sigtrampgo(SB)
ADJSP $-24
MOVQ r15-48(SP), R15 POP_REGS_HOST_TO_ABI0()
MOVQ r14-40(SP), R14
MOVQ r13-32(SP), R13
MOVQ r12-24(SP), R12
MOVQ bp-16(SP), BP
MOVQ bx-8(SP), BX
RET RET
// //