3. 3 | P a g e
BOOT DISK
A boot disk is actually not a computer disk in the shape of a boot. If it was, most disk drives
would have a difficult time reading it. Instead, a boot disk is a disk that a computer can start up
or "boot" from. The most common type of boot disk is an internal hard drive, which most
computers use to start up from. The operating system installed on the hard drive is loaded
during the boot process.
However, most computers allow you to boot from other disks, including external Firewire hard
drives, CD-ROMs, DVD-ROMs, and floppy disks. In order to function as boot disks, these disks
need to have an operating system installed that is understandable by the computer. This can
either be a full-blown operating system like Windows or Mac OS X, or a small utility operating
system, such as Norton Utilities or Disk Warrior.
CD and DVD boot disks are often used to start up a computer when the operating system on
the internal hard drive won't load. This can happen when bad data blocks or other errors occur
on the disk. By running a disk repair utility from the CD or DVD, you can often fix the hard drive
and restart from it, using the full operating system.
What is Boot Loader
Boot loader is a program situated at the first sector of the hard drive; and it is the sector where
the boot starts from. BIOS automatically read all content of the first sector to the memory just
after the power is turned on, and jump to it. The first sector is also called Master Boot
Record. Actually it is not obligatory for the first sector of the hard drive to boot something. This
name has been formed historically because developers used to boot their operating systems
with such mechanism.
How system boots
In order to solve our task we should recall how the system is booting.
Let’s consider briefly how the system components are interacting when the system is
booting (see Fig.1).
4. 4 | P a g e
After the control has been passed to the address 0000:7C00, Master Boot Record (MBR) starts
its work and triggers the Operating System boot.
Let’s code
In the next sections we will be directly occupied with the low-level programming – we will
develop our own boot loader.
5. 5 | P a g e
Source code of Boot Loader
[BITS 16] ; 16 bit code generation
[ORG 0x7C00] ; Origin location
; Main program
Main: ; Label for the start of the main program
Mov ax, 0x0000 ; Setup the Data Segment register
; Location of data is DS: Offset
Mov ds, ax ; This cannot be loaded directly it has to be in two steps.
; 'mov ds, 0x0000' will NOT work due to limitations on the CPU
Mov si, HelloWorld ; Load the string into position for the procedure.
Call PutStr ; Call/start the procedure
Jmp $ ; Never ending loop
; Procedures
PutStr: ; Procedure label/start
; Set up the registers for the interrupt call
Mov ah,0x0E ; The function to display a chacter (teletype)
Mov bh,0x00 ; Page number
Mov bl,0x07; Normal text attribute
.nextchar ; Internal label (needed to loop round for the next character)
Lodsb ; I think of this as Load String Block
; (Not sure if that's the real meaning though)
; Loads [SI] into AL and increases SI by one
; Check for end of string '0'
or al,al ; Sets the zero flag if al = 0
; (OR outputs 0's where there is a zero bit in the register)
jz .return ; If the zero flag has been set go to the end of the procedure.
; Zero flag gets set when an instruction returns 0 as the answer.
int 0x10 ; Run the BIOS video interrupt
jmp .nextchar ; Loop back round tothe top
.return ; Label at the end to jump to when complete
Ret ; Return to main program
; Data
HelloWorld db 'C:Windows',13,10,0
; End Matter
6. 6 | P a g e
times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55The Boot Loader that we have made Assembly Is totally depend on the
above Piece of code
nasm -f bin -o floppy.img new.asm
The followingBOOTLOADER we used to create a File:
NASM: The Netwide Assembler (NASM) is an assembler and disassembles for the Intel x86
architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. NASM
is considered to be one of the most popular assemblers for Linux and is the second most
popular assembler overall.