]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/RuntimeDxe/Crc32.c
remove some comments introduced by tools.
[mirror_edk2.git] / MdeModulePkg / Core / RuntimeDxe / Crc32.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Crc32.c
15
16 Abstract:
17
18 CalculateCrc32 Boot Services as defined in DXE CIS.
19
20 This Boot Services is in the Runtime Driver because this service is
21 also required by SetVirtualAddressMap() when the EFI System Table and
22 EFI Runtime Services Table are converted from physical address to
23 virtual addresses. This requires that the 32-bit CRC be recomputed.
24
25 Revision History:
26
27 --*/
28
29
30 #include <PiDxe.h>
31
32 UINT32 mCrcTable[256];
33
34 EFI_STATUS
35 EFIAPI
36 RuntimeDriverCalculateCrc32 (
37 IN VOID *Data,
38 IN UINTN DataSize,
39 OUT UINT32 *CrcOut
40 )
41 /*++
42
43 Routine Description:
44
45 Calculate CRC32 for target data
46
47 Arguments:
48
49 Data - The target data.
50 DataSize - The target data size.
51 CrcOut - The CRC32 for target data.
52
53 Returns:
54
55 EFI_SUCCESS - The CRC32 for target data is calculated successfully.
56 EFI_INVALID_PARAMETER - Some parameter is not valid, so the CRC32 is not
57 calculated.
58
59 --*/
60 {
61 UINT32 Crc;
62 UINTN Index;
63 UINT8 *Ptr;
64
65 if (Data == NULL || DataSize == 0 || CrcOut == NULL) {
66 return EFI_INVALID_PARAMETER;
67 }
68
69 Crc = 0xffffffff;
70 for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
71 Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
72 }
73
74 *CrcOut = Crc ^ 0xffffffff;
75 return EFI_SUCCESS;
76 }
77
78 STATIC
79 UINT32
80 ReverseBits (
81 UINT32 Value
82 )
83 /*++
84
85 Routine Description:
86
87 Reverse bits for 32bit data.
88
89 Arguments:
90
91 Value - the data to be reversed.
92
93 Returns:
94
95 UINT32 data reversed.
96
97 --*/
98 {
99 UINTN Index;
100 UINT32 NewValue;
101
102 NewValue = 0;
103 for (Index = 0; Index < 32; Index++) {
104 if (Value & (1 << Index)) {
105 NewValue = NewValue | (1 << (31 - Index));
106 }
107 }
108
109 return NewValue;
110 }
111
112 VOID
113 RuntimeDriverInitializeCrc32Table (
114 VOID
115 )
116 /*++
117
118 Routine Description:
119
120 Initialize CRC32 table.
121
122 Arguments:
123
124 None.
125
126 Returns:
127
128 None.
129
130 --*/
131 {
132 UINTN TableEntry;
133 UINTN Index;
134 UINT32 Value;
135
136 for (TableEntry = 0; TableEntry < 256; TableEntry++) {
137 Value = ReverseBits ((UINT32) TableEntry);
138 for (Index = 0; Index < 8; Index++) {
139 if (Value & 0x80000000) {
140 Value = (Value << 1) ^ 0x04c11db7;
141 } else {
142 Value = Value << 1;
143 }
144 }
145
146 mCrcTable[TableEntry] = ReverseBits (Value);
147 }
148 }