]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. UINTN & INTN issue for EBC architecture:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 22 Jun 2006 06:08:00 +0000 (06:08 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 22 Jun 2006 06:08:00 +0000 (06:08 +0000)
The MAX_BIT of EBC will no longer be fixed to bit 63. It is defined as (1ULL << (sizeof (INTN) * 8 - 1)).
Make EdkModulePkg & MdePkg EBC compiler clean: treat all EFI_STATUS error code as variable.
2. PrintLib
Complete all missing ASSERT()s.
Fix “\n” & “%\n” issue thanks to the clarification of MWG 0.56d.
Adjust StatusString array to support EBC build.
3. BaseMemoryLib
Adjust ASSERT () & function header of ComparaMem, SetMemXX, ScanMemXX to synchronize with MWG 0.56d.
4.SmbusLib
Change Pec bit to bit 22 SmBusAddress to synchronize MWG 0.56d.
Add ASSERT()s to check if length is illegal for SmBusBlockWrite() & SmBusProcessBlock() since it is 6 bit now.
5. PerformanceLib
Rename “EdkDxePerformanceLib” & “EdkPeiPerformanceLib” to “DxePerformanceLib” & “PeiPerformanceLib” respectively.
Synchronize the function header of GetPerformanceMeasurement() with MWG 0.56d.
6. BasePeCoffLoaderLib.
Make PeCoffLoaderLoadImage () Assert() if ImageContext is NULL>
Make PeCoffLoaderLoadImage () return RETURN_INVALID_PARAMETER if the ImageAddress in ImageContext is 0.
Adjust some coding style.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@593 6f19259b-4bc3-4df7-8a09-765794883524

89 files changed:
EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c
EdkModulePkg/Core/Dxe/Hand/locate.c
EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c
EdkModulePkg/EdkModulePkg.spd
EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c [new file with mode: 0644]
EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd [new file with mode: 0644]
EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa [new file with mode: 0644]
EdkModulePkg/Library/DxePerformanceLib/build.xml [new file with mode: 0644]
EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c [new file with mode: 0644]
EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd [new file with mode: 0644]
EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa [new file with mode: 0644]
EdkModulePkg/Library/PeiPerformanceLib/build.xml [new file with mode: 0644]
EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_bc_udp.c
EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_loadfile.c
EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4Run.c
MdePkg/Include/Ebc/ProcessorBind.h
MdePkg/Include/Library/PeCoffLib.h
MdePkg/Include/Library/PerformanceLib.h
MdePkg/Include/Library/SmbusLib.h
MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c
MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c
MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c
MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c
MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c
MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c
MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c
MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c
MdePkg/Library/BaseMemoryLib/SetMemWrapper.c
MdePkg/Library/BaseMemoryLibMmx/CompareMemWrapper.c
MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c
MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c
MdePkg/Library/BaseMemoryLibRepStr/CompareMemWrapper.c
MdePkg/Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/SetMem16Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/SetMem32Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/SetMem64Wrapper.c
MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c
MdePkg/Library/BaseMemoryLibSse2/CompareMemWrapper.c
MdePkg/Library/BaseMemoryLibSse2/ScanMem16Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/ScanMem32Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/ScanMem64Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c
MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c
MdePkg/Library/BasePeCoffLib/BasePeCoff.c
MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c
MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c
MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c
MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c
MdePkg/Library/BasePerformanceLibNull/PerformanceLib.c
MdePkg/Library/BasePrintLib/PrintLib.c
MdePkg/Library/BaseSmbusLib/SmbusLib.c
MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h
MdePkg/Library/DxeSmbusLib/SmbusLib.c
MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c
MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c
MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c
MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c
MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c
MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c
MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c
MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c
MdePkg/Library/PeiMemoryLib/SetMemWrapper.c
MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h
MdePkg/Library/PeiSmbusLib/SmbusLib.c
MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c
MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c
MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c
MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c
MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c
MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c
MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c
MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c
MdePkg/Library/UefiMemoryLib/SetMemWrapper.c

index 006cc73bcbcabb1c1918f542928effee484000bd..88c4c3aec8ad5e291b87bc1b9e8cdaffa7ce7c98 100644 (file)
@@ -874,43 +874,34 @@ Returns:
             &InquiryDataLength,\r
             FALSE\r
             );\r
-  switch (Status) {\r
-  //\r
-  // no need to check HostAdapterStatus and TargetStatus\r
-  //\r
-  case EFI_SUCCESS:\r
-  case EFI_WARN_BUFFER_TOO_SMALL:\r
+  if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     ParseInquiryData (ScsiDiskDevice);\r
     return EFI_SUCCESS;\r
-\r
-  case EFI_NOT_READY:\r
+  } else if (Status == EFI_NOT_READY) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_INVALID_PARAMETER:\r
-  case EFI_UNSUPPORTED:\r
+  } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
-\r
+  }\r
   //\r
   // go ahead to check HostAdapterStatus and TargetStatus\r
   // (EFI_TIMEOUT, EFI_DEVICE_ERROR)\r
   //\r
-  default:\r
-    break;\r
-  }\r
-\r
   Status = CheckHostAdapterStatus (HostAdapterStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_TIMEOUT:\r
-  case EFI_NOT_READY:\r
+  if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     //\r
     // reset the scsi channel\r
     //\r
@@ -920,19 +911,14 @@ Returns:
   }\r
 \r
   Status = CheckTargetStatus (TargetStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_NOT_READY:\r
+  if (Status == EFI_NOT_READY) {\r
     //\r
     // reset the scsi device\r
     //\r
     ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -1022,37 +1008,27 @@ ScsiDiskTestUnitReady (
             &HostAdapterStatus,\r
             &TargetStatus\r
             );\r
-  switch (Status) {\r
-  //\r
-  // no need to check HostAdapterStatus and TargetStatus\r
-  //\r
-  case EFI_NOT_READY:\r
+  if (Status == EFI_NOT_READY) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_INVALID_PARAMETER:\r
-  case EFI_UNSUPPORTED:\r
+  } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
-\r
+  }\r
   //\r
   // go ahead to check HostAdapterStatus and TargetStatus\r
   //\r
-  default:\r
-    break;\r
-  }\r
-\r
   Status = CheckHostAdapterStatus (HostAdapterStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_TIMEOUT:\r
-  case EFI_NOT_READY:\r
+  if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     //\r
     // reset the scsi channel\r
     //\r
@@ -1062,19 +1038,14 @@ ScsiDiskTestUnitReady (
   }\r
 \r
   Status = CheckTargetStatus (TargetStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_NOT_READY:\r
+  if (Status == EFI_NOT_READY) {\r
     //\r
     // reset the scsi device\r
     //\r
     ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -1258,42 +1229,35 @@ Returns:
                     &DataLength,\r
                     FALSE\r
                     );\r
-  switch (CommandStatus) {\r
-  //\r
-  // no need to check HostAdapterStatus and TargetStatus\r
-  //\r
-  case EFI_SUCCESS:\r
+  if (CommandStatus == EFI_SUCCESS) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     GetMediaInfo (ScsiDiskDevice, &CapacityData);\r
     return EFI_SUCCESS;\r
-\r
-  case EFI_NOT_READY:\r
+  } else if (CommandStatus == EFI_NOT_READY) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_INVALID_PARAMETER:\r
-  case EFI_UNSUPPORTED:\r
+  } else if ((CommandStatus == EFI_INVALID_PARAMETER) || (CommandStatus == EFI_UNSUPPORTED)) {\r
+    //\r
+    // no need to check HostAdapterStatus and TargetStatus\r
+    //\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
-\r
+  }\r
   //\r
   // go ahead to check HostAdapterStatus and TargetStatus\r
   // (EFI_TIMEOUT, EFI_DEVICE_ERROR, EFI_WARN_BUFFER_TOO_SMALL)\r
   //\r
-  default:\r
-    break;\r
-  }\r
-\r
+  \r
   Status = CheckHostAdapterStatus (HostAdapterStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_TIMEOUT:\r
-  case EFI_NOT_READY:\r
+  if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     //\r
     // reset the scsi channel\r
     //\r
@@ -1303,19 +1267,14 @@ Returns:
   }\r
 \r
   Status = CheckTargetStatus (TargetStatus);\r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
-    break;\r
-\r
-  case EFI_NOT_READY:\r
+  if (Status == EFI_NOT_READY) {\r
     //\r
     // reset the scsi device\r
     //\r
     ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
     *NeedRetry = TRUE;\r
     return EFI_DEVICE_ERROR;\r
-\r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     *NeedRetry = FALSE;\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -1506,40 +1465,20 @@ ScsiDiskRequestSenseKeys (
               &HostAdapterStatus,\r
               &TargetStatus\r
               );\r
-    switch (Status) {\r
-\r
-    case EFI_SUCCESS:\r
-\r
-    //\r
-    // fall through\r
-    //\r
-    case EFI_WARN_BUFFER_TOO_SMALL:\r
+    if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) {\r
       FallStatus = EFI_SUCCESS;\r
-      break;\r
-\r
-    case EFI_TIMEOUT:\r
-\r
-    //\r
-    // fall through\r
-    //\r
-    case EFI_NOT_READY:\r
+    } else if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) { \r
       *NeedRetry  = TRUE;\r
       FallStatus  = EFI_DEVICE_ERROR;\r
-      break;\r
-\r
-    case EFI_INVALID_PARAMETER:\r
-    case EFI_UNSUPPORTED:\r
+    } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
       *NeedRetry  = FALSE;\r
       FallStatus  = EFI_DEVICE_ERROR;\r
-      break;\r
-\r
-    case EFI_DEVICE_ERROR:\r
+    } else if (Status == EFI_DEVICE_ERROR) {\r
       if (AskResetIfError) {\r
         ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
       }\r
 \r
       FallStatus = EFI_DEVICE_ERROR;\r
-      break;\r
     }\r
 \r
     if (EFI_ERROR (FallStatus)) {\r
index faa4255c7e9105ac311d114364343218a562779e..54d72c30a228778a2fed64059484c223bafb64f4 100644 (file)
@@ -702,15 +702,11 @@ Returns:
   //\r
   // Add code to correctly handle expected errors from CoreLocateHandle().\r
   //\r
-  if (EFI_ERROR(Status)) {\r
-    switch (Status) {\r
-    case EFI_BUFFER_TOO_SMALL:\r
-      break;\r
-    case EFI_INVALID_PARAMETER:\r
-      return Status;\r
-    default:\r
-      return EFI_NOT_FOUND;\r
+  if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
+    if (Status != EFI_INVALID_PARAMETER) {\r
+      Status = EFI_NOT_FOUND;\r
     }\r
+    return Status;\r
   }\r
 \r
   *Buffer = CoreAllocateBootServicesPool (BufferSize);\r
index 0bec576e6d9c8ba4a8ae6bd7cbcc3311342a238d..1eb5a4a0204486ce76c6def7dae81ecbed425855 100644 (file)
@@ -448,12 +448,7 @@ Returns:
   // Check if the total number of PEIMs exceed the bitmap.\r
   // CurrentPeim is 0-based\r
   //\r
-  DEBUG_CODE (\r
-    if (CurrentPeim > (sizeof (*DispatchedPeimBitMap) * 8 - 1)) {\r
-      ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);\r
-    }\r
-  );\r
-\r
+  ASSERT (CurrentPeim < (sizeof (*DispatchedPeimBitMap) * 8));\r
   *DispatchedPeimBitMap |= (1 << CurrentPeim);\r
   return;\r
 }\r
