Skip to main content

ab_riscv_primitives/instructions/
zkr.rs

1//! Zkr extension
2
3#[cfg(test)]
4mod tests;
5
6use crate::hart::HartConfig;
7use crate::instructions::zicsr::ZicsrInstruction;
8use crate::instructions::{ImplementedExtension, Instruction, IsaExtension};
9use crate::registers::general_purpose::Register;
10use ab_riscv_macros::instruction;
11use core::fmt;
12
13// TODO: CSR composition?
14/// CSR index of the `seed` register defined by the `Zkr` extension
15pub const SEED_CSR_INDEX: u16 = 0x015;
16
17/// RISC-V Zkr instruction.
18///
19/// `Zkr` (the entropy source extension) defines no instructions of its own: it only adds the
20/// `seed` CSR (see [`SEED_CSR_INDEX`]), which is accessed through ordinary `Zicsr` instructions.
21#[instruction(inherit = [ZicsrInstruction])]
22#[derive(Debug, Clone, Copy)]
23#[derive_const(PartialEq, Eq)]
24pub enum ZkrInstruction<Hart>
25where
26    Hart: HartConfig, {}
27
28#[instruction]
29const impl<Reg, Hart> Instruction for ZkrInstruction<Hart>
30where
31    Reg: [const] Register,
32    Hart: [const] HartConfig<Reg = Reg>,
33{
34    const OWN_ISA_EXTENSIONS: &'static [IsaExtension] = &[IsaExtension::new("zkr", 1, 0)];
35
36    const ALIGNMENT: u8 = align_of::<u32>() as u8;
37
38    type Hart = Hart;
39
40    #[inline(always)]
41    #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
42    fn try_decode(instruction: u32) -> Option<Self> {
43        None
44    }
45
46    #[inline(always)]
47    fn size(&self) -> u8 {
48        size_of::<u32>() as u8
49    }
50}
51
52#[instruction]
53impl<Reg, Hart> fmt::Display for ZkrInstruction<Hart>
54where
55    Reg: fmt::Display + Copy,
56    Hart: HartConfig<Reg = Reg>,
57{
58    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59        match self {}
60    }
61}