From ef72c9d6d5aa90e0c886f8526093fa4f12124fd0 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Sat, 27 Jun 2026 06:47:29 +0000 Subject: [PATCH] stos/amd64: hpet: Add MdHpetTimeUsec() helper Signed-off-by: Chloe M. --- paw/stos/arch/amd64/platform/hpet.c | 15 +++++++++++++++ paw/stos/head/arch/amd64/hpet.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/paw/stos/arch/amd64/platform/hpet.c b/paw/stos/arch/amd64/platform/hpet.c index ad7f08e..caba537 100644 --- a/paw/stos/arch/amd64/platform/hpet.c +++ b/paw/stos/arch/amd64/platform/hpet.c @@ -14,6 +14,7 @@ #include #include #include +#include #define DTRACE(Fmt, ...) \ TRACE("[ HPET ]: " Fmt, ##__VA_ARGS__) @@ -57,6 +58,20 @@ HpetReadq(UCHAR Register) return MMIORead64(RegBase); } +USIZE +MdHpetTimeUsec(VOID) +{ + UQUAD Period, Freq, Caps; + UQUAD Counter; + + Caps = HpetReadq(HPET_GENERAL_CAP); + Period = (Caps >> HPET_PERIOD_SHIFT) & HPET_PERIOD_MASK; + Freq = FSEC_PER_SECOND / Period; + Counter = HpetReadq(HPET_MAIN_COUNTER); + + return (Counter * USEC_PER_SECOND) / Freq; +} + VOID MdHpetInit(VOID) { diff --git a/paw/stos/head/arch/amd64/hpet.h b/paw/stos/head/arch/amd64/hpet.h index 5f79e71..95cb960 100644 --- a/paw/stos/head/arch/amd64/hpet.h +++ b/paw/stos/head/arch/amd64/hpet.h @@ -16,4 +16,9 @@ */ VOID MdHpetInit(VOID); +/* + * Obtain the elapsed time in microseconds + */ +USIZE MdHpetTimeUsec(VOID); + #endif /* !_MACHINE_HPET_H_ */