# ptitseb/box64 architecture

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

- Interactive diagram: https://gitdiagram.com/ptitseb/box64
- Repository: https://github.com/ptitseb/box64

## Overview

Box64 is a Linux userspace emulator that runs x86-64 Linux programs on supported non-x86-64 hosts. The documented user workflow is to invoke `box64 ./program`; the runtime loads ELF executables and dependencies, emulates x86 instructions, and can use architecture-specific dynamic recompilers. It also provides native-library wrappers and configuration controls. The graph combines README capabilities with relationships visible in the supplied source index and excerpts; unsampled implementation details are represented cautiously, without asserting unverified call order.

Main entry points: [`src/core.c`](https://github.com/ptitseb/box64/blob/main/src/core.c) (Runtime core), [`src/librarian/library.c`](https://github.com/ptitseb/box64/blob/main/src/librarian/library.c) (Library resolution), [`src/dynarec/dynarec.c`](https://github.com/ptitseb/box64/blob/main/src/dynarec/dynarec.c) (Dynamic recompiler), [`src/box64context.c`](https://github.com/ptitseb/box64/blob/main/src/box64context.c) (Emulator context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Runtime entry"]
  node_main["CLI entry<br/>[main.c]"]
  node_core["Runtime core<br/>[core.c]"]
end

subgraph group_loading["ELF and libraries"]
  node_elfparser["ELF parsing<br/>[elfparser.c]"]
  node_elfloader["ELF loading"]
  node_libraries["Library resolution<br/>[library.c]"]
  node_library_api["Library interfaces<br/>[library.h]"]
  node_elf_api["Loader interfaces<br/>[elfloader.h]"]
end

subgraph group_emulation["Emulation and translation"]
  node_interpreter["x86 interpreter<br/>[x64run.c]"]
  node_emu_state["x86 emulator state<br/>[x64emu_private.h]"]
  node_dynarec["Dynamic recompiler<br/>[dynarec.c]"]
  node_arm_dynarec["Arm64 backend<br/>[dynarec_arm64_00.c]"]
  node_rv_dynarec["RISC-V backend<br/>[dynarec_rv64_00.c]"]
  node_la_dynarec["LoongArch backend<br/>[dynarec_la64_00.c]"]
end

subgraph group_compat["Compatibility"]
  node_wrapped["Native library wrappers"]
  node_bridge["Function bridges<br/>[bridge.h]"]
  node_gtk["GTK class bridging<br/>[gtkclass.c]"]
end

subgraph group_runtime["Runtime support"]
  node_context["Emulator context<br/>[box64context.c]"]
  node_config["Runtime configuration<br/>[box64rc.py]"]
  node_dynacache[("Translated-code cache<br/>[dynacache.c]")]
end

node_user(("Program user"))
node_native_libs["Host libraries"]

node_user -->|"runs program"| node_main
node_main -->|"enters runtime"| node_core
node_elfparser -->|"uses loader types"| node_elfloader
node_libraries -->|"loads ELF libraries"| node_elfloader
node_libraries -->|"uses interface"| node_library_api
node_elfparser -->|"uses interface"| node_elf_api
node_context -->|"uses interface"| node_elf_api
node_context -->|"uses emulator state"| node_emu_state
node_context -->|"uses bridges"| node_bridge
node_wrapped -->|"bridges callbacks"| node_bridge
node_gtk -->|"bridges callbacks"| node_bridge
node_core -.->|"loads executable"| node_elfloader
node_core -.->|"runs instructions"| node_interpreter
node_core -.->|"resolves dependencies"| node_libraries
node_core -.->|"reads settings"| node_config
node_core -.->|"uses code cache"| node_dynacache
node_dynarec -.->|"dispatches backend"| node_arm_dynarec
node_dynarec -.->|"dispatches backend"| node_rv_dynarec
node_dynarec -.->|"dispatches backend"| node_la_dynarec
node_libraries -.->|"resolves wrappers"| node_wrapped
node_wrapped -.->|"calls host APIs"| node_native_libs
node_core -.->|"translates execution"| node_dynarec

click node_main "https://github.com/ptitseb/box64/blob/main/src/main.c"
click node_core "https://github.com/ptitseb/box64/blob/main/src/core.c"
click node_context "https://github.com/ptitseb/box64/blob/main/src/box64context.c"
click node_elfparser "https://github.com/ptitseb/box64/blob/main/src/elfs/elfparser.c"
click node_elfloader "https://github.com/ptitseb/box64/blob/main/src/elfs/elfloader_private.h"
click node_libraries "https://github.com/ptitseb/box64/blob/main/src/librarian/library.c"
click node_library_api "https://github.com/ptitseb/box64/blob/main/src/include/library.h"
click node_elf_api "https://github.com/ptitseb/box64/blob/main/src/include/elfloader.h"
click node_interpreter "https://github.com/ptitseb/box64/blob/main/src/emu/x64run.c"
click node_emu_state "https://github.com/ptitseb/box64/blob/main/src/emu/x64emu_private.h"
click node_dynarec "https://github.com/ptitseb/box64/blob/main/src/dynarec/dynarec.c"
click node_arm_dynarec "https://github.com/ptitseb/box64/blob/main/src/dynarec/arm64/dynarec_arm64_00.c"
click node_rv_dynarec "https://github.com/ptitseb/box64/blob/main/src/dynarec/rv64/dynarec_rv64_00.c"
click node_la_dynarec "https://github.com/ptitseb/box64/blob/main/src/dynarec/la64/dynarec_la64_00.c"
click node_wrapped "https://github.com/ptitseb/box64/blob/main/src/wrapped/wrappedwaylandclient.c"
click node_bridge "https://github.com/ptitseb/box64/blob/main/src/include/bridge.h"
click node_gtk "https://github.com/ptitseb/box64/blob/main/src/tools/gtkclass.c"
click node_config "https://github.com/ptitseb/box64/blob/main/configurator/box64rc.py"
click node_dynacache "https://github.com/ptitseb/box64/blob/main/src/tools/dynacache.c"

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_main,node_core,node_user toneBlue
class node_elfparser,node_elfloader,node_libraries,node_library_api,node_elf_api toneAmber
class node_interpreter,node_emu_state,node_dynarec,node_arm_dynarec,node_rv_dynarec,node_la_dynarec toneMint
class node_wrapped,node_bridge,node_gtk toneRose
class node_context,node_config,node_dynacache,node_native_libs toneIndigo
```

## Components

### Runtime entry

- [CLI entry](https://github.com/ptitseb/box64/blob/main/src/main.c): `src/main.c`
- [Runtime core](https://github.com/ptitseb/box64/blob/main/src/core.c): `src/core.c`

### ELF and libraries

- [ELF parsing](https://github.com/ptitseb/box64/blob/main/src/elfs/elfparser.c): `src/elfs/elfparser.c`
- [ELF loading](https://github.com/ptitseb/box64/blob/main/src/elfs/elfloader_private.h): `src/elfs/elfloader_private.h`
- [Library resolution](https://github.com/ptitseb/box64/blob/main/src/librarian/library.c): `src/librarian/library.c`
- [Library interfaces](https://github.com/ptitseb/box64/blob/main/src/include/library.h): `src/include/library.h`
- [Loader interfaces](https://github.com/ptitseb/box64/blob/main/src/include/elfloader.h): `src/include/elfloader.h`

### Emulation and translation

- [x86 interpreter](https://github.com/ptitseb/box64/blob/main/src/emu/x64run.c): `src/emu/x64run.c`
- [x86 emulator state](https://github.com/ptitseb/box64/blob/main/src/emu/x64emu_private.h): `src/emu/x64emu_private.h`
- [Dynamic recompiler](https://github.com/ptitseb/box64/blob/main/src/dynarec/dynarec.c): `src/dynarec/dynarec.c`
- [Arm64 backend](https://github.com/ptitseb/box64/blob/main/src/dynarec/arm64/dynarec_arm64_00.c): `src/dynarec/arm64/dynarec_arm64_00.c`
- [RISC-V backend](https://github.com/ptitseb/box64/blob/main/src/dynarec/rv64/dynarec_rv64_00.c): `src/dynarec/rv64/dynarec_rv64_00.c`
- [LoongArch backend](https://github.com/ptitseb/box64/blob/main/src/dynarec/la64/dynarec_la64_00.c): `src/dynarec/la64/dynarec_la64_00.c`

### Compatibility

- [Native library wrappers](https://github.com/ptitseb/box64/blob/main/src/wrapped/wrappedwaylandclient.c): `src/wrapped/wrappedwaylandclient.c`
- [Function bridges](https://github.com/ptitseb/box64/blob/main/src/include/bridge.h): `src/include/bridge.h`
- [GTK class bridging](https://github.com/ptitseb/box64/blob/main/src/tools/gtkclass.c): `src/tools/gtkclass.c`

### Runtime support

- [Emulator context](https://github.com/ptitseb/box64/blob/main/src/box64context.c): `src/box64context.c`
- [Runtime configuration](https://github.com/ptitseb/box64/blob/main/configurator/box64rc.py): `configurator/box64rc.py`
- [Translated-code cache](https://github.com/ptitseb/box64/blob/main/src/tools/dynacache.c): `src/tools/dynacache.c`

### Other components

- **Program user**
- **Host libraries**

## Connections

- Program user → CLI entry: runs program (evidence: `README.md`)
- CLI entry → Runtime core: enters runtime (evidence: `src/main.c`)
- ELF parsing → ELF loading: uses loader types (evidence: `src/elfs/elfparser.c`)
- Library resolution → ELF loading: loads ELF libraries (evidence: `src/librarian/library.c`)
- Library resolution → Library interfaces: uses interface (evidence: `src/librarian/library.c`)
- ELF parsing → Loader interfaces: uses interface (evidence: `src/elfs/elfparser.c`)
- Emulator context → Loader interfaces: uses interface (evidence: `src/box64context.c`)
- Emulator context → x86 emulator state: uses emulator state (evidence: `src/box64context.c`)
- Emulator context → Function bridges: uses bridges (evidence: `src/box64context.c`)
- Native library wrappers → Function bridges: bridges callbacks (evidence: `src/wrapped/wrappedwaylandclient.c`)
- GTK class bridging → Function bridges: bridges callbacks (evidence: `src/tools/gtkclass.c`)
- Runtime core → ELF loading: loads executable
- Runtime core → x86 interpreter: runs instructions
- Runtime core → Library resolution: resolves dependencies
- Runtime core → Runtime configuration: reads settings
- Runtime core → Translated-code cache: uses code cache
- Dynamic recompiler → Arm64 backend: dispatches backend
- Dynamic recompiler → RISC-V backend: dispatches backend
- Dynamic recompiler → LoongArch backend: dispatches backend
- Library resolution → Native library wrappers: resolves wrappers
- Native library wrappers → Host libraries: calls host APIs
- Runtime core → Dynamic recompiler: translates execution
