From 0dd56c8dae139bf6ba1339313341520ecc426590 Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Mon, 23 Sep 2024 17:35:27 +0300 Subject: [PATCH] CpuExceptionHandlerLib: Added PcdSerialUseMmio condition. --- MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + .../Core/Dxe/SysCall/Initialization.c | 4 +-- .../DxeCpuExceptionHandlerLib.inf | 1 + .../Ia32/ArchExceptionHandler.c | 27 ++++++++++-------- .../PeiCpuExceptionHandlerLib.inf | 1 + .../SecPeiCpuExceptionHandlerLib.inf | 1 + .../SmmCpuExceptionHandlerLib.inf | 1 + .../X64/ArchExceptionHandler.c | 28 ++++++++++--------- 8 files changed, 37 insertions(+), 27 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index 6b15d89df8..7262cafecd 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -149,6 +149,7 @@ gEfiHobMemoryAllocStackGuid ## SOMETIMES_CONSUMES ## SystemTable gUefiImageLoaderImageContextGuid ## CONSUMES ## HOB gEfiGlobalVariableGuid ## SOMETIMES_CONSUMES ## SysCall + gEarlyPL011BaseAddressGuid ## CONSUMES [Ppis] gEfiVectorHandoffInfoPpiGuid ## UNDEFINED # HOB diff --git a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c index 383e0579fc..2a2995a704 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/Initialization.c +++ b/MdeModulePkg/Core/Dxe/SysCall/Initialization.c @@ -58,7 +58,7 @@ InitializeRing3 ( CopyMem ((VOID *)gRing3Data, (VOID *)Image->Info.SystemTable, sizeof (EFI_SYSTEM_TABLE)); - if (FixedPcdGetBool (PcdSerialUseMmio)) { + if (PcdGetBool (PcdSerialUseMmio)) { Status = CoreAllocatePages ( AllocateAnyPages, EfiRing3MemoryType, @@ -79,7 +79,7 @@ InitializeRing3 ( if (CompareGuid (&gEfiHobListGuid, &(Conf->VendorGuid))) { UartBase = GET_GUID_HOB_DATA (Conf->VendorTable); - gUartBaseAddress = UartBase->DebugAddress; + gUartBaseAddress = (UINTN)UartBase->DebugAddress; } ++Conf; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf index 03d209b81a..8b0f85abb9 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf @@ -52,6 +52,7 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c index dfd803c7a6..ebc98b7b30 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c @@ -231,22 +231,25 @@ ArchSetupExceptionStack ( StackTop -= CPU_KNOWN_GOOD_STACK_SIZE; Tss->SS0 = AsmReadSs (); Tss->IOMapBaseAddress = sizeof (IA32_TASK_STATE_SEGMENT); - // - // Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06; - // and DebugIoPort = 0x402. - // + IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress); SetMem (IOBitMap, IO_BIT_MAP_SIZE, 0xFF); - IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdUartBase) / 8); - Offset = (UINT8)(FixedPcdGet16 (PcdUartBase) & 0x7U); - *(UINT16 *)IOBitMapPointer &= ~((1U << Offset) | (1U << (Offset + 1)) - | (1U << (Offset + 3)) | (1U << (Offset + 4)) - | (1U << (Offset + 5)) | (1U << (Offset + 6))); + if (!PcdGetBool (PcdSerialUseMmio)) { + // + // Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06; + // and DebugIoPort = 0x402. + // + IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdUartBase) / 8); + Offset = (UINT8)(FixedPcdGet16 (PcdUartBase) & 0x7U); + *(UINT16 *)IOBitMapPointer &= ~((1U << Offset) | (1U << (Offset + 1)) + | (1U << (Offset + 3)) | (1U << (Offset + 4)) + | (1U << (Offset + 5)) | (1U << (Offset + 6))); - IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdDebugIoPort) / 8); - Offset = (UINT8)(FixedPcdGet16 (PcdDebugIoPort) & 0x7U); - *IOBitMapPointer &= ~(1U << Offset); + IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdDebugIoPort) / 8); + Offset = (UINT8)(FixedPcdGet16 (PcdDebugIoPort) & 0x7U); + *IOBitMapPointer &= ~(1U << Offset); + } Tss = (IA32_TASK_STATE_SEGMENT *)((UINTN)Tss + sizeof (IA32_TASK_STATE_SEGMENT) + IO_BIT_MAP_SIZE); ++TssDesc; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf index fbde353661..d03cafa91c 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf @@ -61,6 +61,7 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf index eeb09f089d..436401cfde 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf @@ -72,6 +72,7 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf index a21ecd56b8..8c72763b80 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf @@ -59,6 +59,7 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c index 236e72b78b..95b8a9e962 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c @@ -238,23 +238,25 @@ ArchSetupExceptionStack ( Tss->RSP0 = StackTop; StackTop -= CPU_KNOWN_GOOD_STACK_SIZE; Tss->IOMapBaseAddress = sizeof (IA32_TASK_STATE_SEGMENT); - // - // Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06; - // and DebugIoPort = 0x402. - // + IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress); SetMem (IOBitMap, IO_BIT_MAP_SIZE, 0xFF); - IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdUartBase) / 8); - Offset = (UINT8)(FixedPcdGet16 (PcdUartBase) & 0x7U); - *(UINT16 *)IOBitMapPointer &= ~((1U << Offset) | (1U << (Offset + 1)) - | (1U << (Offset + 3)) | (1U << (Offset + 4)) - | (1U << (Offset + 5)) | (1U << (Offset + 6))); - - IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdDebugIoPort) / 8); - Offset = (UINT8)(FixedPcdGet16 (PcdDebugIoPort) & 0x7U); - *IOBitMapPointer &= ~(1U << Offset); + if (!PcdGetBool (PcdSerialUseMmio)) { + // + // Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06; + // and DebugIoPort = 0x402. + // + IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdUartBase) / 8); + Offset = (UINT8)(FixedPcdGet16 (PcdUartBase) & 0x7U); + *(UINT16 *)IOBitMapPointer &= ~((1U << Offset) | (1U << (Offset + 1)) + | (1U << (Offset + 3)) | (1U << (Offset + 4)) + | (1U << (Offset + 5)) | (1U << (Offset + 6))); + IOBitMapPointer = (UINT8 *)((UINTN)IOBitMap + FixedPcdGet16 (PcdDebugIoPort) / 8); + Offset = (UINT8)(FixedPcdGet16 (PcdDebugIoPort) & 0x7U); + *IOBitMapPointer &= ~(1U << Offset); + } // // Fixup IST and task-state segment //