History log of /openbsd-current/sys/arch/i386/stand/boot/conf.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.79 04-Jun-2024 krw

Bump versions of boot media now capable of un-hibernating from non-DEV_BSIZE
sectored media.

Bump to common version (3.67) to indicate new MI capability.

Reminded by deraadt@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.78 22-Jul-2023 jsg

BOOTARG_UCODE for AMD
ok deraadt@


# 1.77 25-Apr-2023 kn

Do not attempt to write to read-only softraid

Bootloaders have no write support for softraid volumes, which manifests in,
e.g. /bsd.upgrade not being stripped of its 'x' permission bit to prevent
sysupgrade loops in case of upgrade failure.

Set a no-write flag handled by libsa to bail out early in write calls.
There should be no real behaviour change, writes just fail earlier now.

i386 BIOS. Crank minor.
Tested inside amd64 vmm.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.76 09-Dec-2020 krw

branches: 1.76.8; 1.76.12;
Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.75 14-Jun-2020 deraadt

crank version number


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.78 22-Jul-2023 jsg

BOOTARG_UCODE for AMD
ok deraadt@


# 1.77 25-Apr-2023 kn

Do not attempt to write to read-only softraid

Bootloaders have no write support for softraid volumes, which manifests in,
e.g. /bsd.upgrade not being stripped of its 'x' permission bit to prevent
sysupgrade loops in case of upgrade failure.

Set a no-write flag handled by libsa to bail out early in write calls.
There should be no real behaviour change, writes just fail earlier now.

i386 BIOS. Crank minor.
Tested inside amd64 vmm.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.76 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.75 14-Jun-2020 deraadt

crank version number


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.77 25-Apr-2023 kn

Do not attempt to write to read-only softraid

Bootloaders have no write support for softraid volumes, which manifests in,
e.g. /bsd.upgrade not being stripped of its 'x' permission bit to prevent
sysupgrade loops in case of upgrade failure.

Set a no-write flag handled by libsa to bail out early in write calls.
There should be no real behaviour change, writes just fail earlier now.

i386 BIOS. Crank minor.
Tested inside amd64 vmm.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.76 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.75 14-Jun-2020 deraadt

crank version number


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.76 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.75 14-Jun-2020 deraadt

crank version number


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.75 14-Jun-2020 deraadt

crank version number


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.74 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


Revision tags: OPENBSD_6_7_BASE
# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.73 21-Mar-2020 otto

Teach i386 boot98) and friends about ffs2. fdboot(8) is the exception:
ffs2 support does not fit there. But the the kernel loaded by the
floppy ramdisk does support ffs2.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.72 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.71 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.70 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.69 08-Jun-2019 jsg

When loading intel microcode in the non-efi case, error if the file is
larger than 256KB not 128KB to cope with the 06-8e-09 microcode which is
currently 193KB.

Reported and tested by Paul de Weerd. Matches a diff from claudio@


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


Revision tags: OPENBSD_6_5_BASE
# 1.68 10-Apr-2019 deraadt

crank versions


# 1.67 08-Apr-2019 florian

crank version; looks good deraadt


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.66 07-Mar-2019 jsg

Return early in ucode loading if cpuid is not available. Should fix
booting on 486s without cpuid. Reported by Falk Richter and diagnosed
by guenther@


Revision tags: OPENBSD_6_4_BASE
# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.65 23-Aug-2018 jsg

port the amd64 code for loading intel microcode on boot to i386
ok deraadt@ mlarkin@


# 1.64 10-Aug-2018 jsing

Bump boot loader versions for softraid passphrase handling change.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


# 1.63 11-Jul-2018 mlarkin

Detect vmm(4) in the bootloader and automatically switch to the serial
console at 115200 baud.

ok deraadt


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.


Revision tags: OPENBSD_6_2_BASE
# 1.62 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.61 18-Sep-2016 jsing

Bump boot loader versions due to bcrypt pbkdf support.


# 1.60 13-Sep-2016 jasper

crank bootloader version after .SUNW_ctf change

as discussed with jsing@ it's easier this way to ensure people have
bootblocks capable of loading the section


