# lushl9301/xtratum architecture

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

- Interactive diagram: https://gitdiagram.com/lushl9301/xtratum
- Repository: https://github.com/lushl9301/xtratum

## Overview

1. This repository is split into three top-level architectural layers: `core` contains the XtratuM hypervisor, `user` contains host-side utilities and guest-side support code, and `scripts` contains build/configuration generators that produce source, headers, and configuration artifacts consumed by both sides.

2. The `core` tree is the privileged runtime. It is organized like a small OS/hypervisor with architecture-specific code under `core/kernel/arch` and common hypervisor logic under `core/kernel`, plus reusable low-level helpers in `core/include`. The build clearly targets at least two hardware families: x86 and SPARC V8/LEON, with separate startup, linker scripts, and config files.

3. Hypervisor boot and CPU bring-up live in the architecture layer: `entry.S`, `head.S`, `start.S`, `boot.c`, `setup.c`, and platform code for APIC/PIC, ACPI/MPS, timers, SMP, and VM mapping. This is the boundary where the hypervisor takes control from firmware/bootloader and initializes interrupts, memory, and processor state.

4. Memory management is a major subsystem. The code is split between physical memory management, reserved memory, and virtual address mapping (`physmm`, `rsvmem`, `vmmap`, `virtmm` in the MMU-specific tree). These components underpin guest isolation and are fed by configuration and boot-time platform discovery.

5. Scheduling and execution control are core services. `sched.c`, `kthread.c`, `ktimer.c`, and the hypercall handlers define how partitions/threads are dispatched, timed, and switched. This suggests XtratuM is a partitioned real-time hypervisor rather than a general-purpose host OS.

6. Interrupt and timer handling are explicit subsystems. The architecture code includes IRQ setup, LAPIC/PIT/HPET/TSC timer support on x86, and there are corresponding low-level interrupt abstractions in the public headers. This separation is important because timing and interrupt routing are central to deterministic partition execution.

7. Device access is provided through a compact driver layer in `core/drivers`. It includes UARTs, VGA text output, memory block helpers, FPGA support, and a substantial TTNoC driver stack (`ttnoc/*`). These drivers are used by the hypervisor itself for console, debug, and platform-specific communication rather than by arbitrary guest code.

8. The `core/objects` directory defines the higher-level managed resources exposed by the hypervisor: communication ports, console, health management, memory objects, status, trace, and TTNoC ports. These objects represent the hypervisor’s internal resource model and are likely the units configured by system descriptions.

9. The public headers under `core/include` form the boundary between core subsystems and everything built on top of them. They define architecture abstractions, hypercalls, guest interfaces, synchronization primitives, paging, PCI, APIC/PIC, and object APIs. This is the main contract surface for both the kernel core and user-space tooling that generate or consume hypervisor definitions.

10. The `user/libxm` library is the runtime API for applications and tools that interact with XtratuM from outside the hypervisor. It wraps hypercalls, container/status/trace management, object descriptors, XEF image handling, and compression/lazy-loading helpers. The presence of separate `x86` and `sparcv8` subtrees shows it is a portability layer over architecture-specific hypercall ABIs.

11. `user/tools` is the build-time tooling pipeline. `xmcparser` parses XML system descriptions and schemas into configuration artifacts; `xmpack` packages them; `xef` handles executable image formatting; `bpatch` and `xmbuildinfo` support binary post-processing and build metadata; `rswbuild` builds boot-related artifacts. These tools are the source of the system configuration that the hypervisor consumes at boot.

12. `user/bootloaders/rsw` is the first-stage user-space boot component. It has separate x86 and SPARC V8 implementations, with architecture-specific boot assembly, linker scripts, serial/VGA output, and shared C support. Its role is to prepare and load the hypervisor/guest image into the machine before control transfers to XtratuM.

13. `user/xal` is the guest-facing application layer library and example suite. It provides a smaller runtime API for partitions, architecture-specific startup and interrupt helpers, and many sample partitions that demonstrate typical partition topologies and communication patterns. The examples are paired with XML configuration files, showing the full flow from system description to runnable partition images.

14. The `scripts/kconfig` and related generators support a Linux-like configuration workflow for the hypervisor and tools. They generate offsets, symbols, and config-derived files used during compilation, making the repository’s build a mix of source code plus generated architecture/configuration artifacts.

15. Overall data flow is: configuration XML and Kconfig inputs are processed by scripts/tools, bootloader artifacts are built in `user/bootloaders/rsw`, partition and management applications are linked against `user/libxm` or `user/xal`, and the resulting images are loaded into the `core` hypervisor, which initializes hardware, sets up memory/interrupts/timers, and schedules partitions while enforcing isolation through hypercalls and managed objects.

