01e3 71d061a4c7
Merge bootsect.S and setup.S into header.S (#467)
* Merge bootsect.S and setup.S into header.S

Currently, Memtest86+ provides two (three counting mbr.S) different
headers: bootsect.S and header.S that together with setup.S are used
to build the final binaries:
 - bootsect.S for booting from the legacy BIOS, used in memtest.bin.
 - header.S for booting from the UEFI, used in memtest.efi.

Both support loading by an intermediate bootloader. Also, both are
derived from the Linux kernel, but from a very different chapter in its
evolution. FDD loading was removed a very long time ago, many, many
years before adding PE/COFF headers for UEFI. Also, the PE/COFF headers
are large (even larger for x86-64) and take a lot of very limited space,
leaving almost no headroom for the actual code.

This commit merges bootsect.S and setup.S into header.S adding BIOS
(FDD) loading support, which should eventually enable to maintain a single,
all-in-one binary that can be booted either by an intermediate bootloader
(such as GRUB or LILO), UEFI and BIOS. Easier and less confusing for users,
as I have continued to see cases when people assume memtest.bin is needed
for non-UEFI systems, even if never intended for FDD loading.

To ensure we have enough space for both the boot code (limited to 512B
including Linux boot header and address of the New EXE header) and
UEFI headers, the PE/COFF headers got moved into the ".setup" section
of the code where *currently* we have 1024B total and about 90B free.
Should more space be needed in the future, we can grow that section or
perhaps even better - move PE/COFF into its own section that will not
even need to be loaded.

Overall, the code got copied from bootsect.S and setup.S with very, very
minimal changes, most importantly:

 - Dedicated routine for printing strings (print_string) got added and
   lives in the ".bootsect" section.

 - Print "Loading " message almost immediately after BIOS loads and
   calls code from the .bootsect" section, even before setting up
   the custom FDD parameter table. The sooner the better.

 - Set DX to 0x0000, as the code depends on its value. While the BIOS is
   expected to set DL register to the boot drive number which is 0 for FDD,
   to my knowledge there is no guarantee for DH to have any particular
   value. Also, when executing "MZ" signature as x86 instructions,
   the original value of DX becomes instantly and irrevocably lost. This
   is fine as we only support booting from FDD anyway.

 - Print "Memtest86+" and its version after loading the ".setup" section.
   We can get the string from mt86plus_version (kernel_version), no need
   to duplicate in the boot sector where we are very space limited and as
   a bonus we can provide the version information.

As diffstat shows a lot of code changed and added, it may be easier use
the following commands:
 diff -Nur bootsect.S header.S
 diff -Nur setup.S header.S

While there are several more changes and fixes I would like to make in the
boot code (some of them were already included in the earlier RFC version
[1] before we got UEFI signing support added) for now I tried this to be as
least disruptive as possible and avoid unnecessary code changes to make
the review easier.

[1] https://github.com/memtest86plus/memtest86plus/pull/136

* Bye bye memtest.bin and memtest.efi, long live mt86plus

With the efi binary providing the BIOS floppy loading functionality,
there is no need to support separate memtest.bin file any longer.

Remove memtest.bin from {build32,build64}/Makefile, replace memtest.bin
amd memtest.efi with mt86plus eveywhere to avoid confusion with
other memtests.

Also, unify build32/Makefile and build64/Makefile by removing
unnecessary differences between them, like extra spaces or
different OBJS order.

Finally, update README.md, HOW_TO_DEBUG_WITH_GDB.md and other
places that had a reference to memtest.{bin,efi}. Note that for
debug_memtest.sh, mt86plus.efi is used.
2025-01-27 19:43:24 +01:00
..
2024-08-30 13:38:46 +02:00
2022-02-19 19:44:58 +00:00