Compare commits

...
179 Commits
Author SHA1 Message Date
dingusdev 5bc1260dbb Start MTSPR/MFSPR refactor 2026-02-11 08:02:40 -07:00
dingusdev e46414721d Name DSISR bits 2026-01-22 19:07:43 -07:00
dingusdev 79784cd36c Initial improvements 2026-01-21 21:17:52 -07:00
joevt d693b0f443 maciotwo: Fix IDE read/write mask again.
Use the entire 4K range.
2026-01-20 07:07:11 -07:00
joevt 5c646e8270 maciotwo: Add methods to override OHARE_ID ids. 2026-01-17 08:40:45 -07:00
joevt 65c5d2425e maciotwo: Fix IDE read/write mask. 2026-01-17 07:02:06 -07:00
joevt f2676e0324 maciotwo: Make Ide1 optional.
Some Macs that use OHare do not have a second ATA bus exposed by Open
Firmware. Allow Ide1 to not be included.

# Conflicts:
#	devices/ioctrl/maciotwo.cpp
2026-01-17 06:54:44 -07:00
dingusdev 48adf99690 Documentation cleanup 2026-01-15 07:39:59 -07:00
joevt 3c0432053b atadefs: Add KeyLargo ATA interrupt register note. 2026-01-15 07:37:17 -07:00
joevt ebc2fcf216 atabasedevice: Add missing this. 2026-01-15 07:36:52 -07:00
joevt 25c74f76d2 idechannel: Fix read and write virtual methods. 2026-01-15 07:35:11 -07:00
dingusdev e3839bdea6 Start vendor-specific SCSI commands 2026-01-12 22:11:11 -07:00
dingusdev 742a810624 Restored floating point testing 2026-01-07 18:45:47 -07:00
dingusdev dbc10ab027 Clean-up for mode_sense_ex 2026-01-03 16:44:08 -07:00
joevt 383f6dd9a1 atahd: Fix endianness in prepare_identify_info.
Use endian macros for fields that have a specific endianness.
2026-01-03 11:22:19 -07:00
joevt be04300846 ppcexec: Add missing registers for disassembly. 2026-01-03 11:18:33 -07:00
Maxim Poliakovski 80c1ebe57d atahd: report max. PIO mode for a basic device.
Prepare identify info for advanced PIO and
Multiword DMA modes but leave them disabled
because ATA DMA doesn't work yet.
2026-01-02 22:12:53 +01:00
Maxim Poliakovski 5996358308 maciotwo: initialize and connect IDE DMA channels. 2026-01-02 21:30:21 +01:00
Maxim Poliakovski 380827e09b idechannel: inherit IdeChannel from DmaDevice. 2026-01-02 21:30:21 +01:00
Maxim Poliakovski c4be881d52 atabasedevice: add push_data and pull_data methods. 2026-01-02 21:30:21 +01:00
joevt ae56bb3743 viacuda: Add append_data for setting out_buf. 2026-01-01 07:25:30 -07:00
joevt fd5bcddcb7 viacuda: Create method for single byte packets. 2026-01-01 07:20:24 -07:00
joevt af8124a525 display_sdl: Set to null after destroy. 2026-01-01 07:14:28 -07:00
dingusdev 8105defb0b Fill out MACE stub further
Last commit of 2025. This will be further expanded next year.
2025-12-31 21:29:49 -07:00
dingusdev 7429a4111e atadefs.h: add SLEEP command code. 2025-12-29 18:37:53 +01:00
dingusdev a537d09c63 Add Page Code 0x1a for CD ROM 2025-12-27 16:01:57 -07:00
dingusdev 7fdb11d64f Another fix-up attempt 2025-12-26 18:16:25 -07:00
dingusdev 5567041c2b Fix std prefix 2025-12-26 08:07:31 -07:00
dingusdev c94cfe0d40 Add GET_CONFIG to ATAPI CD-ROM 2025-12-26 07:22:48 -07:00
Maxim Poliakovski 73d5a2374b viacuda: fix GET/SET_DEVICE_BITMAP again.
Keep only related stuff this time.
2025-12-08 02:53:36 +01:00
Maxim Poliakovski 017f559e90 Revert "viacuda: Fix CUDA_GET_DEVICE_BITMAP."
This reverts commit 2b0b926f52.
2025-12-08 02:53:36 +01:00
dingusdev 29f9ab14ee Merge pull request #157 from mrpapersonic/floppy-cleanup
Clean up floppy signature detection code.
2025-12-06 15:04:39 -07:00
dingusdev 17b2a1a6e4 Merge pull request #158 from mrpapersonic/libstdcpp-build-fix
Fix build fail on linux/libstdc++
2025-12-06 11:58:11 -07:00
Paper 77f1f72122 devices/memctrl/psx: fixed build fail on linux/libstdc++ 2025-12-06 13:00:46 -05:00
Paper 03ec9d9589 devices/floppy/floppyimg: use lambda function for HFS/MFS signature check
this is more obvious to read at a glance.
2025-12-06 08:51:35 -05:00
dingusdev b813a080da Add additional registers to read for DMAReg 2025-12-04 06:52:48 -07:00
joevt 2b0b926f52 viacuda: Fix CUDA_GET_DEVICE_BITMAP.
Bitmap should be at byte 3 and 4, not 2 and 3.
2025-12-02 07:44:53 -07:00
dingusdev 0ac0a5b77e Handle arbitration lost in Mesh 2025-12-01 08:29:05 -07:00
Maxim Poliakovski d19de22540 viacuda: use more appropriate command names. 2025-11-30 17:12:45 +01:00
dingusdev e7535eaec5 More compile fixes 2025-11-30 07:52:56 -07:00
dingusdev 7699075377 Cuda code cleanup
* Fix CUDA_SET_DEVICE_LIST
* Add out_count to CUDA_GET_DEVICE_LIST
* Use this in CUDA_SET_REAL_TIME
2025-11-29 15:58:27 -07:00
dingusdev 2bdf79f813 Prepping for another proper build 2025-11-29 07:52:41 -07:00
dingusdev df738e9edc Merge pull request #156 from alicela1n/fix-build-older-macos
main_sdl.m: Add support for macOS versions prior to 10.13
2025-11-29 06:33:29 -07:00
Alice 9656753232 main_sdl.m: Add support for macOS versions prior to 10.13 2025-11-28 19:25:14 -08:00
joevt e569e7ea05 machinegazelle: Specify RAM slots instead of banks.
Slot 0 is built in RAM which is usually 0 MB but can be 32 MB.
RAM slots can have up to 64 MB of RAM, but those use two 32 MB banks.
2025-11-28 18:18:00 +01:00
joevt 59abb96caa machinegazelle: Use specified DIMM sizes.
Previously, only the total size of all DIMMs was used. For example, four
8 MB DIMMs would behave as a single 32 MB DIMM.

This change forces handling of the individual DIMM sizes.

We currently do not emulate shuffling of 4MB pages. For example, the
data of the first page of bank 1 does not move if you move it to a
different page.

The important parts of this algorithm are:
1) DIMM sizes can be determined.
2) The final memory allocation will be a single contiguous block.
2025-11-28 18:18:00 +01:00
joevt 678b51ddfb grandcentral: Add comment. 2025-11-28 18:18:00 +01:00
Eric Helgeson a51e740f5a cmake: add warning if no audio libs are detected
User may still want to build and detect at runtime,
but we should let them know it may cause runtime issues.
2025-11-28 18:18:01 +01:00
dingusdev d8f65dafd0 Add missing reads for BigMac 2025-11-23 21:01:45 -07:00
dingusdev ebc6590c8f Start filling up BigMac 2025-11-23 16:57:56 -07:00
Maxim Poliakovski a91481fb4d atahd: add stubs for common settings in SET_FEATURES. 2025-11-19 22:28:56 +01:00
Maxim Poliakovski 87f1a1b553 atadefs: add READ_DMA_NR and WRITE_DMA_NR commands. 2025-11-19 21:53:37 +01:00
Maxim Poliakovski c0d3edbc5d atirage: add AtiRageGW (Rage IIc) device. 2025-11-19 21:46:39 +01:00
Maxim Poliakovski 697ab30992 atimach64defs: add Rage IIc PCI device ID. 2025-11-19 21:46:39 +01:00
dingusdev 490de061f5 Quick header fix 2025-11-17 19:57:08 -07:00
joevt a9b589af86 viacuda: Log SET_POWER_MESSAGES and TIMER_TICKLE.
Maybe these should use error_response instead of response_header?
2025-11-17 19:55:04 -07:00
dingusdev 4efb269c96 Fix typecasting warnings from VS2022 2025-11-17 19:47:55 -07:00
Maxim Poliakovski a7deca1228 maciotwo: add DMA channels for IDE0 and IDE1. 2025-11-16 20:16:30 +01:00
joevt 3639f40eb0 Create machine should clear device map on error. 2025-11-16 08:09:18 -07:00
joevt 47e56614af romidentity: Powerbook 190cs is a 68K ROM. 2025-11-16 08:00:53 -07:00
joevt 6ca2a0a29b romidentity: No ROMRelease for ROMVersion < 0x7A.
ROMRelease 0x6000 is probably a BRA.W instruction.
2025-11-16 07:57:00 -07:00
Maxim Poliakovski c3448e1e7c machinepdm: support for pluggable PDS/VDS devices.
Processor direct slot (PDS) is the only expansion
slot available in PDM. It accepts a few Apple PDS
cards as well as Nubus cards attached using a special
adapter. The attached device is handled as it would
be a standard Nubus device plugged into the pseudo slot $E.

Video direct slot (VDS) in Cold Fusion is the same
thing as the PDS slot in PDM.
VDS usually carries either the HPV or the Planaria
video expansion card.

Virtual Nubus cards can be attached to the PDS/VDS
slot using the "--pds=[DeviceName]" option.
2025-11-15 23:48:26 +01:00
Maxim Poliakovski 9290c897e1 hwcomponent: add NUBUS_DEV type. 2025-11-15 23:48:26 +01:00
Maxim Poliakovski d8461475f2 machinebondi: minor comment fixes. 2025-11-15 21:58:47 +01:00
joevt 0b4487d6b7 Create a HWComponent for each machine.
class Machine (subclass of HWComponent) will serve as the root device of
a machine.
Its sub-device list will take the place of the machine device list.
Its create method will take the place of the machine init function.
Its properties will take the place of the machine properties.
This change removes extra loops for the machine devices and properties.
2025-11-15 21:58:47 +01:00
Maxim Poliakovski 40c82785c9 mpc106.cpp: disable pci_GPU property to avoid duplication. 2025-11-15 21:58:47 +01:00
Maxim Poliakovski d6db6c9d7c Cleanup I2C stuff. 2025-11-15 16:35:06 +01:00
joevt c0d5f6df4f main: Make sure gMachineObj gets deleted. 2025-11-15 16:34:37 +01:00
Maxim Poliakovski 7a8f3958c2 atirage: basic rectangle filling (2D acceleration). 2025-11-14 01:35:48 +01:00
Maxim Poliakovski f10c6594e5 atimach64defs.h: correct some field sizes. 2025-11-14 01:34:27 +01:00
dingusdev eb88f94763 Slight manual update 2025-11-12 20:54:44 -07:00
Maxim Poliakovski 5248c31df1 platinum.h: add missing override. 2025-11-10 18:04:52 +01:00
Maxim Poliakovski 8230223440 maciotwo: remove obsolete debugging stuff. 2025-11-10 18:04:52 +01:00
joevt 8db57534d3 Fix spelling of "constants". 2025-11-10 07:48:15 -07:00
joevt 8f3b4ffa05 machinefactory: Output leading zeros of checksum. 2025-11-10 07:41:34 -07:00
joevt 4846f2708f hmc: Add enums for all registers. 2025-11-10 07:40:59 -07:00
joevt c7fbd5ed4a grandcentral: Fix DEVSEL. 2025-11-10 07:40:34 -07:00
Maxim Poliakovski 58fe6e6977 mesh: fix BusFree command logic. 2025-10-24 19:27:13 +02:00
Maxim Poliakovski dc96137c47 scsibusctrl: fix logic to reflect current changes in scsidevice. 2025-10-24 19:27:13 +02:00
Maxim Poliakovski a543d46a10 scsidevice.cpp: fix typo. 2025-10-24 19:27:13 +02:00
dingusdev 550bc8af67 Add further SCSI definitions 2025-09-22 22:09:05 -07:00
Maxim Poliakovski 4d1765dd9a superdrive: remove superfluous track_zero. 2025-09-22 21:35:03 +02:00
Maxim Poliakovski ddd8c21c6d swim3.h: add definition for the INT_ERROR bit.
This bit isn't mentioned in the SWIM3 ERS.
But that's used in the MkLinux and BeOS drivers.
2025-09-22 21:35:03 +02:00
Maxim Poliakovski ee776e41cf dbdma: warn for unexpected amount of data in xfer_from_device. 2025-09-21 00:24:33 +02:00
Maxim Poliakovski ca5989332b sc53c94: fix xfer_from for len < xfer_count. 2025-09-21 00:24:33 +02:00
dingusdev a6b6fc1b61 Add missing returns to mfspr + mtspr 2025-09-15 07:54:15 -07:00
Maxim Poliakovski 049c843891 ppcopcodes: support reading the time base using TBL_S/TBU_S.
This is required by BeOS kernel.
2025-09-15 01:57:13 +02:00
joevt df134894cf displayid: Fix I2C STOP/START comments. 2025-09-07 07:20:41 -07:00
joevt fa4a2e38b7 romidentity: Differentiate Beige rev D ROMs. 2025-09-07 07:00:59 -07:00
joevt d7b3709ee1 romidentity: Update Mac OS ROM file comments. 2025-09-07 07:00:46 -07:00
dingusdev 367c0012ce Revert rework on AWACS 2025-08-24 14:47:07 -07:00
dingusdev fb5f1ed915 Stub out serial
Allows Mac OS 8.x and 9.x to boot from HD on older PCI Power Macs
2025-08-24 13:52:09 -07:00
joevt d789935a6d grandcentral: Supports IOBUS_HOST comp type. 2025-08-24 13:46:03 -07:00
dingusdev 1b3cfb7f24 Start rework on AWACS 2025-08-24 12:55:07 -07:00
joevt 9144bfbbc2 openfirmware.md: Additions and fixes and um/mod. 2025-08-14 07:00:54 -07:00
joevt 2f0f264ef2 ppcdisasm: Add missing MPC601 register duplicates. 2025-07-30 21:30:31 -07:00
joevt f6dbbe73f2 romidentity: Update for PowerBook4,2.
Update possible New World Mac firmware updater name for PowerBook4,2 with 432f1 firmware.
2025-07-30 21:30:24 -07:00
dingusdev 79992a9a64 Adding more ATI Rage register defs
For a future acceleration support project
2025-07-30 07:12:43 -07:00
joevt 36b3e7279b display_sdl: Handle invalid renderer sizes.
If the window is too large, the renderer size doesn't update to match
the new window size. In that case, reduce the window scale until the
renderer size is ok.
2025-07-25 07:15:19 -07:00
joevt 369e2ca238 display_sdl: Add scale_step. 2025-07-25 07:15:05 -07:00
joevt 2a68f57b65 nvram: Add of_nvram_offset.
In case the Open Firmware environment variables are in a different
location such as with the case of Copland disk based Open Firmware
(DBOF).
2025-07-25 07:14:48 -07:00
joevt facbd05b9e ppcopcodes: Add missing break. 2025-07-25 07:14:05 -07:00
joevt 1b719f2d8f ppcmmu: Delete blank line. 2025-07-25 07:09:09 -07:00
joevt 1b7ec272d8 ppcmmu: Don't crash on MPC601 DBAT access. 2025-07-25 07:05:41 -07:00
joevt b509f4aaf6 romidentity: iMac G4 1.0 GHz 17 inch with 4.5.8f1. 2025-07-25 07:03:40 -07:00
joevt c1197423b4 machinefactory: Move rom identity. 2025-07-11 01:44:18 +02:00
Maxim Poliakovski 436c196ba5 viacuda: cleanup interrupt signaling. 2025-07-09 21:08:12 +02:00
joevt b447193a22 machinefactory: More rom info. 2025-07-07 19:42:00 -07:00
joevt 63be7f318e macio: Add TAM note.
Setting this bit for Gazelle causes Twentieth Anniversary Mac startup
chime.
2025-07-07 19:41:52 -07:00
joevt 8d718ca8d1 machinepdm: Revert pm6100 machine id to 3010.
A real Power Macintosh 6100/60 returns A55A0310,
2025-07-07 19:41:42 -07:00
Maxim Poliakovski 31bf69eba2 viacuda.cpp: fix CB2 interrupt line. 2025-07-07 19:04:28 +02:00
dingusdev c4eb3bb4e4 Merge pull request #149 from mihaip/upstream-fix-tlb
ppcmmu: fix tlb_flush_secondary_entry
2025-07-03 18:05:19 -07:00
Mihai Parparita 26724feff1 ppcmmu: fix tlb_flush_secondary_entry
It would iterate over all of the entries in the two-way line, but only
check the first one.

Fixes 10.1 kernel panic on boot after c317ed8b42.
2025-07-03 16:31:20 -07:00
joevt d13a283791 sc53c94: Don't spam latch not implemented warning. 2025-07-03 07:05:37 -07:00
joevt fc0777c45f display: Fix display size changes in full screen.
Fix virtual display resolution change while in full screen mode.

Switching resolutions should keep the same full screen mode (integer,
full, no bars) unless a custom scale (using the zoom keys Control-- or
Control-+) has been selected.

Control-F is for switching forward through the full screen modes. Add
Control-Shift-F for switching backward through the full screen modes.
This allows reducing full screen mode without going through not full
screen mode.
2025-07-03 07:04:43 -07:00
Maxim Poliakovski a686f4c4bb athens: fix data receive sequencer to accept more data.
Athens supports two data bytes per I2C transaction:
reg_addr + reg_value
The Valkyrie driver in Open Firmware 2.0 sends three bytes.
Change the code to accept > 2 bytes and return ACK
for each byte to prevent Cuda errors.
2025-07-01 12:08:42 +02:00
Maxim Poliakovski 91cb5fc6ad maciotwo: change OHare MESH cell to MeshTnt.
It looks like the MESH cell inside OHare reports its version
in the old format, i.e. 0xEY where Y is >= 1.
Returning MESH ID in the new (Heathrow) format causes
the Native SCSI Manager to misrecognize the HW and crash badly.
2025-06-30 01:48:40 +02:00
joevt 0f8876f348 viacuda: Post key events at startup.
Keys that are held down too early are ignored which makes it difficult
perform some tasks at startup:
- Shift key to disable extensions.
- Command-Option-O-F to enter Open Firmware.
- Command-Option-P-R to reset nvram.
- Capslock to boot MkLinux or Copland.

This change hopes to grab all the keys being pressed and post events for
all of them when the ADB bus is ready.
2025-06-29 06:49:15 -07:00
joevt dbadbb4cce hostevents_sdl: Remove superfluous semicolons. 2025-06-29 06:48:51 -07:00
joevt 23b142008f hostevents_sdl: Use key mods from the SDL key event.
No reason to call SDL_GetModState separately.
2025-06-29 06:48:40 -07:00
joevt d3e0b743bb hostevents_sdl: Add key for entering debugger.
Because Control-C (sigint) in terminal window isn't always reliable (for
example, release version launched from Xcode).
2025-06-29 06:48:33 -07:00
joevt 91410f3690 hostevents_sdl: Control-L toggles max logging. 2025-06-29 06:48:23 -07:00
joevt 5412fbc198 Remove superfluous semicolons. 2025-06-27 19:01:14 -07:00
joevt 3f830eb5b5 hostevents_sdl: Ignore repeat events.
SDL2 will send a key down event multiple times (with the repeat flag
set) after the first key down event for the same key.
2025-06-27 18:57:35 -07:00
joevt 7ed8bda0fe adbkeyboard: Support Device Handler ID 3.
Device Handler ID 3 returns separate key codes for the right control,
option, and shift keys.
2025-06-27 18:55:55 -07:00
joevt 3eaf38b1d8 adbdevice: Remove redundant arithmetic. 2025-06-27 18:55:47 -07:00
joevt bad8adc0c3 adbdevice: Fix listen. 2025-06-27 18:54:09 -07:00
joevt 5ed44f73cd hostevents: Include gamepad handler.
For some reason this handler was not included with other input handlers
for disconnect or disable.
2025-06-27 18:54:05 -07:00
joevt 7b7dc90158 hostevents: Add keyboard_locale.
Add a keyboard locale field instead of passing it as a parameter to
poll_events.
2025-06-27 18:54:01 -07:00
joevt 8c05e8ac82 hostevents: Remove unused keys_state field. 2025-06-27 18:53:54 -07:00
Maxim Poliakovski 53a393a2c2 More superfluous semicolon removal. 2025-06-24 23:53:34 +02:00
Maxim Poliakovski 7fbc250128 machineid.h: remove superfluous semicolon. 2025-06-24 23:53:34 +02:00
Maxim Poliakovski b351b578b7 maciotwo.cpp: remove superfluous mesh_dma checks. 2025-06-22 13:02:28 +02:00
Maxim Poliakovski 8de664b708 dbdma.h: remove superfluous semicolon. 2025-06-22 12:51:47 +02:00
Maxim Poliakovski 6c12c34297 dmacore.h: remove superfluous semicolon. 2025-06-22 12:51:47 +02:00
joevt 1fae4d28ac maciotwo: Standardize log message format. 2025-06-22 12:16:40 +02:00
joevt 881c0f7d4e maciotwo: Add interrupts for OHare part 2. 2025-06-22 12:16:40 +02:00
joevt 4a824cd9aa maciotwo: Fix indent part 2. 2025-06-22 12:16:40 +02:00
joevt 33e351926f maciotwo: Add interrupts for OHare. 2025-06-22 12:16:40 +02:00
joevt 3f57d072ec maciotwo: Fix indent. 2025-06-22 12:16:40 +02:00
joevt 0f17a04b2f maciotwo: Fix grammar. 2025-06-20 07:03:04 -07:00
joevt fbfbfb4b33 grandcentral: Fix grammar. 2025-06-20 07:02:55 -07:00
Maxim Poliakovski af25d41375 grandcentral: move simple methods to macio.h 2025-06-18 22:59:13 +02:00
Maxim Poliakovski 508c4fa461 macio.h: reorganize, improve comments. 2025-06-17 16:35:33 +02:00
Maxim Poliakovski 20eec5cdc8 Remove ohare.cpp source. 2025-06-17 16:17:11 +02:00
Maxim Poliakovski 6b50f85bfc Switch to MacIoTwo's OHare. 2025-06-17 16:17:11 +02:00
Maxim Poliakovski a27ba815e4 Remove heathrow.cpp source. 2025-06-17 16:07:05 +02:00
Maxim Poliakovski 6142033397 machinebondi: switch to Paddington. 2025-06-17 16:07:05 +02:00
Maxim Poliakovski 7674bc3677 machineyosemite: switch to Paddington. 2025-06-17 16:03:59 +02:00
Maxim Poliakovski 157bd6de88 Switch to MacIoTwo's Heathrow. 2025-06-17 15:52:46 +02:00
Maxim Poliakovski 53eafa5f24 New class MacIoTwo for OHare/Heathrow/Paddington emulation. 2025-06-17 15:27:48 +02:00
Maxim Poliakovski 2701a72598 New class MacIoBase.
Contains common building blocks for various MacIO ASICs.
2025-06-17 15:27:48 +02:00
Maxim Poliakovski 5b1c832a05 Remove duplications of INT_TO_IRQ_ID macro. 2025-06-17 15:27:48 +02:00
Maxim Poliakovski c317ed8b42 ppcmmu: fix TLB invalidation again. 2025-06-17 13:08:31 +02:00
dingusdevandSean McBride 253cffbaca More Loguru fixes for BSD OSes
Co-Authored-By: Sean McBride <[email protected]>
2025-06-03 20:31:44 -07:00
joevt 60558ebf71 videoctrl: Template endianness.
The methods don't need to be virtual.
2025-06-02 05:55:28 -07:00
joevt a1a22cb1ef displayid: Add comments to read_monitor_sense. 2025-06-02 05:55:16 -07:00
joevt 723e84930b superdrive: Add logging. 2025-05-31 14:53:47 -07:00
joevt b7a4e14ee9 floppyimg: Include the path in log messages.
Because there can be more than one floppy.
2025-05-31 14:53:34 -07:00
joevt bd9d7ea275 swim3: Clear timer id to 0 only when cancelling.
Maybe cancel_timer should take a reference and set it to zero for us?
2025-05-31 14:49:24 -07:00
joevt ca77b141a6 machinefactory: iMac G4 has 4.4.1f1. 2025-05-30 19:05:43 -07:00
Maxim Poliakovski 2068803c6b amic: simplify VIA2_IFR writes. 2025-05-29 15:40:26 +02:00
joevt 35f2ce14f1 Add type and description to device descriptors.
Add supports_types to device descriptors so that we can determine
supported types without having to create the hardware device.
Add description so that each device can have an optional description.
2025-05-28 17:58:08 +02:00
joevt 6f00113554 Move MeshTnt to GrandCentralTnt.
Also create GrandCentralCatalyst which doesn't include Mesh.
2025-05-27 07:57:16 -07:00
joevt a8b6a16e1a Move ScsiCurio to Sc53C94. 2025-05-27 07:56:26 -07:00
joevt 393854dee0 heathrow: Spelling. 2025-05-27 07:52:10 -07:00
joevt bbbaf00b9a Move ScsiMesh to MeshTnt and MeshHeathrow. 2025-05-27 07:51:37 -07:00
Rairii bf396600ba displayid: Modify default EDID.
Wrap 8 bytes per line.
Add these modes:
    IBM     :   720x400    87.849542 Hz   9:5     39.444 kHz     35.500000 MHz
    DMT 0x0f:  1024x768i   86.957532 Hz   4:3     35.522 kHz     44.900000 MHz
    DMT 0x24:  1280x1024   75.024675 Hz   5:4     79.976 kHz    135.000000 MHz
    Apple   :  1152x870    75.061550 Hz 192:145   68.681 kHz    100.000000 MHz
