]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/RuntimeDxe/Crc32.c
2 CalculateCrc32 Boot Services as defined in DXE CIS.
4 This Boot Services is in the Runtime Driver because this service is
5 also required by SetVirtualAddressMap() when the EFI System Table and
6 EFI Runtime Services Table are converted from physical address to
7 virtual addresses. This requires that the 32-bit CRC be recomputed.
9 Copyright (c) 2006, Intel Corporation. <BR>
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 UINT32 mCrcTable
[256];
26 Calculate CRC32 for target data.
28 @param Data The target data.
29 @param DataSize The target data size.
30 @param CrcOut The CRC32 for target data.
32 @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
33 @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
39 RuntimeDriverCalculateCrc32 (
49 if (Data
== NULL
|| DataSize
== 0 || CrcOut
== NULL
) {
50 return EFI_INVALID_PARAMETER
;
54 for (Index
= 0, Ptr
= Data
; Index
< DataSize
; Index
++, Ptr
++) {
55 Crc
= (Crc
>> 8) ^ mCrcTable
[(UINT8
) Crc
^ *Ptr
];
58 *CrcOut
= Crc
^ 0xffffffff;
64 Reverse bits for 32bit data.
65 This is a internal function.
67 @param Value The data to be reversed.
69 @return Data reversed.
81 for (Index
= 0; Index
< 32; Index
++) {
82 if ((Value
& (1 << Index
)) != 0) {
83 NewValue
= NewValue
| (1 << (31 - Index
));
91 Initialize CRC32 table.
94 RuntimeDriverInitializeCrc32Table (
102 for (TableEntry
= 0; TableEntry
< 256; TableEntry
++) {
103 Value
= ReverseBits ((UINT32
) TableEntry
);
104 for (Index
= 0; Index
< 8; Index
++) {
105 if ((Value
& 0x80000000) != 0) {
106 Value
= (Value
<< 1) ^ 0x04c11db7;
112 mCrcTable
[TableEntry
] = ReverseBits (Value
);