]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Unaligned.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / BaseLib / Unaligned.c
1 /** @file
2 Unaligned access functions of BaseLib.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // Include common header file for this module.
17 //
18 #include <BaseLibInternals.h>
19
20
21 /**
22 Reads a 16-bit value from memory that may be unaligned.
23
24 This function returns the 16-bit value pointed to by Buffer. The function
25 guarantees that the read operation does not produce an alignment fault.
26
27 If the Buffer is NULL, then ASSERT().
28
29 @param Buffer Pointer to a 16-bit value that may be unaligned.
30
31 @return *Uint16
32
33 **/
34 UINT16
35 EFIAPI
36 ReadUnaligned16 (
37 IN CONST UINT16 *Buffer
38 )
39 {
40 ASSERT (Buffer != NULL);
41
42 return *Buffer;
43 }
44
45 /**
46 Writes a 16-bit value to memory that may be unaligned.
47
48 This function writes the 16-bit value specified by Value to Buffer. Value is
49 returned. The function guarantees that the write operation does not produce
50 an alignment fault.
51
52 If the Buffer is NULL, then ASSERT().
53
54 @param Buffer Pointer to a 16-bit value that may be unaligned.
55 @param Value 16-bit value to write to Buffer.
56
57 @return Value
58
59 **/
60 UINT16
61 EFIAPI
62 WriteUnaligned16 (
63 OUT UINT16 *Buffer,
64 IN UINT16 Value
65 )
66 {
67 ASSERT (Buffer != NULL);
68
69 return *Buffer = Value;
70 }
71
72 /**
73 Reads a 24-bit value from memory that may be unaligned.
74
75 This function returns the 24-bit value pointed to by Buffer. The function
76 guarantees that the read operation does not produce an alignment fault.
77
78 If the Buffer is NULL, then ASSERT().
79
80 @param Buffer Pointer to a 24-bit value that may be unaligned.
81
82 @return The value read.
83
84 **/
85 UINT32
86 EFIAPI
87 ReadUnaligned24 (
88 IN CONST UINT32 *Buffer
89 )
90 {
91 ASSERT (Buffer != NULL);
92
93 return *Buffer & 0xffffff;
94 }
95
96 /**
97 Writes a 24-bit value to memory that may be unaligned.
98
99 This function writes the 24-bit value specified by Value to Buffer. Value is
100 returned. The function guarantees that the write operation does not produce
101 an alignment fault.
102
103 If the Buffer is NULL, then ASSERT().
104
105 @param Buffer Pointer to a 24-bit value that may be unaligned.
106 @param Value 24-bit value to write to Buffer.
107
108 @return The value written.
109
110 **/
111 UINT32
112 EFIAPI
113 WriteUnaligned24 (
114 OUT UINT32 *Buffer,
115 IN UINT32 Value
116 )
117 {
118 ASSERT (Buffer != NULL);
119
120 *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value);
121 return Value;
122 }
123
124 /**
125 Reads a 32-bit value from memory that may be unaligned.
126
127 This function returns the 32-bit value pointed to by Buffer. The function
128 guarantees that the read operation does not produce an alignment fault.
129
130 If the Buffer is NULL, then ASSERT().
131
132 @param Buffer Pointer to a 32-bit value that may be unaligned.
133
134 @return *Uint32
135
136 **/
137 UINT32
138 EFIAPI
139 ReadUnaligned32 (
140 IN CONST UINT32 *Buffer
141 )
142 {
143 ASSERT (Buffer != NULL);
144
145 return *Buffer;
146 }
147
148 /**
149 Writes a 32-bit value to memory that may be unaligned.
150
151 This function writes the 32-bit value specified by Value to Buffer. Value is
152 returned. The function guarantees that the write operation does not produce
153 an alignment fault.
154
155 If the Buffer is NULL, then ASSERT().
156
157 @param Buffer Pointer to a 32-bit value that may be unaligned.
158 @param Value 32-bit value to write to Buffer.
159
160 @return Value
161
162 **/
163 UINT32
164 EFIAPI
165 WriteUnaligned32 (
166 OUT UINT32 *Buffer,
167 IN UINT32 Value
168 )
169 {
170 ASSERT (Buffer != NULL);
171
172 return *Buffer = Value;
173 }
174
175 /**
176 Reads a 64-bit value from memory that may be unaligned.
177
178 This function returns the 64-bit value pointed to by Buffer. The function
179 guarantees that the read operation does not produce an alignment fault.
180
181 If the Buffer is NULL, then ASSERT().
182
183 @param Buffer Pointer to a 64-bit value that may be unaligned.
184
185 @return *Uint64
186
187 **/
188 UINT64
189 EFIAPI
190 ReadUnaligned64 (
191 IN CONST UINT64 *Buffer
192 )
193 {
194 ASSERT (Buffer != NULL);
195
196 return *Buffer;
197 }
198
199 /**
200 Writes a 64-bit value to memory that may be unaligned.
201
202 This function writes the 64-bit value specified by Value to Buffer. Value is
203 returned. The function guarantees that the write operation does not produce
204 an alignment fault.
205
206 If the Buffer is NULL, then ASSERT().
207
208 @param Buffer Pointer to a 64-bit value that may be unaligned.
209 @param Value 64-bit value to write to Buffer.
210
211 @return Value
212
213 **/
214 UINT64
215 EFIAPI
216 WriteUnaligned64 (
217 OUT UINT64 *Buffer,
218 IN UINT64 Value
219 )
220 {
221 ASSERT (Buffer != NULL);
222
223 return *Buffer = Value;
224 }