polyfdOS
|
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.
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 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.
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.
System Tables
Two descriptor tables gate all memory and interrupt access in protected mode.
lgdt instruction from assembly stub./* 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 }
Drivers
Three core drivers provide all hardware access. All I/O goes through inb/outb port operations defined in io.s.
0xB8000. 80×25 character grid. Direct memory writes for characters and color attributes. Hardware cursor via CRTC registers (0x3D4/0x3D5).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 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.
| Command | Description |
|---|---|
| help | List all available commands |
| clear | Clear the screen via framebuffer |
| about | Show OS name, version, and organization |
| echo <text> | Print text to screen |
| sysinfo | Full system info — real CPUID + CMOS memory detection |
| cpu | CPU vendor, family, model, stepping, feature flags |
| mem | RAM total and available via CMOS probing |
| cd / vst <dir> | Change working directory |
| pwd | Print current directory |
| ls | List directory contents (dirs and files) |
| cat <file> | Display file contents from RAM filesystem |
| mkdir / rmdir | Create / remove directory |
| touch / rm | Create empty file / delete file |
| mv / cp | Move·rename / copy files |
| edit <file> | Open built-in text editor |
| play | Launch Snake game (WASD to move, Q to quit) |
| realistic | Three-valued logic demo |
| sudo <cmd> | Run command with simulated elevated privileges |
| download <pkg> | Simulated package download |
| reboot | Restart via keyboard controller (port 0x64) |
| halt | Halt 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().
> ls Contents of /: [DIR] bin/ [DIR] home/ [DIR] usr/ [DIR] etc/ [DIR] dev/ [DIR] tmp/ [DIR] var/ > cat /etc/os-release NAME="polyfdOS" VERSION="1.4" ID=polyfdos PRETTY_NAME="polyfdOS 1.4" HOME_URL="https://github.com/PolyfdOS"
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.
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
| A | B | AND | OR | NOT A | A → B |
|---|---|---|---|---|---|
| TRUE | TRUE | TRUE | TRUE | FALSE | TRUE |
| TRUE | FALSE | FALSE | TRUE | FALSE | FALSE |
| TRUE | REAL | REAL | TRUE | FALSE | REAL |
| FALSE | FALSE | FALSE | FALSE | TRUE | TRUE |
| FALSE | REAL | FALSE | REAL | TRUE | TRUE |
| REAL | REAL | REAL | REAL | REAL | REAL |
Run realistic in the shell demo above to see a live demonstration of all logical operations.
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.
Roadmap
polyfdOS is actively developed. Phase 1 is complete — the kernel boots, drives hardware, and runs a shell. Phase 2 focuses on memory management.