Compare commits

...
8 changed files with 381 additions and 0 deletions

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
+2
View File
@@ -39,6 +39,8 @@ enum HWCompType {
I2C_DEV = 1ULL << 9, /* I2C device */
ADB_HOST = 1ULL << 12, /* ADB host */
ADB_DEV = 1ULL << 13, /* ADB device */
PDS_DEV = 1ULL << 14, /* processor direct slot (PDS) device */
NUBUS_DEV = 1ULL << 15, /* Nubus device */
INT_CTRL = 1ULL << 16, /* interrupt controller */
SCSI_BUS = 1ULL << 20, /* SCSI bus */
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
+92
View File
@@ -0,0 +1,92 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(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/>.
*/
/** Houdini2 PC Compatibility card emulation. */
#include <devices/deviceregistry.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/houdini2.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
HoudiniCard::HoudiniCard()
{
supports_types(HWCompType::PDS_DEV);
this->pl_obj = std::unique_ptr<PretzelLogic> (new PretzelLogic());
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
mem_crtl->add_mmio_region(0xE0000000, 0x10000, this->pl_obj.get());
// load card's declaration ROM
if (load_declaration_rom("Houdini2_DeclROM.bin", 0xE)) {
LOG_F(ERROR, "Could not load declaration ROM, the card won't work!");
}
}
PretzelLogic::PretzelLogic()
{
supports_types(HWCompType::MMIO_DEV);
// tell the world we got some own memory
// (shared memory will be disabled)
this->air3 = Air3Bits::SIMM_INSTALLED;
this->air_reset = 1; // tell the world our PC is not currently running
}
uint32_t PretzelLogic::read(uint32_t rgn_start, uint32_t offset, int size)
{
switch (offset) {
case PretzelLogicReg::AIR_RESET:
return this->air_reset;
case PretzelLogicReg::AIR3:
return this->air3;
default:
LOG_F(WARNING, "PretzelLogic: reading from unimplemented reg at 0x%X", offset);
}
return 0xFF;
}
void PretzelLogic::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
switch (offset) {
case PretzelLogicReg::MAIN_IER:
this->main_ier = value;
if (!value) {
LOG_F(INFO, "PretzelLogic: all interrupts disabled");
}
break;
default:
LOG_F(WARNING, "PretzelLogic: writing to unimplemented reg at 0x%X", offset);
}
}
static const DeviceDescription Houdini_Descriptor = {
HoudiniCard::create, {}, {}
};
REGISTER_DEVICE(Houdini2, Houdini_Descriptor);
+75
View File
@@ -0,0 +1,75 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(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/>.
*/
/** Houdini2 PC Compatibility card definitions. */
#ifndef HOUDINI2_H
#define HOUDINI2_H
#include <devices/common/mmiodevice.h>
#include <cinttypes>
#include <memory>
enum PretzelLogicReg {
MAIN_IER = 0xE0,
MAIN_ISR = 0xE4,
AIR_RESET = 0xE8,
AIR3 = 0x8004,
};
enum Air3Bits {
SIMM_INSTALLED = 1 << 7, // if set, on-card memory SIMM is installed
};
// Pretzel Logic ASIC
class PretzelLogic : public MMIODevice {
public:
PretzelLogic();
~PretzelLogic() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
private:
uint8_t air_reset;
uint8_t air_status;
uint8_t air2;
uint8_t air3;
uint8_t port_AB_dir;
uint8_t port_AB_data;
uint8_t main_ier; // main interrupt enable register
};
class HoudiniCard : public HWComponent {
public:
HoudiniCard();
~HoudiniCard() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<HoudiniCard>(new HoudiniCard());
};
private:
std::unique_ptr<PretzelLogic> pl_obj;
};
#endif // HOUDINI2_H
+146
View File
@@ -0,0 +1,146 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(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/>.
*/
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include "memaccess.h"
#include <cinttypes>
#include <fstream>
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
{
uint32_t sum = 0;
for (int i = 0; i < length; i++) {
// rotate sum left by one bit
if (sum & 0x80000000UL) {
sum = (sum << 1) | 1;
} else {
sum = (sum << 1) | 0;
}
sum += data_ptr[i];
}
return sum;
}
int load_declaration_rom(const std::string rom_path, int slot_num)
{
std::ifstream rom_file;
int result = 0;
try {
rom_file.open(rom_path, std::ios::in | std::ios::binary);
if (rom_file.fail()) {
throw std::runtime_error("could not open declaration ROM image");
}
// determine image size
rom_file.seekg(0, std::ios::end);
uint32_t rom_size = rom_file.tellg();
// load it
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
rom_file.seekg(0, std::ios::beg);
rom_file.read((char *)rom_data.get(), rom_size);
// verify image data
uint8_t byte_lane = rom_data[rom_size - 1];
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF)) {
throw std::runtime_error("invalid byte lane value");
}
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL) {
throw std::runtime_error("invalid test pattern");
}
if (rom_data[rom_size - 7] != 1) {
throw std::runtime_error("unsupported format");
}
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
// patch the CRC field of the format header to 0
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
// restore the CRC field value
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
if (test_crc != crc) {
throw std::runtime_error("invalid CRC");
}
int lanes_used = 0;
// count meaningful lanes in a data quad
for (int i = 0; i < 4; i++) {
if (byte_lane & (1 << i)) {
lanes_used++;
}
}
// calculate padded size = rom_size * (4 / lanes_used)
int padded_len = static_cast<int>((float)rom_size * (4 / (float)lanes_used) + 0.5f);
// calculate starting physical address of the ROM
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len)) {
throw std::runtime_error("could not allocate ROM space");
}
int data_pos = 0;
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
// prepare new ROM data by copying over used lanes
// and padding unused lanes with 0xFF
// NOTE: speed uncritical - don't optimize!
for (int i = 0; i < padded_len; i += 4) {
for (int b = 0; b < 4; b++) {
if (byte_lane & (1 << b)) {
new_data[i+b] = rom_data[data_pos++];
} else {
new_data[i+b] = 0xFF;
}
}
}
// move padded ROM data to the memory region
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
result = -1;
}
rom_file.close();
return result;
}
+30
View File
@@ -0,0 +1,30 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(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/>.
*/
#ifndef NUBUS_UTILS_H
#define NUBUS_UTILS_H
#include <cinttypes>
#include <string>
int load_declaration_rom(const std::string rom_path, int slot_num);
#endif // NUBUS_UTILS_H
+1
View File
@@ -84,6 +84,7 @@ static const map<string, string> PropHelp = {
{"pci_C1", "insert a PCI device into C1 slot"},
{"serial_backend", "specifies the backend for the serial port"},
{"emmo", "enables/disables factory HW tests during startup"},
{"pds", "specify device for the processsor direct slot"},
};
bool MachineFactory::add(const string& machine_id, MachineDescription desc)
+34
View File
@@ -36,6 +36,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <vector>
void setup_pds()
{
std::string dev_name = GET_STR_PROP("pds");
if (!dev_name.empty()) {
if (!DeviceRegistry::device_registered(dev_name)) {
LOG_F(WARNING, "specified PDS device %s doesn't exist", dev_name.c_str());
goto empty_slot;
}
// attempt to create device object
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
// safety check
if (!dev_obj->supports_type(HWCompType::PDS_DEV)) {
LOG_F(WARNING, "Cannot use device %s with the PDS", dev_name.c_str());
goto empty_slot;
}
// add device to the machine object
gMachineObj->add_device(dev_name, std::move(dev_obj));
LOG_F(INFO, "PDS slot: %s", dev_name.c_str());
return;
}
empty_slot:
LOG_F(INFO, "PDS slot: empty");
}
int initialize_pdm(std::string& id)
{
uint16_t machine_id;
@@ -81,6 +110,9 @@ int initialize_pdm(std::string& id)
// add internal SCSI bus
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
// set up the processor direct slot
setup_pds();
// Init virtual CPU and request MPC601
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, 7812500ULL);
@@ -102,6 +134,8 @@ static const PropMap pm6100_settings = {
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
{"mon_id",
new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)},
{"pds",
new StrProperty("")},
{"emmo",
new BinProperty(0)},
};