code style: exclude tabs

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-02-13 21:21:04 +03:00
parent 8d6bc3b17d
commit 7b8e787751

View File

@ -29,9 +29,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#endif #endif
#if PATCH_DEBUG #if PATCH_DEBUG
#define DBG(...) printf(__VA_ARGS__); #define DBG(...) printf(__VA_ARGS__);
#else #else
#define DBG(...) #define DBG(...)
#endif #endif
//// ////
@ -87,28 +87,28 @@ void CorrectMemoryMap(IN UINT32 memMap,
IN UINT32 memDescriptorSize, IN UINT32 memDescriptorSize,
IN OUT UINT32 *memMapSize) IN OUT UINT32 *memMapSize)
{ {
EfiMemoryRange* memDescriptor; EfiMemoryRange* memDescriptor;
UINT64 Bytes; UINT64 Bytes;
UINT32 Index; UINT32 Index;
CHAR16 tmp[80]; CHAR16 tmp[80];
EFI_INPUT_KEY Key; EFI_INPUT_KEY Key;
// UINTN ind; // UINTN ind;
// //
//step 1. Check for last empty descriptors //step 1. Check for last empty descriptors
// //
// PauseForKey(L"Check for last empty descriptors"); // PauseForKey(L"Check for last empty descriptors");
// gST->ConOut->OutputString (gST->ConOut, L"Check for last empty descriptors\n\r"); // gST->ConOut->OutputString (gST->ConOut, L"Check for last empty descriptors\n\r");
// gBS->Stall(2000000); // gBS->Stall(2000000);
memDescriptor = (EfiMemoryRange *)(UINTN)(memMap + *memMapSize - memDescriptorSize); memDescriptor = (EfiMemoryRange *)(UINTN)(memMap + *memMapSize - memDescriptorSize);
while ((memDescriptor->NumberOfPages == 0) || (memDescriptor->NumberOfPages > (1<<25))) while ((memDescriptor->NumberOfPages == 0) || (memDescriptor->NumberOfPages > (1<<25)))
{ {
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor - memDescriptorSize); memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor - memDescriptorSize);
*memMapSize -= memDescriptorSize; *memMapSize -= memDescriptorSize;
} }
// //
//step 2. Add last desc about MEM4GB //step 2. Add last desc about MEM4GB
// //
/* if (gTotalMemory > MEM4GB) { /* if (gTotalMemory > MEM4GB) {
//next descriptor //next descriptor
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize); memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize);
memDescriptor->Type = EfiConventionalMemory; memDescriptor->Type = EfiConventionalMemory;
@ -118,7 +118,7 @@ void CorrectMemoryMap(IN UINT32 memMap,
memDescriptor->Attribute = 0; memDescriptor->Attribute = 0;
*memMapSize += memDescriptorSize; *memMapSize += memDescriptorSize;
} }
*/ */
memDescriptor = (EfiMemoryRange *)(UINTN)memMap; memDescriptor = (EfiMemoryRange *)(UINTN)memMap;
for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) { for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) {
// //
@ -177,17 +177,17 @@ void CorrectMemoryMap(IN UINT32 memMap,
*memMapSize += memDescriptorSize; *memMapSize += memDescriptorSize;
if(MEM_DEB) { if(MEM_DEB) {
gST->ConOut->OutputString (gST->ConOut, L"press any key to dump MemoryMap\r\n"); gST->ConOut->OutputString (gST->ConOut, L"press any key to dump MemoryMap\r\n");
// gBS->Stall(2000000); // gBS->Stall(2000000);
WaitForSingleEvent (gST->ConIn->WaitForKey, 0); WaitForSingleEvent (gST->ConIn->WaitForKey, 0);
gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
// PauseForKey(L"press any key to dump MemoryMap"); // PauseForKey(L"press any key to dump MemoryMap");
memDescriptor = (EfiMemoryRange *)(UINTN)memMap; memDescriptor = (EfiMemoryRange *)(UINTN)memMap;
for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) { for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) {
Bytes = LShiftU64 (memDescriptor->NumberOfPages, 12); Bytes = LShiftU64 (memDescriptor->NumberOfPages, 12);
snwprintf(tmp, 160, "%lX-%lX pages %lX type %lX attr %hhX \r\n\r\t", snwprintf(tmp, 160, "%lX-%lX pages %lX type %lX attr %hhX \r\n\r\t",
memDescriptor->PhysicalStart, memDescriptor->PhysicalStart,
memDescriptor->PhysicalStart + Bytes - 1, memDescriptor->PhysicalStart + Bytes - 1,
@ -198,9 +198,9 @@ void CorrectMemoryMap(IN UINT32 memMap,
gST->ConOut->OutputString (gST->ConOut, tmp); gST->ConOut->OutputString (gST->ConOut, tmp);
// gBS->Stall(2000000); // gBS->Stall(2000000);
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize); memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize);
if (Index % 20 == 19) { if (Index % 20 == 19) {
gST->ConOut->OutputString (gST->ConOut, L"press any key\r\n"); gST->ConOut->OutputString (gST->ConOut, L"press any key\r\n");
WaitForSingleEvent (gST->ConIn->WaitForKey, 0); WaitForSingleEvent (gST->ConIn->WaitForKey, 0);
// gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); // gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
/* if (ReadAllKeyStrokes()) { // remove buffered key strokes /* if (ReadAllKeyStrokes()) { // remove buffered key strokes
@ -212,10 +212,10 @@ void CorrectMemoryMap(IN UINT32 memMap,
ReadAllKeyStrokes(); // empty the buffer to protect the menu ReadAllKeyStrokes(); // empty the buffer to protect the menu
WaitForCR(); WaitForCR();
*/ */
} }
} }
} }
} }
#endif #endif
@ -257,26 +257,26 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
*/ */
gST->ConOut->OutputString (gST->ConOut, L"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); gST->ConOut->OutputString (gST->ConOut, L"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
// //
// Patch kernel and kexts if needed // Patch kernel and kexts if needed
// //
// Jief : OpenCore is doing the kernel patching for all versions. // Jief : OpenCore is doing the kernel patching for all versions.
// LOADER_ENTRY *Entry = ((REFIT_ABSTRACT_MENU_ENTRY*)Context)->getLOADER_ENTRY(); // LOADER_ENTRY *Entry = ((REFIT_ABSTRACT_MENU_ENTRY*)Context)->getLOADER_ENTRY();
// if ( Entry && Entry->OSVersion.startWith("10") ) { // if ( Entry && Entry->OSVersion.startWith("10") ) {
// Entry->KernelAndKextsPatcherStart(); // Entry->KernelAndKextsPatcherStart();
// } // }
#if 0 //it will be as a sample of possible patches in future #if 0 //it will be as a sample of possible patches in future
// gBS->Stall(2000000); // gBS->Stall(2000000);
//PauseForKey(L"press any key to MemoryFix"); //PauseForKey(L"press any key to MemoryFix");
if (gSettings.MemoryFix) { if (gSettings.MemoryFix) {
BootArgs1* bootArgs1v; BootArgs1* bootArgs1v;
BootArgs2* bootArgs2v; BootArgs2* bootArgs2v;
UINT8* ptr=(UINT8*)(UINTN)0x100000; UINT8* ptr=(UINT8*)(UINTN)0x100000;
// DTEntry efiPlatform; // DTEntry efiPlatform;
// CHAR8* dtreeRoot; // CHAR8* dtreeRoot;
UINTN archMode = sizeof(UINTN) * 8; UINTN archMode = sizeof(UINTN) * 8;
UINTN Version = 0; UINTN Version = 0;
while(true) while(true)
{ {
@ -318,7 +318,7 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
// DBG("bootArgs not found!\n"); // DBG("bootArgs not found!\n");
gST->ConOut->OutputString (gST->ConOut, L"bootArgs not found!"); gST->ConOut->OutputString (gST->ConOut, L"bootArgs not found!");
gBS->Stall(5000000); gBS->Stall(5000000);
// return; // return;
break; break;
} }
} }
@ -334,12 +334,12 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
&bootArgs1v->MemoryMapSize); &bootArgs1v->MemoryMapSize);
// bootArgs1v->efiSystemTable = (UINT32)(UINTN)gST; // bootArgs1v->efiSystemTable = (UINT32)(UINTN)gST;
} }
} }
#endif #endif
if (gSettings.Devices.USB.USBFixOwnership) { if (gSettings.Devices.USB.USBFixOwnership) {
FixOwnership(); FixOwnership();
} }
} }
void void
@ -381,44 +381,44 @@ OnSimpleFileSystem (
IN void *Context IN void *Context
) )
{ {
EFI_TPL OldTpl; EFI_TPL OldTpl;
OldTpl = gBS->RaiseTPL (TPL_NOTIFY); OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
gEvent = 1; gEvent = 1;
// ReinitRefitLib(); // ReinitRefitLib();
//ScanVolumes(); //ScanVolumes();
//enter GUI //enter GUI
// DrawMenuText(L"OnSimpleFileSystem", 0, 0, UGAHeight-40, 1); // DrawMenuText(L"OnSimpleFileSystem", 0, 0, UGAHeight-40, 1);
// MsgLog("OnSimpleFileSystem occured\n"); // MsgLog("OnSimpleFileSystem occured\n");
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
} }
EFI_STATUS EFI_STATUS
GuiEventsInitialize () GuiEventsInitialize ()
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_EVENT Event; EFI_EVENT Event;
void* RegSimpleFileSystem = NULL; void* RegSimpleFileSystem = NULL;
gEvent = 0; gEvent = 0;
Status = gBS->CreateEvent ( Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL, EVT_NOTIFY_SIGNAL,
TPL_NOTIFY, TPL_NOTIFY,
OnSimpleFileSystem, OnSimpleFileSystem,
NULL, NULL,
&Event); &Event);
if(!EFI_ERROR(Status)) if(!EFI_ERROR(Status))
{ {
Status = gBS->RegisterProtocolNotify ( Status = gBS->RegisterProtocolNotify (
&gEfiSimpleFileSystemProtocolGuid, &gEfiSimpleFileSystemProtocolGuid,
Event, Event,
&RegSimpleFileSystem); &RegSimpleFileSystem);
} }
return Status; return Status;
} }
//EFI_STATUS //EFI_STATUS
@ -517,141 +517,141 @@ WaitFor2EventWithTsc (
EFI_STATUS EFI_STATUS
EventsInitialize (IN LOADER_ENTRY *Entry) EventsInitialize (IN LOADER_ENTRY *Entry)
{ {
EFI_STATUS Status; EFI_STATUS Status;
void* Registration = NULL; void* Registration = NULL;
//
// Register the event to reclaim variable for OS usage.
//
//EfiCreateEventReadyToBoot(&OnReadyToBootEvent);
/* EfiCreateEventReadyToBootEx (
TPL_NOTIFY,
OnReadyToBoot,
NULL,
&OnReadyToBootEvent
); */
//
// Register notify for exit boot services
//
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_CALLBACK,
OnExitBootServices,
Entry,
&ExitBootServiceEvent);
if(!EFI_ERROR(Status)) //
{ // Register the event to reclaim variable for OS usage.
/*Status = */gBS->RegisterProtocolNotify ( //
//EfiCreateEventReadyToBoot(&OnReadyToBootEvent);
/* EfiCreateEventReadyToBootEx (
TPL_NOTIFY,
OnReadyToBoot,
NULL,
&OnReadyToBootEvent
); */
//
// Register notify for exit boot services
//
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_CALLBACK,
OnExitBootServices,
Entry,
&ExitBootServiceEvent);
if(!EFI_ERROR(Status))
{
/*Status = */gBS->RegisterProtocolNotify (
&gEfiStatusCodeRuntimeProtocolGuid, &gEfiStatusCodeRuntimeProtocolGuid,
ExitBootServiceEvent, ExitBootServiceEvent,
&Registration); &Registration);
} }
// //
// Register the event to convert the pointer for runtime. // Register the event to convert the pointer for runtime.
// //
/* /*
gBS->CreateEventEx ( gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL, EVT_NOTIFY_SIGNAL,
TPL_NOTIFY, TPL_NOTIFY,
VirtualAddressChangeEvent, VirtualAddressChangeEvent,
NULL, NULL,
&gEfiEventVirtualAddressChangeGuid, &gEfiEventVirtualAddressChangeGuid,
&mVirtualAddressChangeEvent &mVirtualAddressChangeEvent
); );
*/ */
// and what if EFI_ERROR? // and what if EFI_ERROR?
return Status; return Status;
} }
EFI_STATUS EjectVolume(IN REFIT_VOLUME *Volume) EFI_STATUS EjectVolume(IN REFIT_VOLUME *Volume)
{ {
EFI_SCSI_IO_PROTOCOL *ScsiIo = NULL; EFI_SCSI_IO_PROTOCOL *ScsiIo = NULL;
EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
// UINT64 Lun = 0; // UINT64 Lun = 0;
// UINT8 *Target; // UINT8 *Target;
// UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; // UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
EFI_STATUS Status; // = EFI_UNSUPPORTED; EFI_STATUS Status; // = EFI_UNSUPPORTED;
UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX]; UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
USB_MASS_DEVICE *UsbMass = NULL; USB_MASS_DEVICE *UsbMass = NULL;
EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL; EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL;
EFI_BLOCK_IO_MEDIA *Media; EFI_BLOCK_IO_MEDIA *Media;
UINT32 Timeout; UINT32 Timeout;
UINT32 CmdResult; UINT32 CmdResult;
// //
// Initialize SCSI REQUEST_PACKET and 6-byte Cdb // Initialize SCSI REQUEST_PACKET and 6-byte Cdb
// //
ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX); ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiScsiIoProtocolGuid, (void **) &ScsiIo); Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiScsiIoProtocolGuid, (void **) &ScsiIo);
if (ScsiIo) { if (ScsiIo) {
// Target = &TargetArray[0]; // Target = &TargetArray[0];
// ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); // ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
// Cdb[1] = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
// Cdb[1] |= 0x01;
Cdb[1] = 0x01;
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC;
CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);
CommandPacket.Cdb = Cdb;
CommandPacket.CdbLength = (UINT8) sizeof (Cdb);
Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
} else { Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiBlockIoProtocolGuid, (void **) &BlkIo); // Cdb[1] = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
if (BlkIo) { // Cdb[1] |= 0x01;
UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlkIo); Cdb[1] = 0x01;
if (!UsbMass) { Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC;
MsgLog("no UsbMass\n"); CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);
Status = EFI_NOT_FOUND; CommandPacket.Cdb = Cdb;
goto ON_EXIT; CommandPacket.CdbLength = (UINT8) sizeof (Cdb);
}
Media = &UsbMass->BlockIoMedia; Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
if (!Media) { } else {
MsgLog("no BlockIoMedia\n"); Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiBlockIoProtocolGuid, (void **) &BlkIo);
Status = EFI_NO_MEDIA; if (BlkIo) {
goto ON_EXIT; UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlkIo);
} if (!UsbMass) {
MsgLog("no UsbMass\n");
// Status = EFI_NOT_FOUND;
// If it is a removable media, such as CD-Rom or Usb-Floppy,
// need to detect the media before each read/write. While some of
// Usb-Flash is marked as removable media.
//
//TODO - DetectMedia will appear automatically. Do nothing?
if (!Media->RemovableMedia) {
//Status = UsbBootDetectMedia (UsbMass);
// if (EFI_ERROR(Status)) {
Status = EFI_UNSUPPORTED;
goto ON_EXIT; goto ON_EXIT;
// } }
} Media = &UsbMass->BlockIoMedia;
if (!Media) {
if (!(Media->MediaPresent)) { MsgLog("no BlockIoMedia\n");
Status = EFI_NO_MEDIA; Status = EFI_NO_MEDIA;
goto ON_EXIT; goto ON_EXIT;
} }
//TODO - remember previous state
/* if (MediaId != Media->MediaId) { //
// If it is a removable media, such as CD-Rom or Usb-Floppy,
// need to detect the media before each read/write. While some of
// Usb-Flash is marked as removable media.
//
//TODO - DetectMedia will appear automatically. Do nothing?
if (!Media->RemovableMedia) {
//Status = UsbBootDetectMedia (UsbMass);
// if (EFI_ERROR(Status)) {
Status = EFI_UNSUPPORTED;
goto ON_EXIT;
// }
}
if (!(Media->MediaPresent)) {
Status = EFI_NO_MEDIA;
goto ON_EXIT;
}
//TODO - remember previous state
/* if (MediaId != Media->MediaId) {
Status = EFI_MEDIA_CHANGED; Status = EFI_MEDIA_CHANGED;
goto ON_EXIT; goto ON_EXIT;
}*/ }*/
Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT; Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT;
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT; Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
// Cdb[1] = (UINT8) (USB_BOOT_LUN(UsbMass->Lun) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK); // Cdb[1] = (UINT8) (USB_BOOT_LUN(UsbMass->Lun) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
// Cdb[1] |= 0x01; // Cdb[1] |= 0x01;
Cdb[1] = 0x01; Cdb[1] = 0x01;
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC; //eject command. Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC; //eject command.
// Status = EFI_UNSUPPORTED; // Status = EFI_UNSUPPORTED;
Status = UsbMass->Transport->ExecCommand ( Status = UsbMass->Transport->ExecCommand (
UsbMass->Context, UsbMass->Context,
&Cdb, &Cdb,
sizeof(Cdb), sizeof(Cdb),
@ -662,10 +662,10 @@ EFI_STATUS EjectVolume(IN REFIT_VOLUME *Volume)
&CmdResult &CmdResult
); );
//ON_EXIT: //ON_EXIT:
// gBS->RestoreTPL (OldTpl); // gBS->RestoreTPL (OldTpl);
} }
} }
ON_EXIT: ON_EXIT:
return Status; return Status;
} }