workarounds for gcc12 bug

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-11-22 22:13:55 +03:00
parent ee4d7a61b8
commit 0fc7980fa8
11 changed files with 108 additions and 70 deletions

View File

@ -2147,8 +2147,11 @@ BiosKeyboardTimerHandler (
//
// Clear the CTRL and ALT BDA flag
//
KbFlag1 = *((UINT8 *) (UINTN) 0x417); // read the STATUS FLAGS 1
KbFlag2 = *((UINT8 *) (UINTN) 0x418); // read STATUS FLAGS 2
volatile UINT8 * volatile kbf;
kbf = (volatile UINT8 *) (UINTN) 0x417;
KbFlag1 = *kbf; // read the STATUS FLAGS 1
kbf = (volatile UINT8 *) (UINTN) 0x418;
KbFlag2 = *kbf; // read STATUS FLAGS 2
/*
DEBUG_CODE (
{
@ -2217,9 +2220,12 @@ BiosKeyboardTimerHandler (
// Clear left alt and left ctrl BDA flag
//
KbFlag2 &= ~(KB_LEFT_ALT_PRESSED | KB_LEFT_CTRL_PRESSED);
*((UINT8 *) (UINTN) 0x418) = KbFlag2;
kbf = (volatile UINT8 *) (UINTN) 0x418;
*kbf = KbFlag2;
KbFlag1 &= ~0x0C;
*((UINT8 *) (UINTN) 0x417) = KbFlag1;
kbf = (volatile UINT8 *) (UINTN) 0x417;
*kbf = KbFlag1;
//

View File

@ -652,8 +652,9 @@ Return:
// Allocate memory only up to EBDA (EBDA boundry speicifed at EFI_MEMORY_BELOW_1MB_END is not universal!)
// Bottom of EBDA is usually available by examining 0x40E, which should contain EBDA base address >> 4
// If value is not sane, we use default value at EFI_MEMORY_BELOW_1MB_END (0x9F800)
EbdaAddress = LShiftU64((UINT64)(*(UINT16 *)(UINTN)(0x40E)), 4);
volatile UINT16 * volatile ebda;
ebda = (volatile UINT16 *)(UINTN)(0x40E);
EbdaAddress = LShiftU64((UINT64)(*ebda), 4);
if (EbdaAddress < 0x90000 || EbdaAddress > EFI_MEMORY_BELOW_1MB_END) {
EbdaAddress = 0x9A000;
}

View File

@ -47,10 +47,11 @@ FindAcpiRsdPtr (
//
// Search EBDA
//
Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
volatile UINT16 * volatile ebda;
ebda = (volatile UINT16 *)(UINTN)(EBDA_BASE_ADDRESS);
Address = (UINTN)(*ebda) << 4;
for (Index = 0; Index < 0x400 ; Index += 16) {
if (*(UINT64 *)(Address + Index) == EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
if (*(volatile UINT64 *)(Address + Index) == EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
return (VOID *)Address;
}
}
@ -95,10 +96,13 @@ FindMPSPtr (
//
// Search EBDA
//
volatile UINT16 * volatile ebda;
ebda = (volatile UINT16 *)(UINTN)(EBDA_BASE_ADDRESS);
Address = (UINTN)(*ebda) << 4;
Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
// Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
for (Index = 0; Index < 0x400 ; Index += 16) {
if (*(UINT32 *)(Address + Index) == MPS_PTR) {
if (*(volatile UINT32 *)(Address + Index) == MPS_PTR) {
return (VOID *)Address;
}
}

View File

@ -167,8 +167,11 @@ GenMemoryMap (
UINT64 EBDAsize = 2;
// EBDA memory protection
EBDAaddr = LShiftU64((UINT64)(*(UINT16 *)(UINTN)(0x40E)), 4);
volatile UINT16 * volatile ebda;
ebda = (volatile UINT16 *)(UINTN)(0x40E);
EBDAaddr = LShiftU64((UINT64)(*ebda), 4);
// EBDAaddr = LShiftU64((UINT64)(*(volatile UINT16 *)(UINTN)(0x40E)), 4);
//fool proof
if (EBDAaddr < 0x90000 || EBDAaddr > 0x9F800) {
EBDAaddr = 0x9A000;

@ -1 +1 @@
Subproject commit 2a9f1370b811ea9f5b7a1abb1c0c68768eeb52f4
Subproject commit cde12f2c5b0efb2120f191eccaeb413f1465864e

View File

@ -1157,60 +1157,62 @@ InitializeCpu (
)
{
EFI_STATUS Status;
EFI_EVENT IdleLoopEvent;
BOOLEAN Called = FALSE;
if (Called) {
EFI_EVENT IdleLoopEvent;
InitializePageTableLib();
InitializePageTableLib();
InitializeFloatingPointUnits ();
InitializeFloatingPointUnits ();
//
// Make sure interrupts are disabled
//
DisableInterrupts ();
//
// Make sure interrupts are disabled
//
DisableInterrupts ();
//
// Init GDT for DXE
//
InitGlobalDescriptorTable ();
//
// Init GDT for DXE
//
InitGlobalDescriptorTable ();
//
// Setup IDT pointer, IDT and interrupt entry points
//
InitInterruptDescriptorTable ();
//
// Setup IDT pointer, IDT and interrupt entry points
//
InitInterruptDescriptorTable ();
//
// Install CPU Architectural Protocol
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mCpuHandle,
&gEfiCpuArchProtocolGuid, &gCpu,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Install CPU Architectural Protocol
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mCpuHandle,
&gEfiCpuArchProtocolGuid, &gCpu,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Refresh GCD memory space map according to MTRR value.
//
RefreshGcdMemoryAttributes ();
//
// Refresh GCD memory space map according to MTRR value.
//
RefreshGcdMemoryAttributes ();
//
// Add and allocate local APIC memory mapped space
//
AddLocalApicMemorySpace (ImageHandle);
//
// Add and allocate local APIC memory mapped space
//
AddLocalApicMemorySpace (ImageHandle);
//
// Setup a callback for idle events
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
IdleLoopEventCallback,
NULL,
&gIdleLoopEventGuid,
&IdleLoopEvent
);
ASSERT_EFI_ERROR (Status);
//
// Setup a callback for idle events
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
IdleLoopEventCallback,
NULL,
&gIdleLoopEventGuid,
&IdleLoopEvent
);
ASSERT_EFI_ERROR (Status);
}
Status = InitializeMpSupport ();
return Status;

View File

@ -10,7 +10,7 @@
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = CpuDxe
BASE_NAME = CpuMpDxe
MODULE_UNI_FILE = CpuDxe.uni
FILE_GUID = 1A1E4886-9517-440e-9FDE-3BE44CEE2136
MODULE_TYPE = DXE_DRIVER
@ -86,3 +86,8 @@
[UserExtensions.TianoCore."ExtraFiles"]
CpuDxeExtra.uni
[BuildOptions]
# XCODE:*_*_*_CC_FLAGS = -Os
GCC:*_*_*_CC_FLAGS = -fno-lto

View File

@ -6,6 +6,11 @@
**/
/*
* Modified by Slice 2022
* to use this driver after external UEFI made initialization
*/
#include "CpuDxe.h"
#include "CpuMp.h"
@ -816,28 +821,32 @@ InitializeMpSupport (
)
{
EFI_STATUS Status;
BOOLEAN Called = FALSE;
UINTN NumberOfProcessors;
UINTN NumberOfEnabledProcessors;
//
// Wakeup APs to do initialization
//
Status = MpInitLibInitialize ();
return Status;
if (Called) Status = MpInitLibInitialize ();
// return Status;
MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
mNumberOfProcessors = NumberOfProcessors;
if (Called) MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
// mNumberOfProcessors = NumberOfProcessors;
UINT64 msr = AsmReadMsr64 (MSR_CORE_THREAD_COUNT);
mNumberOfProcessors = msr && 0xFF;
DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mNumberOfProcessors));
//
// Initialize special exception handlers for each logic processor.
//
InitializeMpExceptionHandlers ();
if (Called) InitializeMpExceptionHandlers ();
//
// Update CPU healthy information from Guided HOB
//
CollectBistDataFromHob ();
if (Called) CollectBistDataFromHob ();
Status = gBS->InstallMultipleProtocolInterfaces (
&mMpServiceHandle,

View File

@ -9,6 +9,8 @@
#ifndef _CPU_MP_H_
#define _CPU_MP_H_
#define MSR_CORE_THREAD_COUNT 0x35
/**
Initialize Multi-processor support.

View File

@ -125,7 +125,11 @@ void* FindAcpiRsdPtr()
//
// Search EBDA
//
Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
volatile UINT16 * volatile ebda;
ebda = (volatile UINT16 *)(UINTN)(EBDA_BASE_ADDRESS);
Address = LShiftU64((UINT64)(*ebda), 4);
// Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
if ( Address == 0 ) return 0; // Jief : if Address==0, the first access at *(UINT64 *)(Address + Index) is at address 0. It's supposed to crash.
for (Index = 0; Index < 0x400 ; Index += 16) {
if (*(UINT64 *)(Address + Index) == EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {

View File

@ -604,7 +604,7 @@ EFI_STATUS bootPBRtest(REFIT_VOLUME* volume)
EFI_BLOCK_IO* pDisk = volume->BlockIO;
UINT8* pBootSector = (UINT8*)(UINTN)0x7C00;
UINT8* mBootSector;
MBR_PARTITION_INFO* pMBR = (MBR_PARTITION_INFO*)(UINTN)0x7BE;
volatile MBR_PARTITION_INFO* volatile pMBR; // = (MBR_PARTITION_INFO*)(UINTN)0x7BE;
UINT32 LbaOffset = 0;
UINT32 LbaSize = 0;
HARDDRIVE_DEVICE_PATH *HdPath = NULL;
@ -613,11 +613,13 @@ EFI_STATUS bootPBRtest(REFIT_VOLUME* volume)
// UINT16 OldMask;
// UINT16 NewMask;
UINTN i, j; //for debug dump
UINT8 *ptr;
UINT8* ptr;
// UINT32 MBRCRC32;
//UINTN LogSize;
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtPointer = NULL;
EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs = NULL;
pMBR = (volatile MBR_PARTITION_INFO*)(UINTN)0x7BE;
IA32_REGISTER_SET Regs;
SetMem(&Regs, sizeof (Regs), 0);
@ -699,7 +701,7 @@ EFI_STATUS bootPBRtest(REFIT_VOLUME* volume)
ptr = (UINT8*)(UINTN)0x7F00;
CopyMem(ptr, &VideoTest[0], 30);
CopyMem(pMBR, &tMBR, 16);
CopyMem((void*)pMBR, &tMBR, 16);
pMBR->StartLBA = LbaOffset;
pMBR->Size = LbaSize;