diff options
author | Merry <[email protected]> | 2024-01-28 14:56:59 +0000 |
---|---|---|
committer | Merry <[email protected]> | 2024-01-28 14:56:59 +0000 |
commit | 99c0a73f91e7a5e66db686f29e158e99193a043d (patch) | |
tree | 67f2658c627ad55fe23d3d83ba76c9d8a65f99c2 /include/oaknut/feature_detection/feature_detection_netbsd.hpp | |
parent | 720d6bbcd87a8aecf628ab26a55ac7b17f7325df (diff) | |
download | dynarmic-99c0a73f91e7a5e66db686f29e158e99193a043d.tar.gz dynarmic-99c0a73f91e7a5e66db686f29e158e99193a043d.zip |
Squashed 'externals/oaknut/' changes from c24f918e5..d0488d932
d0488d932 oaknut: 2.0.0
40ad78bbf oaknut: Implement DualCodeBlock and related support
9f131cfb5 oaknut: add configuration for standalone installation
69799b43c oaknut: Test building for Android on CI
1d51f5512 oaknut: 1.2.2
918bd94f0 oaknut: Eliminate -Wconversion warnings
316d8869e oaknut: Fix edgecases in MOVP2R on +/-4GiB boundary
d8634eaa1 oaknut: Fix page boundary error in ADP
d0ca9a24e oaknut: Update README examples for CPU feature detection
dbeec268b oaknut: feature_detection_freebsd: Warn about incompatibility with earlier FreeBSD versions
86e5386e2 oaknut: feature_detect: Support NetBSD
df4cf2d48 oaknut: feature_detect: Support OpenBSD
99dfff25a oaknut: feature_detection: Read ID registers
319b3d2c9 oaknut: Add basic CPU feature detection
23e9ddb4c oaknut: CI: Don't run slow tests on OpenBSD
734f1bdb4 oaknut: CI: Use up-to-date qemu
f462c9774 oaknut: CI: Build on OpenBSD
19cd42204 oaknut: code_block: Add NetBSD and OpenBSD support
18b86a3ec oaknut: SystemReg: Add more EL0 accessible registers
53c43bf0c oaknut/tests: Reduce iterations for MOVP2R
cc37df19e oaknut: Test on FreeBSD
a66b32d26 oaknut: Fix crossing sign boundary in PageOffset
206468d72 oaknut: CI: Add macos-arm64 build
e6eecc3f9 oaknut: 1.2.1
4252d8f4a oaknut: CMakeLists: Warnings are errors on MSVC
408eed65f oaknut: arm64_encode_helpers: remove unreachable code
bfc8eedfb oaknut: arm64_encode_helpers: p maybe unused
ff4456eca oaknut: Avoid negation of unsigned values
b4ac8fd6c oaknut: Fix MOV for applications of MOVN
0575cadc4 oaknut: Disable certain functionality where absolute addressing is not available
394a3c8f0 oaknut: Appease MSVC
011183670 oaknut: 1.2.0
e83c9f327 oaknut: Add VectorCodeGenerator
5eb122cc5 oaknut: Tidy up public header
45c5a7b25 oaknut: Fix clang-format errors
36243256f oaknut: Add `const` qualifier to `AddrOffset` ctor
4af500cb5 oaknut: Add `ptr` accessor to `Label`
bccb06669 oaknut: CodeGenerator const correctness
da0590a86 oaknut: github: Update package repositories
git-subtree-dir: externals/oaknut
git-subtree-split: d0488d9320ae673167dd9117223e3453d5ff102f
Diffstat (limited to 'include/oaknut/feature_detection/feature_detection_netbsd.hpp')
-rw-r--r-- | include/oaknut/feature_detection/feature_detection_netbsd.hpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/include/oaknut/feature_detection/feature_detection_netbsd.hpp b/include/oaknut/feature_detection/feature_detection_netbsd.hpp new file mode 100644 index 00000000..cdb1deb1 --- /dev/null +++ b/include/oaknut/feature_detection/feature_detection_netbsd.hpp @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: Copyright (c) 2023 merryhime <https://mary.rs> +// SPDX-License-Identifier: MIT + +#pragma once + +#include <array> +#include <cstddef> +#include <cstdint> +#include <optional> +#include <string> + +#include <aarch64/armreg.h> +#include <sys/param.h> +#include <sys/sysctl.h> + +#include "oaknut/feature_detection/cpu_feature.hpp" +#include "oaknut/feature_detection/feature_detection_hwcaps.hpp" +#include "oaknut/feature_detection/feature_detection_idregs.hpp" +#include "oaknut/feature_detection/id_registers.hpp" + +namespace oaknut { + +inline std::optional<id::IdRegisters> read_id_registers(std::size_t core_index) +{ + const std::string path = "machdep.cpu" + std::to_string(core_index) + ".cpu_id"; + + aarch64_sysctl_cpu_id id; + std::size_t id_len = sizeof id; + + if (sysctlbyname(path.c_str(), &id, &id_len, nullptr, 0) < 0) + return std::nullopt; + + return id::IdRegisters{ + id.ac_midr, + id::Pfr0Register{id.ac_aa64pfr0}, + id::Pfr1Register{id.ac_aa64pfr1}, + id::Pfr2Register{0}, + id::Zfr0Register{id.ac_aa64zfr0}, + id::Smfr0Register{0}, + id::Isar0Register{id.ac_aa64isar0}, + id::Isar1Register{id.ac_aa64isar1}, + id::Isar2Register{0}, + id::Isar3Register{0}, + id::Mmfr0Register{id.ac_aa64mmfr0}, + id::Mmfr1Register{id.ac_aa64mmfr1}, + id::Mmfr2Register{id.ac_aa64mmfr2}, + id::Mmfr3Register{0}, + id::Mmfr4Register{0}, + }; +} + +inline std::size_t get_core_count() +{ + int result = 0; + size_t result_size = sizeof(result); + const std::array<int, 2> mib{CTL_HW, HW_NCPU}; + if (sysctl(mib.data(), mib.size(), &result, &result_size, nullptr, 0) < 0) + return 0; + return result; +} + +inline CpuFeatures detect_features() +{ + std::optional<CpuFeatures> result; + + const std::size_t core_count = get_core_count(); + for (std::size_t core_index = 0; core_index < core_count; core_index++) { + if (const std::optional<id::IdRegisters> id_regs = read_id_registers(core_index)) { + const CpuFeatures current_features = detect_features_via_id_registers(*id_regs); + if (result) { + result = *result & current_features; + } else { + result = current_features; + } + } + } + + return result.value_or(CpuFeatures{}); +} + +} // namespace oaknut |