Compare commits

...
4 Commits
Author SHA1 Message Date
dingusdev 5bc1260dbb Start MTSPR/MFSPR refactor 2026-02-11 08:02:40 -07:00
dingusdev e46414721d Name DSISR bits 2026-01-22 19:07:43 -07:00
dingusdev 79784cd36c Initial improvements 2026-01-21 21:17:52 -07:00
joevt d693b0f443 maciotwo: Fix IDE read/write mask again.
Use the entire 4K range.
2026-01-20 07:07:11 -07:00
4 changed files with 75 additions and 22 deletions

No files matched your search

+6
View File
@@ -106,6 +106,7 @@ enum SPR : int {
SPRG1 = 273,
SPRG2 = 274,
SPRG3 = 275,
EAR = 282,
TBL_S = 284, // supervisor TBL
TBU_S = 285, // supervisor TBU
PVR = 287,
@@ -303,6 +304,11 @@ enum XER : uint32_t {
SO = 1UL << 31
};
enum DSISR : uint32_t {
PROT = 1UL << 27,
STORE = 1UL << 25
};
//for inf and nan checks
enum FPOP : int {
DIV = 0x12,
+20 -14
View File
@@ -540,12 +540,11 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
}
}
static TLBEntry* itlb2_refill(uint32_t guest_va)
{
static TLBEntry* itlb2_refill(uint32_t guest_va) {
BATResult bat_res;
uint32_t phys_addr;
TLBEntry *tlb_entry;
uint16_t flags = 0;
TLBEntry* tlb_entry = nullptr;
uint16_t flags = 0;
/* instruction address translation if enabled */
if (ppc_state.msr & MSR::IR) {
@@ -555,11 +554,13 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
} else {
bat_res = ppc_block_address_translation<BATType::IBAT>(guest_va);
}
if (bat_res.hit) {
// check block protection
// only PP = 0 (no access) causes ISI exception
if (!bat_res.prot) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000);
return nullptr; // Stop refill on exception
}
phys_addr = bat_res.phys;
flags |= TLBFlags::TLBE_FROM_BAT; // tell the world we come from
@@ -567,7 +568,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
// page address translation
PATResult pat_res = page_address_translation(guest_va, true, !!(ppc_state.msr & MSR::PR), 0);
phys_addr = pat_res.phys;
flags = TLBFlags::TLBE_FROM_PAT; // tell the world we come from
flags |= TLBFlags::TLBE_FROM_PAT; // tell the world we come from
}
} else { // instruction translation disabled
phys_addr = guest_va;
@@ -577,18 +578,23 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
AddressMapEntry* rgn_desc = mem_ctrl_instance->find_range(phys_addr);
if (rgn_desc) {
if (rgn_desc->type & RT_MMIO) {
ABORT_F("Instruction fetch from MMIO region at 0x%08X!\n", phys_addr);
// TODO: ISI or Machine Check for this?
mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000);
}
// refill the secondary TLB
const uint32_t tag = guest_va & ~0xFFFUL;
tlb_entry = tlb2_target_entry<TLBType::ITLB>(tag);
tlb_entry->tag = tag;
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
(phys_addr - rgn_desc->start);
const uint32_t page_base = guest_va & ~0xFFFUL;
tlb_entry = tlb2_target_entry<TLBType::ITLB>(page_base);
tlb_entry->tag = page_base;
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
// Calculate offset based on page base to ensure alignment
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - (int64_t)page_base +
((phys_addr & ~0xFFFUL) - rgn_desc->start);
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
} else {
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
// TODO: ISI or Machine Check for this?
mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000);
}
return tlb_entry;
@@ -618,7 +624,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
LOG_F(9, "BAT DSI exception in TLB2 refill!");
if (!is_dbg)
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
ppc_state.spr[SPR::DSISR] = DSISR::PROT | (is_write << 25);
ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0);
}
+45 -4
View File
@@ -936,6 +936,11 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
}
switch (ref_spr) {
case SPR::XER:
case SPR::LR:
case SPR::CTR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::MQ:
if (!(is_601 || include_601)) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
@@ -987,8 +992,23 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
break;
}
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::PVR:
case SPR::EAR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MFSPR: %d", ref_spr);
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
}
}
@@ -1010,6 +1030,13 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
uint32_t val = ppc_state.gpr[reg_d];
switch (ref_spr) {
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::LR:
case SPR::CTR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::MQ:
if (is_601 || include_601)
ppc_state.spr[ref_spr] = val;
@@ -1019,13 +1046,13 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case SPR::RTCL_U:
case SPR::RTCU_U:
case SPR::DEC_U:
if (!is_601) {
if (is_601) {
ppc_state.spr[ref_spr] = val;
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
break;
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::SDR1:
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
@@ -1058,6 +1085,19 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
ppc_state.spr[TBL_S] = (uint32_t)tbr_wr_value;
ppc_state.spr[TBU_S] = val;
break;
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::EAR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.spr[ref_spr] = val;
break;
case SPR::PVR:
break;
case 528:
@@ -1084,6 +1124,7 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MTSPR: %d", ref_spr);
ppc_state.spr[ref_spr] = val;
}
}
+4 -4
View File
@@ -110,10 +110,10 @@ uint32_t MacIoTwo::read(uint32_t rgn_start, uint32_t offset, int size) {
value = this->viacuda->read((offset >> 9) & 0xF);
break;
case 0x20: // IDE 0
value = this->ide_0->read((offset >> 4) & 0x3F, size);
value = this->ide_0->read((offset >> 4) & 0xFF, size);
break;
case 0x21: // IDE 1
value = this->ide_1 ? this->ide_1->read((offset >> 4) & 0x3F, size) : 0;
value = this->ide_1 ? this->ide_1->read((offset >> 4) & 0xFF, size) : 0;
break;
default:
if (sub_addr >= 0x60) {
@@ -172,11 +172,11 @@ void MacIoTwo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int si
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 0x20: // IDE 0
this->ide_0->write((offset >> 4) & 0x3F, value, size);
this->ide_0->write((offset >> 4) & 0xFF, value, size);
break;
case 0x21: // IDE 1
if (this->ide_1)
this->ide_1->write((offset >> 4) & 0x3F, value, size);
this->ide_1->write((offset >> 4) & 0xFF, value, size);
break;
default:
if (sub_addr >= 0x60) {