# malwarepad/cavos architecture

> Architecture diagram of the GitHub repository malwarepad/cavos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/malwarepad/cavos
- Repository: https://github.com/malwarepad/cavos

## Overview

#### Purpose and Build Surface
cavOS is a monolithic, x86_64 Unix-like/POSIX-oriented OS written primarily in C with x86 assembly. It builds a bootable disk image containing the kernel, musl-based userspace, system startup code, and a target root filesystem. Primary build/orchestration points are `Makefile`, `src/kernel/Makefile`, and image tooling in `tools/kernel/make_disk.sh`.

#### Boot and Kernel Entry
Limine loads the kernel, with boot protocol integration and early handoff in `src/kernel/entry/bootloader.c` and `src/kernel/entry/kernel.c`. Link layout is defined by `src/kernel/link.ld`. The boot image configuration is `target/boot/limine/limine.conf`; FAT32 is used for boot media, while Ext2 is intended for the root partition.

#### CPU, Interrupt, and Platform Initialization
Early kernel setup establishes memory/CPU execution state, descriptor tables, interrupt handling, APIC timing, and ACPI hardware discovery. Core boundaries are `src/kernel/cpu/gdt.c`, `src/kernel/cpu/idt.c`, `src/kernel/cpu/isr.c`, `src/kernel/cpu/apic.c`, and `src/kernel/acpi/uacpi_glue.c`. This layer converts firmware and hardware interrupts into kernel control flow before device drivers and scheduling run.

#### Memory and Multitasking
Physical and virtual memory management underpin kernel allocation and per-process address spaces: `src/kernel/memory/pmm.c`, `src/kernel/memory/paging.c`, and `src/kernel/memory/vmm.c`. Preemptive execution is managed through task structures, stacks, and scheduling in `src/kernel/multitasking/task.c`, `src/kernel/multitasking/stack.c`, and `src/kernel/multitasking/schedule.c`. Syscall entry uses the x86 `syscall` path (`src/kernel/cpu/fastSyscall.c`).

#### Device and Console Layer
PCI discovery selects storage, input, display, and NIC drivers through `src/kernel/drivers/pci.c` and `src/kernel/drivers/nics/nic_controller.c`. Storage flows from AHCI/disk drivers (`src/kernel/drivers/ahci.c`, `src/kernel/drivers/disk.c`) into filesystems. Console output targets VGA/framebuffer and terminal rendering through `src/kernel/graphical/console.c`, `src/kernel/graphical/fb.c`, and `src/kernel/graphical/ansi.c`; framebuffer exposure supports `/dev/fb0`.

#### Filesystem and Process Interfaces
The VFS is the principal filesystem boundary, mounting and dispatching paths via `src/kernel/filesystems/vfs/vfs_controller.c` and `src/kernel/filesystems/vfs/vfs_mnt.c`. It fronts Ext2 root storage (`src/kernel/filesystems/ext2/ext2_controller.c`), FAT32, and synthetic `/dev`, `/proc`, and `/sys` controllers. ELF program loading is implemented in `src/kernel/utilities/elf.c`. Linux-shaped syscall compatibility routes user requests in `src/kernel/syscalls/syscalls.c` into filesystem, process, memory, I/O, signal, polling, and IPC implementations.

#### Networking and Userspace Runtime
Physical NIC drivers feed a kernel networking layer and bundled lwIP TCP/IP stack: `src/kernel/networking/socket.c`, `src/kernel/networking/stack/netqueue.c`, and `src/kernel/networking/lwip/core/tcp.c`. Supported external network services include DHCP and TCP/IP via lwIP; Unix-domain sockets are handled separately in `src/kernel/syscalls/unixSocket.c`. Userspace is built against musl (`src/libs/musl/build.sh`), started through the system CRT/runtime (`src/libs/system/crt0.c`, `src/libs/system/main.c`), and populated from `target/`, including Xorg configuration and Alpine `apk`-assembled packages.