2025-05-27 07:10:29 -07:00
Maxim Poliakovski 143498f5dd scsihd: implement MODE SENSE, page 4.
Page 4 aka Rigid Disk Drive Geometry Parameters
is required for the rz_disk driver in MkLinux.
2025-05-26 21:37:19 +02:00
Maxim Poliakovski eb61ab8c61 viacuda: implement T1 free-run mode. 2025-05-26 21:37:19 +02:00
Maxim Poliakovski 89139f3bae viacuda: fix VIA T2 emulation. 2025-05-26 21:31:26 +02:00
Maxim Poliakovski 2419731dbc viacuda: fix VIA T1 one-shot emulation.
Implement T1 to closely match the Apple VIA cell spec.
2025-05-26 21:31:26 +02:00
dingusdev 8258b7fb28 Further code cleanup 2025-05-23 06:31:42 -07:00
dingusdev 3646732db3 Fix soundserver_cubeb compilation warnings 2025-05-22 06:37:43 -07:00
joevt 224d869bdd pcibase: Implement status register write.
Writing a 1 to a status register bit will clear that bit. The following bits can be cleared:
- 15 Detected Parity Error
- 14 Signaled System Error
- 13 Received Master Abort
- 12 Received Target Abort
- 11 Signaled Target Abort
-  8 Master Data Parity Error
2025-05-22 06:27:24 -07:00
joevt 69490df8f8 pcicardbusbridge: Fix pci_io_write. 2025-05-22 06:26:55 -07:00
dingusdev 27e99edfeb Start SCSI reassign cmd 2025-05-21 19:44:37 -07:00
Maxim Poliakovski 101d8aa885 ppcmmu: fix TLB invalidation.
The PowerPC manual says that `tlbie` only considers
bits 4-19 of the EA. Set the mask accordingly.
2025-05-21 18:42:57 +02:00
Maxim Poliakovski 9f9160c956 Cleanup devices/CMakeLists.txt 2025-05-09 12:45:06 +02:00
161 changed files with 3506 additions and 2361 deletions

No files matched your search

