...
Run Format

Source file src/runtime/os_linux_arm.go

Documentation: runtime

     1  // Copyright 2009 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  	_AT_PLATFORM = 15 //  introduced in at least 2.6.11
    11  
    12  	_HWCAP_VFP   = 1 << 6  // introduced in at least 2.6.11
    13  	_HWCAP_VFPv3 = 1 << 13 // introduced in 2.6.30
    14  	_HWCAP_IDIVA = 1 << 17
    15  )
    16  
    17  var randomNumber uint32
    18  var armArch uint8 = 6 // we default to ARMv6
    19  var hwcap uint32      // set by setup_auxv
    20  var hardDiv bool      // set if a hardware divider is available
    21  
    22  func checkgoarm() {
    23  	// On Android, /proc/self/auxv might be unreadable and hwcap won't
    24  	// reflect the CPU capabilities. Assume that every Android arm device
    25  	// has the necessary floating point hardware available.
    26  	if GOOS == "android" {
    27  		return
    28  	}
    29  	if goarm > 5 && hwcap&_HWCAP_VFP == 0 {
    30  		print("runtime: this CPU has no floating point hardware, so it cannot run\n")
    31  		print("this GOARM=", goarm, " binary. Recompile using GOARM=5.\n")
    32  		exit(1)
    33  	}
    34  	if goarm > 6 && hwcap&_HWCAP_VFPv3 == 0 {
    35  		print("runtime: this CPU has no VFPv3 floating point hardware, so it cannot run\n")
    36  		print("this GOARM=", goarm, " binary. Recompile using GOARM=5.\n")
    37  		exit(1)
    38  	}
    39  }
    40  
    41  func archauxv(tag, val uintptr) {
    42  	switch tag {
    43  	case _AT_RANDOM:
    44  		// sysargs filled in startupRandomData, but that
    45  		// pointer may not be word aligned, so we must treat
    46  		// it as a byte array.
    47  		randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
    48  			uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
    49  
    50  	case _AT_PLATFORM: // v5l, v6l, v7l
    51  		t := *(*uint8)(unsafe.Pointer(val + 1))
    52  		if '5' <= t && t <= '7' {
    53  			armArch = t - '0'
    54  		}
    55  
    56  	case _AT_HWCAP: // CPU capability bit flags
    57  		hwcap = uint32(val)
    58  		hardDiv = (hwcap & _HWCAP_IDIVA) != 0
    59  	}
    60  }
    61  
    62  //go:nosplit
    63  func cputicks() int64 {
    64  	// Currently cputicks() is used in blocking profiler and to seed fastrand().
    65  	// nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
    66  	// randomNumber provides better seeding of fastrand.
    67  	return nanotime() + int64(randomNumber)
    68  }
    69  

View as plain text