Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mips64el #39

Merged
merged 6 commits into from
Oct 31, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ jobs:
run: cd panda-rs && cargo build --verbose --no-default-features --features=mipsel,syscall-injection
- name: Build 64-bit Mips
run: cd panda-rs && cargo build --verbose --no-default-features --features=mips64,syscall-injection
- name: Build 64-bit Mips (Little Endian)
run: cd panda-rs && cargo build --verbose --no-default-features --features=mips64el,syscall-injection
- name: Build PowerPC
run: cd panda-rs && cargo build --verbose --no-default-features --features=ppc
1 change: 1 addition & 0 deletions panda-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ ppc = []
mips = []
mipsel = []
mips64 = []
mips64el = []
3 changes: 3 additions & 0 deletions panda-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,6 @@ include!("syscalls/mipsel.rs");

#[cfg(feature = "mips64")]
include!("syscalls/mips64.rs");

#[cfg(feature = "mips64el")]
include!("syscalls/mips64el.rs");
779 changes: 779 additions & 0 deletions panda-macros/src/syscalls/mips64el.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions panda-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ ppc = ["panda-re-sys/ppc", "panda-re-macros/ppc"]
mips = ["panda-re-sys/mips", "panda-re-macros/mips"]
mipsel = ["panda-re-sys/mipsel", "panda-re-macros/mipsel"]
mips64 = ["panda-re-sys/mips64", "panda-re-macros/mips64"]
mips64el = ["panda-re-sys/mips64el", "panda-re-macros/mips64el"]
3 changes: 2 additions & 1 deletion panda-rs/src/abi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_macros, unused_imports)]
use crate::prelude::*;
use crate::regs::Reg::{self, *};

Expand Down Expand Up @@ -105,7 +106,7 @@ pub mod syscall {
syscall_number = V0;
}

#[cfg(arch = "mips64")] {
#[cfg(arch = "mips64", arch = "mips64el")] {
// n32 ABI
args = [A0, A1, A2, A3, T0, T1];
return = V0;
Expand Down
52 changes: 44 additions & 8 deletions panda-rs/src/api/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ pub enum Reg {
static RET_REGS: &'static [Reg] = &[Reg::X0, Reg::X1, Reg::X2, Reg::X3];

/// MIPS named guest registers
#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumString, EnumIter, ToString)]
pub enum Reg {
ZERO = 0,
Expand Down Expand Up @@ -163,7 +168,12 @@ pub enum Reg {
}

/// MIPS return registers
#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
static RET_REGS: &'static [Reg] = &[Reg::V0, Reg::V1];

// TODO: support floating point set as well? Separate QEMU bank.
Expand Down Expand Up @@ -225,7 +235,8 @@ pub fn reg_sp() -> Reg {
feature = "aarch64",
feature = "mips",
feature = "mipsel",
feature = "mips64"
feature = "mips64",
feature = "mips64el"
))]
return Reg::SP;

Expand All @@ -250,7 +261,12 @@ pub fn reg_ret_addr() -> Option<Reg> {
#[cfg(any(feature = "arm", feature = "aarch64", feature = "ppc"))]
return Some(Reg::LR);

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
return Some(Reg::RA);
}

Expand All @@ -269,7 +285,12 @@ pub fn get_reg<T: Into<Reg>>(cpu: &CPUState, reg: T) -> target_ulong {
val = (*cpu_arch).xregs[reg.into() as usize];
}

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
unsafe {
val = (*cpu_arch).active_tc.gpr[reg.into() as usize];
}
Expand All @@ -296,7 +317,12 @@ pub fn set_reg<T: Into<Reg>>(cpu: &CPUState, reg: T, val: target_ulong) {
(*cpu_arch).regs[reg.into() as usize] = val;
}

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
unsafe {
(*cpu_arch).active_tc.gpr[reg.into() as usize] = val;
}
Expand Down Expand Up @@ -341,7 +367,12 @@ pub fn get_pc(cpu: &CPUState) -> target_ulong {
val = (*cpu_arch).nip;
}

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
unsafe {
val = (*cpu_arch).active_tc.PC;
}
Expand Down Expand Up @@ -372,7 +403,12 @@ pub fn set_pc(cpu: &mut CPUState, pc: target_ulong) {
(*cpu_arch).nip = pc;
}

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
unsafe {
(*cpu_arch).active_tc.PC = pc;
}
Expand Down
29 changes: 15 additions & 14 deletions panda-rs/src/api/rr.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::os::raw::c_int;
use std::ffi::CString;
use std::ptr;

use crate::{Error, RrError};

/// RR point-in-time: get current count of instructions replayed
pub fn rr_get_guest_instr_count() -> c_int {
unsafe {
panda_sys::rr_get_guest_instr_count_external()
}
pub fn rr_get_guest_instr_count() -> u64 {
unsafe { panda_sys::rr_get_guest_instr_count_external() as _ }
}

/// Stop and quit, wraps QMP functions.
Expand All @@ -26,17 +23,20 @@ pub fn record_begin(name: &str, snapshot: Option<&str>) -> Result<(), Error> {
Ok(c_name) => match snapshot {
Some(snap_name) => match CString::new(snap_name) {
Ok(c_snap_name) => {
let rr_ctrl_ret = unsafe { panda_sys::panda_record_begin(c_name.as_ptr(), c_snap_name.as_ptr()) };
let rr_ctrl_ret = unsafe {
panda_sys::panda_record_begin(c_name.as_ptr(), c_snap_name.as_ptr())
};
RrError::translate_err_code(rr_ctrl_ret)
},
Err(e) => Err(Error::InvalidString(e))
}
Err(e) => Err(Error::InvalidString(e)),
},
None => {
let rr_ctrl_ret = unsafe { panda_sys::panda_record_begin(c_name.as_ptr(), ptr::null()) };
let rr_ctrl_ret =
unsafe { panda_sys::panda_record_begin(c_name.as_ptr(), ptr::null()) };
RrError::translate_err_code(rr_ctrl_ret)
},
}
},
Err(e) => Err(Error::InvalidString(e))
Err(e) => Err(Error::InvalidString(e)),
}
}

