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