mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-12 07:49:14 +00:00
.github
.vscode
Architecture
Core
Crash
Driver
Memory
Video
CPU.cpp
Debugger.cpp
Disk.cpp
InterruptsManager.cpp
Lock.cpp
PeripheralComponentInterconnect.cpp
Power.cpp
README.md
Random.cpp
StackGuard.cpp
Symbols.cpp
SystemManagementBIOS.cpp
Time.cpp
Timer.cpp
UndefinedBehaviorSanitization.c
UniversalAsynchronousReceiverTransmitter.cpp
crashhandler.hpp
smbios.hpp
ubsan.h
Execute
FileSystem
Files
GUI
Library
Network
Profiling
Recovery
SystemCalls
Tasking
Tests
include
.gitignore
DAPI.hpp
Doxyfile
Fex.hpp
KConfig.cpp
KThread.cpp
Kernel.cpp
LICENSE
Makefile
README.md
dump.sh
ipc.h
kernel.h
syscalls.h
90 lines
2.4 KiB
C++
90 lines
2.4 KiB
C++
#include <time.hpp>
|
|
|
|
#include <memory.hpp>
|
|
#include <debug.h>
|
|
#include <io.h>
|
|
|
|
#if defined(a64)
|
|
#include "../Architecture/amd64/acpi.hpp"
|
|
#elif defined(a32)
|
|
#elif defined(aa64)
|
|
#endif
|
|
|
|
#include "../kernel.h"
|
|
|
|
namespace Time
|
|
{
|
|
void time::Sleep(uint64_t Milliseconds)
|
|
{
|
|
#if defined(a64) || defined(a32)
|
|
uint64_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000000) / clk;
|
|
#ifdef DEBUG
|
|
uint64_t Counter = mminq(&((HPET *)hpet)->MainCounterValue);
|
|
while (Counter < Target)
|
|
{
|
|
Counter = mminq(&((HPET *)hpet)->MainCounterValue);
|
|
CPU::Pause();
|
|
}
|
|
#else
|
|
while (mminq(&((HPET *)hpet)->MainCounterValue) < Target)
|
|
CPU::Pause();
|
|
#endif
|
|
#elif defined(aa64)
|
|
#endif
|
|
}
|
|
|
|
uint64_t time::GetCounter()
|
|
{
|
|
#if defined(a64) || defined(a32)
|
|
return mminq(&((HPET *)hpet)->MainCounterValue);
|
|
#elif defined(aa64)
|
|
#endif
|
|
}
|
|
|
|
uint64_t time::CalculateTarget(uint64_t Milliseconds)
|
|
{
|
|
#if defined(a64) || defined(a32)
|
|
return mminq(&((HPET *)hpet)->MainCounterValue) + (Milliseconds * 1000000000000) / clk;
|
|
#elif defined(aa64)
|
|
#endif
|
|
}
|
|
|
|
time::time(void *_acpi)
|
|
{
|
|
if (_acpi)
|
|
{
|
|
#if defined(a64)
|
|
this->acpi = _acpi;
|
|
ACPI::ACPI *acpi = (ACPI::ACPI *)this->acpi;
|
|
if (acpi->HPET)
|
|
{
|
|
Memory::Virtual().Map((void *)acpi->HPET->Address.Address,
|
|
(void *)acpi->HPET->Address.Address,
|
|
Memory::PTFlag::RW | Memory::PTFlag::PCD);
|
|
this->hpet = (void *)acpi->HPET->Address.Address;
|
|
HPET *hpet = (HPET *)this->hpet;
|
|
trace("%s timer is at address %016p", acpi->HPET->Header.OEMID, (void *)acpi->HPET->Address.Address);
|
|
clk = hpet->GeneralCapabilities >> 32;
|
|
mmoutq(&hpet->GeneralConfiguration, 0);
|
|
mmoutq(&hpet->MainCounterValue, 0);
|
|
mmoutq(&hpet->GeneralConfiguration, 1);
|
|
}
|
|
else
|
|
{
|
|
// For now, we need HPET.
|
|
error("HPET not found");
|
|
KPrint("\eFF2200HPET not found");
|
|
CPU::Stop();
|
|
}
|
|
#elif defined(a32)
|
|
#elif defined(aa64)
|
|
#endif
|
|
}
|
|
}
|
|
|
|
time::~time()
|
|
{
|
|
debug("Destructor called");
|
|
}
|
|
}
|