Skip to content

Commit 53d859b

Browse files
Clément Chigotianlancetaylor
Clément Chigot
authored andcommitted
runtime/cgo: add port for aix/ppc64
This commit add port of runtime/cgo for aix/ppc64. AIX assembly is different from Linux assembly, therefore gcc_ppc64.S must be redone for AIX. Change-Id: I780ebab4ef9c4ce912f4c4d521d8c135b1eebf6e Reviewed-on: https://go-review.googlesource.com/c/go/+/164002 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 312bfc5 commit 53d859b

9 files changed

+148
-9
lines changed

src/runtime/cgo/asm_ppc64x.s

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// func crosscall2(fn func(a unsafe.Pointer, n int32, ctxt uintptr), a unsafe.Pointer, n int32, ctxt uintptr)
1212
// Saves C callee-saved registers and calls fn with three arguments.
1313
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
14-
// TODO(austin): ABI v1 (fn is probably a function descriptor)
15-
1614
// Start with standard C stack frame layout and linkage
1715
MOVD LR, R0
1816
MOVD R0, 16(R1) // Save LR in caller's frame
@@ -29,9 +27,16 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
2927
BL runtime·load_g(SB)
3028

3129
MOVD R3, R12
32-
MOVD R3, CTR
30+
#ifdef GOARCH_ppc64
31+
// ppc64 use elf ABI v1. we must get the real entry address from
32+
// first slot of the function descriptor before call.
33+
// Same for AIX.
34+
MOVD 8(R12), R2
35+
MOVD (R12), R12
36+
#endif
37+
MOVD R12, CTR
3338
MOVD R4, FIXED_FRAME+0(R1)
34-
MOVD R5, FIXED_FRAME+8(R1)
39+
MOVW R5, FIXED_FRAME+8(R1)
3540
MOVD R6, FIXED_FRAME+16(R1)
3641
BL (CTR)
3742

src/runtime/cgo/gcc_aix_ppc64.S

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build ppc64
6+
// +build aix
7+
8+
/*
9+
* void crosscall_ppc64(void (*fn)(void), void *g)
10+
*
11+
* Calling into the gc tool chain, where all registers are caller save.
12+
* Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
13+
* callee-save, so they must be saved explicitly.
14+
* AIX has a special assembly syntax and keywords that can be mixed with
15+
* Linux assembly.
16+
*/
17+
.toc
18+
.csect .text[PR]
19+
.globl crosscall_ppc64
20+
.globl .crosscall_ppc64
21+
.csect crosscall_ppc64[DS]
22+
crosscall_ppc64:
23+
.llong .crosscall_ppc64, TOC[tc0], 0
24+
.csect .text[PR]
25+
.crosscall_ppc64:
26+
// Start with standard C stack frame layout and linkage
27+
mflr 0
28+
std 0, 16(1) // Save LR in caller's frame
29+
std 2, 40(1) // Save TOC in caller's frame
30+
bl saveregs
31+
stdu 1, -296(1)
32+
33+
// Set up Go ABI constant registers
34+
bl ._cgo_reginit
35+
nop
36+
37+
// Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
38+
mr 30, 4
39+
40+
// Call fn
41+
mr 12, 3
42+
mtctr 12
43+
bctrl
44+
45+
addi 1, 1, 296
46+
bl restoreregs
47+
ld 2, 40(1)
48+
ld 0, 16(1)
49+
mtlr 0
50+
blr
51+
52+
saveregs:
53+
// Save callee-save registers
54+
// O=-288; for R in {14..31}; do echo "\tstd\t$R, $O(1)"; ((O+=8)); done; for F in f{14..31}; do echo "\tstfd\t$F, $O(1)"; ((O+=8)); done
55+
std 14, -288(1)
56+
std 15, -280(1)
57+
std 16, -272(1)
58+
std 17, -264(1)
59+
std 18, -256(1)
60+
std 19, -248(1)
61+
std 20, -240(1)
62+
std 21, -232(1)
63+
std 22, -224(1)
64+
std 23, -216(1)
65+
std 24, -208(1)
66+
std 25, -200(1)
67+
std 26, -192(1)
68+
std 27, -184(1)
69+
std 28, -176(1)
70+
std 29, -168(1)
71+
std 30, -160(1)
72+
std 31, -152(1)
73+
stfd 14, -144(1)
74+
stfd 15, -136(1)
75+
stfd 16, -128(1)
76+
stfd 17, -120(1)
77+
stfd 18, -112(1)
78+
stfd 19, -104(1)
79+
stfd 20, -96(1)
80+
stfd 21, -88(1)
81+
stfd 22, -80(1)
82+
stfd 23, -72(1)
83+
stfd 24, -64(1)
84+
stfd 25, -56(1)
85+
stfd 26, -48(1)
86+
stfd 27, -40(1)
87+
stfd 28, -32(1)
88+
stfd 29, -24(1)
89+
stfd 30, -16(1)
90+
stfd 31, -8(1)
91+
92+
blr
93+
94+
restoreregs:
95+
// O=-288; for R in {14..31}; do echo "\tld\t$R, $O(1)"; ((O+=8)); done; for F in {14..31}; do echo "\tlfd\t$F, $O(1)"; ((O+=8)); done
96+
ld 14, -288(1)
97+
ld 15, -280(1)
98+
ld 16, -272(1)
99+
ld 17, -264(1)
100+
ld 18, -256(1)
101+
ld 19, -248(1)
102+
ld 20, -240(1)
103+
ld 21, -232(1)
104+
ld 22, -224(1)
105+
ld 23, -216(1)
106+
ld 24, -208(1)
107+
ld 25, -200(1)
108+
ld 26, -192(1)
109+
ld 27, -184(1)
110+
ld 28, -176(1)
111+
ld 29, -168(1)
112+
ld 30, -160(1)
113+
ld 31, -152(1)
114+
lfd 14, -144(1)
115+
lfd 15, -136(1)
116+
lfd 16, -128(1)
117+
lfd 17, -120(1)
118+
lfd 18, -112(1)
119+
lfd 19, -104(1)
120+
lfd 20, -96(1)
121+
lfd 21, -88(1)
122+
lfd 22, -80(1)
123+
lfd 23, -72(1)
124+
lfd 24, -64(1)
125+
lfd 25, -56(1)
126+
lfd 26, -48(1)
127+
lfd 27, -40(1)
128+
lfd 28, -32(1)
129+
lfd 29, -24(1)
130+
lfd 30, -16(1)
131+
lfd 31, -8(1)
132+
133+
blr

src/runtime/cgo/gcc_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// +build cgo
6-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
6+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
77

88
#include "libcgo.h"
99

src/runtime/cgo/gcc_fatalf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !android,linux freebsd
5+
// +build aix !android,linux freebsd
66

77
#include <stdarg.h>
88
#include <stdio.h>

src/runtime/cgo/gcc_libinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// +build cgo
6-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
6+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
77

88
#include <pthread.h>
99
#include <errno.h>

src/runtime/cgo/gcc_ppc64x.S renamed to src/runtime/cgo/gcc_linux_ppc64x.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// +build ppc64 ppc64le
6+
// +build linux
67

78
/*
89
* Apple still insists on underscore prefixes for C function names.
File renamed without changes.

src/runtime/cgo/gcc_setenv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// +build cgo
6-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
6+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
77

88
#include "libcgo.h"
99

src/runtime/cgo/setenv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
66

77
package cgo
88

0 commit comments

Comments
 (0)