https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8...
https://sourceforge.net/projects/gnu-efi/
Broadly: EFI is a simple C environment (albeit one based on windows-style PE binaries and not ELF). The firmware will load and run your application binary and jump to its entry point, passing a giant table of API hooks and callbacks for you to use to interact with its services. You then read and assemble your own OS image using these tools and jump into it.
-target x86_64-unknown-windows -ffreestanding -fno-builtin -fshort-wchar -mno-red-zone
And link, again with clang, using these flags: -target x86_64-unknown-windows -nostdlib -Wl,-entry:efi_main -Wl,-subsystem:efi_application -fuse-ld=lld-link
I believe you can do the same with gcc and gold|gnu ld without much more effort. The toolchain doesn't really justify its complexity at all.The headers, on the other hand, are invaluable. I use c-efi[1]'s headers, but would probably use gnu efi another time; c-efi has some bugs and missing structures. Worth noting: despite the name, gnu efi isn't gpl licensed. In fact, I don't think either (c-efi or gnu efi) can really be considered copyrightable; they're essentially direct translations of the spec.
https://www.kernel.org/doc/html/latest/admin-guide/efi-stub....
Seems to be a little bit out of date, though:
> The code that modifies the bzImage header, along with the EFI-specific entry point that the firmware loader jumps to are collectively known as the “EFI boot stub”, and live in arch/x86/boot/header.S and arch/x86/boot/compressed/eboot.c
I found:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux...
But no eboot.c - there's this however:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux...
uefi-examples - tutorials https://github.com/nrdmn/uefi-examples
uefi-paint - UEFI-bootable touch paint app https://github.com/nrdmn/uefi-paint
uefi-freetype - changing the system BIOS to use Comic Sans https://github.com/nrdmn/uefi-freetype https://twitter.com/andy_kelley/status/1176561072398098432
[1]: https://ziglang.org/download/0.5.0/release-notes.html#UEFI-S...