]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/Unaligned.c
fix a issue caused by code review follow up
[mirror_edk2.git] / MdePkg / Library / BaseLib / Unaligned.c
CommitLineData
e1f414b6 1/** @file\r
2 Unaligned access functions of BaseLib.\r
3\r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
e1f414b6 13**/\r
14\r
1efcc4ae 15\r
f734a10a
A
16#include <BaseLibInternals.h>\r
17\r
e1f414b6 18\r
19/**\r
20 Reads a 16-bit value from memory that may be unaligned.\r
21\r
22 This function returns the 16-bit value pointed to by Buffer. The function\r
23 guarantees that the read operation does not produce an alignment fault.\r
24\r
25 If the Buffer is NULL, then ASSERT().\r
26\r
27 @param Buffer Pointer to a 16-bit value that may be unaligned.\r
28\r
38bbd3d9 29 @return Data read from Buffer.\r
e1f414b6 30\r
31**/\r
32UINT16\r
33EFIAPI\r
34ReadUnaligned16 (\r
35 IN CONST UINT16 *Buffer\r
36 )\r
37{\r
38 ASSERT (Buffer != NULL);\r
39\r
40 return *Buffer;\r
41}\r
42\r
43/**\r
44 Writes a 16-bit value to memory that may be unaligned.\r
45\r
46 This function writes the 16-bit value specified by Value to Buffer. Value is\r
47 returned. The function guarantees that the write operation does not produce\r
48 an alignment fault.\r
49\r
50 If the Buffer is NULL, then ASSERT().\r
51\r
52 @param Buffer Pointer to a 16-bit value that may be unaligned.\r
53 @param Value 16-bit value to write to Buffer.\r
54\r
38bbd3d9 55 @return Value written to Buffer\r
e1f414b6 56\r
57**/\r
58UINT16\r
59EFIAPI\r
60WriteUnaligned16 (\r
61 OUT UINT16 *Buffer,\r
62 IN UINT16 Value\r
63 )\r
64{\r
65 ASSERT (Buffer != NULL);\r
66\r
67 return *Buffer = Value;\r
68}\r
69\r
70/**\r
71 Reads a 24-bit value from memory that may be unaligned.\r
72\r
73 This function returns the 24-bit value pointed to by Buffer. The function\r
74 guarantees that the read operation does not produce an alignment fault.\r
75\r
76 If the Buffer is NULL, then ASSERT().\r
77\r
78 @param Buffer Pointer to a 24-bit value that may be unaligned.\r
79\r
38bbd3d9 80 @return The value read from Buffer.\r
e1f414b6 81\r
82**/\r
83UINT32\r
84EFIAPI\r
85ReadUnaligned24 (\r
86 IN CONST UINT32 *Buffer\r
87 )\r
88{\r
89 ASSERT (Buffer != NULL);\r
90\r
91 return *Buffer & 0xffffff;\r
92}\r
93\r
94/**\r
95 Writes a 24-bit value to memory that may be unaligned.\r
96\r
97 This function writes the 24-bit value specified by Value to Buffer. Value is\r
98 returned. The function guarantees that the write operation does not produce\r
99 an alignment fault.\r
100\r
101 If the Buffer is NULL, then ASSERT().\r
102\r
103 @param Buffer Pointer to a 24-bit value that may be unaligned.\r
104 @param Value 24-bit value to write to Buffer.\r
105\r
38bbd3d9 106 @return The value written to Buffer.\r
e1f414b6 107\r
108**/\r
109UINT32\r
110EFIAPI\r
111WriteUnaligned24 (\r
112 OUT UINT32 *Buffer,\r
113 IN UINT32 Value\r
114 )\r
115{\r
116 ASSERT (Buffer != NULL);\r
117\r
118 *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value);\r
119 return Value;\r
120}\r
121\r
122/**\r
123 Reads a 32-bit value from memory that may be unaligned.\r
124\r
125 This function returns the 32-bit value pointed to by Buffer. The function\r
126 guarantees that the read operation does not produce an alignment fault.\r
127\r
128 If the Buffer is NULL, then ASSERT().\r
129\r
130 @param Buffer Pointer to a 32-bit value that may be unaligned.\r
131\r
38bbd3d9 132 @return Data read from Buffer.\r
e1f414b6 133\r
134**/\r
135UINT32\r
136EFIAPI\r
137ReadUnaligned32 (\r
138 IN CONST UINT32 *Buffer\r
139 )\r
140{\r
141 ASSERT (Buffer != NULL);\r
142\r
143 return *Buffer;\r
144}\r
145\r
146/**\r
147 Writes a 32-bit value to memory that may be unaligned.\r
148\r
149 This function writes the 32-bit value specified by Value to Buffer. Value is\r
150 returned. The function guarantees that the write operation does not produce\r
151 an alignment fault.\r
152\r
153 If the Buffer is NULL, then ASSERT().\r
154\r
155 @param Buffer Pointer to a 32-bit value that may be unaligned.\r
156 @param Value 32-bit value to write to Buffer.\r
157\r
38bbd3d9 158 @return Value written to Buffer\r
e1f414b6 159\r
160**/\r
161UINT32\r
162EFIAPI\r
163WriteUnaligned32 (\r
164 OUT UINT32 *Buffer,\r
165 IN UINT32 Value\r
166 )\r
167{\r
168 ASSERT (Buffer != NULL);\r
169\r
170 return *Buffer = Value;\r
171}\r
172\r
173/**\r
174 Reads a 64-bit value from memory that may be unaligned.\r
175\r
176 This function returns the 64-bit value pointed to by Buffer. The function\r
177 guarantees that the read operation does not produce an alignment fault.\r
178\r
179 If the Buffer is NULL, then ASSERT().\r
180\r
181 @param Buffer Pointer to a 64-bit value that may be unaligned.\r
182\r
38bbd3d9 183 @return Data read from Buffer.\r
e1f414b6 184\r
185**/\r
186UINT64\r
187EFIAPI\r
188ReadUnaligned64 (\r
189 IN CONST UINT64 *Buffer\r
190 )\r
191{\r
192 ASSERT (Buffer != NULL);\r
193\r
194 return *Buffer;\r
195}\r
196\r
197/**\r
198 Writes a 64-bit value to memory that may be unaligned.\r
199\r
200 This function writes the 64-bit value specified by Value to Buffer. Value is\r
201 returned. The function guarantees that the write operation does not produce\r
202 an alignment fault.\r
203\r
204 If the Buffer is NULL, then ASSERT().\r
205\r
206 @param Buffer Pointer to a 64-bit value that may be unaligned.\r
207 @param Value 64-bit value to write to Buffer.\r
208\r
38bbd3d9 209 @return Value written to Buffer.\r
e1f414b6 210\r
211**/\r
212UINT64\r
213EFIAPI\r
214WriteUnaligned64 (\r
215 OUT UINT64 *Buffer,\r
216 IN UINT64 Value\r
217 )\r
218{\r
219 ASSERT (Buffer != NULL);\r
220\r
221 return *Buffer = Value;\r
222}\r