Emulating aarch64 in software using JIT compilation and Rust by Manos Pitsidianakis on 2025-08-25 I was able to write a simple just-in-time compiled emulator for the aarch64 ISA (Arm A-profile A64 Instruction Set Architecture). The Armv8-A/Armv9-A specs are massive in size, so the initial scope is for basic functionality and almost no optional architectural features such as SIMD. I wrote the emulator as an exercise in understanding how QEMU’s TCG (Tiny Code Generator) software emulation works in principle. I did not follow the C code implementation, but rather implemented the same concepts from scratch in Rust, leveraging other libraries for the heavy lifting (disassembly and JIT compilation). In this article we’ll go through what is needed to go from a virtual machine’s instructions to native code execution. Repository: https://github.com/epilys/simulans $ cargo run --release -- \ --memory 4GiB \ --generate-fdt \ --entry-point-address 0x40080000 \ test_kernel.bin Finished `release` profile [optimized] target(s) in 0.06s Running `target/release/simulans --memory 4GiB --generate-fdt --entry-point-address 0x40080000 test_kernel.bin` Hello world! Parsed 6 devicetree nodes! /: Some(Some("linux,dummy-virt")) chosen: None memory@0: None 0x0000000000000000, length Some(4294967296) cpus: None cpu@0: Some(Some("arm,arm-v8")) 0x0000000000000000, length None psci: Some(Some("arm,psci-0.2")) Halting the machine. $ Translating an ISA to native code The emulation is performed in these steps: Disassembling aarch64 binary code using binja Translate each instruction with Cranelift’s JIT backend Note: QEMU TCG uses its own JIT implementation, as well as decoding instructions (see decodetree documentation). The translation logic performs a big match on the instruction operation and emits (hopefully!) equivalent JIT operations that cranelift then compiles to native code. It must also appropriately update machine state such as condition flags. Example translation of the bitwise OR instr...
First seen: 2025-08-30 06:38
Last seen: 2025-08-30 16:40