Skip to content

Commit

Permalink
Fix FreeBSD runtime ARM CPU feature detection (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
baentsch authored Aug 3, 2022
1 parent 1e47e14 commit fe08f69
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,29 @@ static void set_available_cpu_extensions(void) {
cpu_ext_data[OQS_CPU_EXT_INIT] = 1;
}
#elif defined(__FreeBSD__) || defined(__FreeBSD)
#include <stdint.h>
#include <machine/armreg.h>
#include <sys/auxv.h>
#include <machine/elf.h>

static void set_available_cpu_extensions(void) {
/* mark that this function has been called */
u_long hwcaps = 0;
cpu_ext_data[OQS_CPU_EXT_INIT] = 1;
uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1);
if (ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE) {
if (elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long))) {
fprintf(stderr, "Error getting HWCAP for ARM on FreeBSD\n");
return;
}
if (hwcaps | HWCAP_AES) {
cpu_ext_data[OQS_CPU_EXT_ARM_AES] = 1;
}
if (ID_AA64ISAR0_SHA2_VAL(isar0) >= ID_AA64ISAR0_SHA2_BASE) {
if (hwcaps | HWCAP_ASIMD) {
cpu_ext_data[OQS_CPU_EXT_ARM_NEON] = 1;
}
if (hwcaps | HWCAP_SHA2) {
cpu_ext_data[OQS_CPU_EXT_ARM_SHA2] = 1;
}
if (ID_AA64ISAR0_SHA3_VAL(isar0) >= ID_AA64ISAR0_SHA3_BASE) {
if (hwcaps | HWCAP_SHA3) {
cpu_ext_data[OQS_CPU_EXT_ARM_SHA3] = 1;
}
if (ID_AA64ISAR0_AdvSIMD_VAL(isar0) >= ID_AA64ISAR0_AdvSIMD_BASE) {
cpu_ext_data[OQS_CPU_EXT_ARM_NEON] = 1;
}
}
#else
#include <sys/auxv.h>
Expand Down

0 comments on commit fe08f69

Please sign in to comment.