mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
3
Commits
config_speed
...
mmu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bc1260dbb | ||
|
|
e46414721d | ||
|
|
79784cd36c |
No files matched your search
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user