]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dependency/Dependency.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dependency / Dependency.c
index 8146c19ca369f373f847840bcf9d7825d6b9eceb..6ce610a028332e45f9f9248e32258bbc83c7937c 100644 (file)
@@ -5,19 +5,13 @@
   if a driver can be scheduled for execution.  The criteria for\r
   schedulability is that the dependency expression is satisfied.\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-#include <PeiMain.h>\r
-#include "dependency.h"\r
+#include "PeiMain.h"\r
+#include "Dependency.h"\r
 \r
 /**\r
 \r
@@ -26,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   been published and can be queried from the PPI database.\r
 \r
 \r
-  @param PeiServices     The PEI core services table.\r
+  @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
   @param Stack           Reference to EVAL_STACK_ENTRY that contains PPI GUID to check\r
 \r
   @retval TRUE  if the PPI is already installed.\r
@@ -42,17 +36,17 @@ IsPpiInstalled (
   VOID        *PeiInstance;\r
   EFI_STATUS  Status;\r
   EFI_GUID    PpiGuid;\r
-  \r
+\r
   //\r
   // If there is no GUID to evaluate, just return current result on stack.\r
   //\r
   if (Stack->Operator == NULL) {\r
     return Stack->Result;\r
   }\r
-  \r
+\r
   //\r
   // Copy the Guid into a locale variable so that there are no\r
-  // possibilities of alignment faults for cross-compilation \r
+  // possibilities of alignment faults for cross-compilation\r
   // environments such as Intel?Itanium(TM).\r
   //\r
   CopyMem(&PpiGuid, Stack->Operator, sizeof(EFI_GUID));\r
@@ -70,7 +64,7 @@ IsPpiInstalled (
   if (EFI_ERROR(Status)) {\r
     return FALSE;\r
   }\r
-   \r
+\r
   return TRUE;\r
 }\r
 \r
@@ -84,7 +78,7 @@ IsPpiInstalled (
   operation types (AND, OR).\r
 \r
 \r
-  @param PeiServices            Calling context.\r
+  @param PeiServices            An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
   @param DependencyExpression   Pointer to a dependency expression.  The Grammar adheres to\r
                                 the BNF described above and is stored in postfix notation.\r
 \r
@@ -106,23 +100,24 @@ PeimDispatchReadiness (
 \r
   Iterator  = DependencyExpression;\r
 \r
-  StackPtr = &EvalStack[0];\r
+  StackPtr = EvalStack;\r
 \r
   while (TRUE) {\r
 \r
     switch (*(Iterator++)) {\r
-      \r
+\r
       //\r
-      // For performance reason we put the frequently used items in front of \r
+      // For performance reason we put the frequently used items in front of\r
       // the rarely used  items\r
       //\r
-      \r
+\r
       case (EFI_DEP_PUSH):\r
         //\r
         // Check to make sure the dependency grammar doesn't overflow the\r
         // EvalStack on the push\r
         //\r
         if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r
+          DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Underflow Error)\n"));\r
           return FALSE;\r
         }\r
 \r
@@ -132,11 +127,17 @@ PeimDispatchReadiness (
         //\r
         StackPtr->Operator = (VOID *) Iterator;\r
         Iterator = Iterator + sizeof (EFI_GUID);\r
+        DEBUG ((DEBUG_DISPATCH, "  PUSH GUID(%g) = %a\n", StackPtr->Operator, IsPpiInstalled (PeiServices, StackPtr) ? "TRUE" : "FALSE"));\r
         StackPtr++;\r
         break;\r
 \r
-      case (EFI_DEP_AND):    \r
-      case (EFI_DEP_OR):     \r
+      case (EFI_DEP_AND):\r
+      case (EFI_DEP_OR):\r
+        if (*(Iterator - 1) == EFI_DEP_AND) {\r
+          DEBUG ((DEBUG_DISPATCH, "  AND\n"));\r
+        } else {\r
+          DEBUG ((DEBUG_DISPATCH, "  OR\n"));\r
+        }\r
         //\r
         // Check to make sure the dependency grammar doesn't underflow the\r
         // EvalStack on the two POPs for the AND operation.  Don't need to\r
@@ -144,6 +145,7 @@ PeimDispatchReadiness (
         // did two POPs.\r
         //\r
         if (StackPtr < &EvalStack[2]) {\r
+          DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Underflow Error)\n"));\r
           return FALSE;\r
         }\r
 \r
@@ -155,11 +157,11 @@ PeimDispatchReadiness (
         // evaluation of the POPed operator. Otherwise, don't POP the second\r
         // operator since it will now evaluate to the final result on the\r
         // next operand that causes a POP.\r
-        // \r
+        //\r
         StackPtr--;\r
         //\r
-        // Iterator has increased by 1 after we retrieve the operand, so here we \r
-        // should get the value pointed by (Iterator - 1), in order to obtain the \r
+        // Iterator has increased by 1 after we retrieve the operand, so here we\r
+        // should get the value pointed by (Iterator - 1), in order to obtain the\r
         // same operand.\r
         //\r
         if (*(Iterator - 1) == EFI_DEP_AND) {\r
@@ -174,20 +176,23 @@ PeimDispatchReadiness (
           }\r
         }\r
         break;\r
-        \r
+\r
       case (EFI_DEP_END):\r
+        DEBUG ((DEBUG_DISPATCH, "  END\n"));\r
         StackPtr--;\r
         //\r
         // Check to make sure EvalStack is balanced.  If not, then there is\r
         // an error in the dependency grammar, so return EFI_INVALID_PARAMETER.\r
         //\r
         if (StackPtr != &EvalStack[0]) {\r
+          DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Underflow Error)\n"));\r
           return FALSE;\r
         }\r
+        DEBUG ((DEBUG_DISPATCH, "  RESULT = %a\n", IsPpiInstalled (PeiServices, StackPtr) ? "TRUE" : "FALSE"));\r
         return IsPpiInstalled (PeiServices, StackPtr);\r
-        break;\r
 \r
-      case (EFI_DEP_NOT):    \r
+      case (EFI_DEP_NOT):\r
+        DEBUG ((DEBUG_DISPATCH, "  NOT\n"));\r
         //\r
         // Check to make sure the dependency grammar doesn't underflow the\r
         // EvalStack on the POP for the NOT operation.  Don't need to\r
@@ -195,6 +200,7 @@ PeimDispatchReadiness (
         // did a POP.\r
         //\r
         if (StackPtr < &EvalStack[1]) {\r
+          DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Underflow Error)\n"));\r
           return FALSE;\r
         }\r
         (StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));\r
@@ -203,16 +209,22 @@ PeimDispatchReadiness (
 \r
       case (EFI_DEP_TRUE):\r
       case (EFI_DEP_FALSE):\r
+        if (*(Iterator - 1) == EFI_DEP_TRUE) {\r
+          DEBUG ((DEBUG_DISPATCH, "  TRUE\n"));\r
+        } else {\r
+          DEBUG ((DEBUG_DISPATCH, "  FALSE\n"));\r
+        }\r
         //\r
         // Check to make sure the dependency grammar doesn't overflow the\r
         // EvalStack on the push\r
         //\r
         if (StackPtr > &EvalStack[MAX_GRAMMAR_SIZE-1]) {\r
+          DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Underflow Error)\n"));\r
           return FALSE;\r
         }\r
         //\r
-        // Iterator has increased by 1 after we retrieve the operand, so here we \r
-        // should get the value pointed by (Iterator - 1), in order to obtain the \r
+        // Iterator has increased by 1 after we retrieve the operand, so here we\r
+        // should get the value pointed by (Iterator - 1), in order to obtain the\r
         // same operand.\r
         //\r
         if (*(Iterator - 1) == EFI_DEP_TRUE) {\r
@@ -225,11 +237,11 @@ PeimDispatchReadiness (
         break;\r
 \r
       default:\r
+        DEBUG ((DEBUG_DISPATCH, "  RESULT = FALSE (Invalid opcode)\n"));\r
         //\r
         // The grammar should never arrive here\r
         //\r
         return FALSE;\r
-        break;\r
     }\r
   }\r
 }\r