1 Bootloader
In this first Assignment, you will build the basic environment that is needed to develop the operating
system (OS) for the rest of the semester; the bootloader. The bootloader is responsible for loading the
kernel when the PC first boots up. Your job for this assignment is to write x86 code that will do the
following:
1. Print a string of length > 1 while in 16-bit real mode (using the BIOS routines).
2. Load the kernel from disk
3. Switch to 32-bit protected mode
4. Print a string of length > 1 while in 32-bit protected mode.
5. Exec your kernel
6. There should be an X in the top left of your qemu screen. Which means your kernel has been
successfully loaded.
Read about makefiles and use a makefile.
All of the steps are discussed in the book [Link], so you can check out the book for more.
1.1 Submission & Due date
Zip your code and send it to sisaystifanos@[Link] using the subject “OS lab - bootloader”, by
August 22(Section 2) and August 23(Section 1) by 11:59PM. Be sure to check out the Delivarables &
Directory Structure subsections when organizing your code.
The Name of your zip file –> Your_Full_name-[Link]
(Keep in mind that you will present your code. I’ll notify you of the time and date.)
1.2 Assembly Conventions
• You are only allowed to use AT&T syntax for developing the bootloader. (i.e no intel syntax)
• You are only allowed to use the stack to pass arguments.(i.e You’re not allowed to use registers
to pass args.)
• Use comments
1.3 Delivarables
boot.s – This should be your main file, containing the _start function.
1
1.3.1 16-bit real mode.
disk_loader.s – This file should contain the implementation for the function that will load n sectors
from HDD, starting from the 2nd sector. It should accept 2 parameters:
1. Number of sectors to read
2. Where, in memory, to put the read sectors
print_hex.s – This file already contains the implementation for printing Hexadecimal digits. Your
job is to re-implement it using loops. It accepts 1 argument:
1. The number to display its hexadecimal notation.
print_str.s – This file should contain the implementation for the function that will print null termi-
nated strings. It accepts 1 argument:
1. The address of the null terminated string.
switch_to_pm.s – This file will contain the code necessary to make the switch from 16-bit real mode
to 32-bit protected mode.
(Check the [Link] book pages 30-41)
gdt.s – This file will contain the code for The Global Descriptor Table.
(Check the [Link] book pages 30-41)
1.3.2 32-bit protected mode.
print_str32.s – This file should contain the implementation for the function that will print null
terminated strings. This shouldn’t use BIOS. It accepts 1 argument :
1. The address of the null terminated string.
(Check the [Link] book pages 31-32)
1.3.3 C code
kernel.c – This is your kernel code, we will add other things to it in the future but for now, it should
just print an ‘X’ in the top left corner of the qemu screen.
(Check the [Link] book pages 49-54)
2
1.3.4 Misc
kernel_entry.s – this is just a small code needed to make sure we jump on main when the kernel is
loaded and executed. (Check the [Link] book pages 49-54)
1.3.5 Makefile and Readme
Read about makefiles and use one. Additionally include a readme file describing what you did, how to
assemble/compile, and run your project.
in order to compile:
• your kernel use gcc -ffreestanding -m32 -c kernel.c -o kernel.o
• your entry file as --32 -o kernel_entry.o kernel_entry.s
• to link the two to [Link] ld -o [Link] -Ttext 0x1000 kernel_entry.o
kernel.o --oformat binary -m elf_i386 (I am assuming here that 0x1000 is the
location in memory that you loaded you kernel in, change it if you intend to load you kernel to
another location)
In order to trim our [Link] code to 512 bytes: head -c 512 [Link] > boot_trimed.bin
To create our OS image: cat boot_trimed.bin [Link] > os-img
1.4 Directory structure
You can follow any directory structure you like, but make sure it is organized and modular! Below i
have included a recommended directory structure. (Next page)
3
Figure 1: dir structure