2020-03-13 21:49:58 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-10-31 00:05:20 +00:00
|
|
|
Copyright (C) 2018-24 divingkatae and maximum
|
2020-03-13 21:49:58 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Constructs the Gossamer machine.
|
|
|
|
|
|
|
|
Author: Max Poliakovski
|
|
|
|
*/
|
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <cpu/ppc/ppcemu.h>
|
2023-11-03 07:21:33 +00:00
|
|
|
#include <devices/common/hwcomponent.h>
|
|
|
|
#include <devices/common/i2c/i2c.h>
|
2022-08-10 23:45:32 +00:00
|
|
|
#include <devices/common/i2c/athens.h>
|
2022-08-14 20:49:24 +00:00
|
|
|
#include <devices/common/i2c/i2cprom.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/machineid.h>
|
2023-10-31 00:05:20 +00:00
|
|
|
#include <devices/common/scsi/scsihd.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/memctrl/mpc106.h>
|
|
|
|
#include <devices/memctrl/spdram.h>
|
2021-09-15 22:46:38 +00:00
|
|
|
#include <loguru.hpp>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <machines/machinebase.h>
|
2022-07-18 09:48:23 +00:00
|
|
|
#include <machines/machinefactory.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <machines/machineproperties.h>
|
|
|
|
|
2022-08-15 12:50:49 +00:00
|
|
|
#include <cinttypes>
|
2020-12-19 08:53:17 +00:00
|
|
|
#include <string>
|
2020-03-15 13:29:59 +00:00
|
|
|
|
2022-08-15 12:50:49 +00:00
|
|
|
// Bit definitions for the Gossamer system register at 0xFF000004
|
|
|
|
enum : uint16_t {
|
|
|
|
FDC_TYPE_SWIM3 = (1 << 15), // Macintosh style floppy disk controller
|
|
|
|
FDC_TYPE_MFDC = (0 << 15), // PC style floppy disk controller
|
|
|
|
BURST_ROM_FALSE = (1 << 14), // burst ROM not present
|
|
|
|
BURST_ROM_TRUE = (0 << 14), // burst ROM present
|
|
|
|
PCI_C_PRSNT_POS = 12, // PRSNT bits for the PCI Slot C
|
|
|
|
PCI_B_PRSNT_POS = 10, // PRSNT bits for the PCI Slot B
|
|
|
|
PCI_A_PRSNT_POS = 8, // PRSNT bits for the PCI Slot A
|
|
|
|
PCM_PID_POS = 5, // Processor und Cache module ID
|
|
|
|
PCM_PID_MASK = 0xE0,
|
|
|
|
AIO_PRSNT_FALSE = (1 << 4), // Whisper/Wings style card in the PERCH slot
|
|
|
|
AIO_PRSNT_TRUE = (0 << 4), // All-in-one style card in the PERCH slot
|
|
|
|
BUS_SPEED_POS = 1, // bus speed code, see below
|
|
|
|
BUS_SPEED_MASK = 0x0E,
|
|
|
|
UNKNOWN_BIT_0 = 1 // Don't know what this bit is for
|
|
|
|
};
|
|
|
|
|
|
|
|
// Gossamer bus speed frequency codes
|
|
|
|
enum : uint8_t {
|
|
|
|
BUS_FREQ_75P00A = 0, // 75.00 MHz
|
|
|
|
BUS_FREQ_70P00 = 1, // 70.00 MHz
|
|
|
|
BUS_FREQ_78P75 = 2, // 78.75 MHz
|
|
|
|
BUS_FREQ_TRI = 3, // clock output tristated
|
|
|
|
BUS_FREQ_75P00B = 4, // 75.00 MHz
|
|
|
|
BUS_FREQ_60P00 = 5, // 60.00 MHz
|
|
|
|
BUS_FREQ_66P82 = 6, // 66.82 MHz
|
|
|
|
BUS_FREQ_83P00 = 7, // 83.00 MHz
|
|
|
|
};
|
|
|
|
|
2022-08-14 20:49:24 +00:00
|
|
|
// EEPROM ID content for a Whisper personality card.
|
|
|
|
const uint8_t WhisperID[16] = {
|
|
|
|
0x0F, 0xAA, 0x55, 0xAA, 0x57, 0x68, 0x69, 0x73, 0x70, 0x65, 0x72, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x02
|
|
|
|
};
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
2020-03-15 13:29:59 +00:00
|
|
|
if (!capacity_megs)
|
|
|
|
return;
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
gMachineObj->add_device(name, std::unique_ptr<SpdSdram168>(new SpdSdram168(i2c_addr)));
|
2020-05-12 18:55:45 +00:00
|
|
|
SpdSdram168* ram_dimm = dynamic_cast<SpdSdram168*>(gMachineObj->get_comp_by_name(name));
|
2020-03-15 13:29:59 +00:00
|
|
|
ram_dimm->set_capacity(capacity_megs);
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
// register RAM DIMM with the I2C bus
|
2020-05-12 18:55:45 +00:00
|
|
|
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
2020-03-15 13:29:59 +00:00
|
|
|
i2c_bus->register_device(i2c_addr, ram_dimm);
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
int initialize_gossamer(std::string& id)
|
|
|
|
{
|
2023-01-11 22:35:54 +00:00
|
|
|
LOG_F(INFO, "Building machine Gossamer...");
|
2022-12-21 10:24:22 +00:00
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
// get pointer to the memory controller/PCI host bridge object
|
2020-05-12 18:55:45 +00:00
|
|
|
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
2020-03-13 21:49:58 +00:00
|
|
|
|
2022-08-15 12:51:37 +00:00
|
|
|
// configure the Gossamer system register
|
|
|
|
uint16_t sys_reg = FDC_TYPE_SWIM3 | BURST_ROM_TRUE
|
|
|
|
| (0x3F << PCI_A_PRSNT_POS) // pull up all PRSNT bits
|
|
|
|
| (1 << PCM_PID_POS) // CPU/Cache speed ratio = 2:1
|
|
|
|
| AIO_PRSNT_FALSE // this machine is not All-in-one
|
|
|
|
| (BUS_FREQ_66P82 << BUS_SPEED_POS) // set bus frequency
|
|
|
|
| UNKNOWN_BIT_0; // pull up bit 0
|
|
|
|
|
|
|
|
gMachineObj->add_device("MachineID", std::unique_ptr<GossamerID>(new GossamerID(sys_reg)));
|
2020-05-12 18:55:45 +00:00
|
|
|
grackle_obj->add_mmio_region(
|
2023-01-11 22:49:20 +00:00
|
|
|
0xFF000000, 4096, dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
2020-03-13 21:49:58 +00:00
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
// allocate ROM region
|
2020-03-13 21:49:58 +00:00
|
|
|
if (!grackle_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
2022-08-14 12:26:56 +00:00
|
|
|
LOG_F(ERROR, "Could not allocate ROM region!");
|
2020-03-13 21:49:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
// configure RAM slots
|
2021-12-04 13:22:02 +00:00
|
|
|
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
|
|
|
|
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
|
|
|
|
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
|
2020-03-15 13:29:59 +00:00
|
|
|
|
2022-08-22 08:52:48 +00:00
|
|
|
// add pci devices
|
|
|
|
grackle_obj->pci_register_device(
|
2023-02-05 08:37:29 +00:00
|
|
|
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
2022-07-18 09:48:23 +00:00
|
|
|
grackle_obj->pci_register_device(
|
2023-02-05 08:37:29 +00:00
|
|
|
DEV_FUN(0x12,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT")));
|
2021-12-04 13:22:02 +00:00
|
|
|
|
2022-08-10 23:45:32 +00:00
|
|
|
// add Athens clock generator device and register it with the I2C host
|
|
|
|
gMachineObj->add_device("Athens", std::unique_ptr<AthensClocks>(new AthensClocks(0x28)));
|
|
|
|
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
|
|
|
i2c_bus->register_device(0x28, dynamic_cast<I2CDevice*>(gMachineObj->get_comp_by_name("Athens")));
|
|
|
|
|
2022-08-14 20:49:24 +00:00
|
|
|
// create ID EEPROM for the Whisper personality card and register it with the I2C host
|
|
|
|
gMachineObj->add_device("Perch", std::unique_ptr<I2CProm>(new I2CProm(0x53, 256)));
|
|
|
|
I2CProm* perch_id = dynamic_cast<I2CProm*>(gMachineObj->get_comp_by_name("Perch"));
|
|
|
|
perch_id->fill_memory(0, 256, 0);
|
|
|
|
perch_id->fill_memory(32, 223, 0xFF);
|
|
|
|
perch_id->set_memory(0, WhisperID, sizeof(WhisperID));
|
|
|
|
i2c_bus->register_device(0x53, perch_id);
|
|
|
|
|
2022-08-15 12:51:37 +00:00
|
|
|
// configure CPU clocks
|
|
|
|
uint64_t bus_freq = 66820000ULL;
|
|
|
|
uint64_t timebase_freq = bus_freq / 4;
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
// initialize virtual CPU and request MPC750 CPU aka G3
|
2022-08-15 12:51:37 +00:00
|
|
|
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, timebase_freq);
|
|
|
|
|
|
|
|
// set CPU PLL ratio to 3.5
|
|
|
|
ppc_state.spr[SPR::HID1] = 0xE << 28;
|
2020-03-13 21:49:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-18 09:48:23 +00:00
|
|
|
|
|
|
|
static const PropMap gossamer_settings = {
|
|
|
|
{"rambank1_size",
|
|
|
|
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
|
|
|
|
{"rambank2_size",
|
|
|
|
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
|
|
|
{"rambank3_size",
|
|
|
|
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
2022-07-20 18:08:37 +00:00
|
|
|
{"emmo",
|
|
|
|
new BinProperty(0)},
|
2023-11-22 16:10:18 +00:00
|
|
|
{"hdd_config",
|
|
|
|
new StrProperty("Ide0:0")},
|
2023-06-18 21:43:08 +00:00
|
|
|
{"cdr_config",
|
|
|
|
new StrProperty("Ide1:0")},
|
2022-07-18 09:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static vector<string> pmg3_devices = {
|
2023-11-22 16:10:18 +00:00
|
|
|
"Grackle", "ScreamerSnd", "Heathrow", "AtiRageGT", "AtaHardDisk", "AtapiCdrom"
|
2022-07-18 09:48:23 +00:00
|
|
|
};
|
|
|
|
|
2023-09-18 23:30:01 +00:00
|
|
|
static vector<string> pmg3twr_devices = {
|
|
|
|
"Grackle", "ScreamerSnd", "Heathrow", "AtiRagePro", "AtaHardDisk", "AtapiCdrom"
|
|
|
|
};
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
static const MachineDescription pmg3dt_descriptor = {
|
2022-08-10 23:45:32 +00:00
|
|
|
.name = "pmg3dt",
|
2022-07-18 09:48:23 +00:00
|
|
|
.description = "Power Macintosh G3 (Beige) Desktop",
|
|
|
|
.devices = pmg3_devices,
|
|
|
|
.settings = gossamer_settings,
|
|
|
|
.init_func = &initialize_gossamer
|
|
|
|
};
|
|
|
|
|
2023-09-18 23:30:01 +00:00
|
|
|
static const MachineDescription pmg3twr_descriptor = {
|
|
|
|
.name = "pmg3twr",
|
|
|
|
.description = "Power Macintosh G3 (Beige) Tower",
|
|
|
|
.devices = pmg3twr_devices,
|
|
|
|
.settings = gossamer_settings,
|
|
|
|
.init_func = &initialize_gossamer
|
|
|
|
};
|
|
|
|
|
2022-07-18 09:48:23 +00:00
|
|
|
REGISTER_MACHINE(pmg3dt, pmg3dt_descriptor);
|
2023-09-18 23:30:01 +00:00
|
|
|
REGISTER_MACHINE(pmg3twr, pmg3twr_descriptor);
|