use crate::generated::sysreg::{self, Register};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum SystemOp {
At,
Brb,
Dc,
Gic,
Gicr,
Gsb,
Ic,
Plbi,
Sys,
Sysl,
Sysp,
Tlbi,
Tlbip,
}
pub const SYS_AT: SystemOp = SystemOp::At;
pub const SYS_BRB: SystemOp = SystemOp::Brb;
pub const SYS_DC: SystemOp = SystemOp::Dc;
pub const SYS_GIC: SystemOp = SystemOp::Gic;
pub const SYS_GSB: SystemOp = SystemOp::Gsb;
pub const SYS_IC: SystemOp = SystemOp::Ic;
pub const SYS_PLBI: SystemOp = SystemOp::Plbi;
pub const SYS_TLBI: SystemOp = SystemOp::Tlbi;
pub const SYS_TLBIP: SystemOp = SystemOp::Tlbip;
pub const SYSL_GICR: SystemOp = SystemOp::Gicr;
pub fn sys_op(op1: u32, crn: u32, crm: u32, op2: u32) -> SystemOp {
sysreg::sys(op1, crn, crm, op2).map_or(SystemOp::Sys, |operation| operation.category)
}
pub fn sys_l_op(op1: u32, crn: u32, crm: u32, op2: u32) -> SystemOp {
sysreg::sysl(op1, crn, crm, op2).map_or(SystemOp::Sysl, |operation| operation.category)
}
pub fn sys_op128(op1: u32, crn: u32, crm: u32, op2: u32) -> SystemOp {
sysreg::sysp(op1, crn, crm, op2).map_or(SystemOp::Sysp, |operation| operation.category)
}
pub fn sys_register_allowed(op1: u32, crn: u32, crm: u32, op2: u32, rt: u32) -> bool {
rt == 31
|| sysreg::sys(op1, crn, crm, op2)
.is_some_and(|operation| operation.register != Register::Never)
}
pub const fn svcr_field(crm: u32) -> bool {
crm & 0b0110 != 0
}