override CC := x86_64-none-elf-gcc override LD := x86_64-none-elf-ld override OBJCOPY := x86_64-none-elf-objcopy # For GNU-EFI override PREFIX := $(shell dirname $$(dirname $$(which $(CC)))) override INC := $(PREFIX)/include override LIBS := $(PREFIX)/lib override GNUEFICRT0 := $(PREFIX)/lib/crt0-efi-x86_64.o override GNUEFILDS := $(PREFIX)/lib/elf_x86_64_efi.lds # OVMF supplied by OS override OVMF_CODE := /usr/share/OVMF/OVMF_CODE.fd override OVMF_VARS := /usr/share/OVMF/OVMF_VARS.fd ifeq ("$(wildcard $(OVMF_CODE))","") override OVMF_CODE := /usr/share/edk2/x64/OVMF_CODE.fd endif ifeq ("$(wildcard $(OVMF_CODE))","") override OVMF_CODE := $(PREFIX)/share/OVMF/OVMF_CODE_4M.fd endif ifeq ("$(wildcard $(OVMF_VARS))","") override OVMF_VARS := /usr/share/edk2/x64/OVMF_VARS.fd endif ifeq ("$(wildcard $(OVMF_VARS))","") override OVMF_VARS := $(PREFIX)/share/OVMF/OVMF_VARS_4M.fd endif $(info $$OVMF_CODE is [${OVMF_CODE}]) $(info $$OVMF_VARS is [${OVMF_VARS}]) override CFLAGS := \ -mno-red-zone \ -fshort-wchar \ -march=x86-64 \ -mcmodel=large \ -Iarch/x86_64/include \ -D_ARCH_AMD64 override LDFLAGS := \ -m elf_x86_64 \ -T arch/x86_64/linker.ld .PHONY: all all: shinobu asagiri.img .PHONY: run run: shinobu asagiri.img if [ "$$(uname -a | grep -i 'microsoft')" ]; then \ export IMAGE_PATH=$$(wslpath -wa build/asagiri.img); \ export OVMF_CODE=$$(wslpath -wa $(OVMF_CODE)); \ export OVMF_VARS=$$(wslpath -wa $(OVMF_VARS)); \ else \ export IMAGE_PATH=build/asagiri.img; \ export OVMF_CODE=$(OVMF_CODE); \ export OVMF_VARS=$(OVMF_VARS); \ fi; \ qemu-system-x86_64 -cpu qemu64 -net none -monitor stdio -m 4G \ -drive if=pflash,format=raw,unit=0,file=$$OVMF_CODE,readonly=on \ -drive if=pflash,format=raw,unit=1,file=$$OVMF_VARS,readonly=on \ -drive if=ide,format=raw,file=$$IMAGE_PATH ### Bootloader shinobu: build/bin/shinobu override BCFILES := $(shell find -L shinobu/* -type f -name '*.c') override BOBJ := $(addprefix build/shinobu/obj/,$(BCFILES:.c=.c.o)) # Compilation rules for bootloader *.c files. build/shinobu/obj/%.c.o: %.c mkdir -p "$$(dirname $@)" $(CC) $(CFLAGS) \ -I$(INC) \ -Ishinobu/include \ -DEFI_FUNCTION_WRAPPER \ -c $< -o $@ # Linking the bootloader build/bin/shinobu: $(BOBJ) mkdir -p "$$(dirname $@)" $(LD) $(BOBJ) \ $(GNUEFICRT0) \ -T $(GNUEFILDS) \ -L $(LIBS) \ -l:libgnuefi.a \ -l:libefi.a \ -nostdlib \ -znocombreloc \ -shared \ -z noexecstack \ -Bsymbolic \ --no-warn-rwx-segments \ -o $@ $(OBJCOPY) \ -j .text \ -j .sdata \ -j .data \ -j .dynamic \ -j .dynsym \ -j .rel \ -j .rela \ -j .reloc \ --target=efi-app-x86_64 \ $@ $$(dirname $@)/BOOTX64.EFI