Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

wii dsp dispatcher + fix github ci actions to accomodate new chipi syntax

Layledfa6d586f117
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 003a3a5..1f7ce97 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -44,9 +44,9 @@ jobs:
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ matrix.target }}-
- - name: Patch chipi.toml dispatch mode
+ - name: Patch chipi dispatch strategy
shell: bash
- run: sed -i 's/dispatch = "fn_ptr_lut"/dispatch = "jump_table"/g' crates/gecko/chipi.toml
+ run: sed -i 's/strategy fn_ptr_lut/strategy jump_table/g' crates/gecko/*.bindings.chipi
- name: Install Linux dependencies
if: runner.os == 'Linux'
diff --git a/crates/gecko/build.rs b/crates/gecko/build.rs
index 4e343e5..8df98a1 100644
--- a/crates/gecko/build.rs
+++ b/crates/gecko/build.rs
@@ -1,5 +1,6 @@
fn main() {
chipi_build::generate_bindings("gekko.bindings.chipi").expect("chipi codegen failed (gekko)");
- chipi_build::generate_bindings("wii.bindings.chipi").expect("chipi codegen failed (wii)");
chipi_build::generate_bindings("dsp.bindings.chipi").expect("chipi codegen failed (dsp)");
+ chipi_build::generate_bindings("wii_gekko.bindings.chipi").expect("chipi codegen failed (wii gekko)");
+ chipi_build::generate_bindings("wii_dsp.bindings.chipi").expect("chipi codegen failed (wii dsp)");
}
diff --git a/crates/gecko/dsp.bindings.chipi b/crates/gecko/dsp.bindings.chipi
index 66aae78..a32436c 100644
--- a/crates/gecko/dsp.bindings.chipi
+++ b/crates/gecko/dsp.bindings.chipi
@@ -6,6 +6,7 @@ target rust {
context crate::gamecube::GameCube
handlers crate::flipper::dsp::interpreter
+ handler_const crate::system::GC
strategy fn_ptr_lut
invalid_handler crate::flipper::dsp::interpreter::invalid
diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rs
index 9b4b16b..810eb1e 100644
--- a/crates/gecko/src/flipper/dsp.rs
+++ b/crates/gecko/src/flipper/dsp.rs
@@ -11,9 +11,14 @@ pub mod lut {
include!(concat!(env!("OUT_DIR"), "/dsp_lut.rs"));
}
+#[allow(dead_code, unused_variables, non_upper_case_globals, clippy::all)]
+pub mod lut_wii {
+ include!(concat!(env!("OUT_DIR"), "/dsp_lut_wii.rs"));
+}
+
use crate::flipper::dsp::instruction::Instruction;
use crate::mmio::Mmio;
-use crate::system::{GC, System, SystemId};
+use crate::system::{System, SystemId};
pub struct Dsp {
// Registers
@@ -405,20 +410,22 @@ fn write_word(mem: &mut [u8], word_addr: u16, value: u16) {
#[inline(always)]
pub fn dispatch<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
- if SYSTEM == GC {
- let ctx: &mut System<{ GC }> = unsafe { ::core::mem::transmute(ctx) };
+ if SYSTEM == crate::system::GC {
+ let ctx: &mut crate::gamecube::GameCube = unsafe { ::core::mem::transmute(ctx) };
self::lut::dispatch(ctx, instr);
} else {
- todo!()
+ let ctx: &mut crate::wii::Wii = unsafe { ::core::mem::transmute(ctx) };
+ self::lut_wii::dispatch(ctx, instr);
}
}
#[inline(always)]
pub fn dispatch_gc_dsp_ext<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: instruction::GcDspExt) {
- if SYSTEM == GC {
- let ctx: &mut System<{ GC }> = unsafe { ::core::mem::transmute(ctx) };
+ if SYSTEM == crate::system::GC {
+ let ctx: &mut crate::gamecube::GameCube = unsafe { ::core::mem::transmute(ctx) };
self::lut::dispatch_gc_dsp_ext(ctx, instr);
} else {
- todo!()
+ let ctx: &mut crate::wii::Wii = unsafe { ::core::mem::transmute(ctx) };
+ self::lut_wii::dispatch_gc_dsp_ext(ctx, instr);
}
}
diff --git a/crates/gecko/src/flipper/dsp/interpreter.rs b/crates/gecko/src/flipper/dsp/interpreter.rs
index dd5e343..c3ca4a0 100644
--- a/crates/gecko/src/flipper/dsp/interpreter.rs
+++ b/crates/gecko/src/flipper/dsp/interpreter.rs
@@ -4,16 +4,17 @@ use crate::flipper::dsp::core::regs::{SignExtensionMode, StatusRegister};
use crate::flipper::dsp::core::{Registers, reg};
use crate::flipper::dsp::instruction::{GcDspExt, Instruction};
use crate::flipper::dsp::lut::*;
+use crate::system::{System, SystemId};
#[cold]
#[inline(never)]
-pub fn invalid(_ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn invalid<const SYSTEM: SystemId>(_ctx: &mut System<SYSTEM>, instr: Instruction) {
panic!("unimplemented DSP opcode {:#06x}", instr.0);
}
#[cold]
#[inline(never)]
-pub fn invalid_ext(_ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn invalid_ext<const SYSTEM: SystemId>(_ctx: &mut System<SYSTEM>, instr: GcDspExt) {
panic!("unimplemented DSP ext opcode {:#04x}", instr.0);
}
@@ -96,7 +97,7 @@ fn apply_combined_add_product_oc(regs: &mut Registers, pc: bool, po: bool, os_be
}
#[inline(always)]
-fn move_prod_to_ac(ctx: &mut crate::gamecube::GameCube, r: u8) {
+fn move_prod_to_ac<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, r: u8) {
let prod = ctx.dsp.registers.product();
let (carry, overflow) = ctx.dsp.registers.product_flags();
ctx.dsp.registers.set_ac(r, prod);
@@ -105,7 +106,7 @@ fn move_prod_to_ac(ctx: &mut crate::gamecube::GameCube, r: u8) {
}
#[inline(always)]
-fn move_prod_to_ac_zero(ctx: &mut crate::gamecube::GameCube, r: u8) {
+fn move_prod_to_ac_zero<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, r: u8) {
let (carry, overflow) = ctx.dsp.registers.product_flags();
let raw = ctx.dsp.registers.product();
let (prod, rounding_carry) = round_half_to_even(raw);
@@ -115,7 +116,7 @@ fn move_prod_to_ac_zero(ctx: &mut crate::gamecube::GameCube, r: u8) {
}
#[inline(always)]
-fn add_prod_to_ac(ctx: &mut crate::gamecube::GameCube, r: u8) {
+fn add_prod_to_ac<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, r: u8) {
let a = ctx.dsp.registers.ac(r);
let (pc, po) = ctx.dsp.registers.product_flags();
let b = ctx.dsp.registers.product();
@@ -192,7 +193,7 @@ fn mulc_operands(regs: &Registers, s: u8, t: u8) -> (i16, i16) {
}
#[inline(always)]
-pub fn add_sub<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn add_sub<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_ADDR => {
let ss = instr.ss() as usize;
@@ -303,7 +304,7 @@ pub fn add_sub<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instru
}
#[inline(always)]
-pub fn addr_reg<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn addr_reg<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_DAR => {
let d = instr.d_14_15() as usize;
@@ -329,7 +330,7 @@ pub fn addr_reg<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instr
}
#[inline(always)]
-pub fn cmp_test<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn cmp_test<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_CMP => {
let a = ctx.dsp.registers.ac(0);
@@ -401,7 +402,7 @@ pub fn cmp_test<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instr
}
#[inline(always)]
-pub fn control<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn control<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_JCC => {
let branch_control = BranchControl::from(instr.cond());
@@ -457,7 +458,7 @@ pub fn control<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instru
}
#[inline(always)]
-pub fn imm_alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn imm_alu<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_ADDI => {
let d = instr.d_7_7();
@@ -536,7 +537,7 @@ pub fn imm_alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instru
}
#[inline(always)]
-pub fn inc_dec<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn inc_dec<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_INCM => {
let d = instr.d_7_7();
@@ -594,7 +595,7 @@ pub fn inc_dec<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instru
}
#[inline(always)]
-pub fn load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn load_store<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_LRI => {
ctx.dsp.registers.write::<true>(instr.d_11_15(), instr.imm_16_31());
@@ -699,7 +700,7 @@ pub fn load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Ins
}
#[inline(always)]
-pub fn logic<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn logic<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_XORR => {
let s = instr.s_6_6() as usize;
@@ -772,7 +773,7 @@ pub fn logic<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruct
}
#[inline(always)]
-pub fn loops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn loops<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_LOOP_REG | OP_LOOPI => {
let counter = match OP {
@@ -809,7 +810,7 @@ pub fn loops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruct
}
#[inline(always)]
-pub fn move_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn move_ops<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_MOVR => {
let ss = instr.ss();
@@ -864,7 +865,7 @@ pub fn move_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instr
}
#[inline(always)]
-pub fn mul<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn mul<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_MUL => {
let s = instr.r_4_4() as usize;
@@ -961,7 +962,7 @@ pub fn mul<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instructio
}
#[inline(always)]
-pub fn shifts<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn shifts<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_LSL | OP_ASL => {
let r = instr.r_7_7();
@@ -1059,7 +1060,7 @@ pub fn shifts<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruc
}
#[inline(always)]
-pub fn status<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
+pub fn status<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
match OP {
OP_SBCLR => {
let idx = 6 + instr.bit();
@@ -1097,10 +1098,10 @@ pub fn status<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruc
// Extension opcode handlers
#[inline(always)]
-pub fn ext_nop(_ctx: &mut crate::gamecube::GameCube, _instr: GcDspExt) {}
+pub fn ext_nop<const SYSTEM: SystemId>(_ctx: &mut System<SYSTEM>, _instr: GcDspExt) {}
#[inline(always)]
-pub fn ext_addr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_addr<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let r = instr.r_6_7() as usize;
match OP {
OP_EXT_DR => ctx.dsp.registers.ar[r] = ctx.dsp.registers.decrement_ar(r),
@@ -1114,7 +1115,7 @@ pub fn ext_addr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDsp
}
#[inline(always)]
-pub fn ext_mv(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_mv<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let d = instr.d_4_5();
let s = instr.s_6_7();
let value = ctx.dsp.registers.ext_ac_cache[s as usize];
@@ -1122,7 +1123,7 @@ pub fn ext_mv(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_store<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let d = instr.d_6_7() as usize;
let s = instr.s_3_4();
let value = ctx.dsp.registers.ext_ac_cache[s as usize];
@@ -1141,7 +1142,7 @@ pub fn ext_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDs
}
#[inline(always)]
-pub fn ext_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_load<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let d = instr.d_2_4();
let s = instr.s_6_7() as usize;
let addr = ctx.dsp.registers.ar[s];
@@ -1160,7 +1161,7 @@ pub fn ext_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDsp
}
#[inline(always)]
-pub fn ext_load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_load_store<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let s = instr.s_7_7() as usize;
let d = instr.d_2_3();
@@ -1215,7 +1216,7 @@ pub fn ext_load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr:
}
#[inline(always)]
-pub fn ext_ld<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_ld<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let d = instr.d_2_2();
let r = instr.r_3_3();
let s = instr.s_6_7() as usize;
@@ -1258,7 +1259,7 @@ pub fn ext_ld<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspEx
}
#[inline(always)]
-pub fn ext_ldax<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
+pub fn ext_ldax<const OP: u32, const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: GcDspExt) {
let s = instr.d_2_2() as usize;
let r = instr.r_3_3() as usize;
diff --git a/crates/gecko/wii_dsp.bindings.chipi b/crates/gecko/wii_dsp.bindings.chipi
new file mode 100644
index 0000000..281612a
--- /dev/null
+++ b/crates/gecko/wii_dsp.bindings.chipi
@@ -0,0 +1,232 @@
+include "../../submodules/chipi-spec/gamecube/dsp.chipi"
+
+target rust {
+ dispatch GcDsp {
+ output "$OUT_DIR/dsp_lut_wii.rs"
+
+ context crate::wii::Wii
+ handlers crate::flipper::dsp::interpreter
+ handler_const crate::system::WII
+ strategy fn_ptr_lut
+
+ invalid_handler crate::flipper::dsp::interpreter::invalid
+
+ instruction_type crate::flipper::dsp::instruction::Instruction {
+ output "$OUT_DIR/dsp_instr_wii.rs"
+ }
+
+ handler control {
+ nop
+ halt
+ ifcc
+ jcc
+ callcc
+ retcc
+ rticc
+ jrcc
+ callrcc
+ }
+
+ handler loops {
+ loop_reg
+ bloop
+ loopi
+ bloopi
+ }
+
+ handler addr_reg {
+ dar
+ iar
+ subarn
+ addarn
+ }
+
+ handler load_store {
+ lri
+ lr
+ sr
+ mrr
+ si
+ lrr
+ lrrd
+ lrri
+ lrrn
+ srr
+ srrd
+ srri
+ srrn
+ lrs
+ srsh
+ srs
+ ilrr
+ ilrrd
+ ilrri
+ ilrrn
+ }
+
+ handler imm_alu {
+ addi
+ xori
+ andi
+ ori
+ cmpi
+ andf
+ andcf
+ addis
+ cmpis
+ lris
+ }
+
+ handler add_sub {
+ addr
+ addax
+ add
+ addp
+ subr
+ subax
+ sub
+ subp
+ addaxl
+ addpaxz
+ }
+
+ handler move_ops {
+ movr
+ movax
+ mov
+ movp
+ movpz
+ movnp
+ }
+
+ handler inc_dec {
+ incm
+ inc
+ decm
+ dec
+ neg
+ abs_ac
+ }
+
+ handler cmp_test {
+ cmp
+ cmpaxh
+ tst
+ tstprod
+ tstaxh
+ nx_0
+ nx_1
+ clr
+ clrp
+ clrl
+ }
+
+ handler logic {
+ xorr
+ andr
+ orr
+ andc
+ orc
+ xorc
+ not_ac
+ }
+
+ handler shifts {
+ lsl
+ lsr
+ asl
+ asr
+ lsl16
+ lsr16
+ asr16
+ lsrn
+ asrn
+ lsrnrx
+ asrnrx
+ lsrnr
+ asrnr
+ }
+
+ handler status {
+ sbclr
+ sbset
+ m2
+ m0
+ clr15
+ set15
+ set16
+ set40
+ }
+
+ handler mul {
+ mul
+ mulx
+ mulc
+ mulaxh
+ mulmv
+ mulmvz
+ mulac
+ mulxmv
+ mulxmvz
+ mulxac
+ mulcmv
+ mulcmvz
+ mulcac
+ madd
+ msub
+ maddx
+ msubx
+ maddc
+ msubc
+ }
+
+ subdispatch GcDspExt {
+ invalid_handler crate::flipper::dsp::interpreter::invalid_ext
+
+ instruction_type crate::flipper::dsp::instruction::GcDspExt {
+ output "$OUT_DIR/dsp_ext_instr_wii.rs"
+ }
+
+ handler ext_addr {
+ ext_dr
+ ext_ir
+ ext_nr
+ }
+
+ handler ext_load {
+ ext_l
+ ext_ln
+ }
+
+ handler ext_store {
+ ext_s
+ ext_sn
+ }
+
+ handler ext_load_store {
+ ext_ls
+ ext_sl
+ ext_lsn
+ ext_sln
+ ext_lsm
+ ext_slm
+ ext_lsnm
+ ext_slnm
+ }
+
+ handler ext_ld {
+ ext_ld_00
+ ext_ldn_01
+ ext_ldm_10
+ ext_ldnm_11
+ }
+
+ handler ext_ldax {
+ ext_ldax
+ ext_ldaxn
+ ext_ldaxm
+ ext_ldaxnm
+ }
+ }
+ }
+}
diff --git a/crates/gecko/wii.bindings.chipi b/crates/gecko/wii_gekko.bindings.chipi
similarity index 100%
rename from crates/gecko/wii.bindings.chipi
rename to crates/gecko/wii_gekko.bindings.chipi