| 1 |
// Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_ARM_ARCH_H |
| 5 |
#define OPENSSL_HEADER_ARM_ARCH_H |
| 6 |
|
| 7 |
#include <openssl/target.h> |
| 8 |
|
| 9 |
// arm_arch.h contains symbols used by ARM assembly, and the C code that calls |
| 10 |
// it. It is included as a public header to simplify the build, but is not |
| 11 |
// intended for external use. |
| 12 |
|
| 13 |
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) |
| 14 |
|
| 15 |
// ARMV7_NEON is true when a NEON unit is present in the current CPU. |
| 16 |
#define ARMV7_NEON (1 << 0) |
| 17 |
|
| 18 |
// ARMV8_AES indicates support for hardware AES instructions. |
| 19 |
#define ARMV8_AES (1 << 2) |
| 20 |
|
| 21 |
// ARMV8_SHA1 indicates support for hardware SHA-1 instructions. |
| 22 |
#define ARMV8_SHA1 (1 << 3) |
| 23 |
|
| 24 |
// ARMV8_SHA256 indicates support for hardware SHA-256 instructions. |
| 25 |
#define ARMV8_SHA256 (1 << 4) |
| 26 |
|
| 27 |
// ARMV8_PMULL indicates support for carryless multiplication. |
| 28 |
#define ARMV8_PMULL (1 << 5) |
| 29 |
|
| 30 |
// ARMV8_SHA512 indicates support for hardware SHA-512 instructions. |
| 31 |
#define ARMV8_SHA512 (1 << 6) |
| 32 |
|
| 33 |
// ARMV8_SHA3 indicates support for hardware SHA-3 instructions including EOR3. |
| 34 |
#define ARMV8_SHA3 (1 << 11) |
| 35 |
|
| 36 |
// Combination of all Armv8 Neon extension bits: 0x087c |
| 37 |
// NOTE: If you add further Armv8 Neon extension bits, adjust |
| 38 |
// "Test algorithm dispatch without CPU indicator or Neon extension capability bits" |
| 39 |
// in util/all_tests.json |
| 40 |
|
| 41 |
// The Neoverse N1, V1, V2, and Apple M1 micro-architectures are detected to |
| 42 |
// allow selecting the fasted implementations for SHA3/SHAKE and AES-GCM. |
| 43 |
// Combination of all CPU indicator bits: 0x7080 |
| 44 |
// NOTE: If you add further CPU indicator bits, adjust |
| 45 |
// "Test algorithm dispatch without CPU indicator bits" in util/all_tests.json. |
| 46 |
#define ARMV8_NEOVERSE_N1 (1 << 7) |
| 47 |
#define ARMV8_NEOVERSE_V1 (1 << 12) |
| 48 |
#define ARMV8_APPLE_M (1 << 13) |
| 49 |
#define ARMV8_NEOVERSE_V2 (1 << 14) |
| 50 |
|
| 51 |
// Combination of CPU indicator bits and Armv8 Neon extension bits: 0x78fc |
| 52 |
|
| 53 |
// ARMV8_DIT indicates support for the Data-Independent Timing (DIT) flag. |
| 54 |
#define ARMV8_DIT (1 << 15) |
| 55 |
// ARMV8_DIT_ALLOWED is a run-time en/disabler for the Data-Independent |
| 56 |
// Timing (DIT) flag capability. It makes the DIT capability allowed when it is |
| 57 |
// first discovered in |OPENSSL_cpuid_setup|. But that bit position in |
| 58 |
// |OPENSSL_armcap_P| can be toggled off and back on at run-time via |
| 59 |
// |armv8_disable_dit| and |armv8_enable_dit|, respectively. |
| 60 |
#define ARMV8_DIT_ALLOWED (1 << 16) |
| 61 |
|
| 62 |
// ARMV8_RNG indicates supports for hardware RNG instruction RNDR. |
| 63 |
#define ARMV8_RNG (1 << 17) |
| 64 |
|
| 65 |
// |
| 66 |
// MIDR_EL1 system register |
| 67 |
// |
| 68 |
// 63___ _ ___32_31___ _ ___24_23_____20_19_____16_15__ _ __4_3_______0 |
| 69 |
// | | | | | | | |
| 70 |
// |RES0 | Implementer | Variant | Arch | PartNum |Revision| |
| 71 |
// |____ _ _____|_____ _ _____|_________|_______ _|____ _ ___|________| |
| 72 |
// |
| 73 |
|
| 74 |
# define ARM_CPU_IMP_ARM 0x41 |
| 75 |
|
| 76 |
# define ARM_CPU_PART_CORTEX_A72 0xD08 |
| 77 |
# define ARM_CPU_PART_N1 0xD0C |
| 78 |
# define ARM_CPU_PART_V1 0xD40 |
| 79 |
# define ARM_CPU_PART_V2 0xD4F |
| 80 |
|
| 81 |
# define MIDR_PARTNUM_SHIFT 4 |
| 82 |
# define MIDR_PARTNUM_MASK (0xfffUL << MIDR_PARTNUM_SHIFT) |
| 83 |
# define MIDR_PARTNUM(midr) \ |
| 84 |
(((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT) |
| 85 |
|
| 86 |
# define MIDR_IMPLEMENTER_SHIFT 24 |
| 87 |
# define MIDR_IMPLEMENTER_MASK (0xffUL << MIDR_IMPLEMENTER_SHIFT) |
| 88 |
# define MIDR_IMPLEMENTER(midr) \ |
| 89 |
(((midr) & MIDR_IMPLEMENTER_MASK) >> MIDR_IMPLEMENTER_SHIFT) |
| 90 |
|
| 91 |
# define MIDR_ARCHITECTURE_SHIFT 16 |
| 92 |
# define MIDR_ARCHITECTURE_MASK (0xfUL << MIDR_ARCHITECTURE_SHIFT) |
| 93 |
# define MIDR_ARCHITECTURE(midr) \ |
| 94 |
(((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT) |
| 95 |
|
| 96 |
# define MIDR_CPU_MODEL_MASK \ |
| 97 |
(MIDR_IMPLEMENTER_MASK | \ |
| 98 |
MIDR_PARTNUM_MASK | \ |
| 99 |
MIDR_ARCHITECTURE_MASK) |
| 100 |
|
| 101 |
# define MIDR_CPU_MODEL(imp, partnum) \ |
| 102 |
(((imp) << MIDR_IMPLEMENTER_SHIFT) | \ |
| 103 |
(0xfUL << MIDR_ARCHITECTURE_SHIFT) | \ |
| 104 |
((partnum) << MIDR_PARTNUM_SHIFT)) |
| 105 |
|
| 106 |
# define MIDR_IS_CPU_MODEL(midr, imp, partnum) \ |
| 107 |
(((midr) & MIDR_CPU_MODEL_MASK) == MIDR_CPU_MODEL(imp, partnum)) |
| 108 |
|
| 109 |
#endif // ARM || AARCH64 |
| 110 |
|
| 111 |
#endif // OPENSSL_HEADER_ARM_ARCH_H |