Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

fix macronix and log EXI

Layle73c4528ef1b7
diff --git a/crates/gecko/src/flipper/exi.rs b/crates/gecko/src/flipper/exi.rs
index f8f5d31..59e1dca 100644
--- a/crates/gecko/src/flipper/exi.rs
+++ b/crates/gecko/src/flipper/exi.rs
@@ -76,6 +76,10 @@ impl ExternalInterface {
}
}
+ pub fn device_connected(&self, channel: usize) -> bool {
+ self.devices[channel][0].as_ref().is_some_and(|d| d.connected())
+ }
+
#[inline(always)]
pub fn interrupt_active(&self) -> bool {
Self::channel_interrupt_active(&self.ch0_csr)
@@ -130,6 +134,16 @@ impl ExternalInterface {
let size = (transfer_length as usize) + 1;
if let Some(device) = &mut self.devices[CHANNEL][slot] {
+ if device.is_stub() {
+ tracing::warn!(
+ channel = CHANNEL,
+ slot,
+ ?transfer_type,
+ size,
+ "EXI immediate transfer to unimplemented device"
+ );
+ }
+
for i in 0..size {
if transfer_type == TransferType::Read {
bytes[i] = 0;
@@ -137,6 +151,14 @@ impl ExternalInterface {
device.transfer_byte(&mut bytes[i]);
}
} else {
+ tracing::warn!(
+ channel = CHANNEL,
+ slot,
+ ?transfer_type,
+ size,
+ "EXI immediate transfer to empty slot"
+ );
+
bytes[..size].fill(0);
}
@@ -265,13 +287,35 @@ pub fn run_dma<const CHANNEL: usize, const SYSTEM: SystemId>(sys: &mut System<SY
};
if let Some(device) = &mut sys.exi.devices[CHANNEL][slot] {
+ let stub = device.is_stub();
+
match transfer_type {
TransferType::Read => {
+ if stub {
+ tracing::warn!(
+ channel = CHANNEL,
+ slot,
+ length,
+ "EXI DMA read from unimplemented device"
+ );
+ }
+
device.dma_read(sys.mmio.phys_slice_mut(address, length as usize));
#[cfg(feature = "jit")]
sys.mmio.queue_icbi_for_range(address, length);
}
- TransferType::Write => device.dma_write(sys.mmio.phys_slice(address, length as usize)),
+ TransferType::Write => {
+ if stub {
+ tracing::error!(
+ channel = CHANNEL,
+ slot,
+ length,
+ "EXI DMA write to unimplemented device (data dropped)"
+ );
+ }
+
+ device.dma_write(sys.mmio.phys_slice(address, length as usize));
+ }
TransferType::ReadAndWrite | TransferType::Reserved => {
tracing::error!(
channel = CHANNEL,
@@ -280,6 +324,8 @@ pub fn run_dma<const CHANNEL: usize, const SYSTEM: SystemId>(sys: &mut System<SY
);
}
}
+ } else {
+ tracing::warn!(channel = CHANNEL, slot, ?transfer_type, length, "EXI DMA to empty slot");
}
sys.exi.finish_transfer::<CHANNEL>();
diff --git a/crates/gecko/src/flipper/exi/device.rs b/crates/gecko/src/flipper/exi/device.rs
index 07303d4..fbc3bb0 100644
--- a/crates/gecko/src/flipper/exi/device.rs
+++ b/crates/gecko/src/flipper/exi/device.rs
@@ -15,6 +15,14 @@ pub trait ExiDevice: Send {
self.transfer_byte(&mut b);
}
}
+
+ fn connected(&self) -> bool {
+ true
+ }
+
+ fn is_stub(&self) -> bool {
+ false
+ }
}
pub struct ExiDummy;
@@ -23,4 +31,12 @@ impl ExiDevice for ExiDummy {
fn transfer_byte(&mut self, byte: &mut u8) {
*byte = 0;
}
+
+ fn connected(&self) -> bool {
+ false
+ }
+
+ fn is_stub(&self) -> bool {
+ true
+ }
}
diff --git a/crates/gecko/src/flipper/exi/macronix.rs b/crates/gecko/src/flipper/exi/macronix.rs
index ebfcd96..35a86c3 100644
--- a/crates/gecko/src/flipper/exi/macronix.rs
+++ b/crates/gecko/src/flipper/exi/macronix.rs
@@ -1,15 +1,15 @@
// GameCube IPL ROM / SRAM / RTC device (EXI channel 0, device 1)
// Macronix device according to yagcd, TODO: update name
// - Address 0x000000..0x1FFFFF: Mask ROM (2 MB)
-// - Address 0x800000..0x800043: SRAM (TODO: 64 or 68 bytes??)
+// - Address 0x800000..0x80003F: SRAM (64 bytes)
// - Address 0x840000: RTC (seconds since 2000-01-01?)
const IPL_START: u32 = 0x000000;
const IPL_END: u32 = 0x1FFFFF;
const SRAM_START: u32 = 0x800000;
-const SRAM_END: u32 = 0x800043;
-const SRAM_SIZE: usize = 68;
+const SRAM_END: u32 = 0x80003F;
+const SRAM_SIZE: usize = 64;
const RTC_START: u32 = 0x840000;
const RTC_END: u32 = 0x840004;
@@ -212,7 +212,6 @@ impl Sram {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
- 0x01, 0x04, 0xFE, 0xFB, // TODO: start and end is cooked? isnt it supposed to be 64 bytes?
],
}
}
diff --git a/crates/gecko/src/flipper/exi/regs.rs b/crates/gecko/src/flipper/exi/regs.rs
index 9a27c3f..dbeaa68 100644
--- a/crates/gecko/src/flipper/exi/regs.rs
+++ b/crates/gecko/src/flipper/exi/regs.rs
@@ -92,7 +92,9 @@ crate::mmio_reg!(Channel0Status: u32 @ 0xCC006800);
impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel0Status {
fn read(sys: &mut System<SYSTEM>) -> Self {
- sys.exi.ch0_csr
+ let mut csr = sys.exi.ch0_csr;
+ csr.set_device_connected(sys.exi.device_connected(0));
+ csr
}
fn write(self, sys: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut sys.exi.ch0_csr, self);
@@ -195,7 +197,9 @@ crate::mmio_reg!(Channel1Status: u32 @ 0xCC006814);
impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel1Status {
fn read(sys: &mut System<SYSTEM>) -> Self {
- sys.exi.ch1_csr
+ let mut csr = sys.exi.ch1_csr;
+ csr.set_device_connected(sys.exi.device_connected(1));
+ csr
}
fn write(self, sys: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut sys.exi.ch1_csr, self);
@@ -298,7 +302,9 @@ crate::mmio_reg!(Channel2Status: u32 @ 0xCC006828);
impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel2Status {
fn read(sys: &mut System<SYSTEM>) -> Self {
- sys.exi.ch2_csr
+ let mut csr = sys.exi.ch2_csr;
+ csr.set_device_connected(sys.exi.device_connected(2));
+ csr
}
fn write(self, sys: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut sys.exi.ch2_csr, self);