forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuid_notry.c
71 lines (53 loc) · 2 KB
/
cpuid_notry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// cpuid_notry.c code for CPU feature detection based on CPUID for ARM64
// without the try except structure (used in boot environment)
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
#if SYMCRYPT_CPU_ARM64 & SYMCRYPT_MS_VC
#define ARM64_SYSREG(op0, op1, crn, crm, op2) \
( ((op0 & 1) << 14) | \
((op1 & 7) << 11) | \
((crn & 15) << 7) | \
((crm & 15) << 3) | \
((op2 & 7) << 0) )
#define ARM64_ID_AA64ISAR0_EL1 ARM64_SYSREG(3,0, 0, 6,0) // ISA Feature Register 0
#define ISAR0_AES 1
#define ISAR0_AES_NI 0
#define ISAR0_AES_INSTRUCTIONS 1
#define ISAR0_AES_PLUS_PMULL64 2
#define ISAR0_SHA2 3
#define ISAR0_SHA2_NI 0
#define ISAR0_SHA2_INSTRUCTIONS 1
#define ISAR0_CRC32 4
#define ISAR0_CRC32_NI 0
#define ISAR0_CRC32_INSTRUCTIONS 1
#define READ_ARM64_FEATURE(_FeatureRegister, _Index) \
(((ULONG64)_ReadStatusReg(_FeatureRegister) >> ((_Index) * 4)) & 0xF)
VOID
SYMCRYPT_CALL
SymCryptDetectCpuFeaturesFromRegistersNoTry(void)
{
ULONG result;
result = ~ (ULONG)(
SYMCRYPT_CPU_FEATURE_NEON |
SYMCRYPT_CPU_FEATURE_NEON_AES |
SYMCRYPT_CPU_FEATURE_NEON_PMULL |
SYMCRYPT_CPU_FEATURE_NEON_SHA256
);
if( READ_ARM64_FEATURE(ARM64_ID_AA64ISAR0_EL1, ISAR0_AES) < ISAR0_AES_INSTRUCTIONS )
{
result |= SYMCRYPT_CPU_FEATURE_NEON_AES;
}
if( READ_ARM64_FEATURE(ARM64_ID_AA64ISAR0_EL1, ISAR0_AES) < ISAR0_AES_PLUS_PMULL64 )
{
result |= SYMCRYPT_CPU_FEATURE_NEON_PMULL;
}
if( READ_ARM64_FEATURE(ARM64_ID_AA64ISAR0_EL1, ISAR0_SHA2) < ISAR0_SHA2_INSTRUCTIONS )
{
result |= SYMCRYPT_CPU_FEATURE_NEON_SHA256;
}
g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) result;
}
#endif // CPU arch selection