Booting A PC

ZealOS supports traditional BIOS booting with the 100% Public Domain ZealC HDD/DVD bootloaders. Using a different bootloader 
and the ZealBooter prekernel, the newer technique, UEFI, is also supported.  This document describes BIOS booting.

When you turn-on (power-up) a computer or you do a hardware reset, the computer starts executing the BIOS.  Sometimes, you 
must change the BIOS boot order to boot the device you want.

The BIOS loads a boot sector from CD/DVD, hard disk or whatever.    The boot sector runs in 16-bit real mode and often 
loads-in a second file that's bigger if it can't be done by just one sector.  It's a safe bet that boot sectors are hand-coded 
assembly language.  Most boot sectors use the BIOS to load-in the next stage.

Not only do boot sectors have a size limit, 512 bytes or 2048 bytes for CD/DVD, the files they load have to fit within 640K 
because they run in 16-bit mode.    This means they usually can't just load the whole operating system and start it running.    
Some boot loaders, like Grub, have a capability of switching modes before handing-off control to the operating system.  The 
operating system must load the rest of itself.  With ZealOS, the ::/Boot/Kernel.ZXE file is loaded by the boot sector.  We try 
to put a minimum in the Kernel Module, so that it will always fit in 640K.  When Kernel.ZXE runs, it switches to 32-bit mode, 
then, to 64-bit mode allowing access to more memory.  Then, it loads in the rest of ZealOS by executing ::/StartOS.ZC.

All the boot related code for ZealOS is in the /System/Boot directory.

BootDVD.ZC          CD/DVD boot sector.
BootDVDIns.ZC       Prep for CD/DVD install by creating /Boot/DVDKernel.ZXE.
If you are curious about CD/DVDs, see DiskISORedSea.ZC.  To make a custom bootable CD/DVD, look here Bootable CD.

BootMHD.ZC          Stage 1 Master HD boot loader.
BootMHD2.ZC         Stage 2 Master HD boot loader.
BootMHDIns.ZC       Installs Master HD boot loader.
BootMHD goes on block zero.  /Boot/BootMHD2.BIN is stored as a file in a partition, risky and unusual, since most master boot 
loaders place stage 2 in a gap that's not in any partition.  BootMHD2 displays a menu and boots a partition.

BootHD.ZC           HD partition boot record.
BootHDIns.ZC        Installs HD partition boot record at /Boot/Kernel.ZXE.
BootHD is the boot record for a ZealOS partition.  Each partition has its own partition boot record, the first block of the 
partition.

The boot records don't access directories because that would make them too big for one block and would make them depend on a 
file system layout.  Instead, they get patched with the LBA, logical block addresses, to load files.    To update with a new 
ZealOS kernel, you must create a ::/Boot/Kernel.ZXE binary file and patch the boot loader so it knows the LBA blocks to load.   
Therefore, you usually recompile the kernel and update the boot sector at the same time with    BootHDIns().    BootMHDIns() 
will install a master boot loader.

With ZealOS, ::/Boot/Kernel.ZXE loads ::/Compiler/Compiler.ZXE so it can work with source code from then on.  It compiles 
start-up scripts beginning with ::/StartOS.ZC into the System Task's memory including the code in the /System and /Home 
directories.

It is possible to do a fast reboot without doing a hardware reset.  You might do this when working on ::/Boot/Kernel.ZXE or 
your start-up scripts when you want to compile them effect.  See BootRAM().


/* Graphics Not Rendered in HTML */