index da00472ce2b5896a40b7687dd0880bb62a10d981..e2b9542e65c67ed08cae343cec0cca6398e64f50 100644 (file)
       <Filename>Library/EdkDxePeCoffLoaderFromHobLib/EdkDxePeCoffLoaderFromHobLib.msa</Filename>
     </MsaFile>
     <MsaFile>
-      <Filename>Library/EdkDxePerformanceLib/EdkDxePerformanceLib.msa</Filename>
+      <Filename>Library/DxePerformanceLib/DxePerformanceLib.msa</Filename>
     </MsaFile>
     <MsaFile>
       <Filename>Library/EdkDxePrintLib/EdkDxePrintLib.msa</Filename>
       <Filename>Library/EdkPeCoffLoaderX64Lib/EdkPeCoffLoaderX64Lib.msa</Filename>
     </MsaFile>
     <MsaFile>
-      <Filename>Library/EdkPeiPerformanceLib/EdkPeiPerformanceLib.msa</Filename>
+      <Filename>Library/PeiPerformanceLib/PeiPerformanceLib.msa</Filename>
     </MsaFile>
     <MsaFile>
       <Filename>Library/EdkRuntimeStatusCodeLib/BsDataHubStatusCode/BsDataHubStatusCode.msa</Filename>
index c75ab851f70c2377b60e874c05f0041fde7ab5a7..e4e7b3bb3b689080aa87e824d45cc60abc8d95ac 100644 (file)
@@ -532,34 +532,46 @@ EndPerformanceMeasurement (
 }\r
 \r
 /**\r
-  Retrieves a previously logged performance measurement\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log\r
   \r
-  Retrieves the performance log entry from the performance log\r
-  that immediately follows the log entry specified by LogEntryKey.\r
-  If LogEntryKey is zero, then the first entry from the performance log is returned.\r
-  If the log entry specified by LogEntryKey is the last entry in the performance log,\r
-  then 0 is returned.  Otherwise, the performance log entry is returned in Handle,\r
-  Token, Module, StartTimeStamp, and EndTimeStamp.\r
-  The key for the current performance log entry is returned. \r
-\r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  StartTimeStamp          The 64-bit time stamp that was recorded when the measurement was started.\r
-  @param  EndTimeStamp            The 64-bit time stamp that was recorded when the measurement was ended.\r
-\r
-  @return The key for the current performance log entry.\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  UINTN           LogEntryKey, \r
+  IN  UINTN       LogEntryKey, \r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r
diff --git a/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
new file mode 100644 (file)
index 0000000..8a3ac40
--- /dev/null
@@ -0,0 +1,228 @@
+/*++\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
+  DxePerformanceLib.c\r
+\r
+Abstract:\r
+\r
+  Performance Library\r
+\r
+--*/\r
+\r
+STATIC PERFORMANCE_PROTOCOL    *mPerformance = NULL;\r
+\r
+/**\r
+  The constructor function caches the pointer to Performance protocol.\r
+  \r
+  The constructor function locates Performance protocol from protocol database.\r
+  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PerformanceLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+\r
+  Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &mPerformance);\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (mPerformance != NULL);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Creates a record for the beginning of a performance measurement. \r
+  \r
+  Creates a record that contains the Handle, Token, and Module.\r
+  If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
+  If TimeStamp is zero, then this function reads the current time stamp\r
+  and adds that time stamp value to the record as the start time.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
+  @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StartPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);\r
+\r
+  return (RETURN_STATUS) Status;\r
+}\r
+\r
+/**\r
+  Fills in the end time of a performance measurement. \r
+  \r
+  Looks up the record that matches Handle, Token, and Module.\r
+  If the record can not be found then return RETURN_NOT_FOUND.\r
+  If the record is found and TimeStamp is not zero,\r
+  then TimeStamp is added to the record as the end time.\r
+  If the record is found and TimeStamp is zero, then this function reads\r
+  the current time stamp and adds that time stamp value to the record as the end time.\r
+  If this function is called multiple times for the same record, then the end time is overwritten.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
+  @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+EndPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
+\r
+  return (RETURN_STATUS) Status;\r
+}\r
+\r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log. \r
+  \r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetPerformanceMeasurement (\r
+  IN  UINTN       LogEntryKey, \r
+  OUT CONST VOID  **Handle,\r
+  OUT CONST CHAR8 **Token,\r
+  OUT CONST CHAR8 **Module,\r
+  OUT UINT64      *StartTimeStamp,\r
+  OUT UINT64      *EndTimeStamp\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  GAUGE_DATA_ENTRY  *GaugeData;\r
+\r
+  ASSERT (Handle != NULL);\r
+  ASSERT (Token != NULL);\r
+  ASSERT (Module != NULL);\r
+  ASSERT (StartTimeStamp != NULL);\r
+  ASSERT (EndTimeStamp != NULL);\r
+\r
+  Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r
+  \r
+  //\r
+  // Make sure that LogEntryKey is a valid log entry key,\r
+  //\r
+  ASSERT (Status != EFI_INVALID_PARAMETER);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // The LogEntryKey is the last entry (equals to the total entry number).\r
+    //\r
+    return 0;\r
+  }\r
+\r
+  ASSERT (GaugeData != NULL);\r
+\r
+  *Handle         = (VOID *) (UINTN) GaugeData->Handle;\r
+  *Token          = GaugeData->Token;\r
+  *Module         = GaugeData->Module;\r
+  *StartTimeStamp = GaugeData->StartTimeStamp;\r
+  *EndTimeStamp   = GaugeData->EndTimeStamp;\r
+\r
+  return LogEntryKey;  \r
+}\r
+\r
+/**\r
+  Returns TRUE if the performance measurement macros are enabled. \r
+  \r
+  This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+  PcdPerformanceLibraryPropertyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval TRUE                    The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+                                  PcdPerformanceLibraryPropertyMask is set.\r
+  @retval FALSE                   The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+                                  PcdPerformanceLibraryPropertyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PerformanceMeasurementEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
+}\r
diff --git a/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd
new file mode 100644 (file)
index 0000000..1d8df54
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>\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
+<LibraryModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">\r
+  <MbdLibHeader>\r
+    <BaseName>DxePerformanceLib</BaseName>\r
+    <Guid>8B8B4CCC-65FC-41a5-8067-308B8E42CCF2</Guid>\r
+    <Version>EDK_RELEASE_VERSION        0x00020000</Version>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>\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
+    </License>\r
+    <Created>2006-04-04 11:11</Created>\r
+  </MbdLibHeader>\r
+</LibraryModuleBuildDescription>\r
diff --git a/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa
new file mode 100644 (file)
index 0000000..d8696f2
--- /dev/null
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>\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
+<LibraryModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">\r
+  <MsaLibHeader>\r
+    <BaseName>DxePerformanceLib</BaseName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <ComponentType>LIBRARY</ComponentType>\r
+    <Guid>8B8B4CCC-65FC-41a5-8067-308B8E42CCF2</Guid>\r
+    <Version>EDK_RELEASE_VERSION        0x00020000</Version>\r
+    <Abstract>Memory-only library functions with no library constructor/destructor</Abstract>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>\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
+    </License>\r
+    <Created>2006-04-04 11:11</Created>\r
+    <Specification>EFI_SPECIFICATION_VERSION    0x00000000</Specification>\r
+  </MsaLibHeader>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">PerformanceLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">DebugLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">TimerLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">PcdLib</LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>DxePerformanceLib.c</Filename>\r
+  </SourceFiles>\r
+  <Includes>\r
+    <PackageName>MdePkg</PackageName>\r
+    <PackageName>EdkModulePkg</PackageName>\r
+  </Includes>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">Performance</Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Extern>\r
+      <Constructor>PerformanceLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdPerformanceLibraryPropertyMask</C_Name>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</LibraryModuleSurfaceArea>\r
diff --git a/EdkModulePkg/Library/DxePerformanceLib/build.xml b/EdkModulePkg/Library/DxePerformanceLib/build.xml
new file mode 100644 (file)
index 0000000..a663483
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?><!-- 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
+<project basedir="." default="DxePerformanceLib"><!--Apply external ANT tasks-->\r
+   <taskdef resource="GenBuild.tasks"/>\r
+   <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+   <property environment="env"/>\r
+   <property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>\r
+   <import file="${WORKSPACE_DIR}/Tools/Conf/BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->\r
+   <property name="MODULE_RELATIVE_PATH" value="Library/DxePerformanceLib"/>\r
+   <property name="MODULE_DIR" value="${PACKAGE_DIR}/${MODULE_RELATIVE_PATH}"/>\r
+   <property name="COMMON_FILE" value="${WORKSPACE_DIR}/Tools/Conf/Common.xml"/>\r
+   <target name="DxePerformanceLib">\r
+      <GenBuild baseName="DxePerformanceLib" mbdFilename="${MODULE_DIR}/DxePerformanceLib.mbd" msaFilename="${MODULE_DIR}/DxePerformanceLib.msa"/>\r
+   </target>\r
+   <target depends="DxePerformanceLib_clean" name="clean"/>\r
+   <target depends="DxePerformanceLib_cleanall" name="cleanall"/>\r
+   <target name="DxePerformanceLib_clean">\r
+      <OutputDirSetup baseName="DxePerformanceLib" mbdFilename="${MODULE_DIR}/DxePerformanceLib.mbd" msaFilename="${MODULE_DIR}/DxePerformanceLib.msa"/>\r
+      <if>\r
+         <available file="${DEST_DIR_OUTPUT}/DxePerformanceLib_build.xml"/>\r
+         <then>\r
+            <ant antfile="${DEST_DIR_OUTPUT}/DxePerformanceLib_build.xml" target="clean"/>\r
+         </then>\r
+      </if>\r
+      <delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>\r
+   </target>\r
+   <target name="DxePerformanceLib_cleanall">\r
+      <OutputDirSetup baseName="DxePerformanceLib" mbdFilename="${MODULE_DIR}/DxePerformanceLib.mbd" msaFilename="${MODULE_DIR}/DxePerformanceLib.msa"/>\r
+      <if>\r
+         <available file="${DEST_DIR_OUTPUT}/DxePerformanceLib_build.xml"/>\r
+         <then>\r
+            <ant antfile="${DEST_DIR_OUTPUT}/DxePerformanceLib_build.xml" target="cleanall"/>\r
+         </then>\r
+      </if>\r
+      <delete dir="${DEST_DIR_OUTPUT}"/>\r
+      <delete dir="${DEST_DIR_DEBUG}"/>\r
+      <delete>\r
+         <fileset dir="${BIN_DIR}" includes="**DxePerformanceLib*"/>\r
+      </delete>\r
+   </target>\r
+</project>
\ No newline at end of file
diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
new file mode 100644 (file)
index 0000000..b97849f
--- /dev/null
@@ -0,0 +1,330 @@
+/*++\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
+  PeiPerformanceLib.c\r
+\r
+Abstract:\r
+\r
+  Performance Library\r
+\r
+--*/\r
+\r
+/**\r
+  Gets PEI the GUID HOB for PEI performance.\r
+\r
+  This internal function searches for the GUID HOB for PEI performance.\r
+  If that GUID HOB is not found, it will build a new one.\r
+  It returns the data area of that GUID HOB to record performance log.    \r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+\r
+  @retval The index of log entry in the array.\r
+\r
+**/\r
+PEI_PERFORMANCE_LOG_HEADER *\r
+InternalGetPerformanceHobLog (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE           *GuidHob;\r
+  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
+  UINTN                       PeiPerformanceLogSize;\r
+\r
+  GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid);\r
+  \r
+  if (GuidHob != NULL) {\r
+    //\r
+    // PEI Performance HOB was found, then return the existing one.\r
+    //\r
+    PeiPerformanceLog = GET_GUID_HOB_DATA (GuidHob);\r
+  } else {\r
+    //\r
+    // PEI Performance HOB was not found, then build one.\r
+    //\r
+    PeiPerformanceLogSize = sizeof (PEI_PERFORMANCE_LOG_HEADER) + \r
+                            sizeof (PEI_PERFORMANCE_LOG_ENTRY) * MAX_PEI_PERFORMANCE_LOG_ENTRIES;\r
+    PeiPerformanceLog     = BuildGuidHob (&gPeiPerformanceHobGuid, PeiPerformanceLogSize);\r
+    PeiPerformanceLog     = ZeroMem (PeiPerformanceLog, PeiPerformanceLogSize);\r
+  }\r
+\r
+  return PeiPerformanceLog;\r
+}\r
+\r
+/**\r
+  Searches in the log array with keyword Handle, Token and Module.\r
+\r
+  This internal function searches for the log entry in the log array.\r
+  If there is an entry that exactly matches the given key word triple\r
+  and its end time stamp is zero, then the index of that log entry is returned;\r
+  otherwise, the the number of log entries in the array is returned.  \r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+\r
+  @retval The index of log entry in the array.\r
+\r
+**/\r
+UINT32\r
+InternalSearchForLogEntry (\r
+  IN PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog,\r
+  IN CONST VOID                 *Handle,  OPTIONAL\r
+  IN CONST CHAR8                *Token,   OPTIONAL\r
+  IN CONST CHAR8                *Module   OPTIONAL\r
+  )\r
+{\r
+  UINT32                    Index;\r
+  UINT32                    NumberOfEntries;\r
+  PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
+  \r
+\r
+  if (Token == NULL) {\r
+    Token = "";\r
+  }\r
+  if (Module == NULL) {\r
+    Module = "";\r
+  }\r
+  NumberOfEntries = PeiPerformanceLog->NumberOfEntries;\r
+  LogEntryArray   = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
+  \r
+  for (Index = 0; Index < NumberOfEntries; Index++) {\r
+    if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
+         AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+         AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+         LogEntryArray[Index].EndTimeStamp == 0\r
+       ) {\r
+      break;\r
+    }\r
+  }\r
+  return Index;\r
+} \r
+\r
+/**\r
+  Creates a record for the beginning of a performance measurement. \r
+  \r
+  Creates a record that contains the Handle, Token, and Module.\r
+  If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
+  If TimeStamp is zero, then this function reads the current time stamp\r
+  and adds that time stamp value to the record as the start time.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
+  @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StartPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
+  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
+  UINT32                      Index;\r
+\r
+  PeiPerformanceLog = InternalGetPerformanceHobLog ();\r
+  \r
+  if (PeiPerformanceLog->NumberOfEntries >= MAX_PEI_PERFORMANCE_LOG_ENTRIES) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+  Index                       = PeiPerformanceLog->NumberOfEntries++;\r
+  LogEntryArray               = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);        \r
+  LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+\r
+  if (Token != NULL) {\r
+    AsciiStrnCpy (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH);\r
+  }\r
+  if (Module != NULL) {\r
+    AsciiStrnCpy (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH);\r
+  }\r
+\r
+  if (TimeStamp == 0) {\r
+    TimeStamp = GetPerformanceCounter ();\r
+  }\r
+  LogEntryArray[Index].StartTimeStamp = TimeStamp;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Fills in the end time of a performance measurement. \r
+  \r
+  Looks up the record that matches Handle, Token, and Module.\r
+  If the record can not be found then return RETURN_NOT_FOUND.\r
+  If the record is found and TimeStamp is not zero,\r
+  then TimeStamp is added to the record as the end time.\r
+  If the record is found and TimeStamp is zero, then this function reads\r
+  the current time stamp and adds that time stamp value to the record as the end time.\r
+  If this function is called multiple times for the same record, then the end time is overwritten.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
+  @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+EndPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
+  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
+  UINT32                      Index;\r
+\r
+  if (TimeStamp == 0) {\r
+    TimeStamp = GetPerformanceCounter ();\r
+  }\r
+  \r
+  PeiPerformanceLog = InternalGetPerformanceHobLog ();\r
+  Index             = InternalSearchForLogEntry (PeiPerformanceLog, Handle, Token, Module);\r
+  if (Index >= PeiPerformanceLog->NumberOfEntries) {\r
+    return RETURN_NOT_FOUND;\r
+  }\r
+  LogEntryArray     = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
+  LogEntryArray[Index].EndTimeStamp = TimeStamp;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log. \r
+  \r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetPerformanceMeasurement (\r
+  IN  UINTN       LogEntryKey, \r
+  OUT CONST VOID  **Handle,\r
+  OUT CONST CHAR8 **Token,\r
+  OUT CONST CHAR8 **Module,\r
+  OUT UINT64      *StartTimeStamp,\r
+  OUT UINT64      *EndTimeStamp\r
+  )\r
+{\r
+  PEI_PERFORMANCE_LOG_HEADER  *PeiPerformanceLog;\r
+  PEI_PERFORMANCE_LOG_ENTRY   *CurrentLogEntry;\r
+  PEI_PERFORMANCE_LOG_ENTRY   *LogEntryArray;\r
+  UINTN                       NumberOfEntries;\r
+\r
+  ASSERT (Handle != NULL);\r
+  ASSERT (Token != NULL);\r
+  ASSERT (Module != NULL);\r
+  ASSERT (StartTimeStamp != NULL);\r
+  ASSERT (EndTimeStamp != NULL);\r
+  \r
+  PeiPerformanceLog = InternalGetPerformanceHobLog ();\r
\r
+  NumberOfEntries   = (UINTN) (PeiPerformanceLog->NumberOfEntries);\r
+  LogEntryArray     = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
+  //\r
+  // Make sure that LogEntryKey is a valid log entry key.\r
+  //\r
+  ASSERT (LogEntryKey <= NumberOfEntries);\r
+  \r
+  if (LogEntryKey == NumberOfEntries) {\r
+    return 0;\r
+  }\r
+\r
+  CurrentLogEntry = &(LogEntryArray[LogEntryKey++]);\r
+\r
+  *Handle         = (VOID *) (UINTN) (CurrentLogEntry->Handle);\r
+  *Token          = CurrentLogEntry->Token;\r
+  *Module         = CurrentLogEntry->Module;\r
+  *StartTimeStamp = CurrentLogEntry->StartTimeStamp;\r
+  *EndTimeStamp   = CurrentLogEntry->EndTimeStamp;\r
+\r
+  return LogEntryKey;  \r
+}\r
+\r
+/**\r
+  Returns TRUE if the performance measurement macros are enabled. \r
+  \r
+  This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+  PcdPerformanceLibraryPropertyMask is set.  Otherwise FALSE is returned.\r
+\r
+  @retval TRUE                    The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+                                  PcdPerformanceLibraryPropertyMask is set.\r
+  @retval FALSE                   The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
+                                  PcdPerformanceLibraryPropertyMask is clear.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PerformanceMeasurementEnabled (\r
+  VOID\r
+  )\r
+{\r
+  return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
+}\r
diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd
new file mode 100644 (file)
index 0000000..8dba9c2
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>\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
+<LibraryModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">\r
+  <MbdLibHeader>\r
+    <BaseName>PeiPerformanceLib</BaseName>\r
+    <Guid>F72DE735-B24F-4ef6-897F-70A85D01A047</Guid>\r
+    <Version>EDK_RELEASE_VERSION        0x00020000</Version>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>\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
+    </License>\r
+    <Created>2006-04-04 11:12</Created>\r
+  </MbdLibHeader>\r
+</LibraryModuleBuildDescription>\r
diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa
new file mode 100644 (file)
index 0000000..a80adce
--- /dev/null
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>\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
+<LibraryModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">\r
+  <MsaLibHeader>\r
+    <BaseName>PeiPerformanceLib</BaseName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <ComponentType>LIBRARY</ComponentType>\r
+    <Guid>F72DE735-B24F-4ef6-897F-70A85D01A047</Guid>\r
+    <Version>EDK_RELEASE_VERSION        0x00020000</Version>\r
+    <Abstract>Memory-only library functions with no library constructor/destructor</Abstract>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>\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
+    </License>\r
+    <Created>2006-04-04 11:12</Created>\r
+    <Specification>EFI_SPECIFICATION_VERSION    0x00000000</Specification>\r
+  </MsaLibHeader>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">PerformanceLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">DebugLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">HobLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">BaseLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">TimerLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">PcdLib</LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeiPerformanceLib.c</Filename>\r
+  </SourceFiles>\r
+  <Includes>\r
+    <PackageName>MdePkg</PackageName>\r
+    <PackageName>EdkModulePkg</PackageName>\r
+  </Includes>\r
+  <Guids>\r
+    <GuidEntry Usage="SOMETIMES_CONSUMED">\r
+      <C_Name>PeiPerformanceHob</C_Name>\r
+    </GuidEntry>\r
+  </Guids>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="FIXED_AT_BUILD">\r
+      <C_Name>PcdPerformanceLibraryPropertyMask</C_Name>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</LibraryModuleSurfaceArea>\r
diff --git a/EdkModulePkg/Library/PeiPerformanceLib/build.xml b/EdkModulePkg/Library/PeiPerformanceLib/build.xml
new file mode 100644 (file)
index 0000000..e0bd259
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?><!-- 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
+<project basedir="." default="PeiPerformanceLib"><!--Apply external ANT tasks-->\r
+   <taskdef resource="GenBuild.tasks"/>\r
+   <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+   <property environment="env"/>\r
+   <property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>\r
+   <import file="${WORKSPACE_DIR}/Tools/Conf/BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->\r
+   <property name="MODULE_RELATIVE_PATH" value="Library/PeiPerformanceLib"/>\r
+   <property name="MODULE_DIR" value="${PACKAGE_DIR}/${MODULE_RELATIVE_PATH}"/>\r
+   <property name="COMMON_FILE" value="${WORKSPACE_DIR}/Tools/Conf/Common.xml"/>\r
+   <target name="PeiPerformanceLib">\r
+      <GenBuild baseName="PeiPerformanceLib" mbdFilename="${MODULE_DIR}/PeiPerformanceLib.mbd" msaFilename="${MODULE_DIR}/PeiPerformanceLib.msa"/>\r
+   </target>\r
+   <target depends="PeiPerformanceLib_clean" name="clean"/>\r
+   <target depends="PeiPerformanceLib_cleanall" name="cleanall"/>\r
+   <target name="PeiPerformanceLib_clean">\r
+      <OutputDirSetup baseName="PeiPerformanceLib" mbdFilename="${MODULE_DIR}/PeiPerformanceLib.mbd" msaFilename="${MODULE_DIR}/PeiPerformanceLib.msa"/>\r
+      <if>\r
+         <available file="${DEST_DIR_OUTPUT}/PeiPerformanceLib_build.xml"/>\r
+         <then>\r
+            <ant antfile="${DEST_DIR_OUTPUT}/PeiPerformanceLib_build.xml" target="clean"/>\r
+         </then>\r
+      </if>\r
+      <delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>\r
+   </target>\r
+   <target name="PeiPerformanceLib_cleanall">\r
+      <OutputDirSetup baseName="PeiPerformanceLib" mbdFilename="${MODULE_DIR}/PeiPerformanceLib.mbd" msaFilename="${MODULE_DIR}/PeiPerformanceLib.msa"/>\r
+      <if>\r
+         <available file="${DEST_DIR_OUTPUT}/PeiPerformanceLib_build.xml"/>\r
+         <then>\r
+            <ant antfile="${DEST_DIR_OUTPUT}/PeiPerformanceLib_build.xml" target="cleanall"/>\r
+         </then>\r
+      </if>\r
+      <delete dir="${DEST_DIR_OUTPUT}"/>\r
+      <delete dir="${DEST_DIR_DEBUG}"/>\r
+      <delete>\r
+         <fileset dir="${BIN_DIR}" includes="**PeiPerformanceLib*"/>\r
+      </delete>\r
+   </target>\r
+</project>
\ No newline at end of file
index 7d782955c82ca14c729cb45e8a95923eaaf8adcf..32768c05c68e896659c5bf77cbecf7afbdde5c54 100644 (file)
@@ -463,12 +463,7 @@ Returns:
       }\r
     }\r
 \r
-    switch (StatCode) {\r
-    case EFI_SUCCESS:\r
-    case EFI_TIMEOUT:\r
-      break;\r
-\r
-    default:\r
+    if ((StatCode != EFI_SUCCESS) && (StatCode != EFI_TIMEOUT)) {\r
       DEBUG (\r
         (EFI_D_INFO,\r
         "\nUdpRead()  Exit #3  %Xh %r",\r
index 315c95a9f588269c640dd1aa358317a8cecb65ae..182462c02f1c5a33fdf7714f49708b59cd0d784d 100644 (file)
@@ -1456,15 +1456,12 @@ Returns:
                   (VOID *) &LoadfilePtr->Private->CallbackProtocolPtr\r
                   );\r
 \r
-  switch (Status) {\r
-  case EFI_SUCCESS:\r
+  if (Status == EFI_SUCCESS) {\r
     //\r
     // There is already a callback routine.  Do nothing.\r
     //\r
     DEBUG ((EFI_D_WARN, "\nLoadFile()  BC callback exists."));\r
-    break;\r
-\r
-  case EFI_UNSUPPORTED:\r
+  } else if (Status == EFI_UNSUPPORTED) {\r
     //\r
     // No BaseCode Callback protocol found.  Add our own.\r
     //\r
@@ -1490,10 +1487,7 @@ Returns:
                                     &NewMakeCallback\r
                                     );\r
     }\r
-\r
-    break;\r
-\r
-  default:\r
+  } else {\r
     DEBUG ((EFI_D_WARN, "\nLoadFile()  Callback check status == %xh", Status));\r
   }\r
   //\r
@@ -1578,11 +1572,11 @@ Returns:
 \r
   DEBUG ((EFI_D_WARN, "\nBC.Loadfile()  Status == %xh\n", Status));\r
 \r
-  switch (Status) {\r
-  case EFI_SUCCESS:           /* 0 */\r
+  if (Status == EFI_SUCCESS) {\r
+    /* 0 */\r
     return EFI_SUCCESS;\r
-\r
-  case EFI_BUFFER_TOO_SMALL:  /* 5 */\r
+  } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    /* 5 */\r
     //\r
     // Error is only displayed when we are actually trying to\r
     // download the boot image.\r
