Skip to content

Commit c140105

Browse files
committed
runtime: add support for openbsd/ppc64
Add runtime support for the openbsd/ppc64 port. Updates #56001 Change-Id: I3cf010b34f96ce269858b02f16481fdad2cd5b77 Reviewed-on: https://go-review.googlesource.com/c/go/+/475618 Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Paul Murphy <[email protected]> Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Lynn Boger <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Eric Grosse <[email protected]>
1 parent b291538 commit c140105

9 files changed

+985
-2
lines changed

src/runtime/asm_ppc64x.s

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,43 @@ TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0
545545
#define asmcgocallSaveOffset cgoCalleeStackSize
546546
#endif
547547

548+
// func asmcgocall_no_g(fn, arg unsafe.Pointer)
549+
// Call fn(arg) aligned appropriately for the gcc ABI.
550+
// Called on a system stack, and there may be no g yet (during needm).
551+
TEXT ·asmcgocall_no_g(SB),NOSPLIT,$0-16
552+
MOVD fn+0(FP), R3
553+
MOVD arg+8(FP), R4
554+
555+
MOVD R1, R15
556+
SUB $(asmcgocallSaveOffset+8), R1
557+
RLDCR $0, R1, $~15, R1 // 16-byte alignment for gcc ABI
558+
MOVD R15, asmcgocallSaveOffset(R1)
559+
560+
MOVD R0, 0(R1) // clear back chain pointer (TODO can we give it real back trace information?)
561+
562+
// This is a "global call", so put the global entry point in r12
563+
MOVD R3, R12
564+
565+
#ifdef GO_PPC64X_HAS_FUNCDESC
566+
// Load the real entry address from the first slot of the function descriptor.
567+
MOVD 8(R12), R2
568+
MOVD (R12), R12
569+
#endif
570+
MOVD R12, CTR
571+
MOVD R4, R3 // arg in r3
572+
BL (CTR)
573+
574+
// C code can clobber R0, so set it back to 0. F27-F31 are
575+
// callee save, so we don't need to recover those.
576+
XOR R0, R0
577+
578+
MOVD asmcgocallSaveOffset(R1), R1 // Restore stack pointer.
579+
#ifndef GOOS_aix
580+
MOVD 24(R1), R2
581+
#endif
582+
583+
RET
584+
548585
// func asmcgocall(fn, arg unsafe.Pointer) int32
549586
// Call fn(arg) on the scheduler stack,
550587
// aligned appropriately for the gcc ABI.
@@ -677,9 +714,11 @@ TEXT ·cgocallback(SB),NOSPLIT,$24-24
677714

678715
loadg:
679716
// Load m and g from thread-local storage.
717+
#ifndef GOOS_openbsd
680718
MOVBZ runtime·iscgo(SB), R3
681719
CMP R3, $0
682720
BEQ nocgo
721+
#endif
683722
BL runtime·load_g(SB)
684723
nocgo:
685724

src/runtime/crash_unix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestCrashDumpsAllThreads(t *testing.T) {
6565
t.Skipf("skipping; not supported on %v", runtime.GOOS)
6666
}
6767

