Compare commits

..
370 Commits
Author SHA1 Message Date
dingusdev af055e0519 Manual tweaks 2025-05-04 17:40:48 -07:00
joevt f2f048d435 hostevents: Fix mouse grab for multiple displays.
Create a mouse grab toggle event to toggle the mouse grab using the current window. After the toggle event is transmitted, transmit a mouse grab changed event so that all windows can update their title.
2025-05-03 06:04:07 -07:00
joevt a62a1dcd09 machinebondi: Grackle machines use separate banks.
For the set of grackle machines, you can change the machine argument without having to change the ram bank sizes arguments.
For example, all grackle machines can specify 1 GiB using two 512 MiB ram banks.
2025-05-01 06:53:04 -07:00
joevt 74da4e148d debugger: Ensure cout fill changes back to right. 2025-04-29 06:31:15 -07:00
joevt c0cd18323e profiler: Ensure cout fill changes back to right. 2025-04-29 06:30:19 -07:00
joevt b848ea2300 ofnvram: Explicitly set cout fill direction. 2025-04-28 19:40:03 -07:00
joevt f9f77f78a8 ofnvram: Set cout fill direction back to right. 2025-04-28 19:39:55 -07:00
joevt f7b88cf5ee machinefactory: Set cout fill to right.
Always set the fill direction explicitly in case someone set it to left elsewhere.
2025-04-28 07:05:32 -07:00
joevt 72dbafdb3f debugger: Format 68K register dump.
Fix alignment and use 8 hex digits for each register.
2025-04-28 07:00:57 -07:00
joevt f55d5c9002 debugger: Use FILENO defines. 2025-04-28 15:05:40 +02:00
dingusdev 65d414bd4e Fixing compile issues 2025-04-28 15:05:40 +02:00
joevt fa5e8b0bf8 amic: Return random value for SCC DMA Rcv.
This allows Mac OS 8.5 and Mac OS 8.5.1 to boot from SCSI of Power Mac 6100.
2025-04-28 15:05:40 +02:00
joevt b05dec8778 viacuda: Add some memory address notes.
These are registers used during boot of Mac OS 8.5 from SCSI on Power Mac 6100.
2025-04-27 09:27:02 -07:00
joevt 24a18f7769 amic: Define local variable in minimum scope. 2025-04-27 07:33:30 -07:00
joevt a74ad4b1d1 amic: Add some register notes.
These are registers used during boot of Mac OS 8.5 from SCSI.
2025-04-27 07:32:33 -07:00
joevt 6c430b7d83 poweropcodes: Use ROTR_32 where possible. 2025-04-24 19:16:43 -07:00
dingusdev 2ce4e13170 ROTL_32 header fixes 2025-04-24 06:36:11 -07:00
joevt 746f461c5b ppcopcodes: Use ROTL_32 where possible. 2025-04-24 06:34:52 -07:00
joevt 00be8ce606 display: Fix update_mouse_grab.
Need to ungrab the mouse to move it.
2025-04-24 06:34:18 -07:00
joevt a1f15228fd display: Fix Visual Studio compiler warnings. 2025-04-24 06:34:04 -07:00
joevt 16762ab9e3 bitops: Handle rotate count 0. 2025-04-24 06:33:54 -07:00
joevt 28c497e455 bitops: Spelling. 2025-04-24 06:33:31 -07:00
joevt 5b3043c372 ppcfpopcodes: Remove redundant expression. 2025-04-24 06:33:22 -07:00
joevt 0019681be4 Properly merge "display: Remove resizing flag." 2025-04-23 21:12:03 -07:00
dingusdev c1ed416b58 Revert "display: Remove resizing flag."
This reverts commit c781ba8fab.
2025-04-23 21:08:45 -07:00
joevt 72ef266d07 display: Update grabbed mouse when resizing.
If the window's size is reduced such that the grabbed mouse is no longer inside the window, then a mouse click will go to another app. Therefore, check the mouse position and update if necessary every time the window changes size.
2025-04-23 06:56:25 -07:00
joevt c781ba8fab display: Remove resizing flag.
It doesn't do anything useful yet and setting the resizing flag to true stops updates if the window doesn't actually change size.
2025-04-23 06:50:24 -07:00
joevt c6013f076a ppcmmu: Fix DMA for adjacent cross region ranges.
If a DMA range extends beyond the end of a region into a second region of the same type (either RAM or ROM), and the regions are adjacent in both the guest and host address spaces, then allow the DMA to proceed.
2025-04-23 06:32:28 -07:00
joevt 9c6a7de45f ppcopcodes: Remove unnecessary type casts. 2025-04-23 06:15:38 -07:00
joevt 47c66666bb display: Add zoom and fullscreen no letterbox.
Added a third full screen mode which removes letterbox or pillarbox black bars.
Added Control-- and control-+ to decrease or increase the scale by a factor of 2^(1/8). This means the scale doubles or halves after pressing the same key 8 times.

drawable_w and drawable_h are floating point so that scaling is reversible (i.e. scaling from 100% to 800% and back to 100% gives 100% instead of 99 or 101%).
default_scale_x

Handle switching host resolution between Retina (HiDPI) and Low resolution modes. This involves updating the window scale factor.

Add window scale factor to window title.
2025-04-22 06:36:04 -07:00
dingusdevandlefp 534d092bd5 Quick fix for Alacritty support
Co-Authored-By: lefp <[email protected]>
2025-04-21 18:28:03 -07:00
dingusdevandBen Boeckel 4d0904667c loguru: use iscntrl to test for control characters
Snatching a pull request from Loguru

Co-Authored-By: Ben Boeckel <[email protected]>
2025-04-21 18:23:50 -07:00
joevt e82d9d1522 Add Full Screen modes.
A display begins in Windowed mode.
1) Press Control-F once to use full screen mode with integer scaling. If this mode is the same size as full screen mode then it is skipped.
2) Press Control-F again to use full screen mode. Smooth Scaling should be used for this mode if the scaling is not integer. Look at the Mac OS 7/8/9 window stripes to see the problem.
3) Press Control-F a third time to get back to windowed mode.

Fixed a bug where Control-S (Toggle Smooth Scaling mode) did not immediately update the display.

These keys only affect the current display.
2025-04-19 05:38:37 -07:00
joevt e64cf73543 manual: Minor edits. 2025-04-19 05:35:37 -07:00
dingusdev 88b5b2ec66 Prep for Alpha 1.0.3 2025-04-18 21:22:19 -07:00
joevt 1340fbedb8 hostevends_sdl: Check all modifier keys.
When checking if certain modifier keys are being pressed, also make sure that all other modifier keys are not being pressed.
2025-04-18 18:51:47 -07:00
joevt 36c7c807a4 display: Add update_window_title and window event.
update_window_title can be used to update statistics about the display (such as display resolution) or about DingusPPC in general (such as "mouse grabbed" status).

A DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED window event is added so that Display::handle_events can update the "mouse grabbed" indicator in each display window. The event handler doesn't check the window ID because the status should be reflected in all windows.

The SDL_WINDOWEVENT_SIZE_CHANGED event causes the window to update the display resolution indicator.

In the future, we might add indicators for HD and CD and floppy disk activity, etc. They will be handled by a window event handler or a general DPPC event handler.
2025-04-18 07:20:49 -07:00
Rairii 61a8402f84 hostevents_sdl: Ralt+delete to ctrl+alt+del.
"Right Option + Forward Delete" is translated to "Control + Right Option + Backspace".
2025-04-18 07:20:46 -07:00
Maxim Poliakovski d315624d54 ppcopcodes: refactor rfi to reduce code duplication. 2025-04-16 00:58:27 +02:00
joevt ec6fa9360c ppcopcodes: Cleanup ppc_rfi.
Reduce the number of operations by 1
and make more clear what is happening.
2025-04-16 00:51:13 +02:00
joevt 0fe6ffeb6f ppcemu: reformat and extend MSR enum. 2025-04-15 18:52:52 +02:00
joevt 2f8e8bf68b videoctrl: Spelling. 2025-04-14 06:40:57 -07:00
joevt a5e2adefa9 atimach64gx: Add RGB 514 read and CLUT_ADDR_RD. 2025-04-14 06:27:46 -07:00
joevt 16542a09f5 atimach64gx: Add rgb514_write_reg logging. 2025-04-14 06:22:50 -07:00
joevt fa865a79fc memctrlbase: Log mirror range.
Because it may differ from the range of the region it points to.
2025-04-14 06:06:42 -07:00
joevt fa7fb5bb1f hammerhead: Define some bits.
From xnu-344/osfmk/ppc/POWERMAC/mp/MPPlugIn.h
2025-04-12 10:20:54 -07:00
joevt 0899d84019 hammerhead: Cleanup.
Replace all occurrences of offset >> 1 with bank.
2025-04-12 08:38:38 -07:00
joevt 3e88c161c1 platinum: Fix PAL/NTSC interlaced display. 2025-04-12 08:38:36 -07:00
joevt 2253e6c595 platinum: Remove spaces. 2025-04-12 08:38:35 -07:00
joevt 86a09a9d3c platinum: Add RAM. 2025-04-12 08:38:33 -07:00
joevt 71990129f3 memctrlbase: Remove region by entry. 2025-04-12 08:38:32 -07:00
Maxim Poliakovski ab8abf39cc amic: remove deprecated SCSI DMA code. 2025-04-11 19:24:56 +02:00
Maxim Poliakovski 8c84b78804 sc53c94: fix bus reset interrupt generation. 2025-04-11 19:24:56 +02:00
Maxim Poliakovski 4312450b70 sc53c94: preliminary support for CMD_XFER_PAD_BYTES.
MkLinux uses this command during synchronous transfer
negotiation.
2025-04-11 19:24:56 +02:00
Maxim Poliakovski a75d806108 Better support for SCSI messages. 2025-04-11 19:19:38 +02:00
Maxim Poliakovski 2a830154f9 sc53c94: implement CMD_SELECT_WITH_ATN_AND_STOP command. 2025-04-11 19:07:35 +02:00
Maxim Poliakovski 89d5196e8b sc53c94: implement CMD_RESET_ATN command. 2025-04-11 19:07:35 +02:00
Maxim Poliakovski 842d0f7f70 sc53c94: improve CMD_MSG_ACCEPTED. 2025-04-11 19:04:47 +02:00
Maxim Poliakovski 23ea02b47c sc53c94: replace some magic numbers with constants. 2025-04-11 19:04:47 +02:00
Maxim Poliakovski 5bd1071d10 scsihd: add support for START_STOP_UNIT.
MkLinux won't boot if this command fails.
2025-04-11 19:04:47 +02:00
Rairii be59ed8304 atapicdrom: Postpone data out phase. 2025-04-09 22:01:15 -07:00
Rairii e4dedb8c09 atapicdrom: Error if read while xfer in progress. 2025-04-09 22:01:06 -07:00
Rairii 17f2562d13 atapicdrom: Short circuit zero length reads. 2025-04-09 21:56:48 -07:00
Rairii 6adce6b120 atapibasedevice: Extra steps when reading STATUS. 2025-04-09 21:56:46 -07:00
Rairii aec5aba379 blockstoragedevice: Use 64-bit math. 2025-04-09 21:56:45 -07:00
Rairii f40ce18bc5 atabasedevice: Postpone data ready signal. 2025-04-09 21:56:44 -07:00
Rairii e4f0588b56 atabasedevice: Postpone write complete interrupt. 2025-04-09 21:56:43 -07:00
Rairii 7ab54276ad atabasedevice: Postpone read complete interrupt. 2025-04-09 21:56:42 -07:00
Rairii 630755f9e5 atabasedevice: Include timermanager. 2025-04-09 21:56:39 -07:00
Maxim Poliakovski 0efab12699 Rename ScsiMsg to avoid ambiguity. 2025-04-09 13:28:15 +02:00
joevt b280da81bc ppc: Timing calculation changes.
Note: all timings are relative to virtual time which is 16 ns per instruction. 8 ns per instruction is too fast for the PDM 'mach' gestalt calculation in firmware.

- For MPC601, bit 7 of RTC and DEC changes at 7.8336 MHz so bit 0 would change at 1.0027008 GHz. Therefore multiply time base frequency by 128. For MPC601, DEC now changes at 1.0027008 GHz instead of 7.8336 MHz.
- Add tbr_freq_shift for cases where time base frequency exceeds 1GHz.
- Change calc_rtcl_value to use time base frequency. For MPC601, RTC now changes at 1.0027008 GHz instead 1GHz.
- For MPC601, the 7 least significant bits of DEC are not implemented so make them not getable or setable.
2025-04-08 19:46:48 -07:00
joevt 6363eef32f ppcexec: Make opcode macros depend on OPr. 2025-04-08 19:46:20 -07:00
joevt 2b4962d1ba sc53c94: Add "this" for class members. 2025-04-05 19:06:41 -07:00
joevt d66c2a39a3 athens: Change pixel clock default.
It should not be 0 MHz because that causes the virtual display to freeze.
Default to 50 MHz so that 800x600 72Hz can work for "control" video output.
2025-04-05 18:59:59 -07:00
Maxim Poliakovski fe304d9f46 sc53c94: support Synchronous Transfer Period register. 2025-04-05 13:11:06 +02:00
joevt 081e0f0576 machinegossamer: Define default GPU property.
Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:29 -07:00
joevt a628d8aa5d machinegazelle: Remove cdr_config property.
cdr_config is for IDE buses. Power Mac 6500 has SCSI CD-ROM.

Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:25 -07:00
joevt b2bff25cc2 machinebondi: Remove AtiMach64Gx.
Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:22 -07:00
joevt 3940080f78 main: Support empty properties.
For example, to remove the GPU of a Gossamer machine, use --pci_GPU=

Continuation of commit "Define default GPU PCI device property value."
2025-04-04 20:52:19 -07:00
joevt 28c50a2018 hostevents: Spaces. 2025-04-04 20:52:05 -07:00
Maxim Poliakovski 3e3eee7ae9 pdmonboard: check framebuffer location on video refresh.
That fixes video for MkLinux.
2025-04-04 18:09:11 +02:00
joevt 41aa8b73e9 cmake: Add USB and FireWire directories. 2025-04-04 06:58:50 -07:00
dingusdev 556d00116f Fixed compile 2025-04-04 06:52:16 -07:00
joevt f4d40ae26b Define default GPU PCI device property value. 2025-04-04 06:49:21 -07:00
Rairii ca55defc55 atabasedevice: Don't attempt command while busy. 2025-04-04 06:40:33 -07:00
joevt 43f5b56033 machineyosemite: Add 512 MB DIMM option.
The max RAM is still 1 GB.
2025-04-04 06:33:22 -07:00
joevt 8484e52407 machinegossamer: Increase max RAM to 1 GB.
Two 512 MB DIMMs gives the max 1 GB of RAM.
2025-04-04 06:33:12 -07:00
joevt 1565d21176 mpc106: Handle overlapping banks. 2025-04-04 06:27:32 -07:00
joevt 986fc22fd4 mpc106: Fix RAM allocation again.
For greater than 4 banks.
2025-04-04 06:27:13 -07:00
joevt 1046baf11d spdram: Add 8 MB DIMMs. 2025-04-03 18:16:44 -07:00
Rairii c4906d1f15 spdram: Add 16 MB DIMMs. 2025-04-03 18:16:38 -07:00
joevt a5dc3bceb9 atirage: Allow up to 8MB of VRAM.
8MB of VRAM is required for 32-bit color at 1600x1200 or 1920x1080. See imacg3 with AtiRagePro.
2025-04-03 07:56:12 -07:00
joevt 3bab9b6f52 endianswap: Convert tabs to spaces. 2025-04-03 07:42:30 -07:00
joevt 25beb13b1b sc53c94: Remove extra space. 2025-04-03 07:42:08 -07:00
joevt 99c06e8690 machinebondi: Increase max RAM to 1 GB. 2025-04-03 07:40:30 -07:00
joevt c483a9a615 spdram: Add 512 MB DIMMs. 2025-04-03 07:40:20 -07:00
joevt 4b25da926b sixty6: Default pixel depth should be 8.
At least in one case I tested.
2025-04-02 07:31:47 -07:00
joevt 06a9e338a9 machinegazelle: Add a default GPU. 2025-04-02 07:12:27 -07:00
joevt 26db2caadd Move ControlVideo to Chaos. 2025-04-02 07:11:26 -07:00
Maxim Poliakovski ff6d75f232 sc53c94: remove unused code. 2025-04-01 16:04:18 +02:00
Maxim Poliakovski f6f11e81e9 Switch AMIC SCSI DMA to the new DMA API. 2025-04-01 04:02:51 +02:00
Maxim Poliakovski c742beb623 sc53c94: return actual number of bytes transferred
in xfer_to and xfer_from methods.
2025-04-01 04:02:51 +02:00
Maxim Poliakovski ba030abb3b scsihd: don't return error for DEFAULT VALUES in MODE_SENSE_6.
Page control 2 (DEFAULT VALUES) in MODE_SENSE_6 may not fail.
2025-04-01 04:02:51 +02:00
Maxim Poliakovski df5c1758d5 sc53c94: don't generate Bus Service int when asserting DREQ.
Generating Bus Service interrupt while asserting DREQ breaks
the Old SCSI API and the applications that depend on it.
2025-04-01 04:02:14 +02:00
Maxim Poliakovski b5edd8347e dbdma.h: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski ed433c0476 scsibusctrl: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski fb03c214ae sc53c94: add missing 'override'. 2025-04-01 04:02:14 +02:00
Maxim Poliakovski 503c6ea662 sc53c94: fix DMA transfers for BeOS.
Mac OS SCSI Manager starts the DMA engine after issuing
a data transfer command to the controller. The device will
assert REQ, then sit and wait for the DMA engine to transfer
data.
Be OS driver does that in the reverse order: the DMA engine
is initialized first, then the controller is instructed to
transfer data.
This commit adds support for both ways.
2025-04-01 04:01:26 +02:00
Maxim Poliakovski 2d61e4c604 dbdma: implement new DmaChannel methods. 2025-04-01 04:01:26 +02:00
Maxim Poliakovski 03bb03fdd5 dmacore: extend DmaChannel API. 2025-04-01 04:01:26 +02:00
Maxim Poliakovski c10183b58f sc53c94: fix sequence step reporting for BeOS. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski be1b567b84 sc53c94: fix handling of multistep commands. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski 237f983493 sc53c94: correct status register emulation. 2025-04-01 04:00:44 +02:00
Maxim Poliakovski 2a3e46eab4 memctrlbase: overload add_ram_region()
to accept externally allocated memory.
2025-04-01 03:05:46 +02:00
joevt d4d19e880c Update Inquiry methods.
ScsiCdrom has an inquiry method that overloads a method in CdromDrive. Make it so that it's a valid override (not overloaded).
For CdromDrive, allow inquiry method to work with lengths <> 36 like the SCSI versions.
For ScsiHarDisk, the inquiry method is not on override or an overload, but make it like the ScsiCdrom version anyway.
2025-03-30 09:40:05 -07:00
joevt 1166fda3e0 heathrow: Connect mesh. 2025-03-30 07:58:34 -07:00
joevt 8b1d673e10 More documentation fixes. 2025-03-30 07:41:15 -07:00
dingusdev 4ac5fd4cb0 Minute documentation fixes 2025-03-29 10:47:28 -07:00
joevt 6da691fb02 atimach64gx: Change logging. 2025-03-29 10:35:59 -07:00
joevt 8f64d35210 atimach64gx: Fix logging. 2025-03-29 10:35:51 -07:00
joevt 61d73a5b79 atimach64gx: Add register reading methods.
In case they are needed in the future.
2025-03-29 10:30:59 -07:00
joevt 794a345e53 atimach64gx: Add logging for registers.
WRITE_VALUE_AND_LOG logs the value that was written to the register and the result that can be read from the register. Use this if you need to write the register before acting upon the changes to the register and use return instead of break to bypass the default path which also calls WRITE_VALUE_AND_LOG after the switch statement.
2025-03-29 10:25:55 -07:00
joevt 1c54cdd368 atimach64gx: Add logging to crtc_update. 2025-03-29 10:25:45 -07:00
joevt 026d53f275 atimach64gx: Log unmapped aperture region accesses. 2025-03-29 10:14:51 -07:00
joevt ca20de9462 atimach64gx: Log rgb514 indirect register writes. 2025-03-29 10:14:40 -07:00
dingusdev 7893d0add7 More BigMac regs + descriptions 2025-03-29 08:58:19 -07:00
joevt 7f34504259 atimach64gx: Log I/O register accesses. 2025-03-29 07:07:46 -07:00
dingusdev 48fd95e284 Add additional BMAC registers 2025-03-28 21:38:33 -07:00
dingusdevandRairii 15baf9a2a0 Add Bondi (iMac G3)
Co-Authored-By: Rairii <[email protected]>
2025-03-28 18:31:00 -07:00
joevt a0edc825fb macio: Add comment for MIO_OH_FC_IN_USE_LED flag. 2025-03-25 21:44:35 -07:00
joevt 20e7dfb0e1 macio: Log unsupported DMA channels once.
For debugging. No need to spam the log.
2025-03-25 21:39:49 -07:00
joevt 83066bbf5f memctrlbase: Return entry instead of bool. 2025-03-24 07:29:31 -07:00
joevt 637c20e3cf grandcentral: Handle bit-flipping of MAC address.
If the ENET ROM begins with 0x10, then the bits of each byte are flipped 7..0 -> 0..7 which means the MAC address will begin with 0x08.
A MAC address beginning with 0x08 can be bit-flipped or not bit-flipped.
A MAC address cannot begin with 0x10.
I have a `dump-device-tree` output for a Power Mac 9500 with MAC address beginning with 08-00-07 (OUI for "Apple, Inc."). I don't know if it's using the bit-flipped ROM (starting with 10) or not bit-flipped ROM (starting with 08).
Most of the other `dump-device-tree` outputs I've seen have a MAC address beginning with an OUI for "Apple, Inc." that begins with 00.
2025-03-24 06:39:55 -07:00
joevt ba9bbb32c3 Catch all errors for debug read/write methods. 2025-03-23 16:14:31 -07:00
Rairii 60c95231ee atimach64gx: Don't allow pitch to be zero. 2025-03-22 21:00:18 -07:00
dingusdev 130beabf2a Re-insert code for tlbia
BeOS uses this as part of its boot handler.
2025-03-21 18:57:17 -07:00
dingusdev a7170f4956 Removing code for tlbia
Seems to be causing a regression in Mac OS X 10.0
2025-03-21 18:42:56 -07:00
dingusdev 10f087be65 Maintenance on ATI Rage code 2025-03-21 07:52:04 -07:00
joevt 392f6cdcd3 mpc106: Document flash ROM related registers. 2025-03-21 07:30:18 -07:00
joevt e43bb02d9a debugger: Remove unused variable in patch_mem. 2025-03-20 19:31:10 -07:00
dingusdev 341d5470a2 Update cubeb 2025-03-20 19:30:05 -07:00
dingusdev 2b0c932e48 Continued fix-ups, for GCC 2025-03-18 19:00:15 -07:00
dingusdevandAndrew Randrianasulu 35095870b2 Fix some warnings for Loguru
Co-Authored-By: Andrew Randrianasulu <[email protected]>
2025-03-18 18:50:35 -07:00
dingusdev a178d12a80 Attempt to fix MSYS2 compile 2025-03-16 14:31:23 -07:00
dingusdev 43361815d2 Update CREDITS.md 2025-03-16 14:26:40 -07:00
dingusdev ddb3657d89 Merge pull request #140 from mrpapersonic/master
endianswap: use byteswap.h when available, and use inline functions for generic impl
2025-03-16 10:07:38 -07:00
Paper 8ce9abcf22 endianswap: use byteswap.h when available, and use inline functions for generic impl 2025-03-16 12:47:59 -04:00
dingusdev aee50331e9 Merge pull request #139 from mrpapersonic/master
endianswap: fix 64-bit byteswap macro on weird compilers
2025-03-16 07:33:36 -07:00
Paper f784cedc0b endianswap: fix 64-bit byteswap macro on weird compilers 2025-03-15 23:07:29 -04:00
joevt d300a31fa7 swim3: Ensure 32-bit multiply result. 2025-03-15 16:26:31 -07:00
dingusdev 9874aa1dfc Small bit of clean-up for PDM Video 2025-03-14 14:39:54 -07:00
dingusdevandjoevt 08f67c010c Add get_type_str + get_entry+str
Co-Authored-By: joevt <[email protected]>
2025-03-14 10:43:37 -07:00
joevt c3005cede3 debugger: Catch memory errors while disassembling. 2025-03-14 10:40:49 -07:00
joevt cf0d78fe98 debugger: add regions command.
To dump the list of memory regions.
2025-03-14 10:31:57 -07:00
Maxim Poliakovski 8aede43f91 scsidevice: remove dead code. 2025-03-14 17:52:48 +01:00
Maxim Poliakovski a7386a648e macio.h: remove unused class members. 2025-03-14 17:52:48 +01:00
Maxim Poliakovski 69c4d6489d debugger: implement setmem command. 2025-03-14 17:52:48 +01:00
joevt fd4057ea61 debugger: Fix spelling in regs help. 2025-03-13 19:54:16 -07:00
joevt d6a6c4196f debugger: Add blank line to output. 2025-03-13 19:54:02 -07:00
joevt 04dc129c61 debugger: Add restart command. 2025-03-13 19:52:36 -07:00
joevt 98925a39b9 Code clean-up part 2. 2025-03-13 06:14:35 -07:00
dingusdev 77503df677 Code clean-up 2025-03-12 07:58:32 -07:00
dingusdev 0146e1a1cc Revert "swim3: Rename int_drive and fix mode change."
This reverts commit de4580d07c.
2025-03-10 20:07:17 -07:00
joevt de4580d07c swim3: Rename int_drive and fix mode change.
Rename int_drive to drive_1 or selected_drive which is selected by a new mode_change method.

mode_change fixes some logic issues with the original code with regards to changes to SWIM3_GO and SWIM3_GO_STEP bits.
2025-03-10 19:57:21 -07:00
joevt 54db971610 debugger: Regs lower case, indent, justify. 2025-03-10 18:55:43 -07:00
joevtandjoevt eef2190e08 Add more spacing for Debugger help
Co-Authored-By: joevt <[email protected]>
2025-03-10 18:45:17 -07:00
joevt 470f4a115a debugger: Fix fregs help alignment. 2025-03-10 18:10:35 -07:00
joevt 6c4e97deac adbmouse: Move handler 1 check. 2025-03-10 07:58:07 -07:00
joevt 89580103fb adbmouse: Fix bug with 5 or more buttons. 2025-03-10 07:56:55 -07:00
joevt ae605157db debugger: Add fregs command. 2025-03-10 07:15:44 -07:00
Rairii a9e0cd5c5e debugger: Include SRR0 and SRR1 in regs output. 2025-03-10 07:03:26 -07:00
joevt cf0881b843 debugger: Fix compiler warnings. 2025-03-10 07:01:06 -07:00
joevt 6b82e15c14 Use ppc_state instead of get_reg.
Might be a speedup if stepping through a few million instructions.
2025-03-10 06:59:52 -07:00
joevt d2aee8af0f awacs: Fix "Add stubs for missing AWACS regs". 2025-03-10 06:51:01 -07:00
joevt 3da972ddc9 Add missing this. 2025-03-10 06:49:37 -07:00
dingusdev baa36cf571 Preparing Alpha 1.02 release 2025-03-09 14:36:36 -07:00
joevt ccea8ae8d1 Fix spelling of NuBus. 2025-03-08 18:19:48 -07:00
dingusdev 6664219057 Add stubs for missing AWACS regs 2025-03-08 18:17:46 -07:00
joevt 1453bd2778 main: Fix spelling of Open Firmware. 2025-03-06 06:52:24 -07:00
dingusdev cf7c102b93 Merge pull request #137 from mihaip/upstream-setenv
Add CLI flag to allow setting of OpenFirmware environment variables
2025-03-02 18:49:44 -07:00
Mihai Parparita a6e1b8c338 Add CLI flag to allow setting of OpenFirmware environment variables
Allows enabling of verbose booting via the command-line interface (instead of having to drop into the interactive debugger).
2025-03-02 16:10:01 -08:00
dingusdev 6e74146466 Don't forget to update CR1 in edge case of fdiv 2025-03-02 10:42:31 -07:00
dingusdev a972bd26f7 Corrected handling of MMU Mode 1 2025-03-02 10:41:42 -07:00
dingusdev b09dfa22ec Fix regression in fdiv(s)(.) 2025-03-01 15:18:24 -07:00
joevt f21d2bd4ea imgfile_sdl: Fix write seek and return result. 2025-02-28 18:50:42 -07:00
dingusdev f3dec30c27 Add missing PR bit checks 2025-02-26 20:40:41 -07:00
Maxim Poliakovski bcb453e7ea Named constants for PCI IDs for MacIO ASICs. 2025-02-26 19:31:22 +01:00
joevt 1b2d3d0e6e cmake: Add header files in CMakeLists.txt.
So the Xcode IDE can list and search them.
2025-02-25 07:33:51 -07:00
joevt 744c0d39b5 amic: Make interrupt flags atomic. 2025-02-23 15:35:29 -07:00
joevt b75dd075bc scsibus: Report error without aborting.
Also, use bus name in log messages.
2025-02-23 10:11:54 -07:00
joevt 1b48983bf6 atapicdrom: Rename descriptors. 2025-02-23 09:58:27 -07:00
joevt 9fbb705595 ohare: Restore NVRAM to subdevices.
It was accidentally removed in previous conflict resolution.
2025-02-17 06:03:57 -07:00
joevt 063a9a6859 machinegazelle: Update ohare to heathrow standard.
Add feature_control.
Add Ide0.
Remove Ide1.
Add Mesh.
Remove built-in Ethernet.
Add Swim3.
Implement device and DMA interrupts.
Fill in dma read and write methods.
Add ESCC compatible addressing.
2025-02-16 10:11:42 -07:00
joevt 434ceab25a Use explicit typecast of float to int. 2025-02-16 07:00:15 -07:00
dingusdev a848eb9e76 Fixed accidental removal in ppc_exec_until 2025-02-16 06:35:24 -07:00
joevt eb2253a23a debugger: Output register names as lowercase.
To match the register names in the disassembly.
2025-02-15 17:05:41 -07:00
joevt 50b57b2cc1 debugger: Fix repeating of until command.
It should show the command that is being repeated (including the address) and indicate how many times it was repeated so far.
2025-02-15 17:05:22 -07:00
dingusdev d82d9ac7b9 Added missing header - chrono 2025-02-15 16:02:32 -07:00
joevt 82a48899f0 Change ppc_opcode_grabber to a variable. 2025-02-10 07:01:32 -07:00
joevt 101bb826f1 Make irq_id 64 bits.
- So that DMA and other interrupts can fit without overlap.
- To simplify conversion to interrupt mask.
- To reduce variables, defines, and code.
2025-02-10 06:49:39 -07:00
Rairii 662166d7c6 heathrow: Add Media Bay ID accessor.
So that a machine can override the mb_id.
2025-02-09 16:51:42 -07:00
joevt 7e9bf45f3d scsihd: Fix data_buf size.
This fix will be replaced by having ScsiHardDisk use BlockStorageDevice.
2025-02-08 12:33:47 -07:00
dingusdev 49a97bd487 Added ability to set up keyboard 2025-01-31 17:06:15 -07:00
joevt 2f30395d00 Break long lines.
Make them 130 characters or less.
2025-01-30 06:30:51 -07:00
dingusdev 8de2c9dafc Start i18n 2025-01-29 21:14:36 -07:00
dingusdevandjoevt 66f2c79605 Avoid MSVC compiler bug.
Use define instead of template for pm7500_settings<>

Co-Authored-By: joevt <[email protected]>
2025-01-27 20:53:27 -07:00
dingusdev 1a7ccce774 Merge pull request #136 from mihaip/upstream-nofpu-perf
Mitigate performance impact of respecting FP bit
2025-01-26 05:42:11 -07:00
Mihai Parparita 134339ae9d Mitigate performance impact of respecting FP bit
In #135 we switched from a static OpcodeGrabber table to a
curOpcodeGrabber pointer in ppc_main_opcode. This results in an extra
indirection (as far as generated assembly having an additional load),
which reduces execution speed.

Switch to making the opcode grabber into a parameter to
ppc_main_opcode, and make ppc_exec_inner keep it up to date (via an
EXEF_OPCODE exception flag).

Also fixes FPU instructions in ppctests - we now need to set the FP
MSR bit when initializing the CPU.
2025-01-25 17:58:31 -08:00
dingusdev 7df166a99e Merge pull request #135 from mihaip/upstream-nofpu
Respect FP bit in MSR when running floating point instructions
2025-01-21 06:53:14 -07:00
Mihai Parparita acc6e77ec5 Respect FP bit in MSR when running floating point instructions
Rather than running them normally, they should trigger a "no FPU"
exception. This appears to be required to allow correct graphical
rendering under Mac OS X - the FP bit cleared via mtmsr and rfi
instructions and something else appears to be relying on the exception
to be thrown.

