Home | History | Annotate | only in /src/sys/arch/i386/stand/lib
History log of /src/sys/arch/i386/stand/lib
RevisionDateAuthorComments
 1.53 01-Jul-2024  rin i386: stand: G/C `I386_INCLUDE_DOS` leftover

Anyway, `I386_INCLUDE_DISK` is enabled for dosboot.
 1.52 29-Jun-2024  rin branches: 1.52.2;
i386: stand: Adjust for DOS-routine migration
 1.51 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.50 29-Jun-2024  rin i386: stand: G/C unused `printmemlist`, NFC
 1.49 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.48 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.47 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.46 18-Aug-2019  manu Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:
boot NAME=root:/netbsd
boot raid0e:/netbsd
 1.45 02-Feb-2018  mrg branches: 1.45.4; 1.45.8;
convert HAVE_GCC handling to modern GCC release numbering:
- HAVE_GCC=5 is now the default (vs. HAVE_GCC=53 we've been using for
GCC 5.4 and GCC 5.5.)
- remove some more GCC 4.8 code. we don't support GCC 4 here.
- adjust set lists to gcc=5 from gcc=53.

add some basic HAVE_GCC=6 handling (totally unused so far.)
 1.44 22-Mar-2016  mrg branches: 1.44.10;
remove a bunch of "@echo done" from the tail of rules. these messages
were vaguely useful back when we didn't run make -j, but now you end
up with a single line "done" every so often, with no idea what it is
for. very few other targets claim they're done so just remove these.
 1.43 07-Sep-2015  uebayasi Order library object build.
 1.42 07-Sep-2015  uebayasi Sprinkle more done messages.
 1.41 16-Apr-2015  mrg remove HAVE_GCC=45 fragment.
 1.40 08-Apr-2014  christos branches: 1.40.4;
make this more attractive (to me).
 1.39 08-Apr-2014  joerg Unbreak clang build by restricting -O0 hack to gcc.
 1.38 07-Apr-2014  christos XXX: gcc-4.8 bug. Passes wrong arguments to biosdisk_read(). Turn optimization
off.
 1.37 14-Feb-2014  joerg branches: 1.37.2;
Only realprot.S still needs to be built with GNU as.
 1.36 10-Aug-2012  joerg branches: 1.36.2; 1.36.4;
Don't depend on HAVE_GCC being always present.
 1.35 22-Jun-2011  mrg branches: 1.35.2;
apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.34 07-Jun-2011  joerg Catch up with addition of putstr32.S.
 1.33 02-Jun-2011  dsl Add C stubs to allow prints early in the boot code.
 1.32 20-May-2011  joerg branches: 1.32.2;
Disable integrated assembler for files that use .code16 or .code32 for
now. Disable Clang completely for bootxx and netboot for now until the
size issue has been sorted out.
 1.31 05-Jan-2011  jakllsch branches: 1.31.2;
Teach BIOS disk driver about GPT partition tables.
Inspired by Mike Volokhov's GPT booting GSoC project.
 1.30 20-Dec-2010  jakllsch MI libsa provides panic() and exit() functions, no need to provide our own.
As MI libsa exit() calls panic() with a "exit" message, don't use it if we
print our own farewell or have already panic()ed.
 1.29 19-Nov-2009  dsl branches: 1.29.4;
Add 32 bit versions of message and dump_eax that write directly to
the serial port. Useful for debugging - especially real_to_prot!
 1.28 30-Mar-2009  tsutsui Remove extra trailing slash in ${S} path.
 1.27 16-Feb-2009  jmcneill Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.26 25-Nov-2008  ad branches: 1.26.4;
Make pxeboot understand boot.cfg.
 1.25 11-Oct-2008  joerg branches: 1.25.2;
Add "multiboot" command to boot multiboot compliant kernels like Xen.
Patch provided by Robert Swindell with fixes for the command line
parsing and addition of passing module options from me. The kernel now
always gets the full string for modules like for the command line,
everything before the first space/tab is the path name of the module.
 1.24 17-Oct-2007  garbled branches: 1.24.16; 1.24.20; 1.24.26;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.23 26-Sep-2007  ad - Make it compile again.
- Don't use (very dodgy) inline assembly.
 1.22 16-Apr-2003  dsl branches: 1.22.18; 1.22.60; 1.22.68; 1.22.78; 1.22.80; 1.22.82;
Add functions needed by new boot code
 1.21 23-Jan-2003  jdolecek add another memory size detection routine, using int15, function 0xc7, which
is supported on later IBM PS/2 models; this is necessary to detect memory
over 64MB
thanks go to Pavel Cahyna for testing on his IBM PS/2 machine with 128MB

bump biosboot version to 2.15
 1.20 12-Dec-2001  tv branches: 1.20.2;
MKfoo=no -> NOfoo
 1.19 14-Nov-2001  tv Work around <bsd.lib.mk> used for kernel libs in other places. Clean up
include paths.
 1.18 19-May-2001  jdolecek branches: 1.18.4;
Add biosmca.S if I386_INCLUDE_PS2 variable is "yes" (default, overridable)
 1.17 24-Sep-2000  jdolecek branches: 1.17.4;
netbsd_opts.c was removed as part of bootverbose/bootquiet changes
Pointed out by Lennart Augustsson in private e-mail.
 1.16 13-May-2000  jdolecek remove now redundant comment regarding IBM_L40 define
 1.15 11-May-2000  jdolecek add commented out CPPFLAGS+= -DIBM_L40 - needed for PS/2 bootblocks
 1.14 23-Apr-2000  tsarna Addredd port-i386/9897, but differently. Since the effect of resetting
the video mode on machines with ancient or no video cards is not clear,
for safety's sake a I created a new biosboot variant, biosboot_resetvideo
that does the call.

Anyway, now I can boot my i-opener without hitting Tab. Thanks Andrew!
 1.13 21-Dec-1999  drochner add a function which prints out the memory descriptors (for debugging)
 1.12 28-Apr-1999  christos branches: 1.12.2; 1.12.8;
use new loadfile
 1.11 08-Mar-1999  drochner branches: 1.11.4;
add a function to pass the "memory map" ie the outcome of INT15/0xe820,
to the kernel
 1.10 13-Feb-1999  lukem convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.
 1.9 30-Jan-1999  christos Remove exec.c from here. I want to make it obvious that it has to be built
with different flags from dosboot and biosboot. Although right now this
does not make a difference because we are building the libraries twice,
it can make a difference when we share the builds.
 1.8 29-Jan-1999  thorpej Um, last rev was kind of backwards... actually build exec.o so that
the boot block links.
 1.7 29-Jan-1999  christos exec.c has all the info now.
 1.6 28-Jan-1999  christos Add loadfile.c (stolen from Jason's alpha/stand/common/loadfile.c)
loadfile.h contains macros that are supposed to be MD, but loadfile.c is now MI.
Fixes:
- a.out support
- pass information values via an array not global variables
- don't assume that you can access memory directly.
- remove MD parts
- remove some printfs.
XXX: loadfile.c needs to be moved somewhere where other ports can use it.
XXX2: read() routines on the i386 don't appear to set errno on failure.
 1.5 17-Sep-1997  drochner add new files
 1.4 14-Aug-1997  drochner Build the new memory detection stuff.
 1.3 13-Apr-1997  perry branches: 1.3.4;
1) Make carriage return start boot immediately.
2) Make "quit" reboot machine. This works by adding a reboot assembler
hook that calls INT 19h
 1.2 14-Mar-1997  thorpej Make this work with obj* dirs.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.4.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.11.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.12.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.17.4.2 08-Jan-2002  nathanw Catch up to -current.
 1.17.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.18.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.20.2.2 12-Dec-2001  tv MKfoo=no -> NOfoo
 1.20.2.1 12-Dec-2001  tv file Makefile was added on branch sommerfeld_i386mp_1 on 2001-12-12 01:49:45 +0000
 1.22.82.1 06-Oct-2007  yamt sync with head.
 1.22.80.1 06-Nov-2007  matt sync with HEAD
 1.22.78.1 02-Oct-2007  joerg Sync with HEAD.
 1.22.68.1 03-Oct-2007  garbled Sync with HEAD
 1.22.60.1 09-Oct-2007  ad Sync with head.
 1.22.18.1 27-Oct-2007  yamt sync with head.
 1.24.26.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.26.1 19-Oct-2008  haad Sync with HEAD.
 1.24.20.2 11-Mar-2010  yamt sync with head
 1.24.20.1 04-May-2009  yamt sync with head.
 1.24.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.25.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.25.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.25.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.26.4.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.26.4.3 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.26.4.2 01-Nov-2009  jym Sync with HEAD.
 1.26.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.29.4.3 12-Jun-2011  rmind sync with head
 1.29.4.2 31-May-2011  rmind sync with head
 1.29.4.1 05-Mar-2011  rmind sync with head
 1.31.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.32.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.35.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.35.2.1 30-Oct-2012  yamt sync with head
 1.36.4.1 18-May-2014  rmind sync with head
 1.36.2.2 03-Dec-2017  jdolecek update from HEAD
 1.36.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37.2.1 10-Aug-2014  tls Rebase.
 1.40.4.3 22-Apr-2016  skrll Sync with HEAD
 1.40.4.2 22-Sep-2015  skrll Sync with HEAD
 1.40.4.1 06-Jun-2015  skrll Sync with HEAD
 1.44.10.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.44.10.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #1373):

sys/arch/i386/stand/boot/boot2.c: revision 1.72 (patch)
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14 (patch)
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.

Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.45.8.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.45.8.1 13-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #200):

sys/arch/i386/stand/boot/boot2.c: revision 1.72
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.
Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.45.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 25-May-2025  rillig i386/stand: build in parallel mode
 1.20 30-Aug-2023  christos branches: 1.20.6;
Explicitly pass COPTS
 1.19 13-Jun-2018  christos revert previous MAKEOBJDIRPREFIX massaging
 1.18 11-Jun-2018  christos switch CFLAGS from using MAKEOBJDIRPREFIX to MAKEOBJDIR. This whole thing
is disgusting, but fixing it properly. requires restructuring
 1.17 27-May-2018  christos - Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
 1.16 22-Mar-2016  mrg branches: 1.16.10; 1.16.16;
remove a bunch of "@echo done" from the tail of rules. these messages
were vaguely useful back when we didn't run make -j, but now you end
up with a single line "done" every so often, with no idea what it is
for. very few other targets claim they're done so just remove these.
 1.15 06-Sep-2015  uebayasi In kernel lib build, print message when things not only start bug also end.
 1.14 26-May-2011  joerg branches: 1.14.32;
Default to -Wno-sign-compare -Wno-pointer-sign for clang.
Push -Wno-array-bounds down to the cases that depend on it.
Selectively disable warnings for 3rd party software or non-trivial
issues to be reviewed later to get clang -Werror to build most of the
tree.
 1.13 11-Dec-2005  christos branches: 1.13.92; 1.13.100; 1.13.106;
merge ktrace-lwp.
 1.12 07-Nov-2003  dsl Make 'dependall' generate the dependencies
 1.11 22-Nov-2001  dillo branches: 1.11.2; 1.11.18;
Repeat James Chacon's fix from sys/lib/lib{kern,sa,z}:

Don't make clean and cleandir depend on the lib subdir.
Just check for it's existance before running the submake.
This makes it possible to run a make build (which runs
cleandir before make obj) in a r/o source tree.
 1.10 18-Aug-2001  enami Fix white space usage.
 1.9 08-Sep-2000  tron branches: 1.9.4; 1.9.6;
Final fix to make this work without object directories again.
 1.8 08-Sep-2000  tron Readd at signs before commands which were removed for debugging.
 1.7 08-Sep-2000  tron Do last change differently: "(unset MAKEOBJDIRPREFIX || true)" is a NOP,
use "MAKEOBJDIRPREFIX= && unset MAKEOBJDIRPREFIX" instead.
 1.6 08-Sep-2000  tron Use "(unset MAKEOBJDIRPREFIX || true)" because unset return an error code
if the variable was not set before.
 1.5 08-Sep-2000  matt deal properly with MAKEOBJDIRPREFIX (which has priority over MAKEOBJDIR so
the MAKEOBJDIR to ${MAKE} has no effect) so we unset MAKEOBJDIRPREFIX before
invoking ${MAKE}
 1.4 01-Feb-2000  tsutsui branches: 1.4.6;
Revert STRIPPROG -> STRIP
 1.3 19-Jan-2000  tsutsui STRIP -> STRIPPROG
 1.2 05-Sep-1998  lukem branches: 1.2.12;
distclean is a synonym for cleandir
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.6.2 11-Sep-2000  tron Pull up from current (approved by thorpej):

Make this work without object directories again.

syssrc/sys/arch/i386/stand/lib/Makefile.inc 1.5 -> 1.9
 1.4.6.1 09-Sep-2000  matt Approved by jhawk
>Make this work with MAKEOBJDIRPREFIX.
 1.9.6.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.9.6.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.9.4.2 08-Jan-2002  nathanw Catch up to -current.
 1.9.4.1 24-Aug-2001  nathanw Catch up with -current.
 1.11.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.11.18.1 03-Aug-2004  skrll Sync with HEAD
 1.11.2.2 22-Nov-2001  dillo Repeat James Chacon's fix from sys/lib/lib{kern,sa,z}:

Don't make clean and cleandir depend on the lib subdir.
Just check for it's existance before running the submake.
This makes it possible to run a make build (which runs
cleandir before make obj) in a r/o source tree.
 1.11.2.1 22-Nov-2001  dillo file Makefile.inc was added on branch sommerfeld_i386mp_1 on 2001-11-22 00:04:56 +0000
 1.13.106.1 06-Jun-2011  jruoho Sync with HEAD.
 1.13.100.1 31-May-2011  rmind sync with head
 1.13.92.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.14.32.2 22-Apr-2016  skrll Sync with HEAD
 1.14.32.1 22-Sep-2015  skrll Sync with HEAD
 1.16.16.1 25-Jun-2018  pgoyette Sync with HEAD
 1.16.10.1 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.20.6.1 02-Aug-2025  perseant Sync with HEAD
 1.23 10-Sep-2022  rillig fix misspellings of 'available' and nearby typos
 1.22 19-Jul-2014  erh Fix bootxx_* and boot on machines where the bios sets high bits of %eax on success.
 1.21 16-Jun-2011  joerg branches: 1.21.12; 1.21.26;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.20 29-Dec-2010  jakllsch branches: 1.20.6;
Utilize movz[bw]l to save a few instrutions and bytes of .text.
 1.19 21-Nov-2009  dsl branches: 1.19.4;
Preserve %ds over bios calls.
Not strickly necessary because real_to_prot doesn't normally rely on in.
However it caused much confusion while debugging, and does no harm.
 1.18 11-Dec-2005  christos branches: 1.18.78; 1.18.92;
merge ktrace-lwp.
 1.17 29-Jun-2005  junyoung Massive renames for consistency:
biosdiskreset -> biosdisk_reset
biosread -> biosdisk_read
get_diskinfo -> biosdisk_getinfo
int13_extension -> biosdisk_int13ext
biosextread -> biosdisk_extread
int13_getextinfo -> biosdisk_getextinfo
struct biosdisk_ext13info -> biosdisk_extinfo
BIOSDISK_EXT13 -> BIOSDISK_INT13EXT
BIOSDISK_EXT13INFO_V{2,3} -> BIOSDISK_EXTINFO_V{2,3}
EXT13_* -> EXTINFO_*
 1.16 29-Jun-2005  junyoung get_diskinfo():
Return status code in bits [31:24] of %eax. 0 for success, otherwise failure.
 1.15 22-Jun-2005  junyoung Do not mix assembly-style comments and C-style comments.
 1.14 13-Jun-2005  junyoung Remove trailing spaces.
 1.13 16-Apr-2003  dsl branches: 1.13.2;
C code now sets length of disk info structure
 1.12 08-Mar-2003  dsl Don't trust %bp to point to same place in real and protected modes.
prot_to_real preserves %ebp but changes %ss and %sp.
(ok if real %ss is offset n*64k from protected %ss - which it has been)
 1.11 05-Feb-2003  dsl Remove unused defines
 1.10 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.9 10-Oct-2002  dyoung Introduce biosdiskreset(), and call it to reset the disk (with Int
0x13 Function 0) after a read error. This is a requirement mentioned
in most BIOS documentation.

This answers PR 18591.

Incidentally, on the Soekris Engineering net45x1 single-board
computer, this fixes a bug where the bootloader corrupts the kernel
while loading it from certain varieties of CompactFlash card
(especially varieties identified by NetBSD as <TOSHIBA THNCF064MBA>).
 1.8 21-May-2000  perry branches: 1.8.6; 1.8.8;
Actually return the BIOS error code (if any) generated by the reads
 1.7 30-Mar-1999  fvdl branches: 1.7.8;
Shifting ecx without explicit prefix in real mode won't work.
 1.6 30-Mar-1999  drochner fix some disk handling problems introduced in the last commits:
-read retries were botched, use the right sector count
-read-ahead buffer was effectively unused
-concentrate the handling of the weird BIOS geometry report at one place
-fallback for old floppies left cylinder count uninitialized
 1.5 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.4 30-Oct-1998  ws Fix a thinko which still prevented this to run on non-int13-ext machines.
Thanks to entropy@zippy.bernstein.com for pointing this out and testing the fix.
 1.3 27-Oct-1998  ws Fix typo which prevented this from working
on disks without int13-extension support.
 1.2 15-Oct-1998  ws Add int13 extension support
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.7.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.8.1 18-Oct-2002  nathanw Catch up to -current.
 1.8.6.2 21-May-2000  perry Actually return the BIOS error code (if any) generated by the reads
 1.8.6.1 21-May-2000  perry file bios_disk.S was added on branch sommerfeld_i386mp_1 on 2000-05-21 16:59:29 +0000
 1.13.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.92.3 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.18.92.2 10-Jan-2011  jym Sync with HEAD
 1.18.92.1 24-Oct-2010  jym Sync with HEAD
 1.18.78.1 11-Mar-2010  yamt sync with head
 1.19.4.1 05-Mar-2011  rmind sync with head
 1.20.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.21.26.1 10-Aug-2014  tls Rebase.
 1.21.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.4 01-Feb-2003  dsl branches: 1.4.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.3 18-Aug-1997  hannken Change "it's" to "it is" inside assembler comments to
stop "unterminated character constant" messages from `mkdep'.
 1.2 13-Jun-1997  drochner branches: 1.2.4;
Fix operand size confusion in 16-bit code.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 06-Jul-2005  junyoung - Do not mix C-style comments and assembly-style comments.
- Remove unused #define.
 1.2 01-Feb-2003  dsl branches: 1.2.2; 1.2.18;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.18.1 21-Jun-2006  yamt sync with head.
 1.2.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.61 06-Jan-2024  mlelstv In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
hard drives (with geom) and CD-ROM (without).
 1.60 02-Oct-2023  manu Fix build with -DNO_GPT
 1.59 28-Sep-2023  manu Align the behavior of different boot methods in RAIDframe

We enforce the documented and paritally implemented behavior when
looking for the kernel in RAID 1 sets without a partition name given.
We search for:
- A GPT partition with bootme attribute set
- A FFS or LFS patititon
- The first partition
 1.58 03-May-2022  jmcneill branches: 1.58.4;
Trailing whitespace
 1.57 28-Dec-2021  simonb In biosdisk_findpartition() check if part_name isn't NULL before
assigning *part_name.

Thanks to manu@ for the pointer.
 1.56 28-Dec-2021  simonb Fix a tyop.
 1.55 30-May-2021  mlelstv Add "root" command to provide a BTINFO_ROOTDEVICE parameter.
 1.54 17-Dec-2019  manu branches: 1.54.12; 1.54.14;
Do not use NAME=label syntax when label are empty

When booting sysinst from UEFI, it defaults to a GPT installation
where partition have no labels. Bootstrap used the NAME=label partition
anyway, with the result that both EFI and FFS root partition had
the same name "NAME=" and could not be distinguished. The first matching
partition for the name was used, and bootstrap looked for the kernel
in the EFI partition.

We fix that by not using NAME=label names for partition when label
is empty. In that case we revert to old syntax such as hd0b
 1.53 10-Dec-2019  manu In-RAID partitions with no name can be candidate for booting

The code to select boot partition in RAID assumed thet had a name,
which is true when there is a GPT inside the RAID, but not when there
is a disklabel inside the RAID. This caused a regression from behavior
of NetBSD 8.1.

We fix this by allowing nameless partition to be boot candidates.
This fixes misc/54748

While there, let raid device be used in the boot specification, like
raid0a:/netbsd.
 1.52 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.51 18-Aug-2019  kamil Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.
 1.50 18-Aug-2019  manu Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:
boot NAME=root:/netbsd
boot raid0e:/netbsd
 1.49 02-Apr-2018  nonaka branches: 1.49.2; 1.49.6;
efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.48 20-Mar-2018  nonaka efiboot: fix to find boot partition process.

NetBSD related partitions with no bootme flag set are also candidates
for boot partition.
 1.47 08-Mar-2018  nonaka efiboot: system can boot from CD/DVD-ROM media.
 1.46 24-Jan-2017  nonaka branches: 1.46.6; 1.46.12;
Initial commit of native amd64 EFI boot loader.
 1.45 05-Jun-2016  maxv branches: 1.45.2; 1.45.4;
The bootinfo is refreshed each time the bootloader tries to execute a
kernel, so there's no point in using this global variable. Because of
this variable, only one "boot" command can be issued in the prompt, and
you have to reboot the machine if you mistyped the kernel name.
 1.44 18-Jan-2015  jakllsch While the old gpt.S mbr code looks at both primary and alternate GPT
partition tables, mbrgpt.S and DKWEDGE_METHOD_GPT only look in the
primary. Align the bootxx/boot2 biosdisk code with this so as to avoid
situations where the disk becomes unbootable when it has an undestroyed
secondary GPT.
 1.43 31-Oct-2013  christos branches: 1.43.4; 1.43.6;
avoid pointer aliasing problems.
 1.42 03-Jul-2012  tsutsui branches: 1.42.2; 1.42.4;
Apply patch:
PR/46583: BIOS bootloader problems with partitions that start above 1TB

Should be pulled up to netbsd-6.
 1.41 13-Jun-2012  perseant Sanity check the values coming back from the int13 extensions of the bios,
so we can catch impossible return values. Allows the bootloader to work
again on the Soekris net4501.

Fixes PR kern/46027.
 1.40 16-Jan-2012  christos branches: 1.40.2;
PR/45796: Evgeniy Ivanov minixfs3 support.
 1.39 21-Sep-2011  gsutre branches: 1.39.2; 1.39.6;
Fix btinfo_bootdisk's labelsector and btinfo_bootwedge's startblk for
the non-GPT case.

ok jakllsch@
 1.38 17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.37 26-Jan-2011  jakllsch Attempt to correct two regressions.
- avoid Virtualbox's BIOS panicing on 64-bit LBAs
- MBR-without-disklabel was ignored
 1.36 05-Jan-2011  jakllsch branches: 1.36.2; 1.36.4;
Teach BIOS disk driver about GPT partition tables.
Inspired by Mike Volokhov's GPT booting GSoC project.
 1.35 05-Jan-2011  jakllsch Let the compiler determine the correct type for sizeof().
From Mike Volokhov's GPT booting GSoC.
 1.34 30-Dec-2010  jakllsch Fix DISK_DEBUG build.
 1.33 25-Dec-2010  jakllsch Use printf format macros for long longs.
 1.32 24-Dec-2010  jakllsch Sprinkle daddr_t.
Adjust DISK_DEBUG printf formats to match.
 1.31 25-Jun-2010  tsutsui Add wait_sec() which uses BIOS function call INT 1Ah/AH=00h (GET SYSTEMTIME)
and use it for large delays (in seconds) instead of delay() that uses
INT 15h/AH=86h (WAIT) in microsecond because the latter one can't provide
precise delays on emulators.
Fixes PR port-i386/43156 (NetBSD bootloader countdown runs at 1/20 speed
in qemu 0.12).

No particular comments on the PR and port-i386@.
 1.30 20-Oct-2009  jmcneill branches: 1.30.2; 1.30.4;
trim some fat, don't scan disklabels on non-HD disks
 1.29 13-Sep-2009  jmcneill Make the 'dev' command print out a list of known boot devices based on
information from the BIOS in addition to the currently selected default
partition. Handy when you don't know where to boot from. Here's a demo:

type "?" or "help" for help.
> dev
disk hd0 size 3815 MB
hd0a(4.2BSD) hd0b(swap)
disk cd0
cd0a(unknown)
default hd0a
>
 1.28 05-Jan-2008  dsl branches: 1.28.10; 1.28.24;
Remove #define DISK_DEBUG left in by mistake
 1.27 04-Jan-2008  dsl Allow the boot code to use the disklabel 'faked up' from the mbr.
Should allow bootxx_fat16 (and bootxx_msdos etc) to boot from drives that
don't contain a netbsd disklabel.
 1.26 25-Jan-2006  christos branches: 1.26.48; 1.26.54; 1.26.62;
free -> dealloc
unsigned -> size_t for alloc/dealloc
 1.25 11-Dec-2005  christos branches: 1.25.2;
merge ktrace-lwp.
 1.24 22-Jun-2005  junyoung branches: 1.24.2;
Add support for cd9660 file system to the i386 BIOS bootloader.
 1.23 22-Jun-2005  junyoung Cosmetic changes.
 1.22 13-Jun-2005  junyoung ANSI, KNF, remove trailing spaces, and some other non-functional changes
 1.21 23-Oct-2004  thorpej Add support for passing booted wedge information to the kernel.
 1.20 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.19 31-Oct-2003  hannken Remove memset prototype. Already present in sys/lib/libsa/stand.h.
 1.18 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.17 07-Jul-2003  dsl Support booting from a netbsd partition in the MBR extended partition.
 1.16 01-Feb-2003  dsl branches: 1.16.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.15 07-Jul-2001  perry branches: 1.15.4;
b*()->mem*()
 1.14 01-Jun-2001  jdolecek g/c COMPAT_OLDBOOT from bootblocks, sprinkle some const
bump bootblock version to 2.10
 1.13 30-Oct-2000  lukem branches: 1.13.4;
Add support for booting off RAIDframe RAID1 mirrors. Check the first partition
type in biosdiskopen(), and if it is of type FS_RAID, add 64 to d->b_off.

NOTE: installboot(8) still needs some hacking to DTRT, but at least this way
if you can load "/boot" off another partition (e.g, wd0h), then wd0a can be
of type `RAID' with a raidframe mirror at the start and the kernel
will load OK of wd0a, and with raidctl -A root partitions, it will change
root as well.
 1.12 03-Aug-1999  drochner branches: 1.12.2; 1.12.14;
