Damien Zammit, le ven. 02 févr. 2024 06:39:57 +0000, a ecrit: > diff --git a/i386/i386/apic.c b/i386/i386/apic.c > index 0cf7c37c..e3d53ce3 100644 > --- a/i386/i386/apic.c > +++ b/i386/i386/apic.c > @@ -26,6 +26,9 @@ > #include <kern/printf.h> > #include <kern/kalloc.h> > > +uint32_t hpet_period_nsec; > + > +extern uint32_t *hpet_addr;
We'd rather avoid extern variable declarations outside .h files. I know we still have some left in gnumach, but let's not add even more :) > +void > +hpet_udelay(uint32_t us) > +{ > + uint32_t start, finish, now; > + > + us *= NSEC_PER_USEC / hpet_period_nsec; You'll be more precise by using us = (us * NSEC_PER_USEC) / hpet_period_nsec; Also, please loudly reject values which are not supported. > + start = HPET32(HPET_COUNTER); > + > + finish = start + us; > + > + while (1) { > + now = HPET32(HPET_COUNTER); > + > + if (finish > start) { > + /* ticks did not wrap initially */ > + if (now >= finish) > + break; > + } else { > + /* ticks wrapped initially */ > + if ((now < start) && (now >= finish)) > + break; > + } Can't you rather just subtract start from now, and check when it beyond us? Samuel