diff --git a/Makefile b/Makefile index dd6072d..4a18cd9 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,27 @@ -NASM = nasm -NASMFLAGS = -f win64 -STANDALONE_FLAGS = -Dfill_sector +ASM = nasm +ASMFLAGS = -f win64 LINKER = clang LLD-FLAGS = --target=x86_64-unknown-windows -nostdlib -Wl,-entry:_start -Wl,-subsystem:efi_application -fuse-ld=lld -SRC_DIR = . +SRC_DIR = src +OBJ_DIR = obj +EFI_DIR = efi +INC_DIR = inc + SRC = $(wildcard $(SRC_DIR)/*.asm) -OBJ_DIR = . -OBJ = $(SRC:.asm=.obj) +OBJ = $(SRC:$(SRC_DIR)/%.asm=$(OBJ_DIR)/%.obj) -EFI = uefi.efi -BIOS = bios.bin +EFI = $(EFI_DIR)/uefi.efi +BIOS = $(wildcard $(INC_DIR)/*.bios) BOOT_DRIVE = uefi.img -.PHONY: clean qemu all standalone vhd +.PHONY: clean qemu all img all: $(OBJ) $(LINKER) $(LLD-FLAGS) -o $(EFI) $< - -standalone: NASMFLAGS += $(STANDALONE_FLAGS) -standalone: $(OBJ) + make img clean: rm -f $(OBJ) $(BOOT_DRIVE) $(EFI) @@ -30,12 +30,12 @@ qemu: qemu-system-x86_64 -bios $(BIOS) -drive file=$(BOOT_DRIVE),format=raw # needs dosfstools and mtools -vhd: +img: dd if=/dev/zero of=$(BOOT_DRIVE) bs=1M count=1 mkfs.vfat $(BOOT_DRIVE) mmd -i $(BOOT_DRIVE) ::EFI mmd -i $(BOOT_DRIVE) ::EFI/BOOT - mcopy -i $(BOOT_DRIVE) uefi.efi ::EFI/BOOT/BOOTX64.EFI + mcopy -i $(BOOT_DRIVE) $(EFI) ::EFI/BOOT/BOOTX64.EFI -%.obj: %.asm - $(NASM) $(NASMFLAGS) -o $@ $< +$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.asm + $(ASM) $(ASMFLAGS) -o $@ $< diff --git a/README.md b/README.md index 7841089..3164302 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # UEFI-helloworld -A hello world example for UEFI +A hello world example for UEFI written in x86 NASM assembly + +#### How to use: +Running `make` will: + - Assemble the files from `src` into win64 object files, and put them in `obj` + - Link the win64 object files from `obj` into a PE32+ executable, and put it in `efi` + - Create a FAT32 .img file and move the PE32+ executable into that .img file at the location `EFI/BOOT/BOOTX64.EFI` + +You can then run `make qemu` to boot that PE32+ executable with the UEFI provided by the OVMF project that's stored in `inc`. + diff --git a/uefi.efi b/efi/uefi.efi similarity index 96% rename from uefi.efi rename to efi/uefi.efi index 74ba488..fe21664 100644 Binary files a/uefi.efi and b/efi/uefi.efi differ diff --git a/bios.bin b/inc/ovmf-uefi.bios similarity index 100% rename from bios.bin rename to inc/ovmf-uefi.bios diff --git a/uefi.obj b/obj/uefi.obj similarity index 94% rename from uefi.obj rename to obj/uefi.obj index 6e1846f..a7fbb49 100644 Binary files a/uefi.obj and b/obj/uefi.obj differ diff --git a/uefi.asm b/src/uefi.asm similarity index 100% rename from uefi.asm rename to src/uefi.asm diff --git a/uefi.img b/uefi.img index 2ab46de..8976898 100644 Binary files a/uefi.img and b/uefi.img differ