--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ RealTimeClock.c\r
+\r
+Abstract:\r
+\r
+ NT Emulation Architectural Protocol Driver as defined in Tiano\r
+\r
+--*/\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+BOOLEAN\r
+DayValid (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGetTime (\r
+ OUT EFI_TIME *Time,\r
+ OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->GetTime \r
+\r
+Arguments:\r
+\r
+ Time - A pointer to storage that will receive a snapshot of the current time.\r
+\r
+ Capabilities - A pointer to storage that will receive the capabilities of the real time clock\r
+ in the platform. This includes the real time clock's resolution and accuracy. \r
+ All reported device capabilities are rounded up. This is an OPTIONAL argument.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The underlying GetSystemTime call occurred and returned\r
+ Note that in the NT32 emulation, the GetSystemTime call has no return value\r
+ thus you will always receive a EFI_SUCCESS on this.\r
+\r
+--*/\r
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+ SYSTEMTIME SystemTime;\r
+ TIME_ZONE_INFORMATION TimeZone;\r
+\r
+ //\r
+ // Check parameter for null pointer\r
+ //\r
+ if (Time == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+\r
+ }\r
+\r
+ gWinNt->GetLocalTime (&SystemTime);\r
+ gWinNt->GetTimeZoneInformation (&TimeZone);\r
+\r
+ Time->Year = (UINT16) SystemTime.wYear;\r
+ Time->Month = (UINT8) SystemTime.wMonth;\r
+ Time->Day = (UINT8) SystemTime.wDay;\r
+ Time->Hour = (UINT8) SystemTime.wHour;\r
+ Time->Minute = (UINT8) SystemTime.wMinute;\r
+ Time->Second = (UINT8) SystemTime.wSecond;\r
+ Time->Nanosecond = (UINT32) (SystemTime.wMilliseconds * 1000000);\r
+ Time->TimeZone = (INT16) TimeZone.Bias;\r
+\r
+ if (Capabilities != NULL) {\r
+ Capabilities->Resolution = 1;\r
+ Capabilities->Accuracy = 50000000;\r
+ Capabilities->SetsToZero = FALSE;\r
+ }\r
+\r
+ Time->Daylight = 0;\r
+ if (TimeZone.StandardDate.wMonth) {\r
+ Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSetTime (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->SetTime \r
+\r
+Arguments:\r
+\r
+ Time - A pointer to storage containing the time and date information to\r
+ program into the real time clock.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r
+\r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+--*/\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ TIME_ZONE_INFORMATION TimeZone;\r
+ EFI_STATUS Status;\r
+ SYSTEMTIME SystemTime;\r
+ BOOL Flag;\r
+\r
+ if (Time == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ //\r
+ // Make sure that the time fields are valid\r
+ //\r
+ Status = RtcTimeFieldsValid (Time);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ //\r
+ // Set Daylight savings time information and Time Zone\r
+ //\r
+ gWinNt->GetTimeZoneInformation (&TimeZone);\r
+ TimeZone.StandardDate.wMonth = Time->Daylight;\r
+ TimeZone.Bias = Time->TimeZone;\r
+ gWinNt->SetTimeZoneInformation (&TimeZone);\r
+\r
+ SystemTime.wYear = Time->Year;\r
+ SystemTime.wMonth = Time->Month;\r
+ SystemTime.wDay = Time->Day;\r
+ SystemTime.wHour = Time->Hour;\r
+ SystemTime.wMinute = Time->Minute;\r
+ SystemTime.wSecond = Time->Second;\r
+ SystemTime.wMilliseconds = (INT16) (Time->Nanosecond / 1000000);\r
+\r
+ Flag = gWinNt->SetLocalTime (&SystemTime);\r
+\r
+ if (!Flag) {\r
+ return EFI_DEVICE_ERROR;\r
+ } else {\r
+ return EFI_SUCCESS;\r
+ }\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGetWakeupTime (\r
+ OUT BOOLEAN *Enabled,\r
+ OUT BOOLEAN *Pending,\r
+ OUT EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->GetWakeupTime\r
+\r
+Arguments:\r
+ This - Indicates the protocol instance structure.\r
+\r
+ Enabled - Indicates if the alarm is currently enabled or disabled.\r
+\r
+ Pending - Indicates if the alarm signal is pending and requires\r
+ acknowledgement.\r
+\r
+ Time - The current alarm setting.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+ EFI_UNSUPPORTED - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtSetWakeupTime (\r
+ IN BOOLEAN Enable,\r
+ OUT EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->SetWakeupTime\r
+\r
+Arguments:\r
+\r
+ Enabled - Enable or disable the wakeup alarm.\r
+\r
+ Time - If enable is TRUE, the time to set the wakup alarm for.\r
+ If enable is FALSE, then this parameter is optional, and\r
+ may be NULL.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+ EFI_INVALID_PARAMETER - A field in Time is out of range.\r
+\r
+ EFI_UNSUPPORTED - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Install Real Time Clock Protocol \r
+\r
+Arguments:\r
+ (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r
+\r
+--*/\r
+// TODO: ImageHandle - add argument and description to function comment\r
+// TODO: SystemTable - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
+\r
+\r
+ SystemTable->RuntimeServices->GetTime = WinNtGetTime;\r
+ SystemTable->RuntimeServices->SetTime = WinNtSetTime;\r
+ SystemTable->RuntimeServices->GetWakeupTime = WinNtGetWakeupTime;\r
+ SystemTable->RuntimeServices->SetWakeupTime = WinNtSetWakeupTime;\r
+\r
+ Handle = NULL;\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Handle,\r
+ &gEfiRealTimeClockArchProtocolGuid,\r
+ NULL,\r
+ NULL\r
+ );\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Arguments:\r
+ \r
+ Returns: \r
+--*/\r
+// TODO: Time - add argument and description to function comment\r
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ if (Time->Year < 1998 ||\r
+ Time->Year > 2099 ||\r
+ Time->Month < 1 ||\r
+ Time->Month > 12 ||\r
+ (!DayValid (Time)) ||\r
+ Time->Hour > 23 ||\r
+ Time->Minute > 59 ||\r
+ Time->Second > 59 ||\r
+ Time->Nanosecond > 999999999 ||\r
+ (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
+ (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
+ ) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+DayValid (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+{\r
+\r
+ INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
+\r
+ if (Time->Day < 1 ||\r
+ Time->Day > DayOfMonth[Time->Month - 1] ||\r
+ (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
+ ) {\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+{\r
+ if (Time->Year % 4 == 0) {\r
+ if (Time->Year % 100 == 0) {\r
+ if (Time->Year % 400 == 0) {\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+ } else {\r
+ return TRUE;\r
+ }\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r
--- /dev/null
+#/** @file\r
+# NT Emulation Real time clock Architectural Protocol Driver as defined in TIANO\r
+#\r
+# This real time clock module simulates virtual device by time WinAPI.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = RealTimeClock\r
+ FILE_GUID = 27F05AF5-1644-4EF4-8944-48C4F75675A0\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+ ENTRY_POINT = InitializeRealTimeClock\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+ RealTimeClock.dxs\r
+ RealTimeClock.c\r
+ CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+ $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+ UefiBootServicesTableLib\r
+ WinNtLib\r
+ UefiDriverEntryPoint\r
+ DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+# that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+ gEfiRealTimeClockArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+ <MsaHeader>\r
+ <ModuleName>RealTimeClock</ModuleName>\r
+ <ModuleType>DXE_DRIVER</ModuleType>\r
+ <GuidValue>27F05AF5-1644-4EF4-8944-48C4F75675A0</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>NT Emulation Real time clock Architectural Protocol Driver as defined in TIANO</Abstract>\r
+ <Description>This real time clock module simulates virtual device by time WinAPI.</Description>\r
+ <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+ <License>All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>RealTimeClock</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <LibraryClassDefinitions>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>DebugLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>UefiDriverEntryPoint</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>WinNtLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>UefiBootServicesTableLib</Keyword>\r
+ </LibraryClass>\r
+ </LibraryClassDefinitions>\r
+ <SourceFiles>\r
+ <Filename>RealTimeClock.c</Filename>\r
+ <Filename>RealTimeClock.dxs</Filename>\r
+ </SourceFiles>\r
+ <PackageDependencies>\r
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+ <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
+ </PackageDependencies>\r
+ <Protocols>\r
+ <Protocol Usage="ALWAYS_PRODUCED">\r
+ <ProtocolCName>gEfiRealTimeClockArchProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ </Protocols>\r
+ <Externs>\r
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+ <Extern>\r
+ <ModuleEntryPoint>InitializeRealTimeClock</ModuleEntryPoint>\r
+ </Extern>\r
+ </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file