X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FRuntimeDxe%2FCrc32.c;h=c271856015bef1deda3bc813865380b517b5d5c4;hb=9917def3294bac4d14cd86ba382652aa41c6c1d6;hp=14370dbc7d9b4d5d51ff13d95ab73468b0d3a461;hpb=9920ae74af5a38672ddde0a997a7ec0960c96275;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/RuntimeDxe/Crc32.c b/MdeModulePkg/Core/RuntimeDxe/Crc32.c index 14370dbc7d..c271856015 100644 --- a/MdeModulePkg/Core/RuntimeDxe/Crc32.c +++ b/MdeModulePkg/Core/RuntimeDxe/Crc32.c @@ -1,13 +1,14 @@ /** @file - CalculateCrc32 Boot Services as defined in DXE CIS. + This file implements CalculateCrc32 Boot Services as defined in + Platform Initialization specification 1.0 VOLUME 2 DXE Core Interface. This Boot Services is in the Runtime Driver because this service is also required by SetVirtualAddressMap() when the EFI System Table and EFI Runtime Services Table are converted from physical address to - virtual addresses. This requires that the 32-bit CRC be recomputed. + virtual addresses. This requires that the 32-bit CRC be recomputed. -Copyright (c) 2006, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -18,9 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include - -UINT32 mCrcTable[256]; +#include +#include /** Calculate CRC32 for target data. @@ -42,73 +42,10 @@ RuntimeDriverCalculateCrc32 ( OUT UINT32 *CrcOut ) { - UINT32 Crc; - UINTN Index; - UINT8 *Ptr; - if (Data == NULL || DataSize == 0 || CrcOut == NULL) { return EFI_INVALID_PARAMETER; } - Crc = 0xffffffff; - for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) { - Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr]; - } - - *CrcOut = Crc ^ 0xffffffff; + *CrcOut = CalculateCrc32 (Data, DataSize); return EFI_SUCCESS; } - - -/** - Reverse bits for 32bit data. - This is a internal function. - - @param Value The data to be reversed. - - @return Data reversed. - -**/ -UINT32 -ReverseBits ( - UINT32 Value - ) -{ - UINTN Index; - UINT32 NewValue; - - NewValue = 0; - for (Index = 0; Index < 32; Index++) { - if ((Value & (1 << Index)) != 0) { - NewValue = NewValue | (1 << (31 - Index)); - } - } - - return NewValue; -} - -/** - Initialize CRC32 table. -**/ -VOID -RuntimeDriverInitializeCrc32Table ( - VOID - ) -{ - UINTN TableEntry; - UINTN Index; - UINT32 Value; - - for (TableEntry = 0; TableEntry < 256; TableEntry++) { - Value = ReverseBits ((UINT32) TableEntry); - for (Index = 0; Index < 8; Index++) { - if ((Value & 0x80000000) != 0) { - Value = (Value << 1) ^ 0x04c11db7; - } else { - Value = Value << 1; - } - } - - mCrcTable[TableEntry] = ReverseBits (Value); - } -}