Fix IDE functionality

This commit is contained in:
dingusdev 2022-11-26 21:34:54 -07:00
parent a58ce8aeb3
commit 311538b81d
5 changed files with 32 additions and 14 deletions

View File

@ -43,6 +43,7 @@ enum HWCompType {
SCSI_BUS = 1ULL << 20, /* SCSI bus */
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
SCSI_DEV = 1ULL << 22, /* SCSI device */
IDE_BUS = 1ULL << 23, /* IDE bus */
IDE_DEV = 1ULL << 25, /* IDE device */
SND_SERVER = 1ULL << 31, /* host sound server */
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */

View File

@ -33,12 +33,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
IdeHardDisk::IdeHardDisk() {
this->name = "IDE0";
this->name = "IdeHardDisk";
supports_types(HWCompType::IDE_DEV);
}
void IdeHardDisk::insert_image(std::string filename) {
hdd_img.open(filename);
this->hdd_img.open(filename, ios::out | ios::in | ios::binary);
// Taken from:
// https://stackoverflow.com/questions/22984956/tellg-function-give-wrong-size-of-file/22986486
@ -82,25 +82,37 @@ void IdeHardDisk::write(int reg, uint32_t value) {
switch (reg) {
case IDE_Reg::IDE_DATA:
regs[IDE_Reg::IDE_DATA] = value;
break;
break;
case IDE_Reg::FEATURES:
regs[IDE_Reg::FEATURES] = value;
break;
case IDE_Reg::SEC_COUNT:
regs[IDE_Reg::SEC_COUNT] = value;
break;
case IDE_Reg::SEC_NUM:
regs[IDE_Reg::SEC_NUM] = value;
break;
case IDE_Reg::CYL_LOW:
regs[IDE_Reg::CYL_LOW] = value;
break;
case IDE_Reg::CYL_HIGH:
regs[IDE_Reg::CYL_HIGH] = value;
break;
case IDE_Reg::DRIVE_HEAD:
regs[IDE_Reg::DRIVE_HEAD] = value;
break;
case IDE_Reg::COMMAND:
regs[IDE_Reg::COMMAND] = value;
LOG_F(0, "Executing COMMAND for IDE: %x", value);
perform_command(value);
break;
case IDE_Reg::DEV_CTRL:
regs[IDE_Reg::DEV_CTRL] = value;
break;
case IDE_Reg::TIME_CONFIG:
regs[IDE_Reg::TIME_CONFIG] = value;
break;
default:
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg);
}
@ -110,8 +122,10 @@ void IdeHardDisk::perform_command(uint32_t command) {
switch (command) {
case IDE_Cmd::READ_SECTOR:
LOG_F(WARNING, "Trying to read sector with: %x", command);
break;
case IDE_Cmd::WRITE_SECTOR:
LOG_F(WARNING, "Trying to write sector with: %x", command);
break;
default:
LOG_F(WARNING, "Attempted to execute IDE command: %x", command);
}

View File

@ -80,10 +80,12 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
this->mesh = dynamic_cast<MESHController*>(gMachineObj->get_comp_by_name("Mesh"));
// connect IDE HW
this->ide_0 = dynamic_cast<IdeHardDisk*>(gMachineObj->get_comp_by_name("IDE0"));
if (!StrProperty("hdd_img").get_string().empty()) {
this->ide_0->insert_image(GET_STR_PROP("hdd_img"));
}
this->ide_1 = dynamic_cast<IdeHardDisk*>(gMachineObj->get_comp_by_name("IdeHardDisk"));
//std::string hd_image_path = GET_STR_PROP("hdd_img");
//if (!hd_image_path.empty()) {
// this->ide_1->insert_image(hd_image_path);
//}
// connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
@ -168,8 +170,9 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
case 0x17:
res = this->viacuda->read((offset - 0x16000) >> 9);
break;
case 0x20:
res = this->ide_0->read((offset - 0x20000) >> 4);
case 0x21: //IDE 1
LOG_F(0, "Read IDE offset=0x%X", offset);
res = this->ide_1->read((offset - 0x21000) >> 4);
break;
default:
if (sub_addr >= 0x60) {
@ -216,8 +219,9 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
case 0x17:
this->viacuda->write((offset - 0x16000) >> 9, value);
break;
case 0x20:
this->ide_0->write((offset - 0x20000) >> 4, value);
case 0x21:
LOG_F(0, "Write IDE offset=0x%X", offset);
this->ide_1->write(((offset - 0x21000) >> 4), value);
break;
default:
if (sub_addr >= 0x60) {
@ -395,8 +399,7 @@ void HeathrowIC::clear_cpu_int()
}
static const vector<string> Heathrow_Subdevices = {
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3"
};
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3", "IdeHardDisk"};
static const DeviceDescription Heathrow_Descriptor = {
HeathrowIC::create, Heathrow_Subdevices, {}

View File

@ -231,7 +231,7 @@ private:
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
MESHController* mesh; // MESH SCSI cell instance
EsccController* escc; // ESCC serial controller
IdeHardDisk* ide_0; // Internal ATA
IdeHardDisk* ide_1; // Internal ATA
Swim3::Swim3Ctrl* swim3; // floppy disk controller
std::unique_ptr<DMAChannel> snd_out_dma;

View File

@ -164,7 +164,7 @@ static const PropMap gossamer_settings = {
};
static vector<string> pmg3_devices = {
"Grackle", "Heathrow", "AtiRageGT"
"Grackle", "Heathrow", "AtiRageGT", "IdeHardDisk"
};
static const MachineDescription pmg3dt_descriptor = {