# hermit-os/kernel architecture

> Architecture diagram of the GitHub repository hermit-os/kernel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hermit-os/kernel
- Repository: https://github.com/hermit-os/kernel

## Overview

##### Main Components Organization

a) Architecture Layer (Top Level)
- Kernel (interrupts, scheduler, processor management)
- Memory Management (paging, physical/virtual memory)
- Architecture-specific features (like ACPI for x86_64)

b) Core Kernel Services (Middle Layer)
- Drivers subsystem
- Network drivers (virtio, rtl8139, gem)
- File system drivers
- PCI and MMIO interfaces
- Memory Management
- Task Execution
- System Calls Interface
- Synchronization Primitives

c) Interface Layer (Bottom Layer)
- External Interface components
- Application Integration points
- Runtime support

##### Detailed Elements

For each major component, show:
- Key files/modules
- External dependencies
- Interface points
- Cross-cutting concerns (logging, error handling)

##### Implementation Details

- Memory management system
- Task scheduling
- Device driver architecture
- System call interface

##### Notes Section

Annotations for:
- Build configuration options
- Architecture-specific features
- Logging levels (HERMIT_LOG_LEVEL_FILTER)
- Integration points with Rust/C++ applications

- The modular architecture supporting multiple CPU architectures
- The clean separation between architecture-specific and common code
- The driver subsystem's extensibility
- The system call interface design
- Memory management and task execution models

Keep the abstraction level high enough to show the overall architecture while including enough detail to understand the key components and their interactions. Focus on showing how the unikernel nature of the project influences its architecture and how it differs from traditional kernels.

Remember to highlight the integration points with applications, as this is primarily used as a library kernel linked to applications rather than a standalone operating system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Architecture Layer
    subgraph Architectures
        x86["x86_64 Architecture"]
        aarch["aarch64 Architecture"]
        riscv["riscv64 Architecture"]
    end

    %% Core Kernel Services
    subgraph KernelServices
        mm["Memory Management"]:::memory
        task["Task Execution"]:::task
        syscall["System Calls Interface"]:::syscall
        sync["Synchronization"]:::sync
    end

    %% Drivers Layer
    subgraph Drivers
        net["Network Drivers"]:::driver
        fs["File System Drivers"]:::driver
        virtio["Virtio Subsystem"]:::driver
        pci["PCI Interface"]:::driver
    end

    %% Interface Layer
    subgraph Interfaces
        extif["External Interface"]:::interface
        appint["Application Integration"]:::interface
        runtime["Runtime Support"]:::interface
    end

    %% Relationships
    Architectures --> KernelServices
    KernelServices --> Drivers
    Drivers --> Interfaces

    %% Component Details
    mm --> task
    syscall --> task
    sync --> task
    virtio --> net
    virtio --> fs
    
    %% Click Events
    click x86 "https://github.com/hermit-os/kernel/tree/main/src/arch/x86_64/"
    click aarch "https://github.com/hermit-os/kernel/tree/main/src/arch/aarch64/"
    click riscv "https://github.com/hermit-os/kernel/tree/main/src/arch/riscv64/"
    click mm "https://github.com/hermit-os/kernel/tree/main/src/mm/"
    click task "https://github.com/hermit-os/kernel/tree/main/src/executor/"
    click syscall "https://github.com/hermit-os/kernel/tree/main/src/syscalls/"
    click sync "https://github.com/hermit-os/kernel/tree/main/src/synch/"
    click net "https://github.com/hermit-os/kernel/tree/main/src/drivers/net/"
    click fs "https://github.com/hermit-os/kernel/tree/main/src/drivers/fs/"
    click virtio "https://github.com/hermit-os/kernel/tree/main/src/drivers/virtio/"

    %% Styling
    classDef memory fill:#a8d1ff
    classDef task fill:#ffb3b3
    classDef syscall fill:#b3ffb3
    classDef sync fill:#ffccff
    classDef driver fill:#ffd9b3
    classDef interface fill:#ffffb3

    %% Legend
    subgraph Legend
        l1["Memory Management"]:::memory
        l2["Task Execution"]:::task
        l3["System Calls"]:::syscall
        l4["Synchronization"]:::sync
        l5["Drivers"]:::driver
        l6["Interfaces"]:::interface
    end
```