put biosdiskclose() inside LIBSA_NO_FS_CLOSE
 1.11 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.10 27-Jan-1999  thorpej Use the MI <sys/disklabel_mbr.h>, not our own machine-dependent
definitions.
 1.9 15-May-1998  drochner Allow to use the code in user land test programs.
 1.8 19-Feb-1998  drochner Add compatibility code (#ifdef COMPAT_386BSD_MBRPART): look for 386BSD
partition ID if the NetBSD ID was not found.
 1.7 13-Oct-1997  drochner branches: 1.7.2;
Ignore BIOS partition table and disklabel for floppys and RAW_PART,
for consistency with the kernel.
 1.6 20-Sep-1997  drochner don't forget to save the partition number for the kernel
 1.5 17-Sep-1997  drochner Do the vararg stuff cleanly.
Collect disk information in a "bootinfo" structure.
 1.4 13-Jun-1997  drochner branches: 1.4.4;
Reformat comments. (messed up by "indent")
 1.3 22-Mar-1997  thorpej Purely cosmetic whitespace/indentation changes (mmm, indent(1))
 1.2 22-Mar-1997  thorpej Don't abort if we don't find an MBR or NetBSD MBR partition; simply assume
that the NetBSD portion of the disk begins at sector 0.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.4.4.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.4.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.2 01-Dec-1998  cgd capitalize the name of the project correctly in the warning message,
and also clean up other caps/spacing in that message. If we're going
to include stuff like punctuation, it really should follow other rules of
English. Not done on trunk because, for whatever reason, the message
is entirely different there!
 1.7.2.1 23-Nov-1998  cgd Add forward-compatibility with new NetBSD MBR partition-id 169 (0xa9).
Warn about old-style 165 partitions with a reference to installboot(8)
for details on when and how to upgrade bootblocks and partition IDs.
Do fresh installs using the new ID. Done via patch because it's a long
list of changes which didn't quite apply cleanly. (jonathan)
 1.12.14.1 03-Feb-2001  he Pull up revision 1.13 (requested by lukem):
Add support for booting off RAIDframe RAID1 mirrors. Done by
checking the first partition type in biosdiskopen(), and if it
is of type FS_RAID, add 64 to d->b_off.

NOTE: installboot(8) still needs some hacking to DTRT, but at
least this way if you can load "/boot" off another partition
(e.g, wd0h), then wd0a can be of type `RAID' with a raidframe
mirror at the start and the kernel will load OK of wd0a, and with
raidctl -A root partitions, it will change root as well.
 1.12.2.1 22-Nov-2000  bouyer Sync with HEAD.
 1.13.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.13.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.4.2 07-Jul-2001  perry b*()->mem*()
 1.15.4.1 07-Jul-2001  perry file biosdisk.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:58 +0000
 1.16.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.16.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.16.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.2.1 03-Aug-2004  skrll Sync with HEAD
 1.24.2.2 21-Jan-2008  yamt sync with head
 1.24.2.1 21-Jun-2006  yamt sync with head.
 1.25.2.1 01-Feb-2006  yamt sync with head.
 1.26.62.1 08-Jan-2008  bouyer Sync with HEAD
 1.26.54.1 18-Feb-2008  mjf Sync with HEAD.
 1.26.48.1 09-Jan-2008  matt sync with HEAD
 1.28.24.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.28.24.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.28.24.2 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.28.24.1 01-Nov-2009  jym Sync with HEAD.
 1.28.10.3 11-Aug-2010  yamt sync with head.
 1.28.10.2 11-Mar-2010  yamt sync with head
 1.28.10.1 16-Sep-2009  yamt sync with head
 1.30.4.2 05-Mar-2011  rmind sync with head
 1.30.4.1 03-Jul-2010  rmind sync with head
 1.30.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.36.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.36.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.39.6.1 18-Feb-2012  mrg merge to -current.
 1.39.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.39.2.2 30-Oct-2012  yamt sync with head
 1.39.2.1 17-Apr-2012  yamt sync with head
 1.40.2.2 21-Jul-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #432):
sys/arch/i386/stand/lib/biosdisk.c: revision 1.42
Apply patch:
PR/46583: BIOS bootloader problems with partitions that start above 1TB
Should be pulled up to netbsd-6.
 1.40.2.1 24-Jun-2012  jdc Pull up revision 1.41 (requested by martin in ticket #349).

Sanity check the values coming back from the int13 extensions of the bios,
so we can catch impossible return values. Allows the bootloader to work
again on the Soekris net4501.

Fixes PR kern/46027.
 1.42.4.1 18-May-2014  rmind sync with head
 1.42.2.2 03-Dec-2017  jdolecek update from HEAD
 1.42.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.6.3 05-Feb-2017  skrll Sync with HEAD
 1.43.6.2 09-Jul-2016  skrll Sync with HEAD
 1.43.6.1 06-Apr-2015  skrll Sync with HEAD
 1.43.4.1 20-Jan-2015  martin Pull up following revision(s) (requested by jakllsch in ticket #436):
sys/arch/i386/stand/lib/biosdisk.c: revision 1.44
While the old gpt.S mbr code looks at both primary and alternate GPT
partition tables, mbrgpt.S and DKWEDGE_METHOD_GPT only look in the
primary. Align the bootxx/boot2 biosdisk code with this so as to avoid
situations where the disk becomes unbootable when it has an undestroyed
secondary GPT.
 1.45.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.45.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.46.12.3 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.46.12.2 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.46.12.1 15-Mar-2018  pgoyette Synch with HEAD
 1.46.6.7 17-Dec-2019  martin Pull up following revision(s) (requested by manu in ticket #1474):

sys/arch/i386/stand/lib/biosdisk.c: revision 1.54
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.9

Do not use NAME=label syntax when label are empty

When booting sysinst from UEFI, it defaults to a GPT installation
where partition have no labels. Bootstrap used the NAME=label partition
anyway, with the result that both EFI and FFS root partition had
the same name "NAME=" and could not be distinguished. The first matching
partition for the name was used, and bootstrap looked for the kernel
in the EFI partition.

We fix that by not using NAME=label names for partition when label
is empty. In that case we revert to old syntax such as hd0b
 1.46.6.6 17-Dec-2019  martin Pull up following revision(s) (requested by manu in ticket #1473):

sys/arch/i386/stand/lib/biosdisk.c: revision 1.53
sys/arch/i386/stand/efiboot/devopen.c: revision 1.9
sys/arch/i386/stand/boot/devopen.c: revision 1.10

In-RAID partitions with no name can be candidate for booting

The code to select boot partition in RAID assumed thet had a name,
which is true when there is a GPT inside the RAID, but not when there
is a disklabel inside the RAID. This caused a regression from behavior
of NetBSD 8.1.

We fix this by allowing nameless partition to be boot candidates.
This fixes PR misc/54748

While there, let raid device be used in the boot specification, like
raid0a:/netbsd.
 1.46.6.5 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.46.6.4 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #1373):

sys/arch/i386/stand/boot/boot2.c: revision 1.72 (patch)
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14 (patch)
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.

Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.46.6.3 04-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #692):

sys/arch/i386/stand/efiboot/devopen.c: revision 1.4
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.5
sys/arch/i386/stand/efiboot/devopen.h: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.3
sys/lib/libsa/bootcfg.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.9
sys/lib/libsa/bootcfg.c: revision 1.3
sys/arch/i386/stand/lib/bootmenu.c: revision 1.17
sys/arch/i386/stand/lib/biosdisk.c: revision 1.49
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.5
sys/arch/i386/stand/lib/bootmenu.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.h: revision 1.10

efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.46.6.2 21-Mar-2018  martin Pull up following revision(s) (requested by nonaka in ticket #648):
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.3
sys/arch/i386/stand/efiboot/devopen.c: revision 1.3
sys/arch/i386/stand/efiboot/boot.c: revision 1.7
sys/arch/i386/stand/lib/biosdisk.c: revision 1.48

efiboot: fix it can't boot from HDD.

efiboot: more pager.

efiboot: boot device is always efi_distlist first element.

efiboot: fix to find boot partition process.
NetBSD related partitions with no bootme flag set are also candidates
for boot partition.
 1.46.6.1 13-Mar-2018  martin Pull up following revision(s) (requested by nonaka in ticket #625):
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.2
sys/arch/i386/stand/efiboot/devopen.c: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.6
sys/arch/i386/stand/efiboot/efidisk_ll.c: revision 1.2
sys/arch/i386/stand/efiboot/efidev.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk_ll.h: revision 1.16
sys/arch/i386/stand/lib/biosdisk.h: revision 1.9
sys/lib/libsa/cd9660.c: revision 1.31
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.5
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.c: revision 1.47
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.10
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.4
efiboot: system can boot from CD/DVD-ROM media.

Add missed file in previous commit.
 1.49.6.5 18-Oct-2023  martin Pull up following revision(s) (requested by manu in ticket #1751):

sys/dev/raidframe/rf_netbsdkintf.c: revision 1.383
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.385
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.402
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.403
sys/arch/i386/stand/lib/biosdisk.c: revision 1.59
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.377
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.378
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.379
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.392
sys/rump/librump/rumpkern/emul.c: revision 1.200
sys/arch/i386/stand/lib/biosdisk.c: revision 1.60
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.416
(all via patch)

Get &rsc->sc_dksc only when we know 'rsc' is not NULL. This was actually
harmless because we didn't use the pointer then.

Gcc -Os on landisk is not smart enough to follow the conditional
initialization and warns, unconditionaly initialize dksc at declaration
with a XXX gcc comment.

Improve wording in comments in raid_dumpblock().

in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.

Nix trailing whitespace.

if raidframe sets booted_device, log a debug message about it.
merge two debug lines in auto-root selection.
convert non-config-handled "DEBUG_ROOT" to aprint_debug().
now it's possible to get boot-time info about raidframe root
device selection with simple "boot -x".

Align the behavior of different boot methods in RAIDframe

We enforce the documented and paritally implemented behavior when
looking for the kernel in RAID 1 sets without a partition name given.

We search for:
- A GPT partition with bootme attribute set
- A FFS or LFS patititon
- The first partition

Fix root search in RAID 1 sets

We use the wedge information given by bootstrap, where the kernel was
found. This requires src/sys/arch/i386/stand/i386/lib/biosdisk.c 1.59
to work in all cases.

Fix build with -DNO_GPT
 1.49.6.4 17-Dec-2019  martin Pull up following revision(s) (requested by manu in ticket #568):

sys/arch/i386/stand/lib/biosdisk.c: revision 1.54
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.9

Do not use NAME=label syntax when label are empty

When booting sysinst from UEFI, it defaults to a GPT installation
where partition have no labels. Bootstrap used the NAME=label partition
anyway, with the result that both EFI and FFS root partition had
the same name "NAME=" and could not be distinguished. The first matching
partition for the name was used, and bootstrap looked for the kernel
in the EFI partition.

We fix that by not using NAME=label names for partition when label
is empty. In that case we revert to old syntax such as hd0b
 1.49.6.3 17-Dec-2019  martin Pull up following revision(s) (requested by manu in ticket #567):

sys/arch/i386/stand/lib/biosdisk.c: revision 1.53
sys/arch/i386/stand/efiboot/devopen.c: revision 1.9
sys/arch/i386/stand/boot/devopen.c: revision 1.10

In-RAID partitions with no name can be candidate for booting

The code to select boot partition in RAID assumed thet had a name,
which is true when there is a GPT inside the RAID, but not when there
is a disklabel inside the RAID. This caused a regression from behavior
of NetBSD 8.1.

We fix this by allowing nameless partition to be boot candidates.
This fixes misc/54748

While there, let raid device be used in the boot specification, like
raid0a:/netbsd.
 1.49.6.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.49.6.1 13-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #200):

sys/arch/i386/stand/boot/boot2.c: revision 1.72
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.
Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.49.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.54.14.1 31-May-2021  cjep sync with head
 1.54.12.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.58.4.2 14-Jan-2024  martin Pull up following revision(s) (requested by mlelstv in ticket #548):

sys/arch/i386/stand/efiboot/efidisk.h: revision 1.4
sys/arch/i386/stand/lib/exec.c: revision 1.80
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.11
sys/arch/i386/stand/lib/biosdisk.c: revision 1.61

In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
hard drives (with geom) and CD-ROM (without).
 1.58.4.1 18-Oct-2023  martin Pull up following revision(s) (requested by manu in ticket #418):

sys/arch/i386/stand/lib/biosdisk.c: revision 1.59
sys/rump/librump/rumpkern/emul.c: revision 1.200
sys/arch/i386/stand/lib/biosdisk.c: revision 1.60
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.416

Align the behavior of different boot methods in RAIDframe

We enforce the documented and paritally implemented behavior when
looking for the kernel in RAID 1 sets without a partition name given.

We search for:
- A GPT partition with bootme attribute set
- A FFS or LFS patititon
- The first partition

Fix root search in RAID 1 sets

We use the wedge information given by bootstrap, where the kernel was
found. This requires src/sys/arch/i386/stand/i386/lib/biosdisk.c 1.59
to work in all cases.

Fix build with -DNO_GPT
 1.13 30-May-2021  mlelstv Add "root" command to provide a BTINFO_ROOTDEVICE parameter.
 1.12 13-Sep-2019  manu branches: 1.12.12; 1.12.14;
Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.11 18-Aug-2019  manu Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:
boot NAME=root:/netbsd
boot raid0e:/netbsd
 1.10 02-Apr-2018  nonaka branches: 1.10.2; 1.10.6;
efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.9 08-Mar-2018  nonaka efiboot: system can boot from CD/DVD-ROM media.
 1.8 24-Dec-2010  jakllsch branches: 1.8.52; 1.8.58;
Sprinkle daddr_t.
Adjust DISK_DEBUG printf formats to match.
 1.7 14-Dec-2008  christos branches: 1.7.2; 1.7.6;
ANSI and KNF from Anon Ymous
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.78; 1.6.86;
merge ktrace-lwp.
 1.5 22-Jun-2005  junyoung Add support for cd9660 file system to the i386 BIOS bootloader.
 1.4 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.3 01-Feb-2003  dsl branches: 1.3.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace/indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.6.78.1 04-May-2009  yamt sync with head.
 1.6.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.6.1 05-Mar-2011  rmind sync with head
 1.7.2.1 10-Jan-2011  jym Sync with HEAD
 1.8.58.2 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.8.58.1 15-Mar-2018  pgoyette Synch with HEAD
 1.8.52.4 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.8.52.3 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #1373):

sys/arch/i386/stand/boot/boot2.c: revision 1.72 (patch)
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14 (patch)
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.

Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.8.52.2 04-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #692):

sys/arch/i386/stand/efiboot/devopen.c: revision 1.4
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.5
sys/arch/i386/stand/efiboot/devopen.h: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.3
sys/lib/libsa/bootcfg.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.9
sys/lib/libsa/bootcfg.c: revision 1.3
sys/arch/i386/stand/lib/bootmenu.c: revision 1.17
sys/arch/i386/stand/lib/biosdisk.c: revision 1.49
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.5
sys/arch/i386/stand/lib/bootmenu.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.h: revision 1.10

efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.8.52.1 13-Mar-2018  martin Pull up following revision(s) (requested by nonaka in ticket #625):
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.2
sys/arch/i386/stand/efiboot/devopen.c: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.6
sys/arch/i386/stand/efiboot/efidisk_ll.c: revision 1.2
sys/arch/i386/stand/efiboot/efidev.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk_ll.h: revision 1.16
sys/arch/i386/stand/lib/biosdisk.h: revision 1.9
sys/lib/libsa/cd9660.c: revision 1.31
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.5
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.c: revision 1.47
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.10
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.4
efiboot: system can boot from CD/DVD-ROM media.

Add missed file in previous commit.
 1.10.6.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.10.6.1 13-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #200):

sys/arch/i386/stand/boot/boot2.c: revision 1.72
sys/arch/i386/stand/lib/biosdisk.c: revision 1.50
sys/arch/i386/stand/lib/biosdisk.c: revision 1.51
sys/arch/i386/stand/efiboot/devopen.c: revision 1.6
sys/arch/i386/stand/efiboot/devopen.h: revision 1.4
sys/arch/i386/stand/efiboot/devopen.c: revision 1.7
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.8
share/man/man8/man8.x86/boot.8: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.17
sys/arch/i386/stand/lib/Makefile: revision 1.46
sys/arch/i386/stand/boot/devopen.h: revision 1.5
sys/arch/i386/stand/boot/devopen.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.14
sys/arch/i386/stand/efiboot/boot.c: revision 1.15
sys/arch/i386/stand/lib/biosdisk.h: revision 1.11
sys/arch/i386/stand/boot/boot2.c: revision 1.71

Add GPT and RAIDframe support to bootloaders

Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:

boot NAME=root:/netbsd
boot raid0e:/netbsd

Correct the memset(3)'s third argument in i386 biosdisk.c

The size of allocation is the size of the structure biosdisk, not the size
of a pointer.

Document new GPT and RAIDframe capacity of bootstrap code
While there, also document EFI setup and some bugs

Typo fixes, 'file system'; new sentence, new line; expand IA-32.
Bump date for previous.

Make sure devices names are copied including last byte
Fix from M. Levinson.
 1.10.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.14.1 31-May-2021  cjep sync with head
 1.12.12.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.31 21-Feb-2011  jakllsch Rework previous commit. Return non-zero instead of turning off
BIOSDISK_INT13EXT. BIOSDISK_INT13EXT also enables LBA access mechanisms
that we really want to be using if at all possible.
 1.30 21-Feb-2011  dyoung biosdisk_getextinfo() can fail. If it does fail in set_geometry(),
clear the flag BIOSDISK_INT13EXT so that a caller such as read_gpt()
will not try to rely on the gibberish in the biosdisk_extinfo.
 1.29 30-Dec-2010  jakllsch branches: 1.29.2; 1.29.4;
Make this actually build with DISK_DEBUG.
 1.28 25-Dec-2010  jakllsch Use printf format macros for long longs.
 1.27 24-Dec-2010  jakllsch Sprinkle daddr_t.
Adjust DISK_DEBUG printf formats to match.
 1.26 28-Apr-2008  martin branches: 1.26.14; 1.26.22;
Remove clause 3 and 4 from TNF licenses
 1.25 18-Nov-2006  erh branches: 1.25.52; 1.25.54; 1.25.56;
Add casts so this works with DISK_DEBUG defined.
 1.24 11-Dec-2005  christos branches: 1.24.20; 1.24.22;
merge ktrace-lwp.
 1.23 29-Jun-2005  junyoung branches: 1.23.2;
Massive renames for consistency:
biosdiskreset -> biosdisk_reset
biosread -> biosdisk_read
get_diskinfo -> biosdisk_getinfo
int13_extension -> biosdisk_int13ext
biosextread -> biosdisk_extread
int13_getextinfo -> biosdisk_getextinfo
struct biosdisk_ext13info -> biosdisk_extinfo
BIOSDISK_EXT13 -> BIOSDISK_INT13EXT
BIOSDISK_EXT13INFO_V{2,3} -> BIOSDISK_EXTINFO_V{2,3}
EXT13_* -> EXTINFO_*
 1.22 29-Jun-2005  junyoung get_diskinfo():
Return status code in bits [31:24] of %eax. 0 for success, otherwise failure.
 1.21 22-Jun-2005  junyoung Add support for cd9660 file system to the i386 BIOS bootloader.
 1.20 13-Jun-2005  junyoung ANSI, KNF, kill trailing spaces, and cosmetic changes.
 1.19 23-Aug-2004  junyoung Include libi386.h for function prototypes.
 1.18 25-Jun-2003  thorpej branches: 1.18.2;
Add a way to force (at compile time) use of int13 extensions.
 1.17 16-Apr-2003  dsl Use daddr_t for disk block numbers,
Set size of extended disk info structure in the C code
 1.16 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.15 07-Feb-2003  dsl Use on-stack buffer to check for 2.88MB floppy, malloc() hasn't been
loaded when this is called.
Clearly the information is actually available from the bios.
(Approved by christos)
 1.14 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.13 04-Dec-2002  jdolecek If booting from floppy in 2.88MB drive, actually test if it's possible
to read sector 18, and fallback to 1.44MB drive geometry if that fails.
This allows to boot from 1.44MB floppy disk in 2.88MB drive.
Tested with 2.88MB drive in IBM PS/2 model 95 donated
by 'Yokotashi' <lhc at kanal ucw cz> and Pavel Cahyna
<pavel.cahyna at st ms mff cuni cz>
Bump biosboot version.

Fixes PR kern/3418 by Keith Moore.

Change okayed by Frank van den Linden.
 1.12 10-Oct-2002  dyoung Introduce biosdiskreset(), and call it to reset the disk (with Int
0x13 Function 0) after a read error. This is a requirement mentioned
in most BIOS documentation.

This answers PR 18591.

Incidentally, on the Soekris Engineering net45x1 single-board
computer, this fixes a bug where the bootloader corrupts the kernel
while loading it from certain varieties of CompactFlash card
(especially varieties identified by NetBSD as <TOSHIBA THNCF064MBA>).
 1.11 07-Jul-2001  perry branches: 1.11.4; 1.11.18;
b*()->mem*()
 1.10 02-Nov-1999  drochner branches: 1.10.10;
correct debug printf() to make it compile with DISK_DEBUG again,
closes PR kern/8718 by Takahiro Kambe
 1.9 04-May-1999  fvdl branches: 1.9.2; 1.9.4; 1.9.6;
Restrict "out of CHS range" check to harddisks.
 1.8 28-Apr-1999  fvdl Only use int13 extensions if the sectors can not be read through the
older CHS interface. This works around stupid BIOSs who report that
int13 extensions are present and functional, but fail when you actually
use them. Like Adaptec SCSI BIOSs.
 1.7 30-Mar-1999  drochner branches: 1.7.2;
fix some disk handling problems introduced in the last commits:
-read retries were botched, use the right sector count
-read-ahead buffer was effectively unused
-concentrate the handling of the weird BIOS geometry report at one place
-fallback for old floppies left cylinder count uninitialized
 1.6 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.5 15-Oct-1998  ws Add int13 extension support
 1.4 23-Jul-1998  drochner retry disk accesses (for shaky floppy drives)
 1.3 13-Jun-1997  drochner Reformat comments. (messed up by "indent")
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace/indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.7.2.2 04-May-1999  perry branches: 1.7.2.2.2;
pullup 1.8->1.9 (fvdl)
 1.7.2.1 02-May-1999  perry pullup 1.7->1.8 (fvdl)
 1.7.2.2.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.9.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.4.1 15-Nov-1999  fvdl Sync with -current
 1.9.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.10.10.3 11-Dec-2002  thorpej Sync with HEAD.
 1.10.10.2 18-Oct-2002  nathanw Catch up to -current.
 1.10.10.1 24-Aug-2001  nathanw Catch up with -current.
 1.11.18.1 12-Jan-2003  jmc Pull up versions 1.12-1.13 (requested by jdolecek in ticket #1067)
If booting from floppy in 2.88MB drive, actually test if it's possible
to read sector 18, and fallback to 1.44MB drive geometry if that fails.
This allows to boot from 1.44MB floppy disk in 2.88MB drive.
Tested with 2.88MB drive in IBM PS/2 model 95 donated
by 'Yokotashi' <lhc at kanal ucw cz> and Pavel Cahyna
<pavel.cahyna at st ms mff cuni cz>
Bump biosboot version.

Fixes PR kern/3418 by Keith Moore.
 1.11.4.2 07-Jul-2001  perry b*()->mem*()
 1.11.4.1 07-Jul-2001  perry file biosdisk_ll.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:58 +0000
 1.18.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.23.2.1 30-Dec-2006  yamt sync with head.
 1.24.22.1 10-Dec-2006  yamt sync with head.
 1.24.20.1 12-Jan-2007  ad Sync with head.
 1.25.56.1 16-May-2008  yamt sync with head.
 1.25.54.1 18-May-2008  yamt sync with head.
 1.25.52.1 02-Jun-2008  mjf Sync with HEAD.
 1.26.22.1 05-Mar-2011  rmind sync with head
 1.26.14.2 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.26.14.1 10-Jan-2011  jym Sync with HEAD
 1.29.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.29.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.16 08-Mar-2018  nonaka efiboot: system can boot from CD/DVD-ROM media.
 1.15 25-Dec-2007  perry branches: 1.15.90; 1.15.96;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.14 11-Dec-2005  christos branches: 1.14.50; 1.14.56; 1.14.60; 1.14.64;
merge ktrace-lwp.
 1.13 29-Jun-2005  junyoung branches: 1.13.2;
Massive renames for consistency:
biosdiskreset -> biosdisk_reset
biosread -> biosdisk_read
get_diskinfo -> biosdisk_getinfo
int13_extension -> biosdisk_int13ext
biosextread -> biosdisk_extread
int13_getextinfo -> biosdisk_getextinfo
struct biosdisk_ext13info -> biosdisk_extinfo
BIOSDISK_EXT13 -> BIOSDISK_INT13EXT
BIOSDISK_EXT13INFO_V{2,3} -> BIOSDISK_EXTINFO_V{2,3}
EXT13_* -> EXTINFO_*
 1.12 23-Jun-2005  junyoung Define BIOSDISK_DEFAULT_SECSIZE in biosdisk_ll.h and replace BIOSDISK_SECSIZE
with it.
 1.11 22-Jun-2005  junyoung Add support for cd9660 file system to the i386 BIOS bootloader.
 1.10 13-Jun-2005  junyoung Cosmetic changes.
 1.9 13-Jun-2005  junyoung - Remove support for gcc < 2.7.x. Nobody is using such an old version
these days.
- s/u_int/uint/
- De-__P()
 1.8 16-Apr-2003  dsl branches: 1.8.2;
used daddr_t for disk block numbers,
add definitions for v2 and v3 disk info structures
 1.7 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.6 28-Apr-1999  fvdl Only use int13 extensions if the sectors can not be read through the
older CHS interface. This works around stupid BIOSs who report that
int13 extensions are present and functional, but fail when you actually
use them. Like Adaptec SCSI BIOSs.
 1.5 12-Mar-1999  fvdl branches: 1.5.2;
Clean up the BIOS disk matching code a bit (better naming, one structure
and sysctl to export to userland). Also, only use total number of sectors
given in the extended parameters if the physical chs geometry is
marked invalid. Hopefully fixes a problem where BIOSs would not correctly
fill in this field.
 1.4 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.3 15-Oct-1998  ws Add int13 extension support
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace/indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.5.2.1 02-May-1999  perry branches: 1.5.2.1.2;
pullup 1.5->1.6 (fvdl)
 1.5.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.2.1 21-Jan-2008  yamt sync with head
 1.14.64.1 02-Jan-2008  bouyer Sync with HEAD
 1.14.60.1 26-Dec-2007  ad Sync with head.
 1.14.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.50.1 09-Jan-2008  matt sync with HEAD
 1.15.96.1 15-Mar-2018  pgoyette Synch with HEAD
 1.15.90.1 13-Mar-2018  martin Pull up following revision(s) (requested by nonaka in ticket #625):
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.2
sys/arch/i386/stand/efiboot/devopen.c: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.6
sys/arch/i386/stand/efiboot/efidisk_ll.c: revision 1.2
sys/arch/i386/stand/efiboot/efidev.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk_ll.h: revision 1.16
sys/arch/i386/stand/lib/biosdisk.h: revision 1.9
sys/lib/libsa/cd9660.c: revision 1.31
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.5
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.c: revision 1.47
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.10
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.4
efiboot: system can boot from CD/DVD-ROM media.

Add missed file in previous commit.
 1.7 16-Jun-2011  joerg Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.6 11-Dec-2005  christos branches: 1.6.92; 1.6.110;
merge ktrace-lwp.
 1.5 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.4 12-May-2003  dsl branches: 1.4.2;
Remove some unused defines
 1.3 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.2 13-Jun-1997  drochner Add missing datasize prefix.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.110.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6.92.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.3 16-Jun-2011  joerg Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.2 28-Apr-2008  martin branches: 1.2.14; 1.2.32;
Remove clause 3 and 4 from TNF licenses
 1.1 16-Apr-2003  dsl branches: 1.1.104; 1.1.106; 1.1.108;
additional support routines for boot code
 1.1.108.1 16-May-2008  yamt sync with head.
 1.1.106.1 18-May-2008  yamt sync with head.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.32.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.14.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.4 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.3 23-Jan-2003  jdolecek use %e?x instead of %?x as 'xorl' arguments
use %al for 'movb' target, and 'andb' for masking the result with $0x02
since 'and' conveniently sets ZF, use 'and+jnz' instead of 'and+cmp+jne'
 1.2 14-May-2001  jdolecek branches: 1.2.2; 1.2.4;
Change biosmca() to export the model number via biosmca_ps2model
variable, if the machine has a MCA bus according to info returned
by BIOS (i.e. on machines without MCA bus, biosmca_ps2model would be zero).

biosmca() is expected to be called on beginning the initialization,
and biosmca_ps2model is then used for further checks.
 1.1 02-May-2001  jdolecek Add function which uses bios call to get system configuration; this can
be used for presence of MCA bus, if ever needed to be done in bootblocks.
Not used at the moment, but may be in future.
 1.2.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.4.1 14-May-2001  nathanw file biosmca.S was added on branch nathanw_sa on 2001-06-21 19:26:15 +0000
 1.2.2.2 14-May-2001  jdolecek Change biosmca() to export the model number via biosmca_ps2model
variable, if the machine has a MCA bus according to info returned
by BIOS (i.e. on machines without MCA bus, biosmca_ps2model would be zero).

biosmca() is expected to be called on beginning the initialization,
and biosmca_ps2model is then used for further checks.
 1.2.2.1 14-May-2001  jdolecek file biosmca.S was added on branch sommerfeld_i386mp_1 on 2001-05-14 22:14:48 +0000
 1.3 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.2 28-Apr-2008  martin branches: 1.2.8;
Remove clause 3 and 4 from TNF licenses
 1.1 14-May-2001  jdolecek branches: 1.1.2; 1.1.4; 1.1.128; 1.1.130; 1.1.132;
Change biosmca() to export the model number via biosmca_ps2model
variable, if the machine has a MCA bus according to info returned
by BIOS (i.e. on machines without MCA bus, biosmca_ps2model would be zero).

biosmca() is expected to be called on beginning the initialization,
and biosmca_ps2model is then used for further checks.
 1.1.132.2 04-May-2009  yamt sync with head.
 1.1.132.1 16-May-2008  yamt sync with head.
 1.1.130.1 18-May-2008  yamt sync with head.
 1.1.128.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.128.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 14-May-2001  nathanw file biosmca.h was added on branch nathanw_sa on 2001-06-21 19:26:16 +0000
 1.1.2.2 14-May-2001  jdolecek Change biosmca() to export the model number via biosmca_ps2model
variable, if the machine has a MCA bus according to info returned
by BIOS (i.e. on machines without MCA bus, biosmca_ps2model would be zero).

biosmca() is expected to be called on beginning the initialization,
and biosmca_ps2model is then used for further checks.
 1.1.2.1 14-May-2001  jdolecek file biosmca.h was added on branch sommerfeld_i386mp_1 on 2001-05-14 22:14:48 +0000
 1.2.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.10 04-Dec-2016  maxv KNF and explain a few things
 1.9 16-Jun-2011  joerg branches: 1.9.12; 1.9.30; 1.9.34;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.8 11-Dec-2005  christos branches: 1.8.92; 1.8.110;
merge ktrace-lwp.
 1.7 06-Jul-2005  junyoung Remove unused #define.
 1.6 01-Feb-2003  dsl branches: 1.6.2; 1.6.18;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.5 18-Aug-1997  hannken Change "it's" to "it is" inside assembler comments to
stop "unterminated character constant" messages from `mkdep'.
 1.4 14-Aug-1997  drochner New, optional, method to get size of extended memory.
It will be used for getextmem() if EXTENDED_MEMDETECT is defined.
Worked on all tested machines.
Thanks to all testers, especially Martin Husemann!
 1.3 13-Jun-1997  drochner branches: 1.3.4;
Fix misleading comment.
 1.2 19-Mar-1997  sommerfe In 16-bit mode, mov %ax,%bx is interpreted as mov %eax,%ebx; this
breaks zero-extension of the 16-bit memory size return from the BIOS.
on at least one system, the trash left in the upper half of %eax
causes the kernel to crash during VM system initialization when it
thinks it has on the order of 2**31 bytes of memory to play with.

We now *say* mov %eax,%ebx, but *mean* mov %ax,%bx..
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.18.1 21-Jun-2006  yamt sync with head.
 1.6.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.110.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.8.92.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.9.34.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.9.30.1 05-Dec-2016  skrll Sync with HEAD
 1.9.12.1 03-Dec-2017  jdolecek update from HEAD
 1.7 04-Dec-2016  maxv KNF and explain a few things
 1.6 16-Jun-2011  joerg branches: 1.6.12; 1.6.30; 1.6.34;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.5 20-Feb-2011  jakllsch branches: 1.5.2;
%bl is part of %bx, %bx contains the address we requested from the BIOS.
Thus, use %cl instead of %bl for return value storage.
 1.4 21-Nov-2009  dsl branches: 1.4.4; 1.4.6; 1.4.8;
Preserve %ds over bios calls.
Not strickly necessary because real_to_prot doesn't normally rely on in.
However it caused much confusion while debugging, and does no harm.
 1.3 28-Apr-2008  martin branches: 1.3.14;
Remove clause 3 and 4 from TNF licenses
 1.2 05-Feb-2003  dsl branches: 1.2.104; 1.2.106; 1.2.108;
Change to use .codw16/32 and ensure buffer address <64k
(approved by christos)
 1.1 23-Jan-2003  jdolecek add another memory size detection routine, using int15, function 0xc7, which
is supported on later IBM PS/2 models; this is necessary to detect memory
over 64MB
thanks go to Pavel Cahyna for testing on his IBM PS/2 machine with 128MB

bump biosboot version to 2.15
 1.2.108.2 11-Mar-2010  yamt sync with head
 1.2.108.1 16-May-2008  yamt sync with head.
 1.2.106.1 18-May-2008  yamt sync with head.
 1.2.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.14.3 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.3.14.2 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.3.14.1 24-Oct-2010  jym Sync with HEAD
 1.4.8.1 05-Mar-2011  bouyer Sync with HEAD
 1.4.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.4.4.1 05-Mar-2011  rmind sync with head
 1.5.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6.34.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.6.30.1 05-Dec-2016  skrll Sync with HEAD
 1.6.12.1 03-Dec-2017  jdolecek update from HEAD
 1.13 24-Aug-2024  riastradh i386/stand/lib: Nix trailing whitespace and tidy comments a bit.

No functional change intended.

PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.12 17-Aug-2024  andvar Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().
This in turn was leading to erroneous caluclations and memory addresses.
This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.

needs-pullups to 9, 10.

PR install/49470
 1.11 02-Aug-2021  andvar branches: 1.11.8; 1.11.14;
fix various typos in comments and log messages.
 1.10 04-Dec-2016  maxv branches: 1.10.20;
KNF and explain a few things
 1.9 14-Oct-2008  ad branches: 1.9.38; 1.9.58; 1.9.62;
PR kern/39726 Soekris 5501-60 boot/bootxx 120 second delay

Try enabling A20 using an extended BIOS call before playing around with
the keyboard controller or system config port.
 1.8 11-Dec-2005  christos branches: 1.8.74; 1.8.78; 1.8.84;
merge ktrace-lwp.
 1.7 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.6 07-Nov-2003  dsl Change getextmem2 to return 'configured' values from cx/dx if ax/bx zero,
make absolutely high the top 16bits of returned values are zero.
Ralf's list says that some BIOS need %eax = 0x0000e820 in getmementry.
Add a few comments.
Might fix problems with memory size detection on some systems.
 1.5 14-Feb-2003  dsl branches: 1.5.2;
Use correct segment register in getmementry
 1.4 05-Feb-2003  dsl A buffer slipped though the net... Ensure offset < 64k.
(approved by christos)
 1.3 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.2 08-Mar-1999  drochner change the interface for getmementry() to hold the iterator in an
argument and to return success or error explicitely.
Now we can "error" and "end of list" cleanly; this should fix the
problem where the last list element was ignored.
 1.1 14-Aug-1997  drochner branches: 1.1.2;
New, optional, method to get size of extended memory.
It will be used for getextmem() if EXTENDED_MEMDETECT is defined.
Worked on all tested machines.
Thanks to all testers, especially Martin Husemann!
 1.1.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 14-Aug-1997  thorpej file biosmemx.S was added on branch marc-pcmcia on 1997-08-23 07:09:35 +0000
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.84.1 19-Oct-2008  haad Sync with HEAD.
 1.8.78.1 04-May-2009  yamt sync with head.
 1.8.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.9.62.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.9.58.1 05-Dec-2016  skrll Sync with HEAD
 1.9.38.1 03-Dec-2017  jdolecek update from HEAD
 1.10.20.1 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #1884):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.11.14.1 02-Aug-2025  perseant Sync with HEAD
 1.11.8.1 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #815):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.6 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.5 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.78; 1.4.86;
merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 22-Mar-1997  thorpej branches: 1.2.58;
Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.58.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.58.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.58.1 03-Aug-2004  skrll Sync with HEAD
 1.4.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.4.78.1 04-May-2009  yamt sync with head.
 1.4.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.5 16-Jun-2011  joerg Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.4 11-Dec-2005  christos branches: 1.4.92; 1.4.110;
merge ktrace-lwp.
 1.3 06-Jul-2005  junyoung Remove unused #define and trailing spaces.
 1.2 01-Feb-2003  dsl branches: 1.2.2; 1.2.18;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 13-Apr-1997  perry Provides "reboot" call, which just calles INT 19h to ask the bios to
reboot the machine.
This may be insufficient, but its enough for now.
 1.2.18.1 21-Jun-2006  yamt sync with head.
 1.2.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.110.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.92.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.3 20-Feb-2011  jakllsch Follow a minor detail in the spec a bit more closely.
 1.2 09-Feb-2011  jmcneill Add VESA VBE/DDC EDID support for determining the monitor's preferred
video mode. "vesa on" will now select the preferred mode @ 8bpp if it can
be determined and is supported by the display adapter, otherwise it will
use 640x480 @ 8bpp.
 1.1 16-Feb-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.10; 1.1.12; 1.1.14;
Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.1.14.2 05-Mar-2011  bouyer Sync with HEAD
 1.1.14.1 17-Feb-2011  bouyer Sync with HEAD
 1.1.12.1 06-Jun-2011  jruoho Sync with HEAD.
 1.1.10.1 05-Mar-2011  rmind sync with head
 1.1.6.4 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.1.6.3 01-Nov-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 16-Feb-2009  jym file biosvbe.S was added on branch jym-xensuspend on 2009-05-13 17:17:51 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 16-Feb-2009  yamt file biosvbe.S was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.1.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.1.2.1 16-Feb-2009  skrll file biosvbe.S was added on branch nick-hppapmap on 2009-03-03 18:29:00 +0000
 1.3 16-Apr-2003  dsl Add cvs version, delete unused definition
 1.2 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 23-Apr-2000  tsarna branches: 1.1.2; 1.1.8;
Addredd port-i386/9897, but differently. Since the effect of resetting
the video mode on machines with ancient or no video cards is not clear,
for safety's sake a I created a new biosboot variant, biosboot_resetvideo
that does the call.

Anyway, now I can boot my i-opener without hitting Tab. Thanks Andrew!
 1.1.8.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.8.1 23-Apr-2000  bouyer file biosvideomode.S was added on branch thorpej_scsipi on 2000-11-20 20:09:39 +0000
 1.1.2.2 23-Apr-2000  tsarna Addredd port-i386/9897, but differently. Since the effect of resetting
the video mode on machines with ancient or no video cards is not clear,
for safety's sake a I created a new biosboot variant, biosboot_resetvideo
that does the call.

Anyway, now I can boot my i-opener without hitting Tab. Thanks Andrew!
 1.1.2.1 23-Apr-2000  tsarna file biosvideomode.S was added on branch sommerfeld_i386mp_1 on 2000-04-23 19:57:15 +0000
 1.6 17-Jan-2010  drochner Invert the flag bits to control module loading: rename
LOADMODULES->NOMODULES and READBOOTCONF->NOBOOTCONF.
This way, the default value (0) wired into old bootxx_* and installed
to file systems remains valid and we avoid problems on partial updates.
 1.5 14-Jan-2010  drochner On i386/amd64, define two flag bits in the boot parameters which control
whether modules are loaded and whether boot.cfg is evaluated, and
set both to "off" per default in the PXE bootloader.
Extend "installboot" to toggle the bits.
This way, pxeboot works with existing dhcp server setups (and as
described in the manpage) out of the box. Also, boot.cfg reading
involves a stat() call which is horribly inefficient with the
TFTP pseudo file system.
 1.4 11-Dec-2005  christos branches: 1.4.78; 1.4.92;
merge ktrace-lwp.
 1.3 15-Aug-2004  dsl Allow the com port base address to be specified by the user (via installboot)
rather than taking the value from the bios.
Should allow the system to use a serial console that is also a 'bios serial
console' and isn't in the bios serial port table.
Probably fixes (with a few other changes) PR port-i386/9236
 1.2 13-Mar-2004  dsl branches: 1.2.4;
Translate ascii keycode to help those with azerty keyboard type straight.
 1.1 09-Oct-2003  dsl Pick up X86_BOOT_MAGIC_* from bootblock.h
Move boot_params.S to lib (seems useful to use it in pxeboot).
 1.2.4.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.4.4 18-Sep-2004  skrll Sync with HEAD.
 1.2.4.3 25-Aug-2004  skrll Sync with HEAD.
 1.2.4.2 03-Aug-2004  skrll Sync with HEAD
 1.2.4.1 13-Mar-2004  skrll file boot_params.S was added on branch ktrace-lwp on 2004-08-03 10:36:19 +0000
 1.4.92.1 24-Oct-2010  jym Sync with HEAD
 1.4.78.1 11-Mar-2010  yamt sync with head
 1.6 05-Jun-2016  maxv Don't use a magic value. Define a limit, and enforce it.
 1.5 14-Dec-2008  christos branches: 1.5.24; 1.5.42;
more KNF and ANSI from Anon-ymous
 1.4 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.78; 1.3.86;
merge ktrace-lwp.
 1.2 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.1 17-Sep-1997  drochner branches: 1.1.2; 1.1.54;
Definitions and helper functions to collect information in the boot
loader (still experimental).
 1.1.54.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.54.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.54.1 03-Aug-2004  skrll Sync with HEAD
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file bootinfo.c was added on branch marc-pcmcia on 1997-09-22 06:31:23 +0000
 1.3.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.78.1 04-May-2009  yamt sync with head.
 1.3.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.42.1 09-Jul-2016  skrll Sync with HEAD
 1.5.24.1 03-Dec-2017  jdolecek update from HEAD
 1.12 27-Jan-2018  pgoyette Recent changes have increased the number of "things" the bootloader
needs to deal with. Increase the table size so we don't overflow.
 1.11 05-Jun-2016  maxv branches: 1.11.10;
Don't use a magic value. Define a limit, and enforce it.
 1.10 18-Nov-2013  jakllsch branches: 1.10.6;
Bring arch/i386/stand bootinfo structure in line with the kernel's
fixed-layout understanding of it.
 1.9 25-Jan-2006  christos branches: 1.9.110; 1.9.120; 1.9.126;
free -> dealloc
unsigned -> size_t for alloc/dealloc
 1.8 11-Dec-2005  christos branches: 1.8.2;
merge ktrace-lwp.
 1.7 06-Jul-2005  junyoung branches: 1.7.2;
De-__P()
 1.6 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.5 10-Mar-1999  fvdl branches: 1.5.44;
Create a list of native disks too, and make it retrievable. It contains
all matching BIOS disks per entry, so that we have complete match info.
Enable the matching code.
 1.4 08-Mar-1999  drochner add a function to pass the "memory map" ie the outcome of INT15/0xe820,
to the kernel
 1.3 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.2 20-Sep-1997  drochner branches: 1.2.2;
Use <machine/bootinfo.h> for definitions shared with the kernel.
 1.1 17-Sep-1997  drochner Definitions and helper functions to collect information in the boot
loader (still experimental).
 1.2.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.1 20-Sep-1997  thorpej file bootinfo.h was added on branch marc-pcmcia on 1997-09-22 06:31:24 +0000
 1.5.44.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.44.1 03-Aug-2004  skrll Sync with HEAD
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.8.2.1 01-Feb-2006  yamt sync with head.
 1.9.126.1 18-May-2014  rmind sync with head
 1.9.120.2 03-Dec-2017  jdolecek update from HEAD
 1.9.120.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.110.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10.6.1 09-Jul-2016  skrll Sync with HEAD
 1.11.10.1 04-Feb-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #521):
sys/arch/i386/stand/lib/bootinfo.h: revision 1.12
Recent changes have increased the number of "things" the bootloader
needs to deal with. Increase the table size so we don't overflow.
 1.24 01-Aug-2019  manu Fix buffer overflow in BIOS disk geometry collect for bootinfo

This spares a boot-time panic on iMac with fusion drive, which
feature both a hard drive and a solid-state drive.
 1.23 24-Jan-2017  nonaka branches: 1.23.6; 1.23.14; 1.23.18;
Initial commit of native amd64 EFI boot loader.
 1.22 16-May-2013  christos branches: 1.22.10; 1.22.14; 1.22.18;
Complete the dosparts -> mbrparts conversion. Only x86k new uses dosparts
because it also uses struct dos_partition.
 1.21 25-Dec-2010  jakllsch branches: 1.21.8; 1.21.18;
Use printf format macros for long longs.
 1.20 20-Nov-2009  dsl branches: 1.20.4;
EXT13_DEVPATH_SIGNATURE should be EXTINFO_DEVPATH_SIGNATURE
 1.19 11-Dec-2005  christos branches: 1.19.78; 1.19.92;
merge ktrace-lwp.
 1.18 29-Jun-2005  junyoung Massive renames for consistency:
biosdiskreset -> biosdisk_reset
biosread -> biosdisk_read
get_diskinfo -> biosdisk_getinfo
int13_extension -> biosdisk_int13ext
biosextread -> biosdisk_extread
int13_getextinfo -> biosdisk_getextinfo
struct biosdisk_ext13info -> biosdisk_extinfo
BIOSDISK_EXT13 -> BIOSDISK_INT13EXT
BIOSDISK_EXT13INFO_V{2,3} -> BIOSDISK_EXTINFO_V{2,3}
EXT13_* -> EXTINFO_*
 1.17 23-Jun-2005  junyoung Define BIOSDISK_DEFAULT_SECSIZE in biosdisk_ll.h and replace BIOSDISK_SECSIZE
with it.
 1.16 22-Jun-2005  junyoung Use get_harddrives().
 1.15 22-Jun-2005  junyoung Add support for cd9660 file system to the i386 BIOS bootloader.
 1.14 21-Jun-2005  junyoung Cosmetic changes.
 1.13 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.12 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.11 16-Apr-2003  dsl branches: 1.11.2;
Add code to parse V3.x bios disk information.
This should let NetBSD guarantee to tie together the bios disk numbers
with the physical hardware.
#defined out because I don't have a system with a bios that supports it.
 1.10 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.9 07-Jul-2001  perry branches: 1.9.4;
b*()->mem*()
 1.8 30-Mar-1999  drochner branches: 1.8.22;
adapt to set_geometry change: we don't have to correct the geometry
anymore
 1.7 28-Mar-1999  fvdl Only use the total number of sectors information field from the EDD if
the bit is set that declares the geometry valid. The spec itself says
that this field isn't covered by the "geometry valid" bit, but at
least one BIOS implements it that way.
 1.6 12-Mar-1999  fvdl Clean up the BIOS disk matching code a bit (better naming, one structure
and sysctl to export to userland). Also, only use total number of sectors
given in the extended parameters if the physical chs geometry is
marked invalid. Hopefully fixes a problem where BIOSs would not correctly
fill in this field.
 1.5 11-Mar-1999  fvdl Declare nhd to be unsigned char, as we're only copying one byte to it.
From Matthias Drochner.
 1.4 08-Mar-1999  fvdl * query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.3 28-Jan-1999  christos Minor changes to prototypes.
 1.2 27-Jan-1999  thorpej Use the MI <sys/disklabel_mbr.h>, not our own machine-dependent
definitions.
 1.1 17-Sep-1997  drochner branches: 1.1.2;
Function to collect geometry and partitioning information about the
BIOS-known disks in a "bootinfo" structure (still experimental).
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file bootinfo_biosgeom.c was added on branch marc-pcmcia on 1997-09-22 06:31:25 +0000
 1.8.22.1 24-Aug-2001  nathanw Catch up with -current.
 1.9.4.2 07-Jul-2001  perry b*()->mem*()
 1.9.4.1 07-Jul-2001  perry file bootinfo_biosgeom.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:58 +0000
 1.11.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.11.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.11.2.1 03-Aug-2004  skrll Sync with HEAD
 1.19.92.2 10-Jan-2011  jym Sync with HEAD
 1.19.92.1 24-Oct-2010  jym Sync with HEAD
 1.19.78.1 11-Mar-2010  yamt sync with head
 1.20.4.1 05-Mar-2011  rmind sync with head
 1.21.18.2 03-Dec-2017  jdolecek update from HEAD
 1.21.18.1 23-Jun-2013  tls resync from head
 1.21.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.22.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.22.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.22.10.1 05-Feb-2017  skrll Sync with HEAD
 1.23.18.1 13-Aug-2019  martin Pull up following revision(s) (requested by manu in ticket #51):

sys/arch/i386/stand/lib/bootinfo_biosgeom.c: revision 1.24

Fix buffer overflow in BIOS disk geometry collect for bootinfo

This spares a boot-time panic on iMac with fusion drive, which
feature both a hard drive and a solid-state drive.
 1.23.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.23.6.1 13-Aug-2019  martin Pull up following revision(s) (requested by manu in ticket #1336):

sys/arch/i386/stand/lib/bootinfo_biosgeom.c: revision 1.24

Fix buffer overflow in BIOS disk geometry collect for bootinfo

This spares a boot-time panic on iMac with fusion drive, which
feature both a hard drive and a solid-state drive.
 1.8 24-Aug-2024  riastradh i386/stand/lib: Nix trailing whitespace and tidy comments a bit.

No functional change intended.

PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.7 17-Aug-2024  andvar Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().
This in turn was leading to erroneous caluclations and memory addresses.
This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.

needs-pullups to 9, 10.

PR install/49470
 1.6 13-Sep-2019  manu branches: 1.6.26; 1.6.32;
Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.5 14-Dec-2008  christos branches: 1.5.58; 1.5.66; 1.5.70;
ANSI and KNF from Anon Ymous
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.78; 1.4.86;
merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 07-Jul-2001  perry branches: 1.2.4; 1.2.24;
b*()->mem*()
 1.1 08-Mar-1999  drochner branches: 1.1.22;
add a function to pass the "memory map" ie the outcome of INT15/0xe820,
to the kernel
 1.1.22.1 24-Aug-2001  nathanw Catch up with -current.
 1.2.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.24.1 03-Aug-2004  skrll Sync with HEAD
 1.2.4.2 07-Jul-2001  perry b*()->mem*()
 1.2.4.1 07-Jul-2001  perry file bootinfo_memmap.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:58 +0000
 1.4.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.4.78.1 04-May-2009  yamt sync with head.
 1.4.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.70.2 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #1884):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.5.70.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.5.66.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.58.1 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.6.32.1 02-Aug-2025  perseant Sync with HEAD
 1.6.26.1 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #815):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.21 06-May-2025  pgoyette Allow the dev= command when processing /boot.cfg file. This
addresses kern/59207
 1.20 27-Nov-2024  martin Do not display the boot menu at all if (1) there is no choice and
(2) the timeout value is set to 0.
 1.19 09-Nov-2024  mlelstv Add 'fs' option for boot.cfg.
 1.18 08-Jun-2022  wiz branches: 1.18.10;
Remove now unused bootdefault() function.

Part of PR 56862.
 1.17 02-Apr-2018  nonaka efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.16 11-Jun-2016  dholland branches: 1.16.10; 1.16.16;
gets_s -> kgets.

The exact name isn't that important; but it is important not to use
"gets_s" and thereby allow anyone to falsely get the impression we're
implementing Annex K. We aren't.

ok core.
 1.15 05-Jun-2016  maxv Use gets_s instead of gets. The x86 bootloader prompt is easy to
overflow.
 1.14 10-Aug-2014  isaki branches: 1.14.4;
Unify all arch/*/stand's atoi() to MI libsa.
lib/libsa/atoi.c was separated from lib/libsa/bootcfg.c.
PR/49084
 1.13 28-Jun-2014  rtr patch posted to tech-kern@ 2014/06/25 for review with minor changes
resulting from feedback.

move multiple copies of code for parsing boot.cfg file from sparc, i386
and zaurus into libsa/bootcfg.{h,c}. largely retained i386 parsing logic
in addition to keeping sparc dispatch function while remaining consistent
with boot.cfg(5).

previous sparc64 file format has been obsoleted but only used by boot
CDs distrib/sparc64/bootfs/boot.cfg has been updated to compensate.

exported names have been prefixed with either BOOTCFG_ or bootcfg_ as per
feedback from christos@

tested on amd64 & sparc64 but not zaurus.
 1.12 06-Apr-2014  jakllsch Use __dead.
 1.11 28-Jul-2013  he branches: 1.11.2;
Two changes for the i386 boot loader related to the boot menu which
can be defined in boot.cfg:

* Add a "menu" command which re-displays the menu and initiates
the timed countdown
* Use any default command defined in boot.cfg as default args
if the user runs "boot" with no arguments

This is useful in circumstances where you e.g. need to interrupt
the normal boot process to switch to serial console, and where
simply "boot netbsd" is no longer sufficient (e.g. as with install
media which needs the miniroot kernel module loaded).
 1.10 18-Aug-2011  christos branches: 1.10.2; 1.10.8; 1.10.12; 1.10.16;
PR/43563: Wolfgang Solfrank: boot.cfg doesn't support comments
Fix makes it support # comments and treat spaces and tabs the same way.
 1.9 26-May-2011  uebayasi Support userconf(4) command in boot(8)/boot.cfg(5) on i386/amd64.

From jmmv@, no objections seen in the proposed thread:

http://mail-index.netbsd.org/tech-kern/2009/01/22/msg004081.html
 1.8 14-Sep-2009  jmcneill branches: 1.8.4; 1.8.6;
Don't treat timeouts or the return key as an invalid choice; spotted by
Andreas Gustafsson.
 1.7 13-Sep-2009  jmcneill If the menuformat is not letter, do not allow letter keys to be aliases
for number keys. snj@ often overshoots the spacebar in a panic and
accidentally hits 'b' instead, which makes the loader boot item '2'.
Can't fix snj@, so fix the boot loader instead.
 1.6 10-Apr-2009  perry branches: 1.6.2;
Check the size of the offered boot.cfg file. Bail out if it is larger
than 32k.

A bootconf file is normally only a few hundred bytes long. If it is
much bigger than expected, we can't load it into an 8086 real mode
segment anyway.

Much more to the point, in the pxeboot case, someone may have
configured their dhcpd to return the filename for the kernel, not
realizing that the filename is now for boot.cfg which didn't used to
be the case. If we try to load the kernel here, thinking it is
boot.cfg by accident, the boot loader will die ignominiously and
without much of an error message, so we don't want to do that.

This needs to be pulled up to 5.0 if 5.0 has all this machinery
-- I'm not sure whether it does.
 1.5 18-Mar-2009  cegger bzero -> memset
 1.4 14-Dec-2008  christos branches: 1.4.2; 1.4.4; 1.4.6;
more KNF and ANSI from Anon-ymous
 1.3 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.2 13-Dec-2008  christos add a boot.cfg option to clear the screen; default off. From Anon Ymous
 1.1 25-Nov-2008  ad branches: 1.1.4;
Make pxeboot understand boot.cfg.
 1.1.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.4.1 25-Nov-2008  haad file bootmenu.c was added on branch haad-dm on 2008-12-13 01:13:15 +0000
 1.4.6.3 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.4.6.2 01-Nov-2009  jym Sync with HEAD.
 1.4.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.4.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.4.4.1 14-Dec-2008  skrll file bootmenu.c was added on branch nick-hppapmap on 2009-01-19 13:16:21 +0000
 1.4.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.2.1 14-Dec-2008  mjf file bootmenu.c was added on branch mjf-devfs2 on 2009-01-17 13:28:05 +0000
 1.6.2.3 16-Sep-2009  yamt sync with head
 1.6.2.2 04-May-2009  yamt sync with head.
 1.6.2.1 10-Apr-2009  yamt file bootmenu.c was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.8.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.8.4.1 31-May-2011  rmind sync with head
 1.10.16.2 18-May-2014  rmind sync with head
 1.10.16.1 28-Aug-2013  rmind sync with head
 1.10.12.2 03-Dec-2017  jdolecek update from HEAD
 1.10.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.8.1 10-Aug-2013  riz Pull up following revision(s) (requested by he in ticket #925):
sys/arch/i386/stand/lib/bootmenu.c: revision 1.11
sys/arch/i386/stand/lib/bootmenu.h: revision 1.3
sys/arch/i386/stand/boot/boot2.c: revision 1.59
Two changes for the i386 boot loader related to the boot menu which
can be defined in boot.cfg:
* Add a "menu" command which re-displays the menu and initiates
the timed countdown
* Use any default command defined in boot.cfg as default args
if the user runs "boot" with no arguments
This is useful in circumstances where you e.g. need to interrupt
the normal boot process to switch to serial console, and where
simply "boot netbsd" is no longer sufficient (e.g. as with install
media which needs the miniroot kernel module loaded).
 1.10.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.1 10-Aug-2014  tls Rebase.
 1.14.4.1 09-Jul-2016  skrll Sync with HEAD
 1.16.16.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.16.10.1 04-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #692):

sys/arch/i386/stand/efiboot/devopen.c: revision 1.4
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.5
sys/arch/i386/stand/efiboot/devopen.h: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.3
sys/lib/libsa/bootcfg.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.9
sys/lib/libsa/bootcfg.c: revision 1.3
sys/arch/i386/stand/lib/bootmenu.c: revision 1.17
sys/arch/i386/stand/lib/biosdisk.c: revision 1.49
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.5
sys/arch/i386/stand/lib/bootmenu.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.h: revision 1.10

efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.18.10.1 02-Aug-2025  perseant Sync with HEAD
 1.7 08-Jun-2022  wiz Remove now unused bootdefault() function.

Part of PR 56862.
 1.6 02-Apr-2018  nonaka efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.5 10-Aug-2014  isaki branches: 1.5.20; 1.5.26;
Unify all arch/*/stand's atoi() to MI libsa.
lib/libsa/atoi.c was separated from lib/libsa/bootcfg.c.
PR/49084
 1.4 28-Jun-2014  rtr patch posted to tech-kern@ 2014/06/25 for review with minor changes
resulting from feedback.

move multiple copies of code for parsing boot.cfg file from sparc, i386
and zaurus into libsa/bootcfg.{h,c}. largely retained i386 parsing logic
in addition to keeping sparc dispatch function while remaining consistent
with boot.cfg(5).

previous sparc64 file format has been obsoleted but only used by boot
CDs distrib/sparc64/bootfs/boot.cfg has been updated to compensate.

exported names have been prefixed with either BOOTCFG_ or bootcfg_ as per
feedback from christos@

tested on amd64 & sparc64 but not zaurus.
 1.3 28-Jul-2013  he branches: 1.3.2;
Two changes for the i386 boot loader related to the boot menu which
can be defined in boot.cfg:

* Add a "menu" command which re-displays the menu and initiates
the timed countdown
* Use any default command defined in boot.cfg as default args
if the user runs "boot" with no arguments

This is useful in circumstances where you e.g. need to interrupt
the normal boot process to switch to serial console, and where
simply "boot netbsd" is no longer sufficient (e.g. as with install
media which needs the miniroot kernel module loaded).
 1.2 13-Dec-2008  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.20; 1.2.26; 1.2.30; 1.2.34;
add a boot.cfg option to clear the screen; default off. From Anon Ymous
 1.1 25-Nov-2008  ad branches: 1.1.4;
Make pxeboot understand boot.cfg.
 1.1.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.4.1 25-Nov-2008  haad file bootmenu.h was added on branch haad-dm on 2008-12-13 01:13:15 +0000
 1.2.34.1 28-Aug-2013  rmind sync with head
 1.2.30.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.26.1 10-Aug-2013  riz Pull up following revision(s) (requested by he in ticket #925):
sys/arch/i386/stand/lib/bootmenu.c: revision 1.11
sys/arch/i386/stand/lib/bootmenu.h: revision 1.3
sys/arch/i386/stand/boot/boot2.c: revision 1.59
Two changes for the i386 boot loader related to the boot menu which
can be defined in boot.cfg:
* Add a "menu" command which re-displays the menu and initiates
the timed countdown
* Use any default command defined in boot.cfg as default args
if the user runs "boot" with no arguments
This is useful in circumstances where you e.g. need to interrupt
the normal boot process to switch to serial console, and where
simply "boot netbsd" is no longer sufficient (e.g. as with install
media which needs the miniroot kernel module loaded).
 1.2.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.8.2 04-May-2009  yamt sync with head.
 1.2.8.1 13-Dec-2008  yamt file bootmenu.h was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 13-Dec-2008  skrll file bootmenu.h was added on branch nick-hppapmap on 2009-01-19 13:16:21 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 13-Dec-2008  mjf file bootmenu.h was added on branch mjf-devfs2 on 2009-01-17 13:28:05 +0000
 1.3.2.1 10-Aug-2014  tls Rebase.
 1.5.26.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.5.20.1 04-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #692):

sys/arch/i386/stand/efiboot/devopen.c: revision 1.4
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.5
sys/arch/i386/stand/efiboot/devopen.h: revision 1.2
sys/arch/i386/stand/efiboot/efidisk.h: revision 1.3
sys/lib/libsa/bootcfg.h: revision 1.2
sys/arch/i386/stand/efiboot/boot.c: revision 1.9
sys/lib/libsa/bootcfg.c: revision 1.3
sys/arch/i386/stand/lib/bootmenu.c: revision 1.17
sys/arch/i386/stand/lib/biosdisk.c: revision 1.49
sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.5
sys/arch/i386/stand/lib/bootmenu.h: revision 1.6
sys/arch/i386/stand/lib/biosdisk.h: revision 1.10

efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.
 1.6 30-Aug-2013  jmcneill Add support for using a raw file-system image as memory disk root with
the x86 bootloader.
 1.5 28-Nov-2011  tls branches: 1.5.8; 1.5.12;

Add support for passing saved entropy (random seed file) to the kernel
from the bootloader. This can fix the problem of poor quality keys
for other kernel modules which call arc4random() early in kernel startup
(NFS startup, in particular, causes this).

We continue to rely on the etc/rc.d/random_seed script to save entropy
to the seed file at shutdown and erase the seed file at startup.

Boot loader support implemented only for i386 and amd64 ports for now but
it should be easy for other ports to do the same or similar.
 1.4 06-Feb-2011  jmcneill branches: 1.4.4;
add support for passing image files to the kernel with the 'splash' keyword:

vesa on;splash /netbsd.jpg;boot -z
 1.3 05-May-2008  jmcneill branches: 1.3.4; 1.3.6; 1.3.8; 1.3.20; 1.3.28; 1.3.34; 1.3.36;
Use 2-clause license.
 1.2 03-May-2008  ad Handle compressed modules.
 1.1 02-May-2008  ad - Give x86 BIOS boot the ability to load new style modules and pass them
into the kernel. Based on a patch by jmcneill@, with many fixes and
improvements by me.
 1.3.36.1 08-Feb-2011  bouyer Sync with HEAD
 1.3.34.1 06-Jun-2011  jruoho Sync with HEAD.
 1.3.28.1 05-Mar-2011  rmind sync with head
 1.3.20.1 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.3.8.2 02-Jun-2008  mjf Sync with HEAD.
 1.3.8.1 05-May-2008  mjf file bootmod.h was added on branch mjf-devfs2 on 2008-06-02 13:22:19 +0000
 1.3.6.2 18-May-2008  yamt sync with head.
 1.3.6.1 05-May-2008  yamt file bootmod.h was added on branch yamt-pf42 on 2008-05-18 12:32:17 +0000
 1.3.4.2 16-May-2008  yamt sync with head.
 1.3.4.1 05-May-2008  yamt file bootmod.h was added on branch yamt-nfs-mp on 2008-05-16 02:22:39 +0000
 1.4.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.4.1 17-Apr-2012  yamt sync with head
 1.5.12.1 18-May-2014  rmind sync with head
 1.5.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4 16-Apr-2003  dsl remove unused defines
 1.3 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.2 27-Oct-1997  drochner Pass status byte to caller too.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.8;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.8.1 28-Oct-1997  mellon Pull rev. 1.2 up from trunk (drochner)
 1.12 05-Sep-2022  tsutsui G/C ISSET() macro copies. It has been defined in <sys/types.h> since 2006.
 1.11 05-Jan-2014  jakllsch don't shadow local variable
 1.10 14-Dec-2008  christos branches: 1.10.14; 1.10.24; 1.10.28;
more KNF and ANSI from Anon-ymous
 1.9 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.8 11-Nov-2005  dsl branches: 1.8.76; 1.8.80; 1.8.88;
Make a baud rate of zero cause the baud rate divisor be read and converted
to the current baud rate.
That way we use the same baud rate as the system BIOS (or whatever).
Rather useful for pxeboot.
 1.7 07-Aug-2003  agc branches: 1.7.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.6 27-Jul-2003  mrg #undef takes just a name, no params
 1.5 16-Apr-2003  dsl branches: 1.5.2;
Modify baud rate handling to make it easier to take it from a variable.
Default to 9600 if the requested baud rate is illegal.
 1.4 20-Jan-2000  drochner like com.c, raise DTR/RTS in console initialisation
 1.3 05-Jan-1998  perry branches: 1.3.8; 1.3.14;
RCSID Police.
 1.2 16-Oct-1997  mycroft dev/isa/comreg.h -> dev/ic/comreg.h
 1.1 17-Sep-1997  drochner branches: 1.1.2;
Console I/O functions for serial lines, accessing the hardware directly.
Allows higher baudrates than 9.6 and software flow control.
From Martin Husemann.
 1.1.2.3 16-Oct-1997  thorpej Sync w/ trunk.
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file comio_direct.c was added on branch marc-pcmcia on 1997-09-22 06:31:26 +0000
 1.3.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.8.1 24-Jan-2000  he Pull up revision 1.4 (requested by drochner):
Raise the serial carrier lines in console initialization, similar
to sys/dev/ic/com.c revision 1.165.
 1.5.2.4 11-Dec-2005  christos Sync with head.
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.16.1 21-Jun-2006  yamt sync with head.
 1.8.88.1 19-Jan-2009  skrll Sync with HEAD.
 1.8.80.1 04-May-2009  yamt sync with head.
 1.8.76.1 17-Jan-2009  mjf Sync with HEAD.
 1.10.28.1 18-May-2014  rmind sync with head
 1.10.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.14.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4 11-Nov-2005  dsl Make a baud rate of zero cause the baud rate divisor be read and converted
to the current baud rate.
That way we use the same baud rate as the system BIOS (or whatever).
Rather useful for pxeboot.
 1.3 16-Apr-2003  dsl branches: 1.3.2; 1.3.18;
Add baud_rate arg to cominit_d
 1.2 05-Jan-1998  perry RCSID Police.
 1.1 17-Sep-1997  drochner branches: 1.1.2;
Console I/O functions for serial lines, accessing the hardware directly.
Allows higher baudrates than 9.6 and software flow control.
From Martin Husemann.
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file comio_direct.h was added on branch marc-pcmcia on 1997-09-22 06:31:28 +0000
 1.3.18.1 21-Jun-2006  yamt sync with head.
 1.3.2.1 11-Dec-2005  christos Sync with head.
 1.7 16-Jun-2011  joerg Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.6 21-May-2008  ad branches: 1.6.12; 1.6.30;
- Stop the twiddler going awry.
- Clear screen if on a glass tty (!).
 1.5 11-Dec-2005  christos branches: 1.5.74; 1.5.76; 1.5.78; 1.5.80;
merge ktrace-lwp.
 1.4 06-Jul-2005  junyoung Remove unused #define.
 1.3 27-Jan-2005  mycroft branches: 1.3.6;
Make awaitkey() poll once even if the timeout is 0. This also fixes a problem
where a keypress within the last polling interval would not be noticed.
Add a new function, conisshift(), which is used to detect whether a shift key
is pressed. Use this via awaitkey() to allow interrupting the boot by holding
down shift (similar to LILO).

This allows setting the timeout to 0 and still being able to use the boot
program.
 1.2 01-Feb-2003  dsl branches: 1.2.2; 1.2.10; 1.2.12;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.12.1 12-Feb-2005  yamt sync with head.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.3.6.1 21-Jun-2006  yamt sync with head.
 1.5.80.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.78.1 04-May-2009  yamt sync with head.
 1.5.76.1 04-Jun-2008  yamt sync with head
 1.5.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.30.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6.12.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.4 08-Jun-2011  joerg G/C wbinvd
 1.3 22-Oct-2008  ad branches: 1.3.8; 1.3.16; 1.3.26;
+wbinvd
 1.2 28-Apr-2008  martin branches: 1.2.6;
Remove clause 3 and 4 from TNF licenses
 1.1 26-Sep-2007  ad branches: 1.1.2; 1.1.4; 1.1.6; 1.1.10; 1.1.14; 1.1.28; 1.1.30; 1.1.32;
- Make it compile again.
- Don't use (very dodgy) inline assembly.
 1.1.32.2 04-May-2009  yamt sync with head.
 1.1.32.1 16-May-2008  yamt sync with head.
 1.1.30.1 18-May-2008  yamt sync with head.
 1.1.28.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.28.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.14.2 06-Nov-2007  matt sync with HEAD
 1.1.14.1 26-Sep-2007  matt file cpufunc.S was added on branch matt-armv6 on 2007-11-06 23:17:52 +0000
 1.1.10.2 27-Oct-2007  yamt sync with head.
 1.1.10.1 26-Sep-2007  yamt file cpufunc.S was added on branch yamt-lazymbuf on 2007-10-27 11:26:52 +0000
 1.1.6.2 09-Oct-2007  ad Sync with head.
 1.1.6.1 26-Sep-2007  ad file cpufunc.S was added on branch vmlocking on 2007-10-09 13:38:01 +0000
 1.1.4.2 06-Oct-2007  yamt sync with head.
 1.1.4.1 26-Sep-2007  yamt file cpufunc.S was added on branch yamt-x86pmap on 2007-10-06 15:34:58 +0000
 1.1.2.2 02-Oct-2007  joerg Sync with HEAD.
 1.1.2.1 26-Sep-2007  joerg file cpufunc.S was added on branch jmcneill-pm on 2007-10-02 18:27:29 +0000
 1.2.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.26.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.3.16.1 12-Jun-2011  rmind sync with head
 1.3.8.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 26-Sep-2007  ad branches: 1.1.2; 1.1.4; 1.1.6; 1.1.10; 1.1.14; 1.1.28; 1.1.30; 1.1.32;
- Make it compile again.
- Don't use (very dodgy) inline assembly.
 1.1.32.1 16-May-2008  yamt sync with head.
 1.1.30.1 18-May-2008  yamt sync with head.
 1.1.28.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.14.2 06-Nov-2007  matt sync with HEAD
 1.1.14.1 26-Sep-2007  matt file cpufunc.h was added on branch matt-armv6 on 2007-11-06 23:17:52 +0000
 1.1.10.2 27-Oct-2007  yamt sync with head.
 1.1.10.1 26-Sep-2007  yamt file cpufunc.h was added on branch yamt-lazymbuf on 2007-10-27 11:26:52 +0000
 1.1.6.2 09-Oct-2007  ad Sync with head.
 1.1.6.1 26-Sep-2007  ad file cpufunc.h was added on branch vmlocking on 2007-10-09 13:38:01 +0000
 1.1.4.2 06-Oct-2007  yamt sync with head.
 1.1.4.1 26-Sep-2007  yamt file cpufunc.h was added on branch yamt-x86pmap on 2007-10-06 15:34:58 +0000
 1.1.2.2 02-Oct-2007  joerg Sync with HEAD.
 1.1.2.1 26-Sep-2007  joerg file cpufunc.h was added on branch jmcneill-pm on 2007-10-02 18:27:29 +0000
 1.7 24-Jan-2017  nonaka Initial commit of native amd64 EFI boot loader.
 1.6 11-Dec-2005  christos branches: 1.6.122; 1.6.142; 1.6.146; 1.6.150;
merge ktrace-lwp.
 1.5 28-Jun-2005  junyoung #include <lib/libsa/stand.h> rather than <stand.h> or "stand.h"
 1.4 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.3 02-Apr-2003  fvdl branches: 1.3.2;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.2 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.150.1 21-Apr-2017  bouyer Sync with HEAD
 1.6.146.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.142.1 05-Feb-2017  skrll Sync with HEAD
 1.6.122.1 03-Dec-2017  jdolecek update from HEAD
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 01-Feb-2003  dsl branches: 1.2.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7 29-Jun-2024  rin i386: stand: Migrate DOS support routines from `lib` to `dosboot`
 1.6 21-Nov-2009  dsl Preserve %ds over bios calls.
Not strickly necessary because real_to_prot doesn't normally rely on in.
However it caused much confusion while debugging, and does no harm.
 1.5 01-Feb-2003  dsl branches: 1.5.108; 1.5.122;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.4 22-Jan-1999  thorpej Fixup some usage of _C_LABEL().
 1.3 18-Aug-1997  hannken Change "it's" to "it is" inside assembler comments to
stop "unterminated character constant" messages from `mkdep'.
 1.2 13-Jun-1997  drochner branches: 1.2.4;
Fix operand size confusion in 16-bit code.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.122.1 24-Oct-2010  jym Sync with HEAD
 1.5.108.1 11-Mar-2010  yamt sync with head
 1.20 29-Jun-2024  rin i386: stand: Migrate DOS support routines from `lib` to `dosboot`
 1.19 13-Dec-2015  christos one default is better than two
 1.18 13-Dec-2015  christos better than returning random errors.
 1.17 11-Dec-2015  mlelstv PR 50516 bad switch statement.
Adding some comments.
 1.16 20-Oct-2013  christos branches: 1.16.6;
remove unused variable
 1.15 16-Jun-2011  joerg branches: 1.15.2; 1.15.12; 1.15.16;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.14 14-Dec-2008  christos branches: 1.14.2; 1.14.12;
ANSI and KNF from Anon Ymous
 1.13 10-May-2006  skrll branches: 1.13.62; 1.13.66; 1.13.74;
Fix a bunch of cast lvalues.
 1.12 25-Jan-2006  christos branches: 1.12.2; 1.12.4; 1.12.6; 1.12.8; 1.12.10;
free -> dealloc
unsigned -> size_t for alloc/dealloc
 1.11 11-Dec-2005  christos branches: 1.11.2;
merge ktrace-lwp.
 1.10 24-Mar-2004  drochner branches: 1.10.16;
remove license clauses 3 and 4 from my cpoyright notices
 1.9 31-Aug-2003  fvdl Fix signed/unsigned warnings.
 1.8 18-Aug-2003  dsl Further fallout from making 'path' arg to 'ufs_open' 'constchar *'.
There may be fallout in other builds....
 1.7 01-Feb-2003  dsl branches: 1.7.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.6 07-Jul-2001  perry branches: 1.6.4;
b*()->mem*()
 1.5 14-Apr-1999  drochner branches: 1.5.16;
add prototypes, slight formatting changes
 1.4 17-Sep-1997  drochner branches: 1.4.12;
Convert DOS error numbers into UNIX errno values.
 1.3 13-Jun-1997  drochner branches: 1.3.4;
Reformat comments. (messed up by "indent")
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.4.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.12.1 21-Jun-1999  thorpej Sync w/ -current.
 1.5.16.1 24-Aug-2001  nathanw Catch up with -current.
 1.6.4.2 07-Jul-2001  perry b*()->mem*()
 1.6.4.1 07-Jul-2001  perry file dosfile.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:58 +0000
 1.7.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.16.1 21-Jun-2006  yamt sync with head.
 1.11.2.1 01-Feb-2006  yamt sync with head.
 1.12.10.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.12.8.1 11-May-2006  elad sync with head
 1.12.6.1 24-May-2006  yamt sync with head.
 1.12.4.1 01-Jun-2006  kardel Sync with head.
 1.12.2.1 09-Sep-2006  rpaulo sync with head
 1.13.74.1 19-Jan-2009  skrll Sync with HEAD.
 1.13.66.1 04-May-2009  yamt sync with head.
 1.13.62.1 17-Jan-2009  mjf Sync with HEAD.
 1.14.12.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.14.2.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.15.16.1 18-May-2014  rmind sync with head
 1.15.12.2 03-Dec-2017  jdolecek update from HEAD
 1.15.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.6.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.5 29-Jun-2024  rin i386: stand: Migrate DOS support routines from `lib` to `dosboot`
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 18-Aug-2003  dsl Further fallout from making 'path' arg to 'ufs_open' 'constchar *'.
There may be fallout in other builds....
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.58;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.58.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.1.1.58.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.1.1.58.1 03-Aug-2004  skrll Sync with HEAD
 1.4 19-Nov-2009  dsl Shorten slightly
 1.3 11-Feb-2009  jnemeth PR/40608 - Gao Ya'nan -- typo in comment
 1.2 28-Apr-2008  martin branches: 1.2.8; 1.2.14;
Remove clause 3 and 4 from TNF licenses
 1.1 16-Apr-2003  dsl branches: 1.1.104; 1.1.106; 1.1.108;
additional support routines for boot code
 1.1.108.3 11-Mar-2010  yamt sync with head
 1.1.108.2 04-May-2009  yamt sync with head.
 1.1.108.1 16-May-2008  yamt sync with head.
 1.1.106.1 18-May-2008  yamt sync with head.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.14.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.2.14.2 01-Nov-2009  jym Sync with HEAD.
 1.2.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.81 11-Sep-2024  andvar dosboot(8): remove XMS-specific code. The boot process has been broken for over
a decade, and its relevance has diminished due to the availability of other boot
options.

PR port-i386/58624
 1.80 06-Jan-2024  mlelstv branches: 1.80.2;
In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
hard drives (with geom) and CD-ROM (without).
 1.79 20-Apr-2023  manu Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.
 1.78 21-Sep-2022  riastradh branches: 1.78.4;
i386/stand: Handle 9.99.100 by taking four, not two, digits.

We haven't used the revision part of __NetBSD_Version__ = MMmmrrpp00
in almos two decades so we're apparently reclaiming it as MMmmpppp00.
 1.77 30-May-2021  mlelstv Add "root" command to provide a BTINFO_ROOTDEVICE parameter.
 1.76 04-Apr-2020  christos branches: 1.76.8; 1.76.10;
Infrastructure for putting kernel+modules in /netbsd/kernel and
/netbsd/modules respectively instead of /netbsd and
/stand/<arch>/<version>/modules. This is only supported for x86,
and is turned off by default. To try it, add KERNEL_DIR=yes in your
/mk.conf and install a system from that build.
 1.75 07-Dec-2019  christos loadfile sets errno, return the correct error, not EIO.
 1.74 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.73 26-Jul-2019  nonaka branches: 1.73.2;
Pre-allocate memory for the kernel space at startup.
 1.72 24-Jun-2019  pgoyette Now that the ufs module has been split out from ffs and ext2fs, we need
to update the boot-loader to push all modules required to support the
booted filesystem. We treat the fsmod string as a slash-separated list
of module names (relative to kern.module.path), rather than as a single
module path name.

Note that ffsv1 and ffsv2 are still exempted from the boot-loader's
auto-push, but the list of required filesystems is still noted in the
source.

Also note that arch/sandpoint needs a similar change. I have not made
this change because I am totally unable to test it.

Tested on my kernel with _no_ built-in file-systems and with the ffs
bootloader settings of fsmod enabled.
 1.71 24-Jun-2019  pgoyette Remove double-include for reboot.h
 1.70 20-Jun-2019  maxv Add KASLR support in UEFI.
 1.69 07-Oct-2017  maxv branches: 1.69.4;
Add a new option in libsa, to load dynamic binaries. A separate function
is used, and it does not break in any way the generic static loader. Then,
add a new "pkboot" command in the x86 bootloader, which boots a
GENERIC_KASLR kernel via the prekern. (See thread on tech-kern@.)
 1.68 24-Mar-2017  nonaka branches: 1.68.6;
efiboot: fix calculation of the kernel size when loading modules.
 1.67 12-Mar-2017  nonaka efiboot: Kernel modules are loaded in pre-allocated memory.
 1.66 23-Feb-2017  nonaka no need COUNT_KERNEL hack.
 1.65 11-Feb-2017  nonaka PR/51953: fix unable to boot on some AMD machine.

Delayed the timing to copy the kernel to actual address.
copy routine from common/lib/libc/arch/x86_64/string/bcopy.S
 1.64 11-Feb-2017  nonaka efiboot: Copy bootinfo to safe arena.
 1.63 24-Jan-2017  nonaka Initial commit of native amd64 EFI boot loader.
 1.62 04-Dec-2016  maxv branches: 1.62.2;
KNF and explain a few things
 1.61 05-Jun-2016  maxv branches: 1.61.2;
Don't use a magic value. Define a limit, and enforce it.
 1.60 05-Jun-2016  maxv The bootinfo is refreshed each time the bootloader tries to execute a
kernel, so there's no point in using this global variable. Because of
this variable, only one "boot" command can be issued in the prompt, and
you have to reboot the machine if you mistyped the kernel name.
 1.59 06-Apr-2014  jakllsch branches: 1.59.4;
Misc WARNS=4 fixes.
 1.58 10-Jan-2014  jakllsch branches: 1.58.2;
fix style and whitespace nits
 1.57 05-Jan-2014  jakllsch Make name argument to module_add_common const; use this to allow the libsa
fsmod string to soon become const.
 1.56 30-Dec-2013  jakllsch Zero out on-stack 'marks' array before first use.
This is needed so the MARK_DATA index is properly filled in.
 1.55 27-Nov-2013  jakllsch Use the size of what's at the bootinfo_userconf pointer, not the size
of the pointer itself.
 1.54 24-Nov-2013  jakllsch The x86 kernel entry point stack arguments are always 32-bit, even on amd64.
 1.53 24-Nov-2013  jakllsch use <i386/multiboot.h> instead of <machine/multiboot.h> so this can be
compiled for amd64
 1.52 24-Nov-2013  jakllsch cast from 32-bit integer to void * though uintptr_t to avoid warnings
when compiling for x86_64.
 1.51 30-Aug-2013  jmcneill Add support for using a raw file-system image as memory disk root with
the x86 bootloader.
 1.50 21-May-2012  dsl branches: 1.50.2; 1.50.4;
Remove the code that tries to load the "ffs" kernel module during boot.
This is in line with the core decision than even modular kernels should
contain the ffs code.
I've left in the code that tries to load "nfs" and "ext2fs", but it
isn't clear that is necessary.
Removes a warning message that (usually) flashes past to fast to read.
AFAICT all the relevant kernels contain ffs (and nfs for that matter).
 1.49 28-Nov-2011  tls branches: 1.49.2; 1.49.4;

Add support for passing saved entropy (random seed file) to the kernel
from the bootloader. This can fix the problem of poor quality keys
for other kernel modules which call arc4random() early in kernel startup
(NFS startup, in particular, causes this).

We continue to rely on the etc/rc.d/random_seed script to save entropy
to the seed file at shutdown and erase the seed file at startup.

Boot loader support implemented only for i386 and amd64 ports for now but
it should be easy for other ports to do the same or similar.
 1.48 17-Jul-2011  joerg branches: 1.48.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.47 26-May-2011  uebayasi Support userconf(4) command in boot(8)/boot.cfg(5) on i386/amd64.

From jmmv@, no objections seen in the proposed thread:

http://mail-index.netbsd.org/tech-kern/2009/01/22/msg004081.html
 1.46 06-Feb-2011  jmcneill add support for passing image files to the kernel with the 'splash' keyword:

vesa on;splash /netbsd.jpg;boot -z
 1.45 30-Oct-2010  jnemeth branches: 1.45.2; 1.45.4;
Reduce licence with copyright Perry E. Metzger and Matthias Drochner
to two clauses.

On Thu, 21 Oct 2010 22:42:00 -0700 jnemeth@XXX
(John Nemeth) wrote:
> The file src/sys/arch/i386/stand/lib/exec.c has a licence
> section that starts off saying copyright by each of you. That is
> then followed by a standard four claus UCB licence. Would it be
> okay to reduce that to the two claus licence that is now standard
> for NetBSD?

I have no particular objections.

--
Perry E. Metzger perry@XXX

jnemeth@XXX said:
> Would it be okay to reduce that to the two claus licence

Yes of course, this is OK.

best regards
Matthias
 1.44 25-Aug-2010  christos use LOAD_BACKWARDS instead of LOAD_NOTE for floppy book.
 1.43 25-Jun-2010  tsutsui Add wait_sec() which uses BIOS function call INT 1Ah/AH=00h (GET SYSTEMTIME)
and use it for large delays (in seconds) instead of delay() that uses
INT 15h/AH=86h (WAIT) in microsecond because the latter one can't provide
precise delays on emulators.
Fixes PR port-i386/43156 (NetBSD bootloader countdown runs at 1/20 speed
in qemu 0.12).

No particular comments on the PR and port-i386@.
 1.42 14-Sep-2009  jmcneill branches: 1.42.2; 1.42.4;
Don't commit the selected VBE mode until the loader is past the point of
no return; need to stick in text mode as long as possible since libsa does
not include a rasops library. While here, add the 'vesa' command to pxeboot
to mirror biosboot behaviour.
 1.41 13-Sep-2009  jmcneill kmod improvements
- unless otherwise specified, modules are now loaded from the same device
as the kernel ('load miniroot' now implies 'load tftp:miniroot' if the
boot command is 'boot tftp:netbsd')
- the module name -> path expansion now works when a device prefix: is
specified ('load tftp:miniroot' now works)
- if the module name has been expanded to a path, print that path when
loading the module rather than the symbolic name
- only print an error in module_open if both the expanded path and the
raw path fail to open
 1.40 21-Mar-2009  ad Fix 'boot -z' bogons.
 1.39 16-Feb-2009  jmcneill Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.38 24-Jan-2009  rmind branches: 1.38.2;
Revert path of modules back to "/stand".
 1.37 24-Jan-2009  rmind Change path to kernel modules from "/stand" to "/kernel".
Needs to go in before 5.0. Proposed on <tech-kern>.
 1.36 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.35 25-Nov-2008  ad Make pxeboot understand boot.cfg.
 1.34 19-Nov-2008  ad For the x86 boot loader, autoload a kernel module corresponding to the
root file system type.
 1.33 11-Oct-2008  joerg branches: 1.33.2;
Add "multiboot" command to boot multiboot compliant kernels like Xen.
Patch provided by Robert Swindell with fixes for the command line
parsing and addition of passing module options from me. The kernel now
always gets the full string for modules like for the command line,
everything before the first space/tab is the path name of the module.
 1.32 08-Oct-2008  joerg Move functionality for preparing the kernel (including XMS support) into
a new function common_load_kernel.
 1.31 08-Oct-2008  joerg Move initialisation of boot_argv after the full loading of the kernel,
directly before loading modules.
 1.30 08-Oct-2008  joerg Setup module_base in module_init().
 1.29 26-Sep-2008  christos The structure of our elf kernel is:

elf header/program headers/text/data/note/
section headers/symbol table/string table

We need to read the section headers first to find the offset of the note
and thus we requite backwards seek. The only reason we need to read the
note is to find the version of the kernel, and this seems not to be used
anywhere. We could potentially change the kernel ldscript to add the note
information in the program headers, but dealing with ldscripts is painful
and producing a more complex binary could break some dumb standalone loader.
So the simple solution is to just disable the note loading for floppies
which is what this patch does. If someone wants to fix it in a better way,
be my guest.
 1.28 25-May-2008  chris branches: 1.28.4;
Fix pxeboot's load tftp:miniroot.i386.kmod to work again.

We now wrapper the open call for a module with module_open. It first
attempts to open the module_path munged path, if this fails it then tries
to open the original path.

This allows tftp files to be located correctly.
 1.27 20-May-2008  ad Take $MACHINE into account when looking for modules.
 1.26 20-May-2008  ad PR kern/38694 module dependencies do not work as expected

If a given module name/path does not start with '/', assume it's a module
name and choose a default path based on the kernel version.
 1.25 04-May-2008  martin branches: 1.25.2;
Remove my personal license, the TNF one is good enough for me.
 1.24 03-May-2008  ad Handle compressed modules.
 1.23 02-May-2008  ad - Give x86 BIOS boot the ability to load new style modules and pass them
into the kernel. Based on a patch by jmcneill@, with many fixes and
improvements by me.

- Put MEMORY_DISK_DYNAMIC and MODULAR into the GENERIC kernels, so that
you can load miniroot.kmod from the boot blocks and boot into the
installer!
 1.22 11-Dec-2005  christos branches: 1.22.74; 1.22.76; 1.22.78;
merge ktrace-lwp.
 1.21 21-Jun-2005  junyoung ANSI, KNF, trailing spaces, and etc.
 1.20 10-Nov-2003  wiz Spell address with two d's. Inspired by similar changes in OpenBSD,
originating from Jonathon Gray and forwarded by jmc@openbsd.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.18 27-Feb-2003  hannken branches: 1.18.2;
Change "i386_trunc_page" to "x86_trunc_page".
 1.17 01-Jun-2001  jdolecek branches: 1.17.2;
g/c COMPAT_OLDBOOT from bootblocks, sprinkle some const
bump bootblock version to 2.10
 1.16 19-May-2001  jdolecek Add some IBM PS/2 support bits:
* recognize PS/2 L40 via biosmca() and biosmca_ps2model in gatea20.c, instead
of being a compile time option
* if the system is PS/2 with MCA bus, map DTYPE_ESDI disks to ed(4) for
COMPAT_OLDBOOT

The new code is conditional on SUPPORT_PS2 define, which is on by default
for biosboot-based bootblocks.
 1.15 22-Feb-2000  dbj branches: 1.15.8;
use bios' idea of the basemem size and create the kernel stack
at the top of it instead of hard coding 0x90000
 1.14 07-Sep-1999  ross branches: 1.14.2;
spelling
 1.13 15-May-1999  drochner don't printf(NULL), not even in the DEBUG case
(It doesn't hurt the bootloader, but the junk output hangs my serial
console.)
 1.12 28-Apr-1999  christos use new loadfile
 1.11 14-Apr-1999  drochner add prototype
 1.10 08-Apr-1999  drochner Call bi_getbiosgeom() after loadfile() returned successfully. This avoids
a memory leak if loadfile() gets an error.
 1.9 08-Mar-1999  fvdl branches: 1.9.2;
* query BIOS geometry information, possibly using the int 13 extensions.
* pass them on to the kernel
* print a message if the 2nd stage bootloader returns (i.e. fails)
instead of just hanging.
 1.8 29-Jan-1999  christos Merge XMS changes from exec_fromdos.c
 1.7 28-Jan-1999  christos Add support for selectively loading sections, and make this compile in
userland with -DINSTALLBOOT
 1.6 28-Jan-1999  christos Remove a.out loading code and use loadfile.c for everything.
Populate the btinfo_symtab structure.
 1.5 28-Sep-1997  drochner Pass new boot information per default.
 1.4 17-Sep-1997  drochner Use the "bootinfo" defined structures to collect information about boot
device/file and console setting, remove the old, limited, "xbootinfo".
Fix a printf() format warning in debug code.
 1.3 22-Mar-1997  thorpej branches: 1.3.4;
Mimmick the old boot block's hdN -> Xd0 (where X is specified by the
disklabel type) unit conversion behavior.
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.4.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.4.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.1 09-Apr-1999  drochner branches: 1.9.2.1.2;
pull up rev. 1.10 - avoid memory leak if loadfile() fails
 1.9.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.14.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.17.2.2 01-Jun-2001  jdolecek g/c COMPAT_OLDBOOT from bootblocks, sprinkle some const
bump bootblock version to 2.10
 1.17.2.1 01-Jun-2001  jdolecek file exec.c was added on branch sommerfeld_i386mp_1 on 2001-06-01 23:26:32 +0000
 1.18.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 03-Aug-2004  skrll Sync with HEAD
 1.22.78.5 09-Oct-2010  yamt sync with head
 1.22.78.4 11-Aug-2010  yamt sync with head.
 1.22.78.3 16-Sep-2009  yamt sync with head
 1.22.78.2 04-May-2009  yamt sync with head.
 1.22.78.1 16-May-2008  yamt sync with head.
 1.22.76.2 04-Jun-2008  yamt sync with head
 1.22.76.1 18-May-2008  yamt sync with head.
 1.22.74.3 17-Jan-2009  mjf Sync with HEAD.
 1.22.74.2 28-Sep-2008  mjf Sync with HEAD.
 1.22.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.25.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.28.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.28.4.1 19-Oct-2008  haad Sync with HEAD.
 1.33.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.33.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.33.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.38.2.5 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.38.2.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.38.2.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.38.2.2 01-Nov-2009  jym Sync with HEAD.
 1.38.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.42.4.3 31-May-2011  rmind sync with head
 1.42.4.2 05-Mar-2011  rmind sync with head
 1.42.4.1 03-Jul-2010  rmind sync with head
 1.42.2.3 06-Nov-2010  uebayasi Sync with HEAD.
 1.42.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.42.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.45.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.45.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.48.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.48.2.2 23-May-2012  yamt sync with head.
 1.48.2.1 17-Apr-2012  yamt sync with head
 1.49.4.1 03-Jun-2012  jdc Pull up revisions:
src/sys/arch/i386/stand/lib/exec.c revision 1.50
src/sys/arch/sandpoint/stand/altboot/main.c revision 1.21 via patch
src/sys/lib/libsa/ext2fs.c revision 1.13
src/sys/lib/libsa/ffsv1.c revision 1.6
src/sys/lib/libsa/ffsv2.c revision 1.6
src/sys/lib/libsa/globals.c revision 1.9
src/sys/lib/libsa/lfsv1.c revision 1.5
src/sys/lib/libsa/lfsv2.c revision 1.5
src/sys/lib/libsa/stand.h revision 1.76
src/sys/lib/libsa/ufs.c revision 1.58
(requested by dsl in ticket #279).

Remove the code that tries to load the "ffs" kernel module during boot.
This is in line with the core decision than even modular kernels should
contain the ffs code.
I've left in the code that tries to load "nfs" and "ext2fs", but it
isn't clear that is necessary.
Removes a warning message that (usually) flashes past to fast to read.
AFAICT all the relevant kernels contain ffs (and nfs for that matter).
 1.49.2.1 02-Jun-2012  mrg sync to latest -current.
 1.50.4.1 18-May-2014  rmind sync with head
 1.50.2.2 03-Dec-2017  jdolecek update from HEAD
 1.50.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.58.2.1 10-Aug-2014  tls Rebase.
 1.59.4.4 28-Aug-2017  skrll Sync with HEAD
 1.59.4.3 05-Feb-2017  skrll Sync with HEAD
 1.59.4.2 05-Dec-2016  skrll Sync with HEAD
 1.59.4.1 09-Jul-2016  skrll Sync with HEAD
 1.61.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.61.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.61.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.62.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.68.6.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.68.6.1 01-Aug-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1309):

sys/arch/i386/stand/lib/exec.c: revision 1.73
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.10
sys/arch/i386/stand/lib/libi386.h: revision 1.44
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.6
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.7
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.12
sys/arch/i386/stand/efiboot/boot.c: revision 1.13
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.9
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.15
sys/arch/i386/stand/efiboot/dev_net.c: revision 1.2

Added tftp support to x86 efiboot.

Pre-allocate memory for the kernel space at startup.

Added BTINFO_EFIMEMMAP compaction support to x86 efiboot.

Sync the output of memmap command to the output of stand/efiboot mem command.

Added missing efi_memory_probe() call.
 1.69.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.69.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.73.2.2 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #1632):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28 (via patch)
share/man/man8/man8.x86/boot.8: revision 1.29 (via patch)
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.

Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.

Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.73.2.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.76.10.1 31-May-2021  cjep sync with head
 1.76.8.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.78.4.2 14-Jan-2024  martin Pull up following revision(s) (requested by mlelstv in ticket #548):

sys/arch/i386/stand/efiboot/efidisk.h: revision 1.4
sys/arch/i386/stand/lib/exec.c: revision 1.80
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.11
sys/arch/i386/stand/lib/biosdisk.c: revision 1.61

In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
hard drives (with geom) and CD-ROM (without).
 1.78.4.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #159):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28
share/man/man8/man8.x86/boot.8: revision 1.29
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.


Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.


Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.80.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 29-Jan-1999  christos exec.c has all the info now.
 1.6 03-Nov-1997  drochner When using XMS, use the XMS size returned by the BIOS only if the other
methods to detect extended memory didn't work well.
(this XMS size is always too small, typically by 68k)
 1.5 28-Sep-1997  drochner Pass new boot information per default.
 1.4 17-Sep-1997  drochner Use the "bootinfo" defined structures to collect information about boot
device/file and console setting, remove the old, limited, "xbootinfo".
Fix a printf() format warning in debug code.
 1.3 14-Aug-1997  drochner Use traditional memory detect function (int15/88) as indication for
a XMS driver.
From Martin Husemann.
 1.2 05-Aug-1997  drochner #if -> #ifdef, fixes XMS support
from Martin Husemann, pr port-i386/3941
 1.1 13-Jun-1997  drochner branches: 1.1.4;
Allow to boot from DOS if a XMS manager is installed.
XMS is recognized and used as temporary buffer for the kernel image.
The processor must still be in real mode at program start, so EMM386
or QEMM are not allowed. W*95 is OK.
Written by Martin Husemann (pr port-i386/3336).
Completely separated from other bootloaders for sanity.
 1.1.4.3 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.4.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3 18-Oct-2019  manu branches: 1.3.8;
Add kernel symbols for multiboot1
 1.2 18-Oct-2019  manu Fix multiboot1 header detection

Specification states it must be must be longword (32-bit) aligned
 1.1 13-Sep-2019  manu branches: 1.1.2; 1.1.4;
Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.1.4.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.1.4.1 13-Sep-2019  martin file exec_multiboot1.c was added on branch netbsd-8 on 2019-09-18 17:30:05 +0000
 1.1.2.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.1.2.1 13-Sep-2019  martin file exec_multiboot1.c was added on branch netbsd-9 on 2019-09-17 19:32:00 +0000
 1.3.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.8.1 18-Oct-2019  martin file exec_multiboot1.c was added on branch phil-wifi on 2020-04-13 08:03:54 +0000
 1.8 28-Jun-2025  joe fix missing break in multiboot header tag
 1.7 23-Jun-2025  joe clear whitespace
 1.6 04-Aug-2023  rin branches: 1.6.6;
x86/multiboot2: Fix short read for 64-bit ELF headers

XXX document this
At the moment, this cannot affect NetBSD/amd64, as we have not
supported multiboot for kernel side.

Found by GCC12.
 1.5 21-Jul-2021  jmcneill Separate MI smbios interface from MD specific code.
 1.4 14-May-2020  msaitoh branches: 1.4.6;
Remove extra semicolon.
 1.3 18-Oct-2019  manu branches: 1.3.8;
Fix kernel symbols for multiboot2

Previous version just provided the ELF section table, which is correct
as far as the multiboot 2 specification is concerned.

But in order to retreive kernel symboles, the NetBSD kernelneeds symbol
table and string table sections to be loaded in memory, and have an
address set in the section table.

Requires change: Add kernel symbols for multiboot1
src/sys/arch/i386/stand/lib/exec_multiboot1.c 1.2 - 1.3
src/sys/arch/i386/stand/lib/libi386.h 1.45 - 1.46
 1.2 15-Sep-2019  manu branches: 1.2.2; 1.2.4;
Remove debug define.

It remained there unseen because it was misspelled!
 1.1 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.2.4.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.2.4.1 15-Sep-2019  martin file exec_multiboot2.c was added on branch netbsd-8 on 2019-09-18 17:30:05 +0000
 1.2.2.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.2.2.1 15-Sep-2019  martin file exec_multiboot2.c was added on branch netbsd-9 on 2019-09-17 19:32:00 +0000
 1.3.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.8.1 18-Oct-2019  martin file exec_multiboot2.c was added on branch phil-wifi on 2020-04-13 08:03:54 +0000
 1.4.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.6.6.1 02-Aug-2025  perseant Sync with HEAD
 1.12 23-Aug-2009  jmcneill PR# kern/39726: Soekris 5501-60 boot/bootxx 120 second delay
PR# port-i386/41162: A20 gate legacy hook cause long pxeboot delay on Soekris net5501

Remove calls to delay() before polling KBD registers in gateA20().
 1.11 14-Oct-2008  ad branches: 1.11.4; 1.11.8;
PR kern/39726 Soekris 5501-60 boot/bootxx 120 second delay

Try enabling A20 using an extended BIOS call before playing around with
the keyboard controller or system config port.
 1.10 17-Oct-2007  garbled branches: 1.10.16; 1.10.20; 1.10.26;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.9 26-Sep-2007  ad - Make it compile again.
- Don't use (very dodgy) inline assembly.
 1.8 11-Dec-2005  christos branches: 1.8.30; 1.8.38; 1.8.48; 1.8.50; 1.8.52;
merge ktrace-lwp.
 1.7 29-Jun-2005  junyoung branches: 1.7.2;
KNF.
 1.6 24-Jun-2005  manu Support PC engines WRAP (From OpenBSD)
 1.5 12-Aug-2002  thorpej branches: 1.5.2; 1.5.8; 1.5.22;
There are other systems besides the PS/2 L40 that enable A20
via the Configuration Port, so restructure the code a little
to allow for them, and list at least one other system that does
(anything based on AMD Elan SC520).

XXX We don't actually check for Elan SC520 yet.
 1.4 19-May-2001  jdolecek branches: 1.4.4; 1.4.16; 1.4.18;
Add some IBM PS/2 support bits:
* recognize PS/2 L40 via biosmca() and biosmca_ps2model in gatea20.c, instead
of being a compile time option
* if the system is PS/2 with MCA bus, map DTYPE_ESDI disks to ed(4) for
COMPAT_OLDBOOT

The new code is conditional on SUPPORT_PS2 define, which is on by default
for biosboot-based bootblocks.
 1.3 11-May-2000  jdolecek branches: 1.3.8;
minor adjustment for compiling with IBM_L40
 1.2 29-Oct-1997  fvdl branches: 1.2.14;
Disable interrupts when frobbing the keyboard controller for A20, as
it may generate a reset on some (older) controllers. Introduce a delay
to make some kbd controllers happier.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.8.2 13-Aug-2002  nathanw Catch up to -current.
 1.3.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.18.1 18-Nov-2002  he Pull up revision 1.5 (requested by thorpej in ticket #665):
There are other systems besides the PS/2 L40 that enable
A20 via the Configuration Port, so restructure the code a
little to allow for them, and list at least one other system
that does (anything based on the AMD Elan SC520).
 1.4.16.1 31-Aug-2002  gehenna catch up with -current.
 1.4.4.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.5.22.1 02-Jul-2005  tron Pull up revision 1.6 (requested by manu in ticket #504):
Support PC engines WRAP (From OpenBSD)
 1.5.8.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.2 12-Aug-2002  thorpej There are other systems besides the PS/2 L40 that enable A20
via the Configuration Port, so restructure the code a little
to allow for them, and list at least one other system that does
(anything based on AMD Elan SC520).

XXX We don't actually check for Elan SC520 yet.
 1.5.2.1 12-Aug-2002  thorpej file gatea20.c was added on branch sommerfeld_i386mp_1 on 2002-08-12 14:27:35 +0000
 1.7.2.1 27-Oct-2007  yamt sync with head.
 1.8.52.1 06-Oct-2007  yamt sync with head.
 1.8.50.1 06-Nov-2007  matt sync with HEAD
 1.8.48.1 02-Oct-2007  joerg Sync with HEAD.
 1.8.38.1 03-Oct-2007  garbled Sync with HEAD
 1.8.30.1 09-Oct-2007  ad Sync with head.
 1.10.26.1 19-Oct-2008  haad Sync with HEAD.
 1.10.20.2 16-Sep-2009  yamt sync with head
 1.10.20.1 04-May-2009  yamt sync with head.
 1.10.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.11.8.1 01-Nov-2009  jym Sync with HEAD.
 1.11.4.1 16-Oct-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #923):
sys/arch/i386/stand/lib/gatea20.c: revision 1.12
PR# kern/39726: Soekris 5501-60 boot/bootxx 120 second delay
PR# port-i386/41162: A20 gate legacy hook cause long pxeboot delay on Soekris
net5501
Remove calls to delay() before polling KBD registers in gateA20().
 1.12 24-Aug-2024  riastradh i386/stand/lib: Nix trailing whitespace and tidy comments a bit.

No functional change intended.

PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.11 17-Aug-2024  andvar Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().
This in turn was leading to erroneous caluclations and memory addresses.
This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.

needs-pullups to 9, 10.

PR install/49470
 1.10 16-Jun-2011  joerg branches: 1.10.58; 1.10.84; 1.10.90;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.9 14-Dec-2008  christos branches: 1.9.2; 1.9.12;
ANSI and KNF from Anon Ymous
 1.8 25-Dec-2007  perry branches: 1.8.6; 1.8.10; 1.8.18;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.7 11-Dec-2005  christos branches: 1.7.50; 1.7.56; 1.7.60; 1.7.64;
merge ktrace-lwp.
 1.6 24-Mar-2004  drochner branches: 1.6.16;
remove license clauses 3 and 4 from my cpoyright notices
 1.5 07-Nov-2003  dsl Adjust location of 'extmem2' diagnostic print.
 1.4 16-Apr-2003  dsl branches: 1.4.2;
Add some debug prints to the memory size code
 1.3 23-Jan-2003  jdolecek add another memory size detection routine, using int15, function 0xc7, which
is supported on later IBM PS/2 models; this is necessary to detect memory
over 64MB
thanks go to Pavel Cahyna for testing on his IBM PS/2 machine with 128MB

bump biosboot version to 2.15
 1.2 08-Mar-1999  drochner change the interface for getmementry() to hold the iterator in an
argument and to return success or error explicitely.
Now we can "error" and "end of list" cleanly; this should fix the
problem where the last list element was ignored.
 1.1 14-Aug-1997  drochner branches: 1.1.2;
New, optional, method to get size of extended memory.
It will be used for getextmem() if EXTENDED_MEMDETECT is defined.
Worked on all tested machines.
Thanks to all testers, especially Martin Husemann!
 1.1.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 14-Aug-1997  thorpej file getextmemx.c was added on branch marc-pcmcia on 1997-08-23 07:09:40 +0000
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.1 21-Jan-2008  yamt sync with head
 1.7.64.1 02-Jan-2008  bouyer Sync with HEAD
 1.7.60.1 26-Dec-2007  ad Sync with head.
 1.7.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.7.50.1 09-Jan-2008  matt sync with HEAD
 1.8.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.8.10.1 04-May-2009  yamt sync with head.
 1.8.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.9.12.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.9.2.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.10.90.1 02-Aug-2025  perseant Sync with HEAD
 1.10.84.1 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #815):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.10.58.1 03-Sep-2024  martin Pull up following revision(s) (requested by andvar in ticket #1884):

sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.7
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.8
sys/arch/i386/stand/lib/getextmemx.c: revision 1.11
sys/arch/i386/stand/lib/getextmemx.c: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.12
sys/arch/i386/stand/lib/biosmemx.S: revision 1.13

Allocate buf[6] instead of buf[5] to work around buggy firmware, which may
write mementry to 24 bytes instead 20 requested with ACPI 3.0 enabled,
causing corrupted stack and wrong marks[] values in common_load_kernel().

This in turn was leading to erroneous caluclations and memory addresses.

This eventually may result in null pointer dereference in the kernel and sudden
reboot for VIA based systems.

Commit should fix boot issues for VIA C7-M based HP 2133 Mini-Note,
mentioned in the original bug report. For AMD based HP Compaq 6005 Pro
discussed in a separate thread, the issue may be different.

Tested on my VIA C7-D based Biostar Viotech 3100+ motherboard.
PR install/49470

i386/stand/lib: Nix trailing whitespace and tidy comments a bit.
No functional change intended.
PR port-amd64/49470: NetBSD 7 BETA reboots after bootloader (HP 2133)
 1.4 12-Jan-2009  tsutsui Replace time_t values in libsa sources with the following two types
to avoid unnecessary 64 bit ops which would make binaries larger:

satime_t (currently unsigned int):
numbers in seconds returned by the machine dependent getsecs() function
which are used to measure relative time

saseconds_t (currently int):
numbers in seconds used to specify timeout to network drivers

Per discussion on current-users.
 1.3 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.2 14-Apr-1999  drochner branches: 1.2.140; 1.2.144; 1.2.152;
add prototypes, slight formatting changes
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.18;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.18.1 21-Jun-1999  thorpej Sync w/ -current.
 1.2.152.1 19-Jan-2009  skrll Sync with HEAD.
 1.2.144.1 04-May-2009  yamt sync with head.
 1.2.140.1 17-Jan-2009  mjf Sync with HEAD.
 1.3 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.2 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.160; 1.1.1.1.164; 1.1.1.1.172;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.172.1 19-Jan-2009  skrll Sync with HEAD.
 1.1.1.1.164.1 04-May-2009  yamt sync with head.
 1.1.1.1.160.1 17-Jan-2009  mjf Sync with HEAD.
 1.3 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.2 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.160; 1.1.1.1.164; 1.1.1.1.172;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.172.1 19-Jan-2009  skrll Sync with HEAD.
 1.1.1.1.164.1 04-May-2009  yamt sync with head.
 1.1.1.1.160.1 17-Jan-2009  mjf Sync with HEAD.
 1.6 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.5 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.78; 1.4.86;
merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 22-Mar-1997  thorpej branches: 1.2.58;
Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.58.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.58.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.58.1 03-Aug-2004  skrll Sync with HEAD
 1.4.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.4.78.1 04-May-2009  yamt sync with head.
 1.4.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.5 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.4 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.78; 1.3.86;
merge ktrace-lwp.
 1.2 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.58;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.58.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.1.1.58.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.1.1.58.1 03-Aug-2004  skrll Sync with HEAD
 1.3.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.78.1 04-May-2009  yamt sync with head.
 1.3.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.56 09-Oct-2025  manu Add support for USB-to-serial adapter in UEFI bootstrap.

This change lets UEFI bootstrap use any UEFI supported serial port.
com0 to com3 remain used for EISA based serial ports. com4 and over
are used for serial ports based on something else (USB, PCI or whatever).

Support for non-EISA serial ports may be provided by UEFI. An open
source UEFI driver exists for FTDI FT232R USB-to-serial adapter.

The change also introduce the kconsdev command, to select the kernel
console device without altering the bootstrap console device. This
useful because the device names can differ in bootstrap and kernel.
For instance an USB-to-serial device could be com4 in boostrap and
ucom0 for the kernel.

An upcoming change will add console suport to ucom(4).
 1.55 06-May-2025  pgoyette Allow the dev= command when processing /boot.cfg file. This
addresses kern/59207
 1.54 18-Sep-2024  rin i386/stand: Remove XMS leftover from libi386.h, NFC

PR port-i386/58624
 1.53 29-Jun-2024  rin branches: 1.53.2;
i386: stand: Adjust for DOS-routine migration
 1.52 29-Jun-2024  rin libi386.h: Drop `I386_INCLUDE_BUS` support

This is what I intended for this commit:

https://mail-index.netbsd.org/source-changes/2024/06/29/msg151996.html

Instead, I removed libi386.h by mistake :(
 1.51 29-Jun-2024  rin libi386.h: Restore rev 1.48
 1.50 29-Jun-2024  rin i386: stand: Restore libi386.h,v 1.47, which I removed accidentally
 1.49 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.48 29-Jun-2024  rin i386: stand: G/C unused `printmemlist`, NFC
 1.47 18-Oct-2019  manu Remove prototype added twice by mistake
 1.46 18-Oct-2019  manu Add kernel symbols for multiboot1
 1.45 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.44 26-Jul-2019  nonaka branches: 1.44.2;
Pre-allocate memory for the kernel space at startup.
 1.43 24-Jun-2019  pgoyette Now that the ufs module has been split out from ffs and ext2fs, we need
to update the boot-loader to push all modules required to support the
booted filesystem. We treat the fsmod string as a slash-separated list
of module names (relative to kern.module.path), rather than as a single
module path name.

Note that ffsv1 and ffsv2 are still exempted from the boot-loader's
auto-push, but the list of required filesystems is still noted in the
source.

Also note that arch/sandpoint needs a similar change. I have not made
this change because I am totally unable to test it.

Tested on my kernel with _no_ built-in file-systems and with the ffs
bootloader settings of fsmod enabled.
 1.42 12-Mar-2017  nonaka branches: 1.42.6; 1.42.14;
efiboot: Kernel modules are loaded in pre-allocated memory.
 1.41 24-Jan-2017  nonaka Initial commit of native amd64 EFI boot loader.
 1.40 24-Nov-2013  jakllsch branches: 1.40.6; 1.40.10; 1.40.14;
The x86 kernel entry point stack arguments are always 32-bit, even on amd64.
 1.39 30-Aug-2013  jmcneill Add support for using a raw file-system image as memory disk root with
the x86 bootloader.
 1.38 28-Nov-2011  tls branches: 1.38.8; 1.38.12;

Add support for passing saved entropy (random seed file) to the kernel
from the bootloader. This can fix the problem of poor quality keys
for other kernel modules which call arc4random() early in kernel startup
(NFS startup, in particular, causes this).

We continue to rely on the etc/rc.d/random_seed script to save entropy
to the seed file at shutdown and erase the seed file at startup.

Boot loader support implemented only for i386 and amd64 ports for now but
it should be easy for other ports to do the same or similar.
 1.37 16-Jun-2011  joerg branches: 1.37.2;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.36 26-May-2011  uebayasi branches: 1.36.2;
Support userconf(4) command in boot(8)/boot.cfg(5) on i386/amd64.

From jmmv@, no objections seen in the proposed thread:

http://mail-index.netbsd.org/tech-kern/2009/01/22/msg004081.html
 1.35 21-Feb-2011  dyoung biosdisk_getextinfo() returns 0 on success, non-zero on failure, so
change its return type from void to int.
 1.34 06-Feb-2011  jmcneill add support for passing image files to the kernel with the 'splash' keyword:

vesa on;splash /netbsd.jpg;boot -z
 1.33 25-Jun-2010  tsutsui branches: 1.33.2; 1.33.4;
Add wait_sec() which uses BIOS function call INT 1Ah/AH=00h (GET SYSTEMTIME)
and use it for large delays (in seconds) instead of delay() that uses
INT 15h/AH=86h (WAIT) in microsecond because the latter one can't provide
precise delays on emulators.
Fixes PR port-i386/43156 (NetBSD bootloader countdown runs at 1/20 speed
in qemu 0.12).

No particular comments on the PR and port-i386@.
 1.32 13-Sep-2009  jmcneill branches: 1.32.2; 1.32.4;
Make the 'dev' command print out a list of known boot devices based on
information from the BIOS in addition to the currently selected default
partition. Handy when you don't know where to boot from. Here's a demo:

type "?" or "help" for help.
> dev
disk hd0 size 3815 MB
hd0a(4.2BSD) hd0b(swap)
disk cd0
cd0a(unknown)
default hd0a
>
 1.31 21-Mar-2009  ad Fix 'boot -z' bogons.
 1.30 16-Feb-2009  jmcneill Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.29 12-Jan-2009  tsutsui branches: 1.29.2;
Replace time_t values in libsa sources with the following two types
to avoid unnecessary 64 bit ops which would make binaries larger:

satime_t (currently unsigned int):
numbers in seconds returned by the machine dependent getsecs() function
which are used to measure relative time

saseconds_t (currently int):
numbers in seconds used to specify timeout to network drivers

Per discussion on current-users.
 1.28 13-Dec-2008  christos add a boot.cfg option to clear the screen; default off. From Anon Ymous
 1.27 19-Nov-2008  ad For the x86 boot loader, autoload a kernel module corresponding to the
root file system type.
 1.26 11-Oct-2008  joerg branches: 1.26.2;
Add "multiboot" command to boot multiboot compliant kernels like Xen.
Patch provided by Robert Swindell with fixes for the command line
parsing and addition of passing module options from me. The kernel now
always gets the full string for modules like for the command line,
everything before the first space/tab is the path name of the module.
 1.25 26-Sep-2008  christos The structure of our elf kernel is:

elf header/program headers/text/data/note/
section headers/symbol table/string table

We need to read the section headers first to find the offset of the note
and thus we requite backwards seek. The only reason we need to read the
note is to find the version of the kernel, and this seems not to be used
anywhere. We could potentially change the kernel ldscript to add the note
information in the program headers, but dealing with ldscripts is painful
and producing a more complex binary could break some dumb standalone loader.
So the simple solution is to just disable the note loading for floppies
which is what this patch does. If someone wants to fix it in a better way,
be my guest.
 1.24 21-May-2008  ad branches: 1.24.4;
- Stop the twiddler going awry.
- Clear screen if on a glass tty (!).
 1.23 11-Dec-2005  christos branches: 1.23.74; 1.23.76; 1.23.78; 1.23.80;
merge ktrace-lwp.
 1.22 29-Jun-2005  junyoung Massive renames for consistency:
biosdiskreset -> biosdisk_reset
biosread -> biosdisk_read
get_diskinfo -> biosdisk_getinfo
int13_extension -> biosdisk_int13ext
biosextread -> biosdisk_extread
int13_getextinfo -> biosdisk_getextinfo
struct biosdisk_ext13info -> biosdisk_extinfo
BIOSDISK_EXT13 -> BIOSDISK_INT13EXT
BIOSDISK_EXT13INFO_V{2,3} -> BIOSDISK_EXTINFO_V{2,3}
EXT13_* -> EXTINFO_*
 1.21 22-Jun-2005  dyoung Cosmetic: join line.
 1.20 22-Jun-2005  junyoung Add support for cd9660 file system to the i386 BIOS bootloader.
 1.19 13-Jun-2005  junyoung Cosmetic changes.
 1.18 27-Jan-2005  mycroft Make awaitkey() poll once even if the timeout is 0. This also fixes a problem
where a keypress within the last polling interval would not be noticed.
Add a new function, conisshift(), which is used to detect whether a shift key
is pressed. Use this via awaitkey() to allow interrupting the boot by holding
down shift (similar to LILO).

This allows setting the timeout to 0 and still being able to use the boot
program.
 1.17 23-Aug-2004  junyoung branches: 1.17.4; 1.17.6;
* Nuke __P().
* No need to use 'extern' for function prototypes.
 1.16 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.15 16-Apr-2003  dsl branches: 1.15.2;
Add prototyps for all the asm bios/dos calls
 1.14 01-Jun-2001  jdolecek branches: 1.14.2;
g/c COMPAT_OLDBOOT from bootblocks, sprinkle some const
bump bootblock version to 2.10
 1.13 24-Sep-2000  jdolecek branches: 1.13.4;
add new macro BOOT_FLAG() (defined in <sys/boot_flag.h>) - this
maps standard boot flags to corresponding RB_* values
use BOOT_FLAG() in port's MD code as appropriate

as discussed on tech-kern, add new boot flags -v, -q for booting
verbosely or quietly, and corresponding AB_VERBOSE/AB_QUIET
boot flags; also add FreeBSD-compatible bootverbose macro and
NetBSD-specific bootquiet macro

for hpcmips, use new bootverbose instead of it's own hpcmips_verbose

Tested on i386, and to limited extend (compile of affected files) also for
mvme68k, hp300, luna68k, sun3.
 1.12 31-Aug-2000  jdolecek constify first arg to parseopts()
 1.11 23-Apr-2000  tsarna Addredd port-i386/9897, but differently. Since the effect of resetting
the video mode on machines with ancient or no video cards is not clear,
for safety's sake a I created a new biosboot variant, biosboot_resetvideo
that does the call.

Anyway, now I can boot my i-opener without hitting Tab. Thanks Andrew!
 1.10 21-Dec-1999  drochner add a function which prints out the memory descriptors (for debugging)
 1.9 14-Apr-1999  christos branches: 1.9.2; 1.9.8;
Add prototype for getsecs
 1.8 28-Jan-1999  christos branches: 1.8.4;
Minor changes to prototypes.
 1.7 13-Aug-1998  rvb Make serial line debugging easier to enable and use
 1.6 17-Sep-1997  drochner Add now common menu / parsing functions.
Adapt to new console I/O functionality.
Update exec() arguments.
 1.5 14-Aug-1997  drochner Make new memory detection default.
Introduce a new option, "CONSERVATIVE_MEMDETECT", which disables the
new BIOS calls.
 1.4 14-Aug-1997  drochner New, optional, method to get size of extended memory.
It will be used for getextmem() if EXTENDED_MEMDETECT is defined.
Worked on all tested machines.
Thanks to all testers, especially Martin Husemann!
 1.3 13-Jun-1997  drochner branches: 1.3.4;
Allow to boot from DOS if a XMS manager is installed.
XMS is recognized and used as temporary buffer for the kernel image.
The processor must still be in real mode at program start, so EMM386
or QEMM are not allowed. W*95 is OK.
Written by Martin Husemann (pr port-i386/3336).
Completely separated from other bootloaders for sanity.
 1.2 13-Apr-1997  perry 1) Make carriage return start boot immediately.
2) Make "quit" reboot machine. This works by adding a reboot assembler
hook that calls INT 19h
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.4.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.8.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.9.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.14.2.2 01-Jun-2001  jdolecek g/c COMPAT_OLDBOOT from bootblocks, sprinkle some const
bump bootblock version to 2.10
 1.14.2.1 01-Jun-2001  jdolecek file libi386.h was added on branch sommerfeld_i386mp_1 on 2001-06-01 23:26:32 +0000
 1.15.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.15.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.15.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.15.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.15.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.15.2.1 03-Aug-2004  skrll Sync with HEAD
 1.17.6.1 12-Feb-2005  yamt sync with head.
 1.17.4.1 29-Apr-2005  kent sync with -current
 1.23.80.2 10-Oct-2008  skrll Sync with HEAD.
 1.23.80.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.23.78.3 11-Aug-2010  yamt sync with head.
 1.23.78.2 16-Sep-2009  yamt sync with head
 1.23.78.1 04-May-2009  yamt sync with head.
 1.23.76.1 04-Jun-2008  yamt sync with head
 1.23.74.3 17-Jan-2009  mjf Sync with HEAD.
 1.23.74.2 28-Sep-2008  mjf Sync with HEAD.
 1.23.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.4.1 19-Oct-2008  haad Sync with HEAD.
 1.26.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.26.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.26.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.29.2.5 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.29.2.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.29.2.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.29.2.2 01-Nov-2009  jym Sync with HEAD.
 1.29.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.32.4.3 31-May-2011  rmind sync with head
 1.32.4.2 05-Mar-2011  rmind sync with head
 1.32.4.1 03-Jul-2010  rmind sync with head
 1.32.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.33.4.2 05-Mar-2011  bouyer Sync with HEAD
 1.33.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.33.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.36.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.37.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.37.2.1 17-Apr-2012  yamt sync with head
 1.38.12.1 18-May-2014  rmind sync with head
 1.38.8.2 03-Dec-2017  jdolecek update from HEAD
 1.38.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.40.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.40.6.2 28-Aug-2017  skrll Sync with HEAD
 1.40.6.1 05-Feb-2017  skrll Sync with HEAD
 1.42.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.42.6.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.42.6.1 01-Aug-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1309):

sys/arch/i386/stand/lib/exec.c: revision 1.73
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.10
sys/arch/i386/stand/lib/libi386.h: revision 1.44
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.6
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.7
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.12
sys/arch/i386/stand/efiboot/boot.c: revision 1.13
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.9
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.15
sys/arch/i386/stand/efiboot/dev_net.c: revision 1.2

Added tftp support to x86 efiboot.

Pre-allocate memory for the kernel space at startup.

Added BTINFO_EFIMEMMAP compaction support to x86 efiboot.

Sync the output of memmap command to the output of stand/efiboot mem command.

Added missing efi_memory_probe() call.
 1.44.2.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.53.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Apr-1999  christos use new loadfile
 1.9 17-Apr-1999  drochner another nit in error handling: don't try to print out a NULL filename
(which means "use default" and is dealt with properly by open())
 1.8 09-Apr-1999  drochner fix error handling: almost all errors were ignored
 1.7 07-Mar-1999  he branches: 1.7.2;
Add handling of OMAGIC files, where exec header isn't part of the
text segment. Needed for woring installboot, since biosboot.sym is OMAGIC.
 1.6 05-Mar-1999  fvdl Make bootblocks really work this time. From Christos.
 1.5 04-Mar-1999  christos Fix the symbol reading problem...
 1.4 30-Jan-1999  christos Add my name in the copyright, since the code looks very different now.
 1.3 29-Jan-1999  christos Add the ability to get the size of the loaded image without actually
loading. This is useful for dos loading and installboot.
 1.2 28-Jan-1999  christos Add support for selectively loading sections, and make this compile in
userland with -DINSTALLBOOT
 1.1 28-Jan-1999  christos Add loadfile.c (stolen from Jason's alpha/stand/common/loadfile.c)
loadfile.h contains macros that are supposed to be MD, but loadfile.c is now MI.
Fixes:
- a.out support
- pass information values via an array not global variables
- don't assume that you can access memory directly.
- remove MD parts
- remove some printfs.
XXX: loadfile.c needs to be moved somewhere where other ports can use it.
XXX2: read() routines on the i386 don't appear to set errno on failure.
 1.7.2.1 19-Apr-1999  perry branches: 1.7.2.1.2;
pull up 1.7->1.9 to fix error handling (req. by drochner)
 1.7.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.4 28-Apr-1999  christos use new loadfile
 1.3 29-Jan-1999  christos branches: 1.3.2; 1.3.4;
Add the ability to get the size of the loaded image without actually
loading. This is useful for dos loading and installboot.
 1.2 28-Jan-1999  christos Add support for selectively loading sections, and make this compile in
userland with -DINSTALLBOOT
 1.1 28-Jan-1999  christos Add loadfile.c (stolen from Jason's alpha/stand/common/loadfile.c)
loadfile.h contains macros that are supposed to be MD, but loadfile.c is now MI.
Fixes:
- a.out support
- pass information values via an array not global variables
- don't assume that you can access memory directly.
- remove MD parts
- remove some printfs.
XXX: loadfile.c needs to be moved somewhere where other ports can use it.
XXX2: read() routines on the i386 don't appear to set errno on failure.
 1.3.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.3.2.1 20-Dec-1999  he Apply patch (based on rev. 1.3 of loadfile_machdep.h, requested by drochner):
Allow booting of kernels which are larger than 16MB on i386.
 1.6 11-Jun-2016  dholland gets_s -> kgets.

The exact name isn't that important; but it is important not to use
"gets_s" and thereby allow anyone to falsely get the impression we're
implementing Annex K. We aren't.

ok core.
 1.5 05-Jun-2016  maxv Use gets_s instead of gets. The x86 bootloader prompt is easy to
overflow.
 1.4 06-Apr-2014  jakllsch branches: 1.4.4;
Use __dead.
 1.3 14-Dec-2008  christos branches: 1.3.14; 1.3.24; 1.3.28; 1.3.38;
more KNF and ANSI from Anon-ymous
 1.2 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.1 17-Sep-1997  drochner branches: 1.1.2; 1.1.156; 1.1.160; 1.1.168;
Factor out functions for table driven boot menus and command line parsing
usable for different boot programs.
 1.1.168.1 19-Jan-2009  skrll Sync with HEAD.
 1.1.160.1 04-May-2009  yamt sync with head.
 1.1.156.1 17-Jan-2009  mjf Sync with HEAD.
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file menuutils.c was added on branch marc-pcmcia on 1997-09-22 06:31:33 +0000
 1.3.38.1 10-Aug-2014  tls Rebase.
 1.3.28.1 18-May-2014  rmind sync with head
 1.3.24.2 03-Dec-2017  jdolecek update from HEAD
 1.3.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.14.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.4.1 09-Jul-2016  skrll Sync with HEAD
 1.4 19-Nov-2009  dsl Move code for outputting directly to the serial port into message.S
Allows it to be enabled for other parts of the boot sequence.
 1.3 28-Apr-2008  martin branches: 1.3.14;
Remove clause 3 and 4 from TNF licenses
 1.2 24-Apr-2003  dsl branches: 1.2.104; 1.2.106; 1.2.108;
Don't use ENTRY - it aligns the label and we can't afford the space.
Adjust coding to save 2 more bytes (assume 'D' flag clear - it is)
 1.1 16-Apr-2003  dsl additional support routines for boot code
 1.2.108.2 11-Mar-2010  yamt sync with head
 1.2.108.1 16-May-2008  yamt sync with head.
 1.2.106.1 18-May-2008  yamt sync with head.
 1.2.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.14.1 24-Oct-2010  jym Sync with HEAD
 1.1 19-Nov-2009  dsl branches: 1.1.4; 1.1.8;
Add 32 bit versions of message and dump_eax that write directly to
the serial port. Useful for debugging - especially real_to_prot!
 1.1.8.2 24-Oct-2010  jym Sync with HEAD
 1.1.8.1 19-Nov-2009  jym file message32.S was added on branch jym-xensuspend on 2010-10-24 22:48:05 +0000
 1.1.4.2 11-Mar-2010  yamt sync with head
 1.1.4.1 19-Nov-2009  yamt file message32.S was added on branch yamt-nfs-mp on 2010-03-11 15:02:31 +0000
 1.3 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.2 04-Dec-2016  maxv branches: 1.2.8; 1.2.16; 1.2.20;
KNF and explain a few things
 1.1 11-Oct-2008  joerg branches: 1.1.2; 1.1.10; 1.1.16; 1.1.44; 1.1.64; 1.1.68;
Add "multiboot" command to boot multiboot compliant kernels like Xen.
Patch provided by Robert Swindell with fixes for the command line
parsing and addition of passing module options from me. The kernel now
always gets the full string for modules like for the command line,
everything before the first space/tab is the path name of the module.
 1.1.68.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1.64.1 05-Dec-2016  skrll Sync with HEAD
 1.1.44.1 03-Dec-2017  jdolecek update from HEAD
 1.1.16.2 04-May-2009  yamt sync with head.
 1.1.16.1 11-Oct-2008  yamt file multiboot.S was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.1.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.10.1 11-Oct-2008  mjf file multiboot.S was added on branch mjf-devfs2 on 2009-01-17 13:28:05 +0000
 1.1.2.2 19-Oct-2008  haad Sync with HEAD.
 1.1.2.1 11-Oct-2008  haad file multiboot.S was added on branch haad-dm on 2008-10-19 22:15:50 +0000
 1.2.20.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.2.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.8.1 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.4 24-Sep-2000  jdolecek add new macro BOOT_FLAG() (defined in <sys/boot_flag.h>) - this
maps standard boot flags to corresponding RB_* values
use BOOT_FLAG() in port's MD code as appropriate

as discussed on tech-kern, add new boot flags -v, -q for booting
verbosely or quietly, and corresponding AB_VERBOSE/AB_QUIET
boot flags; also add FreeBSD-compatible bootverbose macro and
NetBSD-specific bootquiet macro

for hpcmips, use new bootverbose instead of it's own hpcmips_verbose

Tested on i386, and to limited extend (compile of affected files) also for
mvme68k, hp300, luna68k, sun3.
 1.3 29-Jul-2000  jdolecek branches: 1.3.2;
g/c RB_DFLTROOT

I've tried hard to find also various usage() messages and remove the
appropriate flag from there as well, hopefully all occurences are covered.
 1.2 14-Mar-1997  thorpej branches: 1.2.22; 1.2.34;
Purely cosmetic whitespace changes.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.2.34.1 13-Aug-2000  jdolecek pullup from trunk (approved by thorpej):
retire RB_DFLTROOT, it's no longer used

revisions pulled up:
arch/i386/stand/lib/netbsd_opts.c 1.3
arch/i386/stand/biosboot/main.c 1.23
arch/i386/stand/dosboot/main.c 1.15
arch/i386/stand/netboot/main.c 1.6
arch/arc/arc/machdep.c 1.42
arch/bebox/stand/boot/boot.c 1.11
arch/hpcmips/hpcmips/machdep.c 1.32
arch/newsmips/newsmips/machdep.c 1.45
arch/pc532/stand/boot/boot.c 1.2
arch/pmax/pmax/machdep.c 1.178
arch/prep/stand/boot/boot.c 1.2
arch/sparc/sparc/autoconf.c 1.141
arch/sparc64/sparc64/autoconf.c 1.38
arch/x68k/stand/loadbsd/loadbsd.c 1.5
arch/mvme68k/stand/libsa/parse_args.c 1.6
compat/osf1/osf1_cvt.c 1.9
sys/reboot.h 1.17
 1.2.22.1 20-Nov-2000  bouyer Remove files that are no longer on the trunck
 1.3.2.2 23-Jan-2001  thorpej Sync with the trunk.
 1.3.2.1 29-Jul-2000  thorpej file netbsd_opts.c was added on branch sommerfeld_i386mp_1 on 2001-01-23 06:34:55 +0000
 1.8 20-Dec-2010  jakllsch MI libsa provides panic() and exit() functions, no need to provide our own.
As MI libsa exit() calls panic() with a "exit" message, don't use it if we
print our own farewell or have already panic()ed.
 1.7 11-Dec-2005  christos branches: 1.7.92; 1.7.100;
merge ktrace-lwp.
 1.6 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.5 01-Jun-2002  itojun branches: 1.5.2; 1.5.8;
use exit(int), not exit(void), consistently - even if the arg has no meaning.
 1.4 20-Sep-2001  wiz branches: 1.4.12;
When using va_list, use vprintf, not printf.
 1.3 12-Feb-1999  cjs branches: 1.3.22; 1.3.24; 1.3.26;
Don't give exit() a parameter, as libstand version doesn't take one.
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.26.1 01-Oct-2001  fvdl Catch up with -current.
 1.3.24.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.24.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.22.2 20-Jun-2002  nathanw Catch up to -current.
 1.3.22.1 21-Sep-2001  nathanw Catch up to -current.
 1.4.12.1 14-Jul-2002  gehenna catch up with -current.
 1.5.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.8.1 03-Aug-2004  skrll Sync with HEAD
 1.5.2.2 01-Jun-2002  itojun use exit(int), not exit(void), consistently - even if the arg has no meaning.
 1.5.2.1 01-Jun-2002  itojun file panic.c was added on branch sommerfeld_i386mp_1 on 2002-06-01 11:40:34 +0000
 1.7.100.1 05-Mar-2011  rmind sync with head
 1.7.92.1 10-Jan-2011  jym Sync with HEAD
 1.7 05-Jan-2014  jakllsch No need to return a empty string literal of the wrong const-ness when we
already have a empty string of the correct const-ness.
 1.6 18-Aug-2011  christos branches: 1.6.2; 1.6.12; 1.6.16;
PR/43563: Wolfgang Solfrank: boot.cfg doesn't support comments
Fix makes it support # comments and treat spaces and tabs the same way.
 1.5 14-Dec-2008  christos branches: 1.5.2;
ANSI and KNF from Anon Ymous
 1.4 09-Dec-2008  christos Allow parsing more than one command line switch. From anon ymous.
 1.3 24-Sep-2000  jdolecek branches: 1.3.2; 1.3.128; 1.3.132; 1.3.138; 1.3.140;
add new macro BOOT_FLAG() (defined in <sys/boot_flag.h>) - this
maps standard boot flags to corresponding RB_* values
use BOOT_FLAG() in port's MD code as appropriate

as discussed on tech-kern, add new boot flags -v, -q for booting
verbosely or quietly, and corresponding AB_VERBOSE/AB_QUIET
boot flags; also add FreeBSD-compatible bootverbose macro and
NetBSD-specific bootquiet macro

for hpcmips, use new bootverbose instead of it's own hpcmips_verbose

Tested on i386, and to limited extend (compile of affected files) also for
mvme68k, hp300, luna68k, sun3.
 1.2 31-Aug-2000  jdolecek constify first arg to parseopts()
 1.1 17-Sep-1997  drochner branches: 1.1.2; 1.1.18;
Factor out functions for table driven boot menus and command line parsing
usable for different boot programs.
 1.1.18.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 17-Sep-1997  thorpej file parseutils.c was added on branch marc-pcmcia on 1997-09-22 06:31:34 +0000
 1.3.140.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.138.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.132.1 04-May-2009  yamt sync with head.
 1.3.128.1 17-Jan-2009  mjf Sync with HEAD.
 1.3.2.2 24-Sep-2000  jdolecek add new macro BOOT_FLAG() (defined in <sys/boot_flag.h>) - this
maps standard boot flags to corresponding RB_* values
use BOOT_FLAG() in port's MD code as appropriate

as discussed on tech-kern, add new boot flags -v, -q for booting
verbosely or quietly, and corresponding AB_VERBOSE/AB_QUIET
boot flags; also add FreeBSD-compatible bootverbose macro and
NetBSD-specific bootquiet macro

for hpcmips, use new bootverbose instead of it's own hpcmips_verbose

Tested on i386, and to limited extend (compile of affected files) also for
mvme68k, hp300, luna68k, sun3.
 1.3.2.1 24-Sep-2000  jdolecek file parseutils.c was added on branch sommerfeld_i386mp_1 on 2000-09-24 12:32:36 +0000
 1.5.2.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.6.16.1 18-May-2014  rmind sync with head
 1.6.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.30 08-Jun-2011  joerg Use prototypes from libi386.h.
 1.29 14-Feb-2011  jmcneill branches: 1.29.2;
port-i386/44563: boot loader prompt doesn't read keyboard input on a MacBook1,1

check for keystroke (int 16h, AH=01h) before getting keystroke (int 16h,
AH=00h), fixes bootloader keyboard input with Apple firmware, from Taylor R
Campbell
 1.28 25-Jun-2010  tsutsui branches: 1.28.2; 1.28.4;
Add wait_sec() which uses BIOS function call INT 1Ah/AH=00h (GET SYSTEMTIME)
and use it for large delays (in seconds) instead of delay() that uses
INT 15h/AH=86h (WAIT) in microsecond because the latter one can't provide
precise delays on emulators.
Fixes PR port-i386/43156 (NetBSD bootloader countdown runs at 1/20 speed
in qemu 0.12).

No particular comments on the PR and port-i386@.
 1.27 26-Aug-2009  jmcneill branches: 1.27.2; 1.27.4;
int 15h/AH=86h (WAIT) doesn't work properly on all hardware and emulators, so
for the countdown use the more coarsely grained sleep implementation based
on int 1ah/AH=00h (GET SYSTEM TIME).

ok ad@
 1.26 29-Jun-2009  mbalmer Have the boot countdown on i386 display "starting in N seconds." instead
of "starting in N" and eliminate a use of sprintf. Note that on
some rare machines it can be that the BIOS does not provide the delay
function. On such machines the countdown will almost immediately count down
to zero display "starting in 0 seconds."; apparently the net4801 is such a
machine.
Feedback, ideas, and inspiration from tron, ok tron/tonnerre
 1.25 14-Dec-2008  christos branches: 1.25.2;
more KNF and ANSI from Anon-ymous
 1.24 13-Dec-2008  christos add a boot.cfg option to clear the screen; default off. From Anon Ymous
 1.23 21-May-2008  ad branches: 1.23.6; 1.23.8; 1.23.14;
Fix build failure.
 1.22 21-May-2008  ad - Stop the twiddler going awry.
- Clear screen if on a glass tty (!).
 1.21 30-Jan-2006  junyoung branches: 1.21.72; 1.21.74; 1.21.76; 1.21.78;
ANSI & KNF.
 1.20 11-Nov-2005  dsl branches: 1.20.4;
Make a baud rate of zero cause the baud rate divisor be read and converted
to the current baud rate.
That way we use the same baud rate as the system BIOS (or whatever).
Rather useful for pxeboot.
 1.19 27-Jan-2005  mycroft branches: 1.19.6;
Make awaitkey() poll once even if the timeout is 0. This also fixes a problem
where a keypress within the last polling interval would not be noticed.
Add a new function, conisshift(), which is used to detect whether a shift key
is pressed. Use this via awaitkey() to allow interrupting the boot by holding
down shift (similar to LILO).

This allows setting the timeout to 0 and still being able to use the boot
program.
 1.18 15-Aug-2004  dsl branches: 1.18.4; 1.18.6;
Allow the com port base address to be specified by the user (via installboot)
rather than taking the value from the bios.
Should allow the system to use a serial console that is also a 'bios serial
console' and isn't in the bios serial port table.
Probably fixes (with a few other changes) PR port-i386/9236
 1.17 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.16 13-Mar-2004  dsl Translate ascii keycode to help those with azerty keyboard type straight.
 1.15 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.14 16-Apr-2003  dsl branches: 1.14.2;
Modify baud rate handling to make it easier to take it from a variable.
Default to 9600 if the requested baud rate is illegal.
 1.13 08-Mar-2003  dsl Avoid pulling strncpy() into minimal boot code
 1.12 01-Feb-2003  dsl Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.11 19-Feb-2002  thorpej branches: 1.11.2;
Add some comments to make some #if/#else/#endif's more clear.
 1.10 10-Sep-1999  drochner branches: 1.10.16; 1.10.18;
improve awaitkey()'s printout for >9 seconds
 1.9 14-Apr-1999  drochner add prototypes, slight formatting changes
 1.8 12-Mar-1999  sommerfe branches: 1.8.4;
Fix compile warning in getcomaddr()
 1.7 13-Aug-1998  rvb Make serial line debugging easier to enable and use
 1.6 27-Oct-1997  drochner Catch "timeout" return of serial port read BIOS call.
 1.5 17-Sep-1997  drochner branches: 1.5.2;
-extend serial console code to all 4 BIOS known interfaces
-optionally, use Martin's direct hardware access to serial lines
-optionally, new console autoselection method: select serial console
if a character is seen within 1 second
-move awaitkey() here, it can be shared by different bootloaders and
it is used by console autoselection
-collect information about console selection in a "bootinfo" defined
structure, for passing to the kernel
 1.4 13-Jun-1997  drochner branches: 1.4.4;
Reformat comments. (messed up by "indent")
-Wall fixes
 1.3 22-Mar-1997  thorpej Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.2 15-Mar-1997  perry From Matthias Drochner:
fix prototypes
use CONSDEV_* constants for consistency
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.4.4.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.2.1 28-Oct-1997  mellon Pull rev 1.6 up from trunk (drochner)
 1.8.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.10.18.1 16-Mar-2002  jdolecek Catch up with -current.
 1.10.16.1 28-Feb-2002  nathanw Catch up to -current.
 1.11.2.2 19-Feb-2002  thorpej Add some comments to make some #if/#else/#endif's more clear.
 1.11.2.1 19-Feb-2002  thorpej file pcio.c was added on branch sommerfeld_i386mp_1 on 2002-02-19 20:18:37 +0000
 1.14.2.6 11-Dec-2005  christos Sync with head.
 1.14.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.14.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.14.2.1 03-Aug-2004  skrll Sync with HEAD
 1.18.6.1 12-Feb-2005  yamt sync with head.
 1.18.4.1 29-Apr-2005  kent sync with -current
 1.19.6.1 21-Jun-2006  yamt sync with head.
 1.20.4.1 01-Feb-2006  yamt sync with head.
 1.21.78.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.21.76.4 11-Aug-2010  yamt sync with head.
 1.21.76.3 16-Sep-2009  yamt sync with head
 1.21.76.2 18-Jul-2009  yamt sync with head.
 1.21.76.1 04-May-2009  yamt sync with head.
 1.21.74.1 04-Jun-2008  yamt sync with head
 1.21.72.2 17-Jan-2009  mjf Sync with HEAD.
 1.21.72.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.14.1 21-Apr-2010  matt sync to netbsd-5
 1.23.8.2 28-Nov-2009  bouyer Pull up following revision(s) (requested by mbalmer in ticket #1143):
sys/arch/i386/stand/lib/pcio.c: revision 1.26
Have the boot countdown on i386 display "starting in N seconds." instead
of "starting in N" and eliminate a use of sprintf. Note that on
some rare machines it can be that the BIOS does not provide the delay
function. On such machines the countdown will almost immediately count down
to zero display "starting in 0 seconds."; apparently the net4801 is such a
machine.
Feedback, ideas, and inspiration from tron, ok tron/tonnerre
 1.23.8.1 26-Sep-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #928):
sys/arch/i386/stand/lib/pcio.c: revision 1.27
int 15h/AH=86h (WAIT) doesn't work properly on all hardware and emulators, so
for the countdown use the more coarsely grained sleep implementation based
on int 1ah/AH=00h (GET SYSTEM TIME).
ok ad@
 1.23.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.25.2.5 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.25.2.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.25.2.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.25.2.2 01-Nov-2009  jym Sync with HEAD.
 1.25.2.1 23-Jul-2009  jym Sync with HEAD.
 1.27.4.3 12-Jun-2011  rmind sync with head
 1.27.4.2 05-Mar-2011  rmind sync with head
 1.27.4.1 03-Jul-2010  rmind sync with head
 1.27.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.28.4.1 17-Feb-2011  bouyer Sync with HEAD
 1.28.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.29.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.5 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.4 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.78; 1.3.86;
merge ktrace-lwp.
 1.2 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry branches: 1.1.1.1.58;
Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.1.1.1.58.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.1.1.58.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.1.1.58.1 03-Aug-2004  skrll Sync with HEAD
 1.3.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.78.1 04-May-2009  yamt sync with head.
 1.3.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.8 13-Sep-2019  manu Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.7 14-Dec-2008  christos branches: 1.7.58; 1.7.66; 1.7.70;
ANSI and KNF from Anon Ymous
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.78; 1.6.86;
merge ktrace-lwp.
 1.5 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.4 01-Feb-2003  dsl branches: 1.4.2;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.3 28-Jan-1999  christos Minor changes to prototypes.
 1.2 22-Mar-1997  thorpej Purely cosmetic whitespace and indentation changes (mmm, indent(1))
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.6.78.1 04-May-2009  yamt sync with head.
 1.6.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.70.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.7.66.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.58.1 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.3 29-Jun-2024  rin i386: stand: G/C unused `printmemlist`, NFC
 1.2 14-Dec-2008  christos ANSI and KNF from Anon Ymous
 1.1 21-Dec-1999  drochner branches: 1.1.2; 1.1.10; 1.1.136; 1.1.140; 1.1.148;
add a function which prints out the memory descriptors (for debugging)
 1.1.148.1 19-Jan-2009  skrll Sync with HEAD.
 1.1.140.1 04-May-2009  yamt sync with head.
 1.1.136.1 17-Jan-2009  mjf Sync with HEAD.
 1.1.10.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.10.1 21-Dec-1999  bouyer file printmemlist.c was added on branch thorpej_scsipi on 2000-11-20 20:09:40 +0000
 1.1.2.2 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.2.1 21-Dec-1999  wrstuden file printmemlist.c was added on branch wrstuden-devbsize on 1999-12-27 18:32:29 +0000
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 16-Apr-2003  dsl branches: 1.1.104; 1.1.106; 1.1.108;
additional support routines for boot code
 1.1.108.1 16-May-2008  yamt sync with head.
 1.1.106.1 18-May-2008  yamt sync with head.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.1 02-Jun-2011  dsl branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Add C stubs to allow prints early in the boot code.
 1.1.8.2 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.1.8.1 02-Jun-2011  jym file putstr32.S was added on branch jym-xensuspend on 2011-08-27 15:59:48 +0000
 1.1.6.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.6.1 02-Jun-2011  cherry file putstr32.S was added on branch cherry-xenmp on 2011-06-23 14:19:16 +0000
 1.1.4.2 12-Jun-2011  rmind sync with head
 1.1.4.1 02-Jun-2011  rmind file putstr32.S was added on branch rmind-uvmplock on 2011-06-12 00:23:59 +0000
 1.1.2.2 06-Jun-2011  jruoho Sync with HEAD.
 1.1.2.1 02-Jun-2011  jruoho file putstr32.S was added on branch jruoho-x86intr on 2011-06-06 09:05:53 +0000
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 16-Apr-2003  dsl branches: 1.1.104; 1.1.106; 1.1.108;
additional support routines for boot code
 1.1.108.1 16-May-2008  yamt sync with head.
 1.1.106.1 18-May-2008  yamt sync with head.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.1 16-Feb-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6;
Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.1.6.3 01-Nov-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 16-Feb-2009  jym file rasops.c was added on branch jym-xensuspend on 2009-05-13 17:17:52 +0000
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 16-Feb-2009  yamt file rasops.c was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.1.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.1.2.1 16-Feb-2009  skrll file rasops.c was added on branch nick-hppapmap on 2009-03-03 18:29:00 +0000
 1.13 05-Mar-2025  andvar fix couple typos in comments.
 1.12 01-Apr-2022  andvar branches: 1.12.10;
s/potected/protected and s/investication/investigation/ in comments.
 1.11 24-Dec-2013  jakllsch Obtain CR0_PE constant from <x86/specialreg.h> rather than a local #define.
 1.10 19-Dec-2010  jakllsch branches: 1.10.8; 1.10.18; 1.10.22;
Compute real/protected %sp/%esp offset in 'gdt_fixup' using all 32-bits.
Allows the case of %ss being less than %cs to work.
Also, completely save and restore the general-purpose registers we use.
 1.9 21-Nov-2009  dsl branches: 1.9.4;
Replace EPIA_HACK code with a version that 'just' trashes any return
address cache. This seems to be rather more effective!
This seems to be adequate and is more justifyable than the previous hack.
 1.8 16-Feb-2009  jmcneill Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.7 28-Apr-2008  martin branches: 1.7.8; 1.7.14;
Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.76; 1.6.78;
merge ktrace-lwp.
 1.5 21-Jun-2005  junyoung Remove trailing spaces.
 1.4 27-May-2005  gavan Workaround for issues seen on VIA C3-based systems. PR port-i386/26007

Tested on ML5000 board. This may not fix the problem on all variations of the
hardware, but it's likely that variations on the theme will. This workaround
is non-intrusive and should not affect any other CPUs.
 1.3 13-Feb-2004  wiz branches: 1.3.6; 1.3.14;
Uppercase CPU, plural is CPUs.
 1.2 24-Apr-2003  dsl branches: 1.2.2;
Missing end of comment
 1.1 16-Apr-2003  dsl Routines to switch between 16bit real and 32bit protected modes
 1.2.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.3.14.1 30-May-2005  riz Pull up revision 1.4 (requested by gavan in ticket #356):
Workaround for issues seen on VIA C3-based systems. PR port-i386/26007
Tested on ML5000 board. This may not fix the problem on all variations
of the
hardware, but it's likely that variations on the theme will. This workaround
is non-intrusive and should not affect any other CPUs.
 1.3.6.1 30-May-2005  riz Pull up revision 1.4 (requested by gavan in ticket #1870):
Workaround for issues seen on VIA C3-based systems. PR port-i386/26007
Tested on ML5000 board. This may not fix the problem on all variations
of the
hardware, but it's likely that variations on the theme will. This workaround
is non-intrusive and should not affect any other CPUs.
 1.6.78.3 11-Mar-2010  yamt sync with head
 1.6.78.2 04-May-2009  yamt sync with head.
 1.6.78.1 16-May-2008  yamt sync with head.
 1.6.76.1 18-May-2008  yamt sync with head.
 1.6.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.14.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.7.14.2 01-Nov-2009  jym Sync with HEAD.
 1.7.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.7.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.9.4.1 05-Mar-2011  rmind sync with head
 1.10.22.1 18-May-2014  rmind sync with head
 1.10.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.10.1 02-Aug-2025  perseant Sync with HEAD
 1.4 04-Dec-2016  maxv KNF and explain a few things
 1.3 01-Feb-2003  dsl branches: 1.3.152; 1.3.172; 1.3.176;
Change all .S files to use .code16 and .code32
Support 32bit addresses >64k as valid on bios calls.
Move stack for dosboot and biosboot to >64 so stack doesn't hit data.
Use disk sector number passed by mbr code to select default partition
(the mbr code doesn't do this yet).
NB only biosboot and dosboot have been tested so far.
(changes approved by christos and fvdl)
 1.2 01-Mar-1999  simonb fix spel.
 1.1 14-Mar-1997  perry branches: 1.1.1;
Initial revision
 1.1.1.1 14-Mar-1997  perry Initial import of new boot code, created by Matthias Drochner with a
little hacking by me. This isn't strictly identical to his 920312
release -- I've hacked it a bit -- but since we are taking over change
control it doesn't matter much.
 1.3.176.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.3.172.1 05-Dec-2016  skrll Sync with HEAD
 1.3.152.1 03-Dec-2017  jdolecek update from HEAD
 1.10 15-Dec-2019  christos PR/54767: elo: fix incorrect test (mlelstv)
Add symbolic constants and reference to the standard.
 1.9 24-Jan-2017  nonaka branches: 1.9.14;
Initial commit of native amd64 EFI boot loader.
 1.8 31-May-2013  tsutsui branches: 1.8.10; 1.8.14; 1.8.18;
The 'vesa' command can take 'list' flag so mention it in an error message.
 1.7 09-Feb-2011  jmcneill branches: 1.7.4; 1.7.10; 1.7.14;
Add VESA VBE/DDC EDID support for determining the monitor's preferred
video mode. "vesa on" will now select the preferred mode @ 8bpp if it can
be determined and is supported by the display adapter, otherwise it will
use 640x480 @ 8bpp.
 1.6 25-Jun-2010  tsutsui branches: 1.6.2; 1.6.4;
Add wait_sec() which uses BIOS function call INT 1Ah/AH=00h (GET SYSTEMTIME)
and use it for large delays (in seconds) instead of delay() that uses
INT 15h/AH=86h (WAIT) in microsecond because the latter one can't provide
precise delays on emulators.
Fixes PR port-i386/43156 (NetBSD bootloader countdown runs at 1/20 speed
in qemu 0.12).

No particular comments on the PR and port-i386@.
 1.5 20-Oct-2009  jmcneill branches: 1.5.2; 1.5.4;
trim some fat
 1.4 14-Sep-2009  jmcneill Don't commit the selected VBE mode until the loader is past the point of
no return; need to stick in text mode as long as possible since libsa does
not include a rasops library. While here, add the 'vesa' command to pxeboot
to mirror biosboot behaviour.
 1.3 24-Aug-2009  jmcneill Pass the VBE mode number from the bootloader to the kernel, and then
make the ACPI wakecode aware of it. Restore the desired VBE mode on resume
when acpi_vbios_reset=1, so suspend/resume with genfb console will work.
 1.2 17-Feb-2009  jmcneill branches: 1.2.2; 1.2.4; 1.2.6;
Reorder command line parsing logic; previously the code assumed a string
containing the letter 'x' was a mode string (eg. 640x480), which prevented
the parser from picking up a mode number (eg. 0x101).
 1.1 16-Feb-2009  jmcneill Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.2.6.5 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.2.6.4 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.2.6.3 01-Nov-2009  jym Sync with HEAD.
 1.2.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.6.1 17-Feb-2009  jym file vbe.c was added on branch jym-xensuspend on 2009-05-13 17:17:52 +0000
 1.2.4.5 11-Aug-2010  yamt sync with head.
 1.2.4.4 11-Mar-2010  yamt sync with head
 1.2.4.3 16-Sep-2009  yamt sync with head
 1.2.4.2 04-May-2009  yamt sync with head.
 1.2.4.1 17-Feb-2009  yamt file vbe.c was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.2.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.2.2.1 17-Feb-2009  skrll file vbe.c was added on branch nick-hppapmap on 2009-03-03 18:29:00 +0000
 1.5.4.2 05-Mar-2011  rmind sync with head
 1.5.4.1 03-Jul-2010  rmind sync with head
 1.5.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.6.4.1 17-Feb-2011  bouyer Sync with HEAD
 1.6.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.7.14.2 03-Dec-2017  jdolecek update from HEAD
 1.7.14.1 23-Jun-2013  tls resync from head
 1.7.10.1 20-Oct-2013  bouyer Pull up following revision(s) (requested by tsutsui in ticket #957):
sys/arch/i386/stand/lib/vbe.c: revision 1.8
The 'vesa' command can take 'list' flag so mention it in an error message.
 1.7.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.8.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.8.10.1 05-Feb-2017  skrll Sync with HEAD
 1.9.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 09-Feb-2011  jmcneill Add VESA VBE/DDC EDID support for determining the monitor's preferred
video mode. "vesa on" will now select the preferred mode @ 8bpp if it can
be determined and is supported by the display adapter, otherwise it will
use 640x480 @ 8bpp.
 1.2 14-Sep-2009  jmcneill branches: 1.2.4; 1.2.6; 1.2.8;
Don't commit the selected VBE mode until the loader is past the point of
no return; need to stick in text mode as long as possible since libsa does
not include a rasops library. While here, add the 'vesa' command to pxeboot
to mirror biosboot behaviour.
 1.1 16-Feb-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6;
Bootloader modifications for generic framebuffer console support on i386
and amd64 where VESA VBE 2.0+ is available.

* Add helper library and stubs to invoke VBE bioscalls.
* Bump HEAP_START as we were already dangerously close to our limits.
* bootdataseg now allows access > 16MB so in the future we can scribble
on the framebuffer.
* Pass BTINFO_FRAMEBUFFER parameters to kernel when configured.
* VBE modes are configured with the new 'vesa' command. Usage, when present:
* vesa {enabled|disabled}
Enable / disable linear framebuffer, default mode is 640x480x8. May
be changed in the future to determine mode based on VBE/DDC where
available.
* vesa list
List modes supported by the firmware that meet the following criteria:
* linear framebuffer
* packed pixel or direct colour mode
* vesa {modenum|modestr}
Enable specific VBE mode. The mode can be specified either as a
VBE mode number (eg. 0x101) or as a string (eg. 800x600x16).
 1.1.6.4 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.1.6.3 01-Nov-2009  jym Sync with HEAD.
 1.1.6.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.6.1 16-Feb-2009  jym file vbe.h was added on branch jym-xensuspend on 2009-05-13 17:17:52 +0000
 1.1.4.3 16-Sep-2009  yamt sync with head
 1.1.4.2 04-May-2009  yamt sync with head.
 1.1.4.1 16-Feb-2009  yamt file vbe.h was added on branch yamt-nfs-mp on 2009-05-04 08:11:19 +0000
 1.1.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.1.2.1 16-Feb-2009  skrll file vbe.h was added on branch nick-hppapmap on 2009-03-03 18:29:00 +0000
 1.2.8.1 17-Feb-2011  bouyer Sync with HEAD
 1.2.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.2.4.1 05-Mar-2011  rmind sync with head
 1.2 19-Feb-1999  drochner redirect the linker's stderr to the protocol file too
 1.1 15-May-1998  drochner Framework to test standalone code in a friedly user environment.
 1.7 14-Dec-2008  christos more KNF and ANSI from Anon-ymous
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.78; 1.6.86;
merge ktrace-lwp.
 1.5 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.4 01-Apr-1999  drochner branches: 1.4.44;
sync to changed biosdisk interface again
 1.3 30-Mar-1999  drochner sync to changed geometry handling in the standalone code
 1.2 22-Nov-1998  drochner Update for INT13 support.
XXX We can't easily emulate this here due to the 16-bit-pointer
call interface.
 1.1 15-May-1998  drochner Framework to test standalone code in a friedly user environment.
 1.4.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.44.1 03-Aug-2004  skrll Sync with HEAD
 1.6.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.6.78.1 04-May-2009  yamt sync with head.
 1.6.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 30-Mar-1999  drochner branches: 1.2.44;
sync to changed geometry handling in the standalone code
 1.1 15-May-1998  drochner Framework to test standalone code in a friedly user environment.
 1.2.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.44.1 03-Aug-2004  skrll Sync with HEAD
 1.11 29-Jun-2024  rin i386: stand: G/C `netif` with its test; only used by netboot
 1.10 14-Dec-2008  christos more KNF and ANSI from Anon-ymous
 1.9 05-Dec-2007  dyoung branches: 1.9.12; 1.9.16; 1.9.24;
Use IFADDR_FIRST(), IFADDR_NEXT(), IFNET_NEXT().
 1.8 05-Dec-2007  dyoung Don't open-code queue(3) macros (x = ifnet.tqh_first; y =
x.if_list.tqe_next). Instead, use the macros themselves.
 1.7 17-Oct-2007  garbled branches: 1.7.2; 1.7.4;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.6 26-Aug-2007  dyoung branches: 1.6.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).

Use sockaddr_dl_setaddr() in a few places.
 1.5 04-Mar-2007  christos branches: 1.5.2; 1.5.10; 1.5.14; 1.5.18;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 24-Mar-2004  drochner branches: 1.3.16;
remove license clauses 3 and 4 from my cpoyright notices
 1.2 07-Jul-2001  perry branches: 1.2.4; 1.2.24;
b*()->mem*()
 1.1 15-May-1998  drochner branches: 1.1.28;
Framework to test standalone code in a friedly user environment.
 1.1.28.1 24-Aug-2001  nathanw Catch up with -current.
 1.2.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.24.1 03-Aug-2004  skrll Sync with HEAD
 1.2.4.2 07-Jul-2001  perry b*()->mem*()
 1.2.4.1 07-Jul-2001  perry file ether_bpf.c was added on branch sommerfeld_i386mp_1 on 2001-07-07 22:57:59 +0000
 1.3.16.2 07-Dec-2007  yamt sync with head
 1.3.16.1 03-Sep-2007  yamt sync with head.
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.18.2 09-Dec-2007  jmcneill Sync with HEAD.
 1.5.18.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.5.14.1 03-Sep-2007  skrll Sync with HEAD.
 1.5.10.1 03-Oct-2007  garbled Sync with HEAD
 1.5.2.1 09-Oct-2007  ad Sync with head.
 1.6.2.2 09-Jan-2008  matt sync with HEAD
 1.6.2.1 06-Nov-2007  matt sync with HEAD
 1.7.4.1 08-Dec-2007  ad Sync with head.
 1.7.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.9.24.1 19-Jan-2009  skrll Sync with HEAD.
 1.9.16.1 04-May-2009  yamt sync with head.
 1.9.12.1 17-Jan-2009  mjf Sync with HEAD.
 1.5 29-Jun-2024  rin i386: stand: G/C `I386_INCLUDE_BUS`; only used by netboot
 1.4 14-Dec-2008  christos more KNF and ANSI from Anon-ymous
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.78; 1.3.86;
merge ktrace-lwp.
 1.2 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.1 15-May-1998  drochner branches: 1.1.50;
Framework to test standalone code in a friedly user environment.
 1.1.50.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.50.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.50.1 03-Aug-2004  skrll Sync with HEAD
 1.3.86.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.78.1 04-May-2009  yamt sync with head.
 1.3.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.2 26-Mar-2014  christos kill sprintf.
 1.1 15-May-1998  drochner branches: 1.1.190; 1.1.200; 1.1.206;
Framework to test standalone code in a friedly user environment.
 1.1.206.1 18-May-2014  rmind sync with head
 1.1.200.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.190.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 14-Dec-2008  christos more KNF and ANSI from Anon-ymous
 1.5 04-Mar-2007  christos branches: 1.5.40; 1.5.44; 1.5.52;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 24-Mar-2004  drochner branches: 1.3.16;
remove license clauses 3 and 4 from my cpoyright notices
 1.2 22-Nov-1998  drochner branches: 1.2.46;
Update for INT13 support.
XXX We can't easily emulate this here due to the 16-bit-pointer
call interface.
 1.1 15-May-1998  drochner Framework to test standalone code in a friedly user environment.
 1.2.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.46.1 03-Aug-2004  skrll Sync with HEAD
 1.3.16.1 03-Sep-2007  yamt sync with head.
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.52.1 19-Jan-2009  skrll Sync with HEAD.
 1.5.44.1 04-May-2009  yamt sync with head.
 1.5.40.1 17-Jan-2009  mjf Sync with HEAD.

RSS XML Feed