================================================================================
ELILONG BOOT PROCESS REFERENCE
================================================================================
Target Platform: x86_64 UEFI (Slackware 15.0 / gnu-efi)
Primary Goal: Support Above 4G Decoding and Secure Boot Bypass
================================================================================

1. UEFI HANDOFF
- Firmware initializes hardware, including modern 64-bit PCIe BARs (Above 4G Decoding).
- BIOS reads the NVRAM BootOrder and locates elilong.efi on the EFI System Partition (ESP).
- If Secure Boot is enabled, the BIOS verifies elilong.efi against the enrolled SHA-256 hash.
- Execution begins at the efi_main() entry point.

2. INITIALIZATION
- InitializeLib: Sets up gnu-efi library hooks and system table pointers.
- Console Discovery: Locates ConIn/ConOut protocols for keyboard input and text display.
- ESP Identification: Uses the LoadedImageProtocol to identify the physical device and partition from which the loader was launched.

3. MEMORY ANALYSIS (Above 4G Detection)
- Call GetMemoryMap(): Pulls the full system memory map from the firmware.
- 64-bit Verification: Scans descriptors for PhysicalStart addresses exceeding 0xFFFFFFFF (4GB).
- Above 4G Support: Notes these high-memory regions to ensure the kernel is not loaded into a conflicting hardware MMIO hole.

4. CONFIGURATION PARSING
- File System Access: Uses SimpleFileSystemProtocol to open the root directory of the ESP.
- Config Search: Looks for elilo.conf or elilong.conf.
- Line Parsing: Reads kernel paths (e.g., /boot/vmlinuz), initrd paths, and the "append=" command-line strings.

5. USER INTERACTION
- Boot Menu: Displays available labels (e.g., "Slackware", "Windows") via the GOP or text console.
- Input Handling: Waits for a numeric selection or a timeout. Allows for manual editing of kernel parameters if the user interrupts the countdown.

6. KERNEL LOADING (Secure Boot Bypass Path)
- Linux Kernel: The vmlinuz file is read into a temporary buffer. elilong manually parses the PE/COFF headers, identifies the Entry Point, and uses AllocatePages(AllocateAnyPages) to map the kernel into a safe 64-bit memory segment.
- Manual Handoff: Sections (.text, .data) are copied to their relative offsets. This bypasses the BIOS's signature check because elilong is performing the "Load" instead of the firmware.
- Windows: Locates \EFI\Microsoft\Boot\bootmgfw.efi. Uses standard UEFI LoadImage/StartImage calls, as Windows is already signed by the Microsoft keys typically present in all BIOSes.

7. THE HANDOFF (ExitBootServices)
- Final Memory Map: Performs a final GetMemoryMap to obtain the current MapKey.
- ExitBootServices: Formally shuts down UEFI boot services. elilong now has exclusive control over the CPU and memory.
- Jumping to Entry: The CPU jumps to the kernel's 64-bit entry point, passing the system table and memory map pointer.

8. KERNEL EXECUTION
- The OS kernel (Linux or Windows) takes over. Using the 64-bit memory map provided by elilong, it correctly initializes high-memory-mapped hardware (like GPUs with Resizable BAR) without crashing.
================================================================================

[Firmware] ──> efi_main() (main.c)
                │
                ├──> get_esp_root() (loader.c)
                │
                ├──> load_config() (loader.c)
                │     └──> FileRead() (loader.c)
                │     └──> parse_config() (config.c)
                │           └──> process_line_content() (config.c)
                │
                ├──> display_message_file() (main.c)
                │
                ├──> display_menu() (main.c)
                │
                └──> manual_pe_load_and_jump() (loader.c)
                      └──> boot_linux() (loader.c)
