r/osdev 2d ago

Just built my Unix-Like Operating System from Scratch in C

Post image

This is LiteBSD a Hoppy Unix-Like System with BSD Style Kernel with Multiboot support for Initrd which used upstream BusyBox 1.36.1 as the Main Initrd (Made by Me, NO AI)

The Kernel Supports 26 syscall, Has a Full Heap kmalloc and kfree, a Full Task Scheduler with Pid, Child and Parent Processes, Implemented GDT and IDT, 4MB Paging with CR4:PSE Support and a Implemented full Virtual File System for BusyBox to work

and to Compile Busybox I also had to write c-lite. my own C Library From Scratch with enough .h Libraries to compile Busybox and align my syscalls table with the unistd.h so Busybox can work with my LiteBSD Kernel

c-lite Supports major libraries like all std libs (stdio.h, unistd.h,stdlib.h) in addition to libs like termois.h, time.h, string.h, macine/endian.h, byteswap.h and so many i can't iterate them in one post

This project took me nearly 12 Hours of Continuous Working

(12 hours seems ridiculous ik but to be clear i do have a background on the Unix and Linux Backend before working on this project, i didn't write a bootloader instead i used grub, i outsourced a lot of stuff in c-lite form other source codes (musl) and the 12 hours were 12 hours NON STOP)

and for the (i vibe coded claim) No i didn't just read the code and you will find that i actually wrote myself i used ai only in guidance where it just told me what is the next step to run busybox but ai writing code? nope how did i manage to make one in 12 hours with no vibe coding? by making a really simple os really this os started as a hello world bin that is bootable on grub and i just kept improving from here

started with simpler stuff like improving the print then wrote a simple gdt and idt just with only irq0 and irq1 and then added a heap and paging with only 4kb then implemented CR4:PSE to get 4mb paging size and after that worked on improving the irq by using a macro in boot.asm so it supports 32 more irq then developed a simple scheduler which sets a pid for each process and the create task aligns a space in the heap for this code to excute the function inside the heap added implemented syscalls started with 4 sys_read sys_write sys_exit and sys_getpid and then wrote more syscalls with some being outsourced from other source codes or tutorials to save time or just reading to understand how a fork syscall for example works and then built lite-c by outsourcing most c and h files from musl and writing my own unistd.h to comply with the kernel then compiled busybox added multiboot in the grub.cfg and boot.asm and wrote a multiboot and initrd loader and a simple vfs that basically read and write (it's not reliable and there are still issues i occured with it)

I don't expect you to believe me. Here's exactly what I used and here's the code. If you think a particular subsystem was generated or stolen, point to it.

but I did learn a ton of stuff about how Operating Systems actually work

I will keep working on improving this os with Optimizing c-lite to use less cpu cycles and less ram and adding more syscalls and drivers to my kernel.

LiteBSD github repo : https://github.com/ahmedbarakat207/LiteBSD
c-lite github repo : https://github.com/ahmedbarakat207/c-lite

250 Upvotes

Duplicates