1 /*++ 2 3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR> 4 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 13 Module Name: 14 15 EdkIIGlueBaseMemoryLib.h 16 17 Abstract: 18 19 Memory-only library functions with no library constructor/destructor 20 21 --*/ 22 23 #ifndef __EDKII_GLUE_BASE_MEMORY_LIB_H__ 24 #define __EDKII_GLUE_BASE_MEMORY_LIB_H__ 25 26 27 #define CopyMem(_DESTINATIONBUFFER, _SOURCEBUFFER, _LENGTH) GlueCopyMem(_DESTINATIONBUFFER, _SOURCEBUFFER, _LENGTH) 28 #define ZeroMem(_BUFFER, _LENGTH) GlueZeroMem(_BUFFER, _LENGTH) 29 #define SetMem(_BUFFER, _LENGTH, _VALUE) GlueSetMem(_BUFFER, _LENGTH, _VALUE) 30 #define CompareMem(_DESTINATIONBUFFER, _SOURCEBUFFER, _LENGTH) GlueCompareMem(_DESTINATIONBUFFER, _SOURCEBUFFER, _LENGTH) 31 #define CompareGuid(_GUID1, _GUID2) GlueCompareGuid(_GUID1, _GUID2) 32 #define ScanGuid(_BUFFER, _LENGTH, _GUID) GlueScanGuid(_BUFFER, _LENGTH, _GUID) 33 34 /** 35 Copies a source buffer to a destination buffer, and returns the destination buffer. 36 37 This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns 38 DestinationBuffer. The implementation must be reentrant, and it must handle the case 39 where SourceBuffer overlaps DestinationBuffer. 40 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). 41 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). 42 43 @param DestinationBuffer Pointer to the destination buffer of the memory copy. 44 @param SourceBuffer Pointer to the source buffer of the memory copy. 45 @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer. 46 47 @return DestinationBuffer. 48 49 **/ 50 VOID * 51 EFIAPI 52 GlueCopyMem ( 53 OUT VOID *DestinationBuffer, 54 IN CONST VOID *SourceBuffer, 55 IN UINTN Length 56 ); 57 58 /** 59 Fills a target buffer with a byte value, and returns the target buffer. 60 61 This function fills Length bytes of Buffer with Value, and returns Buffer. 62 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 63 64 @param Buffer Memory to set. 65 @param Length Number of bytes to set. 66 @param Value Value of the set operation. 67 68 @return Buffer. 69 70 **/ 71 VOID * 72 EFIAPI 73 GlueSetMem ( 74 OUT VOID *Buffer, 75 IN UINTN Length, 76 IN UINT8 Value 77 ); 78 79 /** 80 Fills a target buffer with a 16-bit value, and returns the target buffer. 81 82 This function fills Length bytes of Buffer with the 16-bit value specified by 83 Value, and returns Buffer. Value is repeated every 16-bits in for Length 84 bytes of Buffer. 85 86 If Length > 0 and Buffer is NULL, then ASSERT(). 87 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 88 If Buffer is not aligned on a 16-bit boundary, then ASSERT(). 89 If Length is not aligned on a 16-bit boundary, then ASSERT(). 90 91 @param Buffer Pointer to the target buffer to fill. 92 @param Length Number of bytes in Buffer to fill. 93 @param Value Value with which to fill Length bytes of Buffer. 94 95 @return Buffer. 96 97 **/ 98 VOID * 99 EFIAPI 100 SetMem16 ( 101 OUT VOID *Buffer, 102 IN UINTN Length, 103 IN UINT16 Value 104 ); 105 106 /** 107 Fills a target buffer with a 32-bit value, and returns the target buffer. 108 109 This function fills Length bytes of Buffer with the 32-bit value specified by 110 Value, and returns Buffer. Value is repeated every 32-bits in for Length 111 bytes of Buffer. 112 113 If Length > 0 and Buffer is NULL, then ASSERT(). 114 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 115 If Buffer is not aligned on a 32-bit boundary, then ASSERT(). 116 If Length is not aligned on a 32-bit boundary, then ASSERT(). 117 118 @param Buffer Pointer to the target buffer to fill. 119 @param Length Number of bytes in Buffer to fill. 120 @param Value Value with which to fill Length bytes of Buffer. 121 122 @return Buffer. 123 124 **/ 125 VOID * 126 EFIAPI 127 SetMem32 ( 128 OUT VOID *Buffer, 129 IN UINTN Length, 130 IN UINT32 Value 131 ); 132 133 /** 134 Fills a target buffer with a 64-bit value, and returns the target buffer. 135 136 This function fills Length bytes of Buffer with the 64-bit value specified by 137 Value, and returns Buffer. Value is repeated every 64-bits in for Length 138 bytes of Buffer. 139 140 If Length > 0 and Buffer is NULL, then ASSERT(). 141 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 142 If Buffer is not aligned on a 64-bit boundary, then ASSERT(). 143 If Length is not aligned on a 64-bit boundary, then ASSERT(). 144 145 @param Buffer Pointer to the target buffer to fill. 146 @param Length Number of bytes in Buffer to fill. 147 @param Value Value with which to fill Length bytes of Buffer. 148 149 @return Buffer. 150 151 **/ 152 VOID * 153 EFIAPI 154 SetMem64 ( 155 OUT VOID *Buffer, 156 IN UINTN Length, 157 IN UINT64 Value 158 ); 159 160 /** 161 Fills a target buffer with zeros, and returns the target buffer. 162 163 This function fills Length bytes of Buffer with zeros, and returns Buffer. 164 If Length > 0 and Buffer is NULL, then ASSERT(). 165 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 166 167 @param Buffer Pointer to the target buffer to fill with zeros. 168 @param Length Number of bytes in Buffer to fill with zeros. 169 170 @return Buffer. 171 172 **/ 173 VOID * 174 EFIAPI 175 GlueZeroMem ( 176 OUT VOID *Buffer, 177 IN UINTN Length 178 ); 179 180 /** 181 Compares the contents of two buffers. 182 183 This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. 184 If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the 185 value returned is the first mismatched byte in SourceBuffer subtracted from the first 186 mismatched byte in DestinationBuffer. 187 If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). 188 If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). 189 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). 190 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). 191 192 @param DestinationBuffer Pointer to the destination buffer to compare. 193 @param SourceBuffer Pointer to the source buffer to compare. 194 @param Length Number of bytes to compare. 195 196 @return 0 All Length bytes of the two buffers are identical. 197 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first 198 mismatched byte in DestinationBuffer. 199 200 **/ 201 INTN 202 EFIAPI 203 GlueCompareMem ( 204 IN CONST VOID *DestinationBuffer, 205 IN CONST VOID *SourceBuffer, 206 IN UINTN Length 207 ); 208 209 /** 210 Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value 211 in the target buffer. 212 213 This function searches target the buffer specified by Buffer and Length from the lowest 214 address to the highest address for an 8-bit value that matches Value. If a match is found, 215 then a pointer to the matching byte in the target buffer is returned. If no match is found, 216 then NULL is returned. If Length is 0, then NULL is returned. 217 If Length > 0 and Buffer is NULL, then ASSERT(). 218 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 219 220 @param Buffer Pointer to the target buffer to scan. 221 @param Length Number of bytes in Buffer to scan. 222 @param Value Value to search for in the target buffer. 223 224 @return A pointer to the matching byte in the target buffer or NULL otherwise. 225 226 **/ 227 VOID * 228 EFIAPI 229 ScanMem8 ( 230 IN CONST VOID *Buffer, 231 IN UINTN Length, 232 IN UINT8 Value 233 ); 234 235 /** 236 Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value 237 in the target buffer. 238 239 This function searches target the buffer specified by Buffer and Length from the lowest 240 address to the highest address for a 16-bit value that matches Value. If a match is found, 241 then a pointer to the matching byte in the target buffer is returned. If no match is found, 242 then NULL is returned. If Length is 0, then NULL is returned. 243 If Length > 0 and Buffer is NULL, then ASSERT(). 244 If Buffer is not aligned on a 16-bit boundary, then ASSERT(). 245 If Length is not aligned on a 16-bit boundary, then ASSERT(). 246 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 247 248 @param Buffer Pointer to the target buffer to scan. 249 @param Length Number of bytes in Buffer to scan. 250 @param Value Value to search for in the target buffer. 251 252 @return A pointer to the matching byte in the target buffer or NULL otherwise. 253 254 **/ 255 VOID * 256 EFIAPI 257 ScanMem16 ( 258 IN CONST VOID *Buffer, 259 IN UINTN Length, 260 IN UINT16 Value 261 ); 262 263 /** 264 Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value 265 in the target buffer. 266 267 This function searches target the buffer specified by Buffer and Length from the lowest 268 address to the highest address for a 32-bit value that matches Value. If a match is found, 269 then a pointer to the matching byte in the target buffer is returned. If no match is found, 270 then NULL is returned. If Length is 0, then NULL is returned. 271 If Length > 0 and Buffer is NULL, then ASSERT(). 272 If Buffer is not aligned on a 32-bit boundary, then ASSERT(). 273 If Length is not aligned on a 32-bit boundary, then ASSERT(). 274 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 275 276 @param Buffer Pointer to the target buffer to scan. 277 @param Length Number of bytes in Buffer to scan. 278 @param Value Value to search for in the target buffer. 279 280 @return A pointer to the matching byte in the target buffer or NULL otherwise. 281 282 **/ 283 VOID * 284 EFIAPI 285 ScanMem32 ( 286 IN CONST VOID *Buffer, 287 IN UINTN Length, 288 IN UINT32 Value 289 ); 290 291 /** 292 Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value 293 in the target buffer. 294 295 This function searches target the buffer specified by Buffer and Length from the lowest 296 address to the highest address for a 64-bit value that matches Value. If a match is found, 297 then a pointer to the matching byte in the target buffer is returned. If no match is found, 298 then NULL is returned. If Length is 0, then NULL is returned. 299 If Length > 0 and Buffer is NULL, then ASSERT(). 300 If Buffer is not aligned on a 64-bit boundary, then ASSERT(). 301 If Length is not aligned on a 64-bit boundary, then ASSERT(). 302 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 303 304 @param Buffer Pointer to the target buffer to scan. 305 @param Length Number of bytes in Buffer to scan. 306 @param Value Value to search for in the target buffer. 307 308 @return A pointer to the matching byte in the target buffer or NULL otherwise. 309 310 **/ 311 VOID * 312 EFIAPI 313 ScanMem64 ( 314 IN CONST VOID *Buffer, 315 IN UINTN Length, 316 IN UINT64 Value 317 ); 318 319 /** 320 Copies a source GUID to a destination GUID. 321 322 This function copies the contents of the 128-bit GUID specified by SourceGuid to 323 DestinationGuid, and returns DestinationGuid. 324 If DestinationGuid is NULL, then ASSERT(). 325 If SourceGuid is NULL, then ASSERT(). 326 327 @param DestinationGuid Pointer to the destination GUID. 328 @param SourceGuid Pointer to the source GUID. 329 330 @return DestinationGuid. 331 332 **/ 333 GUID * 334 EFIAPI 335 CopyGuid ( 336 OUT GUID *DestinationGuid, 337 IN CONST GUID *SourceGuid 338 ); 339 340 /** 341 Compares two GUIDs. 342 343 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned. 344 If there are any bit differences in the two GUIDs, then FALSE is returned. 345 If Guid1 is NULL, then ASSERT(). 346 If Guid2 is NULL, then ASSERT(). 347 348 @param Guid1 A pointer to a 128 bit GUID. 349 @param Guid2 A pointer to a 128 bit GUID. 350 351 @retval TRUE Guid1 and Guid2 are identical. 352 @retval FALSE Guid1 and Guid2 are not identical. 353 354 **/ 355 BOOLEAN 356 EFIAPI 357 GlueCompareGuid ( 358 IN CONST GUID *Guid1, 359 IN CONST GUID *Guid2 360 ); 361 362 /** 363 Scans a target buffer for a GUID, and returns a pointer to the matching GUID 364 in the target buffer. 365 366 This function searches target the buffer specified by Buffer and Length from 367 the lowest address to the highest address at 128-bit increments for the 128-bit 368 GUID value that matches Guid. If a match is found, then a pointer to the matching 369 GUID in the target buffer is returned. If no match is found, then NULL is returned. 370 If Length is 0, then NULL is returned. 371 If Length > 0 and Buffer is NULL, then ASSERT(). 372 If Buffer is not aligned on a 32-bit boundary, then ASSERT(). 373 If Length is not aligned on a 128-bit boundary, then ASSERT(). 374 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). 375 376 @param Buffer Pointer to the target buffer to scan. 377 @param Length Number of bytes in Buffer to scan. 378 @param Guid Value to search for in the target buffer. 379 380 @return A pointer to the matching Guid in the target buffer or NULL otherwise. 381 382 **/ 383 VOID * 384 EFIAPI 385 ScanGuid ( 386 IN CONST VOID *Buffer, 387 IN UINTN Length, 388 IN CONST GUID *Guid 389 ); 390 391 #endif 392