]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/RuntimeDxe/Crc32.c
2 CalculateCrc32 Boot Services as defined in DXE CIS.
4 Copyright (c) 2006, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 This Boot Services is in the Runtime Driver because this service is
20 also required by SetVirtualAddressMap() when the EFI System Table and
21 EFI Runtime Services Table are converted from physical address to
22 virtual addresses. This requires that the 32-bit CRC be recomputed.
29 UINT32 mCrcTable
[256];
32 Calculate CRC32 for target data.
34 @param Len The target data.
35 @param DataSize The target data size.
36 @param CrcOut The CRC32 for target data.
38 @retval EFI_SUCCESS The CRC32 for target data is calculated successfully.
39 @retval EFI_INVALID_PARAMETER Some parameter is not valid, so the CRC32 is not
45 RuntimeDriverCalculateCrc32 (
55 if (Data
== NULL
|| DataSize
== 0 || CrcOut
== NULL
) {
56 return EFI_INVALID_PARAMETER
;
60 for (Index
= 0, Ptr
= Data
; Index
< DataSize
; Index
++, Ptr
++) {
61 Crc
= (Crc
>> 8) ^ mCrcTable
[(UINT8
) Crc
^ *Ptr
];
64 *CrcOut
= Crc
^ 0xffffffff;
70 Reverse bits for 32bit data.
72 @param Value The data to be reversed.
74 @retrun Data reversed.
87 for (Index
= 0; Index
< 32; Index
++) {
88 if (Value
& (1 << Index
)) {
89 NewValue
= NewValue
| (1 << (31 - Index
));
97 Initialize CRC32 table.
105 RuntimeDriverInitializeCrc32Table (
113 for (TableEntry
= 0; TableEntry
< 256; TableEntry
++) {
114 Value
= ReverseBits ((UINT32
) TableEntry
);
115 for (Index
= 0; Index
< 8; Index
++) {
116 if (Value
& 0x80000000) {
117 Value
= (Value
<< 1) ^ 0x04c11db7;
123 mCrcTable
[TableEntry
] = ReverseBits (Value
);