]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/Unaligned.c
1c4a937ab9ad1663ee21b27dee5a00aff00ebf1b
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.
13 Module Name: Unaligned.c
18 // Include common header file for this module.
20 #include <BaseLibInternals.h>
23 Reads a 16-bit value from memory that may be unaligned.
25 This function returns the 16-bit value pointed to by Buffer. The function
26 guarantees that the read operation does not produce an alignment fault.
28 If the Buffer is NULL, then ASSERT().
30 @param Buffer Pointer to a 16-bit value that may be unaligned.
38 IN CONST UINT16
*Buffer
41 ASSERT (Buffer
!= NULL
);
43 return (UINT16
)(((UINT8
*)Buffer
)[0] | (((UINT8
*)Buffer
)[1] << 8));
47 Writes a 16-bit value to memory that may be unaligned.
49 This function writes the 16-bit value specified by Value to Buffer. Value is
50 returned. The function guarantees that the write operation does not produce
53 If the Buffer is NULL, then ASSERT().
55 @param Buffer Pointer to a 16-bit value that may be unaligned.
56 @param Value 16-bit value to write to Buffer.
68 ASSERT (Buffer
!= NULL
);
70 ((UINT8
*)Buffer
)[0] = (UINT8
)Value
;
71 ((UINT8
*)Buffer
)[1] = (UINT8
)(Value
>> 8);
77 Reads a 24-bit value from memory that may be unaligned.
79 This function returns the 24-bit value pointed to by Buffer. The function
80 guarantees that the read operation does not produce an alignment fault.
82 If the Buffer is NULL, then ASSERT().
84 @param Buffer Pointer to a 24-bit value that may be unaligned.
86 @return The value read.
92 IN CONST UINT32
*Buffer
95 ASSERT (Buffer
!= NULL
);
98 ReadUnaligned16 ((UINT16
*)Buffer
) |
99 (((UINT8
*)Buffer
)[2] << 16)
104 Writes a 24-bit value to memory that may be unaligned.
106 This function writes the 24-bit value specified by Value to Buffer. Value is
107 returned. The function guarantees that the write operation does not produce
110 If the Buffer is NULL, then ASSERT().
112 @param Buffer Pointer to a 24-bit value that may be unaligned.
113 @param Value 24-bit value to write to Buffer.
115 @return The value written.
125 ASSERT (Buffer
!= NULL
);
127 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
128 *(UINT8
*)((UINT16
*)Buffer
+ 1) = (UINT8
)(Value
>> 16);
133 Reads a 32-bit value from memory that may be unaligned.
135 This function returns the 32-bit value pointed to by Buffer. The function
136 guarantees that the read operation does not produce an alignment fault.
138 If the Buffer is NULL, then ASSERT().
140 @param Buffer Pointer to a 32-bit value that may be unaligned.
148 IN CONST UINT32
*Buffer
154 ASSERT (Buffer
!= NULL
);
156 LowerBytes
= ReadUnaligned16 ((UINT16
*) Buffer
);
157 HigherBytes
= ReadUnaligned16 ((UINT16
*) Buffer
+ 1);
159 return (UINT32
) (LowerBytes
| (HigherBytes
<< 16));
163 Writes a 32-bit value to memory that may be unaligned.
165 This function writes the 32-bit value specified by Value to Buffer. Value is
166 returned. The function guarantees that the write operation does not produce
169 If the Buffer is NULL, then ASSERT().
171 @param Buffer Pointer to a 32-bit value that may be unaligned.
172 @param Value 32-bit value to write to Buffer.
184 ASSERT (Buffer
!= NULL
);
186 WriteUnaligned16 ((UINT16
*)Buffer
, (UINT16
)Value
);
187 WriteUnaligned16 ((UINT16
*)Buffer
+ 1, (UINT16
)(Value
>> 16));
192 Reads a 64-bit value from memory that may be unaligned.
194 This function returns the 64-bit value pointed to by Buffer. The function
195 guarantees that the read operation does not produce an alignment fault.
197 If the Buffer is NULL, then ASSERT().
199 @param Buffer Pointer to a 64-bit value that may be unaligned.
207 IN CONST UINT64
*Buffer
213 ASSERT (Buffer
!= NULL
);
215 LowerBytes
= ReadUnaligned32 ((UINT32
*) Buffer
);
216 HigherBytes
= ReadUnaligned32 ((UINT32
*) Buffer
+ 1);
218 return (UINT64
) (LowerBytes
| LShiftU64 (HigherBytes
, 32));
222 Writes a 64-bit value to memory that may be unaligned.
224 This function writes the 64-bit value specified by Value to Buffer. Value is
225 returned. The function guarantees that the write operation does not produce
228 If the Buffer is NULL, then ASSERT().
230 @param Buffer Pointer to a 64-bit value that may be unaligned.
231 @param Value 64-bit value to write to Buffer.
243 ASSERT (Buffer
!= NULL
);
245 WriteUnaligned32 ((UINT32
*)Buffer
, (UINT32
)Value
);
246 WriteUnaligned32 ((UINT32
*)Buffer
+ 1, (UINT32
)RShiftU64 (Value
, 32));