Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions clicky-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ static_assertions = "1.1"
thiserror = "1.0"

# emulation related
armv4t_emu = { git = "https://github.com/daniel5151/armv4t_emu.git" }
gdbstub = "0.4"
armv4t_emu = "0.1.2"
gdbstub = "0.5"
gdbstub_arch = "0.1.0"

# async/await
async-channel = "1.4"
Expand Down
95 changes: 74 additions & 21 deletions clicky-core/src/sys/ipod4g/gdb.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use std::collections::HashMap;

use armv4t_emu::reg;
use gdbstub::arch;
use gdbstub_arch;
use gdbstub::common::Tid;
use gdbstub::target;
use gdbstub::target::ext::base::GdbInterrupt;
use gdbstub::target::ext::base::multithread::{
Actions, MultiThreadOps, ResumeAction, ThreadStopReason,
MultiThreadOps, ResumeAction, ThreadStopReason,
};
use gdbstub::target::ext::breakpoints::WatchKind;
use gdbstub::target::ext::monitor_cmd::{outputln, ConsoleOutput};
use gdbstub::target::{Target, TargetResult};

use crate::devices::Device;
use crate::error::*;
use crate::memory::{MemAccessKind, Memory};
use crate::memory::{MemAccess, MemAccessKind, MemAccessVal, Memory};

use super::{BlockMode, CpuId, Ipod4g};

Expand All @@ -32,6 +33,7 @@ pub struct Ipod4gGdb {
breakpoints: Vec<u32>,

single_step_irq: bool,
resume_action_is_step: Option<bool>,
}

impl Ipod4gGdb {
Expand All @@ -42,6 +44,7 @@ impl Ipod4gGdb {
watchpoint_kinds: HashMap::new(),
breakpoints: Vec::new(),
single_step_irq: false,
resume_action_is_step: None,
}
}

Expand Down Expand Up @@ -205,38 +208,49 @@ fn event_to_stopreason(e: Event, id: CpuId) -> ThreadStopReason<u32> {
}

