Skip to content

Commit 090e330

Browse files
committed
unix: add support for openbsd/ppc64
Updates golang/go#56001 Change-Id: Ic2c7db7a0c2056d3bbc153066c187f27508cb96c Reviewed-on: https://go-review.googlesource.com/c/sys/+/439978 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
1 parent 3938a4f commit 090e330

11 files changed

+6085
-8
lines changed

unix/asm_bsd_ppc64.s

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 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+
//go:build (darwin || freebsd || netbsd || openbsd) && gc
6+
// +build darwin freebsd netbsd openbsd
7+
// +build gc
8+
9+
#include "textflag.h"
10+
11+
//
12+
// System call support for ppc64, BSD
13+
//
14+
15+
// Just jump to package syscall's implementation for all these functions.
16+
// The runtime may know about them.
17+
18+
TEXT ·Syscall(SB),NOSPLIT,$0-56
19+
JMP syscall·Syscall(SB)
20+
21+
TEXT ·Syscall6(SB),NOSPLIT,$0-80
22+
JMP syscall·Syscall6(SB)
23+
24+
TEXT ·Syscall9(SB),NOSPLIT,$0-104
25+
JMP syscall·Syscall9(SB)
26+
27+
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
28+
JMP syscall·RawSyscall(SB)
29+
30+
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
31+
JMP syscall·RawSyscall6(SB)

unix/mkall.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ openbsd_mips64)
182182
# API consistent across platforms.
183183
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
184184
;;
185+
openbsd_ppc64)
186+
mkasm="go run mkasm.go"
187+
mkerrors="$mkerrors -m64"
188+
mksyscall="go run mksyscall.go -openbsd -libc"
189+
mksysctl="go run mksysctl_openbsd.go"
190+
# Let the type of C char be signed for making the bare syscall
191+
# API consistent across platforms.
192+
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
193+
;;
185194
openbsd_riscv64)
186195
mkasm="go run mkasm.go"
187196
mkerrors="$mkerrors -m64"

unix/mkasm.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ func archPtrSize(arch string) int {
2323
switch arch {
2424
case "386", "arm":
2525
return 4
26-
case "amd64", "arm64", "mips64", "riscv64":
26+
case "amd64", "arm64", "mips64", "ppc64", "riscv64":
2727
return 8
2828
default:
2929
log.Fatalf("Unknown arch %q", arch)
3030
return 0
3131
}
3232
}
3333

34-
func generateASMFile(arch string, inFileNames []string, outFileName string) map[string]bool {
34+
func generateASMFile(goos, arch string, inFileNames []string, outFileName string) map[string]bool {
3535
trampolines := map[string]bool{}
3636
var orderedTrampolines []string
3737
for _, inFileName := range inFileNames {
@@ -62,7 +62,12 @@ func generateASMFile(arch string, inFileNames []string, outFileName string) map[
6262
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
6363
for _, fn := range orderedTrampolines {
6464
fmt.Fprintf(&out, "\nTEXT %s_trampoline<>(SB),NOSPLIT,$0-0\n", fn)
65-
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n\n", fn)
65+
if goos == "openbsd" && arch == "ppc64" {
66+
fmt.Fprintf(&out, "\tCALL\t%s(SB)\n", fn)
67+
fmt.Fprintf(&out, "\tRET\n")
68+
} else {
69+
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
70+
}
6671
fmt.Fprintf(&out, "GLOBL\t·%s_trampoline_addr(SB), RODATA, $%d\n", fn, ptrSize)
6772
fmt.Fprintf(&out, "DATA\t·%s_trampoline_addr(SB)/%d, $%s_trampoline<>(SB)\n", fn, ptrSize, fn)
6873
}
@@ -127,7 +132,7 @@ func main() {
127132
zsyscallArchFilename,
128133
}
129134

130-
trampolines := generateASMFile(arch, inFileNames, zsyscallASMFileName)
135+
trampolines := generateASMFile(goos, arch, inFileNames, zsyscallASMFileName)
131136

132137
if goos == "darwin" {
133138
writeDarwinTest(trampolines, fmt.Sprintf("darwin_%s_test.go", arch), arch)

unix/syscall_openbsd_ppc64.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
//go:build ppc64 && openbsd
6+
// +build ppc64,openbsd
7+
8+
package unix
9+
10+
func setTimespec(sec, nsec int64) Timespec {
11+
return Timespec{Sec: sec, Nsec: nsec}
12+
}
13+
14+
func setTimeval(sec, usec int64) Timeval {
15+
return Timeval{Sec: sec, Usec: usec}
16+
}
17+
18+
func SetKevent(k *Kevent_t, fd, mode, flags int) {
19+
k.Ident = uint64(fd)
20+
k.Filter = int16(mode)
21+
k.Flags = uint16(flags)
22+
}
23+
24+
func (iov *Iovec) SetLen(length int) {
25+
iov.Len = uint64(length)
26+
}
27+
28+
func (msghdr *Msghdr) SetControllen(length int) {
29+
msghdr.Controllen = uint32(length)
30+
}
31+
32+
func (msghdr *Msghdr) SetIovlen(length int) {
33+
msghdr.Iovlen = uint32(length)
34+
}
35+
36+
func (cmsg *Cmsghdr) SetLen(length int) {
37+
cmsg.Len = uint32(length)
38+
}
39+
40+
// SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions
41+
// of openbsd/ppc64 the syscall is called sysctl instead of __sysctl.
42+
const SYS___SYSCTL = SYS_SYSCTL

unix/syscall_unix_gc.go

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

5-
//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris) && gc && !ppc64le && !ppc64
6-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
5+
//go:build (darwin || dragonfly || freebsd || (linux && !ppc64 && !ppc64le) || netbsd || openbsd || solaris) && gc
6+
// +build darwin dragonfly freebsd linux,!ppc64,!ppc64le netbsd openbsd solaris
77
// +build gc
8-
// +build !ppc64le
9-
// +build !ppc64
108

119
package unix
1210

0 commit comments

Comments
 (0)