+15
View File
@@ -97,6 +97,21 @@ if (NOT EMSCRIPTEN)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
# Warn if no audio backends were detected on Linux/Unix systems
if (UNIX AND NOT APPLE)
if (NOT USE_PULSE AND NOT USE_ALSA AND NOT USE_JACK AND
NOT USE_SNDIO AND NOT USE_OSS AND NOT USE_SUN)
message(WARNING
"No Cubeb audio backends detected on Linux/Unix system!\n"
"Audio will NOT work at runtime.\n"
"Please install development headers for at least one of:\n"
" - PulseAudio (libpulse-dev / pulseaudio-libs-devel)\n"
" - ALSA (libasound2-dev / alsa-lib-devel)\n"
" - JACK (libjack-dev / jack-audio-connection-kit-devel)\n"
" - sndio (libsndio-dev)")
endif()
endif()
endif()
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
+3
View File
@@ -27,6 +27,9 @@
- Randrianasulu
- lefp
- mathstuf
- seanm
- erichelgeson
- alicela1n
## Testing
+19 -11
View File
@@ -8,17 +8,19 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
## Implemented Features
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World PowerPC Macs, and the Pippin.
This emulator has a debugging environment, complete with a disassembler.
## How to Use
This program currently uses the command prompt to work.
There are a few command line arguments one must enter when starting the program.
There are a few command line arguments one can enter when starting the program.
```
-r, --realtime
@@ -36,21 +38,31 @@ Enter the interactive debugger.
-b, --bootrom TEXT:FILE
```
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
Specifies the Boot ROM path. It otherwise looks for bootrom.bin.
```
-m, --machine TEXT
```
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
Specify machine ID. Otherwise, the emulator will attempt to determine machine ID from the boot rom otherwise.
As of now, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
As of now, the most complete machines are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3 Beige.
To go into to the debugger regardless of how you started the emulator, press Control and C on the terminal window.
## How to Compile
You need to install development tools first.
At least, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
At minimum, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
Clone the repository using the appropriate command:
```
git clone https://github.com/dingusdev/dingusppc
```
If this is from a mirror, replace the argument with the source you want to use instead.
You will also have to recursive clone or run
```
@@ -100,7 +112,3 @@ make testppc
- 2 GB of RAM
- 2 GB of Hard Disk Space
- Graphics Card with a minimum resolution of 800*600
## Compiler Requirements
- Any C++20 compatible compiler
+9 -4
View File
@@ -42,6 +42,7 @@ enum : uint16_t {
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
};
@@ -75,7 +76,6 @@ public:
uint32_t flags;
uint32_t key;
uint16_t keys_state;
};
@@ -126,9 +126,11 @@ public:
event_manager = new EventManager();
}
return event_manager;
};
}
void poll_events(uint32_t kbd_locale);
void poll_events();
void set_keyboard_locale(uint32_t keyboard_id);
void post_keyboard_state_events();
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -159,17 +161,19 @@ public:
_window_signal.disconnect_all();
_mouse_signal.disconnect_all();
_keyboard_signal.disconnect_all();
_gamepad_signal.disconnect_all();
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
_gamepad_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {}; // private constructor to implement a singleton
EventManager() {} // private constructor to implement a singleton
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
@@ -182,6 +186,7 @@ private:
uint64_t key_downs = 0;
uint64_t key_ups = 0;
uint8_t buttons_state = 0;
uint32_t kbd_locale = 0;
};
#endif // EVENT_MANAGER_H
+119 -14
View File
@@ -32,7 +32,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_l
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
void EventManager::poll_events(uint32_t kbd_locale) {
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
this->kbd_locale = keyboard_id;
}
void EventManager::poll_events() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -54,9 +58,12 @@ void EventManager::poll_events(uint32_t kbd_locale) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
if (event.key.repeat)
break;
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
if (event.key.keysym.sym == SDLK_g && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_g && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we;
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
@@ -69,7 +76,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_s && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
@@ -79,7 +86,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
@@ -88,8 +95,18 @@ void EventManager::poll_events(uint32_t kbd_locale) {
}
return;
}
// Control-Shift-F: fullscreen reverse
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LSHIFT)) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-+: bigger
if (event.key.keysym.sym == SDLK_EQUALS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_EQUALS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
@@ -99,7 +116,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
return;
}
// Control--: smaller
if (event.key.keysym.sym == SDLK_MINUS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_MINUS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
@@ -108,8 +125,26 @@ void EventManager::poll_events(uint32_t kbd_locale) {
}
return;
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
loguru::Verbosity_INFO
:
loguru::Verbosity_MAX;
}
return;
}
// Control-D: debugger
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
power_on = false;
power_off_reason = po_enter_debugger;
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((SDL_GetModState() & KMOD_ALL) == KMOD_RALT) != 0) {
if (event.key.keysym.sym == SDLK_DELETE && ((event.key.keysym.mod & KMOD_ALL) == KMOD_RALT) != 0) {
KeyboardEvent ke{};
ke.key = AdbKey_Control;
@@ -126,7 +161,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
this->_keyboard_signal.emit(ke);
return;
}
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
int key_code = get_sdl_event_key_code(event.key, this->kbd_locale);
if (key_code != -1) {
KeyboardEvent ke{};
ke.key = key_code;
@@ -139,7 +174,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
}
// Caps Lock is a special case, since it's a toggle key
if (ke.key == AdbKey_CapsLock) {
ke.flags = SDL_GetModState() & KMOD_CAPS ?
ke.flags = event.key.keysym.mod & KMOD_CAPS ?
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
}
this->_keyboard_signal.emit(ke);
@@ -249,6 +284,76 @@ void EventManager::poll_events(uint32_t kbd_locale) {
this->_post_signal.emit();
}
void EventManager::post_keyboard_state_events() {
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
SDL_KeyboardEvent keyevent = { .type = SDL_KEYDOWN };
SDL_Scancode scancode;
KeyboardEvent ke{};
typedef struct {
SDL_Scancode scancode;
SDL_Keymod keymod;
AdbKey adbkey;
} Modifier_t;
static Modifier_t modifiers[] = {
SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift ,
SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift ,
SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control ,
SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl,
SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option ,
SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption ,
SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command ,
SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command ,
// SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear ,
SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock ,
// SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? ,
// SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 ,
SDL_SCANCODE_UNKNOWN
};
LOG_F(INFO, "Current keyboard state:");
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
if (!(modstate & mod->keymod))
continue;
LOG_F(INFO, " mod:%s", SDL_GetScancodeName(mod->scancode));
ke.key = mod->adbkey;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
}
for (int i = 0; i < numkeys; i++) {
if (!states[i])
continue;
scancode = (SDL_Scancode)i;
Modifier_t *mod = modifiers;
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
if (mod->scancode == scancode) {
LOG_F(INFO, " ignore:%s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
int key_code = get_sdl_event_key_code(keyevent, this->kbd_locale);
if (key_code != -1) {
ke.key = key_code;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
}
}
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
{
@@ -331,11 +436,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_PAGEDOWN: return AdbKey_PageDown;
case SDLK_LCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_RightControl;
case SDLK_LSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_RightShift;
case SDLK_LALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_RightOption;
case SDLK_LGUI: return AdbKey_Command;
case SDLK_RGUI: return AdbKey_Command;
case SDLK_MENU: return AdbKey_Grave;
@@ -345,7 +450,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_DOWN: return AdbKey_ArrowDown;
case SDLK_LEFT: return AdbKey_ArrowLeft;
case SDLK_RIGHT: return AdbKey_ArrowRight;
;
case SDLK_KP_0: return AdbKey_Keypad0;
case SDLK_KP_1: return AdbKey_Keypad1;
case SDLK_KP_2: return AdbKey_Keypad2;
@@ -364,7 +469,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
;
case SDLK_F1: return AdbKey_F1;
case SDLK_F2: return AdbKey_F2;
case SDLK_F3: return AdbKey_F3;
+8 -8
View File
@@ -64,13 +64,13 @@ public:
return true;
}
return false;
};
}
void push(T val)
{
std::lock_guard<std::recursive_mutex> lk(mtx);
std::priority_queue<T, Container, Compare>::push(val);
};
}
T pop()
{
@@ -78,7 +78,7 @@ public:
T val = std::priority_queue<T, Container, Compare>::top();
std::priority_queue<T, Container, Compare>::pop();
return val;
};
}
std::recursive_mutex& get_mtx()
{
@@ -111,20 +111,20 @@ public:
timer_manager = new TimerManager();
}
return timer_manager;
};
}
// callback for retrieving current time
void set_time_now_cb(const std::function<uint64_t()> &cb) {
this->get_time_now = cb;
};
}
// callback for acknowledging time changes
void set_notify_changes_cb(const timer_cb &cb) {
this->notify_timer_changes = cb;
};
}
// return current virtual time in nanoseconds
uint64_t current_time_ns() { return get_time_now(); };
uint64_t current_time_ns() { return get_time_now(); }
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
@@ -137,7 +137,7 @@ public:
private:
static TimerManager* timer_manager;
TimerManager(){}; // private constructor to implement a singleton
TimerManager(){} // private constructor to implement a singleton
// timer queue
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
+2 -2
View File
@@ -253,9 +253,9 @@ const char* trap_cond[32] = {/*Trap conditions*/
"twlt", "", "", "", "twle", "", "", "",
"twne", "", "", "", "", "", "", ""};
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "", "",
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "dec", "",
"lr", "ctr", "", "", "", "", "", "",
"", "", "dsisr", "dar", "", "", "dec", "",
"", "", "dsisr", "dar", "rtcu", "rtcl", "dec", "",
"", "sdr1", "srr0", "srr1", "", "", "", ""};
const char* spr_index8[32] = {
+8
View File
@@ -106,6 +106,7 @@ enum SPR : int {
SPRG1 = 273,
SPRG2 = 274,
SPRG3 = 275,
EAR = 282,
TBL_S = 284, // supervisor TBL
TBU_S = 285, // supervisor TBU
PVR = 287,
@@ -114,6 +115,8 @@ enum SPR : int {
PMC2 = 954,
SIA = 955,
MMCR1 = 956,
PMC3 = 957,
PMC4 = 958,
SDA = 959,
HID0 = 1008,
HID1 = 1009,
@@ -301,6 +304,11 @@ enum XER : uint32_t {
SO = 1UL << 31
};
enum DSISR : uint32_t {
PROT = 1UL << 27,
STORE = 1UL << 25
};
//for inf and nan checks
enum FPOP : int {
DIV = 0x12,
+6 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -118,7 +118,7 @@ std::unordered_map<uint32_t, uint64_t> num_opcodes;
class CPUProfile : public BaseProfile {
public:
CPUProfile() : BaseProfile("PPC_CPU") {};
CPUProfile() : BaseProfile("PPC_CPU") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -169,7 +169,7 @@ public:
.count_total = num_executed_instrs});
}
#endif
};
}
void reset() {
num_executed_instrs = 0;
@@ -180,7 +180,7 @@ public:
#ifdef CPU_PROFILING_OPS
num_opcodes.clear();
#endif
};
}
};
#endif
@@ -899,7 +899,8 @@ static map<string, int> SPRName2Num = {
{"SDR1", SPR::SDR1}, {"MQ", SPR::MQ}, {"RTCU", SPR::RTCU_S},
{"RTCL", SPR::RTCL_S}, {"DSISR", SPR::DSISR}, {"DAR", SPR::DAR},
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1}
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
};
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
+38 -27
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -540,12 +540,11 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
}
}
static TLBEntry* itlb2_refill(uint32_t guest_va)
{
static TLBEntry* itlb2_refill(uint32_t guest_va) {
BATResult bat_res;
uint32_t phys_addr;
TLBEntry *tlb_entry;
uint16_t flags = 0;
TLBEntry* tlb_entry = nullptr;
uint16_t flags = 0;
/* instruction address translation if enabled */
if (ppc_state.msr & MSR::IR) {
@@ -555,11 +554,13 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
} else {
bat_res = ppc_block_address_translation<BATType::IBAT>(guest_va);
}
if (bat_res.hit) {
// check block protection
// only PP = 0 (no access) causes ISI exception
if (!bat_res.prot) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000);
return nullptr; // Stop refill on exception
}
phys_addr = bat_res.phys;
flags |= TLBFlags::TLBE_FROM_BAT; // tell the world we come from
@@ -567,7 +568,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
// page address translation
PATResult pat_res = page_address_translation(guest_va, true, !!(ppc_state.msr & MSR::PR), 0);
phys_addr = pat_res.phys;
flags = TLBFlags::TLBE_FROM_PAT; // tell the world we come from
flags |= TLBFlags::TLBE_FROM_PAT; // tell the world we come from
}
} else { // instruction translation disabled
phys_addr = guest_va;
@@ -577,18 +578,23 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
AddressMapEntry* rgn_desc = mem_ctrl_instance->find_range(phys_addr);
if (rgn_desc) {
if (rgn_desc->type & RT_MMIO) {
ABORT_F("Instruction fetch from MMIO region at 0x%08X!\n", phys_addr);
// TODO: ISI or Machine Check for this?
mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000);
}
// refill the secondary TLB
const uint32_t tag = guest_va & ~0xFFFUL;
tlb_entry = tlb2_target_entry<TLBType::ITLB>(tag);
tlb_entry->tag = tag;
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
(phys_addr - rgn_desc->start);
const uint32_t page_base = guest_va & ~0xFFFUL;
tlb_entry = tlb2_target_entry<TLBType::ITLB>(page_base);
tlb_entry->tag = page_base;
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
// Calculate offset based on page base to ensure alignment
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - (int64_t)page_base +
((phys_addr & ~0xFFFUL) - rgn_desc->start);
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
} else {
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
// TODO: ISI or Machine Check for this?
mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000);
}
return tlb_entry;
@@ -618,7 +624,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
LOG_F(9, "BAT DSI exception in TLB2 refill!");
if (!is_dbg)
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
ppc_state.spr[SPR::DSISR] = DSISR::PROT | (is_write << 25);
ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0);
}
@@ -782,9 +788,9 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
{
TLBEntry *tlb_entry = &tlb1[(tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (tlb_entry->tag == tag) {
if (tlb_entry->tag != TLB_INVALID_TAG && (tlb_entry->tag & TLB_VPS_MASK) == tag) {
tlb_entry->tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", tag);
}
}
@@ -792,16 +798,16 @@ static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &
{
TLBEntry *tlb_entry = &tlb2[((tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
for (int i = 0; i < TLB2_WAYS; i++) {
if (tlb_entry[i].tag == tag) {
if (tlb_entry[i].tag != TLB_INVALID_TAG && (tlb_entry[i].tag & TLB_VPS_MASK) == tag) {
tlb_entry[i].tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", tag);
}
}
}
void tlb_flush_entry(uint32_t ea)
{
const uint32_t tag = ea & ~0xFFFUL;
const uint32_t tag = ea & TLB_VPS_MASK;
tlb_flush_primary_entry(itlb1_mode1, tag);
tlb_flush_secondary_entry(itlb2_mode1, tag);
tlb_flush_primary_entry(itlb1_mode2, tag);
@@ -951,6 +957,11 @@ static void mpc601_bat_update(uint32_t bat_reg)
}
}
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
{
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
static void ppc_ibat_update(uint32_t bat_reg)
{
int upper_reg_num;
@@ -999,7 +1010,6 @@ static void ppc_dbat_update(uint32_t bat_reg)
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
}
}
void mmu_pat_ctx_changed()
@@ -1340,7 +1350,7 @@ template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint
class MMUProfile : public BaseProfile {
public:
MMUProfile() : BaseProfile("PPC_MMU") {};
MMUProfile() : BaseProfile("PPC_MMU") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1388,7 +1398,7 @@ public:
vars.push_back({.name = "Unaligned Crosspage Writes Total",
.format = ProfileVarFmt::DEC,
.value = unaligned_crossp_w});
};
}
void reset() {
dmem_reads_total = 0;
@@ -1402,7 +1412,7 @@ public:
unaligned_writes = 0;
unaligned_crossp_r = 0;
unaligned_crossp_w = 0;
};
}
};
#endif
@@ -1414,7 +1424,7 @@ public:
class TLBProfile : public BaseProfile {
public:
TLBProfile() : BaseProfile("PPC:MMU:TLB") {};
TLBProfile() : BaseProfile("PPC:MMU:TLB") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1446,14 +1456,14 @@ public:
vars.push_back({.name = "Number of replaced TLB entries",
.format = ProfileVarFmt::DEC,
.value = num_entry_replacements});
};
}
void reset() {
num_primary_dtlb_hits = 0;
num_secondary_dtlb_hits = 0;
num_dtlb_refills = 0;
num_entry_replacements = 0;
};
}
};
#endif
@@ -1638,6 +1648,7 @@ void ppc_mmu_init()
if (is_601) {
// use 601-style unified BATs
ibat_update = &mpc601_bat_update;
dbat_update = &mpc601_dbat_update;
} else {
// use PPC-style BATs
ibat_update = &ppc_ibat_update;
+1
View File
@@ -87,6 +87,7 @@ constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
typedef struct TLBEntry {
uint32_t tag;
+62 -4
View File
@@ -931,10 +931,16 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
}
switch (ref_spr) {
case SPR::XER:
case SPR::LR:
case SPR::CTR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::MQ:
if (!(is_601 || include_601)) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
@@ -972,8 +978,37 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
break;
}
case SPR::TBL_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
break;
}
case SPR::TBU_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
break;
}
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::PVR:
case SPR::EAR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MFSPR: %d", ref_spr);
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
}
}
@@ -988,12 +1023,20 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
}
uint32_t val = ppc_state.gpr[reg_d];
switch (ref_spr) {
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::LR:
case SPR::CTR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::MQ:
if (is_601 || include_601)
ppc_state.spr[ref_spr] = val;
@@ -1003,13 +1046,13 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case SPR::RTCL_U:
case SPR::RTCU_U:
case SPR::DEC_U:
if (!is_601) {
if (is_601) {
ppc_state.spr[ref_spr] = val;
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
break;
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::SDR1:
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
@@ -1042,6 +1085,19 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
ppc_state.spr[TBL_S] = (uint32_t)tbr_wr_value;
ppc_state.spr[TBU_S] = val;
break;
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::EAR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.spr[ref_spr] = val;
break;
case SPR::PVR:
break;
case 528:
@@ -1065,8 +1121,10 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case 543:
ppc_state.spr[ref_spr] = val;
dbat_update(ref_spr);
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MTSPR: %d", ref_spr);
ppc_state.spr[ref_spr] = val;
}
}
+2 -1
View File
@@ -321,7 +321,8 @@ int main() {
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
int new_msr = (MSR::ME | MSR::IP | MSR::FP);
ppc_msr_did_change(ppc_state.msr, new_msr, false);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,7 +31,7 @@ public:
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
};
}
void enter_debugger();
+2 -4
View File
@@ -8,10 +8,10 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_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/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
@@ -26,12 +26,10 @@ platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
+1 -1
View File
@@ -94,7 +94,7 @@ void AdbAppleJack::set_register_3() {
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}
AdbAppleJack::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+1 -1
View File
@@ -133,7 +133,7 @@ static const PropMap AdbBus_Properties = {
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, AdbBus_Properties
AdbBus::create, {}, AdbBus_Properties, HWCompType::ADB_HOST
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+7 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -55,7 +55,7 @@ public:
void register_device(AdbDevice* dev_obj);
uint8_t process_command(const uint8_t* in_data, int data_size);
uint8_t get_output_count() { return this->output_count; };
uint8_t get_output_count() { return this->output_count; }
// Polls devices that have a service request flag set. Returns the talk
// command corresponding to the first device that responded with data, or
@@ -63,11 +63,11 @@ public:
uint8_t poll();
// callbacks meant to be called by devices
const uint8_t* get_input_buf() { return this->input_buf; };
uint8_t* get_output_buf() { return this->output_buf; };
uint8_t get_input_count() { return this->input_count; };
void set_output_count(uint8_t count) { this->output_count = count; };
bool already_answered() { return this->got_answer; };
const uint8_t* get_input_buf() { return this->input_buf; }
uint8_t* get_output_buf() { return this->output_buf; }
uint8_t get_input_count() { return this->input_count; }
void set_output_count(uint8_t count) { this->output_count = count; }
bool already_answered() { return this->got_answer; }
private:
std::vector<AdbDevice*> devices;
+7 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -37,7 +37,7 @@ int AdbDevice::device_postinit() {
this->host_obj->register_device(this);
return 0;
};
}
uint8_t AdbDevice::poll() {
if (!this->srq_flag) {
@@ -84,12 +84,16 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
switch(reg_num & 3) {
case 0:
this->set_register_0();
break;
case 1:
this->set_register_1();
break;
case 2:
this->set_register_2();
break;
case 3:
this->set_register_3();
break;
}
}
}
@@ -104,5 +108,5 @@ bool AdbDevice::get_register_3() {
}
uint8_t AdbDevice::gen_random_address() {
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
return TimerManager::get_instance()->current_time_ns() & 0xF;
}
+9 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,7 +47,7 @@ public:
virtual void reset() = 0;
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
virtual uint8_t get_address() { return this->my_addr; };
virtual uint8_t get_address() { return this->my_addr; }
// Attempts to poll the device. Returns the talk command corresponding to
// the device if it has data, 0 otherwise.
@@ -56,15 +56,15 @@ public:
protected:
uint8_t gen_random_address();
virtual bool get_register_0() { return false; };
virtual bool get_register_1() { return false; };
virtual bool get_register_2() { return false; };
virtual bool get_register_0() { return false; }
virtual bool get_register_1() { return false; }
virtual bool get_register_2() { return false; }
virtual bool get_register_3();
virtual void set_register_0() {};
virtual void set_register_1() {};
virtual void set_register_2() {};
virtual void set_register_3() {};
virtual void set_register_0() {}
virtual void set_register_1() {}
virtual void set_register_2() {}
virtual void set_register_3() {}
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
+9 -1
View File
@@ -77,6 +77,14 @@ uint8_t AdbKeyboard::consume_pending_event() {
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
}
if (this->dev_handler_id != 3) {
switch (event->key) {
case AdbKey_RightControl : event->key = AdbKey_Control; break;
case AdbKey_RightShift : event->key = AdbKey_Shift ; break;
case AdbKey_RightOption : event->key = AdbKey_Option ; break;
}
}
return (key_state << 7) | (event->key & 0x7F);
}
@@ -111,7 +119,7 @@ void AdbKeyboard::set_register_3() {
}
static const DeviceDescription AdbKeyboard_Descriptor = {
AdbKeyboard::create, {}, {}
AdbKeyboard::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
+4
View File
@@ -128,6 +128,10 @@ enum AdbKey {
AdbKey_Command = 0x37,
AdbKey_CapsLock = 0x39,
AdbKey_RightControl = 0x7d,
AdbKey_RightShift = 0x7b,
AdbKey_RightOption = 0x7c,
AdbKey_ArrowUp = 0x3e,
AdbKey_ArrowDown = 0x3d,
AdbKey_ArrowLeft = 0x3b,
+1 -1
View File
@@ -172,7 +172,7 @@ uint8_t AdbMouse::get_buttons_state() const {
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}
AdbMouse::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
+36 -3
View File
@@ -21,13 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Basic ATA device emulation. */
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
#include <loguru.hpp>
#include <cstring>
#include <cinttypes>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -110,7 +111,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (is_selected() && this->has_data()) {
if (this->is_selected() && this->has_data()) {
*this->cur_data_ptr++ = BYTESWAP_16(value);
this->chunk_cnt -= 2;
if (this->chunk_cnt <= 0) {
@@ -159,7 +160,7 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
break;
}
this->r_command = value;
if (is_selected() || this->r_command == DIAGNOSTICS) {
if (this->is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
}
break;
@@ -191,6 +192,38 @@ void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
this->r_dev_ctrl = new_ctrl;
}
int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
if (!this->xfer_cnt || !this->is_dma_xfer)
return 0;
int xfer_size = std::min(this->xfer_cnt, len);
if (this->xfer_cnt != len)
LOG_F(WARNING, "%s: xfer_cnt != len", this->name.c_str());
//for (int i = 0; i < xfer_size >> 1; i++)
// this->data_ptr[i] = BYTESWAP_16(this->data_ptr[i]);
std::memcpy(buf, this->data_ptr, xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
} else {
this->r_status &= ~BSY;
this->r_status |= DRQ;
}
return xfer_size;
}
int AtaBaseDevice::push_data(uint8_t *buf, int len) {
return 0;
}
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
return;
+6 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -43,10 +43,12 @@ public:
void set_host(IdeChannel* host, uint8_t dev_id) {
this->host_obj = host;
this->my_dev_id = dev_id;
};
}
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
int pull_data(uint8_t *buf, int len) override;
int push_data(uint8_t *buf, int len) override;
virtual int perform_command() = 0;
@@ -54,7 +56,7 @@ public:
void pdiag_callback() override {
this->r_error &= 0x7F;
};
}
virtual void device_reset(bool is_soft_reset);
virtual void device_set_signature();
@@ -103,6 +105,7 @@ protected:
int xfer_cnt = 0;
int chunk_cnt = 0;
int chunk_size = 0;
bool is_dma_xfer = false;
std::function<void()> post_xfer_action = nullptr;
};
+14 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -56,7 +56,8 @@ enum ATA_Reg : int {
COMMAND = 0x07, // command (write)
ALT_STATUS = 0x16, // alt status (read)
DEV_CTRL = 0x16, // device control (write)
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
TIME_CONFIG = 0x20, // Apple ASIC specific timing configuration
INT_REG = 0x30, // Interrupt Register (read) 0x40 = int request (KeyLargo only)
};
/** ATAPI specific register offsets. */
@@ -142,8 +143,11 @@ enum ATA_Cmd : uint8_t {
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
READ_DMA = 0xC8,
READ_DMA_NR = 0xC9,
WRITE_DMA = 0xCA,
STANDBY_IMMEDIATE_E0 = 0xE0,
WRITE_DMA_NR = 0xCB,
STANDBY_IMMEDIATE = 0xE0,
SLEEP = 0xE6,
FLUSH_CACHE = 0xE7, // ATA-5
WRITE_BUFFER_DMA = 0xE9,
READ_BUFFER_DMA = 0xEB,
@@ -151,7 +155,7 @@ enum ATA_Cmd : uint8_t {
SET_FEATURES = 0xEF,
};
}; // namespace ata_interface
} // namespace ata_interface
/** Interface for ATA devices. */
class AtaInterface {
@@ -160,9 +164,11 @@ public:
virtual ~AtaInterface() = default;
virtual uint16_t read(const uint8_t reg_addr) = 0;
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
virtual int pull_data(uint8_t *buf, int len) { return 0; };
virtual int push_data(uint8_t *buf, int len) { return 0; };
virtual int get_device_id() = 0;
virtual void pdiag_callback() {};
virtual void pdiag_callback() {}
};
/** Dummy ATA device. */
@@ -178,12 +184,12 @@ public:
// to prevent the software from waiting for a long time
// for empty slots
return 0xFF7FU;
};
}
void write(const uint8_t reg_addr, const uint16_t val) override {};
void write(const uint8_t reg_addr, const uint16_t val) override {}
// invalid device ID means no real device is present
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; }
};
#endif // ATA_INTERFACE_H
+35 -21
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -191,7 +191,11 @@ int AtaHardDisk::perform_command() {
this->signal_data_ready();
break;
case SET_FEATURES:
if (this->r_features == 3) {
switch (this->r_features) {
case 2:
LOG_F(INFO, "%s: write cache enabled", this->name.c_str());
break;
case 3:
switch(this->r_sect_count >> 3) {
case 0:
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
@@ -201,8 +205,9 @@ int AtaHardDisk::perform_command() {
this->r_sect_count & 7);
break;
case 4:
this->cur_dma_mode = this->r_sect_count & 7;
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
this->r_sect_count & 7);
this->cur_dma_mode);
break;
default:
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
@@ -210,15 +215,19 @@ int AtaHardDisk::perform_command() {
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
} else {
break;
case 0xAA:
LOG_F(INFO, "%s: read look-ahead enabled", this->name.c_str());
break;
default:
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
this->name.c_str(), this->r_features);
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case STANDBY_IMMEDIATE_E0:
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
case STANDBY_IMMEDIATE:
LOG_F(INFO, "%s: immediate standby requested", this->name.c_str());
this->r_status &= ~BSY;
this->update_intrq(1);
break;
@@ -236,35 +245,40 @@ void AtaHardDisk::prepare_identify_info() {
std::memset(this->data_buf, 0, sizeof(this->data_buf));
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
buf_ptr[49] = 0x0200; // report LBA support
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
// Maximum number of logical sectors per data block that the device supports
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
WRITE_WORD_LE_A(&buf_ptr[47], 0x8000 | SECTORS_PER_INT);
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
// logical sectors that shall be transferred per data block for
// READ_MULTIPLE/WRITE_MULTIPLE commands.
if (this->sectors_per_int)
buf_ptr[59] = 0x100 | this->sectors_per_int;
WRITE_WORD_LE_A(&buf_ptr[59], 0x100 | this->sectors_per_int);
buf_ptr[ 1] = this->cylinders;
buf_ptr[ 3] = this->heads;
buf_ptr[ 6] = this->sectors;
WRITE_WORD_LE_A(&buf_ptr[ 1], this->cylinders);
WRITE_WORD_LE_A(&buf_ptr[ 3], this->heads);
WRITE_WORD_LE_A(&buf_ptr[ 6], this->sectors);
buf_ptr[57] = this->total_sectors & 0xFFFFU;
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
// report validity for the advanced PIO and MWDMA fields
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
// report LBA capacity
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
}
uint64_t AtaHardDisk::get_lba() {
if (this->r_dev_head & ATA_Dev_Head::LBA) {
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num);
return uint64_t(((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num));
} else { // translate old fashioned CHS addressing to LBA
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
uint8_t h = this->r_dev_head & 0xF;
@@ -274,7 +288,7 @@ uint64_t AtaHardDisk::get_lba() {
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
return -1ULL;
} else
return (this->heads * c + h) * this->sectors + s - 1;
return uint64_t((this->heads * c + h) * this->sectors + s - 1);
}
}
@@ -331,7 +345,7 @@ static const PropMap AtaHardDisk_Properties = {
};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties
AtaHardDisk::create, {}, AtaHardDisk_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
+2 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -71,6 +71,7 @@ private:
uint8_t sectors;
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
char * buffer = new char[1 <<17];
};
+1
View File
@@ -43,6 +43,7 @@ public:
// methods to be implemented in the particular device
int perform_command() override;
virtual void perform_packet_command() = 0;
virtual int get_config(uint8_t* pkt, uint8_t* buf) = 0;
virtual int request_data() = 0;
virtual bool data_available() = 0;
+43 -6
View File
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <machines/machineproperties.h>
#include <memaccess.h>
#include <cstring>
#include <string>
#include <core/timermanager.h>
@@ -315,6 +316,18 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
break;
}
case ScsiCommand::GET_CONFIG: {
this->xfer_cnt = this->get_config(this->cmd_pkt, this->data_buf);
if (this->xfer_cnt == 0) {
this->present_status();
} else {
this->xfer_cnt = std::min((int)this->r_byte_count, this->xfer_cnt);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
}
default:
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
this->cmd_pkt[0]);
@@ -323,6 +336,29 @@ void AtapiCdrom::perform_packet_command() {
}
}
int AtapiCdrom::get_config(uint8_t* pkt, uint8_t* buf) {
std::memset(buf, 0, 16);
// Data length (4 bytes header + 8 bytes for one feature descriptor - 4 bytes for length field)
uint32_t data_len = 8;
buf[0] = (data_len >> 24) & 0xFF;
buf[1] = (data_len >> 16) & 0xFF;
buf[2] = (data_len >> 8) & 0xFF;
buf[3] = data_len & 0xFF;
// Feature Descriptor 1 - Set profile to CD-ROM
buf[6] = 0;
buf[7] = 0x08;
// Feature Descriptor 2 - Feature Code, Version 0
buf[8] = 0x00;
buf[9] = 0x01; // Core Feature Code
buf[10] = 0x03; // Persist and Current bits set
buf[11] = 0x04; // Additional Length
return 12;
}
int AtapiCdrom::request_data() {
// continuation of READ_CD above
@@ -358,11 +394,12 @@ uint16_t AtapiCdrom::get_data() {
area_end += 4; // Header
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4];
header[0] = msf.min;
header[1] = msf.sec;
header[2] = msf.frm;
header[3] = 0x01; // Mode 1
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
@@ -438,7 +475,7 @@ static const PropMap AtapiCdrom_Properties = {
};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties
AtapiCdrom::create, {}, AtapiCdrom_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
+2
View File
@@ -42,6 +42,8 @@ public:
void perform_packet_command() override;
int get_config(uint8_t* pkt, uint8_t* buf) override;
int request_data() override;
bool data_available() override {
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -139,7 +139,7 @@ bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
return true;
};
}
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
+18 -2
View File
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
and interrupt handling.
*/
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
@@ -81,6 +82,21 @@ void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int siz
}
}
int IdeChannel::xfer_from(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->pull_data(buf, len);
}
int IdeChannel::xfer_to(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->push_data(buf, len);
}
void IdeChannel::assert_dmareq(uint64_t delay) {
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
this->channel_obj->xfer_retry();
});
}
int MacioIdeChannel::device_postinit() {
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
@@ -117,11 +133,11 @@ void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const in
}
static const DeviceDescription Ide0_Descriptor = {
MacioIdeChannel::create_first, {}, {}
MacioIdeChannel::create_first, {}, {}, HWCompType::IDE_BUS
};
static const DeviceDescription Ide1_Descriptor = {
MacioIdeChannel::create_second, {}, {}
MacioIdeChannel::create_second, {}, {}, HWCompType::IDE_BUS
};
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
+13 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define IDE_CHANNEL_H
#include <devices/common/ata/atadefs.h>
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
@@ -33,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
class IdeChannel : public HWComponent
class IdeChannel : public HWComponent, public DmaDevice
{
public:
IdeChannel(const std::string name);
@@ -41,8 +42,11 @@ public:
void register_device(int id, AtaInterface* dev_obj);
uint32_t read(const uint8_t reg_addr, const int size);
void write(const uint8_t reg_addr, const uint32_t val, const int size);
virtual uint32_t read(const uint8_t reg_addr, const int size);
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size);
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
void assert_pdiag() {
this->devices[0]->pdiag_callback();
@@ -60,6 +64,8 @@ public:
this->irq_callback(intrq_state);
}
void assert_dmareq(uint64_t delay);
protected:
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
@@ -74,7 +80,7 @@ private:
class MacioIdeChannel : public IdeChannel
{
public:
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
MacioIdeChannel(const std::string name) : IdeChannel(name) {}
~MacioIdeChannel() = default;
static std::unique_ptr<HWComponent> create_first() {
@@ -87,8 +93,8 @@ public:
int device_postinit() override;
uint32_t read(const uint8_t reg_addr, const int size);
void write(const uint8_t reg_addr, const uint32_t val, const int size);
virtual uint32_t read(const uint8_t reg_addr, const int size) override;
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size) override;
private:
uint32_t ch_config = 0; // timing configuration for this channel
+6 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -38,10 +38,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <vector>
AthensClocks::AthensClocks(uint8_t dev_addr)
{
AthensClocks::AthensClocks(uint8_t dev_addr) : I2CDevice() {
set_name("Athens");
supports_types(HWCompType::I2C_DEV);
this->my_addr = dev_addr;
@@ -75,10 +73,9 @@ bool AthensClocks::send_subaddress(uint8_t sub_addr)
bool AthensClocks::send_byte(uint8_t data)
{
switch (this->pos) {
switch (this->pos++) {
case 0:
this->reg_num = data;
this->pos++;
break;
case 1:
if (this->reg_num >= ATHENS_NUM_REGS) {
@@ -90,7 +87,7 @@ bool AthensClocks::send_byte(uint8_t data)
break;
default:
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
return false; // return NACK
//return false; // return NACK
}
return true;
}
@@ -103,6 +100,8 @@ bool AthensClocks::receive_byte(uint8_t* p_data)
int AthensClocks::get_sys_freq()
{
LOG_F(ERROR, "%s: sys clock calculation not implemented yet", this->name.c_str());
return 0;
}
+3 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATHENS_H
#define ATHENS_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
@@ -47,10 +46,9 @@ enum AthensRegs: uint8_t {
P1 = 7
};
}; // namespace AthensRegs
} // namespace AthensRegs
class AthensClocks : public I2CDevice, public HWComponent
{
class AthensClocks : public I2CDevice {
public:
AthensClocks(uint8_t dev_addr);
AthensClocks(uint8_t dev_addr, const float crystal_freq);
+12
View File
@@ -313,6 +313,15 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
case DMAReg::CMD_PTR_LO:
result = this->cmd_ptr;
break;
case DMAReg::INT_SELECT:
result = this->int_select;
break;
case DMAReg::BRANCH_SELECT:
result = this->branch_select;
break;
case DMAReg::WAIT_SELECT:
result = this->wait_select;
break;
default:
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
this->get_name().c_str(), offset);
@@ -431,6 +440,9 @@ void DMAChannel::xfer_from_device() {
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
} else if (got_bytes) {
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
this->get_name().c_str());
}
this->interpret_cmd();
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -99,7 +99,7 @@ namespace DBDMA_Cmd {
NOP = 6,
STOP = 7
};
};
}
typedef std::function<void(void)> DbdmaCallback;
@@ -129,7 +129,7 @@ public:
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
this->int_ctrl = int_ctrl_obj;
this->irq_id = irq_id;
};
}
protected:
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
+21 -21
View File
@@ -35,15 +35,15 @@ enum DmaPullResult : int {
class DmaOutChannel {
public:
DmaOutChannel(std::string name) { this->name = name; };
DmaOutChannel(std::string name) { this->name = name; }
virtual bool is_out_active() { return true; };
virtual bool is_out_active() { return true; }
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
virtual int get_pull_data_remaining() { return 1; };
virtual void end_pull_data() { };
virtual int get_pull_data_remaining() { return 1; }
virtual void end_pull_data() {}
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -51,14 +51,14 @@ private:
class DmaInChannel {
public:
DmaInChannel(std::string name) { this->name = name; };
DmaInChannel(std::string name) { this->name = name; }
virtual bool is_in_active() { return true; };
virtual bool is_in_active() { return true; }
virtual int push_data(const char* src_ptr, int len) = 0;
virtual int get_push_data_remaining() { return 1; };
virtual void end_push_data() { };
virtual int get_push_data_remaining() { return 1; }
virtual void end_push_data() {}
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -68,9 +68,9 @@ private:
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
public:
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
DmaInChannel(name + std::string(" In")) { this->name = name; };
DmaInChannel(name + std::string(" In")) { this->name = name; }
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -96,11 +96,11 @@ public:
DmaDevice() = default;
~DmaDevice() = default;
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
virtual void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
virtual int xfer_to(uint8_t *buf, int len) { return len; };
virtual int tell_xfer_size() { return 0; };
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
virtual void notify(DmaMsg msg) {}
virtual int xfer_from(uint8_t *buf, int len) { return len; }
virtual int xfer_to(uint8_t *buf, int len) { return len; }
virtual int tell_xfer_size() { return 0; }
protected:
DmaChannel* channel_obj = nullptr;
@@ -111,10 +111,10 @@ public:
DmaChannel() = default;
~DmaChannel() = default;
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
virtual void notify(DmaMsg msg) {};
virtual bool is_ready() { return false; };
virtual void xfer_retry() {};
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; }
virtual void notify(DmaMsg msg) {}
virtual bool is_ready() { return false; }
virtual void xfer_retry() {}
protected:
DmaDevice* dev_obj = nullptr;
+8 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,6 +35,7 @@ enum HWCompType : uint64_t {
MMIO_DEV = 1ULL << 4, // memory mapped I/O device
PCI_HOST = 1ULL << 5, // PCI host
PCI_DEV = 1ULL << 6, // PCI device
NUBUS_DEV = 1ULL << 7, // Nubus device
I2C_HOST = 1ULL << 8, // I2C host
I2C_DEV = 1ULL << 9, // I2C device
ADB_HOST = 1ULL << 12, // ADB host
@@ -53,6 +54,7 @@ enum HWCompType : uint64_t {
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
MACHINE = 1ULL << 41, // machine root
};
/** Base class for HW components. */
@@ -63,22 +65,22 @@ public:
virtual std::string get_name(void) {
return this->name;
};
}
virtual void set_name(std::string name) {
this->name = name;
};
}
virtual bool supports_type(HWCompType type) {
return !!(this->supported_types & type);
};
}
virtual void supports_types(uint64_t types) {
this->supported_types = types;
};
}
virtual int device_postinit() {
return 0;
};
}
protected:
std::string name;
+15 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <devices/common/hwcomponent.h>
#include <loguru.hpp>
#include <cinttypes>
@@ -35,8 +36,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
/** Base class for I2C devices */
class I2CDevice {
class I2CDevice : virtual public HWComponent {
public:
I2CDevice() {
supports_types(HWCompType::I2C_DEV);
}
virtual ~I2CDevice() = default;
virtual void start_transaction() = 0;
virtual bool send_subaddress(uint8_t sub_addr) = 0;
virtual bool send_byte(uint8_t data) = 0;
@@ -44,11 +50,11 @@ public:
};
/** Base class for I2C hosts */
class I2CBus {
class I2CBus : virtual public HWComponent {
public:
I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
};
}
virtual ~I2CBus() = default;
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
@@ -57,7 +63,7 @@ public:
}
this->dev_list[dev_addr] = dev_obj;
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
};
}
virtual bool start_transaction(uint8_t dev_addr) {
if (this->dev_list[dev_addr]) {
@@ -66,28 +72,28 @@ public:
} else {
return false;
}
};
}
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
};
}
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_byte(data);
};
}
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->receive_byte(p_data);
};
}
protected:
I2CDevice* dev_list[128]; /* list of registered I2C devices */
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -54,17 +54,17 @@ void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
void I2CProm::start_transaction() {
this->pos = 0;
};
}
bool I2CProm::send_subaddress(uint8_t sub_addr) {
this->pos = sub_addr;
return true;
};
}
bool I2CProm::send_byte(uint8_t data) {
LOG_F(9, "I2CRom: 0x%X received", data);
return true;
};
}
bool I2CProm::receive_byte(uint8_t* p_data) {
if (this->pos >= this->rom_size) {
@@ -72,4 +72,4 @@ bool I2CProm::receive_byte(uint8_t* p_data) {
}
*p_data = this->data[this->pos++];
return true;
};
}
+2 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,14 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_PROM_H
#define I2C_PROM_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
#include <memory>
class I2CProm : public I2CDevice, public HWComponent
{
class I2CProm : public I2CDevice {
public:
I2CProm(uint8_t dev_addr, int size);
~I2CProm() = default;
+12 -12
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -43,7 +43,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Machine ID register for NuBus Power Macs.
It's located at physical address 0x5FFFFFFC and contains four bytes:
+0 uint16_t signature = 0xA55A
+1 uint8_t machine_type (3 - Power Mac)
+1 uint8_t machine_type (0x30 - Power Mac)
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
*/
class NubusMacID : public MMIODevice {
@@ -55,7 +55,7 @@ public:
this->id[2] = (id >> 8) & 0xFF;
this->id[3] = id & 0xFF;
supports_types(HWCompType::MMIO_DEV);
};
}
~NubusMacID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
@@ -67,10 +67,10 @@ public:
}
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
return 0;
};
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint8_t id[4];
@@ -88,19 +88,19 @@ public:
this->set_name(name);
supports_types(HWCompType::IOBUS_DEV);
this->data = data;
};
}
~BoardRegister() = default;
uint16_t iodev_read(uint32_t address) {
return this->data;
};
}
// appears read-only to guest
void iodev_write(uint32_t address, uint16_t value) {};
void iodev_write(uint32_t address, uint16_t value) {}
void update_bits(const uint16_t val, const uint16_t mask) {
this->data = (this->data & ~mask) | (val & mask);
};
}
private:
uint16_t data;
@@ -118,15 +118,15 @@ public:
this->id = id;
this->name = "Machine-id";
supports_types(HWCompType::MMIO_DEV);
};
}
~GossamerID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
return ((offset == 4 && size == 2) ? this->id : 0);
};
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint16_t id;
+5 -1
View File
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nvram.h>
#include <devices/common/ofnvram.h>
#include <devices/deviceregistry.h>
#include <cinttypes>
@@ -46,6 +47,9 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
this->file_name = file_name;
this->ram_size = ram_size;
if (ram_size == 8192)
this->of_nvram_offset = OF_NVRAM_OFFSET;
// allocate memory storage and fill it with zeroes
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
@@ -99,7 +103,7 @@ void NVram::save() {
}
static const DeviceDescription Nvram_Descriptor = {
NVram::create, {}, {}
NVram::create, {}, {}, HWCompType::NVRAM
};
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
+2
View File
@@ -45,11 +45,13 @@ public:
uint8_t read_byte(uint32_t offset);
void write_byte(uint32_t offset, uint8_t value);
uint32_t get_of_nvram_offset() { return of_nvram_offset; }
private:
std::string file_name; // file name for the backing file
uint16_t ram_size; // NVRAM size
std::unique_ptr<uint8_t[]> storage;
uint32_t of_nvram_offset = 0;
void init();
void save();
+7 -7
View File
@@ -67,7 +67,7 @@ bool OfConfigAppl::validate() {
// read OF partition header
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// validate partition signature and version
@@ -81,7 +81,7 @@ bool OfConfigAppl::validate() {
// read the entire partition into the local buffer
for (i = 0; i < this->size; i++) {
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
this->buf[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// verify partition checksum
@@ -161,7 +161,7 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
break;
case OF_VAR_TYPE_STR:
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - this->nvram_obj->get_of_nvram_offset();
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
if ((str_offset + str_len) > OF_CFG_SIZE) {
@@ -194,7 +194,7 @@ void OfConfigAppl::update_partition() {
// write the entire partition back to NVRAM
for (int i = 0; i < this->size; i++) {
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
this->nvram_obj->write_byte(this->nvram_obj->get_of_nvram_offset() + i, this->buf[i]);
}
}
@@ -266,8 +266,8 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
}
// remove the old string
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET],
&this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
std::memmove(&this->buf[top + str_len - this->nvram_obj->get_of_nvram_offset()],
&this->buf[top - this->nvram_obj->get_of_nvram_offset()], str_offset - top);
for (auto& var : of_vars) {
auto type = std::get<0>(var.second);
@@ -284,7 +284,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
// copy new string into NVRAM buffer char by char
i = 0;
for(char& ch : value) {
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
this->buf[top + i - this->nvram_obj->get_of_nvram_offset()] = ch == '\x0A' ? '\x0D' : ch;
i++;
}
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -87,7 +87,7 @@ public:
// Old World implementation
class OfConfigAppl : public OfConfigImpl {
public:
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigAppl() = default;
bool validate();
@@ -108,7 +108,7 @@ private:
// New World implementation
class OfConfigChrp : public OfConfigImpl {
public:
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigChrp() = default;
bool validate();
+5 -5
View File
@@ -394,23 +394,23 @@ static const std::vector<std::string> Chaos_Subdevices = {
};
static const DeviceDescription Bandit1_Descriptor = {
Bandit::create_first, {}, Bandit1_Properties
Bandit::create_first, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Bandit2_Descriptor = {
Bandit::create_second, {}, Bandit2_Properties
Bandit::create_second, {}, Bandit2_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, PsxPci1_Properties
Bandit::create_psx_first, {}, PsxPci1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, Chaos_Subdevices, Chaos_Properties
Chaos::create, Chaos_Subdevices, Chaos_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription AspenPci1_Descriptor = {
AspenPci::create, {}, Bandit1_Properties
AspenPci::create, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
+7 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -71,7 +71,7 @@ enum {
*/
class BanditHost : public PCIHost, public MMIODevice {
public:
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
BanditHost(int bridge_num) { this->bridge_num = bridge_num; }
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
@@ -121,15 +121,15 @@ public:
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
};
}
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
};
}
static std::unique_ptr<HWComponent> create_psx_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
};
}
private:
std::unique_ptr<BanditPciDevice> my_pci_device;
@@ -146,7 +146,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
};
}
};
/**
@@ -159,7 +159,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
};
}
};
#endif // BANDIT_PCI_H
+2 -2
View File
@@ -102,11 +102,11 @@ static const PropMap Dec21154Yosemite_Properties = {
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}
DecPciBridge::create, {}, {}, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
+6 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -41,7 +41,10 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
this->pci_wr_stat = [](uint16_t val) {};
this->pci_wr_stat = [this](uint16_t val) {
this->status &= ~(0b1111100100000000 & val);
};
this->pci_wr_cmd = [this](uint16_t cmd) {
/*
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
@@ -54,7 +57,7 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
this->pci_notify_bar_change = [](int bar_num) {};
};
}
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+4 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -86,16 +86,16 @@ public:
virtual bool supports_io_space() {
return has_io_space;
};
}
/* I/O space access methods */
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
return false;
};
}
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
};
}
// configuration space access methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
+12 -10
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -39,12 +39,12 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_memory_base = [this](uint16_t val) {
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_base_32 = ((this->memory_base & 0xfff0) << 16);
this->memory_base_32 = (((uint64_t)this->memory_base & 0xfff0) << 16);
};
this->pci_wr_memory_limit = [this](uint16_t val) {
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_limit_32 = ((this->memory_limit & 0xfff0) << 16) + 0x100000;
this->memory_limit_32 = (((uint64_t)this->memory_limit & 0xfff0) << 16) + 0x100000;
};
this->pci_wr_io_base = [this](uint8_t val) {
@@ -61,12 +61,13 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_pref_mem_base = [this](uint16_t val) {
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
((this->pref_mem_base & 0xfff0) << 16);
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
if ((this->io_base & 15) == 1)
@@ -85,16 +86,17 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
if ((this->pref_mem_cfg & 15) == 1)
this->pref_base_upper32 = val;
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
((this->pref_mem_base & 0xfff0) << 16);
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
if ((this->pref_mem_cfg & 15) == 1)
this->pref_limit_upper32 = val;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
};
}
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+1 -1
View File
@@ -40,7 +40,7 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
};
this->pci_wr_sec_status = [this](uint16_t val) {};
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
};
}
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
+1 -1
View File
@@ -52,7 +52,7 @@ public:
bool supports_io_space() override {
return true;
};
}
// plugin interface for using in the derived classes
std::function<uint8_t()> pci_rd_primary_bus;
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -126,7 +126,7 @@ PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_H
this->io_limit_1 = (val & this->io_1_cfg);
this->io_limit_1_32 = this->io_limit_1 + 4;
};
};
}
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
@@ -219,5 +219,5 @@ bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t si
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
return this->pci_io_read_loop(offset, size, value);
return this->pci_io_write_loop(offset, size, value);
}
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
PCIDevice::PCIDevice(std::string name) : PCIBase(name, PCI_HEADER_TYPE_0, 6)
{
};
}
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+3 -3
View File
@@ -65,7 +65,7 @@ public:
PCIHost() {
this->dev_map.clear();
io_space_devs.clear();
};
}
~PCIHost() = default;
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
@@ -89,13 +89,13 @@ public:
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
};
}
virtual int pcihost_device_postinit();
virtual bool register_pci_int(PCIBase* dev_instance);
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
this->int_ctrl = int_ctrl_obj;
};
}
virtual InterruptCtrl *get_interrupt_controller();
protected:
+22 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -209,7 +209,16 @@ void MeshController::perform_command(const uint8_t cmd) {
this->sequencer();
break;
case SeqCmd::BusFree:
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// Don't release ACK if ATN is asserted. This condition indicates
// that the initiator wants to reject last message.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// Let the target switch to next bus phase if
// - both ACK and ATN are asserted so the target will reject last message
// - when in MESSAGE_IN phase to tell the target the initiator accepts last message
if (this->is_initiator && (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN) ||
this->bus_obj->current_phase() == ScsiPhase::MESSAGE_IN))
this->bus_obj->target_next_step();
// generate phase mismatch exception
// if the target is still connected
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
@@ -282,7 +291,11 @@ void MeshController::step_completed() {
}
void MeshController::report_error(const int error) {
switch(error) {
switch (error) {
case ARB_LOST:
this->exception |= EXC_ARB_LOST;
this->int_stat |= INT_EXCEPTION;
break;
case SEL_TIMEOUT:
this->exception |= EXC_SEL_TIMEOUT;
this->int_stat |= INT_EXCEPTION;
@@ -299,12 +312,16 @@ static const PropMap Mesh_properties = {
{"cdr_img2", new StrProperty("")},
};
static const std::vector<std::string> Mesh_Subdevices = {
"ScsiMesh"
};
static const DeviceDescription Mesh_Tnt_Descriptor = {
MeshController::create_for_tnt, {}, Mesh_properties
MeshController::create_for_tnt, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
static const DeviceDescription Mesh_Heathrow_Descriptor = {
MeshController::create_for_heathrow, {}, Mesh_properties
MeshController::create_for_heathrow, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
REGISTER_DEVICE(MeshTnt, Mesh_Tnt_Descriptor);
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -91,7 +91,7 @@ namespace MeshScsi {
INT_ERROR = 1 << 2,
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
};
}; // namespace MeshScsi
} // namespace MeshScsi
class MeshBase {
public:
@@ -107,8 +107,8 @@ public:
~MeshStub() = default;
// registers access
uint8_t read(uint8_t reg_offset) override { return 0; };
void write(uint8_t reg_offset, uint8_t value) override {};
uint8_t read(uint8_t reg_offset) override { return 0; }
void write(uint8_t reg_offset, uint8_t value) override {}
};
class MeshController : public ScsiBusController, public MeshBase {
@@ -116,7 +116,7 @@ public:
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
this->chip_id = mesh_id;
this->reset(true);
};
}
~MeshController() = default;
static std::unique_ptr<HWComponent> create_for_tnt() {
+20 -8
View File
@@ -97,7 +97,11 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
if (this->config2 & CFG2_ENF) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
static bool log_it = true;
if (log_it) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
log_it = false;
}
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
} else
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
@@ -849,11 +853,13 @@ int Sc53C94::xfer_from(uint8_t *buf, int len) {
len = std::min(len, (int)(this->xfer_count));
// see if there are data bytes in the FIFO we want to grab first
if (this->data_fifo_pos) {
int fifo_bytes = std::min(this->data_fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->data_fifo_pos -= fifo_bytes;
this->xfer_count -= fifo_bytes;
len -= fifo_bytes;
bytes_moved += fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
@@ -864,12 +870,14 @@ int Sc53C94::xfer_from(uint8_t *buf, int len) {
}
}
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
bytes_moved += this->xfer_count;
this->xfer_count = 0;
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
if (this->bus_obj->pull_data(this->target_id, buf, len)) {
bytes_moved += len;
this->xfer_count -= len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
}
return bytes_moved;
@@ -924,8 +932,12 @@ static const PropMap Sc53C94_properties = {
{"cdr_img", new StrProperty("")},
};
static const std::vector<std::string> Sc53C94_Subdevices = {
"ScsiCurio"
};
static const DeviceDescription Sc53C94_Descriptor = {
Sc53C94::create, {}, Sc53C94_properties
Sc53C94::create, Sc53C94_Subdevices, Sc53C94_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
+9 -9
View File
@@ -58,7 +58,7 @@ namespace Read {
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
//
};
};
}
/** 53C94 write registers */
namespace Write {
@@ -80,7 +80,7 @@ namespace Write {
Xfer_Cnt_Hi = 0xE, // Start Transfer Count Register High ; Am53CF94 extension
Data_Align = 0xF, // Data Alignment Register
};
};
}
/** NCR53C94/Am53CF94 commands. */
enum {
@@ -180,7 +180,7 @@ namespace SeqState {
RCV_STATUS,
RCV_MESSAGE,
};
};
}
constexpr auto DATA_FIFO_MAX = 16;
@@ -228,7 +228,7 @@ public:
std::bind(&Sc53C94::dma_stop, this)
);
}
};
}
void set_drq_callback(DrqCb cb) {
this->drq_cb = cb;
@@ -236,18 +236,18 @@ public:
// ScsiDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; };
bool get_more_data() override { return false; };
bool has_data() override { return this->data_fifo_pos != 0; };
bool prepare_data() override { return false; }
bool get_more_data() override { return false; }
bool has_data() override { return this->data_fifo_pos != 0; }
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {};
void process_command() override {}
// DmaDevice methods
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
int tell_xfer_size() override {
return this->xfer_count;
};
}
protected:
void reset_device();
+24 -7
View File
@@ -62,7 +62,7 @@ namespace ScsiPhase {
MESSAGE_OUT,
RESET,
};
};
}
/** SCSI status codes. */
namespace ScsiStatus {
@@ -70,7 +70,7 @@ namespace ScsiStatus {
GOOD = 0,
CHECK_CONDITION = 2,
};
};
}
/** Standard message codes. */
namespace ScsiMessage {
@@ -83,7 +83,7 @@ namespace ScsiMessage {
HAS_DISCONNECT_PRIVILEDGE = 0x40,
IDENTIFY = 0x80,
};
};
}
/** Extended message codes. */
namespace ScsiExtMessage {
@@ -92,7 +92,7 @@ namespace ScsiExtMessage {
SYNCH_XFER_REQ = 1,
WIDE_XFER_REQ = 3,
};
};
}
/** Internal notification codes for our SCSI implementation. */
enum ScsiNotification : int {
@@ -106,6 +106,7 @@ enum ScsiCommand : uint8_t {
REQ_SENSE = 0x03,
FORMAT_UNIT = 0x04,
READ_BLK_LIMITS = 0x05,
REASSIGN = 0x07,
READ_6 = 0x08,
WRITE_6 = 0x0A,
SEEK_6 = 0x0B,
@@ -122,17 +123,32 @@ enum ScsiCommand : uint8_t {
READ_CAPACITY_10 = 0x25,
READ_10 = 0x28,
WRITE_10 = 0x2A,
SEEK_10 = 0x2B,
VERIFY_WRITE_10 = 0x2E,
VERIFY_10 = 0x2F,
READ_LONG_10 = 0x35,
WRITE_BUFFER = 0x3B,
READ_BUFFER = 0x3C,
GET_CONFIG = 0x46,
GET_EVENT_STATUS_NOTIFY = 0x4A,
READ_DISC_INFO = 0x51,
MODE_SELECT_10 = 0x55,
MODE_SENSE_10 = 0x5A,
READ_12 = 0xA8,
WRITE_12 = 0xAA,
READ_DVD_STRUCTURE = 0xAD,
SET_SPEED = 0xBB,
// CD-ROM specific commands
READ_TOC = 0x43,
SET_CD_SPEED = 0xBB,
READ_CD = 0xBE,
// vendor specific commands
VENDOR_09 = 0x09,
EJECT = 0xC0,
READ_CDDA = 0xD8, //TOSHIBA
READ_CDDA_MSF = 0xD9, //TOSHIBA
};
enum ScsiSense : int {
@@ -186,7 +202,7 @@ public:
this->scsi_id = my_id;
this->lun = 0,
this->cur_phase = ScsiPhase::BUS_FREE;
};
}
~ScsiDevice() = default;
virtual void notify(ScsiNotification notif_type, int param);
@@ -195,7 +211,7 @@ public:
virtual void switch_phase(const int new_phase);
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; };
virtual bool has_data() { return this->data_size != 0; }
virtual int xfer_data();
virtual int send_data(uint8_t* dst_ptr, int count);
virtual int rcv_data(const uint8_t* src_ptr, const int count);
@@ -230,6 +246,7 @@ protected:
int ascq;
int sksv;
int field;
bool valid;
bool last_selection_has_atention = false;
uint8_t last_selection_message = 0;
@@ -279,7 +296,7 @@ public:
uint16_t test_ctrl_lines(uint16_t mask);
// reading/writing data lines
uint8_t get_data_lines() { return this->data_lines; };
uint8_t get_data_lines() { return this->data_lines; }
// high-level control/status
int switch_phase(int id, int new_phase);
+2 -2
View File
@@ -377,11 +377,11 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
}
static const DeviceDescription ScsiCurio_Descriptor = {
ScsiBus::create_ScsiCurio, {}, {}
ScsiBus::create_ScsiCurio, {}, {}, HWCompType::SCSI_BUS
};
static const DeviceDescription ScsiMesh_Descriptor = {
ScsiBus::create_ScsiMesh, {}, {}
ScsiBus::create_ScsiMesh, {}, {}, HWCompType::SCSI_BUS
};
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
+9 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -95,8 +95,10 @@ void ScsiBusController::sequencer() {
if (this->fifo_pos) {
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
if (this->to_xfer <= 0)
if (this->to_xfer <= 0) {
this->bus_obj->target_next_step();
this->step_completed();
}
}
break;
case SeqState::SEND_CMD:
@@ -147,9 +149,12 @@ void ScsiBusController::sequencer() {
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_MESSAGE)
if (this->cur_state == SeqState::RCV_STATUS) {
this->bus_obj->target_next_step();
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
} else if (this->cur_state == SeqState::RCV_MESSAGE)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
this->bus_obj->target_next_step();
this->step_completed();
this->cur_state = SeqState::IDLE;
}
+5 -5
View File
@@ -50,7 +50,7 @@ namespace Scsi_Bus_Controller {
RCV_STATUS,
RCV_MESSAGE,
};
};
}
/** Sequencer error codes. */
enum : int {
@@ -75,12 +75,12 @@ public:
// ScsiDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; };
bool get_more_data() override { return false; };
bool has_data() override { return false; };
bool prepare_data() override { return false; }
bool get_more_data() override { return false; }
bool has_data() override { return false; }
bool rcv_data();
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {};
void process_command() override {}
// DmaDevice methods
int xfer_from(uint8_t *buf, int len) override;
+15
View File
@@ -45,6 +45,8 @@ void ScsiCdrom::process_command()
{
uint32_t lba;
uint32_t cdda_start, cdda_end, cdda_len;
this->pre_xfer_action = nullptr;
this->post_xfer_action = nullptr;
@@ -98,6 +100,19 @@ void ScsiCdrom::process_command()
this->switch_phase(ScsiPhase::DATA_IN);
}
break;
case ScsiCommand::READ_CDDA:
lba = READ_DWORD_BE_U(&cmd[2]);
cdda_len = READ_DWORD_BE_U(&cmd[6]);
this->read(lba, cdda_len, 12);
break;
case ScsiCommand::READ_CDDA_MSF:
cdda_start = (cmd[3] * 60 * 75) + (cmd[4] * 75) + cmd[5];
cdda_end = (cmd[7] * 60 * 75) + (cmd[8] * 75) + cmd[9];
cdda_len = (cdda_end > cdda_start) ? (cdda_end - cdda_start) : 0;
this->read(cdda_start, cdda_len, 12);
break;
default:
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
this->illegal_command(cmd);
+1 -1
View File
@@ -86,7 +86,7 @@ void ScsiDevice::next_step()
!this->allow_phase_change())
return;
// check for puggable sequences and follow them if applicable
// check for pluggable sequences and follow them if applicable
if (this->seq_steps && *this->seq_steps >= 0) {
if (this->cur_phase == *this->seq_steps) {
this->seq_steps++;
+28 -1
View File
@@ -75,6 +75,9 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::FORMAT_UNIT:
this->format();
break;
case ScsiCommand::REASSIGN:
this->reassign();
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
@@ -350,7 +353,7 @@ void ScsiHardDisk::mode_sense_6() {
// default values taken from Empire 540/1080S manual
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
WRITE_WORD_BE_U(&p_buf[10], 92); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&p_buf[10], 64); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
@@ -360,6 +363,18 @@ void ScsiHardDisk::mode_sense_6() {
got_page = true;
}
if (page_code == 4 || page_code == 0x3f) { // Rigid Disk Drive Geometry Page
page_size = 24;
p_buf[0] = 4; // page code
p_buf[1] = page_size - 2; // page length
std::memset(&p_buf[2], 0, 22);
int num_cylinders = this->total_blocks / 64 / 4;
p_buf[2] = (num_cylinders >> 16) & 0xFF;
WRITE_WORD_BE_U(&p_buf[3], num_cylinders & 0xFFFFU); // number of cylinders
p_buf[5] = 4; // number of heads
got_page = true;
}
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
if (sub_page_code != 0x00 && sub_page_code != 0xff)
goto bad_sub_page;
@@ -445,6 +460,18 @@ void ScsiHardDisk::format() {
});
}
void ScsiHardDisk::reassign() {
LOG_F(WARNING, "%s: attempt to reassign blocks on the disk!", this->name.c_str());
this->status = ScsiStatus::GOOD;
this->sense = ScsiSense::NO_SENSE;
this->asc = ScsiError::NO_ERROR;
this->valid = false;
TimerManager::get_instance()->add_oneshot_timer(
NS_PER_SEC, [this]() { this->switch_phase(ScsiPhase::STATUS); });
}
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
if (!check_lun())
return;
+3 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -39,7 +39,7 @@ public:
void insert_image(std::string filename);
void process_command();
bool prepare_data();
bool get_more_data() { return false; };
bool get_more_data() { return false; }
protected:
int test_unit_ready();
@@ -49,6 +49,7 @@ protected:
void mode_sense_6();
void format();
void reassign();
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
void read_capacity_10();
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
+101 -67
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/timermanager.h>
#include <devices/common/adb/adbbus.h>
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/viacuda.h>
#include <devices/deviceregistry.h>
@@ -39,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ViaCuda::ViaCuda() {
ViaCuda::ViaCuda() : I2CBus() {
this->name = "ViaCuda";
supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST);
@@ -58,7 +59,6 @@ ViaCuda::ViaCuda() {
// (not prescribed in the 6522 datasheet)
this->via_t1ll = 0xFF;
this->via_t1lh = 0xFF;
this->via_t2cl = 0xFF;
this->_via_ifr = 0; // all flags cleared
this->_via_ier = 0; // all interrupts disabled
@@ -204,12 +204,9 @@ void ViaCuda::write(int reg, uint8_t value) {
LOG_F(9, "VIA_DIRA = 0x%X", value);
break;
case VIA_T1CL:
this->via_t1cl = value;
this->via_t1ll = value; // writes to T1CL are redirected to T1LL
break;
case VIA_T1CH:
if (this->via_acr & 0xC0) {
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
}
// cancel active T1 timer task
if (this->t1_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
@@ -218,33 +215,25 @@ void ViaCuda::write(int reg, uint8_t value) {
// clear T1 flag in IFR
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
// load initial value into counter 1
this->t1_counter = (value << 8) | this->via_t1cl;
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
// set up timout timer for T1
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
this->t1_timer_id = 0;
this->assert_t1_int();
}
);
// load the high-order latch from the current T1CH value
this->via_t1lh = value;
// load the T1 counter from the corresponding latches
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
this->activate_t1();
break;
case VIA_T1LL:
this->via_t1ll = value;
break;
case VIA_T1LH:
this->via_t1lh = value;
// writes to T1LH clear T1 interrupt in the Apple VIA cell
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
break;
case VIA_T2CL:
this->via_t2cl = value;
this->via_t2ll = value; // writes to T2CL are redirected to T2LL
break;
case VIA_T2CH:
if (this->via_acr & 0x20) {
ABORT_F("VIA T2 pulse count mode not supported!");
}
// cancel active T2 timer task
if (this->t2_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
@@ -254,7 +243,7 @@ void ViaCuda::write(int reg, uint8_t value) {
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
// load initial value into counter 2
this->t2_counter = (value << 8) | this->via_t2cl;
this->t2_counter = (value << 8) | this->via_t2ll;
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
@@ -273,7 +262,7 @@ void ViaCuda::write(int reg, uint8_t value) {
update_irq();
break;
case VIA_ACR:
this->via_acr = value;
this->via_acr = value & VIA_ACR_IMPL_BITS;
LOG_F(9, "VIA_ACR = 0x%X", value);
break;
case VIA_PCR:
@@ -282,7 +271,8 @@ void ViaCuda::write(int reg, uint8_t value) {
break;
case VIA_IFR:
// for each "1" in value clear the corresponding flags
this->_via_ifr &= ~value;
// bit 7 is ignored
this->_via_ifr &= ~(value & 0x7F);
update_irq();
break;
case VIA_IER:
@@ -305,6 +295,24 @@ uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last
return last_val - diff;
}
void ViaCuda::activate_t1() {
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
// set up timout timer for T1
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
// reload the T1 counter from the corresponding latches
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
this->t1_timer_id = 0;
this->assert_t1_int();
if (this->via_acr & 0x40)
this->activate_t1();
}
);
}
void ViaCuda::print_enabled_ints() {
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
@@ -314,15 +322,15 @@ void ViaCuda::print_enabled_ints() {
}
}
void ViaCuda::update_irq()
{
void ViaCuda::update_irq() {
uint8_t active_ints = this->_via_ifr & this->_via_ier & 0x7F;
if (active_ints != this->old_ifr) {
uint8_t new_irq = !!active_ints;
this->_via_ifr = (active_ints) | (new_irq << 7);
this->old_ifr = active_ints;
LOG_F(6, "VIA: assert IRQ, IFR=0x%02X", this->_via_ifr);
this->int_ctrl->ack_int(this->irq_id, new_irq);
uint8_t irq_state = !!active_ints;
// let CPU know when irq_state is "1" or it changes from "1" to "0"
if (irq_state || (irq_state != (this->_via_ifr >> 7))) {
this->_via_ifr = (irq_state << 7) | (this->_via_ifr & 0x7F);
LOG_F(6, "%s: signal IRQ line change to 0x%X, IFR=0x%02X",
this->name.c_str(), irq_state, this->_via_ifr);
this->int_ctrl->ack_int(this->irq_id, irq_state);
}
}
@@ -361,7 +369,7 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
this->_via_ifr |= VIA_IF_CB1;
break;
case ViaLine::CB2:
this->_via_ifr |= VIA_IF_CB1;
this->_via_ifr |= VIA_IF_CB2;
break;
default:
ABORT_F("Assertion of unknown VIA line requested!");
@@ -494,6 +502,15 @@ void ViaCuda::error_response(uint32_t error) {
this->is_open_ended = false;
}
void ViaCuda::one_byte_header(uint32_t pkt_type) {
this->out_buf[0] = pkt_type;
this->out_count = 1;
this->out_pos = 0;
this->out_handler = &ViaCuda::out_buf_handler;
this->next_out_handler = &ViaCuda::null_out_handler;
this->is_open_ended = false;
}
void ViaCuda::process_packet() {
if (this->in_count < 2) {
LOG_F(ERROR, "Cuda: invalid packet (too few data)!");
@@ -521,20 +538,41 @@ void ViaCuda::process_packet() {
}
}
void ViaCuda::append_data(uint8_t* src, int len) {
if (len > 0) {
std::memcpy(&this->out_buf[this->out_count], src, len);
this->out_count += len;
}
}
template <class T>
void ViaCuda::append_data(T data) {
switch(sizeof(T)) {
case 1: this->out_buf[this->out_count] = data;
case 2: WRITE_WORD_BE_U( &this->out_buf[this->out_count], data);
case 4: WRITE_DWORD_BE_U(&this->out_buf[this->out_count], data);
}
this->out_count += sizeof(T);
}
template void ViaCuda::append_data(uint8_t data);
template void ViaCuda::append_data(uint16_t data);
template void ViaCuda::append_data(uint32_t data);
void ViaCuda::process_adb_command() {
uint8_t adb_stat, output_size;
adb_stat = this->adb_bus_obj->process_command(&this->in_buf[1],
this->in_count - 1);
response_header(CUDA_PKT_ADB, adb_stat);
output_size = this->adb_bus_obj->get_output_count();
if (output_size) {
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
this->out_count += output_size;
}
this->append_data(this->adb_bus_obj->get_output_buf(), this->adb_bus_obj->get_output_count());
}
void ViaCuda::autopoll_handler() {
if (this->do_post_keyboard_state_events && !(!this->old_tip || !this->treq)) {
EventManager::get_instance()->post_keyboard_state_events();
this->do_post_keyboard_state_events = false;
}
uint8_t poll_command = this->autopoll_enabled ? this->adb_bus_obj->poll() : 0;
if (poll_command) {
@@ -545,11 +583,7 @@ void ViaCuda::autopoll_handler() {
// prepare autopoll packet
response_header(CUDA_PKT_ADB, ADB_STAT_OK | ADB_STAT_AUTOPOLL);
this->out_buf[2] = poll_command; // put the proper ADB command
uint8_t output_size = this->adb_bus_obj->get_output_count();
if (output_size) {
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
this->out_count += output_size;
}
this->append_data(this->adb_bus_obj->get_output_buf(), this->adb_bus_obj->get_output_count());
// assert TREQ
this->via_portb &= ~CUDA_TREQ;
@@ -571,12 +605,10 @@ void ViaCuda::autopoll_handler() {
this->out_buf[2] = CUDA_GET_REAL_TIME;
if (send_time || this->one_sec_mode == 1) {
uint32_t real_time = this_time + this->time_offset;
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
this->out_count = 7;
this->append_data(real_time);
}
} else if (this->one_sec_mode == 3) {
response_header(CUDA_PKT_TICK, 0);
this->out_count = 1;
one_byte_header(CUDA_PKT_TICK);
}
this->last_time = this_time;
@@ -600,9 +632,11 @@ void ViaCuda::pseudo_command() {
if (this->in_buf[2]) {
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
this->autopoll_enabled = true;
this->do_post_keyboard_state_events = true;
} else {
LOG_F(INFO, "Cuda: autopoll stopped");
this->autopoll_enabled = false;
this->do_post_keyboard_state_events = false;
}
response_header(CUDA_PKT_PSEUDO, 0);
break;
@@ -616,11 +650,10 @@ void ViaCuda::pseudo_command() {
this->next_out_handler = &ViaCuda::pram_out_handler;
} else if (addr >= CUDA_ROM_START) {
// HACK: Cuda ROM dump requsted so let's partially fake it
this->out_buf[3] = 0; // empty copyright string
WRITE_WORD_BE_A(&this->out_buf[4], 0x0019U);
WRITE_WORD_BE_A(&this->out_buf[6], CUDA_FW_VERSION_MAJOR);
WRITE_WORD_BE_A(&this->out_buf[8], CUDA_FW_VERSION_MINOR);
this->out_count += 7;
this->append_data(uint8_t(0)); // empty copyright string
this->append_data(uint16_t(0x0019U));
this->append_data(uint16_t(CUDA_FW_VERSION_MAJOR));
this->append_data(uint16_t(CUDA_FW_VERSION_MINOR));
}
this->is_open_ended = true;
break;
@@ -628,8 +661,7 @@ void ViaCuda::pseudo_command() {
response_header(CUDA_PKT_PSEUDO, 0);
uint32_t this_time = this->calc_real_time();
uint32_t real_time = this_time + this->time_offset;
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
this->out_count = 7;
this->append_data(real_time);
break;
}
case CUDA_WRITE_MCU_MEM:
@@ -659,7 +691,7 @@ void ViaCuda::pseudo_command() {
case CUDA_SET_REAL_TIME: {
response_header(CUDA_PKT_PSEUDO, 0);
uint32_t real_time = this->calc_real_time();
uint32_t new_time = READ_DWORD_BE_U(&in_buf[2]);
uint32_t new_time = READ_DWORD_BE_U(&this->in_buf[2]);
this->time_offset = new_time - real_time;
break;
}
@@ -692,18 +724,15 @@ void ViaCuda::pseudo_command() {
break;
case CUDA_GET_AUTOPOLL_RATE:
response_header(CUDA_PKT_PSEUDO, 0);
this->out_buf[3] = this->poll_rate;
this->out_count++;
this->append_data(this->poll_rate);
break;
case CUDA_SET_DEVICE_LIST:
case CUDA_SET_DEVICE_BITMAP:
this->device_mask = READ_WORD_BE_U(&this->in_buf[2]);
response_header(CUDA_PKT_PSEUDO, 0);
this->device_mask = ((uint16_t)in_buf[2]) >> 8;
this->device_mask += ((uint16_t)in_buf[3]);
break;
case CUDA_GET_DEVICE_LIST:
case CUDA_GET_DEVICE_BITMAP:
response_header(CUDA_PKT_PSEUDO, 0);
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
this->append_data(this->device_mask);
break;
case CUDA_ONE_SECOND_MODE:
LOG_F(INFO, "Cuda: One Second Interrupt Mode: %d", this->in_buf[2]);
@@ -711,12 +740,17 @@ void ViaCuda::pseudo_command() {
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_SET_POWER_MESSAGES:
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X SET_POWER_MESSAGES", cmd);
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_READ_WRITE_I2C:
response_header(CUDA_PKT_PSEUDO, 0);
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
break;
case CUDA_TIMER_TICKLE:
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X TIMER_TICKLE - Byte Sent: 0x%02x", cmd, this->in_buf[2]);
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_COMB_FMT_I2C:
response_header(CUDA_PKT_PSEUDO, 0);
if (this->in_count >= 5) {
@@ -855,7 +889,7 @@ static const vector<string> Cuda_Subdevices = {
};
static const DeviceDescription ViaCuda_Descriptor = {
ViaCuda::create, Cuda_Subdevices, {}
ViaCuda::create, Cuda_Subdevices, {}, HWCompType::ADB_HOST | HWCompType::I2C_HOST
};
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
+29 -19
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,8 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Versatile interface adapter (VIA) is an old I/O controller that can be found
in nearly every Macintosh computer. In the 68k era, VIA was used to control
various peripheral devices. In a Power Macintosh, its function is limited
to the I/O interface with the Cuda MCU. I therefore decided to put VIA
emulation code here.
to the I/O interface with the Cuda MCU and some basic timer functionality.
Cuda MCU is a multipurpose IC built around a custom version of the Motorola
MC68HC05 microcontroller. It provides several functions including:
@@ -43,7 +42,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef VIACUDA_H
#define VIACUDA_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <devices/common/nvram.h>
@@ -93,6 +91,9 @@ enum class ViaLine {
CB2
};
// for masking unimplemented bits in the Apple VIA cell.
constexpr uint8_t VIA_ACR_IMPL_BITS = 0x5C;
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
enum {
CUDA_TIP = 0x20, // transaction in progress
@@ -119,17 +120,23 @@ enum {
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
CUDA_SET_REAL_TIME = 0x09, // set real time
CUDA_POWER_DOWN = 0x0A, // power down system
CUDA_SET_POWER_UPTIME = 0x0B, // set power up time
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
CUDA_SEND_DFAC = 0x0E, // send dfac
CUDA_BATTERY_SWAP_SENSE = 0x10, // battery swap sense
CUDA_RESTART_SYSTEM = 0x11, // restart system
CUDA_SET_IPL_LEVEL = 0x12, // set IPL level
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
CUDA_SET_DEVICE_LIST = 0x19, // set device list
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
CUDA_SET_DEVICE_BITMAP = 0x19, // set device bitmap
CUDA_GET_DEVICE_BITMAP = 0x1A, // get device bitmap
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C
CUDE_TOGGLE_WAKEUP = 0x23, // toggle wake-up
CUDA_TIMER_TICKLE = 0x24, // set timer tickle
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
};
@@ -156,7 +163,7 @@ constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM contain
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
class ViaCuda : public HWComponent, public I2CBus {
class ViaCuda : public I2CBus {
public:
ViaCuda();
~ViaCuda();
@@ -183,10 +190,6 @@ private:
uint8_t via_porta = 0;
uint8_t via_ddrb = 0;
uint8_t via_ddra = 0;
uint8_t via_t1cl = 0xFF;
uint8_t via_t1ll = 0xFF;
uint8_t via_t1lh = 0xFF;
uint8_t via_t2cl = 0xFF;
uint8_t via_sr;
uint8_t via_acr = 0;
uint8_t via_pcr = 0;
@@ -198,21 +201,23 @@ private:
uint8_t last_orb = 0; // last value written to the ORB register.
// timer 1 state
uint16_t t1_counter;
uint32_t t1_timer_id = 0;
uint8_t via_t1ll; // low-order latch
uint8_t via_t1lh; // high-order latch
uint16_t t1_counter; // internal counter
uint32_t t1_timer_id = 0;
uint64_t t1_start_time = 0;
// timer 2 state
uint16_t t2_counter;
uint8_t via_t2ll; // low-order latch (write-only)
uint16_t t2_counter; // internal counter
uint32_t t2_timer_id = 0;
uint64_t t2_start_time = 0;
// VIA interrupt related stuff
InterruptCtrl* int_ctrl;
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id;
uint8_t _via_ifr;
uint8_t _via_ier;
uint8_t old_ifr = 0;
uint8_t _via_ifr = 0;
uint8_t _via_ier = 0;
/* Cuda state. */
uint8_t old_tip;
@@ -243,6 +248,7 @@ private:
AdbBus* adb_bus_obj = nullptr;
bool autopoll_enabled = false;
bool do_post_keyboard_state_events = false;
// VIA methods
void print_enabled_ints(); // print enabled VIA interrupts and their sources
@@ -253,12 +259,16 @@ private:
void assert_t2_int();
void schedule_sr_int(uint64_t timeout_ns);
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t& last_time);
void activate_t1();
// CUDA methods
void cuda_init();
void write(uint8_t new_state);
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
void error_response(uint32_t error);
void one_byte_header(uint32_t pkt_type);
inline void append_data(uint8_t* src, int len);
template <class T> inline void append_data(T data);
void process_packet();
void process_adb_command();
void pseudo_command();
+3 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,6 +40,8 @@ struct DeviceDescription {
CreateFunc m_create_func;
std::vector<std::string> subdev_list;
PropMap properties;
uint64_t supports_types;
std::string description;
};
class DeviceRegistry
+153 -16
View File
@@ -35,6 +35,7 @@ BigMac::BigMac(uint8_t id) {
void BigMac::chip_reset() {
this->event_mask = 0xFFFFU; // disable HW events causing on-chip interrupts
this->rng_seed = (uint16_t)rand();
this->stat = 0;
this->phy_reset();
@@ -46,13 +47,25 @@ uint16_t BigMac::read(uint16_t reg_offset) {
switch (reg_offset) {
case BigMacReg::XIFC:
return this->tx_if_ctrl;
case BigMacReg::XCVR_IF:
return this->xcvr_if_ctrl;
case BigMacReg::CHIP_ID:
return this->chip_id;
case BigMacReg::TX_FIFO_TH:
return this->tx_fifo_tresh;
case BigMacReg::TX_FIFO_CSR:
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
case BigMacReg::RX_FIFO_CSR:
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
case BigMacReg::TX_PNTR:
return this->tx_ptr;
case BigMacReg::RX_PNTR:
return this->rx_ptr;
case BigMacReg::MIF_CSR:
return (this->mif_csr_old & ~Mif_Data_In) | (this->mii_in_bit << 3);
case BigMacReg::GLOB_STAT: {
uint16_t old_stat = this->stat;
this->stat = 0; // clear-on-read
this->stat = 0; // clear-on-read
return old_stat;
}
case BigMacReg::EVENT_MASK:
@@ -63,22 +76,83 @@ uint16_t BigMac::read(uint16_t reg_offset) {
return this->tx_reset;
case BigMacReg::TX_CONFIG:
return this->tx_config;
case BigMacReg::TX_MAX:
return this->tx_max;
case BigMacReg::TX_MIN:
return this->tx_min;
case BigMacReg::PEAK_ATT: {
uint8_t old_val = this->peak_attempts;
this->peak_attempts = 0; // clear-on-read
return old_val;
}
uint8_t old_val = this->peak_attempts;
this->peak_attempts = 0; // clear-on-read
return old_val;
}
case BigMacReg::NC_CNT:
return this->norm_coll_cnt;
case BigMacReg::NT_CNT:
return this->net_coll_cnt;
case BigMacReg::EX_CNT:
return this->excs_coll_cnt;
case BigMacReg::LT_CNT:
return this->late_coll_cnt;
case BigMacReg::RNG_SEED:
return this->rng_seed;
case BigMacReg::RX_FRM_CNT:
return this->rcv_frame_cnt;
case BigMacReg::RX_LE_CNT:
return this->len_err_cnt;
case BigMacReg::RX_AE_CNT:
return this->align_err_cnt;
case BigMacReg::RX_FE_CNT:
return this->fcs_err_cnt;
case BigMacReg::RX_CVE_CNT:
return this->cv_err_cnt;
case BigMacReg::RX_CONFIG:
return this->rx_config;
case BigMacReg::RX_MAX:
return this->rx_max;
case BigMacReg::RX_MIN:
return this->rx_min;
case BigMacReg::MEM_ADD:
return this->mem_add;
case BigMacReg::MEM_DATA_HI:
return this->mem_data_hi;
case BigMacReg::MEM_DATA_LO:
return this->mem_data_lo;
case BigMacReg::IPG_1:
return this->ipg1;
case BigMacReg::IPG_2:
return this->ipg2;
case BigMacReg::A_LIMIT:
return this->attempt_limit;
case BigMacReg::SLOT:
return this->slot_time;
case BigMacReg::PA_LEN:
return this->preamble_len;
case BigMacReg::PA_PAT:
return this->preamble_pat;
case BigMacReg::TX_SFD:
return this->tx_sfd;
case BigMacReg::JAM_SIZE:
return this->jam_size;
case BigMacReg::DEFER_TMR:
return this->defer_timer;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
return this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)];
case BigMacReg::HASH_TAB_0:
case BigMacReg::HASH_TAB_1:
case BigMacReg::HASH_TAB_2:
case BigMacReg::HASH_TAB_3:
return this->hash_table[(reg_offset >> 4) & 3];
case BigMacReg::AFR_0:
case BigMacReg::AFR_1:
case BigMacReg::AFR_2:
return this->addr_filters[((reg_offset >> 4) & 0xF) - 4];
case BigMacReg::AFC_R:
return this->addr_filt_mask;
default:
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(),
reg_offset);
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(), reg_offset);
}
return 0;
@@ -89,16 +163,25 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::XIFC:
this->tx_if_ctrl = value;
break;
case BigMacReg::XCVR_IF:
this->xcvr_if_ctrl = value;
break;
case BigMacReg::TX_FIFO_CSR:
this->tx_fifo_enable = !!(value & 1);
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
break;
case BigMacReg::TX_FIFO_TH:
this->tx_fifo_tresh = value;
break;
case BigMacReg::RX_FIFO_CSR:
this->rx_fifo_enable = !!(value & 1);
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
break;
case BigMacReg::TX_PNTR:
this->tx_ptr = value;
break;
case BigMacReg::RX_PNTR:
this->rx_ptr = value;
break;
case BigMacReg::MIF_CSR:
if (value & Mif_Data_Out_En) {
@@ -111,6 +194,9 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
}
this->mif_csr_old = value;
break;
case BigMacReg::MEM_ADD:
this->mem_add = value;
break;
case BigMacReg::EVENT_MASK:
this->event_mask = value;
break;
@@ -127,7 +213,7 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::TX_SW_RST:
if (value == 1) {
LOG_F(INFO, "%s: transceiver soft reset asserted", this->name.c_str());
this->tx_reset = 0; // acknowledge SW reset
this->tx_reset = 0; // acknowledge SW reset
}
break;
case BigMacReg::TX_CONFIG:
@@ -156,10 +242,32 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::RX_CONFIG:
this->rx_config = value;
break;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
case BigMacReg::RX_MAX:
this->rx_max = value;
break;
case BigMacReg::RX_MIN:
this->rx_min = value;
break;
case BigMacReg::SLOT:
this->slot_time = value;
break;
case BigMacReg::PA_LEN:
this->preamble_len = value;
break;
case BigMacReg::PA_PAT:
this->preamble_pat = value;
break;
case BigMacReg::TX_SFD:
this->tx_sfd = value;
break;
case BigMacReg::JAM_SIZE:
this->jam_size = value;
break;
case BigMacReg::PEAK_ATT:
this->peak_attempts = value;
break;
case BigMacReg::DEFER_TMR:
this->defer_timer = value;
break;
case BigMacReg::RX_FRM_CNT:
this->rcv_frame_cnt = value;
@@ -176,15 +284,44 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::RX_CVE_CNT:
this->cv_err_cnt = value;
break;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
break;
case BigMacReg::HASH_TAB_0:
case BigMacReg::HASH_TAB_1:
case BigMacReg::HASH_TAB_2:
case BigMacReg::HASH_TAB_3:
this->hash_table[(reg_offset >> 4) & 3] = value;
break;
case BigMacReg::IPG_1:
this->ipg1 = value;
break;
case BigMacReg::IPG_2:
this->ipg2 = value;
break;
case BigMacReg::A_LIMIT:
this->attempt_limit = value;
break;
case BigMacReg::AFR_0:
case BigMacReg::AFR_1:
case BigMacReg::AFR_2:
this->addr_filters[((reg_offset >> 4) & 0xF) - 4] = value;
break;
case BigMacReg::AFC_R:
this->addr_filt_mask = value;
break;
case BigMacReg::CHIP_ID:
case BigMacReg::TX_SM:
case BigMacReg::RX_ST_MCHN:
LOG_F(WARNING, "%s: Attempted write to read-only register at 0x%X with 0x%X",
this->name.c_str(), reg_offset, value);
break;
default:
LOG_F(WARNING, "%s: unimplemented register at 0x%X is written with 0x%X",
this->name.c_str(), reg_offset, value);
}
}
@@ -444,11 +581,11 @@ void BigMac::srom_xmit_bit(const uint8_t bit_val) {
}
static const DeviceDescription BigMac_Heathrow_Descriptor = {
BigMac::create_for_heathrow, {}, {}
BigMac::create_for_heathrow, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
};
static const DeviceDescription BigMac_Paddington_Descriptor = {
BigMac::create_for_paddington, {}, {}
BigMac::create_for_paddington, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
};
REGISTER_DEVICE(BigMacHeathrow, BigMac_Heathrow_Descriptor);
+23 -1
View File
@@ -183,7 +183,8 @@ private:
// BigMac state
uint16_t tx_reset = 0; // self-clearing one-bit register
uint16_t tx_if_ctrl = 0;
uint16_t rng_seed;
uint16_t xcvr_if_ctrl = 0;
uint16_t rng_seed = 0;
uint16_t norm_coll_cnt = 0;
uint16_t net_coll_cnt = 0;
uint16_t excs_coll_cnt = 0;
@@ -201,8 +202,29 @@ private:
uint16_t rx_fifo_size = 0;
uint16_t hash_table[4] = {};
uint16_t mac_addr_flt[3] = {};
uint16_t addr_filters[3] = {};
uint16_t addr_filt_mask = 0;
uint16_t tx_config = 0;
uint16_t tx_sfd = 0;
uint16_t tx_ptr = 0;
uint16_t tx_min = 0;
uint16_t tx_max = 0;
uint16_t rx_config = 0;
uint16_t rx_ptr = 0;
uint16_t rx_min = 0;
uint16_t rx_max = 0;
uint16_t ipg1 = 0;
uint16_t ipg2 = 0;
uint16_t attempt_limit = 0;
uint16_t mem_add = 0;
uint16_t mem_data_hi = 0;
uint16_t mem_data_lo = 0;
uint16_t slot_time = 0;
uint16_t preamble_len = 0;
uint16_t preamble_pat = 0;
uint16_t jam_size = 0;
uint16_t defer_timer = 0;
// Interrupt state
uint16_t event_mask = 0xFFFFU; // inverted mask: 0 - enabled, 1 - disabled
+33 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,9 +31,19 @@ using namespace MaceEnet;
uint8_t MaceController::read(uint8_t reg_offset)
{
switch(reg_offset) {
switch (reg_offset) {
case MaceReg::Rcv_FIFO:
return 0; //No FIFO yet
case MaceReg::Rcv_Frame_Ctrl:
return this->rcv_fc;
case MaceReg::Xmit_Frame_Stat:
return this->xmt_fs;
case MaceReg::Xmit_Retry_Cnt:
return this->xmt_retry;
case MaceReg::Rcv_Frame_Stat:
return this->rcv_fs;
case MaceReg::FIFO_Frame_Cnt:
return this->fifo_fc;
case MaceReg::Interrupt: {
uint8_t ret_val = this->int_stat;
this->int_stat = 0;
@@ -42,12 +52,26 @@ uint8_t MaceController::read(uint8_t reg_offset)
}
case MaceReg::Interrupt_Mask:
return this->int_mask;
case MaceReg::Poll:
return this->poll_reg;
case MaceReg::BIU_Config_Ctrl:
return this->biu_ctrl;
case MaceReg::FIFO_Config:
return this->fifo_ctrl;
case MaceReg::MAC_Config_Ctrl:
return this->mac_cc;
case MaceReg::PLS_Config_Ctrl:
return this->pls_cc;
case MaceReg::PHY_Config_Ctrl:
return this->phy_cc;
case MaceReg::Chip_ID_Lo:
return this->chip_id & 0xFFU;
case MaceReg::Chip_ID_Hi:
return (this->chip_id >> 8) & 0xFFU;
case MaceReg::Int_Addr_Config:
return this->addr_cfg;
case MaceReg::Missed_Pkt_Cnt:
return this->missed_pkts;
default:
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
}
@@ -64,9 +88,6 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
case MaceReg::Interrupt_Mask:
this->int_mask = value;
break;
case MaceReg::MAC_Config_Ctrl:
this->mac_cfg = value;
break;
case MaceReg::BIU_Config_Ctrl:
if (value & BIU_SWRST) {
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
@@ -74,6 +95,12 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
}
this->biu_ctrl = value;
break;
case MaceReg::FIFO_Config:
this->fifo_ctrl = value;
break;
case MaceReg::MAC_Config_Ctrl:
this->mac_cfg = value;
break;
case MaceReg::PLS_Config_Ctrl:
if (value != 7)
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
@@ -113,7 +140,7 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
}
static const DeviceDescription Mace_Descriptor = {
MaceController::create, {}, {}
MaceController::create, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
};
REGISTER_DEVICE(Mace, Mace_Descriptor);
+23 -11
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -79,7 +79,7 @@ namespace MaceEnet {
IAC_ADDRCHG = 1 << 7
};
}; // namespace MaceEnet
} // namespace MaceEnet
class MaceController : public DmaDevice, public HWComponent {
public:
@@ -87,7 +87,7 @@ public:
this->chip_id = id;
this->set_name("MACE");
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
};
}
~MaceController() = default;
static std::unique_ptr<HWComponent> create() {
@@ -99,14 +99,26 @@ public:
void write(uint8_t reg_offset, uint8_t value);
private:
uint16_t chip_id; // per-instance MACE Chip ID
uint8_t addr_cfg = 0;
uint8_t addr_ptr = 0;
uint8_t rcv_fc = 1;
uint8_t biu_ctrl = 0;
uint8_t mac_cfg = 0;
uint64_t phys_addr = 0;
uint64_t log_addr = 0;
uint16_t chip_id; // per-instance MACE Chip ID
uint8_t addr_cfg = 0;
uint8_t addr_ptr = 0;
uint8_t xmt_fs = 0;
uint8_t xmt_retry = 0;
uint8_t rcv_fc = 1;
uint8_t rcv_fs = 0;
uint8_t biu_ctrl = 0;
uint8_t fifo_ctrl = 0;
uint8_t poll_reg = 0;
uint8_t mac_cfg = 0;
uint8_t mac_cc = 0;
uint8_t pls_cc = 0;
uint8_t phy_cc = 0;
uint8_t fifo_fc = 0;
uint8_t missed_pkts = 0;
uint64_t phys_addr = 0;
uint64_t log_addr = 0;
// interrupt stuff
uint8_t int_stat = 0;
+21 -18
View File
@@ -34,8 +34,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
static FlopImgType identify_image(ImgFile& img_file)
{
// WOZ images identification strings
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
static uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
static const uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
static const uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
uint8_t buf[8] = { 0 };
@@ -47,20 +47,23 @@ static FlopImgType identify_image(ImgFile& img_file)
} else if (!std::memcmp(buf, WOZ2_SIG, sizeof(buf))) {
return FlopImgType::WOZ2;
} else {
for (int offset = 0; offset <=84; offset += 84) {
auto check_hfs_mfs = [](ImgFile& img, std::size_t offset) -> bool {
/* 2 bytes needed for MFS/HFS signature */
unsigned char buf[2];
// rewind to logical block 2
img_file.read((char *)buf, 2*BLOCK_SIZE + offset, sizeof(buf));
img.read((char *)buf, 2*BLOCK_SIZE + offset, sizeof(buf));
// check for HFS/MFS signature at the start of the logical block 2
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
(buf[0] == 0xD2 && buf[1] == 0xD7)) {
if (offset) {
return FlopImgType::DC42;
} else {
return FlopImgType::RAW;
}
}
}
return ((buf[0] == 0x42 && buf[1] == 0x44)
|| (buf[0] == 0xD2 && buf[1] == 0xD7));
};
if (check_hfs_mfs(img_file, 84))
return FlopImgType::DC42;
if (check_hfs_mfs(img_file, 0))
return FlopImgType::RAW;
}
return FlopImgType::UNKNOWN;
@@ -285,7 +288,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
if (!img_file.open(img_path)) {
img_file.close();
LOG_F(ERROR, "Could not open specified floppy image (%s)!", img_path.c_str());
LOG_F(ERROR, "Could not open specified floppy image (\"%s\")!", img_path.c_str());
return nullptr;
}
@@ -295,19 +298,19 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
switch(itype) {
case FlopImgType::RAW:
LOG_F(INFO, "Raw floppy image");
LOG_F(INFO, "Raw floppy image (\"%s\")", img_path.c_str());
fconv = new RawFloppyImg(img_path);
break;
case FlopImgType::DC42:
LOG_F(INFO, "Disk Copy 4.2 image");
LOG_F(INFO, "Disk Copy 4.2 image (\"%s\")", img_path.c_str());
fconv = new DiskCopy42Img(img_path);
break;
case FlopImgType::WOZ1:
case FlopImgType::WOZ2:
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
LOG_F(INFO, "WOZ v%s image (\"%s\")", (itype == FlopImgType::WOZ2) ? "2" : "1", img_path.c_str());
break;
default:
LOG_F(WARNING, "Unknown image format - assume RAW");
LOG_F(WARNING, "Unknown image format - assume RAW (\"%s\")", img_path.c_str());
fconv = new RawFloppyImg(img_path);
}
+50 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,15 +21,56 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Macintosh Superdrive emulation. */
#include <core/timermanager.h>
#include <devices/floppy/floppyimg.h>
#include <devices/floppy/superdrive.h>
#include <loguru.hpp>
#include <cinttypes>
namespace loguru {
enum : Verbosity {
Verbosity_READWRITE = loguru::Verbosity_9,
Verbosity_SUPERDRIVE = loguru::Verbosity_9,
};
}
using namespace MacSuperdrive;
std::string MacSuperdrive::get_command_name(uint8_t addr)
{
switch (addr) {
#define one_command(x) case CommandAddr::x: return #x;
one_command(Step_Direction)
one_command(Do_Step)
one_command(Motor_On_Off)
one_command(Eject_Disk)
one_command(Reset_Eject_Latch)
one_command(Switch_Drive_Mode)
default: return "unknown";
}
}
std::string MacSuperdrive::get_status_name(uint8_t addr)
{
switch (addr) {
#define one_status(x) case StatusAddr::x: return #x;
one_status(Step_Status)
one_status(Motor_Status)
one_status(Eject_Latch)
one_status(Select_Head_0)
one_status(MFM_Support)
one_status(Double_Sided)
one_status(Drive_Exists)
one_status(Disk_In_Drive)
one_status(Write_Protect)
one_status(Track_Zero)
one_status(Select_Head_1)
one_status(Drive_Mode)
one_status(Drive_Ready)
one_status(Media_Kind)
default: return "unknown";
}
}
MacSuperDrive::MacSuperDrive(std::string name)
{
this->set_name(name);
@@ -55,7 +96,8 @@ void MacSuperDrive::reset_params()
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
LOG_F(SUPERDRIVE, "%s: command %-17s addr=0x%X, value=%d",
this->get_name().c_str(), get_command_name(addr).c_str(), addr, value);
switch(addr) {
case CommandAddr::Step_Direction:
@@ -71,7 +113,6 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
this->cur_track = this->num_tracks - 1;
}
this->track_zero = this->cur_track == 0;
}
break;
case CommandAddr::Motor_On_Off:
@@ -121,7 +162,6 @@ void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
uint8_t MacSuperDrive::status(uint8_t addr)
{
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
uint8_t value;
switch(addr) {
@@ -153,7 +193,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
value = this->wr_protect ^ 1; // reverse logic
break;
case StatusAddr::Track_Zero:
value = this->track_zero ^ 1; // reverse logic
value = this->cur_track != 0; // reverse logic
break;
case StatusAddr::Select_Head_1:
value = this->cur_head = 1;
@@ -171,6 +211,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
value = 0;
}
LOG_F(SUPERDRIVE, "%s: status %-13s 0x%X = %d", this->get_name().c_str(), get_status_name(addr).c_str(), addr, value);
return value;
}
@@ -390,6 +431,8 @@ SectorHdr MacSuperDrive::current_sector_header()
char* MacSuperDrive::get_sector_data_ptr(int sector_num)
{
LOG_F(READWRITE, "%s: get_sector_data_ptr track:%d head:%d sector:%d",
this->get_name().c_str(), this->cur_track, this->cur_head, sector_num);
return this->disk_data.get() +
((this->track2lblk[this->cur_track] +
(this->cur_head * this->sectors_per_track[this->cur_track]) +
+6 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,7 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// convert number of bytes to disk time = nbytes * bits_per_byte * 2 us
#define MFM_BYTES_TO_DISK_TIME(bytes) USECS_TO_NSECS((bytes) * 8 * 2)
// timing constans for MFM disks
// timing constants for MFM disks
constexpr uint32_t MFM_INDX_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(146);
constexpr uint32_t MFM_ADR_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(22);
constexpr uint32_t MFM_SECT_DATA_DELAY = MFM_BYTES_TO_DISK_TIME(514);
@@ -94,6 +94,9 @@ typedef struct SectorHdr {
int format;
} SectorHdr;
std::string get_command_name(uint8_t addr);
std::string get_status_name(uint8_t addr);
class MacSuperDrive : public HWComponent {
public:
MacSuperDrive(std::string name);
@@ -125,7 +128,6 @@ private:
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
uint8_t is_ready;
uint8_t track_zero; // 1 - if head is at track zero
int step_dir; // step direction -1/+1
int cur_track; // track number the head is currently at
int cur_head; // current head number: 1 - upper, 0 - lower
@@ -158,6 +160,6 @@ private:
std::unique_ptr<char[]> disk_data;
};
}; // namespace MacSuperdrive
} // namespace MacSuperdrive
#endif // MAC_SUPERDRIVE_H
+6 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,7 +40,7 @@ using namespace Swim3;
Swim3Ctrl::Swim3Ctrl()
{
this->name = "SWIM3";
this->supported_types = HWCompType::FLOPPY_CTRL;
supports_types(HWCompType::FLOPPY_CTRL);
this->reset();
@@ -98,7 +98,7 @@ int Swim3Ctrl::device_postinit()
}
return 0;
};
}
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
{
@@ -290,8 +290,8 @@ void Swim3Ctrl::stop_stepping()
// cancel stepping task
if (this->step_timer_id) {
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
this->step_timer_id = 0;
}
this->step_timer_id = 0;
this->step_count = 0; // not sure this one is required
}
@@ -382,8 +382,8 @@ void Swim3Ctrl::stop_disk_access()
// cancel disk access timer
if (this->access_timer_id) {
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
this->access_timer_id = 0;
}
this->access_timer_id = 0;
}
void Swim3Ctrl::init_timer(const uint8_t start_val)
@@ -440,7 +440,7 @@ static const PropMap Swim3_Properties = {
};
static const DeviceDescription Swim3_Descriptor = {
Swim3Ctrl::create, {}, Swim3_Properties
Swim3Ctrl::create, {}, Swim3_Properties, HWCompType::FLOPPY_CTRL
};
REGISTER_DEVICE(Swim3, Swim3_Descriptor);
+5 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -73,7 +73,8 @@ enum {
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
INT_SENSE = 0x10, // unused by SWIM3 driver
INT_SENSE = 0x10, // generates interrupts on sense line changes
INT_ERROR = 0x20, // missing in SWIM3 ERS but used in MkLinux/BeOS
};
// SWIM3 internal states.
@@ -100,7 +101,7 @@ public:
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
};
}
protected:
void reset();
@@ -151,6 +152,6 @@ private:
uint8_t irq = 0;
};
}; // namespace Swim3
} // namespace Swim3
#endif // SWIM3_H
+5 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -329,11 +329,10 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
break;
case AMICReg::VIA2_IFR:
// if bit 7 is set, clear the corresponding IRQ bit for each "1" in value
// writing any value to VIA2_IFR with bit 7 cleared has no effect
if (value & 0x80) {
this->via2_ifr &= ~(value & 0x7F);
this->update_via2_irq();
} else { // writing any value to VIA2_IFR with bit 7 cleared has no effect
LOG_F(WARNING, "%s: bit 7 of VIA2_IFR is cleared!", this->name.c_str());
}
break;
case AMICReg::VIA2_Slot_IER:
@@ -824,14 +823,14 @@ DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len
uint8_t **p_data)
{
return DmaPullResult::NoMoreData;
};
}
static std::vector<std::string> Amic_Subdevices = {
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
"Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
};
static const DeviceDescription Amic_Descriptor = {
AMIC::create, Amic_Subdevices, {}
AMIC::create, Amic_Subdevices, {}, HWCompType::MMIO_DEV | HWCompType::INT_CTRL
};
REGISTER_DEVICE(Amic, Amic_Descriptor);
+8 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -106,19 +106,19 @@ public:
~AmicSndOutDma() = default;
void init(uint32_t buf_base, uint32_t buf_samples);
void enable() { this->enabled = true; };
void disable() { this->enabled = false; };
void enable() { this->enabled = true; }
void disable() { this->enabled = false; }
uint8_t read_stat();
void update_irq();
void write_dma_out_ctrl(uint8_t value);
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; }
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
void init_interrupts(InterruptCtrl *int_ctrl, uint64_t irq_id) {
this->int_ctrl = int_ctrl;
this->snd_dma_irq_id = irq_id;
};
}
private:
bool enabled = false;
@@ -144,7 +144,7 @@ public:
void reinit(const uint32_t addr_ptr, const uint16_t byte_cnt);
void reset(const uint32_t addr_ptr);
void write_ctrl(const uint8_t value);
uint8_t read_stat() { return this->stat; };
uint8_t read_stat() { return this->stat; }
int push_data(const char* src_ptr, int len);
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
@@ -163,7 +163,7 @@ public:
~AmicSerialXmitDma() = default;
void write_ctrl(const uint8_t value);
uint8_t read_stat() { return this->stat; };
uint8_t read_stat() { return this->stat; }
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
@@ -183,7 +183,7 @@ public:
void reinit(const uint32_t addr_ptr);
void reset(const uint32_t addr_ptr);
void write_ctrl(const uint8_t value);
uint8_t read_stat() { return this->stat; };
uint8_t read_stat() { return this->stat; }
void xfer_to_device();
void xfer_from_device();
+32 -30
View File
@@ -33,35 +33,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <memory>
uint16_t NvramAddrHiDev::iodev_read(uint32_t address) {
return nvram_addr_hi;
}
void NvramAddrHiDev::iodev_write(uint32_t address, uint16_t value) {
this->nvram_addr_hi = value;
}
NvramDev::NvramDev(NvramAddrHiDev *addr_hi) {
// NVRAM connection
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
this->addr_hi = addr_hi;
}
uint16_t NvramDev::iodev_read(uint32_t address) {
return this->nvram->read_byte((addr_hi->iodev_read(0) << 5) + address);
}
void NvramDev::iodev_write(uint32_t address, uint16_t value) {
this->nvram->write_byte((addr_hi->iodev_read(0) << 5) + address, value);
}
GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
supports_types(HWCompType::IOBUS_HOST | HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_GRANDCENTRAL;
this->status = 0x0200; // 9:DEVSEL
this->class_rev = 0xFF000002;
this->cache_ln_sz = 8;
@@ -230,6 +215,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
uint8_t val = mac_address[(offset >> 4) & 0x7];
if (((offset >> 4) & 0x7) < 6) {
if (mac_address[0] == 0x08 && bit_flip_0x08)
// reverse the order of the bits
val = (val * 0x0202020202ULL & 0x010884422010ULL) % 1023;
} else {
LOG_F(WARNING, "%s: reading byte %d of ENET_ROM using offset %x",
@@ -271,6 +257,13 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
return this->enet_tx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ETH_RCV:
return this->enet_rx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ESCC_A_XMIT:
case MIO_GC_DMA_ESCC_A_RCV:
case MIO_GC_DMA_ESCC_B_XMIT:
case MIO_GC_DMA_ESCC_B_RCV:
return 0;
/*Stubbed out due to serial emulation being unfinished.
case MIO_GC_DMA_ESCC_A_XMIT:
return this->escc_a_tx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ESCC_A_RCV:
@@ -278,7 +271,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_GC_DMA_ESCC_B_XMIT:
return this->escc_b_tx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ESCC_B_RCV:
return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);
return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);*/
case MIO_GC_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_AUDIO_IN:
@@ -307,7 +300,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_INT_MASK1:
return BYTESWAP_32(this->int_mask);
case MIO_INT_CLEAR1:
// some Mac OS drivers reads from this write-only register
// some Mac OS drivers read from this write-only register
// so we return zero here as real HW does
return 0;
case MIO_INT_LEVELS1:
@@ -405,16 +398,16 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
this->enet_rx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ESCC_A_XMIT:
this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
//this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ESCC_A_RCV:
this->escc_a_rx_dma->reg_write(offset & 0xFF, value, size);
//this->escc_a_rx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ESCC_B_XMIT:
this->escc_b_tx_dma->reg_write(offset & 0xFF, value, size);
//this->escc_b_tx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ESCC_B_RCV:
this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
//this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
@@ -468,8 +461,6 @@ void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
}
}
#define INT_TO_IRQ_ID(intx) (1 << intx)
uint64_t GrandCentral::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C);
@@ -577,12 +568,23 @@ void GrandCentral::clear_cpu_int() {
}
}
static const std::vector<std::string> GCSubdevices = {
"NVRAM", "ViaCuda", "Escc", "ScsiCurio", "Sc53C94", "Mace", "Swim3"
static const std::vector<std::string> GrandCentralCatalyst_Subdevices = {
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "Mace", "Swim3"
};
static const DeviceDescription GC_Descriptor = {
GrandCentral::create, GCSubdevices, {}
static const std::vector<std::string> GrandCentralTnt_Subdevices = {
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "MeshTnt", "Mace", "Swim3"
};
REGISTER_DEVICE(GrandCentral, GC_Descriptor);
static const DeviceDescription GrandCentralCatalyst_Descriptor = {
GrandCentral::create, GrandCentralCatalyst_Subdevices, {},
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
};
static const DeviceDescription GrandCentralTnt_Descriptor = {
GrandCentral::create, GrandCentralTnt_Subdevices, {},
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
};
REGISTER_DEVICE(GrandCentralCatalyst, GrandCentralCatalyst_Descriptor);
REGISTER_DEVICE(GrandCentralTnt, GrandCentralTnt_Descriptor);
+107 -137
View File
@@ -69,6 +69,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <memory>
#include <string>
/** PCI device IDs for various MacIO ASICs. */
enum {
@@ -82,24 +83,20 @@ enum {
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
#define INT_TO_IRQ_ID(intx) (1ULL << intx)
/** Offsets to common MacIO interrupt registers. */
enum {
MIO_INT_EVENTS2 = 0x10,
MIO_INT_MASK2 = 0x14,
MIO_INT_CLEAR2 = 0x18,
MIO_INT_LEVELS2 = 0x1C,
MIO_INT_EVENTS2 = 0x10, // Heathrow/Paddington only
MIO_INT_MASK2 = 0x14, // Heathrow/Paddington only
MIO_INT_CLEAR2 = 0x18, // Heathrow/Paddington only
MIO_INT_LEVELS2 = 0x1C, // Heathrow/Paddington only
MIO_INT_EVENTS1 = 0x20,
MIO_INT_MASK1 = 0x24,
MIO_INT_CLEAR1 = 0x28,
MIO_INT_LEVELS1 = 0x2C
};
class IobusDevice {
public:
virtual uint16_t iodev_read(uint32_t address) = 0;
virtual void iodev_write(uint32_t address, uint16_t value) = 0;
};
/** GrandCentral DBDMA channels. */
enum : uint8_t {
MIO_GC_DMA_SCSI_CURIO = 0,
@@ -115,11 +112,22 @@ enum : uint8_t {
MIO_GC_DMA_SCSI_MESH = 0xA,
};
class IobusDevice {
public:
virtual uint16_t iodev_read(uint32_t address) = 0;
virtual void iodev_write(uint32_t address, uint16_t value) = 0;
};
class NvramAddrHiDev: public IobusDevice {
public:
// IobusDevice methods
uint16_t iodev_read(uint32_t address);
void iodev_write(uint32_t address, uint16_t value);
uint16_t iodev_read(uint32_t address) {
return nvram_addr_hi;
}
void iodev_write(uint32_t address, uint16_t value) {
this->nvram_addr_hi = value;
}
protected:
uint16_t nvram_addr_hi = 0;
@@ -130,12 +138,59 @@ public:
NvramDev(NvramAddrHiDev *addr_hi);
// IobusDevice methods
uint16_t iodev_read(uint32_t address);
void iodev_write(uint32_t address, uint16_t value);
uint16_t iodev_read(uint32_t address) {
return this->nvram->read_byte((addr_hi->iodev_read(0) << 5) + address);
}
void iodev_write(uint32_t address, uint16_t value) {
this->nvram->write_byte((addr_hi->iodev_read(0) << 5) + address, value);
}
protected:
NVram* nvram;
NvramAddrHiDev* addr_hi;
NVram* nvram = nullptr;
NvramAddrHiDev* addr_hi = nullptr;
};
/** This class provides common building blocks for various MacIO ASICs. */
class MacIoBase : public PCIDevice, public InterruptCtrl {
public:
MacIoBase(std::string name, uint16_t dev_id, uint8_t rev=1);
~MacIoBase() = default;
uint64_t register_dma_int(IntSrc src_id) override;
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
protected:
void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
void signal_cpu_int();
void clear_cpu_int();
// PCI device state
uint32_t iomem_size = 0;
uint32_t base_addr = 0;
// interrupt state
uint64_t int_mask = 0;
bool cpu_int_latch = false;
std::atomic<uint64_t> int_levels{0};
std::atomic<uint64_t> int_events{0};
// Subdevice objects
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
Swim3::Swim3Ctrl* swim3; // floppy disk controller
MacioSndCodec* snd_codec; // audio codec instance
EsccController* escc; // ESCC serial controller
// DMA channels
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> snd_out_dma;
std::unique_ptr<DMAChannel> snd_in_dma;
std::unique_ptr<DMAChannel> escc_a_tx_dma;
std::unique_ptr<DMAChannel> escc_a_rx_dma;
std::unique_ptr<DMAChannel> escc_b_tx_dma;
std::unique_ptr<DMAChannel> escc_b_rx_dma;
};
class GrandCentral : public PCIDevice, public InterruptCtrl {
@@ -206,92 +261,6 @@ private:
uint16_t unsupported_dma_channel_write = 0;
};
class OHare : public PCIDevice, public InterruptCtrl {
public:
OHare();
~OHare() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<OHare>(new OHare());
}
// MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
// InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override;
uint64_t register_dma_int(IntSrc src_id) override;
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
protected:
void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
uint32_t mio_ctrl_read(uint32_t offset, int size);
uint32_t mio_ctrl_read_aligned(uint32_t offset);
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
uint32_t dma_read(uint32_t offset, int size);
void dma_write(uint32_t offset, uint32_t value, int size);
void feature_control(const uint32_t value);
void signal_cpu_int();
void clear_cpu_int();
private:
uint32_t base_addr = 0;
// interrupt state
uint32_t int_mask = 0;
std::atomic<uint32_t> int_levels{0};
std::atomic<uint32_t> int_events{0};
bool cpu_int_latch = false;
uint32_t feat_ctrl = 0; // features control register
// subdevice objects
MacioSndCodec* snd_codec; // audio codec instance
NVram* nvram; // NVRAM
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
MeshController* mesh; // MESH SCSI cell instance
EsccController* escc; // ESCC serial controller
IdeChannel* ide_0; // Internal ATA
Swim3::Swim3Ctrl* swim3; // floppy disk controller
// DMA channels
std::unique_ptr<DMAChannel> mesh_dma;
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> snd_out_dma;
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
};
/**
Heathrow ASIC emulation
Heathrow is a MIO-compliant ASIC used in the Gossamer architecture. It's
hard-wired to PCI device number 16. Its I/O memory (512Kb) will be configured
by the Macintosh firmware to live at 0xF3000000.
Emulated subdevices and their offsets within Heathrow I/O space:
----------------------------------------------------------------
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
escc(compat) register space: 0x00012000, size: 0x00001000
DMA space: 0x00008400, size: 0x00000400
escc(MacRISC) register space: 0x00013000, size: 0x00001000
DMA space: 0x00008400, size: 0x00000400
escc:ch-a register space: 0x00013020, DMA space: 0x00008400, 0x00008500
escc:ch-b register space: 0x00013000, DMA space: 0x00008600, 0x00008700
davbus(sound) register space: 0x00014000, DMA space: 0x00008800, 0x00008900
SWIM3(floppy) register space: 0x00015000, DMA space: 0x00008100
NVRAM register space: 0x00060000, size: 0x00020000
IDE register space: 0x00020000, DMA space: 0x00008b00
VIA-CUDA register space: 0x00016000, size: 0x00002000
*/
/** O'Hare/Heathrow specific registers. */
enum {
MIO_OHARE_ID = 0x34, // IDs register
@@ -303,7 +272,7 @@ enum {
enum {
MIO_OH_ID_FP = 0x70000000, // Flat panel ID
MIO_OH_ID_MON = 0x00300000, // Monitor ID (mon_id?=1, no s-video/composite=3 but only if fatman exists).
MIO_OH_ID_MB = 0x0000F000, // Media Bay ID (0,1=swim, 3=ata, 5=pci, 7=?)
MIO_OH_ID_MB = 0x0000F000, // Media Bay ID (0,1=swim, 3=ata, 5=pci, 7=?, 4=TAM)
MIO_OH_ID_CPU = 0x000000E0, // CPUID field
MIO_OH_ID_DISABLE_SCSI_TERMINATORS = 0x00000010, // clear this bit to disable-scsi-terminators - read this bit for emmo_pin
MIO_OH_ID_ENABLE_SCSI_TERMINATORS = 0x00000008, // set this bit to enable-scsi-terminators
@@ -339,8 +308,8 @@ enum {
MIO_OH_FC_NOT_IDE1_RESET = 1 << 23,
MIO_OH_FC_SLOW_SCC_PCLK = 1 << 24,
MIO_OH_FC_RESET_SCC = 1 << 25,
MIO_OH_FC_MFDC_CELL_EN = 1 << 26,
MIO_OH_FC_USE_MFDC = 1 << 27,
MIO_OH_FC_MFDC_CELL_EN = 1 << 26, // Heathrow/Paddington only
MIO_OH_FC_USE_MFDC = 1 << 27, // Heathrow/Paddington only
MIO_OH_FC_RESVD28 = 1 << 28,
MIO_OH_FC_RESVD29 = 1 << 29,
MIO_OH_FC_RESVD30 = 1 << 30,
@@ -363,16 +332,39 @@ enum : uint8_t {
MIO_OHARE_DMA_IDE1 = 0xC
};
class HeathrowIC : public PCIDevice, public InterruptCtrl {
/** Implementation class for O'Hare/Heathrow/Paddington devices. */
class MacIoTwo : public MacIoBase {
public:
HeathrowIC();
~HeathrowIC() = default;
MacIoTwo(std::string name, uint16_t dev_id);
~MacIoTwo() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<HeathrowIC>(new HeathrowIC());
static std::unique_ptr<HWComponent> create_ohare() {
return std::unique_ptr<MacIoTwo>(new MacIoTwo("ohare", MIO_DEV_ID_OHARE));
}
void set_media_bay_id(uint8_t id);
static std::unique_ptr<HWComponent> create_heathrow() {
return std::unique_ptr<MacIoTwo>(new MacIoTwo("heathrow", MIO_DEV_ID_HEATHROW));
}
static std::unique_ptr<HWComponent> create_paddington() {
return std::unique_ptr<MacIoTwo>(new MacIoTwo("paddington", MIO_DEV_ID_PADDINGTON));
}
void set_fp_id(uint8_t id) {
this->fp_id = id;
}
void set_mon_id(uint8_t id) {
this->mon_id = id;
}
void set_media_bay_id(uint8_t id) {
this->mb_id = id;
}
void set_cpu_id(uint8_t id) {
this->cpu_id = id;
}
// MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
@@ -381,8 +373,6 @@ public:
// InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override;
uint64_t register_dma_int(IntSrc src_id) override;
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
protected:
uint32_t dma_read(uint32_t offset, int size);
@@ -391,23 +381,9 @@ protected:
uint32_t mio_ctrl_read(uint32_t offset, int size);
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
void feature_control(uint32_t value);
void signal_cpu_int();
void clear_cpu_int();
private:
uint32_t base_addr = 0;
// interrupt state
uint64_t int_mask = 0;
std::atomic<uint64_t> int_levels{0};
std::atomic<uint64_t> int_events{0};
bool cpu_int_latch = false;
uint32_t feat_ctrl = 0; // features control register
uint32_t aux_ctrl = 0; // aux features control register
@@ -415,27 +391,21 @@ private:
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
uint8_t mon_id = 0x10; // Monitor ID (bits 23:16 of the MIO_HEAT_ID)
uint8_t fp_id = 0x70; // Flat panel ID (MSB of the MIO_HEAT_ID)
uint8_t emmo_pin; // factory tester status, active low
// subdevice objects
MacioSndCodec* snd_codec; // audio codec instance
uint8_t emmo = 0x01; // factory tester status, active low
// Subdevice object pointers
NVram* nvram; // NVRAM
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
MeshController* mesh; // MESH SCSI cell instance
EsccController* escc; // ESCC serial controller
IdeChannel* ide_0; // Internal ATA
IdeChannel* ide_1; // Media Bay ATA
Swim3::Swim3Ctrl* swim3; // floppy disk controller
BigMac* bmac; // Ethernet MAC cell
// DMA channels
std::unique_ptr<DMAChannel> mesh_dma;
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> enet_xmit_dma;
std::unique_ptr<DMAChannel> enet_rcv_dma;
std::unique_ptr<DMAChannel> escc_b_rcv_dma;
std::unique_ptr<DMAChannel> snd_out_dma;
std::unique_ptr<DMAChannel> ide0_dma;
std::unique_ptr<DMAChannel> ide1_dma;
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
+176
View File
@@ -0,0 +1,176 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 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 <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/viacuda.h>
#include <devices/ioctrl/macio.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
#include <functional>
#include <memory>
MacIoBase::MacIoBase(std::string name, uint16_t dev_id, uint8_t rev) :
PCIDevice("mac-io_" + name), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = dev_id;
this->class_rev = 0xFF000000 + rev;
this->cache_ln_sz = 8;
// select memory mapped I/O size: 128Kb for Grand Central, 512Kb for others
this->iomem_size = (dev_id == MIO_DEV_ID_GRANDCENTRAL) ? 0x20000 : 0x80000;
this->setup_bars({{0, -this->iomem_size}});
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
// connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// find the sound codec, create its DMA channels, then wire everything together
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_out"));
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
this->snd_codec->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
);
this->snd_in_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_in"));
this->snd_in_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Rx));
this->snd_codec->set_dma_in(this->snd_in_dma.get());
this->snd_in_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_in_start, this->snd_codec),
std::bind(&AwacsScreamer::dma_in_stop, this->snd_codec)
);
// connect floppy disk controller and initialize its DMA channel
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel("floppy"));
this->swim3->set_dma_channel(this->floppy_dma.get());
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
// connect serial HW to its DMA channels
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
this->escc_a_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_tx"));
this->escc_a_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_rx"));
this->escc_b_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_tx"));
this->escc_b_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_rx"));
this->escc_a_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Tx));
this->escc_a_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Rx));
this->escc_b_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Tx));
this->escc_b_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Rx));
this->escc->set_dma_channel(0, this->escc_a_tx_dma.get());
this->escc->set_dma_channel(1, this->escc_a_rx_dma.get());
this->escc->set_dma_channel(2, this->escc_b_tx_dma.get());
this->escc->set_dma_channel(3, this->escc_b_rx_dma.get());
}
void MacIoBase::notify_bar_change(int bar_num) {
if (bar_num) // only BAR0 is supported
return;
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
if (this->base_addr) {
this->host_instance->pci_unregister_mmio_region(this->base_addr,
this->iomem_size, this);
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, this->iomem_size, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->name.c_str(), this->base_addr);
}
}
uint64_t MacIoBase::register_dma_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09);
default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
// native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions
#if 0
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events),
uint32_t(this->int_levels >> 32), uint32_t(this->int_levels),
uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
);
#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
} else {
this->int_events &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
} else {
this->int_levels &= ~irq_id;
}
this->signal_cpu_int();
}
void MacIoBase::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state);
}
void MacIoBase::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state);
}
void MacIoBase::signal_cpu_int() {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
} else {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
}
}
}
void MacIoBase::clear_cpu_int() {
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
}
}
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -19,66 +19,19 @@ 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 <cpu/ppc/ppcemu.h>
/** @file MacIO 2nd generation I/O controllers emulation. */
#include <devices/deviceregistry.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/dbdma.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/viacuda.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/macio.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
#include <functional>
#include <memory>
/** Heathrow Mac I/O device emulation.
Author: Max Poliakovski
*/
using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_HEATHROW;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
this->setup_bars({{0, 0xFFF80000UL}}); // declare 512Kb of memory-mapped I/O space
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
MacIoTwo::MacIoTwo(std::string name, uint16_t dev_id) : MacIoBase(name, dev_id) {
// NVRAM connection
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
// connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// find appropriate sound chip, create a DMA output channel for sound,
// then wire everything together
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_out"));
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
this->snd_codec->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
);
// connect SCSI HW and the corresponding DMA channel
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
// connect SCSI controller cell and its DMA channel
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_type(HWCompType::SCSI_HOST));
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
this->mesh_dma->connect(this->mesh);
@@ -86,130 +39,35 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
// connect IDE HW
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
this->ide0_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Ide0-Dma"));
this->ide0_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_IDE0));
this->ide0_dma->connect(this->ide_0);
this->ide_0->connect(this->ide0_dma.get());
// connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
// connect DBDMA
this->escc_b_rcv_dma = std::unique_ptr<DMAChannel>(new DMAChannel("DBDMABRx"));
// connect floppy disk HW and initialize its DMA channel
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel("floppy"));
this->swim3->set_dma_channel(this->floppy_dma.get());
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
// connect Ethernet HW
this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
// set EMMO pin status (active low)
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
default : return "unknown" ;
}
}
void HeathrowIC::set_media_bay_id(uint8_t id) {
this->mb_id = id;
}
void HeathrowIC::notify_bar_change(int bar_num)
{
if (bar_num) // only BAR0 is supported
return;
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
if (this->base_addr) {
this->host_instance->pci_unregister_mmio_region(this->base_addr, 0x80000, this);
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
}
}
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma)
return this->mesh_dma->reg_read(offset & 0xFF, size);
else
return 0;
case MIO_OHARE_DMA_FLOPPY:
return this->floppy_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ETH_XMIT:
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ETH_RCV:
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ESCC_B_RCV:
return this->escc_b_rcv_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
}
this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name_optional("Ide1"));
this->ide1_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Ide1-Dma"));
this->ide1_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_IDE1));
if (this->ide_1) {
this->ide1_dma->connect(this->ide_1);
this->ide_1->connect(this->ide1_dma.get());
}
return 0;
}
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_FLOPPY:
this->floppy_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ETH_XMIT:
this->enet_xmit_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ETH_RCV:
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ESCC_B_RCV:
this->escc_b_rcv_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
default:
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
// connect Ethernet HW (Heathrow and Paddington)
if (this->device_id != MIO_DEV_ID_OHARE) {
this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
}
// set EMMO status (active low)
this->emmo = GET_BIN_PROP("emmo") ^ 1;
}
uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
uint32_t MacIoTwo::read(uint32_t rgn_start, uint32_t offset, int size) {
uint32_t value;
LOG_F(9, "%s: reading from offset %x", this->name.c_str(), offset);
LOG_F(9, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
unsigned sub_addr = (offset >> 12) & 0x7F;
@@ -233,7 +91,8 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
}
if ((offset & 0xFF) < 0x60) {
value = 0;
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(),
offset, SIZE_ARG(size));
break;
}
// fallthrough
@@ -251,25 +110,27 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
value = this->viacuda->read((offset >> 9) & 0xF);
break;
case 0x20: // IDE 0
value = this->ide_0->read((offset >> 4) & 0x1F, size);
value = this->ide_0->read((offset >> 4) & 0xFF, size);
break;
case 0x21: // IDE 1
value = this->ide_1->read((offset >> 4) & 0x1F, size);
value = this->ide_1 ? this->ide_1->read((offset >> 4) & 0xFF, size) : 0;
break;
default:
if (sub_addr >= 0x60) {
value = this->nvram->read_byte((offset >> 4) & 0x1FFF);
} else {
value = 0;
LOG_F(WARNING, "Attempting to read from unmapped I/O space: %x", offset);
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
}
}
return value;
}
void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
LOG_F(9, "%s: writing to offset %x", this->name.c_str(), offset);
void MacIoTwo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
LOG_F(9, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
unsigned sub_addr = (offset >> 12) & 0x7F;
@@ -310,22 +171,111 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
case 0x17:
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 0x20: // IDE O
this->ide_0->write((offset >> 4) & 0x1F, value, size);
case 0x20: // IDE 0
this->ide_0->write((offset >> 4) & 0xFF, value, size);
break;
case 0x21: // IDE 1
this->ide_1->write((offset >> 4) & 0x1F, value, size);
if (this->ide_1)
this->ide_1->write((offset >> 4) & 0xFF, value, size);
break;
default:
if (sub_addr >= 0x60) {
this->nvram->write_byte((offset - 0x60000) >> 4, value);
} else {
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x", offset);
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
}
}
}
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
default : return "unknown" ;
}
}
uint32_t MacIoTwo::dma_read(uint32_t offset, int size) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
return this->mesh_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_FLOPPY:
return this->floppy_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ETH_XMIT:
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ETH_RCV:
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ESCC_B_RCV:
return 0;
//return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_IDE0:
return this->ide0_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_IDE1:
return this->ide1_dma->reg_read(offset & 0xFF, size);
default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c",
this->name.c_str(), dma_channel, get_name_dma(dma_channel),
offset & 0xFF, SIZE_ARG(size));
}
}
return 0;
}
void MacIoTwo::dma_write(uint32_t offset, uint32_t value, int size) {
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
this->mesh_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_FLOPPY:
this->floppy_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ETH_XMIT:
this->enet_xmit_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ETH_RCV:
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ESCC_B_RCV:
this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_IDE0:
this->ide0_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_IDE1:
this->ide1_dma->reg_write(offset & 0xFF, value, size);
break;
default:
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x",
this->name.c_str(), dma_channel, get_name_dma(dma_channel),
offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
}
}
uint32_t MacIoTwo::mio_ctrl_read(uint32_t offset, int size) {
uint32_t value;
switch (offset & 0xFC) {
@@ -349,29 +299,31 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
break;
case MIO_INT_CLEAR1:
case MIO_INT_CLEAR2:
// some Mac OS drivers reads from those write-only registers
// some Mac OS drivers read from these write-only registers
// so we return zero here as real HW does
value = 0;
break;
case MIO_OHARE_ID:
LOG_F(9, "read from MIO:ID register at Address %x", ppc_state.pc);
value = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
(this->cpu_id | (this->emmo_pin << 4));
(this->cpu_id | (this->emmo << 4));
LOG_F(9, "%s: read OHARE_ID @%02x = %08x",
this->get_name().c_str(), offset, value);
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(9, "read from MIO:Feat_Ctrl register");
value = this->feat_ctrl;
LOG_F(9, "%s: read FEAT_CTRL @%02x = %08x",
this->get_name().c_str(), offset, value);
break;
default:
value = 0;
LOG_F(WARNING, "read from unknown MIO register at %x", offset);
break;
LOG_F(WARNING, "%s: read @%02x",
this->get_name().c_str(), offset);
}
return BYTESWAP_32(value);
}
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
void MacIoTwo::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) {
case MIO_INT_MASK2:
this->int_mask |= uint64_t(BYTESWAP_32(value) & ~MACIO_INT_MODE) << 32;
@@ -396,38 +348,41 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
clear_cpu_int();
break;
case MIO_OHARE_ID:
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x", value, offset, ppc_state.pc);
LOG_F(ERROR, "%s: write OHARE_ID @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(WARNING, "%s: write FEAT_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
this->feature_control(BYTESWAP_32(value));
break;
case MIO_AUX_CTRL:
LOG_F(9, "write %x to MIO:Aux_Ctrl register", value);
LOG_F(9, "%s: write AUX_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
this->aux_ctrl = value;
break;
default:
LOG_F(WARNING, "write %x to unknown MIO register at %x", value, offset);
break;
LOG_F(WARNING, "%s: write @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
}
}
void HeathrowIC::feature_control(uint32_t value)
{
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
void MacIoTwo::feature_control(uint32_t value) {
this->feat_ctrl = value;
if (!(this->feat_ctrl & 1)) {
LOG_F(9, "Heathrow: Monitor sense enabled");
LOG_F(9, "%s: monitor sense enabled", this->name.c_str());
} else {
LOG_F(9, "Heathrow: Monitor sense disabled");
LOG_F(9, "%s: monitor sense disabled", this->name.c_str());
}
}
#define INT_TO_IRQ_ID(intx) (1ULL << intx)
uint64_t MacIoTwo::register_dev_int(IntSrc src_id) {
if (this->device_id == MIO_DEV_ID_OHARE && src_id == ETHERNET) {
ABORT_F("%s: attempt to register non-existing Ethernet device int",
this->name.c_str());
}
uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
{
switch (src_id) {
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D); // Beige G3 first IDE controller, or Yosemite ata-3
@@ -439,11 +394,23 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
case IntSrc::SWIM3 : return INT_TO_IRQ_ID(0x13);
case IntSrc::NMI : return INT_TO_IRQ_ID(0x14); // nmiSource in AppleHeathrow/Heathrow.cpp; programmer-switch in B&W G3
case IntSrc::BANDIT1 : return INT_TO_IRQ_ID(0x16);
case IntSrc::PCI_E : return (this->device_id == MIO_DEV_ID_OHARE)
? INT_TO_IRQ_ID(0x16) // same interrupt as bandit
: INT_TO_IRQ_ID(0x18); // Lombard GPU
case IntSrc::PCI_F : return INT_TO_IRQ_ID(0x18);
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
case IntSrc::PCI_B : return (this->device_id == MIO_DEV_ID_OHARE)
? INT_TO_IRQ_ID(0x19)
: INT_TO_IRQ_ID(0x18);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1A);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1B);
case IntSrc::PCI_C : return (this->device_id == MIO_DEV_ID_OHARE)
? INT_TO_IRQ_ID(0x1C)
: INT_TO_IRQ_ID(0x19);
case IntSrc::PERCH2 : return INT_TO_IRQ_ID(0x15);
case IntSrc::PCI_GPU : return INT_TO_IRQ_ID(0x16);
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
case IntSrc::PCI_B : return INT_TO_IRQ_ID(0x18);
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x19);
case IntSrc::PERCH1 : return INT_TO_IRQ_ID(0x1A);
case IntSrc::PCI_PERCH : return INT_TO_IRQ_ID(0x1C);
@@ -453,100 +420,66 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
case IntSrc::PCI_J10 : return INT_TO_IRQ_ID(0x18); // Yosemite 64-bit 33MHz slot
case IntSrc::PCI_J9 : return INT_TO_IRQ_ID(0x19); // Yosemite 64-bit 33MHz slot
case IntSrc::ATA : return INT_TO_IRQ_ID(0x1A); // Yosemite PCI pci-ata
case IntSrc::USB : return INT_TO_IRQ_ID(0x1C); // Yosemite PCI usb
case IntSrc::USB : return INT_TO_IRQ_ID(0x1C); // Yosemite PCI USB
case IntSrc::ETHERNET : return INT_TO_IRQ_ID(0x2A);
default:
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
uint64_t HeathrowIC::register_dma_int(IntSrc src_id)
{
uint64_t MacIoTwo::register_dma_int(IntSrc src_id) {
if (this->device_id == MIO_DEV_ID_OHARE &&
(src_id == IntSrc::DMA_ETHERNET_Tx || src_id == IntSrc::DMA_ETHERNET_Rx)) {
ABORT_F("%s: attempt to register non-existing Ethernet DMA int", this->name.c_str());
}
switch (src_id) {
case IntSrc::DMA_SCSI_MESH : return INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_IDE1 : return INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_ETHERNET_Tx : return INT_TO_IRQ_ID(0x20);
case IntSrc::DMA_ETHERNET_Rx : return INT_TO_IRQ_ID(0x21);
default:
ABORT_F("Heathrow: unknown DMA interrupt source %d", src_id);
return MacIoBase::register_dma_int(src_id);
}
return 0;
}
void HeathrowIC::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
{
// native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions
#if 0
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events), uint32_t(this->int_levels >> 32),
uint32_t(this->int_levels), uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
);
#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
} else {
this->int_events &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
} else {
this->int_levels &= ~irq_id;
}
//===========================================================================
static const std::vector<std::string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "MeshTnt", "Escc", "Swim3", "Ide0", "Ide1"
};
this->signal_cpu_int();
}
void HeathrowIC::ack_int(uint64_t irq_id, uint8_t irq_line_state)
{
this->ack_int_common(irq_id, irq_line_state);
}
void HeathrowIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state)
{
this->ack_int_common(irq_id, irq_line_state);
}
void HeathrowIC::signal_cpu_int() {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
} else {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
}
}
}
void HeathrowIC::clear_cpu_int()
{
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "Heathrow: CPU INT latch cleared");
}
}
static const vector<string> Heathrow_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
static const std::vector<std::string> Heathrow_Subdevices = {
"NVRAM", "ViaCuda", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
"BigMacHeathrow"
};
static const DeviceDescription Heathrow_Descriptor = {
HeathrowIC::create, Heathrow_Subdevices, {}
static const std::vector<std::string> Paddington_Subdevices = {
"NVRAM", "ViaCuda", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
"BigMacPaddington"
};
static const DeviceDescription OHare_Descriptor = {
MacIoTwo::create_ohare, OHare_Subdevices, {},
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
};
static const DeviceDescription Heathrow_Descriptor = {
MacIoTwo::create_heathrow, Heathrow_Subdevices, {},
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
};
static const DeviceDescription Paddington_Descriptor = {
MacIoTwo::create_paddington, Paddington_Subdevices, {},
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
};
REGISTER_DEVICE(OHare, OHare_Descriptor);
REGISTER_DEVICE(Heathrow, Heathrow_Descriptor);
REGISTER_DEVICE(Paddington, Paddington_Descriptor);
-499
View File
@@ -1,499 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 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 <cpu/ppc/ppcemu.h>
#include <devices/deviceregistry.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/dbdma.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/viacuda.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/macio.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
#include <functional>
#include <memory>
namespace loguru {
enum : Verbosity {
Verbosity_INTERRUPT = loguru::Verbosity_9,
Verbosity_DBDMA = loguru::Verbosity_9
};
}
OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_OHARE;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
this->setup_bars({{0, 0xFFF80000UL}}); // declare 512Kb of memory-mapped I/O space
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
// NVRAM connection
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
// connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// find appropriate sound chip, create a DMA output channel for sound,
// then wire everything together
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_out"));
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
this->snd_codec->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
);
// connect SCSI HW and the corresponding DMA channel
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
this->mesh_dma->connect(this->mesh);
this->mesh->connect(this->mesh_dma.get());
// connect IDE HW
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
//this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
// connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
// connect floppy disk HW and initialize its DMA channel
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel("floppy"));
this->swim3->set_dma_channel(this->floppy_dma.get());
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
// connect Ethernet HW
//this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
//this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
//this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
// set EMMO pin status (active low) FIXME: Is there an emmo pin?
//this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
default : return "unknown" ;
}
}
void OHare::notify_bar_change(int bar_num)
{
if (bar_num) // only BAR0 is supported
return;
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
if (this->base_addr) {
this->host_instance->pci_unregister_mmio_region(this->base_addr, 0x80000, this);
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
}
}
uint32_t OHare::read(uint32_t rgn_start, uint32_t offset, int size)
{
uint32_t value;
LOG_F(9, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
unsigned sub_addr = (offset >> 12) & 0x7F;
switch (sub_addr) {
case 0:
value = mio_ctrl_read(offset, size);
break;
case 8:
value = dma_read(offset & 0x7FFF, size);
break;
case 0x10: // SCSI
value = this->mesh->read((offset >> 4) & 0xF);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
value = this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
break;
}
if ((offset & 0xFF) < 0x60) {
value = 0;
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
break;
}
// fallthrough
case 0x13: // ESCC MacRISC addressing
value = this->escc->read((offset >> 4) & 0xF);
break;
case 0x14:
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size);
break;
case 0x15: // SWIM3
value = this->swim3->read((offset >> 4) & 0xF);
break;
case 0x16: // VIA-CUDA
case 0x17:
value = this->viacuda->read((offset >> 9) & 0xF);
break;
case 0x20: // IDE 0
value = this->ide_0->read((offset >> 4) & 0x1F, size);
break;
default:
if (sub_addr >= 0x60) {
value = this->nvram->read_byte((offset - 0x60000) >> 4);
} else {
value = 0;
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
}
}
return value;
}
void OHare::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
LOG_F(9, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
unsigned sub_addr = (offset >> 12) & 0x7F;
switch (sub_addr) {
case 0:
this->mio_ctrl_write(offset, value, size);
break;
case 8:
this->dma_write(offset & 0x7FFF, value, size);
break;
case 0x10: // SCSI
this->mesh->write((offset >> 4) & 0xF, value);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
break;
}
if ((offset & 0xFF) < 0x60) {
LOG_F(ERROR, "%s: SCC write @%x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
break;
}
// fallthrough
case 0x13: // ESCC MacRISC addressing
this->escc->write((offset >> 4) & 0xF, value);
break;
case 0x14:
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size);
break;
case 0x15: // SWIM3
this->swim3->write((offset >> 4) & 0xF, value);
break;
case 0x16: // VIA-CUDA
case 0x17:
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 0x20: // IDE 0
this->ide_0->write((offset >> 4) & 0x1F, value, size);
break;
default:
if (sub_addr >= 0x60) {
this->nvram->write_byte((offset - 0x60000) >> 4, value);
} else {
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
}
}
}
uint32_t OHare::mio_ctrl_read(uint32_t offset, int size) {
uint32_t value;
switch (offset & 0xFC) {
case MIO_INT_EVENTS1:
value = this->int_events;
break;
case MIO_INT_MASK1:
value = this->int_mask;
break;
case MIO_INT_LEVELS1:
value = this->int_levels;
break;
case MIO_OHARE_ID: // FIXME: HACK: no clue what this register is supposed to contain
value = ~0x00004000; // 1<<14
LOG_F(ERROR, "%s: read OHARE_ID @%02x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
case MIO_OHARE_FEAT_CTRL:
value = this->feat_ctrl;
LOG_F(WARNING, "%s: read FEAT_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
default:
value = 0;
LOG_F(WARNING, "%s: read @%02x.%c",
this->get_name().c_str(), offset, SIZE_ARG(size));
}
return BYTESWAP_32(value);
}
void OHare::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset) {
case MIO_INT_MASK1:
this->int_mask = BYTESWAP_32(value);
LOG_F(INTERRUPT, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
this->signal_cpu_int();
break;
case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events = 0;
} else {
this->int_events &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
}
clear_cpu_int();
break;
case MIO_INT_LEVELS1:
LOG_F(INTERRUPT, "%s: write INT_LEVELS1 @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value); // writing 0x100000 happens often
break;
case MIO_OHARE_ID:
LOG_F(ERROR, "%s: write OHARE_ID @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(WARNING, "%s: write FEAT_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
this->feature_control(BYTESWAP_32(value));
break;
default:
LOG_F(WARNING, "%s: write @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
}
}
uint32_t OHare::dma_read(uint32_t offset, int size)
{
uint32_t value;
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma)
value = this->mesh_dma->reg_read(offset & 0xFF, size);
else
value = 0;
break;
case MIO_OHARE_DMA_FLOPPY:
value = this->floppy_dma->reg_read(offset & 0xFF, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
value = this->snd_out_dma->reg_read(offset & 0xFF, size);
break;
default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
return 0;
}
value = 0;
}
return value;
}
void OHare::dma_write(uint32_t offset, uint32_t value, int size)
{
int dma_channel = offset >> 8;
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_FLOPPY:
this->floppy_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
default:
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
unsupported_dma_channel_write |= (1 << dma_channel);
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
}
}
}
void OHare::feature_control(const uint32_t value)
{
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
this->feat_ctrl = value;
if (!(this->feat_ctrl & 1)) {
LOG_F(9, "%s: Monitor sense enabled", this->get_name().c_str());
} else {
LOG_F(9, "%s: Monitor sense disabled", this->get_name().c_str());
}
}
#define INT_TO_IRQ_ID(intx) (1 << intx)
uint64_t OHare::register_dev_int(IntSrc src_id)
{
switch (src_id) {
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D);
// case IntSrc::IDE1 : return INT_TO_IRQ_ID(0x0E);
case IntSrc::SCCA : return INT_TO_IRQ_ID(0x0F);
case IntSrc::SCCB : return INT_TO_IRQ_ID(0x10);
case IntSrc::DAVBUS : return INT_TO_IRQ_ID(0x11);
case IntSrc::VIA_CUDA : return INT_TO_IRQ_ID(0x12);
case IntSrc::SWIM3 : return INT_TO_IRQ_ID(0x13);
// case IntSrc::NMI : return INT_TO_IRQ_ID(0x14);
// case IntSrc::EXT1 : return INT_TO_IRQ_ID(0x15);
case IntSrc::BANDIT1 : return INT_TO_IRQ_ID(0x16);
case IntSrc::PCI_E : return INT_TO_IRQ_ID(0x16); // same interrupt as bandit
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
case IntSrc::PCI_F : return INT_TO_IRQ_ID(0x18);
case IntSrc::PCI_B : return INT_TO_IRQ_ID(0x19);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1A);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1B);
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x1C);
default:
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
uint64_t OHare::register_dma_int(IntSrc src_id)
{
switch (src_id) {
case IntSrc::DMA_SCSI_MESH: return INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02);
//
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx: return INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx: return INT_TO_IRQ_ID(0x09);
default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
void OHare::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
{
// native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions
#if 0
LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
);
#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= (uint32_t)irq_id;
} else {
this->int_events &= ~(uint32_t)irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels |= (uint32_t)irq_id;
} else {
this->int_levels &= ~(uint32_t)irq_id;
}
this->signal_cpu_int();
}
void OHare::ack_int(uint64_t irq_id, uint8_t irq_line_state)
{
this->ack_int_common(irq_id, irq_line_state);
}
void OHare::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state)
{
this->ack_int_common(irq_id, irq_line_state);
}
void OHare::signal_cpu_int() {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
} else {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
}
}
}
void OHare::clear_cpu_int()
{
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
}
}
static const std::vector<std::string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0"
};
static const DeviceDescription OHare_Descriptor = {
OHare::create, OHare_Subdevices, {
}};
REGISTER_DEVICE(OHare, OHare_Descriptor);
+1 -1
View File
@@ -172,7 +172,7 @@ int AspenCtrl::map_phys_ram() {
}
static const DeviceDescription Aspen_Descriptor = {
AspenCtrl::create, {}, {}
AspenCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
};
REGISTER_DEVICE(Aspen, Aspen_Descriptor);
+1 -1
View File
@@ -170,7 +170,7 @@ void HammerheadCtrl::map_phys_ram()
}
static const DeviceDescription Hammerhead_Descriptor = {
HammerheadCtrl::create, {}, {}
HammerheadCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
};
REGISTER_DEVICE(Hammerhead, Hammerhead_Descriptor);
+4 -4
View File
@@ -101,7 +101,7 @@ namespace Hammerhead {
BANK_25_BASE_LSB = 0x4F0,
};
}; // namespace Hammerhead
} // namespace Hammerhead
class HammerheadCtrl : public MemCtrlBase, public MMIODevice {
public:
@@ -118,15 +118,15 @@ public:
void set_motherboard_id(const uint8_t val) {
this->mb_id = val & 7;
};
}
void set_rom_type(const uint8_t val) {
this->rom_type = val & 1;
};
}
void set_bus_speed(const uint8_t val) {
this->bus_speed = val & 7;
};
}
void insert_ram_dimm(int slot_num, uint32_t capacity);
void map_phys_ram();
+1 -1
View File
@@ -205,7 +205,7 @@ int HMC::install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_
}
static const DeviceDescription Hmc_Descriptor = {
HMC::create, {}, {}
HMC::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
};
REGISTER_DEVICE(HMC, Hmc_Descriptor);
+24 -1
View File
@@ -40,11 +40,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/* Control register bit definitions. */
enum {
HMC_CTRL_BITS = 35, // width of the HMC control register
HMC_CSIZ = 0, // Cache size inputs
HMC_WBRST = 2, // Write-buffer burst clocks
HMC_WINIT = 3, // Write-buffer initial clocks
HMC_RCASD = 4, // Read CAS duration
HMC_RASP = 6, // RAS pre-charge clocks
HMC_RASD = 8, // RAS duration
HMC_RDAC = 12, // Read data access clocks
HMC_WCASD = 14, // Write CAS duration
HMC_WCASP = 15, // Write CAS pre-charge
HMC_RFSH = 16, // Refresh period
HMC_ROMD = 22, // ROM cycle duration
HMC_NBLROM = 24, // Nibble ROM
HMC_L2_ROMW = 25, // L2 Cache update on ROM write
HMC_L2_BRST = 26, // L2 Cache burst clocks
HMC_L2_EN = 27, // L2 Cache enable
HMC_L2_INST = 28, // L2 Cache instruction only
HMC_SIZE = 29, // RAM size
HMC_MB_RAM = 31, // Motherboard RAM
HMC_VTST = 32, // Video test
HMC_VBASE = 33, // Video Base
HMC_L2_INIT = 34, // L2 initial access
HMC_RAM_CFG_POS = 29, // DRAM configuration bits position
HMC_VBASE_BIT = 33, // framebuffer base address: 0 - 0x00100000, 1 - 0x0
};
/* Motherboard RAM size constans. */
/* Motherboard RAM size constants. */
enum {
BANK_CFG_128MB = 0, // 12 x 12 address maxtrix (reset config)
BANK_CFG_2MB = 1, // 9 x 9 address maxtrix
+4 -4
View File
@@ -48,22 +48,22 @@ static std::string get_type_str(uint32_t type) {
if (str.length())
str += ",";
str += "ROM";
};
}
if (type & RT_RAM) {
if (str.length())
str += ",";
str += "RAM";
};
}
if (type & RT_MMIO) {
if (str.length())
str += ",";
str += "MMIO";
};
}
if (type & RT_MIRROR) {
if (str.length())
str += ",";
str += "MIRROR";
};
}
return str;
}
+4 -3
View File
@@ -317,14 +317,15 @@ static const PropMap Grackle_Properties = {
new StrProperty("")},
{"pci_C1",
new StrProperty("")},
{"pci_GPU",
new StrProperty("")},
//{"pci_GPU",
// new StrProperty("")},
{"pci_J12",
new StrProperty("")},
};
static const DeviceDescription Grackle_Descriptor = {
MPC106::create, {}, Grackle_Properties
MPC106::create, {}, Grackle_Properties,
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
REGISTER_DEVICE(Grackle, Grackle_Descriptor);
+4 -4
View File
@@ -86,7 +86,7 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
int PlatinumCtrl::device_postinit() {
// attach IOBus Device #2 0xF301B000 ; register DACula with the I/O controller
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentral"));
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentralCatalyst"));
gc_obj->attach_iodevice(1, this->dacula.get());
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
@@ -519,12 +519,12 @@ void PlatinumCtrl::enable_display() {
break;
case 16:
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
this->convert_frame_15bpp_BE(dst_buf, dst_pitch);
this->convert_frame_15bpp<BE>(dst_buf, dst_pitch);
};
break;
case 32:
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
this->convert_frame_32bpp_BE(dst_buf, dst_pitch);
this->convert_frame_32bpp<BE>(dst_buf, dst_pitch);
};
break;
default:
@@ -618,7 +618,7 @@ static const PropMap Platinum_Properties = {
};
static const DeviceDescription Platinum_Descriptor = {
PlatinumCtrl::create, {}, Platinum_Properties
PlatinumCtrl::create, {}, Platinum_Properties, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
};
REGISTER_DEVICE(Platinum, Platinum_Descriptor);
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -295,7 +295,7 @@ enum {
constexpr auto VRAM_REGION_BASE = 0xF1000000UL;
constexpr auto PLATINUM_IOREG_BASE = 0xF8000000UL;
}; // namespace Platinum
} // namespace Platinum
class PlatinumCtrl : public MemCtrlBase, public VideoCtrlBase, public MMIODevice {
public:
@@ -307,11 +307,11 @@ public:
}
// HWComponent methods
int device_postinit();
int device_postinit() override;
// MMIODevice methods
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);
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
void insert_ram_dimm(int slot_num, uint32_t capacity);
void map_phys_ram();
+57 -12
View File
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <string>
#include <algorithm>
PsxCtrl::PsxCtrl(int bridge_num, std::string name)
{
@@ -75,12 +76,15 @@ void PsxCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int siz
case PsxReg::Flash_Config:
this->flash_cfg = value;
break;
case PsxReg::Page1_Mapping:
case PsxReg::Page2_Mapping:
case PsxReg::Page3_Mapping:
case PsxReg::Page4_Mapping:
case PsxReg::Page5_Mapping:
this->pages_cfg[(offset >> 3) - PsxReg::Page1_Mapping] = value;
case PsxReg::Page_Mappings_1:
case PsxReg::Page_Mappings_2:
case PsxReg::Page_Mappings_3:
case PsxReg::Page_Mappings_4:
case PsxReg::Page_Mappings_5:
LOG_F(INFO, "PSX: write Page Mappings %d @%02x.%c = %0*x",
(offset >> 3) - PsxReg::Page_Mappings_1 + 1, offset, SIZE_ARG(size), size * 2, value);
this->pages_cfg[(offset >> 3) - PsxReg::Page_Mappings_1] = value;
this->map_phys_ram();
break;
default:
LOG_F(WARNING, "PSX: write to unsupported/read-only control register at 0x%X", offset);
@@ -96,12 +100,15 @@ void PsxCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
switch (capacity) {
case 0:
break;
case DRAM_CAP_2MB:
case DRAM_CAP_4MB:
case DRAM_CAP_8MB:
case DRAM_CAP_16MB:
case DRAM_CAP_32MB:
this->bank_sizes[slot_num] = capacity;
this->bank_size[slot_num] = capacity;
break;
case DRAM_CAP_64MB:
this->bank_size[slot_num + 0] = capacity / 2;
this->bank_size[slot_num + 1] = capacity / 2;
break;
default:
ABORT_F("PSX: unsupported DRAM capacity %d", capacity);
@@ -111,18 +118,56 @@ void PsxCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
void PsxCtrl::map_phys_ram()
{
uint32_t total_ram = 0;
uint32_t bank_size_remaining[5];
for (int i = 0; i < 5; i++) {
total_ram += this->bank_sizes[i];
bank_size_remaining[i] = this->bank_size[i];
total_ram += this->bank_size[i];
}
if (!add_ram_region(0x00000000, total_ram)) {
ABORT_F("PSX: could not allocate RAM storage");
if (!this->dram_ptr) {
this->dram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[total_ram]()); /* () intializer clears the memory to zero */
if (!this->dram_ptr) {
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
}
}
ram_map.erase(std::remove_if(ram_map.begin(), ram_map.end(),
[this](AddressMapEntry *entry) {
delete this->remove_region(entry);
return true;
}
), ram_map.end());
uint32_t ram_offset = -1;
uint32_t mem_start = 0;
for (int page = 0; page < 41; page++) {
int bank = page >= 40 ? 8 : (this->pages_cfg[page / 8] >> ((page % 8) * 4)) & 15;
//LOG_F(INFO, "page:%02d bank:%d", page, bank);
if ((ram_offset == -1) == (bank < 5 && bank_size_remaining[bank] > 0)) {
if (ram_offset == -1) {
ram_offset = page * DRAM_CAP_4MB;
//LOG_F(INFO, "ram_offset:%08x", ram_offset);
} else {
uint32_t mem_size = page * DRAM_CAP_4MB - ram_offset;
AddressMapEntry *entry = this->add_ram_region(ram_offset, mem_size, &dram_ptr[mem_start]);
mem_start += mem_size;
ram_offset = -1;
if (entry) {
ram_map.push_back(entry);
} else {
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
}
}
}
if (ram_offset != -1) {
bank_size_remaining[bank] -= DRAM_CAP_4MB;
}
}
}
static const DeviceDescription Psx_Descriptor = {
PsxCtrl::create, {}, {}
PsxCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
};
REGISTER_DEVICE(Psx, Psx_Descriptor);
Loaded 100 of 161 files, more files were not shown because too many files have changed in this diff. Show more