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