use core::num::NonZeroUsize;
use gdbstub::arch::{Arch, RegId};
use crate::exceptions::DebugEventContext;
pub enum ArmV7 {}
impl Arch for ArmV7 {
type Usize = u32;
type BreakpointKind = ArmBreakpointKind;
type RegId = ArmRegisterID;
type Registers = DebugEventContext;
fn target_description_xml() -> Option<&'static str> {
Some(include_str!("./target.full.xml"))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ArmBreakpointKind {
Thumb16,
Thumb32,
Arm32,
}
impl gdbstub::arch::BreakpointKind for ArmBreakpointKind {
fn from_usize(kind: usize) -> Option<Self> {
let kind = match kind {
2 => ArmBreakpointKind::Thumb16,
3 => ArmBreakpointKind::Thumb32,
4 => ArmBreakpointKind::Arm32,
_ => return None,
};
Some(kind)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ArmRegisterID {
Gpr(u8),
Sp,
Lr,
Pc,
Cpsr,
Fpr(u8),
Fpscr,
}
impl ArmRegisterID {
#[must_use]
const fn size(self) -> NonZeroUsize {
NonZeroUsize::new(match self {
Self::Fpr(_) => size_of::<u64>(),
_ => size_of::<u32>(),
})
.unwrap()
}
}
impl RegId for ArmRegisterID {
fn from_raw_id(id: usize) -> Option<(Self, Option<core::num::NonZeroUsize>)> {
let reg = match id {
0..=12 => Self::Gpr(id as u8),
13 => Self::Sp,
14 => Self::Lr,
15 => Self::Pc,
25 => Self::Cpsr,
26..=57 => Self::Fpr((id - 26) as u8),
58 => Self::Fpscr,
_ => return None,
};
Some((reg, Some(reg.size())))
}
}