A GameCube/Wii emulator and debugger written in Rust.
added callstack and lilyskategc homebrew
Laylec4cb6a301adc
diff --git a/.gitmodules b/.gitmodulesindex e2415e2..7122d95 100644--- a/.gitmodules+++ b/.gitmodules@@ -1,3 +1,6 @@[submodule "submodules/chipi-spec"]path = submodules/chipi-specurl = https://github.com/ioncodes/chipi-spec+[submodule "submodules/lilyskategc"]+ path = submodules/lilyskategc+ url = https://github.com/ioncodes/lilyskategcdiff --git a/Cargo.lock b/Cargo.lockindex dca75fc..cf7451b 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -664,6 +664,7 @@ dependencies = ["egui","egui-phosphor","gecko",+ "image 0.1.0",][[package]]diff --git a/crates/dbglib/Cargo.toml b/crates/dbglib/Cargo.tomlindex e72dd2d..994077f 100644--- a/crates/dbglib/Cargo.toml+++ b/crates/dbglib/Cargo.toml@@ -6,6 +6,7 @@ edition = "2024"[dependencies]gecko = { path = "../gecko" }disasm = { path = "../disasm" }+image = { path = "../image" }backend-wgpu = { path = "../backend-wgpu" }egui = "0.33.3"egui-phosphor = "0.11.0"diff --git a/crates/dbglib/src/windows.rs b/crates/dbglib/src/windows.rsindex 862649b..0c97d75 100644--- a/crates/dbglib/src/windows.rs+++ b/crates/dbglib/src/windows.rs@@ -1,3 +1,4 @@+pub mod callstack;pub mod controls;pub mod cpu;pub mod dsp;diff --git a/crates/dbglib/src/windows/callstack.rs b/crates/dbglib/src/windows/callstack.rsnew file mode 100644index 0000000..769e0e3--- /dev/null+++ b/crates/dbglib/src/windows/callstack.rs@@ -0,0 +1,146 @@+use egui::{Color32, Context, RichText, ScrollArea};+use gecko::cpu::Cpu;+use gecko::mmio::Mmio;+use image::symbols::SymbolTable;++const MAX_FRAMES: usize = 64;+const RAM_LO: u32 = 0x8000_0000;+const RAM_HI: u32 = 0x817F_FFFF;++fn is_valid_ram(addr: u32) -> bool {+ (RAM_LO..=RAM_HI).contains(&addr)+}++pub struct CallFrame {+ pub addr: u32,+ pub symbol: Option<String>,+ pub offset: u32,+}++/// Walk the PowerPC stack using the back-chain / saved-LR convention.+///+/// PowerPC EABI stack frame layout (32-bit):+/// [SP + 0] = back chain (pointer to caller's frame)+/// [SP + 4] = saved LR (written by the callee that owns this frame)+///+/// We emit the current PC, then LR (handles leaf functions that never save+/// LR to the stack), then walk back-chain pointers reading saved LRs.+pub fn walk_callstack(cpu: &Cpu, mmio: &Mmio, symbols: Option<&SymbolTable>) -> Vec<CallFrame> {+ let mut frames = Vec::new();++ let resolve = |addr: u32| -> (Option<String>, u32) {+ if let Some(syms) = symbols {+ if let Some(sym) = syms.lookup(addr) {+ return (Some(sym.name.clone()), addr - sym.addr);+ }+ }+ (None, 0)+ };++ let push = |frames: &mut Vec<CallFrame>, addr: u32| {+ let (sym, off) = resolve(addr);+ frames.push(CallFrame {+ addr,+ symbol: sym,+ offset: off,+ });+ };++ // Frame 0: current PC+ push(&mut frames, cpu.pc);++ // Frame 1: LR, immediate return address+ // For leaf functions LR is the only way to find the caller since they+ // don't create a stack frame or save LR to memory.+ let lr = cpu.spr.lr;+ if lr != 0 && is_valid_ram(lr) {+ push(&mut frames, lr);+ }++ // Walk the back-chain, reading saved LR from each frame+ let mut sp = cpu.gprs[1]; // r1 = stack pointer++ for _ in 0..MAX_FRAMES {+ if !is_valid_ram(sp) {+ break;+ }++ let back_chain = mmio.virt_read_u32(sp);++ if back_chain == 0 || !is_valid_ram(back_chain) {+ break;+ }++ // Stack grows downward, so back chain should be at a higher address.+ if back_chain <= sp {+ break;+ }++ // The LR save slot at [SP + 4] was written by the function that+ // created this frame (i.e. the callee that set up SP).+ let saved_lr = mmio.virt_read_u32(sp + 4);++ if saved_lr != 0 && is_valid_ram(saved_lr) {+ // Avoid duplicating the LR we already emitted above.+ if frames.len() < 2 || saved_lr != frames[1].addr {+ push(&mut frames, saved_lr);+ }+ }++ sp = back_chain;+ }++ frames+}++pub fn show_callstack(ctx: &Context, open: &mut bool, cpu: &Cpu, mmio: &Mmio, symbols: Option<&SymbolTable>) {+ let frames = walk_callstack(cpu, mmio, symbols);++ egui::Window::new("Call Stack").open(open).show(ctx, |ui| {+ ui.label(+ RichText::new(format!("{} frames", frames.len()))+ .small()+ .color(Color32::from_rgb(140, 140, 140)),+ );++ ui.separator();++ ScrollArea::vertical().id_salt("callstack_scroll").show(ui, |ui| {+ egui::Grid::new("callstack_grid")+ .num_columns(3)+ .striped(true)+ .min_col_width(0.0)+ .show(ui, |ui| {+ for (i, frame) in frames.iter().enumerate() {+ // Frame index+ ui.label(+ RichText::new(format!("#{i}"))+ .monospace()+ .color(Color32::from_rgb(100, 100, 100)),+ );++ // Address+ ui.label(+ RichText::new(format!("{:#010X}", frame.addr))+ .monospace()+ .color(Color32::from_rgb(150, 220, 150)),+ );++ // Symbol name + offset+ if let Some(name) = &frame.symbol {+ let label = if frame.offset > 0 {+ format!("{}+{:#X}", name, frame.offset)+ } else {+ name.clone()+ };+ ui.label(RichText::new(label).monospace().color(Color32::from_rgb(100, 180, 255)));+ } else {+ ui.label(RichText::new("???").monospace().color(Color32::from_rgb(100, 100, 100)));+ }++ ui.end_row();+ }+ });+ });+ });+}diff --git a/crates/dbglib/src/windows/cpu.rs b/crates/dbglib/src/windows/cpu.rsindex 9d17a98..f817f20 100644--- a/crates/dbglib/src/windows/cpu.rs+++ b/crates/dbglib/src/windows/cpu.rs@@ -1,174 +1,187 @@use egui::{Align, Color32, Context, Grid, RichText, ScrollArea};use gecko::cpu::Cpu;use gecko::mmio::Mmio;+use image::symbols::SymbolTable;use super::token_color;-pub fn show_cpu(ctx: &Context, open: &mut bool, cpu: &Cpu, mmio: &Mmio) {- egui::Window::new("CPU")- .open(open)- .default_size(egui::vec2(1200.0, 800.0))- .show(ctx, |ui| {- ui.horizontal_top(|ui| {- ui.vertical(|ui| {- ui.set_min_width(350.0);- ui.set_max_width(350.0);- Grid::new("special_regs").num_columns(5).striped(true).show(ui, |ui| {- ui.label("PC");- ui.monospace(format!("{:#010X}", cpu.pc));- ui.allocate_space(egui::vec2(16.0, 0.0));- ui.label("CTR");- ui.monospace(format!("{:#010X}", cpu.spr.ctr));- ui.end_row();-- ui.label("LR");- ui.monospace(format!("{:#010X}", cpu.spr.lr));- ui.allocate_space(egui::vec2(16.0, 0.0));- ui.label("MSR");- ui.monospace(format!("{:#010X}", cpu.msr.raw()));- ui.end_row();-- ui.label("XER");- ui.monospace(format!("{:#010X}", cpu.spr.xer.raw()));- ui.allocate_space(egui::vec2(16.0, 0.0));- ui.label("FPSCR");- ui.monospace(format!("{:#010X}", cpu.fpscr));- ui.end_row();- });+pub fn show_cpu(ctx: &Context, open: &mut bool, cpu: &Cpu, mmio: &Mmio, symbols: Option<&SymbolTable>) {+ egui::Window::new("CPU").open(open).show(ctx, |ui| {+ ui.horizontal_top(|ui| {+ ui.vertical(|ui| {+ ui.set_min_width(350.0);+ ui.set_max_width(350.0);+ Grid::new("special_regs").num_columns(5).striped(true).show(ui, |ui| {+ ui.label("PC");+ ui.monospace(format!("{:#010X}", cpu.pc));+ ui.allocate_space(egui::vec2(16.0, 0.0));+ ui.label("CTR");+ ui.monospace(format!("{:#010X}", cpu.spr.ctr));+ ui.end_row();++ ui.label("LR");+ ui.monospace(format!("{:#010X}", cpu.spr.lr));+ ui.allocate_space(egui::vec2(16.0, 0.0));+ ui.label("MSR");+ ui.monospace(format!("{:#010X}", cpu.msr.raw()));+ ui.end_row();++ ui.label("XER");+ ui.monospace(format!("{:#010X}", cpu.spr.xer.raw()));+ ui.allocate_space(egui::vec2(16.0, 0.0));+ ui.label("FPSCR");+ ui.monospace(format!("{:#010X}", cpu.fpscr));+ ui.end_row();+ });- ui.separator();+ ui.separator();- ui.scope(|ui| {- Grid::new("cr_fields")- .num_columns(9)- .spacing([1.0, 1.0])- .striped(true)- .show(ui, |ui| {- ui.label("");+ ui.scope(|ui| {+ Grid::new("cr_fields")+ .num_columns(9)+ .spacing([1.0, 1.0])+ .striped(true)+ .show(ui, |ui| {+ ui.label("");+ for i in 0..8u8 {+ ui.label(format!("CR{i}"));+ }+ ui.end_row();++ for (name, getter) in [+ ("LT", (|i: u8, c: &Cpu| c.cr.get_field(i).lt()) as fn(u8, &Cpu) -> bool),+ ("GT", (|i: u8, c: &Cpu| c.cr.get_field(i).gt()) as fn(u8, &Cpu) -> bool),+ ("EQ", (|i: u8, c: &Cpu| c.cr.get_field(i).eq()) as fn(u8, &Cpu) -> bool),+ ("SO", (|i: u8, c: &Cpu| c.cr.get_field(i).so()) as fn(u8, &Cpu) -> bool),+ ] {+ ui.label(name);for i in 0..8u8 {- ui.label(format!("CR{i}"));+ let mut val = getter(i, cpu);+ ui.add_enabled(false, egui::Checkbox::without_text(&mut val));}ui.end_row();+ }+ });+ });- for (name, getter) in [- ("LT", (|i: u8, c: &Cpu| c.cr.get_field(i).lt()) as fn(u8, &Cpu) -> bool),- ("GT", (|i: u8, c: &Cpu| c.cr.get_field(i).gt()) as fn(u8, &Cpu) -> bool),- ("EQ", (|i: u8, c: &Cpu| c.cr.get_field(i).eq()) as fn(u8, &Cpu) -> bool),- ("SO", (|i: u8, c: &Cpu| c.cr.get_field(i).so()) as fn(u8, &Cpu) -> bool),- ] {- ui.label(name);- for i in 0..8u8 {- let mut val = getter(i, cpu);- ui.add_enabled(false, egui::Checkbox::without_text(&mut val));- }- ui.end_row();- }- });- });-- ui.separator();-- let pc = cpu.pc;- let start = pc.saturating_sub(16 * 4);- let end = pc.saturating_add(16 * 4);+ ui.separator();- ScrollArea::vertical()- .id_salt("disasm_scroll")- .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)- .show(ui, |ui| {- Grid::new("disasm_grid")- .num_columns(4)- .min_col_width(0.0)- .striped(true)- .show(ui, |ui| {- let mut addr = start;- while addr <= end {- let raw = mmio.virt_read_u32(addr);- let text = disasm::gekko::GekkoInstruction::decode(&raw.to_be_bytes())- .map(|(insn, _)| insn.to_string())- .unwrap_or_else(|| format!(".word {:#010X}", raw));-- let is_pc = addr == pc;-- let indicator_resp = if is_pc {- Some(- ui.label(- RichText::new(egui_phosphor::regular::PLAY)- .color(Color32::from_rgb(120, 220, 120)),- ),- )- } else {+ let pc = cpu.pc;+ let start = pc.saturating_sub(16 * 4);+ let end = pc.saturating_add(16 * 4);++ ScrollArea::vertical()+ .id_salt("disasm_scroll")+ .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)+ .show(ui, |ui| {+ Grid::new("disasm_grid")+ .num_columns(4)+ .min_col_width(0.0)+ .striped(true)+ .show(ui, |ui| {+ let mut addr = start;+ while addr <= end {+ // Show function label if this address is a function entry+ if let Some(sym) = symbols.and_then(|s| s.lookup_exact(addr)) {+ if sym.kind == image::symbols::SymbolKind::Func {ui.label("");- None- };-- ui.monospace(format!("{:#010X}", addr));-- ui.label(- RichText::new(format!("{:08X}", raw))- .monospace()- .color(Color32::from_rgb(100, 100, 100)),- );-- let tokens = disasm::tokenizer::tokenize(&text);- ui.horizontal(|ui| {- ui.spacing_mut().item_spacing.x = 0.0;- for token in &tokens {- let mut rt = RichText::new(token.to_string()).monospace();- if let Some(color) = token_color(token) {- rt = rt.color(color);- }- ui.label(rt);- }- });-- ui.end_row();-- if let Some(resp) = indicator_resp {- resp.scroll_to_me(Some(Align::Min));+ ui.label("");+ ui.label("");+ ui.label(+ RichText::new(format!("{}:", sym.name))+ .monospace()+ .color(Color32::from_rgb(220, 180, 80)),+ );+ ui.end_row();}-- addr = addr.wrapping_add(4);}- });- });- });- ui.separator();+ let raw = mmio.virt_read_u32(addr);+ let text = disasm::gekko::GekkoInstruction::decode(&raw.to_be_bytes())+ .map(|(insn, _)| insn.to_string())+ .unwrap_or_else(|| format!(".word {:#010X}", raw));++ let is_pc = addr == pc;++ let indicator_resp = if is_pc {+ Some(+ ui.label(+ RichText::new(egui_phosphor::regular::PLAY)+ .color(Color32::from_rgb(120, 220, 120)),+ ),+ )+ } else {+ ui.label("");+ None+ };++ ui.monospace(format!("{:#010X}", addr));++ ui.label(+ RichText::new(format!("{:08X}", raw))+ .monospace()+ .color(Color32::from_rgb(100, 100, 100)),+ );++ let tokens = disasm::tokenizer::tokenize(&text);+ ui.horizontal(|ui| {+ ui.spacing_mut().item_spacing.x = 0.0;+ for token in &tokens {+ let mut rt = RichText::new(token.to_string()).monospace();+ if let Some(color) = token_color(token) {+ rt = rt.color(color);+ }+ ui.label(rt);+ }+ });- ui.vertical(|ui| {- ui.label("GPRs");- ScrollArea::vertical()- .id_salt("gprs_scroll")- .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)- .show(ui, |ui| {- Grid::new("gprs").num_columns(2).striped(true).show(ui, |ui| {- for (i, &val) in cpu.gprs.iter().enumerate() {- ui.label(format!("r{i:<2}"));- ui.monospace(format!("{:#010X}", val));ui.end_row();- }- });- });- });- ui.separator();+ if let Some(resp) = indicator_resp {+ resp.scroll_to_me(Some(Align::Min));+ }- ui.vertical(|ui| {- ui.label("FPRs");- ScrollArea::vertical()- .id_salt("fprs_scroll")- .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)- .show(ui, |ui| {- Grid::new("fprs").num_columns(2).striped(true).show(ui, |ui| {- for (i, &val) in cpu.fprs.iter().enumerate() {- ui.label(format!("f{i:<2}"));- ui.monospace(format!("{:+.6e}", val));- ui.end_row();+ addr = addr.wrapping_add(4);}});+ });+ });++ ui.separator();++ ui.vertical(|ui| {+ ui.label("GPRs");+ ScrollArea::vertical()+ .id_salt("gprs_scroll")+ .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)+ .show(ui, |ui| {+ Grid::new("gprs").num_columns(2).striped(true).show(ui, |ui| {+ for (i, &val) in cpu.gprs.iter().enumerate() {+ ui.label(format!("r{i:<2}"));+ ui.monospace(format!("{:#010X}", val));+ ui.end_row();+ }});- });+ });+ });++ ui.separator();++ ui.vertical(|ui| {+ ui.label("FPRs");+ ScrollArea::vertical()+ .id_salt("fprs_scroll")+ .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::VisibleWhenNeeded)+ .show(ui, |ui| {+ Grid::new("fprs").num_columns(2).striped(true).show(ui, |ui| {+ for (i, &val) in cpu.fprs.iter().enumerate() {+ ui.label(format!("f{i:<2}"));+ ui.monospace(format!("{:+.6e}", val));+ ui.end_row();+ }+ });+ });});});+ });}diff --git a/crates/dbglib/src/windows/dvd.rs b/crates/dbglib/src/windows/dvd.rsindex 4541d4d..13e7569 100644--- a/crates/dbglib/src/windows/dvd.rs+++ b/crates/dbglib/src/windows/dvd.rs@@ -4,125 +4,122 @@ use gecko::dvd::DvdInterface;use super::flag;pub fn show_dvd(ctx: &Context, open: &mut bool, di: &DvdInterface) {- egui::Window::new("DVD")- .open(open)- .default_size(egui::vec2(350.0, 300.0))- .show(ctx, |ui| {- // Disc info- if let Some(dvd) = &di.dvd {- let game_name = String::from_utf8_lossy(&dvd.header.game_name);- let game_name = game_name.trim_end_matches('\0');- let game_code = String::from_utf8_lossy(&dvd.header.game_code);- let maker_code = String::from_utf8_lossy(&dvd.header.maker_code);-- ui.strong("Disc");- Grid::new("dvd_disc_info").num_columns(2).striped(true).show(ui, |ui| {- ui.label("Game");- ui.monospace(game_name);- ui.end_row();-- ui.label("ID");- ui.monospace(format!("{}{} v{}", game_code, maker_code, dvd.header.version));- ui.end_row();- });- } else {- ui.label("No disc inserted");- }-- ui.separator();-- // Status register- ui.strong("Status (DISR)");- Grid::new("dvd_status").num_columns(4).striped(true).show(ui, |ui| {- ui.label("TCINT");- flag(ui, di.status.transfer_complete());- ui.label("Mask");- flag(ui, di.status.transfer_complete_mask());+ egui::Window::new("DVD").open(open).show(ctx, |ui| {+ // Disc info+ if let Some(dvd) = &di.dvd {+ let game_name = String::from_utf8_lossy(&dvd.header.game_name);+ let game_name = game_name.trim_end_matches('\0');+ let game_code = String::from_utf8_lossy(&dvd.header.game_code);+ let maker_code = String::from_utf8_lossy(&dvd.header.maker_code);++ ui.strong("Disc");+ Grid::new("dvd_disc_info").num_columns(2).striped(true).show(ui, |ui| {+ ui.label("Game");+ ui.monospace(game_name);ui.end_row();- ui.label("DEINT");- flag(ui, di.status.device_error());- ui.label("Mask");- flag(ui, di.status.device_error_mask());- ui.end_row();-- ui.label("BRKINT");- flag(ui, di.status.break_complete());- ui.label("Mask");- flag(ui, di.status.break_complete_mask());- ui.end_row();-- ui.label("BRK");- flag(ui, di.status.brk());- ui.label("");- ui.label("");- ui.end_row();- });-- ui.add_space(4.0);-- // Cover register- ui.strong("Cover (DICVR)");- Grid::new("dvd_cover").num_columns(4).striped(true).show(ui, |ui| {- ui.label("Cover");- flag(ui, di.cover.cover_status());- ui.label("CVRINT");- flag(ui, di.cover.cover_interrupt());- ui.end_row();-- ui.label("Mask");- flag(ui, di.cover.cover_interrupt_mask());- ui.label("");- ui.label("");+ ui.label("ID");+ ui.monospace(format!("{}{} v{}", game_code, maker_code, dvd.header.version));ui.end_row();});+ } else {+ ui.label("No disc inserted");+ }++ ui.separator();++ // Status register+ ui.strong("Status (DISR)");+ Grid::new("dvd_status").num_columns(4).striped(true).show(ui, |ui| {+ ui.label("TCINT");+ flag(ui, di.status.transfer_complete());+ ui.label("Mask");+ flag(ui, di.status.transfer_complete_mask());+ ui.end_row();++ ui.label("DEINT");+ flag(ui, di.status.device_error());+ ui.label("Mask");+ flag(ui, di.status.device_error_mask());+ ui.end_row();++ ui.label("BRKINT");+ flag(ui, di.status.break_complete());+ ui.label("Mask");+ flag(ui, di.status.break_complete_mask());+ ui.end_row();++ ui.label("BRK");+ flag(ui, di.status.brk());+ ui.label("");+ ui.label("");+ ui.end_row();+ });- ui.add_space(4.0);-- // Control register- ui.strong("Control (DICR)");- Grid::new("dvd_control").num_columns(4).striped(true).show(ui, |ui| {- ui.label("TSTART");- flag(ui, di.control.tstart());- ui.label("DMA");- ui.monospace(format!("{:?}", di.control.dma()));- ui.end_row();+ ui.add_space(4.0);++ // Cover register+ ui.strong("Cover (DICVR)");+ Grid::new("dvd_cover").num_columns(4).striped(true).show(ui, |ui| {+ ui.label("Cover");+ flag(ui, di.cover.cover_status());+ ui.label("CVRINT");+ flag(ui, di.cover.cover_interrupt());+ ui.end_row();++ ui.label("Mask");+ flag(ui, di.cover.cover_interrupt_mask());+ ui.label("");+ ui.label("");+ ui.end_row();+ });- ui.label("RW");- ui.monospace(format!("{:?}", di.control.access_mode()));- ui.label("");- ui.label("");- ui.end_row();- });+ ui.add_space(4.0);++ // Control register+ ui.strong("Control (DICR)");+ Grid::new("dvd_control").num_columns(4).striped(true).show(ui, |ui| {+ ui.label("TSTART");+ flag(ui, di.control.tstart());+ ui.label("DMA");+ ui.monospace(format!("{:?}", di.control.dma()));+ ui.end_row();++ ui.label("RW");+ ui.monospace(format!("{:?}", di.control.access_mode()));+ ui.label("");+ ui.label("");+ ui.end_row();+ });- ui.add_space(4.0);+ ui.add_space(4.0);- // Command buffers & DMA- ui.strong("Command / DMA");- Grid::new("dvd_cmd_dma").num_columns(2).striped(true).show(ui, |ui| {- ui.label("CMDBUF0");- ui.monospace(format!("{:#010X}", di.cmdbuf0));- ui.end_row();+ // Command buffers & DMA+ ui.strong("Command / DMA");+ Grid::new("dvd_cmd_dma").num_columns(2).striped(true).show(ui, |ui| {+ ui.label("CMDBUF0");+ ui.monospace(format!("{:#010X}", di.cmdbuf0));+ ui.end_row();- ui.label("CMDBUF1");- ui.monospace(format!("{:#010X}", di.cmdbuf1));- ui.end_row();+ ui.label("CMDBUF1");+ ui.monospace(format!("{:#010X}", di.cmdbuf1));+ ui.end_row();- ui.label("CMDBUF2");- ui.monospace(format!("{:#010X}", di.cmdbuf2));- ui.end_row();+ ui.label("CMDBUF2");+ ui.monospace(format!("{:#010X}", di.cmdbuf2));+ ui.end_row();- ui.label("IMMBUF");- ui.monospace(format!("{:#010X}", di.immbuf));- ui.end_row();+ ui.label("IMMBUF");+ ui.monospace(format!("{:#010X}", di.immbuf));+ ui.end_row();- ui.label("DMA Address");- ui.monospace(format!("{:#010X}", di.dma_address.address()));- ui.end_row();+ ui.label("DMA Address");+ ui.monospace(format!("{:#010X}", di.dma_address.address()));+ ui.end_row();- ui.label("DMA Length");- ui.monospace(format!("{:#010X}", di.dma_length.length()));- ui.end_row();- });+ ui.label("DMA Length");+ ui.monospace(format!("{:#010X}", di.dma_length.length()));+ ui.end_row();});+ });}diff --git a/crates/dbglib/src/windows/exi.rs b/crates/dbglib/src/windows/exi.rsindex 5afbc0a..d3338e8 100644--- a/crates/dbglib/src/windows/exi.rs+++ b/crates/dbglib/src/windows/exi.rs@@ -231,15 +231,12 @@ fn show_channel(ui: &mut egui::Ui, ch: &ChannelInfo) {}pub fn show_exi(ctx: &Context, open: &mut bool, exi: &ExternalInterface) {- egui::Window::new("EXI")- .open(open)- .default_size(egui::vec2(600.0, 400.0))- .show(ctx, |ui| {- ui.columns(3, |cols| {- for (i, col) in cols.iter_mut().enumerate() {- let ch = channel_info(exi, i);- show_channel(col, &ch);- }- });+ egui::Window::new("EXI").open(open).show(ctx, |ui| {+ ui.columns(3, |cols| {+ for (i, col) in cols.iter_mut().enumerate() {+ let ch = channel_info(exi, i);+ show_channel(col, &ch);+ }});+ });}diff --git a/crates/dbglib/src/windows/irq.rs b/crates/dbglib/src/windows/irq.rsindex 4223775..e4e9ea0 100644--- a/crates/dbglib/src/windows/irq.rs+++ b/crates/dbglib/src/windows/irq.rs@@ -34,87 +34,84 @@ fn interrupt_row(ui: &mut egui::Ui, name: &str, pending: bool, masked: bool) {}pub fn show_irq(ctx: &Context, open: &mut bool, cpu: &Cpu, pi: &ProcessorInterface) {- egui::Window::new("IRQ")- .open(open)- .default_size(egui::vec2(380.0, 480.0))- .show(ctx, |ui| {- let msr = &cpu.msr;- let spr = &cpu.spr;- let ee = msr.external_interrupt_enable();+ egui::Window::new("IRQ").open(open).show(ctx, |ui| {+ let msr = &cpu.msr;+ let spr = &cpu.spr;+ let ee = msr.external_interrupt_enable();- // MSR.EE, SRR0/SRR1- Grid::new("top_state").num_columns(2).striped(true).show(ui, |ui| {- ui.label("MSR.EE");- ui.horizontal(|ui| {- let (icon, color) = if ee {- (egui_phosphor::regular::CHECK_CIRCLE, Color32::from_rgb(80, 220, 80))- } else {- (egui_phosphor::regular::X_CIRCLE, Color32::from_rgb(200, 60, 60))- };- ui.label(RichText::new(icon).color(color));- ui.label(if ee {- "interrupts enabled"- } else {- "interrupts disabled"- });+ // MSR.EE, SRR0/SRR1+ Grid::new("top_state").num_columns(2).striped(true).show(ui, |ui| {+ ui.label("MSR.EE");+ ui.horizontal(|ui| {+ let (icon, color) = if ee {+ (egui_phosphor::regular::CHECK_CIRCLE, Color32::from_rgb(80, 220, 80))+ } else {+ (egui_phosphor::regular::X_CIRCLE, Color32::from_rgb(200, 60, 60))+ };+ ui.label(RichText::new(icon).color(color));+ ui.label(if ee {+ "interrupts enabled"+ } else {+ "interrupts disabled"});- ui.end_row();-- ui.label("SRR0");- ui.monospace(format!("{:#010X}", spr.srr0.raw()));- ui.end_row();-- ui.label("SRR1");- ui.monospace(format!("{:#010X}", spr.srr1));- ui.end_row();});+ ui.end_row();- ui.add_space(8.0);+ ui.label("SRR0");+ ui.monospace(format!("{:#010X}", spr.srr0.raw()));+ ui.end_row();- // PI Table- ui.strong("PI Interrupts");- ui.separator();+ ui.label("SRR1");+ ui.monospace(format!("{:#010X}", spr.srr1));+ ui.end_row();+ });- Grid::new("pi_ints")- .num_columns(3)- .striped(true)- .min_col_width(0.0)- .show(ui, |ui| {- ui.label(RichText::new("Source").strong());- ui.label(RichText::new("Pending").strong());- ui.label(RichText::new("Masked").strong());- ui.end_row();+ ui.add_space(8.0);- let sr = &pi.intsr;- let mr = &pi.intmr;+ // PI Table+ ui.strong("PI Interrupts");+ ui.separator();- interrupt_row(ui, "GP Error", sr.gp_runtime_error(), mr.gp_runtime_error());- interrupt_row(ui, "Reset Switch", sr.reset_switch(), mr.reset_switch());- interrupt_row(ui, "DVD", sr.dvd(), mr.dvd());- interrupt_row(ui, "Serial", sr.serial(), mr.serial());- interrupt_row(ui, "EXI", sr.exi(), mr.exi());- interrupt_row(ui, "Streaming", sr.streaming(), mr.streaming());- interrupt_row(ui, "DSP", sr.dsp(), mr.dsp());- interrupt_row(ui, "Memory", sr.memory(), mr.memory());- interrupt_row(ui, "Video", sr.video(), mr.video());- interrupt_row(- ui,- "PE Token",- sr.token_assertion_in_cmd_list(),- mr.token_assertion_in_cmd_list(),- );- interrupt_row(ui, "PE Finish", sr.frame_is_ready(), mr.frame_is_ready());- interrupt_row(ui, "Cmd FIFO", sr.command_fifo(), mr.command_fifo());- interrupt_row(ui, "Debug", sr.debug(), mr.debug());- interrupt_row(ui, "Hi-Speed Port", sr.highspeed_port(), mr.highspeed_port());- });+ Grid::new("pi_ints")+ .num_columns(3)+ .striped(true)+ .min_col_width(0.0)+ .show(ui, |ui| {+ ui.label(RichText::new("Source").strong());+ ui.label(RichText::new("Pending").strong());+ ui.label(RichText::new("Masked").strong());+ ui.end_row();- ui.horizontal(|ui| {- ui.label("INTSR");- ui.monospace(format!("{:#010X}", pi.intsr.raw()));- ui.add_space(12.0);- ui.label("INTMR");- ui.monospace(format!("{:#010X}", pi.intmr.raw()));+ let sr = &pi.intsr;+ let mr = &pi.intmr;++ interrupt_row(ui, "GP Error", sr.gp_runtime_error(), mr.gp_runtime_error());+ interrupt_row(ui, "Reset Switch", sr.reset_switch(), mr.reset_switch());+ interrupt_row(ui, "DVD", sr.dvd(), mr.dvd());+ interrupt_row(ui, "Serial", sr.serial(), mr.serial());+ interrupt_row(ui, "EXI", sr.exi(), mr.exi());+ interrupt_row(ui, "Streaming", sr.streaming(), mr.streaming());+ interrupt_row(ui, "DSP", sr.dsp(), mr.dsp());+ interrupt_row(ui, "Memory", sr.memory(), mr.memory());+ interrupt_row(ui, "Video", sr.video(), mr.video());+ interrupt_row(+ ui,+ "PE Token",+ sr.token_assertion_in_cmd_list(),+ mr.token_assertion_in_cmd_list(),+ );+ interrupt_row(ui, "PE Finish", sr.frame_is_ready(), mr.frame_is_ready());+ interrupt_row(ui, "Cmd FIFO", sr.command_fifo(), mr.command_fifo());+ interrupt_row(ui, "Debug", sr.debug(), mr.debug());+ interrupt_row(ui, "Hi-Speed Port", sr.highspeed_port(), mr.highspeed_port());});++ ui.horizontal(|ui| {+ ui.label("INTSR");+ ui.monospace(format!("{:#010X}", pi.intsr.raw()));+ ui.add_space(12.0);+ ui.label("INTMR");+ ui.monospace(format!("{:#010X}", pi.intmr.raw()));});+ });}diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rsindex 6671535..8ee410b 100644--- a/crates/debugger/src/debugger.rs+++ b/crates/debugger/src/debugger.rs@@ -2,11 +2,13 @@ use std::fs::File;use std::io::BufWriter;use dbglib::Debugger;+use image::symbols::SymbolTable;const TRACE_FILENAME: &str = "trace.log";pub struct DebuggerUi {pub debugger: Debugger,+ pub symbols: Option<SymbolTable>,pub show_cpu: bool,pub show_dsp: bool,pub show_gx_state: bool,@@ -15,6 +17,7 @@ pub struct DebuggerUi {pub show_exi: bool,pub show_irqs: bool,pub show_controls: bool,+ pub show_callstack: bool,pub memory_base: u32,pub memory_addr_input: String,pub run_until_addr_input: String,@@ -25,6 +28,7 @@ impl Default for DebuggerUi {fn default() -> Self {DebuggerUi {debugger: Debugger::new(),+ symbols: None,show_cpu: true,show_dsp: false,show_controls: true,@@ -33,6 +37,7 @@ impl Default for DebuggerUi {show_dvd: false,show_exi: false,show_irqs: false,+ show_callstack: false,memory_base: 0x8000_0000,memory_addr_input: "80000000".to_string(),run_until_addr_input: String::new(),diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rsindex 19fa1a5..a651b11 100644--- a/crates/debugger/src/main.rs+++ b/crates/debugger/src/main.rs@@ -74,9 +74,9 @@ impl ApplicationHandler for App {#[derive(Parser)]#[command(about = "GameCube debugger")]struct Args {- /// Path to the ROM/DOL file+ /// Path to the DOL file#[arg(long)]- rom: Option<String>,+ dol: Option<String>,/// Path to an IPL file#[arg(long)]@@ -94,6 +94,10 @@ struct Args {#[arg(long)]dsp: Option<String>,+ /// Path to a companion ELF file for symbol names+ #[arg(long)]+ elf: Option<String>,+/// Path to a Lua script for scripting hooks#[arg(long)]script: Option<String>,@@ -119,12 +123,12 @@ fn main() {let mut emulator = if let Some(ref ipl) = args.ipl {let ipl_data = std::fs::read(ipl).expect("failed to read IPL");GameCube::with_ipl(&ipl_data)- } else if let Some(ref rom) = args.rom {- let rom_data = std::fs::read(rom).expect("failed to read ROM");- let dol = Dol::parse(rom_data);+ } else if let Some(ref path) = args.dol {+ let dol_data = std::fs::read(path).expect("failed to read DOL");+ let dol = Dol::parse(dol_data);GameCube::with_image(&dol)} else {- eprintln!("error: either --ipl or --rom must be provided");+ eprintln!("error: either --ipl or --dol must be provided");std::process::exit(1);};@@ -149,15 +153,25 @@ fn main() {emulator.set_script_host(Box::new(host));}+ let symbols = args.elf.as_ref().map(|path| {+ let elf_data = std::fs::read(path).expect("failed to read ELF file");+ image::elf::parse_elf_symbols(&elf_data).expect("failed to parse ELF symbols")+ });+emulator.add_primary_controller(PadStatus {connected: true,..PadStatus::default()});+ let ui = DebuggerUi {+ symbols,+ ..DebuggerUi::default()+ };+let event_loop = EventLoop::new().unwrap();let mut app = App {emulator,- ui: DebuggerUi::default(),+ ui,window: None,state: None,present_mode,diff --git a/crates/debugger/src/render.rs b/crates/debugger/src/render.rsindex bd40bed..6bbe418 100644--- a/crates/debugger/src/render.rs+++ b/crates/debugger/src/render.rs@@ -246,6 +246,7 @@ impl RenderState {ui.menu_button("Windows", |ui| {ui.checkbox(&mut debugger_ui.show_cpu, "CPU");+ ui.checkbox(&mut debugger_ui.show_callstack, "Call Stack");ui.checkbox(&mut debugger_ui.show_dsp, "DSP");ui.checkbox(&mut debugger_ui.show_gx_state, "GX");ui.checkbox(&mut debugger_ui.show_mmio, "MMIO");@@ -258,7 +259,22 @@ impl RenderState {});if debugger_ui.show_cpu {- dbglib::windows::cpu::show_cpu(&ctx, &mut debugger_ui.show_cpu, cpu, mmio);+ dbglib::windows::cpu::show_cpu(+ &ctx,+ &mut debugger_ui.show_cpu,+ cpu,+ mmio,+ debugger_ui.symbols.as_ref(),+ );+ }+ if debugger_ui.show_callstack {+ dbglib::windows::callstack::show_callstack(+ &ctx,+ &mut debugger_ui.show_callstack,+ cpu,+ mmio,+ debugger_ui.symbols.as_ref(),+ );}if debugger_ui.show_dsp {dbglib::windows::dsp::show_dsp(&ctx, &mut debugger_ui.show_dsp, &emulator.dsp);diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rsindex 6c68b0b..dcbf436 100644--- a/crates/tinyapp/src/main.rs+++ b/crates/tinyapp/src/main.rs@@ -477,9 +477,9 @@ impl ApplicationHandler for App {#[derive(Parser)]#[command(about = "GameCube emulator")]struct Args {- /// Path to the ROM/DOL file+ /// Path to the DOL file#[arg(long)]- rom: Option<String>,+ dol: Option<String>,/// Path to an IPL file#[arg(long)]@@ -528,12 +528,12 @@ fn main() {let mut emulator = if let Some(ref ipl) = args.ipl {let ipl_data = std::fs::read(ipl).expect("failed to read IPL");GameCube::with_ipl(&ipl_data)- } else if let Some(ref rom) = args.rom {- let rom_data = std::fs::read(rom).expect("failed to read ROM");- let dol = Dol::parse(rom_data);+ } else if let Some(ref path) = args.dol {+ let dol_data = std::fs::read(path).expect("failed to read DOL");+ let dol = Dol::parse(dol_data);GameCube::with_image(&dol)} else {- eprintln!("error: either --ipl or --rom must be provided");+ eprintln!("error: either --ipl or --dol must be provided");std::process::exit(1);};diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rsindex 727d1f5..970f7d7 100644--- a/crates/tinyemu/src/main.rs+++ b/crates/tinyemu/src/main.rs@@ -11,9 +11,9 @@ use snaptshot::CpuSnapshot;#[derive(Parser)]#[command(about = "GameCube emulator")]struct Args {- /// Path to the ROM/DOL file+ /// Path to the DOL file#[arg(long)]- rom: Option<String>,+ dol: Option<String>,/// Path to an IPL file#[arg(long)]@@ -69,15 +69,15 @@ fn main() {).init();- let mut emulator = if let Some(rom_path) = &args.rom {- let rom_data = std::fs::read(rom_path).expect("failed to read ROM");- let dol = image::Dol::parse(rom_data);+ let mut emulator = if let Some(dol_path) = &args.dol {+ let dol_data = std::fs::read(dol_path).expect("failed to read DOL");+ let dol = image::Dol::parse(dol_data);gecko::gamecube::GameCube::with_image(&dol)} else if let Some(ipl_path) = &args.ipl {let ipl_data = std::fs::read(ipl_path).expect("failed to read IPL");gecko::gamecube::GameCube::with_ipl(&ipl_data)} else {- panic!("Either --rom or --ipl must be provided");+ panic!("Either --dol or --ipl must be provided");};if let Some(iso_path) = &args.iso {diff --git a/crates/web/src/debug_ui.rs b/crates/web/src/debug_ui.rsindex aae306c..ca71a20 100644--- a/crates/web/src/debug_ui.rs+++ b/crates/web/src/debug_ui.rs@@ -1,8 +1,10 @@use dbglib::{Debugger, EmulatorState};use gecko::gamecube::GameCube;+use image::symbols::SymbolTable;pub struct DebugState {pub debugger: Debugger,+ pub symbols: Option<SymbolTable>,pub show_cpu: bool,pub show_dsp: bool,pub show_gx_state: bool,@@ -11,6 +13,7 @@ pub struct DebugState {pub show_exi: bool,pub show_irqs: bool,pub show_controls: bool,+ pub show_callstack: bool,pub memory_base: u32,pub memory_addr_input: String,pub run_until_addr_input: String,@@ -23,6 +26,7 @@ impl Default for DebugState {debugger.set_state(EmulatorState::Running);DebugState {debugger,+ symbols: None,show_cpu: false,show_dsp: false,show_controls: true,@@ -31,6 +35,7 @@ impl Default for DebugState {show_dvd: false,show_exi: false,show_irqs: false,+ show_callstack: false,memory_base: 0x8000_0000,memory_addr_input: "80000000".to_string(),run_until_addr_input: String::new(),@@ -60,6 +65,7 @@ impl DebugState {ui.horizontal(|ui| {ui.checkbox(&mut self.show_controls, "Controls");ui.checkbox(&mut self.show_cpu, "CPU");+ ui.checkbox(&mut self.show_callstack, "Call Stack");ui.checkbox(&mut self.show_dsp, "DSP");ui.checkbox(&mut self.show_gx_state, "GX");ui.checkbox(&mut self.show_mmio, "MMIO");@@ -70,7 +76,22 @@ impl DebugState {});if self.show_cpu {- dbglib::windows::cpu::show_cpu(ctx, &mut self.show_cpu, &emulator.cpu, &emulator.mmio);+ dbglib::windows::cpu::show_cpu(+ ctx,+ &mut self.show_cpu,+ &emulator.cpu,+ &emulator.mmio,+ self.symbols.as_ref(),+ );+ }+ if self.show_callstack {+ dbglib::windows::callstack::show_callstack(+ ctx,+ &mut self.show_callstack,+ &emulator.cpu,+ &emulator.mmio,+ self.symbols.as_ref(),+ );}if self.show_dsp {dbglib::windows::dsp::show_dsp(ctx, &mut self.show_dsp, &emulator.dsp);diff --git a/submodules/lilyskategc b/submodules/lilyskategcnew file mode 160000index 0000000..85ee77c--- /dev/null+++ b/submodules/lilyskategc@@ -0,0 +1 @@+Subproject commit 85ee77ccf987d9368cf03bc6a3fc899f7b7914f4