diff --git a/UEFI_fireworks.dsc b/UEFI_fireworks.dsc index b9a4000..0648eb8 100644 --- a/UEFI_fireworks.dsc +++ b/UEFI_fireworks.dsc @@ -24,12 +24,12 @@ RegisterFilterLib|edk2/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNul StackCheckLib|edk2/MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf IoLib|edk2/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf RngLib|edk2/MdePkg/Library/BaseRngLib/BaseRngLib.inf -SerialPortLib|edk2/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf -TimerLib|edk2/OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf -PciLib|edk2/MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf -HobLib|edk2/MdePkg/Library/DxeHobLib/DxeHobLib.inf -PciCf8Lib|edk2/MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf +SerialPortLib|edk2/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf DebugPrintErrorLevelLib|edk2/MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf +LocalApicLib|edk2/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf +CpuLib|edk2/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf +UefiRuntimeServicesTableLib|edk2/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf +TimerLib|edk2/MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf [Components] src/UEFI_fireworks/UEFI_fireworks.inf diff --git a/build.sh b/build.sh index 188b152..89ec7ae 100755 --- a/build.sh +++ b/build.sh @@ -5,5 +5,6 @@ if [ "$1" == "debug" ]; then else build -a X64 -t GCC5 -p UEFI_fireworks.dsc fi -mkdir -p build +mkdir -p build/EFI/BOOT/ cp edk2/Build/UEFI_fireworks/DEBUG_GCC5/X64/UEFI_fireworks.efi build/ +cp edk2/Build/UEFI_fireworks/DEBUG_GCC5/X64/UEFI_fireworks.efi build/EFI/BOOT/BOOTX64.EFI diff --git a/src/UEFI_fireworks/UEFI_fireworks.inf b/src/UEFI_fireworks/UEFI_fireworks.inf index 0ea9ed2..3169724 100644 --- a/src/UEFI_fireworks/UEFI_fireworks.inf +++ b/src/UEFI_fireworks/UEFI_fireworks.inf @@ -10,6 +10,7 @@ UefiMain.c drawing.c rng.c + time.c [Packages] edk2/MdePkg/MdePkg.dec @@ -28,6 +29,7 @@ TimerLib RngLib SerialPortLib + UefiRuntimeServicesTableLib [Protocols] gEfiRngProtocolGuid diff --git a/src/UEFI_fireworks/UefiMain.c b/src/UEFI_fireworks/UefiMain.c index 959090f..6a0c8a4 100644 --- a/src/UEFI_fireworks/UefiMain.c +++ b/src/UEFI_fireworks/UefiMain.c @@ -4,6 +4,7 @@ #include "global.h" #include "macros.h" #include "rng.h" +#include "time.h" #include "types.h" #include #include @@ -11,9 +12,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -24,9 +25,11 @@ EFI_GRAPHICS_OUTPUT_BLT_PIXEL *framebuffer = NULL; EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, IN EFI_SYSTEM_TABLE *sysTable) { + Print(L"Starting program\n"); gST = sysTable; gBS = sysTable->BootServices; gImageHandle = imgHandle; + gRT = sysTable->RuntimeServices; // UEFI apps automatically exit after 5 minutes. Stop that here gBS->SetWatchdogTimer(0, 0, 0, NULL); @@ -40,6 +43,11 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&GraphicsOutput); + if (GraphicsOutput == NULL) { + Print(L"GraphicsOutput protocol not found!\n"); + return EFI_NOT_FOUND; + } + framebuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)GraphicsOutput->Mode->FrameBufferBase; @@ -58,9 +66,9 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, gBS->SetMem(firework_array, sizeof(firework_array), 0); // make all pointers null - SERIAL_PRINT("DOES it work?"); + SERIAL_PRINT("DOES it work?\n"); Print(L"If you see this message timer does not work\n"); - MicroSecondDelay(1000); + milisleep(100); clear_screen(); while (TRUE) { @@ -86,7 +94,7 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, goto assgned; } // firework will not be created if if all slots are full } - Print(L"NO free slots\n"); + SERIAL_PRINT("NO free slots\n"); } assgned: for (UINT8 i = 0; i < ARRAY_SIZE(firework_array); i++) { @@ -102,7 +110,7 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, } } - MicroSecondDelay(100000); + milisleep(10); } return EFI_SUCCESS; diff --git a/src/UEFI_fireworks/rng.c b/src/UEFI_fireworks/rng.c index c40ec78..aa3764b 100644 --- a/src/UEFI_fireworks/rng.c +++ b/src/UEFI_fireworks/rng.c @@ -2,6 +2,7 @@ #include "Library/UefiBootServicesTableLib.h" #include "Library/UefiLib.h" #include "ProcessorBind.h" +#include "time.h" #include #include #include @@ -63,7 +64,7 @@ void init_rng() { Print(L"Continuing in "); for (UINT8 i = 5; i > 0; i--) { Print(L"\b%d", i); - MicroSecondDelay(1000000); + milisleep(1000); } fill_random_bytes = fill_random_bytes_LFSR; diff --git a/src/UEFI_fireworks/time.c b/src/UEFI_fireworks/time.c new file mode 100644 index 0000000..d64b681 --- /dev/null +++ b/src/UEFI_fireworks/time.c @@ -0,0 +1,24 @@ +#include "Library/UefiLib.h" +#include +EFI_STATUS +milisleep(UINTN Milliseconds) { + EFI_STATUS Status; + EFI_EVENT TimerEvent; + + Status = + gBS->CreateEvent(EVT_TIMER, TPL_APPLICATION, NULL, NULL, &TimerEvent); + + if (EFI_ERROR(Status)) { + return Status; + } + + Status = gBS->SetTimer(TimerEvent, TimerRelative, + EFI_TIMER_PERIOD_MILLISECONDS(Milliseconds)); + + if (!EFI_ERROR(Status)) { + gBS->WaitForEvent(1, &TimerEvent, NULL); + } + + gBS->CloseEvent(TimerEvent); + return Status; +} \ No newline at end of file diff --git a/src/UEFI_fireworks/time.h b/src/UEFI_fireworks/time.h new file mode 100644 index 0000000..ad4f20a --- /dev/null +++ b/src/UEFI_fireworks/time.h @@ -0,0 +1,2 @@ +#pragma once +void milisleep(UINTN Milliseconds); \ No newline at end of file