#![allow(missing_docs)]

use abi_serde::impl_struct_serde;

use super::FrameOps;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct SavedFrame {
    pub gp_regs: [usize; 32],
    pub spsr_el1: u64,
    pub elr_el1: u64,
    pub sp_el0: u64,
    pub mdscr_el1: u64,
}

impl FrameOps for SavedFrame {
    fn set_user_ip(&mut self, value: usize) {
        self.elr_el1 = value as _;
    }

    fn user_ip(&self) -> usize {
        self.elr_el1 as _
    }
}

impl_struct_serde!(SavedFrame: [
    gp_regs,
    spsr_el1,
    elr_el1,
    sp_el0,
    mdscr_el1,
]);
