TianoCore EDK2 master
Unaligned.c
Go to the documentation of this file.
1
12#include "BaseLibInternals.h"
13
27UINT16
28EFIAPI
30 IN CONST UINT16 *Buffer
31 )
32{
33 volatile UINT8 LowerByte;
34 volatile UINT8 HigherByte;
35
36 ASSERT (Buffer != NULL);
37
38 LowerByte = ((UINT8 *)Buffer)[0];
39 HigherByte = ((UINT8 *)Buffer)[1];
40
41 return (UINT16)(LowerByte | (HigherByte << 8));
42}
43
59UINT16
60EFIAPI
62 OUT UINT16 *Buffer,
63 IN UINT16 Value
64 )
65{
66 ASSERT (Buffer != NULL);
67
68 ((volatile UINT8 *)Buffer)[0] = (UINT8)Value;
69 ((volatile UINT8 *)Buffer)[1] = (UINT8)(Value >> 8);
70
71 return Value;
72}
73
87UINT32
88EFIAPI
90 IN CONST UINT32 *Buffer
91 )
92{
93 ASSERT (Buffer != NULL);
94
95 return (UINT32)(
96 ReadUnaligned16 ((UINT16 *)Buffer) |
97 (((UINT8 *)Buffer)[2] << 16)
98 );
99}
100
116UINT32
117EFIAPI
119 OUT UINT32 *Buffer,
120 IN UINT32 Value
121 )
122{
123 ASSERT (Buffer != NULL);
124
125 WriteUnaligned16 ((UINT16 *)Buffer, (UINT16)Value);
126 *(UINT8 *)((UINT16 *)Buffer + 1) = (UINT8)(Value >> 16);
127 return Value;
128}
129
143UINT32
144EFIAPI
146 IN CONST UINT32 *Buffer
147 )
148{
149 UINT16 LowerBytes;
150 UINT16 HigherBytes;
151
152 ASSERT (Buffer != NULL);
153
154 LowerBytes = ReadUnaligned16 ((UINT16 *)Buffer);
155 HigherBytes = ReadUnaligned16 ((UINT16 *)Buffer + 1);
156
157 return (UINT32)(LowerBytes | (HigherBytes << 16));
158}
159
175UINT32
176EFIAPI
178 OUT UINT32 *Buffer,
179 IN UINT32 Value
180 )
181{
182 ASSERT (Buffer != NULL);
183
184 WriteUnaligned16 ((UINT16 *)Buffer, (UINT16)Value);
185 WriteUnaligned16 ((UINT16 *)Buffer + 1, (UINT16)(Value >> 16));
186 return Value;
187}
188
202UINT64
203EFIAPI
205 IN CONST UINT64 *Buffer
206 )
207{
208 UINT32 LowerBytes;
209 UINT32 HigherBytes;
210
211 ASSERT (Buffer != NULL);
212
213 LowerBytes = ReadUnaligned32 ((UINT32 *)Buffer);
214 HigherBytes = ReadUnaligned32 ((UINT32 *)Buffer + 1);
215
216 return (UINT64)(LowerBytes | LShiftU64 (HigherBytes, 32));
217}
218
234UINT64
235EFIAPI
237 OUT UINT64 *Buffer,
238 IN UINT64 Value
239 )
240{
241 ASSERT (Buffer != NULL);
242
243 WriteUnaligned32 ((UINT32 *)Buffer, (UINT32)Value);
244 WriteUnaligned32 ((UINT32 *)Buffer + 1, (UINT32)RShiftU64 (Value, 32));
245 return Value;
246}
UINT32 EFIAPI WriteUnaligned24(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:118
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
Definition: Unaligned.c:204
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
Definition: Unaligned.c:29
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
Definition: Unaligned.c:61
UINT32 EFIAPI ReadUnaligned24(IN CONST UINT32 *Buffer)
Definition: Unaligned.c:89
UINT64 EFIAPI WriteUnaligned64(OUT UINT64 *Buffer, IN UINT64 Value)
Definition: Unaligned.c:236
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
Definition: Unaligned.c:145
#define NULL
Definition: Base.h:312
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
#define ASSERT(Expression)
Definition: DebugLib.h:391