Skip to content

Commit 57c1dfd

Browse files
committed
runtime: add runtime support for openbsd/riscv64 port
Updates #55999 Change-Id: I0e80f80d49696a00d979f85230d482e24d4c2d7c Reviewed-on: https://go-review.googlesource.com/c/go/+/518626 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Aaron Bieber <[email protected]>
1 parent 65e1fc7 commit 57c1dfd

File tree

8 files changed

+1021
-2
lines changed

8 files changed

+1021
-2
lines changed

src/runtime/asm_riscv64.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0
309309
CALL runtime·abort(SB)
310310
RET
311311

312+
// func asmcgocall_no_g(fn, arg unsafe.Pointer)
313+
// Call fn(arg) aligned appropriately for the gcc ABI.
314+
// Called on a system stack, and there may be no g yet (during needm).
315+
TEXT ·asmcgocall_no_g(SB),NOSPLIT,$0-16
316+
MOV fn+0(FP), X5
317+
MOV arg+8(FP), X10
318+
JALR RA, (X5)
319+
RET
320+
312321
// func asmcgocall(fn, arg unsafe.Pointer) int32
313322
// Call fn(arg) on the scheduler stack,
314323
// aligned appropriately for the gcc ABI.

src/runtime/defs_openbsd_riscv64.go

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

src/runtime/rt0_openbsd_riscv64.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#include "textflag.h"
6+
7+
TEXT _rt0_riscv64_openbsd(SB),NOSPLIT|NOFRAME,$0
8+
MOV 0(X2), A0 // argc
9+
ADD $8, X2, A1 // argv
10+
JMP main(SB)
11+
12+
TEXT main(SB),NOSPLIT|NOFRAME,$0
13+
MOV $runtime·rt0_go(SB), T0
14+
JALR ZERO, T0

src/runtime/signal_openbsd_riscv64.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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) ra() uint64 { return uint64(c.regs().sc_ra) }
24+
func (c *sigctxt) sp() uint64 { return uint64(c.regs().sc_sp) }
25+
func (c *sigctxt) gp() uint64 { return uint64(c.regs().sc_gp) }
26+
func (c *sigctxt) tp() uint64 { return uint64(c.regs().sc_tp) }
27+
func (c *sigctxt) t0() uint64 { return uint64(c.regs().sc_t[0]) }
28+
func (c *sigctxt) t1() uint64 { return uint64(c.regs().sc_t[1]) }
29+
func (c *sigctxt) t2() uint64 { return uint64(c.regs().sc_t[2]) }
30+
func (c *sigctxt) s0() uint64 { return uint64(c.regs().sc_s[0]) }
31+
func (c *sigctxt) s1() uint64 { return uint64(c.regs().sc_s[1]) }
32+
func (c *sigctxt) a0() uint64 { return uint64(c.regs().sc_a[0]) }
33+
func (c *sigctxt) a1() uint64 { return uint64(c.regs().sc_a[1]) }
34+
func (c *sigctxt) a2() uint64 { return uint64(c.regs().sc_a[2]) }
35+
func (c *sigctxt) a3() uint64 { return uint64(c.regs().sc_a[3]) }
36+
func (c *sigctxt) a4() uint64 { return uint64(c.regs().sc_a[4]) }
37+
func (c *sigctxt) a5() uint64 { return uint64(c.regs().sc_a[5]) }
38+
func (c *sigctxt) a6() uint64 { return uint64(c.regs().sc_a[6]) }
39+
func (c *sigctxt) a7() uint64 { return uint64(c.regs().sc_a[7]) }
40+
func (c *sigctxt) s2() uint64 { return uint64(c.regs().sc_s[2]) }
41+
func (c *sigctxt) s3() uint64 { return uint64(c.regs().sc_s[3]) }
42+
func (c *sigctxt) s4() uint64 { return uint64(c.regs().sc_s[4]) }
43+
func (c *sigctxt) s5() uint64 { return uint64(c.regs().sc_s[5]) }
44+
func (c *sigctxt) s6() uint64 { return uint64(c.regs().sc_s[6]) }
45+
func (c *sigctxt) s7() uint64 { return uint64(c.regs().sc_s[7]) }
46+
func (c *sigctxt) s8() uint64 { return uint64(c.regs().sc_s[8]) }
47+
func (c *sigctxt) s9() uint64 { return uint64(c.regs().sc_s[9]) }
48+
func (c *sigctxt) s10() uint64 { return uint64(c.regs().sc_s[10]) }
49+
func (c *sigctxt) s11() uint64 { return uint64(c.regs().sc_s[11]) }
50+
func (c *sigctxt) t3() uint64 { return uint64(c.regs().sc_t[3]) }
51+
func (c *sigctxt) t4() uint64 { return uint64(c.regs().sc_t[4]) }
52+
func (c *sigctxt) t5() uint64 { return uint64(c.regs().sc_t[5]) }
53+
func (c *sigctxt) t6() uint64 { return uint64(c.regs().sc_t[6]) }
54+
55+
//go:nosplit
56+
//go:nowritebarrierrec
57+
func (c *sigctxt) pc() uint64 { return uint64(c.regs().sc_sepc) }
58+
59+
func (c *sigctxt) sigcode() uint64 { return uint64(c.info.si_code) }
60+
func (c *sigctxt) sigaddr() uint64 {
61+
return *(*uint64)(add(unsafe.Pointer(c.info), 2*goarch.PtrSize))
62+
}
63+
64+
func (c *sigctxt) set_pc(x uint64) { c.regs().sc_sepc = uintptr(x) }
65+
func (c *sigctxt) set_ra(x uint64) { c.regs().sc_ra = uintptr(x) }
66+
func (c *sigctxt) set_sp(x uint64) { c.regs().sc_sp = uintptr(x) }
67+
func (c *sigctxt) set_gp(x uint64) { c.regs().sc_gp = uintptr(x) }
68+
69+
func (c *sigctxt) set_sigcode(x uint32) { c.info.si_code = int32(x) }
70+
func (c *sigctxt) set_sigaddr(x uint64) {
71+
*(*uintptr)(add(unsafe.Pointer(c.info), 2*goarch.PtrSize)) = uintptr(x)
72+
}

src/runtime/signal_riscv64.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 (linux || freebsd) && riscv64
5+
//go:build (linux || freebsd || openbsd) && riscv64
66

77
package runtime
88

src/runtime/stubs_riscv64.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
package runtime
66

7+
import "unsafe"
8+
79
// Called from assembly only; declared for go vet.
810
func load_g()
911
func save_g()
1012

13+
//go:noescape
14+
func asmcgocall_no_g(fn, arg unsafe.Pointer)
15+
1116
// Used by reflectcall and the reflect package.
1217
//
1318
// Spills/loads arguments in registers to/from an internal/abi.RegArgs

0 commit comments

Comments
 (0)