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