You are on page 1of 6

BOOTING PROCESS

INTRODUCTION
When the computer starts, the processor starts executing instructions at the memory address 0xffff. This is usually a location in the BIOS ROM. Thus the BIOS code is executed by the processor. The first thing that occurs is that it sends a signal to motherboard which in turn starts the power supply. After supplying the correct amount of power to each device, it sends a signal called "Power OK" to BIOS which resides on motherboard.Once the BIOS receive the "Power OK" signal, it starts the booting process by first initializing a process called POST (Power On Self Test). POST first checks that every device has right amount of power and then it checks whether the memory is not corrupted. Then it initializes each device and finally it gives control to BIOS for further booting.Now the final process of booting begins. Boot loader or Bootsector is a program situated at the first sector of the hard drive; and it is the sector where the boot starts from. For this the BIOS first finds 512 bytes of image called MBR (Master Boot Record) or Bootsector from the floppy disk or hard disk which is used for booting. The priority of boot devices is set by the user in BIOS setting. The normal priority is floppy disk first, then hard disk. Once BIOS finds the bootsector it loads the image in memory and executes it. If a valid bootsector is not found, BIOS checks for next drive in boot sequence until it finds a valid bootsector. If BIOS fails to get valid bootsector, generally it stops the execution and gives an error message "Disk boot failure".It is bootsectors responsibility to load the operating system in memory and execute it.

MASTER BOOT RECORD


A device is "bootable" if it carries a boot sector with the byte sequence 0x55, 0xAA in bytes 511 and 512 respectively. When the BIOS finds such a boot sector, it is loaded into memory at a specific location; this is usually 0x0000:0x7c00 (segment 0, address 0x7c00). However, some BIOS loads it to 0x7c0:0x0000 (segment 0x07c0, offset 0), which resolves to the same physical address. On a hard drive, the so-called Master Boot Record (MBR) holds executable code at

offset 0x0000 - 0x01bd, followed by table entries for the four primary partitions, using sixteen bytes per entry (0x01be - 0x01fd), and the two-byte signature (0x01fe - 0x01ff). The layout of the table entries is as follows:
Offset Size (bytes) Description

0x00

Boot Indicator (0x80=bootable, 0x00=not bootable)

0x01

Starting Head Number

0x02

Starting Cylinder Number (10 bits) and Sector (6 bits)

0x04

Descriptor (Type of partition/filesystem)

0x05

Ending Head Number

0x06

Ending Cylinder and Sector numbers

0x08

Starting Sector (relative to begining of disk)

0x0C

Number of Sectors in partition

TESTING BOOTLOADER
Boot loader can be tested on the real hardware or using specially designed for such purposes virtual machine VirtualBox. VirtualBox is an open-source hypervisor platform which creates a virtualized computing environment for virtual machines. This allows a host computer to run multiple guest operating systems simultaneously. It creates virtual hardware devices that guest operating systems can install on and us. To test boot loader we created a new virtual machine with minimal disk size for example 1 Gb.

NASM
The assembler used here is NASM (Netwide Assembler). NASM is an 80x86 assembler designed for portability and modularity. It supports a range of object file formats, including Linux and NetBSD/FreeBSD a.out, ELF, COFF, Microsoft 16bit OBJ and Win32. It outputs plain binary files.
nasm -f bin -o myfirst.bin myfirst.asm

Here we assemble the code from our text file into a raw binary file of machinecode instructions. With the -f bin flag, we tell NASM that we want a plain binary file (not a complicated Linux executable - we want it as plain as possible!). The -o myfirst.bin part tells NASM to generate the resulting binary in a file called myfirst.bin.

Floppy Disk
VirtualBox can create a virtual floppy disk drive that uses a floppy disk image file on the computer. The virtual machine can access the floppy disk image like a real floppy disk drive, including booting from the floppy disk image inside the virtual machine.Floppy disk image is created from Virtual Machines Storage category in the settings window,then adding Floppy Device in the Floppy Controller.Then clicking on Choose Disk creates floppy disk image file in the disk_images/ directory.

Compiling / Assembling
Now when the code is developed we need to transform it to the file for the 16-bit OS. Such files are .com files. We can start each of compilers (for Assembler and C, C++) from the command line, transmit necessary parameters to them and obtain several object files as the result. Next we start linker to transform all .obj files to the one executable file with .com extension.We compile our bootloader using NASM. For that the command is:
nasm ourbootloader.asm -f bin -o boot.bin

This will create a file boot.bin.

Copying bootsector to floppy disk


Now we need a virtual floppy disk image to which we can write our bootloadersized kernel. Copy .flp from the disk_images/ directory into your home directory, and rename it myfirst.flp. Then enter:
dd status=noxfer conv=notrunc if=myfirst.bin of=myfirst.flp

This uses the 'dd' utility to directly copy our kernel to the first sector of the floppy disk image.

IMPLEMENTATION OF COMMAND LINE INTERFACE


BIOS proposes a number of interrupts for the work with computer hardware such as video adapter, keyboard, disk system.CLI is implemented with use of BIOS Interrupts like 10h and 13h,setting different values in register to implement each of these functionalities.User can type words, display message, use backspace and reboot.To show our message on the screen we should clear it first. We will use special BIOS interrupt for this purpose. Each interrupt has the certain number of parameters that should be set before calling it. The ah processor register is always responsible for the number of function for the current interrupt, and the other registers are usually used for the other parameters of the current operation.

COMMANDS IMPLEMENTED
Restart
When the computer starts, the processor starts executing instructions at the memory address FFFF:0000. This is usually a location in the BIOS ROM. Thus the BIOS code is executed by the processor which finds the boot device.Thus Jump to location memory address FFFF:0000 is made.

EXPLANATION OF SOME LINES OF CODE


[BITS 16]: Our code starts with [BITS 16] which is an assembler directive. This will tell assembler that our code is a 16 bit code.

[ORG 0x7C00]: Then we have used [ORG 0x7C00] which tell assembler to assemble the instructions from Origin 0x7C00. BIOS loads bootloader at physical address 0x7C00 hence we have assemble our bootloader starting from that location. JMP $: JMP at location $ means jumping to the same location. Thus this nothing but an infinite loop. We just want to hang our code here. TIMES 510 - ($ - $$) db 0: As bootloader is always of length 512 bytes, our code does not fit in this size as its small. We need to use rest of memory and hence we clear it out using TIMES directive. $ stands for start of instruction and $$ stands for start of program. Thus ($ - $$) means length of our code. DW 0xAA55: This is boot signature. This tells the BIOS that this is a valid bootloader. If bios does not get 0x55 and 0xAA at the end of the bootloader than it will treat bootloader as invalid. Thus we provide this two bytes at the end of our bootloader. For printing we will use BIOS video interrupt int 0x10.
INT 0x10 is a BIOS video interrupt. All the video related calls are made through this interrupt. To use this interrupt we need to set the values of some register. AL = ASCII value of character to display AH = 0x0E ;Teletype mode (This will tell bios that we want to print one character on screen) BL = Text Attribute (This will be the fore ground and background color of character to be displayed. 0x07 in our case.) BH = Page Number (0x00 for most of the cases) Once all the registers all filled with appropriate value, we can call interrupt.

You might also like