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