Crate raki

Source
Expand description

raki

raki is a RISC-V instruction decoder written in Rust.

  • Both 32/64bit support.
  • Support rv32/64imac, Zicsr, Zifencei extensions.
  • Implement Display trait for formatting.

§Usage

Call the decode as u16/u32 method.

use raki::{BaseIOpcode, Decode, Instruction, Isa, OpcodeKind};

fn example() {
    let inst_bytes: u32 = 0b1110_1110_1100_0010_1000_0010_1001_0011;
    let inst: Instruction = match inst_bytes.decode(Isa::Rv32) {
        Ok(inst) => inst,
        Err(e) => panic!("decoding failed due to {e:?}"),
    };

    assert_eq!(inst.opc, OpcodeKind::BaseI(BaseIOpcode::ADDI));
    println!("{inst}");
}
// --output--
// addi t0, t0, -276

Structs§

Instruction
Instruction

Enums§

AOpcode
Insturctions in A Extension.
BaseIOpcode
Insturctions in Base-I.
COpcode
Insturctions in C Extension.
DecodingError
Cause of decoding error.
InstFormat
Instruction format See: The RISC-V Instruction Set Manual: Volume II Version 20240411 p.23,141
Isa
Target isa.
MOpcode
Insturctions in M Extension.
OpcodeKind
Extension type and Instruction name.
PrivOpcode
Privileged Insturctions.
ZicbozOpcode
Insturctions in Zicboz Extension.
ZicfissOpcode
Insturctions in Zicntr Extension.
ZicntrOpcode
Insturctions in Zicntr Extension.
ZicsrOpcode
Insturctions in Zicsr Extension.
ZifenceiOpcode
Insturctions in Zifencei Extension.

Traits§

Decode
A trait to decode an instruction from u16/u32. This trait provides public api.