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