8000 GitHub - Shreongit/x86-Kernel: A minimal x86 operating system kernel written in C++, booted using GRUB, and run in QEMU. This kernel boots directly into VGA text mode and displays a simple terminal output. · GitHub
[go: up one dir, main page]

Skip to content

About

A minimal x86 operating system kernel written in C++, booted using GRUB, and run in QEMU. This kernel boots directly into VGA text mode and displays a simple terminal output.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🧠 Minimal C++ Kernel (Terminal Boot) – x86

A minimal x86 operating system kernel written in C++, booted using GRUB, and run in QEMU. This kernel boots directly into VGA text mode and displays a simple terminal output.

Designed for learning Operating System Development from scratch using modern tools.


✨ Features

  • ✅ Boots using GRUB (Multiboot)
  • ✅ Written in freestanding C++
  • ✅ VGA text-mode terminal
  • ✅ Runs on QEMU
  • ✅ Clean & beginner-friendly codebase

📁 Project Structure

.
├── boot/
│   └── grub/
│       └── grub.cfg
├── kernel/
│   ├── kernel.cpp
│   ├── terminal.cpp
│   └── terminal.hpp
├── linker.ld
├── Makefile
└── README.md

🧰 Prerequisites

This project is designed to run on Windows using WSL (Ubuntu).

Required Tools:

  • Windows 10/11 with WSL 2
  • Ubuntu (via WSL)
  • VS Code with Remote - WSL extension
  • QEMU
  • GRUB tools
  • i686-elf-gcc cross compiler

🚀 Setup Instructions

🐧 Step 1: Install WSL (Ubuntu)

Open PowerShell as Administrator and run:

wsl --install
  • Reboot when prompted
  • After reboot, open Ubuntu from Start Menu
  • Set your username and password

🔄 Step 2: Update Ubuntu

sudo apt update && sudo apt upgrade -y

🧰 Step 3: Install Required Packages

sudo apt install -y \
  build-essential \
  bison \
  flex \
  libgmp3-dev \
  libmpc-dev \
  libmpfr-dev \
  texinfo \
  grub-pc-bin \
  grub-common \
  xorriso \
  qemu-system-x86

Verify installation:

grub-mkrescue --version
qemu-system-i386 --version

🛠 Step 4: Install i686-elf-gcc Cross Compiler

Create build directory

mkdir ~/cross
cd ~/cross

Build Binutils

wget https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz
tar -xf binutils-2.41.tar.xz
mkdir build-binutils
cd build-binutils

../binutils-2.41/configure \
  --target=i686-elf \
  --prefix=/usr/local/cross \
  --with-sysroot \
  --disable-nls \
  --disable-werror

make -j$(nproc)
sudo make install

Build GCC (C & C++)

cd ~/cross
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz
tar -xf gcc-13.2.0.tar.xz
mkdir build-gcc
cd build-gcc

../gcc-13.2.0/configure \
  --target=i686-elf \
  --prefix=/usr/local/cross \
  --disable-nls \
  --enable-languages=c,c++ \
  --without-headers

make all-gcc -j$(nproc)
make all-target-libgcc -j$(nproc)
sudo make install-gcc
sudo make install-target-libgcc

Add Compiler to PATH

echo 'export PATH="/usr/local/cross/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verify:

i686-elf-gcc --version

You should see output indicating the cross-compiler is installed.


🧠 Step 5: Open Project in VS Code

  1. Install Remote - WSL extension in VS Code
  2. From Ubuntu terminal:
cd ~/your-project-folder
code .

VS Code will reopen inside WSL.


▶️ Step 6: Build & Run the Kernel

In the VS Code terminal (or Ubuntu terminal):

make clean
make
make run

A QEMU window will open showing:

Welcome to My C++ Kernel!
Booted successfully into terminal mode.

🧯 Troubleshooting

❌ i686-elf-gcc: command not found

Solution:

source ~/.bashrc

Make sure /usr/local/cross/bin is in your PATH.


❌ grub-mkrescue: command not found

Solution:

sudo apt install grub-pc-bin xorriso

❌ Black screen in QEMU

Check:

  • Architecture is i686
  • Kernel is compiled with -ffreestanding
  • GRUB config path is correct in boot/grub/grub.cfg
  • Multiboot header is properly defined in kernel.cpp

❌ GCC Build Fails

Common issues:

  • Missing dependencies: ensure all packages from Step 3 are installed
  • Disk space: cross-compiler builds require ~5GB
  • Build time: GCC compilation can take 20-60 minutes depending on your CPU

📚 Learning Resources


🚀 Future Improvements

  • Keyboard driver
  • Scrollable terminal
  • Interrupt handling (IDT)
  • Memory management
  • 64-bit long mode
  • Simple shell

📜 License

MIT License – Feel free to fork, modify, and learn.


🤝 Contributing

Pull requests are welcome! If you're learning OS development, this project is a great starting point.


🙏 Acknowledgments

Special thanks to the OSDev community for their extensive documentation and resources.


Happy hacking! 🚀

About

A minimal x86 operating system kernel written in C++, booted using GRUB, and run in QEMU. This kernel boots directly into VGA text mode and displays a simple terminal output.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0