Revision tags: OPENBSD_6_0_BASE
# 1.59 28-May-2016 sthen

crank version numbers of those bootloaders that have been changed by
the com_init fix. ok beck deraadt


Revision tags: OPENBSD_5_9_BASE
# 1.58 19-Feb-2016 naddy

belatedly bump bootstrap version after mdrandom() changes; ok deraadt@


# 1.57 18-Sep-2015 miod

Remove support for building the boot blocks with DEBUGFLAGS=-D_TEST, which is
supposed to create a userland binary in order to test non-boot related
functionality. This feature has been bitrotting in a non-compiling state
for years, and causes a too-many-ifdefs disease now that there are intrusive
EFI changes.

No functional change.


# 1.56 02-Sep-2015 yasuoka

Bring the boot changes on amd64 to i386. alloca is deleted.
Also fix the boot from BIOS and bump the version.

input and ok deraadt


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.55 18-Feb-2014 jsing

Bump version numbers.


# 1.54 02-Jan-2014 deraadt

crank version after random instruction fix from jsing


# 1.53 28-Dec-2013 deraadt

crank the version


# 1.52 23-Oct-2013 mlarkin

Crank bootblock versions after last commit


# 1.51 20-Oct-2013 stsp

Add i386/amd64 boot(8) support for keydisk-based softraid crypto volumes.

So far, only passphrase-based crypto volumes were bootable. Full disk
encryption with keydisks required a non-crypto partition to load the kernel.

The bootloader now scans all BIOS-visible disks for RAID partitions and
automatically associates keydisk partitions with their crypto volume.
Attempting to boot from a volume without its keydisk currently results
in a passphrase prompt (this might be changed in the future).

There is no need to re-create existing volumes. Moving the root partition
onto the crypto disk and running installboot(8) is all that's needed.

help & ok jsing


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.50 31-Oct-2012 jsing

Bump i386 boot(8) version.


# 1.49 12-Oct-2012 jsing

Force 16 byte alignment in boot(8) srt0.S, since this is more likely to get
the required file offset (0x120) for the .text segment.


# 1.48 09-Oct-2012 jsing

Bump boot versions due to recent changes.


Revision tags: OPENBSD_5_2_BASE
# 1.47 03-Jun-2012 kettenis

Add support for serial consoles at non-standard addresses. This implements
a new "machine comaddr" command that makes it possible to configure the
io port used to access the serial port. This can be used to use serial ports
on a puc(4) device as serial console.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.46 26-Apr-2011 jsing

Make amd64/i386 boot(8) pass the DUID of the selected boot device to the
kernel so that it can use it to identify the root disk. This will be
needed in order to correctly boot from a softraid volume.

ok deraadt@ marco@ krw@


# 1.45 08-Mar-2011 krw

Fix extended partition searching so we don't get lost. The offset
of the next EBR is relative to the start of the extended partition
described in the first MBR, not relative to the EBR specifying the
offset in its extended partition entry.

Clean up installboot -v output. Use daddr64_t for all sector numbers.

Not a complete fix, but better than what we had. More tweaks to
come.

Inspired by a diff and cluebat from uscav on tech@ a few weeks
ago.

Feedback from matthew@, weingart@.

ok deraadt@


Revision tags: OPENBSD_4_9_BASE
# 1.44 06-Dec-2010 jasper

- properly remove NENTS now after fixing the fallout.

ok deraadt@


# 1.43 06-Dec-2010 jasper

- partially revert previous NENTS removal for arches which got busted.


# 1.42 06-Dec-2010 jasper

- drop NENTS(), which was yet another copy of nitems().
no binary change


ok deraadt@


Revision tags: OPENBSD_4_8_BASE
# 1.41 11-Aug-2010 deraadt

crank version


# 1.40 02-Jul-2010 weingart

Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.

ok thib@, tedu@, phessler@


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.39 19-Apr-2008 weingart

Change ELF loader to use the LMA as the load address for the
various segments. Hopefully this will help remove various
hacks in the boot loader in the future. This should have no
effect on most architectures (as we tend to have LMA == VMA).

ok drahn@, soft ok's various others.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.38 31-May-2007 tom

