]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Arm/Unaligned.c
2 Unaligned access functions of BaseLib for ARM.
4 volatile was added to work around optimization issues.
6 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "BaseLibInternals.h"
15 Reads a 16-bit value from memory that may be unaligned.
17 This function returns the 16-bit value pointed to by Buffer. The function
18 guarantees that the read operation does not produce an alignment fault.
20 If the Buffer is NULL, then ASSERT().
22 @param Buffer The pointer to a 16-bit value that may be unaligned.
24 @return The 16-bit value read from Buffer.
30 IN CONST UINT16
*Buffer
33 volatile UINT8 LowerByte
;
34 volatile UINT8 HigherByte
;
36 ASSERT (Buffer
!= NULL
);
38 LowerByte
= ((UINT8
*)Buffer
)[0];
39 HigherByte
= ((UINT8
*)Buffer
)[1];
41 return (UINT16
)(LowerByte
| (HigherByte
<< 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 The pointer to a 16-bit value that may be unaligned.
54 @param Value 16-bit value to write to Buffer.
56 @return The 16-bit value to write to Buffer.
66 ASSERT (Buffer
!= NULL
);
68 ((volatile UINT8
*)Buffer
)[0] = (UINT8
)Value
;
69 ((volatile 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 The pointer to a 24-bit value that may be unaligned.
84 @return The 24-bit value read from Buffer.
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 The pointer to a 24-bit value that may be unaligned.
111 @param Value 24-bit value to write to Buffer.
113 @return The 24-bit value to write to Buffer.
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 The pointer to a 32-bit value that may be unaligned.
140 @return The 32-bit value read from Buffer.
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 The pointer to a 32-bit value that may be unaligned.
170 @param Value 32-bit value to write to Buffer.
172 @return The 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 The pointer to a 64-bit value that may be unaligned.
199 @return The 64-bit value read from Buffer.
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 The pointer to a 64-bit value that may be unaligned.
229 @param Value 64-bit value to write to Buffer.
231 @return The 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));