+ // According to the content structure of Buffer shown above, the size of\r
+ // the FormatString buffer is the size of Buffer minus the Padding\r
+ // (4 bytes), minus the size of EFI_DEBUG_INFO, minus the size of\r
+ // variable arguments (12 * sizeof (UINT64)).\r
+ //\r
+ DestBufferSize = sizeof (Buffer) - 4 - sizeof (EFI_DEBUG_INFO) - 12 * sizeof (UINT64);\r
+ AsciiStrnCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format, DestBufferSize / sizeof (CHAR8) - 1);\r
+\r
+ //\r
+ // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
+ // of format in DEBUG string, which is followed by the DEBUG format string.\r
+ // Here we will process the variable arguments and pack them in this area.\r
+ //\r
+ for (; *Format != '\0'; Format++) {\r
+ //\r
+ // Only format with prefix % is processed.\r
+ //\r
+ if (*Format != '%') {\r
+ continue;\r
+ }\r
+ Long = FALSE;\r
+ //\r
+ // Parse Flags and Width\r
+ //\r
+ for (Format++; TRUE; Format++) {\r
+ if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {\r
+ //\r
+ // These characters in format field are omitted.\r
+ //\r
+ continue;\r
+ }\r
+ if (*Format >= '0' && *Format <= '9') {\r
+ //\r
+ // These characters in format field are omitted.\r
+ //\r
+ continue;\r
+ }\r
+ if (*Format == 'L' || *Format == 'l') {\r
+ //\r
+ // 'L" or "l" in format field means the number being printed is a UINT64\r
+ //\r
+ Long = TRUE;\r
+ continue;\r
+ }\r
+ if (*Format == '*') {\r
+ //\r
+ // '*' in format field means the precision of the field is specified by\r
+ // a UINTN argument in the argument list.\r
+ //\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);\r
+ }\r
+ continue;\r
+ }\r
+ if (*Format == '\0') {\r
+ //\r
+ // Make no output if Format string terminates unexpectedly when\r
+ // looking up for flag, width, precision and type.\r
+ //\r
+ Format--;\r
+ }\r
+ //\r
+ // When valid argument type detected or format string terminates unexpectedly,\r
+ // the inner loop is done.\r
+ //\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Pack variable arguments into the storage area following EFI_DEBUG_INFO.\r
+ //\r
+ if ((*Format == 'p') && (sizeof (VOID *) > 4)) {\r
+ Long = TRUE;\r
+ }\r
+ if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') {\r
+ if (Long) {\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, INT64) = VA_ARG (VaListMarker, INT64);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, INT64) = BASE_ARG (BaseListMarker, INT64);\r
+ }\r
+ } else {\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, int) = VA_ARG (VaListMarker, int);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, int) = BASE_ARG (BaseListMarker, int);\r
+ }\r
+ }\r
+ } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, VOID *) = VA_ARG (VaListMarker, VOID *);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, VOID *) = BASE_ARG (BaseListMarker, VOID *);\r
+ }\r
+ } else if (*Format == 'c') {\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);\r
+ }\r
+ } else if (*Format == 'r') {\r
+ if (BaseListMarker == NULL) {\r
+ BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
+ } else {\r
+ BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = BASE_ARG (BaseListMarker, RETURN_STATUS);\r
+ }\r
+ }\r
+\r
+ //\r
+ // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()\r
+ // This indicates that the DEBUG() macro is passing in more argument than can be handled by\r
+ // the EFI_DEBUG_INFO record\r
+ //\r
+ ASSERT ((CHAR8 *)BaseListMarkerPointer <= FormatString);\r
+\r
+ //\r
+ // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r
+ //\r
+ if ((CHAR8 *)BaseListMarkerPointer > FormatString) {\r
+ return;\r
+ }\r