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
7 changed files with 85 additions and 62 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;
}
}
+1 -2
View File
@@ -67,8 +67,7 @@ protected:
virtual void set_register_3() {}
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
uint8_t led_state = 0;
uint8_t srq_flag = 0;
uint8_t my_addr = 0;
uint8_t dev_handler_id = 0;
bool got_collision = false;
+9 -36
View File
@@ -35,18 +35,13 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
if (this->pending_events.size() == 1) {
this->srq_flag = 1;
}
}
void AdbKeyboard::reset() {
this->my_addr = ADB_ADDR_KBD;
this->dev_handler_id = 2; // Extended ADB keyboard
this->exc_event_flag = 1;
this->srq_flag = 0; // don't process keyboard service requests yet
this->led_state = 0; // LEDs off
this->srq_flag = 1; // enable service requests
this->pending_events.clear();
}
@@ -58,11 +53,6 @@ bool AdbKeyboard::get_register_0() {
out_buf[0] = this->consume_pending_event();
out_buf[1] = this->consume_pending_event();
this->host_obj->set_output_count(2);
if (this->pending_events.empty()) {
this->srq_flag = 0;
}
return true;
}
@@ -78,7 +68,14 @@ uint8_t AdbKeyboard::consume_pending_event() {
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
this->pending_events.pop_front();
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
uint8_t key_state = 0;
if (event->flags & KEYBOARD_EVENT_DOWN) {
key_state = 0;
} else if (event->flags & KEYBOARD_EVENT_UP) {
key_state = 1;
} else {
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
}
if (this->dev_handler_id != 3) {
switch (event->key) {
@@ -91,31 +88,7 @@ uint8_t AdbKeyboard::consume_pending_event() {
return (key_state << 7) | (event->key & 0x7F);
}
bool AdbKeyboard::get_register_2() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = 0;
out_buf[1] = this->led_state & 0x07;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_2() {
if (this->host_obj->get_input_count() < 2)
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
this->led_state = in_data[1] & 0x07;
}
bool AdbKeyboard::get_register_3() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
out_buf[1] = this->dev_handler_id;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_3() {
-2
View File
@@ -46,8 +46,6 @@ public:
void event_handler(const KeyboardEvent& event);
bool get_register_0() override;
bool get_register_2() override;
bool get_register_3() override;
void set_register_2() override;
void set_register_3() override;
+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) {