]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Declaration of internal functions in BaseLib.\r | |
3 | \r | |
8c9b4950 | 4 | Copyright (c) 2006 - 2019, 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 | |
d8af3301 HW |
472 | /**\r |
473 | Convert a Unicode character to numerical value.\r | |
474 | \r | |
475 | This internal function only deal with Unicode character\r | |
476 | which maps to a valid hexadecimal ASII character, i.e.\r | |
477 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r | |
478 | Unicode character, the value returned does not make sense.\r | |
479 | \r | |
480 | @param Char The character to convert.\r | |
481 | \r | |
482 | @return The numerical value converted.\r | |
483 | \r | |
484 | **/\r | |
485 | UINTN\r | |
486 | EFIAPI\r | |
487 | InternalHexCharToUintn (\r | |
488 | IN CHAR16 Char\r | |
489 | );\r | |
490 | \r | |
491 | \r | |
492 | /**\r | |
493 | Check if a Unicode character is a hexadecimal character.\r | |
494 | \r | |
495 | This internal function checks if a Unicode character is a\r | |
496 | decimal character. The valid hexadecimal character is\r | |
497 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
498 | \r | |
499 | \r | |
500 | @param Char The character to check against.\r | |
501 | \r | |
502 | @retval TRUE If the Char is a hexadecmial character.\r | |
503 | @retval FALSE If the Char is not a hexadecmial character.\r | |
504 | \r | |
505 | **/\r | |
506 | BOOLEAN\r | |
507 | EFIAPI\r | |
508 | InternalIsHexaDecimalDigitCharacter (\r | |
509 | IN CHAR16 Char\r | |
510 | );\r | |
511 | \r | |
512 | \r | |
513 | /**\r | |
514 | Check if a ASCII character is a decimal character.\r | |
515 | \r | |
516 | This internal function checks if a Unicode character is a\r | |
517 | decimal character. The valid decimal character is from\r | |
518 | '0' to '9'.\r | |
519 | \r | |
520 | @param Char The character to check against.\r | |
521 | \r | |
522 | @retval TRUE If the Char is a decmial character.\r | |
523 | @retval FALSE If the Char is not a decmial character.\r | |
524 | \r | |
525 | **/\r | |
526 | BOOLEAN\r | |
527 | EFIAPI\r | |
528 | InternalAsciiIsDecimalDigitCharacter (\r | |
529 | IN CHAR8 Char\r | |
530 | );\r | |
531 | \r | |
532 | \r | |
d8af3301 HW |
533 | /**\r |
534 | Check if a ASCII character is a hexadecimal character.\r | |
535 | \r | |
536 | This internal function checks if a ASCII character is a\r | |
537 | decimal character. The valid hexadecimal character is\r | |
538 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
539 | \r | |
540 | \r | |
541 | @param Char The character to check against.\r | |
542 | \r | |
543 | @retval TRUE If the Char is a hexadecmial character.\r | |
544 | @retval FALSE If the Char is not a hexadecmial character.\r | |
545 | \r | |
546 | **/\r | |
547 | BOOLEAN\r | |
548 | EFIAPI\r | |
549 | InternalAsciiIsHexaDecimalDigitCharacter (\r | |
550 | IN CHAR8 Char\r | |
551 | );\r | |
552 | \r | |
553 | \r | |
554 | /**\r | |
555 | Convert a ASCII character to numerical value.\r | |
556 | \r | |
557 | This internal function only deal with Unicode character\r | |
558 | which maps to a valid hexadecimal ASII character, i.e.\r | |
559 | '0' to '9', 'a' to 'f' or 'A' to 'F'. For other\r | |
560 | ASCII character, the value returned does not make sense.\r | |
561 | \r | |
562 | @param Char The character to convert.\r | |
563 | \r | |
564 | @return The numerical value converted.\r | |
565 | \r | |
566 | **/\r | |
567 | UINTN\r | |
568 | EFIAPI\r | |
569 | InternalAsciiHexCharToUintn (\r | |
570 | IN CHAR8 Char\r | |
571 | );\r | |
572 | \r | |
573 | \r | |
e1f414b6 | 574 | //\r |
575 | // Ia32 and x64 specific functions\r | |
576 | //\r | |
577 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r | |
578 | \r | |
579 | /**\r | |
580 | Reads the current Global Descriptor Table Register(GDTR) descriptor.\r | |
581 | \r | |
582 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r | |
030cd1a2 | 583 | function is only available on IA-32 and x64.\r |
e1f414b6 | 584 | \r |
127010dd | 585 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 586 | \r |
587 | **/\r | |
588 | VOID\r | |
589 | EFIAPI\r | |
590 | InternalX86ReadGdtr (\r | |
591 | OUT IA32_DESCRIPTOR *Gdtr\r | |
592 | );\r | |
593 | \r | |
594 | /**\r | |
595 | Writes the current Global Descriptor Table Register (GDTR) descriptor.\r | |
596 | \r | |
597 | Writes and the current GDTR descriptor specified by Gdtr. This function is\r | |
030cd1a2 | 598 | only available on IA-32 and x64.\r |
e1f414b6 | 599 | \r |
127010dd | 600 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 601 | \r |
602 | **/\r | |
603 | VOID\r | |
604 | EFIAPI\r | |
605 | InternalX86WriteGdtr (\r | |
606 | IN CONST IA32_DESCRIPTOR *Gdtr\r | |
607 | );\r | |
608 | \r | |
609 | /**\r | |
610 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
611 | \r | |
612 | Reads and returns the current IDTR descriptor and returns it in Idtr. This\r | |
030cd1a2 | 613 | function is only available on IA-32 and x64.\r |
e1f414b6 | 614 | \r |
127010dd | 615 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 616 | \r |
617 | **/\r | |
618 | VOID\r | |
619 | EFIAPI\r | |
620 | InternalX86ReadIdtr (\r | |
621 | OUT IA32_DESCRIPTOR *Idtr\r | |
622 | );\r | |
623 | \r | |
624 | /**\r | |
625 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
626 | \r | |
627 | Writes the current IDTR descriptor and returns it in Idtr. This function is\r | |
030cd1a2 | 628 | only available on IA-32 and x64.\r |
e1f414b6 | 629 | \r |
127010dd | 630 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 631 | \r |
632 | **/\r | |
633 | VOID\r | |
634 | EFIAPI\r | |
635 | InternalX86WriteIdtr (\r | |
636 | IN CONST IA32_DESCRIPTOR *Idtr\r | |
637 | );\r | |
638 | \r | |
639 | /**\r | |
640 | Save the current floating point/SSE/SSE2 context to a buffer.\r | |
641 | \r | |
642 | Saves the current floating point/SSE/SSE2 state to the buffer specified by\r | |
643 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r | |
030cd1a2 | 644 | available on IA-32 and x64.\r |
e1f414b6 | 645 | \r |
127010dd | 646 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 647 | \r |
648 | **/\r | |
649 | VOID\r | |
650 | EFIAPI\r | |
651 | InternalX86FxSave (\r | |
652 | OUT IA32_FX_BUFFER *Buffer\r | |
653 | );\r | |
654 | \r | |
655 | /**\r | |
656 | Restores the current floating point/SSE/SSE2 context from a buffer.\r | |
657 | \r | |
658 | Restores the current floating point/SSE/SSE2 state from the buffer specified\r | |
659 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r | |
030cd1a2 | 660 | only available on IA-32 and x64.\r |
e1f414b6 | 661 | \r |
127010dd | 662 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 663 | \r |
664 | **/\r | |
665 | VOID\r | |
666 | EFIAPI\r | |
667 | InternalX86FxRestore (\r | |
668 | IN CONST IA32_FX_BUFFER *Buffer\r | |
669 | );\r | |
670 | \r | |
671 | /**\r | |
672 | Enables the 32-bit paging mode on the CPU.\r | |
673 | \r | |
674 | Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
675 | must be properly initialized prior to calling this service. This function\r | |
676 | assumes the current execution mode is 32-bit protected mode. This function is\r | |
677 | only available on IA-32. After the 32-bit paging mode is enabled, control is\r | |
678 | transferred to the function specified by EntryPoint using the new stack\r | |
679 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
680 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
681 | EntryPoint must never return.\r | |
682 | \r | |
683 | There are a number of constraints that must be followed before calling this\r | |
684 | function:\r | |
685 | 1) Interrupts must be disabled.\r | |
686 | 2) The caller must be in 32-bit protected mode with flat descriptors. This\r | |
687 | means all descriptors must have a base of 0 and a limit of 4GB.\r | |
688 | 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r | |
689 | descriptors.\r | |
690 | 4) CR3 must point to valid page tables that will be used once the transition\r | |
691 | is complete, and those page tables must guarantee that the pages for this\r | |
692 | function and the stack are identity mapped.\r | |
693 | \r | |
694 | @param EntryPoint A pointer to function to call with the new stack after\r | |
695 | paging is enabled.\r | |
696 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
697 | function as the first parameter after paging is enabled.\r | |
698 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
699 | function as the second parameter after paging is enabled.\r | |
700 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
701 | function after paging is enabled.\r | |
702 | \r | |
703 | **/\r | |
704 | VOID\r | |
705 | EFIAPI\r | |
706 | InternalX86EnablePaging32 (\r | |
707 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
708 | IN VOID *Context1, OPTIONAL\r | |
709 | IN VOID *Context2, OPTIONAL\r | |
710 | IN VOID *NewStack\r | |
711 | );\r | |
712 | \r | |
713 | /**\r | |
714 | Disables the 32-bit paging mode on the CPU.\r | |
715 | \r | |
716 | Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r | |
717 | mode. This function assumes the current execution mode is 32-paged protected\r | |
718 | mode. This function is only available on IA-32. After the 32-bit paging mode\r | |
719 | is disabled, control is transferred to the function specified by EntryPoint\r | |
720 | using the new stack specified by NewStack and passing in the parameters\r | |
721 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
722 | may be NULL. The function EntryPoint must never return.\r | |
723 | \r | |
724 | There are a number of constraints that must be followed before calling this\r | |
725 | function:\r | |
726 | 1) Interrupts must be disabled.\r | |
727 | 2) The caller must be in 32-bit paged mode.\r | |
728 | 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r | |
729 | 4) CR3 must point to valid page tables that guarantee that the pages for\r | |
730 | this function and the stack are identity mapped.\r | |
731 | \r | |
732 | @param EntryPoint A pointer to function to call with the new stack after\r | |
733 | paging is disabled.\r | |
734 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
735 | function as the first parameter after paging is disabled.\r | |
736 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
737 | function as the second parameter after paging is\r | |
738 | disabled.\r | |
739 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
740 | function after paging is disabled.\r | |
741 | \r | |
742 | **/\r | |
743 | VOID\r | |
744 | EFIAPI\r | |
745 | InternalX86DisablePaging32 (\r | |
746 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
747 | IN VOID *Context1, OPTIONAL\r | |
748 | IN VOID *Context2, OPTIONAL\r | |
749 | IN VOID *NewStack\r | |
750 | );\r | |
751 | \r | |
752 | /**\r | |
753 | Enables the 64-bit paging mode on the CPU.\r | |
754 | \r | |
755 | Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
756 | must be properly initialized prior to calling this service. This function\r | |
757 | assumes the current execution mode is 32-bit protected mode with flat\r | |
758 | descriptors. This function is only available on IA-32. After the 64-bit\r | |
759 | paging mode is enabled, control is transferred to the function specified by\r | |
760 | EntryPoint using the new stack specified by NewStack and passing in the\r | |
761 | parameters specified by Context1 and Context2. Context1 and Context2 are\r | |
762 | optional and may be 0. The function EntryPoint must never return.\r | |
763 | \r | |
764 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
765 | is called. The descriptor in the GDT that this selector\r | |
766 | references must be setup for long mode.\r | |
767 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
768 | the new stack after paging is enabled.\r | |
769 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
770 | the EntryPoint function as the first parameter after\r | |
771 | paging is enabled.\r | |
772 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
773 | the EntryPoint function as the second parameter after\r | |
774 | paging is enabled.\r | |
775 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
776 | the EntryPoint function after paging is enabled.\r | |
777 | \r | |
778 | **/\r | |
779 | VOID\r | |
780 | EFIAPI\r | |
781 | InternalX86EnablePaging64 (\r | |
782 | IN UINT16 Cs,\r | |
783 | IN UINT64 EntryPoint,\r | |
784 | IN UINT64 Context1, OPTIONAL\r | |
785 | IN UINT64 Context2, OPTIONAL\r | |
786 | IN UINT64 NewStack\r | |
787 | );\r | |
788 | \r | |
789 | /**\r | |
790 | Disables the 64-bit paging mode on the CPU.\r | |
791 | \r | |
792 | Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r | |
793 | mode. This function assumes the current execution mode is 64-paging mode.\r | |
030cd1a2 | 794 | This function is only available on x64. After the 64-bit paging mode is\r |
e1f414b6 | 795 | disabled, control is transferred to the function specified by EntryPoint\r |
796 | using the new stack specified by NewStack and passing in the parameters\r | |
797 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
798 | may be 0. The function EntryPoint must never return.\r | |
799 | \r | |
800 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
801 | is called. The descriptor in the GDT that this selector\r | |
802 | references must be setup for 32-bit protected mode.\r | |
803 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
804 | the new stack after paging is disabled.\r | |
805 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
806 | the EntryPoint function as the first parameter after\r | |
807 | paging is disabled.\r | |
808 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
809 | the EntryPoint function as the second parameter after\r | |
810 | paging is disabled.\r | |
811 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
812 | the EntryPoint function after paging is disabled.\r | |
813 | \r | |
814 | **/\r | |
815 | VOID\r | |
816 | EFIAPI\r | |
817 | InternalX86DisablePaging64 (\r | |
818 | IN UINT16 Cs,\r | |
819 | IN UINT32 EntryPoint,\r | |
820 | IN UINT32 Context1, OPTIONAL\r | |
821 | IN UINT32 Context2, OPTIONAL\r | |
822 | IN UINT32 NewStack\r | |
823 | );\r | |
824 | \r | |
9ec9a7a5 QL |
825 | /**\r |
826 | Generates a 16-bit random number through RDRAND instruction.\r | |
827 | \r | |
828 | @param[out] Rand Buffer pointer to store the random result.\r | |
829 | \r | |
830 | @retval TRUE RDRAND call was successful.\r | |
831 | @retval FALSE Failed attempts to call RDRAND.\r | |
832 | \r | |
833 | **/\r | |
834 | BOOLEAN\r | |
835 | EFIAPI\r | |
836 | InternalX86RdRand16 (\r | |
837 | OUT UINT16 *Rand\r | |
838 | );\r | |
839 | \r | |
840 | /**\r | |
841 | Generates a 32-bit random number through RDRAND instruction.\r | |
842 | \r | |
843 | @param[out] Rand Buffer pointer to store the random result.\r | |
844 | \r | |
845 | @retval TRUE RDRAND call was successful.\r | |
846 | @retval FALSE Failed attempts to call RDRAND.\r | |
847 | \r | |
848 | **/\r | |
849 | BOOLEAN\r | |
850 | EFIAPI\r | |
851 | InternalX86RdRand32 (\r | |
852 | OUT UINT32 *Rand\r | |
853 | );\r | |
854 | \r | |
855 | /**\r | |
856 | Generates a 64-bit random number through RDRAND instruction.\r | |
857 | \r | |
858 | \r | |
859 | @param[out] Rand Buffer pointer to store the random result.\r | |
860 | \r | |
861 | @retval TRUE RDRAND call was successful.\r | |
862 | @retval FALSE Failed attempts to call RDRAND.\r | |
863 | \r | |
864 | **/\r | |
865 | BOOLEAN\r | |
866 | EFIAPI\r | |
867 | InternalX86RdRand64 (\r | |
868 | OUT UINT64 *Rand\r | |
869 | );\r | |
870 | \r | |
e1f414b6 | 871 | #else\r |
872 | \r | |
873 | #endif\r | |
874 | \r | |
875 | #endif\r |