SLP Lab BootLoader e
SLP Lab BootLoader e
________________________________________________________________________
1. Overview
Every operating system is responsible for enabling other programs to be run. However,
who enables the operating system? This function is performed by a small program known
as the bootloader. Although bootloaders take a different form with each computer
architecture, the core ideas remain the same. In this project, you will create a bootloader for
the x86 architecture.
In the x86 architecture, the bootup procedure looks for a bootloader on the first sector of
the booting device (a USB flash disk, hard drive, image file, etc.) and is automatically
loaded and executed during the system booting process. It is responsible for loading the rest
of the operating system from the booting device into memory. The bootloader cannot rely
upon any functionality from the operating system, such as OS calls for disk I/O, or linking
an object file against static libraries. However, the x86 architecture requires the presence of
the Basic Input Output System (BIOS), which provides minimal terminal, keyboard and
disk support. The bootloader will use these BIOS calls to load the kernel from disk into
memory, set up a stack space, and then switch control to the kernel. At this point, the OS
begins running.
The first 512 bytes of a disk are known as the boot sector or Master Boot Record. The boot
sector is an area of the disk reserved for booting purposes. If the boot sector of a disk
contains a valid boot sector (the last word of the sector must contain the signature 0xAA55),
then the disk is treated by the BIOS as bootable.
In the lab, we'll write a bootloader that displays "Hello, World!" in assembly language. Just
for fun.
The bootloader:
Stored in the Master Boot Record (MBR), on the first sector of the disk
Size is exactly 1 sector, or 512 bytes
Ends with a signature of 0x55 and 0xaa at bytes 511 and 512
Loaded by the BIOS POST interrupt 0x19 at address 0x7c00
Runs in 16 bits mode
Keep in mind that we have no file system and no operating system. No DOS, no Windows,
no Linux and none of the associated interrupts, libraries and routines.
1
System Level Programming Bootloader Lab 2
________________________________________________________________________
https://www.nasm.us/
You may download the zip version. And simply unzip the file.
After installation, type “cmd” in the Windows search bar, then enter the following
command:
nasm -v
This command will show nasm version you just have installed in your computer.
You may need to edit an Environment Variable in Windows to make this work.
Tip: In the System Properties window, click on the Advanced tab, then click the
Environment Variables button near the bottom of that tab. In the Environment
Variables window, highlight the Path variable in the "System
variables" section and click the Edit button. Then add the nasm directory you just installed.
2
System Level Programming Bootloader Lab 3
________________________________________________________________________
https://docs.oracle.com/cd/E26217_01/E26796/html/qs-create-vm.html
Check the above link to get help on how to create a new virtual machine in VirtulBox.
3
System Level Programming Bootloader Lab 4
________________________________________________________________________
3) Create a virtual floppy disk by VirtualBox
In Oracle VirtualBox, it is possible to add a floppy drive to a virtual machine. Virtual
floppy drives, like virtual CD/DVD drives, can be connected to either a host floppy drive
(if you have one) or a disk image, which must be in RAW format.
Here are the steps to add a floppy drive to a virtual machine in Oracle VirtualBox:
Select the virtual machine from the Oracle VM VirtualBox Manager and choose Settings:
--------------------------------------boot.asm------------------------------------------------------
4
System Level Programming Bootloader Lab 5
________________________________________________________________________
org 07c00h ;
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ;
jmp $ ;
DispStr:
mov ax, BootMessage
mov bp, ax ;
mov cx, 16 ;
mov ax, 01301h ;
mov bx, 000ch ;
mov dl, 0
int 10h ;
ret
BootMessage: db "Hello, OS world!"
times 510-($-$$) db 0 ;
;
dw 0xaa55
----------------------------------boot.asm--------------------------------------------------------------
1) Compile your “boot.asm” by NASM assembler. You need to install the NASM first.
Open the nasm, compile the boot.asm file to binary file boot.bin which size of 512 bits by
the following command:
5
System Level Programming Bootloader Lab 6
________________________________________________________________________
3) Write the BootLoader boot.bin to virtual floppy disk of virtual machine use tool
FloppyWriter. Remember it should be done in the first sector of floppy disk.
Open FloppyWriter,
6
System Level Programming Bootloader Lab 7
________________________________________________________________________
In VirtualBox Workstation, click “Power on your virtual machine”, you should see the
“hello” message print out to screen.
7
System Level Programming Bootloader Lab 8
________________________________________________________________________
3. Your task
3.1 Study boot.asm source code, write comments for each line of code.
3.2 Change the source code of this assembly program. The new program should show your
student id and name on the screen. Show me the source code and the screen shot of testing.