diff --git a/xtoskrnl/includes/ke.hh b/xtoskrnl/includes/ke.hh index 6448dd3..e4ceec4 100644 --- a/xtoskrnl/includes/ke.hh +++ b/xtoskrnl/includes/ke.hh @@ -27,6 +27,7 @@ #include #include #include +#include #include #endif /* __XTOSKRNL_KE_HH */ diff --git a/xtoskrnl/includes/ke/systime.hh b/xtoskrnl/includes/ke/systime.hh new file mode 100644 index 0000000..c37ba75 --- /dev/null +++ b/xtoskrnl/includes/ke/systime.hh @@ -0,0 +1,32 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ke/systime.hh + * DESCRIPTION: Timebase and system clock support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_KE_SYSTIME_HH +#define __XTOSKRNL_KE_SYSTIME_HH + +#include + + +/* Kernel Library */ +namespace KE +{ + class SystemTime + { + private: + STATIC LARGE_INTEGER BootTime; + + public: + STATIC XTAPI VOID GetSystemTime(OUT PLARGE_INTEGER SystemTime); + STATIC XTAPI VOID SetSystemTime(IN PLARGE_INTEGER NewTime, + OUT PLARGE_INTEGER OldTime, + IN BOOLEAN AdjustInterruptTime, + IN BOOLEAN WriteToRtc); + }; +} + +#endif /* __XTOSKRNL_KE_SYSTIME_HH */ diff --git a/xtoskrnl/ke/systime.cc b/xtoskrnl/ke/systime.cc new file mode 100644 index 0000000..b31dda7 --- /dev/null +++ b/xtoskrnl/ke/systime.cc @@ -0,0 +1,99 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/ke/systime.cc + * DESCRIPTION: Timebase and system clock support + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Returns the current system time. + * + * @param SystemTime + * Supplies a pointer to a variable that receives the current system time. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::SystemTime::GetSystemTime(OUT PLARGE_INTEGER SystemTime) +{ + LARGE_INTEGER CurrentTime; + + /* Fetch the time using the lock-free shared data mechanism and return it */ + CurrentTime = KE::SharedData::GetSystemTime(); + SystemTime->QuadPart = CurrentTime.QuadPart; +} + +/** + * Sets the system time, updates the boot time, and optionally updates the hardware Real-Time Clock (RTC). + * + * @param NewTime + * Supplies a pointer to the new system time. + * + * @param OldTime + * Supplies a pointer to a variable that receives the previous system time. + * + * @param AdjustInterruptTime + * Specifies if the physical interrupt time should be adjusted. + * + * @param WriteToRtc + * Specifies if the new system time should be written to RTC. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::SystemTime::SetSystemTime(IN PLARGE_INTEGER NewTime, + OUT PLARGE_INTEGER OldTime, + IN BOOLEAN CorrectInterruptTime, + IN BOOLEAN WriteToRtc) +{ + LARGE_INTEGER TimeDelta; + TIME_FIELDS TimeFields; + + /* Check if the new system time should be written to the RTC */ + if(WriteToRtc) + { + /* Convert the new system time to a human-readable calendar structure */ + RTL::Time::XtEpochToTimeFields(NewTime, &TimeFields); + } + + /* Start a guarded code block */ + { + /* Raise runlevel to HIGH level */ + KE::RaiseRunLevel Runlevel(HIGH_LEVEL); + + /* Save the previous system time for the caller and for delta calculation */ + GetSystemTime(OldTime); + + /* Write new system time to the Kernel Shared Data */ + KE::SharedData::SetSystemTime(*NewTime); + + /* Check if the new system time should be written to the RTC */ + if(WriteToRtc) + { + /* Update the hardware CMOS clock */ + HL::Rtc::SetRealTimeClock(&TimeFields); + } + + /* Calculate the time difference */ + TimeDelta.QuadPart = NewTime->QuadPart - OldTime->QuadPart; + + /* Update the boot time by the delta */ + BootTime.QuadPart += TimeDelta.QuadPart; + } + + /* Check if interrupt time needs to be corrected */ + if(CorrectInterruptTime) + { + UNIMPLEMENTED; + } +}