1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2011-2022 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#ifndef OSSL_CRYPTO_ARM_ARCH_H 11e1051a39Sopenharmony_ci# define OSSL_CRYPTO_ARM_ARCH_H 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ci# if !defined(__ARM_ARCH__) 14e1051a39Sopenharmony_ci# if defined(__CC_ARM) 15e1051a39Sopenharmony_ci# define __ARM_ARCH__ __TARGET_ARCH_ARM 16e1051a39Sopenharmony_ci# if defined(__BIG_ENDIAN) 17e1051a39Sopenharmony_ci# define __ARMEB__ 18e1051a39Sopenharmony_ci# else 19e1051a39Sopenharmony_ci# define __ARMEL__ 20e1051a39Sopenharmony_ci# endif 21e1051a39Sopenharmony_ci# elif defined(__GNUC__) 22e1051a39Sopenharmony_ci# if defined(__aarch64__) 23e1051a39Sopenharmony_ci# define __ARM_ARCH__ 8 24e1051a39Sopenharmony_ci# if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ 25e1051a39Sopenharmony_ci# define __ARMEB__ 26e1051a39Sopenharmony_ci# else 27e1051a39Sopenharmony_ci# define __ARMEL__ 28e1051a39Sopenharmony_ci# endif 29e1051a39Sopenharmony_ci /* 30e1051a39Sopenharmony_ci * Why doesn't gcc define __ARM_ARCH__? Instead it defines 31e1051a39Sopenharmony_ci * bunch of below macros. See all_architectures[] table in 32e1051a39Sopenharmony_ci * gcc/config/arm/arm.c. On a side note it defines 33e1051a39Sopenharmony_ci * __ARMEL__/__ARMEB__ for little-/big-endian. 34e1051a39Sopenharmony_ci */ 35e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH) 36e1051a39Sopenharmony_ci# define __ARM_ARCH__ __ARM_ARCH 37e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH_8A__) 38e1051a39Sopenharmony_ci# define __ARM_ARCH__ 8 39e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \ 40e1051a39Sopenharmony_ci defined(__ARM_ARCH_7R__)|| defined(__ARM_ARCH_7M__) || \ 41e1051a39Sopenharmony_ci defined(__ARM_ARCH_7EM__) 42e1051a39Sopenharmony_ci# define __ARM_ARCH__ 7 43e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \ 44e1051a39Sopenharmony_ci defined(__ARM_ARCH_6K__)|| defined(__ARM_ARCH_6M__) || \ 45e1051a39Sopenharmony_ci defined(__ARM_ARCH_6Z__)|| defined(__ARM_ARCH_6ZK__) || \ 46e1051a39Sopenharmony_ci defined(__ARM_ARCH_6T2__) 47e1051a39Sopenharmony_ci# define __ARM_ARCH__ 6 48e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \ 49e1051a39Sopenharmony_ci defined(__ARM_ARCH_5E__)|| defined(__ARM_ARCH_5TE__) || \ 50e1051a39Sopenharmony_ci defined(__ARM_ARCH_5TEJ__) 51e1051a39Sopenharmony_ci# define __ARM_ARCH__ 5 52e1051a39Sopenharmony_ci# elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) 53e1051a39Sopenharmony_ci# define __ARM_ARCH__ 4 54e1051a39Sopenharmony_ci# else 55e1051a39Sopenharmony_ci# error "unsupported ARM architecture" 56e1051a39Sopenharmony_ci# endif 57e1051a39Sopenharmony_ci# endif 58e1051a39Sopenharmony_ci# endif 59e1051a39Sopenharmony_ci 60e1051a39Sopenharmony_ci# if !defined(__ARM_MAX_ARCH__) 61e1051a39Sopenharmony_ci# define __ARM_MAX_ARCH__ __ARM_ARCH__ 62e1051a39Sopenharmony_ci# endif 63e1051a39Sopenharmony_ci 64e1051a39Sopenharmony_ci# if __ARM_MAX_ARCH__<__ARM_ARCH__ 65e1051a39Sopenharmony_ci# error "__ARM_MAX_ARCH__ can't be less than __ARM_ARCH__" 66e1051a39Sopenharmony_ci# elif __ARM_MAX_ARCH__!=__ARM_ARCH__ 67e1051a39Sopenharmony_ci# if __ARM_ARCH__<7 && __ARM_MAX_ARCH__>=7 && defined(__ARMEB__) 68e1051a39Sopenharmony_ci# error "can't build universal big-endian binary" 69e1051a39Sopenharmony_ci# endif 70e1051a39Sopenharmony_ci# endif 71e1051a39Sopenharmony_ci 72e1051a39Sopenharmony_ci# ifndef __ASSEMBLER__ 73e1051a39Sopenharmony_ciextern unsigned int OPENSSL_armcap_P; 74e1051a39Sopenharmony_ciextern unsigned int OPENSSL_arm_midr; 75e1051a39Sopenharmony_ciextern unsigned int OPENSSL_armv8_rsa_neonized; 76e1051a39Sopenharmony_ci# endif 77e1051a39Sopenharmony_ci 78e1051a39Sopenharmony_ci# define ARMV7_NEON (1<<0) 79e1051a39Sopenharmony_ci# define ARMV7_TICK (1<<1) 80e1051a39Sopenharmony_ci# define ARMV8_AES (1<<2) 81e1051a39Sopenharmony_ci# define ARMV8_SHA1 (1<<3) 82e1051a39Sopenharmony_ci# define ARMV8_SHA256 (1<<4) 83e1051a39Sopenharmony_ci# define ARMV8_PMULL (1<<5) 84e1051a39Sopenharmony_ci# define ARMV8_SHA512 (1<<6) 85e1051a39Sopenharmony_ci# define ARMV8_CPUID (1<<7) 86e1051a39Sopenharmony_ci 87e1051a39Sopenharmony_ci/* 88e1051a39Sopenharmony_ci * MIDR_EL1 system register 89e1051a39Sopenharmony_ci * 90e1051a39Sopenharmony_ci * 63___ _ ___32_31___ _ ___24_23_____20_19_____16_15__ _ __4_3_______0 91e1051a39Sopenharmony_ci * | | | | | | | 92e1051a39Sopenharmony_ci * |RES0 | Implementer | Variant | Arch | PartNum |Revision| 93e1051a39Sopenharmony_ci * |____ _ _____|_____ _ _____|_________|_______ _|____ _ ___|________| 94e1051a39Sopenharmony_ci * 95e1051a39Sopenharmony_ci */ 96e1051a39Sopenharmony_ci 97e1051a39Sopenharmony_ci# define ARM_CPU_IMP_ARM 0x41 98e1051a39Sopenharmony_ci 99e1051a39Sopenharmony_ci# define ARM_CPU_PART_CORTEX_A72 0xD08 100e1051a39Sopenharmony_ci# define ARM_CPU_PART_N1 0xD0C 101e1051a39Sopenharmony_ci 102e1051a39Sopenharmony_ci# define MIDR_PARTNUM_SHIFT 4 103e1051a39Sopenharmony_ci# define MIDR_PARTNUM_MASK (0xfffU << MIDR_PARTNUM_SHIFT) 104e1051a39Sopenharmony_ci# define MIDR_PARTNUM(midr) \ 105e1051a39Sopenharmony_ci (((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT) 106e1051a39Sopenharmony_ci 107e1051a39Sopenharmony_ci# define MIDR_IMPLEMENTER_SHIFT 24 108e1051a39Sopenharmony_ci# define MIDR_IMPLEMENTER_MASK (0xffU << MIDR_IMPLEMENTER_SHIFT) 109e1051a39Sopenharmony_ci# define MIDR_IMPLEMENTER(midr) \ 110e1051a39Sopenharmony_ci (((midr) & MIDR_IMPLEMENTER_MASK) >> MIDR_IMPLEMENTER_SHIFT) 111e1051a39Sopenharmony_ci 112e1051a39Sopenharmony_ci# define MIDR_ARCHITECTURE_SHIFT 16 113e1051a39Sopenharmony_ci# define MIDR_ARCHITECTURE_MASK (0xfU << MIDR_ARCHITECTURE_SHIFT) 114e1051a39Sopenharmony_ci# define MIDR_ARCHITECTURE(midr) \ 115e1051a39Sopenharmony_ci (((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT) 116e1051a39Sopenharmony_ci 117e1051a39Sopenharmony_ci# define MIDR_CPU_MODEL_MASK \ 118e1051a39Sopenharmony_ci (MIDR_IMPLEMENTER_MASK | \ 119e1051a39Sopenharmony_ci MIDR_PARTNUM_MASK | \ 120e1051a39Sopenharmony_ci MIDR_ARCHITECTURE_MASK) 121e1051a39Sopenharmony_ci 122e1051a39Sopenharmony_ci# define MIDR_CPU_MODEL(imp, partnum) \ 123e1051a39Sopenharmony_ci (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ 124e1051a39Sopenharmony_ci (0xfU << MIDR_ARCHITECTURE_SHIFT) | \ 125e1051a39Sopenharmony_ci ((partnum) << MIDR_PARTNUM_SHIFT)) 126e1051a39Sopenharmony_ci 127e1051a39Sopenharmony_ci# define MIDR_IS_CPU_MODEL(midr, imp, partnum) \ 128e1051a39Sopenharmony_ci (((midr) & MIDR_CPU_MODEL_MASK) == MIDR_CPU_MODEL(imp, partnum)) 129e1051a39Sopenharmony_ci#endif 130