2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2022-01-16 20:30:43 +00:00
|
|
|
Copyright (C) 2018-22 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(theweirdo) spatium
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-02-28 16:04:28 +00:00
|
|
|
(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/>.
|
|
|
|
*/
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2022-01-16 20:30:43 +00:00
|
|
|
/** MPC106 (Grackle) emulation
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2019-08-23 19:30:30 +00:00
|
|
|
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
2019-08-21 06:33:01 +00:00
|
|
|
It's the central device in the Gossamer architecture.
|
|
|
|
Manual: https://www.nxp.com/docs/en/reference-manual/MPC106UM.pdf
|
|
|
|
|
2019-08-28 00:39:29 +00:00
|
|
|
This code emulates as much functionality as needed to run PowerMac Beige G3.
|
2019-08-21 06:33:01 +00:00
|
|
|
This implies that
|
|
|
|
- we only support address map B
|
|
|
|
- our virtual device reports revision 4.0 as expected by machine firmware
|
|
|
|
*/
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
#ifndef MPC106_H_
|
|
|
|
#define MPC106_H_
|
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/mmiodevice.h>
|
|
|
|
#include <devices/common/pci/pcidevice.h>
|
|
|
|
#include <devices/common/pci/pcihost.h>
|
|
|
|
#include <devices/memctrl/memctrlbase.h>
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2022-07-17 03:33:06 +00:00
|
|
|
#include <memory>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <unordered_map>
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
|
2019-08-21 06:33:01 +00:00
|
|
|
public:
|
|
|
|
MPC106();
|
2022-01-16 20:30:43 +00:00
|
|
|
~MPC106() = default;
|
2020-03-14 13:23:46 +00:00
|
|
|
|
2022-07-17 03:33:06 +00:00
|
|
|
static std::unique_ptr<HWComponent> create() {
|
|
|
|
return std::unique_ptr<MPC106>(new MPC106());
|
|
|
|
}
|
|
|
|
|
2022-08-22 10:16:31 +00:00
|
|
|
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);
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2022-08-19 18:07:22 +00:00
|
|
|
int device_postinit();
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
protected:
|
|
|
|
/* PCI access */
|
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 10:32:28 +00:00
|
|
|
uint32_t pci_read(uint32_t offset, uint32_t size);
|
|
|
|
void pci_write(uint32_t offset, uint32_t value, uint32_t size);
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2019-08-23 19:30:30 +00:00
|
|
|
/* my own PCI configuration registers access */
|
|
|
|
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
|
|
|
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
bool supports_io_space(void) {
|
|
|
|
return true;
|
|
|
|
};
|
2019-08-23 19:30:30 +00:00
|
|
|
|
2019-10-07 01:21:01 +00:00
|
|
|
void setup_ram(void);
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
private:
|
|
|
|
uint8_t my_pci_cfg_hdr[256] = {
|
2020-05-12 18:55:45 +00:00
|
|
|
0x57, 0x10, // vendor ID: Motorola
|
|
|
|
0x02, 0x00, // device ID: MPC106
|
|
|
|
0x06, 0x00, // PCI command
|
|
|
|
0x80, 0x00, // PCI status
|
|
|
|
0x40, // revision ID: 4.0
|
|
|
|
0x00, // standard programming
|
|
|
|
0x00, // subclass code: host bridge
|
|
|
|
0x06, // class code: bridge device
|
|
|
|
0x08, // cache line size
|
|
|
|
0x00, // latency timer
|
|
|
|
0x00, // header type
|
|
|
|
0x00, // BIST Control
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0x00, // Interrupt line
|
|
|
|
0x00, // Interrupt pin
|
|
|
|
0x00, // MIN GNT
|
|
|
|
0x00, // MAX LAT
|
|
|
|
0x00, // Bus number
|
|
|
|
0x00, // Subordinate bus number
|
|
|
|
0x00, // Discount counter
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // Performance monitor command
|
|
|
|
0x00, 0x00, // Performance monitor mode control
|
2019-10-16 04:19:00 +00:00
|
|
|
0xFF, 0xFF,
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 0
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 1
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 2
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 3
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF,
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, 0x00, // Power mgt config 1
|
|
|
|
0x00, // Power mgt config 2
|
|
|
|
0xCD, // default value for ODCR
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, // Memory Starting Address
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Starting Address
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Memory Ending Address
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Ending Address
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, // Memory bank enable
|
2019-10-16 04:19:00 +00:00
|
|
|
0xFF, 0xFF,
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, // Memory page mode
|
2019-10-16 04:19:00 +00:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x10, 0x00, 0x00, 0xFF, // PICR1
|
|
|
|
0x0C, 0x06, 0x0C, 0x00, // PICR2
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0x00, // ECC single-bit error counter
|
|
|
|
0x00, // ECC single-bit error trigger
|
|
|
|
0x04, // Alternate OS visible paramaters 1
|
|
|
|
0x01, // Alternate OS visible paramaters 2
|
2019-10-16 04:19:00 +00:00
|
|
|
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x01, // Error enabling 1
|
|
|
|
0x00, // Error detection 1
|
2019-10-16 04:19:00 +00:00
|
|
|
0xFF,
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, // 60x bus error status
|
|
|
|
0x00, // Error enabling 2
|
|
|
|
0x00, // Error detection 2
|
2019-10-16 04:19:00 +00:00
|
|
|
0xFF,
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, // PCI bus error status
|
|
|
|
0x00, 0x00, 0x00, 0x00, // 60x/PCI ERROR address
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2019-10-16 04:48:31 +00:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF,
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x42, 0x00, 0xFF, 0x0F, // Emulation support config 1
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Modified memory status (no clear)
|
|
|
|
0x20, 0x00, 0x00, 0x00, // Emulation support config 2
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Modified memory status (clear)
|
2019-10-16 04:19:00 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
0x00, 0x00, 0x02, 0xFF, // Memory ctrl config 1
|
|
|
|
0x03, 0x00, 0x00, 0x00, // Memory ctrl config 2
|
|
|
|
0x00, 0x00, 0x00, 0x00, // Memory ctrl config 3
|
|
|
|
0x00, 0x00, 0x10, 0x00 // Memory ctrl config 4
|
2019-08-21 06:33:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t config_addr;
|
|
|
|
};
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
#endif
|