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