]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/Arm/ScanMemGeneric.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / Arm / ScanMemGeneric.c
1 /** @file
2 Architecture Independent Base Memory Library Implementation.
3
4 The following BaseMemoryLib instances contain the same copy of this file:
5 BaseMemoryLib
6 PeiMemoryLib
7 UefiMemoryLib
8
9 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #include "../MemLibInternals.h"
15
16 /**
17 Scans a target buffer for a 16-bit value, and returns a pointer to the
18 matching 16-bit value in the target buffer.
19
20 @param Buffer The pointer to the target buffer to scan.
21 @param Length The count of 16-bit value to scan. Must be non-zero.
22 @param Value The value to search for in the target buffer.
23
24 @return The pointer to the first occurrence, or NULL if not found.
25
26 **/
27 CONST VOID *
28 EFIAPI
29 InternalMemScanMem16 (
30 IN CONST VOID *Buffer,
31 IN UINTN Length,
32 IN UINT16 Value
33 )
34 {
35 CONST UINT16 *Pointer;
36
37 Pointer = (CONST UINT16*)Buffer;
38 do {
39 if (*Pointer == Value) {
40 return Pointer;
41 }
42 ++Pointer;
43 } while (--Length != 0);
44 return NULL;
45 }
46
47 /**
48 Scans a target buffer for a 32-bit value, and returns a pointer to the
49 matching 32-bit value in the target buffer.
50
51 @param Buffer The pointer to the target buffer to scan.
52 @param Length The count of 32-bit value to scan. Must be non-zero.
53 @param Value The value to search for in the target buffer.
54
55 @return The pointer to the first occurrence, or NULL if not found.
56
57 **/
58 CONST VOID *
59 EFIAPI
60 InternalMemScanMem32 (
61 IN CONST VOID *Buffer,
62 IN UINTN Length,
63 IN UINT32 Value
64 )
65 {
66 CONST UINT32 *Pointer;
67
68 Pointer = (CONST UINT32*)Buffer;
69 do {
70 if (*Pointer == Value) {
71 return Pointer;
72 }
73 ++Pointer;
74 } while (--Length != 0);
75 return NULL;
76 }
77
78 /**
79 Scans a target buffer for a 64-bit value, and returns a pointer to the
80 matching 64-bit value in the target buffer.
81
82 @param Buffer The pointer to the target buffer to scan.
83 @param Length The count of 64-bit value to scan. Must be non-zero.
84 @param Value The value to search for in the target buffer.
85
86 @return The pointer to the first occurrence, or NULL if not found.
87
88 **/
89 CONST VOID *
90 EFIAPI
91 InternalMemScanMem64 (
92 IN CONST VOID *Buffer,
93 IN UINTN Length,
94 IN UINT64 Value
95 )
96 {
97 CONST UINT64 *Pointer;
98
99 Pointer = (CONST UINT64*)Buffer;
100 do {
101 if (*Pointer == Value) {
102 return Pointer;
103 }
104 ++Pointer;
105 } while (--Length != 0);
106 return NULL;
107 }
108
109 /**
110 Checks whether the contents of a buffer are all zeros.
111
112 @param Buffer The pointer to the buffer to be checked.
113 @param Length The size of the buffer (in bytes) to be checked.
114
115 @retval TRUE Contents of the buffer are all zeros.
116 @retval FALSE Contents of the buffer are not all zeros.
117
118 **/
119 BOOLEAN
120 EFIAPI
121 InternalMemIsZeroBuffer (
122 IN CONST VOID *Buffer,
123 IN UINTN Length
124 )
125 {
126 CONST UINT8 *BufferData;
127 UINTN Index;
128
129 BufferData = Buffer;
130 for (Index = 0; Index < Length; Index++) {
131 if (BufferData[Index] != 0) {
132 return FALSE;
133 }
134 }
135 return TRUE;
136 }