From 9df9f3bcf75f501e159af35d555ea437c7cc0f8c Mon Sep 17 00:00:00 2001 From: SuchAFuriousDeath <48620541+SuchAFuriousDeath@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:54:30 +0200 Subject: [PATCH] Implements read_registers for x86_64 (#1050) Co-authored-by: tompro --- gui/src/vmm/cpu/x86_64.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gui/src/vmm/cpu/x86_64.rs b/gui/src/vmm/cpu/x86_64.rs index 383dfa69..a82b151e 100644 --- a/gui/src/vmm/cpu/x86_64.rs +++ b/gui/src/vmm/cpu/x86_64.rs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 +use super::controller::CpuController; use super::CpuManager; use crate::vmm::hv::Hypervisor; use crate::vmm::screen::Screen; @@ -9,14 +10,27 @@ use gdbstub::target::ext::breakpoints::{ Breakpoints, BreakpointsOps, SwBreakpoint, SwBreakpointOps, }; use gdbstub::target::ext::thread_extra_info::{ThreadExtraInfo, ThreadExtraInfoOps}; -use gdbstub::target::TargetResult; +use gdbstub::target::{TargetError as GdbTargetError, TargetResult}; use gdbstub_arch::x86::reg::X86_64CoreRegs; use gdbstub_arch::x86::X86_64_SSE; use std::num::NonZero; use thiserror::Error; +const ENOENT: u8 = 2; + pub type GdbRegs = gdbstub_arch::x86::reg::X86_64CoreRegs; +impl CpuManager { + fn get_cpu(&mut self, tid: Tid) -> TargetResult<&mut CpuController, Self> { + let cpu = self + .cpus + .get_mut(tid.get() as usize - 1) + .ok_or(GdbTargetError::Errno(ENOENT))?; + + Ok(cpu) + } +} + impl gdbstub::target::Target for CpuManager { type Arch = X86_64_SSE; type Error = TargetError; @@ -32,10 +46,18 @@ impl gdbstub::target::Target for CpuManager { impl MultiThreadBase for CpuManager { fn read_registers(&mut self, regs: &mut X86_64CoreRegs, tid: Tid) -> TargetResult<(), Self> { - todo!() + let mut cpu = self.get_cpu(tid)?; + + let current_regs = cpu.debug_mut().unwrap().lock(); + + *regs = current_regs.clone(); + + Ok(()) } fn write_registers(&mut self, regs: &X86_64CoreRegs, tid: Tid) -> TargetResult<(), Self> { + let mut _cpu = self.get_cpu(tid)?; + todo!() } @@ -45,10 +67,14 @@ impl MultiThreadBase for CpuManager { data: &mut [u8], tid: Tid, ) -> TargetResult { + let mut _cpu = self.get_cpu(tid)?; + todo!() } fn write_addrs(&mut self, start_addr: u64, data: &[u8], tid: Tid) -> TargetResult<(), Self> { + let mut _cpu = self.get_cpu(tid)?; + todo!() }