Botan 3.4.0
Crypto and TLS for C&
cpuid_arm32.cpp
Go to the documentation of this file.
1/*
2* Runtime CPU detection for 32-bit ARM
3* (C) 2009,2010,2013,2017 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/cpuid.h>
9
10#if defined(BOTAN_TARGET_ARCH_IS_ARM32)
11
12 #include <botan/internal/os_utils.h>
13
14namespace Botan {
15
16uint32_t CPUID::CPUID_Data::detect_cpu_features() {
17 uint32_t detected_features = 0;
18
19 #if defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_OS_HAS_ELF_AUX_INFO)
20 /*
21 * On systems with getauxval these bits should normally be defined
22 * in bits/auxv.h but some buggy? glibc installs seem to miss them.
23 * These following values are all fixed, for the Linux ELF format,
24 * so we just hardcode them in ARM_hwcap_bit enum.
25 */
26
27 enum ARM_hwcap_bit {
28 NEON_bit = (1 << 12),
29 AES_bit = (1 << 0),
30 PMULL_bit = (1 << 1),
31 SHA1_bit = (1 << 2),
32 SHA2_bit = (1 << 3),
33
34 ARCH_hwcap_neon = 16, // AT_HWCAP
35 ARCH_hwcap_crypto = 26, // AT_HWCAP2
36 };
37
38 const unsigned long hwcap_neon = OS::get_auxval(ARM_hwcap_bit::ARCH_hwcap_neon);
39 if(hwcap_neon & ARM_hwcap_bit::NEON_bit) {
40 detected_features |= CPUID::CPUID_ARM_NEON_BIT;
41
42 const unsigned long hwcap_crypto = OS::get_auxval(ARM_hwcap_bit::ARCH_hwcap_crypto);
43 if(hwcap_crypto & ARM_hwcap_bit::AES_bit)
44 detected_features |= CPUID::CPUID_ARM_AES_BIT;
45 if(hwcap_crypto & ARM_hwcap_bit::PMULL_bit)
46 detected_features |= CPUID::CPUID_ARM_PMULL_BIT;
47 if(hwcap_crypto & ARM_hwcap_bit::SHA1_bit)
48 detected_features |= CPUID::CPUID_ARM_SHA1_BIT;
49 if(hwcap_crypto & ARM_hwcap_bit::SHA2_bit)
50 detected_features |= CPUID::CPUID_ARM_SHA2_BIT;
51 }
52 #endif
53
54 return detected_features;
55}
56
57} // namespace Botan
58
59#endif
unsigned long get_auxval(unsigned long id)
Definition os_utils.cpp:128