]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
2c7e5c2f HT |
3 | Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | Unaligned.c\r | |
16 | \r | |
17 | Abstract: \r | |
18 | \r | |
19 | Unaligned access functions of BaseLib.\r | |
20 | \r | |
21 | --*/\r | |
22 | \r | |
c7f33ca4 | 23 | #include "BaseLibInternals.h"\r |
3eb9473e | 24 | \r |
25 | /**\r | |
26 | Reads a 16-bit value from memory that may be unaligned.\r | |
27 | \r | |
28 | This function returns the 16-bit value pointed to by Buffer. The function\r | |
29 | guarantees that the read operation does not produce an alignment fault.\r | |
30 | \r | |
31 | If the Buffer is NULL, then ASSERT().\r | |
32 | \r | |
33 | @param Buffer Pointer to a 16-bit value that may be unaligned.\r | |
34 | \r | |
35 | @return *Uint16\r | |
36 | \r | |
37 | **/\r | |
38 | UINT16\r | |
39 | EFIAPI\r | |
40 | ReadUnaligned16 (\r | |
41 | IN CONST UINT16 *Buffer\r | |
42 | )\r | |
43 | {\r | |
44 | ASSERT (Buffer != NULL);\r | |
45 | \r | |
46 | return *Buffer;\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | Writes a 16-bit value to memory that may be unaligned.\r | |
51 | \r | |
52 | This function writes the 16-bit value specified by Value to Buffer. Value is\r | |
53 | returned. The function guarantees that the write operation does not produce\r | |
54 | an alignment fault.\r | |
55 | \r | |
56 | If the Buffer is NULL, then ASSERT().\r | |
57 | \r | |
58 | @param Buffer Pointer to a 16-bit value that may be unaligned.\r | |
59 | @param Value 16-bit value to write to Buffer.\r | |
60 | \r | |
61 | @return Value\r | |
62 | \r | |
63 | **/\r | |
64 | UINT16\r | |
65 | EFIAPI\r | |
66 | WriteUnaligned16 (\r | |
67 | OUT UINT16 *Buffer,\r | |
68 | IN UINT16 Value\r | |
69 | )\r | |
70 | {\r | |
71 | ASSERT (Buffer != NULL);\r | |
72 | \r | |
73 | return *Buffer = Value;\r | |
74 | }\r | |
75 | \r | |
76 | /**\r | |
77 | Reads a 24-bit value from memory that may be unaligned.\r | |
78 | \r | |
79 | This function returns the 24-bit value pointed to by Buffer. The function\r | |
80 | guarantees that the read operation does not produce an alignment fault.\r | |
81 | \r | |
82 | If the Buffer is NULL, then ASSERT().\r | |
83 | \r | |
84 | @param Buffer Pointer to a 24-bit value that may be unaligned.\r | |
85 | \r | |
86 | @return The value read.\r | |
87 | \r | |
88 | **/\r | |
89 | UINT32\r | |
90 | EFIAPI\r | |
91 | ReadUnaligned24 (\r | |
92 | IN CONST UINT32 *Buffer\r | |
93 | )\r | |
94 | {\r | |
95 | ASSERT (Buffer != NULL);\r | |
96 | \r | |
97 | return *Buffer & 0xffffff;\r | |
98 | }\r | |
99 | \r | |
100 | /**\r | |
101 | Writes a 24-bit value to memory that may be unaligned.\r | |
102 | \r | |
103 | This function writes the 24-bit value specified by Value to Buffer. Value is\r | |
104 | returned. The function guarantees that the write operation does not produce\r | |
105 | an alignment fault.\r | |
106 | \r | |
107 | If the Buffer is NULL, then ASSERT().\r | |
108 | \r | |
109 | @param Buffer Pointer to a 24-bit value that may be unaligned.\r | |
110 | @param Value 24-bit value to write to Buffer.\r | |
111 | \r | |
112 | @return The value written.\r | |
113 | \r | |
114 | **/\r | |
115 | UINT32\r | |
116 | EFIAPI\r | |
117 | WriteUnaligned24 (\r | |
118 | OUT UINT32 *Buffer,\r | |
119 | IN UINT32 Value\r | |
120 | )\r | |
121 | {\r | |
122 | ASSERT (Buffer != NULL);\r | |
123 | \r | |
124 | *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value);\r | |
125 | return Value;\r | |
126 | }\r | |
127 | \r | |
128 | /**\r | |
129 | Reads a 32-bit value from memory that may be unaligned.\r | |
130 | \r | |
131 | This function returns the 32-bit value pointed to by Buffer. The function\r | |
132 | guarantees that the read operation does not produce an alignment fault.\r | |
133 | \r | |
134 | If the Buffer is NULL, then ASSERT().\r | |
135 | \r | |
136 | @param Buffer Pointer to a 32-bit value that may be unaligned.\r | |
137 | \r | |
138 | @return *Uint32\r | |
139 | \r | |
140 | **/\r | |
141 | UINT32\r | |
142 | EFIAPI\r | |
143 | ReadUnaligned32 (\r | |
144 | IN CONST UINT32 *Buffer\r | |
145 | )\r | |
146 | {\r | |
147 | ASSERT (Buffer != NULL);\r | |
148 | \r | |
149 | return *Buffer;\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Writes a 32-bit value to memory that may be unaligned.\r | |
154 | \r | |
155 | This function writes the 32-bit value specified by Value to Buffer. Value is\r | |
156 | returned. The function guarantees that the write operation does not produce\r | |
157 | an alignment fault.\r | |
158 | \r | |
159 | If the Buffer is NULL, then ASSERT().\r | |
160 | \r | |
161 | @param Buffer Pointer to a 32-bit value that may be unaligned.\r | |
162 | @param Value 32-bit value to write to Buffer.\r | |
163 | \r | |
164 | @return Value\r | |
165 | \r | |
166 | **/\r | |
167 | UINT32\r | |
168 | EFIAPI\r | |
169 | WriteUnaligned32 (\r | |
170 | OUT UINT32 *Buffer,\r | |
171 | IN UINT32 Value\r | |
172 | )\r | |
173 | {\r | |
174 | ASSERT (Buffer != NULL);\r | |
175 | \r | |
176 | return *Buffer = Value;\r | |
177 | }\r | |
178 | \r | |
179 | /**\r | |
180 | Reads a 64-bit value from memory that may be unaligned.\r | |
181 | \r | |
182 | This function returns the 64-bit value pointed to by Buffer. The function\r | |
183 | guarantees that the read operation does not produce an alignment fault.\r | |
184 | \r | |
185 | If the Buffer is NULL, then ASSERT().\r | |
186 | \r | |
187 | @param Buffer Pointer to a 64-bit value that may be unaligned.\r | |
188 | \r | |
189 | @return *Uint64\r | |
190 | \r | |
191 | **/\r | |
192 | UINT64\r | |
193 | EFIAPI\r | |
194 | ReadUnaligned64 (\r | |
195 | IN CONST UINT64 *Buffer\r | |
196 | )\r | |
197 | {\r | |
198 | ASSERT (Buffer != NULL);\r | |
199 | \r | |
200 | return *Buffer;\r | |
201 | }\r | |
202 | \r | |
203 | /**\r | |
204 | Writes a 64-bit value to memory that may be unaligned.\r | |
205 | \r | |
206 | This function writes the 64-bit value specified by Value to Buffer. Value is\r | |
207 | returned. The function guarantees that the write operation does not produce\r | |
208 | an alignment fault.\r | |
209 | \r | |
210 | If the Buffer is NULL, then ASSERT().\r | |
211 | \r | |
212 | @param Buffer Pointer to a 64-bit value that may be unaligned.\r | |
213 | @param Value 64-bit value to write to Buffer.\r | |
214 | \r | |
215 | @return Value\r | |
216 | \r | |
217 | **/\r | |
218 | UINT64\r | |
219 | EFIAPI\r | |
220 | WriteUnaligned64 (\r | |
221 | OUT UINT64 *Buffer,\r | |
222 | IN UINT64 Value\r | |
223 | )\r | |
224 | {\r | |
225 | ASSERT (Buffer != NULL);\r | |
226 | \r | |
227 | return *Buffer = Value;\r | |
228 | }\r |