Discussion:
UEFI boot basics
(too old to reply)
Paul Edwards
2023-11-25 21:16:39 UTC
Permalink
Hi James.
I had missed off code which you would need
which I didn't write but which is brought
in by the link step. I'll show the final
executable's full disassembly below.
You don't need this code if you produce
normal Windows PE executables with the
subsystem set to UEFI.

So depending on definitions, it would be
simplified if you used the appropriate tools.

mingw64 has what is required.

As does UCX64.

BFN. Paul.
James Harris
2023-11-27 15:44:27 UTC
Permalink
Post by Paul Edwards
Hi James.
I had missed off code which you would need
which I didn't write but which is brought
in by the link step. I'll show the final
executable's full disassembly below.
Hi Paul,

Any idea why your reply appears as a new thread?
Post by Paul Edwards
You don't need this code if you produce
normal Windows PE executables with the
subsystem set to UEFI.
So depending on definitions, it would be
simplified if you used the appropriate tools.
mingw64 has what is required.
As does UCX64.
Well, my development environment is Unix so I am not sure that either
would fit. More importantly, I think that I can already control what
goes in to the finished executable and have tried stripping out the
library code, it's just that there's an unresolved problem with the UEFI
firmware not liking the result.

Specifically, if I omit the library code then the UEFI firmware won't
run the .efi file. That may be because the file is no longer tagged as
relocatable but I'm not sure.

FWIW my current link step is

ld -o obj/x64cpu/bootx64b.so obj/x64cpu/bootx64b.o -nostdlib
-znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic
-L/usr/lib -l:crt0-efi-x86_64.o -lgnuefi -lefi

and that's converted to PE with

objcopy obj/x64cpu/bootx64b.so --subsystem=10 --target efi-app-x86_64 -j
.text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j
.reloc -j .eh_frame bin/x64cpu/bootx64b.efi

The line to run my UEFI code from a disk image is

qemu-system-x86_64 -bios /usr/share/qemu/OVMF.fd -drive
format=raw,file=/tmp/ehd.img -net none
--
James Harris
Loading...