CpuExceptionHandlerLib: Refactored IO Bit Map initialization.

This commit is contained in:
Mikhail Krichanov 2024-09-17 11:37:46 +03:00
parent 2700df080d
commit 9c2eb6d642
4 changed files with 26 additions and 22 deletions

View File

@ -136,6 +136,8 @@ ArchSetupExceptionStack (
UINTN NeedBufferSize;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
UINT8 *IOBitMap;
UINT8 *IOBitMapPointer;
UINT8 Offset;
if (BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
@ -234,17 +236,17 @@ ArchSetupExceptionStack (
// and DebugIoPort = 0x402.
//
IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress);
for (Index = 0; Index < IO_BIT_MAP_SIZE; ++Index) {
if ((Index * 8) == FixedPcdGet16 (PcdUartBase)) {
*IOBitMap = 0x84;
} else if ((Index * 8) == (FixedPcdGet16 (PcdDebugIoPort) - 2)) {
*IOBitMap = 0xFB;
} else {
*IOBitMap = 0xFF;
}
SetMem (IOBitMap, IO_BIT_MAP_SIZE, 0xFF);
++IOBitMap;
}
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);
Tss = (IA32_TASK_STATE_SEGMENT *)((UINTN)Tss + sizeof (IA32_TASK_STATE_SEGMENT) + IO_BIT_MAP_SIZE);
++TssDesc;

View File

@ -39,7 +39,7 @@ typedef struct {
(sizeof (IA32_TSS_DESCRIPTOR) * \
(FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1))
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (FixedPcdGet16 (PcdDebugIoPort) / 8 + 1, 16))
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (MAX (FixedPcdGet16 (PcdUartBase) ,FixedPcdGet16 (PcdDebugIoPort)) / 8 + 1, 16))
#define CPU_TSS_SIZE \
(sizeof (IA32_TASK_STATE_SEGMENT) * \
(FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1) + IO_BIT_MAP_SIZE)

View File

@ -140,6 +140,8 @@ ArchSetupExceptionStack (
UINT8 *StackSwitchExceptions;
UINTN NeedBufferSize;
UINT8 *IOBitMap;
UINT8 *IOBitMapPointer;
UINT8 Offset;
if (BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
@ -241,17 +243,17 @@ ArchSetupExceptionStack (
// and DebugIoPort = 0x402.
//
IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress);
for (Index = 0; Index < IO_BIT_MAP_SIZE; ++Index) {
if ((Index * 8) == FixedPcdGet16 (PcdUartBase)) {
*IOBitMap = 0x84;
} else if ((Index * 8) == (FixedPcdGet16 (PcdDebugIoPort) - 2)) {
*IOBitMap = 0xFB;
} else {
*IOBitMap = 0xFF;
}
SetMem (IOBitMap, IO_BIT_MAP_SIZE, 0xFF);
++IOBitMap;
}
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

View File

@ -38,7 +38,7 @@ typedef struct {
} RESERVED_VECTORS_DATA;
#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (FixedPcdGet16 (PcdDebugIoPort) / 8 + 1, 16))
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (MAX (FixedPcdGet16 (PcdUartBase) ,FixedPcdGet16 (PcdDebugIoPort)) / 8 + 1, 16))
#define CPU_TSS_SIZE (sizeof (IA32_TASK_STATE_SEGMENT) + IO_BIT_MAP_SIZE)
#endif