]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Declaration of internal functions in BaseLib.\r | |
3 | \r | |
3cb0a311 | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
bb817c56 | 5 | This program and the accompanying materials\r |
e1f414b6 | 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 | |
127010dd | 8 | http://opensource.org/licenses/bsd-license.php.\r |
e1f414b6 | 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 | |
e1f414b6 | 13 | **/\r |
14 | \r | |
15 | #ifndef __BASE_LIB_INTERNALS__\r | |
16 | #define __BASE_LIB_INTERNALS__\r | |
17 | \r | |
f734a10a A |
18 | #include <Base.h>\r |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
f734a10a A |
22 | #include <Library/PcdLib.h>\r |
23 | \r | |
e1f414b6 | 24 | //\r |
25 | // Math functions\r | |
26 | //\r | |
27 | \r | |
28 | /**\r | |
29 | Shifts a 64-bit integer left between 0 and 63 bits. The low bits\r | |
30 | are filled with zeros. The shifted value is returned.\r | |
31 | \r | |
32 | This function shifts the 64-bit value Operand to the left by Count bits. The\r | |
33 | low Count bits are set to zero. The shifted value is returned.\r | |
34 | \r | |
35 | @param Operand The 64-bit operand to shift left.\r | |
36 | @param Count The number of bits to shift left.\r | |
37 | \r | |
38 | @return Operand << Count\r | |
39 | \r | |
40 | **/\r | |
41 | UINT64\r | |
42 | EFIAPI\r | |
43 | InternalMathLShiftU64 (\r | |
44 | IN UINT64 Operand,\r | |
45 | IN UINTN Count\r | |
46 | );\r | |
47 | \r | |
48 | /**\r | |
127010dd | 49 | Shifts a 64-bit integer right between 0 and 63 bits. The high bits\r |
e1f414b6 | 50 | are filled with zeros. The shifted value is returned.\r |
51 | \r | |
52 | This function shifts the 64-bit value Operand to the right by Count bits. The\r | |
53 | high Count bits are set to zero. The shifted value is returned.\r | |
54 | \r | |
55 | @param Operand The 64-bit operand to shift right.\r | |
56 | @param Count The number of bits to shift right.\r | |
57 | \r | |
58 | @return Operand >> Count\r | |
59 | \r | |
60 | **/\r | |
61 | UINT64\r | |
62 | EFIAPI\r | |
63 | InternalMathRShiftU64 (\r | |
64 | IN UINT64 Operand,\r | |
65 | IN UINTN Count\r | |
66 | );\r | |
67 | \r | |
68 | /**\r | |
69 | Shifts a 64-bit integer right between 0 and 63 bits. The high bits\r | |
70 | are filled with original integer's bit 63. The shifted value is returned.\r | |
71 | \r | |
72 | This function shifts the 64-bit value Operand to the right by Count bits. The\r | |
73 | high Count bits are set to bit 63 of Operand. The shifted value is returned.\r | |
74 | \r | |
75 | @param Operand The 64-bit operand to shift right.\r | |
76 | @param Count The number of bits to shift right.\r | |
77 | \r | |
78 | @return Operand arithmetically shifted right by Count\r | |
79 | \r | |
80 | **/\r | |
81 | UINT64\r | |
82 | EFIAPI\r | |
83 | InternalMathARShiftU64 (\r | |
84 | IN UINT64 Operand,\r | |
85 | IN UINTN Count\r | |
86 | );\r | |
87 | \r | |
88 | /**\r | |
89 | Rotates a 64-bit integer left between 0 and 63 bits, filling\r | |
90 | the low bits with the high bits that were rotated.\r | |
91 | \r | |
92 | This function rotates the 64-bit value Operand to the left by Count bits. The\r | |
127010dd | 93 | low Count bits are filled with the high Count bits of Operand. The rotated\r |
e1f414b6 | 94 | value is returned.\r |
95 | \r | |
96 | @param Operand The 64-bit operand to rotate left.\r | |
97 | @param Count The number of bits to rotate left.\r | |
98 | \r | |
99 | @return Operand <<< Count\r | |
100 | \r | |
101 | **/\r | |
102 | UINT64\r | |
103 | EFIAPI\r | |
104 | InternalMathLRotU64 (\r | |
105 | IN UINT64 Operand,\r | |
106 | IN UINTN Count\r | |
107 | );\r | |
108 | \r | |
109 | /**\r | |
110 | Rotates a 64-bit integer right between 0 and 63 bits, filling\r | |
111 | the high bits with the high low bits that were rotated.\r | |
112 | \r | |
113 | This function rotates the 64-bit value Operand to the right by Count bits.\r | |
127010dd | 114 | The high Count bits are filled with the low Count bits of Operand. The rotated\r |
e1f414b6 | 115 | value is returned.\r |
116 | \r | |
117 | @param Operand The 64-bit operand to rotate right.\r | |
118 | @param Count The number of bits to rotate right.\r | |
119 | \r | |
120 | @return Operand >>> Count\r | |
121 | \r | |
122 | **/\r | |
123 | UINT64\r | |
124 | EFIAPI\r | |
125 | InternalMathRRotU64 (\r | |
126 | IN UINT64 Operand,\r | |
127 | IN UINTN Count\r | |
128 | );\r | |
129 | \r | |
130 | /**\r | |
131 | Switches the endianess of a 64-bit integer.\r | |
132 | \r | |
133 | This function swaps the bytes in a 64-bit unsigned value to switch the value\r | |
134 | from little endian to big endian or vice versa. The byte swapped value is\r | |
135 | returned.\r | |
136 | \r | |
137 | @param Operand A 64-bit unsigned value.\r | |
138 | \r | |
24dcb5e5 | 139 | @return The byte swapped Operand.\r |
e1f414b6 | 140 | \r |
141 | **/\r | |
142 | UINT64\r | |
143 | EFIAPI\r | |
144 | InternalMathSwapBytes64 (\r | |
145 | IN UINT64 Operand\r | |
146 | );\r | |
147 | \r | |
148 | /**\r | |
127010dd | 149 | Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer\r |
e1f414b6 | 150 | and generates a 64-bit unsigned result.\r |
151 | \r | |
127010dd | 152 | This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit\r |
e1f414b6 | 153 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r |
154 | bit unsigned result is returned.\r | |
155 | \r | |
156 | @param Multiplicand A 64-bit unsigned value.\r | |
157 | @param Multiplier A 32-bit unsigned value.\r | |
158 | \r | |
159 | @return Multiplicand * Multiplier\r | |
160 | \r | |
161 | **/\r | |
162 | UINT64\r | |
163 | EFIAPI\r | |
164 | InternalMathMultU64x32 (\r | |
165 | IN UINT64 Multiplicand,\r | |
166 | IN UINT32 Multiplier\r | |
167 | );\r | |
168 | \r | |
169 | /**\r | |
127010dd | 170 | Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer\r |
e1f414b6 | 171 | and generates a 64-bit unsigned result.\r |
172 | \r | |
173 | This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r | |
174 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r | |
175 | bit unsigned result is returned.\r | |
176 | \r | |
177 | @param Multiplicand A 64-bit unsigned value.\r | |
178 | @param Multiplier A 64-bit unsigned value.\r | |
179 | \r | |
180 | @return Multiplicand * Multiplier\r | |
181 | \r | |
182 | **/\r | |
183 | UINT64\r | |
184 | EFIAPI\r | |
185 | InternalMathMultU64x64 (\r | |
186 | IN UINT64 Multiplicand,\r | |
187 | IN UINT64 Multiplier\r | |
188 | );\r | |
189 | \r | |
190 | /**\r | |
191 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
192 | generates a 64-bit unsigned result.\r | |
193 | \r | |
194 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
195 | unsigned value Divisor and generates a 64-bit unsigned quotient. This\r | |
196 | function returns the 64-bit unsigned quotient.\r | |
197 | \r | |
24dcb5e5 | 198 | @param Dividend A 64-bit unsigned value.\r |
e1f414b6 | 199 | @param Divisor A 32-bit unsigned value.\r |
200 | \r | |
201 | @return Dividend / Divisor\r | |
202 | \r | |
203 | **/\r | |
204 | UINT64\r | |
205 | EFIAPI\r | |
206 | InternalMathDivU64x32 (\r | |
207 | IN UINT64 Dividend,\r | |
208 | IN UINT32 Divisor\r | |
209 | );\r | |
210 | \r | |
211 | /**\r | |
212 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
213 | generates a 32-bit unsigned remainder.\r | |
214 | \r | |
215 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
216 | unsigned value Divisor and generates a 32-bit remainder. This function\r | |
217 | returns the 32-bit unsigned remainder.\r | |
218 | \r | |
219 | @param Dividend A 64-bit unsigned value.\r | |
220 | @param Divisor A 32-bit unsigned value.\r | |
221 | \r | |
222 | @return Dividend % Divisor\r | |
223 | \r | |
224 | **/\r | |
225 | UINT32\r | |
226 | EFIAPI\r | |
227 | InternalMathModU64x32 (\r | |
228 | IN UINT64 Dividend,\r | |
229 | IN UINT32 Divisor\r | |
230 | );\r | |
231 | \r | |
232 | /**\r | |
233 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
234 | generates a 64-bit unsigned result and an optional 32-bit unsigned remainder.\r | |
235 | \r | |
236 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
237 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r | |
238 | is not NULL, then the 32-bit unsigned remainder is returned in Remainder.\r | |
239 | This function returns the 64-bit unsigned quotient.\r | |
240 | \r | |
241 | @param Dividend A 64-bit unsigned value.\r | |
242 | @param Divisor A 32-bit unsigned value.\r | |
243 | @param Remainder A pointer to a 32-bit unsigned value. This parameter is\r | |
244 | optional and may be NULL.\r | |
245 | \r | |
246 | @return Dividend / Divisor\r | |
247 | \r | |
248 | **/\r | |
249 | UINT64\r | |
250 | EFIAPI\r | |
251 | InternalMathDivRemU64x32 (\r | |
252 | IN UINT64 Dividend,\r | |
253 | IN UINT32 Divisor,\r | |
42eedea9 | 254 | OUT UINT32 *Remainder OPTIONAL\r |
e1f414b6 | 255 | );\r |
256 | \r | |
257 | /**\r | |
258 | Divides a 64-bit unsigned integer by a 64-bit unsigned integer and\r | |
259 | generates a 64-bit unsigned result and an optional 64-bit unsigned remainder.\r | |
260 | \r | |
261 | This function divides the 64-bit unsigned value Dividend by the 64-bit\r | |
262 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r | |
263 | is not NULL, then the 64-bit unsigned remainder is returned in Remainder.\r | |
264 | This function returns the 64-bit unsigned quotient.\r | |
265 | \r | |
266 | @param Dividend A 64-bit unsigned value.\r | |
267 | @param Divisor A 64-bit unsigned value.\r | |
268 | @param Remainder A pointer to a 64-bit unsigned value. This parameter is\r | |
269 | optional and may be NULL.\r | |
270 | \r | |
271 | @return Dividend / Divisor\r | |
272 | \r | |
273 | **/\r | |
274 | UINT64\r | |
275 | EFIAPI\r | |
276 | InternalMathDivRemU64x64 (\r | |
277 | IN UINT64 Dividend,\r | |
278 | IN UINT64 Divisor,\r | |
42eedea9 | 279 | OUT UINT64 *Remainder OPTIONAL\r |
e1f414b6 | 280 | );\r |
281 | \r | |
282 | /**\r | |
283 | Divides a 64-bit signed integer by a 64-bit signed integer and\r | |
24dcb5e5 | 284 | generates a 64-bit signed result and an optional 64-bit signed remainder.\r |
e1f414b6 | 285 | \r |
24dcb5e5 | 286 | This function divides the 64-bit signed value Dividend by the 64-bit\r |
287 | signed value Divisor and generates a 64-bit signed quotient. If Remainder\r | |
288 | is not NULL, then the 64-bit signed remainder is returned in Remainder.\r | |
289 | This function returns the 64-bit signed quotient.\r | |
e1f414b6 | 290 | \r |
291 | @param Dividend A 64-bit signed value.\r | |
292 | @param Divisor A 64-bit signed value.\r | |
293 | @param Remainder A pointer to a 64-bit signed value. This parameter is\r | |
294 | optional and may be NULL.\r | |
295 | \r | |
296 | @return Dividend / Divisor\r | |
297 | \r | |
298 | **/\r | |
299 | INT64\r | |
38bbd3d9 | 300 | EFIAPI\r |
e1f414b6 | 301 | InternalMathDivRemS64x64 (\r |
302 | IN INT64 Dividend,\r | |
303 | IN INT64 Divisor,\r | |
304 | OUT INT64 *Remainder OPTIONAL\r | |
7e43ed89 | 305 | );\r |
e1f414b6 | 306 | \r |
307 | /**\r | |
308 | Transfers control to a function starting with a new stack.\r | |
309 | \r | |
310 | Transfers control to the function specified by EntryPoint using the\r | |
311 | new stack specified by NewStack and passing in the parameters specified\r | |
312 | by Context1 and Context2. Context1 and Context2 are optional and may\r | |
313 | be NULL. The function EntryPoint must never return.\r | |
314 | Marker will be ignored on IA-32, x64, and EBC.\r | |
315 | IPF CPUs expect one additional parameter of type VOID * that specifies\r | |
316 | the new backing store pointer.\r | |
317 | \r | |
318 | If EntryPoint is NULL, then ASSERT().\r | |
319 | If NewStack is NULL, then ASSERT().\r | |
320 | \r | |
321 | @param EntryPoint A pointer to function to call with the new stack.\r | |
322 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
323 | function.\r | |
324 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
325 | function.\r | |
326 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
327 | function.\r | |
328 | @param Marker VA_LIST marker for the variable argument list.\r | |
329 | \r | |
330 | **/\r | |
331 | VOID\r | |
332 | EFIAPI\r | |
333 | InternalSwitchStack (\r | |
334 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
335 | IN VOID *Context1, OPTIONAL\r | |
336 | IN VOID *Context2, OPTIONAL\r | |
337 | IN VOID *NewStack,\r | |
338 | IN VA_LIST Marker\r | |
339 | );\r | |
340 | \r | |
341 | \r | |
e1f414b6 | 342 | /**\r |
24dcb5e5 | 343 | Worker function that returns a bit field from Operand.\r |
e1f414b6 | 344 | \r |
345 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
346 | \r | |
347 | @param Operand Operand on which to perform the bitfield operation.\r | |
348 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
349 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
350 | \r | |
351 | @return The bit field read.\r | |
352 | \r | |
353 | **/\r | |
28ca72bc | 354 | UINTN\r |
38bbd3d9 | 355 | EFIAPI\r |
e1f414b6 | 356 | BitFieldReadUint (\r |
28ca72bc | 357 | IN UINTN Operand,\r |
e1f414b6 | 358 | IN UINTN StartBit,\r |
359 | IN UINTN EndBit\r | |
360 | );\r | |
361 | \r | |
362 | \r | |
363 | /**\r | |
364 | Worker function that reads a bit field from Operand, performs a bitwise OR,\r | |
365 | and returns the result.\r | |
366 | \r | |
367 | Performs a bitwise OR between the bit field specified by StartBit and EndBit\r | |
368 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
369 | preserved. The new value is returned.\r | |
370 | \r | |
371 | @param Operand Operand on which to perform the bitfield operation.\r | |
372 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
373 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
374 | @param OrData The value to OR with the read value from the value\r | |
375 | \r | |
376 | @return The new value.\r | |
377 | \r | |
378 | **/\r | |
28ca72bc | 379 | UINTN\r |
38bbd3d9 | 380 | EFIAPI\r |
e1f414b6 | 381 | BitFieldOrUint (\r |
28ca72bc | 382 | IN UINTN Operand,\r |
e1f414b6 | 383 | IN UINTN StartBit,\r |
384 | IN UINTN EndBit,\r | |
28ca72bc | 385 | IN UINTN OrData\r |
e1f414b6 | 386 | );\r |
387 | \r | |
388 | \r | |
389 | /**\r | |
390 | Worker function that reads a bit field from Operand, performs a bitwise AND,\r | |
391 | and returns the result.\r | |
392 | \r | |
393 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
394 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
395 | preserved. The new value is returned.\r | |
396 | \r | |
397 | @param Operand Operand on which to perform the bitfield operation.\r | |
398 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
399 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
400 | @param AndData The value to And with the read value from the value\r | |
401 | \r | |
402 | @return The new value.\r | |
403 | \r | |
404 | **/\r | |
28ca72bc | 405 | UINTN\r |
38bbd3d9 | 406 | EFIAPI\r |
e1f414b6 | 407 | BitFieldAndUint (\r |
28ca72bc | 408 | IN UINTN Operand,\r |
e1f414b6 | 409 | IN UINTN StartBit,\r |
410 | IN UINTN EndBit,\r | |
28ca72bc | 411 | IN UINTN AndData\r |
e1f414b6 | 412 | );\r |
413 | \r | |
414 | \r | |
415 | /**\r | |
416 | Worker function that checks ASSERT condition for JumpBuffer\r | |
417 | \r | |
418 | Checks ASSERT condition for JumpBuffer.\r | |
419 | \r | |
420 | If JumpBuffer is NULL, then ASSERT().\r | |
421 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r | |
422 | \r | |
423 | @param JumpBuffer A pointer to CPU context buffer.\r | |
424 | \r | |
425 | **/\r | |
426 | VOID\r | |
38bbd3d9 | 427 | EFIAPI\r |
e1f414b6 | 428 | InternalAssertJumpBuffer (\r |
429 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r | |
430 | );\r | |
431 | \r | |
432 | \r | |
433 | /**\r | |
434 | Restores the CPU context that was saved with SetJump().\r | |
435 | \r | |
436 | Restores the CPU context from the buffer specified by JumpBuffer.\r | |
437 | This function never returns to the caller.\r | |
438 | Instead is resumes execution based on the state of JumpBuffer.\r | |
439 | \r | |
440 | @param JumpBuffer A pointer to CPU context buffer.\r | |
441 | @param Value The value to return when the SetJump() context is restored.\r | |
442 | \r | |
443 | **/\r | |
444 | VOID\r | |
445 | EFIAPI\r | |
446 | InternalLongJump (\r | |
447 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,\r | |
448 | IN UINTN Value\r | |
449 | );\r | |
450 | \r | |
451 | \r | |
d8af3301 HW |
452 | /**\r |
453 | Check if a Unicode character is a decimal character.\r | |
454 | \r | |
455 | This internal function checks if a Unicode character is a\r | |
456 | decimal character. The valid decimal character is from\r | |
457 | L'0' to L'9'.\r | |
458 | \r | |
459 | @param Char The character to check against.\r | |
460 | \r | |
461 | @retval TRUE If the Char is a decmial character.\r | |
462 | @retval FALSE If the Char is not a decmial character.\r | |
463 | \r | |
464 | **/\r | |
465 | BOOLEAN\r | |
466 | EFIAPI\r | |
467 | InternalIsDecimalDigitCharacter (\r | |
468 | IN CHAR16 Char\r | |
469 | );\r | |
470 | \r | |
471 | \r | |
472 | /**\r | |
473 | Convert a Unicode character to upper case only if\r | |
474 | it maps to a valid small-case ASCII character.\r | |
475 | \r | |
476 | This internal function only deal with Unicode character\r | |
477 | which maps to a valid small-case ASCII character, i.e.\r | |
478 | L'a' to L'z'. For other Unicode character, the input character\r | |
479 | is returned directly.\r | |
480 | \r | |
481 | @param Char The character to convert.\r | |
482 | \r | |
483 | @retval LowerCharacter If the Char is with range L'a' to L'z'.\r | |
484 | @retval Unchanged Otherwise.\r | |
485 | \r | |
486 | **/\r | |
487 | CHAR16\r | |
488 | EFIAPI\r | |
489 | InternalCharToUpper (\r | |
490 | IN CHAR16 Char\r | |
491 | );\r | |
492 | \r | |
493 | \r | |
494 | /**\r | |
495 | Convert a Unicode character to numerical value.\r | |
496 | \r | |
497 | This internal function only deal with Unicode character\r | |
498 | which maps to a valid hexadecimal ASII character, i.e.\r | |
499 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r | |
500 | Unicode character, the value returned does not make sense.\r | |
501 | \r | |
502 | @param Char The character to convert.\r | |
503 | \r | |
504 | @return The numerical value converted.\r | |
505 | \r | |
506 | **/\r | |
507 | UINTN\r | |
508 | EFIAPI\r | |
509 | InternalHexCharToUintn (\r | |
510 | IN CHAR16 Char\r | |
511 | );\r | |
512 | \r | |
513 | \r | |
514 | /**\r | |
515 | Check if a Unicode character is a hexadecimal character.\r | |
516 | \r | |
517 | This internal function checks if a Unicode character is a\r | |
518 | decimal character. The valid hexadecimal character is\r | |
519 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
520 | \r | |
521 | \r | |
522 | @param Char The character to check against.\r | |
523 | \r | |
524 | @retval TRUE If the Char is a hexadecmial character.\r | |
525 | @retval FALSE If the Char is not a hexadecmial character.\r | |
526 | \r | |
527 | **/\r | |
528 | BOOLEAN\r | |
529 | EFIAPI\r | |
530 | InternalIsHexaDecimalDigitCharacter (\r | |
531 | IN CHAR16 Char\r | |
532 | );\r | |
533 | \r | |
534 | \r | |
535 | /**\r | |
536 | Check if a ASCII character is a decimal character.\r | |
537 | \r | |
538 | This internal function checks if a Unicode character is a\r | |
539 | decimal character. The valid decimal character is from\r | |
540 | '0' to '9'.\r | |
541 | \r | |
542 | @param Char The character to check against.\r | |
543 | \r | |
544 | @retval TRUE If the Char is a decmial character.\r | |
545 | @retval FALSE If the Char is not a decmial character.\r | |
546 | \r | |
547 | **/\r | |
548 | BOOLEAN\r | |
549 | EFIAPI\r | |
550 | InternalAsciiIsDecimalDigitCharacter (\r | |
551 | IN CHAR8 Char\r | |
552 | );\r | |
553 | \r | |
554 | \r | |
555 | /**\r | |
556 | Converts a lowercase Ascii character to upper one.\r | |
557 | \r | |
558 | If Chr is lowercase Ascii character, then converts it to upper one.\r | |
559 | \r | |
560 | If Value >= 0xA0, then ASSERT().\r | |
561 | If (Value & 0x0F) >= 0x0A, then ASSERT().\r | |
562 | \r | |
563 | @param Chr one Ascii character\r | |
564 | \r | |
565 | @return The uppercase value of Ascii character\r | |
566 | \r | |
567 | **/\r | |
568 | CHAR8\r | |
569 | EFIAPI\r | |
570 | InternalBaseLibAsciiToUpper (\r | |
571 | IN CHAR8 Chr\r | |
572 | );\r | |
573 | \r | |
574 | \r | |
575 | /**\r | |
576 | Check if a ASCII character is a hexadecimal character.\r | |
577 | \r | |
578 | This internal function checks if a ASCII character is a\r | |
579 | decimal character. The valid hexadecimal character is\r | |
580 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
581 | \r | |
582 | \r | |
583 | @param Char The character to check against.\r | |
584 | \r | |
585 | @retval TRUE If the Char is a hexadecmial character.\r | |
586 | @retval FALSE If the Char is not a hexadecmial character.\r | |
587 | \r | |
588 | **/\r | |
589 | BOOLEAN\r | |
590 | EFIAPI\r | |
591 | InternalAsciiIsHexaDecimalDigitCharacter (\r | |
592 | IN CHAR8 Char\r | |
593 | );\r | |
594 | \r | |
595 | \r | |
596 | /**\r | |
597 | Convert a ASCII character to numerical value.\r | |
598 | \r | |
599 | This internal function only deal with Unicode character\r | |
600 | which maps to a valid hexadecimal ASII character, i.e.\r | |
601 | '0' to '9', 'a' to 'f' or 'A' to 'F'. For other\r | |
602 | ASCII character, the value returned does not make sense.\r | |
603 | \r | |
604 | @param Char The character to convert.\r | |
605 | \r | |
606 | @return The numerical value converted.\r | |
607 | \r | |
608 | **/\r | |
609 | UINTN\r | |
610 | EFIAPI\r | |
611 | InternalAsciiHexCharToUintn (\r | |
612 | IN CHAR8 Char\r | |
613 | );\r | |
614 | \r | |
615 | \r | |
e1f414b6 | 616 | //\r |
617 | // Ia32 and x64 specific functions\r | |
618 | //\r | |
619 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r | |
620 | \r | |
621 | /**\r | |
622 | Reads the current Global Descriptor Table Register(GDTR) descriptor.\r | |
623 | \r | |
624 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r | |
030cd1a2 | 625 | function is only available on IA-32 and x64.\r |
e1f414b6 | 626 | \r |
127010dd | 627 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 628 | \r |
629 | **/\r | |
630 | VOID\r | |
631 | EFIAPI\r | |
632 | InternalX86ReadGdtr (\r | |
633 | OUT IA32_DESCRIPTOR *Gdtr\r | |
634 | );\r | |
635 | \r | |
636 | /**\r | |
637 | Writes the current Global Descriptor Table Register (GDTR) descriptor.\r | |
638 | \r | |
639 | Writes and the current GDTR descriptor specified by Gdtr. This function is\r | |
030cd1a2 | 640 | only available on IA-32 and x64.\r |
e1f414b6 | 641 | \r |
127010dd | 642 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 643 | \r |
644 | **/\r | |
645 | VOID\r | |
646 | EFIAPI\r | |
647 | InternalX86WriteGdtr (\r | |
648 | IN CONST IA32_DESCRIPTOR *Gdtr\r | |
649 | );\r | |
650 | \r | |
651 | /**\r | |
652 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
653 | \r | |
654 | Reads and returns the current IDTR descriptor and returns it in Idtr. This\r | |
030cd1a2 | 655 | function is only available on IA-32 and x64.\r |
e1f414b6 | 656 | \r |
127010dd | 657 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 658 | \r |
659 | **/\r | |
660 | VOID\r | |
661 | EFIAPI\r | |
662 | InternalX86ReadIdtr (\r | |
663 | OUT IA32_DESCRIPTOR *Idtr\r | |
664 | );\r | |
665 | \r | |
666 | /**\r | |
667 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
668 | \r | |
669 | Writes the current IDTR descriptor and returns it in Idtr. This function is\r | |
030cd1a2 | 670 | only available on IA-32 and x64.\r |
e1f414b6 | 671 | \r |
127010dd | 672 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 673 | \r |
674 | **/\r | |
675 | VOID\r | |
676 | EFIAPI\r | |
677 | InternalX86WriteIdtr (\r | |
678 | IN CONST IA32_DESCRIPTOR *Idtr\r | |
679 | );\r | |
680 | \r | |
681 | /**\r | |
682 | Save the current floating point/SSE/SSE2 context to a buffer.\r | |
683 | \r | |
684 | Saves the current floating point/SSE/SSE2 state to the buffer specified by\r | |
685 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r | |
030cd1a2 | 686 | available on IA-32 and x64.\r |
e1f414b6 | 687 | \r |
127010dd | 688 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 689 | \r |
690 | **/\r | |
691 | VOID\r | |
692 | EFIAPI\r | |
693 | InternalX86FxSave (\r | |
694 | OUT IA32_FX_BUFFER *Buffer\r | |
695 | );\r | |
696 | \r | |
697 | /**\r | |
698 | Restores the current floating point/SSE/SSE2 context from a buffer.\r | |
699 | \r | |
700 | Restores the current floating point/SSE/SSE2 state from the buffer specified\r | |
701 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r | |
030cd1a2 | 702 | only available on IA-32 and x64.\r |
e1f414b6 | 703 | \r |
127010dd | 704 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 705 | \r |
706 | **/\r | |
707 | VOID\r | |
708 | EFIAPI\r | |
709 | InternalX86FxRestore (\r | |
710 | IN CONST IA32_FX_BUFFER *Buffer\r | |
711 | );\r | |
712 | \r | |
713 | /**\r | |
714 | Enables the 32-bit paging mode on the CPU.\r | |
715 | \r | |
716 | Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
717 | must be properly initialized prior to calling this service. This function\r | |
718 | assumes the current execution mode is 32-bit protected mode. This function is\r | |
719 | only available on IA-32. After the 32-bit paging mode is enabled, control is\r | |
720 | transferred to the function specified by EntryPoint using the new stack\r | |
721 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
722 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
723 | EntryPoint must never return.\r | |
724 | \r | |
725 | There are a number of constraints that must be followed before calling this\r | |
726 | function:\r | |
727 | 1) Interrupts must be disabled.\r | |
728 | 2) The caller must be in 32-bit protected mode with flat descriptors. This\r | |
729 | means all descriptors must have a base of 0 and a limit of 4GB.\r | |
730 | 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r | |
731 | descriptors.\r | |
732 | 4) CR3 must point to valid page tables that will be used once the transition\r | |
733 | is complete, and those page tables must guarantee that the pages for this\r | |
734 | function and the stack are identity mapped.\r | |
735 | \r | |
736 | @param EntryPoint A pointer to function to call with the new stack after\r | |
737 | paging is enabled.\r | |
738 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
739 | function as the first parameter after paging is enabled.\r | |
740 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
741 | function as the second parameter after paging is enabled.\r | |
742 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
743 | function after paging is enabled.\r | |
744 | \r | |
745 | **/\r | |
746 | VOID\r | |
747 | EFIAPI\r | |
748 | InternalX86EnablePaging32 (\r | |
749 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
750 | IN VOID *Context1, OPTIONAL\r | |
751 | IN VOID *Context2, OPTIONAL\r | |
752 | IN VOID *NewStack\r | |
753 | );\r | |
754 | \r | |
755 | /**\r | |
756 | Disables the 32-bit paging mode on the CPU.\r | |
757 | \r | |
758 | Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r | |
759 | mode. This function assumes the current execution mode is 32-paged protected\r | |
760 | mode. This function is only available on IA-32. After the 32-bit paging mode\r | |
761 | is disabled, control is transferred to the function specified by EntryPoint\r | |
762 | using the new stack specified by NewStack and passing in the parameters\r | |
763 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
764 | may be NULL. The function EntryPoint must never return.\r | |
765 | \r | |
766 | There are a number of constraints that must be followed before calling this\r | |
767 | function:\r | |
768 | 1) Interrupts must be disabled.\r | |
769 | 2) The caller must be in 32-bit paged mode.\r | |
770 | 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r | |
771 | 4) CR3 must point to valid page tables that guarantee that the pages for\r | |
772 | this function and the stack are identity mapped.\r | |
773 | \r | |
774 | @param EntryPoint A pointer to function to call with the new stack after\r | |
775 | paging is disabled.\r | |
776 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
777 | function as the first parameter after paging is disabled.\r | |
778 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
779 | function as the second parameter after paging is\r | |
780 | disabled.\r | |
781 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
782 | function after paging is disabled.\r | |
783 | \r | |
784 | **/\r | |
785 | VOID\r | |
786 | EFIAPI\r | |
787 | InternalX86DisablePaging32 (\r | |
788 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
789 | IN VOID *Context1, OPTIONAL\r | |
790 | IN VOID *Context2, OPTIONAL\r | |
791 | IN VOID *NewStack\r | |
792 | );\r | |
793 | \r | |
794 | /**\r | |
795 | Enables the 64-bit paging mode on the CPU.\r | |
796 | \r | |
797 | Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
798 | must be properly initialized prior to calling this service. This function\r | |
799 | assumes the current execution mode is 32-bit protected mode with flat\r | |
800 | descriptors. This function is only available on IA-32. After the 64-bit\r | |
801 | paging mode is enabled, control is transferred to the function specified by\r | |
802 | EntryPoint using the new stack specified by NewStack and passing in the\r | |
803 | parameters specified by Context1 and Context2. Context1 and Context2 are\r | |
804 | optional and may be 0. The function EntryPoint must never return.\r | |
805 | \r | |
806 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
807 | is called. The descriptor in the GDT that this selector\r | |
808 | references must be setup for long mode.\r | |
809 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
810 | the new stack after paging is enabled.\r | |
811 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
812 | the EntryPoint function as the first parameter after\r | |
813 | paging is enabled.\r | |
814 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
815 | the EntryPoint function as the second parameter after\r | |
816 | paging is enabled.\r | |
817 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
818 | the EntryPoint function after paging is enabled.\r | |
819 | \r | |
820 | **/\r | |
821 | VOID\r | |
822 | EFIAPI\r | |
823 | InternalX86EnablePaging64 (\r | |
824 | IN UINT16 Cs,\r | |
825 | IN UINT64 EntryPoint,\r | |
826 | IN UINT64 Context1, OPTIONAL\r | |
827 | IN UINT64 Context2, OPTIONAL\r | |
828 | IN UINT64 NewStack\r | |
829 | );\r | |
830 | \r | |
831 | /**\r | |
832 | Disables the 64-bit paging mode on the CPU.\r | |
833 | \r | |
834 | Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r | |
835 | mode. This function assumes the current execution mode is 64-paging mode.\r | |
030cd1a2 | 836 | This function is only available on x64. After the 64-bit paging mode is\r |
e1f414b6 | 837 | disabled, control is transferred to the function specified by EntryPoint\r |
838 | using the new stack specified by NewStack and passing in the parameters\r | |
839 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
840 | may be 0. The function EntryPoint must never return.\r | |
841 | \r | |
842 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
843 | is called. The descriptor in the GDT that this selector\r | |
844 | references must be setup for 32-bit protected mode.\r | |
845 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
846 | the new stack after paging is disabled.\r | |
847 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
848 | the EntryPoint function as the first parameter after\r | |
849 | paging is disabled.\r | |
850 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
851 | the EntryPoint function as the second parameter after\r | |
852 | paging is disabled.\r | |
853 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
854 | the EntryPoint function after paging is disabled.\r | |
855 | \r | |
856 | **/\r | |
857 | VOID\r | |
858 | EFIAPI\r | |
859 | InternalX86DisablePaging64 (\r | |
860 | IN UINT16 Cs,\r | |
861 | IN UINT32 EntryPoint,\r | |
862 | IN UINT32 Context1, OPTIONAL\r | |
863 | IN UINT32 Context2, OPTIONAL\r | |
864 | IN UINT32 NewStack\r | |
865 | );\r | |
866 | \r | |
9ec9a7a5 QL |
867 | /**\r |
868 | Generates a 16-bit random number through RDRAND instruction.\r | |
869 | \r | |
870 | @param[out] Rand Buffer pointer to store the random result.\r | |
871 | \r | |
872 | @retval TRUE RDRAND call was successful.\r | |
873 | @retval FALSE Failed attempts to call RDRAND.\r | |
874 | \r | |
875 | **/\r | |
876 | BOOLEAN\r | |
877 | EFIAPI\r | |
878 | InternalX86RdRand16 (\r | |
879 | OUT UINT16 *Rand\r | |
880 | );\r | |
881 | \r | |
882 | /**\r | |
883 | Generates a 32-bit random number through RDRAND instruction.\r | |
884 | \r | |
885 | @param[out] Rand Buffer pointer to store the random result.\r | |
886 | \r | |
887 | @retval TRUE RDRAND call was successful.\r | |
888 | @retval FALSE Failed attempts to call RDRAND.\r | |
889 | \r | |
890 | **/\r | |
891 | BOOLEAN\r | |
892 | EFIAPI\r | |
893 | InternalX86RdRand32 (\r | |
894 | OUT UINT32 *Rand\r | |
895 | );\r | |
896 | \r | |
897 | /**\r | |
898 | Generates a 64-bit random number through RDRAND instruction.\r | |
899 | \r | |
900 | \r | |
901 | @param[out] Rand Buffer pointer to store the random result.\r | |
902 | \r | |
903 | @retval TRUE RDRAND call was successful.\r | |
904 | @retval FALSE Failed attempts to call RDRAND.\r | |
905 | \r | |
906 | **/\r | |
907 | BOOLEAN\r | |
908 | EFIAPI\r | |
909 | InternalX86RdRand64 (\r | |
910 | OUT UINT64 *Rand\r | |
911 | );\r | |
912 | \r | |
e1f414b6 | 913 | #else\r |
914 | \r | |
915 | #endif\r | |
916 | \r | |
917 | #endif\r |