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

View as plain text