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