Skip to content

Instantly share code, notes, and snippets.

@mudassaralichouhan
Last active October 21, 2025 14:24
Show Gist options
  • Select an option

  • Save mudassaralichouhan/05b84b85fa01de69f0e555a6b6cdbbe5 to your computer and use it in GitHub Desktop.

Select an option

Save mudassaralichouhan/05b84b85fa01de69f0e555a6b6cdbbe5 to your computer and use it in GitHub Desktop.
Operating System Kernel is one of the best ways to truly master computer systems

That’s awesome — learning assembly language for OS boot development is one of the best ways to understand how computers really work. 💻

Let’s build a structured roadmap together so you can go from zero to writing your own bootable OS in assembly.


🧩 Step 1: Understand the Big Picture

When a computer boots, it goes through this process:

  1. Power on → BIOS/UEFI runs
  2. BIOS loads the bootloader from the first sector of the boot disk (512 bytes, called the boot sector)
  3. The bootloader runs in 16-bit real mode
  4. The bootloader sets up the system (memory, segments, etc.)
  5. It loads and jumps to your kernel (which can be in assembly or C)

So your first goal is to write a bootloader in assembly that can:

  • Run in 16-bit real mode
  • Print text on the screen
  • Load another program (like your kernel)

⚙️ Step 2: Set Up Tools

You’ll need a few tools to assemble and test your code:

Tool Purpose Install
NASM Assembler sudo apt install nasm or brew install nasm
QEMU Emulator for testing sudo apt install qemu
dd To write boot sectors Preinstalled on Linux/macOS
hex editor (optional) to inspect binaries e.g. xxd, HxD, etc.

You’ll be writing .asm files, assembling them with nasm, and testing them in QEMU.


🧱 Step 3: Your First Bootloader

Let’s make a simple “Hello, world” boot sector.

File: boot.asm

; boot.asm - simple bootloader

BITS 16                  ; We're in 16-bit real mode
ORG 0x7C00               ; BIOS loads the boot sector here

start:
    mov si, message       ; Point to our string
    call print_string     ; Print it
    jmp $                 ; Infinite loop (halt here)

print_string:
    lodsb                 ; Load next char from [SI] into AL
    or al, al             ; Check if null terminator (AL == 0?)
    jz done               ; If yes, we're done
    mov ah, 0x0E          ; BIOS teletype function
    int 0x10              ; Print character in AL
    jmp print_string

done:
    ret

message db "Hello from Bootloader!", 0

times 510-($-$$) db 0     ; Pad up to 510 bytes
dw 0xAA55                 ; Boot signature

🔧 Step 4: Assemble and Run It

nasm -f bin boot.asm -o boot.bin
qemu-system-x86_64 -drive format=raw,file=boot.bin

If everything’s right, you’ll see:

Hello from Bootloader!

🎉 Congratulations — you just wrote a working bootloader in pure assembly!


🧠 Step 5: Next Steps

Once you understand this basic bootloader, the next things to learn are:

  1. Real Mode basics — registers, memory addressing, segment:offset
  2. BIOS interrupts (for I/O, disk reads, etc.)
  3. Loading a kernel from disk
  4. Switching to 32-bit protected mode
  5. Writing your kernel in C or assembly
  6. (Optional) Moving to 64-bit long mode

📚 Recommended Learning Path

  • 🔹 Book: “Programming from the Ground Up” by Jonathan Bartlett (great intro to assembly)
  • 🔹 Book: “Operating Systems: From 0 to 1” (free online)
  • 🔹 Tutorial series: os-dev wiki → the “Bare Bones” tutorial
  • 🔹 YouTube: “Write your own OS” by Low Level Learning or Poncho

Would you like me to make a step-by-step mini course (like a week-by-week plan) where each day you build a new piece — from bootloader → kernel → basic OS shell? That’s the best way to stay consistent.

🧭 OS Development Roadmap (Step-by-Step)


⚙️ Phase 0 — Setup & Foundations

🎯 Goal:

Set up your development environment and understand what happens when a computer boots.

🧩 Steps:

  1. Learn key concepts:

    • How a CPU boots (BIOS/UEFI → Bootloader → Kernel)
    • What an interrupt is
    • What virtual memory and paging are
  2. Set up tools:

    • Language: Assembly + C
    • Emulator: QEMU (to test your OS)
    • Cross-compiler: i686-elf-gcc or x86_64-elf-gcc
    • Build tools: make, nasm or gas, ld, grub
  3. Recommended resources:

    • OSDev Wiki
    • “The Little Book About OS Development” (free PDF)
    • YouTube: “Write your own Operating System” by Poncho / Tsoding

🧾 Phase 1 — Bootloader (Assembly)

