mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
@ -29,13 +29,13 @@ namespace Time
|
||||
bool HighPrecisionEventTimer::Sleep(size_t Duration, Units Unit)
|
||||
{
|
||||
#if defined(a64)
|
||||
uint64_t Target = mminq(&((HPET *)hpet)->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
|
||||
while (mminq(&((HPET *)hpet)->MainCounterValue) < Target)
|
||||
uint64_t Target = mminq(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
|
||||
while (mminq(&hpet->MainCounterValue) < Target)
|
||||
CPU::Pause();
|
||||
return true;
|
||||
#elif defined(a32)
|
||||
uint64_t Target = mminl(&((HPET *)hpet)->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
|
||||
while (mminl(&((HPET *)hpet)->MainCounterValue) < Target)
|
||||
uint64_t Target = mminl(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
|
||||
while (mminl(&hpet->MainCounterValue) < Target)
|
||||
CPU::Pause();
|
||||
return true;
|
||||
#endif
|
||||
@ -45,18 +45,18 @@ namespace Time
|
||||
uint64_t HighPrecisionEventTimer::GetCounter()
|
||||
{
|
||||
#if defined(a64)
|
||||
return mminq(&((HPET *)hpet)->MainCounterValue);
|
||||
return mminq(&hpet->MainCounterValue);
|
||||
#elif defined(a32)
|
||||
return mminl(&((HPET *)hpet)->MainCounterValue);
|
||||
return mminl(&hpet->MainCounterValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t HighPrecisionEventTimer::CalculateTarget(uint64_t Target, Units Unit)
|
||||
{
|
||||
#if defined(a64)
|
||||
return mminq(&((HPET *)hpet)->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
|
||||
return mminq(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
|
||||
#elif defined(a32)
|
||||
return mminl(&((HPET *)hpet)->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
|
||||
return mminl(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -66,7 +66,9 @@ namespace Time
|
||||
uint64_t Subtraction = this->GetCounter() - this->ClassCreationTime;
|
||||
if (Subtraction <= 0 || this->clk <= 0)
|
||||
return 0;
|
||||
return uint64_t(Subtraction / (this->clk / ConvertUnit(Units::Nanoseconds)));
|
||||
|
||||
Subtraction *= ConvertUnit(Units::Nanoseconds);
|
||||
return uint64_t(Subtraction / this->clk);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -74,13 +76,16 @@ namespace Time
|
||||
{
|
||||
#if defined(a86)
|
||||
ACPI::ACPI::HPETHeader *HPET_HDR = (ACPI::ACPI::HPETHeader *)hpet;
|
||||
Memory::Virtual().Map((void *)HPET_HDR->Address.Address,
|
||||
(void *)HPET_HDR->Address.Address,
|
||||
Memory::PTFlag::RW | Memory::PTFlag::PCD);
|
||||
Memory::Virtual vmm;
|
||||
vmm.Map((void *)HPET_HDR->Address.Address,
|
||||
(void *)HPET_HDR->Address.Address,
|
||||
Memory::PTFlag::RW | Memory::PTFlag::PCD);
|
||||
this->hpet = (HPET *)HPET_HDR->Address.Address;
|
||||
trace("%s timer is at address %016p", HPET_HDR->Header.OEMID, (void *)HPET_HDR->Address.Address);
|
||||
trace("%s timer is at address %016p",
|
||||
HPET_HDR->Header.OEMID,
|
||||
(void *)HPET_HDR->Address.Address);
|
||||
clk = s_cst(uint32_t, (uint64_t)this->hpet->GeneralCapabilities >> 32);
|
||||
debug("HPET clock is %u Hz", clk);
|
||||
KPrint("HPET clock is %u Hz", clk);
|
||||
#ifdef a64
|
||||
mmoutq(&this->hpet->GeneralConfiguration, 0);
|
||||
mmoutq(&this->hpet->MainCounterValue, 0);
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <time.hpp>
|
||||
@ -21,91 +21,91 @@
|
||||
|
||||
namespace Time
|
||||
{
|
||||
Clock ReadClock()
|
||||
{
|
||||
Clock tm;
|
||||
Clock ReadClock()
|
||||
{
|
||||
Clock tm;
|
||||
#if defined(a86)
|
||||
uint32_t t = 0;
|
||||
outb(0x70, 0x00);
|
||||
t = inb(0x71);
|
||||
tm.Second = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x02);
|
||||
t = inb(0x71);
|
||||
tm.Minute = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x04);
|
||||
t = inb(0x71);
|
||||
tm.Hour = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x07);
|
||||
t = inb(0x71);
|
||||
tm.Day = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x08);
|
||||
t = inb(0x71);
|
||||
tm.Month = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x09);
|
||||
t = inb(0x71);
|
||||
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
tm.Counter = 0;
|
||||
uint32_t t = 0;
|
||||
outb(0x70, 0x00);
|
||||
t = inb(0x71);
|
||||
tm.Second = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x02);
|
||||
t = inb(0x71);
|
||||
tm.Minute = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x04);
|
||||
t = inb(0x71);
|
||||
tm.Hour = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x07);
|
||||
t = inb(0x71);
|
||||
tm.Day = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x08);
|
||||
t = inb(0x71);
|
||||
tm.Month = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
outb(0x70, 0x09);
|
||||
t = inb(0x71);
|
||||
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
|
||||
tm.Counter = 0;
|
||||
#elif defined(aa64)
|
||||
tm.Year = 0;
|
||||
tm.Month = 0;
|
||||
tm.Day = 0;
|
||||
tm.Hour = 0;
|
||||
tm.Minute = 0;
|
||||
tm.Second = 0;
|
||||
tm.Counter = 0;
|
||||
tm.Year = 0;
|
||||
tm.Month = 0;
|
||||
tm.Day = 0;
|
||||
tm.Hour = 0;
|
||||
tm.Minute = 0;
|
||||
tm.Second = 0;
|
||||
tm.Counter = 0;
|
||||
#endif
|
||||
return tm;
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
Clock ConvertFromUnix(int Timestamp)
|
||||
{
|
||||
Clock result;
|
||||
Clock ConvertFromUnix(int Timestamp)
|
||||
{
|
||||
Clock result;
|
||||
|
||||
uint64_t Seconds = Timestamp;
|
||||
uint64_t Minutes = Seconds / 60;
|
||||
uint64_t Hours = Minutes / 60;
|
||||
uint64_t Days = Hours / 24;
|
||||
uint64_t Seconds = Timestamp;
|
||||
uint64_t Minutes = Seconds / 60;
|
||||
uint64_t Hours = Minutes / 60;
|
||||
uint64_t Days = Hours / 24;
|
||||
|
||||
result.Year = 1970;
|
||||
while (Days >= 365)
|
||||
{
|
||||
if (result.Year % 4 == 0 &&
|
||||
(result.Year % 100 != 0 ||
|
||||
result.Year % 400 == 0))
|
||||
{
|
||||
if (Days >= 366)
|
||||
{
|
||||
Days -= 366;
|
||||
result.Year++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Days -= 365;
|
||||
result.Year++;
|
||||
}
|
||||
}
|
||||
result.Year = 1970;
|
||||
while (Days >= 365)
|
||||
{
|
||||
if (result.Year % 4 == 0 &&
|
||||
(result.Year % 100 != 0 ||
|
||||
result.Year % 400 == 0))
|
||||
{
|
||||
if (Days >= 366)
|
||||
{
|
||||
Days -= 366;
|
||||
result.Year++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Days -= 365;
|
||||
result.Year++;
|
||||
}
|
||||
}
|
||||
|
||||
int DaysInMonth[] = {31,
|
||||
result.Year % 4 == 0
|
||||
? 29
|
||||
: 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
for (result.Month = 0; result.Month < 12; result.Month++)
|
||||
{
|
||||
if (Days < s_cst(uint64_t, (DaysInMonth[result.Month])))
|
||||
break;
|
||||
Days -= DaysInMonth[result.Month];
|
||||
}
|
||||
result.Month++;
|
||||
int DaysInMonth[] = {31,
|
||||
result.Year % 4 == 0
|
||||
? 29
|
||||
: 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
for (result.Month = 0; result.Month < 12; result.Month++)
|
||||
{
|
||||
if (Days < s_cst(uint64_t, (DaysInMonth[result.Month])))
|
||||
break;
|
||||
Days -= DaysInMonth[result.Month];
|
||||
}
|
||||
result.Month++;
|
||||
|
||||
result.Day = s_cst(int, (Days) + 1);
|
||||
result.Hour = s_cst(int, (Hours % 24));
|
||||
result.Minute = s_cst(int, (Minutes % 60));
|
||||
result.Second = s_cst(int, (Seconds % 60));
|
||||
result.Counter = s_cst(uint64_t, (Timestamp));
|
||||
return result;
|
||||
}
|
||||
result.Day = s_cst(int, (Days) + 1);
|
||||
result.Hour = s_cst(int, (Hours % 24));
|
||||
result.Minute = s_cst(int, (Minutes % 60));
|
||||
result.Second = s_cst(int, (Seconds % 60));
|
||||
result.Counter = s_cst(uint64_t, (Timestamp));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace Time
|
||||
TimeStampCounter::TimeStampCounter()
|
||||
{
|
||||
#if defined(a86)
|
||||
fixme(""); // FIXME: This is not a good way to measure the clock speed
|
||||
stub; // FIXME: This is not a good way to measure the clock speed
|
||||
uint64_t Start = CPU::Counter();
|
||||
TimeManager->Sleep(1, Units::Milliseconds);
|
||||
uint64_t End = CPU::Counter();
|
||||
|
Reference in New Issue
Block a user