Skip to content

Commit

Permalink
syscall: add syscall support for openbsd/riscv64 port
Browse files Browse the repository at this point in the history
Updates #55999

Change-Id: I5b8452207e951e543b9be42ebcb7d62c0c023f08
Reviewed-on: https://go-review.googlesource.com/c/go/+/518627
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Joel Sing <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Reviewed-by: Aaron Bieber <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
4a6f656c committed Oct 4, 2023
1 parent 57c1dfd commit 9018601
Show file tree
Hide file tree
Showing 8 changed files with 4,617 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/syscall/asm_openbsd_riscv64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "textflag.h"

//
// System call support for RISCV64, OpenBSD
//

// Provide these function names via assembly so they are provided as ABI0,
// rather than ABIInternal.

// func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
TEXT ·Syscall(SB),NOSPLIT,$0-56
JMP ·syscallInternal(SB)

// func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
JMP ·syscall6Internal(SB)

// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
JMP ·rawSyscallInternal(SB)

// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
JMP ·rawSyscall6Internal(SB)

// func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
TEXT ·Syscall9(SB),NOSPLIT,$0-104
JMP ·syscall9Internal(SB)
11 changes: 11 additions & 0 deletions src/syscall/mkall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ openbsd_ppc64)
# API consistent between platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
mkasm="go run mkasm.go"
openbsd_riscv64)
GOOSARCH_in="syscall_openbsd_libc.go syscall_openbsd_$GOARCH.go"
mkerrors="$mkerrors -m64"
mksyscall="./mksyscall.pl -openbsd -libc"
mksysctl="./mksysctl_openbsd.pl"
zsysctl="zsysctl_openbsd.go"
mksysnum="curl -s 'http:https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
# Let the type of C char be signed to make the bare syscall
# API consistent between platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
mkasm="go run mkasm.go"
;;
plan9_386)
mkerrors=
Expand Down
38 changes: 38 additions & 0 deletions src/syscall/syscall_openbsd_riscv64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package syscall

func setTimespec(sec, nsec int64) Timespec {
return Timespec{Sec: sec, Nsec: nsec}
}

func setTimeval(sec, usec int64) Timeval {
return Timeval{Sec: sec, Usec: usec}
}

func SetKevent(k *Kevent_t, fd, mode, flags int) {
k.Ident = uint64(fd)
k.Filter = int16(mode)
k.Flags = uint16(flags)
}

func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}

func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = uint32(length)
}

func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length)
}

// RTM_LOCK only exists in OpenBSD 6.3 and earlier.
const RTM_LOCK = 0x8

// SYS___SYSCTL only exists in OpenBSD 5.8 and earlier, when it was
// was renamed to SYS_SYSCTL.
const SYS___SYSCTL = SYS_SYSCTL
Loading

0 comments on commit 9018601

Please sign in to comment.