Skip to content

Commit 3d94dd7

Browse files
4a6f656cbradfitz
authored andcommitted
runtime: add support for openbsd/arm64
Updates #31656 Change-Id: I0b7486f7381fd8bd16a76278c0e9ec9763671fcc Reviewed-on: https://go-review.googlesource.com/c/go/+/174119 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 80704ec commit 3d94dd7

9 files changed

+704
-4
lines changed

src/runtime/defs_openbsd_arm64.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package runtime
2+
3+
import "unsafe"
4+
5+
const (
6+
_EINTR = 0x4
7+
_EFAULT = 0xe
8+
9+
_PROT_NONE = 0x0
10+
_PROT_READ = 0x1
11+
_PROT_WRITE = 0x2
12+
_PROT_EXEC = 0x4
13+
14+
_MAP_ANON = 0x1000
15+
_MAP_PRIVATE = 0x2
16+
_MAP_FIXED = 0x10
17+
_MAP_STACK = 0x4000
18+
19+
_MADV_FREE = 0x6
20+
21+
_SA_SIGINFO = 0x40
22+
_SA_RESTART = 0x2
23+
_SA_ONSTACK = 0x1
24+
25+
_SIGHUP = 0x1
26+
_SIGINT = 0x2
27+
_SIGQUIT = 0x3
28+
_SIGILL = 0x4
29+
_SIGTRAP = 0x5
30+
_SIGABRT = 0x6
31+
_SIGEMT = 0x7
32+
_SIGFPE = 0x8
33+
_SIGKILL = 0x9
34+
_SIGBUS = 0xa
35+
_SIGSEGV = 0xb
36+
_SIGSYS = 0xc
37+
_SIGPIPE = 0xd
38+
_SIGALRM = 0xe
39+
_SIGTERM = 0xf
40+
_SIGURG = 0x10
41+
_SIGSTOP = 0x11
42+
_SIGTSTP = 0x12
43+
_SIGCONT = 0x13
44+
_SIGCHLD = 0x14
45+
_SIGTTIN = 0x15
46+
_SIGTTOU = 0x16
47+
_SIGIO = 0x17
48+
_SIGXCPU = 0x18
49+
_SIGXFSZ = 0x19
50+
_SIGVTALRM = 0x1a
51+
_SIGPROF = 0x1b
52+
_SIGWINCH = 0x1c
53+
_SIGINFO = 0x1d
54+
_SIGUSR1 = 0x1e
55+
_SIGUSR2 = 0x1f
56+
57+
_FPE_INTDIV = 0x1
58+
_FPE_INTOVF = 0x2
59+
_FPE_FLTDIV = 0x3
60+
_FPE_FLTOVF = 0x4
61+
_FPE_FLTUND = 0x5
62+
_FPE_FLTRES = 0x6
63+
_FPE_FLTINV = 0x7
64+
_FPE_FLTSUB = 0x8
65+
66+
_BUS_ADRALN = 0x1
67+
_BUS_ADRERR = 0x2
68+
_BUS_OBJERR = 0x3
69+
70+
_SEGV_MAPERR = 0x1
71+
_SEGV_ACCERR = 0x2
72+
73+
_ITIMER_REAL = 0x0
74+
_ITIMER_VIRTUAL = 0x1
75+
_ITIMER_PROF = 0x2
76+
77+
_EV_ADD = 0x1
78+
_EV_DELETE = 0x2
79+
_EV_CLEAR = 0x20
80+
_EV_ERROR = 0x4000
81+
_EV_EOF = 0x8000
82+
_EVFILT_READ = -0x1
83+
_EVFILT_WRITE = -0x2
84+
)
85+
86+
type tforkt struct {
87+
tf_tcb unsafe.Pointer
88+
tf_tid *int32
89+
tf_stack uintptr
90+
}
91+
92+
type sigcontext struct {
93+
__sc_unused int32
94+
sc_mask int32
95+
sc_sp uintptr
96+
sc_lr uintptr
97+
sc_elr uintptr
98+
sc_spsr uintptr
99+
sc_x [30]uintptr
100+
sc_cookie int64
101+
}
102+
103+
type siginfo struct {
104+
si_signo int32
105+
si_code int32
106+
si_errno int32
107+
pad_cgo_0 [4]byte
108+
_data [120]byte
109+
}
110+
111+
type stackt struct {
112+
ss_sp uintptr
113+
ss_size uintptr
114+
ss_flags int32
115+
pad_cgo_0 [4]byte
116+
}
117+
118+
type timespec struct {
119+
tv_sec int64
120+
tv_nsec int64
121+
}
122+
123+
//go:nosplit
124+
func (ts *timespec) setNsec(ns int64) {
125+
ts.tv_sec = ns / 1e9
126+
ts.tv_nsec = ns % 1e9
127+
}
128+
129+
type timeval struct {
130+
tv_sec int64
131+
tv_usec int64
132+
}
133+
134+
func (tv *timeval) set_usec(x int32) {
135+
tv.tv_usec = int64(x)
136+
}
137+
138+
type itimerval struct {
139+
it_interval timeval
140+
it_value timeval
141+
}
142+
143+
type keventt struct {
144+
ident uint64
145+
filter int16
146+
flags uint16
147+
fflags uint32
148+
data int64
149+
udata *byte
150+
}

src/runtime/os_openbsd_arm64.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
package runtime
6+
7+
//go:nosplit
8+
func cputicks() int64 {
9+
// Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
10+
// runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
11+
// TODO: need more entropy to better seed fastrand.
12+
return nanotime()
13+
}