impl Target for Ipod4gGdb {
type Arch = arch::arm::Armv4t;
type Arch = gdbstub_arch::arm::Armv4t;
type Error = FatalMemException;

fn base_ops(&mut self) -> target::ext::base::BaseOps<Self::Arch, Self::Error> {
target::ext::base::BaseOps::MultiThread(self)
}

fn sw_breakpoint(&mut self) -> Option<target::ext::breakpoints::SwBreakpointOps<Self>> {
fn breakpoints(&mut self) -> Option<target::ext::breakpoints::BreakpointsOps<Self>> {
Some(self)
}

fn hw_watchpoint(&mut self) -> Option<target::ext::breakpoints::HwWatchpointOps<Self>> {
fn monitor_cmd(&mut self) -> Option<target::ext::monitor_cmd::MonitorCmdOps<Self>> {
Some(self)
}
}

fn monitor_cmd(&mut self) -> Option<target::ext::monitor_cmd::MonitorCmdOps<Self>> {
impl target::ext::breakpoints::Breakpoints for Ipod4gGdb {
fn sw_breakpoint(&mut self) -> Option<target::ext::breakpoints::SwBreakpointOps<Self>> {
Some(self)
}

fn hw_watchpoint(&mut self) -> Option<target::ext::breakpoints::HwWatchpointOps<Self>> {
Some(self)
}
}

impl MultiThreadOps for Ipod4gGdb {
fn resume(
&mut self,
actions: Actions,
check_gdb_interrupt: &mut dyn FnMut() -> bool,
default_resume_action: ResumeAction,
gdb_interrupt: GdbInterrupt<'_>,
) -> Result<ThreadStopReason<u32>, Self::Error> {
// FIXME: properly handle multiple actions...
let actions = actions.collect::<Vec<_>>();
let (_, action) = actions[0];
let default_resume_action_is_step = match default_resume_action {
ResumeAction::Step => true,
ResumeAction::Continue => false,
_ => return Ok(ThreadStopReason::DoneStep), // should be an error
};

match action {
ResumeAction::Step => {
match self
.resume_action_is_step
.unwrap_or(default_resume_action_is_step)
{
true => {
if !self.single_step_irq {
self.sys.skip_irq_check = true;
}
Expand All @@ -248,12 +262,13 @@ impl MultiThreadOps for Ipod4gGdb {
self.sys.skip_irq_check = false;
}
res
}
ResumeAction::Continue => {
},
false => {
let mut gdb_interrupt = gdb_interrupt.no_async();
let mut cycles: usize = 0;
loop {
// check for GDB interrupt every 1024 instructions
if cycles % 1024 == 0 && check_gdb_interrupt() {
if cycles % 1024 == 0 && gdb_interrupt.pending() {
return Ok(ThreadStopReason::GdbInterrupt);
}
cycles += 1;
Expand All @@ -266,9 +281,47 @@ impl MultiThreadOps for Ipod4gGdb {
}
}

fn clear_resume_actions(&mut self) -> Result<(), Self::Error> {
self.resume_action_is_step = None;
Ok(())
}

fn set_resume_action(&mut self, tid: Tid, action: ResumeAction) -> Result<(), Self::Error> {
// in this emulator, each core runs in lock-step, so we don't actually care
// about the specific tid. In real integrations, you very much should!

if self.resume_action_is_step.is_some() {
return Ok(());
}

let cpu = match tid_to_cpuid(tid).unwrap() {
CpuId::Cpu => &mut self.sys.cpu,
CpuId::Cop => &mut self.sys.cop,
};

self.resume_action_is_step = match action {
ResumeAction::Step => Some(true),
ResumeAction::Continue => Some(false),
_ => return MemException::Fatal("no support for resuming with signal".to_owned()).resolve(
"Debug",
MemExceptionCtx {
pc: cpu.reg_get(cpu.mode(), reg::PC),
access: MemAccess {
kind: MemAccessKind::Read,
offset: 0,
val: MemAccessVal::U8(0),
},
in_device: format!("{}", tid_to_cpuid(tid).unwrap()),
},
),
};

Ok(())
}

fn read_registers(
&mut self,
regs: &mut arch::arm::reg::ArmCoreRegs,
regs: &mut gdbstub_arch::arm::reg::ArmCoreRegs,
tid: Tid,
) -> TargetResult<(), Self> {
let cpu = match tid_to_cpuid(tid).unwrap() {
Expand All @@ -291,7 +344,7 @@ impl MultiThreadOps for Ipod4gGdb {

fn write_registers(
&mut self,
regs: &arch::arm::reg::ArmCoreRegs,
regs: &gdbstub_arch::arm::reg::ArmCoreRegs,
tid: Tid,
) -> TargetResult<(), Self> {
let cpu = match tid_to_cpuid(tid).unwrap() {
Expand Down Expand Up @@ -351,12 +404,12 @@ impl MultiThreadOps for Ipod4gGdb {
}

impl target::ext::breakpoints::SwBreakpoint for Ipod4gGdb {
fn add_sw_breakpoint(&mut self, addr: u32) -> TargetResult<bool, Self> {
fn add_sw_breakpoint(&mut self, addr: u32, _kind: gdbstub_arch::arm::ArmBreakpointKind) -> TargetResult<bool, Self> {
self.breakpoints.push(addr);
Ok(true)
}

fn remove_sw_breakpoint(&mut self, addr: u32) -> TargetResult<bool, Self> {
fn remove_sw_breakpoint(&mut self, addr: u32, _kind: gdbstub_arch::arm::ArmBreakpointKind) -> TargetResult<bool, Self> {
match self.breakpoints.iter().position(|x| *x == addr) {
None => return Ok(false),
Some(pos) => self.breakpoints.remove(pos),
Expand Down
2 changes: 1 addition & 1 deletion clicky-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ default = ["minifb"]
clicky-core = { path = "../clicky-core/" }

cfg-if = "0.1"
gdbstub = "0.4"
gdbstub = "0.5"
human-size = "0.4"
log = "0.4"
pretty_env_logger = "0.3"
Expand Down
8 changes: 6 additions & 2 deletions clicky-desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ fn main() -> DynResult<()> {
info!("Target is still running. Resuming execution...");
system.run()
}
DisconnectReason::TargetHalted => {
info!("Target halted!");
DisconnectReason::TargetExited(_) => {
info!("Target exited!");
Ok(())
}
DisconnectReason::TargetTerminated(_) => {
info!("Target terminated!");
Ok(())
}
DisconnectReason::Kill => {
Expand Down
Loading