From 26c222a91430ed7ad82a4e7bb3a6dc0a151061c0 Mon Sep 17 00:00:00 2001 From: "Chen, Gang G" Date: Tue, 20 Feb 2024 10:36:14 +0800 Subject: [PATCH] Add rdtsc implementation and get efiwarpper start tsc Test Done: boot success Tracked-On: OAM-115655 Signed-off-by: Chen, Gang G --- include/libefiwrapper/rdtsc.h | 14 ++++++++++++++ main.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/libefiwrapper/rdtsc.h diff --git a/include/libefiwrapper/rdtsc.h b/include/libefiwrapper/rdtsc.h new file mode 100644 index 0000000..8451c3e --- /dev/null +++ b/include/libefiwrapper/rdtsc.h @@ -0,0 +1,14 @@ +#ifndef RDTSC_H +#define RDTSC_H + +#include + +static uint64_t rdtsc(void) +{ + uint32_t lo, hi; + + asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); + return (uint64_t) hi << 32 | lo; +} + +#endif diff --git a/main.c b/main.c index 7fbedad..b3b1fc1 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,14 @@ #include #include #include +#include + +static uint64_t efiwarpper_start_tsc; +uint64_t efiwrapper_tsc() +{ + return efiwarpper_start_tsc; +} + /* Entry point */ int main(int argc, char **argv) { @@ -44,6 +52,8 @@ int main(int argc, char **argv) EFI_SYSTEM_TABLE *st; EFI_STATUS ret; + efiwarpper_start_tsc = rdtsc(); + ret = efiwrapper_init(argc, argv, &st, &image); if (ret) { ewerr("efiwrapper library initialization failed");