]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ipf/Unaligned.c
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 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
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.
21 #include "BaseLibInternals.h"
24 Reads a 16-bit value from memory that may be unaligned.
26 This function returns the 16-bit value pointed to by Buffer. The function
27 guarantees that the read operation does not produce an alignment fault.
29 If the Buffer is NULL, then ASSERT().
31 @param Buffer Pointer to a 16-bit value that may be unaligned.
39 IN CONST UINT16
*Buffer
42 ASSERT (Buffer
!= NULL
);
44 return (UINT16
)(((UINT8
*)Buffer
)[0] | (((UINT8
*)Buffer
)[1] << 8));
48 Writes a 16-bit value to memory that may be unaligned.
50 This function writes the 16-bit value specified by Value to Buffer. Value is
51 returned. The function guarantees that the write operation does not produce
54 If the Buffer is NULL, then ASSERT().
56 @param Buffer Pointer to a 16-bit value that may be unaligned.
57 @param Value 16-bit value to write to Buffer.
69 ASSERT (Buffer
!= NULL
);
71 ((UINT8
*)Buffer
)[0] = (UINT8
)Value
;
72 ((UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
78 Reads a 24-bit value from memory that may be unaligned.
80 This function returns the 24-bit value pointed to by Buffer. The function
81 guarantees that the read operation does not produce an alignment fault.
83 If the Buffer is NULL, then ASSERT().
85 @param Buffer Pointer to a 24-bit value that may be unaligned.
87 @return The value read.
93 IN CONST UINT32
*Buffer
96 ASSERT (Buffer
!= NULL
);
99 ReadUnaligned16 ((UINT16
*)Buffer
) |
100 (((UINT8
*)Buffer
)[2] << 16)
105 Writes a 24-bit value to memory that may be unaligned.
107 This function writes the 24-bit value specified by Value to Buffer. Value is
108 returned. The function guarantees that the write operation does not produce
111 If the Buffer is NULL, then ASSERT().
113 @param Buffer Pointer to a 24-bit value that may be unaligned.
114 @param Value 24-bit value to write to Buffer.
116 @return The value written.
126 ASSERT (Buffer
!= NULL
);
128 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
129 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
134 Reads a 32-bit value from memory that may be unaligned.
136 This function returns the 32-bit value pointed to by Buffer. The function
137 guarantees that the read operation does not produce an alignment fault.
139 If the Buffer is NULL, then ASSERT().
141 @param Buffer Pointer to a 32-bit value that may be unaligned.
149 IN CONST UINT32
*Buffer
155 ASSERT (Buffer
!= NULL
);
157 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
158 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
160 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
164 Writes a 32-bit value to memory that may be unaligned.
166 This function writes the 32-bit value specified by Value to Buffer. Value is
167 returned. The function guarantees that the write operation does not produce
170 If the Buffer is NULL, then ASSERT().
172 @param Buffer Pointer to a 32-bit value that may be unaligned.
173 @param Value 32-bit value to write to Buffer.
185 ASSERT (Buffer
!= NULL
);
187 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
188 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
193 Reads a 64-bit value from memory that may be unaligned.
195 This function returns the 64-bit value pointed to by Buffer. The function
196 guarantees that the read operation does not produce an alignment fault.
198 If the Buffer is NULL, then ASSERT().
200 @param Buffer Pointer to a 64-bit value that may be unaligned.
208 IN CONST UINT64
*Buffer
214 ASSERT (Buffer
!= NULL
);
216 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
217 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
219 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
223 Writes a 64-bit value to memory that may be unaligned.
225 This function writes the 64-bit value specified by Value to Buffer. Value is
226 returned. The function guarantees that the write operation does not produce
229 If the Buffer is NULL, then ASSERT().
231 @param Buffer Pointer to a 64-bit value that may be unaligned.
232 @param Value 64-bit value to write to Buffer.
244 ASSERT (Buffer
!= NULL
);
246 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
247 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));