From 06fd67c1d2104cbe09cc9811cd5d160e808f7698 Mon Sep 17 00:00:00 2001 From: pyao12 Date: Sat, 9 May 2026 20:07:36 +0800 Subject: [PATCH] Hello UEFI! --- .gitignore | 3 +++ Makefile | 18 ++++++++++++++++++ boot.c | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 boot.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5620f0e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +vdir/ +.vscode/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b9113ba --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +MINGW_GCC = x86_64-w64-mingw32-gcc +QEMU = qemu-system-x86_64 +MINGW_GCC_FLAGS = -Wall -Wextra -e efi_main -nostdinc -nostdlib -fno-builtin -Wl,--subsystem,10 + +all: + mkdir -p build + x86_64-w64-mingw32-gcc $(MINGW_GCC_FLAGS) -o build/BOOTX64.EFI boot.c + +vdir: all + mkdir -p vdir + mkdir -p vdir/EFI/BOOT + cp build/BOOTX64.EFI vdir/EFI/BOOT + +run: vdir + $(QEMU) -bios /usr/share/ovmf/OVMF.fd -net none -drive file=fat:rw:vdir,index=0,format=vvfat -serial stdio + +clean: + rm -rf build vdir \ No newline at end of file diff --git a/boot.c b/boot.c new file mode 100644 index 0000000..3b253fb --- /dev/null +++ b/boot.c @@ -0,0 +1,22 @@ +#define ull unsigned long long + +struct EFI_SYSTEM_TABLE { + char _buf[60]; + struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL { + ull _buf; + ull (*OutputString)( + struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, + unsigned short *String); + ull _buf2[4]; + ull (*ClearScreen)( + struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This); + } *ConOut; +}; + +void efi_main(void *ImageHandle __attribute__ ((unused)), struct EFI_SYSTEM_TABLE *SystemTable) +{ + SystemTable->ConOut->ClearScreen(SystemTable->ConOut); + SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello UEFI!\n"); + while (1); +} +