javm_recompiler_x86/lib.rs
1#![no_std]
2
3//! PVM recompiler — compiles PVM bytecode to native x86-64 machine code.
4//!
5//! This crate is the no_std bytes-producer: it emits x86-64 machine
6//! code into a `Vec<u8>` (or directly into an mmap region when run
7//! under the std-gated paths in `asm.rs` / `codegen.rs` that are
8//! currently dormant). The runtime substrate that loads + executes
9//! the emitted code lives in `nub-arch-x86`, which compiles this
10//! crate with `default-features = false` and supplies its own
11//! per-invocation page table.
12//!
13//! Public surface:
14//! - [`JitContext`] — `#[repr(C)]` execution context, written by the
15//! driver before entry and read after exit. Layout is mirrored by
16//! the codegen-side `CTX_*` offset constants in
17//! `javm-recompiler-x86::codegen`.
18//! - [`asm`], [`codegen`], [`predecode`] — codegen pipeline.
19
20extern crate alloc;
21
22pub mod asm;
23pub mod codegen;
24pub mod predecode;
25
26/// JIT execution context passed to compiled code via R15.
27/// Must be `#[repr(C)]` with exact field ordering matching the
28/// `CTX_*` offset constants in [`codegen`].
29#[repr(C)]
30pub struct JitContext {
31 /// PVM registers (offset 0, 13 × 8 = 104 bytes).
32 pub regs: [u64; 13],
33 /// Gas counter (offset 104). Signed to detect underflow.
34 pub gas: i64,
35 /// Exit reason code (offset 112).
36 pub exit_reason: u32,
37 /// Exit argument (offset 116) — host call ID, page fault addr, etc.
38 pub exit_arg: u32,
39 /// Heap base address (offset 120).
40 pub heap_base: u32,
41 /// Current heap top (offset 124).
42 pub heap_top: u32,
43 /// Jump table pointer (offset 128).
44 pub jt_ptr: *const u32,
45 /// Jump table length (offset 136).
46 pub jt_len: u32,
47 pub _pad0: u32,
48 /// Basic block starts pointer (offset 144).
49 pub bb_starts: *const u8,
50 /// Basic block starts length (offset 152).
51 pub bb_len: u32,
52 pub _pad1: u32,
53 /// Entry PC for re-entry after host calls (offset 160).
54 pub entry_pc: u32,
55 /// Current PC when execution stopped (offset 164).
56 pub pc: u32,
57 /// Dispatch table: PVM PC → native code offset (offset 168).
58 pub dispatch_table: *const i32,
59 /// Base address of native code (offset 176).
60 pub code_base: u64,
61 /// Flat guest memory buffer base pointer (offset 184).
62 pub flat_buf: *mut u8,
63 /// Fast re-entry flag.
64 pub fast_reentry: u32,
65 pub _pad2: u32,
66 /// Maximum heap pages — grow_heap refuses beyond this.
67 pub max_heap_pages: u32,
68 pub _pad3: u32,
69}