@@ -1590,104 +1584,81 @@ Returns:
     if (Buffer == NULL) {\r
       return EFI_BUFFER_TOO_SMALL;\r
     }\r
-\r
     AsciiPrint ("\nPXE-E05: Download buffer is smaller than requested file.\n");\r
-    break;\r
-\r
-  case EFI_DEVICE_ERROR:      /* 7 */\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
+    /* 7 */\r
     AsciiPrint ("\nPXE-E07: Network device error.  Check network connection.\n");\r
-    break;\r
-\r
-  case EFI_OUT_OF_RESOURCES:  /* 9 */\r
+  } else if (Status == EFI_OUT_OF_RESOURCES) {\r
+    /* 9 */\r
     AsciiPrint ("\nPXE-E09: Could not allocate I/O buffers.\n");\r
-    break;\r
-\r
-  case EFI_NO_MEDIA:          /* 12 */\r
+  } else if (Status == EFI_NO_MEDIA) {\r
+    /* 12 */\r
     AsciiPrint ("\nPXE-E12: Could not detect network connection.  Check cable.\n");\r
-    break;\r
-\r
-  case EFI_NO_RESPONSE:       /* 16 */\r
+  } else if (Status == EFI_NO_RESPONSE) {\r
+    /* 16 */\r
     AsciiPrint ("\nPXE-E16: Valid PXE offer not received.\n");\r
-    break;\r
-\r
-  case EFI_TIMEOUT:           /* 18 */\r
+  } else if (Status == EFI_TIMEOUT) {\r
+    /* 18 */\r
     AsciiPrint ("\nPXE-E18: Timeout.  Server did not respond.\n");\r
-    break;\r
-\r
-  case EFI_ABORTED:           /* 21 */\r
+  } else if (Status == EFI_ABORTED) {\r
+    /* 21 */\r
     AsciiPrint ("\nPXE-E21: Remote boot cancelled.\n");\r
-    break;\r
-\r
-  case EFI_ICMP_ERROR:        /* 22 */\r
+  } else if (Status == EFI_ICMP_ERROR) {\r
+    /* 22 */\r
     AsciiPrint ("\nPXE-E22: Client received ICMP error from server.\n");\r
 \r
-    if (LoadfilePtr->Private->EfiBc.Mode == NULL) {\r
-      break;\r
-    }\r
-\r
-    if (!LoadfilePtr->Private->EfiBc.Mode->IcmpErrorReceived) {\r
-      break;\r
-    }\r
+    if ((LoadfilePtr->Private->EfiBc.Mode != NULL) && LoadfilePtr->Private->EfiBc.Mode->IcmpErrorReceived) {\r
+      AsciiPrint (\r
+        "PXE-E98: Type: %xh  Code: %xh  ",\r
+        LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type,\r
+        LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code\r
+        );\r
 \r
-    AsciiPrint (\r
-      "PXE-E98: Type: %xh  Code: %xh  ",\r
-      LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type,\r
-      LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code\r
-      );\r
+      switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type) {\r
+      case 0x03:\r
+        switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code) {\r
+        case 0x00:              /* net unreachable */\r
+          AsciiPrint ("Net unreachable");\r
+          break;\r
 \r
-    switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type) {\r
-    case 0x03:\r
-      switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code) {\r
-      case 0x00:              /* net unreachable */\r
-        AsciiPrint ("Net unreachable");\r
-        break;\r
+        case 0x01:              /* host unreachable */\r
+          AsciiPrint ("Host unreachable");\r
+          break;\r
 \r
-      case 0x01:              /* host unreachable */\r
-        AsciiPrint ("Host unreachable");\r
-        break;\r
+        case 0x02:              /* protocol unreachable */\r
+          AsciiPrint ("Protocol unreachable");\r
+          break;\r
 \r
-      case 0x02:              /* protocol unreachable */\r
-        AsciiPrint ("Protocol unreachable");\r
-        break;\r
+        case 0x03:              /* port unreachable */\r
+          AsciiPrint ("Port unreachable");\r
+          break;\r
 \r
-      case 0x03:              /* port unreachable */\r
-        AsciiPrint ("Port unreachable");\r
-        break;\r
+        case 0x04:              /* Fragmentation needed */\r
+          AsciiPrint ("Fragmentation needed");\r
+          break;\r
 \r
-      case 0x04:              /* Fragmentation needed */\r
-        AsciiPrint ("Fragmentation needed");\r
-        break;\r
+        case 0x05:              /* Source route failed */\r
+          AsciiPrint ("Source route failed");\r
+          break;\r
+        }\r
 \r
-      case 0x05:              /* Source route failed */\r
-        AsciiPrint ("Source route failed");\r
         break;\r
       }\r
 \r