🎯 Goal:

Get your computer (or QEMU) to load and run your code.

🧩 Steps:

  1. Write a bootloader in Assembly (512 bytes):

    • Must end with the magic number 0xAA55
    • Loads the kernel from disk into memory
    • Switches CPU from Real Mode → Protected Mode
  2. Display text (“Hello from my OS!”) using BIOS interrupts or VGA memory.

  3. Test using:

    qemu-system-x86_64 -drive format=raw,file=myos.img
  4. (Optional) Use GRUB instead of your own bootloader to simplify.


💻 Phase 2 — Kernel Initialization (C + Assembly)

🎯 Goal:

Transition from bootloader to C code and print something from your kernel.

🧩 Steps:

  1. Write a minimal kernel entry point in Assembly:

    • Set up stack pointer
    • Call your C function: kmain()
  2. In C, implement:

    void kmain(void) {
        printf("Welcome to MyOS Kernel!\n");
        while(1);
    }
  3. Create your own simple printf() using VGA memory (0xB8000).

  4. Now you have a “Hello World” kernel!


🧠 Phase 3 — Interrupts and Exceptions

🎯 Goal:

Handle CPU interrupts and exceptions properly.

🧩 Steps:

  1. Learn about:

    • Interrupt Descriptor Table (IDT)
    • Interrupt Service Routines (ISRs)
    • Interrupt Request (IRQ) lines
  2. Implement:

    • IDT setup in C/Assembly
    • ISRs for CPU exceptions (divide by zero, general protection fault, etc.)
    • IRQs for hardware (keyboard, timer)
  3. Add a keyboard driver:

    • Capture keyboard input via PS/2 port
    • Print pressed keys to the screen

✅ You’ve now handled hardware-level input.


🧮 Phase 4 — Memory Management

🎯 Goal:

Understand and implement how your kernel manages memory.

🧩 Steps:

  1. Learn about:

    • Physical vs. virtual memory
    • Paging (4 KB pages)
    • Page tables and directories
  2. Implement:

    • Physical memory manager (bitmap of free/used pages)
    • Virtual memory manager (page mapping)
    • Basic kmalloc() and kfree() (your own malloc/free)
  3. Test:

    • Allocate and free blocks.
    • Display memory map at boot.

🧵 Phase 5 — Task Switching and Multitasking

🎯 Goal:

Allow multiple “processes” (or threads) to run.

🧩 Steps:

  1. Understand:

    • Context switching
    • CPU registers saving/restoring
    • Timer interrupts
  2. Implement:

    • Task structure (stack, registers)
    • Scheduler (round-robin, cooperative)
    • Context switch using timer IRQ (PIT)
  3. You’ll see multiple “tasks” printing alternately → proof of multitasking!


💾 Phase 6 — File System (Optional)

🎯 Goal:

Add basic file I/O to your OS.

🧩 Steps:

  1. Implement:

    • RAM-based file system (RAMFS) first
    • Basic read/write/open system calls
    • Directory structure
  2. Later: try parsing FAT12/FAT32 from a disk image.


🌐 Phase 7 — User Mode (Optional, Advanced)

🎯 Goal:

Run programs in user mode safely (ring 3).

🧩 Steps:

  1. Implement:

    • CPU privilege levels (ring 0 vs. ring 3)
    • Syscalls (int 0x80 or syscall instruction)
    • Process isolation with paging
  2. Write a tiny “user program” and load it from disk or memory.


🎨 Phase 8 — Polish & Presentation

🎯 Goal:

Make your project portfolio-ready.

🧩 Steps:

  1. Add a simple shell (command-line interface)
  2. Create documentation (README + diagrams)
  3. Record a demo running in QEMU
  4. Push to GitHub with build scripts and screenshots
  5. (Optional) Add a simple GUI later using VESA graphics mode

🧰 Tools & Resources

Category Recommended
Emulator QEMU
Assembler NASM / GAS
Compiler GCC cross-compiler (i686-elf-gcc)
Bootloader GRUB
Debugger GDB with QEMU
Learning OSDev Wiki, LittleOSBook, xv6 source code
Reference OS xv6-public (MIT)

🗓️ Suggested Timeline (If You Study Part-Time)

Phase Duration Focus
0–1 1 week Environment + Bootloader
2 1 week Kernel Init
3 2 weeks Interrupts + Drivers
4 2–3 weeks Memory Management
5 2–3 weeks Multitasking
6–8 3–4 weeks Filesystem + Shell + Docs

➡️ Total: ~10–14 weeks (2–3 months part-time)


