OS · V1.4 · MIT License · x86 · Morocco 🇲🇦

polyfdOS

|

x86 Protected Mode GRUB Multiboot 26 KB kernel 490 KB ISO 3-valued logic
# Build and run in QEMU make run # Or manually qemu-system-i386 -cdrom polyfdos.iso # Run on real hardware sudo dd if=polyfdos.iso of=/dev/sdX bs=4M
→ github.com/PolyfdOS/PolyfdOS
~2klines of code
26KBkernel binary
490KBbootable ISO
<1sboot time
70%C + 30% ASM
Getting Started

Introduction

polyfdOS is a bare-metal x86 operating system built from scratch in Morocco by Daftyon. It runs entirely without a host OS — booting via GRUB directly into a custom kernel written in C and x86 Assembly.

The kernel initializes protected mode, sets up the GDT and IDT, loads hardware drivers, mounts a RAM filesystem, and drops the user into an interactive shell. Unique to polyfdOS is native three-valued logic through the realistic type — the same Kleene-extended logic found in the MatyOS language.

The source is ~2,000 lines across 15 C/Assembly files. The compiled kernel fits in 26 KB and boots in under one second on QEMU.

Organization
Daftyon — Morocco 🇲🇦
Status
Active development — Phase 2 in progress
License
MIT — open source
Languages
C (70%) · x86 Assembly (30%)

Getting Started

Quick Start

Building

Install the prerequisites for your platform, then run make to produce kernel.elf and polyfdos.iso.

# Linux / WSL2
sudo apt install build-essential nasm grub-pc-bin genisoimage qemu-system-x86

# macOS
brew install nasm qemu xorriso grub i386-elf-gcc

# Build
make clean && make

# Output
# kernel.elf  → 26 KB compiled kernel
# polyfdos.iso → 490 KB bootable ISO

Running

The fastest way is QEMU. polyfdOS also runs in Bochs, VirtualBox, VMware, and on real x86 hardware.

# QEMU (recommended)
make run
# or manually
qemu-system-i386 -cdrom polyfdos.iso

# Bochs
bochs -f bochsrc.txt -q

# Real hardware (⚠ overwrites /dev/sdX)
sudo dd if=polyfdos.iso of=/dev/sdX bs=4M status=progress

Architecture

Architecture Overview

polyfdOS uses a monolithic flat-memory kernel. After GRUB hands off control, loader.s sets up the stack and jumps to kmain() in C. The kernel runs entirely in 32-bit protected mode at ring 0.

Boot Sequence

From power-on to interactive shell in under one second. Click Play to walk through each stage.

BIOS
🥾GRUB
⚙️loader.s
🏗️kmain()
🔌Drivers
$Shell
Press Play to walk through the boot sequence.
// kernel boot log will appear here

Memory Layout

polyfdOS uses a flat memory model with segmentation. The kernel loads at 1 MB (0x100000), the VGA framebuffer is memory-mapped at 0xB8000.

0x00000000–0x3FF
Interrupt Vector Table (IVT) Real Mode
0x00000400–0x4FF
BIOS Data Area Reserved
0x00007C00–0x7DFF
GRUB Bootloader Stage 1
0x000A0000–0xBFFFF
VGA / Video Memory Hardware
0x000B8000–0xB8FA0
VGA Text Buffer (80×25) Framebuffer
0x00100000+
Kernel Code & Data 26 KB

System Tables

Two descriptor tables gate all memory and interrupt access in protected mode.

GDT — gdt.c / gdt_asm.s
Global Descriptor Table. Defines flat code and data segments (base 0x0, limit 0xFFFFFFFF). Loaded via lgdt instruction from assembly stub.
IDT — idt.c / idt_asm.s
48 interrupt handlers (0–47). PIC remapped: IRQ0–7 → INT 0x20–0x27, IRQ8–15 → INT 0x28–0x2F. Keyboard is IRQ1 → INT 0x21.
/* kmain.c — kernel initialization order */
int kmain(void) {
    serial_configure_baud_rate(SERIAL_COM1_BASE, 3);  // COM1 debug
    gdt_install();            // load Global Descriptor Table
    idt_install();            // load Interrupt Descriptor Table
    keyboard_init();          // PS/2 keyboard (IRQ1)
    fs_init();                // RAM filesystem
    sysfiles_init();          // populate /etc, /bin, …
    __asm__ ("sti");           // enable interrupts
    bootsplash_show();        // animated ASCII splash
    shell_init();             // print banner, set prompt
    while (1) shell_update(); // main loop
}

Hardware Drivers

Drivers

Three core drivers provide all hardware access. All I/O goes through inb/outb port operations defined in io.s.

🖥️
Framebuffer
fb.c / fb.h
VGA text mode at 0xB8000. 80×25 character grid. Direct memory writes for characters and color attributes. Hardware cursor via CRTC registers (0x3D4/0x3D5).
⌨️
Keyboard
keyboard.c / keyboard.h
PS/2 controller on IRQ1 (INT 0x21). Scan code to ASCII translation. US QWERTY layout. Interrupt-driven — no polling. Backspace and enter handling built in.
🔌
Serial Port
serial.c / serial.h
COM1 debug output at configurable baud rate. FIFO buffer management. Used for kernel log messages visible in qemu -serial stdio. Does not expose to shell.

Framebuffer — VGA Text Mode

/* VGA text buffer: 80×25 = 2000 cells, 2 bytes each */
/* byte 0: ASCII char, byte 1: color attribute          */

#define FB_ADDRESS  0xB8000
#define FB_COLS     80
#define FB_ROWS     25

