Bootstrapping an OS on an x86-based PC, with application to ETH Oberon

Overview

The purpose of this document is to explain how an operating system is started starting from nothing (i.e. the bootstrap mechanism) in a systematic and progressive manner, from the simplest case of a single operating system setup, to a more complex and more demanding multi-boot manager setup including the cascading of boot loaders. Each operating system has its own boot sector on the installation medium and several of them will be reviewed here, but the generic aspect will be emphasized to facilitate the understanding of the details of the mechanism used for starting an OS.

The alternative ways to start an operating system will be reviewed in the order:

  1. boot directly from diskette: a diskette is a single partition storage medium (described in this document)
  2. boot a partition indirectly via the MBR of a (potentially multiple partition) mass storage medium
  3. boot via boot manager, commonly used in a multiple operating systems environment
  4. boot indirectly via another operating system, e.g. via DOS with noboot.exe (Oberon), or loadlin.exe (Linux)
  5. boot a virtual operating system hosted in a file (in FatFS or in Linux FS)
The recipe is generally applicable to most OSes but the focus is placed on ETH Oberon, the OS we are interested in.

BIOS activity during the boot sequence

This part is common to all x86-based machines, but some differences will be observed depending on the BIOS provided by different manufacturers and the BIOS set-up can differ from machine to machine too.

At the completion of a system's Power On Self Test (POST), the BIOS bootstrap routine generates an INT 19. Usually, INT 19 tries to read a boot sector from the first floppy drive (see next section "Boot directly from diskette"). If a boot sector is found on the floppy diskette, that boot sector is read into memory at location 0000:7C00 and the BIOS checks that the last two bytes of the sector are "55 AA". If that is correct, the routine jumps to memory location 0000:7C00 to execute the boot loader program in charge of loading and starting the operating system (it starts with the kernel).

If the last two bytes do not contain the "55 AA" signature, a BIOS-dependant message such as "Non-bootable disk" or "Non-System" is issued and the machine will halt.

However, if no boot sector is found on the first floppy drive, INT 19 tries to read the MBR from the first hard drive. If an MBR is found it is read into memory at location 0000:7C00 and INT 19 jumps to memory location 0000:7C00. The small program in the MBR will attempt to locate an active (bootable) partition in its partition table in a simple case. Alternatively, it can be the starting part of a boot manager program.

INT 19 is also called when the Ctrl-Alt-Del keys are pressed. On most systems, Ctrl-Alt-Del causes a short version of the POST to be executed before INT 19 is called.

Boot directly from diskette

A simple and stable manner of starting an operating system, with the inconvenience of being comparatively slow. Most manufacturers recommend creating rescue floppy diskette(s) for use in case of difficulty starting the operating system of concern.

The prerequisites are:

  1. the machine must be equipped with a diskette drive. This cannot be the case for newer non-legacy machines.
  2. the BIOS set-up must give precedence to the floppy drive. In case two floppy drives are installed, it is possible to switch the A and B drives via the BIOS setup or by switching the cables in older machines whose BIOS does not support software switching.
  3. a bootable diskette must be available. For ETH Oberon cf. Diskette support.

Advantage: The possible difficulties encountered with the installation of an MBR or a boot manager are eliminated.

ETH Oberon boot loader

The complete ETH Oberon boot loader (OBL) assembly code is found in OBL.Asm and its compiled form in OBL.Bin.

An OBL is written in the first 4 sectors in an Oberon partition (type 76) when a Partitions.Format command is executed. A partition occupies an entire floppy diskette. The same applies to a partition on a mass storage device. The difference is that in the latter case OBL becomes the second stage loader after the first stage loader placed in the MBR.

The structure of the boot sector is:

Offset Value        Assembler      Description 
in hex.             instruction
     First 3 bytes 
0000   EB29         JMP    START 
0002   90           NOP 
     BIOS parameter block (BPB) 
(* the values in the fields depend on the media *)
0003   4F4245524F4E00             ;OEM ID - 'OBERON',0 
000A   1F                         ;mask for shift status byte 
000B   0000                       ;bytes per sector 
000D   00                         ;sectors per cluster 
000E   0800                       ;reserved sectors 
0010   04                         ;table sectors 
0011   0000                       ;root directory size 
0013   0000                       ;total sectors on disk 
0015   00                         ;media descriptor 
0016   0000                       ;sectors per FAT 
0018   3F00                       ;sectors per track 
001A   0000                       ;number of heads 
001C   00000000                   ;hidden sectors 
0020   00000000                   ;total sectors of partition 
0024   00                         ;drive number 
0025   00                         ;current head 
                                  ; used for checksum 
0026   00                         ;signature 
0027   0300                       ;offset of 'OBERON' 
0029   00                         ; 
002A   00                         ; 
     Boot program 
002B   FA            CLI          ;disable interrupts 
002C   EA            JMP          ;jump 
002D   3100          ... 
.... 
     Message 
01E4   492F4F206572726F7221       ;'I/O error!' 
01EF 
01F0   08040000                   ;file system ofs in blocks 
01F4   E7000000                   ;file system size in sectors 
01F8   414F5321                   ;'AOS!' 
01FC   01                         ;version 
01FD   0C                         ;sector size log2 
01FE   55AA                       ;signature
When Oberon is running, the boot sector is displayed by executing: Partitions.ShowBlocks dev#part 0 1 ~. The same information can be obtained using the facilities of your preferred operating system or third-party software (commercial, shareware, ...).

DOS boot sector

Read "How it works: DOS Floppy Disk Boot Sector" by Hale Landis.

Linux boot sector

Read "Example Boot Sector"

[Top]

19 Mar 2008 - Copyright © 2002 ETH Zürich. All rights reserved.
E-Mail: oberon-web at inf.ethz.ch
Homepage: http://www.ethoberon.ethz.ch/