Compare commits

..
Author SHA1 Message Date
Maxim Poliakovski 3a5c61797c Revert "PCI fixes" 2022-09-02 23:24:06 +00:00
dingusdev 467e4df7dc Merge pull request #32 from joevt/master
PCI fixes
2022-09-02 07:42:01 -07:00
joevt 24ecdbe75b Allow non-HFS/MFS raw floppies
Such as FAT formatted floppies which should be readable in Open Firmware (when floppy support is updated to work in Open Firmware).
2022-09-02 03:39:50 -07:00
joevt b654424465 Fix PCI config r/w of byte and word and unaligned
dingusppc could not read bytes from offset 1,2,3 or words from offset 2.
dingusppc did not read words from offset 1,3 and longs from offset 1,2,3 in the same way as a real Power Mac 8600 or B&W G3.
This commit fixes those issues.

- Added pci_cfg_rev_read. It takes a 32 bit value from offset 0 and returns a value of the specified size using bytes starting from the specified offset. Offsets 4,5, & 6 wrap around to 0,1, & 2 respectively. The result bytes are in flipped order as required by the pci_cfg_read method (so a value of 0x12345678 is returned as 0x78563412)
A real Power Mac 8600 might return a random byte for offset 4, 5, 6 for vci0 but usually not for pci1. A B&W G3 seems to always wrap around correctly. We won't read random bytes, and we won't read a default such as 00 or FF. We'll do the wrap around which makes the most sense because writing 0x12345678 to any offset and reading from the same offset should produce the value that was written.

- Added pci_cfg_rev_write. It takes a 32 bit value from offset 0, and modifies a specified number of bytes starting at a specified offset with the offset wrapping around to 0 if it exceeds 3. The modified bytes take their new values from the flipped bytes passed to pci_cfg_write. When size is 4, the original value is not used since all bytes will be modified.

Basically, those two functions handle all the sizes and all the offsets and replace calls to BYTESWAP_32, read_mem or read_mem_rev, and write_mem or write_mem_rev.
read_mem_rev, as it was used by pcidevice and some other places, could read beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always read the wrong byte or word if they were not at offset 0. Same for read_mem as used by mpc106.
write_mem_rev, as it was used by pcidevice and some other places, could write beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always write the wrong byte or word if they were not at offset 0. Same for write_mem as used by mpc106.

The PCI controllers (bandit, chaos, mpc106) need to encode the offset (0,1,2,3) into the reg_offs parameter passed to pci_cfg_read and pci_cfg_write so they can return or modify the correct bytes of the dword at reg_offs & 3.

The pci_cfg_read and pci_cfg_write methods extract the offset from reg_offs and report unaligned accesses.

pci_cfg_read uses pci_cfg_rev_read to read from the reg using the size and offset to determine which bytes to read.

pci_cfg_write uses pci_cfg_rev_write to write to the reg using the size and offset to determine which bytes to modify.

Other changes:
- for unimplemented config register reads and writes, bandit and ATIRage now includes offset and size (and value in the case of writes) in log warnings.
- for unimplemented config register reads and writes, pcidevice now includes offset in log warnings.
- pci_read and pci_write of mpc106 require an offset parameter since config_addr does not contain the offset (it is always a multiple of 4). The offset is included in the log warninings for non-existent PCI devices.
- ATIRage uses pci_cfg_rev_read and pci_cfg_rev_write which correctly places user_cfg at byte 0x40 instead of 0x43 and writes the correct byte depending on size and offset.

Notes:
- pci_cfg_read calls READ_DWORD_LE_A and pci_cfg_write calls WRITE_DWORD_LE_A. When reading or writing memory that is organized as little endian dwords, such as my_pci_cfg_hdr of mpc106, the function should explicitly state that it's little endian so that the emulator may be ported one day to a CPU architecture that is not little endian.
2022-09-02 03:39:50 -07:00
joevt d91e14abc6 Log PCI config write values MSB first
Writes to config registers of invalid or non-existent PCI devices are logged. They should be logged with most significant byte first.
The values enter the methods in reverse byte order so they need to be byte swapped (except when size is 1) for logging.
The result is that this command in Open Firmware:
`12345678 16800 config-l!`
will log this:
`VCI0 err: write attempt to non-existing VCI device ??:0d.0 @00.l = 12345678`
2022-09-02 03:39:50 -07:00
joevt a08e70781a Add BAR 0 to control
BAR 0 exists on a real Power Mac 8600 and the dingusppc 7500.

On a Power Mac 8600, the initial value is 0x84000003. In Open Firmware, you can write to all bits of the BAR and read the value back except the 2 least significant bits are always %11. Bit 0 indicates I/O space. Bit 1 is reserved and should be zero so maybe this is not a real I/O space BAR. 0x8400000 is written to the BAR by Open Firmware. It doesn't look like a normal I/O address which are usually 16 bits.

On the emulated 7500, 0x02000000 is written to the BAR by Open Firmware sometime during probe-all. The BAR did not behave as it does in the Power Mac 8600. This commit fixes that.

Two questions remain:
1) Which fcode writes to the BAR? Is it the probe fcode or is it the control fcode? There's no config-_! in the control fcode.
2) What is the purpose of the BAR? Writing to it can cause a hang. The testbits code below seems to succeed - it restores the original value after reading the result of testing each bit and before displaying the result. The values shown for the MSB (0x84 on the 8600 and 0x02 on the 7500) could be three flag bits.

```
dev vci0
: testbits { adr ; org }
	cr
	adr config-l@ dup -> org ." original : " 8 u.r cr
	20 0 do
		1 1f i - << dup 8 u.r ."  : "
		adr config-l!
		adr config-l@
		org adr config-l!
		8 u.r cr
	loop
	;

15810 testbits \ 15810 is the address of the BAR on the emulated 7500.
```
2022-09-02 03:39:50 -07:00
joevt a24840803c Allow bit 1 of I/O BARs to be set
Usually bit 1 of I/O BARs is 0 since it is reserved, but control has an I/O BAR where this bit is set.
bar_cfg is used to determine the default values of the least significant bits (2 bits for I/O BARs and 4 bits for Memory BARs).
The upper bits of bar_cfg determine which bits can be set and also determines the size of the BAR.
2022-09-02 03:39:50 -07:00
joevt 7e7522d4b7 Fix Expansion ROM BAR writes
The bits that can be set are the enable bit (bit 0) plus the bits represented by exp_bar_cfg which is determined by the size of the ROM which is calculated to be a power of 2 and a minimum of 2K.
2022-09-02 03:39:50 -07:00
8 changed files with 0 additions and 381 deletions

No files matched your search

-1
View File
@@ -6,7 +6,6 @@ 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,8 +39,6 @@ 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
@@ -1,92 +0,0 @@
/*
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
@@ -1,75 +0,0 @@
/*
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
@@ -1,146 +0,0 @@
/*
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
@@ -1,30 +0,0 @@
/*
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,7 +84,6 @@ 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,35 +36,6 @@ 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;
@@ -110,9 +81,6 @@ 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);
@@ -134,8 +102,6 @@ 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)},
};