(VOID**)&NumberDbgDeviceInfo, NULL, NULL}\r
};\r
\r
+/// An ACPI_PARSER array describing the debug device information structure\r
+/// header.\r
+STATIC CONST ACPI_PARSER DbgDevInfoHeaderParser[] = {\r
+ {L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
+ {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL}\r
+};\r
+\r
/// An ACPI_PARSER array describing the debug device information.\r
STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {\r
{L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
- {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL},\r
+ {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},\r
\r
{L"Generic Address Registers Count", 1, 3, L"0x%x", NULL,\r
(VOID**)&GasCount, NULL, NULL},\r
/**\r
This function parses the debug device information structure.\r
\r
- @param [in] Ptr Pointer to the start of the buffer.\r
- @param [out] Length Pointer in which the length of the debug\r
- device information is returned.\r
+ @param [in] Ptr Pointer to the start of the buffer.\r
+ @param [in] Length Length of the debug device information structure.\r
**/\r
STATIC\r
VOID\r
EFIAPI\r
DumpDbgDeviceInfo (\r
- IN UINT8* Ptr,\r
- OUT UINT32* Length\r
+ IN UINT8* Ptr,\r
+ IN UINT16 Length\r
)\r
{\r
UINT16 Index;\r
- UINT8* DataPtr;\r
- UINT32* AddrSize;\r
-\r
- // Parse the debug device info to get the Length\r
- ParseAcpi (\r
- FALSE,\r
- 0,\r
- "Debug Device Info",\r
- Ptr,\r
- 3, // Length is 2 bytes starting at offset 1\r
- PARSER_PARAMS (DbgDevInfoParser)\r
- );\r
+ UINT16 Offset;\r
\r
ParseAcpi (\r
TRUE,\r
2,\r
"Debug Device Info",\r
Ptr,\r
- *DbgDevInfoLen,\r
+ Length,\r
PARSER_PARAMS (DbgDevInfoParser)\r
);\r
\r
- // GAS and Address Size\r
+ // GAS\r
Index = 0;\r
- DataPtr = Ptr + (*BaseAddrRegOffset);\r
- AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));\r
- while (Index < (*GasCount)) {\r
+ Offset = *BaseAddrRegOffset;\r
+ while ((Index++ < *GasCount) &&\r
+ (Offset < Length)) {\r
PrintFieldName (4, L"BaseAddressRegister");\r
- DumpGasStruct (DataPtr, 4, GAS_LENGTH);\r
+ Offset += (UINT16)DumpGasStruct (\r
+ Ptr + Offset,\r
+ 4,\r
+ Length - Offset\r
+ );\r
+ }\r
+\r
+ // Make sure the array of address sizes corresponding to each GAS fit in the\r
+ // Debug Device Information structure\r
+ if ((*AddrSizeOffset + (*GasCount * sizeof (UINT32))) > Length) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"ERROR: Invalid GAS count. GasCount = %d. RemainingBufferLength = %d. " \\r
+ L"Parsing of the Debug Device Information structure aborted.\n",\r
+ *GasCount,\r
+ Length - *AddrSizeOffset\r
+ );\r
+ return;\r
+ }\r
+\r
+ // Address Size\r
+ Index = 0;\r
+ Offset = *AddrSizeOffset;\r
+ while ((Index++ < *GasCount) &&\r
+ (Offset < Length)) {\r
PrintFieldName (4, L"Address Size");\r
- Print (L"0x%x\n", AddrSize[Index]);\r
- DataPtr += GAS_LENGTH;\r
- Index++;\r
+ Print (L"0x%x\n", *((UINT32*)(Ptr + Offset)));\r
+ Offset += sizeof (UINT32);\r
}\r
\r
// NameSpace String\r
Index = 0;\r
- DataPtr = Ptr + (*NameSpaceStringOffset);\r
+ Offset = *NameSpaceStringOffset;\r
PrintFieldName (4, L"NameSpace String");\r
- while (Index < (*NameSpaceStringLength)) {\r
- Print (L"%c", DataPtr[Index++]);\r
+ while ((Index++ < *NameSpaceStringLength) &&\r
+ (Offset < Length)) {\r
+ Print (L"%c", *(Ptr + Offset));\r
+ Offset++;\r
}\r
Print (L"\n");\r
\r
// OEM Data\r
- Index = 0;\r
- DataPtr = Ptr + (*OEMDataOffset);\r
- PrintFieldName (4, L"OEM Data");\r
- while (Index < (*OEMDataLength)) {\r
- Print (L"%x ", DataPtr[Index++]);\r
- if ((Index & 7) == 0) {\r
- Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");\r
+ if (*OEMDataOffset != 0) {\r
+ Index = 0;\r
+ Offset = *OEMDataOffset;\r
+ PrintFieldName (4, L"OEM Data");\r
+ while ((Index++ < *OEMDataLength) &&\r
+ (Offset < Length)) {\r
+ Print (L"%x ", *(Ptr + Offset));\r
+ if ((Index & 7) == 0) {\r
+ Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");\r
+ }\r
+ Offset++;\r
}\r
+ Print (L"\n");\r
}\r
- Print (L"\n");\r
-\r
- *Length = *DbgDevInfoLen;\r
}\r
\r
/**\r
)\r
{\r
UINT32 Offset;\r
- UINT32 DbgDeviceInfoLength;\r
- UINT8* DevInfoPtr;\r
+ UINT32 Index;\r
\r
if (!Trace) {\r
return;\r
AcpiTableLength,\r
PARSER_PARAMS (Dbg2Parser)\r
);\r
- DevInfoPtr = Ptr + Offset;\r
\r
- while (Offset < AcpiTableLength) {\r
- DumpDbgDeviceInfo (\r
- DevInfoPtr,\r
- &DbgDeviceInfoLength\r
+ Offset = *OffsetDbgDeviceInfo;\r
+ Index = 0;\r
+\r
+ while (Index++ < *NumberDbgDeviceInfo) {\r
+\r
+ // Parse the Debug Device Information Structure header to obtain Length\r
+ ParseAcpi (\r
+ FALSE,\r
+ 0,\r
+ NULL,\r
+ Ptr + Offset,\r
+ AcpiTableLength - Offset,\r
+ PARSER_PARAMS (DbgDevInfoHeaderParser)\r
);\r
- Offset += DbgDeviceInfoLength;\r
- DevInfoPtr += DbgDeviceInfoLength;\r
+\r
+ // Make sure the Debug Device Information structure lies inside the table.\r
+ if ((Offset + *DbgDevInfoLen) > AcpiTableLength) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"ERROR: Invalid Debug Device Information structure length. " \\r
+ L"DbgDevInfoLen = %d. RemainingTableBufferLength = %d. " \\r
+ L"DBG2 parsing aborted.\n",\r
+ *DbgDevInfoLen,\r
+ AcpiTableLength - Offset\r
+ );\r
+ return;\r
+ }\r
+\r
+ DumpDbgDeviceInfo (Ptr + Offset, (*DbgDevInfoLen));\r
+ Offset += (*DbgDevInfoLen);\r
}\r
}\r