-      break;\r
+      AsciiPrint ("\n");\r
     }\r
-\r
-    AsciiPrint ("\n");\r
-\r
-    break;\r
-\r
-  case EFI_TFTP_ERROR:        /* 23 */\r
+  } else if (Status == EFI_TFTP_ERROR) {\r
+    /* 23 */\r
     AsciiPrint ("\nPXE-E23: Client received TFTP error from server.\n");\r
 \r
-    if (LoadfilePtr->Private->EfiBc.Mode == NULL) {\r
-      break;\r
-    }\r
-\r
-    if (LoadfilePtr->Private->EfiBc.Mode->TftpErrorReceived) {\r
+    if ((LoadfilePtr->Private->EfiBc.Mode != NULL) && (LoadfilePtr->Private->EfiBc.Mode->TftpErrorReceived)) {\r
       AsciiPrint (\r
         "PXE-E98: Code: %xh  %a\n",\r
         LoadfilePtr->Private->EfiBc.Mode->TftpError.ErrorCode,\r
         LoadfilePtr->Private->EfiBc.Mode->TftpError.ErrorString\r
         );\r
     }\r
-\r
-    break;\r
-\r
-  default:\r
+  } else {\r
     AsciiPrint ("\nPXE-E99: Unexpected network error: %xh\n", Status);\r
   }\r
 \r
index 50f97a8915022b1686ed91e59e06d07da9a9a381..8e015b2a3d987be8b0f86c4eb72211f389630513 100644 (file)
@@ -126,14 +126,9 @@ PxeDhcp4Run (
     //\r
     efi_status = PxeDhcp4Init (This, timeout, &offers, &offer_list);\r
 \r
-    switch (efi_status) {\r
-    case EFI_NO_RESPONSE:\r
-    case EFI_TIMEOUT:\r
-    case EFI_SUCCESS:\r
-      break;\r
-\r
-    case EFI_ABORTED:\r
-    default:\r
+    if ((efi_status != EFI_NO_RESPONSE) &&\r
+        (efi_status != EFI_TIMEOUT) &&\r
+        (efi_status != EFI_SUCCESS)) {\r
       return efi_status;\r
     }\r
     //\r
index cef769241b1fbe9cb92c8e3e6a16c4914b5242b5..5a6e7dc9bbdb58ce5bab9ceafd67bb09b9f43be5 100644 (file)
@@ -54,15 +54,13 @@ typedef unsigned long         UINTN;
 //\r
 // Scalable macro to set the most significant bit in a natural number\r
 //\r
-#define MAX_BIT     0x8000000000000000ULL \r
-#define MAX_2_BITS  0xC000000000000000ULL\r
-\r
+#define MAX_BIT     (1ULL << (sizeof (INTN) * 8 - 1)) \r
+#define MAX_2_BITS  (3ULL << (sizeof (INTN) * 8 - 2))\r
 \r
 //\r
 // Maximum legal EBC address\r
 //\r
-#define MAX_ADDRESS   0xFFFFFFFFFFFFFFFFULL\r
-\r
+#define MAX_ADDRESS   ((UINTN) ~0)\r
 //\r
 // Modifier to ensure that all protocol member functions and EFI intrinsics\r
 // use the correct C calling convention. All protocol member functions and\r
index 08e8195a8a2c8991ecd3f2f279d61b0750a5df67..0a68ae640f146811d35bc6346730ee4d23214beb 100644 (file)
@@ -75,15 +75,22 @@ typedef struct {
 \r
 \r
 /**\r
-       Retrieves information on a PE/COFF image\r
+  Retrieves information about a PE/COFF image.\r
 \r
-       @param  ImageContext The context of the image being loaded\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
 \r
-       @retval EFI_SUCCESS The information on the PE/COFF image was collected.\r
-       @retval EFI_INVALID_PARAMETER ImageContext is NULL.\r
-       @retval EFI_UNSUPPORTED The PE/COFF image is not supported.\r
-       @retval Otherwise The error status from reading the PE/COFF image using the\r
-       ImageContext->ImageRead() function\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -94,13 +101,23 @@ PeCoffLoaderGetImageInfo (
 ;\r
 \r
 /**\r
-       Relocates a PE/COFF image in memory\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
 \r
-       @param  ImageContext Contains information on the loaded image to relocate\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
 \r
-       @retval EFI_SUCCESS      if the PE/COFF image was relocated\r
-       @retval EFI_LOAD_ERROR   if the image is not a valid PE/COFF image\r
-       @retval EFI_UNSUPPORTED  not support\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -111,14 +128,26 @@ PeCoffLoaderRelocateImage (
 ;\r
 \r
 /**\r
-       Loads a PE/COFF image into memory\r
-\r
-       @param  ImageContext Contains information on image to load into memory\r
-\r
-       @retval EFI_SUCCESS            if the PE/COFF image was loaded\r
-       @retval EFI_BUFFER_TOO_SMALL   if the caller did not provide a large enough buffer\r
-       @retval EFI_LOAD_ERROR         if the image is a runtime driver with no relocations\r
-       @retval EFI_INVALID_PARAMETER  if the image address is invalid\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
 \r
 **/\r
 RETURN_STATUS\r
index 36564095e9ec5cd9ec7e78cd11d43cde6e528c2b..ca32d98b1d5fb819e437b70ce8b0319bb1d241f5 100644 (file)
@@ -84,31 +84,46 @@ EndPerformanceMeasurement (
   );\r
 \r
 /**\r
-  Retrieves a previously logged performance measurement\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log\r
   \r
-  Looks up the record that matches Handle, Token, and Module.\r
-  If the record can not be found then return RETURN_NOT_FOUND.\r
-  If the record is found then the start of the measurement is returned in StartTimeStamp,\r
-  and the end of the measurement is returned in EndTimeStamp.\r
-\r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  StartTimeStamp          The 64-bit time stamp that was recorded when the measurement was started.\r
-  @param  EndTimeStamp            The 64-bit time stamp that was recorded when the measurement was ended.\r
-\r
-  @return The key for the current performance log entry.\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  UINTN           LogEntryKey, \r
+  IN  UINTN       LogEntryKey, \r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r
index 484ab90144caf9f3378c55cb56895af0a3140b9f..6d214aaa8e6bf51f51af49e43519475d22b6b4cc 100644 (file)
@@ -18,9 +18,9 @@
 #define __SMBUS_LIB__\r
 \r
 //\r
-// PEC BIT is bit 21 in SMBUS address\r
+// PEC BIT is bit 22 in SMBUS address\r
 //\r
-#define SMBUS_LIB_PEC_BIT   (1 << 21)\r
+#define SMBUS_LIB_PEC_BIT   (1 << 22)\r
 \r
 /**\r
   Macro that converts SMBUS slave address, SMBUS command, SMBUS data length,\r
@@ -32,7 +32,7 @@
   \r
   @param  SlaveAddress    SMBUS Slave Address.  Range 0..127.\r
   @param  Command         SMBUS Command.  Range 0..255.\r
-  @param  Length          SMBUS Data Length.  Range 0..31.\r
+  @param  Length          SMBUS Data Length.  Range 0..32.\r
   @param  Pec             TRUE if Packet Error Checking is enabled.  Otherwise FALSE.\r
 \r
 **/\r
@@ -40,7 +40,7 @@
   ( ((Pec) ? SMBUS_LIB_PEC_BIT: 0)      | \\r
     (((SlaveAddress) & 0x7f) << 1)      | \\r
     (((Command)      & 0xff) << 8)      | \\r
-    (((Length)       & 0x1f) << 16)       \\r
+    (((Length)       & 0x3f) << 16)       \\r
   )\r
 \r
 /**\r
@@ -296,7 +296,7 @@ SmBusProcessCall (
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
   If Length in SmBusAddress is not zero, then ASSERT().\r
   If Buffer is NULL, then ASSERT().\r
@@ -355,19 +355,19 @@ SmBusWriteBlock (
 \r
   Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
   The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
-  Bytes are written to the SMBUS from OutBuffer.  Bytes are then read from the SMBUS into InBuffer.\r
+  Bytes are written to the SMBUS from WriteBuffer.  Bytes are then read from the SMBUS into ReadBuffer.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
-  If OutBuffer is NULL, then ASSERT().\r
-  If InBuffer is NULL, then ASSERT().\r
+  If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
+  If WriteBuffer is NULL, then ASSERT().\r
+  If ReadBuffer is NULL, then ASSERT().\r
   If any reserved bits of SmBusAddress are set, then ASSERT().\r
 \r
-\r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -378,10 +378,11 @@ UINTN
 EFIAPI\r
 SmBusBlockProcessCall (\r
   IN  UINTN          SmBusAddress,\r
-  IN  VOID           *OutBuffer,\r
-  OUT VOID           *InBuffer,\r
+  IN  VOID           *WriteBuffer,\r
+  OUT VOID           *ReadBuffer,\r
   OUT RETURN_STATUS  *Status        OPTIONAL\r
   )\r
 ;\r
 \r
+\r
 #endif\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index bda1f4992f7945ffa063a3578651339e25a22711..53c4e4416b7ad289c6c71d8a02f144f81093792c 100644 (file)
@@ -132,7 +132,6 @@ InternalMemCompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (Length > 0);\r
   while ((--Length != 0) &&\r
          (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
     DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r
index e91e9a6c2ff089071887069ae0999c9dd60e8978..32a70c00c46d1fec385a294b01bbf4a96d406309 100644 (file)
 \r
 **/\r
 \r
+/**\r
+  Performs an Itanium-based specific relocation fixup.\r
 \r
+  @param  Reloc       Pointer to the relocation record.\r
+  @param  Fixup       Pointer to the address to fix up.\r
+  @param  FixupData   Pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
 \r
+  @return Status code.\r
 \r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderGetPeHeader (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  OUT    EFI_IMAGE_NT_HEADERS          *PeHdr,\r
-  OUT    EFI_TE_IMAGE_HEADER           *TeHdr\r
-  );\r
-\r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderCheckImageType (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  IN     EFI_IMAGE_NT_HEADERS          *PeHdr,\r
-  IN     EFI_TE_IMAGE_HEADER           *TeHdr\r
-  );\r
-\r
-STATIC\r
-VOID *\r
-PeCoffLoaderImageAddress (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  IN     UINTN                         Address\r
-  );\r
-\r
+**/\r
 RETURN_STATUS\r
 PeCoffLoaderRelocateImageEx (\r
   IN UINT16      *Reloc,\r
@@ -193,11 +178,9 @@ PeCoffLoaderCheckImageType (
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that needs to be examined by this function.\r
 \r
-  @retval  RETURN_SUCCESS           The information on the PE/COFF image was collected.\r
-  @retval  RETURN_INVALID_PARAMETER ImageContext is NULL.\r
-  @retval  RETURN_UNSUPPORTED       The PE/COFF image is not supported.\r
-  @retval  Others                   The error status from reading the PE/COFF image\r
-                                    using the ImageContext->ImageRead() function.\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
 \r
 **/\r
 RETURN_STATUS\r
@@ -687,6 +670,7 @@ PeCoffLoaderRelocateImage (
   specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
   the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
   The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
 \r
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that is being loaded.\r
@@ -724,8 +708,11 @@ PeCoffLoaderLoadImage (
   UINTN                                 Size;\r
   UINT32                                TempDebugEntryRva;\r
 \r
+  ASSERT (ImageContext != NULL);\r
+\r
   PeHdr = NULL;\r
   TeHdr = NULL;\r
+\r
   //\r
   // Assume success\r
   //\r
@@ -750,7 +737,13 @@ PeCoffLoaderLoadImage (
     ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_SIZE;\r
     return RETURN_BUFFER_TOO_SMALL;\r
   }\r
-\r
+  if (ImageContext->ImageAddress == 0) {\r
+    //\r
+    // Image cannot be loaded into 0 address.\r
+    //\r
+    ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS;\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
   //\r
   // If there's no relocations, then make sure it's not a runtime driver,\r
   // and that it's being loaded at the linked address.\r
index 6cfc566bd42519f9bb67f6891cabc626823a77d8..fe41ac03bd5d25bc1c27264c4758e0fe0664c9a1 100644 (file)
 \r
 \r
 /**\r
-  Performs an IA-32 specific relocation fixup.\r
+  Performs an EBC specific relocation fixup.\r
 \r
-  @param  Reloc Pointer to the relocation record.\r
+  @param  Reloc       Pointer to the relocation record.\r
+  @param  Fixup       Pointer to the address to fix up.\r
+  @param  FixupData   Pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
 \r
-  @param  Fixup Pointer to the address to fix up.\r
-\r
-  @param  FixupData Pointer to a buffer to log the fixups.\r
-\r
-  @param  Adjust The offset to adjust the fixup.\r
-\r
-  @retval  EFI_UNSUPPORTED Unsupported now.\r
+  @retval EFI_UNSUPPORTED Unsupported now.\r
 \r
 **/\r
 RETURN_STATUS\r
index 4ee64c2b367f92c6e3edc528d17edef568034963..9a2b2a04dd9067c67841ab811f6441ddf9fbb9d7 100644 (file)
 /**\r
   Performs an IA-32 specific relocation fixup.\r
 \r
-  @param  Reloc Pointer to the relocation record.\r
+  @param  Reloc       Pointer to the relocation record.\r
+  @param  Fixup       Pointer to the address to fix up.\r
+  @param  FixupData   Pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
 \r
-  @param  Fixup Pointer to the address to fix up.\r
-\r
-  @param  FixupData Pointer to a buffer to log the fixups.\r
-\r
-  @param  Adjust The offset to adjust the fixup.\r
-\r
-  @retval  EFI_UNSUPPORTED Unsupported now.\r
+  @retval EFI_UNSUPPORTED Unsupported now.\r
 \r
 **/\r
 RETURN_STATUS\r
index d35231e9cd81ce8ad733ec31655af446cc25469f..57c6555408d2d087ea411369707b0c3c948c0b57 100644 (file)
 /**\r
   Performs an Itanium-based specific relocation fixup.\r
 \r
-  @param  Reloc Pointer to the relocation record.\r
-  \r
-  @param  Fixup Pointer to the address to fix up.\r
-  \r
-  @param  FixupData Pointer to a buffer to log the fixups.\r
-  \r
-  @param  Adjust The offset to adjust the fixup.\r
+  @param  Reloc       Pointer to the relocation record.\r
+  @param  Fixup       Pointer to the address to fix up.\r
+  @param  FixupData   Pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
 \r
   @return Status code.\r
 \r
index 7648447f7190fb4d9a69de2a35ef8ac34400b5ec..db7eead97d0c47ebdfbe06038504c5fbc469dc01 100644 (file)
 \r
 **/\r
 \r
-\r
-\r
-\r
 /**\r
   Performs an x64 specific relocation fixup.\r
 \r
-  @param  Reloc Pointer to the relocation record\r
-  @param  Fixup Pointer to the address to fix up\r
-  @param  FixupData Pointer to a buffer to log the fixups\r
-  @param  Adjust The offset to adjust the fixup\r
+  @param  Reloc       Pointer to the relocation record\r
+  @param  Fixup       Pointer to the address to fix up\r
+  @param  FixupData   Pointer to a buffer to log the fixups\r
+  @param  Adjust      The offset to adjust the fixup\r
 \r
 **/\r
 RETURN_STATUS\r
index 01226cbb02abadbf94783910bf555f4c23de4f50..ec88d848ae3c0dbd827375c295b444be1010a593 100644 (file)
@@ -82,34 +82,46 @@ EndPerformanceMeasurement (
 }\r
 \r
 /**\r
-  Retrieves a previously logged performance measurement\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log\r
   \r
-  Retrieves the performance log entry from the performance log\r
-  that immediately follows the log entry specified by LogEntryKey.\r
-  If LogEntryKey is zero, then the first entry from the performance log is returned.\r
-  If the log entry specified by LogEntryKey is the last entry in the performance log,\r
-  then 0 is returned.  Otherwise, the performance log entry is returned in Handle,\r
-  Token, Module, StartTimeStamp, and EndTimeStamp.\r
-  The key for the current performance log entry is returned. \r
-\r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  Handle                  Pointer to environment specific context used\r
-                                  to identify the component being measured.\r
-  @param  Token                   Pointer to a Null-terminated ASCII string\r
-                                  that identifies the component being measured.\r
-  @param  Module                  Pointer to a Null-terminated ASCII string\r
-                                  that identifies the module being measured.\r
-  @param  StartTimeStamp          The 64-bit time stamp that was recorded when the measurement was started.\r
-  @param  EndTimeStamp            The 64-bit time stamp that was recorded when the measurement was ended.\r
-\r
-  @return The key for the current performance log entry.\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance lof entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.  \r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured. \r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  UINTN           LogEntryKey, \r
+  IN  UINTN       LogEntryKey, \r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r
index e940bedb3497aec3b32b83c5fa29b49f7008609e..0a8c22ed16dc4679b96709eeb243711e9c12d1b7 100644 (file)
 \r
 #include "PrintLibInternal.h"\r
 \r
-typedef struct {\r
-  RETURN_STATUS  Status;\r
-  CHAR8          *String;\r
-} STATUS_LOOKUP_TABLE_ENTRY;\r
-\r
-static CONST STATUS_LOOKUP_TABLE_ENTRY  StatusString[] = {\r
-  { RETURN_SUCCESS,               "Success" },\r
-  { RETURN_LOAD_ERROR,            "Load Error" },\r
-  { RETURN_INVALID_PARAMETER,     "Invalid Parameter" },\r
-  { RETURN_UNSUPPORTED,           "Unsupported" },\r
-  { RETURN_BAD_BUFFER_SIZE,       "Bad Buffer Size" },\r
-  { RETURN_BUFFER_TOO_SMALL,      "Buffer Too Small" },\r
-  { RETURN_NOT_READY,             "Not Ready" },\r
-  { RETURN_DEVICE_ERROR,          "Device Error" },\r
-  { RETURN_WRITE_PROTECTED,       "Write Protected" },\r
-  { RETURN_OUT_OF_RESOURCES,      "Out of Resources" },\r
-  { RETURN_VOLUME_CORRUPTED,      "Volume Corrupt" },\r
-  { RETURN_VOLUME_FULL,           "Volume Full" },\r
-  { RETURN_NO_MEDIA,              "No Media" },\r
-  { RETURN_MEDIA_CHANGED,         "Media changed" },\r
-  { RETURN_NOT_FOUND,             "Not Found" },\r
-  { RETURN_ACCESS_DENIED,         "Access Denied" },\r
-  { RETURN_NO_RESPONSE,           "No Response" },\r
-  { RETURN_NO_MAPPING,            "No mapping" },\r
-  { RETURN_TIMEOUT,               "Time out" },\r
-  { RETURN_NOT_STARTED,           "Not started" },\r
-  { RETURN_ALREADY_STARTED,       "Already started" },\r
-  { RETURN_ABORTED,               "Aborted" },\r
-  { RETURN_ICMP_ERROR,            "ICMP Error" },\r
-  { RETURN_TFTP_ERROR,            "TFTP Error" },\r
-  { RETURN_PROTOCOL_ERROR,        "Protocol Error" },\r
-  { RETURN_WARN_UNKNOWN_GLYPH,    "Warning Unknown Glyph" },\r
-  { RETURN_WARN_DELETE_FAILURE,   "Warning Delete Failure" },\r
-  { RETURN_WARN_WRITE_FAILURE,    "Warning Write Failure" },\r
-  { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" },\r
-  { 0,                              NULL                     }\r
+#define WARNING_STATUS_NUMBER          4\r
+#define ERROR_STATUS_NUMBER            24\r
+\r
+STATIC CONST CHAR8 *StatusString [] = {\r
+  "Success",                      //  RETURN_SUCCESS                = 0\r
+  "Warning Unknown Glyph",        //  RETURN_WARN_UNKNOWN_GLYPH     = 1\r
+  "Warning Delete Failure",       //  RETURN_WARN_DELETE_FAILURE    = 2\r
+  "Warning Write Failure",        //  RETURN_WARN_WRITE_FAILURE     = 3\r
+  "Warning Buffer Too Small",     //  RETURN_WARN_BUFFER_TOO_SMALL  = 4\r
+  "Load Error",                   //  RETURN_LOAD_ERROR             = 1  | MAX_BIT\r
+  "Invalid Parameter",            //  RETURN_INVALID_PARAMETER      = 2  | MAX_BIT\r
+  "Unsupported",                  //  RETURN_UNSUPPORTED            = 3  | MAX_BIT\r
+  "Bad Buffer Size",              //  RETURN_BAD_BUFFER_SIZE        = 4  | MAX_BIT\r
+  "Buffer Too Small",             //  RETURN_BUFFER_TOO_SMALL,      = 5  | MAX_BIT\r
+  "Not Ready",                    //  RETURN_NOT_READY              = 6  | MAX_BIT\r
+  "Device Error",                 //  RETURN_DEVICE_ERROR           = 7  | MAX_BIT\r
+  "Write Protected",              //  RETURN_WRITE_PROTECTED        = 8  | MAX_BIT\r
+  "Out of Resources",             //  RETURN_OUT_OF_RESOURCES       = 9  | MAX_BIT\r
+  "Volume Corrupt",               //  RETURN_VOLUME_CORRUPTED       = 10 | MAX_BIT\r
+  "Volume Full",                  //  RETURN_VOLUME_FULL            = 11 | MAX_BIT\r
+  "No Media",                     //  RETURN_NO_MEDIA               = 12 | MAX_BIT\r
+  "Media changed",                //  RETURN_MEDIA_CHANGED          = 13 | MAX_BIT\r
+  "Not Found",                    //  RETURN_NOT_FOUND              = 14 | MAX_BIT\r
+  "Access Denied",                //  RETURN_ACCESS_DENIED          = 15 | MAX_BIT\r
+  "No Response",                  //  RETURN_NO_RESPONSE            = 16 | MAX_BIT\r
+  "No mapping",                   //  RETURN_NO_MAPPING             = 17 | MAX_BIT\r
+  "Time out",                     //  RETURN_TIMEOUT                = 18 | MAX_BIT\r
+  "Not started",                  //  RETURN_NOT_STARTED            = 19 | MAX_BIT\r
+  "Already started",              //  RETURN_ALREADY_STARTED        = 20 | MAX_BIT\r
+  "Aborted",                      //  RETURN_ABORTED                = 21 | MAX_BIT\r
+  "ICMP Error",                   //  RETURN_ICMP_ERROR             = 22 | MAX_BIT\r
+  "TFTP Error",                   //  RETURN_TFTP_ERROR             = 23 | MAX_BIT\r
+  "Protocol Error"                //  RETURN_PROTOCOL_ERROR         = 24 | MAX_BIT\r
 };\r
 \r
-\r
 /**\r
   Worker function that produces a Null-terminated string in an output buffer \r
   based on a Null-terminated format string and a VA_LIST argument list.\r
@@ -92,7 +88,7 @@ BasePrintLibVSPrint (
   UINTN           Width;\r
   UINTN           Precision;\r
   INT64           Value;\r
-  CHAR8           *ArgumentString;\r
+  CONST CHAR8     *ArgumentString;\r
   UINTN           Character;\r
   GUID            *TmpGuid;\r
   TIME            *TmpTime;\r
@@ -113,7 +109,6 @@ BasePrintLibVSPrint (
     return 0;\r
   }\r
   ASSERT (Buffer != NULL);\r
-  ASSERT (Format != NULL);\r
 \r
   OriginalBuffer = Buffer;\r
 \r
@@ -123,9 +118,19 @@ BasePrintLibVSPrint (
     BytesPerOutputCharacter = 1;\r
   }\r
   if ((Flags & FORMAT_UNICODE) != 0) {\r
+    //\r
+    // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
+    // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
+    //\r
+    ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
     BytesPerFormatCharacter = 2;\r
     FormatMask = 0xffff;\r
   } else {\r
+    //\r
+    // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
+    // Ascii characters if PcdMaximumUnicodeStringLength is not zero. \r
+    //\r
+    ASSERT (AsciiStrSize (Format) != 0);\r
     BytesPerFormatCharacter = 1;\r
     FormatMask = 0xff;\r
   }\r
@@ -381,9 +386,18 @@ BasePrintLibVSPrint (
       case 'r':\r
         Status = VA_ARG (Marker, RETURN_STATUS);\r
         ArgumentString = ValueBuffer;\r
-        for (Index = 0; StatusString[Index].String != NULL; Index++) {\r
-          if (Status == StatusString[Index].Status) {\r
-            ArgumentString = StatusString[Index].String;\r
+        if (RETURN_ERROR (Status)) {\r
+          //\r
+          // Clear error bit\r
+          //\r
+          Index = Status & ~MAX_BIT;\r
+          if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r
+            ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];\r
+          }\r
+        } else {\r
+          Index = Status;\r
+          if (Index <= WARNING_STATUS_NUMBER) {\r
+            ArgumentString = StatusString [Index];\r
           }\r
         }\r
         if (ArgumentString == ValueBuffer) {\r
@@ -392,7 +406,7 @@ BasePrintLibVSPrint (
         break;\r
 \r
       case '\n':\r
-        ArgumentString = "\r\n";\r
+        ArgumentString = "\n\r";\r
         break;\r
 \r
       case '%':\r
@@ -405,6 +419,11 @@ BasePrintLibVSPrint (
         break;\r
       }\r
       break;\r
\r
+    case '\n':\r
+      ArgumentString = "\n\r";\r
+      break;\r
+\r
     default:\r
       ArgumentString = (CHAR8 *)&FormatCharacter;\r
       Flags |= ARGUMENT_UNICODE;\r
@@ -521,7 +540,18 @@ BasePrintLibVSPrint (
   // Null terminate the Unicode or ASCII string\r
   //\r
   Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);\r
+  //\r
+  // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
+  // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
+  //\r
+  ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));\r
+  //\r
+  // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
+  // Ascii characters if PcdMaximumUnicodeStringLength is not zero. \r
+  //\r
+  ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));\r
    \r
+\r
   return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r
 }\r
 \r
index 29c09e730e7728b210040a56cdfb0f94b93b7433..39fa7e6f375907e5c6e913b48fe41568b968c46a 100644 (file)
@@ -18,9 +18,9 @@
 \r
 #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress)      (((SmBusAddress) >> 1)  & 0x7f)\r
 #define SMBUS_LIB_COMMAND(SmBusAddress)            (((SmBusAddress) >> 8)  & 0xff)\r
-#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x1f)\r
+#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x3f)\r
 #define SMBUS_LIB_PEC(SmBusAddress)     ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0))\r
-#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT))\r
+#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT))\r
 \r
 //\r
 // Replaced by PCD\r
@@ -639,14 +639,14 @@ SmBusProcessCall (
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
 \r
   @param  HostControl     The value of Host Control Register to set.  \r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -657,8 +657,8 @@ UINTN
 InternalSmBusBlock (\r
   IN  UINT8                     HostControl,\r
   IN  UINTN                     SmBusAddress,\r
-  IN  UINT8                     *OutBuffer,\r
-  OUT UINT8                     *InBuffer,\r
+  IN  UINT8                     *WriteBuffer,\r
+  OUT UINT8                     *ReadBuffer,\r
   OUT RETURN_STATUS             *Status\r
   )\r
 {\r
@@ -667,7 +667,7 @@ InternalSmBusBlock (
   UINTN                         BytesCount;\r
   UINT8                         AuxiliaryControl;\r
 \r
-  BytesCount = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  BytesCount = SMBUS_LIB_LENGTH (SmBusAddress);\r
 \r
   ReturnStatus = InternalSmBusAcquire ();\r
   if (RETURN_ERROR (ReturnStatus)) {\r
@@ -684,9 +684,9 @@ InternalSmBusBlock (
 \r
   InternalSmBusIoWrite8 (SMBUS_R_HST_D0, (UINT8) BytesCount);\r
 \r
-  if (OutBuffer != NULL) {\r
+  if (WriteBuffer != NULL) {\r
     for (Index = 0; Index < BytesCount; Index++) {\r
-      InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, OutBuffer[Index]);\r
+      InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, WriteBuffer[Index]);\r
     }\r
   }\r
   //\r
@@ -711,9 +711,9 @@ InternalSmBusBlock (
   }\r
 \r
   BytesCount = InternalSmBusIoRead8 (SMBUS_R_HST_D0);\r
-  if (InBuffer != NULL) {\r
+  if (ReadBuffer != NULL) {\r
     for (Index = 0; Index < BytesCount; Index++) {\r
-      InBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB);\r
+      ReadBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB);\r
     }\r
   }\r
 \r
@@ -738,7 +738,7 @@ Done:
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
   If Length in SmBusAddress is not zero, then ASSERT().\r
   If Buffer is NULL, then ASSERT().\r
@@ -804,6 +804,8 @@ SmBusWriteBlock (
   )\r
 {\r
   ASSERT (Buffer != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
   return InternalSmBusBlock (\r
@@ -820,18 +822,19 @@ SmBusWriteBlock (
 \r
   Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
   The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
-  Bytes are written to the SMBUS from OutBuffer.  Bytes are then read from the SMBUS into InBuffer.\r
+  Bytes are written to the SMBUS from WriteBuffer.  Bytes are then read from the SMBUS into ReadBuffer.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
-  If OutBuffer is NULL, then ASSERT().\r
-  If InBuffer is NULL, then ASSERT().\r
+  If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
+  If WriteBuffer is NULL, then ASSERT().\r
+  If ReadBuffer is NULL, then ASSERT().\r
   If any reserved bits of SmBusAddress are set, then ASSERT().\r
 \r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -842,20 +845,22 @@ UINTN
 EFIAPI\r
 SmBusBlockProcessCall (\r
   IN  UINTN          SmBusAddress,\r
-  IN  VOID           *OutBuffer,\r
-  OUT VOID           *InBuffer,\r
+  IN  VOID           *WriteBuffer,\r
+  OUT VOID           *ReadBuffer,\r
   OUT RETURN_STATUS  *Status        OPTIONAL\r
   )\r
 {\r
-  ASSERT (InBuffer  != NULL);\r
-  ASSERT (OutBuffer != NULL);\r
+  ASSERT (WriteBuffer != NULL);\r
+  ASSERT (ReadBuffer  != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
   return InternalSmBusBlock (\r
            SMBUS_V_SMB_CMD_BLOCK_PROCESS,\r
            SmBusAddress | SMBUS_B_WRITE,\r
-           OutBuffer,\r
-           InBuffer,\r
+           WriteBuffer,\r
+           ReadBuffer,\r
            Status\r
            );\r
 }\r
index bd6d57f2d307d422ea03fdafe526b9b397348eda..47c00a7306d1e6a04cacbb6099219e80fa65943d 100644 (file)
@@ -11,8 +11,6 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
 \r
-Module Name: SmbusLib.c\r
-\r
 **/\r
 \r
 #ifndef __INTERNAL_SMBUS_LIB_H\r
@@ -20,9 +18,9 @@ Module Name: SmbusLib.c
 \r
 #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress)      (((SmBusAddress) >> 1)  & 0x7f)\r
 #define SMBUS_LIB_COMMAND(SmBusAddress)            (((SmBusAddress) >> 8)  & 0xff)\r
-#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x1f)\r
+#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x3f)\r
 #define SMBUS_LIB_PEC(SmBusAddress)     ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0))\r
-#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT))\r
+#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT))\r
 \r
 //\r
 // Declaration for internal functions\r
index e71f11bef81b7c535b1222197eebc9952f5cf037..93fadb6598fdf4e5dd8a6a8eebb474d6fc0a53bc 100644 (file)
@@ -350,7 +350,7 @@ SmBusProcessCall (
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
   If Length in SmBusAddress is not zero, then ASSERT().\r
   If Buffer is NULL, then ASSERT().\r
@@ -412,9 +412,11 @@ SmBusWriteBlock (
   UINTN  Length;\r
 \r
   ASSERT (Buffer != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
-  Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
   return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status);\r
 }\r
 \r
@@ -423,19 +425,19 @@ SmBusWriteBlock (
 \r
   Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
   The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
-  Bytes are written to the SMBUS from OutBuffer.  Bytes are then read from the SMBUS into InBuffer.\r
+  Bytes are written to the SMBUS from WriteBuffer.  Bytes are then read from the SMBUS into ReadBuffer.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
-  If OutBuffer is NULL, then ASSERT().\r
-  If InBuffer is NULL, then ASSERT().\r
+  If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
+  If WriteBuffer is NULL, then ASSERT().\r
+  If ReadBuffer is NULL, then ASSERT().\r
   If any reserved bits of SmBusAddress are set, then ASSERT().\r
 \r
-\r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -446,21 +448,23 @@ UINTN
 EFIAPI\r
 SmBusBlockProcessCall (\r
   IN  UINTN          SmBusAddress,\r
-  IN  VOID           *OutBuffer,\r
-  OUT VOID           *InBuffer,\r
+  IN  VOID           *WriteBuffer,\r
+  OUT VOID           *ReadBuffer,\r
   OUT RETURN_STATUS  *Status        OPTIONAL\r
   )\r
 {\r
   UINTN   Length;\r
 \r
-  ASSERT (InBuffer  != NULL);\r
-  ASSERT (OutBuffer != NULL);\r
+  ASSERT (WriteBuffer != NULL);\r
+  ASSERT (ReadBuffer  != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
-  Length   = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
   //\r
-  // Assuming that InBuffer is large enough to save another memory copy.\r
+  // Assuming that ReadBuffer is large enough to save another memory copy.\r
   //\r
-  InBuffer = CopyMem (InBuffer, OutBuffer, Length);\r
-  return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, InBuffer, Status);\r
+  ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length);\r
+  return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status);\r
 }\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index bda1f4992f7945ffa063a3578651339e25a22711..53c4e4416b7ad289c6c71d8a02f144f81093792c 100644 (file)
@@ -132,7 +132,6 @@ InternalMemCompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (Length > 0);\r
   while ((--Length != 0) &&\r
          (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
     DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r
index bd6d57f2d307d422ea03fdafe526b9b397348eda..47c00a7306d1e6a04cacbb6099219e80fa65943d 100644 (file)
@@ -11,8 +11,6 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
 \r
-Module Name: SmbusLib.c\r
-\r
 **/\r
 \r
 #ifndef __INTERNAL_SMBUS_LIB_H\r
@@ -20,9 +18,9 @@ Module Name: SmbusLib.c
 \r
 #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress)      (((SmBusAddress) >> 1)  & 0x7f)\r
 #define SMBUS_LIB_COMMAND(SmBusAddress)            (((SmBusAddress) >> 8)  & 0xff)\r
-#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x1f)\r
+#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x3f)\r
 #define SMBUS_LIB_PEC(SmBusAddress)     ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0))\r
-#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT))\r
+#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT))\r
 \r
 //\r
 // Declaration for internal functions\r
index e71f11bef81b7c535b1222197eebc9952f5cf037..93fadb6598fdf4e5dd8a6a8eebb474d6fc0a53bc 100644 (file)
@@ -350,7 +350,7 @@ SmBusProcessCall (
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
   If Length in SmBusAddress is not zero, then ASSERT().\r
   If Buffer is NULL, then ASSERT().\r
@@ -412,9 +412,11 @@ SmBusWriteBlock (
   UINTN  Length;\r
 \r
   ASSERT (Buffer != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
-  Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
   return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status);\r
 }\r
 \r
@@ -423,19 +425,19 @@ SmBusWriteBlock (
 \r
   Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
   The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
-  Bytes are written to the SMBUS from OutBuffer.  Bytes are then read from the SMBUS into InBuffer.\r
+  Bytes are written to the SMBUS from WriteBuffer.  Bytes are then read from the SMBUS into ReadBuffer.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
-  If OutBuffer is NULL, then ASSERT().\r
-  If InBuffer is NULL, then ASSERT().\r
+  If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
+  If WriteBuffer is NULL, then ASSERT().\r
+  If ReadBuffer is NULL, then ASSERT().\r
   If any reserved bits of SmBusAddress are set, then ASSERT().\r
 \r
-\r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -446,21 +448,23 @@ UINTN
 EFIAPI\r
 SmBusBlockProcessCall (\r
   IN  UINTN          SmBusAddress,\r
-  IN  VOID           *OutBuffer,\r
-  OUT VOID           *InBuffer,\r
+  IN  VOID           *WriteBuffer,\r
+  OUT VOID           *ReadBuffer,\r
   OUT RETURN_STATUS  *Status        OPTIONAL\r
   )\r
 {\r
   UINTN   Length;\r
 \r
-  ASSERT (InBuffer  != NULL);\r
-  ASSERT (OutBuffer != NULL);\r
+  ASSERT (WriteBuffer != NULL);\r
+  ASSERT (ReadBuffer  != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
-  Length   = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
   //\r
-  // Assuming that InBuffer is large enough to save another memory copy.\r
+  // Assuming that ReadBuffer is large enough to save another memory copy.\r
   //\r
-  InBuffer = CopyMem (InBuffer, OutBuffer, Length);\r
-  return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, InBuffer, Status);\r
+  ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length);\r
+  return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status);\r
 }\r
index c8199d8dc31cb2badd25ee641ade2fb443fddf91..6081bbe1b7b804bf55fc2c27b678ac8f4586e7a3 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Compares two memory buffers of a given length.\r
+  Compares the contents of two buffers.\r
 \r
-  This function compares Length bytes of SourceBuffer to Length bytes of\r
-  DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
-  0 is returned. Otherwise, the value returned is the first mismatched byte in\r
-  SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
+  This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
+  If all Length bytes of the two buffers are identical, then 0 is returned.  Otherwise, the\r
+  value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
+  mismatched byte in DestinationBuffer.\r
+  If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). \r
 \r
-  If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
-  If SourceBuffer is NULL and Length > 0, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
-  ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
 \r
-  @param  DestinationBuffer First memory buffer\r
-  @param  SourceBuffer      Second memory buffer\r
-  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
-                            regions to compare\r
+  @param  DestinationBuffer Pointer to the destination buffer to compare.\r
+  @param  SourceBuffer      Pointer to the source buffer to compare.\r
+  @param  Length            Number of bytes to compare.\r
 \r
-  @retval 0         if DestinationBuffer == SourceBuffer\r
-  @retval Non-zero  if DestinationBuffer != SourceBuffer\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
 \r
 **/\r
 INTN\r
@@ -56,12 +55,13 @@ CompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (DestinationBuffer != NULL);\r
-  ASSERT (SourceBuffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
   if (Length == 0) {\r
     return 0;\r
   }\r
+  ASSERT (DestinationBuffer != NULL);\r
+  ASSERT (SourceBuffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer));\r
+\r
   return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
 }\r
index bda1f4992f7945ffa063a3578651339e25a22711..53c4e4416b7ad289c6c71d8a02f144f81093792c 100644 (file)
@@ -132,7 +132,6 @@ InternalMemCompareMem (
   IN      UINTN                     Length\r
   )\r
 {\r
-  ASSERT (Length > 0);\r
   while ((--Length != 0) &&\r
          (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
     DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
index a17705db1dc2511877bb3275d2632a19d317779f..d336d596417296689b28788b30121c72805e729d 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 16-bit value, and returns a pointer to the\r
-  matching 16-bit value in the target buffer.\r
+  Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 16-bit increments for a 16-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 16-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 67eb84d8ef4486fc8b8fbb4bf7e44c14170422de..8de55945ce148e193b42a754fbf1199053d07262 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 32-bit value, and returns a pointer to the\r
-  matching 32-bit value in the target buffer.\r
+  Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 32-bit increments for a 32-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 32-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index c5f0762ebe69ee21eb757f9b5de19ca3a45a6c41..228c864b04e69f8f9299868c2cb695f5c4dc9319 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for a 64-bit value, and returns a pointer to the\r
-  matching 64-bit value in the target buffer.\r
+  Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address at 64-bit increments for a 64-bit\r
-  value that matches Value. If a match is found, then a pointer to the matching\r
-  value in the target buffer is returned. If no match is found, then NULL is\r
-  returned. If Length is 0, then NULL is returned.\r
-\r
-  If Buffer is NULL, then ASSERT().\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for a 64-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -55,12 +52,13 @@ ScanMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
+  if (Length == 0) {\r
+    return NULL;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
   ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return NULL;\r
-  }\r
-  return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
+  return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 9b817b1b0e96920b9d8092b4b610ed38d0b9c42d..72a8078b8134bdce4b7de76b0fa681886a26e7e4 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Scans a target buffer for an 8-bit value, and returns a pointer to the\r
-  matching 8-bit value in the target buffer.\r
+  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
+  in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
-  the lowest address to the highest address for an 8-bit value that matches\r
-  Value. If a match is found, then a pointer to the matching byte in the target\r
-  buffer is returned. If no match is found, then NULL is returned. If Length is\r
-  0, then NULL is returned.\r
+  This function searches target the buffer specified by Buffer and Length from the lowest\r
+  address to the highest address for an 8-bit value that matches Value.  If a match is found,\r
+  then a pointer to the matching byte in the target buffer is returned.  If no match is found,\r
+  then NULL is returned.  If Length is 0, then NULL is returned.\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Buffer is NULL, then ASSERT().\r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer      Pointer to the target buffer to scan.\r
+  @param  Length      Number of bytes in Buffer to scan.\r
+  @param  Value       Value to search for in the target buffer.\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Value   Value to search for in the target buffer.\r
-\r
-  @return Pointer to the first occurrence or NULL if not found.\r
-  @retval NULL  if Length == 0 or Value was not found.\r
+  @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
 \r
 **/\r
 VOID *\r
@@ -54,11 +51,11 @@ ScanMem8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
-  ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
-\r
-  if ((Length /= sizeof (Value)) == 0) {\r
+  if (Length == 0) {\r
     return NULL;\r
   }\r
-  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
\r
+  return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index dea31608fe3d3ee98298101a80d0ef8cb12ce1c5..fd3720cd51e17d41f384d476c9b326b8cfef5d41 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem16 (Buffer, Length, Value);\r
+  return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 1ae7acb0132bf8bad4c1e8f2e638603b344f896e..77f1abda04d86a8a16a1703a8a45753ad1e3f6f0 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem32 (Buffer, Length, Value);\r
+  return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0128a2d6f13fe2b6057c37edbcd60fa4f8a9cac5..f95b97ff87281c58a454824ce2c1569a02aec5d4 100644 (file)
@@ -32,7 +32,7 @@
   Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
   bytes of Buffer.\r
 \r
-  If Buffer is NULL and Length > 0, then ASSERT().\r
+  If Length > 0 and Buffer is NULL and Length > 0, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
   If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
@@ -52,13 +52,14 @@ SetMem64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (!(Buffer == NULL && Length > 0));\r
-  ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
+  if (Length == 0) {\r
+    return Buffer;\r
+  }\r
+\r
+  ASSERT (Buffer != NULL);\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
   ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0);\r
   ASSERT ((Length & (sizeof (Value) - 1)) == 0);\r
 \r
-  if ((Length /= sizeof (Value)) == 0) {\r
-    return Buffer;\r
-  }\r
-  return InternalMemSetMem64 (Buffer, Length, Value);\r
+  return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value);\r
 }\r
index 0600dc289fb45c4496d3a16d7f56a3d33631d398..d0e8760ff62337f5e63fc6c3a80623a5db17cbb1 100644 (file)
 #include "MemLibInternals.h"\r
 \r
 /**\r
-  Set Buffer to Value for Size bytes.\r
+  Fills a target buffer with a byte value, and returns the target buffer.\r
 \r
   This function fills Length bytes of Buffer with Value, and returns Buffer.\r
+  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
 \r
-  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+  @param  Buffer    Memory to set.\r
+  @param  Length    Number of bytes to set\r
+  @param  Value     Value of the set operation.\r
 \r
-  @param  Buffer Memory to set.\r
-  @param  Size Number of bytes to set\r
-  @param  Value Value of the set operation.\r
-\r
-  @return Buffer\r
+  @return Buffer.\r
 \r
 **/\r
 VOID *\r
 EFIAPI\r
 SetMem (\r
   IN      VOID                      *Buffer,\r
-  IN      UINTN                     Size,\r
+  IN      UINTN                     Length,\r
   IN      UINT8                     Value\r
   )\r
 {\r
-  if (Size == 0) {\r
+  if (Length == 0) {\r
     return Buffer;\r
   }\r
-  ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer);\r
-  return InternalMemSetMem (Buffer, Size, Value);\r
+\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+\r
+  return InternalMemSetMem (Buffer, Length, Value);\r
 }\r