Main entry points: [`core/kernel/arch`](https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch) (Boot bring-up), [`core/include`](https://github.com/lushl9301/xtratum/tree/master/core/include) (Core API), [`user/xal/examples`](https://github.com/lushl9301/xtratum/tree/master/user/xal/examples) (Examples), [`user/tools`](https://github.com/lushl9301/xtratum/tree/master/user/tools) (Build tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["core"]
  node_core_boot["Boot bring-up<br/>hypervisor startup"]
  node_core_hw["HW setup<br/>platform init"]
  node_core_mmu["Memory mgmt<br/>mmu subsystem"]
  node_core_sched["Scheduler<br/>dispatch core<br/>[sched.c]"]
  node_core_timeirq["Timers & IRQs<br/>interrupt control"]
  node_core_hypercalls["Hypercalls<br/>kernel ABI<br/>[hypercalls.c]"]
  node_core_obj["Objects<br/>resource model"]
  node_core_drivers["Drivers"]
  node_core_headers["Core API<br/>public headers"]
  node_core_klibc["Klibc<br/>runtime libc"]
end

subgraph group_user["user"]
  node_user_tools["Build tools<br/>toolchain"]
  node_user_rsw["RSW bootloader<br/>first-stage loader"]
  node_user_libxm["libxm<br/>host runtime"]
  node_user_xal["XAL<br/>guest runtime"]
  node_user_examples["Examples<br/>guest apps"]
end

subgraph group_scripts["scripts"]
  node_scripts_kconfig["Kconfig tools<br/>config generator"]
  node_scripts_gen["Generators<br/>build scripts"]
end

node_scripts_kconfig -->|"generate config"| node_core_headers
node_scripts_gen -->|"emit offsets"| node_core_boot
node_scripts_gen -->|"derive headers"| node_core_headers
node_user_tools -->|"build images"| node_user_rsw
node_user_tools -->|"package configs"| node_user_examples
node_user_rsw -->|"handoff"| node_core_boot
node_user_libxm -->|"call ABI"| node_core_hypercalls
node_user_xal -->|"guest ABI"| node_core_hypercalls
node_user_examples -->|"link against"| node_user_xal
node_user_examples -->|"describe system"| node_user_tools
node_core_boot -->|"init platform"| node_core_hw
node_core_hw -->|"enable irq/timers"| node_core_timeirq
node_core_boot -->|"init memory"| node_core_mmu
node_core_mmu -->|"isolate partitions"| node_core_sched
node_core_timeirq -->|"drive ticks"| node_core_sched
node_core_hypercalls -->|"manage resources"| node_core_obj
node_core_drivers -->|"backend support"| node_core_obj
node_core_headers -->|"shared contract"| node_user_libxm
node_core_headers -->|"guest interface"| node_user_xal
node_core_klibc -->|"runtime support"| node_core_boot

click node_core_boot "https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch"
click node_core_hw "https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch"
click node_core_mmu "https://github.com/lushl9301/xtratum/tree/master/core/kernel/mmu"
click node_core_sched "https://github.com/lushl9301/xtratum/blob/master/core/kernel/sched.c"
click node_core_timeirq "https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch"
click node_core_hypercalls "https://github.com/lushl9301/xtratum/blob/master/core/kernel/hypercalls.c"
click node_core_obj "https://github.com/lushl9301/xtratum/tree/master/core/objects"
click node_core_drivers "https://github.com/lushl9301/xtratum/tree/master/core/drivers"
click node_core_headers "https://github.com/lushl9301/xtratum/tree/master/core/include"
click node_core_klibc "https://github.com/lushl9301/xtratum/tree/master/core/klibc"
click node_user_tools "https://github.com/lushl9301/xtratum/tree/master/user/tools"
click node_user_rsw "https://github.com/lushl9301/xtratum/tree/master/user/bootloaders/rsw"
click node_user_libxm "https://github.com/lushl9301/xtratum/tree/master/user/libxm"
click node_user_xal "https://github.com/lushl9301/xtratum/tree/master/user/xal"
click node_user_examples "https://github.com/lushl9301/xtratum/tree/master/user/xal/examples"
click node_scripts_kconfig "https://github.com/lushl9301/xtratum/tree/master/scripts/kconfig"
click node_scripts_gen "https://github.com/lushl9301/xtratum/tree/master/scripts"

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_core_boot,node_core_hw,node_core_mmu,node_core_sched,node_core_timeirq,node_core_hypercalls,node_core_obj,node_core_drivers,node_core_headers,node_core_klibc toneBlue
class node_user_tools,node_user_rsw,node_user_libxm,node_user_xal,node_user_examples toneAmber
class node_scripts_kconfig,node_scripts_gen toneMint
```

## Components

### core

Privileged hypervisor runtime and kernel subsystems

- [Boot bring-up](https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch): hypervisor startup · Architecture entry and CPU initialization from firmware into the hypervisor. · `core/kernel/arch`
- [HW setup](https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch): platform init · ACPI/MPS, APIC/PIC, SMP, and processor-specific platform setup. · `core/kernel/arch`
- [Memory mgmt](https://github.com/lushl9301/xtratum/tree/master/core/kernel/mmu): mmu subsystem · Physical, reserved, virtual, and mapped memory management for isolation. · `core/kernel/mmu`
- [Scheduler](https://github.com/lushl9301/xtratum/blob/master/core/kernel/sched.c): dispatch core · Partition and thread dispatch, switching, and time control. · `core/kernel/sched.c`
- [Timers & IRQs](https://github.com/lushl9301/xtratum/tree/master/core/kernel/arch): interrupt control · Interrupt routing and timer services used for deterministic execution. · `core/kernel/arch`
- [Hypercalls](https://github.com/lushl9301/xtratum/blob/master/core/kernel/hypercalls.c): kernel ABI · Hypercall entry points and privileged service dispatch. · `core/kernel/hypercalls.c`
- [Objects](https://github.com/lushl9301/xtratum/tree/master/core/objects): resource model · Managed hypervisor objects such as comm ports, console, health, memory, status, trace, and TTNoC ports. · `core/objects`
- [Drivers](https://github.com/lushl9301/xtratum/tree/master/core/drivers): platform drivers · Console, memory block, FPGA, and TTNoC support used by the hypervisor. · `core/drivers`
- [Core API](https://github.com/lushl9301/xtratum/tree/master/core/include): public headers · Boundary headers for architecture abstractions, guests, paging, synchronization, and objects. · `core/include`
- [Klibc](https://github.com/lushl9301/xtratum/tree/master/core/klibc): runtime libc · Minimal internal C library used by core and loader components. · `core/klibc`

### user

Host-side tools, bootloaders, and guest-facing libraries

- [Build tools](https://github.com/lushl9301/xtratum/tree/master/user/tools): toolchain · XML/config parsing, packaging, image formatting, binary patching, and build metadata tools. · `user/tools`
- [RSW bootloader](https://github.com/lushl9301/xtratum/tree/master/user/bootloaders/rsw): first-stage loader · Architecture-specific bootloader that prepares and loads images before handoff. · `user/bootloaders/rsw`
- [libxm](https://github.com/lushl9301/xtratum/tree/master/user/libxm): host runtime · Host-side API for hypercalls, object/status/trace management, XEF handling, and lazy loading. · `user/libxm`
- [XAL](https://github.com/lushl9301/xtratum/tree/master/user/xal): guest runtime · Guest-facing runtime library and support layer for partitions and examples. · `user/xal`
- [Examples](https://github.com/lushl9301/xtratum/tree/master/user/xal/examples): guest apps · Sample partition applications and their XML system descriptions. · `user/xal/examples`

### scripts

Generators and configuration tooling

- [Kconfig tools](https://github.com/lushl9301/xtratum/tree/master/scripts/kconfig): config generator · Configuration and symbol generation pipeline used across the build. · `scripts/kconfig`
- [Generators](https://github.com/lushl9301/xtratum/tree/master/scripts): build scripts · Assembly-offset, symbol, extraction, and composition helpers for generated artifacts. · `scripts`

## Connections

- Kconfig tools → Core API: generate config · Produces config-derived headers and symbols consumed by the core build.
- Generators → Boot bring-up: emit offsets · Generates assembly offsets and build artifacts used by low-level startup code.
- Generators → Core API: derive headers · Creates generated definitions shared by core and user components.
- Build tools → RSW bootloader: build images · Builds bootloader and packaging artifacts for loading system images.
- Build tools → Examples: package configs · Turns XML/system descriptions into packaged runnable outputs.
- RSW bootloader → Boot bring-up: handoff · Transfers control to the hypervisor after loading the runtime image.
- libxm → Hypercalls: call ABI · Wraps hypercall interfaces from host-side management code.
- XAL → Hypercalls: guest ABI · Uses guest-facing hypercalls and runtime services.
- Examples → XAL: link against · Example partitions build on the XAL runtime and support headers.
- Examples → Build tools: describe system · Examples pair code with XML configuration consumed by build tools.
- Boot bring-up → HW setup: init platform · Boot code initializes processor state, interrupts, and platform hardware.
- HW setup → Timers & IRQs: enable irq/timers · Sets up interrupt controllers and timer sources.
- Boot bring-up → Memory mgmt: init memory · Establishes early memory structures and mappings.
- Memory mgmt → Scheduler: isolate partitions · Provides address-space and memory boundaries used by scheduling.
- Timers & IRQs → Scheduler: drive ticks · Timer and IRQ events trigger dispatch and time accounting.
- Hypercalls → Objects: manage resources · Hypercalls operate on managed objects and hypervisor state.
- Drivers → Objects: backend support · Drivers provide console and platform backends for core objects.
- Core API → libxm: shared contract · Public headers define the ABI and object interfaces used by libxm.
- Core API → XAL: guest interface · Guest code consumes the core-facing ABI and low-level abstractions.
- Klibc → Boot bring-up: runtime support · Provides minimal C library services for early and low-level code.
