]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/Unaligned.c
Check in the Pcd service Driver/PEIM according to the new way of generating PCD Database
[mirror_edk2.git] / MdePkg / Library / BaseLib / Unaligned.c
CommitLineData
878ddf1f 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 Reads a 16-bit value from memory that may be unaligned.\r
19\r
20 This function returns the 16-bit value pointed to by Buffer. The function\r
21 guarantees that the read operation does not produce an alignment fault.\r
22\r
23 If the Buffer is NULL, then ASSERT().\r
24\r
25 @param Buffer Pointer to a 16-bit value that may be unaligned.\r
26\r
27 @return *Uint16\r
28\r
29**/\r
30UINT16\r
31EFIAPI\r
32ReadUnaligned16 (\r
33 IN CONST UINT16 *Buffer\r
34 )\r
35{\r
36 return *Buffer;\r
37}\r
38\r
39/**\r
40 Writes a 16-bit value to memory that may be unaligned.\r
41\r
42 This function writes the 16-bit value specified by Value to Buffer. Value is\r
43 returned. The function guarantees that the write operation does not produce\r
44 an alignment fault.\r
45\r
46 If the Buffer is NULL, then ASSERT().\r
47\r
48 @param Buffer Pointer to a 16-bit value that may be unaligned.\r
49 @param Value 16-bit value to write to Buffer.\r
50\r
51 @return Value\r
52\r
53**/\r
54UINT16\r
55EFIAPI\r
56WriteUnaligned16 (\r
57 OUT UINT16 *Buffer,\r
58 IN UINT16 Value\r
59 )\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
72 @param Buffer Pointer to a 24-bit value that may be unaligned.\r
73\r
74 @return The value read.\r
75\r
76**/\r
77UINT32\r
78EFIAPI\r
79ReadUnaligned24 (\r
80 IN CONST UINT32 *Buffer\r
81 )\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 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 value written.\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 return *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value);\r
109}\r
110\r
111/**\r
112 Reads a 32-bit value from memory that may be unaligned.\r
113\r
114 This function returns the 32-bit value pointed to by Buffer. The function\r
115 guarantees that the read operation does not produce an alignment fault.\r
116\r
117 If the Buffer is NULL, then ASSERT().\r
118\r
119 @param Buffer Pointer to a 32-bit value that may be unaligned.\r
120\r
121 @return *Uint32\r
122\r
123**/\r
124UINT32\r
125EFIAPI\r
126ReadUnaligned32 (\r
127 IN CONST UINT32 *Buffer\r
128 )\r
129{\r
130 return *Buffer;\r
131}\r
132\r
133/**\r
134 Writes a 32-bit value to memory that may be unaligned.\r
135\r
136 This function writes the 32-bit value specified by Value to Buffer. Value is\r
137 returned. The function guarantees that the write operation does not produce\r
138 an alignment fault.\r
139\r
140 If the Buffer is NULL, then ASSERT().\r
141\r
142 @param Buffer Pointer to a 32-bit value that may be unaligned.\r
143 @param Value 32-bit value to write to Buffer.\r
144\r
145 @return Value\r
146\r
147**/\r
148UINT32\r
149EFIAPI\r
150WriteUnaligned32 (\r
151 OUT UINT32 *Buffer,\r
152 IN UINT32 Value\r
153 )\r
154{\r
155 return *Buffer = Value;\r
156}\r
157\r
158/**\r
159 Reads a 64-bit value from memory that may be unaligned.\r
160\r
161 This function returns the 64-bit value pointed to by Buffer. The function\r
162 guarantees that the read operation does not produce an alignment fault.\r
163\r
164 If the Buffer is NULL, then ASSERT().\r
165\r
166 @param Buffer Pointer to a 64-bit value that may be unaligned.\r
167\r
168 @return *Uint64\r
169\r
170**/\r
171UINT64\r
172EFIAPI\r
173ReadUnaligned64 (\r
174 IN CONST UINT64 *Buffer\r
175 )\r
176{\r
177 return *Buffer;\r
178}\r
179\r
180/**\r
181 Writes a 64-bit value to memory that may be unaligned.\r
182\r
183 This function writes the 64-bit value specified by Value to Buffer. Value is\r
184 returned. The function guarantees that the write operation does not produce\r
185 an alignment fault.\r
186\r
187 If the Buffer is NULL, then ASSERT().\r
188\r
189 @param Buffer Pointer to a 64-bit value that may be unaligned.\r
190 @param Value 64-bit value to write to Buffer.\r
191\r
192 @return Value\r
193\r
194**/\r
195UINT64\r
196EFIAPI\r
197WriteUnaligned64 (\r
198 OUT UINT64 *Buffer,\r
199 IN UINT64 Value\r
200 )\r
201{\r
202 return *Buffer = Value;\r
203}\r