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