Skip to content

jvmespark/peanut

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PeanutOS

A 32-bit x86 multi-core operating system booted on bare metal via a hand-rolled two-stage BIOS bootloader. Brings up multiple cores via the Local APIC, and runs a preemptive multitasking kernel with paging, a buddy allocator, a kernel heap, synchronization primitives, device drivers, a VFS-backed in-memory filesystem, cycle-accurate timing, and a tiny embedded CPU emulator for sandboxed bytecode execution.


Features

Subsystem What it does
Bootloader Hand-rolled 2-stage BIOS bootloader (MBR + Stage 2). Reads kernel via INT 13h, gathers an E820 memory map, enables A20, sets up GDT, switches to protected mode, jumps to kernel.
Architecture i686 (32-bit x86), protected mode, paging enabled, FPU/SSE bring-up, segmentation flat-model.
Memory management Page-frame allocator backed by a power-of-two buddy allocator, 4 KiB pages, kernel virtual memory manager, kernel heap (first-fit + free-list).
Multitasking Preemptive round-robin scheduler with per-CPU run queues, kernel threads, processes (kernel-mode), context switching via iret.
SMP Local APIC + IO-APIC bring-up, MP Floating Pointer Structure parsing, INIT-SIPI-SIPI AP startup, real-mode → protected-mode trampoline at 0x8000.
Synchronization Spinlocks (xchg-based), recursive mutexes, counting semaphores, IRQ-disabling critical sections.
Interrupts IDT with 32 CPU exception handlers + 16 PIC IRQs + APIC redirection. Per-vector C dispatchers.
Timing PIT (channel 0) tick driver, TSC-backed cycle counters, kernel uptime, busy-wait calibration.
Drivers VGA text mode (80x25, color, scroll), PS/2 keyboard with scancode → ASCII translation, 16550 UART serial logger, PIT, PIC, APIC.
Filesystem Tiny VFS layer with a RAM-backed ramfs providing open/read/write/close/seek/stat.
CPU emulator A small register-based bytecode VM (16 registers, 14 opcodes) embedded in the kernel — boots, executes a bundled program, prints results. Useful as a sandbox for trusted-test execution.
Build / tooling GNU Make, NASM, an i686-elf-* cross toolchain, a disk-image builder, a QEMU launcher script.

Repository layout

PeanutOS/
├── boot/                    # Stage1 (MBR) + Stage2 BIOS bootloader
├── kernel/
│   ├── arch/x86/            # CPU-specific: GDT, IDT, paging, SMP, APIC, timers
│   ├── mm/                  # Physical (buddy) + virtual + heap allocators
│   ├── sched/               # Tasks, threads, scheduler, sync primitives
│   ├── drivers/             # VGA, keyboard, serial, PIT
│   ├── fs/                  # VFS + ramfs
│   ├── emu/                 # Embedded bytecode CPU emulator
│   ├── lib/                 # printf, string, assert, types
│   ├── include/             # Public kernel headers
│   ├── kmain.c              # The entry point
│   └── linker.ld
├── tools/                   # Disk-image build scripts, QEMU launcher
├── tests/                   # Stub unit-test harness
├── Makefile
└── README.md

Quick start

Prerequisites

  • An i686-elf cross-compiler toolchain (i686-elf-gcc, i686-elf-ld, i686-elf-objcopy). See docs/BUILDING.md for one-command instructions.
  • nasm
  • qemu-system-i386
  • make, dd

Build & run

make           # builds boot/, kernel/, and disk.img
make run       # boots disk.img in QEMU with 2 cores, 64 MiB RAM
make debug     # boots under QEMU + GDB stub on :1234
make clean

On boot you should see VGA text from the kernel, serial logs on stdio, secondary CPUs reporting their LAPIC IDs, the buddy allocator coming up, the scheduler launching kernel threads on every CPU, the embedded CPU emulator running its built-in test program, and a keyboard shell prompt.


Roadmap

  • Userland & syscalls. Add a Ring 3 GDT entry, an int 0x80 (or syscall) handler, an ELF loader, and a usermode/ subtree.
  • Per-CPU storage via gs:-relative segments.
  • Wait queues + sleep_on/wake_up to remove the busy-wait fallbacks in synchronization primitives.
  • A real disk driver (ATA PIO is ~150 lines) to back a real filesystem (FAT16/ext2-mini).
  • Network stack. RTL8139 driver under QEMU, then ARP/IP/UDP.
  • 64-bit port. The arch layer is small enough to fork to arch/x86_64.
  • More drivers: ACPI shutdown, HPET, framebuffer (VBE), PCI bus walker.

About

32-bit x86 multi-core operating system booted on bare metal via a hand-rolled two-stage BIOS bootloader.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors