]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Arm/Unaligned.c
ac3ac95766c85258eb77ceb3f720cb8e83f6cf04
2 Unaligned access functions of BaseLib for ARM.
4 volatile was added to work around optimization issues.
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
7 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
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 The pointer to a 16-bit value that may be unaligned.
30 @return The 16-bit value read from Buffer.
36 IN CONST UINT16
*Buffer
39 volatile UINT8 LowerByte
;
40 volatile UINT8 HigherByte
;
42 ASSERT (Buffer
!= NULL
);
44 LowerByte
= ((UINT8
*)Buffer
)[0];
45 HigherByte
= ((UINT8
*)Buffer
)[1];
47 return (UINT16
)(LowerByte
| (HigherByte
<< 8));
51 Writes a 16-bit value to memory that may be unaligned.
53 This function writes the 16-bit value specified by Value to Buffer. Value is
54 returned. The function guarantees that the write operation does not produce
57 If the Buffer is NULL, then ASSERT().
59 @param Buffer The pointer to a 16-bit value that may be unaligned.
60 @param Value 16-bit value to write to Buffer.
62 @return The 16-bit value to write to Buffer.
72 ASSERT (Buffer
!= NULL
);
74 ((volatile UINT8
*)Buffer
)[0] = (UINT8
)Value
;
75 ((volatile UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
81 Reads a 24-bit value from memory that may be unaligned.
83 This function returns the 24-bit value pointed to by Buffer. The function
84 guarantees that the read operation does not produce an alignment fault.
86 If the Buffer is NULL, then ASSERT().
88 @param Buffer The pointer to a 24-bit value that may be unaligned.
90 @return The 24-bit value read from Buffer.
96 IN CONST UINT32
*Buffer
99 ASSERT (Buffer
!= NULL
);
102 ReadUnaligned16 ((UINT16
*)Buffer
) |
103 (((UINT8
*)Buffer
)[2] << 16)
108 Writes a 24-bit value to memory that may be unaligned.
110 This function writes the 24-bit value specified by Value to Buffer. Value is
111 returned. The function guarantees that the write operation does not produce
114 If the Buffer is NULL, then ASSERT().
116 @param Buffer The pointer to a 24-bit value that may be unaligned.
117 @param Value 24-bit value to write to Buffer.
119 @return The 24-bit value to write to Buffer.
129 ASSERT (Buffer
!= NULL
);
131 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
132 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
137 Reads a 32-bit value from memory that may be unaligned.
139 This function returns the 32-bit value pointed to by Buffer. The function
140 guarantees that the read operation does not produce an alignment fault.
142 If the Buffer is NULL, then ASSERT().
144 @param Buffer The pointer to a 32-bit value that may be unaligned.
146 @return The 32-bit value read from Buffer.
152 IN CONST UINT32
*Buffer
158 ASSERT (Buffer
!= NULL
);
160 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
161 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
163 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
167 Writes a 32-bit value to memory that may be unaligned.
169 This function writes the 32-bit value specified by Value to Buffer. Value is
170 returned. The function guarantees that the write operation does not produce
173 If the Buffer is NULL, then ASSERT().
175 @param Buffer Pointer to a 32-bit value that may be unaligned.
176 @param Value 32-bit value to write to Buffer.
178 @return The 32-bit value to write to Buffer.
188 ASSERT (Buffer
!= NULL
);
190 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
191 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
196 Reads a 64-bit value from memory that may be unaligned.
198 This function returns the 64-bit value pointed to by Buffer. The function
199 guarantees that the read operation does not produce an alignment fault.
201 If the Buffer is NULL, then ASSERT().
203 @param Buffer The pointer to a 64-bit value that may be unaligned.
205 @return The 64-bit value read from Buffer.
211 IN CONST UINT64
*Buffer
217 ASSERT (Buffer
!= NULL
);
219 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
220 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
222 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
226 Writes a 64-bit value to memory that may be unaligned.
228 This function writes the 64-bit value specified by Value to Buffer. Value is
229 returned. The function guarantees that the write operation does not produce
232 If the Buffer is NULL, then ASSERT().
234 @param Buffer The pointer to a 64-bit value that may be unaligned.
235 @param Value 64-bit value to write to Buffer.
237 @return The 64-bit value to write to Buffer.
247 ASSERT (Buffer
!= NULL
);
249 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
250 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));