Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

Refresh README.md landing page and add CONTRIBUTING.md

Alexey Fateeva108e680384c
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..d6d6e29
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,55 @@
+# Contributing to llm.asm
+
+Thank you for checking out **llm.asm**! This repository explores how far extreme low-level AI can go without runtime bloat—tens of kilobytes, zero libc, deterministic math, and hard hardware verification.
+
+To keep `main` focused and maintainable, please review our scope and pull request guidelines before contributing.
+
+## Project Ethos
+
+Every component in this repository is built around four rules:
+
+- **Zero runtime bloat:** Core binaries must ship with zero dynamic libraries (`readelf -d` reports no dynamic section) and zero unnecessary runtime dependencies.
+- **Phases `01–03` (Pure Assembly):** Strictly **100% pure x86-64 NASM** (`nasm` + `ld`). Zero C, zero C++, zero Rust, zero libc, zero libm.
+- **Phases `04–05+` (Hypervisor & Kernel ML):** Freestanding Ring `-1` hypervisors (NASM + zero-libc C) and verifier-clean in-kernel eBPF ML (`0` floats, bounded loops, verifiable safety).
+- **Hard verification:** Every math kernel, binary format change, and performance claim must be backed by reproducible parity and benchmark evidence.
+
+## What Belongs Upstream (In Scope)
+
+PRs that directly strengthen the existing phases and core ethos are welcome:
+
+- **Bug fixes & safety:** Bounds checks, argument parsing safety, ELF/Multiboot/NPT edge cases, register/ABI preservation, and crash or leak fixes.
+- **Docs & size accuracy:** Fixing broken commands, clarifying reproduction steps, and keeping binary sizes and benchmark numbers strictly factual.
+- **Pure x86-64 NASM optimizations & ISA fallbacks:** Faster AVX2/FMA/F16C kernels, clean fallback paths (e.g., AVX1) that preserve `FAST_Q8=1|0` and bit-exactness, and compact zero-dependency kernel or model work.
+- **Unified bare-metal boot & hardware fixes:** Real-hardware ACPI/APIC, VGA/serial, and loader fixes—please check open PRs first so we do not duplicate loaders.
+- **CI & automated verification:** Clean scripts and CI workflows covering `make all`, `make check-all`, and existing parity harnesses.
+
+## What Belongs in Your Own Fork / Repo (Out of Scope for `main`)
+
+To keep `llm.asm` tight and true to its scope, we do **not** merge the following into `main`:
+
+- **Ports to other CPU/GPU stacks or languages:** ARM64, RISC-V, C++, Rust, Metal, CUDA, or WebGPU rewrites.
+- **Heavy host-side wrappers:** HTTP/OpenAI API proxies, agent framework glue, GUIs, or desktop installers.
+- **General-purpose multi-model USB OS distributions:** Broad hardware-enablement distros, package managers, or multi-engine live USB images.
+
+> **Cool ports and wrappers are genuinely welcome!** Build them in your own repository and open an issue or PR adding a link to the **Ecosystem** section of [`README.md`](README.md) so the community can discover your project.
+
+## Pull Request Checklist
+
+Before opening a PR, please confirm all of the following:
+
+1. **Small, focused diff:** One cohesive change per PR. Avoid unrelated formatting sweeps or edits to untouched phases.
+2. **Zero new runtime dependencies:** Do not introduce libc, shared libraries, or new runtime tools into core binaries.
+3. **Reproducible numbers only:** Include the exact commands and measured parity/benchmark outputs in your PR description. Never alter benchmark tables or binary size claims in `README.md` without an independently reproducible run.
+4. **Preserve formats & builds:** Keep `.asmbin` v1/v2 compatibility intact and verify that builds and checks pass cleanly:
+
+```bash
+# Phases 1–3 build, ELF inspection, and assembly math kernel tests
+make all && make check-all
+python3 scripts/test_math.py build/test_math
+
+# Phase 4 verifier selftest (when touching 04-ring1-kernel-surgeon/)
+python3 04-ring1-kernel-surgeon/verifier/kvm_verifier.py --selftest
+
+# Phase 5 KVM verification (when touching 05-ebpf-jev/)
+python3 05-ebpf-jev/testbed/verify_demo.py
+```
diff --git a/README.md b/README.md
index 1b7fe85..e30ad0a 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,33 @@
+<div align="center">
+
# llm.asm
-**Three complete LLM projects written in 100% pure x86-64 NASM assembly.**
-Zero C, zero C++, zero Rust, zero libc, zero libm, zero runtime dependencies.
+**AI where it doesn't belong — bare metal, Ring `-1` hypervisors, and Linux kernel eBPF.**
+*Zero libc. Zero runtime dependencies. Tens of kilobytes.*
+
+[Projects](#projects) · [Benchmarks](#benchmarks) · [Proof](#proof) · [Quick Start](#quick-start) · [Ecosystem](#ecosystem) · [Contributing](#contributing) · [MIT License](LICENSE)
-Assembled directly with `nasm` and linked with `ld`. Every math kernel (`expf`, `sincosf`, `RMSNorm`, `RoPE`, `SiLU`, `Softmax`), AVX2+FMA+F16C GEMM/GEMV engine, BPE tokenizer, `clone()`/`futex()` thread pool, bare-metal SMP kernel, analytical backward pass, AdamW optimizer, and live Unicode Braille TUI is hand-written x86-64 assembly (`17,252` lines total across all three projects).
+</div>
-## The Projects
+---
-| Project | Binary | Size | Deps | Key Numbers |
-|---|---|---:|---:|---|
-| **[01-qwen3-inference/](01-qwen3-inference/)** | `build/asm-llm` | **14,712 B** *(14,008 B `FAST_Q8=0`)* | **0** | Pure x86-64 NASM static Linux ELF running `Qwen/Qwen3-0.6B` (Q8_0, built-in BPE tokenizer, GQA + QK-Norm + RoPE + SwiGLU, single-shot & `--chat` multi-turn KV-cache REPL). **`FAST_Q8=1` (default):** **126.8 tok/s** decode at 40T (**20.7 tok/s** at 1T), **+18% to +36% faster than `llama.cpp` CPU (`Q8_0`) across 1..40T**, **`0.99965`** cosine & **64/64** exact greedy tokens vs PyTorch FP32. |
-| **[02-baremetal-os/](02-baremetal-os/)** | `build/asm-llm-os.elf` | **24,252 B** *(23,612 B `FAST_Q8=0`)* | **0** | Pure x86-64 NASM bootable bare-metal `Qwen3-0.6B` OS with no Linux or Windows. Multiboot 1 -> Long Mode -> AVX2/FMA/F16C -> ACPI/APIC SMP -> VGA + PS/2 + COM1 multi-turn KV-cache chat (`/clear`, `/think`, `/bench`). **74–94 ms** boot, **134.9 tok/s** KVM EPYC (**23.7 tok/s** 1 vCPU, **136.6 tok/s** peak), **55.4 tok/s** live on Proxmox Xeon E5-2670 v3 with **0 GB** disk. |
-| **[03-minigpt-train/](03-minigpt-train/)** | `build/asm-gpt-train` | **32,944 B** | **0** | Pure x86-64 NASM FP32 Mini-GPT trainer and sampler. Register-blocked `6x16` AVX2+FMA SGEMM, full analytical backward pass (**`1.0000000000`** cosine across all 21 gradient tensors vs PyTorch CPU), decoupled AdamW, **27,662 train tok/s**, live 80x24 Braille TUI, `val_loss 4.19 -> 1.51` on TinyShakespeare in 4 min. |
-| **[04-ring1-kernel-surgeon/](04-ring1-kernel-surgeon/)** | `04-ring1-kernel-surgeon/build/surgeon.elf` | **75,424 B** | **0** *(freestanding NASM + zero-libc C)* | Bare-metal Type-1 AMD SVM hypervisor (`Ring -1`) running beneath unmodified Linux `5.15` (`Ring 0`) with an embedded **MiniCPM5-2B `Q4_K_M`** engine across 24 LAPIC SMP cores, NPT memory isolation, live `efifb` HUD, static x86-64 patch validator, and single-level KVM verifier RL. **97.54% pass@1** (`119/122` unseen test scenarios, `0%` dangerous continues) vs **16.39%** base. |
-| **[05-ebpf-jev/](05-ebpf-jev/)** | `05-ebpf-jev/ml/out/ebpf_jev_model.bin` | **21,280 B** *(INT8 weights)* | **0** *(in-kernel eBPF LSM)* | Fixed-point INT8 recurrent decision model (`64 -> 64 -> 4` + FNV-1a 3-gram embeddings) running directly inside four Linux `6.12.118` eBPF LSM hooks (`21,457` verified insns / 1M limit, `0` floats, `0` tail calls, `0` userspace RTT). Carries 32-byte `h[32]` state in `BPF_MAP_TYPE_TASK_STORAGE` across `fork()`/`execve()`, blocks secret exfiltration with `-EPERM` at **5.65 µs** median hook latency (**12.25 µs** p99), **0** false denies / 1,000 across 3,840 unseen workflows (**75%** strict-gate recall vs **50%** stateless, **0.947** evasion F1), **500/500** `0-LSB` parity, and live atomic weight hot-swap. |
+## Projects
+
+| Phase | Target | Size | Stack | Headline Result |
+|---|---|---:|---|---|
+| [`01`](01-qwen3-inference/) | [`01-qwen3-inference/`](01-qwen3-inference/) · `Qwen3-0.6B` static ELF | **14.7 KB** (`14,712 B`) | Pure x86-64 NASM | `126.8 tok/s` (40T), `+18%..+36%` vs `llama.cpp` CPU, `64/64` PyTorch parity |
+| [`02`](02-baremetal-os/) | [`02-baremetal-os/`](02-baremetal-os/) · Bootable Bare-Metal OS | **24.3 KB** (`24,252 B`) | Pure x86-64 NASM | `74–94 ms` boot, `134.9 tok/s` KVM (16 vCPU), Proxmox `0 GB` disk (`55.4 tok/s`) |
+| [`03`](03-minigpt-train/) | [`03-minigpt-train/`](03-minigpt-train/) · Mini-GPT Trainer + TUI | **32.9 KB** (`32,944 B`) | Pure x86-64 NASM | `27,662 tok/s`, `1.0000000000` grad cosine vs PyTorch, `80x24` Braille UI |
+| [`04`](04-ring1-kernel-surgeon/) | [`04-ring1-kernel-surgeon/`](04-ring1-kernel-surgeon/) · Ring `-1` SVM Hypervisor | **75.4 KB** (`75,424 B`) | NASM + zero-libc C | MiniCPM5-2B live kernel crash patcher, `97.54%` pass@1 (`119/122`), `0%` dangerous |
+| [`05`](05-ebpf-jev/) | [`05-ebpf-jev/`](05-ebpf-jev/) · Linux `6.12` eBPF LSM | **21.3 KB** (`21,280 B`) | eBPF C + INT8 RNN | `5.65 µs` median hook, `0` floats, `500/500` `0-LSB` parity, atomic hot-swap |
---
-## Head-to-Head CPU Decode Benchmark: `llm.asm` vs `llama.cpp` (`Qwen3-0.6B Q8_0`)
+## Benchmarks
-Measured on the same machine (**AMD EPYC 7642**, 47C online, 256 MiB L3, DDR4, CPU-only `-ngl 0`), same model (`Qwen3-0.6B Q8_0`: `613.66 MiB` `.asmbin` v2 FP16-scale vs `604.15 MiB` GGUF `Q8_0`), `34` prompt tokens / `64` generated tokens, `3`-run average:
+**`Qwen3-0.6B Q8_0` CPU Decode** — AMD EPYC 7642 (47C online, CPU-only `-ngl 0`, `.asmbin` v2 `613.66 MiB` vs GGUF `604.15 MiB`, `pp34 / tg64`, 3-run avg):
-| Threads | `llm.asm` (`FAST_Q8=0`, FP32 act) | `llama.cpp` (`Q8_0`, `-ngl 0`) | **`llm.asm` (`FAST_Q8=1`, 14.7 KB)** | **vs `llama.cpp`** | **Bare-Metal OS KVM (`FAST_Q8=1`)** |
+| Threads | `llm.asm` (`FAST_Q8=0`) | `llama.cpp` (`Q8_0`) | **`llm.asm` (`FAST_Q8=1`, 14.7 KB)** | **vs `llama.cpp`** | **Bare-Metal OS KVM** |
|---:|---:|---:|---:|---:|---:|
| **1** | 7.18 tok/s | 16.63 tok/s | **20.70 tok/s** | **1.24x (+24.5%)** | **23.67 tok/s** |
| **4** | 28.12 tok/s | 51.08 tok/s | **69.24 tok/s** | **1.36x (+35.6%)** | **78.89 tok/s** |
@@ -31,21 +37,29 @@ Measured on the same machine (**AMD EPYC 7642**, 47C online, 256 MiB L3, DDR4, C
| **32** | 96.63 tok/s | 103.82 tok/s | **122.51 tok/s** | **1.18x (+18.0%)** | **133.75 tok/s** |
| **40** | 98.50 tok/s | 105.08 tok/s | **125.86 tok/s** *(peak 126.81)* | **1.20x (+19.8%)** | — |
-*(Note: `llama.cpp` uses batched GEMM for prompt prefill `pp34`, whereas `llm.asm` runs token-by-token GEMV. For autoregressive decode `tg64`, `llm.asm` (`FAST_Q8=1`) combines INT8xINT8 AVX2 `vpmaddubsw`/`vpmaddwd`, `.asmbin` v2 FP16 block scales (`F16C vcvtph2ps`), monotonic next-row prefetch, contiguous head-major KV-cache, and parallel GQA attention — beating `llama.cpp` by +18%..+36% across 1..40 threads while producing bit-exact deterministic outputs across all thread counts. The bare-metal OS gains another ~10% from 2 MiB huge-page identity mapping.)*
+<sub>`FAST_Q8=1` uses an INT8xINT8 AVX2+F16C kernel (`vpmaddubsw`/`vpmaddwd`, `.asmbin` v2 FP16 block scales via `vcvtph2ps`), contiguous head-major KV-cache, and parallel GQA; Bare-Metal OS gains another ~10% from 2 MiB huge-page identity mapping (bit-exact across all thread counts).</sub>
---
-## Live Output & Visual Proof
-
-### Phase 2: Booting Qwen3-0.6B Directly on Bare Metal (QEMU KVM, 16 vCPUs)
-
-![Bare-Metal Qwen3-0.6B OS VGA Console](assets/baremetal-vga.png)
-
-### Phase 2: Running Live on a Proxmox VE VM (0 GB Disk, Intel Xeon E5-2670 v3, 12 Cores)
-
-![Running on Real Proxmox VE VM (0 GB Disk, Intel Xeon KVM)](assets/proxmox-vm250-vga.png)
-
-### Phase 3: Pure-Assembly Live 80x24 UTF-8 Braille TUI (`build/asm-gpt-train`)
+## Proof
+
+<table>
+<tr>
+<td align="center" width="50%">
+<img src="assets/baremetal-vga.png" alt="Bare-Metal Qwen3-0.6B OS VGA Console" width="480" />
+<br />
+<sub><b>Phase 2:</b> QEMU KVM · AMD EPYC 7642 (16 vCPUs)</sub>
+</td>
+<td align="center" width="50%">
+<img src="assets/proxmox-vm250-vga.png" alt="Proxmox VE VM 0 GB Disk Intel Xeon VGA Console" width="480" />
+<br />
+<sub><b>Phase 2:</b> Proxmox VE · Intel Xeon E5-2670 v3 (0 GB Disk)</sub>
+</td>
+</tr>
+</table>
+
+<details>
+<summary><b>Phase 3: Live 80x24 UTF-8 Braille TUI (<code>build/asm-gpt-train</code>, pure assembly)</b></summary>
```text
╭──────────────────────────────────────────────────────────────────────────────╮
@@ -74,170 +88,48 @@ Measured on the same machine (**AMD EPYC 7642**, 47C online, 256 MiB L3, DDR4, C
╰──────────────────────────────────────────────────────────────────────────────╯
```
+</details>
+
---
## Quick Start
-Clone the repo and build everything with `make all`:
-
-```bash
-git clone https://github.com/alesha-pro/llm.asm.git
-cd llm.asm
-make all
-```
-
-### 1. Run Qwen3-0.6B Inference in 14 KB (`01-qwen3-inference/`)
-
-```bash
-# Export compact .asmbin v2 (FP16 block scales, 613.66 MiB; or --scale-dtype fp32 for legacy v1)
-python3 scripts/export_weights.py --model-dir models/qwen3-0.6b-bf16 --out models/qwen3-0.6b-q8_0.asmbin --scale-dtype fp16
-# Build with FAST_Q8=1 (default: INT8xINT8 AVX2 + parallel GQA) or FAST_Q8=0 (exact FP32 activations)
-make inference FAST_Q8=1
-./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin -p "Explain how a CPU cache works in 3 concise sentences." -n 128 -t 16
-# Or start an interactive multi-turn chat preserving the KV-cache across turns:
-./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin --chat -t 16
-```
-
-Full step-by-step setup, model download, CLI flags, and benchmarks: **[01-qwen3-inference/README.md](01-qwen3-inference/README.md)**.
-
-### 2. Boot Bare-Metal Qwen3-0.6B OS in 24 KB (`02-baremetal-os/`)
-
```bash
-make os FAST_Q8=1
-make os-run MODEL=models/qwen3-0.6b-q8_0.asmbin SMP=16
-# Or build a bootable BIOS+UEFI ISO for QEMU / Proxmox VE:
-make os-iso MODEL=models/qwen3-0.6b-q8_0.asmbin
+git clone https://github.com/alesha-pro/llm.asm.git && cd llm.asm
+make all # Builds Phase 1 (asm-llm, test_math), Phase 2 (asm-llm-os.elf), Phase 3 (asm-gpt-train)
```
-Full QEMU KVM, bootable ISO, and 0 GB disk Proxmox VE deployment guide: **[02-baremetal-os/README.md](02-baremetal-os/README.md)**.
+- **01 · Qwen3 Inference (`14.7 KB`):** `python3 scripts/export_weights.py --model-dir models/qwen3-0.6b-bf16 --out models/qwen3-0.6b-q8_0.asmbin --scale-dtype fp16 && ./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin --chat -t 16` → [01-qwen3-inference/README.md](01-qwen3-inference/README.md)
+- **02 · Bare-Metal OS (`24.3 KB`):** `make os-run MODEL=models/qwen3-0.6b-q8_0.asmbin SMP=16` *(or `make os-iso` for BIOS+UEFI ISO)* → [02-baremetal-os/README.md](02-baremetal-os/README.md)
+- **03 · Mini-GPT Trainer (`32.9 KB`):** `./build/asm-gpt-train --data data/tinyshakespeare.txt --steps 400 --seq 128 -t 16 --save checkpoints/shakespeare.ckpt` → [03-minigpt-train/README.md](03-minigpt-train/README.md)
+- **04 · Ring `-1` Kernel Surgeon (`75.4 KB`):** `cd 04-ring1-kernel-surgeon && make hv && python3 verifier/kvm_verifier.py --selftest` → [04-ring1-kernel-surgeon/README.md](04-ring1-kernel-surgeon/README.md)
+- **05 · Linux `6.12` eBPF LSM (`21.3 KB`):** `cd 05-ebpf-jev && bash testbed/build.sh && testbed/run_vm.sh verify` → [05-ebpf-jev/README.md](05-ebpf-jev/README.md)
-### 3. Train Mini-GPT from Scratch in 32 KB (`03-minigpt-train/`)
+<details>
+<summary><b>System Requirements, Repository Layout &amp; Verification Summary</b></summary>
-Zero Python required to train or run inference:
+- **Requirements:** x86-64 CPU with **AVX2 + FMA + F16C**, `nasm`, and GNU `binutils` (`ld`, `objcopy`). Phase 2 ISOs use `grub-mkrescue` (`grub-pc-bin`, `grub-efi-amd64-bin`, `mtools`, `xorriso`) and `qemu-system-x86_64` (KVM). Phase 4 requires AMD SVM + NPT (`nested=1`) and kernel headers; Phase 5 targets Linux `6.12` (`CONFIG_BPF_LSM=y`). Python (`numpy`, optional `torch`/`transformers`) is only used for offline weight export and reference harnesses.
+- **Repository Map:** [`shared/`](shared/) (3,857-line shared NASM core reused across Phases 1–3), [`01-qwen3-inference/`](01-qwen3-inference/), [`02-baremetal-os/`](02-baremetal-os/), [`03-minigpt-train/`](03-minigpt-train/), [`04-ring1-kernel-surgeon/`](04-ring1-kernel-surgeon/), [`05-ebpf-jev/`](05-ebpf-jev/), [`scripts/`](scripts/), [`assets/`](assets/), [`Makefile`](Makefile).
+- **Verification Highlights:**
+ - **Phase 1:** `FAST_Q8=1` matches PyTorch FP32 `Qwen3-0.6B` (`cosine = 0.9996517`, `64/64` exact greedy tokens; `FAST_Q8=0` hits `1.000000000` vs Python Q8_0), deterministic across `1T..40T`.
+ - **Phase 2:** 100% token-exact & byte-identical to Phase 1 across `1..32` KVM vCPUs (`134.9 tok/s` at 16 vCPUs) and real Proxmox VE (`55.4 tok/s`, `0 GB` disk).
+ - **Phase 3:** `1.0000000000` min cosine (`3.35e-8` worst max diff) across all 21 gradient tensors vs PyTorch CPU; 10-step AdamW `max_loss_diff = 4.77e-7`; `val_loss 4.19 -> 1.51` in 4 min.
+ - **Phase 4:** MiniCPM5-2B GRPO achieves `97.54%` pass@1 (`119/122` unseen scenarios vs `16.39%` base, `0%` dangerous continues) and live Ring `-1` `#PF`/`#DE`/`#UD` patching over 24 LAPIC cores.
+ - **Phase 5:** Passed Linux `6.12.118` eBPF verifier (`74` / `5,775` / `6,035` / `21,457` insns / 1M limit, `0` floats, `0` tail calls), `500/500` `0-LSB` parity, `0` false denies / 1,000 across 3,840 unseen workflows (`75%` strict-gate recall, `0.947` evasion F1), and live atomic hot-swap.
-```bash
-mkdir -p data checkpoints && curl -fsSL https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt -o data/tinyshakespeare.txt
-make train
-./build/asm-gpt-train --data data/tinyshakespeare.txt --steps 400 --seq 128 -t 16 --save checkpoints/shakespeare.ckpt
-```
-
-Full training, live Braille TUI, checkpoint chat loop, and PyTorch gradient check guide: **[03-minigpt-train/README.md](03-minigpt-train/README.md)**.
-
-### 4. Live-Patch Linux Ring 0 Crashes from Ring `-1` (`04-ring1-kernel-surgeon/`)
-
-```bash
-cd 04-ring1-kernel-surgeon
-make hv # Build 75 KB freestanding Ring -1 AMD SVM hypervisor (surgeon.elf)
-python3 verifier/kvm_verifier.py --selftest
-```
-
-Full architecture, QEMU nested-SVM + VNC demo, SFT/GRPO training, and KVM verifier guide: **[04-ring1-kernel-surgeon/README.md](04-ring1-kernel-surgeon/README.md)**.
-
----
-
-## Repository Layout
-
-```text
-llm.asm/
-├── LICENSE # MIT License
-├── Makefile # Single build file: inference, os, os-iso, train, all, check
-├── README.md # You are here
-├── assets/
-│ ├── baremetal-vga.png # QEMU KVM 80x25 VGA text-mode capture (EPYC 7642, 16 cores)
-│ └── proxmox-vm250-vga.png # Real Proxmox VE 0 GB disk VM capture (Xeon E5-2670 v3, 12 cores)
-├── shared/ # Pure x86-64 NASM core reused across phases (3,857 lines)
-│ ├── constants.inc # Linux syscalls, .asmbin v1/v2 header, runtime context offsets
-│ ├── syscalls.asm # Raw Linux syscalls + string/number formatting helpers
-│ ├── math.asm # AVX2/SSE2 expf, sincosf, FP64 RoPE, RMSNorm, Softmax, SiLU, argmax, top-p
-│ ├── matmul.asm # FAST_Q8=1 INT8xINT8 AVX2+F16C & FAST_Q8=0 Q8_0xFP32 matmul, dequant, dot, saxpy
-│ ├── threads.asm # Zero-libc Linux clone() + hybrid spin/futex thread pool (matmul + GQA attn)
-│ ├── tokenizer.asm # Fibonacci-hashed BPE encoder, UTF-8 decoder, Qwen3 chat template
-│ └── transformer.asm # Full 28-layer Qwen3 forward pass (v1/v2 auto-detect, contiguous KV, parallel GQA)
-├── 01-qwen3-inference/ # Phase 1: 14 KB static Linux ELF inference engine + --chat (1,251 lines)
-│ ├── README.md
-│ ├── main.asm
-│ └── test_math.asm
-├── 02-baremetal-os/ # Phase 2: 24 KB bare-metal bootable LLM OS (4,167 lines)
-│ ├── README.md
-│ ├── boot.asm # Multiboot 1 -> 4-level paging -> Long Mode -> AVX2/FMA -> IDT
-│ ├── drivers.asm # COM1 115200, 80x25 Color VGA, PS/2 keyboard, PIT+RDTSC, ACPI poweroff
-│ ├── kernel.asm # Kernel entrypoint, CPUID banner, cmdline parser, multi-turn chat REPL
-│ ├── linker.ld # Bare-metal linker script at 0x00100000
-│ ├── os_constants.inc # Hardware, Multiboot 1, Local APIC, and SMP constants
-│ ├── runtime.asm # Multiboot mmap bump allocator + bare-metal formatting runtime
-│ └── smp.asm # ACPI MADT + 16->32->64 AP trampoline + INIT-SIPI-SIPI spin-barrier
-├── 03-minigpt-train/ # Phase 3: 32 KB Mini-GPT trainer + inference engine (7,977 lines)
-│ ├── README.md
-│ ├── train_constants.inc # Training context offsets, SGEMM flags, .gptckpt format
-│ ├── sgemm.asm # Thread pool + register-blocked 6x16 AVX2+FMA FP32 SGEMM (NN/TN/NT)
-│ ├── kernels.asm # Forward/backward RMSNorm, RoPE, Causal MHA, SwiGLU, CE, AdamW, PRNG
-│ ├── model.asm # Arena layout, deterministic init, full fwd/bwd pass, sampler
-│ ├── tui.asm # ioctl(TCGETS) TTY detect + flicker-free 80x24 ANSI/Braille TUI
-│ └── main.asm # CLI, auto char-vocab, 90/10 split, .gptckpt I/O, train/sample loop
-├── 04-ring1-kernel-surgeon/ # Phase 4: Ring -1 AMD SVM hypervisor + MiniCPM5-2B live kernel patcher
-│ ├── README.md
-│ ├── ARCHITECTURE.md # Physical memory map, NPT isolation, SVM intercepts
-│ ├── Makefile # Builds surgeon.elf, surgeon_crash.ko, initramfs, UEFI ISO
-│ ├── hv/ # Bare-metal Ring -1 hypervisor (NASM + freestanding zero-libc C)
-│ ├── guest/ # Ring 0 fault-injection test module (crash_mod) & KVM verifier module (bench_mod)
-│ ├── dataset/ # 48-pilot & 600-scenario corpus + DeepSeek distillation script
-│ ├── verifier/ # 3-tier single-level QEMU/KVM + Capstone safety verifier
-│ ├── training/ # MiniCPM5-2B LoRA SFT, KVM-verified GRPO, eval, TensorBoard logger
-│ ├── dashboard/ # Live FastAPI training & verifier telemetry dashboard
-│ └── scripts/ # Initramfs/ISO builders, QEMU/VNC demos, GGUF/.r1m packers
-├── 05-ebpf-jev/ # Phase 5: 21 KB INT8 recurrent decision model inside Linux 6.12 eBPF LSM
-│ ├── README.md
-│ ├── SPEC_CONTRACT.md # Frozen binary weight pack & bit-exact fixed-point math contract
-│ ├── Makefile # Builds eBPF object, libbpf skeleton, warden, parity_check
-│ ├── bpf/ # 4 LSM hooks + bpf_loop INT8 forward pass + ringbuf telemetry
-│ ├── src/ # Userspace warden loader, --reload-weights hot-swap, parity & latency tools
-│ ├── ml/ # Dataset generator, INT8 recurrent & GBDT trainers, 10s CPU aligner, pretrained 21 KB pack
-│ ├── demo/ # Live curses kernel HUD, loopback listeners, 4 demo scripts
-│ └── testbed/ # Disposable Debian trixie Linux 6.12 KVM builder, split-screen demo & 7-check verifier
-└── scripts/
- ├── export_weights.py # Offline HuggingFace Qwen3-0.6B -> .asmbin (Q8_0) converter
- ├── mkiso.sh # Bootable BIOS+UEFI hybrid GRUB Multiboot 1 ISO builder
- ├── test_math.py # Automated SIMD & math kernel unit test driver
- ├── verify_ref.py # Independent NumPy Q8_0 + PyTorch FP32 parity harness
- ├── verify_os.py # Phase 2 parity, SMP determinism, KVM benchmark & VGA capture suite
- └── verify_train_ref.py # Phase 3 per-tensor PyTorch CPU grad-check & AdamW trajectory suite
-```
-
----
-
-## System Requirements
-
-- **CPU:** x86-64 with **AVX2 + FMA + F16C** (Intel Haswell / AMD Excavator or newer).
-- **Build tools:** `nasm` and GNU `binutils` (`ld`, `objcopy`).
- ```bash
- sudo apt install nasm binutils
- ```
-- **Phase 1 & 3 runtime:** Any Linux x86-64 kernel. Zero shared libraries (`readelf -d` reports no dynamic section).
-- **Phase 2 runtime (optional):** `qemu-system-x86_64` with KVM, or any x86-64 hypervisor/bare-metal machine (Proxmox VE, VirtualBox, real hardware). Building bootable ISOs uses `grub-mkrescue` (`grub-pc-bin`, `grub-efi-amd64-bin`, `mtools`, `xorriso`).
-- **Offline tooling (optional):** `python3` + `numpy` only for one-time `Qwen3-0.6B` `.asmbin` export and reference verification (`torch` + `transformers` only if running PyTorch parity checks).
+</details>
---
-## Architecture & Verification Summary
+## Ecosystem
-Every phase is built on the same engineering rules: no runtime libraries, deterministic parallel partitioning, and numerical verification against independent Python/PyTorch references.
+**Built on `llm.asm`:**
+- [`ringzero`](https://github.com/tcsenpai/ringzero) — Rust `no_std` Limine OS running the `llm.asm` engine in ring 0.
-- **Shared assembly core (`shared/`):** Phase 2 compiles the exact same `math.asm`, `matmul.asm`, `tokenizer.asm`, and `transformer.asm` with `-DBARE_METAL` (swapping Linux `mmap`/`clone`/`write` for physical Multiboot modules, APIC spin-barriers, and VGA+COM1 drivers). Phase 3 reuses `syscalls.asm` and `math.asm`.
-- **Phase 1 verification:** All math/SIMD kernels pass unit tests within `1e-7..1e-6` (`init_rope_freqs` FP64 `< 5e-14`) for both `FAST_Q8=1` and `FAST_Q8=0` across v1 FP32 and v2 FP16 scale formats. `FAST_Q8=1` matches PyTorch FP32 `Qwen3-0.6B` with `cosine = 0.9996517` and **64/64 exact greedy tokens** (`FAST_Q8=0` matches the Python Q8_0 reference with `cosine = 1.000000000`). Bit-exact deterministic from `1T` to `40T`.
-- **Phase 2 verification:** **100% token-exact and byte-for-byte identical** to Phase 1 across 5 test prompts (English, Russian UTF-8, arithmetic, `--think` mode), multi-turn KV-cache recall + `/clear`, and across `1..32` KVM vCPUs (`134.9 tok/s` at 16 vCPUs). Verified on both QEMU KVM (AMD EPYC 7642) and a real Proxmox VE VM (Intel Xeon E5-2670 v3, 0 GB disk, BIOS GRUB ISO).
-- **Phase 3 verification:** Verified against PyTorch FP32 CPU on all **21 parameter tensors** (`worst max_abs_diff = 3.35e-8`, `min cosine_sim = 1.0000000000`), 10-step AdamW + cosine LR + grad-clip trajectory (`max_loss_diff = 4.77e-7`), and bit-exact determinism across `1T`, `8T`, and `16T`.
-- **Phase 4 verification (`04-ring1-kernel-surgeon/`):** MiniCPM5-2B GRPO achieves **`97.54%` pass@1 (`119/122`)** on unseen held-out fault scenarios (`16.39%` base) with **`0%` dangerous continues** under the 3-tier QEMU/KVM verifier, and runs end-to-end inside Ring `-1` (`75 KB` `surgeon.elf`, 24 LAPIC SMP cores, 2 GiB read-only NVDIMM unmapped in AMD NPT) to live-patch `#PF`/`#DE`/`#UD`, delegate `extable`, and freeze `lock_held` faults.
-- **Phase 5 verification (`05-ebpf-jev/`):** Passed the real Linux `6.12.118` eBPF verifier across all 4 LSM hooks (`74` / `5,775` / `6,035` / `21,457` insns out of 1M, `0` floats, `0` tail calls), `500/500` `0-LSB` bit-exact Python/C/eBPF parity, `7/7` live KVM acceptance checks, `5.65 µs` median (`12.25 µs` p99) hook latency over 10,000 UDP `connect()` calls, `0` false denies / 1,000 across 3,840 unseen workflows (`75%` strict-gate recall vs `50%` stateless, `0.947` evasion F1), and live atomic weight hot-swap (`gen #1 -> gen #2`).
+Building an external port, language binding, or downstream OS on `llm.asm`? Host it in your own repository and open an issue or PR with a link so we can list it here.
-See each project's README for full tables, memory layouts, and reproduction steps:
-- [01-qwen3-inference/README.md](01-qwen3-inference/README.md)
-- [02-baremetal-os/README.md](02-baremetal-os/README.md)
-- [03-minigpt-train/README.md](03-minigpt-train/README.md)
-- [04-ring1-kernel-surgeon/README.md](04-ring1-kernel-surgeon/README.md)
-- [05-ebpf-jev/README.md](05-ebpf-jev/README.md)
-
----
+## Contributing
-## License
+We keep `main` strictly focused on zero-bloat x86-64 assembly, bare-metal hypervisors, and in-kernel ML with hard numerical verification. Read [`CONTRIBUTING.md`](CONTRIBUTING.md) before opening a PR.
-MIT License. See [LICENSE](LICENSE).
+**License:** [MIT](LICENSE)