Forgot to commit the changes to this file with the rest of the ELF32+64
pieces. Since this is where the "boot both ELF32 and ELF64" behaviour
is turned on for i386, it is quite important.

Bump version numbers too.

Found by ckuethe@; thanks.


# 1.37 30-May-2007 tom

Pull out the ELF loadfile pieces from the standalone libraries, so that
both 32- and 64-bit versions can be created (previously only one or the
other could be built for a given boot loader).

Use this to allow the i386 and amd64 boot blocks to boot both ELF32 and
ELF64 kernels (i.e. amd64 boot blocks can now load i386 kernels, and
vice versa). Obviously the system must support LONG mode in order to
successfully run the amd64 kernel once it is loaded.

Advice and discussions from/with dale@ (going back three years). Much
testing nick@ and todd@; thanks.


# 1.36 27-Apr-2007 tom

Check for Control key held down when starting, and don't read boot.conf
if it is. This gives a way to recover from "switching to com0" when
there's no serial cable handy.

Bump version numbers.

A similar change will be made to amd64 boot soon.

ok toby@ deraadt@


Revision tags: OPENBSD_4_1_BASE
# 1.35 02-Jan-2007 tom

Fix the keyboard problem seen on Intel Macs, where only the first
keypress is seen by boot.

It appears that on the Intel Mac, we have to issue the "check for
keystroke" BIOS call before the "get keystroke" call will get it
(unlike any other BIOS I have seen in over 20 years).

It would not have been possible to fix this problem without the
donation from Steven N. Fettig (steve (at) anywheretechnology.com);
many thanks.

Bump versions of boot, cdboot and pxeboot accordingly.

Testing kettenis@, otto@, and others; ok weingart@.


# 1.34 12-Oct-2006 krw

Bump versions to note behaviour change of no longer trying
to boot from NetBSD partitions. Requested by tom@.


# 1.33 18-Sep-2006 mpf

boot(8) ``machine memory'' support for > 4G.
Convert parser to strtoll(3) and use 64bit printf.
With help from mickey@
i386 and amd64 tests by me, alpha test by mickey@
OK mickey@, miod@, deraadt@


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.32 03-May-2005 tom

The return value from getEBDAaddr() (info) is not used in bios_E820(),
so nuke it. amd64 no longer needs biosprobe.c listed in SRCS. Trims
100 bytes from the boot blocks.

Bump versions on boot, cdboot and pxeboot, as I'm getting cautious in
my old age.

ok weingart@


# 1.31 03-May-2005 tom

Convert the size of a memory chunk from bytes to megabytes before
casting to a 32-bit value, not after. Corrects the display of large
memory chunks in the probing: line (mem[615K 3518M 0M a20=on] becomes
mem[615K 3518M 12288M a20=on]).

Bump version on boot, cdboot and pxeboot accordingly.

"looks ok to me" weingart@


# 1.30 30-Apr-2005 tom

Ensure we save the %ebx register returned from the BIOS call, not just
%bx. Fixes problem introduced in gidt.S r1.29, which could lead to an
incomplete memory map, and "too little memory available; running in
degraded mode", as found by Roy Morris rmorris (at) internetsecure (dot)
com. (Thanks for the report, and for testing the fix.)

Bump version on boot, cdboot and pxeboot accordingly.

ok weingart@


# 1.29 25-Apr-2005 tom

[OpenBSD]

Make boot code use real mode with 64K segments instead of 1M
segments. Improves stability with some disk controller cards.
Also explicitly state operand size on some moves.

Bump version on boot, cdboot and pxeboot accordingly.

"just get them in" beck@ ok weingart@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.28 19-Mar-2004 tom

Enter pxeboot, derived from the NetBSD implementation. Initially
intended to support network installs using bsd.rd over TFTP.

Thanks to the many who tested, including Diana Eichert.

ok deraadt@


# 1.27 23-Oct-2003 fgsch

- delay reading the disklabel for floppies until after we're sure it's
the boot device. this fixes a delay (sometimes very long) if the bios
correctly reports a floppy but it's unplugged.
- bump version.

original idea from mdw@, tested by nick@, toby@ ok.


