Logo

dev-resources.site

for different kinds of informations.

Writing a bootloader: learnings

Published at
4/11/2024
Categories
kernel
bootloader
c
Author
sarthak889
Categories
3 categories in total
kernel
open
bootloader
open
c
open
Author
10 person written this
sarthak889
open
Writing a bootloader: learnings
  1. The instruction pointer of the CPU, on boot, is hardcoded to the value 0xFFFFFFF0 i.e. the last 16 bytes of the 32-bit address space.

  2. On boot, the BIOS copies itself to some address in memory.
    So, the address contains 0xFFFFFFF0 contains a jump instruction to the place in memory where the BIOS has copied itself.

  3. Once the BIOS is loaded, it goes through the list of devices to check which are bootable: by checking the bytes 511 and 512 of the first sector of each device. If the value of those bytes is 0xAA55, that device is bootable.

  4. Once a bootable device is found, copy the contents of the device's first sector into memory to the address 0x7c00. This address now contains the bootloader. Jump to this address and execute the code. The bootloader then loads the kernel at 0x100000.

Fun facts:

  1. All x86 processors begin in a 16-bit mode called real mode. The bootloader switches to 32-bit protected mode by setting the lowest bit of CR0 register to 1.

  2. 0xb8000 is the start of video memory. This memory supports 25 lines, each line contains 80 ASCII characters. Each element here is of 2 bytes (1 byte for the ASCII character, 1 byte is the attribute byte like color). So, we can set the color of each character we want to display by writing bytes starting from this address.

kernel Article's
30 articles in total
Favicon
Ditana GNU/Linux: Unmatched Configuration Flexibility and Generic Hardware Detection
Favicon
I added networking standards to my custom kernel!
Favicon
I'm building my own kernel!
Favicon
Bash vs. Shell: The Ultimate Comparison
Favicon
x64 Virtual Address Translation
Favicon
Debian 12: NVIDIA Drivers Installation
Favicon
Exploring the Linux Kernel and Switching Kernels on Arch Linux & Snigdha OS in Short!
Favicon
All About Linux: A Comprehensive Guide
Favicon
Exploring Applications That Fully Utilize the Linux Kernel for Maximum Efficiency
Favicon
Raspberry Pi 4B: Natively Build a 64 Bit Fully Preemptible Kernel (Real-Time) with Desktop
Favicon
How to Configure a Network Block Device on a Debian-BasedΒ System
Favicon
Kernel vs Operating System
Favicon
C++ in Kernel Development: A Comprehensive Guide
Favicon
The Importance of Separating Kernels and Userspace in Modern Computing Systems
Favicon
Written by a 16 year old, a book on how computers work
Favicon
The Linux Audacity
Favicon
How to cross compile linux kernel on MacOS
Favicon
esBPF: Stress-Testing compares Software-Offload with iptables
Favicon
Commentary on CrowdStrike BSOD Root Cause Analysis Release
Favicon
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---
Favicon
eBPF: Revolutionizing Linux Kernel Programming
Favicon
The Fundamentals of Support Vector Machines
Favicon
Understanding Docker Containers: Leveraging Linux Kernel's Namespaces and cgroups
Favicon
Understanding the Structural Differences Between BSD-based Kernels and Linux Kernels
Favicon
nvidia-dkms-545 error in Ubuntu 24.04
Favicon
AppArmor testsuite
Favicon
From User to OS: Exploring System Calls with glibc through a Restaurant Analogy
Favicon
Writing a bootloader: learnings
Favicon
Instalando kernel Linux Zen no Arch Linux com systemd-boot πŸ§‘πŸ½β€πŸ’»
Favicon
Kernel Internals and Kernel Module Development in Fedora Linux

Featured ones: