Hi all,
I'm announcing a renewed repository for mkfreeOS, a hobby OS I've been
building since 2019 in whatever spare time I can find — which isn't much.
Progress has been slow by necessity, but steady. After years of accumulated
commits, refactors, and experimental branches in the original repo, I decided
to start a clean repository from scratch — keeping the code but resetting
the git history to something coherent and reviewable.
---
**What it is**
mkfreeOS is a bare-metal OS written from scratch in C++ and assembly,
targeting x86 (32-bit) and x64 (64-bit). It includes everything from the
boot sector to a windowed GUI running real applications.
Feature overview:
- 512-byte real-mode bootloader + secondary loader (NASM)
- Preemptive multithreaded kernel with virtual memory and page tables
- SMP support (LAPIC/IOAPIC, per-CPU runqueues, IPI rescheduling)
- ELF process loader
- FAT32 filesystem + VFS abstraction
- IDE/ATA block device stack with read cache
- PS/2 keyboard and mouse drivers
- CPU-based graphics renderer
- AF_LOCAL socket-based window server
- GUI applications: notepad, file explorer, terminal
- 20+ POSIX-inspired userland utilities (shell, cat, ls, grep, cp, mv, ...)
- Freestanding libc (no host OS dependency)
License: GPL v3
Repo: https://github.com/ramonmayedo/mkfreeOS
Docs: https://github.com/ramonmayedo/mkfreeOS/tree/main/help
---
**A few things that may be of interest**
1. **Adaptive round-robin scheduler via EMA**
The scheduler adjusts the quantum for each thread using an exponential
moving average over recent CPU consumption:
plannedTime = (filter * recentConsumed + (100 - filter) * standardTime) / 100
The `filter` coefficient adapts to whether the thread is I/O-bound or
CPU-bound. I/O-bound threads end up with longer planned quanta (they
rarely use their full slice anyway), which reduces unnecessary context
switches. It's not CFS, but it's more responsive than naive round-robin
without the complexity of a priority-inversion-aware scheduler.
2. **Clean architecture adapter layer (IArch* contracts)**
The kernel core has zero knowledge of x86 or x64 specifics. All hardware
interaction goes through a set of pure virtual interfaces aggregated in a
single `Arch` struct:
struct Arch {
IArchIO *io;
IArchInterrupt *interrupt;
IArchVirtualMemory *virtualMemory;
IArchCPU *cpu;
IArchEventHandler *eventHandler;
IArchDebug *debug;
IArchAtomic *atomic;
IMemoryMapProvider *memoryMap;
};
`archBootstrap()` is resolved by the linker to the target arch and wires
the struct at boot. Porting to a new architecture means implementing those
interfaces — the kernel core doesn't change.
3. **The adapter layer as a seam for AI-driven modules**
The same IArch* contract system that isolates hardware could also serve
as a natural seam for pluggable AI-driven modules at the OS policy level.
The scheduler already exposes an ISchedulerPolicy interface:
class ISchedulerPolicy {
virtual void onCreate (Thread*) = 0;
virtual void onActivate (Thread*) = 0;
virtual void onDeactivate(Thread*) = 0;
virtual bool onTick (Thread*) = 0; // return true to preempt
};
An AI module implementing ISchedulerPolicy could observe thread behavior
across activations and make preemption decisions without touching the
scheduler infrastructure at all. Similarly, IArchVirtualMemory exposes
walkAddressSpace() with a visitor pattern — a monitoring module could
inspect page access patterns without modifying the kernel.
The broader idea: if kernel policies (scheduling, memory reclaim,
I/O prioritization) are expressed as pure virtual interfaces rather than
hard-coded algorithms, they become hot-swappable at runtime. An AI agent
running in a privileged user-space process could implement those interfaces
over a shared memory channel and influence kernel behavior — without being
part of the kernel itself.
This isn't implemented yet, but the interface boundaries are already in
the right places. Curious if anyone here has explored this direction.
4. **Forward-planned SMP lock hierarchy**
There's a documented 10-level global lock acquisition order
(heap → page pool → virtual memory → process AS → scheduler → filesystem)
with explicit rules for SpinlockIrq vs sleeping Mutex. The kernel currently
runs with a big-lock (cli during syscalls), but the hierarchy is
documented ahead of the migration to fine-grained locking.
5. **Two-mode concurrency pattern**
All major subsystems (allocators, device manager, VFS) operate without
any locking during boot (single-threaded invariant), then switch to
SpinlockIrq atomically when `enableConcurrency()` is called, just before
the IDT goes live. This avoids the spinlock overhead on the entire boot
path without any ifdef guards.
---
**The migration**
The original repository accumulated a lot of history from the initial
Makefile-based build, through several full rewrites of the scheduler,
memory manager, and GUI system. The new repo starts clean — one commit per
module, coherent history, same code. The old repo is now private.
If you've seen a previous version of mkfreeOS anywhere: this is the same
project, rebuilt from the ground up with the lessons from those years. Given
that this is a spare-time effort, some areas are more polished than others —
but the core is solid enough to boot, run a shell, and display a windowed GUI.
---
**What I'm looking for**
- Feedback on the architecture decisions above, especially the IArch* approach
- Anyone who has built something similar and ran into problems with the
adaptive quantum approach
- Thoughts on the AI/policy interface direction — has anyone explored this?
- Testing reports if you try to build/run it (QEMU works out of the box
with the included run-qemu.bat / equivalent Linux command)
Build requirements: CMake ≥ 3.20, Ninja, x86_64-elf cross-compiler, NASM,
mtools. Full instructions in src/BUILD.md.
Thanks