Commit Graph

479 Commits

Author SHA1 Message Date
Maxim Poliakovski
136aeca8f2 Fix Gossamer system register. 2023-01-11 23:49:20 +01:00
Maxim Poliakovski
8d01440558 Improve previous (cosmetics & code duplication). 2023-01-11 23:36:16 +01:00
joevt
f2db6bd066 Add missing header. 2023-01-11 01:17:13 -08:00
joevt
1b221bc0bd Fix compiler warnings: never executed. 2023-01-11 01:17:12 -08:00
joevt
85d0900d7d Fix compiler warnings: possible misuse of comma. 2023-01-11 01:17:12 -08:00
joevt
5294a8b71c Fix compiler warnings: unused variables. 2023-01-11 01:17:12 -08:00
joevt
64fec88436 Fix compiler warnings: cast loses precision.
Use explicit cast when converting large integer types to smaller integer types when it is known that the most significant bytes are not required.
For pcidevice, check the ROM file size before casting to int. We'll allow expansion ROM sizes up to 4MB but usually they are 64K, sometimes 128K, rarely 256K.
for machinefactory, change the type to size_t so that it can correctly get the size of files that are larger than 4GB; it already checks the file size is 4MB before we need to cast to uint32_t.
For floppyimg, check the image size before casting to int. For raw images, only allow files up to 2MB. For DiskCopy42 images, it already checks the file size, so do the cast after that.
2023-01-11 01:17:12 -08:00
joevt
52fa30b71d Add ability to unregister mmio region.
mmio regions are registered when a PCI BAR is set. Add the ability to reverse that - for when a PCI BAR is changed.
2023-01-11 00:05:23 -08:00
joevt
911acb4bc2 Remove MPC106 RAM allocation failed error.
It might not be an error - usually it just means that it was already allocated so demote this message to a warning.

Related memory allocation changes:
- Added find_range_exact which searches for an allocation that exactly matches a range.
- Added find_range_contains which searches for an allocation that is completely contained within a range.
- Added find_range_overlaps which searches for an allocation that overlaps any part of a range.
- Added is_range_free which is similar to the above three. It returns false if any allocated range overlaps a range. It reports the regions that it overlaps.
- Fix add_mem_region and add_memio_region so that they don't just check the first byte and last byte.
- Memory allocation logging should include the range (first byte..last byte) and device if possible.
- Log memory allocations.
2023-01-11 00:05:23 -08:00
joevt
0bd9d0e973 Fix HWComponent name initialization.
First, remove name override for subclasses of HWComponent (Chaos and ScsiBus) because HWComponent has its own name field.

