]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/Unaligned.c
2 Unaligned access functions of BaseLib for IPF.
4 Copyright (c) 2006, Intel Corporation<BR>
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
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.
16 #include <BaseLibInternals.h>
19 Reads a 16-bit value from memory that may be unaligned.
21 This function returns the 16-bit value pointed to by Buffer. The function
22 guarantees that the read operation does not produce an alignment fault.
24 If the Buffer is NULL, then ASSERT().
26 @param Buffer Pointer to a 16-bit value that may be unaligned.
34 IN CONST UINT16
*Buffer
37 ASSERT (Buffer
!= NULL
);
39 return (UINT16
)(((UINT8
*)Buffer
)[0] | (((UINT8
*)Buffer
)[1] << 8));
43 Writes a 16-bit value to memory that may be unaligned.
45 This function writes the 16-bit value specified by Value to Buffer. Value is
46 returned. The function guarantees that the write operation does not produce
49 If the Buffer is NULL, then ASSERT().
51 @param Buffer Pointer to a 16-bit value that may be unaligned.
52 @param Value 16-bit value to write to Buffer.
64 ASSERT (Buffer
!= NULL
);
66 ((UINT8
*)Buffer
)[0] = (UINT8
)Value
;
67 ((UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
73 Reads a 24-bit value from memory that may be unaligned.
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.
78 If the Buffer is NULL, then ASSERT().
80 @param Buffer Pointer to a 24-bit value that may be unaligned.
82 @return The value read.
88 IN CONST UINT32
*Buffer
91 ASSERT (Buffer
!= NULL
);
94 ReadUnaligned16 ((UINT16
*)Buffer
) |
95 (((UINT8
*)Buffer
)[2] << 16)
100 Writes a 24-bit value to memory that may be unaligned.
102 This function writes the 24-bit value specified by Value to Buffer. Value is
103 returned. The function guarantees that the write operation does not produce
106 If the Buffer is NULL, then ASSERT().
108 @param Buffer Pointer to a 24-bit value that may be unaligned.
109 @param Value 24-bit value to write to Buffer.
111 @return The value written.
121 ASSERT (Buffer
!= NULL
);
123 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
124 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
129 Reads a 32-bit value from memory that may be unaligned.
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.
134 If the Buffer is NULL, then ASSERT().
136 @param Buffer Pointer to a 32-bit value that may be unaligned.
144 IN CONST UINT32
*Buffer
150 ASSERT (Buffer
!= NULL
);
152 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
153 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
155 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
159 Writes a 32-bit value to memory that may be unaligned.
161 This function writes the 32-bit value specified by Value to Buffer. Value is
162 returned. The function guarantees that the write operation does not produce
165 If the Buffer is NULL, then ASSERT().
167 @param Buffer Pointer to a 32-bit value that may be unaligned.
168 @param Value 32-bit value to write to Buffer.
180 ASSERT (Buffer
!= NULL
);
182 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
183 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
188 Reads a 64-bit value from memory that may be unaligned.
190 This function returns the 64-bit value pointed to by Buffer. The function
191 guarantees that the read operation does not produce an alignment fault.
193 If the Buffer is NULL, then ASSERT().
195 @param Buffer Pointer to a 64-bit value that may be unaligned.
203 IN CONST UINT64
*Buffer
209 ASSERT (Buffer
!= NULL
);
211 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
212 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
214 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
218 Writes a 64-bit value to memory that may be unaligned.
220 This function writes the 64-bit value specified by Value to Buffer. Value is
221 returned. The function guarantees that the write operation does not produce
224 If the Buffer is NULL, then ASSERT().
226 @param Buffer Pointer to a 64-bit value that may be unaligned.
227 @param Value 64-bit value to write to Buffer.
239 ASSERT (Buffer
!= NULL
);
241 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
242 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));