]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeMemoryLib/MemLibGeneric.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / DxeMemoryLib / MemLibGeneric.c
1 /** @file
2 Architecture Independent Base Memory Library Implementation.
3
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
9
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.
12
13 The following BaseMemoryLib instances share the same version of this file:
14
15 BaseMemoryLib
16 PeiMemoryLib
17 DxeMemoryLib
18
19 **/
20
21 #include "MemLibInternals.h"
22
23 /**
24 Fills a target buffer with a 16-bit value, and returns the target buffer.
25
26 @param Buffer Pointer to the target buffer to fill.
27 @param Length Number of bytes in Buffer to fill.
28 @param Value Value with which to fill Length bytes of Buffer.
29
30 @return Buffer
31
32 **/
33 VOID *
34 EFIAPI
35 InternalMemSetMem16 (
36 OUT VOID *Buffer,
37 IN UINTN Length,
38 IN UINT16 Value
39 )
40 {
41 do {
42 ((UINT16*)Buffer)[--Length] = Value;
43 } while (Length != 0);
44 return Buffer;
45 }
46
47 /**
48 Fills a target buffer with a 32-bit value, and returns the target buffer.
49
50 @param Buffer Pointer to the target buffer to fill.
51 @param Length Number of bytes in Buffer to fill.
52 @param Value Value with which to fill Length bytes of Buffer.
53
54 @return Buffer
55
56 **/
57 VOID *
58 EFIAPI
59 InternalMemSetMem32 (
60 OUT VOID *Buffer,
61 IN UINTN Length,
62 IN UINT32 Value
63 )
64 {
65 do {
66 ((UINT32*)Buffer)[--Length] = Value;
67 } while (Length != 0);
68 return Buffer;
69 }
70
71 /**
72 Fills a target buffer with a 64-bit value, and returns the target buffer.
73
74 @param Buffer Pointer to the target buffer to fill.
75 @param Length Number of bytes in Buffer to fill.
76 @param Value Value with which to fill Length bytes of Buffer.
77
78 @return Buffer
79
80 **/
81 VOID *
82 EFIAPI
83 InternalMemSetMem64 (
84 OUT VOID *Buffer,
85 IN UINTN Length,
86 IN UINT64 Value
87 )
88 {
89 do {
90 ((UINT64*)Buffer)[--Length] = Value;
91 } while (Length != 0);
92 return Buffer;
93 }
94
95 /**
96 Set Buffer to 0 for Size bytes.
97
98 @param Buffer Memory to set.
99 @param Size Number of bytes to set
100
101 @return Buffer
102
103 **/
104 VOID *
105 EFIAPI
106 InternalMemZeroMem (
107 OUT VOID *Buffer,
108 IN UINTN Length
109 )
110 {
111 return InternalMemSetMem (Buffer, Length, 0);
112 }
113
114 /**
115 Compares two memory buffers of a given length.
116
117 @param DestinationBuffer First memory buffer
118 @param SourceBuffer Second memory buffer
119 @param Length Length of DestinationBuffer and SourceBuffer memory
120 regions to compare. Must be non-zero.
121
122 @retval 0 if MemOne == MemTwo
123
124 **/
125 INTN
126 EFIAPI
127 InternalMemCompareMem (
128 IN CONST VOID *DestinationBuffer,
129 IN CONST VOID *SourceBuffer,
130 IN UINTN Length
131 )
132 {
133 while ((--Length != 0) &&
134 (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {
135 DestinationBuffer = (INT8*)DestinationBuffer + 1;
136 SourceBuffer = (INT8*)SourceBuffer + 1;
137 }
138 return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;
139 }
140
141 /**
142 Scans a target buffer for an 8-bit value, and returns a pointer to the
143 matching 8-bit value in the target buffer.
144
145 @param Buffer Pointer to the target buffer to scan.
146 @param Length Number of bytes in Buffer to scan. Must be non-zero.
147 @param Value Value to search for in the target buffer.
148
149 @return Pointer to the first occurrence or NULL if not found.
150
151 **/
152 CONST VOID *
153 EFIAPI
154 InternalMemScanMem8 (
155 IN CONST VOID *Buffer,
156 IN UINTN Length,
157 IN UINT8 Value
158 )
159 {
160 CONST UINT8 *Pointer;
161
162 Pointer = (CONST UINT8*)Buffer;
163 do {
164 if (*(Pointer++) == Value) {
165 return Pointer;
166 }
167 } while (--Length != 0);
168 return NULL;
169 }
170
171 /**
172 Scans a target buffer for a 16-bit value, and returns a pointer to the
173 matching 16-bit value in the target buffer.
174
175 @param Buffer Pointer to the target buffer to scan.
176 @param Length Number of bytes in Buffer to scan. Must be non-zero.
177 @param Value Value to search for in the target buffer.
178
179 @return Pointer to the first occurrence or NULL if not found.
180
181 **/
182 CONST VOID *
183 EFIAPI
184 InternalMemScanMem16 (
185 IN CONST VOID *Buffer,
186 IN UINTN Length,
187 IN UINT16 Value
188 )
189 {
190 CONST UINT16 *Pointer;
191
192 Pointer = (CONST UINT16*)Buffer;
193 do {
194 if (*(Pointer++) == Value) {
195 return Pointer;
196 }
197 } while (--Length != 0);
198 return NULL;
199 }
200
201 /**
202 Scans a target buffer for a 32-bit value, and returns a pointer to the
203 matching 32-bit value in the target buffer.
204
205 @param Buffer Pointer to the target buffer to scan.
206 @param Length Number of bytes in Buffer to scan. Must be non-zero.
207 @param Value Value to search for in the target buffer.
208
209 @return Pointer to the first occurrence or NULL if not found.
210
211 **/
212 CONST VOID *
213 EFIAPI
214 InternalMemScanMem32 (
215 IN CONST VOID *Buffer,
216 IN UINTN Length,
217 IN UINT32 Value
218 )
219 {
220 CONST UINT32 *Pointer;
221
222 Pointer = (CONST UINT32*)Buffer;
223 do {
224 if (*(Pointer++) == Value) {
225 return Pointer;
226 }
227 } while (--Length != 0);
228 return NULL;
229 }
230
231 /**
232 Scans a target buffer for a 64-bit value, and returns a pointer to the
233 matching 64-bit value in the target buffer.
234
235 @param Buffer Pointer to the target buffer to scan.
236 @param Length Number of bytes in Buffer to scan. Must be non-zero.
237 @param Value Value to search for in the target buffer.
238
239 @return Pointer to the first occurrence or NULL if not found.
240
241 **/
242 CONST VOID *
243 EFIAPI
244 InternalMemScanMem64 (
245 IN CONST VOID *Buffer,
246 IN UINTN Length,
247 IN UINT64 Value
248 )
249 {
250 CONST UINT64 *Pointer;
251
252 Pointer = (CONST UINT64*)Buffer;
253 do {
254 if (*(Pointer++) == Value) {
255 return Pointer;
256 }
257 } while (--Length != 0);
258 return NULL;
259 }