Implemented by maintaining a parallel version of the OpcodeGrabber
table (OpcodeGrabberNoFPU) which contains alternate implementations
for all the floating point instructions. We switch the table whenever
the MSR value changes. This should minimize the overhead of doing
these checks.
2025-01-20 23:19:37 -08:00
joevt 38c4f1e4cc memaccess: Fix comments for some 64 bit macros. 2025-01-14 19:06:28 -07:00
dingusdev a6483fa895 Merge pull request #133 from mihaip/upstream-max-scsi-size
scsi: Check for maximum transfer size
2025-01-08 07:35:07 -07:00
Mihai Parparita 40617692b8 scsi: Check for maximum transfer size
Better to fail immediately than to have a buffer overflow.
2025-01-07 22:52:00 -08:00
Maxim Poliakovski a5ba986666 debugger: set maximal 68k instruction length to 12. 2025-01-06 14:30:13 +01:00
Maxim Poliakovski 497ab52ff0 nubusutils.cpp: break long lines. 2025-01-04 23:00:11 +01:00
joevt 24baf77dba nubusutils: rom_size fixes.
Support 64-bit file size.
Abort if file size > 16 MiB.
Calculate lane expanded memory size using integer arithmetic only.
Allocated memory is rounded to 4096 bytes. This can be adjusted. The lowest rounding of 4 would be "+ 3) / 4 * 4" instead of "+ 4095) / 4096 * 4096".
Abort if ROM size after lane expansion is > 16 MiB.
Expand lanes starting with the last byte instead of the first since the last byte must align with the last used lane of the memory range.
Include ROM image name in exceptions.
2025-01-04 12:27:46 -07:00
Maxim Poliakovski ce245f8885 Move SAA7187 emulator to devices/video 2025-01-03 18:11:57 +01:00
Maxim Poliakovski e508031c98 Move Athens emulator to devices/common/clockgen 2025-01-03 17:47:04 +01:00
Maxim Poliakovski 4ed13cdd04 control: break long lines. 2025-01-02 23:27:23 +01:00
Maxim Poliakovski f31f13f77b Add nubusutils for handling DeclROMs for Nubus/PDS/VDS cards. 2024-12-30 13:04:47 +01:00
joevt e63f928a3c ppcexec: Simplify ppc_exec_inner.
One while loop instead of two.
One call to ppc_read_instruction instead of four.
2024-12-17 19:01:34 -07:00
joevt 7b1ea17fb8 ppcmmu: Fix compiler warning. 2024-12-17 18:46:53 -07:00
dingusdev 240ec95a74 bench1: Set power_off_reason. 2024-12-17 18:46:20 -07:00
joevt ee45291533 superdrive: Make sure track remains in range. 2024-12-17 07:16:13 -07:00
joevt f813aed1ce superdrive: One exit path for status. 2024-12-17 07:11:01 -07:00
joevt a62954d1a7 superdrive: Separate function for set_motor_stat. 2024-12-17 07:10:22 -07:00
joevt 30582cfb05 main: Make realtime and debugger flags exclusive.
Put them in a separate option group named "execution mode" and specify that only one of them can be selected.
CLI11 will handle the error message if the user attempts to set both options.
2024-12-16 07:12:26 -07:00
joevt 355738d42b machinefactory: ROM identification changes.
Read ROM file once.
Identify 68K and New World ROMs.
Improve identification of Old World ROMs.
Perform checksum checks.
Identify the ROM even if the user specifies a machine option.
2024-12-15 18:53:48 -07:00
Maxim Poliakovski 749e296796 scsihd: use legacy vendor name
supported by legacy low-level disk initialization SW.
2024-12-14 22:33:22 +01:00
joevt e4d9cb95b4 ppcexec: Make ppc_exec template functions. 2024-12-14 06:32:07 -07:00
joevt 98c7e224fe ppcmacros: Make rot_sh unsigned. 2024-12-14 06:31:59 -07:00
joevt ac0faf78fd poweropcodes: Fix more compiler warnings. 2024-12-14 06:31:51 -07:00
dingusdev f08554758b Fixed working directory code
Should work on both Windows and Unix systems
2024-12-13 18:32:52 -07:00
dingusdev b302014ee1 Revert "main: Add a working directory option."
This reverts commit 210199db1c.
2024-12-13 08:11:12 -07:00
joevt 210199db1c main: Add a working directory option.
This is an alternative method for specifying the working directory.
Normally, the user would change the directory before executing dingusppc to set the working directory.
The working directory is the default location for files and sockets used by dingusppc (the bootrom file, symbols file, nvram, pram, serial port sockets, logs, etc.)
2024-12-13 08:06:23 -07:00
joevt d48eefceb0 poweropcodes: Remove undefined behavior.
Shift 32 is undefined.
-2^31 - 1 is undefined.
2024-12-12 08:03:47 -07:00
joevt 394fdd00f0 machinegazelle: Support 160 MB RAM. 2024-12-10 18:22:02 -07:00
joevt 78f62c8db8 ppcfpopcodes: Use macros for ppcstate.
Helps with abstraction.
2024-12-10 18:18:32 -07:00
joevt a64b000459 ppcfpopcodes: Remove extra space. 2024-12-10 18:18:23 -07:00
joevt 1da7cb1c2f ppcmacros: Remove semicolon from one line macros. 2024-12-10 18:18:12 -07:00
joevt 49b8c4c39f ppcfpopcodes: Fix Revert Tweak.
Fixes lfsu, lfsux, lfdu, lfdux so they correctly update rA as before.
2024-12-11 00:19:06 +01:00
joevt bf4ee72c0f machinetnt: Chaos is optional.
It's not used for Power Mac 9500/9600.
2024-12-08 12:39:07 -07:00
joevt 3124b10eaa Implement DIMM properties. 2024-12-08 12:26:14 -07:00
dingusdev 47969d9d50 Reverting tweak
Restoring Virtus Player back to 'normal'
2024-12-07 20:49:00 -07:00
dingusdev c0a06a88c7 Merge pull request #132 from mihaip/upstream-volatile
Suppress Clang warnings about `volatile` being deprecated
2024-12-07 16:40:57 -07:00
Mihai Parparita ab5f7071ce Suppress Clang warnings about volatile being deprecated 2024-12-07 15:30:24 -08:00
joevt f42b239713 heathrow: Use mask, not minus, for address decode. 2024-12-07 10:12:01 -07:00
joevt bfc51b8967 heathrow: Add missing this. 2024-12-07 10:04:15 -07:00
joevt 9c66a56a65 heathrow: Replace res with value. 2024-12-07 09:58:55 -07:00
joevt cea889bde5 ppcopcodes: Cleanup lzu lzux lhau lhaux. 2024-12-07 06:34:00 -07:00
joevt 78696aa822 chario: Use "this" for class fields. 2024-12-06 07:25:14 -07:00
joevt 1f8a76e534 escc: Remove unused variable. 2024-12-06 07:22:04 -07:00
dingusdev d22f926a8a Tweak s*u(x) and l*u(x) instructions for 601
These are what the instructions are supposed to do according the 601 manual.
2024-12-06 07:07:36 -07:00
dingusdev 1c95619aa4 Assign ESCC B RCV DMA 2024-12-06 05:47:06 -07:00
dingusdev 81ebc40158 Add ESCC B RCV DMA
Diagnosing issues in booting up Mac OS 9.0.4 for Beige G3
2024-12-04 21:11:47 -07:00
joevt 1bf4073fa7 macio: Range check scc compatible register index.
Also, non-compatible registers don't begin until 0x60 for SCC compatible addressing.
2024-12-04 21:03:09 -07:00
joevt ab59a34604 bandit: Modify address ranges.
- Increase I/O space from 22 bits (4 MB) to 23 bits (8 MB).
- Add Special Cycles and Interrupt Acknowledge Cycles at 14 MB offset.
- Pass Through range at 16 MB offset is 16 MB size. VGA and 24 bit physical addresses can go here.
- Bandit is 32 MB except for pci1 which has GrandCentral at Bandit's 16 MB offset.
2024-12-04 20:47:22 -07:00
dingusdev 31323e7bf1 Fix compiling errors for MON_ID_SENSE (platinum) 2024-12-04 07:48:38 -07:00
joevt 05658ad5c5 platinum: Fix MON_ID_SENSE read/write. 2024-12-04 07:38:53 -07:00
joevt a593a4a73e platinum: Implement VRAM_REFRESH read. 2024-12-04 07:36:59 -07:00
joevt 99972307dc platinum: Implement FB_TEST read/write. 2024-12-04 07:36:48 -07:00
joevt d7fb49166f platinum: Add comments and enums for registers. 2024-12-04 07:16:47 -07:00
joevt 0bca7bc743 platinum: Make some FB_CONFIG_1 bits read only. 2024-12-04 07:16:45 -07:00
dingusdev 10a3fa5984 Tweak logging for main branch 2024-12-04 07:11:43 -07:00
joevt d98929f24c platinum: Registers affect display immediately. 2024-12-04 07:11:07 -07:00
joevt 2ab6a94795 Ignore zero sized DIMM. 2024-12-04 07:10:40 -07:00
joevt 818f982c75 swim3: Create separate reset method.
And set defaults for some class fields.
2024-12-03 18:20:13 -07:00
joevt e72b571069 swim3: Add enums and use them. 2024-12-03 18:19:23 -07:00
dingusdev 2a92ce78f5 Removed unneeded test code
Was trying to see what was causing Mac OS X's menu bar to sag 96 pixels
2024-12-03 07:46:13 -07:00
joevt b512702fbb ppcopcodes: Fix indent in ppc_mtsr. 2024-12-03 06:52:20 -07:00
joevt 47fca9f4ff ppcexec: Fix absolute address comment. 2024-12-03 06:52:09 -07:00
joevt ee8c912397 poweropcodes: Fix clcs for MPC601.
These output values will pass the current set of risu tests which tests all 32 input values multiple times.
2024-12-03 06:51:56 -07:00
joevt 3fd422008e ppcfpopcodes: Use enums instead of literals. 2024-12-03 06:51:15 -07:00
joevt bce4c98475 ppcfpopcodes: Fix fdiv for MPC601. 2024-12-03 06:50:57 -07:00
joevt b45b0a8df4 ppcopcodes: Fix divw for MPC601. 2024-12-03 06:50:17 -07:00
joevt b8af8d387c ppcopcodes: Fix divu for MPC601. 2024-12-03 06:50:08 -07:00
joevt 84075c5988 ppcopcodes: Fix lswx for MPC601. 2024-12-03 06:49:53 -07:00
dingusdev 35919802f3 Tweak fsel
Inspired by a similar fix toxieainc committed for Supermodel
2024-12-03 06:49:08 -07:00
Maxim Poliakovski 6b3a399015 Merge pull request #129 from mihaip/upstream-sdl-revert
Revert unintentional change to imgfile_sdl.cpp
2024-12-03 13:59:26 +01:00
joevt 80b763ecc3 ppcexec: Fix OP59d.
Some of these accept a 4th register "C" so they exist in the opcode table 32 times.
Some of these don't accept a 4th register "C" so they exist in the opcode table once.
2024-12-03 12:12:56 +01:00
Maxim Poliakovski 85d5b10f61 sc53c94: switch to the new DMA API. 2024-12-03 11:37:18 +01:00
Maxim Poliakovski 5057792d4d dbdma: implement xfer_to_device method. 2024-12-03 11:37:18 +01:00
Mihai Parparita a1d945a61f Revert unintentional change to imgfile_sdl.cpp
Did not mean to include this in #127
2024-12-02 22:50:03 -08:00
dingusdev 46425faaa9 Merge pull request #128 from mihaip/upstream-using-namespace
Remove `using namespace std` from remaining header files
2024-12-01 07:01:05 -07:00
Mihai Parparita 4479387580 Remove using namespace std from remaining header files
It's somewhat of an anti-pattern, and can lead to conflicts with
other symbols (e.g. the Windows build failure in https://github.com/dingusdev/dingusppc/actions/runs/11762906342/job/32766290288,
I removed `using namespace std` from timermanager.h to fix that one).
2024-11-30 20:01:09 -08:00
dingusdev f355fb0dfe Merge pull request #127 from mihaip/upstream-opcode-dispatcher
ppc: Use a unified opcode lookup table
2024-11-30 12:51:08 -07:00
Mihai Parparita b759f25d87 ppc: Use a unified opcode lookup table
Instead of a primary opcode lookup table with 64 entries and a few
smaller tables with 4-2048 entries, use a single 64 * 2048 (128K)
entry table to dispatch opcodes.

