-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CPU feature detection for FreeBSD/aarch64
I agree to license my contributions to each file under the terms given at the top of each file I changed.
- Loading branch information
1 parent
03ffd88
commit 79fd0f8
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2019 Greg V | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for any | ||
// purpose with or without fee is hereby granted, provided that the above | ||
// copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
|
||
// Run-time feature detection for aarch64 on any OS that emulates the mrs instruction. | ||
// | ||
// On FreeBSD >= 12.0, Linux >= 4.11 and other operating systems, it is possible to use | ||
// privileged system registers from userspace to check CPU feature support. | ||
// | ||
// For proper support of SoCs where different cores have different capabilities | ||
// the OS has to always report only the features supported by all cores, like FreeBSD does. | ||
// | ||
// Only FreeBSD uses this right now. | ||
|
||
#ifdef __FreeBSD__ | ||
#pragma GCC diagnostic ignored "-Wgnu-statement-expression" | ||
#include <GFp/cpu.h> | ||
#include <GFp/arm_arch.h> | ||
#include <machine/armreg.h> | ||
|
||
void GFp_mrs_setup(void) { | ||
GFp_armcap_P = 0; | ||
|
||
uint64_t id_aa64isar0 = READ_SPECIALREG(ID_AA64ISAR0_EL1); | ||
|
||
if (ID_AA64ISAR0_AES(id_aa64isar0) >= ID_AA64ISAR0_AES_BASE) | ||
GFp_armcap_P |= ARMV8_AES; | ||
|
||
if (ID_AA64ISAR0_AES(id_aa64isar0) >= ID_AA64ISAR0_AES_PMULL) | ||
GFp_armcap_P |= ARMV8_PMULL; | ||
|
||
if (ID_AA64ISAR0_SHA2(id_aa64isar0) >= ID_AA64ISAR0_SHA2_BASE) | ||
GFp_armcap_P |= ARMV8_SHA256; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters