]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/Arm/ScanMemGeneric.c
MdePkg: Apply uncrustify changes
[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
43 ++Pointer;
44 } while (--Length != 0);
45
46 return NULL;
47 }
48
49 /**
50 Scans a target buffer for a 32-bit value, and returns a pointer to the
51 matching 32-bit value in the target buffer.
52
53 @param Buffer The pointer to the target buffer to scan.
54 @param Length The count of 32-bit value to scan. Must be non-zero.
55 @param Value The value to search for in the target buffer.
56
57 @return The pointer to the first occurrence, or NULL if not found.
58
59 **/
60 CONST VOID *
61 EFIAPI
62 InternalMemScanMem32 (
63 IN CONST VOID *Buffer,
64 IN UINTN Length,
65 IN UINT32 Value
66 )
67 {
68 CONST UINT32 *Pointer;
69
70 Pointer = (CONST UINT32 *)Buffer;
71 do {
72 if (*Pointer == Value) {
73 return Pointer;
74 }
75
76 ++Pointer;
77 } while (--Length != 0);
78
79 return NULL;
80 }
81
82 /**
83 Scans a target buffer for a 64-bit value, and returns a pointer to the
84 matching 64-bit value in the target buffer.
85
86 @param Buffer The pointer to the target buffer to scan.
87 @param Length The count of 64-bit value to scan. Must be non-zero.
88 @param Value The value to search for in the target buffer.
89
90 @return The pointer to the first occurrence, or NULL if not found.
91
92 **/
93 CONST VOID *
94 EFIAPI
95 InternalMemScanMem64 (
96 IN CONST VOID *Buffer,
97 IN UINTN Length,
98 IN UINT64 Value
99 )
100 {
101 CONST UINT64 *Pointer;
102
103 Pointer = (CONST UINT64 *)Buffer;
104 do {
105 if (*Pointer == Value) {
106 return Pointer;
107 }
108
109 ++Pointer;
110 } while (--Length != 0);
111
112 return NULL;
113 }
114
115 /**
116 Checks whether the contents of a buffer are all zeros.
117
118 @param Buffer The pointer to the buffer to be checked.
119 @param Length The size of the buffer (in bytes) to be checked.
120
121 @retval TRUE Contents of the buffer are all zeros.
122 @retval FALSE Contents of the buffer are not all zeros.
123
124 **/
125 BOOLEAN
126 EFIAPI
127 InternalMemIsZeroBuffer (
128 IN CONST VOID *Buffer,
129 IN UINTN Length
130 )
131 {
132 CONST UINT8 *BufferData;
133 UINTN Index;
134
135 BufferData = Buffer;
136 for (Index = 0; Index < Length; Index++) {
137 if (BufferData[Index] != 0) {
138 return FALSE;
139 }
140 }
141
142 return TRUE;
143 }