# 1.26 19-Sep-2003 fgsch

- some bios return a valid geometry for inexistent hd's so before
getting the geometry check the number of attached drives from
the bios area at 40:75.
- bump version.

from toby@. we want people to test this, specially those with ghost
drives showing up.


# 1.25 18-Sep-2003 fgsch

- move checks earlier to catch inexistent devices before testing for edd.
- bump version.
toby@ ok.


Revision tags: OPENBSD_3_4_BASE
# 1.24 11-Sep-2003 deraadt

handle case where bios EDD support only supports a subset; from fgsch,
ok toby, and now tested for lots of machines


# 1.23 03-Jun-2003 mickey

three four kills


# 1.22 03-Jun-2003 deraadt

fix tree after mickey breakage


# 1.21 31-May-2003 weingart

First lba support in /boot. Not complete lba boot support, but it's the
first step on the way there. Ok deraadt@, espie@, todd@, and others.


Revision tags: UBC_SYNC_A
# 1.20 17-Apr-2003 drahn

i386 ELF bootloader. developed with weingart@


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.19 21-Jun-2002 weingart

Bump version to help distinquish new memory probe and fixes.


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE UBC_BASE
# 1.18 20-Aug-2001 mickey

branches: 1.18.4;
bump the version for new kbd probe; 10x for a reminder from fgsch@


# 1.17 06-May-2001 mickey

increase version since we've removed -b; per fgsch@'s suggestion


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 25-Oct-2000 mickey

add pciprobe back into /boot.
it appears there are machines only equipped w/ real-mode pci bios.
int time, we will benefit from this the other way around, --
we'll elliminate pci bios _calls_ in kernel instead.


# 1.15 19-Oct-2000 fgsch

Increment version; deraadt@ ok.


# 1.14 30-May-2000 mickey

aout_ldsym, increase boot minor version


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.13 20-Jul-1998 mickey

branches: 1.13.8;
new exec framework


Revision tags: OPENBSD_2_3_BASE
# 1.12 18-Apr-1998 deraadt

i386 bootblocks that work for 2.3. A tale too long to tell


# 1.11 24-Feb-1998 weingart

Changes/updates to /boot stuff. More to come.
Fixes many divide by zero and pointer bugs.


Revision tags: OPENBSD_2_2_BASE
# 1.10 26-Oct-1997 mickey

we have new features, bump boot version


# 1.9 17-Oct-1997 weingart

Use BIOS to probe for memory map.
Probe for BIOS supported disks.
Use BIOS to get geometry for supported disks.

All in preparation to passing the whole thing
to the kernel.


# 1.8 29-Sep-1997 mickey

bump the version number


# 1.7 02-Sep-1997 mickey

completely disable network support


# 1.6 13-Aug-1997 niklas

s/kbd/pc/ for consistency with kernel. Do even better __asms for BIOS calls.
Adapt to new console probing and setting API. Do not try to probe pc0 via
the NVRAM. Fix some other buglets.


# 1.5 12-Aug-1997 mickey

new cons


# 1.4 17-Jul-1997 mickey

proper includes
add const for consw declarations


Revision tags: OPENBSD_2_1_BASE
# 1.3 31-Mar-1997 mickey

commit all my mods to the last imported libsa stuff....
including:
- disklabel support;
- better boot cmd line
- smaller size (using some compilation switches ;)
- no more relocations in /boot, it's loaded in the place;
- better disk performance (maybe were already in there)
- installboot -n does not require write perms for device
- more debugs
- missing parts in libsa (such as cd9660 and so)
- i don't like 2 files for exec_i386 (sorry, toby, let's discuss maybe?)
tricks and tails:
- joined .text and .data (saves you a page)
- prot mode switching still in biosboot (it's freezed for awhile)
- biosdisk internals changed
- biosdev is not passed propery to the kernel (i'll fix it soon)
- sure i missed smth here to note (use the source, Luke!)


# 1.2 31-Mar-1997 weingart

Initial /boot stuff (from Mickey)


# 1.1 03-Dec-1996 mickey

branches: 1.1.2;
file conf.c was initially added on branch new.