Main entry points: [`src/kernel/entry/kernel.c`](https://github.com/malwarepad/cavos/blob/master/src/kernel/entry/kernel.c) (Kernel initialization), [`src/kernel/syscalls/syscalls.c`](https://github.com/malwarepad/cavos/blob/master/src/kernel/syscalls/syscalls.c) (Syscall compatibility), [`src/kernel/drivers/pci.c`](https://github.com/malwarepad/cavos/blob/master/src/kernel/drivers/pci.c) (PCI & device drivers), [`Makefile`](https://github.com/malwarepad/cavos/blob/master/Makefile) (Top-level build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Image"]
  node_top_make["Top-level build<br/>build orchestration"]
  node_kernel_make["Kernel build"]
  node_disk_tool["Disk image tool<br/>image assembly<br/>[make_disk.sh]"]
  node_target_root[("Target root filesystem<br/>root filesystem content")]
end

subgraph group_boot["Boot"]
  node_limine_config["Limine configuration<br/>boot config<br/>[limine.conf]"]
  node_boot_entry["Boot handoff<br/>kernel entry<br/>[bootloader.c]"]
  node_kernel_entry["Kernel initialization<br/>kernel entry<br/>[kernel.c]"]
  node_linker_layout["Kernel link layout<br/>linker script<br/>[link.ld]"]
end

subgraph group_kernel["Kernel Core"]
  node_platform_init["CPU, interrupts &amp; ACPI<br/>platform initialization<br/>[idt.c]"]
  node_memory["Memory management<br/>PMM, paging and VMM<br/>[paging.c]"]
  node_scheduler["Tasks &amp; scheduler<br/>preemptive multitasking<br/>[schedule.c]"]
  node_syscall_entry["Fast syscall entry<br/>x86 syscall entry<br/>[fastSyscall.c]"]
  node_syscall_api["Syscall compatibility<br/>kernel syscall API<br/>[syscalls.c]"]
  node_elf_loader["ELF loader<br/>program loader<br/>[elf.c]"]
end

subgraph group_io["Devices, FS &amp; Network"]
  node_pci_drivers["PCI &amp; device drivers<br/>hardware drivers<br/>[pci.c]"]
  node_storage["AHCI disk layer<br/>block storage<br/>[ahci.c]"]
  node_vfs["VFS mounts &amp; dispatch<br/>virtual filesystem<br/>[vfs_controller.c]"]
  node_ext2[("Ext2 root storage<br/>filesystem driver<br/>[ext2_controller.c]")]
  node_network["Network stack<br/>sockets and lwIP<br/>[socket.c]"]
  node_console["Framebuffer console<br/>console and terminal<br/>[console.c]"]
end

subgraph group_user["Userspace"]
  node_musl["musl runtime build<br/>C userspace runtime<br/>[build.sh]"]
  node_crt0["System CRT startup<br/>userspace startup<br/>[crt0.c]"]
end

node_top_make -->|"builds"| node_kernel_make
node_top_make -->|"populates"| node_target_root
node_top_make -->|"invokes"| node_disk_tool
node_kernel_make -->|"links with"| node_linker_layout
node_disk_tool -->|"includes"| node_limine_config
node_disk_tool -->|"packages"| node_target_root
node_boot_entry -->|"hands off to"| node_kernel_entry
node_kernel_entry -->|"initializes"| node_platform_init
node_kernel_entry -->|"initializes"| node_memory
node_kernel_entry -->|"starts"| node_scheduler
node_platform_init -->|"enables"| node_pci_drivers
node_memory -->|"provides address spaces"| node_scheduler
node_syscall_entry -->|"dispatches"| node_syscall_api
node_syscall_api -->|"filesystem requests"| node_vfs
node_syscall_api -->|"socket requests"| node_network
node_syscall_api -->|"exec requests"| node_elf_loader
node_pci_drivers -->|"selects"| node_storage
node_pci_drivers -->|"connects NICs"| node_network
node_pci_drivers -->|"provides display hardware"| node_console
node_storage -->|"block I/O"| node_ext2
node_vfs -->|"mounts root"| node_ext2
node_musl -->|"runtime for"| node_crt0
node_crt0 -->|"user requests"| node_syscall_entry

click node_top_make "https://github.com/malwarepad/cavos/blob/master/Makefile"
click node_kernel_make "https://github.com/malwarepad/cavos/blob/master/src/kernel/Makefile"
click node_disk_tool "https://github.com/malwarepad/cavos/blob/master/tools/kernel/make_disk.sh"
click node_limine_config "https://github.com/malwarepad/cavos/blob/master/target/boot/limine/limine.conf"
click node_boot_entry "https://github.com/malwarepad/cavos/blob/master/src/kernel/entry/bootloader.c"
click node_kernel_entry "https://github.com/malwarepad/cavos/blob/master/src/kernel/entry/kernel.c"
click node_linker_layout "https://github.com/malwarepad/cavos/blob/master/src/kernel/link.ld"
click node_platform_init "https://github.com/malwarepad/cavos/blob/master/src/kernel/cpu/idt.c"
click node_memory "https://github.com/malwarepad/cavos/blob/master/src/kernel/memory/paging.c"
click node_scheduler "https://github.com/malwarepad/cavos/blob/master/src/kernel/multitasking/schedule.c"
click node_syscall_entry "https://github.com/malwarepad/cavos/blob/master/src/kernel/cpu/fastSyscall.c"
click node_syscall_api "https://github.com/malwarepad/cavos/blob/master/src/kernel/syscalls/syscalls.c"
click node_pci_drivers "https://github.com/malwarepad/cavos/blob/master/src/kernel/drivers/pci.c"
click node_storage "https://github.com/malwarepad/cavos/blob/master/src/kernel/drivers/ahci.c"
click node_vfs "https://github.com/malwarepad/cavos/blob/master/src/kernel/filesystems/vfs/vfs_controller.c"
click node_ext2 "https://github.com/malwarepad/cavos/blob/master/src/kernel/filesystems/ext2/ext2_controller.c"
click node_network "https://github.com/malwarepad/cavos/blob/master/src/kernel/networking/socket.c"
click node_console "https://github.com/malwarepad/cavos/blob/master/src/kernel/graphical/console.c"
click node_elf_loader "https://github.com/malwarepad/cavos/blob/master/src/kernel/utilities/elf.c"
click node_musl "https://github.com/malwarepad/cavos/blob/master/src/libs/musl/build.sh"
click node_crt0 "https://github.com/malwarepad/cavos/blob/master/src/libs/system/crt0.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_top_make,node_kernel_make,node_disk_tool,node_target_root toneBlue
class node_limine_config,node_boot_entry,node_kernel_entry,node_linker_layout toneAmber
class node_platform_init,node_memory,node_scheduler,node_syscall_entry,node_syscall_api,node_elf_loader toneMint
class node_pci_drivers,node_storage,node_vfs,node_ext2,node_network,node_console toneRose
class node_musl,node_crt0 toneIndigo
```

## Components

### Build & Image

- [Top-level build](https://github.com/malwarepad/cavos/blob/master/Makefile): build orchestration · Builds the kernel, userspace, target root, and bootable image. · `Makefile`
- [Kernel build](https://github.com/malwarepad/cavos/blob/master/src/kernel/Makefile): kernel build · `src/kernel/Makefile`
- [Disk image tool](https://github.com/malwarepad/cavos/blob/master/tools/kernel/make_disk.sh): image assembly · Creates bootable FAT32 media and the root partition image. · `tools/kernel/make_disk.sh`
- **Target root filesystem**: root filesystem content · Contains packaged userspace, boot assets, and system configuration.

### Boot

- [Limine configuration](https://github.com/malwarepad/cavos/blob/master/target/boot/limine/limine.conf): boot config · `target/boot/limine/limine.conf`
- [Boot handoff](https://github.com/malwarepad/cavos/blob/master/src/kernel/entry/bootloader.c): kernel entry · Receives Limine state and enters early kernel initialization. · `src/kernel/entry/bootloader.c`
- [Kernel initialization](https://github.com/malwarepad/cavos/blob/master/src/kernel/entry/kernel.c): kernel entry · `src/kernel/entry/kernel.c`
- [Kernel link layout](https://github.com/malwarepad/cavos/blob/master/src/kernel/link.ld): linker script · `src/kernel/link.ld`

### Kernel Core

- [CPU, interrupts & ACPI](https://github.com/malwarepad/cavos/blob/master/src/kernel/cpu/idt.c): platform initialization · Establishes descriptor tables, interrupt control, APIC timing, and firmware discovery. · `src/kernel/cpu/idt.c`
- [Memory management](https://github.com/malwarepad/cavos/blob/master/src/kernel/memory/paging.c): PMM, paging and VMM · Provides physical allocation, virtual mappings, and process address spaces. · `src/kernel/memory/paging.c`
- [Tasks & scheduler](https://github.com/malwarepad/cavos/blob/master/src/kernel/multitasking/schedule.c): preemptive multitasking · Manages task state, stacks, and scheduling. · `src/kernel/multitasking/schedule.c`
- [Fast syscall entry](https://github.com/malwarepad/cavos/blob/master/src/kernel/cpu/fastSyscall.c): x86 syscall entry · `src/kernel/cpu/fastSyscall.c`
- [Syscall compatibility](https://github.com/malwarepad/cavos/blob/master/src/kernel/syscalls/syscalls.c): kernel syscall API · Routes Linux-shaped requests to process, memory, I/O, IPC, and filesystem services. · `src/kernel/syscalls/syscalls.c`
- [ELF loader](https://github.com/malwarepad/cavos/blob/master/src/kernel/utilities/elf.c): program loader · `src/kernel/utilities/elf.c`

### Devices, FS & Network

- [PCI & device drivers](https://github.com/malwarepad/cavos/blob/master/src/kernel/drivers/pci.c): hardware drivers · Discovers PCI hardware and selects storage, input, display, and NIC drivers. · `src/kernel/drivers/pci.c`
- [AHCI disk layer](https://github.com/malwarepad/cavos/blob/master/src/kernel/drivers/ahci.c): block storage · `src/kernel/drivers/ahci.c`
- [VFS mounts & dispatch](https://github.com/malwarepad/cavos/blob/master/src/kernel/filesystems/vfs/vfs_controller.c): virtual filesystem · Dispatches paths across Ext2, FAT32, and synthetic filesystem controllers. · `src/kernel/filesystems/vfs/vfs_controller.c`
- [Ext2 root storage](https://github.com/malwarepad/cavos/blob/master/src/kernel/filesystems/ext2/ext2_controller.c): filesystem driver · `src/kernel/filesystems/ext2/ext2_controller.c`
- [Network stack](https://github.com/malwarepad/cavos/blob/master/src/kernel/networking/socket.c): sockets and lwIP · Connects NIC traffic to socket handling and the bundled TCP/IP stack. · `src/kernel/networking/socket.c`
- [Framebuffer console](https://github.com/malwarepad/cavos/blob/master/src/kernel/graphical/console.c): console and terminal · Renders terminal output and exposes framebuffer support for /dev/fb0. · `src/kernel/graphical/console.c`

### Userspace

- [musl runtime build](https://github.com/malwarepad/cavos/blob/master/src/libs/musl/build.sh): C userspace runtime · `src/libs/musl/build.sh`
- [System CRT startup](https://github.com/malwarepad/cavos/blob/master/src/libs/system/crt0.c): userspace startup · Initializes userspace before invoking the system main routine. · `src/libs/system/crt0.c`

## Connections

- Top-level build → Kernel build: builds
- Top-level build → Target root filesystem: populates
- Top-level build → Disk image tool: invokes
- Kernel build → Kernel link layout: links with
- Disk image tool → Limine configuration: includes
- Disk image tool → Target root filesystem: packages
- Boot handoff → Kernel initialization: hands off to
- Kernel initialization → CPU, interrupts & ACPI: initializes
- Kernel initialization → Memory management: initializes
- Kernel initialization → Tasks & scheduler: starts
- CPU, interrupts & ACPI → PCI & device drivers: enables
- Memory management → Tasks & scheduler: provides address spaces
- Fast syscall entry → Syscall compatibility: dispatches
- Syscall compatibility → VFS mounts & dispatch: filesystem requests
- Syscall compatibility → Network stack: socket requests
- Syscall compatibility → ELF loader: exec requests
- PCI & device drivers → AHCI disk layer: selects
- PCI & device drivers → Network stack: connects NICs
- PCI & device drivers → Framebuffer console: provides display hardware
- AHCI disk layer → Ext2 root storage: block I/O
- VFS mounts & dispatch → Ext2 root storage: mounts root
- musl runtime build → System CRT startup: runtime for
- System CRT startup → Fast syscall entry: user requests
