Raam Raam ji (greeting with god's name :) ). Hello world. This is our first blog post in the operating system development series.
Today, we will try to address this fundamental question - "How does an OS (Operating System) boot? What happens first?"
Let's get our hands dirty. Let us learn by doing. So it is the "firmware", the UEFI firmware on modern systems that is responsible for loading and calling your OS boot loader's entry point.
If you don't know what is UEFI, it stands for "Unified Extensible Firmware Interface". You don't need to know what is it. Just know that it is both different and newer than BIOS (Basic Input/Output System). It's a firmware that loads your OS's boot loader into RAM and calls its entry point. Simple!
Now what is a boot loader? It is a boot program that performs some initialization tasks, loads the kernel file into memory, and provides the kernel with the information it needs to work correctly.
So the first system program that runs after booting by the firmware is your boot loader which in turns loads and jumps to your kernel's entry point. A kernel is the core and central component of an OS. The userspace program like your shell runs later.
1. Enough theory! Now let's create a simple boot loader that does nothing but goes into an infinite loop and you will test it on your real machine:
format pe64 efi
entry start
section '.text' code executable readable
start:
; infinite loop
jmp $
Open your favorite text editor (I like `vim`) and paste the above code. Save it as
boot.asm
and then on a 64-bit Ubuntu like machine, install fasm assembler
with apt install fasm
. Then run the following command:
fasm boot.asm BOOTx64.EFI
On successful passes, you will get the output file `BOOTx64.EFI`.Finally, `jmp $` tells the program control to jump to the present address (which is this line itself) and so it goes into an infinite loop.
No comments:
Post a Comment