Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

i see tty logs in framebuffer in consoletest demo now

Layled77ddac2fe03
diff --git a/crates/gekko/src/cpu/interpreter/store_load.rs b/crates/gekko/src/cpu/interpreter/store_load.rs
index 6175e35..b3f25e0 100644
--- a/crates/gekko/src/cpu/interpreter/store_load.rs
+++ b/crates/gekko/src/cpu/interpreter/store_load.rs
@@ -3,21 +3,21 @@ use crate::cpu::condition::ConditionField;
pub fn store_load<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
match OP {
crate::cpu::lut::OP_STW | crate::cpu::lut::OP_STWU => {
- let addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
ctx.write_u32(addr, ctx.cpu.read_gpr(instr.rs()));
if OP == crate::cpu::lut::OP_STWU {
ctx.cpu.write_gpr(instr.ra(), addr);
}
}
crate::cpu::lut::OP_STH | crate::cpu::lut::OP_STHU => {
- let addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
ctx.write_u16(addr, ctx.cpu.read_gpr(instr.rs()) as u16);
if OP == crate::cpu::lut::OP_STHU {
ctx.cpu.write_gpr(instr.ra(), addr);
}
}
crate::cpu::lut::OP_STB | crate::cpu::lut::OP_STBU => {
- let addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
ctx.write_u8(addr, ctx.cpu.read_gpr(instr.rs()) as u8);
if OP == crate::cpu::lut::OP_STBU {
ctx.cpu.write_gpr(instr.ra(), addr);
@@ -64,7 +64,7 @@ pub fn store_load<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cp
}
}
crate::cpu::lut::OP_STMW => {
- let mut addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let mut addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
for r in instr.rs()..32 {
let val = ctx.cpu.read_gpr(r);
ctx.write_u32(addr, val);
@@ -186,7 +186,7 @@ pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate:
}
}
crate::cpu::lut::OP_STFD | crate::cpu::lut::OP_STFDU => {
- let addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
ctx.write_f64(addr, ctx.cpu.read_fpr(instr.rs()));
if OP == crate::cpu::lut::OP_STFDU {
ctx.cpu.write_gpr(instr.ra(), addr);
@@ -201,7 +201,7 @@ pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate:
}
}
crate::cpu::lut::OP_STFS | crate::cpu::lut::OP_STFSU => {
- let addr = ctx.cpu.read_gpr(instr.ra()).wrapping_add_signed(instr.disp());
+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
ctx.write_f32(addr, ctx.cpu.read_fpr(instr.rs()));
if OP == crate::cpu::lut::OP_STFSU {
ctx.cpu.write_gpr(instr.ra(), addr);
diff --git a/crates/gekko/src/cpu/irq.rs b/crates/gekko/src/cpu/irq.rs
index f45562d..340c735 100644
--- a/crates/gekko/src/cpu/irq.rs
+++ b/crates/gekko/src/cpu/irq.rs
@@ -47,6 +47,6 @@ impl Gekko {
self.cpu.pc = base | IRQ_EXTERNAL;
- tracing::trace!(addr = format!("{:08X}", self.cpu.pc), "IRQ triggered");
+ tracing::debug!(addr = format!("{:08X}", self.cpu.pc), "IRQ triggered");
}
-}
+}
diff --git a/crates/gekko/src/exi.rs b/crates/gekko/src/exi.rs
index f0cff3e..e26fc36 100644
--- a/crates/gekko/src/exi.rs
+++ b/crates/gekko/src/exi.rs
@@ -278,7 +278,7 @@ impl Exi {
regs::Channel2Data,
);
- pub fn mmio_read_u8(&self, offset: u32) -> u8 {
+ pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {
self.read_raw(EXI_BASE + offset, 1).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u8");
0
@@ -291,7 +291,7 @@ impl Exi {
}
}
- pub fn mmio_read_u16(&self, offset: u32) -> u16 {
+ pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {
self.read_raw(EXI_BASE + offset, 2).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u16");
0
@@ -304,7 +304,7 @@ impl Exi {
}
}
- pub fn mmio_read_u32(&self, offset: u32) -> u32 {
+ pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {
self.read_raw(EXI_BASE + offset, 4).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u32");
0
diff --git a/crates/gekko/src/flipper/pi.rs b/crates/gekko/src/flipper/pi.rs
index 4093c07..029f415 100644
--- a/crates/gekko/src/flipper/pi.rs
+++ b/crates/gekko/src/flipper/pi.rs
@@ -51,7 +51,7 @@ impl Pi {
crate::impl_mmio_dispatch!(regs::InterruptCause, regs::InterruptMask,);
- pub fn mmio_read_u8(&self, offset: u32) -> u8 {
+ pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {
self.read_raw(PI_BASE + offset, 1).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u8");
0
@@ -64,7 +64,7 @@ impl Pi {
}
}
- pub fn mmio_read_u16(&self, offset: u32) -> u16 {
+ pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {
self.read_raw(PI_BASE + offset, 2).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u16");
0
@@ -77,7 +77,7 @@ impl Pi {
}
}
- pub fn mmio_read_u32(&self, offset: u32) -> u32 {
+ pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {
self.read_raw(PI_BASE + offset, 4).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u32");
0
diff --git a/crates/gekko/src/flipper/pi/regs.rs b/crates/gekko/src/flipper/pi/regs.rs
index 0a80e84..40d2871 100644
--- a/crates/gekko/src/flipper/pi/regs.rs
+++ b/crates/gekko/src/flipper/pi/regs.rs
@@ -1,23 +1,25 @@
use super::Pi;
+use crate::mmio::traits::MmioRegister;
// 0xCC003000 4 r INTSR - Interrupt Cause
+
crate::mmio_register! {
- InterruptCause: u32 @ 0xCC003000 => Pi.intsr {
+ InterruptCause: u32 @ 0xCC003000 {
#[bits(0, alias = "error")]
pub gp_runtime_error: bool,
-
+
#[bits(1, alias = "rsw")]
pub reset_switch: bool,
-
+
#[bits(2, alias = "di")]
pub dvd: bool,
-
+
#[bits(3, alias = "si")]
pub serial: bool,
-
+
#[bits(4)]
pub exi: bool,
-
+
#[bits(5, alias = "ai")]
pub streaming: bool,
@@ -50,24 +52,39 @@ crate::mmio_register! {
}
}
+impl crate::mmio::traits::MmioAccess<Pi> for InterruptCause {
+ fn read(dev: &Pi) -> Self {
+ dev.intsr
+ }
+ fn write(self, dev: &mut Pi) {
+ dev.intsr = self;
+ }
+
+ fn read_at(dev: &mut Pi, addr: u32, access_size: u32) -> u32 {
+ let val = Self::read_sub(dev.intsr.to_raw(), addr, access_size);
+ dev.intsr = InterruptCause::from_raw(0); // auto-clear
+ val
+ }
+}
+
// 0xCC003004 4 r/w INTMR - Interrupt Mask
crate::mmio_register! {
InterruptMask: u32 @ 0xCC003004 => Pi.intmr {
#[bits(0, alias = "error")]
pub gp_runtime_error: bool,
-
+
#[bits(1, alias = "rsw")]
pub reset_switch: bool,
-
+
#[bits(2, alias = "di")]
pub dvd: bool,
-
+
#[bits(3, alias = "si")]
pub serial: bool,
-
+
#[bits(4)]
pub exi: bool,
-
+
#[bits(5, alias = "ai")]
pub streaming: bool,
diff --git a/crates/gekko/src/flipper/vi.rs b/crates/gekko/src/flipper/vi.rs
index 8b82595..7976aea 100644
--- a/crates/gekko/src/flipper/vi.rs
+++ b/crates/gekko/src/flipper/vi.rs
@@ -123,7 +123,7 @@ impl Vi {
(self.tfbl.xfb_addr() << 9) | ((self.tfbl.page_offset() as u32) << 24)
}
- pub fn mmio_read_u8(&self, offset: u32) -> u8 {
+ pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {
self.read_raw(VI_BASE + offset, 1).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u8");
0
@@ -136,7 +136,7 @@ impl Vi {
}
}
- pub fn mmio_read_u16(&self, offset: u32) -> u16 {
+ pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {
self.read_raw(VI_BASE + offset, 2).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u16");
0
@@ -149,7 +149,7 @@ impl Vi {
}
}
- pub fn mmio_read_u32(&self, offset: u32) -> u32 {
+ pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {
self.read_raw(VI_BASE + offset, 4).unwrap_or_else(|| {
tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u32");
0
diff --git a/crates/gekko/src/flipper/vi/tests.rs b/crates/gekko/src/flipper/vi/tests.rs
index 6115055..5dab73f 100644
--- a/crates/gekko/src/flipper/vi/tests.rs
+++ b/crates/gekko/src/flipper/vi/tests.rs
@@ -32,13 +32,13 @@ fn u16_write_lower_half_of_u32_register() {
#[test]
fn u16_read_upper_half_of_u32_register() {
- let vi = vi_with_top(0xAABBCCDD);
+ let mut vi = vi_with_top(0xAABBCCDD);
assert_eq!(vi.mmio_read_u16(TOP_OFF), 0xAABB);
}
#[test]
fn u16_read_lower_half_of_u32_register() {
- let vi = vi_with_top(0xAABBCCDD);
+ let mut vi = vi_with_top(0xAABBCCDD);
assert_eq!(vi.mmio_read_u16(TOP_OFF + 2), 0xCCDD);
}
diff --git a/crates/gekko/src/mmio/macros.rs b/crates/gekko/src/mmio/macros.rs
index c6ff747..7b2b887 100644
--- a/crates/gekko/src/mmio/macros.rs
+++ b/crates/gekko/src/mmio/macros.rs
@@ -5,7 +5,7 @@
macro_rules! impl_mmio_dispatch {
($($reg:ty),* $(,)?) => {
#[inline]
- fn read_raw(&self, addr: u32, access_size: u32) -> Option<u32> {
+ fn read_raw(&mut self, addr: u32, access_size: u32) -> Option<u32> {
$(if <$reg>::fits(addr, access_size) {
return Some(<$reg>::read_at(self, addr, access_size));
})*
diff --git a/crates/gekko/src/mmio/traits.rs b/crates/gekko/src/mmio/traits.rs
index 893d7f7..1896c34 100644
--- a/crates/gekko/src/mmio/traits.rs
+++ b/crates/gekko/src/mmio/traits.rs
@@ -35,7 +35,7 @@ pub trait MmioAccess<C>: MmioRegister {
fn write(self, component: &mut C);
/// Read `access_size` bytes from this register in `component` at physical address `addr`
- fn read_at(component: &C, addr: u32, access_size: u32) -> u32 {
+ fn read_at(component: &mut C, addr: u32, access_size: u32) -> u32 {
Self::read_sub(Self::read(component).to_raw(), addr, access_size)
}