A GameCube/Wii emulator and debugger written in Rust.
implemented majority of cpu instructions
Layle37652877a98b
diff --git a/crates/disasm/src/lib.rs b/crates/disasm/src/lib.rsindex d7d4dca..8ae4bc0 100644--- a/crates/disasm/src/lib.rs+++ b/crates/disasm/src/lib.rs@@ -38,4 +38,4 @@ pub mod cpu {Fpr(val)}}-}\ No newline at end of file+}diff --git a/crates/disasm/src/tokenizer.rs b/crates/disasm/src/tokenizer.rsindex 61cab57..92c5ae4 100644--- a/crates/disasm/src/tokenizer.rs+++ b/crates/disasm/src/tokenizer.rs@@ -37,13 +37,12 @@ impl fmt::Display for AsmToken<'_> {}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",- "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",+ "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", "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"];@@ -119,11 +118,7 @@ pub fn tokenize(s: &str) -> Vec<AsmToken<'_>> {tokens}-fn tokenize_operands<'a>(- sc: &mut Scanner<'a>,- tokens: &mut Vec<AsmToken<'a>>,- mut expect_spr: bool,-) {+fn tokenize_operands<'a>(sc: &mut Scanner<'a>, tokens: &mut Vec<AsmToken<'a>>, mut expect_spr: bool) {while let Some(b) = sc.peek() {let ch = b as char;@@ -233,15 +228,10 @@ fn classify_word<'a>(word: &'a str, expect_spr: bool) -> AsmToken<'a> {fn parse_register(word: &str, prefix: &str, max: u8) -> Option<u8> {let rest = word.strip_prefix(prefix)?;- let n: u8 = rest- .parse()- .ok()- .filter(|_| rest.bytes().all(|b| b.is_ascii_digit()))?;+ let n: u8 = rest.parse().ok().filter(|_| rest.bytes().all(|b| b.is_ascii_digit()))?;(n <= max).then_some(n)}fn is_standalone_operand(tokens: &[AsmToken<'_>]) -> bool {- tokens.len() == 2- && matches!(tokens[0], AsmToken::Mnemonic(_))- && matches!(tokens[1], AsmToken::Punct(' '))+ tokens.len() == 2 && matches!(tokens[0], AsmToken::Mnemonic(_)) && matches!(tokens[1], AsmToken::Punct(' '))}diff --git a/crates/gctool/src/main.rs b/crates/gctool/src/main.rsindex 68d9444..4f25c25 100644--- a/crates/gctool/src/main.rs+++ b/crates/gctool/src/main.rs@@ -17,8 +17,7 @@ fn parse_offset(s: &str) -> Result<usize, String> {if let Some(hex) = s.strip_prefix("0x").or_else(|| s.strip_prefix("0X")) {usize::from_str_radix(hex, 16).map_err(|e| e.to_string())} else {- s.parse()- .map_err(|e: std::num::ParseIntError| e.to_string())+ s.parse().map_err(|e: std::num::ParseIntError| e.to_string())}}diff --git a/crates/gekko/build.rs b/crates/gekko/build.rsindex 7972374..470d2ab 100644--- a/crates/gekko/build.rs+++ b/crates/gekko/build.rs@@ -10,7 +10,7 @@ fn main() {.handler_mod("crate::cpu::interpreter").ctx_type("crate::gekko::Gekko").instr_type("crate::cpu::semantics::Instruction")- .group("branch", ["bx", "bcx", "bclrx"])+ .group("branch", ["bx", "bcx", "bclrx", "bcctrx"]).group("alu",[@@ -23,16 +23,76 @@ fn main() {"xoris","andi_dot","andis_dot",+ "subfx",+ "negx",+ "addcx",+ "subfcx",+ "addex",+ "subfex",+ "addzex",+ "subfzex",+ "addmex",+ "subfmex",+ "mullwx",+ "divwux",+ "divwx",+ "mulhwux",+ "mulhwx",+ "subfic",+ "addic",+ "addic_dot",+ "mulli",],)- .group("rotate", ["rlwinmx"])+ .group("rotate", ["rlwinmx", "rlwimix", "rlwnmx"]).group("msr", ["mtmsr", "mfmsr", "rfi"]).group("spr", ["mtspr", "mfspr"]).group("segment", ["mtsr", "mfsr"])- .group("store_load", ["stw", "stwu", "sth", "sthu", "lwz", "lwzu"])- .group("store_load_fp", ["lfd", "lfdu", "stfd", "stfdu"])- .group("compare", ["cmp", "cmpi"])- .group("nop", ["isync", "sync"]); // instructions that we can treat as no-ops+ .group(+ "store_load",+ [+ "stw", "stwu", "sth", "sthu", "lwz", "lwzu", "lbz", "lbzu", "stb", "stbu", "lhz", "lhzu", "lha",+ "lhau", "lmw", "stmw", "lwzx", "lbzx", "lhzx", "lhax", "stwx", "stbx", "sthx", "lwzux", "lbzux",+ "lhzux", "lhaux", "stwux", "stbux", "sthux",+ ],+ )+ .group(+ "store_load_fp",+ [+ "lfd", "lfdu", "stfd", "stfdu", "lfs", "lfsu", "stfs", "stfsu", "lfsx", "lfsux", "lfdx", "lfdux",+ "stfsx", "stfsux", "stfdx", "stfdux",+ ],+ )+ .group("compare", ["cmp", "cmpi", "cmpli", "cmpl"])+ .group(+ "nop",+ [+ "isync", "sync", "eieio", "dcbf", "dcbi", "dcbst", "dcbt", "dcbtst", "dcba", "dcbz", "dcbz_l", "icbi",+ "tlbie", "tlbia", "tlbsync", "tlbld", "tlbli",+ ],+ )+ .group(+ "logical",+ [+ "andx", "orx", "xorx", "nandx", "norx", "andcx", "orcx", "eqvx", "slwx", "srwx", "srawx", "srawix",+ "cntlzwx", "extshx", "extsbx",+ ],+ )+ .group(+ "cr_ops",+ [+ "mtcrf", "mfcr", "crxor", "cror", "crand", "creqv", "crnor", "crnand", "crandc", "crorc", "mcrf",+ ],+ )+ .group(+ "fp_ops",+ [+ "mtfsfx", "mffsx", "mtfsb0x", "mtfsb1x", "mtfsfix", "mcrfs", "fmrx", "fnegx", "fabsx", "fnabsx",+ "frspx", "fctiwx", "fctiwzx", "fcmpu", "fcmpo", "faddx", "fsubx", "fmulx", "fdivx", "fmaddx", "fmsubx",+ "fnmaddx", "fnmsubx", "faddsx", "fsubsx", "fmulsx", "fdivsx", "fmaddsx", "fmsubsx", "fnmaddsx",+ "fnmsubsx",+ ],+ );// Generate the instruction type with accessor methodsbuilderdiff --git a/crates/gekko/src/cpu.rs b/crates/gekko/src/cpu.rsindex 56bdf5b..93cfe4e 100644--- a/crates/gekko/src/cpu.rs+++ b/crates/gekko/src/cpu.rs@@ -66,7 +66,7 @@ impl Cpu {#[inline]pub fn update_cr0(&mut self, val: u32) {- let so = (self.spr.xer >> 31) != 0; // SO is copied from XER[SO]+ let so = self.spr.xer.summary_overflow(); // SO is copied from XER[SO]self.cr.set_cr0(condition::ConditionField::new().with_lt((val as i32) < 0)@@ -75,4 +75,29 @@ impl Cpu {.with_so(so),);}++ /// Update CR1 with FPSCR[0:3] (used by Rc=1 FP instructions)+ #[inline]+ pub fn update_cr1(&mut self) {+ let cr1 = condition::ConditionField::from((self.fpscr >> 28) as u8);+ self.cr.set_field(1, cr1);+ }++ /// Read GPR with the PowerPC "rA|0" convention: returns 0 when index is 0+ #[inline(always)]+ pub fn read_gpr_or_zero(&self, index: u8) -> u32 {+ if index == 0 { 0 } else { self.gprs[index as usize] }+ }++ /// Get XER carry bit+ #[inline(always)]+ pub fn xer_ca(&self) -> u32 {+ self.spr.xer.carry() as u32+ }++ /// Set XER carry bit+ #[inline(always)]+ pub fn set_xer_ca(&mut self, ca: bool) {+ self.spr.xer = self.spr.xer.with_carry(ca);+ }}diff --git a/crates/gekko/src/cpu/condition.rs b/crates/gekko/src/cpu/condition.rsindex 3daa2b6..9cdd312 100644--- a/crates/gekko/src/cpu/condition.rs+++ b/crates/gekko/src/cpu/condition.rs@@ -66,20 +66,28 @@ pub struct ConditionField {#[bits(2, alias = ["equal", "vx", "fp_invalid_exception"])]pub eq: bool,#[bits(3, alias = ["summary_overflow", "ox", "fp_overflow_exception"])]- pub so: bool,+ pub so: bool,}#[chapa::bitfield(u32, order = msb0)]#[derive(Clone, Copy)]pub struct ConditionRegister {- #[bits(0..=3)] pub cr0: ConditionField,- #[bits(4..=7)] pub cr1: ConditionField,- #[bits(8..=11)] pub cr2: ConditionField,- #[bits(12..=15)] pub cr3: ConditionField,- #[bits(16..=19)] pub cr4: ConditionField,- #[bits(20..=23)] pub cr5: ConditionField,- #[bits(24..=27)] pub cr6: ConditionField,- #[bits(28..=31)] pub cr7: ConditionField,+ #[bits(0..=3)]+ pub cr0: ConditionField,+ #[bits(4..=7)]+ pub cr1: ConditionField,+ #[bits(8..=11)]+ pub cr2: ConditionField,+ #[bits(12..=15)]+ pub cr3: ConditionField,+ #[bits(16..=19)]+ pub cr4: ConditionField,+ #[bits(20..=23)]+ pub cr5: ConditionField,+ #[bits(24..=27)]+ pub cr6: ConditionField,+ #[bits(28..=31)]+ pub cr7: ConditionField,}impl ConditionRegister {@@ -98,6 +106,26 @@ impl ConditionRegister {}}+ #[inline]+ pub fn get_bit(&self, bit: u8) -> bool {+ (self.raw() >> (31 - bit)) & 1 != 0+ }++ #[inline]+ pub fn set_bit(&mut self, bit: u8, val: bool) {+ let mask = 1u32 << (31 - bit);+ let raw = if val { self.raw() | mask } else { self.raw() & !mask };+ *self = Self::from(raw);+ }++ pub fn field_from_ord(ord: std::cmp::Ordering) -> ConditionField {+ match ord {+ std::cmp::Ordering::Less => ConditionField::new().with_lt(true),+ std::cmp::Ordering::Equal => ConditionField::new().with_eq(true),+ std::cmp::Ordering::Greater => ConditionField::new().with_gt(true),+ }+ }+#[inline]pub fn get_field(&self, index: u8) -> ConditionField {match index {@@ -112,4 +140,4 @@ impl ConditionRegister {_ => panic!("Invalid CR field index: {}", index),}}-}\ No newline at end of file+}diff --git a/crates/gekko/src/cpu/interpreter.rs b/crates/gekko/src/cpu/interpreter.rsindex b9de68d..e94ec93 100644--- a/crates/gekko/src/cpu/interpreter.rs+++ b/crates/gekko/src/cpu/interpreter.rs@@ -1,520 +1,19 @@-use crate::cpu::{- condition::{BranchControl, ConditionField},- sr::Sr,-};--pub fn branch<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- if instr.lk() {- ctx.cpu.spr.lr = ctx.cpu.cia.wrapping_add(4);- }-- match OP {- crate::cpu::lut::OP_BX => {- ctx.cpu.nia = if instr.aa() {- instr.li() as u32- } else {- ctx.cpu.cia.wrapping_add_signed(instr.li())- }- }- crate::cpu::lut::OP_BCLRX | crate::cpu::lut::OP_BCX => {- let ctrl = BranchControl::from_bo(instr.bo());- tracing::trace!("Branch control: {ctrl:?}");-- if ctrl.should_decrement_ctr() {- ctx.cpu.spr.ctr = ctx.cpu.spr.ctr.wrapping_sub(1);- }-- let (crf, bit) = (instr.bi() >> 2, instr.bi() & 0b11);- let condition = match bit {- 0 => ctx.cpu.cr.get_field(crf).lt(),- 1 => ctx.cpu.cr.get_field(crf).gt(),- 2 => ctx.cpu.cr.get_field(crf).eq(),- 3 => ctx.cpu.cr.get_field(crf).so(),- _ => panic!("Invalid CR bit index: {}", bit),- };- if !ctrl.should_branch(ctx.cpu.spr.ctr, condition) {- return;- }-- match OP {- crate::cpu::lut::OP_BCLRX => {- ctx.cpu.nia = ctx.cpu.spr.lr;- }- crate::cpu::lut::OP_BCX => {- ctx.cpu.nia = if instr.aa() {- instr.bd() as u32- } else {- ctx.cpu.cia.wrapping_add_signed(instr.bd())- }- }- _ => {- tracing::error!("missing OP = {OP:#x}");- }- }- }- _ => todo!("branch instruction with OP = {OP:#x}"),- };-}--pub fn alu<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- match OP {- crate::cpu::lut::OP_ADDX => {- let res = ctx- .cpu- .read_gpr(instr.ra())- .wrapping_add(ctx.cpu.read_gpr(instr.rb()));- ctx.cpu.write_gpr(instr.rd(), res);- if instr.rc() {- ctx.cpu.update_cr0(res);- }- }- crate::cpu::lut::OP_ADDI | crate::cpu::lut::OP_ADDIS => {- let ra = if instr.ra() == 0 {- 0- } else {- ctx.cpu.read_gpr(instr.ra())- };- let simm = if OP == crate::cpu::lut::OP_ADDIS {- instr.simm() << 16- } else {- instr.simm()- };- ctx.cpu.write_gpr(instr.rd(), ra.wrapping_add_signed(simm));- }- crate::cpu::lut::OP_ORI | crate::cpu::lut::OP_ORIS => {- let imm = if OP == crate::cpu::lut::OP_ORIS {- (instr.uimm() as u32) << 16- } else {- instr.uimm() as u32- };- ctx.cpu- .write_gpr(instr.ra(), ctx.cpu.read_gpr(instr.rs()) | imm);- }- crate::cpu::lut::OP_XORI | crate::cpu::lut::OP_XORIS => {- let imm = if OP == crate::cpu::lut::OP_XORIS {- (instr.uimm() as u32) << 16- } else {- instr.uimm() as u32- };- ctx.cpu- .write_gpr(instr.ra(), ctx.cpu.read_gpr(instr.rs()) ^ imm);- }- crate::cpu::lut::OP_ANDI_DOT | crate::cpu::lut::OP_ANDIS_DOT => {- let mask = if OP == crate::cpu::lut::OP_ANDIS_DOT {- (instr.uimm() as u32) << 16- } else {- instr.uimm() as u32- };- let val = ctx.cpu.read_gpr(instr.rs()) & mask;- ctx.cpu.write_gpr(instr.ra(), val);- ctx.cpu.update_cr0(val);- }- _ => todo!("ALU instruction with OP = {OP:#x}"),- }-}--pub fn rotate<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- match OP {- crate::cpu::lut::OP_RLWINMX => {- let r = ctx.cpu.read_gpr(instr.rs()).rotate_left(instr.sh() as u32);- let mb = instr.mb() as u32;- let me = instr.me() as u32;- let begin = 0xFFFF_FFFFu32 >> mb;- let end = if me >= 31 {- 0- } else {- 0xFFFF_FFFFu32 >> (me + 1)- };- let m = if mb <= me { begin & !end } else { begin | !end };- let res = r & m;- ctx.cpu.write_gpr(instr.ra(), res);- if instr.rc() {- ctx.cpu.update_cr0(res);- }- }- _ => todo!("Rotate instruction with OP = {OP:#x}"),- }-}--pub fn msr<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- _instr: crate::cpu::semantics::Instruction,-) {- match OP {- crate::cpu::lut::OP_MTMSR => {- tracing::error!("OP_MTMSR!!");- }- crate::cpu::lut::OP_MFMSR => {- tracing::error!("OP_MFMSR!!");- }- crate::cpu::lut::OP_RFI => {- // "Bits SRR1[16–23, 25–27, 30–31] are placed into the corresponding bits of the MSR."- const RFI_MSR_MASK: u32 = 0x0000_FF73;- ctx.cpu.msr = (ctx.cpu.msr & !RFI_MSR_MASK) | (ctx.cpu.spr.srr1 & RFI_MSR_MASK);- // "If the new MSR value does not enable any pending exceptions, then the- // next instruction is fetched, under control of the new MSR value,- // from the address SRR0[0–29] || 0b00"- ctx.cpu.pc = ctx.cpu.spr.srr0.value() << 2;- }- _ => todo!("MSR instruction with OP = {OP:#x}"),- }-}--pub fn spr<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- match OP {- crate::cpu::lut::OP_MTSPR => ctx- .cpu- .spr- .write(instr.spr_swapped(), ctx.cpu.read_gpr(instr.rs())),- crate::cpu::lut::OP_MFSPR => ctx- .cpu- .write_gpr(instr.rd(), ctx.cpu.spr.read(instr.spr_swapped())),- _ => todo!("SPR instruction with OP = {OP:#x}"),- }-}--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,-) {- 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());- 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());- ctx.write_u16(addr, (ctx.cpu.read_gpr(instr.rs()) & 0xffff) as u16);- if OP == crate::cpu::lut::OP_STHU {- ctx.cpu.write_gpr(instr.ra(), addr);- }- }- crate::cpu::lut::OP_LWZ | crate::cpu::lut::OP_LWZU => {- let addr = ctx- .cpu- .read_gpr(instr.ra())- .wrapping_add_signed(instr.disp());- let val = ctx.read_u32(addr);- ctx.cpu.write_gpr(instr.rd(), val);- if OP == crate::cpu::lut::OP_LWZU {- ctx.cpu.write_gpr(instr.ra(), addr);- }- }- _ => todo!("Store/Load instruction with OP = {OP:#x}"),- }-}--pub fn store_load_fp<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- match OP {- crate::cpu::lut::OP_LFD | crate::cpu::lut::OP_LFDU => {- let addr = ctx- .cpu- .read_gpr(instr.ra())- .wrapping_add_signed(instr.disp());- let value =- (ctx.read_u32(addr) as u64 | ((ctx.read_u32(addr + 4) as u64) << 32)) as f64;- ctx.cpu.write_fpr(instr.rd(), value);-- if OP == crate::cpu::lut::OP_LFDU {- ctx.cpu.write_gpr(instr.ra(), addr);- }- }- crate::cpu::lut::OP_STFD | crate::cpu::lut::OP_STFDU => {- let addr = ctx- .cpu- .read_gpr(instr.ra())- .wrapping_add_signed(instr.disp());- let value = ctx.cpu.read_fpr(instr.rs()) as u64;- ctx.write_u32(addr, value as u32);- ctx.write_u32(addr + 4, (value >> 32) as u32);-- if OP == crate::cpu::lut::OP_STFDU {- ctx.cpu.write_gpr(instr.ra(), addr);- }- }- _ => todo!("FP Store/Load instruction with OP = {OP:#x}"),- }-}--pub fn compare<const OP: u32>(- ctx: &mut crate::gekko::Gekko,- instr: crate::cpu::semantics::Instruction,-) {- let (a, b) = match OP {- crate::cpu::lut::OP_CMP => (- ctx.cpu.read_gpr(instr.ra()) as i32,- ctx.cpu.read_gpr(instr.rb()) as i32,- ),- crate::cpu::lut::OP_CMPI => (ctx.cpu.read_gpr(instr.ra()) as i32, instr.simm()),- _ => todo!("Compare instruction with OP = {OP:#x}"),- };-- ctx.cpu.cr.set_field(- instr.crfd(),- match a.cmp(&b) {- std::cmp::Ordering::Less => ConditionField::new().with_lt(true),- std::cmp::Ordering::Equal => ConditionField::new().with_eq(true),- std::cmp::Ordering::Greater => ConditionField::new().with_gt(true),- },- );-}--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") }-#[rustfmt::skip] pub fn ps_cmpu1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpu1") }-#[rustfmt::skip] pub fn ps_cmpo1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpo1") }-#[rustfmt::skip] pub fn ps_res(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_res") }-#[rustfmt::skip] pub fn ps_rsqrte(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_rsqrte") }-#[rustfmt::skip] pub fn ps_neg(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_neg") }-#[rustfmt::skip] pub fn ps_mr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_mr") }-#[rustfmt::skip] pub fn ps_nabs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nabs") }-#[rustfmt::skip] pub fn ps_abs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_abs") }-#[rustfmt::skip] pub fn ps_merge00(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge00") }-#[rustfmt::skip] pub fn ps_merge01(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge01") }-#[rustfmt::skip] pub fn ps_merge10(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge10") }-#[rustfmt::skip] pub fn ps_merge11(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge11") }-#[rustfmt::skip] pub fn psq_lx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lx") }-#[rustfmt::skip] pub fn psq_stx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stx") }-#[rustfmt::skip] pub fn psq_lux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lux") }-#[rustfmt::skip] pub fn psq_stux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stux") }-#[rustfmt::skip] pub fn ps_sum0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sum0") }-#[rustfmt::skip] pub fn ps_sum1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sum1") }-#[rustfmt::skip] pub fn ps_muls0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_muls0") }-#[rustfmt::skip] pub fn ps_muls1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_muls1") }-#[rustfmt::skip] pub fn ps_madds0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madds0") }-#[rustfmt::skip] pub fn ps_madds1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madds1") }-#[rustfmt::skip] pub fn ps_div(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_div") }-#[rustfmt::skip] pub fn ps_sub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sub") }-#[rustfmt::skip] pub fn ps_add(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_add") }-#[rustfmt::skip] pub fn ps_sel(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sel") }-#[rustfmt::skip] pub fn ps_mul(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_mul") }-#[rustfmt::skip] pub fn ps_msub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_msub") }-#[rustfmt::skip] pub fn ps_madd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madd") }-#[rustfmt::skip] pub fn ps_nmsub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nmsub") }-#[rustfmt::skip] pub fn ps_nmadd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nmadd") }-#[rustfmt::skip] pub fn dcbz_l(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbz_l") }-#[rustfmt::skip] pub fn mulli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulli") }-#[rustfmt::skip] pub fn subfic(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfic") }-#[rustfmt::skip] pub fn cmpli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmpli") }-#[rustfmt::skip] pub fn addic(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addic") }-#[rustfmt::skip] pub fn addic_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addic_dot") }-#[rustfmt::skip] pub fn bcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bcx") }-#[rustfmt::skip] pub fn sc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sc") }-#[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 crandc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crandc") }-#[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") }-#[rustfmt::skip] pub fn creqv(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("creqv") }-#[rustfmt::skip] pub fn crorc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crorc") }-#[rustfmt::skip] pub fn cror(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cror") }-#[rustfmt::skip] pub fn bcctrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bcctrx") }-#[rustfmt::skip] pub fn rlwimix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwimix") }-#[rustfmt::skip] pub fn rlwinmx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwinmx") }-#[rustfmt::skip] pub fn rlwnmx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwnmx") }-#[rustfmt::skip] pub fn ori(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ori") }-#[rustfmt::skip] pub fn oris(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("oris") }-#[rustfmt::skip] pub fn xori(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xori") }-#[rustfmt::skip] pub fn xoris(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xoris") }-#[rustfmt::skip] pub fn andi_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andi_dot") }-#[rustfmt::skip] pub fn andis_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andis_dot") }-#[rustfmt::skip] pub fn cmp(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmp") }-#[rustfmt::skip] pub fn tw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tw") }-#[rustfmt::skip] pub fn subfcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfcx") }-#[rustfmt::skip] pub fn mulhwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulhwux") }-#[rustfmt::skip] pub fn addcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addcx") }-#[rustfmt::skip] pub fn lwarx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwarx") }-#[rustfmt::skip] pub fn lwzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwzx") }-#[rustfmt::skip] pub fn slwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("slwx") }-#[rustfmt::skip] pub fn cntlzwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cntlzwx") }-#[rustfmt::skip] pub fn andx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andx") }-#[rustfmt::skip] pub fn cmpl(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmpl") }-#[rustfmt::skip] pub fn subfx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfx") }-#[rustfmt::skip] pub fn dcbst(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbst") }-#[rustfmt::skip] pub fn lwzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwzux") }-#[rustfmt::skip] pub fn andcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andcx") }-#[rustfmt::skip] pub fn mulhwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulhwx") }-#[rustfmt::skip] pub fn mfcr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfcr") }-#[rustfmt::skip] pub fn dcbf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbf") }-#[rustfmt::skip] pub fn lbzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzx") }-#[rustfmt::skip] pub fn negx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("negx") }-#[rustfmt::skip] pub fn lbzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzux") }-#[rustfmt::skip] pub fn norx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("norx") }-#[rustfmt::skip] pub fn subfex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfex") }-#[rustfmt::skip] pub fn addex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addex") }-#[rustfmt::skip] pub fn mtcrf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtcrf") }-#[rustfmt::skip] pub fn stwcx_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwcx_dot") }-#[rustfmt::skip] pub fn stwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwx") }-#[rustfmt::skip] pub fn stwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwux") }-#[rustfmt::skip] pub fn subfzex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfzex") }-#[rustfmt::skip] pub fn addzex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addzex") }-#[rustfmt::skip] pub fn mtsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtsr") }-#[rustfmt::skip] pub fn stbx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbx") }-#[rustfmt::skip] pub fn subfmex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfmex") }-#[rustfmt::skip] pub fn addmex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addmex") }-#[rustfmt::skip] pub fn mullwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mullwx") }-#[rustfmt::skip] pub fn mtsrin(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtsrin") }-#[rustfmt::skip] pub fn dcbtst(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbtst") }-#[rustfmt::skip] pub fn stbux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbux") }-#[rustfmt::skip] pub fn addx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addx") }-#[rustfmt::skip] pub fn dcbt(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbt") }-#[rustfmt::skip] pub fn lhzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzx") }-#[rustfmt::skip] pub fn eqvx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eqvx") }-#[rustfmt::skip] pub fn tlbie(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbie") }-#[rustfmt::skip] pub fn eciwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eciwx") }-#[rustfmt::skip] pub fn lhzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzux") }-#[rustfmt::skip] pub fn xorx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xorx") }-#[rustfmt::skip] pub fn lhax(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhax") }-#[rustfmt::skip] pub fn tlbia(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbia") }-#[rustfmt::skip] pub fn mftb(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mftb") }-#[rustfmt::skip] pub fn lhaux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhaux") }-#[rustfmt::skip] pub fn sthx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthx") }-#[rustfmt::skip] pub fn orcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("orcx") }-#[rustfmt::skip] pub fn ecowx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ecowx") }-#[rustfmt::skip] pub fn sthux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthux") }-#[rustfmt::skip] pub fn orx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("orx") }-#[rustfmt::skip] pub fn divwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("divwux") }-#[rustfmt::skip] pub fn dcbi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbi") }-#[rustfmt::skip] pub fn nandx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("nandx") }-#[rustfmt::skip] pub fn divwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("divwx") }-#[rustfmt::skip] pub fn mcrxr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrxr") }-#[rustfmt::skip] pub fn lwbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwbrx") }-#[rustfmt::skip] pub fn lfsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsx") }-#[rustfmt::skip] pub fn srwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srwx") }-#[rustfmt::skip] pub fn lswx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lswx") }-#[rustfmt::skip] pub fn tlbsync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbsync") }-#[rustfmt::skip] pub fn lfsux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsux") }-#[rustfmt::skip] pub fn mfsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfsr") }-#[rustfmt::skip] pub fn lswi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lswi") }-#[rustfmt::skip] pub fn sync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sync") }-#[rustfmt::skip] pub fn lfdx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdx") }-#[rustfmt::skip] pub fn lfdux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdux") }-#[rustfmt::skip] pub fn mfsrin(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfsrin") }-#[rustfmt::skip] pub fn stswx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stswx") }-#[rustfmt::skip] pub fn stwbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwbrx") }-#[rustfmt::skip] pub fn stfsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsx") }-#[rustfmt::skip] pub fn stfsux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsux") }-#[rustfmt::skip] pub fn stswi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stswi") }-#[rustfmt::skip] pub fn stfdx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdx") }-#[rustfmt::skip] pub fn stfdux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdux") }-#[rustfmt::skip] pub fn dcba(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcba") }-#[rustfmt::skip] pub fn lhbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhbrx") }-#[rustfmt::skip] pub fn srawx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srawx") }-#[rustfmt::skip] pub fn srawix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srawix") }-#[rustfmt::skip] pub fn eieio(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eieio") }-#[rustfmt::skip] pub fn sthbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthbrx") }-#[rustfmt::skip] pub fn extshx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("extshx") }-#[rustfmt::skip] pub fn extsbx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("extsbx") }-#[rustfmt::skip] pub fn icbi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("icbi") }-#[rustfmt::skip] pub fn stfiwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfiwx") }-#[rustfmt::skip] pub fn tlbld(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbld") }-#[rustfmt::skip] pub fn tlbli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbli") }-#[rustfmt::skip] pub fn dcbz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbz") }-#[rustfmt::skip] pub fn lbz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbz") }-#[rustfmt::skip] pub fn lbzu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzu") }-#[rustfmt::skip] pub fn stw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stw") }-#[rustfmt::skip] pub fn stb(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stb") }-#[rustfmt::skip] pub fn stbu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbu") }-#[rustfmt::skip] pub fn lhz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhz") }-#[rustfmt::skip] pub fn lhzu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzu") }-#[rustfmt::skip] pub fn lha(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lha") }-#[rustfmt::skip] pub fn lhau(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhau") }-#[rustfmt::skip] pub fn lmw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lmw") }-#[rustfmt::skip] pub fn stmw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stmw") }-#[rustfmt::skip] pub fn lfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfs") }-#[rustfmt::skip] pub fn lfsu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsu") }-#[rustfmt::skip] pub fn lfd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfd") }-#[rustfmt::skip] pub fn lfdu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdu") }-#[rustfmt::skip] pub fn stfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfs") }-#[rustfmt::skip] pub fn stfsu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsu") }-#[rustfmt::skip] pub fn stfd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfd") }-#[rustfmt::skip] pub fn stfdu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdu") }-#[rustfmt::skip] pub fn psq_l(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_l") }-#[rustfmt::skip] pub fn psq_lu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lu") }-#[rustfmt::skip] pub fn fdivsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fdivsx") }-#[rustfmt::skip] pub fn fsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsubsx") }-#[rustfmt::skip] pub fn faddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("faddsx") }-#[rustfmt::skip] pub fn fsqrtsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsqrtsx") }-#[rustfmt::skip] pub fn fresx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fresx") }-#[rustfmt::skip] pub fn fmulsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmulsx") }-#[rustfmt::skip] pub fn fmsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmsubsx") }-#[rustfmt::skip] pub fn fmaddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmaddsx") }-#[rustfmt::skip] pub fn fnmsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmsubsx") }-#[rustfmt::skip] pub fn fnmaddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmaddsx") }-#[rustfmt::skip] pub fn psq_st(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_st") }-#[rustfmt::skip] pub fn psq_stu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stu") }-#[rustfmt::skip] pub fn fcmpu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fcmpu") }-#[rustfmt::skip] pub fn frspx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("frspx") }-#[rustfmt::skip] pub fn fctiwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fctiwx") }-#[rustfmt::skip] pub fn fctiwzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fctiwzx") }-#[rustfmt::skip] pub fn fcmpo(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fcmpo") }-#[rustfmt::skip] pub fn mtfsb1x(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsb1x") }-#[rustfmt::skip] pub fn fnegx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnegx") }-#[rustfmt::skip] pub fn mcrfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrfs") }-#[rustfmt::skip] pub fn mtfsb0x(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsb0x") }-#[rustfmt::skip] pub fn fmrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmrx") }-#[rustfmt::skip] pub fn mtfsfix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsfix") }-#[rustfmt::skip] pub fn fnabsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnabsx") }-#[rustfmt::skip] pub fn fabsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fabsx") }-#[rustfmt::skip] pub fn mffsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mffsx") }-#[rustfmt::skip] pub fn mtfsfx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsfx") }-#[rustfmt::skip] pub fn fdivx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fdivx") }-#[rustfmt::skip] pub fn fsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsubx") }-#[rustfmt::skip] pub fn faddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("faddx") }-#[rustfmt::skip] pub fn fsqrtx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsqrtx") }-#[rustfmt::skip] pub fn fselx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fselx") }-#[rustfmt::skip] pub fn fmulx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmulx") }-#[rustfmt::skip] pub fn frsqrtex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("frsqrtex") }-#[rustfmt::skip] pub fn fmsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmsubx") }-#[rustfmt::skip] pub fn fmaddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmaddx") }-#[rustfmt::skip] pub fn fnmsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmsubx") }-#[rustfmt::skip] pub fn fnmaddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmaddx") }+mod alu;+mod branch;+mod compare;+mod cr_ops;+mod fp_ops;+mod rotate;+mod store_load;+mod stubs;+mod system;++pub use alu::{alu, logical};+pub use branch::branch;+pub use compare::compare;+pub use cr_ops::cr_ops;+pub use fp_ops::fp_ops;+pub use rotate::rotate;+pub use store_load::{store_load, store_load_fp};+pub use stubs::*;+pub use system::{mftb, msr, nop, segment, spr};diff --git a/crates/gekko/src/cpu/interpreter/alu.rs b/crates/gekko/src/cpu/interpreter/alu.rsnew file mode 100644index 0000000..cfff8a4--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/alu.rs@@ -0,0 +1,271 @@+pub fn alu<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_ADDX => {+ let res = ctx.cpu.read_gpr(instr.ra()).wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_ADDI | crate::cpu::lut::OP_ADDIS => {+ let ra = ctx.cpu.read_gpr_or_zero(instr.ra());+ let simm = if OP == crate::cpu::lut::OP_ADDIS {+ instr.simm() << 16+ } else {+ instr.simm()+ };+ ctx.cpu.write_gpr(instr.rd(), ra.wrapping_add_signed(simm));+ }+ crate::cpu::lut::OP_ORI | crate::cpu::lut::OP_ORIS => {+ let imm = if OP == crate::cpu::lut::OP_ORIS {+ (instr.uimm() as u32) << 16+ } else {+ instr.uimm() as u32+ };+ ctx.cpu.write_gpr(instr.ra(), ctx.cpu.read_gpr(instr.rs()) | imm);+ }+ crate::cpu::lut::OP_XORI | crate::cpu::lut::OP_XORIS => {+ let imm = if OP == crate::cpu::lut::OP_XORIS {+ (instr.uimm() as u32) << 16+ } else {+ instr.uimm() as u32+ };+ ctx.cpu.write_gpr(instr.ra(), ctx.cpu.read_gpr(instr.rs()) ^ imm);+ }+ crate::cpu::lut::OP_ANDI_DOT | crate::cpu::lut::OP_ANDIS_DOT => {+ let mask = if OP == crate::cpu::lut::OP_ANDIS_DOT {+ (instr.uimm() as u32) << 16+ } else {+ instr.uimm() as u32+ };+ let val = ctx.cpu.read_gpr(instr.rs()) & mask;+ ctx.cpu.write_gpr(instr.ra(), val);+ ctx.cpu.update_cr0(val);+ }+ crate::cpu::lut::OP_SUBFX => {+ let res = ctx.cpu.read_gpr(instr.rb()).wrapping_sub(ctx.cpu.read_gpr(instr.ra()));+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_NEGX => {+ let res = (!ctx.cpu.read_gpr(instr.ra())).wrapping_add(1);+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_ADDCX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let rb = ctx.cpu.read_gpr(instr.rb());+ let (res, carry) = ra.overflowing_add(rb);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(carry);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_SUBFCX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let rb = ctx.cpu.read_gpr(instr.rb());+ let res = rb.wrapping_sub(ra);+ ctx.cpu.set_xer_ca(rb >= ra);+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_ADDEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let rb = ctx.cpu.read_gpr(instr.rb());+ let ca = ctx.cpu.xer_ca();+ let (t1, c1) = ra.overflowing_add(rb);+ let (res, c2) = t1.overflowing_add(ca);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(c1 || c2);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_SUBFEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let rb = ctx.cpu.read_gpr(instr.rb());+ let ca = ctx.cpu.xer_ca();+ let (t1, c1) = (!ra).overflowing_add(rb);+ let (res, c2) = t1.overflowing_add(ca);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(c1 || c2);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_ADDZEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let ca = ctx.cpu.xer_ca();+ let (res, carry) = ra.overflowing_add(ca);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(carry);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_SUBFZEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let ca = ctx.cpu.xer_ca();+ let (res, carry) = (!ra).overflowing_add(ca);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(carry);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_ADDMEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let ca = ctx.cpu.xer_ca();+ let (t1, c1) = ra.overflowing_add(ca);+ let (res, c2) = t1.overflowing_add(0xFFFF_FFFF);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(c1 || c2);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_SUBFMEX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let ca = ctx.cpu.xer_ca();+ let (t1, c1) = (!ra).overflowing_add(ca);+ let (res, c2) = t1.overflowing_add(0xFFFF_FFFF);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(c1 || c2);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_MULLWX => {+ let res = (ctx.cpu.read_gpr(instr.ra()) as i32 as i64)+ .wrapping_mul(ctx.cpu.read_gpr(instr.rb()) as i32 as i64) as u32;+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_DIVWUX => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let rb = ctx.cpu.read_gpr(instr.rb());+ let res = if rb == 0 { 0 } else { ra / rb };+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_DIVWX => {+ let ra = ctx.cpu.read_gpr(instr.ra()) as i32;+ let rb = ctx.cpu.read_gpr(instr.rb()) as i32;+ let res = if rb == 0 || (ra == i32::MIN && rb == -1) {+ 0u32+ } else {+ (ra / rb) as u32+ };+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_MULHWUX => {+ let res = ((ctx.cpu.read_gpr(instr.ra()) as u64 * ctx.cpu.read_gpr(instr.rb()) as u64) >> 32) as u32;+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_MULHWX => {+ let res = ((ctx.cpu.read_gpr(instr.ra()) as i32 as i64 * ctx.cpu.read_gpr(instr.rb()) as i32 as i64) >> 32)+ as u32;+ ctx.cpu.write_gpr(instr.rd(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_SUBFIC => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let simm = instr.simm() as u32;+ ctx.cpu.write_gpr(instr.rd(), simm.wrapping_sub(ra));+ ctx.cpu.set_xer_ca(simm >= ra);+ }+ crate::cpu::lut::OP_ADDIC | crate::cpu::lut::OP_ADDIC_DOT => {+ let ra = ctx.cpu.read_gpr(instr.ra());+ let (res, carry) = ra.overflowing_add(instr.simm() as u32);+ ctx.cpu.write_gpr(instr.rd(), res);+ ctx.cpu.set_xer_ca(carry);+ if OP == crate::cpu::lut::OP_ADDIC_DOT {+ ctx.cpu.update_cr0(res);+ }+ }+ crate::cpu::lut::OP_MULLI => {+ let res = (ctx.cpu.read_gpr(instr.ra()) as i32 as i64).wrapping_mul(instr.simm() as i64) as u32;+ ctx.cpu.write_gpr(instr.rd(), res);+ }+ _ => todo!("ALU instruction with OP = {OP:#x}"),+ }+}++pub fn logical<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ let rs = ctx.cpu.read_gpr(instr.rs());+ let rb = ctx.cpu.read_gpr(instr.rb());++ let res = match OP {+ crate::cpu::lut::OP_ANDX => rs & rb,+ crate::cpu::lut::OP_ORX => rs | rb,+ crate::cpu::lut::OP_XORX => rs ^ rb,+ crate::cpu::lut::OP_NANDX => !(rs & rb),+ crate::cpu::lut::OP_NORX => !(rs | rb),+ crate::cpu::lut::OP_ANDCX => rs & !rb,+ crate::cpu::lut::OP_ORCX => rs | !rb,+ crate::cpu::lut::OP_EQVX => !(rs ^ rb),+ crate::cpu::lut::OP_SLWX => {+ let sh = rb & 0x3F;+ if sh >= 32 { 0 } else { rs << sh }+ }+ crate::cpu::lut::OP_SRWX => {+ let sh = rb & 0x3F;+ if sh >= 32 { 0 } else { rs >> sh }+ }+ crate::cpu::lut::OP_SRAWX => {+ let sh = rb & 0x3F;+ let signed = rs as i32;+ if sh >= 32 {+ ctx.cpu.set_xer_ca(signed < 0);+ (signed >> 31) as u32+ } else if sh == 0 {+ ctx.cpu.set_xer_ca(false);+ rs+ } else {+ let mask = (1u32 << sh) - 1;+ ctx.cpu.set_xer_ca(signed < 0 && (rs & mask) != 0);+ (signed >> sh) as u32+ }+ }+ crate::cpu::lut::OP_SRAWIX => {+ let sh = instr.sh() as u32;+ let signed = rs as i32;+ if sh == 0 {+ ctx.cpu.set_xer_ca(false);+ rs+ } else {+ let mask = (1u32 << sh) - 1;+ ctx.cpu.set_xer_ca(signed < 0 && (rs & mask) != 0);+ (signed >> sh) as u32+ }+ }+ crate::cpu::lut::OP_CNTLZWX => rs.leading_zeros(),+ crate::cpu::lut::OP_EXTSHX => rs as i16 as i32 as u32,+ crate::cpu::lut::OP_EXTSBX => rs as i8 as i32 as u32,+ _ => todo!("Logical instruction with OP = {OP:#x}"),+ };++ ctx.cpu.write_gpr(instr.ra(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+}diff --git a/crates/gekko/src/cpu/interpreter/branch.rs b/crates/gekko/src/cpu/interpreter/branch.rsnew file mode 100644index 0000000..c9b6bd5--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/branch.rs@@ -0,0 +1,51 @@+use crate::cpu::condition::BranchControl;++pub fn branch<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ if instr.lk() {+ ctx.cpu.spr.lr = ctx.cpu.cia.wrapping_add(4);+ }++ match OP {+ crate::cpu::lut::OP_BX => {+ ctx.cpu.nia = if instr.aa() {+ instr.li() as u32+ } else {+ ctx.cpu.cia.wrapping_add_signed(instr.li())+ }+ }+ crate::cpu::lut::OP_BCLRX | crate::cpu::lut::OP_BCX | crate::cpu::lut::OP_BCCTRX => {+ let ctrl = BranchControl::from_bo(instr.bo());+ tracing::trace!("Branch control: {ctrl:?}");++ if ctrl.should_decrement_ctr() {+ ctx.cpu.spr.ctr = ctx.cpu.spr.ctr.wrapping_sub(1);+ }++ let (crf, bit) = (instr.bi() >> 2, instr.bi() & 0b11);+ let condition = match bit {+ 0 => ctx.cpu.cr.get_field(crf).lt(),+ 1 => ctx.cpu.cr.get_field(crf).gt(),+ 2 => ctx.cpu.cr.get_field(crf).eq(),+ 3 => ctx.cpu.cr.get_field(crf).so(),+ _ => panic!("Invalid CR bit index: {}", bit),+ };+ if !ctrl.should_branch(ctx.cpu.spr.ctr, condition) {+ return;+ }++ match OP {+ crate::cpu::lut::OP_BCLRX => ctx.cpu.nia = ctx.cpu.spr.lr,+ crate::cpu::lut::OP_BCX => {+ ctx.cpu.nia = if instr.aa() {+ instr.bd() as u32+ } else {+ ctx.cpu.cia.wrapping_add_signed(instr.bd())+ }+ }+ crate::cpu::lut::OP_BCCTRX => ctx.cpu.nia = ctx.cpu.spr.ctr,+ _ => tracing::error!("missing OP = {OP:#x}"),+ }+ }+ _ => todo!("branch instruction with OP = {OP:#x}"),+ };+}diff --git a/crates/gekko/src/cpu/interpreter/compare.rs b/crates/gekko/src/cpu/interpreter/compare.rsnew file mode 100644index 0000000..f5ddf5b--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/compare.rs@@ -0,0 +1,21 @@+use crate::cpu::condition::ConditionRegister;++pub fn compare<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ let field = match OP {+ crate::cpu::lut::OP_CMP => ConditionRegister::field_from_ord(+ (ctx.cpu.read_gpr(instr.ra()) as i32).cmp(&(ctx.cpu.read_gpr(instr.rb()) as i32)),+ ),+ crate::cpu::lut::OP_CMPI => {+ ConditionRegister::field_from_ord((ctx.cpu.read_gpr(instr.ra()) as i32).cmp(&instr.simm()))+ }+ crate::cpu::lut::OP_CMPL => {+ ConditionRegister::field_from_ord(ctx.cpu.read_gpr(instr.ra()).cmp(&ctx.cpu.read_gpr(instr.rb())))+ }+ crate::cpu::lut::OP_CMPLI => {+ ConditionRegister::field_from_ord(ctx.cpu.read_gpr(instr.ra()).cmp(&(instr.uimm() as u32)))+ }+ _ => todo!("Compare instruction with OP = {OP:#x}"),+ };++ ctx.cpu.cr.set_field(instr.crfd(), field);+}diff --git a/crates/gekko/src/cpu/interpreter/cr_ops.rs b/crates/gekko/src/cpu/interpreter/cr_ops.rsnew file mode 100644index 0000000..a65aec3--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/cr_ops.rs@@ -0,0 +1,41 @@+pub fn cr_ops<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_MTCRF => {+ let crm = instr.crm();+ let rs = ctx.cpu.read_gpr(instr.rs());+ let mut cr = ctx.cpu.cr.raw();+ for i in 0u8..8 {+ if crm & (1 << (7 - i)) != 0 {+ let shift = (7 - i) * 4;+ let mask = 0xFu32 << shift;+ cr = (cr & !mask) | (rs & mask);+ }+ }+ ctx.cpu.cr = crate::cpu::condition::ConditionRegister::from(cr);+ }+ crate::cpu::lut::OP_MFCR => {+ ctx.cpu.write_gpr(instr.rd(), ctx.cpu.cr.raw());+ }+ crate::cpu::lut::OP_MCRF => {+ let src = ctx.cpu.cr.get_field(instr.crfs());+ ctx.cpu.cr.set_field(instr.crfd(), src);+ }+ // CR bit operations+ _ => {+ let a = ctx.cpu.cr.get_bit(instr.crba());+ let b = ctx.cpu.cr.get_bit(instr.crbb());+ let result = match OP {+ crate::cpu::lut::OP_CRXOR => a ^ b,+ crate::cpu::lut::OP_CROR => a | b,+ crate::cpu::lut::OP_CRAND => a & b,+ crate::cpu::lut::OP_CREQV => a == b,+ crate::cpu::lut::OP_CRNOR => !(a | b),+ crate::cpu::lut::OP_CRNAND => !(a & b),+ crate::cpu::lut::OP_CRANDC => a & !b,+ crate::cpu::lut::OP_CRORC => a | !b,+ _ => todo!("CR instruction with OP = {OP:#x}"),+ };+ ctx.cpu.cr.set_bit(instr.crbd(), result);+ }+ }+}diff --git a/crates/gekko/src/cpu/interpreter/fp_ops.rs b/crates/gekko/src/cpu/interpreter/fp_ops.rsnew file mode 100644index 0000000..96eb2dc--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/fp_ops.rs@@ -0,0 +1,183 @@+use crate::cpu::condition::ConditionField;++pub fn fp_ops<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_MTFSFX => {+ let fm = instr.fm();+ let fb = ctx.cpu.read_fpr(instr.rb()).to_bits() as u32;+ let mut mask = 0u32;+ for i in 0u8..8 {+ if fm & (1 << (7 - i)) != 0 {+ mask |= 0xF << ((7 - i) * 4);+ }+ }+ ctx.cpu.fpscr = (ctx.cpu.fpscr & !mask) | (fb & mask);+ }+ crate::cpu::lut::OP_MFFSX => {+ ctx.cpu.write_fpr(instr.rd(), f64::from_bits(ctx.cpu.fpscr as u64));+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_MTFSB0X => {+ ctx.cpu.fpscr &= !(1 << (31 - instr.crbd()));+ }+ crate::cpu::lut::OP_MTFSB1X => {+ ctx.cpu.fpscr |= 1 << (31 - instr.crbd());+ }+ crate::cpu::lut::OP_MTFSFIX => {+ let crfd = instr.crfd();+ let imm = (instr.0 >> 12) & 0xF;+ let shift = (7 - crfd) * 4;+ let mask = 0xFu32 << shift;+ ctx.cpu.fpscr = (ctx.cpu.fpscr & !mask) | (imm << shift);+ }+ crate::cpu::lut::OP_MCRFS => {+ let src_field = instr.crfs();+ let shift = (7 - src_field) * 4;+ let fpscr_nibble = (ctx.cpu.fpscr >> shift) & 0xF;+ ctx.cpu+ .cr+ .set_field(instr.crfd(), ConditionField::from(fpscr_nibble as u8));+ if src_field != 0 && src_field != 1 {+ ctx.cpu.fpscr &= !(0xF << shift);+ }+ }+ crate::cpu::lut::OP_FMRX => {+ ctx.cpu.write_fpr(instr.rd(), ctx.cpu.read_fpr(instr.rb()));+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FNEGX => {+ ctx.cpu.write_fpr(instr.rd(), -ctx.cpu.read_fpr(instr.rb()));+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FABSX => {+ ctx.cpu.write_fpr(instr.rd(), ctx.cpu.read_fpr(instr.rb()).abs());+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FNABSX => {+ ctx.cpu.write_fpr(instr.rd(), -ctx.cpu.read_fpr(instr.rb()).abs());+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FRSPX => {+ ctx.cpu+ .write_fpr(instr.rd(), ctx.cpu.read_fpr(instr.rb()) as f32 as f64);+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FCTIWX => {+ let res = ctx.cpu.read_fpr(instr.rb()).round() as i32;+ ctx.cpu.write_fpr(instr.rd(), f64::from_bits(res as u32 as u64));+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FCTIWZX => {+ let res = ctx.cpu.read_fpr(instr.rb()) as i32;+ ctx.cpu.write_fpr(instr.rd(), f64::from_bits(res as u32 as u64));+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+ }+ crate::cpu::lut::OP_FCMPU | crate::cpu::lut::OP_FCMPO => {+ let fa = ctx.cpu.read_fpr(instr.ra());+ let fb = ctx.cpu.read_fpr(instr.rb());+ let cf = if fa.is_nan() || fb.is_nan() {+ ConditionField::new().with_so(true)+ } else if fa < fb {+ ConditionField::new().with_lt(true)+ } else if fa > fb {+ ConditionField::new().with_gt(true)+ } else {+ ConditionField::new().with_eq(true)+ };+ ctx.cpu.cr.set_field(instr.crfd(), cf);+ }+ crate::cpu::lut::OP_FADDX => fp_write(ctx, &instr, ctx.cpu.read_fpr(instr.ra()) + ctx.cpu.read_fpr(instr.rb())),+ crate::cpu::lut::OP_FSUBX => fp_write(ctx, &instr, ctx.cpu.read_fpr(instr.ra()) - ctx.cpu.read_fpr(instr.rb())),+ crate::cpu::lut::OP_FMULX => fp_write(ctx, &instr, ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc())),+ crate::cpu::lut::OP_FDIVX => fp_write(ctx, &instr, ctx.cpu.read_fpr(instr.ra()) / ctx.cpu.read_fpr(instr.rb())),+ crate::cpu::lut::OP_FMADDX => fp_write(+ ctx,+ &instr,+ ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) + ctx.cpu.read_fpr(instr.rb()),+ ),+ crate::cpu::lut::OP_FMSUBX => fp_write(+ ctx,+ &instr,+ ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) - ctx.cpu.read_fpr(instr.rb()),+ ),+ crate::cpu::lut::OP_FNMADDX => fp_write(+ ctx,+ &instr,+ -(ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) + ctx.cpu.read_fpr(instr.rb())),+ ),+ crate::cpu::lut::OP_FNMSUBX => fp_write(+ ctx,+ &instr,+ -(ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) - ctx.cpu.read_fpr(instr.rb())),+ ),+ crate::cpu::lut::OP_FADDSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) + ctx.cpu.read_fpr(instr.rb())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FSUBSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) - ctx.cpu.read_fpr(instr.rb())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FMULSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FDIVSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) / ctx.cpu.read_fpr(instr.rb())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FMADDSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) + ctx.cpu.read_fpr(instr.rb())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FMSUBSX => fp_write(+ ctx,+ &instr,+ (ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) - ctx.cpu.read_fpr(instr.rb())) as f32 as f64,+ ),+ crate::cpu::lut::OP_FNMADDSX => fp_write(+ ctx,+ &instr,+ (-(ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) + ctx.cpu.read_fpr(instr.rb()))) as f32+ as f64,+ ),+ crate::cpu::lut::OP_FNMSUBSX => fp_write(+ ctx,+ &instr,+ (-(ctx.cpu.read_fpr(instr.ra()) * ctx.cpu.read_fpr(instr.fc()) - ctx.cpu.read_fpr(instr.rb()))) as f32+ as f64,+ ),++ _ => todo!("FP instruction with OP = {OP:#x}"),+ }+}++/// Write FP result to fD and optionally update CR1+#[inline(always)]+fn fp_write(ctx: &mut crate::gekko::Gekko, instr: &crate::cpu::semantics::Instruction, val: f64) {+ ctx.cpu.write_fpr(instr.rd(), val);+ if instr.rc() {+ ctx.cpu.update_cr1();+ }+}diff --git a/crates/gekko/src/cpu/interpreter/rotate.rs b/crates/gekko/src/cpu/interpreter/rotate.rsnew file mode 100644index 0000000..4065de7--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/rotate.rs@@ -0,0 +1,31 @@+#[inline]+fn mask(mb: u32, me: u32) -> u32 {+ let begin = 0xFFFF_FFFFu32 >> mb;+ let end = if me >= 31 { 0 } else { 0xFFFF_FFFFu32 >> (me + 1) };+ if mb <= me { begin & !end } else { begin | !end }+}++pub fn rotate<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ let rs = ctx.cpu.read_gpr(instr.rs());+ let mb = instr.mb() as u32;+ let me = instr.me() as u32;++ let res = match OP {+ crate::cpu::lut::OP_RLWINMX => rs.rotate_left(instr.sh() as u32) & mask(mb, me),+ crate::cpu::lut::OP_RLWIMIX => {+ let m = mask(mb, me);+ let r = rs.rotate_left(instr.sh() as u32);+ (r & m) | (ctx.cpu.read_gpr(instr.ra()) & !m)+ }+ crate::cpu::lut::OP_RLWNMX => {+ let sh = ctx.cpu.read_gpr(instr.rb()) & 0x1F;+ rs.rotate_left(sh) & mask(mb, me)+ }+ _ => todo!("Rotate instruction with OP = {OP:#x}"),+ };++ ctx.cpu.write_gpr(instr.ra(), res);+ if instr.rc() {+ ctx.cpu.update_cr0(res);+ }+}diff --git a/crates/gekko/src/cpu/interpreter/store_load.rs b/crates/gekko/src/cpu/interpreter/store_load.rsnew file mode 100644index 0000000..e63c4f0--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/store_load.rs@@ -0,0 +1,226 @@+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());+ 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());+ 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());+ 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);+ }+ }+ crate::cpu::lut::OP_LWZ | crate::cpu::lut::OP_LWZU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_u32(addr);+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LWZU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LBZ | crate::cpu::lut::OP_LBZU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_u8(addr) as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LBZU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LHZ | crate::cpu::lut::OP_LHZU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_u16(addr) as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LHZU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LHA | crate::cpu::lut::OP_LHAU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_u16(addr) as i16 as i32 as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LHAU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LMW => {+ let mut addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ for r in instr.rd()..32 {+ let val = ctx.read_u32(addr);+ ctx.cpu.write_gpr(r, val);+ addr = addr.wrapping_add(4);+ }+ }+ crate::cpu::lut::OP_STMW => {+ let mut addr = ctx.cpu.read_gpr(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);+ addr = addr.wrapping_add(4);+ }+ }+ crate::cpu::lut::OP_LWZX | crate::cpu::lut::OP_LWZUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_u32(addr);+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LWZUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LBZX | crate::cpu::lut::OP_LBZUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_u8(addr) as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LBZUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LHZX | crate::cpu::lut::OP_LHZUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_u16(addr) as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LHZUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LHAX | crate::cpu::lut::OP_LHAUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_u16(addr) as i16 as i32 as u32;+ ctx.cpu.write_gpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LHAUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STWX | crate::cpu::lut::OP_STWUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.write_u32(addr, ctx.cpu.read_gpr(instr.rs()));+ if OP == crate::cpu::lut::OP_STWUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STBX | crate::cpu::lut::OP_STBUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.write_u8(addr, ctx.cpu.read_gpr(instr.rs()) as u8);+ if OP == crate::cpu::lut::OP_STBUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STHX | crate::cpu::lut::OP_STHUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.write_u16(addr, ctx.cpu.read_gpr(instr.rs()) as u16);+ if OP == crate::cpu::lut::OP_STHUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ _ => todo!("Store/Load instruction with OP = {OP:#x}"),+ }+}++pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_LFD | crate::cpu::lut::OP_LFDU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_f64(addr);+ ctx.cpu.write_fpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LFDU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STFD | crate::cpu::lut::OP_STFDU => {+ let addr = ctx.cpu.read_gpr(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);+ }+ }+ crate::cpu::lut::OP_LFS | crate::cpu::lut::OP_LFSU => {+ let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());+ let val = ctx.read_f32(addr);+ ctx.cpu.write_fpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LFSU {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STFS | crate::cpu::lut::OP_STFSU => {+ let addr = ctx.cpu.read_gpr(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);+ }+ }+ crate::cpu::lut::OP_LFSX | crate::cpu::lut::OP_LFSUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_f32(addr);+ ctx.cpu.write_fpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LFSUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_LFDX | crate::cpu::lut::OP_LFDUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ let val = ctx.read_f64(addr);+ ctx.cpu.write_fpr(instr.rd(), val);+ if OP == crate::cpu::lut::OP_LFDUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STFSX | crate::cpu::lut::OP_STFSUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.write_f32(addr, ctx.cpu.read_fpr(instr.rs()));+ if OP == crate::cpu::lut::OP_STFSUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ crate::cpu::lut::OP_STFDX | crate::cpu::lut::OP_STFDUX => {+ let addr = ctx+ .cpu+ .read_gpr_or_zero(instr.ra())+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));+ ctx.write_f64(addr, ctx.cpu.read_fpr(instr.rs()));+ if OP == crate::cpu::lut::OP_STFDUX {+ ctx.cpu.write_gpr(instr.ra(), addr);+ }+ }+ _ => todo!("FP Store/Load instruction with OP = {OP:#x}"),+ }+}diff --git a/crates/gekko/src/cpu/interpreter/stubs.rs b/crates/gekko/src/cpu/interpreter/stubs.rsnew file mode 100644index 0000000..41578f0--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/stubs.rs@@ -0,0 +1,35 @@+macro_rules! stub {+ ($($name:ident),* $(,)?) => {+ $(+ #[rustfmt::skip]+ pub fn $name(+ _ctx: &mut crate::gekko::Gekko,+ _instr: crate::cpu::semantics::Instruction,+ ) {+ todo!(stringify!($name))+ }+ )*+ };+}++stub! {+ twi,+ ps_cmpu0, ps_cmpo0, ps_cmpu1, ps_cmpo1,+ ps_res, ps_rsqrte, ps_neg, ps_mr, ps_nabs, ps_abs,+ ps_merge00, ps_merge01, ps_merge10, ps_merge11,+ psq_lx, psq_stx, psq_lux, psq_stux,+ ps_sum0, ps_sum1, ps_muls0, ps_muls1,+ ps_madds0, ps_madds1,+ ps_div, ps_sub, ps_add, ps_sel, ps_mul,+ ps_msub, ps_madd, ps_nmsub, ps_nmadd,+ sc, tw,+ lwarx, stwcx_dot,+ mtsrin, mcrxr,+ lwbrx, lswx, lswi, mfsrin,+ stswx, stwbrx, stswi,+ lhbrx,+ eciwx, ecowx,+ sthbrx, stfiwx,+ psq_l, psq_lu, psq_st, psq_stu,+ fsqrtsx, fresx, fsqrtx, fselx, frsqrtex,+}diff --git a/crates/gekko/src/cpu/interpreter/system.rs b/crates/gekko/src/cpu/interpreter/system.rsnew file mode 100644index 0000000..4a07345--- /dev/null+++ b/crates/gekko/src/cpu/interpreter/system.rs@@ -0,0 +1,57 @@+use crate::cpu::sr::Sr;++pub fn msr<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_MTMSR => {+ ctx.cpu.msr = crate::cpu::msr::Msr::from(ctx.cpu.read_gpr(instr.rs()));+ }+ crate::cpu::lut::OP_MFMSR => {+ ctx.cpu.write_gpr(instr.rd(), ctx.cpu.msr.raw());+ }+ crate::cpu::lut::OP_RFI => {+ const RFI_MSR_MASK: u32 = 0x0000_FF73;+ ctx.cpu.msr =+ crate::cpu::msr::Msr::from((ctx.cpu.msr.raw() & !RFI_MSR_MASK) | (ctx.cpu.spr.srr1 & RFI_MSR_MASK));+ ctx.cpu.nia = ctx.cpu.spr.srr0.value() << 2;+ }+ _ => todo!("MSR instruction with OP = {OP:#x}"),+ }+}++pub fn spr<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_MTSPR => {+ ctx.cpu.spr.write(instr.spr_swapped(), ctx.cpu.read_gpr(instr.rs()));+ }+ crate::cpu::lut::OP_MFSPR => {+ ctx.cpu.write_gpr(instr.rd(), ctx.cpu.spr.read(instr.spr_swapped()));+ }+ _ => todo!("SPR instruction with OP = {OP:#x}"),+ }+}++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 mftb(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ let tbr = instr.spr_swapped();+ let val = match tbr {+ 268 => ctx.scheduler.cycles as u32, // TBL+ 269 => (ctx.scheduler.cycles >> 32) as u32, // TBU+ _ => panic!("unknown TBR {tbr}"),+ };+ ctx.cpu.write_gpr(instr.rd(), val);+}++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}");+}diff --git a/crates/gekko/src/cpu/msr.rs b/crates/gekko/src/cpu/msr.rsindex 301472d..6b5749a 100644--- a/crates/gekko/src/cpu/msr.rs+++ b/crates/gekko/src/cpu/msr.rs@@ -1,17 +1,30 @@#[chapa::bitfield(u32, width = 32, order = msb0)]#[derive(Clone, Copy, Default)]pub struct Msr {- #[bits(13, alias = "pow")] pub power_management: bool,- #[bits(15, alias = "ile")] pub exception_little_endian: bool,- #[bits(16, alias = "ee")] pub external_interrupt_enable: bool,- #[bits(17, alias = "pr")] pub privilege_level: bool,- #[bits(18, alias = "fp")] pub floating_point_available: bool,- #[bits(19, alias = "me")] pub machine_check_enable: bool,- #[bits(20, alias = "fe0")] pub floating_point_exception_mode_0: bool,- #[bits(21, alias = "se")] pub single_step_trace: bool,- #[bits(22, alias = "be")] pub branch_trace: bool,- #[bits(23, alias = "fe1")] pub floating_point_exception_mode_1: bool,- #[bits(25, alias = "ip")] pub exception_prefix: bool,- #[bits(26, alias = "ir")] pub instruction_address_translation: bool,- #[bits(27, alias = "dr")] pub data_address_translation: bool,-}\ No newline at end of file+ #[bits(13, alias = "pow")]+ pub power_management: bool,+ #[bits(15, alias = "ile")]+ pub exception_little_endian: bool,+ #[bits(16, alias = "ee")]+ pub external_interrupt_enable: bool,+ #[bits(17, alias = "pr")]+ pub privilege_level: bool,+ #[bits(18, alias = "fp")]+ pub floating_point_available: bool,+ #[bits(19, alias = "me")]+ pub machine_check_enable: bool,+ #[bits(20, alias = "fe0")]+ pub floating_point_exception_mode_0: bool,+ #[bits(21, alias = "se")]+ pub single_step_trace: bool,+ #[bits(22, alias = "be")]+ pub branch_trace: bool,+ #[bits(23, alias = "fe1")]+ pub floating_point_exception_mode_1: bool,+ #[bits(25, alias = "ip")]+ pub exception_prefix: bool,+ #[bits(26, alias = "ir")]+ pub instruction_address_translation: bool,+ #[bits(27, alias = "dr")]+ pub data_address_translation: bool,+}diff --git a/crates/gekko/src/cpu/semantics.rs b/crates/gekko/src/cpu/semantics.rsindex ea30569..d3fbd56 100644--- a/crates/gekko/src/cpu/semantics.rs+++ b/crates/gekko/src/cpu/semantics.rs@@ -19,4 +19,3 @@ impl Instruction {(raw >> 5) | ((raw & 0x1f) << 5)}}-diff --git a/crates/gekko/src/cpu/spr.rs b/crates/gekko/src/cpu/spr.rsindex b9bf9cb..9f2b98e 100644--- a/crates/gekko/src/cpu/spr.rs+++ b/crates/gekko/src/cpu/spr.rs@@ -5,9 +5,22 @@ pub struct Srr0 {pub value: u32, // low 2 bits are always 0}+#[chapa::bitfield(u32, width = 32, order = msb0)]+#[derive(Clone, Copy, Default)]+pub struct Xer {+ #[bits(0, alias = "so")]+ pub summary_overflow: bool,+ #[bits(1, alias = "ov")]+ pub overflow: bool,+ #[bits(2, alias = "ca")]+ pub carry: bool,+ #[bits(25..=31)]+ pub byte_count: u8,+}+#[derive(Default)]pub struct Spr {- pub xer: u32,+ pub xer: Xer,pub lr: u32,pub ctr: u32,pub dsisr: u32,@@ -80,7 +93,7 @@ pub struct Spr {impl Spr {pub fn read(&self, spr_num: u32) -> u32 {match spr_num {- 1 => self.xer,+ 1 => self.xer.raw(),8 => self.lr,9 => self.ctr,18 => self.dsisr,@@ -154,7 +167,7 @@ impl Spr {pub fn write(&mut self, spr_num: u32, value: u32) {match spr_num {- 1 => self.xer = value,+ 1 => self.xer = Xer::from(value),8 => self.lr = value,9 => self.ctr = value,18 => self.dsisr = value,diff --git a/crates/gekko/src/gekko.rs b/crates/gekko/src/gekko.rsindex 82f22d9..cc0bd11 100644--- a/crates/gekko/src/gekko.rs+++ b/crates/gekko/src/gekko.rs@@ -51,6 +51,34 @@ impl Gekko {}}+ /// Load a 64-bit double from memory+ #[inline]+ pub fn read_f64(&mut self, addr: u32) -> f64 {+ let hi = self.read_u32(addr) as u64;+ let lo = self.read_u32(addr.wrapping_add(4)) as u64;+ f64::from_bits((hi << 32) | lo)+ }++ /// Store a 64-bit double to memory+ #[inline]+ pub fn write_f64(&mut self, addr: u32, val: f64) {+ let bits = val.to_bits();+ self.write_u32(addr, (bits >> 32) as u32);+ self.write_u32(addr.wrapping_add(4), bits as u32);+ }++ /// Load a 32-bit float from memory, return as f64+ #[inline]+ pub fn read_f32(&mut self, addr: u32) -> f64 {+ f32::from_bits(self.read_u32(addr)) as f64+ }++ /// Store f64 as 32-bit float to memory+ #[inline]+ pub fn write_f32(&mut self, addr: u32, val: f64) {+ self.write_u32(addr, (val as f32).to_bits());+ }+pub fn run_until_event(&mut self) {self.cpu.cia = self.cpu.pc;self.cpu.nia = self.cpu.cia.wrapping_add(4);diff --git a/crates/gekko/src/lib.rs b/crates/gekko/src/lib.rsindex c426e49..43c0912 100644--- a/crates/gekko/src/lib.rs+++ b/crates/gekko/src/lib.rs@@ -1,6 +1,5 @@pub mod cpu;-pub mod scheduler;pub mod gekko;pub mod mmio;+pub mod scheduler;pub mod vi;-diff --git a/crates/gekko/src/mmio.rs b/crates/gekko/src/mmio.rsindex ac1b939..b29aff9 100644--- a/crates/gekko/src/mmio.rs+++ b/crates/gekko/src/mmio.rs@@ -1,10 +1,10 @@#[cfg(test)]mod tests;+pub mod bus;pub mod constants;pub mod macros;pub mod traits;-pub mod bus;use constants::*;@@ -28,18 +28,13 @@ impl Mmio {fn resolve(&self, phys: u32) -> (&[u8], usize) {match phys {RAM_BASE..=RAM_END => (&self.ram, phys as usize),- EFB_BASE..=EFB_END => {- (&self.efb, (phys - EFB_BASE) as usize)- },+ EFB_BASE..=EFB_END => (&self.efb, (phys - EFB_BASE) as usize),HW_REG_BASE..=HW_REG_END => {tracing::warn!(phys_addr = format!("{:08X}", phys), "read from mmio");(&self.hwr, (phys - HW_REG_BASE) as usize)}_ => {- tracing::error!(- phys_addr = format!("{:08X}", phys),- "unmapped physical read"- );+ tracing::error!(phys_addr = format!("{:08X}", phys), "unmapped physical read");(&self.ram, 0)}}@@ -57,10 +52,7 @@ impl Mmio {(&mut self.hwr, (phys - HW_REG_BASE) as usize)}_ => {- tracing::error!(- phys_addr = format!("{:08X}", phys),- "unmapped physical write"- );+ tracing::error!(phys_addr = format!("{:08X}", phys), "unmapped physical write");(&mut self.ram, 0)}}diff --git a/crates/gekko/src/mmio/constants.rs b/crates/gekko/src/mmio/constants.rsindex a8eb83c..19552bd 100644--- a/crates/gekko/src/mmio/constants.rs+++ b/crates/gekko/src/mmio/constants.rs@@ -12,4 +12,4 @@ pub const HW_REG_SIZE: usize = 0x0080_0000; // 8 MB// Hardware block address ranges (physical)pub const VI_BASE: u32 = 0x0C00_2000;-pub const VI_END: u32 = 0x0C00_27FF;\ No newline at end of file+pub const VI_END: u32 = 0x0C00_27FF;diff --git a/crates/gekko/src/scheduler.rs b/crates/gekko/src/scheduler.rsindex 1d81c65..7d7aaf5 100644--- a/crates/gekko/src/scheduler.rs+++ b/crates/gekko/src/scheduler.rs@@ -1,3 +1,3 @@pub struct Scheduler {pub cycles: u64,-}\ No newline at end of file+}diff --git a/crates/gekko/src/vi.rs b/crates/gekko/src/vi.rsindex ff3f0a2..8b82595 100644--- a/crates/gekko/src/vi.rs+++ b/crates/gekko/src/vi.rs@@ -1,6 +1,6 @@+pub mod regs;#[cfg(test)]mod tests;-pub mod regs;use crate::{gekko::Gekko,diff --git a/crates/image/src/lib.rs b/crates/image/src/lib.rsindex 433fbd8..2154e6e 100644--- a/crates/image/src/lib.rs+++ b/crates/image/src/lib.rs@@ -30,36 +30,22 @@ impl Dol {let mut data_sections = Vec::new();for i in 0..=6 {- let offset =- u32::from_be_bytes(data[0x00 + (i * 4)..0x00 + (i * 4) + 4].try_into().unwrap());- let vaddr =- u32::from_be_bytes(data[0x48 + (i * 4)..0x48 + (i * 4) + 4].try_into().unwrap());- let size =- u32::from_be_bytes(data[0x90 + (i * 4)..0x90 + (i * 4) + 4].try_into().unwrap());+ let offset = u32::from_be_bytes(data[0x00 + (i * 4)..0x00 + (i * 4) + 4].try_into().unwrap());+ let vaddr = u32::from_be_bytes(data[0x48 + (i * 4)..0x48 + (i * 4) + 4].try_into().unwrap());+ let size = u32::from_be_bytes(data[0x90 + (i * 4)..0x90 + (i * 4) + 4].try_into().unwrap());if size > 0 {- text_sections.push(Section {- offset,- vaddr,- size,- });+ text_sections.push(Section { offset, vaddr, size });}}for i in 0..=10 {- let offset =- u32::from_be_bytes(data[0x1C + (i * 4)..0x1C + (i * 4) + 4].try_into().unwrap());- let vaddr =- u32::from_be_bytes(data[0x64 + (i * 4)..0x64 + (i * 4) + 4].try_into().unwrap());- let size =- u32::from_be_bytes(data[0xAC + (i * 4)..0xAC + (i * 4) + 4].try_into().unwrap());+ let offset = u32::from_be_bytes(data[0x1C + (i * 4)..0x1C + (i * 4) + 4].try_into().unwrap());+ let vaddr = u32::from_be_bytes(data[0x64 + (i * 4)..0x64 + (i * 4) + 4].try_into().unwrap());+ let size = u32::from_be_bytes(data[0xAC + (i * 4)..0xAC + (i * 4) + 4].try_into().unwrap());if size > 0 {- data_sections.push(Section {- offset,- vaddr,- size,- });+ data_sections.push(Section { offset, vaddr, size });}}diff --git a/crates/image/src/symbols.rs b/crates/image/src/symbols.rsindex 9030a25..eb1d570 100644--- a/crates/image/src/symbols.rs+++ b/crates/image/src/symbols.rs@@ -25,10 +25,7 @@ impl SymbolTable {/// Find the symbol containing `addr` (i.e. `sym.addr <= addr < sym.addr + sym.size`)pub fn lookup(&self, addr: u32) -> Option<&Symbol> {- let idx = self- .symbols- .partition_point(|s| s.addr <= addr)- .checked_sub(1)?;+ let idx = self.symbols.partition_point(|s| s.addr <= addr).checked_sub(1)?;let sym = &self.symbols[idx];if addr < sym.addr.wrapping_add(sym.size) {Some(sym)@@ -45,7 +42,6 @@ impl SymbolTable {/// Returns `true` if `addr` is the entry point of a function symbolpub fn is_function_entry(&self, addr: u32) -> bool {- self.lookup_exact(addr)- .is_some_and(|s| s.kind == SymbolKind::Func)+ self.lookup_exact(addr).is_some_and(|s| s.kind == SymbolKind::Func)}}diff --git a/crates/tinyemu/src/fmt.rs b/crates/tinyemu/src/fmt.rsindex 29b678e..dc04b4a 100644--- a/crates/tinyemu/src/fmt.rs+++ b/crates/tinyemu/src/fmt.rs@@ -21,11 +21,7 @@ pub fn colorize(tok: &AsmToken<'_>) -> String {pub fn colorize_instr(instr: &disasm::gekko::GekkoInstruction) -> String {let text = format!("{}", instr);let tokens = tokenizer::tokenize(&text);- tokens- .into_iter()- .map(|t| colorize(&t))- .collect::<Vec<_>>()- .join("")+ tokens.into_iter().map(|t| colorize(&t)).collect::<Vec<_>>().join("")}pub fn gpr_refs(instr: &disasm::gekko::GekkoInstruction) -> Vec<u8> {diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rsindex a5bf780..748d5f7 100644--- a/crates/tinyemu/src/main.rs+++ b/crates/tinyemu/src/main.rs@@ -31,8 +31,7 @@ struct Args {}fn parse_hex_addr(s: &str) -> Result<u32, String> {- u32::from_str_radix(s.trim_start_matches("0x"), 16)- .map_err(|e| format!("invalid hex address: {e}"))+ u32::from_str_radix(s.trim_start_matches("0x"), 16).map_err(|e| format!("invalid hex address: {e}"))}fn main() {@@ -67,11 +66,7 @@ fn main() {render_kitty(&pixels, video_format.columns(), video_format.lines());}-fn run_emulator(- gekko: &mut gekko::gekko::Gekko,- args: &Args,- symbols: Option<&image::symbols::SymbolTable>,-) {+fn run_emulator(gekko: &mut gekko::gekko::Gekko, args: &Args, symbols: Option<&image::symbols::SymbolTable>) {let mut prev_snapshot = CpuSnapshot::from_cpu(&gekko.cpu);let mut prev_pc = gekko.cpu.pc;let mut in_busyloop = false;@@ -194,23 +189,22 @@ fn dump_registers(curr: &CpuSnapshot, prev: &CpuSnapshot) {("cr7", curr.cr.cr7(), prev.cr.cr7()),];- let fmt_cr_field = |label: &str,- val: gekko::cpu::condition::ConditionField,- prev_val: gekko::cpu::condition::ConditionField| {- let flags = format!(- "{}{}{}{}",- if val.lt() { "L" } else { "·" },- if val.gt() { "G" } else { "·" },- if val.eq() { "Z" } else { "·" },- if val.so() { "O" } else { "·" },- );- let text = format!("{}[{}] ", label, flags);- if val.raw() != prev_val.raw() {- format!("{}", text.bright_red().bold())- } else {- format!("{}", text.dimmed())- }- };+ let fmt_cr_field =+ |label: &str, val: gekko::cpu::condition::ConditionField, prev_val: gekko::cpu::condition::ConditionField| {+ let flags = format!(+ "{}{}{}{}",+ if val.lt() { "L" } else { "·" },+ if val.gt() { "G" } else { "·" },+ if val.eq() { "Z" } else { "·" },+ if val.so() { "O" } else { "·" },+ );+ let text = format!("{}[{}] ", label, flags);+ if val.raw() != prev_val.raw() {+ format!("{}", text.bright_red().bold())+ } else {+ format!("{}", text.dimmed())+ }+ };let cr_line: String = cr_fields.iter()diff --git a/rustfmt.toml b/rustfmt.tomlnew file mode 100644index 0000000..7530651--- /dev/null+++ b/rustfmt.toml@@ -0,0 +1 @@+max_width = 120