use gdbstub::target::ext::breakpoints;
use patina_internal_cpu::{interrupts::ExceptionContext, paging::PatinaPageTable};
use crate::ExceptionInfo;
cfg_if::cfg_if! {
if #[cfg(target_arch = "x86_64")] {
#[cfg_attr(coverage, coverage(off))]
mod x64;
pub type SystemArch = x64::X64Arch;
} else if #[cfg(target_arch = "aarch64")] {
#[cfg_attr(coverage, coverage(off))]
mod aarch64;
pub type SystemArch = aarch64::Aarch64Arch;
}
}
pub trait DebuggerArch {
const DEFAULT_EXCEPTION_TYPES: &'static [usize];
const BREAKPOINT_INSTRUCTION: &'static [u8];
const GDB_TARGET_XML: &'static str;
const GDB_REGISTERS_XML: &'static str;
fn breakpoint();
fn process_entry(exception_type: u64, context: &mut ExceptionContext) -> ExceptionInfo;
fn process_exit(exception_info: &mut ExceptionInfo);
fn set_single_step(exception_info: &mut ExceptionInfo);
fn initialize();
fn add_watchpoint(address: u64, length: u64, access_type: breakpoints::WatchKind) -> bool;
fn remove_watchpoint(address: u64, length: u64, access_type: breakpoints::WatchKind) -> bool;
fn reboot();
fn get_page_table() -> Result<impl PatinaPageTable, ()>;
fn monitor_cmd(_tokens: &mut core::str::SplitWhitespace, _out: &mut dyn core::fmt::Write) {}
fn memory_poke_test(_address: u64) -> Result<(), ()>;
fn check_memory_poke_test(_context: &mut ExceptionContext) -> bool;
}
pub trait UefiArchRegs: Sized {
fn from_context(context: &ExceptionContext) -> Self;
fn write_to_context(&self, context: &mut ExceptionContext);
fn read_from_context(&mut self, context: &ExceptionContext) {
*self = Self::from_context(context);
}
fn read_register_from_context(
context: &ExceptionContext,
reg_id: <SystemArch as gdbstub::arch::Arch>::RegId,
buf: &mut [u8],
) -> Result<usize, ()>;
fn write_register_to_context(
context: &mut ExceptionContext,
reg_id: <SystemArch as gdbstub::arch::Arch>::RegId,
buf: &[u8],
) -> Result<(), ()>;
}