Helps with performance, since we avoid the function call overhead for
some frequently-used instructions (e.g. branch, integer, floating point).
Saves ~2 seconds from the time to Welcome to Macintosh (same measurement
methodology as #125)

Secondarily also makes opcode registration/decoding a bit more uniform,
and scannable, since it's now all in initialize_ppc_opcode_table.
2024-11-30 20:37:26 +01:00
Maxim Poliakovski f1e56cd353 Make the debugger a global object. 2024-11-30 12:12:32 +01:00
Maxim Poliakovski 04899d6528 dbdma: prevent STOP from updating xferStatus. 2024-11-30 12:12:32 +01:00
Maxim Poliakovski bd7c424989 dmacore: add xfer_to method. 2024-11-30 11:55:16 +01:00
Maxim Poliakovski aa17bf06de ppcmmu: implement mem_write_dbg method. 2024-11-30 11:55:16 +01:00
Maxim Poliakovski 6d2872a07f superdrive: add missing break. 2024-11-30 11:55:16 +01:00
Maxim Poliakovski c12561074c Merge pull request #126 from mihaip/upstream-named-constant
debugger: Use a named constant when we don't have a current instruction
2024-11-29 18:47:25 +01:00
Mihai Parparita bf92b04d6c debugger: Use a named constant when we don't have a current instruction 2024-11-29 18:33:22 +01:00
Maxim Poliakovski 7e93d2d169 scsihd: add missing phase switch to write(). 2024-11-29 17:47:29 +01:00
Rairii 2bb35dc613 pcihost: Add machine check exception.
A machine check exception happens when attempting to read from an unmapped I/O address.
2024-11-29 07:41:57 -07:00
dingusdev 26aa452c57 Fix benchmark compiling, again 2024-11-29 07:41:45 -07:00
joevt 7a55a81186 pcihost: Fix pci_unregister_device.
Remove the device from the hosts dev_map.
Remove the device from the Machine object.
2024-11-29 07:31:23 -07:00
joevt c9359592d7 pcihost: Modify name of attached PCI devices.
In case multiple PCI devices of the same type are added, make sure each has a different name for logging.
2024-11-29 07:31:16 -07:00
dingusdev bf55aa50ce Merge pull request #125 from mihaip/upstream-curr-instruction
ppc: Remove ppc_cur_instruction global variable
2024-11-28 15:59:32 -07:00
Mihai Parparita 564c43c907 Remove ppc_cur_instruction global variable
Replace it wth an explicit opcode parameter that is passed around. That
is both slightly easier to reason about (to trace where it comes from)
and slightly faster, since it can be read from a register.

On my machine takes booting to "Welcome to Macintosh" being output in
a verbose boot of Mac OS X 10.2.8 from 31.8s to 30.6s (average of 5
runs, measured using deterministic mode and looking at when execution
reaches PC 0x90004a88).
2024-11-28 23:41:38 +01:00
Mihai Parparita 31bc6f79e5 Fix instructions for building with tests 2024-11-28 23:25:57 +01:00
Mihai Parparita e4c84c5f80 Reduce frequency of deterministic mode instruction logging
Do as the comment says and log every (logical) second only.
2024-11-28 22:12:43 +01:00
Mihai Parparita 2d90aff408 ppc: Remove unncesessary function declarations
ppc_opcode16 and other functions are only needed in the implementation in
ppcexec.cpp, they don't need to be in the header.

fp_return_double and fp_return_uint64 have no uses (as of 2141a72b87)
can can thus be removed altogether.

Similarly ppc_fpu_off has no uses (as of bb3f4e596e)
and can be removed.
2024-11-28 22:12:16 +01:00
joevt 820da037da ppcmacros: Add missing space. 2024-11-28 07:25:23 -07:00
joevt 00f38133e9 ppcfpopcodes: fnabs fix.
fnabs sets the sign bit regardless of nan status.
2024-11-28 07:25:14 -07:00
joevt e231dc4dec ppcfpopcodes: fabs fix.
fabs clears the sign bit regardless of nan status.
2024-11-28 07:25:06 -07:00
joevt 549cb2284c Revert "Tweaking conditional branch instructions"
This reverts commit 0835e6f9f4.
2024-11-27 08:20:05 -07:00
joevt d41287c320 ppcfpopcodes: fneg fix.
fneg inverts the sign bit regardless of nan status.
2024-11-27 08:06:31 -07:00
joevt b38b1731a0 ppcopcodes: Don't change MQ if not MPC601.
MQ should not be writable if not doing MPC601.
Fix is_601 and include_601.
This fixes risu tests.
2024-11-27 07:59:19 -07:00
dingusdev 1d807d10e9 Merge pull request #124 from mihaip/upstream-empty-cdrom
Make ImgFile ignore operations before the file is opened
2024-11-25 18:35:31 -07:00
Mihai Parparita 08fa2f887d Make ImgFile ignore operations before the file is opened
Before f65f9b9845 this would happen
automatically (since the stream member was always valid). It's now a
unique_ptr that's only initialized when the file is opened, so we need
to add guards for all the operations.
2024-11-25 22:37:37 +01:00
Maxim Poliakovski 04280ecda4 Revert "Fix LR update in bc instructions"
This reverts commit 5a0a7b12e4.
2024-11-25 21:56:32 +01:00
dingusdev f4b5ac2d16 Minor fix to page 0x31 2024-11-25 08:11:11 -07:00
dingusdev c8e2a4d921 Avoid flush on web ports 2024-11-24 15:32:47 -07:00
dingusdev f6dc704aff Add MODE_SENSE_6 to ATAPI CD-ROM emulation 2024-11-24 15:23:38 -07:00
Maxim Poliakovski b3f2a6cf20 machineyosemite: remove non-existent Rage128 connection. 2024-11-22 21:29:23 +01:00
dingusdev ad44ce8ce4 Merge pull request #121 from mihaip/upstream-settings
Add support for specifying properties of dynamically-registered devices via the command line
2024-11-22 07:59:37 -07:00
joevt 4b13af6691 atirage: Change BAR 0 size calculation.
We only need up to BE_FB_OFFSET + this->vram_size.
If vram_size is 8MB, then make sure the last 4K is not mapped to BAR 0 because the macOS driver likes to map BAR 2 at that location.
2024-11-22 07:58:21 -07:00
Mihai Parparita a941836a4d Add support for specifying properties of dynamically-registered devices via the command line
The previous approach of traversing the machine and its device tree
at startup to register CLI11 options was not working for dynamically
registered devices like PCI cards. This meant that options like
gfxmem_size or mon_id from the video cards could not be set.

Switch to instead registering in MachineFactory a hook function that
provides CLI flag values. We can call it when registering any property,
whether at startup or dynamically.
2024-11-21 22:58:36 -08:00
dingusdev 5a0a7b12e4 Fix LR update in bc instructions
Only executes when the branch path is taken.
2024-11-20 20:53:59 -07:00
dingusdev 0835e6f9f4 Tweaking conditional branch instructions 2024-11-20 18:23:03 -07:00
dingusdev d279ada718 Revert "dbdma: Schedule interpret_cmd."
This reverts commit e1849a2bfd.
2024-11-17 06:49:43 -07:00
joevt e1849a2bfd dbdma: Schedule interpret_cmd.
Have the entire dbdma program executed by scheduling each iteration in the CPU loop.
This is done only for devices that use the dbdma program to drive data input/output (has_data_callbacks) rather than have the device drive the dbdma program.
2024-11-16 10:30:20 -07:00
joevt 362cfcbc83 atahd: Rename descriptors. 2024-11-15 12:05:50 -07:00
joevt 6c093e141b Add missing override statements. 2024-11-15 10:03:57 -07:00
Rairii aeac232e12 imgfile_sdl: Flush on write. 2024-11-15 07:54:49 -07:00
joevt 0ce96ffc12 CLI11: Update to v2.4.2. 2024-11-15 06:08:44 -07:00
joevt ef6f2a40c8 atimach64defs: Add some bits. 2024-11-13 07:52:34 -07:00
joevt 3fbf0ddaa4 atimach64defs: Don't need L for unsigned constants. 2024-11-13 07:52:25 -07:00
joevt 6572bf8ce3 atirage: Fix Apple monitor extended sense codes.
Now multi-sync displays should be usable with Beige G3.
2024-11-13 07:51:49 -07:00
joevt f27b8ba1be pdmonboard: Fix display resolution change.
You can connect a multisync display which should support 640x480 and 832x624.
2024-11-12 19:04:59 -07:00
joevt f53a7cce32 appleramdac: Fix clock divisor 1x.
If bits 6 and 7 are 3, then the divisor should be 1 instead of 16.
0 -> 2x
1 -> 4x
2 -> 8x
3 -> 1x (not 16x).
This change affects RGB 12 inch dislay 512 x 384 60Hz mode in Platinum.
2024-11-12 19:04:29 -07:00
joevt e7eb1c8a66 Fix PCI interrupts and add devices.
- Use interrupt source instead of IRQ ID in the IrqMap.
- Add a get_interrupt_controller method to mirror the set_interrupt_controller method.
- Have PCI hosts use pcihost_device_postinit to add PCI devices. This was moved from bandit's device_postinit and allows for duplicate devices by appending the slot to the registered device name.
- Fix interrupts of Pippin.

Fix interrupts of cmd646
- Make it work like other PCI devices.
- IntDetails is built into the pcibase base class.
- IntDetails is initialized by calling pci_interrupt.
- pci_interrupt checks the "enable interrupts" flag before doing an interrupt.
2024-11-12 07:04:55 -07:00
joevt e707d1f27a Remove slashes from PCI device names.
So they are not mistaken for path separators.
2024-11-11 21:28:51 -07:00
joevt 9a2303c495 pci: Replace pci_name with get_name.
It's redundant to have two names.
2024-11-11 21:28:23 -07:00
joevt 6154b7cbe2 amic: Add modem port transmit DMA read. 2024-11-11 21:10:17 -07:00
joevt ffc7de4715 platinum: Handle read 4 bytes with offset. 2024-11-10 21:05:05 -07:00
joevt 97339e4ce4 platinum: Add disable_display.
To mirror enable_display.
2024-11-10 21:03:53 -07:00
joevt fc89fec3e6 dbdma: Do interrupt after setting resCount and xferStatus. 2024-11-10 06:24:24 -07:00
joevt 15986a4e4f dbdma: Allow clearing only control bits.
Only control bits can be set and cleared by software.
Command bits and status bits cannot be cleared.
2024-11-10 06:23:35 -07:00
joevt d56520d22a dbdma: Set active only when wake is set. 2024-11-10 06:22:38 -07:00
dingusdev 42f1871c84 Merge pull request #120 from mihaip/upstream-deterministic
Add a deterministic execution mode
2024-11-10 06:13:35 -07:00
Mihai Parparita f65f9b9845 Add a deterministic execution mode
Adds support for a --deterministic command-line option that makes
repeated runs the same:
- Keyboard and mouse input is ignored
- The sound server does a periodic pull from the DMA channel (so that
  it gets drained), but only does so via a periodic timer (instead of
  being driven by a cubeb callback, which could arrive at different
  times)
- Disk image writes are disabled (reads of a modified area still
  work via an in-memory copy)
- NVRAM writes are disabled
- The current time that ViaCuda initializes the guest OS is always the
  same.

This makes execution exactly the same each time, which should
make debugging of more subtle issues easier.

To validate that the deterministic mode is working, I've added a
periodic log of the current "time" (measured in cycle count), PC
and opcode. When comparing two runs with --log-no-uptime, the generated
log files are identical.
2024-11-09 22:48:06 -08:00
joevt f415a63b76 dbdma: Allow Stop command to set xferStatus.
Some software may check the status flags of a Stop DBDMA descriptor.
2024-11-09 21:05:32 -07:00
joevt 50e661f804 dbdma: Resume should continue DBDMA program.
Just like Start does.
2024-11-09 21:05:27 -07:00
joevt 7ffafdc007 dbdma: Implement branch taken flag. 2024-11-09 20:31:54 -07:00
joevt 96875a1278 dbdma: Clear active flag if paused flag is set.
The active flag is cleared when the pause flag is set, so why shouldn't the active flag be cleared when the start flag is set with the pause flag is already set?
2024-11-09 19:59:52 -07:00
dingusdev 6766ca8647 Merge pull request #118 from mihaip/upstream-hidpi
Enable HiDPI mode for SDL and ensure that we use nearest-neighbor scaling
2024-11-09 16:59:15 -07:00
Mihai Parparita fc13f6870b Enable HiDPI mode for SDL and ensure that we use nearest-neighbor scaling
Avoids blurriness on macOS hosts with Retina displays.

Smooth scaling can be toggled back on via control-S
2024-11-09 15:48:00 -08:00
joevt 27d389c36a debugger: Erase prompt when repeating command.
Enterring a blank command continues the disassembly or stepping for one instruction. Erasing the prompt saves one line in the console so the disassembly doesn't appear double spaced. I don't know if the terminal control sequence works in Windows.
2024-11-09 06:48:22 -07:00
Rairii 625e474c03 atirage: Force redraw if pixel format changes. 2024-11-08 08:00:43 -07:00
joevt 116a65ce77 ati: Frame refresh if CRTC_ENABLE changes. 2024-11-08 07:38:07 -07:00
Maxim Poliakovski c6116fcc88 grandcentral: pass Curio DREQ state to its DMA channel.
Bit 5 of the channel status register of the SCSI0 DMA channel
reflects the DREQ signal from Curio.
The old SCSI API still used in some Macintosh applications
- most notably HD SC Setup and Drive Setup - relies on this API
and that signal to be implemented.
2024-11-03 15:10:33 +01:00
Maxim Poliakovski 86ce9b0bb1 dbdma: support for non-DWORD register reads. 2024-11-03 15:10:33 +01:00
dingusdev 6ca5b738d5 More FPU refactoring
Now down to 520 tests
2024-11-01 21:28:13 -07:00
dingusdev f660efcd54 Continued FPU fixes 2024-10-30 07:46:44 -07:00
dingusdev 5f826d6a9d More floating point fixes
Down to 752 failing tests
2024-10-27 12:51:16 -07:00
dingusdev 873f8632e4 More floating point fixes
Confirmed to partially fix Mac OS X installation screen errors
2024-10-26 16:16:52 -07:00
dingusdev af7c22e7b3 Compile fixes, pt. 2 2024-10-17 19:50:15 -07:00
dingusdev 28ec650e4f Compile fixes 2024-10-17 19:41:58 -07:00
dingusdev 329bcc68b1 Floating-point fix-ups
Largely to fix setting flags, but partially to fix the incorrect nan emulation
2024-10-17 08:00:27 -07:00
Maxim Poliakovski b3eb1f6419 machineyosemite: register stock hard drive. 2024-10-09 14:50:44 +02:00
Maxim Poliakovski 2132922c7b machineyosemite: attach CMD646 Ultra ATA controller. 2024-10-09 14:49:59 +02:00
Maxim Poliakovski 9915c15086 Initial CMD646U2 Ultra ATA controller emulation. 2024-10-09 14:49:09 +02:00
Keith Kaisershot 6df1c7dd9d Update documentation 2024-10-06 23:46:19 -07:00
Keith Kaisershot ec9987aab6 machinepippin: replace Mouse with AppleJack
Leave a keyboard attached for compatibility.
2024-10-06 23:45:27 -07:00
Keith Kaisershot 34e0ba84f1 Add AppleJack controller support, based on AdbMouse
All AppleJack controllers start in mouse emulation mode, behaving exactly like
ADB mice. Only upon receiving a Listen command on register 3 with handler ID
0x46 does the AppleJack switch protocols, albeit such a change consisting merely
of expanding register 0's buffer size to 4 bytes. In this state, the first 2
bytes remain defined as they are for an ADB mouse; the additional 16 bits carry
the respective states of each of the AppleJack controller's remaining 11 buttons
out of a possible supported 16.

For backward compatibility, honor both mouse clicks and shoulder button presses
on the host when considering the state of the emulated trigger buttons.
2024-10-06 23:43:50 -07:00
Keith Kaisershot d23f21b391 sdl: handle gamepad events
Add new GamepadButton enum with bits corresponding to AppleJack button bits.
Both the AppleJack controller and the SDL GameController coincidentally define
one d-pad, two shoulder buttons, four face buttons, and three system buttons.
This makes mapping modern game controllers to the AppleJack straightforward.
2024-10-06 23:28:05 -07:00
Keith Kaisershot 6696248158 adbbus: decouple ADB devices from CUDA
AdbMouse and AdbKeyboard are subdevices of the CUDA device alongside AdbBus.
This doesn't make sense because conceptually, ADB devices hang off of the ADB
bus, not CUDA itself. An ADB bus can exist without a CUDA present, for example
Egret on older 68K Macs and the PMU on newer Power Macs. Therefore, make the ADB
device list a subhierarchy of AdbBus instead. Add a new "adb_devices" property
belonging to AdbBus that can allow users to specify ADB devices on the command
line at machine creation time, independent of the emulated bus's host. Make this
property default to "Mouse,Keyboard" to preserve existing behavior.
2024-10-06 23:20:10 -07:00
170 changed files with 15487 additions and 8052 deletions

No files matched your search

+12
View File
@@ -7,6 +7,7 @@
- maximumspatium
- joevt
- mihaip
- kkaisershot
## NT4/PPC fork
@@ -22,11 +23,22 @@
- kth5
- dyharlan
- roytam1
- mrpapersonic
- Randrianasulu
- lefp
- mathstuf
## Testing
- LagLifeYT
## 3rd Party Libraries
- [Capstone](https://github.com/capstone-engine/capstone)
- [CLI11](https://github.com/CLIUtils/CLI11)
- [Loguru](https://github.com/emilk/loguru)
- [SDL 2](https://github.com/libsdl-org/SDL)
## Thanks
- 68kmla
+1 -1
View File
@@ -89,7 +89,7 @@ emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True ..
cmake -DCMAKE_BUILD_TYPE=Release -DDPPC_BUILD_PPC_TESTS=True ..
make testppc
```
+4 -3
View File
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_on = false;
power_off_reason = po_benchmark_exception;
}
#endif
@@ -42,7 +43,7 @@ uint32_t cs_code[] = {
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
0x7C650194, 0x4E800020
0x7C650194, /* 0x4E800020 */ 0x00005AF0
};
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
@@ -75,7 +76,7 @@ int main(int argc, char** argv) {
/* load executable code into RAM at address 0 */
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
mmu_write_vmem<uint32_t>(0, i * 4, cs_code[i]);
}
srand(0xCAFEBABE);
@@ -85,7 +86,7 @@ int main(int argc, char** argv) {
bool did_lf = false;
for (i = 0; i < test_size; i++) {
uint8_t val = rand() % 256;
mmu_write_vmem<uint8_t>(0x1000+i, val);
mmu_write_vmem<uint8_t>(0, 0x1000+i, val);
if (i < 64) {
printf("%02x", val);
did_lf = false;
+8 -4
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)
@@ -44,16 +44,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// cyclic rotation idioms that modern compilers will
// recognize and generate very compact code for
// evolving specific machine instructions
// involving specific machine instructions
inline unsigned ROTL_32(unsigned x, unsigned n) {
n &= 0x1F;
return (x << n) | (x >> (32 - n));
if (n)
return (x << n) | (x >> (32 - n));
return x;
}
inline unsigned ROTR_32(unsigned x, unsigned n) {
n &= 0x1F;
return (x >> n) | (x << (32 - n));
if (n)
return (x >> n) | (x << (32 - n));
return x;
}
#endif
+16
View File
@@ -53,6 +53,9 @@ public:
// Calls all connected slots.
void emit(Args... args) {
if (!_is_enabled) {
return;
}
for (auto const& it : _slots) {
it.second(args...);
}
@@ -66,9 +69,22 @@ public:
_slots.clear();
}
void disable() {
_is_enabled = false;
}
void enable() {
_is_enabled = true;
}
bool is_enabled() {
return _is_enabled;
}
private:
mutable std::map<int, std::function<void(Args...)>> _slots;
mutable unsigned int _current_id { 0 };
mutable bool _is_enabled { true };
};
#endif // CORE_SIGNAL_H
+67 -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)
@@ -35,11 +35,24 @@ public:
uint32_t window_id;
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's.
// We add our own custom events after that.
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
};
enum : uint32_t {
MOUSE_EVENT_MOTION = 1 << 0,
MOUSE_EVENT_BUTTON = 1 << 1,
KEYBOARD_EVENT_DOWN = 1 << 0,
KEYBOARD_EVENT_UP = 1 << 1,
GAMEPAD_EVENT_DOWN = 1 << 0,
GAMEPAD_EVENT_UP = 1 << 1,
};
class MouseEvent {
@@ -65,6 +78,47 @@ public:
uint16_t keys_state;
};
enum KeyboardLocale : uint32_t {
Eng_USA = 0,
Eng_GBR = 1,
Fra_FRA = 10,
Deu_DEU = 20,
Ita_ITA = 30,
Spa_ESP = 40,
Jpn_JPN = 80,
};
/* AppleJack bits 3-7 are supported but unused */
enum GamepadButton : uint8_t {
Red = 14,
Green = 15,
Yellow = 9,
Blue = 8,
FrontLeft = 0,
FrontMiddle = 1,
FrontRight = 2,
LeftTrigger = 17,
RightTrigger = 16,
Up = 10,
Down = 13,
Left = 11,
Right = 12,
};
class GamepadEvent {
public:
GamepadEvent() = default;
~GamepadEvent() = default;
uint32_t gamepad_id;
uint32_t flags;
uint8_t button;
};
class EventManager {
public:
static EventManager* get_instance() {
@@ -74,7 +128,7 @@ public:
return event_manager;
};
void poll_events();
void poll_events(uint32_t kbd_locale);
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -91,6 +145,11 @@ public:
_keyboard_signal.connect_method(inst, func);
}
template <typename T>
void add_gamepad_handler(T* inst, void (T::*func)(const GamepadEvent&)) {
_gamepad_signal.connect_method(inst, func);
}
template <typename T>
void add_post_handler(T *inst, void (T::*func)()) {
_post_signal.connect_method(inst, func);
@@ -103,6 +162,11 @@ public:
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {}; // private constructor to implement a singleton
@@ -110,6 +174,7 @@ private:
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
CoreSignal<const KeyboardEvent&> _keyboard_signal;
CoreSignal<const GamepadEvent&> _gamepad_signal;
CoreSignal<> _post_signal;
uint64_t events_captured = 0;
+129 -40
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)
@@ -28,11 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
void EventManager::poll_events()
{
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) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -45,7 +45,7 @@ void EventManager::poll_events()
break;
case SDL_WINDOWEVENT: {
WindowEvent we;
WindowEvent we{};
we.sub_type = event.window.event;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
@@ -54,17 +54,81 @@ void EventManager::poll_events()
case SDL_KEYDOWN:
case SDL_KEYUP: {
// Internal shortcuts to trigger mouse grab, intentionally not
// sent to the host.
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
// 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.type == SDL_KEYUP) {
toggle_mouse_grab(event.key);
WindowEvent we;
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
int key_code = get_sdl_event_key_code(event.key);
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
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.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control--: smaller
if (event.key.keysym.sym == SDLK_MINUS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((SDL_GetModState() & KMOD_ALL) == KMOD_RALT) != 0) {
KeyboardEvent ke{};
ke.key = AdbKey_Control;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
key_downs++;
} else {
ke.flags = KEYBOARD_EVENT_UP;
key_ups++;
}
this->_keyboard_signal.emit(ke);
ke.key = AdbKey_Delete;
this->_keyboard_signal.emit(ke);
return;
}
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
if (key_code != -1) {
KeyboardEvent ke;
KeyboardEvent ke{};
ke.key = key_code;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
@@ -86,7 +150,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEMOTION: {
MouseEvent me;
MouseEvent me{};
me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel;
me.xabs = event.motion.x;
@@ -97,7 +161,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEBUTTONDOWN: {
MouseEvent me;
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -114,7 +178,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEBUTTONUP: {
MouseEvent me;
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -130,6 +194,52 @@ void EventManager::poll_events()
}
break;
case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_DOWN;
this->_gamepad_signal.emit(ge);
}
break;
case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_UP;
this->_gamepad_signal.emit(ge);
}
break;
default:
unhandled_events++;
}
@@ -140,7 +250,7 @@ void EventManager::poll_events()
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
{
switch (event.keysym.sym) {
case SDLK_a: return AdbKey_A;
@@ -275,10 +385,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
//Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
return AdbKey_JIS_Yen;
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
case 0XBC:
return AdbKey_JIS_KP_Comma;
case 0X89:
return AdbKey_JIS_Eisu;
@@ -317,25 +428,3 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
}
return -1;
}
static void toggle_mouse_grab(const SDL_KeyboardEvent &event) {
SDL_Window *window = SDL_GetWindowFromID(event.windowID);
if (SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_SetWindowTitle(window, "DingusPPC Display");
} else {
// If the mouse is initially outside the window, move it to the middle,
// so that clicks are handled by the window (instead making it lose
// focus, at least with macOS hosts).
int mouse_x, mouse_y, window_x, window_y, window_width, window_height;
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
SDL_GetWindowPosition(window, &window_x, &window_y);
SDL_GetWindowSize(window, &window_width, &window_height);
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
mouse_y < window_y || mouse_y >= window_y + window_height) {
SDL_WarpMouseInWindow(window, window_width / 2, window_height / 2);
}
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_SetWindowTitle(window, "DingusPPC Display (Mouse Grabbed)");
}
}
+2
View File
@@ -19,6 +19,8 @@ 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 <cstdint>
#ifndef MATH_UTILS_H
#define MATH_UTILS_H
+15 -15
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)
@@ -31,18 +31,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <vector>
#include <mutex>
using namespace std;
#define NS_PER_SEC 1000000000
#define USEC_PER_SEC 1000000
#define NS_PER_USEC 1000
#define NS_PER_MSEC 1000000
#define ONE_BILLION_NS 1000000000
constexpr auto NS_PER_SEC = 1000000000;
constexpr auto USEC_PER_SEC = 1000000;
constexpr auto NS_PER_USEC = 1000;
constexpr auto NS_PER_MSEC = 1000000;
constexpr auto ONE_BILLION_NS = 1000000000;
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
typedef function<void()> timer_cb;
typedef std::function<void()> timer_cb;
/** Extend std::priority_queue as suggested here:
https://stackoverflow.com/a/36711682
@@ -101,7 +99,7 @@ typedef struct TimerInfo {
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
return l.get()->timeout_ns > r.get()->timeout_ns;
}
};
@@ -116,7 +114,7 @@ public:
};
// callback for retrieving current time
void set_time_now_cb(const function<uint64_t()> &cb) {
void set_time_now_cb(const std::function<uint64_t()> &cb) {
this->get_time_now = cb;
};
@@ -142,13 +140,15 @@ private:
TimerManager(){}; // private constructor to implement a singleton
// timer queue
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
function<uint64_t()> get_time_now;
function<void()> notify_timer_changes;
std::function<uint64_t()> get_time_now;
std::function<void()> notify_timer_changes;
std::atomic<uint32_t> id{0};
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
bool cb_active = false; // true if a timer callback is executing
};
#endif // TIMER_MANAGER_H
+6
View File
@@ -5,4 +5,10 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
)
# The use of volatile is deprecated, but we still need it to avoid function
# parameters being clobbered when using setjmp/longjmp.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-volatile)
endif()
add_library(cpu_ppc OBJECT ${SOURCES})
+288 -255
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)
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// The Power-specific opcodes for the processor - ppcopcodes.cpp
// Any shared opcodes are in ppcopcodes.cpp
#include <core/bitops.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
@@ -35,14 +36,15 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
}
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_abs() {
void dppc_interpreter::power_abs(uint32_t opcode) {
uint32_t ppc_result_d;
if (ppc_state.gpr[instr.arg1] == 0x80000000) {
ppc_result_d = ppc_state.gpr[instr.arg1];
ppc_grab_regsda(opcode);
if (ppc_result_a == 0x80000000) {
ppc_result_d = ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_result_d = (int32_t(ppc_state.gpr[instr.arg1]) < 0) ? -ppc_state.gpr[instr.arg1] : ppc_state.gpr[instr.arg1];
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
@@ -50,48 +52,47 @@ void dppc_interpreter::power_abs() {
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_abs<RC0, OV0>();
template void dppc_interpreter::power_abs<RC0, OV1>();
template void dppc_interpreter::power_abs<RC1, OV0>();
template void dppc_interpreter::power_abs<RC1, OV1>();
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_clcs() {
switch (ppc_state.gpr[instr.arg1]) {
case 12: //instruction cache line size
case 13: //data cache line size
case 14: //minimum line size
case 15: //maximum line size
default:
ppc_state.gpr[instr.arg0] = is_601 ? 64 : 32;
break;
case 7:
case 23:
ppc_state.gpr[instr.arg0] = is_601 ? 64 : 0;
break;
case 8:
case 9:
case 24:
case 25:
ppc_state.gpr[instr.arg0] = is_601 ? 64 : 4;
break;
case 10:
case 11:
case 26:
case 27:
ppc_state.gpr[instr.arg0] = is_601 ? 64 : 0x4000;
break;
void dppc_interpreter::power_clcs(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_da(opcode);
switch (reg_a & 15) {
case 0:
case 1:
case 2:
case 3:
case 0xC: //instruction cache line size
case 0xD: //data cache line size
case 0xE: //minimum line size
case 0xF: //maximum line size
ppc_result_d = is_601 ? 0x40 : 0x20; break;
case 4:
case 5:
case 6: ppc_result_d = 0x20; break;
case 7: ppc_result_d = is_601 ? 1 : 0; break;
case 8:
case 9: ppc_result_d = is_601 ? 8 : 4; break;
case 0xA:
case 0xB: ppc_result_d = is_601 ? 0x8000 : 0x4000; break;
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_div() {
void dppc_interpreter::power_div(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsdab(opcode);
int64_t dividend = (uint64_t(ppc_state.gpr[instr.arg1]) << 32) | ppc_state.spr[SPR::MQ];
int32_t divisor = ppc_state.gpr[instr.arg2];
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
int32_t divisor = ppc_result_b;
int64_t quotient;
int32_t remainder;
@@ -121,52 +122,54 @@ void dppc_interpreter::power_div() {
if (rec)
ppc_changecrf0(remainder);
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
template void dppc_interpreter::power_div<RC0, OV0>();
template void dppc_interpreter::power_div<RC0, OV1>();
template void dppc_interpreter::power_div<RC1, OV0>();
template void dppc_interpreter::power_div<RC1, OV1>();
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_divs() {
void dppc_interpreter::power_divs(uint32_t opcode) {
uint32_t ppc_result_d;
int32_t remainder;
ppc_grab_regsdab(opcode);
if (!ppc_state.gpr[instr.arg2]) { // handle the "anything / 0" case
if (!ppc_result_b) { // handle the "anything / 0" case
ppc_result_d = -1;
remainder = ppc_state.gpr[instr.arg1];
remainder = ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else if (ppc_state.gpr[instr.arg1] == 0x80000000U && ppc_state.gpr[instr.arg2] == 0xFFFFFFFFU) {
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
ppc_result_d = 0x80000000U;
remainder = 0;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else { // normal signed devision
ppc_result_d = int32_t(ppc_state.gpr[instr.arg1]) / int32_t(ppc_state.gpr[instr.arg2]);
remainder = (int32_t(ppc_state.gpr[instr.arg1]) % int32_t(ppc_state.gpr[instr.arg2]));
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
if (rec)
ppc_changecrf0(remainder);
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
template void dppc_interpreter::power_divs<RC0, OV0>();
template void dppc_interpreter::power_divs<RC0, OV1>();
template void dppc_interpreter::power_divs<RC1, OV0>();
template void dppc_interpreter::power_divs<RC1, OV1>();
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_doz() {
uint32_t ppc_result_d = (int32_t(ppc_state.gpr[instr.arg1]) < int32_t(ppc_state.gpr[instr.arg2])) ?
ppc_state.gpr[instr.arg2] - ppc_state.gpr[instr.arg1] : 0;
void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
ppc_result_b - ppc_result_a : 0;
if (ov) {
if (int32_t(ppc_result_d) < 0) {
@@ -178,27 +181,29 @@ void dppc_interpreter::power_doz() {
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_doz<RC0, OV0>();
template void dppc_interpreter::power_doz<RC0, OV1>();
template void dppc_interpreter::power_doz<RC1, OV0>();
template void dppc_interpreter::power_doz<RC1, OV1>();
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_dozi() {
void dppc_interpreter::power_dozi(uint32_t opcode) {
uint32_t ppc_result_d;
if (((int32_t)ppc_state.gpr[instr.arg1]) > instr.i_simm) {
ppc_grab_regsdasimm(opcode);
if (((int32_t)ppc_result_a) > simm) {
ppc_result_d = 0;
} else {
ppc_result_d = instr.i_simm - ppc_state.gpr[instr.arg1];
ppc_result_d = simm - ppc_result_a;
}
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template <field_rc rec>
void dppc_interpreter::power_lscbx() {
uint32_t ea = ppc_state.gpr[instr.arg2] + (instr.arg1 ? ppc_state.gpr[instr.arg1] : 0);
void dppc_interpreter::power_lscbx(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
uint32_t bytes_remaining = bytes_to_load;
@@ -210,13 +215,13 @@ void dppc_interpreter::power_lscbx() {
uint8_t shift_amount = 24;
while (bytes_remaining > 0) {
uint8_t return_value = mmu_read_vmem<uint8_t>(ea);
uint8_t return_value = mmu_read_vmem<uint8_t>(opcode, ea);
ppc_result_d |= return_value << shift_amount;
if (!shift_amount) {
if (instr.arg0 != instr.arg1 && instr.arg0 != instr.arg2)
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
instr.arg0 = (instr.arg0 + 1) & 0x1F;
if (reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
reg_d = (reg_d + 1) & 0x1F;
ppc_result_d = 0;
shift_amount = 24;
} else {
@@ -233,8 +238,8 @@ void dppc_interpreter::power_lscbx() {
}
// store partially loaded register if any
if (shift_amount != 24 && instr.arg0 != instr.arg1 && instr.arg0 != instr.arg2)
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
@@ -246,13 +251,14 @@ void dppc_interpreter::power_lscbx() {
}
}
template void dppc_interpreter::power_lscbx<RC0>();
template void dppc_interpreter::power_lscbx<RC1>();
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_maskg() {
uint32_t mask_start = ppc_state.gpr[instr.arg0] & 0x1F;
uint32_t mask_end = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_grab_regssab(opcode);
uint32_t mask_start = ppc_result_d & 0x1F;
uint32_t mask_end = ppc_result_b & 0x1F;
uint32_t insert_mask = 0;
if (mask_start < (mask_end + 1)) {
@@ -265,32 +271,35 @@ void dppc_interpreter::power_maskg() {
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
}
ppc_state.gpr[instr.arg1] = insert_mask;
ppc_result_a = insert_mask;
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_state.gpr[instr.arg1]);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_maskg<RC0>();
template void dppc_interpreter::power_maskg<RC1>();
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_maskir() {
ppc_state.gpr[instr.arg1] = ((ppc_state.gpr[instr.arg1] & ~ppc_state.gpr[instr.arg2]) | \
(ppc_state.gpr[instr.arg0] & ppc_state.gpr[instr.arg2]));
void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_maskir<RC0>();
template void dppc_interpreter::power_maskir<RC1>();
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_mul() {
int64_t product = int64_t(int32_t(ppc_state.gpr[instr.arg1])) * int32_t(ppc_state.gpr[instr.arg2]);
void dppc_interpreter::power_mul(uint32_t opcode) {
ppc_grab_regsdab(opcode);
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
ppc_state.spr[SPR::MQ] = uint32_t(product);
@@ -303,180 +312,189 @@ void dppc_interpreter::power_mul() {
}
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_mul<RC0, OV0>();
template void dppc_interpreter::power_mul<RC0, OV1>();
template void dppc_interpreter::power_mul<RC1, OV0>();
template void dppc_interpreter::power_mul<RC1, OV1>();
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_nabs() {
uint32_t ppc_result_d = (int32_t(ppc_state.gpr[instr.arg1]) < 0) ? ppc_state.gpr[instr.arg1] : -ppc_state.gpr[instr.arg1];
void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(instr.arg0, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_nabs<RC0, OV0>();
template void dppc_interpreter::power_nabs<RC0, OV1>();
template void dppc_interpreter::power_nabs<RC1, OV0>();
template void dppc_interpreter::power_nabs<RC1, OV1>();
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_rlmi() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t r =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(instr.arg3, instr.arg4);
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
uint32_t mask = power_rot_mask(rot_mb, rot_me);
uint32_t ppc_result_a = ((r & mask) | (ppc_state.gpr[instr.arg1] & ~mask));
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
if ((ppc_cur_instruction & 0x01) == 1)
if ((opcode & 0x01) == 1)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template <field_rc rec>
void dppc_interpreter::power_rrib() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (int32_t(ppc_state.gpr[instr.arg1]) < 0) {
ppc_state.gpr[instr.arg1] |= (0x80000000U >> rot_sh);
if (int32_t(ppc_result_d) < 0) {
ppc_result_a |= (0x80000000U >> rot_sh);
} else {
ppc_state.gpr[instr.arg1] &= ~(0x80000000U >> rot_sh);
ppc_result_a &= ~(0x80000000U >> rot_sh);
}
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_rrib<RC0>();
template void dppc_interpreter::power_rrib<RC1>();
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sle() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] << rot_sh;
ppc_state.spr[SPR::MQ] =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(instr.arg1, ppc_state.gpr[instr.arg1]);
ppc_store_iresult_reg(reg_a, ppc_result_a);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_state.gpr[instr.arg1]);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sle<RC0>();
template void dppc_interpreter::power_sle<RC1>();
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sleq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t r =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_state.gpr[instr.arg1] = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sleq<RC0>();
template void dppc_interpreter::power_sleq<RC1>();
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sliq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] << rot_sh;
ppc_state.spr[SPR::MQ] =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_state.gpr[instr.arg1]);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sliq<RC0>();
template void dppc_interpreter::power_sliq<RC1>();
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t r =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_state.gpr[instr.arg1] = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_slliq<RC0>();
template void dppc_interpreter::power_slliq<RC1>();
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sllq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_state.gpr[instr.arg2] & 0x20) {
ppc_state.gpr[instr.arg1] = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
if (ppc_result_b & 0x20) {
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
} else {
ppc_state.gpr[instr.arg1] =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1U << rot_sh) - 1)));
}
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sllq<RC0>();
template void dppc_interpreter::power_sllq<RC1>();
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_slq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_state.gpr[instr.arg2] & 0x20) {
ppc_state.gpr[instr.arg1] = 0;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] << rot_sh;
ppc_result_a = ppc_result_d << rot_sh;
}
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_slq<RC0>();
template void dppc_interpreter::power_slq<RC1>();
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraiq() {
uint32_t mask = (1 << instr.arg2) - 1;
uint32_t ppc_result_a = (int32_t)ppc_state.gpr[instr.arg0] >> instr.arg2;
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> instr.arg2) |
(ppc_state.gpr[instr.arg0] << (32 - instr.arg2));
void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_state.gpr[instr.arg1]) < 0) && (ppc_state.gpr[instr.arg1] & mask)) {
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
@@ -485,60 +503,64 @@ void dppc_interpreter::power_sraiq() {
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sraiq<RC0>();
template void dppc_interpreter::power_sraiq<RC1>();
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t mask = (ppc_state.gpr[instr.arg2] & 0x20) ? -1 : (1 << rot_sh) - 1;
ppc_state.gpr[instr.arg1] = (int32_t)ppc_state.gpr[instr.arg0] >>
((ppc_state.gpr[instr.arg2] & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] =
((ppc_state.gpr[instr.arg0] << rot_sh) | (ppc_state.gpr[instr.arg0] >> (32 - rot_sh)));
void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_state.gpr[instr.arg0]) < 0) && (ppc_state.gpr[instr.arg0] & mask)) {
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> rot_sh) |
(ppc_state.gpr[instr.arg0] << (32 - rot_sh));
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sraq<RC0>();
template void dppc_interpreter::power_sraq<RC1>();
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sre() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] >> rot_sh;
void dppc_interpreter::power_sre(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> rot_sh) |
(ppc_state.gpr[instr.arg0] << (32 - rot_sh));
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sre<RC0>();
template void dppc_interpreter::power_sre<RC1>();
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srea() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t ppc_result_a = (int32_t)ppc_state.gpr[instr.arg0] >> rot_sh;
uint32_t r = ((ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh)));
void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_state.gpr[instr.arg0]) < 0) && (r & ~mask)) {
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
@@ -547,93 +569,104 @@ void dppc_interpreter::power_srea() {
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r;
}
template void dppc_interpreter::power_srea<RC0>();
template void dppc_interpreter::power_srea<RC1>();
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sreq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = -1U >> rot_sh;
uint32_t ppc_result_a = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh));
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(instr.arg1, ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sreq<RC0>();
template void dppc_interpreter::power_sreq<RC1>();
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sriq() {
uint32_t rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] >> rot_sh;
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh));
void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sriq<RC0>();
template void dppc_interpreter::power_sriq<RC1>();
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq() {
uint32_t rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t r = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh));
unsigned mask = power_rot_mask(ppc_state.gpr[instr.arg2], 31);
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_state.gpr[instr.arg1] = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srliq<RC0>();
template void dppc_interpreter::power_srliq<RC1>();
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srlq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
uint32_t r = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh));
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_state.gpr[instr.arg2] & 0x20) {
ppc_state.gpr[instr.arg1] = (ppc_state.spr[SPR::MQ] & mask);
if (ppc_result_b & 0x20) {
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
} else {
ppc_state.gpr[instr.arg1] = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
}
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srlq<RC0>();
template void dppc_interpreter::power_srlq<RC1>();
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srq() {
unsigned rot_sh = ppc_state.gpr[instr.arg2] & 0x1F;
void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_state.gpr[instr.arg2] & 0x20) {
ppc_state.gpr[instr.arg1] = 0;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_state.gpr[instr.arg1] = ppc_state.gpr[instr.arg0] >> rot_sh;
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = (ppc_state.gpr[instr.arg0] >> rot_sh) | (ppc_state.gpr[instr.arg0] << (32 - rot_sh));
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_state.gpr[instr.arg1]);
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srq<RC0>();
template void dppc_interpreter::power_srq<RC1>();
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode);
+257 -237
View File
@@ -47,7 +47,7 @@ enum EXEC_MODE:uint32_t {
enum endian_switch { big_end = 0, little_end = 1 };
typedef void (*PPCOpcode)(void);
typedef void (*PPCOpcode)(uint32_t opcode);
union FPR_storage {
double dbl64_r; // double floating-point representation
@@ -68,25 +68,6 @@ fpscr = FP Status and Condition Register
sr = Segment Register
**/
typedef struct struct_ppc_instr {
uint8_t arg0;
uint8_t arg1;
uint8_t arg2;
uint8_t arg3;
uint8_t arg4;
int32_t addr;
int32_t mask;
uint8_t main_op;
uint16_t sub_op;
union {
int32_t i_simm;
uint32_t i_uimm;
};
} SetInstr;
extern SetInstr instr;
typedef struct struct_ppc_state {
FPR_storage fpr[32];
uint32_t pc; // Referred as the CIA in the PPC manual
@@ -196,14 +177,16 @@ extern uint64_t rtc_timestamp;
extern uint64_t tbr_wr_value;
extern uint32_t dec_wr_value;
extern uint32_t tbr_freq_ghz;
extern uint32_t tbr_freq_shift;
extern uint64_t tbr_period_ns;
extern uint32_t rtc_lo, rtc_hi;
/* Flags for controlling interpreter execution. */
enum {
EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2,
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
EXEF_RFI = 1 << 2, // RFI instruction executed
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
};
enum CR_select : int32_t {
@@ -262,22 +245,54 @@ enum FPSCR : uint32_t {
FX = 1UL << 31
};
/** Bit definitions for the Machine State Register (MSR). */
enum MSR : int {
LE = 0x1, //little endian mode
RI = 0x2,
DR = 0x10,
IR = 0x20,
IP = 0x40,
FE1 = 0x100,
BE = 0x200,
SE = 0x400,
FE0 = 0x800,
ME = 0x1000,
FP = 0x2000,
PR = 0x4000,
EE = 0x8000, //external interrupt
ILE = 0x10000,
POW = 0x40000
// ----------------------------------------------------------------------------------------
// 64-bit // 32-bit // Notes for MPC601 (601), PowerPC (PPC),
// // // MPC750 (750), Altivec (AV), Power ISA (ISA)
// ----------------------------------------------------------------------------------------
LE = (1 << (63 - 63)), // 31 // Little-endian mode enable (not 601);
// Little-Endian Mode (ISA)
RI = (1 << (63 - 62)), // 30 // Recoverable exception (not 601);
// Recoverable Interrupt (ISA)
PM = (1 << (63 - 61)), // 29 // Performance monitor marked mode (750);
// Performance Monitor Mark (PMM for ISA)
// = (1 << (63 - 60)), // 28 // Reserved
DR = (1 << (63 - 59)), // 27 // Data address translation (DT on 601);
// Data Relocate (ISA)
IR = (1 << (63 - 58)), // 26 // Instruction address translation (IT on 601);
// Instruction Relocate (ISA)
IP = (1 << (63 - 57)), // 25 // Exception prefix (EP); Reserved (ISA)
// = (1 << (63 - 56)), // 24 // Reserved (AL for POWER)
FE1 = (1 << (63 - 55)), // 23 // Floating-point exception mode 1
BE = (1 << (63 - 54)), // 22 // Branch trace enable (Optional, not 601);
// Trace Enable (TE): Branch Trace (ISA)
SE = (1 << (63 - 53)), // 21 // Single-step trace enable (Optional);
// Trace Enable (TE): Single Step Trace (ISA)
FE0 = (1 << (63 - 52)), // 20 // Floating-point exception mode 0
ME = (1 << (63 - 51)), // 19 // Machine check enable;
// Machine Check Interrupt Enable (ISA)
FP = (1 << (63 - 50)), // 18 // Floating-point available
PR = (1 << (63 - 49)), // 17 // Privilege level; Problem State (ISA)
EE = (1 << (63 - 48)), // 16 // External exception enable (601);
// External interrupt enable
// ----------------------------------------------------------------------------------------
ILE = (1 << (63 - 47)), // 15 // Exception little-endian mode (not 601, not ISA)
TGPR = (1 << (63 - 46)), // 14 // Temporary GPR remapping (603e)
POW = (1 << (63 - 45)), // 13 // Power management enable (not 601, not ISA)
// = (1 << (63 - 44)), // 12 // Reserved
// = (1 << (63 - 42)), // 10 // Reserved
// S = (1 << (63 - 41)), // 9 // Secure (ISA)
// VSX = (1 << (63 - 40)), // 8 // VSX Available (ISA)
// = (1 << (63 - 39)), // 7 // Reserved
VEC = (1 << (63 - 38)), // 6 // AltiVec available (AV); Vector Available (ISA)
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// HV = (1ULL << (63 - 3)), // // Hypervisor State (ISA)
// ISF = (1ULL << (63 - 2)), // // Exception 64-bit mode (optional, PPC)
// = (1ULL << (63 - 1)), // // Reserved
// SF = (1ULL << (63 - 0)), // // Sixty-four bit mode (PowerPC, PowerISA)
// ----------------------------------------------------------------------------------------
};
enum XER : uint32_t {
@@ -336,6 +351,7 @@ enum Po_Cause : int {
po_enter_debugger,
po_entered_debugger,
po_signal_interrupt,
po_benchmark_exception
};
extern bool power_on;
@@ -344,15 +360,19 @@ extern bool int_pin;
extern bool dec_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation
// Make execution deterministic (ignore external input, used a fixed date, etc.)
extern bool is_deterministic;
// Important Addressing Integers
extern uint32_t ppc_cur_instruction;
extern uint32_t ppc_next_instruction_address;
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
return READ_DWORD_BE_A(ptr);
}
// Profiling Stats
@@ -416,21 +436,18 @@ typedef enum {
IS601,
} field_601;
// Placeholder value for cases where we don't have a currently-executing instruction.
constexpr uint32_t NO_OPCODE = 0;
// Function prototypes
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
extern void ppc_mmu_init();
void ppc_illegalop();
void ppc_fpu_off();
void ppc_illegalop(uint32_t opcode);
void ppc_assert_int();
void ppc_release_int();
void decode_instr();
void exec_instr();
void initialize_ppc_opcode_tables(bool include_601);
extern double fp_return_double(uint32_t reg);
extern uint64_t fp_return_uint64(uint32_t reg);
void initialize_ppc_opcode_table();
void ppc_changecrf0(uint32_t set_result);
void set_host_rounding_mode(uint8_t mode);
@@ -439,8 +456,8 @@ void update_fpscr(uint32_t new_fpscr);
/* Exception handlers. */
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
void ppc_floating_point_exception();
void ppc_alignment_exception(uint32_t ea);
void ppc_floating_point_exception(uint32_t opcode);
void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
// MEMORY DECLARATIONS
extern MemCtrlBase* mem_ctrl_instance;
@@ -451,203 +468,203 @@ extern void do_ctx_sync(void);
// The functions used by the PowerPC processor
namespace dppc_interpreter {
template <field_lk l, field_601 for601> extern void ppc_bcctr();
template <field_lk l> extern void ppc_bclr();
extern void ppc_crand();
extern void ppc_crandc();
extern void ppc_creqv();
extern void ppc_crnand();
extern void ppc_crnor();
extern void ppc_cror();
extern void ppc_crorc();
extern void ppc_crxor();
extern void ppc_isync();
template <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode);
template <field_lk l> extern void ppc_bclr(uint32_t opcode);
extern void ppc_crand(uint32_t opcode);
extern void ppc_crandc(uint32_t opcode);
extern void ppc_creqv(uint32_t opcode);
extern void ppc_crnand(uint32_t opcode);
extern void ppc_crnor(uint32_t opcode);
extern void ppc_cror(uint32_t opcode);
extern void ppc_crorc(uint32_t opcode);
extern void ppc_crxor(uint32_t opcode);
extern void ppc_isync(uint32_t opcode);
template <logical_fun logical_op, field_rc rec> extern void ppc_logical();
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add();
template <field_rc rec, field_ov ov> extern void ppc_adde();
template <field_rc rec, field_ov ov> extern void ppc_addme();
template <field_rc rec, field_ov ov> extern void ppc_addze();
extern void ppc_cmp();
extern void ppc_cmpl();
template <field_rc rec> extern void ppc_cntlzw();
extern void ppc_dcbf();
extern void ppc_dcbi();
extern void ppc_dcbst();
extern void ppc_dcbt();
extern void ppc_dcbtst();
extern void ppc_dcbz();
template <field_rc rec, field_ov ov> extern void ppc_divw();
template <field_rc rec, field_ov ov> extern void ppc_divwu();
extern void ppc_eciwx();
extern void ppc_ecowx();
extern void ppc_eieio();
template <class T, field_rc rec>extern void ppc_exts();
extern void ppc_icbi();
extern void ppc_mftb();
extern void ppc_lhaux();
extern void ppc_lhax();
extern void ppc_lhbrx();
extern void ppc_lwarx();
extern void ppc_lwbrx();
template <class T> extern void ppc_lzx();
template <class T> extern void ppc_lzux();
extern void ppc_mcrxr();
extern void ppc_mfcr();
template <field_rc rec> extern void ppc_mulhwu();
template <field_rc rec> extern void ppc_mulhw();
template <field_rc rec, field_ov ov> extern void ppc_mullw();
template <field_rc rec, field_ov ov> extern void ppc_neg();
template <field_direction shift, field_rc rec> extern void ppc_shift();
template <field_rc rec> extern void ppc_sraw();
template <field_rc rec> extern void ppc_srawi();
template <class T> extern void ppc_stx();
template <class T> extern void ppc_stux();
extern void ppc_stfiwx();
extern void ppc_sthbrx();
extern void ppc_stwcx();
extern void ppc_stwbrx();
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf();
template <field_rc rec, field_ov ov> extern void ppc_subfe();
template <field_rc rec, field_ov ov> extern void ppc_subfme();
template <field_rc rec, field_ov ov> extern void ppc_subfze();
extern void ppc_sync();
extern void ppc_tlbia();
extern void ppc_tlbie();
extern void ppc_tlbli();
extern void ppc_tlbld();
extern void ppc_tlbsync();
extern void ppc_tw();
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_adde(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_addme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode);
extern void ppc_cmp(uint32_t opcode);
extern void ppc_cmpl(uint32_t opcode);
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode);
extern void ppc_dcbf(uint32_t opcode);
extern void ppc_dcbi(uint32_t opcode);
extern void ppc_dcbst(uint32_t opcode);
extern void ppc_dcbt(uint32_t opcode);
extern void ppc_dcbtst(uint32_t opcode);
extern void ppc_dcbz(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_divw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_divwu(uint32_t opcode);
extern void ppc_eciwx(uint32_t opcode);
extern void ppc_ecowx(uint32_t opcode);
extern void ppc_eieio(uint32_t opcode);
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode);
extern void ppc_icbi(uint32_t opcode);
extern void ppc_mftb(uint32_t opcode);
extern void ppc_lhaux(uint32_t opcode);
extern void ppc_lhax(uint32_t opcode);
extern void ppc_lhbrx(uint32_t opcode);
extern void ppc_lwarx(uint32_t opcode);
extern void ppc_lwbrx(uint32_t opcode);
template <class T> extern void ppc_lzx(uint32_t opcode);
template <class T> extern void ppc_lzux(uint32_t opcode);
extern void ppc_mcrxr(uint32_t opcode);
extern void ppc_mfcr(uint32_t opcode);
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode);
template <field_rc rec> extern void ppc_mulhw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_mullw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_neg(uint32_t opcode);
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode);
template <field_rc rec> extern void ppc_sraw(uint32_t opcode);
template <field_rc rec> extern void ppc_srawi(uint32_t opcode);
template <class T> extern void ppc_stx(uint32_t opcode);
template <class T> extern void ppc_stux(uint32_t opcode);
extern void ppc_stfiwx(uint32_t opcode);
extern void ppc_sthbrx(uint32_t opcode);
extern void ppc_stwcx(uint32_t opcode);
extern void ppc_stwbrx(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfe(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode);
extern void ppc_sync(uint32_t opcode);
extern void ppc_tlbia(uint32_t opcode);
extern void ppc_tlbie(uint32_t opcode);
extern void ppc_tlbli(uint32_t opcode);
extern void ppc_tlbld(uint32_t opcode);
extern void ppc_tlbsync(uint32_t opcode);
extern void ppc_tw(uint32_t opcode);
extern void ppc_lswi();
extern void ppc_lswx();
extern void ppc_stswi();
extern void ppc_stswx();
extern void ppc_lswi(uint32_t opcode);
extern void ppc_lswx(uint32_t opcode);
extern void ppc_stswi(uint32_t opcode);
extern void ppc_stswx(uint32_t opcode);
extern void ppc_mfsr();
extern void ppc_mfsrin();
extern void ppc_mtsr();
extern void ppc_mtsrin();
extern void ppc_mfsr(uint32_t opcode);
extern void ppc_mfsrin(uint32_t opcode);
extern void ppc_mtsr(uint32_t opcode);
extern void ppc_mtsrin(uint32_t opcode);
extern void ppc_mcrf();
extern void ppc_mtcrf();
extern void ppc_mfmsr();
extern void ppc_mfspr();
extern void ppc_mtmsr();
extern void ppc_mtspr();
extern void ppc_mcrf(uint32_t opcode);
extern void ppc_mtcrf(uint32_t opcode);
extern void ppc_mfmsr(uint32_t opcode);
extern void ppc_mfspr(uint32_t opcode);
extern void ppc_mtmsr(uint32_t opcode);
extern void ppc_mtspr(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb0();
template <field_rc rec> extern void ppc_mtfsb1();
extern void ppc_mcrfs();
template <field_rc rec> extern void ppc_fmr();
template <field_601 for601, field_rc rec> extern void ppc_mffs();
template <field_rc rec> extern void ppc_mtfsf();
template <field_rc rec> extern void ppc_mtfsfi();
template <field_rc rec> extern void ppc_mtfsb0(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode);
extern void ppc_mcrfs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmr(uint32_t opcode);
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode);
template <field_shift shift> extern void ppc_addi();
template <field_rc rec> extern void ppc_addic();
template <field_shift shift> extern void ppc_andirc();
template <field_lk l, field_aa a> extern void ppc_b();
template <field_lk l, field_aa a> extern void ppc_bc();
extern void ppc_cmpi();
extern void ppc_cmpli();
template <class T> extern void ppc_lz();
template <class T> extern void ppc_lzu();
extern void ppc_lha();
extern void ppc_lhau();
extern void ppc_lmw();
extern void ppc_mulli();
template <field_shift shift> extern void ppc_ori();
extern void ppc_rfi();
extern void ppc_rlwimi();
extern void ppc_rlwinm();
extern void ppc_rlwnm();
extern void ppc_sc();
template <class T> extern void ppc_st();
template <class T> extern void ppc_stu();
extern void ppc_stmw();
extern void ppc_subfic();
extern void ppc_twi();
template <field_shift shift> extern void ppc_xori();
template <field_shift shift> extern void ppc_addi(uint32_t opcode);
template <field_rc rec> extern void ppc_addic(uint32_t opcode);
template <field_shift shift> extern void ppc_andirc(uint32_t opcode);
template <field_lk l, field_aa a> extern void ppc_b(uint32_t opcode);
template <field_lk l, field_aa a> extern void ppc_bc(uint32_t opcode);
extern void ppc_cmpi(uint32_t opcode);
extern void ppc_cmpli(uint32_t opcode);
template <class T> extern void ppc_lz(uint32_t opcode);
template <class T> extern void ppc_lzu(uint32_t opcode);
extern void ppc_lha(uint32_t opcode);
extern void ppc_lhau(uint32_t opcode);
extern void ppc_lmw(uint32_t opcode);
extern void ppc_mulli(uint32_t opcode);
template <field_shift shift> extern void ppc_ori(uint32_t opcode);
extern void ppc_rfi(uint32_t opcode);
extern void ppc_rlwimi(uint32_t opcode);
extern void ppc_rlwinm(uint32_t opcode);
extern void ppc_rlwnm(uint32_t opcode);
extern void ppc_sc(uint32_t opcode);
template <class T> extern void ppc_st(uint32_t opcode);
template <class T> extern void ppc_stu(uint32_t opcode);
extern void ppc_stmw(uint32_t opcode);
extern void ppc_subfic(uint32_t opcode);
extern void ppc_twi(uint32_t opcode);
template <field_shift shift> extern void ppc_xori(uint32_t opcode);
extern void ppc_lfs();
extern void ppc_lfsu();
extern void ppc_lfsx();
extern void ppc_lfsux();
extern void ppc_lfd();
extern void ppc_lfdu();
extern void ppc_lfdx();
extern void ppc_lfdux();
extern void ppc_stfs();
extern void ppc_stfsu();
extern void ppc_stfsx();
extern void ppc_stfsux();
extern void ppc_stfd();
extern void ppc_stfdu();
extern void ppc_stfdx();
extern void ppc_stfdux();
extern void ppc_lfs(uint32_t opcode);
extern void ppc_lfsu(uint32_t opcode);
extern void ppc_lfsx(uint32_t opcode);
extern void ppc_lfsux(uint32_t opcode);
extern void ppc_lfd(uint32_t opcode);
extern void ppc_lfdu(uint32_t opcode);
extern void ppc_lfdx(uint32_t opcode);
extern void ppc_lfdux(uint32_t opcode);
extern void ppc_stfs(uint32_t opcode);
extern void ppc_stfsu(uint32_t opcode);
extern void ppc_stfsx(uint32_t opcode);
extern void ppc_stfsux(uint32_t opcode);
extern void ppc_stfd(uint32_t opcode);
extern void ppc_stfdu(uint32_t opcode);
extern void ppc_stfdx(uint32_t opcode);
extern void ppc_stfdux(uint32_t opcode);
template <field_rc rec> extern void ppc_fadd();
template <field_rc rec> extern void ppc_fsub();
template <field_rc rec> extern void ppc_fmul();
template <field_rc rec> extern void ppc_fdiv();
template <field_rc rec> extern void ppc_fadds();
template <field_rc rec> extern void ppc_fsubs();
template <field_rc rec> extern void ppc_fmuls();
template <field_rc rec> extern void ppc_fdivs();
template <field_rc rec> extern void ppc_fmadd();
template <field_rc rec> extern void ppc_fmsub();
template <field_rc rec> extern void ppc_fnmadd();
template <field_rc rec> extern void ppc_fnmsub();
template <field_rc rec> extern void ppc_fmadds();
template <field_rc rec> extern void ppc_fmsubs();
template <field_rc rec> extern void ppc_fnmadds();
template <field_rc rec> extern void ppc_fnmsubs();
template <field_rc rec> extern void ppc_fabs();
template <field_rc rec> extern void ppc_fnabs();
template <field_rc rec> extern void ppc_fneg();
template <field_rc rec> extern void ppc_fsel();
template <field_rc rec> extern void ppc_fres();
template <field_rc rec> extern void ppc_fsqrts();
template <field_rc rec> extern void ppc_fsqrt();
template <field_rc rec> extern void ppc_frsqrte();
template <field_rc rec> extern void ppc_frsp();
template <field_rc rec> extern void ppc_fctiw();
template <field_rc rec> extern void ppc_fctiwz();
template <field_rc rec> extern void ppc_fadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmul(uint32_t opcode);
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode);
template <field_rc rec> extern void ppc_fadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode);
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fneg(uint32_t opcode);
template <field_rc rec> extern void ppc_fsel(uint32_t opcode);
template <field_rc rec> extern void ppc_fres(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode);
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode);
template <field_rc rec> extern void ppc_frsp(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode);
extern void ppc_fcmpo();
extern void ppc_fcmpu();
extern void ppc_fcmpo(uint32_t opcode);
extern void ppc_fcmpu(uint32_t opcode);
// Power-specific instructions
template <field_rc rec, field_ov ov> extern void power_abs();
extern void power_clcs();
template <field_rc rec, field_ov ov> extern void power_div();
template <field_rc rec, field_ov ov> extern void power_divs();
template <field_rc rec, field_ov ov> extern void power_doz();
extern void power_dozi();
template <field_rc rec> extern void power_lscbx();
template <field_rc rec> extern void power_maskg();
template <field_rc rec> extern void power_maskir();
template <field_rc rec, field_ov ov> extern void power_mul();
template <field_rc rec, field_ov ov> extern void power_nabs();
extern void power_rlmi();
template <field_rc rec> extern void power_rrib();
template <field_rc rec> extern void power_sle();
template <field_rc rec> extern void power_sleq();
template <field_rc rec> extern void power_sliq();
template <field_rc rec> extern void power_slliq();
template <field_rc rec> extern void power_sllq();
template <field_rc rec> extern void power_slq();
template <field_rc rec> extern void power_sraiq();
template <field_rc rec> extern void power_sraq();
template <field_rc rec> extern void power_sre();
template <field_rc rec> extern void power_srea();
template <field_rc rec> extern void power_sreq();
template <field_rc rec> extern void power_sriq();
template <field_rc rec> extern void power_srliq();
template <field_rc rec> extern void power_srlq();
template <field_rc rec> extern void power_srq();
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode);
extern void power_clcs(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_div(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_divs(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode);
extern void power_dozi(uint32_t opcode);
template <field_rc rec> extern void power_lscbx(uint32_t opcode);
template <field_rc rec> extern void power_maskg(uint32_t opcode);
template <field_rc rec> extern void power_maskir(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_mul(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_nabs(uint32_t opcode);
extern void power_rlmi(uint32_t opcode);
template <field_rc rec> extern void power_rrib(uint32_t opcode);
template <field_rc rec> extern void power_sle(uint32_t opcode);
template <field_rc rec> extern void power_sleq(uint32_t opcode);
template <field_rc rec> extern void power_sliq(uint32_t opcode);
template <field_rc rec> extern void power_slliq(uint32_t opcode);
template <field_rc rec> extern void power_sllq(uint32_t opcode);
template <field_rc rec> extern void power_slq(uint32_t opcode);
template <field_rc rec> extern void power_sraiq(uint32_t opcode);
template <field_rc rec> extern void power_sraq(uint32_t opcode);
template <field_rc rec> extern void power_sre(uint32_t opcode);
template <field_rc rec> extern void power_srea(uint32_t opcode);
template <field_rc rec> extern void power_sreq(uint32_t opcode);
template <field_rc rec> extern void power_sriq(uint32_t opcode);
template <field_rc rec> extern void power_srliq(uint32_t opcode);
template <field_rc rec> extern void power_srlq(uint32_t opcode);
template <field_rc rec> extern void power_srq(uint32_t opcode);
} // namespace dppc_interpreter
// AltiVec instructions
@@ -658,13 +675,16 @@ template <field_rc rec> extern void power_srq();
extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode);
extern void ppc_exec(void);
extern void ppc_exec_single(void);
extern void ppc_exec_until(uint32_t goal_addr);
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
extern PPCOpcode* ppc_opcode_grabber;
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
/* debugging support API */
void print_fprs(void); /* print content of the floating-point registers */
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
+33 -28
View File
@@ -57,7 +57,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_ISI:
if (exec_flags) {
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
@@ -66,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags) {
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -90,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_DECR:
if (exec_flags) {
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -114,9 +114,14 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
}
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
ppc_state.msr &= 0xFFFB1041;
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
if (!is_601) {
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
}
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, new_msr_val, false);
if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000;
@@ -196,17 +201,17 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
throw std::invalid_argument(exc_descriptor);
}
void ppc_floating_point_exception() {
void ppc_floating_point_exception(uint32_t opcode) {
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
ppc_state.pc, ppc_cur_instruction);
ppc_state.pc, opcode);
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
}
void ppc_alignment_exception(uint32_t ea)
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
{
uint32_t dsisr;
switch (ppc_cur_instruction & 0xfc000000) {
switch (opcode & 0xfc000000) {
case 0x80000000: // lwz
case 0x90000000: // stw
case 0xa0000000: // lhz
@@ -228,11 +233,11 @@ void ppc_alignment_exception(uint32_t ea)
case 0xd4000000: // stfsu
case 0xdc000000: // stfdu
// indirect with immediate index
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
dsisr = ((opcode >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((opcode >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
break;
case 0x7c000000:
switch (ppc_cur_instruction & 0xfc0007ff) {
switch (opcode & 0xfc0007ff) {
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
case 0x7c0002aa: // lwax (64-bit only)
case 0x7c00042a: // lswx
@@ -266,12 +271,12 @@ void ppc_alignment_exception(uint32_t ea)
case 0x7c00056e: // stfsux
case 0x7c0005ee: // stfdux
indirect_with_index:
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
dsisr = ((opcode << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
| ((opcode << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
| ((opcode << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
break;
case 0x7c0007ec:
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
goto indirect_with_index;
/* fallthrough */
default:
@@ -282,31 +287,31 @@ indirect_with_index:
unexpected_instruction:
dsisr = 0;
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
ppc_cur_instruction);
opcode);
}
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
// Undefined for dcbz.
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
dsisr |= ((opcode >> 16) & 0x000003e0);
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
if ((opcode & 0xfc000000) == 0xb8000000) { // lmw
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
"What to set DSISR bits 27-31?", ppc_cur_instruction);
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
else if ((opcode & 0xfc0007ff) == 0x7c0004aa) { // lswi
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
"What to set DSISR bits 27-31?", ppc_cur_instruction);
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
else if ((opcode & 0xfc0007ff) == 0x7c00042a) { // lswx
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
"What to set DSISR bits 27-31?", ppc_cur_instruction);
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else {
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
dsisr |= ((opcode >> 16) & 0x0000001f);
}
ppc_state.spr[SPR::DSISR] = dsisr;
+292 -533
View File
File diff suppressed because it is too large. Load diff
+765 -396
View File
File diff suppressed because it is too large. Load diff
+145 -137
View File
@@ -23,183 +23,191 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define PPC_MACROS_H
#include <cinttypes>
#include "ppcemu.h"
#define reg_d(opcode) ((opcode >> 21) & 0x1F)
#define reg_a(opcode) ((opcode >> 16) & 0x1F)
#define reg_b(opcode) ((opcode >> 11) & 0x1F)
#define reg_c(opcode) ((opcode >> 6) & 0x1F)
#define reg_s(opcode) reg_d(opcode)
#define trap_to(opcode) reg_d(opcode)
#define simm(opcode) int32_t(int16_t(opcode))
#define uimm(opcode) uint16_t(opcode)
#define rot_sh(opcode) reg_b(opcode)
#define rot_mb(opcode) ((opcode >> 6) & 0x1F)
#define rot_me(opcode) ((opcode >> 1) & 0x1F)
#define crf_d(opcode) ((opcode >> 21) & 0x1C)
#define crf_s(opcode) ((opcode >> 16) & 0x1C)
#define crm(opcode) ((opcode >> 12) & 0xFFU)
#define fcrm(opcode) crm(opcode)
#define fmmask(opcode) ((opcode >> 17) & 0xFFU)
#define br_bo(opcode) reg_d(opcode)
#define br_bi(opcode) reg_a(opcode)
#define br_bd(opcode) int32_t(int16_t(opcode & ~3UL))
#define adr_li(opcode) int32_t((opcode & ~3UL) << 6) >> 6
#define adr_d(opcode) int32_t(int16_t(opcode))
#define segreg(opcode) ((opcode >> 16) & 0xF)
#define mtfsfi_mask(opcode) ((opcode << 16) & 0xF0000000UL)
#define ppc_grab_regsdasimm(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int32_t simm = int32_t(int16_t(opcode)); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_twi(opcode) \
instr.i_simm = simm(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg0 = trap_to(opcode);
#define ppc_grab_tw(opcode) \
instr.i_simm = simm(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg0 = trap_to(opcode); \
#define ppc_grab_crfd(opcode) \
instr.arg0 = crf_d(opcode);
#define ppc_grab_mcrxr(opcode) \
instr.arg0 = crf_d(opcode); \
instr.arg4 = crf_d(opcode); \
#define ppc_grab_sr(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = segreg(opcode); \
#define ppc_grab_mtfsfi(opcode) \
instr.arg0 = reg_d(opcode); \
instr.mask = mtfsfi_mask(opcode); \
#define ppc_grab_mtfsf(opcode) \
instr.arg2 = reg_b(opcode); \
instr.mask = fmmask(opcode);\
#define ppc_grab_regs_dasimm(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.i_simm = simm(opcode); \
#define ppc_grab_regs_sauimm(opcode) \
instr.arg0 = reg_s(opcode); \
instr.arg1 = reg_a(opcode); \
instr.i_simm = simm(opcode); \
#define ppc_grab_regs_da_addr(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.addr = adr_d(opcode); \
#define ppc_grab_branch(opcode) \
instr.addr = adr_li(opcode); \
#define ppc_grab_branch_cond(opcode) \
instr.arg0 = br_bo(opcode); \
instr.arg1 = br_bi(opcode); \
#define ppc_grab_d(opcode) \
instr.arg0 = reg_d(opcode);
#define ppc_grab_dab(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
#define ppc_grab_regsdauimm(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsasimm(opcode) \
instr.arg0 = reg_s(opcode); \
instr.arg1 = reg_a(opcode); \
instr.i_simm = simm(opcode); \
int reg_a = (opcode >> 16) & 31; \
int32_t simm = int32_t(int16_t(opcode)); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssauimm(opcode) \
instr.arg0 = reg_s(opcode); \
instr.arg1 = reg_a(opcode); \
instr.i_simm = simm(opcode); \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_crfd_regsauimm(opcode) \
instr.arg0 = crf_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.i_simm = simm(opcode); \
int crf_d = (opcode >> 21) & 0x1C; \
int reg_a = (opcode >> 16) & 31; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_crfd_regsab(opcode) \
instr.arg0 = crf_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode);
#define ppc_grab_da(opcode)\
int reg_d = (opcode >> 21) & 31;\
int reg_a = (opcode >> 16) & 31;\
#define ppc_grab_dab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31;
#define ppc_grab_s(opcode) \
instr.arg0 = reg_s(opcode); \
#define ppc_grab_regs_crfds(opcode) \
instr.arg0 = crf_d(opcode); \
instr.arg1 = crf_s(opcode); \
int reg_s = (opcode >> 21) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
#define ppc_grab_regsdab(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regs_sab_rot(opcode) \
instr.arg0 = reg_s(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
instr.arg3 = rot_mb(opcode); \
instr.arg4 = rot_me(opcode); \
#define ppc_grab_regssab(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
#define ppc_grab_regssab_stswx(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsab(opcode) \
int reg_a = (opcode >> 16) & 31;\
int reg_b = (opcode >> 11) & 31;\
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssa_stmw(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash_stswi(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
#define ppc_grab_regsda(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdb(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_store_iresult_reg(reg, ppc_result)\
ppc_state.gpr[reg] = ppc_result;
ppc_state.gpr[reg] = ppc_result
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d)\
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define ppc_grab_regsfpdb(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31;
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
#define ppc_grab_regsfpdiab(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdia(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsia(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsiab(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpsab(opcode) \
instr.arg0 = crf_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
int crf_d = (opcode >> 21) & 0x1C; \
double db_test_a = GET_FPR(reg_a); \
double db_test_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdab(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdac(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg3 = reg_c(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_c = (opcode >> 6) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_grab_regsfpdabc(opcode) \
instr.arg0 = reg_d(opcode); \
instr.arg1 = reg_a(opcode); \
instr.arg2 = reg_b(opcode); \
instr.arg3 = reg_c(opcode); \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
int reg_c = (opcode >> 6) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b); \
double val_reg_c = GET_FPR(reg_c);
#endif // PPC_MACROS_H
+137 -49
View File
@@ -311,6 +311,7 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
uint32_t dev_base = 0;
bool is_writable;
AddressMapEntry *cur_dma_rgn;
AddressMapEntry *next_dma_rgn;
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
if (!cur_dma_rgn) {
@@ -320,9 +321,44 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
}
if (addr + size - 1 > cur_dma_rgn->end) {
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!",
addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end
);
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
cur_dma_rgn->start, cur_dma_rgn->end,
uint64_t(cur_dma_rgn->mem_ptr),
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
);
else
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
cur_dma_rgn->start, cur_dma_rgn->end
);
next_dma_rgn = mem_ctrl_instance->find_range(cur_dma_rgn->end + 1);
if (next_dma_rgn) {
if (next_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "next region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
next_dma_rgn->start, next_dma_rgn->end,
uint64_t(next_dma_rgn->mem_ptr),
uint64_t(next_dma_rgn->mem_ptr + next_dma_rgn->end - next_dma_rgn->start)
);
else
LOG_F(ERROR, "next region: 0x%08X..0x%08X",
next_dma_rgn->start, next_dma_rgn->end
);
}
if (next_dma_rgn &&
(cur_dma_rgn->type & (RT_ROM | RT_RAM)) &&
((cur_dma_rgn->type & (RT_ROM | RT_RAM)) == (next_dma_rgn->type & (RT_ROM | RT_RAM))) &&
(next_dma_rgn->mem_ptr == cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start + 1) &&
(addr + size - 1 <= next_dma_rgn->end)
) {
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
" The regions are the same type and adjacent in host and guest spaces.",
addr, addr + size - 1
);
} else {
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
addr, addr + size - 1
);
}
}
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {
@@ -385,7 +421,9 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurITLBMode != mmu_mode) {
switch(mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
case 0: // real address mode
pCurITLB1 = &itlb1_mode1[0];
pCurITLB2 = &itlb2_mode1[0];
@@ -394,10 +432,6 @@ void mmu_change_mode()
pCurITLB1 = &itlb1_mode2[0];
pCurITLB2 = &itlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
//LOG_F(ERROR, "instruction mmu mode 1 is invalid!"); // this happens alot. Maybe it's not invalid?
mmu_mode = 3;
case 3: // user mode with instruction translation enabled
pCurITLB1 = &itlb1_mode3[0];
pCurITLB2 = &itlb2_mode3[0];
@@ -410,7 +444,9 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurDTLBMode != mmu_mode) {
switch(mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
case 0: // real address mode
pCurDTLB1 = &dtlb1_mode1[0];
pCurDTLB2 = &dtlb2_mode1[0];
@@ -419,10 +455,6 @@ void mmu_change_mode()
pCurDTLB1 = &dtlb1_mode2[0];
pCurDTLB2 = &dtlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
LOG_F(ERROR, "data mmu mode 1 is invalid!");
mmu_mode = 3;
case 3: // user mode with data translation enabled
pCurDTLB1 = &dtlb1_mode3[0];
pCurDTLB2 = &dtlb2_mode3[0];
@@ -741,7 +773,6 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
}
ppc_set_cur_instruction(host_va);
if (paddr)
*paddr = tlb1_entry->phys_tag | (vaddr & 0xFFFUL);
@@ -985,12 +1016,12 @@ void mmu_pat_ctx_changed()
// Forward declarations.
template <class T>
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template <class T>
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value);
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value);
template <class T>
inline T mmu_read_vmem(uint32_t guest_va)
inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
{
TLBEntry *tlb1_entry, *tlb2_entry;
uint8_t *host_va;
@@ -1034,7 +1065,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
#endif
if (sizeof(T) == 8) {
if (guest_va & 3)
ppc_alignment_exception(guest_va);
ppc_alignment_exception(opcode, guest_va);
return (
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
@@ -1061,7 +1092,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
// handle unaligned memory accesses
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
return read_unaligned<T>(guest_va, host_va);
return read_unaligned<T>(opcode, guest_va, host_va);
}
// handle aligned memory accesses
@@ -1078,13 +1109,13 @@ inline T mmu_read_vmem(uint32_t guest_va)
}
// explicitely instantiate all required mmu_read_vmem variants
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va);
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va);
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va);
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va);
template uint8_t mmu_read_vmem<uint8_t>(uint32_t opcode, uint32_t guest_va);
template uint16_t mmu_read_vmem<uint16_t>(uint32_t opcode, uint32_t guest_va);
template uint32_t mmu_read_vmem<uint32_t>(uint32_t opcode, uint32_t guest_va);
template uint64_t mmu_read_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va);
template <class T>
inline void mmu_write_vmem(uint32_t guest_va, T value)
inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
{
TLBEntry *tlb1_entry, *tlb2_entry;
uint8_t *host_va;
@@ -1156,7 +1187,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
#endif
if (sizeof(T) == 8) {
if (guest_va & 3)
ppc_alignment_exception(guest_va);
ppc_alignment_exception(opcode, guest_va);
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
@@ -1179,7 +1210,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
// handle unaligned memory accesses
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
write_unaligned<T>(guest_va, host_va, value);
write_unaligned<T>(opcode, guest_va, host_va, value);
return;
}
@@ -1201,17 +1232,17 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
}
// explicitely instantiate all required mmu_write_vmem variants
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint8_t value);
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint16_t value);
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t value);
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint64_t value);
template void mmu_write_vmem<uint8_t> (uint32_t opcode, uint32_t guest_va, uint8_t value);
template void mmu_write_vmem<uint16_t>(uint32_t opcode, uint32_t guest_va, uint16_t value);
template void mmu_write_vmem<uint32_t>(uint32_t opcode, uint32_t guest_va, uint32_t value);
template void mmu_write_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va, uint64_t value);
template <class T>
static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
{
if ((sizeof(T) == 8) && (guest_va & 3)) {
#ifndef PPC_TESTS
ppc_alignment_exception(guest_va);
ppc_alignment_exception(opcode, guest_va);
#endif
}
@@ -1226,7 +1257,7 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
// Because such accesses suffer a performance penalty, they will be
// presumably very rare so don't waste time optimizing the code below.
for (int i = 0; i < sizeof(T); guest_va++, i++) {
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va);
result = (result << 8) | mmu_read_vmem<uint8_t>(opcode, guest_va);
}
} else {
#ifdef MMU_PROFILING
@@ -1247,16 +1278,16 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
}
// explicitely instantiate all required read_unaligned variants
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va);
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va);
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va);
template uint16_t read_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template uint32_t read_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template uint64_t read_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template <class T>
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value)
{
if ((sizeof(T) == 8) && (guest_va & 3)) {
#ifndef PPC_TESTS
ppc_alignment_exception(guest_va);
ppc_alignment_exception(opcode, guest_va);
#endif
}
@@ -1272,7 +1303,7 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
uint32_t shift = (sizeof(T) - 1) * 8;
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
mmu_write_vmem<uint8_t>(guest_va, (value >> shift) & 0xFF);
mmu_write_vmem<uint8_t>(opcode, guest_va, (value >> shift) & 0xFF);
}
} else {
#ifdef MMU_PROFILING
@@ -1296,9 +1327,9 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
}
// explicitely instantiate all required write_unaligned variants
template void write_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va, uint16_t value);
template void write_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va, uint32_t value);
template void write_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va, uint64_t value);
template void write_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint16_t value);
template void write_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint32_t value);
template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint64_t value);
/* MMU profiling. */
@@ -1438,21 +1469,22 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
try {
switch (size) {
case 1:
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
break;
case 2:
ret_val = mmu_read_vmem<uint16_t>(virt_addr);
ret_val = mmu_read_vmem<uint16_t>(NO_OPCODE, virt_addr);
break;
case 4:
ret_val = mmu_read_vmem<uint32_t>(virt_addr);
ret_val = mmu_read_vmem<uint32_t>(NO_OPCODE, virt_addr);
break;
case 8:
ret_val = mmu_read_vmem<uint64_t>(virt_addr);
ret_val = mmu_read_vmem<uint64_t>(NO_OPCODE, virt_addr);
break;
default:
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
}
} catch (std::invalid_argument& exc) {
}
catch (std::invalid_argument& exc) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
@@ -1461,6 +1493,15 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
/* rethrow MMU exception */
throw exc;
}
catch (...) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
/* rethrow MMU exception */
throw(false);
}
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
@@ -1470,6 +1511,48 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
return ret_val;
}
void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size) {
uint32_t save_dsisr, save_dar;
uint64_t ret_val;
// save MMU-related CPU state
save_dsisr = ppc_state.spr[SPR::DSISR];
save_dar = ppc_state.spr[SPR::DAR];
mmu_exception_handler = dbg_exception_handler;
try {
switch (size) {
case 1:
mmu_write_vmem<uint8_t>(NO_OPCODE, virt_addr, value);
break;
case 2:
mmu_write_vmem<uint16_t>(NO_OPCODE, virt_addr, value);
break;
case 4:
mmu_write_vmem<uint32_t>(NO_OPCODE, virt_addr, uint32_t(value));
break;
case 8:
mmu_write_vmem<uint64_t>(NO_OPCODE, virt_addr, value);
break;
default:
mmu_write_vmem<uint8_t>(NO_OPCODE, virt_addr, value);
}
} catch (std::invalid_argument& exc) {
// restore MMU-related CPU state
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
// rethrow MMU exception
throw exc;
}
// restore MMU-related CPU state
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
}
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
uint32_t save_dsisr, save_dar;
bool is_mapped;
@@ -1512,7 +1595,12 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
guest_pa = tlb1_entry->phys_tag | (guest_va & 0xFFFUL);
is_mapped = true;
} while (0);
} catch (std::invalid_argument& exc) {
}
catch (std::invalid_argument& exc) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
catch (...) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
+3 -2
View File
@@ -126,12 +126,13 @@ extern void mmu_pat_ctx_changed();
extern void tlb_flush_entry(uint32_t ea);
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
template <class T>
extern T mmu_read_vmem(uint32_t guest_va);
extern T mmu_read_vmem(uint32_t opcode, uint32_t guest_va);
template <class T>
extern void mmu_write_vmem(uint32_t guest_va, T value);
extern void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value);
#endif // PPCMMU_H
+916 -760
View File
File diff suppressed because it is too large. Load diff
+4
View File
@@ -313,6 +313,10 @@ def gen_rot_opcode(opc_str, sh, mb, me):
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWINM.":
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1) + 1
elif opc_str == "RLWNM":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWNM.":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1) + 1
def extract_imm(line):
pos = 12
+14 -17
View File
@@ -42,13 +42,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
}
#endif
static void xer_ov_test(string mnem, uint32_t opcode) {
void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_cur_instruction = opcode;
decode_instr();
exec_instr();
ppc_main_opcode(ppc_opcode_grabber, opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++;
@@ -56,7 +54,7 @@ static void xer_ov_test(string mnem, uint32_t opcode) {
ntested++;
}
static void xer_update_test() {
void xer_update_test() {
xer_ov_test("ADDCO", 0x7C632414);
xer_ov_test("ADDCO.", 0x7C632415);
xer_ov_test("ADDO", 0x7C632614);
@@ -152,10 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0;
ppc_cur_instruction = opcode;
decode_instr();
exec_instr();
ppc_main_opcode(ppc_opcode_grabber, opcode);
ntested++;
@@ -174,7 +169,7 @@ static void read_test_data() {
}
}
static double double_from_string(string str) {
double double_from_string(string str) {
if (str == "snan")
return std::numeric_limits<double>::signaling_NaN();
if (str == "qnan")
@@ -297,10 +292,7 @@ static void read_test_float_data() {
ppc_state.cr = 0;
ppc_cur_instruction = opcode;
decode_instr();
exec_instr();
ppc_main_opcode(ppc_opcode_grabber, opcode);
ntested++;
@@ -310,10 +302,11 @@ static void read_test_float_data() {
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x"
<< hex << check_cr << endl;
<< hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -324,7 +317,11 @@ static void read_test_float_data() {
}
int main() {
initialize_ppc_opcode_tables(true); //kludge
is_601 = true;
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);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+1 -1
View File
@@ -73,7 +73,7 @@ static vector<PPCDisasmContext> read_test_data() {
/* put instruction mnemonic padded with trailing spaces */
idisasm << tokens[2];
idisasm << setw(8 - (int)tokens[2].length()) << " ";
idisasm << setw(streamsize(8) - (int)tokens[2].length()) << " ";
/* now add comma-separated operands */
for (i = 3; i < tokens.size(); i++) {
+2 -1
View File
@@ -2,6 +2,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_library(debugger OBJECT ${SOURCES})
+236 -78
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)
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcdisasm.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ofnvram.h>
#include "memaccess.h"
@@ -50,9 +51,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define COUTX uppercase << hex
#define COUT0_X(w) setfill('0') << setw(w) << right << COUTX
#define COUT016X COUT0_X(16)
#define COUT08X COUT0_X(8)
#define COUT04X COUT0_X(4)
static uint32_t str2addr(string& addr_str) {
try {
return (uint32_t)stoul(addr_str, NULL, 0);
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + addr_str);
}
@@ -60,7 +67,7 @@ static uint32_t str2addr(string& addr_str) {
static uint32_t str2num(string& num_str) {
try {
return (uint32_t)stol(num_str, NULL, 0);
return static_cast<uint32_t>(stol(num_str, NULL, 0));
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + num_str);
}
@@ -68,41 +75,49 @@ static uint32_t str2num(string& num_str) {
static void show_help() {
cout << "Debugger commands:" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GRPs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GPRs" << endl;
cout << " fregs -- dump content of the FPRs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " setmem X=V.T -- set memory at address X to value V of size T" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " regions -- dump memory regions" << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
#ifdef PROFILER
cout << " profiler -- show stats related to the processor" << endl;
cout << " profiler -- show stats related to the processor" << endl;
#endif
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
#ifdef ENABLE_68K_DEBUGGER
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
#endif
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << " quit -- quit the debugger" << endl << endl;
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
cout << "Pressing ENTER will repeat last command." << endl;
}
@@ -110,7 +125,7 @@ static void show_help() {
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle;
uint8_t code[10];
uint8_t code[12]{};
size_t code_size;
uint64_t dis_addr;
@@ -122,9 +137,14 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cs_insn* insn = cs_malloc(cs_handle);
for (; power_on && count > 0; count--) {
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1);
try {
code[i] = mem_read_dbg(address + i, 1);
}
catch(...) {
printf("<memerror>");
}
}
const uint8_t *code_ptr = code;
@@ -138,16 +158,16 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
}
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
cout << uppercase << hex << insn->address << " ";
cout << COUTX << insn->address << " ";
cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
address = dis_addr;
cout << setw(10) << left << insn->mnemonic << insn->op_str << right << endl;
address = static_cast<uint32_t>(dis_addr);
} else {
print_bin:
cout << uppercase << hex << address << " ";
cout << COUTX << address << " ";
cout << setfill(' ');
cout << setw(10) << left << "dc.w" << "$" << hex <<
((code[0] << 8) | code[1]) << endl;
((code[0] << 8) | code[1]) << right << endl;
address += 2;
}
}
@@ -158,7 +178,7 @@ print_bin:
}
/* emulator opcode table size --> 512 KB */
#define EMU_68K_TABLE_SIZE 0x80000
constexpr auto EMU_68K_TABLE_SIZE = 0x80000;
/** Execute one emulated 68k instruction. */
void exec_single_68k()
@@ -167,17 +187,17 @@ void exec_single_68k()
/* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */
cur_68k_pc = get_reg(string("R24")) - 2;
cur_68k_pc = static_cast<uint32_t>(get_reg(string("R24")) - 2);
/* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
/* calculate address of the current opcode table entry as follows:
get_word(68k_PC) * entry_size + table_base */
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(NO_OPCODE, cur_68k_pc) * 8 + emu_table_virt;
/* grab the PPC PC too */
ppc_pc = get_reg(string("PC"));
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
@@ -186,7 +206,7 @@ void exec_single_68k()
one by one until the execution goes outside the opcode table. */
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single();
ppc_pc = get_reg(string("PC"));
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
}
/* Getting here means we're outside the emualtor opcode table.
@@ -219,21 +239,22 @@ void print_68k_regs()
for (i = 0; i < 8; i++) {
reg = "R" + to_string(i + 8);
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " D" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
for (i = 0; i < 7; i++) {
reg = "R" + to_string(i + 16);
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " A" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
cout << " A7 : " << COUT08X << get_reg(string("R1")) << endl;
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
cout << " PC : " << COUT08X << get_reg(string("R24")) - 2 << endl;
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << " SR : " << COUT08X << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
cout << " CCR : " << COUT08X << get_reg(string("R26")) << endl;
cout << dec << setfill(' ');
}
#endif // ENABLE_68K_DEBUGGER
@@ -319,8 +340,7 @@ static void dump_mem(string& params) {
cout << (char)val;
chars_per_line += cell_size;
} else {
cout << setw(cell_size * 2) << setfill('0') << right;
cout << uppercase << hex << val << " ";
cout << COUT0_X(cell_size * 2) << val << " ";
chars_per_line += cell_size * 2 + 2;
}
}
@@ -332,6 +352,79 @@ static void dump_mem(string& params) {
cout << endl << endl;
}
static void patch_mem(string& params) {
int value_size = 1;
uint32_t addr, value;
string addr_str, value_str, size_str;
if (params.find_first_of("=") == std::string::npos) {
cout << "setmem: not enough arguments specified. Try 'help'." << endl;
return;
}
addr_str = params.substr(0, params.find_first_of("="));
value_str = params.substr(params.find_first_of("=") + 1);
if (value_str.find_first_of(".") == std::string::npos) {
cout << "setmem: no value size specified. Try 'help'." << endl;
return;
}
size_str = value_str.substr(value_str.find_first_of(".") + 1);
value_str = value_str.substr(0, value_str.find_first_of("."));
switch (size_str.back()) {
case 'b':
case 'B':
value_size = 1;
break;
case 'w':
case 'W':
value_size = 2;
break;
case 'd':
case 'D':
value_size = 4;
break;
case 'q':
case 'Q':
value_size = 8;
break;
case 'c':
case 'C':
value_size = 1;
break;
default:
cout << "Invalid value size " << size_str << endl;
return;
}
try {
addr = str2addr(addr_str);
} catch (invalid_argument& exc) {
try {
// number conversion failed, trying reg name
addr = get_reg(addr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
}
try {
value = str2num(value_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
try {
mem_write_dbg(addr, value, value_size);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
@@ -340,9 +433,9 @@ static uint32_t disasm(uint32_t count, uint32_t address) {
for (int i = 0; power_on && i < count; i++) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_addr;
cout << ": " << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << endl;
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
}
return ctx.instr_addr;
}
@@ -352,10 +445,10 @@ static void print_gprs() {
int i;
for (i = 0; i < 32; i++) {
reg_name = "R" + to_string(i);
reg_name = "r" + to_string(i);
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
COUT08X << get_reg(reg_name) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -364,11 +457,11 @@ static void print_gprs() {
}
}
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
array<string, 8> sprs = {"pc", "lr", "cr", "ctr", "xer", "msr", "srr0", "srr1"};
for (auto &spr : sprs) {
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
COUT08X << get_reg(spr) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -380,34 +473,46 @@ static void print_gprs() {
}
}
static void print_fprs() {
string reg_name;
for (int i = 0; i < 32; i++) {
reg_name = "f" + to_string(i);
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
COUT016X << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601;
static void print_mmu_regs()
{
printf("MSR : 0x%08X\n", ppc_state.msr);
printf(" msr : %08X\n", ppc_state.msr);
printf("\nBAT registers:\n");
for (int i = 0; i < 4; i++) {
printf("IBAT%dU : 0x%08X, IBAT%dL : 0x%08X\n",
printf(" ibat%du : %08X ibat%dl : %08X\n",
i, ppc_state.spr[528+i*2],
i, ppc_state.spr[529+i*2]);
}
if (!is_601) {
for (int i = 0; i < 4; i++) {
printf("DBAT%dU : 0x%08X, DBAT%dL : 0x%08X\n",
printf(" dbat%du : %08X dbat%dl : %08X\n",
i, ppc_state.spr[536+i*2],
i, ppc_state.spr[537+i*2]);
}
}
printf("\n");
printf("SDR1 : 0x%08X\n", ppc_state.spr[SPR::SDR1]);
printf(" sdr1 : %08X\n", ppc_state.spr[SPR::SDR1]);
printf("\nSegment registers:\n");
for (int i = 0; i < 16; i++) {
printf("SR%-2d : 0x%08X\n", i, ppc_state.sr[i]);
printf(" %ssr%d : %08X\n", (i < 10) ? " " : "", i, ppc_state.sr[i]);
}
}
@@ -438,7 +543,18 @@ static void mysig_handler(int signum)
}
#endif
void enter_debugger() {
static void delete_prompt() {
#ifndef _WIN32
// move up, carriage return (move to column 0), erase from cursor to end of line
cout << "\e[A\r\e[0K";
#endif
}
DppcDebugger::DppcDebugger() {
}
void DppcDebugger::enter_debugger() {
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
inst_string, inst_num_str, profile_name, sub_cmd;
uint32_t addr, inst_grab;
@@ -451,6 +567,7 @@ void enter_debugger() {
uint32_t next_addr_68k;
#endif
bool cmd_repeat;
int repeat_count = 0;
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
@@ -458,7 +575,7 @@ void enter_debugger() {
#ifndef _WIN32
struct winsize win_size_previous;
ioctl(0, TIOCGWINSZ, &win_size_previous);
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_previous);
#endif
while (1) {
@@ -497,6 +614,7 @@ void enter_debugger() {
power_off_reason = po_entered_debugger;
}
if (!did_message) {
cout << endl;
cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl;
did_message = true;
@@ -517,7 +635,7 @@ void enter_debugger() {
#ifndef _WIN32
struct winsize win_size_current;
ioctl(0, TIOCGWINSZ, &win_size_current);
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_current);
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
win_size_previous = win_size_current;
if (cmd.empty()) {
@@ -544,6 +662,10 @@ void enter_debugger() {
cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) {
cmd = last_cmd;
repeat_count++;
}
else {
repeat_count = 1;
}
if (cmd == "help") {
cmd = "";
@@ -551,6 +673,10 @@ void enter_debugger() {
} else if (cmd == "quit") {
cmd = "";
break;
} else if (cmd == "restart") {
cmd = "";
power_on = false;
power_off_reason = po_restart;
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
@@ -573,6 +699,9 @@ void enter_debugger() {
} else {
print_gprs();
}
} else if (cmd == "fregs") {
cmd = "";
print_fprs();
} else if (cmd == "mregs") {
cmd = "";
print_mmu_regs();
@@ -620,21 +749,34 @@ void enter_debugger() {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
exec_single_68k();
}
#endif
} else {
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
addr = ppc_state.pc;
ppc_exec_single();
}
}
} else if (cmd == "next" || cmd == "ni") {
addr_str = "PC";
addr = (uint32_t)get_reg(addr_str) + 4;
addr = static_cast<uint32_t>(get_reg(addr_str) + 4);
ppc_exec_until(addr);
} else if (cmd == "until") {
ss >> addr_str;
if (cmd_repeat) {
delete_prompt();
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
}
else {
ss >> addr_str;
}
try {
addr = str2addr(addr_str);
if (context == 2) {
@@ -703,21 +845,23 @@ void enter_debugger() {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
addr = next_addr_68k;
}
else {
addr_str = "R24";
addr = get_reg(addr_str) - 2;
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
}
next_addr_68k = disasm_68k(1, addr);
#endif
} else {
if (cmd_repeat) {
delete_prompt();
addr = next_addr_ppc;
}
else {
addr_str = "PC";
addr = (uint32_t)get_reg(addr_str);
addr = static_cast<uint32_t>(get_reg(addr_str));
}
next_addr_ppc = disasm(1, addr);
}
@@ -729,6 +873,10 @@ void enter_debugger() {
expr_str = "";
ss >> expr_str;
dump_mem(expr_str);
} else if (cmd == "setmem") {
expr_str = "";
ss >> expr_str;
patch_mem(expr_str);
#ifdef ENABLE_68K_DEBUGGER
} else if (cmd == "context") {
cmd = "";
@@ -742,6 +890,10 @@ void enter_debugger() {
cout << "Unknown debugging context: " << expr_str << endl;
}
#endif
} else if (cmd == "regions") {
cmd = "";
if (mem_ctrl_instance)
mem_ctrl_instance->dump_regions();
} else if (cmd == "printenv") {
cmd = "";
if (ofnvram->init())
@@ -753,9 +905,15 @@ void enter_debugger() {
ss >> var_name;
std::istream::sentry se(ss); // skip white space
getline(ss, value); // get everything up to eol
if (ofnvram->init())
if (ofnvram->init()) {
cout << " Cannot open NVRAM" << endl;
continue;
ofnvram->setenv(var_name, value);
}
if (!ofnvram->setenv(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
#ifndef _WIN32
} else if (cmd == "nvedit") {
cmd = "";
+17 -1
View File
@@ -22,6 +22,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DEBUGGER_H_
#define DEBUGGER_H_
void enter_debugger();
#include <memory>
class DppcDebugger {
public:
static DppcDebugger* get_instance() {
if (!debugger_obj) {
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
};
void enter_debugger();
private:
inline static std::unique_ptr<DppcDebugger> debugger_obj{nullptr};
explicit DppcDebugger(); // private constructor to implement a singleton
};
#endif // DEBUGGER_H_
+4
View File
@@ -8,10 +8,14 @@ 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/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"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
+100
View File
@@ -0,0 +1,100 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 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/>.
*/
/** @file Apple Desktop Bus AppleJack controller emulation. */
#include <devices/common/adb/adbapplejack.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <loguru.hpp>
AdbAppleJack::AdbAppleJack(std::string name) : AdbMouse(name, AdbMouse::TRACKBALL, 2, 7, 300) {
EventManager::get_instance()->add_gamepad_handler(this, &AdbAppleJack::event_handler);
}
void AdbAppleJack::event_handler(const GamepadEvent& event) {
uint32_t button_bit = 1 << event.button;
if (event.flags & GAMEPAD_EVENT_DOWN)
this->buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
else
this->buttons_changed = true;
}
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
}
bool AdbAppleJack::get_register_0() {
bool changed = this->triggers_changed || this->buttons_changed;
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
// AppleJack triggers always affect the mouse button bits.
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = ~this->buttons_state >> 8;
out_buf[3] = ~this->buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
}
return changed;
}
void AdbAppleJack::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case APPLEJACK_HANDLER_ID: // switch over to AppleJack protocol
this->dev_handler_id = in_data[1];
LOG_F(INFO, "%s: switched to AppleJack mode", this->name.c_str());
break;
default:
this->AdbMouse::set_register_3();
break;
}
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+60
View File
@@ -0,0 +1,60 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 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/>.
*/
/** @file Apple Desktop Bus AppleJack controller definitions. */
#ifndef ADB_APPLEJACK_H
#define ADB_APPLEJACK_H
#include <devices/common/adb/adbmouse.h>
#include <devices/common/hwcomponent.h>
#include <memory>
#include <string>
enum : uint8_t {
APPLEJACK_HANDLER_ID = 0x46,
};
class GamepadEvent;
class AdbAppleJack : public AdbMouse {
public:
AdbAppleJack(std::string name);
~AdbAppleJack() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbAppleJack>(new AdbAppleJack("ADB-APPLEJACK"));
}
void reset() override;
void event_handler(const GamepadEvent& event);
bool get_register_0() override;
void set_register_3() override;
private:
uint32_t buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
#endif // ADB_APPLEJACK_H
+31 -1
View File
@@ -25,6 +25,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/adb/adbdevice.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <sstream>
AdbBus::AdbBus(std::string name) {
this->set_name(name);
@@ -32,6 +34,30 @@ AdbBus::AdbBus(std::string name) {
this->devices.clear();
}
int AdbBus::device_postinit() {
std::string adb_device_list = GET_STR_PROP("adb_devices");
if (adb_device_list.empty())
return 0;
std::string adb_device;
std::istringstream adb_device_stream(adb_device_list);
while (getline(adb_device_stream, adb_device, ',')) {
std::string dev_name = "Adb" + adb_device;
if (dev_name == this->name)
continue; // don't register a second ADB bus
if (DeviceRegistry::device_registered(dev_name)) {
gMachineObj->add_device(dev_name, DeviceRegistry::get_descriptor(dev_name).m_create_func());
} else {
LOG_F(WARNING, "Unknown specified ADB device \"%s\"", adb_device.c_str());
}
}
return 0;
}
void AdbBus::register_device(AdbDevice* dev_obj) {
this->devices.push_back(dev_obj);
}
@@ -102,8 +128,12 @@ uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
return ADB_STAT_OK;
}
static const PropMap AdbBus_Properties = {
{"adb_devices", new StrProperty("Mouse,Keyboard")},
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, {}
AdbBus::create, {}, AdbBus_Properties
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+3 -1
View File
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <vector>
#define ADB_MAX_DATA_SIZE 8
constexpr auto ADB_MAX_DATA_SIZE = 8;
/** ADB status. */
enum {
@@ -51,6 +51,8 @@ public:
return std::unique_ptr<AdbBus>(new AdbBus("ADB-BUS"));
}
int device_postinit() override;
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; };
+29 -14
View File
@@ -28,7 +28,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <loguru.hpp>
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution
) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution)
{
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset();
@@ -63,17 +66,28 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0() {
if (this->x_rel || this->y_rel || this->changed) {
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
uint8_t* p;
uint8_t* out_buf = this->host_obj->get_output_buf();
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
int num_bits, total_bits;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
num_bits = total_bits = 7;
} else {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
uint8_t buttons_state = ~this->buttons_state;
for (int axis = 0; axis < 2; axis++) {
int bits = this->num_bits;
int bits = num_bits;
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
: this->device_class == TABLET ? this->y_abs : this->y_rel;
if (val < (-1 << (bits - 1)))
@@ -86,7 +100,7 @@ bool AdbMouse::get_register_0() {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((this->buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -101,20 +115,17 @@ bool AdbMouse::get_register_0() {
this->changed = false;
uint8_t count = (uint8_t)(p - out_buf);
// should never happen, but check just in case
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
count = UINT8_MAX;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1)
count = 2;
this->host_obj->set_output_count(count);
return true;
return should_update;
}
return false;
}
bool AdbMouse::get_register_0() {
return get_register_0(this->buttons_state, false);
}
bool AdbMouse::get_register_1() {
uint8_t* out_buf = this->host_obj->get_output_buf();
// Identifier
@@ -156,6 +167,10 @@ void AdbMouse::set_register_3() {
}
}
uint8_t AdbMouse::get_buttons_state() const {
return this->buttons_state;
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}
};
+24 -15
View File
@@ -35,19 +35,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class MouseEvent;
class AdbMouse : public AdbDevice {
public:
enum DeviceClass {
TABLET = 0,
MOUSE = 1,
TRACKBALL = 2,
};
public:
AdbMouse(std::string name);
AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution);
~AdbMouse() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbMouse>(new AdbMouse("ADB-MOUSE"));
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
return std::unique_ptr<AdbMouse>(
new AdbMouse("ADB-MOUSE", device_class, num_buttons, num_bits, resolution));
}
void reset() override;
@@ -57,6 +69,10 @@ public:
bool get_register_1() override;
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons_state, bool force);
uint8_t get_buttons_state() const;
private:
int32_t x_rel = 0;
int32_t y_rel = 0;
@@ -64,17 +80,10 @@ private:
int32_t y_abs = 0;
uint8_t buttons_state = 0;
bool changed = false;
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
uint8_t device_class;
int num_buttons;
int num_bits;
uint16_t resolution;
};
#endif // ADB_MOUSE_H
+16 -4
View File
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
#include <cinttypes>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -75,7 +76,8 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
this->r_status &= ~DRQ;
} else {
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->update_intrq(1);
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
}
}
return ret_data;
@@ -117,12 +119,18 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
if (this->xfer_cnt <= 0) { // transfer complete?
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
this->r_status &= ~BSY;
this->update_intrq(1);
//LOG_F(INFO, "%s: write complete", name.c_str());
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->r_status &= ~BSY;
this->update_intrq(1);
});
} else {
this->cur_data_ptr = this->data_ptr;
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->signal_data_ready();
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->signal_data_ready();
});
}
}
}
@@ -146,6 +154,10 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
this->r_dev_head = value;
break;
case ATA_Reg::COMMAND:
if ((this->r_status & BSY) != 0) {
LOG_F(ERROR, "%s: tried to perform command %x when busy", name.c_str(), value);
break;
}
this->r_command = value;
if (is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
+6 -4
View File
@@ -50,7 +50,7 @@ public:
virtual int perform_command() = 0;
int get_device_id() override { return this->my_dev_id; };
int get_device_id() override { return this->my_dev_id; }
void pdiag_callback() override {
this->r_error &= 0x7F;
@@ -62,7 +62,7 @@ public:
void update_intrq(uint8_t new_intrq_state);
void signal_data_ready();
bool has_data() {
bool has_data() const {
return data_ptr && xfer_cnt;
}
@@ -71,7 +71,9 @@ public:
}
protected:
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
bool is_selected() const {
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
}
void prepare_xfer(int xfer_size, int block_size);
@@ -82,7 +84,7 @@ protected:
IdeChannel* host_obj = nullptr;
// IDE aka task file registers
uint8_t r_error;
uint8_t r_error = 0;
uint8_t r_features;
uint8_t r_sect_count;
uint8_t r_sect_num;
+3
View File
@@ -120,6 +120,7 @@ enum ATA_Cmd : uint8_t {
NOP = 0x00,
ATAPI_SOFT_RESET = 0x08,
RECALIBRATE = 0x10,
ATAPI_COMMAND_MODE_SENSE6 = 0x1A,
READ_SECTOR = 0x20,
READ_SECTOR_NR = 0x21,
READ_LONG = 0x22,
@@ -128,6 +129,7 @@ enum ATA_Cmd : uint8_t {
WRITE_SECTOR_NR = 0x31,
WRITE_LONG = 0x32,
READ_VERIFY = 0x40,
ATAPI_COMMAND_GET_CONFIG = 0x46,
FORMAT_TRACKS = 0x50,
IDE_SEEK = 0x70,
DIAGNOSTICS = 0x90,
@@ -135,6 +137,7 @@ enum ATA_Cmd : uint8_t {
ATAPI_PACKET = 0xA0,
ATAPI_IDFY_DEV = 0xA1,
ATAPI_SERVICE = 0xA2,
ATAPI_READ_DVD_STRUCTURE = 0xAD,
READ_MULTIPLE = 0xC4,
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
+5 -4
View File
@@ -326,11 +326,12 @@ done:
heads, sectors);
}
static const PropMap AtaHardDiskProperties = {
static const PropMap AtaHardDisk_Properties = {
{"hdd_img", new StrProperty("")},
};
static const DeviceDescription AtaHardDiskDescriptor =
{AtaHardDisk::create, {}, AtaHardDiskProperties};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties
};
REGISTER_DEVICE(AtaHardDisk, AtaHardDiskDescriptor);
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
+5 -5
View File
@@ -29,15 +29,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#define ATA_HD_SEC_SIZE 512
#define SECTORS_PER_INT 16
constexpr auto ATA_HD_SEC_SIZE = 512;
constexpr auto SECTORS_PER_INT = 16;
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
#define ATA_BIOS_LIMIT 16514064
constexpr auto ATA_BIOS_LIMIT = 16514064;
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
#define REAL_CHS_LIMIT 267382800
constexpr auto REAL_CHS_LIMIT = 267382800;
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
#define CHS_LIMIT 267386880
constexpr auto CHS_LIMIT = 267386880;
class AtaHardDisk : public AtaBaseDevice
{
-1
View File
@@ -87,7 +87,6 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
return this->r_dev_head;
case ATA_Reg::STATUS:
this->update_intrq(0);
return this->r_status;
case ATA_Reg::ALT_STATUS:
if (this->r_status & BSY && this->data_available()) {
this->r_byte_count = this->request_data();
+71 -8
View File
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <string>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -132,8 +133,19 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_6:
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_10:
this->xfer_cnt = this->mode_sense_ex(this->cmd_pkt, this->data_buf);
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
@@ -146,6 +158,14 @@ void AtapiCdrom::perform_packet_command() {
case ScsiCommand::READ_6:
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
xfer_len = this->cmd_pkt[4];
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -157,8 +177,23 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
break;
case ScsiCommand::READ_10:
if (this->xfer_cnt > 0) {
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -167,11 +202,24 @@ void AtapiCdrom::perform_packet_command() {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_out_phase();
#if 0
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
#else
this->data_out_phase();
#endif
break;
case ScsiCommand::READ_12:
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -192,6 +240,18 @@ void AtapiCdrom::perform_packet_command() {
{
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
// Treat as a non-data command.
xfer_len = 0;
}
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
this->name.c_str(),
@@ -230,7 +290,8 @@ void AtapiCdrom::perform_packet_command() {
else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
int disk_image_byte_count_partial_block =
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
}
@@ -241,7 +302,8 @@ void AtapiCdrom::perform_packet_command() {
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog + (disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count
}
@@ -371,11 +433,12 @@ void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->r_status |= ATA_Status::ERR;
}
static const PropMap AtapiCdromProperties = {
static const PropMap AtapiCdrom_Properties = {
{"cdr_img", new StrProperty("")},
};
static const DeviceDescription AtapiCdromDescriptor =
{AtapiCdrom::create, {}, AtapiCdromProperties};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties
};
REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
+238
View File
@@ -0,0 +1,238 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 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/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller emulation. */
#include <devices/common/ata/cmd646.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
CmdIdeCtrl::CmdIdeCtrl() : PCIDevice("cmd-ide") {
this->supports_types(HWCompType::PCI_DEV | HWCompType::IDE_HOST);
// set up PCI configuration space header
this->vendor_id = this->subsys_vndr = PCI_VENDOR_SILICON_IMAGE;
this->device_id = this->subsys_id = DEV_ID_CMD646;
this->class_rev = ((MY_DEV_CLASS | this->prog_if) << 8) | MY_REV_ID;
this->max_lat = 4;
this->min_gnt = 2;
this->irq_pin = 1;
this->bars_cfg[0] = 0xFFFFFFF9; // Command block I/O space, primary channel
this->bars_cfg[1] = 0xFFFFFFFD; // Control block I/O space, primary channel
this->bars_cfg[2] = 0xFFFFFFF9; // Command block I/O space, secondary channel
this->bars_cfg[3] = 0xFFFFFFFD; // Control block I/O space, secondary channel
this->bars_cfg[4] = 0xFFFFFFF1; // Bus master I/O space, both channels
this->finish_config_bars();
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
gMachineObj->add_device("CmdAta0", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta0")));
gMachineObj->add_device("CmdAta1", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta1")));
this->ch0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta0"));
this->ch1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta1"));
this->ch0->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta0 INTRQ updated to %d", intrq_state);
this->update_irq(0, intrq_state);
});
this->ch1->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta1 INTRQ updated to %d", intrq_state);
this->update_irq(1, intrq_state);
});
}
uint32_t CmdIdeCtrl::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
if (reg_offs < 64)
return PCIDevice::pci_cfg_read(reg_offs, details);
if (details.size != 1)
ABORT_F("%s: non-byte read from PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
return this->read_config_reg(reg_offs + details.offset);
LOG_F(WARNING, "%s: reading config reg at 0x%X", this->name.c_str(), reg_offs);
return 0;
}
void CmdIdeCtrl::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) {
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, details);
return;
}
if (details.size != 1)
ABORT_F("%s: non-byte write to PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
this->write_config_reg(reg_offs + details.offset, value);
else
LOG_F(WARNING, "%s: writing config reg at 0x%X", this->name.c_str(), reg_offs);
}
void CmdIdeCtrl::notify_bar_change(int bar_num) {
if (bar_num >= 0 && bar_num <= 4)
this->io_bases[bar_num] = this->bars[bar_num] & ~3;
}
bool CmdIdeCtrl::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
*res = 0;
if ((offset & ~7) == this->io_bases[0]) {
*res = this->ch0->read(offset & 7, size);
} else if ((offset & ~7) == this->io_bases[2]) {
*res = this->ch1->read(offset & 7, size);
} else if ((offset & ~3) == this->io_bases[1]) {
*res = this->ch0->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~3) == this->io_bases[3]) {
*res = this->ch1->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
*res = this->read_bus_master_reg(offset & 0xF);
} else {
*res = 0xFFFFFFFFUL;
return false;
}
return true;
}
bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
if ((offset & ~7) == this->io_bases[0]) {
this->ch0->write(offset & 7, value, size);
} else if ((offset & ~7) == this->io_bases[2]) {
this->ch1->write(offset & 7, value, size);
} else if ((offset & ~3) == this->io_bases[1]) {
this->ch0->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~3) == this->io_bases[3]) {
this->ch1->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
this->write_bus_master_reg(offset & 0xF, value & 0xFFU);
} else
return false;
return true;
};
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
case ARTTIM0:
return this->addr_setup_time_0;
case DRWTIM0:
return this->data_rw_time_0;
case ARTTIM1:
return this->addr_setup_time_1;
case DRWTIM1:
return this->data_rw_time_1;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_config_reg(uint32_t reg_offset, uint8_t val) {
switch(reg_offset) {
case ARTTIM0:
this->addr_setup_time_0 = val;
LOG_F(9, "%s: ARTTIM0 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM0:
this->data_rw_time_0 = val;
LOG_F(9, "%s: DRWTIM0 set to 0x%X", this->name.c_str(), val);
break;
case ARTTIM1:
this->addr_setup_time_1 = val;
LOG_F(9, "%s: ARTTIM1 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM1:
this->data_rw_time_1 = val;
LOG_F(9, "%s: DRWTIM1 set to 0x%X", this->name.c_str(), val);
break;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
uint8_t CmdIdeCtrl::read_bus_master_reg(const uint8_t reg_offset) {
switch(reg_offset) {
case MRDMODE:
return this->mrdmode;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_bus_master_reg(const uint8_t reg_offset, const uint8_t val) {
switch(reg_offset) {
case MRDMODE:
if (val & BM_CH0_INT)
this->mrdmode &= ~BM_CH0_INT;
if (val & BM_CH1_INT)
this->mrdmode &= ~BM_CH1_INT;
this->mrdmode = (this->mrdmode & ~(BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT)) |
(val & (BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT));
LOG_F(INFO, "%s: MRDMODE set to 0x%X", this->name.c_str(), val);
if ((this->mrdmode & BM_CH0_INT) && !(this->mrdmode & BM_BLOCK_CH0_INT))
this->update_irq(0, 1);
if ((this->mrdmode & BM_CH1_INT) && !(this->mrdmode & BM_BLOCK_CH1_INT))
this->update_irq(1, 1);
break;
case UDIDETCR0:
this->udma_time_cr = val;
break;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
void CmdIdeCtrl::update_irq(const int ch_num, const uint8_t irq_level) {
bool forward_irq = !(this->mrdmode & (ch_num ? BM_BLOCK_CH1_INT : BM_BLOCK_CH0_INT));
if (irq_level)
this->mrdmode |= ch_num ? BM_CH1_INT : BM_CH0_INT;
else
this->mrdmode &= ~(ch_num ? BM_CH1_INT : BM_CH0_INT);
if (!irq_level || forward_irq)
this->pci_interrupt(irq_level);
}
static const DeviceDescription CmdIde_Descriptor = {
CmdIdeCtrl::create, {}, {}
};
REGISTER_DEVICE(CmdAta, CmdIde_Descriptor);
+108
View File
@@ -0,0 +1,108 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 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/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller definitions. */
#ifndef CMD646_IDE_H
#define CMD646_IDE_H
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/pci/pcidevice.h>
#include <memory>
constexpr auto DEV_ID_CMD646 = 0x646;
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master
constexpr auto MY_REV_ID = 7;
// Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14;
/** CMD646 control/status registers. */
enum {
ARTTIM0 = 0x53,
DRWTIM0 = 0x54,
ARTTIM1 = 0x55,
DRWTIM1 = 0x56,
};
/** CMD646 bus master registers. */
enum {
MRDMODE = 1, // misnomer, contains interrupt control/status bits (CMD646U2 specific)
UDIDETCR0 = 3, // Ultra DMA timing control register (CMD646U2 specific)
};
/** Bit definitions for the MRDMODE register. */
enum {
BM_CH0_INT = 1 << 2,
BM_CH1_INT = 1 << 3,
BM_BLOCK_CH0_INT = 1 << 4,
BM_BLOCK_CH1_INT = 1 << 5,
};
class CmdIdeCtrl : public PCIDevice {
public:
CmdIdeCtrl();
~CmdIdeCtrl() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<CmdIdeCtrl>(new CmdIdeCtrl());
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) override;
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) override;
private:
void notify_bar_change(int bar_num);
uint8_t read_config_reg(uint32_t reg_offset);
void write_config_reg(uint32_t reg_offset, uint8_t val);
uint8_t read_bus_master_reg(const uint8_t reg_offset);
void write_bus_master_reg(const uint8_t reg_offset, const uint8_t val);
void update_irq(const int ch_num, const uint8_t irq_level);
// on reset, programming interface defaults to
// "both channels operating in native mode"
uint8_t prog_if = 0x0F;
uint32_t io_bases[5] = {};
IdeChannel *ch0 = nullptr;
IdeChannel *ch1 = nullptr;
// unknown default, set it to 2 clocks (60 ns)
uint8_t addr_setup_time_0 = 0x40; // address setup time for drive 0
uint8_t addr_setup_time_1 = 0x40; // address setup time for drive 1
uint8_t data_rw_time_0 = 0x00; // data read/write time for drive 0
uint8_t data_rw_time_1 = 0x00; // data read/write time for drive 1
uint8_t mrdmode = 0;
uint8_t udma_time_cr = 0;
};
#endif // CMD646_IDE_H
+1 -1
View File
@@ -95,7 +95,7 @@ private:
// interrupt stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t irq_id = 0;
};
#endif // IDE_CHANNEL_H
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters.
*/
#include <devices/common/i2c/athens.h>
#include <devices/common/clockgen/athens.h>
#include <loguru.hpp>
#include <algorithm>
@@ -118,7 +118,7 @@ int AthensClocks::get_dot_freq()
return 0;
}
float out_freq = 0.0f;
float out_freq = 50000000.0; // for 800x600 72Hz
int d2 = this->regs[AthensRegs::D2];
int n2 = this->regs[AthensRegs::N2];
@@ -150,7 +150,7 @@ int AthensClocks::get_dot_freq()
break;
}
LOG_F(INFO, "%s: dot clock frequency set to %f Hz", this->name.c_str(), out_freq);
LOG_F(INFO, "%s: dot clock frequency set to %f MHz", this->name.c_str(), out_freq / 1000000.0);
return static_cast<int>(out_freq + 0.5f);
}
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#define ATHENS_NUM_REGS 8
constexpr auto ATHENS_NUM_REGS = 8;
/** Default external crystal oscillator frequency. */
constexpr auto ATHENS_XTAL = 31334400.0f;
+79 -20
View File
@@ -88,7 +88,7 @@ uint8_t DMAChannel::interpret_cmd() {
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
break;
}
this->queue_len = cmd_struct.req_count;
this->queue_len = cmd_struct.req_count;
if (this->queue_len) {
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
this->queue_data = res.host_va;
@@ -97,6 +97,7 @@ uint8_t DMAChannel::interpret_cmd() {
switch (this->cur_cmd) {
case DBDMA_Cmd::OUTPUT_MORE:
case DBDMA_Cmd::OUTPUT_LAST:
this->xfer_to_device();
if (this->out_cb)
this->out_cb();
break;
@@ -131,6 +132,7 @@ uint8_t DMAChannel::interpret_cmd() {
case DBDMA_Cmd::STOP:
this->ch_stat &= ~CH_STAT_ACTIVE;
this->cmd_in_progress = false;
this->finish_cmd();
break;
default:
LOG_F(ERROR, "%s: Unsupported DMA command 0x%X", this->get_name().c_str(),
@@ -170,9 +172,7 @@ void DMAChannel::finish_cmd() {
return;
}
if (res.is_writable)
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
this->ch_stat &= ~CH_STAT_FLUSH;
this->ch_stat &= ~CH_STAT_BT;
// react to cmd.b (branch) bits
if (cmd_desc[2] & 0xC) {
@@ -187,21 +187,29 @@ void DMAChannel::finish_cmd() {
if (cond) {
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
branch_taken = true;
this->ch_stat |= CH_STAT_BT;
}
}
this->update_irq();
if (res.is_writable)
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
}
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
this->res_count = 0;
}
if (!branch_taken)
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
this->cmd_ptr += 16;
if (this->cur_cmd < DBDMA_Cmd::STOP) {
this->update_irq();
}
this->cmd_in_progress = false;
}
@@ -293,24 +301,27 @@ void DMAChannel::update_irq() {
}
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
if (size != 4) {
ABORT_F("%s: non-DWORD read from a DMA channel not supported",
this->get_name().c_str());
}
uint32_t result = 0;
switch (offset) {
switch (offset & ~3) {
case DMAReg::CH_CTRL:
return 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
result = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
break;
case DMAReg::CH_STAT:
return BYTESWAP_32(this->ch_stat);
result = this->ch_stat;
break;
case DMAReg::CMD_PTR_LO:
return BYTESWAP_32(this->cmd_ptr);
result = this->cmd_ptr;
break;
default:
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
this->get_name().c_str(), offset);
}
return 0;
if ((offset & 3) || size != 4)
return BYTESWAP_SIZED(result >> ((offset & 3) * 8), size);
else
return BYTESWAP_32(result);
}
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
@@ -327,7 +338,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
switch (offset) {
case DMAReg::CH_CTRL:
mask = value >> 16;
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~(mask & 0xC0FF));
LOG_F(9, "%s: New ChannelStatus value = 0x%X", this->get_name().c_str(), new_stat);
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
@@ -365,9 +376,13 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
this->ch_stat = new_stat;
}
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
if (new_stat & CH_STAT_WAKE) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
} else {
LOG_F(ERROR, "%s: Attempt to clear wake status bit 0x%04x", this->get_name().c_str(), CH_STAT_WAKE);
}
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
if (new_stat & CH_STAT_PAUSE) {
new_stat &= ~CH_STAT_ACTIVE;
@@ -412,7 +427,8 @@ void DMAChannel::xfer_from_device() {
this->xfer_dir = DMA_DIR_FROM_DEV;
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
}
@@ -420,6 +436,39 @@ void DMAChannel::xfer_from_device() {
this->interpret_cmd();
}
void DMAChannel::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
}
this->interpret_cmd();
}
void DMAChannel::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
bool DMAChannel::is_ready() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
return false;
return true;
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
@@ -543,6 +592,7 @@ void DMAChannel::start() {
if (this->ch_stat & CH_STAT_PAUSE) {
LOG_F(WARNING, "%s: Cannot start DMA channel, PAUSE bit is set",
this->get_name().c_str());
this->ch_stat &= ~CH_STAT_ACTIVE; // TODO: Test this in Open Firmware.
return;
}
@@ -571,6 +621,15 @@ void DMAChannel::resume() {
}
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
// some DBDMA programs contain commands that don't transfer data
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
// We thus interprete the DBDMA program until a data transfer between
// a device and memory is queued or the channel becomes idle/dead.
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
(this->ch_stat & CH_STAT_ACTIVE)) {
this->interpret_cmd();
}
}
void DMAChannel::abort() {
+14 -10
View File
@@ -114,16 +114,19 @@ public:
void reg_write(uint32_t offset, uint32_t value, int size);
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
bool is_out_active();
bool is_in_active();
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
int push_data(const char* src_ptr, int len);
int get_pull_data_remaining() { return this->queue_len; }
int get_push_data_remaining() { return this->queue_len; }
void end_pull_data();
void end_push_data();
bool is_out_active() override;
bool is_in_active() override;
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
int push_data(const char* src_ptr, int len) override;
int get_pull_data_remaining() override { return this->queue_len; }
int get_push_data_remaining() override { return this->queue_len; }
void end_pull_data() override;
void end_push_data() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
bool is_ready() override;
void xfer_retry() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
this->int_ctrl = int_ctrl_obj;
this->irq_id = irq_id;
};
@@ -135,6 +138,7 @@ protected:
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
void update_irq();
void xfer_from_device();
void xfer_to_device();
void start(void);
void resume(void);
@@ -162,7 +166,7 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t irq_id = 0;
};
#endif // DB_DMA_H
+10 -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)
@@ -96,9 +96,11 @@ public:
DmaDevice() = default;
~DmaDevice() = default;
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
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;
@@ -109,8 +111,10 @@ public:
DmaChannel() = default;
~DmaChannel() = default;
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
void notify(DmaMsg msg) {};
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;
+27 -5
View File
@@ -30,9 +30,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enum IntSrc : uint32_t {
INT_UNKNOWN = 0,
VIA_CUDA,
VIA2,
SCSI_MESH,
SCSI_CURIO,
SWIM3,
ESCC,
SCCA,
SCCB,
ETHERNET,
@@ -58,6 +60,7 @@ enum IntSrc : uint32_t {
PLANB,
VCI,
PLATINUM,
DMA_ALL,
DMA_SCSI_MESH,
DMA_SCSI_CURIO,
DMA_SWIM3,
@@ -71,6 +74,25 @@ enum IntSrc : uint32_t {
DMA_DAVBUS_Rx,
DMA_ETHERNET_Tx,
DMA_ETHERNET_Rx,
FIREWIRE,
PCI_J12,
PCI_J11,
PCI_J10,
PCI_J9,
ATA,
USB,
PIPPIN_E,
PIPPIN_F,
ZIVA,
PCI_CARDBUS,
MEDIA_BAY,
SLOT_ALL,
SLOT_0,
SLOT_1,
SLOT_2,
SLOT_PDS,
SLOT_VDS,
VBL,
};
/** Base class for interrupt controllers. */
@@ -80,17 +102,17 @@ public:
virtual ~InterruptCtrl() = default;
// register interrupt sources for a device
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
virtual uint64_t register_dev_int(IntSrc src_id) = 0;
virtual uint64_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
};
typedef struct {
InterruptCtrl *int_ctrl_obj;
uint32_t irq_id;
uint64_t irq_id;
} IntDetails;
#endif // HW_INTERRUPT_H
+6 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -27,11 +27,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <stdexcept>
#include <cstring>
#include <string>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept>
#include <string>
/** Base class for I2C devices */
class I2CDevice {
public:
+1 -1
View File
@@ -40,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
Machine ID register for Nubus Power Macs.
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)
+156
View File
@@ -0,0 +1,156 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <fstream>
#include <sstream>
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
{
uint32_t sum = 0;
for (int i = 0; i < length; i++) {
// rotate sum left by one bit
if (sum & 0x80000000UL)
sum = (sum << 1) | 1;
else
sum = (sum << 1) | 0;
sum += data_ptr[i];
}
return sum;
}
int load_declaration_rom(const std::string rom_path, int slot_num)
{
std::ifstream rom_file;
int result = 0;
try {
rom_file.open(rom_path, std::ios::in | std::ios::binary);
if (rom_file.fail())
throw std::runtime_error("could not open declaration ROM image " + rom_path);
// determine image size
rom_file.seekg(0, std::ios::end);
uint64_t rom_size = rom_file.tellg();
if (rom_size > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// load it
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
rom_file.seekg(0, std::ios::beg);
rom_file.read((char *)rom_data.get(), rom_size);
// verify image data
uint8_t byte_lane = rom_data[rom_size - 1];
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF))
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid byte lane value");
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL)
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid test pattern");
if (rom_data[rom_size - 7] != 1)
throw std::runtime_error("declaration ROM image " + rom_path +
" has unsupported format");
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
// patch the CRC field of the format header to 0
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
// restore the CRC field value
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
if (test_crc != crc) {
std::stringstream err;
err << "declaration ROM image " + rom_path + " has invalid CRC, expected = 0x"
<< std::hex << crc << ", got = 0x" << std::hex << test_crc;
throw std::runtime_error(err.str());
}
int lanes_used = 0;
// count meaningful lanes in a data quad
for (int i = 0; i < 4; i++) {
if (byte_lane & (1 << i))
lanes_used++;
}
// padded_len is the size in bytes of all pages needed to contain all the bytes of the ROM
uint32_t padded_len =
uint32_t(((rom_size * 4 + lanes_used - 1) / lanes_used + 4095) / 4096 * 4096);
if (padded_len > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// calculate starting physical address of the ROM
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len))
throw std::runtime_error("could not allocate ROM space for declaration ROM image " +
rom_path);
int data_pos = int(rom_size) - 1;
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
// prepare new ROM data by copying over used lanes
// and padding unused lanes with 0xFF
// NOTE: speed uncritical - don't optimize!
for (int i = padded_len - 1; i >= 0; ) {
for (int b = 8; i>= 0 && b != 0; b >>= 1) {
if (data_pos >= 0 && (byte_lane & b))
new_data[i--] = rom_data[data_pos--];
else
new_data[i--] = 0xFF;
}
}
// move padded ROM data to the memory region
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
result = -1;
}
rom_file.close();
return result;
}
+30
View File
@@ -0,0 +1,30 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef NUBUS_UTILS_H
#define NUBUS_UTILS_H
#include <cinttypes>
#include <string>
int load_declaration_rom(const std::string rom_path, int slot_num);
#endif // NUBUS_UTILS_H
+5
View File
@@ -19,6 +19,7 @@ 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/nvram.h>
#include <devices/deviceregistry.h>
@@ -81,6 +82,10 @@ void NVram::init() {
}
void NVram::save() {
if (is_deterministic) {
LOG_F(INFO, "Skipping NVRAM write to \"%s\" in deterministic mode", this->file_name.c_str());
return;
}
ofstream f(this->file_name, ios::out | ios::binary);
/* write file identification */
+8 -9
View File
@@ -41,7 +41,7 @@ using namespace std;
static std::string hex2str(uint32_t n)
{
std::stringstream ss;
ss << setw(8) << setfill('0') << hex << n;
ss << setw(8) << right << setfill('0') << hex << n;
return ss.str();
}
@@ -322,6 +322,9 @@ bool OfConfigChrp::validate()
bool wip = true;
bool of_part_found = false;
if (this->nvram_obj == nullptr)
return false;
// search the entire 8KB NVRAM for CHRP OF config partition.
// Bail out if an unknown partition or free space is encountered.
// Skip over known partitions.
@@ -588,20 +591,16 @@ void OfConfigUtils::printenv() {
ReplaceAll(val, "\r\n", "\n");
ReplaceAll(val, "\r", "\n");
ReplaceAll(val, "\n", "\n "); // 34 spaces
cout << setw(34) << left << var.first << val << endl; // name column has width 34
cout << setw(34) << left << var.first << val << right << endl; // name column has width 34
}
}
void OfConfigUtils::setenv(string var_name, string value)
bool OfConfigUtils::setenv(string var_name, string value)
{
if (!this->open_container())
return;
return false;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
if (!this->cfg_impl->set_var(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
return this->cfg_impl->set_var(var_name, value);
}
+4 -4
View File
@@ -33,9 +33,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class NVram;
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
#define OF_NVRAM_OFFSET 0x1800
#define OF_NVRAM_SIG 0x1275
#define OF_CFG_SIZE 0x800
constexpr auto OF_NVRAM_OFFSET = 0x1800;
constexpr auto OF_NVRAM_SIG = 0x1275;
constexpr auto OF_CFG_SIZE = 0x800;
// OF Variable types
enum {
@@ -134,7 +134,7 @@ public:
int init();
void printenv();
void setenv(std::string var_name, std::string value);
bool setenv(std::string var_name, std::string value);
protected:
bool open_container();
+91 -48
View File
@@ -122,7 +122,7 @@ void BanditPciDevice::verbose_address_space()
return;
}
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
LOG_F(INFO, "%s address spaces:", this->get_name().c_str());
// verbose coarse aka 256MB memory regions
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
@@ -143,8 +143,21 @@ void BanditPciDevice::verbose_address_space()
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
{
switch (offset >> 22) {
case 3: // CONFIG_DATA
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
return pci_io_read_broadcast(offset & 0x007FFFFF, size);
case 4:
case 5:
// CONFIG_ADDR
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
case 6:
// CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
@@ -160,18 +173,46 @@ uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
LOG_READ_NON_EXISTENT_PCI_DEVICE();
return 0xFFFFFFFFUL; // PCI spec §6.1
case 2: // CONFIG_ADDR
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
case 7:
// Interrupt
LOG_F(ERROR, "%s: Interrupt Acknowledge Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
break;
default: // I/O space
return pci_io_read_broadcast(offset, size);
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
}
return 0;
}
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
switch (offset >> 22) {
case 3: // CONFIG_DATA
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
pci_io_write_broadcast(offset & 0x007FFFFF, size, value);
break;
case 4:
case 5:
// CONFIG_ADDR
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
break;
case 6:
// CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
@@ -192,12 +233,23 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
break;
case 2: // CONFIG_ADDR
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
case 7:
// Special
LOG_F(ERROR, "%s: Special Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
break;
default: // I/O space
pci_io_write_broadcast(offset, size, value);
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
}
}
@@ -235,32 +287,7 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
}
int BanditHost::device_postinit() {
std::string pci_dev_name;
static const std::map<std::string, int> pci_slots1 = {
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
};
static const std::map<std::string, int> pci_slots2 = {
{"pci_D2", DEV_FUN(0xD,0)}, {"pci_E2", DEV_FUN(0xE,0)}, {"pci_F2", DEV_FUN(0xF,0)}
};
static const std::map<std::string, int> vci_slots = {
{"vci_D", DEV_FUN(0xD,0)}, {"vci_E", DEV_FUN(0xE,0)}, {"vci_F", DEV_FUN(0xF,0)}
};
for (auto& slot :
this->bridge_num == 0 ? vci_slots :
this->bridge_num == 1 ? pci_slots1 :
this->bridge_num == 2 ? pci_slots2 :
pci_slots1
) {
pci_dev_name = GET_STR_PROP(slot.first);
if (!pci_dev_name.empty()) {
this->attach_pci_device(pci_dev_name, slot.second);
}
}
return 0;
return this->pcihost_device_postinit();
}
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
@@ -277,14 +304,15 @@ Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
// add memory mapped I/O region for Bandit control registers
// This region has the following layout:
// base_addr + 0x000000 --> I/O space
// base_addr + 0x800000 --> CONFIG_ADDR
// base_addr + 0xC00000 --> CONFIG_DATA
// base_addr + 0x1000000 --> pass-through memory space (not included below)
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
// base_addr + 0x00000000 --> I/O space
// base_addr + 0x00800000 --> CONFIG_ADDR
// base_addr + 0x00C00000 --> CONFIG_DATA
// base_addr + 0x00E00000 --> Special(W)/Interrupt(R)
// base_addr + 0x01000000 --> pass-through memory space ; grandcentral exists here for pci1
mem_ctrl->add_mmio_region(base_addr, bridge_num == 1 ? 0x01000000 : 0x02000000, this);
// connnect Bandit PCI device
this->my_pci_device = unique_ptr<BanditPciDevice>(
this->my_pci_device = std::unique_ptr<BanditPciDevice>(
new BanditPciDevice(bridge_num, name, dev_id, rev)
);
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
@@ -346,8 +374,23 @@ static const PropMap Chaos_Properties = {
new StrProperty("")},
{"vci_E",
new StrProperty("")},
{"vci_F",
};
static const PropMap PsxPci1_Properties = {
{"pci_A1",
new StrProperty("")},
{"pci_B1",
new StrProperty("")},
{"pci_C1",
new StrProperty("")},
{"pci_E1",
new StrProperty("")},
{"pci_F1",
new StrProperty("")},
};
static const std::vector<std::string> Chaos_Subdevices = {
"ControlVideo"
};
static const DeviceDescription Bandit1_Descriptor = {
@@ -359,11 +402,11 @@ static const DeviceDescription Bandit2_Descriptor = {
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, Bandit1_Properties
Bandit::create_psx_first, {}, PsxPci1_Properties
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, {}, Chaos_Properties
Chaos::create, Chaos_Subdevices, Chaos_Properties
};
static const DeviceDescription AspenPci1_Descriptor = {
+5 -8
View File
@@ -46,8 +46,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
#define BANDIT_DEV (11) // Bandit's own device number
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
constexpr auto BANDIT_DEV = 11; // Bandit's own device number
constexpr auto BANDIT_CAR_TYPE = 1 << 0; // Bandit config address type bit
/* Convenient macros for parsing CONFIG_ADDR fields. */
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
@@ -73,14 +73,11 @@ class BanditHost : public PCIHost, public MMIODevice {
public:
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
// PCIHost methods
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
// 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;
int device_postinit();
int device_postinit() override;
protected:
uint32_t config_addr;
+20
View File
@@ -86,8 +86,28 @@ void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetail
}
}
static const PropMap Dec21154Yosemite_Properties = {
{"pci_FireWire",
new StrProperty("")},
{"pci_UltraATA",
new StrProperty("")},
{"pci_J11",
new StrProperty("")},
{"pci_J10",
new StrProperty("")},
{"pci_J9",
new StrProperty("")},
{"pci_USB",
new StrProperty("")},
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
REGISTER_DEVICE(Dec21154Yosemite, Dec21154Yosemite_Descriptor);
+4
View File
@@ -44,6 +44,10 @@ public:
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154"));
}
static std::unique_ptr<HWComponent> create_yosemite() {
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154Yosemite"));
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
+28 -9
View File
@@ -32,7 +32,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
{
this->name = name;
this->pci_name = name;
this->hdr_type = hdr_type;
this->num_bars = num_bars;
@@ -162,17 +161,17 @@ int PCIBase::attach_exp_rom_image(const std::string img_path)
if (exp_rom_image_size == this->exp_rom_size) {
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
this->pci_name.c_str(), this->exp_rom_size);
this->get_name().c_str(), this->exp_rom_size);
}
else {
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
this->pci_name.c_str(), (int)exp_rom_image_size, this->exp_rom_size);
this->get_name().c_str(), (int)exp_rom_image_size, this->exp_rom_size);
}
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "%s: %s", this->pci_name.c_str(), exc.what());
LOG_F(ERROR, "%s: %s", this->get_name().c_str(), exc.what());
result = -1;
}
@@ -192,7 +191,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->pci_name.c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
}
break;
@@ -201,7 +201,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->pci_name.c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
}
break;
@@ -239,11 +240,11 @@ void PCIBase::finish_config_bars()
case 2:
if (bar_num >= num_bars - 1) {
ABORT_F("%s: BAR %d cannot be 64-bit",
this->pci_name.c_str(), bar_num);
this->get_name().c_str(), bar_num);
}
else if (this->bars_cfg[bar_num+1] == 0) {
ABORT_F("%s: 64-bit BAR %d has zero for upper 32 bits",
this->pci_name.c_str(), bar_num);
this->get_name().c_str(), bar_num);
}
else {
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
@@ -252,7 +253,7 @@ void PCIBase::finish_config_bars()
break;
default:
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
this->pci_name.c_str(), pci_space_type, bar_num);
this->get_name().c_str(), pci_space_type, bar_num);
} // switch pci_space_type
}
} // for bar_num
@@ -302,3 +303,21 @@ void PCIBase::pci_wr_exp_rom_bar(uint32_t data)
}
}
}
void PCIBase::pci_interrupt(uint8_t irq_line_state) {
if (!(this->command & 0x0400)) {
if (!this->int_details.int_ctrl_obj)
this->host_instance->register_pci_int(this);
if (this->int_details.int_ctrl_obj && this->int_details.irq_id)
this->int_details.int_ctrl_obj->ack_int(this->int_details.irq_id, irq_line_state);
else
LOG_F(ERROR, "Unhandled interrupt from device %s", this->get_name().c_str());
/* A pci device should set the interrupt status bit when an interrupt occurs
* and it should clear the interrupt status bit when its interrupt bits are cleared.
* The interrupt status bit is new to PCI Local Bus Specification Revision 2.3
* and Power Macs use PCI Local Bus Specification Revision 2.0. Some PCI cards
* might not implement this bit.
*/
//this->status |= 0x0008;
}
}
+16 -9
View File
@@ -47,16 +47,19 @@ enum {
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2)
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0); Bridge Control (Type 1 and 2); Int_Pin and Int_Line registers (type 0, 1, and 2)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
// Bridge Control (Type 1 and 2)
// Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
enum {
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_NVIDIA = 0x10DE,
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_SILICON_IMAGE = 0x1095,
PCI_VENDOR_NVIDIA = 0x10DE,
};
/** PCI BAR types */
@@ -76,6 +79,7 @@ typedef struct {
} BarConfig;
class PCIBase : public MMIODevice {
friend class PCIHost;
public:
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
virtual ~PCIBase() = default;
@@ -125,10 +129,12 @@ public:
this->irq_pin = irq_pin;
}
virtual void pci_interrupt(uint8_t irq_line_state) {
this->host_instance->pci_interrupt(irq_line_state, this);
virtual void set_int_details(IntDetails &int_details) {
this->int_details = int_details;
}
virtual void pci_interrupt(uint8_t irq_line_state);
// MMIODevice methods
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
@@ -141,7 +147,6 @@ protected:
void map_exp_rom_mem();
void unmap_exp_rom_mem();
std::string pci_name; // human-readable device name
PCIHost* host_instance; // host bridge instance to call back
// PCI configuration space state (type 0, 1, and 2)
@@ -174,6 +179,8 @@ protected:
// 0 = not writable; 1 = bit is enabled in command register
uint16_t command_cfg = 0xffff - (1<<3) - (1<<7); // disable: special cycles and stepping
IntDetails int_details = { 0 };
};
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
+6 -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)
@@ -42,7 +42,7 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
};
bool PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
// FIXME: constrain region to memory range
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
@@ -85,3 +85,7 @@ void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetai
return PCIBase::pci_cfg_write(reg_offs, value, details);
}
}
int PCIBridgeBase::device_postinit() {
return this->pcihost_device_postinit();
}
+9 -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)
@@ -43,14 +43,14 @@ public:
~PCIBridgeBase() = default;
// PCIHost methods
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool supports_io_space() {
bool supports_io_space() override {
return true;
};
@@ -68,6 +68,9 @@ public:
std::function<uint16_t()> pci_rd_bridge_control;
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit() override;
protected:
// PCI configuration space state
uint8_t primary_bus = 0;
+56 -13
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)
@@ -23,13 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/pci/pcibridge.h>
#include <devices/common/pci/pcihost.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinefactory.h>
#include <machines/machinebase.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <cinttypes>
#include <cpu/ppc/ppcemu.h>
bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
{
@@ -75,18 +75,21 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
if (!this->dev_map.count(dev_fun_num)) {
return;
}
PCIBase* dev_instance = this->dev_map[dev_fun_num];
auto dev_instance = this->dev_map[dev_fun_num];
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor)",
// FIXME: need destructors to remove memory regions and downstream devices.
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs "
"a working destructor to unregister memory and downstream devices etc.)",
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
);
delete dev_instance;
this->dev_map.erase(dev_fun_num);
gMachineObj->remove_device(dev_instance); // calls destructor of dev_instance since it is a unique_ptr in the device_map.
}
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
AddressMapEntry* PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
@@ -119,9 +122,8 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
}
// attempt to create device object
MachineFactory::register_device_settings(dev_name);
auto desc = DeviceRegistry::get_descriptor(dev_name);
map<string, string> settings;
MachineFactory::get_device_settings(desc, settings);
auto dev_obj = desc.m_create_func();
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
@@ -138,6 +140,7 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
gMachineObj->add_device(dev_name + dev_suffix, std::move(dev_obj));
PCIBase *dev = dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
dev->set_name(dev->get_name() + dev_suffix);
// register device with the PCI host
this->pci_register_device(slot_id, dev);
@@ -145,7 +148,16 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
return dev;
}
IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
InterruptCtrl *PCIHost::get_interrupt_controller() {
if (!this->int_ctrl) {
InterruptCtrl *int_ctrl_obj =
dynamic_cast<InterruptCtrl*>(gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->int_ctrl = int_ctrl_obj;
}
return this->int_ctrl;
}
bool PCIHost::register_pci_int(PCIBase* dev_instance) {
bool dev_found = false;
int dev_fun_num = 0;
@@ -160,10 +172,24 @@ IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
ABORT_F("register_pci_int: requested device not found");
for (auto& irq : this->my_irq_map) {
if (irq.dev_fun_num == dev_fun_num)
return {this->int_ctrl, irq.irq_id};
if (irq.dev_fun_num == dev_fun_num) {
IntDetails new_int_detail;
new_int_detail.int_ctrl_obj = this->get_interrupt_controller();
if (new_int_detail.int_ctrl_obj && irq.int_src)
new_int_detail.irq_id = new_int_detail.int_ctrl_obj->register_dev_int(irq.int_src);
dev_instance->set_int_details(new_int_detail);
return true;
}
}
ABORT_F("register_pci_int: no IRQ map for device 0x%X", dev_fun_num);
PCIBridgeBase *self = dynamic_cast<PCIBridgeBase*>(this);
if (self) {
if (!self->int_details.int_ctrl_obj)
self->host_instance->register_pci_int(self);
dev_instance->set_int_details(self->int_details);
return true;
}
return false;
}
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
@@ -202,7 +228,8 @@ uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
SIZE_ARG(size)
);
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
// machine check exception (DEFAULT CATCH!, code=FFF00200)
ppc_exception_handler(Except_Type::EXC_MACHINE_CHECK, 0);
return 0;
}
@@ -245,3 +272,19 @@ PCIBase *PCIHost::pci_find_device(uint8_t dev_num, uint8_t fun_num)
}
return NULL;
}
int PCIHost::pcihost_device_postinit()
{
std::string pci_dev_name;
for (auto& slot : this->my_irq_map) {
if (slot.slot_name) {
pci_dev_name = GET_STR_PROP(slot.slot_name);
if (!pci_dev_name.empty()) {
this->attach_pci_device(pci_dev_name, slot.dev_fun_num, std::string("@") + slot.slot_name);
}
}
}
return 0;
}
+8 -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)
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/bitops.h>
#include <devices/common/hwinterrupt.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <cinttypes>
@@ -53,7 +54,7 @@ typedef struct AccessDetails {
typedef struct {
const char * slot_name;
int dev_fun_num;
uint32_t irq_id;
IntSrc int_src;
} PciIrqMap;
class PCIBase;
@@ -70,8 +71,8 @@ public:
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
virtual void pci_unregister_device(int dev_fun_num);
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
PCIBase *attach_pci_device(const std::string& dev_name, int slot_id,
@@ -86,16 +87,16 @@ public:
virtual PCIBase *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
virtual PCIBase *pci_find_device(uint8_t dev_num, uint8_t fun_num);
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
};
virtual int pcihost_device_postinit();
virtual IntDetails register_pci_int(PCIBase* dev_instance);
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:
std::unordered_map<int, PCIBase*> dev_map;
+250 -82
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)
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
@@ -72,14 +72,19 @@ void Sc53C94::reset_device()
this->data_fifo_pos = 0;
this->data_fifo[0] = 0;
this->sync_period = 5;
this->sync_offset = 0;
this->cur_step = 0;
this->seq_step = 0;
this->status = 0;
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
this->int_status = 0;
}
uint8_t Sc53C94::read(uint8_t reg_offset)
{
uint8_t status, int_status;
uint8_t bus_phase, int_flags;
switch (reg_offset) {
case Read::Reg53C94::Xfer_Cnt_LSB:
@@ -91,18 +96,25 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
case Read::Reg53C94::Command:
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
return (this->status & 0xF8) | status;
if (this->config2 & CFG2_ENF) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
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);
return (this->status & 0xF8) | bus_phase;
case Read::Reg53C94::Int_Status:
int_status = this->int_status;
this->seq_step = 0;
this->int_status = 0;
int_flags = this->int_status;
if (this->irq) {
this->status &= ~(STAT_GE | STAT_PE | STAT_GCV);
this->int_status = 0;
this->seq_step = 0;
}
this->update_irq();
return int_status;
return int_flags;
case Read::Reg53C94::Seq_Step:
return this->seq_step;
case Read::Reg53C94::FIFO_Flags:
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
case Read::Reg53C94::Config_1:
return this->config1;
case Read::Reg53C94::Config_3:
@@ -139,6 +151,9 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
case Write::Reg53C94::Sel_Timeout:
this->sel_timeout = value;
break;
case Write::Reg53C94::Sync_Period:
this->sync_period = value;
break;
case Write::Reg53C94::Sync_Offset:
this->sync_offset = value;
break;
@@ -243,9 +258,9 @@ void Sc53C94::update_command_reg(uint8_t cmd)
void Sc53C94::exec_command()
{
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & CMD_OPCODE;
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
this->is_dma_cmd = !!(this->cmd_fifo[0] & CMD_ISDMA);
if (this->is_dma_cmd) {
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
@@ -258,6 +273,8 @@ void Sc53C94::exec_command()
}
}
this->cmd_steps = nullptr; // assume a single-step command for now
// simple commands will be executed immediately
// complex commands will be broken into multiple steps
// and handled by the sequencer
@@ -290,9 +307,10 @@ void Sc53C94::exec_command()
my_timer_id = 0;
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
});
if (!(config1 & 0x40)) {
if (!(config1 & CFG1_DISR)) {
LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str());
this->int_status = INTSTAT_SRST;
this->update_irq();
}
exec_next_command();
break;
@@ -303,61 +321,86 @@ void Sc53C94::exec_command()
this->int_status = INTSTAT_ICMD;
this->update_irq();
} else {
this->seq_step = 0;
this->cmd_steps = nullptr;
this->cur_state = SeqState::XFER_BEGIN;
this->sequencer();
}
break;
case CMD_COMPLETE_STEPS:
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
{(CMD_COMPLETE_STEPS << 8) + 1, SeqState::RCV_STATUS, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 2, SeqState::RCV_MESSAGE, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 3, SeqState::CMD_COMPLETE, 0, INTSTAT_SR | INTSTAT_SO}
};
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
}
this->seq_step = 0;
this->cmd_steps = complete_steps_desc;
this->cur_state = this->cmd_steps->next_step;
this->cur_state = SeqState::RCV_STATUS;
this->sequencer();
break;
case CMD_MSG_ACCEPTED:
// Don't release ACK if ATN is asserted.
// Executing this command with ATN true means that
// the initiator wants to reject the current message.
// That should be recognized and handled by the target.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->is_initiator) {
this->bus_obj->target_next_step();
}
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
break;
case CMD_XFER_PAD_BYTES:
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
ABORT_F("%s: unsupported phase %d in CMD_XFER_PAD_BYTES",
this->name.c_str(), this->bus_obj->current_phase());
std::memset(this->data_fifo, 0, DATA_FIFO_MAX);
// FIXME: does the non-DMA version of this command use the transfer counter?
this->data_fifo_pos = std::min((int)this->set_xfer_count, DATA_FIFO_MAX);
this->cur_state = SeqState::SEND_CMD;
this->sequencer();
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND) {
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
}
break;
case CMD_RESET_ATN:
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
exec_next_command();
break;
case CMD_SELECT_NO_ATN:
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
{(CMD_SELECT_NO_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_NO_ATN << 8) + 2, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_NO_ATN << 8) + 3, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_no_atn_desc = new SeqDesc[2]{
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = 0;
this->seq_step = this->cur_step = 0;
this->cmd_steps = sel_no_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN:
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
{(CMD_SELECT_WITH_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_WITH_ATN << 8) + 2, SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 3, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 4, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_with_atn_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG, INTSTAT_SR | INTSTAT_SO},
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = 0;
this->seq_step = this->cur_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN_AND_STOP:
static SeqDesc * sel_with_atn_stop_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG_EX, INTSTAT_SR | INTSTAT_SO},
{1, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = this->cur_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_stop_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN AND STOP command started", this->name.c_str());
break;
case CMD_ENA_SEL_RESEL:
exec_next_command();
break;
@@ -380,8 +423,6 @@ void Sc53C94::exec_next_command()
}
}
#define DATA_FIFO_MAX 16
void Sc53C94::fifo_push(const uint8_t data)
{
if (this->data_fifo_pos < DATA_FIFO_MAX) {
@@ -410,19 +451,29 @@ uint8_t Sc53C94::fifo_pop()
void Sc53C94::seq_defer_state(uint64_t delay_ns)
{
if (seq_timer_id) {
if (this->seq_timer_id) {
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
seq_timer_id = 0;
this->seq_timer_id = 0;
}
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
if (delay_ns) {
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
} else {
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
}
}
void Sc53C94::sequencer()
@@ -452,7 +503,7 @@ void Sc53C94::sequencer()
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
this->next_state = this->cmd_steps->next_step;
this->next_state = SeqState::SEL_BEGIN;
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
} else { // arbitration lost
LOG_F(INFO, "%s: arbitration lost!", this->name.c_str());
@@ -473,8 +524,8 @@ void Sc53C94::sequencer()
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
LOG_F(9, "%s: selection completed", this->name.c_str());
} else { // selection timeout
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->seq_step = 0;
this->int_status = INTSTAT_DIS;
this->bus_obj->disconnect(this->my_bus_id);
this->cur_state = SeqState::IDLE;
this->update_irq();
@@ -482,29 +533,30 @@ void Sc53C94::sequencer()
}
break;
case SeqState::SEND_MSG:
case SeqState::SEND_MSG_EX:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
this->int_status = INTSTAT_SR;
this->update_irq();
break;
} else {
this->bus_obj->target_xfer_data();
if (this->cur_state == SeqState::SEND_MSG_EX) {
this->notify(ScsiNotification::BUS_PHASE_CHANGE, ScsiPhase::MESSAGE_OUT);
} else {
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
if (this->cmd_steps)
this->bus_obj->target_next_step();
}
}
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
break;
case SeqState::SEND_CMD:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
this->int_status |= INTSTAT_SR;
this->update_irq();
break;
}
this->bus_obj->target_xfer_data();
} else
this->bus_obj->target_xfer_data();
break;
case SeqState::CMD_COMPLETE:
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->int_status = INTSTAT_SR | INTSTAT_SO;
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
@@ -513,8 +565,8 @@ void Sc53C94::sequencer()
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
if (this->is_dma_cmd) {
this->cur_state = SeqState::SEND_DATA;
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
@@ -523,6 +575,10 @@ void Sc53C94::sequencer()
this->sequencer();
break;
case ScsiPhase::DATA_IN:
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
@@ -530,6 +586,18 @@ void Sc53C94::sequencer()
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
break;
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::MESSAGE_OUT:
this->cur_state = (this->cur_bus_phase == ScsiPhase::MESSAGE_OUT) ?
SeqState::SEND_MSG : SeqState::RCV_MESSAGE;
this->sequencer();
this->cur_state = SeqState::XFER_END;
this->sequencer();
break;
default:
ABORT_F("%s: unsupported phase %d in XFER_BEGIN", this->name.c_str(),
this->cur_bus_phase);
}
break;
case SeqState::XFER_END:
@@ -560,11 +628,17 @@ void Sc53C94::sequencer()
if (this->is_initiator) {
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->my_bus_id, SCSI_CTRL_REQ);
this->cur_state = SeqState::RCV_MESSAGE;
this->sequencer();
}
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
}
}
break;
@@ -583,32 +657,46 @@ void Sc53C94::update_irq()
}
}
void Sc53C94::notify(ScsiMsg msg_type, int param)
void Sc53C94::notify(ScsiNotification notif_type, int param)
{
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
if (this->target_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
seq_timer_id = 0;
this->seq_timer_id = 0;
this->cur_state = SeqState::SEL_END;
this->sequencer();
} else {
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
LOG_F(WARNING, "%s: invalid selection confirmation message ignored",
this->name.c_str());
}
break;
case ScsiMsg::BUS_PHASE_CHANGE:
case ScsiNotification::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
if (param == ScsiPhase::BUS_FREE) { // target want to disconnect
this->int_status = INTSTAT_DIS;
this->update_irq();
this->cur_state = SeqState::IDLE;
}
if (this->cmd_steps != nullptr) {
if (this->cur_bus_phase == this->cmd_steps->expected_phase) {
this->next_state = this->cmd_steps->next_state;
this->cmd_steps++;
this->seq_defer_state(0);
} else {
this->cur_step = this->cmd_steps->step_num;
this->seq_step = this->cur_step;
this->int_status = this->cmd_steps->status;
this->update_irq();
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE)
this->exec_next_command();
}
}
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
msg_type);
notif_type);
}
}
@@ -628,8 +716,7 @@ int Sc53C94::send_data(uint8_t* dst_ptr, int count)
if (this->data_fifo_pos > 0) {
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
} else if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
ABORT_F("%s: don't know what to do next!", this->name.c_str());
this->sequencer();
}
@@ -751,6 +838,87 @@ void Sc53C94::dma_stop()
}
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
int bytes_moved = 0;
if (this->cur_cmd != CMD_XFER || !this->is_dma_cmd ||
this->cur_bus_phase != ScsiPhase::DATA_IN) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
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;
bytes_moved += fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return bytes_moved;
}
}
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();
}
return bytes_moved;
}
int Sc53C94::xfer_to(uint8_t *buf, int len) {
int bytes_moved = 0;
if (!this->xfer_count || !this->is_dma_cmd) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
// Being in the DATA_OUT phase means that we're about to move
// a big chunk of data. The real device uses its FIFO as buffer.
// For simplicity, the code below transfers the whole chunk at once.
// This can be broken into smaller chunks later if desired.
if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
if (this->bus_obj->push_data(this->target_id, buf, len)) {
this->xfer_count -= len;
bytes_moved += len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
len = 0;
} else
LOG_F(WARNING, "%s: xfer_to failed to transfer data", this->name.c_str());
}
if (this->xfer_count) {
// fill in the data FIFO first
uint32_t fifo_bytes = std::min(len, DATA_FIFO_MAX - this->data_fifo_pos);
std::memcpy(&this->data_fifo[this->data_fifo_pos], buf, fifo_bytes);
this->data_fifo_pos += fifo_bytes;
this->xfer_count -= fifo_bytes;
bytes_moved += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->sequencer();
}
}
return bytes_moved;
}
static const PropMap Sc53C94_properties = {
{"hdd_img", new StrProperty("")},
{"cdr_img", new StrProperty("")},
+40 -24
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)
@@ -94,9 +94,9 @@ enum {
CMD_XFER = 0x10,
CMD_COMPLETE_STEPS = 0x11,
CMD_MSG_ACCEPTED = 0x12,
//CMD_TRANSFER_PAD_BYTES = 0x18,
CMD_XFER_PAD_BYTES = 0x18,
CMD_SET_ATN = 0x1A, // no interrupt
//CMD_RESET_ATN = 0x1B, // no interrupt
CMD_RESET_ATN = 0x1B, // no interrupt
// Target commands
//CMD_SEND_MESSAGE = 0x20,
@@ -111,13 +111,13 @@ enum {
//CMD_RECEIVE_DATA = 0x2A,
//CMD_RECEIVE_COMMAND_STEPS = 0x2B,
CMD_DMA_STOP = 0x04, // no interrupt
CMD_ACCESS_FIFO_COMMAND = 0x05,
//CMD_ACCESS_FIFO_COMMAND = 0x05,
// Idle Commands
//CMD_RESELECT_STEPS = 0x40,
CMD_SELECT_NO_ATN = 0x41,
CMD_SELECT_WITH_ATN = 0x42,
//CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
CMD_ENA_SEL_RESEL = 0x44, // no interrupt
//CMD_DISABLE_SEL_RESEL = 0x45,
//CMD_SELECT_WITH_ATN3_STEPS = 0x46,
@@ -128,14 +128,12 @@ enum {
CMD_ISDMA = 0x80,
};
/** Status register bits. **/
/** Status register bits. */
enum {
//SCSI_CTRL_IO = 0x01, // Input/Output
//SCSI_CTRL_CD = 0x02, // Command/Data
//SCSI_CTRL_MSG = 0x04, // Message
//STAT_GCV = 0x08, // Group Code Valid
STAT_PHASE_MASK = 0x07, // mask for I/O, Command and Message bits
STAT_GCV = 0x08, // Group Code Valid
STAT_TC = 0x10, // Terminal count (NCR) / count to zero (AMD)
//STAT_PE = 0x20, // Parity Error
STAT_PE = 0x20, // Parity Error
STAT_GE = 0x40, // Gross Error (NCR) / Illegal Operation Error (AMD)
STAT_INT = 0x80, // Interrupt
};
@@ -152,6 +150,12 @@ enum {
INTSTAT_SEL = 0x01, // selected as a target without attention
};
/** Configuration register 1 bits. */
enum {
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
};
/** Configuration register 2 bits. */
enum {
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
};
@@ -166,6 +170,7 @@ namespace SeqState {
SEL_BEGIN,
SEL_END,
SEND_MSG,
SEND_MSG_EX,
SEND_CMD,
CMD_COMPLETE,
XFER_BEGIN,
@@ -177,17 +182,19 @@ namespace SeqState {
};
};
/** Sequence descriptor for sequencer commands. */
constexpr auto DATA_FIFO_MAX = 16;
/** Sequence descriptor for multistep commands. */
typedef struct {
int seq_id;
int next_step;
int step_num;
int expected_phase;
int next_state;
int status;
} SeqDesc;
typedef std::function<void(const uint8_t drq_state)> DrqCb;
class Sc53C94 : public ScsiDevice {
class Sc53C94 : public ScsiDevice, public DmaDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
~Sc53C94() = default;
@@ -197,7 +204,7 @@ public:
}
// HWComponent methods
int device_postinit();
int device_postinit() override;
// 53C94 registers access
uint8_t read(uint8_t reg_offset);
@@ -228,12 +235,19 @@ public:
}
// ScsiDevice methods
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return this->data_fifo_pos != 0; };
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
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; };
int send_data(uint8_t* dst_ptr, int count) 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();
@@ -256,7 +270,7 @@ private:
uint32_t my_timer_id = 0;
uint8_t cmd_fifo[2];
uint8_t data_fifo[16];
uint8_t data_fifo[DATA_FIFO_MAX];
int cmd_fifo_pos = 0;
int data_fifo_pos = 0;
int bytes_out = 0;
@@ -268,6 +282,7 @@ private:
uint8_t int_status = 0;
uint8_t seq_step = 0;
uint8_t sel_timeout = 0;
uint8_t sync_period = 5;
uint8_t sync_offset = 0;
uint8_t clk_factor = 0;
uint8_t config1 = 0;
@@ -283,10 +298,11 @@ private:
uint8_t cur_cmd = 0;
bool is_dma_cmd = false;
int cur_bus_phase = 0;
uint8_t cur_step = 0; // internal step counter for multistep commands
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t irq_id = 0;
uint8_t irq = 0;
// DMA related stuff
+39 -17
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)
@@ -47,6 +47,7 @@ enum {
SCSI_CTRL_RST = 1 << 15,
};
/** SCSI bus phases. */
namespace ScsiPhase {
enum : int {
BUS_FREE = 0,
@@ -63,6 +64,7 @@ namespace ScsiPhase {
};
};
/** SCSI status codes. */
namespace ScsiStatus {
enum : uint8_t {
GOOD = 0,
@@ -70,6 +72,7 @@ namespace ScsiStatus {
};
};
/** Standard message codes. */
namespace ScsiMessage {
enum : uint8_t {
COMMAND_COMPLETE = 0,
@@ -82,13 +85,19 @@ namespace ScsiMessage {
};
};
enum ScsiMsg : int {
/** Extended message codes. */
namespace ScsiExtMessage {
enum : uint8_t {
MODIFY_DATA_PTR = 0,
SYNCH_XFER_REQ = 1,
WIDE_XFER_REQ = 3,
};
};
/** Internal notification codes for our SCSI implementation. */
enum ScsiNotification : int {
CONFIRM_SEL = 1,
BUS_PHASE_CHANGE,
SEND_CMD_BEGIN,
SEND_CMD_END,
MESSAGE_BEGIN,
MESSAGE_END,
};
enum ScsiCommand : uint8_t {
@@ -156,14 +165,14 @@ enum ScsiError : int {
};
/** Standard SCSI bus timing values measured in ns. */
#define BUS_SETTLE_DELAY 400
#define BUS_FREE_DELAY 800
#define BUS_CLEAR_DELAY 800
#define ARB_DELAY 2400
#define SEL_ABORT_TIME 200000
#define SEL_TIME_OUT 250000000
constexpr uint64_t BUS_SETTLE_DELAY = 400;
constexpr uint64_t BUS_FREE_DELAY = 800;
constexpr uint64_t BUS_CLEAR_DELAY = 800;
constexpr uint64_t ARB_DELAY = 2400;
constexpr uint64_t SEL_ABORT_TIME = 200000;
constexpr uint64_t SEL_TIME_OUT = 250000000;
#define SCSI_MAX_DEVS 8
constexpr auto SCSI_MAX_DEVS = 8;
class ScsiBus;
@@ -180,10 +189,11 @@ public:
};
~ScsiDevice() = default;
virtual void notify(ScsiMsg msg_type, int param);
virtual void notify(ScsiNotification notif_type, int param);
virtual void next_step();
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
virtual void switch_phase(const int new_phase);
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; };
virtual int xfer_data();
@@ -195,6 +205,7 @@ public:
virtual bool prepare_data() = 0;
virtual bool get_more_data() = 0;
virtual void process_command() = 0;
virtual void process_message();
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
this->bus_obj = bus_obj_ptr;
@@ -224,6 +235,8 @@ protected:
uint8_t last_selection_message = 0;
ScsiBus* bus_obj;
int *seq_steps = nullptr;
action_callback pre_xfer_action = nullptr;
action_callback post_xfer_action = nullptr;
};
@@ -246,9 +259,18 @@ public:
// low-level state management
void register_device(int id, ScsiDevice* dev_obj);
int current_phase() { return this->cur_phase; };
int get_initiator_id() { return this->initiator_id; };
int get_target_id() { return this->target_id; };
int current_phase() const {
return this->cur_phase;
}
int get_initiator_id() const {
return this->initiator_id;
}
int get_target_id() const {
return this->target_id;
}
// reading/writing control lines
void assert_ctrl_line(int id, uint16_t mask);
+9 -5
View File
@@ -66,15 +66,17 @@ void ScsiBus::change_bus_phase(int initiator_id)
if (i == initiator_id)
continue; // don't notify the initiator
if (this->devices[i] != nullptr) {
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
this->devices[i]->notify(ScsiNotification::BUS_PHASE_CHANGE, this->cur_phase);
}
}
}
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
{
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS,
"%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
if (!(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
return;
}
uint16_t new_state = 0xFFFFU & mask;
@@ -93,7 +95,9 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
{
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
if (!(id >= 0 && id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
}
uint16_t new_state = 0;
@@ -238,7 +242,7 @@ void ScsiBus::confirm_selection(int target_id)
// notify initiator about selection confirmation from target
if (this->initiator_id >= 0) {
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
this->devices[this->initiator_id]->notify(ScsiNotification::CONFIRM_SEL, target_id);
}
}
+5 -5
View File
@@ -160,9 +160,9 @@ void ScsiBusController::sequencer() {
}
}
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
void ScsiBusController::notify(ScsiNotification notif_type, int param) {
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
if (this->dst_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
@@ -174,7 +174,7 @@ void ScsiBusController::notify(ScsiMsg msg_type, int param) {
this->name.c_str());
}
break;
case ScsiMsg::BUS_PHASE_CHANGE:
case ScsiNotification::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
#if 0
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
@@ -186,7 +186,7 @@ void ScsiBusController::notify(ScsiMsg msg_type, int param) {
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
msg_type);
notif_type);
}
}
+10 -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)
@@ -58,7 +58,7 @@ enum : int {
SEL_TIMEOUT,
};
#define DATA_FIFO_DEPTH 16
constexpr auto DATA_FIFO_DEPTH = 16;
class ScsiBusController : public ScsiDevice, public DmaDevice {
public:
@@ -74,16 +74,16 @@ public:
virtual void report_error(const int error) = 0;
// ScsiDevice methods
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return false; };
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 rcv_data();
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {};
// DmaDevice methods
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
int xfer_from(uint8_t *buf, int len) override;
protected:
void seq_defer_state(uint64_t delay_ns);
@@ -113,7 +113,7 @@ protected:
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t irq_id = 0;
uint8_t irq = 0;
uint8_t int_mask = 0;
uint8_t int_stat = 0;
+28 -28
View File
@@ -65,7 +65,9 @@ void ScsiCdrom::process_command()
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
break;
case ScsiCommand::MODE_SELECT_6:
this->mode_select_6(cmd[4]);
@@ -151,55 +153,53 @@ int ScsiCdrom::test_unit_ready()
return ScsiError::NO_ERROR;
}
void ScsiCdrom::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(ERROR, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
if (this->last_selection_has_atention) {
LOG_F(9, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
LOG_F(9, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
}
this->data_buf[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
this->data_buf[1] = 0x80; // removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
data_ptr[1] = 0x80; // removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
alloc_len);
}
else {
memset(&this->data_buf[36], 0, alloc_len - 36);
memset(&data_ptr[36], 0, alloc_len - 36);
}
this->bytes_out = alloc_len;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
return alloc_len;
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
+1 -1
View File
@@ -44,7 +44,7 @@ public:
protected:
int test_unit_ready();
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
void inquiry();
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
void mode_select_6(uint8_t param_len);
void mode_sense_6();
+66 -13
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)
@@ -26,9 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
void ScsiDevice::notify(ScsiMsg msg_type, int param)
void ScsiDevice::notify(ScsiNotification notif_type, int param)
{
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
if (notif_type == ScsiNotification::BUS_PHASE_CHANGE) {
switch (param) {
case ScsiPhase::RESET:
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
@@ -45,12 +45,11 @@ void ScsiDevice::notify(ScsiMsg msg_type, int param)
return;
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
this->bus_obj->confirm_selection(this->scsi_id);
this->seq_steps = nullptr;
this->initiator_id = this->bus_obj->get_initiator_id();
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
this->switch_phase(ScsiPhase::MESSAGE_OUT);
this->last_selection_has_atention = true;
this->last_selection_message = this->msg_buf[0];
//LOG_F(SCSIDEVICE, "%s: received message:0x%02x", this->get_name().c_str(), this->msg_buf[0]);
this->switch_phase(ScsiPhase::MESSAGE_OUT);
} else {
this->last_selection_has_atention = false;
this->switch_phase(ScsiPhase::COMMAND);
@@ -68,8 +67,36 @@ void ScsiDevice::switch_phase(const int new_phase)
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
}
bool ScsiDevice::allow_phase_change() {
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN | SCSI_CTRL_ACK) ==
(SCSI_CTRL_ATN | SCSI_CTRL_ACK))
ABORT_F("%s: reject message requested", this->name.c_str());
if (this->data_size || this->bus_obj->test_ctrl_lines(SCSI_CTRL_ACK))
return false;
else
return true;
}
void ScsiDevice::next_step()
{
// special case: data transfers during MESSAGE_IN phase
// require handshaking. Rejecting needs to be detected too.
if (bus_obj->current_phase() == ScsiPhase::MESSAGE_IN &&
!this->allow_phase_change())
return;
// check for puggable sequences and follow them if applicable
if (this->seq_steps && *this->seq_steps >= 0) {
if (this->cur_phase == *this->seq_steps) {
this->seq_steps++;
if (*this->seq_steps >= 0) {
this->switch_phase(*this->seq_steps);
return;
}
}
}
switch (this->cur_phase) {
case ScsiPhase::DATA_OUT:
if (this->data_size >= this->incoming_size) {
@@ -96,6 +123,8 @@ void ScsiDevice::next_step()
break;
case ScsiPhase::STATUS:
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
this->data_ptr = this->msg_buf;
this->data_size = 1;
this->switch_phase(ScsiPhase::MESSAGE_IN);
break;
case ScsiPhase::MESSAGE_OUT:
@@ -104,6 +133,7 @@ void ScsiDevice::next_step()
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::BUS_FREE:
this->bus_obj->release_ctrl_lines(this->scsi_id);
this->seq_steps = nullptr;
this->switch_phase(ScsiPhase::BUS_FREE);
break;
default:
@@ -137,9 +167,6 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
bytes_out = 0;
break;
case ScsiPhase::MESSAGE_IN:
this->data_ptr = this->msg_buf;
this->data_size = 1;
bytes_out = 1;
break;
default:
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
@@ -154,14 +181,14 @@ int ScsiDevice::xfer_data() {
switch (this->cur_phase) {
case ScsiPhase::MESSAGE_OUT:
if (this->bus_obj->pull_data(this->initiator_id, this->msg_buf, 1)) {
if (this->msg_buf[0] & 0x80) {
if (this->msg_buf[0] & ScsiMessage::IDENTIFY) {
LOG_F(9, "%s: IDENTIFY MESSAGE received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
this->next_step();
} else {
ABORT_F("%s: unsupported message received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
this->process_message();
}
if (this->last_selection_has_atention)
this->last_selection_message = this->msg_buf[0];
}
break;
case ScsiPhase::COMMAND:
@@ -256,3 +283,29 @@ void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->switch_phase(ScsiPhase::STATUS);
}
void ScsiDevice::process_message() {
static int sdtr_response_seq[4] = {ScsiPhase::MESSAGE_OUT, ScsiPhase::MESSAGE_IN,
ScsiPhase::COMMAND, -1};
if (this->msg_buf[0] == 1) { // extended messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1) ||
!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[2], this->msg_buf[1]))
ABORT_F("%s: incomplete message received", this->name.c_str());
switch(this->msg_buf[2]) {
case ScsiExtMessage::SYNCH_XFER_REQ:
LOG_F(INFO, "%s: SDTR message received", this->name.c_str());
// confirm synchronous transfer capability by sending back the SDTR message
this->seq_steps = sdtr_response_seq;
this->data_ptr = this->msg_buf;
this->data_size = 5;
break;
default:
LOG_F(ERROR, "%s: unsupported message %d", this->name.c_str(), this->msg_buf[2]);
}
} else if ((this->msg_buf[0] >> 4) == 2) { // two-byte messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1))
ABORT_F("%s: incomplete message received", this->name.c_str());
}
}
+51 -44
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)
@@ -34,6 +34,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
this->data_buf_size = 1 << 22;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
void ScsiHardDisk::insert_image(std::string filename) {
@@ -81,7 +84,8 @@ void ScsiHardDisk::process_command() {
this->write(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->switch_phase(ScsiPhase::DATA_IN);
break;
case ScsiCommand::MODE_SELECT_6:
mode_select_6(cmd[4]);
@@ -89,6 +93,9 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::MODE_SENSE_6:
this->mode_sense_6();
break;
case ScsiCommand::START_STOP_UNIT:
this->switch_phase(ScsiPhase::STATUS);
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
this->eject_allowed = (cmd[4] & 1) == 0;
this->switch_phase(ScsiPhase::STATUS);
@@ -106,7 +113,6 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::WRITE_10:
lba = READ_DWORD_BE_U(&cmd[2]);
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
this->switch_phase(ScsiPhase::DATA_OUT);
break;
case ScsiCommand::READ_BUFFER:
read_buffer();
@@ -210,40 +216,42 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
return ScsiError::NO_ERROR;
}
void ScsiHardDisk::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(INFO, "%s: %d bytes requested in INQUIRY", this->name.c_str(), alloc_len);
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(), alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7",
this->name.c_str(), alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(), alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
}
this->data_buf[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
this->data_buf[1] = 0; // non-removable media; 0x80 = removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
data_ptr[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
data_ptr[1] = 0; // non-removable media; 0x80 = removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
@@ -251,12 +259,10 @@ void ScsiHardDisk::inquiry() {
alloc_len);
}
else {
memset(&this->data_buf[36], 0, alloc_len - 36);
memset(&data_ptr[36], 0, alloc_len - 36);
}
this->bytes_out = alloc_len;
this->switch_phase(ScsiPhase::DATA_IN);
return alloc_len;
}
int ScsiHardDisk::send_diagnostic() {
@@ -300,18 +306,6 @@ void ScsiHardDisk::mode_sense_6() {
return;
}
if (page_ctrl == 2) {
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (page_ctrl == 3) {
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
@@ -456,14 +450,19 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
return;
uint32_t transfer_size = transfer_len;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
std::memset(this->data_buf, 0, transfer_size);
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size);
@@ -475,12 +474,18 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size;
@@ -488,6 +493,8 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
this->post_xfer_action = [this, device_offset]() {
this->disk_img.write(this->data_buf, device_offset, this->incoming_size);
};
this->switch_phase(ScsiPhase::DATA_OUT);
}
void ScsiHardDisk::read_buffer() {
+5 -3
View File
@@ -49,7 +49,7 @@ protected:
void mode_sense_6();
void format();
void inquiry();
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);
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
@@ -66,13 +66,15 @@ private:
bool eject_allowed = true;
int bytes_out = 0;
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
std::unique_ptr<uint8_t[]> data_buf_obj = nullptr;
uint8_t* data_buf = nullptr;
uint32_t data_buf_size = 0;
uint8_t error = ScsiError::NO_ERROR;
uint8_t msg_code = 0;
//inquiry info
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
char vendor_info[8] = {'Q', 'U', 'A', 'N', 'T', 'U', 'M', '\0'};
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
char rev_info[4] = {'d', 'i', '0', '1'};
};
+18 -3
View File
@@ -301,7 +301,7 @@ uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last
{
// calculate current counter value based on elapsed time and timer frequency
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
uint32_t diff = uint32_t((cur_time - last_time) / this->via_clk_dur);
return last_val - diff;
}
@@ -751,7 +751,22 @@ void ViaCuda::pseudo_command() {
}
uint32_t ViaCuda::calc_real_time() {
auto end = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> end;
if (is_deterministic) {
// March 24, 2001 was the public release date of Mac OS X.
std::tm tm = {
.tm_sec = 0,
.tm_min = 0,
.tm_hour = 12,
.tm_mday = 24,
.tm_mon = 3 - 1,
.tm_year = 2001 - 1900,
.tm_isdst = 0
};
end = std::chrono::system_clock::from_time_t(std::mktime(&tm));
} else {
end = std::chrono::system_clock::now();
}
auto elapsed_systemclock = end - this->mac_epoch;
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
return uint32_t(elapsed_seconds.count());
@@ -836,7 +851,7 @@ void ViaCuda::i2c_comb_transaction(
}
static const vector<string> Cuda_Subdevices = {
"AdbBus", "AdbMouse", "AdbKeyboard"
"AdbBus"
};
static const DeviceDescription ViaCuda_Descriptor = {
+10 -8
View File
@@ -53,7 +53,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class AdbBus;
class InterruptCtrl;
#define VIA_CLOCK_HZ 783360
constexpr auto VIA_CLOCK_HZ = 783360;
/** VIA register offsets. */
enum {
@@ -143,16 +143,18 @@ enum {
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
};
#define CUDA_IN_BUF_SIZE 256
constexpr auto CUDA_IN_BUF_SIZE = 256;
/** PRAM addresses within Cuda's internal memory. */
#define CUDA_PRAM_START 0x100 // starting address of PRAM
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
// = 0xA1; // byte, read/write 0x00 (Power Mac 6100)
// = 0xB3; // 2 bytes, write 0x3020 (Power Mac 6100)
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW
/** Latest Cuda Firmware version. */
#define CUDA_FW_VERSION_MAJOR 0x0002
#define CUDA_FW_VERSION_MINOR 0x0029
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
class ViaCuda : public HWComponent, public I2CBus {
public:
@@ -207,7 +209,7 @@ private:
// VIA interrupt related stuff
InterruptCtrl* int_ctrl;
uint32_t irq_id;
uint64_t irq_id;
uint8_t _via_ifr;
uint8_t _via_ier;
uint8_t old_ifr = 0;
+2 -2
View File
@@ -36,7 +36,7 @@ bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
return true;
}
bool DeviceRegistry::device_registered(const string dev_name)
bool DeviceRegistry::device_registered(const std::string dev_name)
{
if (get_registry().find(dev_name) != get_registry().end()) {
return true;
@@ -45,7 +45,7 @@ bool DeviceRegistry::device_registered(const string dev_name)
return false;
}
unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
std::unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
{
auto it = get_registry().find(name);
if (it != get_registry().end()) {
+9 -9
View File
@@ -34,12 +34,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class HWComponent;
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
typedef std::function<std::unique_ptr<HWComponent> ()> CreateFunc;
struct DeviceDescription {
CreateFunc m_create_func;
vector<string> subdev_list;
PropMap properties;
CreateFunc m_create_func;
std::vector<std::string> subdev_list;
PropMap properties;
};
class DeviceRegistry
@@ -47,17 +47,17 @@ class DeviceRegistry
public:
DeviceRegistry() = delete;
static bool add(const string name, DeviceDescription desc);
static bool add(const std::string name, DeviceDescription desc);
static bool device_registered(const string dev_name);
static bool device_registered(const std::string dev_name);
static unique_ptr<HWComponent> create(const string& name);
static std::unique_ptr<HWComponent> create(const std::string& name);
static DeviceDescription& get_descriptor(const std::string& name);
private:
static map<string, DeviceDescription> & get_registry() {
static map<string, DeviceDescription> device_registry;
static std::map<std::string, DeviceDescription> & get_registry() {
static std::map<std::string, DeviceDescription> device_registry;
return device_registry;
}
};
+26 -1
View File
@@ -41,21 +41,41 @@ enum BigMacReg : uint16_t {
TX_FIFO_CSR = 0x100,
TX_FIFO_TH = 0x110,
RX_FIFO_CSR = 0x120,
MEM_ADD = 0x130, // Memory Address
MEM_DATA_HI = 0x140, // Memory Data High
MEM_DATA_LO = 0x150, // Memory Data Low
XCVR_IF = 0x160, // Transceiver IF Control
CHIP_ID = 0x170,
MIF_CSR = 0x180,
SROM_CSR = 0x190,
TX_PNTR = 0x1A0, // Apple: TX Pointer
RX_PNTR = 0x1B0, // Apple: RX Pointer
GLOB_STAT = 0x200, // Apple: kSTAT, Sun: Global Status Register
EVENT_MASK = 0x210, // ambiguously called INT_DISABLE in the Apple source
SROM_CSR = 0x190,
TX_SW_RST = 0x420,
TX_CONFIG = 0x430,
IPG_1 = 0x440, // Inter Packet Gap 1
IPG_2 = 0x450,
A_LIMIT = 0x460, // Attempt Limit
SLOT = 0x470,
PA_LEN = 0x480, // Apple: PA Len, Sun: PA Size
PA_PAT = 0x490,
TX_SFD = 0x4A0,
JAM_SIZE = 0x4B0,
TX_MAX = 0x4C0, // Max frame size
TX_MIN = 0x4D0, // Min frame size
PEAK_ATT = 0x4E0, // Apple: kPAREG, Sun: PeakAttempts Register
DEFER_TMR = 0x4F0, // Also called DCNT by Apple
NC_CNT = 0x500, // Normal Collision Counter
NT_CNT = 0x510, // Apple: Network Collision Counter
EX_CNT = 0x520, // Excessive Collision Counter
LT_CNT = 0x530, // Late Collision Counter
RNG_SEED = 0x540,
TX_SM = 0x550,
RX_SW_RST = 0x620,
RX_CONFIG = 0x630,
RX_MAX = 0x640,
RX_MIN = 0x650,
MAC_ADDR_2 = 0x660,
MAC_ADDR_1 = 0x670,
MAC_ADDR_0 = 0x680,
@@ -63,11 +83,16 @@ enum BigMacReg : uint16_t {
RX_LE_CNT = 0x6A0, // Length Error Counter
RX_AE_CNT = 0x6B0, // Alignment Error Counter
RX_FE_CNT = 0x6C0, // FCS Error Counter
RX_ST_MCHN = 0x6D0, // RX State Machine
RX_CVE_CNT = 0x6E0, // Code Violation Error Counter
HASH_TAB_3 = 0x700,
HASH_TAB_2 = 0x710,
HASH_TAB_1 = 0x720,
HASH_TAB_0 = 0x730,
AFR_2 = 0x740, // Address Filter 2
AFR_1 = 0x750, // Address Filter 1
AFR_0 = 0x760, // Address Filter 0
AFC_R = 0x770, // Address Filter Mask
};
/* MIF_CSR bit definitions. */
+2 -2
View File
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
/** Known MACE chip IDs. */
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
constexpr auto MACE_ID_REV_B0 = 0x0940; // Darwin-0.3 source
constexpr auto MACE_ID_REV_A2 = 0x0941; // Darwin-0.3 source & Curio datasheet
/** MACE registers offsets. */
// Refer to the Am79C940 datasheet for details
+28 -8
View File
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <string>
#define BLOCK_SIZE 512 // size in bytes of a logical block
constexpr auto BLOCK_SIZE = 512; // size in bytes of a logical block
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
@@ -50,13 +50,33 @@ public:
virtual int get_raw_disk_data(char* buf) = 0;
virtual int export_data(void) = 0;
int get_data_size() { return this->data_size; };
int get_disk_rec_method() { return this->rec_method; };
int get_number_of_tracks() { return this->num_tracks; };
int get_number_of_sides() { return this->num_sides; };
int get_sectors_per_side() { return this->num_sectors; };
int get_rec_density() { return this->density; };
uint8_t get_format_byte() { return this->format_byte; };
int get_data_size() const {
return this->data_size;
}
int get_disk_rec_method() const {
return this->rec_method;
}
int get_number_of_tracks() const {
return this->num_tracks;
}
int get_number_of_sides() const {
return this->num_sides;
}
int get_sectors_per_side() const {
return this->num_sectors;
}
int get_rec_density() const {
return this->density;
}
uint8_t get_format_byte() const {
return this->format_byte;
}
protected:
std::string img_path;
+58 -34
View File
@@ -55,8 +55,6 @@ void MacSuperDrive::reset_params()
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
uint8_t new_motor_stat;
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
switch(addr) {
@@ -68,26 +66,16 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
this->cur_track += this->step_dir;
if (this->cur_track < 0)
this->cur_track = 0;
else if (this->cur_track >= this->num_tracks) {
LOG_F(ERROR, "%s: track:%d is greater than max track:%d",
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:
new_motor_stat = value ^ 1;
if (this->motor_stat != new_motor_stat) {
this->motor_stat = new_motor_stat;
if (new_motor_stat) {
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
this->track_start_time = 0;
this->sector_start_time = 0;
this->init_track_search(-1);
this->is_ready = 1;
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
} else {
this->motor_on_time = 0;
this->is_ready = 0;
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
}
}
this->set_motor_stat(value ^ 1);
break;
case CommandAddr::Eject_Disk:
if (value) {
@@ -95,6 +83,7 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
this->eject_latch = 1;
this->reset_params();
}
break;
case CommandAddr::Reset_Eject_Latch:
if (value) {
this->eject_latch = 0;
@@ -111,43 +100,78 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
}
}
void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
{
if (this->motor_stat != new_motor_stat) {
this->motor_stat = new_motor_stat;
if (new_motor_stat) {
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
this->track_start_time = 0;
this->sector_start_time = 0;
this->init_track_search(-1);
this->is_ready = 1;
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
} else {
this->motor_on_time = 0;
this->is_ready = 0;
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
}
}
}
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) {
case StatusAddr::Step_Status:
return 1; // not sure what should be returned here
value = 1; // not sure what should be returned here
break;
case StatusAddr::Motor_Status:
return this->motor_stat ^ 1; // reverse logic
value = this->motor_stat ^ 1; // reverse logic
break;
case StatusAddr::Eject_Latch:
return this->eject_latch;
value = this->eject_latch;
break;
case StatusAddr::Select_Head_0:
return this->cur_head = 0;
value = this->cur_head = 0;
break;
case StatusAddr::MFM_Support:
return 1; // Superdrive does support MFM encoding scheme
value = 1; // Superdrive does support MFM encoding scheme
break;
case StatusAddr::Double_Sided:
return 1; // yes, Superdrive is double sided
value = 1; // yes, Superdrive is double sided
break;
case StatusAddr::Drive_Exists:
return 0; // tell the world I'm here
value = 0; // tell the world I'm here
break;
case StatusAddr::Disk_In_Drive:
return this->has_disk ^ 1; // reverse logic (active low)!
value = this->has_disk ^ 1; // reverse logic (active low)!
break;
case StatusAddr::Write_Protect:
return this->wr_protect ^ 1; // reverse logic
value = this->wr_protect ^ 1; // reverse logic
break;
case StatusAddr::Track_Zero:
return this->track_zero ^ 1; // reverse logic
value = this->track_zero ^ 1; // reverse logic
break;
case StatusAddr::Select_Head_1:
return this->cur_head = 1;
value = this->cur_head = 1;
break;
case StatusAddr::Drive_Mode:
return this->drive_mode;
value = this->drive_mode;
break;
case StatusAddr::Drive_Ready:
return this->is_ready ^ 1; // reverse logic
value = this->is_ready ^ 1; // reverse logic
break;
case StatusAddr::Media_Kind:
return this->media_kind ^ 1; // reverse logic!
value = this->media_kind ^ 1; // reverse logic!
break;
default:
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
return 0;
value = 0;
}
return value;
}
int MacSuperDrive::insert_disk(std::string& img_path, int write_flag = 0)
@@ -260,7 +284,7 @@ uint64_t MacSuperDrive::sync_to_disk()
{
uint64_t cur_time_ns, track_time_ns;
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
uint64_t track_delay = uint64_t(this->get_current_track_delay() * NS_PER_SEC);
// look how much ns have been elapsed since the last motor enabling
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
+1
View File
@@ -102,6 +102,7 @@ public:
void command(uint8_t addr, uint8_t value);
uint8_t status(uint8_t addr);
int insert_disk(std::string& img_path, int write_flag);
void set_motor_stat(uint8_t new_motor_stat);
void init_track_search(int pos);
uint64_t sync_to_disk();
uint64_t next_addr_mark_delay(uint8_t *next_sect_num);
+37 -13
View File
@@ -42,6 +42,16 @@ Swim3Ctrl::Swim3Ctrl()
this->name = "SWIM3";
this->supported_types = HWCompType::FLOPPY_CTRL;
this->reset();
// Attach virtual Superdrive to the internal drive connector
// TODO: make SWIM3/drive wiring user selectable
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
}
void Swim3Ctrl::reset()
{
this->setup_reg = 0;
this->mode_reg = 0;
this->int_reg = 0;
@@ -54,10 +64,24 @@ Swim3Ctrl::Swim3Ctrl()
this->cur_state = SWIM3_IDLE;
// Attach virtual Superdrive to the internal drive connector
// TODO: make SWIM3/drive wiring user selectable
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
this->cur_track = 0xFF;
this->cur_sector = 0x7F;
this->timer_val = 0;
this->phase_lines = 0;
if (this->one_us_timer_id) {
TimerManager::get_instance()->cancel_timer(this->one_us_timer_id);
this->one_us_timer_id = 0;
}
if (this->step_timer_id) {
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
this->step_timer_id = 0;
}
if (this->access_timer_id) {
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
this->access_timer_id = 0;
}
}
int Swim3Ctrl::device_postinit()
@@ -92,8 +116,8 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
case Swim3Reg::Setup:
return this->setup_reg;
case Swim3Reg::Handshake_Mode1:
if (this->mode_reg & 2) { // internal drive?
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
if (this->mode_reg & SWIM3_DRIVE_1) { // internal drive?
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
rddata_val = this->int_drive->status(status_addr) & 1;
// transfer rddata_val to both bit 2 (RDDATA) and bit 3 (SENSE)
@@ -128,7 +152,7 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
{
uint8_t status_addr;
uint8_t status_addr = 0;
switch(reg_offset) {
case Swim3Reg::Timer:
@@ -140,14 +164,14 @@ void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
case Swim3Reg::Phase:
this->phase_lines = value & 0xF;
if (this->phase_lines & 8) { // CA3 aka LSTRB high -> sending a command to the drive
if (this->mode_reg & 2) { // if internal drive is selected
if (this->mode_reg & SWIM3_DRIVE_1) { // if internal drive is selected
this->int_drive->command(
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3),
(value >> 2) & 1
);
}
} else if (this->phase_lines == 4 && (this->mode_reg & 2)) {
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
} else if (this->phase_lines == 4 && (this->mode_reg & SWIM3_DRIVE_1)) {
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
this->rd_line = this->int_drive->status(status_addr) & 1;
}
break;
@@ -239,7 +263,7 @@ void Swim3Ctrl::start_stepping()
return;
}
if ((((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3))
if ((((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3))
!= MacSuperdrive::CommandAddr::Do_Step) {
LOG_F(WARNING, "SWIM3: invalid command address on the phase lines!");
return;
@@ -376,7 +400,7 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
this->timer_val * NS_PER_USEC,
uint32_t(this->timer_val) * NS_PER_USEC,
[this]() {
this->timer_val = 0;
this->int_flags |= INT_TIMER_DONE;
+12 -6
View File
@@ -57,10 +57,14 @@ enum Swim3Reg : uint8_t {
/** Mode register bits. */
enum {
SWIM3_INT_ENA = 0x01,
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
SWIM3_GO_STEP = 0x80,
SWIM3_INT_ENA = 0x01,
SWIM3_DRIVE_1 = 0x02,
SWIM3_DRIVE_2 = 0x04,
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
SWIM3_HEAD_SELECT = 0x20,
SWIM3_FORMAT_MODE = 0x40,
SWIM3_GO_STEP = 0x80,
};
/** Interrupt flags. */
@@ -69,6 +73,7 @@ enum {
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
INT_SENSE = 0x10, // unused by SWIM3 driver
};
// SWIM3 internal states.
@@ -98,6 +103,7 @@ public:
};
protected:
void reset();
void update_irq();
void start_stepping();
void do_step();
@@ -113,7 +119,7 @@ private:
DmaBidirChannel* dma_ch;
uint8_t timer_val = 0; // internal timer that decrements at a 1 us rate
uint8_t timer_val; // internal timer that decrements at a 1 us rate
uint8_t setup_reg;
uint8_t mode_reg;
uint8_t error;
@@ -141,7 +147,7 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t irq_id = 0;
uint8_t irq = 0;
};
+136 -64
View File
@@ -54,7 +54,8 @@ AMIC::AMIC() : MMIODevice()
// connect internal SCSI controller
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->curio_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
this->scsi->set_dma_channel(this->curio_dma.get());
this->curio_dma->connect(this->scsi);
this->scsi->connect(this->curio_dma.get());
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
if (drq_state & 1)
via2_ifr |= VIA2_INT_SCSI_DRQ;
@@ -75,8 +76,8 @@ AMIC::AMIC() : MMIODevice()
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, 2 << 8);
this->snd_out_dma = std::unique_ptr<AmicSndOutDma>(new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, DMA1_INT_SOUND << DMA1_INT_SHIFT);
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
@@ -124,15 +125,21 @@ int AMIC::device_postinit()
uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
{
uint32_t phase_val;
// subdevices registers
switch(offset >> 12) {
case 0: // VIA1 registers
case 1:
return this->viacuda->read(offset >> 9);
case 4: // SCC registers
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
if ((offset & 0xF) < 0x0C)
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
else
LOG_F(ERROR, "AMIC SCC read @%x.%c", offset, SIZE_ARG(size));
return 0;
case 0x8:
case 0x9:
LOG_F(WARNING, "AMIC Ethernet ID Rom read @%x.%c", offset, SIZE_ARG(size));
return 0;
case 0xA: // MACE registers
return this->mace->read((offset >> 4) & 0x1F);
case 0x10: // SCSI registers
@@ -149,14 +156,15 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return (this->awacs->read_stat() >> (offset & 3) * 8) & 0xFF;
case AMICReg::Snd_Phase0:
case AMICReg::Snd_Phase1:
case AMICReg::Snd_Phase2:
case AMICReg::Snd_Phase2: {
// the sound phase register is organized as follows:
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
// into the DMA buffer and 'p' is an undocumented prescale value
// HWInit doesn't care about. Let's hope it will be sufficient
// to return 0 for prescale.
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
uint32_t phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
}
case AMICReg::Snd_Out_Ctrl:
return this->snd_out_ctrl;
case AMICReg::Snd_Out_DMA:
@@ -207,8 +215,30 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return (this->floppy_addr_ptr >> (3 - (offset & 3)) * 8) & 0xFF;
case AMICReg::Floppy_DMA_Ctrl:
return this->floppy_dma->read_stat();
case SCC_DMA_Xmt_A_Ctrl:
return this->escc_xmit_a_dma->read_stat();
case SCC_RXA_Byte_Cnt_Hi:
return 0;
case SCC_RXA_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_A_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch A DMA Ctrl read @%x.%c = %0*x", offset,
SIZE_ARG(size), size * 2, value);
return value;
}
case SCC_DMA_Xmt_B_Ctrl:
return this->escc_xmit_b_dma->read_stat();
case SCC_RXB_Byte_Cnt_Hi:
return 0;
case SCC_RXB_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_B_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch B DMA Ctrl read @%x.%c = %0*x",
offset, SIZE_ARG(size), size * 2, value);
return value;
}
default:
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
}
@@ -225,8 +255,12 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
case 1:
this->viacuda->write(offset >> 9, value);
return;
case 4:
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
case 4: // SCC registers
if ((offset & 0xF) < 0x0C)
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
else
LOG_F(ERROR, "AMIC SCC write @%x.%c = %0*x",
offset, SIZE_ARG(size), size * 2, value);
return;
case 0xA: // MACE registers
this->mace->write((offset >> 4) & 0x1F, value);
@@ -386,9 +420,9 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
if (value & 2) { // RUN bit set?
this->curio_dma->reinit(this->scsi_dma_base);
if (value & (1 << 6))
this->scsi->real_dma_xfer_out();
this->curio_dma->xfer_to_device();
else
this->scsi->real_dma_xfer_in();
this->curio_dma->xfer_from_device();
}
this->curio_dma->write_ctrl(value);
break;
@@ -434,50 +468,63 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
}
// ======================== Interrupt related stuff ==========================
uint32_t AMIC::register_dev_int(IntSrc src_id) {
uint64_t AMIC::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::VIA_CUDA:
return CPU_INT_VIA1;
case IntSrc::SCSI_CURIO:
return VIA2_INT_SCSI_IRQ << 8;
case IntSrc::SWIM3:
return VIA2_INT_SWIM3 << 8;
case IntSrc::NMI:
return CPU_INT_NMI;
case IntSrc::VIA_CUDA : return CPU_INT_VIA1 << CPU_INT_SHIFT;
case IntSrc::VIA2 : return CPU_INT_VIA2 << CPU_INT_SHIFT;
case IntSrc::ESCC : return CPU_INT_ESCC << CPU_INT_SHIFT;
case IntSrc::ETHERNET : return CPU_INT_ENET << CPU_INT_SHIFT;
case IntSrc::DMA_ALL : return CPU_INT_ALL_DMA << CPU_INT_SHIFT;
case IntSrc::NMI : return CPU_INT_NMI << CPU_INT_SHIFT;
case IntSrc::DMA_SCSI_CURIO: return VIA2_INT_SCSI_DRQ << VIA2_INT_SHIFT;
case IntSrc::SLOT_ALL : return VIA2_INT_ALL_SLOT << VIA2_INT_SHIFT;
case IntSrc::SCSI_CURIO : return VIA2_INT_SCSI_IRQ << VIA2_INT_SHIFT;
case IntSrc::DAVBUS : return VIA2_INT_SOUND << VIA2_INT_SHIFT;
case IntSrc::SWIM3 : return VIA2_INT_SWIM3 << VIA2_INT_SHIFT;
case IntSrc::SLOT_0 : return SLOT_INT_SLOT_0 << SLOT_INT_SHIFT;
case IntSrc::SLOT_1 : return SLOT_INT_SLOT_1 << SLOT_INT_SHIFT;
case IntSrc::SLOT_2 : return SLOT_INT_SLOT_2 << SLOT_INT_SHIFT;
case IntSrc::SLOT_PDS : return SLOT_INT_SLOT_PDS << SLOT_INT_SHIFT;
case IntSrc::SLOT_VDS : return SLOT_INT_SLOT_VDS << SLOT_INT_SHIFT;
case IntSrc::VBL : return SLOT_INT_VBL << SLOT_INT_SHIFT;
case IntSrc::DMA_DAVBUS_Tx : return DMA1_INT_SOUND << DMA1_INT_SHIFT;
default:
ABORT_F("AMIC: unknown interrupt source %d", src_id);
}
return 0;
}
uint32_t AMIC::register_dma_int(IntSrc src_id) {
uint64_t AMIC::register_dma_int(IntSrc src_id) {
ABORT_F("AMIC: register_dma_int() not implemented");
return 0;
}
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
// dispatch cascaded AMIC interrupts from various sources
// irq_id format: 00DDCCBBAA where
// - AA -> CPU interrupts
// - BB -> pseudo VIA2 interrupts
// - CC -> slot interrupts
if (irq_id < 0x100) {
this->ack_cpu_int(irq_id, irq_line_state);
} else if (irq_id < 0x10000) {
this->ack_via2_int(irq_id >> 8, irq_line_state);
} else if (irq_id < 0x1000000) {
this->ack_slot_int(irq_id >> 16, irq_line_state);
if (irq_id >> SLOT_INT_SHIFT) {
this->ack_slot_int(irq_id >> SLOT_INT_SHIFT, irq_line_state);
} else if (irq_id >> VIA2_INT_SHIFT) {
this->ack_via2_int(irq_id >> VIA2_INT_SHIFT, irq_line_state);
} else if (irq_id >> CPU_INT_SHIFT) {
this->ack_cpu_int(irq_id >> CPU_INT_SHIFT, irq_line_state);
} else {
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
ABORT_F("AMIC: unknown interrupt source ID 0x%llX", irq_id);
}
}
void AMIC::ack_slot_int(uint32_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_slot_int(uint8_t slot_int, uint8_t irq_line_state) {
// CAUTION: reverse logic (0 - true, 1 - false) in the IFR register!
if (irq_line_state) {
this->via2_slot_ifr &= ~irq_id;
this->via2_slot_ifr &= ~slot_int;
} else {
this->via2_slot_ifr |= irq_id;
this->via2_slot_ifr |= slot_int;
}
uint8_t new_irq = !!(~this->via2_slot_ifr & this->via2_slot_ier & 0x7F);
if (new_irq != this->via2_slot_irq) {
@@ -495,26 +542,26 @@ void AMIC::update_via2_irq() {
}
}
void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_via2_int(uint8_t via2_int, uint8_t irq_line_state) {
if (irq_line_state) {
this->via2_ifr |= irq_id;
this->via2_ifr |= via2_int;
} else {
this->via2_ifr &= ~irq_id;
this->via2_ifr &= ~via2_int;
}
this->update_via2_irq();
}
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state) {
if (this->int_ctrl & CPU_INT_MODE) { // 68k interrupt emulation mode?
if (irq_line_state) {
this->dev_irq_lines |= irq_id;
this->dev_irq_lines |= cpu_int;
} else {
this->dev_irq_lines &= ~irq_id;
this->dev_irq_lines &= ~cpu_int;
}
if (!(this->int_ctrl & CPU_INT_FLAG)) {
this->int_ctrl |= CPU_INT_FLAG;
ppc_assert_int();
LOG_F(5, "AMIC: CPU INT asserted, source: %d", irq_id);
LOG_F(5, "AMIC: CPU INT asserted, source: 0x%02x", cpu_int);
} else {
LOG_F(5, "AMIC: CPU INT already latched");
}
@@ -524,15 +571,15 @@ void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
}
}
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_id >= 0x100) { // DMA Interrupt Flags 1
irq_id = (irq_id >> 8) & 0xFFU;
void AMIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
if (irq_id >> DMA1_INT_SHIFT) { // DMA Interrupt Flags 1
irq_id = (irq_id >> DMA1_INT_SHIFT) & 0xFFU;
if (irq_line_state)
this->dma_ifr1 |= irq_id;
else
this->dma_ifr1 &= ~irq_id;
} else { // DMA Interrupt Flags 0
irq_id &= 0xFFU;
} else if (irq_id >> DMA0_INT_SHIFT) { // DMA Interrupt Flags 0
irq_id = (irq_id >> DMA0_INT_SHIFT) & 0xFFU;
if (irq_line_state)
this->dma_ifr0 |= irq_id;
else
@@ -574,7 +621,7 @@ void AmicSndOutDma::update_irq() {
if (new_level != this->irq_level) {
this->irq_level = new_level;
TimerManager::get_instance()->add_immediate_timer([this] {
this->int_ctrl->ack_dma_int(this->irq_id, this->irq_level);
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
});
}
}
@@ -708,25 +755,50 @@ void AmicScsiDma::write_ctrl(uint8_t value)
}
}
int AmicScsiDma::push_data(const char* src_ptr, int len)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
uint8_t *p_data = res.host_va;
std::memcpy(p_data, src_ptr, len);
this->addr_ptr += len;
return 0;
bool AmicScsiDma::is_ready() {
return (this->stat & 2) ? true : false;
}
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, req_len, false);
*p_data = res.host_va;
this->addr_ptr += req_len;
*avail_len = req_len;
return DmaPullResult::MoreData;
void AmicScsiDma::xfer_from_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_FROM_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
int got_bytes = this->dev_obj->xfer_from(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
}
void AmicScsiDma::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
int got_bytes = this->dev_obj->xfer_to(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
}
void AmicScsiDma::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
// =========================== Serial DMA stuff ===============================
@@ -754,7 +826,7 @@ DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len
return DmaPullResult::NoMoreData;
};
static vector<string> Amic_Subdevices = {
static std::vector<std::string> Amic_Subdevices = {
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
};
+53 -33
View File
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/video/displayid.h>
#include <devices/video/pdmonboard.h>
#include <atomic>
#include <cinttypes>
#include <memory>
@@ -43,7 +44,8 @@ namespace Swim3 { class Swim3Ctrl; }
/** Interrupt related constants. */
/** CPU interrupt register bits. */
enum : uint8_t {
enum : uint64_t {
CPU_INT_SHIFT = 0,
CPU_INT_VIA1 = 1 << 0, // (R) VIA1 interrupts
CPU_INT_VIA2 = 1 << 1, // (R) pseudo VIA2 interrupts
CPU_INT_ESCC = 1 << 2, // (R) ESCC interrupt
@@ -56,7 +58,8 @@ enum : uint8_t {
};
/** Pseudo VIA2 interrupt flag/enable register bits. */
enum : uint8_t {
enum : uint64_t {
VIA2_INT_SHIFT = 8,
VIA2_INT_SCSI_DRQ = 1 << 0, // (R) SCSI DRQ interrupt
VIA2_INT_ALL_SLOT = 1 << 1, // (R) all slot interrupts are signalled here
VIA2_INT_SCSI_IRQ = 1 << 3, // (R) SCSI IRQ interrupt
@@ -66,15 +69,23 @@ enum : uint8_t {
};
/** Slot interrupt flag/enable register bits. */
enum : uint8_t {
SLOT_INT_SLOT_0 = 1 << 2, // (R) ColdFusion Nubus slot 0 interrupt
SLOT_INT_SLOT_1 = 1 << 3, // (R) ColdFusion Nubus slot 1 interrupt
SLOT_INT_SLOT_2 = 1 << 4, // (R) ColdFusion Nubus slot 2 interrupt
enum : uint64_t {
SLOT_INT_SHIFT = 16,
SLOT_INT_SLOT_0 = 1 << 2, // (R) ColdFusion NuBus slot 0 interrupt
SLOT_INT_SLOT_1 = 1 << 3, // (R) ColdFusion NuBus slot 1 interrupt
SLOT_INT_SLOT_2 = 1 << 4, // (R) ColdFusion NuBus slot 2 interrupt
SLOT_INT_SLOT_VDS = 1 << 5, // (R) ColdFusion video direct slot interrupt
SLOT_INT_SLOT_PDS = 1 << 5, // (R) PDM processor direct slot interrupt
SLOT_INT_VBL = 1 << 6, // (R) built-in video VBL interrupt
};
/** DMA interrupt bits. */
enum : uint64_t {
DMA0_INT_SHIFT = 24,
DMA1_INT_SHIFT = 32,
DMA1_INT_SOUND = 1 << 1,
};
/** AMIC sound buffers are located at fixed offsets from DMA base. */
#define AMIC_SND_BUF0_OFFS 0x10000
#define AMIC_SND_BUF1_OFFS 0x12000
@@ -104,9 +115,9 @@ public:
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
void init_interrupts(InterruptCtrl *int_ctrl, uint32_t irq_id) {
void init_interrupts(InterruptCtrl *int_ctrl, uint64_t irq_id) {
this->int_ctrl = int_ctrl;
this->irq_id = irq_id;
this->snd_dma_irq_id = irq_id;
};
private:
@@ -120,7 +131,7 @@ private:
uint32_t cur_buf_pos;
InterruptCtrl *int_ctrl = nullptr;
uint32_t irq_id = 0;
uint64_t snd_dma_irq_id = 0;
uint8_t irq_level = 0;
};
@@ -164,19 +175,21 @@ private:
};
/** AMIC-specific SCSI DMA implementation. */
class AmicScsiDma : public DmaBidirChannel {
class AmicScsiDma : public DmaChannel {
public:
AmicScsiDma() : DmaBidirChannel("Scsi") {}
~AmicScsiDma() = default;
AmicScsiDma() = default;
~AmicScsiDma() = default;
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; };
int push_data(const char* src_ptr, int len);
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
void xfer_to_device();
void xfer_from_device();
bool is_ready() override;
void xfer_retry() override;
private:
uint32_t addr_ptr;
@@ -219,10 +232,11 @@ enum AMICReg : uint32_t {
Ariel_Config = 0x24002,
// VIA2 registers
// = 0x26000,
// = 0x26000, // byte, write 0x8f
VIA2_Slot_IFR = 0x26002,
VIA2_IFR = 0x26003,
// = 0x26010,
// = 0x26004, // byte, read
// = 0x26010, // byte, write 0x40
VIA2_Slot_IER = 0x26012,
VIA2_IER = 0x26013,
VIA2_IFR_RBV = 0x27A03, // RBV-compatible mirror for the VIA2_IFR
@@ -268,12 +282,18 @@ enum AMICReg : uint32_t {
Floppy_DMA_Ctrl = 0x32068,
SCC_DMA_Xmt_A_Ctrl = 0x32088,
SCC_RXA_Byte_Cnt_Hi = 0x32094, // 5 bits, read-only
SCC_RXA_Byte_Cnt_Lo = 0x32095, // 8 bits, read-only
// = 0x32092, // byte, read
// = 0x32093, // byte, read
SCC_RXA_Byte_Cnt_Hi = 0x32094, // 5 bits, read; byte, write 0x10
SCC_RXA_Byte_Cnt_Lo = 0x32095, // 8 bits, read; byte, write 0x00
SCC_DMA_Rcv_A_Ctrl = 0x32098,
// = 0x320A4, // byte, write 0x00
// = 0x320A5, // byte, write 0x07
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
SCC_RXB_Byte_Cnt_Hi = 0x320B4, // 5 bits, read-only
SCC_RXB_Byte_Cnt_Lo = 0x320B5, // 8 bits, read-only
// = 0x320B2, // byte, read
// = 0x320B3, // byte, read
SCC_RXB_Byte_Cnt_Hi = 0x320B4, // 5 bits, read; byte, write 0x10
SCC_RXB_Byte_Cnt_Lo = 0x320B5, // 8 bits, read; byte, write 0x00
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
};
@@ -288,22 +308,22 @@ 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;
// InterruptCtrl methods
uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
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 ack_slot_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_via2_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_slot_int(uint8_t slot_int, uint8_t irq_line_state);
void ack_via2_int(uint8_t via2_int, uint8_t irq_line_state);
void ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state);
void update_via2_irq();
private:
@@ -330,8 +350,8 @@ private:
uint8_t dev_irq_lines = 0; // state of the IRQ lines
// DMA IRQ flag registers
uint8_t dma_ifr0 = 0;
uint8_t dma_ifr1 = 0;
std::atomic<uint8_t> dma_ifr0{0};
std::atomic<uint8_t> dma_ifr1{0};
uint8_t dma_irq = 0;
// pseudo VIA2 state
+93 -38
View File
@@ -55,13 +55,13 @@ 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()
GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), 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 = 0x0002;
this->device_id = MIO_DEV_ID_GRANDCENTRAL;
this->class_rev = 0xFF000002;
this->cache_ln_sz = 8;
@@ -125,7 +125,12 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
this->curio = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->curio_dma = std::unique_ptr<DMAChannel> (new DMAChannel("curio_scsi"));
this->curio_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_CURIO));
this->curio->set_dma_channel(this->curio_dma.get());
this->curio_dma->connect(this->curio);
this->curio->connect(this->curio_dma.get());
//this->curio->set_dma_channel(this->curio_dma.get());
this->curio->set_drq_callback([this](const uint8_t drq_state) {
this->curio_dma->set_stat((drq_state & 1) << 5);
});
// connect Ethernet HW
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
@@ -163,12 +168,32 @@ void GrandCentral::notify_bar_change(int bar_num)
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x20000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
}
}
static const char *get_name_dma(unsigned dma_channel) {
switch (dma_channel) {
case MIO_GC_DMA_SCSI_CURIO : return "DMA_SCSI_CURIO" ;
case MIO_GC_DMA_FLOPPY : return "DMA_FLOPPY" ;
case MIO_GC_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
case MIO_GC_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
case MIO_GC_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
case MIO_GC_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
case MIO_GC_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
case MIO_GC_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
case MIO_GC_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
case MIO_GC_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
case MIO_GC_DMA_SCSI_MESH : return "DMA_SCSI_MESH" ;
default : return "unknown" ;
}
}
static uint8_t ENET_ROM[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
// The first 3 bytes of a MAC address is an OUI for "Apple, Inc."
// A MAC address cannot begin with 0x10 because that will get bit-flipped to 0x08.
// A MAC address that begins with 0x08 can be stored as bit-flipped or not bit-flipped.
static uint8_t mac_address[] = { 0x08, 0x00, 0x07, 0x44, 0x55, 0x66, 0x00, 0x00 };
static bool bit_flip_0x08 = false;
uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
{
@@ -181,9 +206,13 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case 1: // MACE
return this->mace->read((offset >> 4) & 0x1F);
case 2: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
if ((offset & 0xFF) < 0x0C) {
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
}
if ((offset & 0xFF) < 0x60) {
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
return 0;
}
// fallthrough
case 3: // ESCC MacRISC addressing
return this->escc->read((offset >> 4) & 0xF);
@@ -197,7 +226,17 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case 8: // MESH SCSI
return this->mesh->read((offset >> 4) & 0xF);
case 9: // ENET-ROM
return ENET_ROM[(offset >> 4) & 0x7];
{
uint8_t val = mac_address[(offset >> 4) & 0x7];
if (((offset >> 4) & 0x7) < 6) {
if (mac_address[0] == 0x08 && bit_flip_0x08)
val = (val * 0x0202020202ULL & 0x010884422010ULL) % 1023;
} else {
LOG_F(WARNING, "%s: reading byte %d of ENET_ROM using offset %x",
this->name.c_str(), (offset >> 4) & 0x7, offset);
}
return val;
}
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
case 0xB: // IOBus device #2 ; RaDACal/DACula
case 0xC: // IOBus device #3 ; chaos or bandit2 PRSNT bits ; sixty6
@@ -243,7 +282,10 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_GC_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_AUDIO_IN:
//LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
#if 0
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c",
this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
#endif
return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_SCSI_MESH:
if (this->mesh_dma) {
@@ -252,8 +294,11 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
}
// fallthrough
default:
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
this->name.c_str(), this->base_addr + offset);
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));
}
}
} else { // Interrupt related registers
switch (offset) {
@@ -288,10 +333,15 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
this->mace->write((offset >> 4) & 0x1F, value);
break;
case 2: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
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 3: // ESCC MacRISC addressing
this->escc->write((offset >> 4) & 0xF, value);
@@ -381,8 +431,11 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
}
// fallthrough
default:
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
this->name.c_str(), this->base_addr + offset);
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);
}
}
} else { // Interrupt related registers
switch (offset) {
@@ -417,7 +470,7 @@ void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
#define INT_TO_IRQ_ID(intx) (1 << intx)
uint32_t GrandCentral::register_dev_int(IntSrc src_id) {
uint64_t GrandCentral::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C);
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0D);
@@ -447,67 +500,69 @@ uint32_t GrandCentral::register_dev_int(IntSrc src_id) {
case IntSrc::PLATINUM : return INT_TO_IRQ_ID(0x1E); // EXT10
case IntSrc::PIPPIN_F : return INT_TO_IRQ_ID(0x1D); // EXT9
case IntSrc::PIPPIN_E : return INT_TO_IRQ_ID(0x1E); // EXT10
default:
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
#define DMA_INT_TO_IRQ_ID(intx) (1 << intx)
uint32_t GrandCentral::register_dma_int(IntSrc src_id) {
uint64_t GrandCentral::register_dma_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::DMA_SCSI_CURIO : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x0A);
case IntSrc::DMA_SCSI_CURIO : return INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_ETHERNET_Tx: return INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_ETHERNET_Rx: 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_SCSI_MESH : return INT_TO_IRQ_ID(0x0A);
default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t irq_line_state) {
void GrandCentral::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 ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
this->int_events |= (uint32_t)irq_id;
} else {
this->int_events &= ~irq_id;
this->int_events &= ~(uint32_t)irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
this->int_levels |= (uint32_t)irq_id;
} else {
this->int_levels &= ~irq_id;
this->int_levels &= ~(uint32_t)irq_id;
}
this->signal_cpu_int(irq_id);
}
void GrandCentral::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
void GrandCentral::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state);
}
void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
void GrandCentral::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state);
}
void GrandCentral::signal_cpu_int(uint32_t irq_id) {
void GrandCentral::signal_cpu_int(uint64_t irq_id) {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
LOG_F(5, "%s: CPU INT asserted, source: %d", this->name.c_str(), irq_id);
LOG_F(5, "%s: CPU INT asserted, source: 0x%08llx", this->name.c_str(), irq_id);
} else {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
}
@@ -522,7 +577,7 @@ void GrandCentral::clear_cpu_int() {
}
}
static const vector<string> GCSubdevices = {
static const std::vector<std::string> GCSubdevices = {
"NVRAM", "ViaCuda", "Escc", "ScsiCurio", "Sc53C94", "Mace", "Swim3"
};
+158 -227
View File
@@ -44,13 +44,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
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 = 0x0010;
this->device_id = MIO_DEV_ID_HEATHROW;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
@@ -80,6 +80,9 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
// 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"));
@@ -88,6 +91,9 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
// 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"));
@@ -103,6 +109,28 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
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
@@ -114,12 +142,13 @@ void HeathrowIC::notify_bar_change(int bar_num)
}
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->pci_name.c_str(), this->base_addr);
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) {
switch (offset >> 8) {
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);
@@ -131,17 +160,24 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
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:
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
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 HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
switch (offset >> 8) {
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;
@@ -154,17 +190,24 @@ void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
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:
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
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 HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
uint32_t res = 0;
uint32_t value;
LOG_F(9, "%s: reading from offset %x", this->name.c_str(), offset);
@@ -172,48 +215,57 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
switch (sub_addr) {
case 0:
res = mio_ctrl_read(offset, size);
value = mio_ctrl_read(offset, size);
break;
case 8:
res = dma_read(offset - 0x8000, size);
value = dma_read(offset & 0x7FFF, size);
break;
case 0x10: // SCSI
res = this->mesh->read((offset >> 4) & 0xF);
value = this->mesh->read((offset >> 4) & 0xF);
break;
case 0x11: // Ethernet
res = BYTESWAP_SIZED(this->bmac->read(offset & 0xFFFU), size);
value = BYTESWAP_SIZED(this->bmac->read(offset & 0xFFFU), size);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
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
return this->escc->read((offset >> 4) & 0xF);
value = this->escc->read((offset >> 4) & 0xF);
break;
case 0x14:
res = this->snd_codec->snd_ctrl_read(offset - 0x14000, size);
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size);
break;
case 0x15: // SWIM3
return this->swim3->read((offset >> 4 )& 0xF);
value = this->swim3->read((offset >> 4) & 0xF);
break;
case 0x16: // VIA-CUDA
case 0x17:
res = this->viacuda->read((offset - 0x16000) >> 9);
value = this->viacuda->read((offset >> 9) & 0xF);
break;
case 0x20: // IDE 0
res = this->ide_0->read((offset >> 4) & 0x1F, size);
value = this->ide_0->read((offset >> 4) & 0x1F, size);
break;
case 0x21: // IDE 1
res = this->ide_1->read((offset >> 4) & 0x1F, size);
value = this->ide_1->read((offset >> 4) & 0x1F, size);
break;
default:
if (sub_addr >= 0x60) {
res = this->nvram->read_byte((offset - 0x60000) >> 4);
value = this->nvram->read_byte((offset >> 4) & 0x1FFF);
} else {
value = 0;
LOG_F(WARNING, "Attempting to read from unmapped I/O space: %x", offset);
}
}
return res;
return value;
}
void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
@@ -223,10 +275,10 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
switch (sub_addr) {
case 0:
mio_ctrl_write(offset, value, size);
this->mio_ctrl_write(offset, value, size);
break;
case 8:
dma_write(offset - 0x8000, value, size);
this->dma_write(offset & 0x7FFF, value, size);
break;
case 0x10: // SCSI
this->mesh->write((offset >> 4) & 0xF, value);
@@ -235,23 +287,28 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
this->bmac->write(offset & 0xFFFU, BYTESWAP_SIZED(value, size));
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
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 - 0x14000, value, size);
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 - 0x16000) >> 9, value);
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 0x20: // IDE O
this->ide_0->write((offset >> 4) & 0x1F, value, size);
@@ -269,71 +326,72 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
}
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
uint32_t res = 0;
uint32_t value;
switch (offset & 0xFC) {
case MIO_INT_EVENTS2:
res = this->int_events2;
value = this->int_events >> 32;
break;
case MIO_INT_MASK2:
res = this->int_mask2;
value = this->int_mask >> 32;
break;
case MIO_INT_LEVELS2:
res = this->int_levels2;
value = this->int_levels >> 32;
break;
case MIO_INT_EVENTS1:
res = this->int_events1;
value = uint32_t(this->int_events);
break;
case MIO_INT_MASK1:
res = this->int_mask1;
value = uint32_t(this->int_mask);
break;
case MIO_INT_LEVELS1:
res = this->int_levels1;
value = uint32_t(int_levels);
break;
case MIO_INT_CLEAR1:
case MIO_INT_CLEAR2:
// some Mac OS drivers reads from those 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);
res = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
(this->cpu_id | (this->emmo_pin << 4));
value = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
(this->cpu_id | (this->emmo_pin << 4));
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(9, "read from MIO:Feat_Ctrl register");
res = this->feat_ctrl;
value = this->feat_ctrl;
break;
default:
value = 0;
LOG_F(WARNING, "read from unknown MIO register at %x", offset);
break;
}
return BYTESWAP_32(res);
return BYTESWAP_32(value);
}
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) {
case MIO_INT_MASK2:
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
this->int_mask |= uint64_t(BYTESWAP_32(value) & ~MACIO_INT_MODE) << 32;
this->signal_cpu_int();
break;
case MIO_INT_CLEAR2:
this->int_events2 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
this->int_events &= ~(uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL) << 32);
clear_cpu_int();
break;
case MIO_INT_MASK1:
this->int_mask1 = BYTESWAP_32(value);
this->int_mask = (this->int_mask & 0x7FFFFFFF00000000ULL) | BYTESWAP_32(value);
// copy IntMode bit to InterruptMask2 register
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
this->int_mask |= uint64_t(this->int_mask & MACIO_INT_MODE) << 32;
this->signal_cpu_int();
break;
case MIO_INT_CLEAR1:
if ((this->int_mask1 & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events1 = 0;
this->int_events2 = 0;
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events = 0;
} else {
this->int_events1 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
this->int_events &= ~uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL);
}
clear_cpu_int();
break;
@@ -353,7 +411,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
}
}
void HeathrowIC::feature_control(const uint32_t value)
void HeathrowIC::feature_control(uint32_t value)
{
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
@@ -366,31 +424,21 @@ void HeathrowIC::feature_control(const uint32_t value)
}
}
#define FIRST_INT1_BIT 12 // The first ten are DMA, the next 2 appear to be unused. We'll map 1:1 the INT1 bits 31..12 (0x1F..0x0C) as IRQ_ID bits.
#define FIRST_INT2_BIT 2 // Skip the first two which are Ethernet DMA. We'll map INT2 bits 13..2 (interrupts 45..34 or 0x2D..0x22) as IRQ_ID bits 11..0.
#define FIRST_INT1_IRQ_ID_BIT 12 // Same as INT1_BIT so there won't be any shifting required.
#define FIRST_INT2_IRQ_ID_BIT 0
#define INT_TO_IRQ_ID(intx) (1ULL << intx)
#define INT1_TO_IRQ_ID(int1) (1 << (int1 - FIRST_INT1_BIT + FIRST_INT1_IRQ_ID_BIT))
#define INT2_TO_IRQ_ID(int2) (1 << (int2 - FIRST_INT2_BIT + FIRST_INT2_IRQ_ID_BIT - 32))
#define INT_TO_IRQ_ID(intx) (intx < 32 ? INT1_TO_IRQ_ID(intx) : INT2_TO_IRQ_ID(intx))
#define IS_INT1(irq_id) (irq_id >= 1 << FIRST_INT1_IRQ_ID_BIT)
#define IRQ_ID_TO_INT1_MASK(irq_id) (irq_id <<= (FIRST_INT1_BIT - FIRST_INT1_IRQ_ID_BIT))
#define IRQ_ID_TO_INT2_MASK(irq_id) (irq_id <<= (FIRST_INT2_BIT - FIRST_INT2_IRQ_ID_BIT))
uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
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);
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D); // Beige G3 first IDE controller, or Yosemite ata-3
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); // nmiSource in AppleHeathrow/Heathrow.cpp
case IntSrc::NMI : return INT_TO_IRQ_ID(0x14); // nmiSource in AppleHeathrow/Heathrow.cpp; programmer-switch in B&W G3
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);
@@ -398,198 +446,82 @@ uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
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);
case IntSrc::FIREWIRE : return INT_TO_IRQ_ID(0x15); // Yosemite built-in PCI FireWire
case IntSrc::PCI_J12 : return INT_TO_IRQ_ID(0x16); // Yosemite 32-bit 66MHz slot for GPU
case IntSrc::PCI_J11 : return INT_TO_IRQ_ID(0x17); // Yosemite 64-bit 33MHz slot
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::ETHERNET : return INT_TO_IRQ_ID(0x2A);
default:
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
}
return 0;
}
#define FIRST_DMA_INT1_BIT 0 // bit 0 is SCSI DMA
#define FIRST_DMA_INT2_BIT 0 // bit 0 is Ethernet DMA Tx
#define FIRST_DMA_INT1_IRQ_ID_BIT 0
#define FIRST_DMA_INT2_IRQ_ID_BIT 16 // There's only 10 INT1 DMA bits but we'll put INT2 DMA bits in the upper 16 bits
#define DMA_INT1_TO_IRQ_ID(int1) (1 << (int1 - FIRST_DMA_INT1_BIT + FIRST_DMA_INT1_IRQ_ID_BIT))
#define DMA_INT2_TO_IRQ_ID(int2) (1 << (int2 - FIRST_DMA_INT2_BIT + FIRST_DMA_INT2_IRQ_ID_BIT - 32))
#define DMA_INT_TO_IRQ_ID(intx) (intx < 32 ? DMA_INT1_TO_IRQ_ID(intx) : DMA_INT2_TO_IRQ_ID(intx))
#define IS_DMA_INT1(irq_id) (irq_id < 1 << FIRST_DMA_INT2_IRQ_ID_BIT)
#define DMA_IRQ_ID_TO_INT1_MASK(irq_id) (irq_id <<= (FIRST_DMA_INT1_BIT - FIRST_DMA_INT1_IRQ_ID_BIT))
#define DMA_IRQ_ID_TO_INT2_MASK(irq_id) (irq_id >>= (FIRST_DMA_INT2_IRQ_ID_BIT - FIRST_DMA_INT2_BIT))
uint32_t HeathrowIC::register_dma_int(IntSrc src_id)
uint64_t HeathrowIC::register_dma_int(IntSrc src_id)
{
switch (src_id) {
case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_IDE1 : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x20);
case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x21);
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 0;
}
void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
void HeathrowIC::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
{
#if 1
if (!IS_INT1(irq_id)) { // does this irq_id belong to the second set?
IRQ_ID_TO_INT2_MASK(irq_id);
// 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(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d",
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state
);
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
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events2 on all transitions
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels2 & irq_id))) {
this->int_events2 |= irq_id;
} else {
this->int_events2 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
} else {
IRQ_ID_TO_INT1_MASK(irq_id);
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
#if 0
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d",
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state);
#endif
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels1 & irq_id))) {
this->int_events1 |= irq_id;
} else {
this->int_events1 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
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();
#endif
#if 0
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
if (!IS_INT1(irq_id)) {
IRQ_ID_TO_INT2_MASK(irq_id);
this->int_events2 |= irq_id; // signal IRQ line change
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
IRQ_ID_TO_INT1_MASK(irq_id);
this->int_events1 |= irq_id; // signal IRQ line change
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
this->signal_cpu_int();
} else {
LOG_F(WARNING, "%s: native interrupt mode not implemented", this->name.c_str());
}
#endif
}
void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
void HeathrowIC::ack_int(uint64_t irq_id, uint8_t irq_line_state)
{
#if 1
if (!IS_DMA_INT1(irq_id)) {
DMA_IRQ_ID_TO_INT2_MASK(irq_id);
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events2 on all transitions
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels2 & irq_id))) {
this->int_events2 |= irq_id;
} else {
this->int_events2 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
DMA_IRQ_ID_TO_INT1_MASK(irq_id);
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels1 & irq_id))) {
this->int_events1 |= irq_id;
} else {
this->int_events1 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
this->ack_int_common(irq_id, irq_line_state);
}
this->signal_cpu_int();
#endif
#if 0
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
if (!IS_DMA_INT1(irq_id)) {
DMA_IRQ_ID_TO_INT2_MASK(irq_id);
this->int_events2 |= irq_id; // signal IRQ line change
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
DMA_IRQ_ID_TO_INT1_MASK(irq_id);
this->int_events1 |= irq_id; // signal IRQ line change
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
this->signal_cpu_int();
} else {
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
}
#endif
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_events1 & this->int_mask1) || (this->int_events2 & this->int_mask2)) {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -601,8 +533,7 @@ void HeathrowIC::signal_cpu_int() {
void HeathrowIC::clear_cpu_int()
{
if (!(this->int_events1 & this->int_mask1) && !(this->int_events2 & this->int_mask2) &&
this->cpu_int_latch) {
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");
+69 -37
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)
@@ -70,6 +70,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <memory>
/** PCI device IDs for various MacIO ASICs. */
enum {
MIO_DEV_ID_GRANDCENTRAL = 0x0002,
MIO_DEV_ID_OHARE = 0x0007,
MIO_DEV_ID_HEATHROW = 0x0010,
MIO_DEV_ID_PADDINGTON = 0x0017,
};
/** Interrupt related constants. */
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
@@ -140,21 +148,21 @@ public:
}
// MMIO device 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;
// InterruptCtrl methods
uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
void attach_iodevice(int dev_num, IobusDevice* dev_obj);
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(uint32_t irq_id, uint8_t irq_line_state);
void signal_cpu_int(uint32_t irq_id);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
void signal_cpu_int(uint64_t irq_id);
void clear_cpu_int();
private:
@@ -208,22 +216,26 @@ public:
}
// MMIO device 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;
// InterruptCtrl methods
uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
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);
uint32_t read_ctrl(uint32_t offset, int size);
void write_ctrl(uint32_t offset, uint32_t value, int size);
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();
@@ -235,13 +247,25 @@ private:
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
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
// 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;
NVram* nvram; // NVRAM module
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
EsccController* escc; // ESCC serial controller
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
};
/**
@@ -288,7 +312,8 @@ enum {
/** MIO_OHARE_FEAT_CTRL bits. */
enum {
MIO_OH_FC_IN_USE_LED = 1 << 0,
MIO_OH_FC_IN_USE_LED = 1 << 0, // modem serial port in use in Open Firmware
// controls display sense on Beige G3 desktop
MIO_OH_FC_NOT_MB_PWR = 1 << 1,
MIO_OH_FC_PCI_MB_EN = 1 << 2,
MIO_OH_FC_IDE_MB_EN = 1 << 3,
@@ -347,15 +372,17 @@ public:
return std::unique_ptr<HeathrowIC>(new HeathrowIC());
}
void set_media_bay_id(uint8_t id);
// MMIO device 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;
// InterruptCtrl methods
uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
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);
@@ -365,23 +392,24 @@ protected:
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(const uint32_t value);
void feature_control(uint32_t value);
void signal_cpu_int();
void clear_cpu_int();
private:
uint32_t base_addr = 0;
std::atomic<uint32_t> int_events2{0};
uint32_t int_mask2 = 0;
std::atomic<uint32_t> int_levels2{0};
std::atomic<uint32_t> int_events1{0};
uint32_t int_mask1 = 0;
std::atomic<uint32_t> int_levels1{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
bool cpu_int_latch = false;
uint8_t cpu_id = 0xE0; // CPUID field (LSB of the MIO_HEAT_ID)
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
@@ -406,7 +434,11 @@ private:
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;
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
};
#endif /* MACIO_H */
+288 -96
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)
@@ -21,26 +21,36 @@ 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_INTERRUPT = loguru::Verbosity_9,
Verbosity_DBDMA = loguru::Verbosity_9
};
}
OHare::OHare() : PCIDevice("mac-io/ohare"), InterruptCtrl()
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 = 0x0007;
this->device_id = MIO_DEV_ID_OHARE;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
@@ -56,17 +66,62 @@ OHare::OHare() : PCIDevice("mac-io/ohare"), InterruptCtrl()
// connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// initialize sound chip and its DMA output channel, then wire them together
this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
// 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->awacs->set_dma_out(this->snd_out_dma.get());
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->awacs.get()),
std::bind(&AwacsScreamer::dma_out_stop, this->awacs.get())
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)
@@ -76,109 +131,165 @@ void OHare::notify_bar_change(int bar_num)
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
if (this->base_addr) {
LOG_F(WARNING, "%s: deallocating I/O memory not implemented",
this->pci_name.c_str());
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->pci_name.c_str(), this->base_addr);
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:
return read_ctrl(offset, size);
value = mio_ctrl_read(offset, size);
break;
case 8:
return dma_read(offset & 0x7FFF, size);
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
return this->escc->read((offset >> 4) & 0xF);
case 0x14: // AWACS
return this->awacs->snd_ctrl_read(offset & 0xFF, size);
case 0x16:
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:
return this->viacuda->read((offset >> 9) & 0xF);
case 0x20:
return 0xFF7FU;
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) {
return this->nvram->read_byte((offset - 0x60000) >> 4);
value = this->nvram->read_byte((offset - 0x60000) >> 4);
} else {
LOG_F(WARNING, "OHare: read from unimplemented register 0x%X",
this->base_addr + offset);
value = 0;
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
}
}
return 0xFFFFFFFFUL;
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->write_ctrl(offset, value, size);
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: // AWACS
this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
case 0x14:
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size);
break;
case 0x16:
case 0x17: // VIA-CUDA
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:
LOG_F(INFO, "OHare: write to IDE0 register at 0x%X", offset);
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, "OHare: writing to unimplemented device register 0x%X",
this->base_addr + offset);
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
}
}
}
uint32_t OHare::read_ctrl(uint32_t offset, int size)
{
uint32_t res = 0;
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:
res = this->int_mask;
value = this->int_mask;
break;
case MIO_INT_LEVELS1:
res = this->int_levels;
value = this->int_levels;
break;
case MIO_INT_EVENTS1:
res = this->int_events;
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;
case MIO_OHARE_ID: // HACK: no clue what this register is supposed to contain
res = 0xFFFFBFFFUL;
default:
LOG_F(WARNING, "OHare: read from unknown control register at %x", offset);
break;
value = 0;
LOG_F(WARNING, "%s: read @%02x.%c",
this->get_name().c_str(), offset, SIZE_ARG(size));
}
return BYTESWAP_32(res);
return BYTESWAP_32(value);
}
void OHare::write_ctrl(uint32_t offset, uint32_t value, int size)
{
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(INFO, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
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)) {
@@ -188,96 +299,177 @@ void OHare::write_ctrl(uint32_t offset, uint32_t value, int size)
}
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, "OHare: writing to unimplemented control register 0x%X",
this->base_addr + offset);
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)
{
switch (offset >> 8) {
case 8:
return this->snd_out_dma->reg_read(offset & 0xFF, 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:
LOG_F(WARNING, "OHare: unsupported DMA channel read, offset=0x%X", offset);
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 0xFFFFFFUL;
return value;
}
void OHare::dma_write(uint32_t offset, uint32_t value, int size)
{
switch (offset >> 8) {
case 8:
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:
LOG_F(WARNING, "OHare: unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
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 OHare::register_dev_int(IntSrc src_id)
void OHare::feature_control(const uint32_t value)
{
LOG_F(ERROR, "OHare: register_dev_int() not implemented");
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;
}
uint32_t OHare::register_dma_int(IntSrc src_id)
uint64_t OHare::register_dma_int(IntSrc src_id)
{
LOG_F(ERROR, "OHare: register_dma_int() not implemented");
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(uint32_t irq_id, uint8_t irq_line_state)
void OHare::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
{
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
#if 1
// 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 |= irq_id;
this->int_events |= (uint32_t)irq_id;
} else {
this->int_events &= ~irq_id;
this->int_events &= ~(uint32_t)irq_id;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
this->int_levels |= (uint32_t)irq_id;
} else {
this->int_levels &= ~irq_id;
this->int_levels &= ~(uint32_t)irq_id;
}
this->signal_cpu_int();
}
void OHare::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
void OHare::ack_int(uint64_t irq_id, uint8_t irq_line_state)
{
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
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;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
} else {
this->int_levels &= ~irq_id;
}
this->ack_int_common(irq_id, irq_line_state);
}
this->signal_cpu_int();
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) {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -289,19 +481,19 @@ void OHare::signal_cpu_int() {
void OHare::clear_cpu_int()
{
if (!this->int_events) {
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 vector<string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3"
static const std::vector<std::string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0"
};
static const DeviceDescription OHare_Descriptor = {
OHare::create, OHare_Subdevices, {}
};
OHare::create, OHare_Subdevices, {
}};
REGISTER_DEVICE(OHare, OHare_Descriptor);
+1 -1
View File
@@ -31,7 +31,7 @@ AspenCtrl::AspenCtrl() : MemCtrlBase() {
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for the configuration and status registers
add_mmio_region(0xF8000000, 0x800, this);
this->add_mmio_region(0xF8000000, 0x800, this);
}
int AspenCtrl::device_postinit() {
+1 -1
View File
@@ -46,7 +46,7 @@ enum {
GPIO_OUT = 14, // 0x38
};
#define ASPEN_REV_1 0x01000000
constexpr auto ASPEN_REV_1 = 0x01000000;
/** Aspen RAM bank size bits. */
enum {
+11 -7
View File
@@ -37,7 +37,7 @@ HammerheadCtrl::HammerheadCtrl() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for the configuration and status registers
add_mmio_region(0xF8000000, 0x500, this);
this->add_mmio_region(0xF8000000, 0x500, this);
}
uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
@@ -47,10 +47,11 @@ uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
offset <= HammerheadReg::BANK_25_BASE_LSB) {
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
int bank = offset >> 1;
if (offset & 1) { // return the LSB part
result = bank_base[offset >> 1] & 0xFFU;
result = bank_base[bank] & 0xFFU;
} else { // return the MSB part
result = bank_base[offset >> 1] >> 8;
result = bank_base[bank] >> 8;
}
goto finish;
}
@@ -94,13 +95,14 @@ void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value,
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
offset <= HammerheadReg::BANK_25_BASE_LSB) {
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
int bank = offset >> 1;
if (offset & 1) { // update the LSB part
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0xFF00U) | value;
bank_base[bank] = (bank_base[bank] & 0xFF00U) | value;
} else { // update the MSB part
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0x00FFU) | (value << 8);
bank_base[bank] = (bank_base[bank] & 0x00FFU) | (value << 8);
}
LOG_F(INFO, "%s: bank base #%d set to 0x%X", this->name.c_str(),
offset >> 1, bank_base[offset >> 1]);
bank, bank_base[bank]);
return;
}
@@ -128,11 +130,13 @@ void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value,
void HammerheadCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
{
if (slot_num < 0 || slot_num >= 26) {
if (slot_num < 0 || slot_num >= 13) {
ABORT_F("%s: invalid DIMM slot number %d", this->name.c_str(), slot_num);
}
switch (capacity) {
case 0:
break;
case DRAM_CAP_2MB:
case DRAM_CAP_4MB:
case DRAM_CAP_8MB:
+16 -5
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)
@@ -38,10 +38,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
namespace Hammerhead {
#define RISC_MACHINE 0x3
#define MACH_TYPE_TNT 0x1
#define EXTENDED_ID 0x1 // examine some other registers to get full ID
#define HH_CPU_ID_TNT ((RISC_MACHINE << 4) | (EXTENDED_ID << 3) | MACH_TYPE_TNT)
constexpr auto RISC_MACHINE = 0x3;
constexpr auto MACH_TYPE_TNT = 0x1;
constexpr auto EXTENDED_ID = 0x1; // examine some other registers to get full ID
constexpr auto HH_CPU_ID_TNT = ((RISC_MACHINE << 4) | (EXTENDED_ID << 3) | MACH_TYPE_TNT);
// constants for the MBID field of the MOTHERBOARD_ID register
enum {
@@ -62,6 +62,11 @@ namespace Hammerhead {
BUS_SPEED_50_MHZ = 3
};
// bits for the ARBITER_CONFIG register
enum {
TWO_CPU = 1 << 1,
};
// bus master IDs for the WHO_AM_I register
enum {
BM_VIDEO_BRIDGE = 1 << 4,
@@ -71,6 +76,11 @@ namespace Hammerhead {
BM_SECONDARY_CPU = 1 << 0
};
// Interrupt bits for the INT_REG register
enum {
SEC_INT = 1 << 7,
};
// Configuration and status registers.
enum HammerheadReg : uint16_t {
CPU_ID = 0x00,
@@ -85,6 +95,7 @@ namespace Hammerhead {
ARBITER_CONFIG = 0x90,
ARBUS_TIMEOUT = 0xA0,
WHO_AM_I = 0xB0,
INT_REG = 0xC0,
L2_CACHE_CONFIG = 0xE0,
BANK_0_BASE_MSB = 0x1C0,
BANK_25_BASE_LSB = 0x4F0,
+1 -1
View File
@@ -36,7 +36,7 @@ HMC::HMC() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add memory mapped I/O region for the HMC control register
add_mmio_region(0x50F40000, 0x10000, this);
this->add_mmio_region(0x50F40000, 0x10000, this);
this->ctrl_reg = 0ULL;
this->bit_pos = 0;
+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)
@@ -75,9 +75,9 @@ public:
int install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_b_size);
uint64_t get_control_reg(void) {
uint64_t get_control_reg(void) const {
return this->ctrl_reg;
};
}
protected:
void remap_ram_regions();
+118 -26
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)
@@ -42,6 +42,51 @@ MemCtrlBase::~MemCtrlBase() {
this->address_map.clear();
}
static std::string get_type_str(uint32_t type) {
std::string str;
if (type & RT_ROM) {
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;
}
static std::string get_entry_str(const AddressMapEntry* entry) {
std::string str;
char buf[50];
if (entry) {
snprintf(buf, sizeof(buf), "0x%08X..0x%08X", entry->start, entry->end);
str = std::string(buf) + " (" + get_type_str(entry->type) + ")";
if (entry->devobj)
str += " (" + entry->devobj->get_name() + ")";
if (entry->type & RT_MIRROR) {
snprintf(buf, sizeof(buf), " -> 0x%08X..0x%08X", entry->mirror,
entry->mirror + entry->end - entry->start);
str += std::string(buf);
}
} else {
str = "null";
}
return str;
}
static inline bool match_mem_entry(const AddressMapEntry* entry,
const uint32_t start, const uint32_t end,
@@ -144,19 +189,20 @@ bool MemCtrlBase::is_range_free(uint32_t addr, uint32_t size) {
}
bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
uint32_t dest_addr, uint32_t type,
uint8_t init_val = 0)
AddressMapEntry* MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
uint32_t dest_addr, uint32_t type,
uint8_t *mem_ptr = nullptr)
{
AddressMapEntry *entry;
// bail out if a memory region for the given range already exists
if (!is_range_free(start_addr, size))
return false;
return nullptr;
uint8_t* reg_content = new uint8_t[size](); // allocate and clear to zero
this->mem_regions.push_back(reg_content);
if (!mem_ptr) {
mem_ptr = new uint8_t[size](); // allocate and clear to zero
this->mem_regions.push_back(mem_ptr);
}
entry = new AddressMapEntry;
@@ -166,7 +212,7 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
entry->mirror = dest_addr;
entry->type = type;
entry->devobj = nullptr;
entry->mem_ptr = reg_content;
entry->mem_ptr = mem_ptr;
// Keep address_map sorted, that way the RAM region (which starts at 0 and
// is most often requested) will be found by find_range on the first
@@ -189,27 +235,32 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
dest_addr
);
return true;
return entry;
}
bool MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size) {
return add_mem_region(start_addr, size, 0, RT_ROM);
}
bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
return add_mem_region(start_addr, size, 0, RT_RAM);
}
AddressMapEntry* MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size,
uint8_t *mem_ptr) {
return add_mem_region(start_addr, size, 0, RT_RAM, mem_ptr);
}
bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry *entry, *ref_entry;
ref_entry = find_range(dest_addr);
if (!ref_entry)
return false;
return nullptr;
// use origin's size if no size was specified
if (!size)
@@ -218,7 +269,7 @@ bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
if (ref_entry->start + offset + size - 1 > ref_entry->end) {
LOG_F(ERROR, "Partial mirror outside the origin, offset=0x%X, size=0x%X",
offset, size);
return false;
return nullptr;
}
entry = new AddressMapEntry;
@@ -247,45 +298,45 @@ bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
: ""
);
return true;
return entry;
}
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
AddressMapEntry* MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
return this->add_mem_mirror_common(start_addr, dest_addr);
}
bool MemCtrlBase::add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
AddressMapEntry* MemCtrlBase::add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
uint32_t offset, uint32_t size) {
return this->add_mem_mirror_common(start_addr, dest_addr, offset, size);
}
bool MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
AddressMapEntry* MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
AddressMapEntry* ref_entry;
uint32_t cpy_size;
ref_entry = find_range(load_addr);
if (!ref_entry)
return false;
return nullptr;
uint32_t load_offset = load_addr - ref_entry->start;
cpy_size = std::min(ref_entry->end - ref_entry->start + 1, size);
memcpy(ref_entry->mem_ptr + load_offset, data, cpy_size);
return true;
return ref_entry;
}
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
AddressMapEntry* MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
{
AddressMapEntry *entry;
// bail out if a memory region for the given range already exists
if (!is_range_free(start_addr, size))
return false;
return nullptr;
entry = new AddressMapEntry;
@@ -307,9 +358,10 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
: ""
);
return true;
return entry;
}
bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
{
int found = 0;
@@ -351,6 +403,36 @@ bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODev
return (found > 0);
}
AddressMapEntry* MemCtrlBase::remove_region(AddressMapEntry* entry)
{
int found = 0;
address_map.erase(std::remove_if(address_map.begin(), address_map.end(),
[entry, &found](const AddressMapEntry *cmp_entry) {
if (entry == cmp_entry) {
if (found)
LOG_F(ERROR, "Removed mem region %s", get_entry_str(entry).c_str());
else
LOG_F(INFO, "Removed mem region %s", get_entry_str(entry).c_str());
found++;
return true;
}
return false;
}
), address_map.end());
if (found == 0) {
LOG_F(ERROR, "Cannot find mem region %s to remove",
get_entry_str(entry).c_str()
);
return nullptr;
}
return entry;
}
AddressMapEntry* MemCtrlBase::find_rom_region()
{
for (auto& entry : address_map) {
@@ -372,3 +454,13 @@ uint8_t *MemCtrlBase::get_region_hostmem_ptr(const uint32_t addr) {
else
return (addr - reg_desc->start) + reg_desc->mem_ptr;
}
void MemCtrlBase::dump_regions()
{
int i = 0;
for (auto& entry : address_map) {
printf("%2d: %s\n", i, get_entry_str(entry).c_str());
i++;
}
}
Loaded 100 of 170 files, more files were not shown because too many files have changed in this diff. Show more