Added Counter() function to CPU

This commit is contained in:
Alex 2022-11-01 01:54:15 +02:00
parent f3cfc623d8
commit 99606bed00
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 21 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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()