]>
Commit | Line | Data |
---|---|---|
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 | \r | |
10 | #include "BaseLibInternals.h"\r | |
11 | \r | |
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 | |
21 | @param Buffer A pointer to a 16-bit value that may be unaligned.\r | |
22 | \r | |
23 | @return The 16-bit value read from Buffer.\r | |
24 | \r | |
25 | **/\r | |
26 | UINT16\r | |
27 | EFIAPI\r | |
28 | ReadUnaligned16 (\r | |
29 | IN CONST UINT16 *Buffer\r | |
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 | |
46 | @param Buffer A pointer to a 16-bit value that may be unaligned.\r | |
47 | @param Value 16-bit value to write to Buffer.\r | |
48 | \r | |
49 | @return The 16-bit value to write to Buffer.\r | |
50 | \r | |
51 | **/\r | |
52 | UINT16\r | |
53 | EFIAPI\r | |
54 | WriteUnaligned16 (\r | |
55 | OUT UINT16 *Buffer,\r | |
56 | IN UINT16 Value\r | |
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 | |
72 | @param Buffer A pointer to a 24-bit value that may be unaligned.\r | |
73 | \r | |
74 | @return The 24-bit value read from Buffer.\r | |
75 | \r | |
76 | **/\r | |
77 | UINT32\r | |
78 | EFIAPI\r | |
79 | ReadUnaligned24 (\r | |
80 | IN CONST UINT32 *Buffer\r | |
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 | |
97 | @param Buffer A pointer to a 24-bit value that may be unaligned.\r | |
98 | @param Value 24-bit value to write to Buffer.\r | |
99 | \r | |
100 | @return The 24-bit value to write to Buffer.\r | |
101 | \r | |
102 | **/\r | |
103 | UINT32\r | |
104 | EFIAPI\r | |
105 | WriteUnaligned24 (\r | |
106 | OUT UINT32 *Buffer,\r | |
107 | IN UINT32 Value\r | |
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 | |
124 | @param Buffer A pointer to a 32-bit value that may be unaligned.\r | |
125 | \r | |
126 | @return The 32-bit value read from Buffer.\r | |
127 | \r | |
128 | **/\r | |
129 | UINT32\r | |
130 | EFIAPI\r | |
131 | ReadUnaligned32 (\r | |
132 | IN CONST UINT32 *Buffer\r | |
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 | |
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 | |
151 | \r | |
152 | @return The 32-bit value to write to Buffer.\r | |
153 | \r | |
154 | **/\r | |
155 | UINT32\r | |
156 | EFIAPI\r | |
157 | WriteUnaligned32 (\r | |
158 | OUT UINT32 *Buffer,\r | |
159 | IN UINT32 Value\r | |
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 | |
175 | @param Buffer A pointer to a 64-bit value that may be unaligned.\r | |
176 | \r | |
177 | @return The 64-bit value read from Buffer.\r | |
178 | \r | |
179 | **/\r | |
180 | UINT64\r | |
181 | EFIAPI\r | |
182 | ReadUnaligned64 (\r | |
183 | IN CONST UINT64 *Buffer\r | |
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 | |
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 | |
202 | \r | |
203 | @return The 64-bit value to write to Buffer.\r | |
204 | \r | |
205 | **/\r | |
206 | UINT64\r | |
207 | EFIAPI\r | |
208 | WriteUnaligned64 (\r | |
209 | OUT UINT64 *Buffer,\r | |
210 | IN UINT64 Value\r | |
211 | )\r | |
212 | {\r | |
213 | ASSERT (Buffer != NULL);\r | |
214 | \r | |
215 | return *Buffer = Value;\r | |
216 | }\r |