mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-12-26 16:47:40 +01:00
946a6428b5
Refactor ACPI_NAME_LIST as XString8Array. Create ACPI_RENAME_DEVICE and ACPI_NAME to replace ACPI_NAME_LIST. Change RAM_SLOT_INFO and MEM_STRUCTURE into class. Improve XObjArray::RemoveWithoutFreeingAtIndex. Create XStringArray::ExtractFromPos. Move CheckFatalError and CheckError to BasicIO.
144 lines
3.2 KiB
C++
144 lines
3.2 KiB
C++
/*
|
|
* BasicIO.cpp
|
|
*
|
|
* Created on: 28 Mar 2020
|
|
*
|
|
*/
|
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
|
#include <Efi.h>
|
|
|
|
#include <stdio.h>
|
|
#include "../Platform/BasicIO.h"
|
|
//#include "EfiExternals.h"
|
|
|
|
extern "C" {
|
|
#include "Library/UefiBootServicesTableLib.h"
|
|
}
|
|
|
|
|
|
//
|
|
// Keyboard input
|
|
//
|
|
|
|
BOOLEAN ReadAllKeyStrokes(void)
|
|
{
|
|
BOOLEAN GotKeyStrokes;
|
|
EFI_STATUS Status;
|
|
EFI_INPUT_KEY key;
|
|
|
|
GotKeyStrokes = FALSE;
|
|
for (;;) {
|
|
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
|
|
if (Status == EFI_SUCCESS) {
|
|
GotKeyStrokes = TRUE;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
return GotKeyStrokes;
|
|
}
|
|
|
|
void PauseForKey(CONST CHAR16* msg)
|
|
{
|
|
UINTN index;
|
|
if (msg) {
|
|
printf("\n %ls", msg);
|
|
}
|
|
printf("\n* Hit any key to continue *");
|
|
|
|
if (ReadAllKeyStrokes()) { // remove buffered key strokes
|
|
gBS->Stall(5000000); // 5 seconds delay
|
|
ReadAllKeyStrokes(); // empty the buffer again
|
|
}
|
|
|
|
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
|
|
ReadAllKeyStrokes(); // empty the buffer to protect the menu
|
|
|
|
printf("\n");
|
|
}
|
|
|
|
// Jief, TODO : not sure of the difference between this and PauseForKey. Looks like none. Can it be removed ?
|
|
|
|
void
|
|
WaitForKeyPress(
|
|
CHAR16 *Message
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
UINTN index;
|
|
EFI_INPUT_KEY key;
|
|
|
|
printf("%ls", Message);
|
|
do {
|
|
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
|
|
} while(Status == EFI_SUCCESS);
|
|
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
|
|
do {
|
|
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
|
|
} while(Status == EFI_SUCCESS);
|
|
}
|
|
|
|
//#if REFIT_DEBUG > 0
|
|
//void DebugPause(void)
|
|
//{
|
|
// // show console and wait for key
|
|
// SwitchToText(FALSE);
|
|
// PauseForKey(L"");
|
|
//
|
|
// // reset error flag
|
|
// haveError = FALSE;
|
|
//}
|
|
//#endif
|
|
|
|
void EndlessIdleLoop(void)
|
|
{
|
|
UINTN index;
|
|
|
|
for (;;) {
|
|
ReadAllKeyStrokes();
|
|
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
|
|
}
|
|
}
|
|
|
|
|
|
BOOLEAN CheckFatalError(IN EFI_STATUS Status, IN CONST CHAR16 *where)
|
|
{
|
|
// CHAR16 ErrorName[64];
|
|
|
|
if (!EFI_ERROR(Status))
|
|
return FALSE;
|
|
|
|
MsgLog("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
// StatusToString(ErrorName, Status);
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_RED | EFI_BACKGROUND_BLACK);
|
|
printf("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK);
|
|
haveError = TRUE;
|
|
|
|
//gBS->Exit(ImageHandle, ExitStatus, ExitDataSize, ExitData);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOLEAN CheckError(IN EFI_STATUS Status, IN CONST CHAR16 *where)
|
|
{
|
|
// CHAR16 ErrorName[64];
|
|
|
|
if (!EFI_ERROR(Status))
|
|
return FALSE;
|
|
|
|
MsgLog("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
// StatusToString(ErrorName, Status);
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_RED | EFI_BACKGROUND_BLACK);
|
|
printf("Error: %s %ls\n", efiStrError(Status), where);
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK);
|
|
haveError = TRUE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|