TinyEMU Data Flow Explorer

Interactive, mobile-friendly deep dive into Fabrice Bellard’s TinyEMU codebase

What is TinyEMU?

TinyEMU is a small, self-contained system emulator by Fabrice Bellard. It supports RISC-V (32/64/128-bit) and x86 (via KVM), and implements VirtIO console, network, block, input, and 9P filesystem devices. It can run with SDL or as a JavaScript demo (JSLinux).

This guide follows the data flow from configuration parsing through machine initialization, CPU execution, memory access, device I/O, and display output. Each page includes GitHub-style permalinks to the source.

High-Level Data Flow

graph TD A[CLI / JS Entry] --> B[Config Parsing] B --> C[Machine Init] C --> D[CPU Init] C --> E[Memory Map] C --> F[Device Init] D --> G[CPU Interpreter Loop] G --> H[TLB / MMU] H --> I[RAM or MMIO] I --> J[Device Handlers] J --> K[IRQ / PLIC] K --> G F --> L[VirtIO Queues] L --> M[Network / Block / FS] E --> N[Framebuffer] N --> O[SDL / simplefb]

Tip: On mobile, pinch to zoom the diagram. All blocks are expanded by default on detail pages.

Component Map

Key Data Structures

Execution Loop

The main loop in temu.c alternates between waiting for I/O events and executing guest instructions:

  1. Compute sleep duration (virt_machine_get_sleep_duration).
  2. select() on console stdin, network sockets, and filesystem events.
  3. Dispatch ready file descriptors (console input, network packets).
  4. Refresh display (sdl_refresh).
  5. Run the CPU interpreter for up to MAX_EXEC_CYCLE instructions (virt_machine_interp).