]>
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 | |
2f88bd3a MK |
38 | IN UINT64 Operand,\r |
39 | IN UINTN Count\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
58 | IN UINT64 Operand,\r |
59 | IN UINTN Count\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
78 | IN UINT64 Operand,\r |
79 | IN UINTN Count\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
99 | IN UINT64 Operand,\r |
100 | IN UINTN Count\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
120 | IN UINT64 Operand,\r |
121 | IN UINTN Count\r | |
e1f414b6 | 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 | |
2f88bd3a | 139 | IN UINT64 Operand\r |
e1f414b6 | 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 | |
2f88bd3a MK |
159 | IN UINT64 Multiplicand,\r |
160 | IN UINT32 Multiplier\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
180 | IN UINT64 Multiplicand,\r |
181 | IN UINT64 Multiplier\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
201 | IN UINT64 Dividend,\r |
202 | IN UINT32 Divisor\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
222 | IN UINT64 Dividend,\r |
223 | IN UINT32 Divisor\r | |
e1f414b6 | 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 | |
2f88bd3a MK |
246 | IN UINT64 Dividend,\r |
247 | IN UINT32 Divisor,\r | |
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 | |
2f88bd3a MK |
271 | IN UINT64 Dividend,\r |
272 | IN UINT64 Divisor,\r | |
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 |
2f88bd3a MK |
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 | |
d0e2f823 MK |
329 | IN VOID *Context1 OPTIONAL,\r |
330 | IN VOID *Context2 OPTIONAL,\r | |
e1f414b6 | 331 | IN VOID *NewStack,\r |
332 | IN VA_LIST Marker\r | |
333 | );\r | |
334 | \r | |
e1f414b6 | 335 | /**\r |
24dcb5e5 | 336 | Worker function that returns a bit field from Operand.\r |
e1f414b6 | 337 | \r |
338 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
339 | \r | |
340 | @param Operand Operand on which to perform the bitfield operation.\r | |
341 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
342 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
343 | \r | |
344 | @return The bit field read.\r | |
345 | \r | |
346 | **/\r | |
28ca72bc | 347 | UINTN\r |
38bbd3d9 | 348 | EFIAPI\r |
e1f414b6 | 349 | BitFieldReadUint (\r |
2f88bd3a MK |
350 | IN UINTN Operand,\r |
351 | IN UINTN StartBit,\r | |
352 | IN UINTN EndBit\r | |
e1f414b6 | 353 | );\r |
354 | \r | |
e1f414b6 | 355 | /**\r |
356 | Worker function that reads a bit field from Operand, performs a bitwise OR,\r | |
357 | and returns the result.\r | |
358 | \r | |
359 | Performs a bitwise OR between the bit field specified by StartBit and EndBit\r | |
360 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
361 | preserved. The new value is returned.\r | |
362 | \r | |
363 | @param Operand Operand on which to perform the bitfield operation.\r | |
364 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
365 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
366 | @param OrData The value to OR with the read value from the value\r | |
367 | \r | |
368 | @return The new value.\r | |
369 | \r | |
370 | **/\r | |
28ca72bc | 371 | UINTN\r |
38bbd3d9 | 372 | EFIAPI\r |
e1f414b6 | 373 | BitFieldOrUint (\r |
2f88bd3a MK |
374 | IN UINTN Operand,\r |
375 | IN UINTN StartBit,\r | |
376 | IN UINTN EndBit,\r | |
377 | IN UINTN OrData\r | |
e1f414b6 | 378 | );\r |
379 | \r | |
e1f414b6 | 380 | /**\r |
381 | Worker function that reads a bit field from Operand, performs a bitwise AND,\r | |
382 | and returns the result.\r | |
383 | \r | |
384 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
385 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
386 | preserved. The new value is returned.\r | |
387 | \r | |
388 | @param Operand Operand on which to perform the bitfield operation.\r | |
389 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
390 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
391 | @param AndData The value to And with the read value from the value\r | |
392 | \r | |
393 | @return The new value.\r | |
394 | \r | |
395 | **/\r | |
28ca72bc | 396 | UINTN\r |
38bbd3d9 | 397 | EFIAPI\r |
e1f414b6 | 398 | BitFieldAndUint (\r |
2f88bd3a MK |
399 | IN UINTN Operand,\r |
400 | IN UINTN StartBit,\r | |
401 | IN UINTN EndBit,\r | |
402 | IN UINTN AndData\r | |
e1f414b6 | 403 | );\r |
404 | \r | |
e1f414b6 | 405 | /**\r |
406 | Worker function that checks ASSERT condition for JumpBuffer\r | |
407 | \r | |
408 | Checks ASSERT condition for JumpBuffer.\r | |
409 | \r | |
410 | If JumpBuffer is NULL, then ASSERT().\r | |
411 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r | |
412 | \r | |
413 | @param JumpBuffer A pointer to CPU context buffer.\r | |
414 | \r | |
415 | **/\r | |
416 | VOID\r | |
38bbd3d9 | 417 | EFIAPI\r |
e1f414b6 | 418 | InternalAssertJumpBuffer (\r |
419 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r | |
420 | );\r | |
421 | \r | |
e1f414b6 | 422 | /**\r |
423 | Restores the CPU context that was saved with SetJump().\r | |
424 | \r | |
425 | Restores the CPU context from the buffer specified by JumpBuffer.\r | |
426 | This function never returns to the caller.\r | |
427 | Instead is resumes execution based on the state of JumpBuffer.\r | |
428 | \r | |
429 | @param JumpBuffer A pointer to CPU context buffer.\r | |
430 | @param Value The value to return when the SetJump() context is restored.\r | |
431 | \r | |
432 | **/\r | |
433 | VOID\r | |
434 | EFIAPI\r | |
435 | InternalLongJump (\r | |
436 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,\r | |
437 | IN UINTN Value\r | |
438 | );\r | |
439 | \r | |
d8af3301 HW |
440 | /**\r |
441 | Check if a Unicode character is a decimal character.\r | |
442 | \r | |
443 | This internal function checks if a Unicode character is a\r | |
444 | decimal character. The valid decimal character is from\r | |
445 | L'0' to L'9'.\r | |
446 | \r | |
447 | @param Char The character to check against.\r | |
448 | \r | |
449 | @retval TRUE If the Char is a decmial character.\r | |
450 | @retval FALSE If the Char is not a decmial character.\r | |
451 | \r | |
452 | **/\r | |
453 | BOOLEAN\r | |
454 | EFIAPI\r | |
455 | InternalIsDecimalDigitCharacter (\r | |
2f88bd3a | 456 | IN CHAR16 Char\r |
d8af3301 HW |
457 | );\r |
458 | \r | |
d8af3301 HW |
459 | /**\r |
460 | Convert a Unicode character to numerical value.\r | |
461 | \r | |
462 | This internal function only deal with Unicode character\r | |
463 | which maps to a valid hexadecimal ASII character, i.e.\r | |
464 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r | |
465 | Unicode character, the value returned does not make sense.\r | |
466 | \r | |
467 | @param Char The character to convert.\r | |
468 | \r | |
469 | @return The numerical value converted.\r | |
470 | \r | |
471 | **/\r | |
472 | UINTN\r | |
473 | EFIAPI\r | |
474 | InternalHexCharToUintn (\r | |
2f88bd3a | 475 | IN CHAR16 Char\r |
d8af3301 HW |
476 | );\r |
477 | \r | |
d8af3301 HW |
478 | /**\r |
479 | Check if a Unicode character is a hexadecimal character.\r | |
480 | \r | |
481 | This internal function checks if a Unicode character is a\r | |
482 | decimal character. The valid hexadecimal character is\r | |
483 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
484 | \r | |
485 | \r | |
486 | @param Char The character to check against.\r | |
487 | \r | |
488 | @retval TRUE If the Char is a hexadecmial character.\r | |
489 | @retval FALSE If the Char is not a hexadecmial character.\r | |
490 | \r | |
491 | **/\r | |
492 | BOOLEAN\r | |
493 | EFIAPI\r | |
494 | InternalIsHexaDecimalDigitCharacter (\r | |
2f88bd3a | 495 | IN CHAR16 Char\r |
d8af3301 HW |
496 | );\r |
497 | \r | |
d8af3301 HW |
498 | /**\r |
499 | Check if a ASCII character is a decimal character.\r | |
500 | \r | |
501 | This internal function checks if a Unicode character is a\r | |
502 | decimal character. The valid decimal character is from\r | |
503 | '0' to '9'.\r | |
504 | \r | |
505 | @param Char The character to check against.\r | |
506 | \r | |
507 | @retval TRUE If the Char is a decmial character.\r | |
508 | @retval FALSE If the Char is not a decmial character.\r | |
509 | \r | |
510 | **/\r | |
511 | BOOLEAN\r | |
512 | EFIAPI\r | |
513 | InternalAsciiIsDecimalDigitCharacter (\r | |
2f88bd3a | 514 | IN CHAR8 Char\r |
d8af3301 HW |
515 | );\r |
516 | \r | |
d8af3301 HW |
517 | /**\r |
518 | Check if a ASCII character is a hexadecimal character.\r | |
519 | \r | |
520 | This internal function checks if a ASCII character is a\r | |
521 | decimal character. The valid hexadecimal character is\r | |
522 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r | |
523 | \r | |
524 | \r | |
525 | @param Char The character to check against.\r | |
526 | \r | |
527 | @retval TRUE If the Char is a hexadecmial character.\r | |
528 | @retval FALSE If the Char is not a hexadecmial character.\r | |
529 | \r | |
530 | **/\r | |
531 | BOOLEAN\r | |
532 | EFIAPI\r | |
533 | InternalAsciiIsHexaDecimalDigitCharacter (\r | |
2f88bd3a | 534 | IN CHAR8 Char\r |
d8af3301 HW |
535 | );\r |
536 | \r | |
d8af3301 HW |
537 | /**\r |
538 | Convert a ASCII character to numerical value.\r | |
539 | \r | |
540 | This internal function only deal with Unicode character\r | |
541 | which maps to a valid hexadecimal ASII character, i.e.\r | |
542 | '0' to '9', 'a' to 'f' or 'A' to 'F'. For other\r | |
543 | ASCII character, the value returned does not make sense.\r | |
544 | \r | |
545 | @param Char The character to convert.\r | |
546 | \r | |
547 | @return The numerical value converted.\r | |
548 | \r | |
549 | **/\r | |
550 | UINTN\r | |
551 | EFIAPI\r | |
552 | InternalAsciiHexCharToUintn (\r | |
2f88bd3a | 553 | IN CHAR8 Char\r |
d8af3301 HW |
554 | );\r |
555 | \r | |
e1f414b6 | 556 | //\r |
557 | // Ia32 and x64 specific functions\r | |
558 | //\r | |
559 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r | |
560 | \r | |
561 | /**\r | |
562 | Reads the current Global Descriptor Table Register(GDTR) descriptor.\r | |
563 | \r | |
564 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r | |
030cd1a2 | 565 | function is only available on IA-32 and x64.\r |
e1f414b6 | 566 | \r |
127010dd | 567 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 568 | \r |
569 | **/\r | |
570 | VOID\r | |
571 | EFIAPI\r | |
572 | InternalX86ReadGdtr (\r | |
2f88bd3a | 573 | OUT IA32_DESCRIPTOR *Gdtr\r |
e1f414b6 | 574 | );\r |
575 | \r | |
576 | /**\r | |
577 | Writes the current Global Descriptor Table Register (GDTR) descriptor.\r | |
578 | \r | |
579 | Writes and the current GDTR descriptor specified by Gdtr. This function is\r | |
030cd1a2 | 580 | only available on IA-32 and x64.\r |
e1f414b6 | 581 | \r |
127010dd | 582 | @param Gdtr The pointer to a GDTR descriptor.\r |
e1f414b6 | 583 | \r |
584 | **/\r | |
585 | VOID\r | |
586 | EFIAPI\r | |
587 | InternalX86WriteGdtr (\r | |
2f88bd3a | 588 | IN CONST IA32_DESCRIPTOR *Gdtr\r |
e1f414b6 | 589 | );\r |
590 | \r | |
591 | /**\r | |
592 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
593 | \r | |
594 | Reads and returns the current IDTR descriptor and returns it in Idtr. This\r | |
030cd1a2 | 595 | function is only available on IA-32 and x64.\r |
e1f414b6 | 596 | \r |
127010dd | 597 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 598 | \r |
599 | **/\r | |
600 | VOID\r | |
601 | EFIAPI\r | |
602 | InternalX86ReadIdtr (\r | |
2f88bd3a | 603 | OUT IA32_DESCRIPTOR *Idtr\r |
e1f414b6 | 604 | );\r |
605 | \r | |
606 | /**\r | |
607 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
608 | \r | |
609 | Writes the current IDTR descriptor and returns it in Idtr. This function is\r | |
030cd1a2 | 610 | only available on IA-32 and x64.\r |
e1f414b6 | 611 | \r |
127010dd | 612 | @param Idtr The pointer to an IDTR descriptor.\r |
e1f414b6 | 613 | \r |
614 | **/\r | |
615 | VOID\r | |
616 | EFIAPI\r | |
617 | InternalX86WriteIdtr (\r | |
2f88bd3a | 618 | IN CONST IA32_DESCRIPTOR *Idtr\r |
e1f414b6 | 619 | );\r |
620 | \r | |
621 | /**\r | |
622 | Save the current floating point/SSE/SSE2 context to a buffer.\r | |
623 | \r | |
624 | Saves the current floating point/SSE/SSE2 state to the buffer specified by\r | |
625 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r | |
030cd1a2 | 626 | available on IA-32 and x64.\r |
e1f414b6 | 627 | \r |
127010dd | 628 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 629 | \r |
630 | **/\r | |
631 | VOID\r | |
632 | EFIAPI\r | |
633 | InternalX86FxSave (\r | |
2f88bd3a | 634 | OUT IA32_FX_BUFFER *Buffer\r |
e1f414b6 | 635 | );\r |
636 | \r | |
637 | /**\r | |
638 | Restores the current floating point/SSE/SSE2 context from a buffer.\r | |
639 | \r | |
640 | Restores the current floating point/SSE/SSE2 state from the buffer specified\r | |
641 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r | |
030cd1a2 | 642 | only available on IA-32 and x64.\r |
e1f414b6 | 643 | \r |
127010dd | 644 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
e1f414b6 | 645 | \r |
646 | **/\r | |
647 | VOID\r | |
648 | EFIAPI\r | |
649 | InternalX86FxRestore (\r | |
2f88bd3a | 650 | IN CONST IA32_FX_BUFFER *Buffer\r |
e1f414b6 | 651 | );\r |
652 | \r | |
653 | /**\r | |
654 | Enables the 32-bit paging mode on the CPU.\r | |
655 | \r | |
656 | Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
657 | must be properly initialized prior to calling this service. This function\r | |
658 | assumes the current execution mode is 32-bit protected mode. This function is\r | |
659 | only available on IA-32. After the 32-bit paging mode is enabled, control is\r | |
660 | transferred to the function specified by EntryPoint using the new stack\r | |
661 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
662 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
663 | EntryPoint must never return.\r | |
664 | \r | |
665 | There are a number of constraints that must be followed before calling this\r | |
666 | function:\r | |
667 | 1) Interrupts must be disabled.\r | |
668 | 2) The caller must be in 32-bit protected mode with flat descriptors. This\r | |
669 | means all descriptors must have a base of 0 and a limit of 4GB.\r | |
670 | 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r | |
671 | descriptors.\r | |
672 | 4) CR3 must point to valid page tables that will be used once the transition\r | |
673 | is complete, and those page tables must guarantee that the pages for this\r | |
674 | function and the stack are identity mapped.\r | |
675 | \r | |
676 | @param EntryPoint A pointer to function to call with the new stack after\r | |
677 | paging is enabled.\r | |
678 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
679 | function as the first parameter after paging is enabled.\r | |
680 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
681 | function as the second parameter after paging is enabled.\r | |
682 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
683 | function after paging is enabled.\r | |
684 | \r | |
685 | **/\r | |
686 | VOID\r | |
687 | EFIAPI\r | |
688 | InternalX86EnablePaging32 (\r | |
689 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
d0e2f823 MK |
690 | IN VOID *Context1 OPTIONAL,\r |
691 | IN VOID *Context2 OPTIONAL,\r | |
e1f414b6 | 692 | IN VOID *NewStack\r |
693 | );\r | |
694 | \r | |
695 | /**\r | |
696 | Disables the 32-bit paging mode on the CPU.\r | |
697 | \r | |
698 | Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r | |
699 | mode. This function assumes the current execution mode is 32-paged protected\r | |
700 | mode. This function is only available on IA-32. After the 32-bit paging mode\r | |
701 | is disabled, control is transferred to the function specified by EntryPoint\r | |
702 | using the new stack specified by NewStack and passing in the parameters\r | |
703 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
704 | may be NULL. The function EntryPoint must never return.\r | |
705 | \r | |
706 | There are a number of constraints that must be followed before calling this\r | |
707 | function:\r | |
708 | 1) Interrupts must be disabled.\r | |
709 | 2) The caller must be in 32-bit paged mode.\r | |
710 | 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r | |
711 | 4) CR3 must point to valid page tables that guarantee that the pages for\r | |
712 | this function and the stack are identity mapped.\r | |
713 | \r | |
714 | @param EntryPoint A pointer to function to call with the new stack after\r | |
715 | paging is disabled.\r | |
716 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
717 | function as the first parameter after paging is disabled.\r | |
718 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
719 | function as the second parameter after paging is\r | |
720 | disabled.\r | |
721 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
722 | function after paging is disabled.\r | |
723 | \r | |
724 | **/\r | |
725 | VOID\r | |
726 | EFIAPI\r | |
727 | InternalX86DisablePaging32 (\r | |
728 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
d0e2f823 MK |
729 | IN VOID *Context1 OPTIONAL,\r |
730 | IN VOID *Context2 OPTIONAL,\r | |
e1f414b6 | 731 | IN VOID *NewStack\r |
732 | );\r | |
733 | \r | |
734 | /**\r | |
735 | Enables the 64-bit paging mode on the CPU.\r | |
736 | \r | |
737 | Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
738 | must be properly initialized prior to calling this service. This function\r | |
739 | assumes the current execution mode is 32-bit protected mode with flat\r | |
740 | descriptors. This function is only available on IA-32. After the 64-bit\r | |
741 | paging mode is enabled, control is transferred to the function specified by\r | |
742 | EntryPoint using the new stack specified by NewStack and passing in the\r | |
743 | parameters specified by Context1 and Context2. Context1 and Context2 are\r | |
744 | optional and may be 0. The function EntryPoint must never return.\r | |
745 | \r | |
746 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
747 | is called. The descriptor in the GDT that this selector\r | |
748 | references must be setup for long mode.\r | |
749 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
750 | the new stack after paging is enabled.\r | |
751 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
752 | the EntryPoint function as the first parameter after\r | |
753 | paging is enabled.\r | |
754 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
755 | the EntryPoint function as the second parameter after\r | |
756 | paging is enabled.\r | |
757 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
758 | the EntryPoint function after paging is enabled.\r | |
759 | \r | |
760 | **/\r | |
761 | VOID\r | |
762 | EFIAPI\r | |
763 | InternalX86EnablePaging64 (\r | |
2f88bd3a MK |
764 | IN UINT16 Cs,\r |
765 | IN UINT64 EntryPoint,\r | |
766 | IN UINT64 Context1 OPTIONAL,\r | |
767 | IN UINT64 Context2 OPTIONAL,\r | |
768 | IN UINT64 NewStack\r | |
e1f414b6 | 769 | );\r |
770 | \r | |
771 | /**\r | |
772 | Disables the 64-bit paging mode on the CPU.\r | |
773 | \r | |
774 | Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r | |
775 | mode. This function assumes the current execution mode is 64-paging mode.\r | |
030cd1a2 | 776 | This function is only available on x64. After the 64-bit paging mode is\r |
e1f414b6 | 777 | disabled, control is transferred to the function specified by EntryPoint\r |
778 | using the new stack specified by NewStack and passing in the parameters\r | |
779 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
780 | may be 0. The function EntryPoint must never return.\r | |
781 | \r | |
782 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
783 | is called. The descriptor in the GDT that this selector\r | |
784 | references must be setup for 32-bit protected mode.\r | |
785 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
786 | the new stack after paging is disabled.\r | |
787 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
788 | the EntryPoint function as the first parameter after\r | |
789 | paging is disabled.\r | |
790 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
791 | the EntryPoint function as the second parameter after\r | |
792 | paging is disabled.\r | |
793 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
794 | the EntryPoint function after paging is disabled.\r | |
795 | \r | |
796 | **/\r | |
797 | VOID\r | |
798 | EFIAPI\r | |
799 | InternalX86DisablePaging64 (\r | |
2f88bd3a MK |
800 | IN UINT16 Cs,\r |
801 | IN UINT32 EntryPoint,\r | |
802 | IN UINT32 Context1 OPTIONAL,\r | |
803 | IN UINT32 Context2 OPTIONAL,\r | |
804 | IN UINT32 NewStack\r | |
e1f414b6 | 805 | );\r |
806 | \r | |
9ec9a7a5 QL |
807 | /**\r |
808 | Generates a 16-bit random number through RDRAND instruction.\r | |
809 | \r | |
810 | @param[out] Rand Buffer pointer to store the random result.\r | |
811 | \r | |
812 | @retval TRUE RDRAND call was successful.\r | |
813 | @retval FALSE Failed attempts to call RDRAND.\r | |
814 | \r | |
815 | **/\r | |
816 | BOOLEAN\r | |
817 | EFIAPI\r | |
818 | InternalX86RdRand16 (\r | |
2f88bd3a | 819 | OUT UINT16 *Rand\r |
9ec9a7a5 QL |
820 | );\r |
821 | \r | |
822 | /**\r | |
823 | Generates a 32-bit random number through RDRAND instruction.\r | |
824 | \r | |
825 | @param[out] Rand Buffer pointer to store the random result.\r | |
826 | \r | |
827 | @retval TRUE RDRAND call was successful.\r | |
828 | @retval FALSE Failed attempts to call RDRAND.\r | |
829 | \r | |
830 | **/\r | |
831 | BOOLEAN\r | |
832 | EFIAPI\r | |
833 | InternalX86RdRand32 (\r | |
2f88bd3a | 834 | OUT UINT32 *Rand\r |
9ec9a7a5 QL |
835 | );\r |
836 | \r | |
837 | /**\r | |
838 | Generates a 64-bit random number through RDRAND instruction.\r | |
839 | \r | |
840 | \r | |
841 | @param[out] Rand Buffer pointer to store the random result.\r | |
842 | \r | |
843 | @retval TRUE RDRAND call was successful.\r | |
844 | @retval FALSE Failed attempts to call RDRAND.\r | |
845 | \r | |
846 | **/\r | |
847 | BOOLEAN\r | |
848 | EFIAPI\r | |
849 | InternalX86RdRand64 (\r | |
2f88bd3a | 850 | OUT UINT64 *Rand\r |
9ec9a7a5 QL |
851 | );\r |
852 | \r | |
e1f414b6 | 853 | #else\r |
854 | \r | |
855 | #endif\r | |
856 | \r | |
857 | #endif\r |