]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/Arm/ScanMemGeneric.c
MdePkg/BaseMemoryLibOptDxe: add accelerated ARM routines
[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 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php.
14
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17
18 **/
19
20 #include "../MemLibInternals.h"
21
22 /**
23 Scans a target buffer for a 16-bit value, and returns a pointer to the
24 matching 16-bit value in the target buffer.
25
26 @param Buffer The pointer to the target buffer to scan.
27 @param Length The count of 16-bit value to scan. Must be non-zero.
28 @param Value The value to search for in the target buffer.
29
30 @return The pointer to the first occurrence, or NULL if not found.
31
32 **/
33 CONST VOID *
34 EFIAPI
35 InternalMemScanMem16 (
36 IN CONST VOID *Buffer,
37 IN UINTN Length,
38 IN UINT16 Value
39 )
40 {
41 CONST UINT16 *Pointer;
42
43 Pointer = (CONST UINT16*)Buffer;
44 do {
45 if (*Pointer == Value) {
46 return Pointer;
47 }
48 ++Pointer;
49 } while (--Length != 0);
50 return NULL;
51 }
52
53 /**
54 Scans a target buffer for a 32-bit value, and returns a pointer to the
55 matching 32-bit value in the target buffer.
56
57 @param Buffer The pointer to the target buffer to scan.
58 @param Length The count of 32-bit value to scan. Must be non-zero.
59 @param Value The value to search for in the target buffer.
60
61 @return The pointer to the first occurrence, or NULL if not found.
62
63 **/
64 CONST VOID *
65 EFIAPI
66 InternalMemScanMem32 (
67 IN CONST VOID *Buffer,
68 IN UINTN Length,
69 IN UINT32 Value
70 )
71 {
72 CONST UINT32 *Pointer;
73
74 Pointer = (CONST UINT32*)Buffer;
75 do {
76 if (*Pointer == Value) {
77 return Pointer;
78 }
79 ++Pointer;
80 } while (--Length != 0);
81 return NULL;
82 }
83
84 /**
85 Scans a target buffer for a 64-bit value, and returns a pointer to the
86 matching 64-bit value in the target buffer.
87
88 @param Buffer The pointer to the target buffer to scan.
89 @param Length The count of 64-bit value to scan. Must be non-zero.
90 @param Value The value to search for in the target buffer.
91
92 @return The pointer to the first occurrence, or NULL if not found.
93
94 **/
95 CONST VOID *
96 EFIAPI
97 InternalMemScanMem64 (
98 IN CONST VOID *Buffer,
99 IN UINTN Length,
100 IN UINT64 Value
101 )
102 {
103 CONST UINT64 *Pointer;
104
105 Pointer = (CONST UINT64*)Buffer;
106 do {
107 if (*Pointer == Value) {
108 return Pointer;
109 }
110 ++Pointer;
111 } while (--Length != 0);
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 return TRUE;
142 }