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