2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2021-10-04 22:26:43 +00:00
|
|
|
Copyright (C) 2018-21 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 17:38:32 +00:00
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <cpu/ppc/ppcemu.h>
|
|
|
|
#include <devices/common/dbdma.h>
|
|
|
|
#include <devices/common/viacuda.h>
|
|
|
|
#include <devices/ioctrl/macio.h>
|
|
|
|
#include <devices/sound/awacs.h>
|
|
|
|
#include <machines/machinebase.h>
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2021-10-04 22:26:43 +00:00
|
|
|
#include <functional>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <iostream>
|
2021-09-15 22:46:38 +00:00
|
|
|
#include <loguru.hpp>
|
2019-08-23 21:34:19 +00:00
|
|
|
|
2019-10-07 01:18:18 +00:00
|
|
|
/** Heathrow Mac I/O device emulation.
|
|
|
|
|
2021-10-04 22:26:43 +00:00
|
|
|
Author: Max Poliakovski
|
2019-10-07 01:18:18 +00:00
|
|
|
*/
|
|
|
|
|
2019-08-23 21:34:19 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
|
|
|
this->nvram = new NVram();
|
2020-03-14 14:39:34 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
this->viacuda = new ViaCuda();
|
2020-03-14 14:39:34 +00:00
|
|
|
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
2020-03-15 16:24:40 +00:00
|
|
|
|
2021-10-04 22:26:43 +00:00
|
|
|
// initialize sound chip and its DMA output channel, then wire them together
|
2021-10-04 21:46:19 +00:00
|
|
|
this->screamer = new AwacsScreamer();
|
2021-10-04 22:26:43 +00:00
|
|
|
this->snd_out_dma = new DMAChannel();
|
2020-03-26 01:07:12 +00:00
|
|
|
this->screamer->set_dma_out(this->snd_out_dma);
|
2021-10-04 22:26:43 +00:00
|
|
|
this->snd_out_dma->set_callbacks(
|
|
|
|
std::bind(&AwacsScreamer::dma_start, this->screamer),
|
|
|
|
std::bind(&AwacsScreamer::dma_end, this->screamer)
|
|
|
|
);
|
2021-08-22 22:20:28 +00:00
|
|
|
|
|
|
|
this->mesh = new MESHController(HeathrowMESHID);
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
HeathrowIC::~HeathrowIC() {
|
2020-01-07 10:52:38 +00:00
|
|
|
if (this->nvram)
|
2020-05-12 18:55:45 +00:00
|
|
|
delete (this->nvram);
|
2020-01-07 10:52:38 +00:00
|
|
|
|
2019-08-27 12:14:12 +00:00
|
|
|
if (this->viacuda)
|
2020-05-12 18:55:45 +00:00
|
|
|
delete (this->viacuda);
|
2021-08-22 22:20:28 +00:00
|
|
|
|
|
|
|
if (this->mesh)
|
|
|
|
delete (this->mesh);
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
2019-08-23 21:34:19 +00:00
|
|
|
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (reg_offs) {
|
2020-05-12 18:55:45 +00:00
|
|
|
case CFG_REG_BAR0: // base address register
|
2020-02-27 02:51:07 +00:00
|
|
|
value = LE2BE(value);
|
2019-08-23 21:34:19 +00:00
|
|
|
if (value == 0xFFFFFFFF) {
|
2020-05-12 18:55:45 +00:00
|
|
|
LOG_F(
|
|
|
|
ERROR,
|
|
|
|
"%s err: BAR0 block size determination not \
|
|
|
|
implemented yet \n",
|
|
|
|
this->name.c_str());
|
|
|
|
} else if (value & 1) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
2020-05-12 18:55:45 +00:00
|
|
|
} else if (value & 0x06) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2019-08-27 12:14:12 +00:00
|
|
|
this->base_addr = value & 0xFFF80000;
|
2019-08-23 21:34:19 +00:00
|
|
|
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
2020-02-25 02:55:33 +00:00
|
|
|
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
2019-08-23 21:34:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
2020-03-18 16:34:03 +00:00
|
|
|
uint32_t res = 0;
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
switch (offset >> 8) {
|
2020-03-18 16:34:03 +00:00
|
|
|
case 8:
|
|
|
|
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
|
|
|
switch (offset >> 8) {
|
2020-03-18 16:34:03 +00:00
|
|
|
case 8:
|
|
|
|
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
2019-08-27 12:14:12 +00:00
|
|
|
uint32_t res = 0;
|
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-01-08 18:33:38 +00:00
|
|
|
unsigned sub_addr = (offset >> 12) & 0x7F;
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (sub_addr) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0:
|
|
|
|
res = mio_ctrl_read(offset, size);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-03-18 16:34:03 +00:00
|
|
|
res = dma_read(offset - 0x8000, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
2021-08-22 22:20:28 +00:00
|
|
|
case 0x10:
|
|
|
|
res = this->mesh->read((offset >> 4) & 0xF);
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x14:
|
2020-03-15 16:24:40 +00:00
|
|
|
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x16:
|
|
|
|
case 0x17:
|
|
|
|
res = this->viacuda->read((offset - 0x16000) >> 9);
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-08 18:33:38 +00:00
|
|
|
if (sub_addr >= 0x60) {
|
|
|
|
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
2020-01-08 18:33:38 +00:00
|
|
|
}
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2019-08-23 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-01-08 18:33:38 +00:00
|
|
|
unsigned sub_addr = (offset >> 12) & 0x7F;
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (sub_addr) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0:
|
|
|
|
mio_ctrl_write(offset, value, size);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-03-18 16:34:03 +00:00
|
|
|
dma_write(offset - 0x8000, value, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
2021-08-22 22:20:28 +00:00
|
|
|
case 0x10:
|
|
|
|
this->mesh->write((offset >> 4) & 0xF, value);
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x14:
|
2020-03-15 16:24:40 +00:00
|
|
|
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x16:
|
|
|
|
case 0x17:
|
|
|
|
this->viacuda->write((offset - 0x16000) >> 9, value);
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-08 18:33:38 +00:00
|
|
|
if (sub_addr >= 0x60) {
|
|
|
|
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
2020-05-12 18:55:45 +00:00
|
|
|
} else {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
2020-01-08 18:33:38 +00:00
|
|
|
}
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
2019-08-27 12:14:12 +00:00
|
|
|
uint32_t res = 0;
|
|
|
|
|
2021-01-08 22:29:43 +00:00
|
|
|
switch (offset & 0xFC) {
|
2020-04-19 18:28:51 +00:00
|
|
|
case 0x14:
|
|
|
|
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
|
|
|
res = this->int_mask2;
|
|
|
|
break;
|
|
|
|
case 0x18:
|
|
|
|
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
|
|
|
res = this->int_clear2;
|
|
|
|
break;
|
|
|
|
case 0x1C:
|
|
|
|
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
|
|
|
res = this->int_levels2;
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x24:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->int_mask1;
|
|
|
|
break;
|
|
|
|
case 0x28:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->int_clear1;
|
|
|
|
break;
|
2020-04-19 18:28:51 +00:00
|
|
|
case 0x2C:
|
|
|
|
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
|
|
|
res = this->int_levels1;
|
|
|
|
break;
|
2019-10-07 01:18:18 +00:00
|
|
|
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
|
|
|
res = this->macio_id;
|
2019-10-07 01:18:18 +00:00
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x38:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->feat_ctrl;
|
|
|
|
break;
|
|
|
|
default:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
2021-01-08 22:29:43 +00:00
|
|
|
switch (offset & 0xFC) {
|
2020-04-19 18:28:51 +00:00
|
|
|
case 0x14:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
|
2020-04-19 18:28:51 +00:00
|
|
|
this->int_mask2 = value;
|
|
|
|
break;
|
|
|
|
case 0x18:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
2020-04-19 18:28:51 +00:00
|
|
|
this->int_clear2 = value;
|
|
|
|
break;
|
|
|
|
case 0x1C:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
2020-04-19 18:28:51 +00:00
|
|
|
this->int_levels2 = value;
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x24:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->int_mask1 = value;
|
|
|
|
break;
|
|
|
|
case 0x28:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->int_clear1 = value;
|
|
|
|
break;
|
2020-04-19 18:28:51 +00:00
|
|
|
case 0x2C:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
2020-04-19 18:28:51 +00:00
|
|
|
this->int_levels1 = value;
|
|
|
|
break;
|
2021-01-08 22:29:43 +00:00
|
|
|
case 0x34:
|
|
|
|
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x38:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->feat_ctrl = value;
|
|
|
|
break;
|
2021-01-08 22:29:43 +00:00
|
|
|
case 0x3C:
|
|
|
|
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
|
|
|
this->aux_ctrl = value;
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
default:
|
2021-01-08 22:29:43 +00:00
|
|
|
LOG_F(WARNING, "write %x to unknown MIO register at %x \n", value, offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-28 16:04:28 +00:00
|
|
|
}
|