]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/Unaligned.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ipf / Unaligned.c
1 /** @file
2 Unaligned access functions of BaseLib for IPF.
3
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
9
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.
12
13 **/
14
15
16 #include <BaseLibInternals.h>
17
18 /**
19 Reads a 16-bit value from memory that may be unaligned.
20
21 This function returns the 16-bit value pointed to by Buffer. The function
22 guarantees that the read operation does not produce an alignment fault.
23
24 If the Buffer is NULL, then ASSERT().
25
26 @param Buffer Pointer to a 16-bit value that may be unaligned.
27
28 @return *Uint16
29
30 **/
31 UINT16
32 EFIAPI
33 ReadUnaligned16 (
34 IN CONST UINT16 *Buffer
35 )
36 {
37 ASSERT (Buffer != NULL);
38
39 return (UINT16)(((UINT8*)Buffer)[0] | (((UINT8*)Buffer)[1] << 8));
40 }
41
42 /**
43 Writes a 16-bit value to memory that may be unaligned.
44
45 This function writes the 16-bit value specified by Value to Buffer. Value is
46 returned. The function guarantees that the write operation does not produce
47 an alignment fault.
48
49 If the Buffer is NULL, then ASSERT().
50
51 @param Buffer Pointer to a 16-bit value that may be unaligned.
52 @param Value 16-bit value to write to Buffer.
53
54 @return Value
55
56 **/
57 UINT16
58 EFIAPI
59 WriteUnaligned16 (
60 OUT UINT16 *Buffer,
61 IN UINT16 Value
62 )
63 {
64 ASSERT (Buffer != NULL);
65
66 ((UINT8*)Buffer)[0] = (UINT8)Value;
67 ((UINT8*)Buffer)[1] = (UINT8)(Value >> 8);
68
69 return Value;
70 }
71
72 /**
73 Reads a 24-bit value from memory that may be unaligned.
74
75 This function returns the 24-bit value pointed to by Buffer. The function
76 guarantees that the read operation does not produce an alignment fault.
77
78 If the Buffer is NULL, then ASSERT().
79
80 @param Buffer Pointer to a 24-bit value that may be unaligned.
81
82 @return The value read.
83
84 **/
85 UINT32
86 EFIAPI
87 ReadUnaligned24 (
88 IN CONST UINT32 *Buffer
89 )
90 {
91 ASSERT (Buffer != NULL);
92
93 return (UINT32)(
94 ReadUnaligned16 ((UINT16*)Buffer) |
95 (((UINT8*)Buffer)[2] << 16)
96 );
97 }
98
99 /**
100 Writes a 24-bit value to memory that may be unaligned.
101
102 This function writes the 24-bit value specified by Value to Buffer. Value is
103 returned. The function guarantees that the write operation does not produce
104 an alignment fault.
105
106 If the Buffer is NULL, then ASSERT().
107
108 @param Buffer Pointer to a 24-bit value that may be unaligned.
109 @param Value 24-bit value to write to Buffer.
110
111 @return The value written.
112
113 **/
114 UINT32
115 EFIAPI
116 WriteUnaligned24 (
117 OUT UINT32 *Buffer,
118 IN UINT32 Value
119 )
120 {
121 ASSERT (Buffer != NULL);
122
123 WriteUnaligned16 ((UINT16*)Buffer, (UINT16)Value);
124 *(UINT8*)((UINT16*)Buffer + 1) = (UINT8)(Value >> 16);
125 return Value;
126 }
127
128 /**
129 Reads a 32-bit value from memory that may be unaligned.
130
131 This function returns the 32-bit value pointed to by Buffer. The function
132 guarantees that the read operation does not produce an alignment fault.
133
134 If the Buffer is NULL, then ASSERT().
135
136 @param Buffer Pointer to a 32-bit value that may be unaligned.
137
138 @return *Uint32
139
140 **/
141 UINT32
142 EFIAPI
143 ReadUnaligned32 (
144 IN CONST UINT32 *Buffer
145 )
146 {
147 UINT16 LowerBytes;
148 UINT16 HigherBytes;
149
150 ASSERT (Buffer != NULL);
151
152 LowerBytes = ReadUnaligned16 ((UINT16*) Buffer);
153 HigherBytes = ReadUnaligned16 ((UINT16*) Buffer + 1);
154
155 return (UINT32) (LowerBytes | (HigherBytes << 16));
156 }
157
158 /**
159 Writes a 32-bit value to memory that may be unaligned.
160
161 This function writes the 32-bit value specified by Value to Buffer. Value is
162 returned. The function guarantees that the write operation does not produce
163 an alignment fault.
164
165 If the Buffer is NULL, then ASSERT().
166
167 @param Buffer Pointer to a 32-bit value that may be unaligned.
168 @param Value 32-bit value to write to Buffer.
169
170 @return Value
171
172 **/
173 UINT32
174 EFIAPI
175 WriteUnaligned32 (
176 OUT UINT32 *Buffer,
177 IN UINT32 Value
178 )
179 {
180 ASSERT (Buffer != NULL);
181
182 WriteUnaligned16 ((UINT16*)Buffer, (UINT16)Value);
183 WriteUnaligned16 ((UINT16*)Buffer + 1, (UINT16)(Value >> 16));
184 return Value;
185 }
186
187 /**
188 Reads a 64-bit value from memory that may be unaligned.
189
190 This function returns the 64-bit value pointed to by Buffer. The function
191 guarantees that the read operation does not produce an alignment fault.
192
193 If the Buffer is NULL, then ASSERT().
194
195 @param Buffer Pointer to a 64-bit value that may be unaligned.
196
197 @return *Uint64
198
199 **/
200 UINT64
201 EFIAPI
202 ReadUnaligned64 (
203 IN CONST UINT64 *Buffer
204 )
205 {
206 UINT32 LowerBytes;
207 UINT32 HigherBytes;
208
209 ASSERT (Buffer != NULL);
210
211 LowerBytes = ReadUnaligned32 ((UINT32*) Buffer);
212 HigherBytes = ReadUnaligned32 ((UINT32*) Buffer + 1);
213
214 return (UINT64) (LowerBytes | LShiftU64 (HigherBytes, 32));
215 }
216
217 /**
218 Writes a 64-bit value to memory that may be unaligned.
219
220 This function writes the 64-bit value specified by Value to Buffer. Value is
221 returned. The function guarantees that the write operation does not produce
222 an alignment fault.
223
224 If the Buffer is NULL, then ASSERT().
225
226 @param Buffer Pointer to a 64-bit value that may be unaligned.
227 @param Value 64-bit value to write to Buffer.
228
229 @return Value
230
231 **/
232 UINT64
233 EFIAPI
234 WriteUnaligned64 (
235 OUT UINT64 *Buffer,
236 IN UINT64 Value
237 )
238 {
239 ASSERT (Buffer != NULL);
240
241 WriteUnaligned32 ((UINT32*)Buffer, (UINT32)Value);
242 WriteUnaligned32 ((UINT32*)Buffer + 1, (UINT32)RShiftU64 (Value, 32));
243 return Value;
244 }