Skip to main content

Module codegen

Module codegen 

Source
Expand description

PVM-to-x86-64 code generation.

Compiles PVM bytecode into native x86-64 machine code. Each PVM basic block becomes a native basic block with gas metering at entry. PVM registers are mapped to x86-64 registers for the duration of execution.

Register mapping (PVM φ[i] → x86-64): φ[0] → RBP (callee-saved) — RA, rarely used as memory base φ[1] → RBX (callee-saved) — SP, avoids RBP encoding penalty φ[2] → R12 (callee-saved) φ[3] → R13 (callee-saved) φ[4] → R14 (callee-saved) φ[5] → RSI (caller-saved) φ[6] → RDI (caller-saved) φ[7] → R8 (caller-saved) φ[8] → R9 (caller-saved) φ[9] → R10 (caller-saved) φ[10] → R11 (caller-saved) φ[11] → RAX (caller-saved) φ[12] → RCX (caller-saved)

Reserved: R15 = gas meter, RDX = scratch, RSP = native stack.

Structs§

CompileResult
Result of compilation.
Compiler
PVM-to-x86-64 compiler.
HelperFns
Helper function pointers passed to compiled code.

Constants§

CTX_BB_LEN
CTX_BB_STARTS
CTX_CODE_BASE
CTX_DISPATCH_TABLE
CTX_ENTRY_PC
CTX_EXIT_ARG
CTX_EXIT_REASON
CTX_FAST_REENTRY
CTX_GAS
CTX_HEAP_BASE
CTX_HEAP_TOP
CTX_JT_LEN
CTX_JT_PTR
CTX_PC
CTX_REGS
CTX_VA
JitContext lives above the PVM u32 address space (no bounds check on guest mem — the full low 4 GiB of native VA belongs to the program). CTX is reached via RIP-relative [rip+disp32], which gives ±2 GiB range from the JIT code, so CTX must be adjacent to the JIT region.
EXIT_ECALL
EXIT_HALT
Exit reason codes (matching ExitReason enum).
EXIT_HOST_CALL
EXIT_OOG
EXIT_PAGE_FAULT
EXIT_PANIC
EXIT_TRAP