Added Counter() function to CPU

This commit is contained in:
Alex
2022-11-01 01:54:15 +02:00
parent f3cfc623d8
commit 99606bed00
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
}
}