]>
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 common header file for this module.
18 #include <BaseLibInternals.h>
21 Reads a 16-bit value from memory that may be unaligned.
23 This function returns the 16-bit value pointed to by Buffer. The function
24 guarantees that the read operation does not produce an alignment fault.
26 If the Buffer is NULL, then ASSERT().
28 @param Buffer Pointer to a 16-bit value that may be unaligned.
36 IN CONST UINT16
*Buffer
39 ASSERT (Buffer
!= NULL
);
41 return (UINT16
)(((UINT8
*)Buffer
)[0] | (((UINT8
*)Buffer
)[1] << 8));
45 Writes a 16-bit value to memory that may be unaligned.
47 This function writes the 16-bit value specified by Value to Buffer. Value is
48 returned. The function guarantees that the write operation does not produce
51 If the Buffer is NULL, then ASSERT().
53 @param Buffer Pointer to a 16-bit value that may be unaligned.
54 @param Value 16-bit value to write to Buffer.
66 ASSERT (Buffer
!= NULL
);
68 ((UINT8
*)Buffer
)[0] = (UINT8
)Value
;
69 ((UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
75 Reads a 24-bit value from memory that may be unaligned.
77 This function returns the 24-bit value pointed to by Buffer. The function
78 guarantees that the read operation does not produce an alignment fault.
80 If the Buffer is NULL, then ASSERT().
82 @param Buffer Pointer to a 24-bit value that may be unaligned.
84 @return The value read.
90 IN CONST UINT32
*Buffer
93 ASSERT (Buffer
!= NULL
);
96 ReadUnaligned16 ((UINT16
*)Buffer
) |
97 (((UINT8
*)Buffer
)[2] << 16)
102 Writes a 24-bit value to memory that may be unaligned.
104 This function writes the 24-bit value specified by Value to Buffer. Value is
105 returned. The function guarantees that the write operation does not produce
108 If the Buffer is NULL, then ASSERT().
110 @param Buffer Pointer to a 24-bit value that may be unaligned.
111 @param Value 24-bit value to write to Buffer.
113 @return The value written.
123 ASSERT (Buffer
!= NULL
);
125 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
126 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
131 Reads a 32-bit value from memory that may be unaligned.
133 This function returns the 32-bit value pointed to by Buffer. The function
134 guarantees that the read operation does not produce an alignment fault.
136 If the Buffer is NULL, then ASSERT().
138 @param Buffer Pointer to a 32-bit value that may be unaligned.
146 IN CONST UINT32
*Buffer
152 ASSERT (Buffer
!= NULL
);
154 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
155 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
157 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
161 Writes a 32-bit value to memory that may be unaligned.
163 This function writes the 32-bit value specified by Value to Buffer. Value is
164 returned. The function guarantees that the write operation does not produce
167 If the Buffer is NULL, then ASSERT().
169 @param Buffer Pointer to a 32-bit value that may be unaligned.
170 @param Value 32-bit value to write to Buffer.
182 ASSERT (Buffer
!= NULL
);
184 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
185 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
190 Reads a 64-bit value from memory that may be unaligned.
192 This function returns the 64-bit value pointed to by Buffer. The function
193 guarantees that the read operation does not produce an alignment fault.
195 If the Buffer is NULL, then ASSERT().
197 @param Buffer Pointer to a 64-bit value that may be unaligned.
205 IN CONST UINT64
*Buffer
211 ASSERT (Buffer
!= NULL
);
213 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
214 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
216 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
220 Writes a 64-bit value to memory that may be unaligned.
222 This function writes the 64-bit value specified by Value to Buffer. Value is
223 returned. The function guarantees that the write operation does not produce
226 If the Buffer is NULL, then ASSERT().
228 @param Buffer Pointer to a 64-bit value that may be unaligned.
229 @param Value 64-bit value to write to Buffer.
241 ASSERT (Buffer
!= NULL
);
243 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
244 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));