/* Color layout: bits[7:4] = background, bits[3:0] = foreground */
#define FB_WHITE    15   // 0xF
#define FB_BLACK    0
#define FB_LIGHT_CYAN 11 // 0xB — used for prompts

Keyboard — PS/2 IRQ Handler

/* Keyboard interrupt fires on every key press/release */
/* Data port 0x60, status port 0x64                    */
/* Bit 7 of scan code = key release event              */

void keyboard_handler() {
    unsigned char scan = inb(0x60);
    if (!(scan & 0x80)) {           // key press (not release)
        char c = scan_to_ascii[scan]; // US QWERTY table
        keyboard_buffer[buf_end++] = c;
    }
    outb(0x20, 0x20);              // PIC end-of-interrupt
}

Shell

Shell Commands

polyfdOS ships with a minimal but complete command-line interpreter. Commands are parsed in shell.c — a simple token split on the first space character.

CommandDescription
helpList all available commands
clearClear the screen via framebuffer
aboutShow OS name, version, and organization
echo <text>Print text to screen
sysinfoFull system info — real CPUID + CMOS memory detection
cpuCPU vendor, family, model, stepping, feature flags
memRAM total and available via CMOS probing
cd / vst <dir>Change working directory
pwdPrint current directory
lsList directory contents (dirs and files)
cat <file>Display file contents from RAM filesystem
mkdir / rmdirCreate / remove directory
touch / rmCreate empty file / delete file
mv / cpMove·rename / copy files
edit <file>Open built-in text editor
playLaunch Snake game (WASD to move, Q to quit)
realisticThree-valued logic demo
sudo <cmd>Run command with simulated elevated privileges
download <pkg>Simulated package download
rebootRestart via keyboard controller (port 0x64)
haltHalt CPU with cli; hlt

RAM Filesystem

polyfdOS mounts a flat RAM filesystem at boot. Up to 50 files, 2 KB each. Standard directories are pre-created: /bin /home /usr /etc /dev /tmp /var /proc /sys. System files (/etc/os-release, /etc/hostname) are populated by sysfiles_init().

Snake Game

A fully playable Snake game rendered via direct framebuffer writes. Launched with play. WASD for movement, Q to quit. Features score tracking and progressive speed increase.

Interactive Demo

Try the polyfdOS shell. Type any command from the table above — this is a faithful simulation of the real kernel shell.

polyfdOS v1.4 — shell simulator
/ > 

System

Realistic Type

polyfdOS implements three-valued logic at the kernel level via the realistic_t type in realistic.h. The same logic underpins the realistic type in the MatyOS language.

Based on Kleene's strong three-valued logic, it extends boolean with a third state: REALISTIC (uncertain / unknown / possible). This is useful for hardware detection where a value is not yet known rather than definitively true or false.

/* realistic.h — three-valued logic type */
typedef enum {
    R_FALSE     = 0,  /* Definitely false      */
    R_TRUE      = 1,  /* Definitely true       */
    R_REALISTIC = 2   /* Uncertain / unknown   */
} realistic_t;

/* Example: detect if feature is present */
realistic_t has_sse = realistic_from_int(feat_edx & (1 << 25));
if (realistic_is_true(has_sse))  fb_puts("SSE supported\n");
if (realistic_is_realistic(has_sse)) fb_puts("SSE: uncertain\n");

Truth Table

ABANDORNOT AA → B
TRUETRUETRUETRUEFALSETRUE
TRUEFALSEFALSETRUEFALSEFALSE
TRUEREALREALTRUEFALSEREAL
FALSEFALSEFALSEFALSETRUETRUE
FALSEREALFALSEREALTRUETRUE
REALREALREALREALREALREAL

Run realistic in the shell demo above to see a live demonstration of all logical operations.


MatyOS Runtime

Run MatyOS on polyfdOS

polyfdOS ships with a MatyOS runtime layer — the El interpreter runs natively on the kernel, giving you a proof-assistant shell directly inside the OS. Type El programs below and execute them as if you were at the polyfdOS terminal.

MatyOS language docs → Realistic Type paper →
polyfdOS v1.4 > matyos --run
polyfdOS$ matyos --interactive
stdout
// output will appear here

Development

Roadmap

polyfdOS is actively developed. Phase 1 is complete — the kernel boots, drives hardware, and runs a shell. Phase 2 focuses on memory management.

Phase 1 Foundation ✓ Complete
✓ Bootloader + protected mode ✓ GDT + IDT ✓ Framebuffer driver ✓ Keyboard driver (IRQ1) ✓ Serial debug (COM1) ✓ Interactive shell ✓ RAM filesystem ✓ Snake game ✓ Realistic type ✓ Real hardware detection (CPUID)
Phase 2 Memory Management In Progress
⟳ Physical memory manager (bitmap) ○ Virtual memory (paging) ○ Heap allocator (kmalloc/kfree) ○ Memory protection
Phase 3 Process Management Planned
○ Task switching + scheduler ○ Process creation/termination ○ Context switching ○ System calls interface
Phase 4 File System Planned
○ VFS layer ○ FAT32 implementation ○ File operations (open/read/write) ○ Directory support
Phase 5 Advanced Features Future
○ Multi-core support ○ Network stack (TCP/IP) ○ ATA + USB drivers ○ ELF loader ○ User space programs
Language MatyOS The language running inside this OS Research Paper Realistic Type Three-valued logic behind realistic_t Creator PolyfdoR Ahmed Hafdi · @polyfdor
polyfdOS shell — live / >
/ >