Initial commit, working

This commit is contained in:
2026-02-26 17:37:57 +00:00
commit 8993630081
4 changed files with 425 additions and 0 deletions

93
main.c Normal file
View File

@@ -0,0 +1,93 @@
#include <efi.h>
#include <efilib.h>
EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
EFI_INPUT_KEY Key;
// Initialize the GNU-EFI library
InitializeLib(ImageHandle, SystemTable);
// Clear the screen
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
// Set text color to light green
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut,
EFI_TEXT_ATTR(EFI_LIGHTGREEN, EFI_BLACK));
// Print welcome messages
Print(L"================================================\n\r");
Print(L" Welcome to Simple UEFI Operating System!\n\r");
Print(L"================================================\n\r");
Print(L"\n\r");
Print(L"System Information:\n\r");
Print(L" UEFI Firmware Vendor: %s\n\r", ST->FirmwareVendor);
Print(L" UEFI Firmware Revision: %d.%d\n\r",
ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xFFFF);
Print(L"\n\r");
// Display some runtime services info
Print(L"Available Services:\n\r");
Print(L" - Console Input/Output: Active\n\r");
Print(L" - Runtime Services: Active\n\r");
Print(L" - Boot Services: Active\n\r");
Print(L"\n\r");
// Simple command loop
Print(L"Commands:\n\r");
Print(L" 'h' - Display help\n\r");
Print(L" 'i' - Display system info\n\r");
Print(L" 'c' - Clear screen\n\r");
Print(L" 'q' - Shutdown\n\r");
Print(L"\n\r");
Print(L"Press a key to start...\n\r");
while (TRUE) {
// Wait for key press
Status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2,
ST->ConIn, &Key);
if (EFI_ERROR(Status)) {
continue;
}
// Handle commands
if (Key.UnicodeChar == L'q' || Key.UnicodeChar == L'Q') {
Print(L"\n\rShutting down...\n\r");
// Reset the system
uefi_call_wrapper(RT->ResetSystem, 4, EfiResetShutdown,
EFI_SUCCESS, 0, NULL);
}
else if (Key.UnicodeChar == L'h' || Key.UnicodeChar == L'H') {
Print(L"\n\r=== Help ===\n\r");
Print(L"This is a minimal UEFI operating system.\n\r");
Print(L"It demonstrates basic UEFI functionality.\n\r");
Print(L"\n\r");
}
else if (Key.UnicodeChar == L'i' || Key.UnicodeChar == L'I') {
Print(L"\n\r=== System Info ===\n\r");
Print(L"Firmware Vendor: %s\n\r", ST->FirmwareVendor);
Print(L"Firmware Revision: %d.%d\n\r",
ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xFFFF);
Print(L"UEFI Specification: %d.%d\n\r",
ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xFFFF);
Print(L"\n\r");
}
else if (Key.UnicodeChar == L'c' || Key.UnicodeChar == L'C') {
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
Print(L"Screen cleared. Press 'h' for help.\n\r");
}
else if (Key.UnicodeChar >= 32 && Key.UnicodeChar < 127) {
// Echo printable characters
Print(L"%c", Key.UnicodeChar);
}
else if (Key.UnicodeChar == L'\r') {
Print(L"\n\r> ");
}
}
return EFI_SUCCESS;
}