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_ */