openvm_platform/
rust_rt.rs

1//! This module contains the components required to link a Rust binary.
2//!
3//! In particular:
4//! * It defines an entrypoint ensuring initialization and finalization are done
5//!   properly.
6//! * It includes a panic handler.
7//! * It includes an allocator.
8
9/// WARNING: the [SYSTEM_OPCODE] here should be equal to `SYSTEM_OPCODE` in `extensions_rv32im_guest`
10/// Can't import `openvm_rv32im_guest` here because would create a circular dependency
11#[cfg(target_os = "zkvm")]
12/// This is custom-0 defined in RISC-V spec document
13const SYSTEM_OPCODE: u8 = 0x0b;
14
15extern crate alloc;
16
17#[inline(always)]
18pub fn terminate<const EXIT_CODE: u8>() {
19    #[cfg(target_os = "zkvm")]
20    crate::custom_insn_i!(
21        opcode = SYSTEM_OPCODE,
22        funct3 = 0,
23        rd = Const "x0",
24        rs1 = Const "x0",
25        imm = Const EXIT_CODE
26    );
27    #[cfg(not(target_os = "zkvm"))]
28    {
29        unimplemented!()
30    }
31}