Source file src/runtime/os_linux_riscv64.go
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 ( 8 "internal/runtime/syscall" 9 "unsafe" 10 ) 11 12 func osArchInit() {} 13 14 type riscvHWProbePairs = struct { 15 key int64 16 value uint64 17 } 18 19 // TODO: Consider whether to use the VDSO entry for riscv_hwprobe. 20 // There is a VDSO entry for riscv_hwprobe that should allow us to avoid the syscall 21 // entirely as it can handle the case where the caller only requests extensions that are 22 // supported on all cores, which is what we're doing here. However, as we're only calling 23 // this syscall once, it may not be worth the added effort to implement the VDSO call. 24 25 //go:linkname internal_cpu_riscvHWProbe internal/cpu.riscvHWProbe 26 func internal_cpu_riscvHWProbe(pairs []riscvHWProbePairs, flags uint) bool { 27 // sys_RISCV_HWPROBE is copied from golang.org/x/sys/unix/zsysnum_linux_riscv64.go. 28 const sys_RISCV_HWPROBE uintptr = 258 29 30 if len(pairs) == 0 { 31 return false 32 } 33 // Passing in a cpuCount of 0 and a cpu of nil ensures that only extensions supported by all the 34 // cores are returned, which is the behaviour we want in internal/cpu. 35 _, _, e1 := syscall.Syscall6(sys_RISCV_HWPROBE, uintptr(unsafe.Pointer(&pairs[0])), uintptr(len(pairs)), uintptr(0), uintptr(unsafe.Pointer(nil)), uintptr(flags), 0) 36 return e1 == 0 37 } 38