Expand All @@ -52,13 +52,14 @@ pub fn replay_begin(name: &str) -> Result<(), Error> {
Ok(c_name) => {
let rr_ctrl_ret = unsafe { panda_sys::panda_replay_begin(c_name.as_ptr()) };
RrError::translate_err_code(rr_ctrl_ret)
},
Err(e) => Err(Error::InvalidString(e))
}
Err(e) => Err(Error::InvalidString(e)),
}
}

/// End currently running replay.
pub fn replay_end() -> Result<(), Error> {
let rr_ctrl_ret = unsafe { panda_sys::panda_replay_end() };
RrError::translate_err_code(rr_ctrl_ret)
}
}

7 changes: 6 additions & 1 deletion panda-rs/src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ pub type CPUArchPtr = *mut panda_sys::CPUX86State;
#[cfg(any(feature = "arm", feature = "aarch64"))]
pub type CPUArchPtr = *mut panda_sys::CPUARMState;

#[cfg(any(feature = "mips", feature = "mipsel", feature = "mips64"))]
#[cfg(any(
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el"
))]
pub type CPUArchPtr = *mut panda_sys::CPUMIPSState;

#[cfg(feature = "ppc")]
Expand Down
6 changes: 6 additions & 0 deletions panda-rs/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const ARCH: &str = "aarch64";
#[cfg(feature = "mips64")]
const ARCH: &str = "mips64";

#[cfg(feature = "mips64el")]
const ARCH: &str = "mips64el";

// ================ ARCH_ENDIAN ================

/// The byte order of the guest architecture being targetted by PANDA
Expand Down Expand Up @@ -68,3 +71,6 @@ const ENDIAN: Endian = Endian::Little;

#[cfg(feature = "mips64")]
const ENDIAN: Endian = Endian::Big;

#[cfg(feature = "mips64el")]
const ENDIAN: Endian = Endian::Little;
1 change: 1 addition & 0 deletions panda-rs/src/guest_ptr/guest_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ macro_rules! align {
feature = "mips",
feature = "mipsel",
feature = "mips64",
feature = "mips64el",
feature = "ppc",
))]
macro_rules! alignments {
Expand Down
5 changes: 4 additions & 1 deletion panda-rs/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use libloading::Symbol;
use std::ffi::CString;
use std::path::Path;

pub mod cosi;
pub mod glib;
pub mod guest_plugin_manager;
pub mod hooks;
pub mod hooks2;
pub mod osi;
pub mod cosi;
pub mod proc_start_linux;

#[cfg(not(feature = "ppc"))]
Expand Down Expand Up @@ -409,6 +409,9 @@ const PLUGIN_DIR: &str = "mipsel-softmmu/panda/plugins";
#[cfg(feature = "mips64")]
const PLUGIN_DIR: &str = "mips64-softmmu/panda/plugins";

#[cfg(feature = "mips64el")]
const PLUGIN_DIR: &str = "mips64el-softmmu/panda/plugins";

#[cfg(feature = "ppc")]
const PLUGIN_DIR: &str = "ppc-softmmu/panda/plugins";

Expand Down
1 change: 1 addition & 0 deletions panda-rs/src/syscall_injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ fn restart_syscall(cpu: &mut CPUState, pc: target_ulong) {
}
}

#[cfg(any(feature = "x86_64", feature = "i386"))]
const SYSENTER_INSTR: &[u8] = &[0xf, 0x34];

/// Run a syscall injector in the form as an async block/value to be evaluated. If
Expand Down
2 changes: 1 addition & 1 deletion panda-rs/src/syscall_injection/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) const VFORK: target_ulong = 190;
pub(crate) const VFORK: target_ulong = 220;

// TODO: mips needs to be changed to VFORK
#[cfg(feature = "mips64")]
#[cfg(any(feature = "mips64", feature = "mips64el"))]
pub(crate) const VFORK: target_ulong = 4002;

#[cfg(any(feature = "mips", feature = "mipsel"))]
Expand Down
1 change: 1 addition & 0 deletions panda-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ppc = []
mips = []
mipsel = []
mips64 = []
mips64el = []
3 changes: 3 additions & 0 deletions panda-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const ARCH: &str = "mipsel";
#[cfg(feature = "mips64")]
const ARCH: &str = "mips64";

#[cfg(feature = "mips64el")]
const ARCH: &str = "mips64el";

fn main() {
if cfg!(feature = "libpanda") {
println!("libpanda mode enabled");
Expand Down
9 changes: 7 additions & 2 deletions panda-sys/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ mod mipsel;
pub use mipsel::*;

#[cfg(feature = "mips64")]
mod mipsel;
mod mips64;
#[cfg(feature = "mips64")]
pub use mipsel::*;
pub use mips64::*;

#[cfg(feature = "mips64el")]
mod mips64el;
#[cfg(feature = "mips64el")]
pub use mips64el::*;
Loading
Loading