Skip to content

atlOS

atlOS logo

CI Release

atlOS is an experimental x86_64 operating system written in C++17 for learning and research.

atlOS booting in QEMU, then help, lspci, smbios, ls, a user program with threads and tasks in the shell

Status

Working:

  • 64-bit higher half kernel (loaded at 4 MB, mapped at 0xFFFFFFFF80000000 + physical), booted by GRUB2
  • GDT with a TSS (double fault stack), IDT, decoded exception reports with a backtrace
  • ACPI tables (RSDP, RSDT/XSDT, MADT); interrupts through the local APIC and the I/O APIC, a 1 ms tick from the APIC timer measured against the PIT; the 8259 PIC and the PIT on a machine without ACPI
  • Physical memory manager (2 MB blocks + 4 KB frames for page tables)
  • Virtual memory with 2 MB pages, a physmap of all physical memory, and separate address spaces sharing the kernel half
  • A heap (free list, first fit, merged on free) shared by the kernel (kmalloc, new) and user programs (malloc)
  • Cooperative round robin scheduler over one list of every thread (no limit but memory): yield, sleep, block/unblock, exit codes and wait, an idle thread, CPU time per task (sched, top)
  • Synchronization: atomics, wait queues, semaphores, mutexes, condition variables
  • PS/2 keyboard (US layout) and serial input
  • A kernel shell (keyboard or serial terminal) that reaches everything: files, md/mw memory dump and write, vmmap, pt, tasks, run, cr, rdmsr/wrmsr, in/out, gdt/idt, irq, int, disk read, lspci, acpi, apic, smbios, ... (help lists them by group)
  • Processes and threads: a process owns the address space, the files and the heap, its threads run (1:1, the scheduler sees every thread); thread ids with the pid in the upper half, user stacks with guard pages, the main thread's end or a fault ends every thread (ps, tasks)
  • User programs in C++17: static ELF64 files from the disk, run in ring 3 in their own address space, int 0x80 system calls (read/write on the keyboard, the screen and files, open/close, sleep, yield, uptime, threads: start, exit, wait, the current thread and process, exitProcess), shared with the kernel through one header (common/abi); a fault ends only the program. Writing one: user/README.md
  • SMBIOS 2.x: the BIOS, system, board, processor and memory module structures (smbios, like dmidecode)
  • PCI and PCIe: every bus scanned through the configuration ports, lspci with the BARs and capabilities
  • ATA disks (PIO), MBR partitions, FAT16 (read and write, 8.3 names) and a VFS with mount points (/disk0/...)
  • Serial (COM1) and VGA text output, a small freestanding libc (libk)
  • In-kernel self tests run headless in QEMU

The CPUID feature report (cpuinfo) is built and tested but not used at boot. The shell runs in the kernel; user programs reach it through thirteen system calls. atlOS runs on a single CPU, scheduling is cooperative.

Quick start

You need an x86_64-elf GCC cross compiler on PATH (scripts/build-toolchain.sh builds one), CMake 3.22+, Ninja, grub-mkrescue (with xorriso) and QEMU. See docs/building.md. Or boot a ready made ISO from the releases.

scripts/build.sh            # libc, kernel and build/default/atlOS.iso
scripts/build.sh run        # boot in QEMU, the shell on the terminal
scripts/build.sh selftest   # build and run the self tests
scripts/build.sh crashtest  # a kernel that faults on purpose: check the report
scripts/build.sh shelltest  # drive the shell over the serial port

The same with CMake directly:

cmake --preset default
cmake --build --preset default --target run

scripts/build.sh run shows the boot messages, then the shell, on the terminal; the GIF at the top shows the same on the VGA screen.

Source layout

kernel/
  arch/x86_64/   boot, crt, cpu (context switch, CPUID), gdt, idt (+ISR stubs), io ports, mmu
  core/          kernel entry (main.cpp), panic, logger, banner
  cxx/           C++ runtime support (global constructors, new/delete)
  mm/            pmm, vmm, the kernel heap's pages
  sched/         scheduler, threads
  shell/         the kernel shell: line editor, parser, commands
  proc/          processes and their threads: ELF loading, ring 3, system calls
  sync/          atomic, interrupt guard, wait queue, semaphore, mutex, condition variable, spinlock
  drivers/       apic/, pic, pit, serial, vga console, keyboard, disk/ (block devices, ATA, MBR), pci/
  fs/            file system interface, fat16, vfs, mounting the disks
  firmware/      acpi/ (the tables, the MADT), smbios/ (the 2.x structures)
  lib/           small header-only helpers (an intrusive list, ...)
  tests/         in-kernel self tests
common/heap/     the heap, built into the kernel and into every user program
common/abi/      the system call numbers and errors, shared by the kernel and user programs
libc/            freestanding C library (libk) used by the kernel
cmake/           cross toolchain file
user/            user programs (ring 3, C++17) for the test disk, see user/README.md
scripts/         build.sh, run-selftest.sh, run-crashtest.sh, symbolize.sh, make-disk-image.sh, check-test-disk.sh
tools/           grub.cfg, files of the test disk
docs/            documentation

Headers live next to their sources; includes are relative to kernel/ or common/, for example #include <mm/vmm.hpp>, #include <heap/heap.hpp>. Kernel code is in namespace Kernel::, the user library in User::, what both share in Common:: and Abi:: (docs/style.md).

The subsystem directories have a README that explains the concept, the usual ways to design it, what atlOS chose and why, with diagrams and references: mm, heap, sched, processes and threads, drivers, interrupts, ACPI, APIC, SMBIOS.

Documentation

The tutorial walks through the kernel in boot order; each chapter is the README next to the subsystem's code. Online, for the latest release: https://oguzhankynk.github.io/atlOS/.

API documentation can be generated with Doxygen: scripts/build.sh docs (output in build/docs/html).

References

The OSDev Wiki is the main reference for this project: boot, paging, interrupts, the PIC and PIT, ACPI and the APIC, ATA, FAT, PCI and user mode all start there. The subsystem READMEs link the pages they build on.

License

MIT, see LICENSE. Third party code and its licenses: THIRD_PARTY.md.