🚀 Pro Tips for Success

  • Test early, test often: Run each stage in QEMU, not real hardware.

  • Keep commits small: Each commit = one working feature.

  • Document your learning in a blog or README — Google recruiters love this.

  • Read other small OS projects like:

That’s an excellent goal — you clearly have the passion and technical curiosity to go deep. Reimplementing something like Linux 0.0.1 from scratch is an ambitious but achievable project if you approach it with discipline, structure, and incremental milestones.

Let’s work this out together step by step — given your long working hours (9:30 AM – 10:30 PM), we’ll create a realistic, low-time, high-impact schedule and a structured roadmap for mastering low-level programming and implementing your own minimal Linux-like kernel.


🧭 Step 1: Define the Goal Clearly

Ultimate goal: Recreate Linux 0.0.1 from scratch — understand and implement its components (bootloader, kernel, system calls, scheduler, etc.).

Intermediate goals:

  1. Deepen understanding of C and Assembly (x86 or x86_64).
  2. Learn OS fundamentals (memory management, interrupts, context switching, etc.).
  3. Write a bootable minimal kernel.
  4. Expand it step-by-step into a Linux-like system.

🕰️ Step 2: Time Reality Check

You work 9:30 AM – 10:30 PM — that’s 13 hours of work. Let’s assume:

  • 7 hours sleep (11 PM – 6 AM)
  • 1 hour for meals & hygiene
  • Remaining usable time: 1.5 hours/day on weekdays
  • Weekends: potentially 4–6 hours/day

That’s ~10–12 hours/week, which is plenty if used efficiently and consistently.


📅 Step 3: Sample Weekly Schedule

Day Time Focus
Mon–Fri 6:00 AM – 7:00 AM Study (theory + reading + planning)
Sat 9:00 AM – 1:00 PM Coding and experimentation
Sun 9:00 AM – 12:00 PM Review, documentation, planning next week

💡 You do thinking and learning on weekdays (light brain work), and deep work and coding on weekends (heavy creative work).


🧱 Step 4: Project Roadmap (Practical & Achievable)

Phase 1 — Foundations (1–2 months)

Goal: Build strong low-level understanding.

  • Learn C deeply (especially pointers, memory, structs, inline assembly)
  • Learn x86 assembly basics (registers, interrupts, real vs protected mode)
  • Study how a CPU boots and loads an OS
  • Read “Operating Systems: From 0 to 1” or “Writing a Simple Operating System — from Scratch”

Milestone: Write a simple bootloader that prints “Hello from my kernel”.


Phase 2 — Bootloader & Minimal Kernel (2 months)

Goal: Create your own bootloader and enter protected mode.

  • Write bootloader in Assembly
  • Load a small C kernel from disk
  • Implement basic printing (using VGA memory)
  • Add interrupt descriptor table (IDT)
  • Handle keyboard input

Milestone: You have a minimal kernel that boots and takes input.


Phase 3 — Core Kernel Components (3–4 months)

Goal: Implement the heart of your Linux-like system.

  • Memory management (paging, heap)
  • Task switching (simple scheduler)
  • System calls
  • Simple filesystem (e.g., read/write from disk)

Milestone: You can run small programs on your kernel.


Phase 4 — Expand and Refine (ongoing)

Goal: Turn it into a miniature Linux.

  • Add user space
  • Implement shell-like interface
  • Study and replicate Linux 0.0.1 features

Milestone: You can boot into your own shell and run simple commands.


🧠 Step 5: Practical Study Method

When you’re tired after work, don’t code — study.

  • Weekdays: Read OS dev guides, take notes, plan what to implement next.
  • Weekends: Implement your planned features.
  • Use small goals: e.g., “this weekend I’ll make the bootloader print text.”

Tools you’ll need:

  • QEMU (for virtual testing)
  • NASM or GAS (assembler)
  • GCC / Clang (cross compiler)
  • Make / CMake
  • Git (version control)

🔥 Step 6: Motivation System

Because your job is long, motivation will come and go. So:

  • Track your progress weekly in a notebook or Git log.
  • Keep your project public (GitHub) — it keeps you accountable.
  • Every small milestone (boot screen works, kernel loads) is worth celebrating.

✅ Example Weekly Plan (Micro-level)

Day Task Duration
Mon Read “How computers boot” (30 min) 30 min
Tue Study x86 registers 45 min
Wed Watch a 20 min OS dev tutorial 30 min
Thu Plan weekend coding goals 15 min
Fri Review notes, mental rest 15 min
Sat Implement bootloader code 3–4 hrs
Sun Debug and document 2–3 hrs

If you’d like, I can create a personalized 12-month roadmap (with exact weekly milestones and reading/coding plan) based on your pace and background in C/Assembly.

Would you like me to make that detailed 12-month schedule for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment