Téléverser les fichiers vers "/"

This commit is contained in:
Pierre Guillod 2024-03-29 01:42:02 +01:00
commit 9a313244ff
2 changed files with 145 additions and 0 deletions

28
EfiClock.inf Normal file
View file

@ -0,0 +1,28 @@
[Defines]
INF_VERSION = 1.25
BASE_NAME = EfiClock
FILE_GUID = 8e2228f9-6249-48a0-bfd6-f99479ad8a46 # Get a GUID from guidgen.com
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiEntry
[Sources]
UefiMain.c
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
TimerLib
[Guids]
[Ppis]
[Protocols]
[FeaturePcd]
[Pcd]

117
UefiMain.c Normal file
View file

@ -0,0 +1,117 @@
#include <Uefi.h>
#include <Protocol/GraphicsOutput.h>
#include <Library/UefiLib.h>
#include <Library/TimerLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop = NULL;
UINT64 Gop_FrameBufferBase = 0;
UINT32 Gop_PixelsPerScanLine = 0;
static inline void drawPixel(UINT32 x, UINT32 y, UINT32 pixel)
{
*((UINT32*)(Gop_FrameBufferBase + 4 * Gop_PixelsPerScanLine * y + 4 * x)) = pixel;
}
static inline void drawRectangle(UINT32 x, UINT32 y, UINT32 w, UINT32 h, UINT32 pixel)
{
for(int ix = 0; ix < w; ++ix)
{
for(int iy = 0; iy < w; ++iy)
{
drawPixel(x+ix, y+iy, pixel);
}
}
}
EFI_STATUS EFIAPI UefiEntry(IN EFI_HANDLE imgHandle, IN EFI_SYSTEM_TABLE* sysTable)
{
gST = sysTable;
gBS = sysTable->BootServices;
gImageHandle = imgHandle;
gBS->SetWatchdogTimer(0, 0, 0, NULL);
EFI_STATUS status = 0;
/**
* GOP Setup
*/
status = gBS->LocateProtocol(&gop_guid, NULL, (VOID **)&Gop);
if (EFI_ERROR(status)) {
Print(u"\r\nERROR: %x; Cannot locate GOP protocol. Return.\r\n", status);
return status;
}
Gop_FrameBufferBase = Gop->Mode->FrameBufferBase;
Gop_PixelsPerScanLine = Gop->Mode->Info->PixelsPerScanLine;
UINT32 W = Gop->Mode->Info->HorizontalResolution;
UINT32 H = Gop->Mode->Info->VerticalResolution;
/**
* Fills framebuffer
*/
drawRectangle(0,0,W,H,0x000000);
UINT32 sq_sid = W * 50 / 1000;
UINT32 sq_gap = W * 17 / 1000;
/**
* Computes squares coordinates
*/
UINT32 col0 = W/2 - 7*sq_gap/2 - 4*sq_sid;
UINT32 col1 = W/2 - 5*sq_gap/2 - 3*sq_sid;
UINT32 col2 = W/2 - sq_gap/2 - sq_sid;
UINT32 col3 = W/2 + sq_gap/2 ;
UINT32 col4 = W/2 + 5*sq_gap/2 + 2*sq_sid;
UINT32 col5 = W/2 + 7*sq_gap/2 + 3*sq_sid;
UINT32 row0 = H/2 - 3*sq_sid/2 - sq_gap;
UINT32 row1 = H/2 - sq_sid/2 ;
UINT32 row2 = H/2 + sq_sid/2 + sq_gap;
/**
* Loops drawing the clockface
*/
EFI_TIME Time;
UINT16 second, minute, hour;
const UINT32 accentColor = 0xFFAB3F, idleColor = 0x555555;
while(1)
{
gRT->GetTime(&Time, NULL);
second = Time.Second;
minute = Time.Minute;
hour = Time.Hour;
second & 0b000001 ? drawRectangle(col5,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row2,sq_sid,sq_sid,idleColor);
second & 0b000010 ? drawRectangle(col5,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row1,sq_sid,sq_sid,idleColor);
second & 0b000100 ? drawRectangle(col5,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row0,sq_sid,sq_sid,idleColor);
second & 0b001000 ? drawRectangle(col4,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row2,sq_sid,sq_sid,idleColor);
second & 0b010000 ? drawRectangle(col4,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row1,sq_sid,sq_sid,idleColor);
second & 0b100000 ? drawRectangle(col4,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row0,sq_sid,sq_sid,idleColor);
minute & 0b000001 ? drawRectangle(col3,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row2,sq_sid,sq_sid,idleColor);
minute & 0b000010 ? drawRectangle(col3,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row1,sq_sid,sq_sid,idleColor);
minute & 0b000100 ? drawRectangle(col3,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row0,sq_sid,sq_sid,idleColor);
minute & 0b001000 ? drawRectangle(col2,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row2,sq_sid,sq_sid,idleColor);
minute & 0b010000 ? drawRectangle(col2,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row1,sq_sid,sq_sid,idleColor);
minute & 0b100000 ? drawRectangle(col2,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row0,sq_sid,sq_sid,idleColor);
hour & 0b00001 ? drawRectangle(col1,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row2,sq_sid,sq_sid,idleColor);
hour & 0b00010 ? drawRectangle(col1,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row1,sq_sid,sq_sid,idleColor);
hour & 0b00100 ? drawRectangle(col1,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row0,sq_sid,sq_sid,idleColor);
hour & 0b01000 ? drawRectangle(col0,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col0,row2,sq_sid,sq_sid,idleColor);
hour & 0b10000 ? drawRectangle(col0,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col0,row1,sq_sid,sq_sid,idleColor);
MicroSecondDelay(1e6);
}
return EFI_SUCCESS;
}