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