]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use AIX C ABI in asmcgocall
authorClément Chigot <clement.chigot@atos.net>
Wed, 20 Feb 2019 14:59:05 +0000 (15:59 +0100)
committerIan Lance Taylor <iant@golang.org>
Tue, 5 Mar 2019 01:30:35 +0000 (01:30 +0000)
The commit fixes asmcgocall in order to use the AIX C ABI.

Change-Id: I2a44914a65557a841ea1e12991938af26ad7fd1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/164000
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/asm_ppc64x.s
src/runtime/sys_aix_ppc64.s

index 0a89b57cd81baecf1f960c01896e466dbdffceed..a1d7ce103c6ddd82609df512a80b8a9b00c9a059 100644 (file)
 #include "textflag.h"
 #include "asm_ppc64x.h"
 
+#ifdef GOOS_aix
+#define cgoCalleeStackSize 48
+#else
+#define cgoCalleeStackSize 32
+#endif
+
 TEXT runtime·rt0_go(SB),NOSPLIT,$0
        // R1 = stack; R3 = argc; R4 = argv; R13 = C TLS base pointer
 
@@ -46,14 +52,16 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
        MOVD    R13, R5                 // arg 2: TLS base pointer
        MOVD    $setg_gcc<>(SB), R4     // arg 1: setg
        MOVD    g, R3                   // arg 0: G
-       // C functions expect 32 bytes of space on caller stack frame
-       // and a 16-byte aligned R1
+       // C functions expect 32 (48 for AIX) bytes of space on caller
+       // stack frame and a 16-byte aligned R1
        MOVD    R1, R14                 // save current stack
-       SUB     $32, R1                 // reserve 32 bytes
+       SUB     $cgoCalleeStackSize, R1 // reserve the callee area
        RLDCR   $0, R1, $~15, R1        // 16-byte align
        BL      (CTR)                   // may clobber R0, R3-R12
        MOVD    R14, R1                 // restore stack
+#ifndef GOOS_aix
        MOVD    24(R1), R2
+#endif
        XOR     R0, R0                  // fix R0
 
 nocgo:
@@ -553,6 +561,12 @@ TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0
        BL      runtime·badctxt(SB)
        RET
 
+#ifdef GOOS_aix
+#define asmcgocallSaveOffset cgoCalleeStackSize + 8
+#else
+#define asmcgocallSaveOffset cgoCalleeStackSize
+#endif
+
 // func asmcgocall(fn, arg unsafe.Pointer) int32
 // Call fn(arg) on the scheduler stack,
 // aligned appropriately for the gcc ABI.
@@ -583,19 +597,21 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20
 
        // Now on a scheduling stack (a pthread-created stack).
 g0:
-       // Save room for two of our pointers, plus 32 bytes of callee
-       // save area that lives on the caller stack.
 #ifdef GOOS_aix
        // Create a fake LR to improve backtrace.
        MOVD    $runtime·asmcgocall(SB), R6
        MOVD    R6, 16(R1)
+       // AIX also save one argument on the stack.
+       SUB $8, R1
 #endif
-       SUB     $48, R1
+       // Save room for two of our pointers, plus the callee
+       // save area that lives on the caller stack.
+       SUB     $(asmcgocallSaveOffset+16), R1
        RLDCR   $0, R1, $~15, R1        // 16-byte alignment for gcc ABI
-       MOVD    R5, 40(R1)      // save old g on stack
+       MOVD    R5, (asmcgocallSaveOffset+8)(R1)// save old g on stack
        MOVD    (g_stack+stack_hi)(R5), R5
        SUB     R7, R5
-       MOVD    R5, 32(R1)      // save depth in old g stack (can't just save SP, as stack might be copied during a callback)
+       MOVD    R5, asmcgocallSaveOffset(R1)    // save depth in old g stack (can't just save SP, as stack might be copied during a callback)
 #ifdef GOOS_aix
        MOVD    R7, 0(R1)       // Save frame pointer to allow manual backtrace with gdb
 #else
@@ -607,24 +623,21 @@ g0:
 #ifdef GOARCH_ppc64
        // ppc64 use elf ABI v1. we must get the real entry address from
        // first slot of the function descriptor before call.
-#ifndef GOOS_aix
-       // aix just passes the function pointer for the moment, see golang.org/cl/146898 for details.
+       // Same for AIX.
        MOVD    8(R12), R2
        MOVD    (R12), R12
-#endif
 #endif
        MOVD    R12, CTR
        MOVD    R4, R3          // arg in r3
        BL      (CTR)
-
-       // C code can clobber R0, so set it back to 0.  F27-F31 are
+       // C code can clobber R0, so set it back to 0. F27-F31 are
        // callee save, so we don't need to recover those.
        XOR     R0, R0
        // Restore g, stack pointer, toc pointer.
        // R3 is errno, so don't touch it
-       MOVD    40(R1), g
+       MOVD    (asmcgocallSaveOffset+8)(R1), g
        MOVD    (g_stack+stack_hi)(g), R5
-       MOVD    32(R1), R6
+       MOVD    asmcgocallSaveOffset(R1), R6
        SUB     R6, R5
 #ifndef GOOS_aix
        MOVD    24(R5), R2
index 38e60f99eb95c918f802ea0c4c2ced6a486e8ac7..ea7fae0ce78a5604d969940d640436a0f42531a0 100644 (file)
@@ -30,7 +30,13 @@ TEXT runtime·callCfunction(SB),     NOSPLIT|NOFRAME,$0
 // Called by runtime.asmcgocall
 // It reserves a stack of 288 bytes for the C function.
 // NOT USING GO CALLING CONVENTION
-TEXT runtime·asmsyscall6(SB),NOSPLIT,$256
+// runtime.asmsyscall6 is a function descriptor to the real asmsyscall6.
+DATA   runtime·asmsyscall6+0(SB)/8, $runtime·_asmsyscall6(SB)
+DATA   runtime·asmsyscall6+8(SB)/8, $TOC(SB)
+DATA   runtime·asmsyscall6+16(SB)/8, $0
+GLOBL  runtime·asmsyscall6(SB), NOPTR, $24
+
+TEXT runtime·_asmsyscall6(SB),NOSPLIT,$256
        MOVD    R3, 48(R1) // Save libcall for later
        MOVD    libcall_fn(R3), R12
        MOVD    libcall_args(R3), R9