]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Unaligned.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseLib / Unaligned.c
1 /** @file
2 Unaligned access functions of BaseLib.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "BaseLibInternals.h"
10
11 /**
12 Reads a 16-bit value from memory that may be unaligned.
13
14 This function returns the 16-bit value pointed to by Buffer. The function
15 guarantees that the read operation does not produce an alignment fault.
16
17 If the Buffer is NULL, then ASSERT().
18
19 @param Buffer A pointer to a 16-bit value that may be unaligned.
20
21 @return The 16-bit value read from Buffer.
22
23 **/
24 UINT16
25 EFIAPI
26 ReadUnaligned16 (
27 IN CONST UINT16 *Buffer
28 )
29 {
30 ASSERT (Buffer != NULL);
31
32 return *Buffer;
33 }
34
35 /**
36 Writes a 16-bit value to memory that may be unaligned.
37
38 This function writes the 16-bit value specified by Value to Buffer. Value is
39 returned. The function guarantees that the write operation does not produce
40 an alignment fault.
41
42 If the Buffer is NULL, then ASSERT().
43
44 @param Buffer A pointer to a 16-bit value that may be unaligned.
45 @param Value 16-bit value to write to Buffer.
46
47 @return The 16-bit value to write to Buffer.
48
49 **/
50 UINT16
51 EFIAPI
52 WriteUnaligned16 (
53 OUT UINT16 *Buffer,
54 IN UINT16 Value
55 )
56 {
57 ASSERT (Buffer != NULL);
58
59 return *Buffer = Value;
60 }
61
62 /**
63 Reads a 24-bit value from memory that may be unaligned.
64
65 This function returns the 24-bit value pointed to by Buffer. The function
66 guarantees that the read operation does not produce an alignment fault.
67
68 If the Buffer is NULL, then ASSERT().
69
70 @param Buffer A pointer to a 24-bit value that may be unaligned.
71
72 @return The 24-bit value read from Buffer.
73
74 **/
75 UINT32
76 EFIAPI
77 ReadUnaligned24 (
78 IN CONST UINT32 *Buffer
79 )
80 {
81 ASSERT (Buffer != NULL);
82
83 return *Buffer & 0xffffff;
84 }
85
86 /**
87 Writes a 24-bit value to memory that may be unaligned.
88
89 This function writes the 24-bit value specified by Value to Buffer. Value is
90 returned. The function guarantees that the write operation does not produce
91 an alignment fault.
92
93 If the Buffer is NULL, then ASSERT().
94
95 @param Buffer A pointer to a 24-bit value that may be unaligned.
96 @param Value 24-bit value to write to Buffer.
97
98 @return The 24-bit value to write to Buffer.
99
100 **/
101 UINT32
102 EFIAPI
103 WriteUnaligned24 (
104 OUT UINT32 *Buffer,
105 IN UINT32 Value
106 )
107 {
108 ASSERT (Buffer != NULL);
109
110 *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value);
111 return Value;
112 }
113
114 /**
115 Reads a 32-bit value from memory that may be unaligned.
116
117 This function returns the 32-bit value pointed to by Buffer. The function
118 guarantees that the read operation does not produce an alignment fault.
119
120 If the Buffer is NULL, then ASSERT().
121
122 @param Buffer A pointer to a 32-bit value that may be unaligned.
123
124 @return The 32-bit value read from Buffer.
125
126 **/
127 UINT32
128 EFIAPI
129 ReadUnaligned32 (
130 IN CONST UINT32 *Buffer
131 )
132 {
133 ASSERT (Buffer != NULL);
134
135 return *Buffer;
136 }
137
138 /**
139 Writes a 32-bit value to memory that may be unaligned.
140
141 This function writes the 32-bit value specified by Value to Buffer. Value is
142 returned. The function guarantees that the write operation does not produce
143 an alignment fault.
144
145 If the Buffer is NULL, then ASSERT().
146
147 @param Buffer A pointer to a 32-bit value that may be unaligned.
148 @param Value The 32-bit value to write to Buffer.
149
150 @return The 32-bit value to write to Buffer.
151
152 **/
153 UINT32
154 EFIAPI
155 WriteUnaligned32 (
156 OUT UINT32 *Buffer,
157 IN UINT32 Value
158 )
159 {
160 ASSERT (Buffer != NULL);
161
162 return *Buffer = Value;
163 }
164
165 /**
166 Reads a 64-bit value from memory that may be unaligned.
167
168 This function returns the 64-bit value pointed to by Buffer. The function
169 guarantees that the read operation does not produce an alignment fault.
170
171 If the Buffer is NULL, then ASSERT().
172
173 @param Buffer A pointer to a 64-bit value that may be unaligned.
174
175 @return The 64-bit value read from Buffer.
176
177 **/
178 UINT64
179 EFIAPI
180 ReadUnaligned64 (
181 IN CONST UINT64 *Buffer
182 )
183 {
184 ASSERT (Buffer != NULL);
185
186 return *Buffer;
187 }
188
189 /**
190 Writes a 64-bit value to memory that may be unaligned.
191
192 This function writes the 64-bit value specified by Value to Buffer. Value is
193 returned. The function guarantees that the write operation does not produce
194 an alignment fault.
195
196 If the Buffer is NULL, then ASSERT().
197
198 @param Buffer A pointer to a 64-bit value that may be unaligned.
199 @param Value The 64-bit value to write to Buffer.
200
201 @return The 64-bit value to write to Buffer.
202
203 **/
204 UINT64
205 EFIAPI
206 WriteUnaligned64 (
207 OUT UINT64 *Buffer,
208 IN UINT64 Value
209 )
210 {
211 ASSERT (Buffer != NULL);
212
213 return *Buffer = Value;
214 }