diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-16 19:56:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 19:56:21 +0200 |
| commit | 1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (patch) | |
| tree | f41f723659c8926e38182fbe062746d821ab487e /dev/kernel/HALKit/AMD64/HalTimer.cc | |
| parent | eb9df5eea339812513c25a8d3b2eeb03c633e7ac (diff) | |
| parent | b301047903b79560dce69085fc271a653a1eb4b6 (diff) | |
Merge pull request #55 from nekernel-org/dev
v0.0.4
Diffstat (limited to 'dev/kernel/HALKit/AMD64/HalTimer.cc')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalTimer.cc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalTimer.cc b/dev/kernel/HALKit/AMD64/HalTimer.cc index 13573880..22876a96 100644 --- a/dev/kernel/HALKit/AMD64/HalTimer.cc +++ b/dev/kernel/HALKit/AMD64/HalTimer.cc @@ -61,11 +61,8 @@ HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { // if not enabled yet.
if (!(*((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) & (1 << 0))) {
*((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) =
- *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) |
- (1 << 0); // enable timer
- *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) =
- *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) |
- (1 << 3); // one shot conf
+ *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | (1 << 0) |
+ (1 << 3); // enable timer & one shot conf
}
}
@@ -80,18 +77,21 @@ HardwareTimer::~HardwareTimer() { BOOL HardwareTimer::Wait() noexcept {
if (fWaitFor < 1) return NO;
+ if (fWaitFor > 1'000'000) return NO; // max 1000s = 16 minutes
- UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue));
+ UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer));
UInt64 femtoseconds_per_tick = (hpet_cap >> 32);
if (femtoseconds_per_tick == 0) return NO;
volatile UInt64* timer = (volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue);
- UInt64 now = *timer;
- UInt64 prev = now + (fWaitFor / femtoseconds_per_tick);
+ UInt64 now = *timer;
+
+ UInt64 fs_wait = fWaitFor * 1'000'000'000'000ULL;
+ UInt64 stop_at = now + (fs_wait / femtoseconds_per_tick);
- while (*timer < (prev)) asm volatile("pause");
+ while (*timer < (stop_at)) asm volatile("pause");
return YES;
}
|
