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