1// Copyright 2015 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// +build arm64
6
7package runtime
8
9import "internal/cpu"
10
11var randomNumber uint32
12
13func archauxv(tag, val uintptr) {
14	switch tag {
15	case _AT_RANDOM:
16		// sysargs filled in startupRandomData, but that
17		// pointer may not be word aligned, so we must treat
18		// it as a byte array.
19		randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
20			uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
21
22	case _AT_HWCAP:
23		// arm64 doesn't have a 'cpuid' instruction equivalent and relies on
24		// HWCAP/HWCAP2 bits for hardware capabilities.
25		hwcap := uint(val)
26		if GOOS == "android" {
27			// The Samsung S9+ kernel reports support for atomics, but not all cores
28			// actually support them, resulting in SIGILL. See issue #28431.
29			// TODO(elias.naur): Only disable the optimization on bad chipsets.
30			const hwcap_ATOMICS = 1 << 8
31			hwcap &= ^uint(hwcap_ATOMICS)
32		}
33		cpu.HWCap = hwcap
34	case _AT_HWCAP2:
35		cpu.HWCap2 = uint(val)
36	}
37}
38