summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/AMD64/HalTimer.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-21 08:51:41 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-21 09:07:20 +0100
commit4e61e22c3da59b259741e57298725330791aed3e (patch)
treeb81e078defa58d1fcae570fa72b403606ae596b8 /dev/kernel/HALKit/AMD64/HalTimer.cc
parent1e12163836e649da0d67fc8f17bc9a415554efe4 (diff)
feat: NeKernel Semaphore API.
includes: - New semaphore API for the kernel, we also make use of the HardwareTimer class here. - Defined header only for now. - New HAL HW Timer API in AMD64. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/AMD64/HalTimer.cc')
-rw-r--r--dev/kernel/HALKit/AMD64/HalTimer.cc18
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..ae3271f6 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
}
}
@@ -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;
}