This is to fix the below bug:
Bug 211746 - [Hyper-V] UEFI VM can't boot from the iso installation disk
(please see the discussion in the bug for more details).
The loader assumes physical memory in the [2MB, 2MB + EFI_STAGING_SIZE)
is Conventional Memory while it may not, e.g. in the case of Hyper-V
Generation-2 VM running on Windows Server 2012 R2 host, there is a
BootServiceData memory block at the address 47.449MB and the memory
is not writable. Without the patch, the loader will crash in
Note: EFI_STAGING_SIZE is 48MB in 10.3 and 64MB in the HEAD.
The patch verifies the end addr of the staging area, and decreases
its size if necessary. This way, the loader will not try to write into
the BootServiceData memory.
The patch also allocates the staging area in the first 1GB memory.
Thank Marcel Moolenaar for helping me on this bug!
PS, actually, this patch is only a temporary workaround for UEFI VM on Hyper-V (currently FreeBSD 10.3, 11, and the HEAD can't boot as UEFI VM on Windows Server 2012 R2 host due to this bug).
To have a thorough fix, we would need to add the "booting from arbitrary address" capability to the kernel, which would require a lot of in-depth and long term work to modify the kernel and the loader.