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