From b874bdead2903d715c6964b2e8f9ed7d2b61db12 Mon Sep 17 00:00:00 2001 From: Christian Weisgerber Date: Sun, 12 Jun 2022 21:51:16 +0200 Subject: Enable runtime arm64 feature detection on openbsd --- fat-arm64.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'fat-arm64.c') diff --git a/fat-arm64.c b/fat-arm64.c index ef3c33f4..f2b8493d 100644 --- a/fat-arm64.c +++ b/fat-arm64.c @@ -46,6 +46,10 @@ # include # include # endif +#elif defined(__OpenBSD__) +# include +# include +# include #endif #include "nettle-types.h" @@ -122,6 +126,21 @@ get_arm64_features (struct arm64_features *features) = ((hwcap & (HWCAP_ASIMD | HWCAP_SHA1)) == (HWCAP_ASIMD | HWCAP_SHA1)); features->have_sha2 = ((hwcap & (HWCAP_ASIMD | HWCAP_SHA2)) == (HWCAP_ASIMD | HWCAP_SHA2)); +#elif defined(__OpenBSD__) + const int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 }; + uint64_t isar0; + size_t len = sizeof(isar0); + + if (sysctl(isar0_mib, 2, &isar0, &len, NULL, 0) < 0) + return; + features->have_aes + = (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_BASE); + features->have_pmull + = (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_PMULL); + features->have_sha1 + = (ID_AA64ISAR0_SHA1(isar0) >= ID_AA64ISAR0_SHA1_BASE); + features->have_sha2 + = (ID_AA64ISAR0_SHA2(isar0) >= ID_AA64ISAR0_SHA2_BASE); #endif } } -- cgit v1.2.1