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