11 releases (4 stable)

1.2.0 Oct 14, 2024
1.1.0 Oct 2, 2024
1.0.1 Sep 28, 2024
1.0.0-beta.3 Aug 16, 2024
0.1.3 Oct 17, 2023

#337 in Encoding

Download history 143/week @ 2024-07-15 252/week @ 2024-07-22 158/week @ 2024-07-29 59/week @ 2024-08-05 459/week @ 2024-08-12 61/week @ 2024-08-19 74/week @ 2024-08-26 188/week @ 2024-09-02 51/week @ 2024-09-09 82/week @ 2024-09-16 291/week @ 2024-09-23 447/week @ 2024-09-30 188/week @ 2024-10-07 390/week @ 2024-10-14 68/week @ 2024-10-21 422/week @ 2024-10-28

1,088 downloads per month
Used in l2r0-profiler-host

MIT license

130KB
3.5K SLoC

raki

Rust
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 main() {
    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

Support

  • BaseI (RV32I, RV64I)
  • M
  • A
  • D
  • Q
  • C
  • B
  • P
  • V
  • H
  • Zicsr
  • Zifencei
  • Zicntr
  • Zicfiss
  • Priv (Now only supports mret, sret, wfi, sfence.vma)

License

This crate is licensed under MIT.
See LICENSE for details.

Contribution

All contributions are welcome, including issues, pull requests, questions, etc... See CONTRIBUTING.md for details.

No runtime deps