Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

segment register skeleton

Layle7e54b65d1cea
diff --git a/crates/disasm/src/tokenizer.rs b/crates/disasm/src/tokenizer.rs
index b5b247f..61cab57 100644
--- a/crates/disasm/src/tokenizer.rs
+++ b/crates/disasm/src/tokenizer.rs
@@ -40,8 +40,10 @@ static SPR_NAMES: &[&str] = &[
"xer", "lr", "ctr", "dsisr", "dar", "dec", "sdr1", "srr0", "srr1", "sprg0", "sprg1", "sprg2",
"sprg3", "ear", "pvr", "ibat0u", "ibat0l", "ibat1u", "ibat1l", "ibat2u", "ibat2l", "ibat3u",
"ibat3l", "dbat0u", "dbat0l", "dbat1u", "dbat1l", "dbat2u", "dbat2l", "dbat3u", "dbat3l",
- "hid0", "hid1", "hid2", "iabr", "dabr", "gqr0", "gqr1", "gqr2", "gqr3", "gqr4", "gqr5", "gqr6",
- "gqr7", "dmau", "dmal", "cr",
+ "gqr0", "gqr1", "gqr2", "gqr3", "gqr4", "gqr5", "gqr6", "gqr7", "hid0", "hid1", "hid2", "wpar",
+ "dmau", "dmal", "ummcr0", "upmc1", "upmc2", "usia", "ummcr1", "upmc3", "upmc4", "usda",
+ "mmcr0", "pmc1", "pmc2", "sia", "mmcr1", "pmc3", "pmc4", "sda", "l2cr", "ictc", "thrm1",
+ "thrm2", "thrm3", "iabr", "dabr", "cr",
];
static SPR_MNEMONICS: &[&str] = &["mfspr", "mtspr", "mftb", "mftbu"];
diff --git a/crates/gekko/build.rs b/crates/gekko/build.rs
index a9b4724..9cae594 100644
--- a/crates/gekko/build.rs
+++ b/crates/gekko/build.rs
@@ -15,8 +15,10 @@ fn main() {
.group("rotate", ["rlwinmx"])
.group("msr", ["mtmsr", "mfmsr", "rfi"])
.group("spr", ["mtspr", "mfspr"])
+ .group("segment", ["mtsr", "mfsr"])
.group("store_load", ["stw", "stwu", "sth", "sthu", "lwz", "lwzu"])
- .group("compare", ["cmp", "cmpi"]);
+ .group("compare", ["cmp", "cmpi"])
+ .group("nop", ["isync", "sync"]); // instructions that we can treat as no-ops
// Generate the instruction type with accessor methods
builder
diff --git a/crates/gekko/src/cpu.rs b/crates/gekko/src/cpu.rs
index 641df4c..73dd23f 100644
--- a/crates/gekko/src/cpu.rs
+++ b/crates/gekko/src/cpu.rs
@@ -1,8 +1,9 @@
+pub mod condition;
pub mod interpreter;
+pub mod msr;
pub mod semantics;
-pub mod condition;
pub mod spr;
-pub mod msr;
+pub mod sr;
use crate::cpu::condition::ConditionRegister;
@@ -16,8 +17,10 @@ pub struct Cpu {
pub fprs: [f64; 32],
pub pc: u32,
pub cr: ConditionRegister,
+ pub fpscr: u32, // TODO: FP Status and Control Register
pub spr: spr::Spr,
pub msr: msr::Msr,
+ pub sr: [sr::Sr; 16], // Segment Registers
// These are used during instruction execution to track the current
// and next PC values. In essence, by writing to `next_pc`, instructions
// can change the flow of execution (e.g. for branches and jumps).
@@ -36,6 +39,8 @@ impl Cpu {
cr: ConditionRegister::new(),
spr: spr::Spr::default(),
msr: msr::Msr::default(),
+ fpscr: 0,
+ sr: [sr::Sr::default(); 16],
}
}
diff --git a/crates/gekko/src/cpu/interpreter.rs b/crates/gekko/src/cpu/interpreter.rs
index 88f89df..a1fcef1 100644
--- a/crates/gekko/src/cpu/interpreter.rs
+++ b/crates/gekko/src/cpu/interpreter.rs
@@ -1,4 +1,7 @@
-use crate::cpu::condition::{BranchControl, ConditionField};
+use crate::cpu::{
+ condition::{BranchControl, ConditionField},
+ sr::Sr,
+};
pub fn branch<const OP: u32>(
ctx: &mut crate::gekko::Gekko,
@@ -172,6 +175,21 @@ pub fn spr<const OP: u32>(
}
}
+pub fn segment<const OP: u32>(
+ ctx: &mut crate::gekko::Gekko,
+ instr: crate::cpu::semantics::Instruction,
+) {
+ match OP {
+ crate::cpu::lut::OP_MTSR => {
+ ctx.cpu.sr[instr.sr() as usize] = Sr::from_raw(ctx.cpu.read_gpr(instr.rs()))
+ }
+ crate::cpu::lut::OP_MFSR => ctx
+ .cpu
+ .write_gpr(instr.rd(), ctx.cpu.sr[instr.sr() as usize].raw()),
+ _ => todo!("Segment Register instruction with OP = {OP:#x}"),
+ }
+}
+
pub fn store_load<const OP: u32>(
ctx: &mut crate::gekko::Gekko,
instr: crate::cpu::semantics::Instruction,
@@ -235,6 +253,13 @@ pub fn compare<const OP: u32>(
);
}
+pub fn nop<const OP: u32>(
+ _ctx: &mut crate::gekko::Gekko,
+ _instr: crate::cpu::semantics::Instruction,
+) {
+ tracing::warn!("Executing instruction treated as NOP: OP = {OP:#x}");
+}
+
#[rustfmt::skip] pub fn twi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("twi") }
#[rustfmt::skip] pub fn ps_cmpu0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpu0") }
#[rustfmt::skip] pub fn ps_cmpo0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpo0") }
@@ -280,9 +305,7 @@ pub fn compare<const OP: u32>(
#[rustfmt::skip] pub fn mcrf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrf") }
#[rustfmt::skip] pub fn bclrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bclrx") }
#[rustfmt::skip] pub fn crnor(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crnor") }
-#[rustfmt::skip] pub fn rfi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rfi") }
#[rustfmt::skip] pub fn crandc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crandc") }
-#[rustfmt::skip] pub fn isync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("isync") }
#[rustfmt::skip] pub fn crxor(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crxor") }
#[rustfmt::skip] pub fn crnand(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crnand") }
#[rustfmt::skip] pub fn crand(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crand") }
diff --git a/crates/gekko/src/cpu/spr.rs b/crates/gekko/src/cpu/spr.rs
index 8b6303d..b9bf9cb 100644
--- a/crates/gekko/src/cpu/spr.rs
+++ b/crates/gekko/src/cpu/spr.rs
@@ -39,6 +39,42 @@ pub struct Spr {
pub dbat3u: u32,
pub dbat3l: u32,
pub dabr: u32,
+ pub gqr0: u32,
+ pub gqr1: u32,
+ pub gqr2: u32,
+ pub gqr3: u32,
+ pub gqr4: u32,
+ pub gqr5: u32,
+ pub gqr6: u32,
+ pub gqr7: u32,
+ pub hid0: u32,
+ pub hid1: u32,
+ pub hid2: u32,
+ pub iabr: u32,
+ pub wpar: u32,
+ pub dmau: u32,
+ pub dmal: u32,
+ pub ummcr0: u32,
+ pub upmc1: u32,
+ pub upmc2: u32,
+ pub usia: u32,
+ pub ummcr1: u32,
+ pub upmc3: u32,
+ pub upmc4: u32,
+ pub usda: u32,
+ pub mmcr0: u32,
+ pub pmc1: u32,
+ pub pmc2: u32,
+ pub sia: u32,
+ pub mmcr1: u32,
+ pub pmc3: u32,
+ pub pmc4: u32,
+ pub sda: u32,
+ pub l2cr: u32,
+ pub ictc: u32,
+ pub thrm1: u32,
+ pub thrm2: u32,
+ pub thrm3: u32,
}
impl Spr {
@@ -75,7 +111,43 @@ impl Spr {
541 => self.dbat2l,
542 => self.dbat3u,
543 => self.dbat3l,
+ 912 => self.gqr0,
+ 913 => self.gqr1,
+ 914 => self.gqr2,
+ 915 => self.gqr3,
+ 916 => self.gqr4,
+ 917 => self.gqr5,
+ 918 => self.gqr6,
+ 919 => self.gqr7,
+ 920 => self.hid2,
+ 921 => self.wpar,
+ 922 => self.dmau,
+ 923 => self.dmal,
+ 936 => self.ummcr0,
+ 937 => self.upmc1,
+ 938 => self.upmc2,
+ 939 => self.usia,
+ 940 => self.ummcr1,
+ 941 => self.upmc3,
+ 942 => self.upmc4,
+ 943 => self.usda,
+ 952 => self.mmcr0,
+ 953 => self.pmc1,
+ 954 => self.pmc2,
+ 955 => self.sia,
+ 956 => self.mmcr1,
+ 957 => self.pmc3,
+ 958 => self.pmc4,
+ 959 => self.sda,
+ 1008 => self.hid0,
+ 1009 => self.hid1,
+ 1010 => self.iabr,
1013 => self.dabr,
+ 1017 => self.l2cr,
+ 1019 => self.ictc,
+ 1020 => self.thrm1,
+ 1021 => self.thrm2,
+ 1022 => self.thrm3,
_ => panic!("unknown SPR {spr_num}"),
}
}
@@ -113,7 +185,43 @@ impl Spr {
541 => self.dbat2l = value,
542 => self.dbat3u = value,
543 => self.dbat3l = value,
+ 912 => self.gqr0 = value,
+ 913 => self.gqr1 = value,
+ 914 => self.gqr2 = value,
+ 915 => self.gqr3 = value,
+ 916 => self.gqr4 = value,
+ 917 => self.gqr5 = value,
+ 918 => self.gqr6 = value,
+ 919 => self.gqr7 = value,
+ 920 => self.hid2 = value,
+ 921 => self.wpar = value,
+ 922 => self.dmau = value,
+ 923 => self.dmal = value,
+ 936 => self.ummcr0 = value,
+ 937 => self.upmc1 = value,
+ 938 => self.upmc2 = value,
+ 939 => self.usia = value,
+ 940 => self.ummcr1 = value,
+ 941 => self.upmc3 = value,
+ 942 => self.upmc4 = value,
+ 943 => self.usda = value,
+ 952 => self.mmcr0 = value,
+ 953 => self.pmc1 = value,
+ 954 => self.pmc2 = value,
+ 955 => self.sia = value,
+ 956 => self.mmcr1 = value,
+ 957 => self.pmc3 = value,
+ 958 => self.pmc4 = value,
+ 959 => self.sda = value,
+ 1008 => self.hid0 = value,
+ 1009 => self.hid1 = value,
+ 1010 => self.iabr = value,
1013 => self.dabr = value,
+ 1017 => self.l2cr = value,
+ 1019 => self.ictc = value,
+ 1020 => self.thrm1 = value,
+ 1021 => self.thrm2 = value,
+ 1022 => self.thrm3 = value,
_ => panic!("unknown SPR {spr_num}"),
}
}
diff --git a/crates/gekko/src/cpu/sr.rs b/crates/gekko/src/cpu/sr.rs
new file mode 100644
index 0000000..5326981
--- /dev/null
+++ b/crates/gekko/src/cpu/sr.rs
@@ -0,0 +1,20 @@
+#[chapa::bitfield(u32, width = 32, order = msb0)]
+#[derive(Clone, Copy, Default)]
+pub struct Sr {
+ #[bits(0, alias = "t")] // decides overlay, gekko only uses T=0 AFAICT
+ pub format: bool,
+ #[bits(1, alias = "ks")]
+ pub supervisor_protection_key: bool,
+ #[bits(2, alias = "kp")]
+ pub user_protection_key: bool,
+
+ #[bits(3, alias = "n", overlay = "t0")]
+ pub no_execute_protection: bool,
+ #[bits(8..=31, alias = "vsid", overlay = "t0")]
+ pub virtual_segment_id: u32,
+
+ #[bits(3..=11, alias = "buid", overlay = "t1")]
+ pub bus_unit_id: u16,
+ #[bits(12..=31, alias = "cntrl_spec", overlay = "t1")]
+ pub device_specific_data: u32,
+}
diff --git a/rsrc/chipi-spec b/rsrc/chipi-spec
index c463284..fa93cd0 160000
--- a/rsrc/chipi-spec
+++ b/rsrc/chipi-spec
@@ -1 +1 @@
-Subproject commit c46328450ebfeac58789c09184d31d16b0f7d38d
+Subproject commit fa93cd07212df8b30a08a43d4a6ad03c75a629d9