]>
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 - 2008, Intel Corporation. All rights reserved.<BR>
5 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.
15 #include "BaseLibInternals.h"
18 Reads a 16-bit value from memory that may be unaligned.
20 This function returns the 16-bit value pointed to by Buffer. The function
21 guarantees that the read operation does not produce an alignment fault.
23 If the Buffer is NULL, then ASSERT().
25 @param Buffer Pointer to a 16-bit value that may be unaligned.
27 @return The 16-bit value read from Buffer.
33 IN CONST UINT16
*Buffer
36 ASSERT (Buffer
!= NULL
);
38 return (UINT16
)(((UINT8
*)Buffer
)[0] | (((UINT8
*)Buffer
)[1] << 8));
42 Writes a 16-bit value to memory that may be unaligned.
44 This function writes the 16-bit value specified by Value to Buffer. Value is
45 returned. The function guarantees that the write operation does not produce
48 If the Buffer is NULL, then ASSERT().
50 @param Buffer Pointer to a 16-bit value that may be unaligned.
51 @param Value 16-bit value to write to Buffer.
53 @return The 16-bit value to write to Buffer.
63 ASSERT (Buffer
!= NULL
);
65 ((UINT8
*)Buffer
)[0] = (UINT8
)Value
;
66 ((UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
72 Reads a 24-bit value from memory that may be unaligned.
74 This function returns the 24-bit value pointed to by Buffer. The function
75 guarantees that the read operation does not produce an alignment fault.
77 If the Buffer is NULL, then ASSERT().
79 @param Buffer Pointer to a 24-bit value that may be unaligned.
81 @return The 24-bit value read from Buffer.
87 IN CONST UINT32
*Buffer
90 ASSERT (Buffer
!= NULL
);
93 ReadUnaligned16 ((UINT16
*)Buffer
) |
94 (((UINT8
*)Buffer
)[2] << 16)
99 Writes a 24-bit value to memory that may be unaligned.
101 This function writes the 24-bit value specified by Value to Buffer. Value is
102 returned. The function guarantees that the write operation does not produce
105 If the Buffer is NULL, then ASSERT().
107 @param Buffer Pointer to a 24-bit value that may be unaligned.
108 @param Value 24-bit value to write to Buffer.
110 @return The 24-bit value to write to Buffer.
120 ASSERT (Buffer
!= NULL
);
122 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
123 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
128 Reads a 32-bit value from memory that may be unaligned.
130 This function returns the 32-bit value pointed to by Buffer. The function
131 guarantees that the read operation does not produce an alignment fault.
133 If the Buffer is NULL, then ASSERT().
135 @param Buffer Pointer to a 32-bit value that may be unaligned.
137 @return The 32-bit value read from Buffer.
143 IN CONST UINT32
*Buffer
149 ASSERT (Buffer
!= NULL
);
151 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
152 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
154 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
158 Writes a 32-bit value to memory that may be unaligned.
160 This function writes the 32-bit value specified by Value to Buffer. Value is
161 returned. The function guarantees that the write operation does not produce
164 If the Buffer is NULL, then ASSERT().
166 @param Buffer Pointer to a 32-bit value that may be unaligned.
167 @param Value 32-bit value to write to Buffer.
169 @return The 32-bit value to write to Buffer.
179 ASSERT (Buffer
!= NULL
);
181 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
182 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
187 Reads a 64-bit value from memory that may be unaligned.
189 This function returns the 64-bit value pointed to by Buffer. The function
190 guarantees that the read operation does not produce an alignment fault.
192 If the Buffer is NULL, then ASSERT().
194 @param Buffer Pointer to a 64-bit value that may be unaligned.
196 @return The 64-bit value read from Buffer.
202 IN CONST UINT64
*Buffer
208 ASSERT (Buffer
!= NULL
);
210 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
211 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
213 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
217 Writes a 64-bit value to memory that may be unaligned.
219 This function writes the 64-bit value specified by Value to Buffer. Value is
220 returned. The function guarantees that the write operation does not produce
223 If the Buffer is NULL, then ASSERT().
225 @param Buffer Pointer to a 64-bit value that may be unaligned.
226 @param Value 64-bit value to write to Buffer.
228 @return The 64-bit value to write to Buffer.
238 ASSERT (Buffer
!= NULL
);
240 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
241 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));