# grisuno/minios architecture

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

- Interactive diagram: https://gitdiagram.com/grisuno/minios
- Repository: https://github.com/grisuno/minios

## Overview

#### Purpose and Entry Points
MiniOS is a bootable 64-bit x86 teaching OS that includes a ramdisk, interactive shell/editor, executable loaders, network stack, TLS client, and prebuilt self-hosting toolchain artifacts. Build orchestration is in `Makefile`; bootable output is `os.img`. Primary runtime entry is the BIOS boot path, while `mcp/minios_mcp.py` is a host-side MCP/stdio JSON-RPC entry point for agents.

#### Boot and Kernel Bring-up
The disk image boots through a two-stage BIOS loader. Stage 1 performs LBA reads to load stage 2; stage 2 loads the kernel above 1 MB and enters x86-64 long mode. Shared layout constants coordinate these boundaries.
- `stage1.S`
- `stage2.S`
- `bootdefs.h`
- `bootloader.c`
- `kernel.c`
- `kernel.ld`

#### Kernel Runtime and User Interaction
The monolithic kernel owns console I/O, memory/heap behavior, ramdisk access, shell, line editor, program loading, and syscall-compatible execution support. The shell is the main control plane: it reads and writes ramdisk files, invokes toolchain objects, runs ELF or CVM content, redirects output, and exposes network commands.
- `kernel.c`
- `kernel.h`
- `ramdisk_data.c`

#### Ramdisk and Self-Hosted Development Loop
`progs/` is packaged into an in-memory filesystem at image-build time. It supplies source files, demos, utilities, and compiled toolchain modules. Inside MiniOS, users edit C, execute `minigcc.o` to produce assembly, execute `ld.o` to link it, then run the resulting ELF. Full source regeneration depends on sibling miniGCC, ld, and CVM repositories; prebuilt artifacts allow a standalone checkout to build an image.
- `mkramdisk.py`
- `progs/minigcc.o`
- `progs/ld.o`
- `progs/cvm.o`
- `progs/bin/cp.c`

#### Program Loading and Execution Boundary
MiniOS supports three execution formats: relocatable objects dynamically linked against kernel-exported libc symbols; Linux `ET_EXEC`/`ET_DYN` binaries using the x86-64 syscall ABI; and CVM bytecode interpreted through the ramdisk-supplied CVM object. This is the principal compatibility boundary between kernel services and guest programs.
- `kernel.c`
- `cvm_host.c`
- `progs/fib.cvm`

#### Networking and HTTPS
The kernel directly drives an rtl8139 NIC under QEMU user-mode networking. It implements Ethernet through TCP, including DNS, then layers a TLS 1.2 client with ECDHE RSA/ECDSA, AES-128-GCM, certificate-chain validation, and hostname verification. Embedded CA roots are generated from DER sources. Networked user programs consume these kernel facilities through TLS syscalls.
- `net.c`
- `net.h`
- `tls.c`
- `tls_crypto.c`
- `tls_x509.c`
- `tls_roots_src/`

#### External Runtime and Validation
QEMU is the material execution environment for graphical, serial, and behavioral runs; its rtl8139/slirp setup provides guest networking. Host TLS validation uses Python and OpenSSL-driven servers. The `freedom` program is the key HTTPS client/browser workload, while MCP launches and supervises QEMU over a PTY serial console.
- `progs/bin/freedom`
- `test_http_server.py`
- `tls_test.py`
- `mcp/minios_mcp.py`

#### Agent Integration Boundary
The MCP bridge owns QEMU lifecycle and translates validated stdio JSON-RPC requests into serial-console interactions. It exposes boot, send/expect, filesystem-oriented, snapshot, status, and shutdown operations; the skill documents the intended in-guest development workflow.
- `mcp/minios_mcp.py`
- `mcp/minios_addons.py`
- `skills/minios/SKILL.md`

