A monolithic kernel implemented from scratch in C and x86 Assembly, featuring round-robin process scheduling with priority queues, buddy algorithm for dynamic memory allocation, and a simple FAT-like file system.
- Monolithic Kernel Architecture: Complete kernel implementation in C and x86 Assembly
- Process Scheduling: Round-robin scheduler with priority queues (4 priority levels)
- Memory Management: Buddy algorithm for efficient dynamic memory allocation
- File System: Simple FAT-like file system for persistent storage
- Interrupt Handling: x86 interrupt service routines (ISRs) for hardware interrupts
- Device Drivers:
- PS/2 keyboard input driver
- VGA text mode display driver
- Boot System: Bootable via GRUB bootloader
- Shell: Interactive shell with basic commands
custom-os-kernel/
├── src/ # Source files
│ ├── boot.asm # Boot code with Multiboot header
│ ├── kernel.c # Kernel entry point
│ ├── gdt.c # Global Descriptor Table
│ ├── idt.c # Interrupt Descriptor Table
│ ├── isr.asm # Interrupt Service Routines
│ ├── isr_handler.c # ISR handlers
│ ├── memory.c # Buddy allocator
│ ├── scheduler.c # Process scheduler
│ ├── keyboard.c # PS/2 keyboard driver
│ ├── vga.c # VGA text mode driver
│ ├── fs.c # File system
│ ├── shell.c # Shell implementation
│ └── util.c # Utility functions
├── include/ # Header files
├── build/ # Build output (generated)
├── iso/ # ISO image (generated)
├── Makefile # Build system
├── linker.ld # Linker script
└── grub.cfg # GRUB configuration
- GCC (with 32-bit support):
gcc -m32 - NASM: Netwide Assembler
- LD: GNU Linker
- GRUB: GRUB bootloader tools (
grub-mkrescueorgrub2-mkrescue) - QEMU: For running the OS (
qemu-system-i386)
brew install gcc nasm qemu
# GRUB may need to be installed separately or use genisoimagesudo apt-get install build-essential nasm qemu-system-x86 grub-pc-bin xorrisosudo dnf install gcc nasm qemu-system-x86 grub2-tools xorriso- Clone the repository:
git clone https://github.com/mo6044-hash/custom-OS-kernel.git
cd custom-OS-kernel- Build the kernel:
makeThis will:
- Compile all C and Assembly source files
- Link them into
build/kernel.bin - Create a bootable ISO image at
iso/os.iso
- Clean build artifacts:
make cleanmake run
# or
qemu-system-i386 -cdrom iso/os.iso -serial stdio- Create a new virtual machine
- Set the ISO (
iso/os.iso) as the boot medium - Start the VM
Once the kernel boots, you'll see an interactive shell. Available commands:
help- Show available commandsclear- Clear the screenls- List files in the file systemcreate <filename> <size>- Create a new filedelete <filename>- Delete a fileecho <text>- Echo text to the screen
The kernel uses a buddy allocator for dynamic memory allocation:
- Minimum block size: 16 bytes
- Maximum block size: 1024 bytes
- 10 allocation orders
- Efficient splitting and merging of blocks
The scheduler implements round-robin with priority queues:
- 4 priority levels (0-3, where 3 is highest)
- Each priority level has its own ready queue
- Higher priority processes are scheduled first
- Context switching optimized for minimal overhead
Simple FAT-like file system:
- Block size: 512 bytes
- Maximum files: 64
- Maximum filename length: 32 characters
- Basic file operations: create, delete, read, write, list
- 32 exception handlers (ISR 0-31)
- Hardware interrupt handlers (IRQ 0-1)
- Programmable Interrupt Controller (PIC) remapping
- Interrupt-driven keyboard input
The kernel includes several optimizations:
- Priority-based scheduling reduces context switch overhead
- Buddy allocator minimizes fragmentation
- Efficient interrupt handling with minimal latency
This is an educational kernel implementation with some limitations:
- No virtual memory/paging
- Limited file system (no directories)
- Basic process management (no fork/exec)
- No networking support
- Simplified memory management (no physical memory mapping)
Potential improvements:
- Virtual memory and paging
- Multi-level file system with directories
- System calls interface
- Networking stack
- Advanced process management (fork, exec, wait)
- Device driver framework
- Real-time scheduling algorithms
This project is for educational purposes. Feel free to use and modify as needed.
GitHub: mo6044-hash
This kernel implementation is inspired by various OS development tutorials and resources, including:
- OSDev.org wiki
- JamesM's kernel development tutorials
- Various open-source kernel projects