3. linux/arch/i386/boot/bootsect.S

Given that we are booting up bzImage, which is
composed of bbootsect, bsetup
and bvmlinux (head.o, misc.o, piggy.o),
the first floppy sector, bbootsect (512 bytes),
which is compiled from linux/arch/i386/boot/bootsect.S,
is loaded by BIOS to 07C0:0.
The reset of bzImage (bsetup
and bvmlinux) has not been loaded yet.

Make sure SP is initialized immediately after SS register.
The recommended method of modifying SS is to use "lss" instruction
according to
IA-32 Intel Architecture Software Developer's Manual
(Vol.3. Ch.5.8.3. Masking Exceptions and Interrupts When Switching Stacks).

Stack operations, such as push and pop, will be OK now.
First 12 bytes of disk parameter have been copied to INITSEG:3FF4.

"lodsb" loads a byte from DS:[SI] to AL and increases SI automatically.

The number of sectors per track has been saved in variable
sectors.

3.3. Load Setup Code

bsetup (setup_sects sectors)
will be loaded right after bbootsect, i.e. SETUPSEG:0.
Note that INITSEG:0200==SETUPSEG:0 and
setup_sects has been changed
by tools/build to match
bsetup size
in Section 2.6.

3.7. Bootsect Helper

setup.S:bootsect_helper() is only used by
bootsect.S:read_it().

Because bbootsect and bsetup
are linked separately, they use offsets relative to
their own code/data segments.
We have to "call far" (lcall) for bootsect_helper()
in different segment, and it must "return far" (lret) then.
This results in CS change in calling, which makes CS!=DS, and
we have to use segment modifier to specify variables in
setup.S.

This "header" must conform to the layout pattern in
linux/Documentation/i386/boot.txt:

Offset Proto Name Meaning
/Size
01F1/1 ALL setup_sects The size of the setup in sectors
01F2/2 ALL root_flags If set, the root is mounted readonly
01F4/2 ALL syssize DO NOT USE - for bootsect.S use only
01F6/2 ALL swap_dev DO NOT USE - obsolete
01F8/2 ALL ram_size DO NOT USE - for bootsect.S use only
01FA/2 ALL vid_mode Video mode control
01FC/2 ALL root_dev Default root device number
01FE/2 ALL boot_flag 0xAA55 magic number