HWComponent name should be set as early as possible in the constructor so it can be used in log messages.
PCIDevice should set name of HWComponent (through MMIODevice) in its constructor, using the name that is given to its constructor.
For Bandit and Grackle, they don't need to set the HWComponent name since its PCIDevice constructor will now do it.
Chaos is not a PCIDevice so it should set the MMIODevice name itself.
Why does PCIDevice have a name that is separate from the HWComponent name?
2023-01-11 00:05:23 -08:00
joevt
5aaae40d94 Add Nvidia vendor ID.
In case you want to emulate an Nvidia GPU in the future (for Core Image, etc.)
2023-01-11 00:05:23 -08:00
joevt
190718fbee 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.
```
2023-01-11 00:05:23 -08:00
joevt
37c352955c 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.
2023-01-11 00:05:23 -08:00
joevt
fb56a6b536 Fix gazelle sys-id.
It should match AAPL,cpu-id property from real Power Mac 6500.
2023-01-11 00:05:23 -08:00
Maxim Poliakovski
101a8d33b0 Manage Windows build dependencies with vcpkg. 2023-01-08 22:27:13 +01:00
Maxim Poliakovski
8002737124 Basic O'Hare I/O controller emulation. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski
a1d9fcfa9d Basic PSX memory controller emulation. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski
f6e208267e bandit: more config space registers. 2022-12-19 01:28:16 +01:00
Maxim Poliakovski
24ccdabedc bandit: add PSX style PCI bridge. 2022-12-18 23:40:56 +01:00
Maxim Poliakovski
a189c94980 scsihd: fix READ_CAPACITY_10 command.
Also bump internal buffer size to 2 MB
to temporarily fix buffer overflows.
2022-12-14 16:14:53 +01:00
Maxim Poliakovski
dee225ee8f atabasedevice: add ATAPI signature at device reset. 2022-12-12 15:07:19 +01:00
Maxim Poliakovski
52bb87b72a Improve ATA interface. 2022-12-12 02:36:56 +01:00
Maxim Poliakovski
78528a1a16 floppyimg: correct format for MFM DC42 images. 2022-12-12 02:27:42 +01:00
dingusdev
0dd9a3d9b1 Further ATA cmd work 2022-12-11 16:08:43 -07:00
Maxim Poliakovski
df02f5053b floppyimg: initial support for Disk Copy 4.2 images. 2022-12-11 23:00:52 +01:00
Maxim Poliakovski
86b0174b13 Fix previous. 2022-12-09 01:07:08 +01:00
Maxim Poliakovski
daf3ecde4e More ATA interface cleanup. 2022-12-09 01:03:09 +01:00
dingusdev
1e9ec5d7ae Start ATA command support 2022-12-08 15:29:04 -07:00
Maxim Poliakovski
2537751fa7 Clean up ATA interface. 2022-12-08 08:04:09 +01:00
Maxim Poliakovski
df1a56305a atabasedevice: rework task file registers. 2022-12-08 00:16:10 +01:00
Maxim Poliakovski
6173a782f2 Implement ATA hard disk stub. 2022-12-07 23:36:56 +01:00
Maxim Poliakovski
a892842b8f Refactor ATA/IDE classes. 2022-12-07 22:36:25 +01:00
dingusdev
58908621e6 IDE refinements 2022-12-05 08:42:51 -07:00
dingusdev
311538b81d Fix IDE functionality 2022-11-26 21:34:54 -07:00
Maxim Poliakovski
14bcb6c08a Clean up previous commit. 2022-11-23 20:28:09 +01:00
joevt
09d374f626 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-11-23 19:55:05 +01:00
joevt
072d5ae330 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-11-23 12:25:28 +01:00
Maxim Poliakovski
3b0e2c677d dbdma: disable two logging messages. 2022-11-18 18:07:32 +01:00
Maxim Poliakovski
4f05d3dae6 swim3: implement reading the Step register. 2022-11-18 18:06:46 +01:00
Maxim Poliakovski
d96351763f swim3: emulate on-chip 1 us timer. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
a0dd1884b3 macio: properly wire floppy DMA. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
a4ff58e9ee New floppy access logic with improved timing. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
9835b96e87 floppyimg: assume raw image by default. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
9f4c248e4c Rework DBDMA logic for bidirectional channels. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
dac50fe0fb GrandCentral: fix DMA dispatching. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
76e0fab33a superdrive: implement eject disk command. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski
585c5fd4ca Guess low-level floppy disk format based on image size.
Also add fdd_fmt property for manually specifying disk
format.
2022-11-17 18:03:18 +01:00
Maxim Poliakovski
13684f7c0b scsicdrom: implement READ_CAPACITY_10 command. 2022-11-14 02:08:05 +01:00
Maxim Poliakovski
5f0358a347 Implement basic SCSI CD-ROM emulation. 2022-11-14 00:55:05 +01:00
Maxim Poliakovski
db17e19699 scsi_hd: cosmetic improvements. 2022-11-10 18:22:44 +01:00
Maxim Poliakovski
3de89eaaf7 Silence SCSI logging messages. 2022-11-08 00:33:38 +01:00
Maxim Poliakovski
d50152dd1a scsi_hd: clean up TEST UNIT READY command. 2022-11-08 00:32:45 +01:00
Maxim Poliakovski
2f02ea4276 sc53c94: release ATN line after MESSAGE_OUT. 2022-11-08 00:30:19 +01:00
Maxim Poliakovski
b2ef809de1 scsi_hd: fix write command. 2022-11-07 22:04:02 +01:00
Maxim Poliakovski
c87fc10376 amic: implement SCSI DMA. 2022-11-07 21:56:27 +01:00
Maxim Poliakovski
a00b87790b sc3c94: implement real DMA. 2022-11-07 12:34:55 +01:00
Maxim Poliakovski
ca5f81417f sc53c94: refactor state machine. 2022-11-07 12:34:42 +01:00
Maxim Poliakovski
40a02cc0f7 scsidevice: refactor states. 2022-11-07 12:24:02 +01:00
Maxim Poliakovski
49331635b2 scsi_hd: determine image file size with stat(). 2022-11-07 12:15:08 +01:00
Maxim Poliakovski
0c4da80c93 sc53c94: small cosmetic fixes. 2022-11-02 23:23:37 +01:00
Maxim Poliakovski
7bc4b8840a scsi_bus: fix device selection bug. 2022-11-02 23:21:46 +01:00
Maxim Poliakovski
5a59b97257 Sc53C94: implement cycle completion commands. 2022-11-02 22:28:43 +01:00
Maxim Poliakovski
5a33fba75e ScsiDevice: command completion states. 2022-11-02 21:28:30 +01:00
Maxim Poliakovski
0c74ebbc45 scsi_bus: support status and message in. 2022-11-02 21:27:18 +01:00
Maxim Poliakovski
2865a611e7 Sc53C94: implement reading the FIFO register. 2022-11-02 21:19:31 +01:00
Maxim Poliakovski
f2be286515 scsi_bus: fix asserting control lines. 2022-11-01 02:52:30 +01:00
Maxim Poliakovski
2c3a5c3b8f Sc53C94: reading current transfer count. 2022-11-01 02:12:09 +01:00
Maxim Poliakovski
c54c1cdb65 Sc53C94: improve status register. 2022-11-01 02:11:06 +01:00
Maxim Poliakovski
8abefb8f8d machinepdm: properly insert SCSI hard disk image.
Skip SCSI hard disk registration if no disk image was given.
2022-11-01 01:17:50 +01:00
Maxim Poliakovski
6ffe28a8a4 Implement SCSI Pseudo-DMA register on PDM. 2022-11-01 01:17:50 +01:00
Maxim Poliakovski
7ab44886c4 Sc53C94: implement information transfer command. 2022-11-01 01:17:50 +01:00
Maxim Poliakovski
fbfae98d6d scsi_bus: packet data transfers. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski
c7ceb9d6b9 sc53c94: fix setting internal transfer counter. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski
3f2b77fd59 amic: basic writing to the VIA2 IFR. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski
c28fd138c2 nvram: fix initialization bug. 2022-10-31 01:01:46 +01:00
dingusdev
b480903c7a Slight code clean-up
Prevents crashing
2022-10-30 15:38:09 -07:00
Maxim Poliakovski
46a0e82258 scsi_hd: some fixes and improvements. 2022-10-27 14:19:58 +02:00
Maxim Poliakovski
a58c9b1a62 ScsiDevice: fix process_command() signature. 2022-10-27 14:07:20 +02:00
Maxim Poliakovski
f3cd5b8b36 sc53c94: fix sending commands to SCSI devices. 2022-10-27 13:49:41 +02:00
dingusdev
2065f3588b Inquiry cmd fixed 2022-10-26 09:30:05 -07:00
dingusdev
f792b38ea3 Started SCSI command reading 2022-10-26 09:18:32 -07:00
Maxim Poliakovski
4f6bd16f3a sc53c94: support selection and command transfer. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski
c51ea575ca scsi_bus: various fixes and improvements. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski
9efac80271 scsi_hd: fix notify() method. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski
eeb576a927 Improve ScsiDevice class. 2022-10-25 02:53:21 +02:00
dingusdev
3af9729e5b Modest refactoring for SCSI HDs 2022-10-23 16:45:58 -07:00
joevt
9f1d613a2d Fix PCI struct offset size
The Pointer to PCI Data Structure is supposed to be two bytes. It is described in the PCI Firmware Specification Revision 3.0, section 5.1.1. PCI Expansion ROM Header Format.
The pointer is two bytes at 0x18. The pointer is supposed to be a multiple of 4 which means there's always at least two bytes of padding after the pointer. Some BIOS firmware images may use the 2 bytes following the pointer for other purposes (plus additional bytes before the PCI Data Structure) so we cannot assume the bytes will be zero.
Some PCI expansion ROMs may include both BIOS and Open Firmware images.
2022-10-23 00:26:32 -07:00
Maxim Poliakovski
c2abc89a3b Fix SCSI HD interface so it can be added to a bus. 2022-10-22 23:41:19 +02:00
dingusdev
aa1d23e08b Fixed hard disk support
Compiles, still unfinished
2022-10-22 11:41:52 -07:00
dingusdev
ee9573327c Reorganized hard disk code
Not compiling yet.
2022-10-08 16:51:54 -07:00
Maxim Poliakovski
3a5c61797c
Revert "PCI fixes" 2022-09-02 23:24:06 +00: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
dingusdev
a61dd5701a Initial prototyping for hard disks 2022-09-01 22:10:52 -07:00
Maxim Poliakovski
5b08f283e5 Hacks for debugging HW interrupts. 2022-08-27 17:38:53 +02:00
joevt
e41b196977 Fix return value for bad pci config address
PCI config read fails should return all 1 bits.
All unused registers in an existing PCI device should return 0.

Because that's what my Power Mac 8600 returns when I run my Open Firmware lspci command.
Any bus/device/function that doesn't exist returns FF and won't be listed by lspci.
Any registers that are unused will show as 00 in the lspci output.

Make grackle log bus:device.function @register.size in all cases.
2022-08-24 07:58:12 -07:00