A GameCube/Wii emulator and debugger written in Rust.
logging device
Layleb2cd051f005a
diff --git a/crates/gecko/src/hollywood/ipc.rs b/crates/gecko/src/hollywood/ipc.rsindex 0555be7..802ed7c 100644--- a/crates/gecko/src/hollywood/ipc.rs+++ b/crates/gecko/src/hollywood/ipc.rs@@ -21,6 +21,7 @@ pub struct DeviceContext<'a> {pub scheduler: &'a mut Scheduler<{ WII }>,pub di: &'a mut DvdInterface,pub pi: &'a mut ProcessorInterface,+ pub device_path: String,}pub trait IosDevice: Send {@@ -32,18 +33,28 @@ pub trait IosDevice: Send {0}- fn read(&mut self, _ctx: &mut DeviceContext<'_>, out_ptr: u32, out_len: u32) -> i32 {- tracing::warn!(out_ptr = format!("{out_ptr:#010X}"), out_len, "IOS_Read: unimplemented");+ fn read(&mut self, ctx: &mut DeviceContext<'_>, out_ptr: u32, out_len: u32) -> i32 {+ tracing::warn!(+ device = &ctx.device_path,+ out_ptr = format!("{out_ptr:#010X}"),+ out_len,+ "IOS_Read: unimplemented"+ );IPC_EINVAL}- fn write(&mut self, _ctx: &mut DeviceContext<'_>, in_ptr: u32, in_len: u32) -> i32 {- tracing::warn!(in_ptr = format!("{in_ptr:#010X}"), in_len, "IOS_Write: unimplemented");+ fn write(&mut self, ctx: &mut DeviceContext<'_>, in_ptr: u32, in_len: u32) -> i32 {+ tracing::warn!(+ device = &ctx.device_path,+ in_ptr = format!("{in_ptr:#010X}"),+ in_len,+ "IOS_Write: unimplemented"+ );IPC_EINVAL}- fn seek(&mut self, _ctx: &mut DeviceContext<'_>, offset: i32, whence: i32) -> i32 {- tracing::warn!(offset, whence, "IOS_Seek: unimplemented");+ fn seek(&mut self, ctx: &mut DeviceContext<'_>, offset: i32, whence: i32) -> i32 {+ tracing::warn!(device = &ctx.device_path, offset, whence, "IOS_Seek: unimplemented");0}@@ -57,6 +68,7 @@ pub trait IosDevice: Send {out_len: u32,) -> i32 {tracing::warn!(+ device = &ctx.device_path,cmd = format!("{cmd:#010X}"),in_buf = format!("{:02X?}", ctx.mmio.phys_slice(in_ptr, in_len as usize)),in_len,@@ -67,8 +79,9 @@ pub trait IosDevice: Send {IPC_EINVAL}- fn ioctlv(&mut self, _ctx: &mut DeviceContext<'_>, cmd: u32, in_count: u32, io_count: u32, vec_ptr: u32) -> i32 {+ fn ioctlv(&mut self, ctx: &mut DeviceContext<'_>, cmd: u32, in_count: u32, io_count: u32, vec_ptr: u32) -> i32 {tracing::warn!(+ device = &ctx.device_path,cmd = format!("{cmd:#010X}"),in_count,io_count,diff --git a/crates/gecko/src/hollywood/ipc/es.rs b/crates/gecko/src/hollywood/ipc/es.rsindex 82296a4..bc06d1c 100644--- a/crates/gecko/src/hollywood/ipc/es.rs+++ b/crates/gecko/src/hollywood/ipc/es.rs@@ -93,6 +93,7 @@ impl IosDevice for ETicketServices {}_ => {tracing::warn!(+ device = &ctx.device_path,cmd = format!("{cmd:#010X}"),in_count,io_count,diff --git a/crates/gecko/src/hollywood/ipc/fs.rs b/crates/gecko/src/hollywood/ipc/fs.rsindex ed60cf6..011c39c 100644--- a/crates/gecko/src/hollywood/ipc/fs.rs+++ b/crates/gecko/src/hollywood/ipc/fs.rs@@ -115,7 +115,12 @@ impl IosDevice for HostBackedFile {0}_ => {- tracing::warn!(cmd = format!("{cmd:#X}"), "HostBackedFile: unhandled ioctl");+ tracing::warn!(+ device = &ctx.device_path,+ path = format!("{}", self.path.display()),+ cmd = format!("{cmd:#X}"),+ "HostBackedFile: unhandled ioctl"+ );IPC_EINVAL}}diff --git a/crates/gecko/src/hollywood/ipc/sdio.rs b/crates/gecko/src/hollywood/ipc/sdio.rsindex e639bed..b9e7c12 100644--- a/crates/gecko/src/hollywood/ipc/sdio.rs+++ b/crates/gecko/src/hollywood/ipc/sdio.rs@@ -42,7 +42,11 @@ impl IosDevice for SdCard {0}_ => {- tracing::error!(cmd = format!("{cmd:#010X}"), "SDIO: unimplemented ioctl");+ tracing::error!(+ device = &ctx.device_path,+ cmd = format!("{cmd:#010X}"),+ "SDIO: unimplemented ioctl"+ );IPC_EINVAL}}diff --git a/crates/gecko/src/hollywood/ipc/stm/immediate.rs b/crates/gecko/src/hollywood/ipc/stm/immediate.rsindex 5a2c3da..1b8cf3b 100644--- a/crates/gecko/src/hollywood/ipc/stm/immediate.rs+++ b/crates/gecko/src/hollywood/ipc/stm/immediate.rs@@ -18,6 +18,7 @@ impl IosDevice for Immediate {IOCTL_VIDIMMING => 0,_ => {tracing::warn!(+ device = &ctx.device_path,cmd = format!("{cmd:#010X}"),in_buf = format!("{:02X?}", ctx.mmio.phys_slice(in_ptr, in_len as usize)),in_len,diff --git a/crates/gecko/src/hollywood/ipc/sysconf.rs b/crates/gecko/src/hollywood/ipc/sysconf.rsindex 10227a7..0a3776f 100644--- a/crates/gecko/src/hollywood/ipc/sysconf.rs+++ b/crates/gecko/src/hollywood/ipc/sysconf.rs@@ -50,7 +50,7 @@ impl IosDevice for SysConf {.phys_slice_mut(out_ptr, n).copy_from_slice(&self.blob[start..start + n]);self.pos += n as u64;-+n as i32}@@ -66,7 +66,7 @@ impl IosDevice for SysConf {SEEK_END => self.blob.len() as i64 + offset as i64,_ => return IPC_EINVAL,};-+if new_pos < 0 || new_pos > self.blob.len() as i64 {return IPC_EINVAL;}@@ -91,6 +91,7 @@ impl IosDevice for SysConf {}tracing::warn!(+ device = &ctx.device_path,cmd = format!("{cmd:#010X}"),out_buf = format!("{out_ptr:#010X}"),"SysConf: unimplemented ioctl"diff --git a/crates/gecko/src/hollywood/ipc/usb.rs b/crates/gecko/src/hollywood/ipc/usb.rsindex bb35df9..686ba7d 100644--- a/crates/gecko/src/hollywood/ipc/usb.rs+++ b/crates/gecko/src/hollywood/ipc/usb.rs@@ -120,7 +120,7 @@ impl Bluetooth {ctx.mmio.phys_slice_mut(buf_ptr, delivered).copy_from_slice(&packet[..delivered]);-+tracing::debug!(len = delivered,bytes = format!("{:02X?}", &packet[..delivered]),diff --git a/crates/gecko/src/hollywood/ipc/usb/l2cap.rs b/crates/gecko/src/hollywood/ipc/usb/l2cap.rsindex 648fb7c..b01a8da 100644--- a/crates/gecko/src/hollywood/ipc/usb/l2cap.rs+++ b/crates/gecko/src/hollywood/ipc/usb/l2cap.rs@@ -94,7 +94,7 @@ impl Bluetooth {dest_cid = format!("{dest_cid:#06x}"),"Wiimote L2CAP channel connected");-+self.queue_l2cap_config_req(source_cid);} else {tracing::warn!(diff --git a/crates/gecko/src/hollywood/ipc/usb/wiimote.rs b/crates/gecko/src/hollywood/ipc/usb/wiimote.rsindex ee36d16..76f0941 100644--- a/crates/gecko/src/hollywood/ipc/usb/wiimote.rs+++ b/crates/gecko/src/hollywood/ipc/usb/wiimote.rs@@ -97,8 +97,7 @@ const WIIMOTE_EEPROM_CALIBRATION: [u8; 42] = [// IR sensor calibration #1 (0x00..0x0B): 4 reference dot positions + checksum0x7F, 0x5D, 0x03, 0x80, 0x5D, 0x80, 0xA2, 0xB8, 0x7F, 0xA2, 0x0C,// IR sensor calibration #2 (0x0B..0x16): duplicate- 0x7F, 0x5D, 0x03, 0x80, 0x5D, 0x80, 0xA2, 0xB8, 0x7F, 0xA2, 0x0C,- // Accel calibration #1 (0x16..0x20)+ 0x7F, 0x5D, 0x03, 0x80, 0x5D, 0x80, 0xA2, 0xB8, 0x7F, 0xA2, 0x0C, // Accel calibration #1 (0x16..0x20)0x80, 0x80, 0x80, 0x00, // accel zero G (X, Y, Z, padding)0x9A, 0x9A, 0x9A, 0x00, // accel one G (X, Y, Z, padding)0x00, 0xA3, // padding, checksum@@ -356,7 +355,7 @@ impl WiimoteState {let chunk = (size - offset).min(16);let chunk_addr = address as u16 + offset as u16;out.push(self.read_chunk_report(chunk_addr, &self.eeprom[start + offset..start + offset + chunk], 0));-+offset += chunk;}@@ -380,21 +379,21 @@ impl WiimoteState {backing[0xFA..0x100].copy_from_slice(&NUNCHUK_ID);let base = (canonical & 0xFF) as usize;-+let mut out = Vec::new();let mut offset = 0usize;while offset < size {let chunk = (size - offset).min(16);let start = base + offset;let end = start + chunk;-+if end > backing.len() {out.push(self.read_chunk_report((address as u16) + offset as u16, &[], 0x08));break;}-+out.push(self.read_chunk_report((address as u16) + offset as u16, &backing[start..end], 0));-+offset += chunk;}out@@ -408,16 +407,16 @@ impl WiimoteState {} else {(((chunk_len as u8 - 1) & 0x0F) << 4) | (error & 0x0F)};-+let mut report = Vec::with_capacity(22);report.extend_from_slice(&[HID_PREFIX_INPUT, 0x21, bb0, bb1, size_and_error]);report.extend_from_slice(&address.to_be_bytes());report.extend_from_slice(&data[..chunk_len]);-+for _ in chunk_len..16 {report.push(0);}-+report}@@ -425,15 +424,15 @@ impl WiimoteState {let [bb0, bb1] = self.button_bytes();let ir_enabled = self.ir_enabled_pin1 && self.ir_enabled_pin2;let mut flags = self.leds << 4;-+if ir_enabled {flags |= 0x08;}-+if self.nunchuk_attached {flags |= 0x02; // extension connected}-+vec![HID_PREFIX_INPUT, 0x20, bb0, bb1, flags, 0x00, 0x00, 0x64]}}diff --git a/crates/gecko/src/input.rs b/crates/gecko/src/input.rsindex 4693fd3..53be6b4 100644--- a/crates/gecko/src/input.rs+++ b/crates/gecko/src/input.rs@@ -1,4 +1,5 @@-use crate::{SystemId, flipper::si::pad, WII, GC};+use crate::flipper::si::pad;+use crate::{GC, SystemId, WII};#[derive(Clone, Copy, Debug)]pub enum HostInput {@@ -35,4 +36,4 @@ impl HostInput {_ => unreachable!(),}}-}\ No newline at end of file+}diff --git a/crates/gecko/src/lib.rs b/crates/gecko/src/lib.rsindex 70cf576..064a158 100644--- a/crates/gecko/src/lib.rs+++ b/crates/gecko/src/lib.rs@@ -7,18 +7,18 @@ pub mod gekko;pub mod hollywood;pub mod host;pub mod idle;+pub mod input;pub mod ipl;pub mod mmio;pub mod scheduler;pub mod starlet;pub mod system;pub mod wii;-pub mod input;pub use gamecube::GameCube;+pub use input::HostInput;pub use system::{GC, System, SystemId, WII};pub use wii::Wii;-pub use input::HostInput;#[cfg(feature = "hooks")]pub mod hooks;diff --git a/crates/gecko/src/starlet.rs b/crates/gecko/src/starlet.rsindex 271beed..6d9fa89 100644--- a/crates/gecko/src/starlet.rs+++ b/crates/gecko/src/starlet.rs@@ -22,7 +22,7 @@ pub struct PendingResponse {/// directly so each fd has its own cursor.enum FdEntry {Shared(String),- Owned(Box<dyn IosDevice>),+ Owned { path: String, dev: Box<dyn IosDevice> },}pub struct Starlet {@@ -58,9 +58,15 @@ impl Starlet {/// Allocate a fresh fd that owns the given device instance. Used for/// per-open resources (host-backed real files).- pub fn allocate_owned_fd(&mut self, dev: Box<dyn IosDevice>) -> i32 {+ pub fn allocate_owned_fd(&mut self, path: &str, dev: Box<dyn IosDevice>) -> i32 {let fd = self.fresh_fd();- self.handles.insert(fd, FdEntry::Owned(dev));+ self.handles.insert(+ fd,+ FdEntry::Owned {+ path: path.to_owned(),+ dev,+ },+ );fd}@@ -77,7 +83,7 @@ impl Starlet {pub fn device_for_fd(&mut self, fd: i32) -> Option<&mut dyn IosDevice> {let path = match self.handles.get(&fd)? {FdEntry::Shared(p) => Some(p.clone()),- FdEntry::Owned(_) => None,+ FdEntry::Owned { .. } => None,};if let Some(path) = path {@@ -85,11 +91,17 @@ impl Starlet {}match self.handles.get_mut(&fd)? {- FdEntry::Owned(dev) => Some(dev.as_mut()),+ FdEntry::Owned { dev, .. } => Some(dev.as_mut()),FdEntry::Shared(_) => unreachable!(),}}+ pub fn device_path_for_fd(&self, fd: i32) -> Option<String> {+ match self.handles.get(&fd)? {+ FdEntry::Shared(path) | FdEntry::Owned { path, .. } => Some(path.clone()),+ }+ }+pub fn set_wiimote_buttons(&mut self, buttons: u16) -> bool {self.devices.get_mut("/dev/usb/oh1/57e/305")@@ -110,7 +122,7 @@ impl Starlet {};match entry {- FdEntry::Owned(mut dev) => dev.close(ctx),+ FdEntry::Owned { mut dev, .. } => dev.close(ctx),FdEntry::Shared(path) => match self.devices.get_mut(&path) {Some(dev) => dev.close(ctx),None => crate::hollywood::ipc::IPC_EINVAL,@@ -151,6 +163,7 @@ impl System<{ crate::WII }> {scheduler: &mut self.scheduler,di: &mut self.di,pi: &mut self.pi,+ device_path: "<unbound>".to_owned(),},)}@@ -198,12 +211,13 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:let path = self::read_c_string(&mut ctx, path_ptr);let fd = if let Some(dev) = starlet.device_for_path(&path) {+ ctx.device_path = path.clone();let rc = dev.open(&mut ctx, mode);if rc >= 0 { starlet.allocate_fd(&path) } else { rc }} else if let Some(real) =crate::hollywood::ipc::fs::HostBackedFile::try_open(&starlet.host_fs_root, &path, mode){- starlet.allocate_owned_fd(Box::new(real))+ starlet.allocate_owned_fd(&path, Box::new(real))} else {tracing::error!(%path, "IOS_Open: no device registered");IPC_ENOENT@@ -213,14 +227,23 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:fd}IOS_CLOSE => {- tracing::debug!(fd, "IOS_Close");+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);++ tracing::debug!(fd, device = device_path.as_str(), "IOS_Close");starlet.close_fd(fd, &mut ctx)}IOS_READ => {let out_ptr = ctx.mmio.phys_read_u32(cmd_paddr + 0x0C);let out_len = ctx.mmio.phys_read_u32(cmd_paddr + 0x10);+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);- tracing::debug!(fd, out_ptr = format!("{out_ptr:#010X}"), out_len, "IOS_Read");+ tracing::debug!(+ fd,+ device = device_path.as_str(),+ out_ptr = format!("{out_ptr:#010X}"),+ out_len,+ "IOS_Read"+ );match starlet.device_for_fd(fd) {Some(dev) => dev.read(&mut ctx, out_ptr, out_len),@@ -230,8 +253,15 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:IOS_WRITE => {let in_ptr = ctx.mmio.phys_read_u32(cmd_paddr + 0x0C);let in_len = ctx.mmio.phys_read_u32(cmd_paddr + 0x10);+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);- tracing::debug!(fd, in_ptr = format!("{in_ptr:#010X}"), in_len, "IOS_Write");+ tracing::debug!(+ fd,+ device = device_path.as_str(),+ in_ptr = format!("{in_ptr:#010X}"),+ in_len,+ "IOS_Write"+ );match starlet.device_for_fd(fd) {Some(dev) => dev.write(&mut ctx, in_ptr, in_len),@@ -241,8 +271,9 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:IOS_SEEK => {let offset = ctx.mmio.phys_read_u32(cmd_paddr + 0x0C) as i32;let whence = ctx.mmio.phys_read_u32(cmd_paddr + 0x10) as i32;+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);- tracing::debug!(fd, offset, whence, "IOS_Seek");+ tracing::debug!(fd, device = device_path.as_str(), offset, whence, "IOS_Seek");match starlet.device_for_fd(fd) {Some(dev) => dev.seek(&mut ctx, offset, whence),@@ -255,9 +286,11 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:let in_len = ctx.mmio.phys_read_u32(cmd_paddr + 0x14);let out_ptr = ctx.mmio.phys_read_u32(cmd_paddr + 0x18);let out_len = ctx.mmio.phys_read_u32(cmd_paddr + 0x1C);+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);tracing::debug!(fd,+ device = device_path.as_str(),ioctl_cmd = format!("{ioctl_cmd:#010X}"),in_ptr = format!("{in_ptr:#010X}"),in_len,@@ -276,8 +309,14 @@ fn process_command<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>, cmd_paddr:let in_count = ctx.mmio.phys_read_u32(cmd_paddr + 0x10);let io_count = ctx.mmio.phys_read_u32(cmd_paddr + 0x14);let vec_ptr = ctx.mmio.phys_read_u32(cmd_paddr + 0x18);+ let device_path = self::bind_fd_context(starlet, &mut ctx, fd);- tracing::debug!(fd, ioctl_cmd = format!("{ioctl_cmd:#010X}"), "IOS_Ioctlv");+ tracing::debug!(+ fd,+ device = device_path.as_str(),+ ioctl_cmd = format!("{ioctl_cmd:#010X}"),+ "IOS_Ioctlv"+ );match starlet.device_for_fd(fd) {Some(dev) => dev.ioctlv(&mut ctx, ioctl_cmd, in_count, io_count, vec_ptr),@@ -306,9 +345,15 @@ fn read_c_string(ctx: &mut DeviceContext<'_>, paddr: u32) -> String {String::from_utf8_lossy(&bytes).into_owned()}+fn bind_fd_context(starlet: &Starlet, ctx: &mut DeviceContext<'_>, fd: i32) -> String {+ let device_path = starlet.device_path_for_fd(fd).unwrap_or_else(|| "<invalid>".to_owned());+ ctx.device_path = device_path.clone();+ device_path+}+fn deliver_pending<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>) {if sys.hollywood.ipc.ppcctrl.arm_response() {- tracing::debug!(+ tracing::trace!(queue_len = sys.starlet.pending.len(),"deliver_pending: arm_response still set, skipping");@@ -316,10 +361,10 @@ fn deliver_pending<const SYSTEM: SystemId>(sys: &mut System<SYSTEM>) {}let Some(p) = sys.starlet.pending.pop_front() else {- tracing::debug!("deliver_pending: queue empty");+ tracing::trace!("deliver_pending: queue empty");return;};- tracing::debug!(+ tracing::trace!(cmd_paddr = format!("{:#010X}", p.cmd_paddr),result = p.result,remaining = sys.starlet.pending.len(),diff --git a/crates/screenshotter/src/main.rs b/crates/screenshotter/src/main.rsindex 13b1b92..d3b5e98 100644--- a/crates/screenshotter/src/main.rs+++ b/crates/screenshotter/src/main.rs@@ -219,13 +219,13 @@ fn run_one(device: &wgpu::Device, queue: &wgpu::Queue, surface_format: wgpu::Texlet mut input = HostInput::gc_connected();gamecube.apply_host_input(&input);-+gamecube.render_sink = Box::new(SyncSink {gx: gx.clone(),device: device.clone(),queue: queue.clone(),});-+gamecube.insert_dvd(image);let framerate = match gamecube.vi.dcr.video_format().refresh_rate() {diff --git a/crates/tinyapp/src/app.rs b/crates/tinyapp/src/app.rsindex b6ce927..3efd7d2 100644--- a/crates/tinyapp/src/app.rs+++ b/crates/tinyapp/src/app.rs@@ -315,7 +315,7 @@ impl ApplicationHandler for App {}}}-+let mut input = self.input.lock().unwrap();match &mut *input {HostInput::Gc(pad) => crate::update_pad(pad, key, pressed),@@ -326,13 +326,7 @@ impl ApplicationHandler for App {nunchuk_stick_y,} => {crate::update_wiimote_keys(wiimote_buttons, key, pressed);- crate::update_nunchuk_keys(- nunchuk_buttons,- nunchuk_stick_x,- nunchuk_stick_y,- key,- pressed,- );+ crate::update_nunchuk_keys(nunchuk_buttons, nunchuk_stick_x, nunchuk_stick_y, key, pressed);}}}@@ -346,7 +340,7 @@ impl ApplicationHandler for App {};if let Some(mask) = mask {let mut input = self.input.lock().unwrap();-+if let HostInput::Wii { wiimote_buttons, .. } = &mut *input {let next = if pressed {*wiimote_buttons | mask