Skip to content

zenyyxz/Kernel-from-scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

64-bit Bare-Metal UEFI Hello World

This is a minimal, from-scratch 64-bit UEFI application (our "kernel") that prints "Hello World" directly using UEFI services, without external libraries like gnu-efi.

How it works

  1. uefi.h: Defines the absolutely essential data types (EFI_SYSTEM_TABLE, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL, etc.) required by the UEFI specification.
  2. main.c: The entry point efi_main. It uses the SystemTable passed by the firmware to write strings directly to the screen via ConOut->OutputString.
  3. Makefile: Uses clang and lld-link to build a PE32+ .efi executable (the format required by UEFI firmware).

Booting from a USB Drive

We have compiled the kernel and placed it at EFI/BOOT/BOOTX64.EFI. This is the default fallback boot path on 64-bit UEFI systems.

To create the bootable USB drive (on Linux):

  1. Insert your USB drive (e.g., /dev/sdX).
  2. Format the drive with a FAT32 filesystem. You can use tools like GParted or mkfs.fat -F 32 /dev/sdX1.
  3. Mount the USB drive.
  4. Copy the entire EFI directory generated here to the root of the USB drive. The structure should look exactly like this:
    [USB Root]
    └── EFI
        └── BOOT
            └── BOOTX64.EFI
    
  5. Unmount the drive, plug it into your modern PC, enter the BIOS/UEFI boot menu, and select the USB drive!

Testing in QEMU (if installed)

If you have QEMU and OVMF (UEFI firmware for QEMU) installed, you can test it virtually:

qemu-system-x86_64 -bios /usr/share/OVMF/OVMF_CODE.fd -drive file=fat:rw:.,format=raw

About

64-bit Bare-Metal UEFI Hello World Kernel From Scratch

Topics

Resources

License

Stars

Watchers

Forks

Contributors