Main entry points: [`kernel.c`](https://github.com/grisuno/minios/blob/main/kernel.c) (Monolithic kernel), [`stage2.S`](https://github.com/grisuno/minios/blob/main/stage2.S) (BIOS stage 2), [`Makefile`](https://github.com/grisuno/minios/blob/main/Makefile) (Build orchestration), [`stage1.S`](https://github.com/grisuno/minios/blob/main/stage1.S) (BIOS stage 1)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Image Build"]
  node_make["Build orchestration<br/>Makefile"]
  node_ramdisk_builder["Ramdisk packer<br/>packaging script<br/>[mkramdisk.py]"]
  node_programs[("Packaged programs<br/>ramdisk content")]
end

subgraph group_boot["Boot Path"]
  node_stage1["BIOS stage 1<br/>boot assembly<br/>[stage1.S]"]
  node_stage2["BIOS stage 2<br/>boot assembly<br/>[stage2.S]"]
  node_boot_layout["Boot layout<br/>shared constants<br/>[bootdefs.h]"]
  node_bootloader["Boot loader support<br/>boot C runtime<br/>[bootloader.c]"]
  node_linker["Kernel linker layout<br/>linker script<br/>[kernel.ld]"]
end

subgraph group_kernel["Kernel Runtime"]
  node_kernel{{"Monolithic kernel<br/>x86-64 kernel<br/>[kernel.c]"}}
  node_ramdisk[("In-memory filesystem<br/>ramdisk image data<br/>[ramdisk_data.c]")]
  node_exec["Program execution<br/>loader boundary<br/>[kernel.c]"]
  node_cvm_host["CVM host adapter<br/>bytecode host<br/>[cvm_host.c]"]
  node_network["Network stack<br/>kernel networking<br/>[net.c]"]
  node_tls["TLS 1.2 client<br/>kernel TLS<br/>[tls.c]"]
  node_roots["CA root sources<br/>certificate inputs"]
end

subgraph group_host["Host Control &amp; Validation"]
  node_qemu{{"QEMU runtime<br/>emulator"}}
  node_mcp["MCP bridge<br/>stdio JSON-RPC service<br/>[minios_mcp.py]"]
  node_tls_validation["Host TLS validation<br/>test server and checks<br/>[tls_test.py]"]
  node_freedom["Freedom HTTPS client<br/>guest workload"]
  node_skill["MiniOS workflow skill<br/>agent documentation<br/>[SKILL.md]"]
end

node_make -->|"packages"| node_ramdisk_builder
node_ramdisk_builder -->|"reads"| node_programs
node_ramdisk_builder -->|"generates"| node_ramdisk
node_make -->|"builds image"| node_stage1
node_make -->|"builds image"| node_stage2
node_make -->|"links"| node_kernel
node_boot_layout -->|"defines layout"| node_stage1
node_boot_layout -->|"defines layout"| node_stage2
node_stage1 -->|"LBA loads"| node_stage2
node_stage2 -->|"uses"| node_bootloader
node_stage2 -->|"loads and enters long mode"| node_kernel
node_linker -->|"places"| node_kernel
node_ramdisk -->|"mounted by"| node_kernel
node_kernel -->|"provides"| node_exec
node_exec -->|"interprets CVM via"| node_cvm_host
node_programs -->|"supplies tools and guests"| node_exec
node_kernel -->|"owns"| node_network
node_network -->|"transport for"| node_tls
node_roots -->|"trust inputs"| node_tls
node_freedom -->|"uses TLS syscalls"| node_tls
node_qemu -->|"boots"| node_stage1
node_mcp -->|"launches and controls"| node_qemu
node_skill -.->|"documents workflow"| node_mcp
node_tls_validation -.->|"validates HTTPS workload"| node_freedom

click node_make "https://github.com/grisuno/minios/blob/main/Makefile"
click node_ramdisk_builder "https://github.com/grisuno/minios/blob/main/mkramdisk.py"
click node_stage1 "https://github.com/grisuno/minios/blob/main/stage1.S"
click node_stage2 "https://github.com/grisuno/minios/blob/main/stage2.S"
click node_boot_layout "https://github.com/grisuno/minios/blob/main/bootdefs.h"
click node_bootloader "https://github.com/grisuno/minios/blob/main/bootloader.c"
click node_linker "https://github.com/grisuno/minios/blob/main/kernel.ld"
click node_kernel "https://github.com/grisuno/minios/blob/main/kernel.c"
click node_ramdisk "https://github.com/grisuno/minios/blob/main/ramdisk_data.c"
click node_exec "https://github.com/grisuno/minios/blob/main/kernel.c"
click node_cvm_host "https://github.com/grisuno/minios/blob/main/cvm_host.c"
click node_network "https://github.com/grisuno/minios/blob/main/net.c"
click node_tls "https://github.com/grisuno/minios/blob/main/tls.c"
click node_mcp "https://github.com/grisuno/minios/blob/main/mcp/minios_mcp.py"
click node_tls_validation "https://github.com/grisuno/minios/blob/main/tls_test.py"
click node_freedom "https://github.com/grisuno/minios/blob/main/progs/bin/freedom"
click node_skill "https://github.com/grisuno/minios/blob/main/skills/minios/SKILL.md"

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_make,node_ramdisk_builder,node_programs toneBlue
class node_stage1,node_stage2,node_boot_layout,node_bootloader,node_linker toneAmber
class node_kernel,node_ramdisk,node_exec,node_cvm_host,node_network,node_tls,node_roots toneMint
class node_qemu,node_mcp,node_tls_validation,node_freedom,node_skill toneRose
```

## Components

### Image Build

- [Build orchestration](https://github.com/grisuno/minios/blob/main/Makefile): Makefile · Builds the bootable image and packages runtime artifacts. · `Makefile`
- [Ramdisk packer](https://github.com/grisuno/minios/blob/main/mkramdisk.py): packaging script · `mkramdisk.py`
- **Packaged programs**: ramdisk content · Sources, utilities, demos, and prebuilt self-hosting modules.

### Boot Path

- [BIOS stage 1](https://github.com/grisuno/minios/blob/main/stage1.S): boot assembly · Reads stage 2 using LBA. · `stage1.S`
- [BIOS stage 2](https://github.com/grisuno/minios/blob/main/stage2.S): boot assembly · Loads the kernel above 1 MB and enters long mode. · `stage2.S`
- [Boot layout](https://github.com/grisuno/minios/blob/main/bootdefs.h): shared constants · `bootdefs.h`
- [Boot loader support](https://github.com/grisuno/minios/blob/main/bootloader.c): boot C runtime · `bootloader.c`
- [Kernel linker layout](https://github.com/grisuno/minios/blob/main/kernel.ld): linker script · `kernel.ld`

### Kernel Runtime

- [Monolithic kernel](https://github.com/grisuno/minios/blob/main/kernel.c): x86-64 kernel · Owns console, memory, ramdisk, shell, loaders, and syscall-compatible execution. · `kernel.c`
- [In-memory filesystem](https://github.com/grisuno/minios/blob/main/ramdisk_data.c): ramdisk image data · `ramdisk_data.c`
- [Program execution](https://github.com/grisuno/minios/blob/main/kernel.c): loader boundary · Runs relocatable objects, ELF ET_EXEC/ET_DYN binaries, and CVM bytecode. · `kernel.c`
- [CVM host adapter](https://github.com/grisuno/minios/blob/main/cvm_host.c): bytecode host · `cvm_host.c`
- [Network stack](https://github.com/grisuno/minios/blob/main/net.c): kernel networking · Drives rtl8139 and implements Ethernet through TCP plus DNS. · `net.c`
- [TLS 1.2 client](https://github.com/grisuno/minios/blob/main/tls.c): kernel TLS · Provides authenticated HTTPS for guest programs through TLS syscalls. · `tls.c`
- **CA root sources**: certificate inputs

### Host Control & Validation

- **QEMU runtime**: emulator · Runs the image with rtl8139 and slirp guest networking.
- [MCP bridge](https://github.com/grisuno/minios/blob/main/mcp/minios_mcp.py): stdio JSON-RPC service · Supervises QEMU and translates agent requests to serial-console interactions. · `mcp/minios_mcp.py`
- [Host TLS validation](https://github.com/grisuno/minios/blob/main/tls_test.py): test server and checks · Python and OpenSSL-driven HTTPS validation. · `tls_test.py`
- [Freedom HTTPS client](https://github.com/grisuno/minios/blob/main/progs/bin/freedom): guest workload · `progs/bin/freedom`
- [MiniOS workflow skill](https://github.com/grisuno/minios/blob/main/skills/minios/SKILL.md): agent documentation · `skills/minios/SKILL.md`

## Connections

- Build orchestration → Ramdisk packer: packages
- Ramdisk packer → Packaged programs: reads
- Ramdisk packer → In-memory filesystem: generates
- Build orchestration → BIOS stage 1: builds image
- Build orchestration → BIOS stage 2: builds image
- Build orchestration → Monolithic kernel: links
- Boot layout → BIOS stage 1: defines layout
- Boot layout → BIOS stage 2: defines layout
- BIOS stage 1 → BIOS stage 2: LBA loads
- BIOS stage 2 → Boot loader support: uses
- BIOS stage 2 → Monolithic kernel: loads and enters long mode
- Kernel linker layout → Monolithic kernel: places
- In-memory filesystem → Monolithic kernel: mounted by
- Monolithic kernel → Program execution: provides
- Program execution → CVM host adapter: interprets CVM via
- Packaged programs → Program execution: supplies tools and guests
- Monolithic kernel → Network stack: owns
- Network stack → TLS 1.2 client: transport for
- CA root sources → TLS 1.2 client: trust inputs
- Freedom HTTPS client → TLS 1.2 client: uses TLS syscalls
- QEMU runtime → BIOS stage 1: boots
- MCP bridge → QEMU runtime: launches and controls
- MiniOS workflow skill → MCP bridge: documents workflow
- Host TLS validation → Freedom HTTPS client: validates HTTPS workload
