diff --git a/Core/CPU.cpp b/Core/CPU.cpp index a477f98..7ff1616 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -240,6 +240,24 @@ namespace CPU trace("Features for BSP initialized."); #elif defined(__i386__) #elif defined(__aarch64__) +#endif + } + + uint64_t Counter() + { + // TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs) +#if defined(__amd64__) + uint64_t counter; + asmv("rdtsc" + : "=A"(counter)); + return counter; +#elif defined(__i386__) + return 0; +#elif defined(__aarch64__) + uint64_t counter; + asmv("mrs %0, cntvct_el0" + : "=r"(counter)); + return counter; #endif } } diff --git a/include/cpu.hpp b/include/cpu.hpp index f064a52..2b34302 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -203,6 +203,9 @@ namespace CPU /** @brief To be used only once. */ void InitializeFeatures(); + /** @brief Get CPU counter value. */ + uint64_t Counter(); + namespace MemBar { __attribute__((no_stack_protector)) static inline void Barrier()