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