Skip to content

Building and running

Requirements

Tool Tested version Used for
x86_64-elf-gcc, x86_64-elf-g++, binutils GCC 13.2.0, binutils 2.41 cross compiling (see below)
CMake 3.22 or newer build
Ninja any build (generator of the presets)
grub-mkrescue + xorriso GRUB 2 bootable ISO
qemu-system-x86_64 6.2 run, debug, self tests
sfdisk, mkfs.fat, mtools util-linux 2.37, dosfstools 4.2, mtools 4.0 the test disk (disk-image), no root needed; optional: without them run and debug boot without a disk, the disk self tests are skipped and shelltest is not available
Doxygen optional API docs
Python 3, MkDocs (pip install -r docs/requirements.txt) MkDocs 1.6.1, Material 9.7.7 optional: the documentation site
clang-format, clang-tidy 14 (as in CI), optional format, format-check, tidy; other versions may format differently

On Debian/Ubuntu:

sudo apt install cmake ninja-build grub-pc-bin grub-common xorriso mtools qemu-system-x86 dosfstools fdisk doxygen

Cross compiler

atlOS has to be built with a cross compiler that targets x86_64-elf; the host compiler will not work. scripts/build-toolchain.sh builds one (binutils 2.41, GCC 13.2.0 for C and C++, libgcc for the kernel code model); the downloaded sources are checked against pinned SHA-256 sums. CI builds its toolchain with the same script.

sudo apt install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo curl
scripts/build-toolchain.sh              # into $HOME/opt/cross (takes 15-30 minutes)
export PATH="$HOME/opt/cross/bin:$PATH" # also add this to ~/.bashrc or ~/.zshrc
x86_64-elf-gcc --version

A different prefix can be given as the argument; JOBS sets the number of parallel jobs. Background: OSDev Wiki: GCC Cross-Compiler.

Building

scripts/build.sh is a shortcut for the CMake presets:

Command What it does
scripts/build.sh / scripts/build.sh all build libc, kernel and build/default/atlOS.iso
scripts/build.sh iso build the ISO
scripts/build.sh run boot the ISO in QEMU with the test disk, the serial console (boot messages, then the shell) on the terminal (Ctrl-C quits); the VGA screen looks like the README's GIF
scripts/build.sh debug boot the ISO in QEMU halted, waiting for gdb on localhost:1234; serial on telnet localhost 4321
scripts/build.sh selftest build the self test kernel in build/selftest/ and run it, see testing.md
scripts/build.sh crashtest build a kernel that faults on purpose in build/crashtest/ and check its report
scripts/build.sh shelltest boot the normal kernel and drive its shell over the serial port, see testing.md
scripts/build.sh docs Doxygen API docs into build/docs/html
scripts/build.sh site the documentation site into build/site/html (scripts/make-site.py); a broken link fails it
scripts/build.sh format / format-check clang-format the sources / check them, see style.md
scripts/build.sh tidy clang-tidy on the kernel sources
scripts/build.sh clean remove build/ (all presets)

Commands can be chained: scripts/build.sh clean all run.

QEMU emulates the same CPU everywhere, without KVM: an Intel Skylake (Skylake-Client-v1) without the features QEMU's emulator does not provide, written in scripts/qemu-cpu. run, debug, the tests and the screenshots use it, so cpuinfo and the tests see the same x86_64 processor on every machine. To try another model: QEMU_CPU=Nehalem-v1 scripts/run-selftest.sh ....

Builds are incremental. Each preset builds in build/<preset>/; nothing is written into the source tree.

With CMake directly

cmake --preset default                        # configure build/
cmake --build --preset default                # kernel + ISO
cmake --build --preset default --target run   # or iso, debug, docs

cmake --preset selftest
cmake --build --preset selftest --target selftest
ctest --preset selftest                       # the same test through CTest
Preset Build directory Notes
default build/default/ normal kernel: mounts the disks and starts the shell
selftest build/selftest/ ATLOS_SELFTEST=ON: the kernel runs the self tests and halts with the result
crashtest build/crashtest/ ATLOS_CRASHTEST=ON: the kernel page faults on purpose after boot

selftest and crashtest also set ATLOS_DEBUG_EXIT_PORT=0xf4: the exit status is written to that port when the kernel halts, see testing.md. Leave it empty (-DATLOS_DEBUG_EXIT_PORT=) for a test kernel meant for real hardware.

All presets export compile_commands.json for editors and clangd.

Outputs

File Description
build/default/kernel/atlOS.kernel the kernel ELF (with debug info)
build/default/libc/libk.a the C library linked into the kernel
build/default/atlOS.iso bootable GRUB ISO
build/default/disk.img the test disk (--target disk-image; run and debug attach it as the primary ATA master)

Debugging

scripts/build.sh debug          # QEMU waits for gdb
gdb build/default/kernel/atlOS.kernel -ex 'target remote localhost:1234'

In VS Code, start the "Run QEMU Debug" task, then the "Debug Kernel" launch configuration (.vscode/launch.json).

FAT test disk

cmake --build --preset default --target disk-image runs scripts/make-disk-image.sh, which creates build/default/disk.img: a 32 MB raw image with an MBR and one FAT16 partition, holding tools/disk/files/, a generated BIG.TXT and the user programs in /BIN. It needs no root (sfdisk, mkfs.fat and mtools). Every preset builds its own, build/<preset>/disk.img. run, debug, shelltest and the self tests attach it as the primary ATA master; the kernel mounts it as /disk0. Contents and how to look inside: tools/disk/README.md.

User programs

The programs in user/ (ring 3, see user/README.md) are built with every preset into build/<preset>/user/*.elf and copied to the test disk as /BIN/<NAME>.ELF. Run one from the shell: run /disk0/BIN/HELLO.ELF.

Screenshots

scripts/take-screenshots.py <iso> <disk.img> <dir> boots the normal kernel, types a few shell commands over the serial port and saves the VGA screen (QEMU's screendump) as boot.png and shell.png, e.g. for the wiki.

scripts/make-demo-gif.py <iso> <disk.img> <out.gif> records the animated GIF of the README (docs/images/demo.gif): the boot from SeaBIOS through GRUB to the prompt, then a few commands typed one key at a time. The boot is faster than a screendump, so it runs in 20 ms slices with the VM stopped for each picture and plays slowed down; repeated pictures become one longer frame, and the 16 colors of text mode keep the file small. Record it from a committed tree, on a release tag the banner shows just (vX.Y.Z).