68-
if runtime.GOOS == "openbsd" && (runtime.GOARCH == "arm" || runtime.GOARCH == "mips64") {
68+
if runtime.GOOS == "openbsd" && (runtime.GOARCH == "arm" || runtime.GOARCH == "mips64" || runtime.GOARCH == "ppc64") {
6969
// This may be ncpu < 2 related...
7070
t.Skipf("skipping; test fails on %s/%s - see issue #42464", runtime.GOOS, runtime.GOARCH)
7171
}

src/runtime/defs_openbsd_ppc64.go

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// Copyright 2023 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+
// Generated from:
6+
//
7+
// GOARCH=ppc64 go tool cgo -godefs defs_openbsd.go
8+
//
9+
// Then converted to the form used by the runtime.
10+
11+
package runtime
12+
13+
import "unsafe"
14+
15+
const (
16+
_EINTR = 0x4
17+
_EFAULT = 0xe
18+
_EAGAIN = 0x23
19+
20+
_O_WRONLY = 0x1
21+
_O_NONBLOCK = 0x4
22+
_O_CREAT = 0x200
23+
_O_TRUNC = 0x400
24+
_O_CLOEXEC = 0x10000
25+
26+
_PROT_NONE = 0x0
27+
_PROT_READ = 0x1
28+
_PROT_WRITE = 0x2
29+
_PROT_EXEC = 0x4
30+
31+
_MAP_ANON = 0x1000
32+
_MAP_PRIVATE = 0x2
33+
_MAP_FIXED = 0x10
34+
_MAP_STACK = 0x4000
35+
36+
_MADV_DONTNEED = 0x4
37+
_MADV_FREE = 0x6
38+
39+
_SA_SIGINFO = 0x40
40+
_SA_RESTART = 0x2
41+
_SA_ONSTACK = 0x1
42+
43+
_PTHREAD_CREATE_DETACHED = 0x1
44+
45+
_SIGHUP = 0x1
46+
_SIGINT = 0x2
47+
_SIGQUIT = 0x3
48+
_SIGILL = 0x4
49+
_SIGTRAP = 0x5
50+
_SIGABRT = 0x6
51+
_SIGEMT = 0x7
52+
_SIGFPE = 0x8
53+
_SIGKILL = 0x9
54+
_SIGBUS = 0xa
55+
_SIGSEGV = 0xb
56+
_SIGSYS = 0xc
57+
_SIGPIPE = 0xd
58+
_SIGALRM = 0xe
59+
_SIGTERM = 0xf
60+
_SIGURG = 0x10
61+
_SIGSTOP = 0x11
62+
_SIGTSTP = 0x12
63+
_SIGCONT = 0x13
64+
_SIGCHLD = 0x14
65+
_SIGTTIN = 0x15
66+
_SIGTTOU = 0x16
67+
_SIGIO = 0x17
68+
_SIGXCPU = 0x18
69+
_SIGXFSZ = 0x19
70+
_SIGVTALRM = 0x1a
71+
_SIGPROF = 0x1b
72+
_SIGWINCH = 0x1c
73+
_SIGINFO = 0x1d
74+
_SIGUSR1 = 0x1e
75+
_SIGUSR2 = 0x1f
76+
77+
_FPE_INTDIV = 0x1
78+
_FPE_INTOVF = 0x2
79+
_FPE_FLTDIV = 0x3
80+
_FPE_FLTOVF = 0x4
81+
_FPE_FLTUND = 0x5
82+
_FPE_FLTRES = 0x6
83+
_FPE_FLTINV = 0x7
84+
_FPE_FLTSUB = 0x8
85+
86+
_BUS_ADRALN = 0x1
87+
_BUS_ADRERR = 0x2
88+
_BUS_OBJERR = 0x3
89+
90+
_SEGV_MAPERR = 0x1
91+
_SEGV_ACCERR = 0x2
92+
93+
_ITIMER_REAL = 0x0
94+
_ITIMER_VIRTUAL = 0x1
95+
_ITIMER_PROF = 0x2
96+
97+
_EV_ADD = 0x1
98+
_EV_DELETE = 0x2
99+
_EV_CLEAR = 0x20
100+
_EV_ERROR = 0x4000
101+
_EV_EOF = 0x8000
102+
_EVFILT_READ = -0x1
103+
_EVFILT_WRITE = -0x2
104+
)
105+
106+
type tforkt struct {
107+
tf_tcb unsafe.Pointer
108+
tf_tid *int32
109+
tf_stack uintptr
110+
}
111+
112+
type sigcontext struct {
113+
sc_cookie uint64
114+
sc_mask int32
115+
sc_reg [32]uint64
116+
sc_lr uint64
117+
sc_cr uint64
118+
sc_xer uint64
119+
sc_ctr uint64
120+
sc_pc uint64
121+
sc_ps uint64
122+
sc_vrsave uint64
123+
pad_cgo_0 [8]byte
124+
sc_vsx [64][16]uint8
125+
sc_fpscr uint64
126+
sc_vscr uint64
127+
}
128+
129+
type siginfo struct {
130+
si_signo int32
131+
si_code int32
132+
si_errno int32
133+
pad_cgo_0 [4]byte
134+
_data [120]byte
135+
}
136+
137+
type stackt struct {
138+
ss_sp uintptr
139+
ss_size uintptr
140+
ss_flags int32
141+
pad_cgo_0 [4]byte
142+
}
143+
144+
type timespec struct {
145+
tv_sec int64
146+
tv_nsec int64
147+
}
148+
149+
//go:nosplit
150+
func (ts *timespec) setNsec(ns int64) {
151+
ts.tv_sec = ns / 1e9
152+
ts.tv_nsec = ns % 1e9
153+
}
154+
155+
type timeval struct {
156+
tv_sec int64
157+
tv_usec int64
158+
}
159+
160+
func (tv *timeval) set_usec(x int32) {
161+
tv.tv_usec = int64(x)
162+
}
163+
164+
type itimerval struct {
165+
it_interval timeval
166+
it_value timeval
167+
}
168+
169+
type keventt struct {
170+
ident uint64
171+
filter int16
172+
flags uint16
173+
fflags uint32
174+
data int64
175+
udata *byte
176+
}
177+
178+
type pthread uintptr
179+
type pthreadattr uintptr
180+
type pthreadcond uintptr
181+
type pthreadcondattr uintptr
182+
type pthreadmutex uintptr
183+
type pthreadmutexattr uintptr

src/runtime/rt0_openbsd_ppc64.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 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+
#include "textflag.h"
6+
7+
TEXT _rt0_ppc64_openbsd(SB),NOSPLIT,$0
8+
BR main(SB)
9+
10+
TEXT main(SB),NOSPLIT,$-8
11+
// Make sure R0 is zero before _main
12+
XOR R0, R0
13+
14+
MOVD $runtime·rt0_go(SB), R12
15+
MOVD R12, CTR
16+
BR (CTR)

src/runtime/signal_openbsd_ppc64.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2023 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+
package runtime
6+
7+
import (
8+
"internal/goarch"
9+
"unsafe"
10+
)
11+
12+
type sigctxt struct {
13+
info *siginfo
14+
ctxt unsafe.Pointer
15+
}
16+
17+
//go:nosplit
18+
//go:nowritebarrierrec
19+
func (c *sigctxt) regs() *sigcontext {
20+
return (*sigcontext)(c.ctxt)
21+
}
22+
23+
func (c *sigctxt) r0() uint64 { return c.regs().sc_reg[0] }
24+
func (c *sigctxt) r1() uint64 { return c.regs().sc_reg[1] }
25+
func (c *sigctxt) r2() uint64 { return c.regs().sc_reg[2] }
26+
func (c *sigctxt) r3() uint64 { return c.regs().sc_reg[3] }
27+
func (c *sigctxt) r4() uint64 { return c.regs().sc_reg[4] }
28+
func (c *sigctxt) r5() uint64 { return c.regs().sc_reg[5] }
29+
func (c *sigctxt) r6() uint64 { return c.regs().sc_reg[6] }
30+
func (c *sigctxt) r7() uint64 { return c.regs().sc_reg[7] }
31+
func (c *sigctxt) r8() uint64 { return c.regs().sc_reg[8] }
32+
func (c *sigctxt) r9() uint64 { return c.regs().sc_reg[9] }
33+
func (c *sigctxt) r10() uint64 { return c.regs().sc_reg[10] }
34+
func (c *sigctxt) r11() uint64 { return c.regs().sc_reg[11] }
35+
func (c *sigctxt) r12() uint64 { return c.regs().sc_reg[12] }
36+
func (c *sigctxt) r13() uint64 { return c.regs().sc_reg[13] }
37+
func (c *sigctxt) r14() uint64 { return c.regs().sc_reg[14] }
38+
func (c *sigctxt) r15() uint64 { return c.regs().sc_reg[15] }
39+
func (c *sigctxt) r16() uint64 { return c.regs().sc_reg[16] }
40+
func (c *sigctxt) r17() uint64 { return c.regs().sc_reg[17] }
41+
func (c *sigctxt) r18() uint64 { return c.regs().sc_reg[18] }
42+
func (c *sigctxt) r19() uint64 { return c.regs().sc_reg[19] }
43+
func (c *sigctxt) r20() uint64 { return c.regs().sc_reg[20] }
44+
func (c *sigctxt) r21() uint64 { return c.regs().sc_reg[21] }
45+
func (c *sigctxt) r22() uint64 { return c.regs().sc_reg[22] }
46+
func (c *sigctxt) r23() uint64 { return c.regs().sc_reg[23] }
47+
func (c *sigctxt) r24() uint64 { return c.regs().sc_reg[24] }
48+
func (c *sigctxt) r25() uint64 { return c.regs().sc_reg[25] }
49+
func (c *sigctxt) r26() uint64 { return c.regs().sc_reg[26] }
50+
func (c *sigctxt) r27() uint64 { return c.regs().sc_reg[27] }
51+
func (c *sigctxt) r28() uint64 { return c.regs().sc_reg[28] }
52+
func (c *sigctxt) r29() uint64 { return c.regs().sc_reg[29] }
53+
func (c *sigctxt) r30() uint64 { return c.regs().sc_reg[30] }
54+
func (c *sigctxt) r31() uint64 { return c.regs().sc_reg[31] }
55+
func (c *sigctxt) sp() uint64 { return c.regs().sc_reg[1] }
56+
57+
//go:nosplit
58+
//go:nowritebarrierrec
59+
func (c *sigctxt) pc() uint64 { return c.regs().sc_pc }
60+
61+
func (c *sigctxt) trap() uint64 { return 0 /* XXX - c.regs().trap */ }
62+
func (c *sigctxt) ctr() uint64 { return c.regs().sc_ctr }
63+
func (c *sigctxt) link() uint64 { return c.regs().sc_lr }
64+
func (c *sigctxt) xer() uint64 { return c.regs().sc_xer }
65+
func (c *sigctxt) ccr() uint64 { return c.regs().sc_cr }
66+
67+
func (c *sigctxt) sigcode() uint32 { return uint32(c.info.si_code) }
68+
func (c *sigctxt) sigaddr() uint64 {
69+
return *(*uint64)(add(unsafe.Pointer(c.info), 16))
70+
}
71+
func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
72+
73+
func (c *sigctxt) set_r0(x uint64) { c.regs().sc_reg[0] = x }
74+
func (c *sigctxt) set_r12(x uint64) { c.regs().sc_reg[12] = x }
75+
func (c *sigctxt) set_r30(x uint64) { c.regs().sc_reg[30] = x }
76+
func (c *sigctxt) set_pc(x uint64) { c.regs().sc_pc = x }
77+
func (c *sigctxt) set_sp(x uint64) { c.regs().sc_reg[1] = x }
78+
func (c *sigctxt) set_link(x uint64) { c.regs().sc_lr = x }
79+
80+
func (c *sigctxt) set_sigcode(x uint32) { c.info.si_code = int32(x) }
81+
func (c *sigctxt) set_sigaddr(x uint64) {
82+
*(*uintptr)(add(unsafe.Pointer(c.info), 2*goarch.PtrSize)) = uintptr(x)
83+
}

src/runtime/signal_ppc64x.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-
//go:build (aix || linux) && (ppc64 || ppc64le)
5+
//go:build (aix || linux || openbsd) && (ppc64 || ppc64le)
66

77
package runtime
88

src/runtime/stubs_ppc64x.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
package runtime
88

9+
import "unsafe"
10+
911
// Called from assembly only; declared for go vet.
1012
func load_g()
1113
func save_g()
1214
func reginit()
1315

16+
//go:noescape
17+
func asmcgocall_no_g(fn, arg unsafe.Pointer)
18+
1419
// Spills/loads arguments in registers to/from an internal/abi.RegArgs
1520
// respectively. Does not follow the Go ABI.
1621
func spillArgs()

0 commit comments

Comments
 (0)