riscv/
.clang-format
570 B
.gitignore
5 B
.gitsigners
112 B
LICENSE
1.1 KiB
Makefile
1.1 KiB
README
3.3 KiB
color.h
567 B
emulator.c
79.7 KiB
io.c
1.1 KiB
io.h
444 B
jit.c
32.6 KiB
jit.h
5.0 KiB
riscv.c
12.0 KiB
riscv.h
12.0 KiB
types.h
1.0 KiB
README
raw
| 1 | |
| 2 | RADIANT RISC-V EMULATOR |
| 3 | |
| 4 | A RISC-V RV64I emulator with an x86-64 JIT compiler, interactive TUI |
| 5 | debugger, and headless execution mode. Part of the Radiant project. |
| 6 | |
| 7 | Supports the RV64I base integer instruction set, M (multiply/divide) |
| 8 | extension, and F (single-precision floating-point) extension. |
| 9 | |
| 10 | BUILDING |
| 11 | |
| 12 | $ make |
| 13 | |
| 14 | Requires `clang` and `lld`. The binary is written to `bin/emulator`. |
| 15 | |
| 16 | INSTALLATION |
| 17 | |
| 18 | $ make install |
| 19 | |
| 20 | Installed as `~/bin/emulator` by default. Can be overridden via the `PREFIX` |
| 21 | variable. |
| 22 | |
| 23 | USAGE |
| 24 | |
| 25 | Interactive (TUI): |
| 26 | |
| 27 | $ bin/emulator <program.bin> |
| 28 | |
| 29 | Headless: |
| 30 | |
| 31 | $ bin/emulator -run <program.bin> [<option>..] |
| 32 | |
| 33 | The emulator loads a flat binary along with optional data sections: |
| 34 | |
| 35 | <program.bin> Program text (machine instructions) |
| 36 | <program.bin>.ro.data Read-only data section |
| 37 | <program.bin>.rw.data Read-write data section |
| 38 | <program.bin>.debug Debug info (optional, for source locations) |
| 39 | |
| 40 | |
| 41 | OPTIONS |
| 42 | |
| 43 | -run Run headless (no TUI). |
| 44 | -debug Load debug info for source-level diagnostics. |
| 45 | -no-jit Disable the JIT compiler; interpret only. |
| 46 | -memory-size=KB Physical memory size in KB (default 128 MB). |
| 47 | -data-size=KB Data memory size in KB. |
| 48 | -stack-size=KB Stack size in KB (default 256 KB). |
| 49 | -no-guard-stack Disable stack guard zones (enabled by default, 16 bytes). |
| 50 | -no-validate Disable memory bounds checking. |
| 51 | -trace Enable instruction tracing. |
| 52 | -trace-headless Enable instruction tracing in headless mode. |
| 53 | -trace-instructions Print each instruction during headless tracing. |
| 54 | -trace-depth=N Number of trace entries to display on fault. |
| 55 | -max-steps=N Maximum steps before timeout in headless mode. |
| 56 | -count-instructions Print instruction count on exit. |
| 57 | -watch=ADDR Set a memory watchpoint at ADDR. |
| 58 | -watch-size=BYTES Size of watched region (default 4). |
| 59 | -watch-arm-pc=ADDR Only trigger watchpoint after reaching ADDR. |
| 60 | -watch-zero-only Only trigger on zero-value stores. |
| 61 | -watch-skip=N Skip the first N watchpoint hits. |
| 62 | -watch-backtrace Print backtrace on watchpoint hit. |
| 63 | -watch-bt-depth=N Backtrace depth (default 8). |
| 64 | |
| 65 | MEMORY LAYOUT |
| 66 | |
| 67 | 0x00010000 Read-only data (.ro.data) |
| 68 | Program base Program text (instructions) |
| 69 | 0x00FFFFF0 Read-write data (.rw.data) |
| 70 | Memory top - stack size Stack |
| 71 | Memory top Top of memory |
| 72 | |
| 73 | ARCHITECTURE |
| 74 | |
| 75 | The emulator operates in two execution modes: |
| 76 | |
| 77 | Interpreter Steps through instructions one at a time. Used for the |
| 78 | TUI debugger, ecalls, ebreak, and as a fallback. |
| 79 | |
| 80 | JIT Translates basic blocks of RV64I instructions to native |
| 81 | x86-64 machine code. Blocks are compiled on first |
| 82 | encounter and cached (16 MB code cache, up to 256K |
| 83 | blocks). Falls back to the interpreter for system |
| 84 | calls and faults. |
| 85 | |
| 86 | The TUI debugger supports single-stepping, reverse execution (via |
| 87 | snapshots), register and stack inspection, and memory watchpoints. |
| 88 | |
| 89 | LICENSE |
| 90 | |
| 91 | Licensed under the MIT License, |
| 92 | Copyright (c) 2025-2026 Radiant Computer (https://radiant.computer) |