src/runtime/pprof/pprof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func testCPUProfile(t *testing.T, matches matchFunc, need []string, avoid []stri
194194
case "darwin", "dragonfly", "netbsd", "solaris":
195195
t.Skipf("ignoring failure on %s; see golang.org/issue/13841", runtime.GOOS)
196196
case "openbsd":
197-
if runtime.GOARCH == "arm" {
197+
if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
198198
t.Skipf("ignoring failure on %s/%s; see golang.org/issue/13841", runtime.GOOS, runtime.GOARCH)
199199
}
200200
}

src/runtime/rt0_openbsd_arm64.s

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
#include "textflag.h"
6+
7+
TEXT _rt0_arm64_openbsd(SB),NOSPLIT|NOFRAME,$0
8+
MOVD 0(RSP), R0 // argc
9+
ADD $8, RSP, R1 // argv
10+
BL main(SB)
11+
12+
// When building with -buildmode=c-shared, this symbol is called when the shared
13+
// library is loaded.
14+
TEXT _rt0_arm64_openbsd_lib(SB),NOSPLIT,$184
15+
// Preserve callee-save registers.
16+
MOVD R19, 24(RSP)
17+
MOVD R20, 32(RSP)
18+
MOVD R21, 40(RSP)
19+
MOVD R22, 48(RSP)
20+
MOVD R23, 56(RSP)
21+
MOVD R24, 64(RSP)
22+
MOVD R25, 72(RSP)
23+
MOVD R26, 80(RSP)
24+
MOVD R27, 88(RSP)
25+
FMOVD F8, 96(RSP)
26+
FMOVD F9, 104(RSP)
27+
FMOVD F10, 112(RSP)
28+
FMOVD F11, 120(RSP)
29+
FMOVD F12, 128(RSP)
30+
FMOVD F13, 136(RSP)
31+
FMOVD F14, 144(RSP)
32+
FMOVD F15, 152(RSP)
33+
MOVD g, 160(RSP)
34+
35+
// Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
36+
MOVD ZR, g
37+
38+
MOVD R0, _rt0_arm64_openbsd_lib_argc<>(SB)
39+
MOVD R1, _rt0_arm64_openbsd_lib_argv<>(SB)
40+
41+
// Synchronous initialization.
42+
MOVD $runtime·libpreinit(SB), R4
43+
BL (R4)
44+
45+
// Create a new thread to do the runtime initialization and return.
46+
MOVD _cgo_sys_thread_create(SB), R4
47+
CMP $0, R4
48+
BEQ nocgo
49+
MOVD $_rt0_arm64_openbsd_lib_go(SB), R0
50+
MOVD $0, R1
51+
SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved.
52+
BL (R4)
53+
ADD $16, RSP
54+
B restore
55+
56+
nocgo:
57+
MOVD $0x800000, R0 // stacksize = 8192KB
58+
MOVD $_rt0_arm64_openbsd_lib_go(SB), R1
59+
MOVD R0, 8(RSP)
60+
MOVD R1, 16(RSP)
61+
MOVD $runtime·newosproc0(SB),R4
62+
BL (R4)
63+
64+
restore:
65+
// Restore callee-save registers.
66+
MOVD 24(RSP), R19
67+
MOVD 32(RSP), R20
68+
MOVD 40(RSP), R21
69+
MOVD 48(RSP), R22
70+
MOVD 56(RSP), R23
71+
MOVD 64(RSP), R24
72+
MOVD 72(RSP), R25
73+
MOVD 80(RSP), R26
74+
MOVD 88(RSP), R27
75+
FMOVD 96(RSP), F8
76+
FMOVD 104(RSP), F9
77+
FMOVD 112(RSP), F10
78+
FMOVD 120(RSP), F11
79+
FMOVD 128(RSP), F12
80+
FMOVD 136(RSP), F13
81+
FMOVD 144(RSP), F14
82+
FMOVD 152(RSP), F15
83+
MOVD 160(RSP), g
84+
RET
85+
86+
TEXT _rt0_arm64_openbsd_lib_go(SB),NOSPLIT,$0
87+
MOVD _rt0_arm64_openbsd_lib_argc<>(SB), R0
88+
MOVD _rt0_arm64_openbsd_lib_argv<>(SB), R1
89+
MOVD $runtime·rt0_go(SB),R4
90+
B (R4)
91+
92+
DATA _rt0_arm64_openbsd_lib_argc<>(SB)/8, $0
93+
GLOBL _rt0_arm64_openbsd_lib_argc<>(SB),NOPTR, $8
94+
DATA _rt0_arm64_openbsd_lib_argv<>(SB)/8, $0
95+
GLOBL _rt0_arm64_openbsd_lib_argv<>(SB),NOPTR, $8
96+
97+
98+
TEXT main(SB),NOSPLIT|NOFRAME,$0
99+
MOVD $runtime·rt0_go(SB), R2
100+
BL (R2)
101+
exit:
102+
MOVD $0, R0
103+
MOVD $1, R8 // sys_exit
104+
SVC
105+
B exit

src/runtime/signal_arm64.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 linux darwin netbsd
5+
// +build darwin linux netbsd openbsd
66

77
package runtime
88

src/runtime/signal_openbsd_arm64.go

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

src/runtime/sys_openbsd_arm.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
8686
RET
8787

8888
TEXT runtime·raise(SB),NOSPLIT,$12
89-
MOVW $0x12B, R12
90-
SWI $0 // sys_getthrid
89+
MOVW $299, R12 // sys_getthrid
90+
SWI $0
9191
// arg 1 - tid, already in R0
9292
MOVW sig+0(FP), R1 // arg 2 - signum
9393
MOVW $0, R2 // arg 3 - tcb

0 commit comments

Comments
 (0)