Compare commits

...
426 Commits
Author SHA1 Message Date
joevt dfea8fa2cd debugger: Show register values during stepping.
So you don't need to use regs after every instruction.
2026-03-31 07:55:21 -07:00
joevt 07f781bf56 debugger: Disassemble instructions while stepping. 2026-03-31 07:54:57 -07:00
joevt 91f5ccc3f9 ppcmmu: Simplify pteg address calculation.
Maybe the optimizer can do it or maybe not.
2026-03-31 07:39:45 -07:00
Maxim Poliakovski 995da89bda scsiblockcmds: fix block descriptor.
SCSI-3 standard specifies a slightly different format for
the short block descriptor applied to direct-access devices.
2026-03-24 20:15:53 +01:00
dingusdev d1d496fda9 Version Prep 2026-03-23 19:30:44 -07:00
joevt bf7fc5fb5a viacuda: Postpone onesec timer if SR int pending. 2026-03-23 07:26:19 -07:00
joevt e275635697 main: Cancel all timers before restart.
Some devices do not cancel their timers when destructed.
If they exist after restart, then bad things can happen.
2026-03-22 17:15:53 -07:00
joevt d8d7ebd40c timermanager: Check for empty queue before remove. 2026-03-22 17:15:35 -07:00
joevt fa6abacf4e hostevents: mouse relative coordinates are signed. 2026-03-22 17:14:06 -07:00
joevt ef8c83108c CLI11: Update to v2.6.2. 2026-03-20 07:00:38 -07:00
joevt 0b32714200 README: Cleanup and add some cmake notes. 2026-03-19 19:33:00 -07:00
joevt c6f17a846b escc: Make W7Prime a peer of WR7.
This simplifies the switch statement and storage of register values.
2026-03-14 15:56:50 -07:00
joevt fb02b15063 escc: Update brg_clock_src when it changes. 2026-03-14 15:55:35 -07:00
joevt ff3e66ecd7 adbmouse: Use parameter for buttons state.
- Rename the parameter from buttons_state to buttons so it is not
  confused with the class data member.

- AdbAppleJack triggers should affect mouse button state in register 0.
  That means AdbMouse::get_register_0 needs to use the buttons parameter
  instead of the buttons_state class data member.
2026-03-12 20:50:35 -07:00
joevt 626497bdc0 adbapplejack: Rename buttons_state.
So that it is not confused with buttons_state of AdbMouse.
2026-03-12 20:50:28 -07:00
Maxim Poliakovski 0b018bd0a4 scsihd: use generic START_STOP_UNIT. 2026-03-12 01:59:23 +01:00
Maxim Poliakovski 9505745006 scsiblockcmds: generic START_STOP_UNIT. 2026-03-12 01:59:23 +01:00
Maxim Poliakovski b62bb5ffa4 blockstoragedevice.h: fix indentation. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski 46901d8d03 scsihd: use generic PREVENT_ALLOW_MEDIUM_REMOVAL. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski cb1e318a28 scsiblockcmds: generic PREVENT_ALLOW_MEDIUM_REMOVAL. 2026-03-10 16:32:45 +01:00
Maxim Poliakovski 93bca96794 scsiphysinterface.h: add set_eject_state method. 2026-03-10 16:32:45 +01:00
joevt 917eec6ff4 CMakeLists.txt: Fix testppc copy command.
The destination of the .csv files should be that of the testppc
executable, not the dingusppc executable.

On Apple platform, the dingusppc executable may be a bundle and copying
the .csv files into the bundle causes a code signing error.
2026-03-10 07:10:11 -07:00
Maxim Poliakovski 954a277bb3 scsihd: remove stub for REASSIGN. 2026-03-10 01:12:51 +01:00
Maxim Poliakovski 202446025a scsiphysdevice: implement writing of big data in chunks. 2026-03-10 00:41:45 +01:00
Maxim Poliakovski f2a9f3cb56 scsi.h: add write_more_data callback. 2026-03-10 00:41:31 +01:00
Tim Jarzombek ad4515721b amic: Emulate SCC receive DMA registers instead of returning random values.
The SCC DMA Receive control registers previously returned std::rand(),
a workaround to unblock Mac OS 8.5/8.5.1 boot which polls these
registers expecting specific bit patterns. This caused non-deterministic
bimodal boot times (~10s vs ~18s) on Power Mac 6100 as the guest would
sometimes enter a ~7s polling loop depending on the random value.

Add AmicSerialRcvDma to properly track the control register and byte
count state for both SCC receive channels. Writes now update the status
byte using the same bit manipulation as the transmit DMA channels, and
reads return the tracked state. Also wire up the RX byte count registers
(SCC_RXA/B_Byte_Cnt_Hi/Lo) which were previously ignored on write.
2026-03-08 18:34:00 -07:00
dingusdevandTim Jarzombek 3decd4b9fc Cuda improvements
* Implements missing Cuda commands
* Proper One Second Mode handling
* Add Stat Response ADB bit
* Typo fixes

Co-Authored-By: Tim Jarzombek <[email protected]>
2026-03-08 16:26:47 -07:00
joevt 16117e6c60 escc: Add channel and direction enums.
Also fix dma_ch index in dma_out_tx, dma_flush_tx.
2026-03-08 10:54:09 -07:00
joevt 9bae84ff07 z85c30: Cleanup and missing info. 2026-03-08 10:51:09 -07:00
joevt 4ca03953d7 ppcemu: Fix EAR spr exception. 2026-03-08 10:42:22 -07:00
joevt dd31610013 viacuda: Increase input buffer size to 259 bytes. 2026-03-08 10:13:08 -07:00
dingusdev 8b2c0b0de9 Slightly safer way to use read_more_data 2026-02-24 18:51:54 -07:00
Maxim Poliakovski 6075807998 scsihd: use new MODE SENSE implementation. 2026-02-23 18:34:31 +01:00
Maxim Poliakovski 9d5373120d scsiblockcmds: fix parameters for error recovery page. 2026-02-23 16:12:28 +01:00
Maxim Poliakovski 6c29738441 scsihd: pass reads and writes to ScsiBlockCmds. 2026-02-23 03:58:45 +01:00
Maxim Poliakovski a8ff30ef36 New class ScsiBlockCmds. 2026-02-23 03:50:16 +01:00
Maxim Poliakovski 20dfe798ac scsicommoncmds: implement generic MODE SENSE. 2026-02-23 03:12:59 +01:00
Maxim Poliakovski 1a8d691777 scsi.h: more mode sense page codes. 2026-02-23 01:48:09 +01:00
Maxim Poliakovski 34b4d6387d blockstoragedevice: clean up and add write support. 2026-02-23 01:09:23 +01:00
Maxim Poliakovski 9ca3e5e870 scsiphysinterface.h: more callbacks. 2026-02-23 00:40:56 +01:00
Maxim Poliakovski 0d25f6dc33 scsi.h: rename READ_CAPACITY_10 to READ_CAPACITY. 2026-02-22 23:48:28 +01:00
Maxim Poliakovski 2735449c75 scsiphysdevice: fix send_data() again to support big transfers. 2026-02-22 22:23:03 +01:00
Maxim Poliakovski 6092882a45 ppcopcodes: fix bit test in eciwx/ecowx. 2026-02-22 18:17:29 +01:00
Maxim Poliakovski 345bcf8a73 scsiphysdevice: remove prepare_data method.
Clean up and simplify buffer setup for various
data transfer phases.
2026-02-19 02:42:59 +01:00
Maxim Poliakovski 6e18241be6 scsiphysinterface: add set_buffer method. 2026-02-19 02:33:29 +01:00
Maxim Poliakovski a9fcde836c Replace get_more_data method with a callback. 2026-02-17 16:06:00 +01:00
Maxim Poliakovski b52a7bebbc scsiphysdevice.cpp: improve send_data() method. 2026-02-17 16:06:00 +01:00
Maxim Poliakovski 6033f75521 scsicommoncmds: minor fixes. 2026-02-15 21:15:50 +01:00
Maxim Poliakovski 2ea8fee204 blockstoragedevice: switch parameter for set_fpos to uint64_t. 2026-02-15 21:15:50 +01:00
Maxim Poliakovski 25a5f193ba blockstoragedevice: assign default value to the 2nd param of read_begin. 2026-02-15 21:15:50 +01:00
dingusdev d9bcb47beb Set up code for Mac OS X bundles 2026-02-15 21:15:50 +01:00
Tim Jarzombek 398e0b025d Fix bugs caught by fuzzing 2026-02-12 21:11:11 -05:00
Maxim Poliakovski cbff26539a scsi.h: add constants for page control in MODE SENSE. 2026-02-12 01:23:00 +01:00
Maxim Poliakovski 8a280f71ab Move page numbers for MODE SENSE to scsi.h 2026-02-12 01:06:34 +01:00
Tim Jarzombek 3545296e3a ci: add macOS (arm64 and x64), general refactor (#163)
- Adds macOS builds on arm64 and x64
- Caching to improve build speeds
- Upload build logs on failure
- Retain PR artifacts for 7 days, others for 30 days
2026-02-09 07:22:50 -07:00
joevt b182e01218 viacuda: Avoid float in VIA timer calculations.
- float is limited to 24 bits so use longer uint32_t or uint64_t.
- Rename the formal parameter so it more closely matches the actual
  parameter. Also, don't hide the class field.
- Multiply is faster than divide.
2026-02-07 20:51:48 -07:00
Maxim Poliakovski 200a2aa9a7 Move SCSI devices to new architecture.
That implies a clear separation between implementation
of the SCSI commands and the physical device layer.
2026-02-08 02:38:02 +01:00
Maxim Poliakovski 470c9a32f5 Implement common SCSI commands in a separate class. 2026-02-08 02:22:23 +01:00
Maxim Poliakovski 44343ad591 New interface for physical SCSI/ATAPI layer abstraction. 2026-02-08 02:22:23 +01:00
Maxim Poliakovski 022d5e4e00 scsi.h: add enum for device capabilities. 2026-02-07 03:00:09 +01:00
Maxim Poliakovski 3dde616c57 scsihd.h: add missing overrides. 2026-02-06 21:57:51 +01:00
Maxim Poliakovski b82dae7ad6 scsihd: remove unused send_diagnostic() stub. 2026-02-04 19:15:37 +01:00
Maxim Poliakovski 924cc5ed97 scsi.h: remove definitions for vendor specific commands. 2026-02-04 18:52:01 +01:00
Maxim Poliakovski 0570513ff1 scsicdrom: remove vendor specific commands. 2026-02-04 18:52:01 +01:00
Maxim Poliakovski fd8d89b711 scsi.h: set subtype for ScsiSense and ScsiError to uint8_t. 2026-02-04 17:58:55 +01:00
Maxim Poliakovski 17f13e8eb3 scsiphysdevice: cleanup logging. 2026-02-04 16:35:32 +01:00
Maxim Poliakovski 8e9ee07e9b Rename ScsiDevice to ScsiPhysDevice. 2026-02-04 15:47:05 +01:00
dingusdevandjoevt 129c5053f6 Improve ADB keyboard emulation
Co-Authored-By: joevt <[email protected]>
2026-02-04 07:21:44 -07:00
dingusdev d29e15332c Merge pull request #162 from Cacodemon345/patch-2
atirage: Implement reads/writes from/to the auxiliary aperture
2026-02-04 07:00:47 -07:00
Cacodemon345 7abc8afc97 atirage: Remove more redundant code 2026-02-04 17:23:41 +06:00
Cacodemon345 4c3989fa13 atirage: Remove unreachable logging for auxiliary aperture 2026-02-04 17:19:08 +06:00
Cacodemon345 6a3654e851 atirage: Implement reads/writes from the auxiliary aperture 2026-02-04 16:56:19 +06:00
Cacodemon345 7c29e41fae atirage: Definitions for auxiliary register aperture 2026-02-04 16:47:57 +06:00
Maxim Poliakovski 7e07919d7c scsi.h: add device types enum. 2026-02-01 02:10:08 +01:00
Maxim Poliakovski 7d4ebf5bf1 Fix spelling. 2026-02-01 02:10:08 +01:00
dingusdevandAndrew Randrianasulu 79c9b5f63e Update manual.md
Co-Authored-By: Andrew Randrianasulu <[email protected]>
2026-01-31 08:36:35 -07:00
Maxim Poliakovski 0fee0a5270 control: reduce logging noise.
Mac OS 7.5.5 accesses the monitor sense register many times.
This causes a huge amount of pointless log messages.
This commit changes priority of the log messages
for the monitor sense registers so none will be displayed
by default.
2026-01-31 15:11:12 +01:00
joevt 60d4750d54 ppcopcodes: Decrementer fixes.
- Always add a tick to the timeout calculation.
- Make sure value of decrementer is < 0 for timed decrementer exception.
- Don't recalculate decrementer write time stamp in the case of an
  immediate decrementer exception.
2026-01-31 13:17:22 +01:00
dingusdev 213dd4c16e Update copyright info further 2026-01-30 08:12:04 -07:00
Maxim Poliakovski 0d22d5cbd8 ppcopcodes: fix decrementer interrupts.
Enable decrementer interrupts for MPC601
required by  MkLinux DR3.
2026-01-30 15:40:15 +01:00
joevt 140c9adb0c hostevents_sdl: Fix INTERNATIONAL3 for non-Japan. 2026-01-30 15:40:15 +01:00
joevt 489bd0dfcf viacuda: Fix append_data. 2026-01-30 07:06:03 -07:00
Maxim Poliakovski e75ee8d32a Update copyright year. 2026-01-30 12:15:00 +01:00
joevt 769ef49f67 ppcopcodes: Implement mfspr for tbl_u and tbu_u. 2026-01-29 07:53:37 -07:00
joevt e0677a8a1f ppcexec: Add TBL_U and TBU_U for reg_op. 2026-01-29 07:53:27 -07:00
joevt 356e74f8c2 ppcdisasm: Cleanup spr calculation. 2026-01-29 07:53:17 -07:00
joevt 3e8121c1f5 ppcdisasm: Add tbl_u and tbu_u for mfspr. 2026-01-29 07:53:02 -07:00
Maxim Poliakovski c2df2e4ad2 sc53c94: fix int_status for CMD_COMPLETE_STEPS.
No known manual specifies interrupt status for COMPLETE_STEPS.
MkLinux DR3 expects that int_status contains INTSTAT_SO after
this command.
2026-01-25 03:32:28 +01:00
Maxim Poliakovski df36ad8369 scsihd: temporarily fix req_sense(). 2026-01-25 03:01:10 +01:00
Maxim Poliakovski ad2abf4433 scsi.h: initialize REQ_SENSE state in ScsiDevice. 2026-01-25 03:01:10 +01:00
dingusdev 0ca4e14195 Clarify command line arguments 2026-01-24 15:59:53 -07:00
Maxim Poliakovski 5883b39c2b viacuda: disable async packets during Sync transaction. 2026-01-23 02:12:44 +01:00
Maxim Poliakovski 1b7338960f viacuda: fix typo. 2026-01-22 15:21:13 +01:00
joevt d693b0f443 maciotwo: Fix IDE read/write mask again.
Use the entire 4K range.
2026-01-20 07:07:11 -07:00
joevt 5c646e8270 maciotwo: Add methods to override OHARE_ID ids. 2026-01-17 08:40:45 -07:00
joevt 65c5d2425e maciotwo: Fix IDE read/write mask. 2026-01-17 07:02:06 -07:00
joevt f2676e0324 maciotwo: Make Ide1 optional.
Some Macs that use OHare do not have a second ATA bus exposed by Open
Firmware. Allow Ide1 to not be included.

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

This change forces handling of the individual DIMM sizes.

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

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

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

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

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

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

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

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

No files matched your search

+236 -216
View File
@@ -4,262 +4,282 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
build-linux:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: install_dependencies
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/linux
key: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
- name: init_submodules
run: git submodule update --init --recursive
sudo apt-get install -y -qq libsdl2-dev ninja-build ccache
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/linux
CCACHE_BASEDIR: ${{ github.workspace }}
run: cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
build-windows:
runs-on: windows-latest
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-macos:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
cache-name: [msys64-cache]
include:
- runner: macos-latest
arch: arm64
brew_prefix: /opt/homebrew
- runner: macos-15-intel
arch: x86_64
brew_prefix: /usr/local
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
key: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew install sdl2 ccache ninja
- name: Configure CMake
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
export PATH="${{ matrix.brew_prefix }}/opt/ccache/libexec:$PATH"
cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-macOS-${{ matrix.arch }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-windows-msys2:
runs-on: windows-latest
timeout-minutes: 45
env:
MSYSTEM: MINGW64
FF_SCRIPT_SECTIONS: '0'
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
TEST_ARGS: '--no-suite qtest'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up MSYS2
run: |
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
If ( !(Test-Path -Path msys64\var\cache ) ) {
mkdir msys64\var\cache
}
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
Write-Output "Cached installer sig" ;
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
Write-Output "Mis-matched installer sig, new installer download required" ;
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
} else {
Write-Output "Matched installer sig, cached installer still valid"
}
} else {
Write-Output "No cached installer sig, new installer download required" ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
}
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
Write-Output "Fetching latest installer" ;
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
} else {
Write-Output "Using cached installer"
}
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
msys64\var\cache\msys2.exe -y
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
taskkill /F /FI "MODULES eq msys-2.0.dll"
- name: Install dependencies
run: |
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
bison \
diffutils \
flex \
tar \
doxygen \
cmake \
wget \
git \
grep \
make \
rsync \
ninja \
glib2-devel \
patch \
sed \
mingw-w64-x86_64-cmake \
mingw-w64-x86_64-binutils \
mingw-w64-x86_64-doxygen \
mingw-w64-x86_64-capstone \
mingw-w64-x86_64-ccache \
mingw-w64-x86_64-curl \
mingw-w64-x86_64-cyrus-sasl \
mingw-w64-x86_64-dtc \
mingw-w64-x86_64-gcc \
mingw-w64-x86_64-glib2 \
mingw-w64-x86_64-gnutls \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-libgcrypt \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-libnfs \
mingw-w64-x86_64-libpng \
mingw-w64-x86_64-libssh \
mingw-w64-x86_64-libtasn1 \
mingw-w64-x86_64-libusb \
mingw-w64-x86_64-lzo2 \
mingw-w64-x86_64-libslirp \
mingw-w64-x86_64-nettle \
mingw-w64-x86_64-clang \
mingw-w64-x86_64-ninja \
mingw-w64-x86_64-pixman \
mingw-w64-x86_64-pkgconf \
mingw-w64-x86_64-python \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-SDL2_image \
mingw-w64-x86_64-snappy \
mingw-w64-x86_64-spice \
mingw-w64-x86_64-usbredir \
mingw-w64-x86_64-zstd \
mingw-w64-x86_64-make'
- name: init_submodules
run: git submodule update --init --recursive
uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/msys
key: windows-msys-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: windows-msys-ccache-${{ env.BUILD_TYPE }}-
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
cmake
ninja
git
mingw-w64-x86_64-cmake
mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-ninja
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-ccache
- name: Build
shell: msys2 {0}
run: |
echo "Running build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
export CHERE_INVOKING=yes
export MSYS=winsymlinks:native
export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
export CCACHE_DIR="${GITHUB_WORKSPACE}/.ccache/msys"
export CCACHE_DEPEND=1
ccache --zero-stats || true
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
ccache --show-stats || true
echo "Finished build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Test
shell: msys2 {0}
run: |
Write-Output "Running build at $(Get-Date -Format u)"
$env:CHERE_INVOKING = 'yes' # Preserve the current working directory
$env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
$env:CCACHE_BASEDIR = "$env:CI_PROJECT_DIR"
$env:CCACHE_DIR = "$env:CCACHE_BASEDIR/ccache"
$env:CCACHE_MAXSIZE = "500M"
$env:CCACHE_DEPEND = 1 # cache misses are too expensive with preprocessor mode
$env:CC = "ccache gcc"
mkdir build
cd build
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --zero-stats"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True .. && ninja"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --show-stats"
Write-Output "Finished build at $(Get-Date -Format u)"
ctest --output-on-failure --parallel
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSYS
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
vsbuild-CLANG:
build-windows-vsbuild:
runs-on: windows-latest
timeout-minutes: 45
env:
VCPKG_FEATURE_FLAGS: binarycaching
strategy:
fail-fast: false
matrix:
include:
- name: clang
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: CLANG
- name: msvc
generator: Ninja
cmake_args: ""
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSVC
- name: msbuild
generator: "Visual Studio 17 2022"
cmake_args: ""
ccache_args: ""
upload_suffix: MSBUILD
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
uses: microsoft/setup-msbuild@v3
- name: Install vcpkg packages
shell: cmd
run: '"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows'
- name: Install Ninja
if: matrix.generator == 'Ninja'
run: choco install ninja -y
- name: Cache ccache
if: matrix.generator == 'Ninja'
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
key: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install ccache
if: matrix.generator == 'Ninja'
run: choco install ccache -y
- name: Configure & Build
shell: cmd
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-CLANG
path: ${{github.workspace}}/build/bin
vsbuild-MSVC:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
cmake -S . -B build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON ${{ matrix.ccache_args }} -DCMAKE_TOOLCHAIN_FILE=%VCPKG_INSTALLATION_ROOT%/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ${{ matrix.cmake_args }}
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
- name: ccache stats
if: matrix.generator == 'Ninja'
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
ccache --show-stats
if %errorlevel% neq 0 echo ccache stats unavailable
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.name }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSVC
path: ${{github.workspace}}/build/bin
vsbuild-MSVC-MSBUILD:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
msbuild dingusppc.sln
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-MSBUILD
name: DingusPPC-${{ matrix.upload_suffix }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
+75 -6
View File
@@ -97,6 +97,21 @@ if (NOT EMSCRIPTEN)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
# Warn if no audio backends were detected on Linux/Unix systems
if (UNIX AND NOT APPLE)
if (NOT USE_PULSE AND NOT USE_ALSA AND NOT USE_JACK AND
NOT USE_SNDIO AND NOT USE_OSS AND NOT USE_SUN)
message(WARNING
"No Cubeb audio backends detected on Linux/Unix system!\n"
"Audio will NOT work at runtime.\n"
"Please install development headers for at least one of:\n"
" - PulseAudio (libpulse-dev / pulseaudio-libs-devel)\n"
" - ALSA (libasound2-dev / alsa-lib-devel)\n"
" - JACK (libjack-dev / jack-audio-connection-kit-devel)\n"
" - sndio (libsndio-dev)")
endif()
endif()
endif()
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
@@ -123,6 +138,16 @@ endif()
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
if (APPLE)
add_executable(dingusppc MACOSX_BUNDLE ${SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
else()
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
@@ -130,9 +155,49 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
endif()
# 2. Configure Apple-specific Bundle Properties
if (APPLE)
# Identify if we are targeting iOS or macOS
if (IOS)
set(BUNDLE_ID "com.dingusdev.dingusppc-ios")
message(STATUS "Configuring for iOS Bundle")
else()
set(BUNDLE_ID "com.dingusdev.dingusppc")
message(STATUS "Configuring for macOS Bundle")
endif()
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "${BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "DingusPPC"
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4"
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4"
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
# Placeholder for the icon file:
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
)
find_library(COCOA_LIBRARY Cocoa)
find_library(IOKIT_LIBRARY IOKit)
find_library(COREAUDIO_LIBRARY CoreAudio)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
target_link_libraries(dingusppc PRIVATE
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREAUDIO_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
)
if (IOS)
target_link_libraries(dingusppc PRIVATE "-framework Foundation" "-framework UIKit")
endif()
endif()
if (WIN32)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(dingusppc PRIVATE SDL_MAIN_HANDLED)
elseif (EMSCRIPTEN)
target_link_libraries(dingusppc PRIVATE
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
@@ -144,7 +209,7 @@ elseif (EMSCRIPTEN)
"-s EXPORT_NAME=emulator"
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
else()
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
target_link_libraries(dingusppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -168,9 +233,10 @@ if (DPPC_BUILD_PPC_TESTS)
$<TARGET_OBJECTS:loguru>)
if (WIN32)
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
target_link_libraries(testppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(testppc PRIVATE SDL_MAIN_HANDLED)
else()
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
target_link_libraries(testppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -193,8 +259,11 @@ if (DPPC_BUILD_BENCHMARKS)
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (WIN32)
target_compile_definitions(bench1 PRIVATE SDL_MAIN_HANDLED)
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(bench1 PRIVATE capstone)
@@ -208,7 +277,7 @@ if (DPPC_BUILD_PPC_TESTS)
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
"$<TARGET_FILE_DIR:$<TARGET_PROPERTY:NAME>>")
endif()
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
+24 -8
View File
@@ -4,10 +4,10 @@
## Developers
- divingkatae
- maximumspatium
- joevt
- mihaip
- kkaisershot
- maximumspatium
- mihaip
## NT4/PPC fork
@@ -15,19 +15,35 @@
## DevOps
- alicela1n
- Cacodemon345
- dressupgeekout
- dyharlan
- erichelgeson
- jarz
- kth5
- leap0x7b
- lefp
- mathstuf
- mrpapersonic
- Randrianasulu
- roytam1
- sdkmap
- seanm
- Waqar144
- webspacecreations
- leap0x7b
- sdkmap
- dressupgeekout
- kth5
- dyharlan
- roytam1
## 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
+48 -19
View File
@@ -6,19 +6,25 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
## Philosophy of Use
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs
accurately (except for QEMU).
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but
also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old
World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
## Implemented Features
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World
PowerPC Macs, and the Pippin.
This emulator has a debugging environment, complete with a disassembler.
## How to Use
This program currently uses the command prompt to work.
There are a few command line arguments one must enter when starting the program.
There are a few command line arguments one can enter when starting the program.
```
-r, --realtime
@@ -36,23 +42,34 @@ Enter the interactive debugger.
-b, --bootrom TEXT:FILE
```
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
Specifies the Boot ROM path. It otherwise looks for bootrom.bin.
```
-m, --machine TEXT
```
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
Specify machine ID. Otherwise, the emulator will attempt to determine machine ID from the boot rom otherwise.
As of now, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
As of now, the most complete machines are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3 Beige.
To go into to the debugger regardless of how you started the emulator, press Control and C on the terminal window.
## How to Compile
You need to install development tools first.
At least, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
At minimum, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
Clone the repository using the appropriate command:
```
git clone https://github.com/dingusdev/dingusppc
```
If this is from a mirror, replace the argument with the source you want to use instead.
You will also have to recursive clone or run
```
git submodule update --init --recursive
```
@@ -65,27 +82,43 @@ For SDL2, Linux users may also have to run:
sudo apt install libsdl2-dev
```
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
macOS users can use Homebrew or MacPorts to install SDL2.
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
For Raspbian, you may also need the following command:
```
sudo apt install doxygen graphviz
```
To build the project in a Unix-like environment, create a build folder, change the directory to the build folder,
and use `cmake` to create the `Makefile` files in that build folder.
Use `make` to do the building. You don't need to execute `cmake` again unless you add/remove/change options or
source files.
For example, to build the project in a Unix-like environment, you will need to run
the following commands in the OS terminal:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make dingusppc
make
```
You may specify another build type using the variable CMAKE_BUILD_TYPE.
For Raspbian, you may also need the following command:
You may specify another build type using the variable `CMAKE_BUILD_TYPE`.
Each build type should have its own build folder.
```
sudo apt install doxygen graphviz
mkdir build-debug
cd build-debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
```
## Testing
DingusPPC includes a test suite for verifying the correctness of its PowerPC CPU
emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
@@ -100,7 +133,3 @@ make testppc
- 2 GB of RAM
- 2 GB of Hard Disk Space
- Graphics Card with a minimum resolution of 800*600
## Compiler Requirements
- Any C++20 compatible compiler
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+10 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+22 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -36,9 +36,15 @@ public:
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's, we add our own custom
// events after that.
WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
// 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_FULL_SCREEN_TOGGLE_REVERSE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
};
enum : uint32_t {
@@ -56,8 +62,8 @@ public:
~MouseEvent() = default;
uint32_t flags;
uint32_t xrel;
uint32_t yrel;
int32_t xrel;
int32_t yrel;
uint32_t xabs;
uint32_t yabs;
uint8_t buttons_state;
@@ -70,7 +76,6 @@ public:
uint32_t flags;
uint32_t key;
uint16_t keys_state;
};
@@ -121,9 +126,11 @@ public:
event_manager = new EventManager();
}
return event_manager;
};
}
void poll_events(uint32_t kbd_locale);
void poll_events();
void set_keyboard_locale(uint32_t keyboard_id);
void post_keyboard_state_events();
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -154,17 +161,19 @@ public:
_window_signal.disconnect_all();
_mouse_signal.disconnect_all();
_keyboard_signal.disconnect_all();
_gamepad_signal.disconnect_all();
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
_gamepad_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {}; // private constructor to implement a singleton
EventManager() {} // private constructor to implement a singleton
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
@@ -177,6 +186,7 @@ private:
uint64_t key_downs = 0;
uint64_t key_ups = 0;
uint8_t buttons_state = 0;
uint32_t kbd_locale = 0;
};
#endif // EVENT_MANAGER_H
+185 -45
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -29,9 +29,14 @@ 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, uint32_t kbd_locale);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
void EventManager::poll_events(uint32_t kbd_locale) {
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
this->kbd_locale = keyboard_id;
}
void EventManager::poll_events() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -53,25 +58,110 @@ void EventManager::poll_events(uint32_t kbd_locale) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
if (event.key.repeat)
break;
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_g && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
toggle_mouse_grab(event.key);
}
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
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, kbd_locale);
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-Shift-F: fullscreen reverse
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LSHIFT)) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-+: bigger
if (event.key.keysym.sym == SDLK_EQUALS && (event.key.keysym.mod & 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 && (event.key.keysym.mod & 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;
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
loguru::Verbosity_INFO
:
loguru::Verbosity_MAX;
}
return;
}
// Control-D: debugger
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
power_on = false;
power_off_reason = po_enter_debugger;
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((event.key.keysym.mod & 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, this->kbd_locale);
if (key_code != -1) {
KeyboardEvent ke{};
ke.key = key_code;
@@ -84,7 +174,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
}
// Caps Lock is a special case, since it's a toggle key
if (ke.key == AdbKey_CapsLock) {
ke.flags = SDL_GetModState() & KMOD_CAPS ?
ke.flags = event.key.keysym.mod & KMOD_CAPS ?
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
}
this->_keyboard_signal.emit(ke);
@@ -194,6 +284,76 @@ void EventManager::poll_events(uint32_t kbd_locale) {
this->_post_signal.emit();
}
void EventManager::post_keyboard_state_events() {
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
SDL_KeyboardEvent keyevent = { .type = SDL_KEYDOWN };
SDL_Scancode scancode;
KeyboardEvent ke{};
typedef struct {
SDL_Scancode scancode;
SDL_Keymod keymod;
AdbKey adbkey;
} Modifier_t;
static Modifier_t modifiers[] = {
SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift ,
SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift ,
SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control ,
SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl,
SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option ,
SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption ,
SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command ,
SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command ,
// SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear ,
SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock ,
// SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? ,
// SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 ,
SDL_SCANCODE_UNKNOWN
};
LOG_F(INFO, "Current keyboard state:");
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
if (!(modstate & mod->keymod))
continue;
LOG_F(INFO, " mod:%s", SDL_GetScancodeName(mod->scancode));
ke.key = mod->adbkey;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
}
for (int i = 0; i < numkeys; i++) {
if (!states[i])
continue;
scancode = (SDL_Scancode)i;
Modifier_t *mod = modifiers;
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
if (mod->scancode == scancode) {
LOG_F(INFO, " ignore:%s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
int key_code = get_sdl_event_key_code(keyevent, this->kbd_locale);
if (key_code != -1) {
ke.key = key_code;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
}
}
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
{
@@ -276,11 +436,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_PAGEDOWN: return AdbKey_PageDown;
case SDLK_LCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_RightControl;
case SDLK_LSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_RightShift;
case SDLK_LALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_RightOption;
case SDLK_LGUI: return AdbKey_Command;
case SDLK_RGUI: return AdbKey_Command;
case SDLK_MENU: return AdbKey_Grave;
@@ -290,7 +450,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_DOWN: return AdbKey_ArrowDown;
case SDLK_LEFT: return AdbKey_ArrowLeft;
case SDLK_RIGHT: return AdbKey_ArrowRight;
;
case SDLK_KP_0: return AdbKey_Keypad0;
case SDLK_KP_1: return AdbKey_Keypad1;
case SDLK_KP_2: return AdbKey_Keypad2;
@@ -309,7 +469,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
;
case SDLK_F1: return AdbKey_F1;
case SDLK_F2: return AdbKey_F2;
case SDLK_F3: return AdbKey_F3;
@@ -332,9 +492,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
else
return -1;
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;
@@ -373,25 +535,3 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
}
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)");
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+13 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -156,3 +156,13 @@ uint64_t TimerManager::process_timers()
// return time slice in nanoseconds until next timer's expiry
return cur_timer->timeout_ns - time_now;
}
void TimerManager::cancel_all_timers()
{
std::shared_ptr<TimerInfo> cur_timer;
while (!this->timer_queue.empty()) {
cur_timer = this->timer_queue.top();
LOG_F(WARNING, "Canceling timer id:%u ns:%llu", cur_timer->id, cur_timer->timeout_ns);
this->timer_queue.pop();
}
}
+14 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -51,6 +51,8 @@ class my_priority_queue : public std::priority_queue<T, Container, Compare> {
public:
bool remove_by_id(const uint32_t id){
std::lock_guard<std::recursive_mutex> lk(mtx);
if (this->empty())
return false;
auto el = this->top();
if (el->id == id) {
std::priority_queue<T, Container, Compare>::pop();
@@ -64,13 +66,13 @@ public:
return true;
}
return false;
};
}
void push(T val)
{
std::lock_guard<std::recursive_mutex> lk(mtx);
std::priority_queue<T, Container, Compare>::push(val);
};
}
T pop()
{
@@ -78,7 +80,7 @@ public:
T val = std::priority_queue<T, Container, Compare>::top();
std::priority_queue<T, Container, Compare>::pop();
return val;
};
}
std::recursive_mutex& get_mtx()
{
@@ -111,20 +113,20 @@ public:
timer_manager = new TimerManager();
}
return timer_manager;
};
}
// callback for retrieving current time
void set_time_now_cb(const std::function<uint64_t()> &cb) {
this->get_time_now = cb;
};
}
// callback for acknowledging time changes
void set_notify_changes_cb(const timer_cb &cb) {
this->notify_timer_changes = cb;
};
}
// return current virtual time in nanoseconds
uint64_t current_time_ns() { return get_time_now(); };
uint64_t current_time_ns() { return get_time_now(); }
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
@@ -132,12 +134,13 @@ public:
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(uint32_t id);
void cancel_all_timers();
uint64_t process_timers();
private:
static TimerManager* timer_manager;
TimerManager(){}; // private constructor to implement a singleton
TimerManager(){} // private constructor to implement a singleton
// timer queue
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
+20 -20
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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"
@@ -341,9 +342,8 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
@@ -380,7 +380,7 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -397,7 +397,7 @@ template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -417,7 +417,7 @@ void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -431,7 +431,7 @@ template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -480,7 +480,7 @@ void dppc_interpreter::power_slq(uint32_t opcode) {
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
@@ -492,7 +492,7 @@ 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] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -515,7 +515,7 @@ void dppc_interpreter::power_sraq(uint32_t 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] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -523,7 +523,7 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -541,7 +541,7 @@ void dppc_interpreter::power_sre(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -557,7 +557,7 @@ 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 = (rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d);
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
@@ -583,7 +583,7 @@ void dppc_interpreter::power_sreq(uint32_t opcode) {
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -598,7 +598,7 @@ template <field_rc rec>
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] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
@@ -612,7 +612,7 @@ template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -631,7 +631,7 @@ template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
@@ -660,7 +660,7 @@ void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
+14 -14
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -253,15 +253,15 @@ const char* trap_cond[32] = {/*Trap conditions*/
"twlt", "", "", "", "twle", "", "", "",
"twne", "", "", "", "", "", "", ""};
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "", "",
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "dec", "",
"lr", "ctr", "", "", "", "", "", "",
"", "", "dsisr", "dar", "", "", "dec", "",
"", "", "dsisr", "dar", "rtcu", "rtcl", "dec", "",
"", "sdr1", "srr0", "srr1", "", "", "", ""};
const char* spr_index8[32] = {
"", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
"", "", "", "", "", "", "", "", "", "", "",
"", "tbl_u", "tbu_u", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
const char* spr_index16[32] = {
"", "", "", "", "", "", "", "",
@@ -1176,14 +1176,14 @@ void opc_group31(PPCDisasmContext* ctx) {
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
ctx->instr_str = my_sprintf("%-7s r%d", "tlbld", rb);
add_reg_in(ctx, "r%d", rb);
}
} else if (index == 30) { /* tlbli - 603 only */
} else if (index == 31) { /* tlbli - 603 only */
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
ctx->instr_str = my_sprintf("%-7s r%d", "tlbli", rb);
add_reg_in(ctx, "r%d", rb);
}
}
@@ -1250,10 +1250,10 @@ void opc_group31(PPCDisasmContext* ctx) {
add_reg_out(ctx, "cr");
}
} else {
strcpy(opcode, opc_logic[index]);
if (!strlen(opcode)) {
if (index >= 16 || !strlen(opc_logic[index])) {
opc_illegal(ctx);
} else {
strcpy(opcode, opc_logic[index]);
if (rc_set) {
strcat(opcode, ".");
add_reg_out(ctx, "cr");
@@ -1394,9 +1394,9 @@ void opc_group31(PPCDisasmContext* ctx) {
break;
}
auto ref_spr = (((ctx->instr_code >> 11) & 31) << 5) | ((ctx->instr_code >> 16) & 31);
auto spr_high = (ctx->instr_code >> 11) & 31;
auto spr_low = (ctx->instr_code >> 16) & 31;
auto ref_spr = (spr_high << 5) | spr_low;
switch (ext_opc) {
case 0: /* cmp */
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+54 -18
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -106,6 +106,7 @@ enum SPR : int {
SPRG1 = 273,
SPRG2 = 274,
SPRG3 = 275,
EAR = 282,
TBL_S = 284, // supervisor TBL
TBU_S = 285, // supervisor TBU
PVR = 287,
@@ -114,6 +115,8 @@ enum SPR : int {
PMC2 = 954,
SIA = 955,
MMCR1 = 956,
PMC3 = 957,
PMC4 = 958,
SDA = 959,
HID0 = 1008,
HID1 = 1009,
@@ -177,6 +180,7 @@ 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;
@@ -244,22 +248,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 {
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -161,6 +161,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
exc_descriptor = "DSI/ISI exception: unmapped memory access";
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
exc_descriptor = "DSI/ISI exception: access protection violation";
else if (ppc_state.spr[SPR::DSISR] & 0x00100000)
exc_descriptor = "DSI exception: External access is disabled";
else {
if (exception_type == Except_Type::EXC_DSI)
exc_descriptor = "DSI exception";
+72 -58
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -92,6 +92,7 @@ uint64_t rtc_timestamp; // stores vCPU virtual time of the last RTC write
uint64_t tbr_wr_value; // last value written to the TBR
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a
// 32 bit fraction less than 1.0 (999.999999 MHz maximum).
uint32_t tbr_freq_shift; // If 32 bits is not sufficient, then include a shift.
uint64_t tbr_period_ns; // TBR/RTC period in ns expressed as a 64 bit value
// with 32 fractional bits (<1 Hz minimum).
uint64_t timebase_counter; // internal timebase counter
@@ -117,7 +118,7 @@ std::unordered_map<uint32_t, uint64_t> num_opcodes;
class CPUProfile : public BaseProfile {
public:
CPUProfile() : BaseProfile("PPC_CPU") {};
CPUProfile() : BaseProfile("PPC_CPU") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -168,7 +169,7 @@ public:
.count_total = num_executed_instrs});
}
#endif
};
}
void reset() {
num_executed_instrs = 0;
@@ -179,7 +180,7 @@ public:
#ifdef CPU_PROFILING_OPS
num_opcodes.clear();
#endif
};
}
};
#endif
@@ -445,86 +446,80 @@ Opcode table macros:
- r is for raw (adding custom entries to the table)
*/
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
} while (0)
#define OPr_fp(opcode, mod, fn) \
do { \
OPr(opcode, mod, fn); \
OpcodeGrabberNoFPU[((opcode) << 11) | (mod)] = ppc_fpu_off; \
} while (0)
#define OP(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
} \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr(opcode, mod, fn); \
} \
} while (0)
#define OP_fp(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | mod] = ppc_fpu_off; \
} \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr_fp(opcode, mod, fn); \
} \
} while (0)
#define OPX(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0)
#define OPX(opcode, subopcode, fn) OPr(opcode, (subopcode)<<1, fn)
#define OPX_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1)] = ppc_fpu_off; \
} while (0)
#define OPX_fp(opcode, subopcode, fn) OPr_fp(opcode, (subopcode)<<1, fn)
#define OPXd(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OPr(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXd_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
OPr_fp(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr_fp(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<RC1, OV1>; \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<RC1, OV1>)); \
} while (0)
#define OPXdc(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OPr(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXdc_fp(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
OPr_fp(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr_fp(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<carry, RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<carry, RC1, OV1>; \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<carry, RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<carry, RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<carry, RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<carry, RC1, OV1>)); \
} while (0)
#define OPla(opcode, subopcode, fn) \
do { \
for (uint32_t mod = 0; mod < 512; mod++) { \
OpcodeGrabber[((opcode) << 11) | (mod << 2) | (subopcode)] = fn; \
} \
} while (0)
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
for (uint32_t mod = 0; mod < 512; mod++) { \
OPr(opcode, (mod << 2) | (subopcode), fn); \
} \
} while (0)
#define OP31(subopcode, fn) OPX(31, subopcode, fn)
@@ -538,10 +533,7 @@ do { \
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry)
#define OP59d(subopcode, fn) \
do { \
OPXd_fp(59, (subopcode), fn); \
} while (0)
#define OP59d(subopcode, fn) OPXd_fp(59, (subopcode), fn)
#define OP59cd(subopcode, fn) \
do { \
@@ -835,12 +827,31 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
//icnt_factor = 6;
icnt_factor = 4;
// // // PDM cpu clock calculated at 0x403036CC in r3
// icnt_factor = 11; // 1 instruction = 2048 ns = 0.488 MHz // 00068034 = 0.426036 MHz = 2347.219 ns // floppy doesn't work
// icnt_factor = 10; // 1 instruction = 1024 ns = 0.977 MHz // 000D204C = 0.860236 MHz = 1162.471 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 9; // 1 instruction = 512 ns = 1.953 MHz // 001A6081 = 1.728641 MHz = 578.489 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 8; // 1 instruction = 256 ns = 3.906 MHz // 0034E477 = 3.466359 MHz = 288.487 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 7; // 1 instruction = 128 ns = 7.813 MHz // 0069E54C = 6.939980 MHz = 144.092 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 6; // 1 instruction = 64 ns = 15.625 MHz // 00D3E6F5 = 13.887221 MHz = 72.008 ns // (10..60] = 50, (60..73] = 66, (73..100] = 80 MHz
// icnt_factor = 5; // 1 instruction = 32 ns = 31.250 MHz // 01A7B672 = 27.768434 MHz = 36.012 ns //
icnt_factor = 4; // 1 instruction = 16 ns = 62.500 MHz // 034F0F0F = 55.512847 MHz = 18.013 ns // 6100/60 in Apple System Profiler
// icnt_factor = 3; // 1 instruction = 8 ns = 125.000 MHz // 069E1E1E = 111.025694 MHz = 9.006 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 2; // 1 instruction = 4 ns = 250.000 MHz // 0D3C3C3C = 222.051388 MHz = 4.503 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 1; // 1 instruction = 2 ns = 500.000 MHz // 1A611A7B = 442.571387 MHz = 2.259 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 0; // 1 instruction = 1 ns = 1500.000 MHz // 3465B2D9 = 879.080153 MHz = 1.137 ns // (100...) MHz = invalid clock for PDM gestalt calculation
tbr_wr_timestamp = 0;
rtc_timestamp = 0;
tbr_wr_value = 0;
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
if (is_601)
tb_freq <<= 7;
tbr_freq_shift = 0;
uint64_t x;
for (x = (tb_freq << 32) / NS_PER_SEC; x >> 32; x >>= 1)
tbr_freq_shift++;
tbr_freq_ghz = (uint32_t)x;
tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq;
exec_flags = 0;
@@ -888,7 +899,10 @@ static map<string, int> SPRName2Num = {
{"SDR1", SPR::SDR1}, {"MQ", SPR::MQ}, {"RTCU", SPR::RTCU_S},
{"RTCL", SPR::RTCL_S}, {"DSISR", SPR::DSISR}, {"DAR", SPR::DAR},
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1}
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
// get value from supervisor index same as we do for SPR268 and SPR269
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
};
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
+4 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -154,9 +154,7 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
((ppc_state.fpscr >> 3) & 0x1F));
uint32_t fpscr_check = (ppc_state.fpscr >> 22) & ppc_state.fpscr & 0x0F8;
if (fpscr_check)
ppc_state.fpscr |= VX;
else
+7 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -72,7 +72,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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];
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab(opcode) \
int reg_s = (opcode >> 21) & 31; \
@@ -87,13 +87,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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];
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];
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
int reg_s = (opcode >> 21) & 31; \
@@ -151,7 +151,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int reg_b = (opcode >> 11) & 31;
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
+79 -23
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -171,9 +171,9 @@ static inline uint8_t* calc_pteg_addr(uint32_t hash)
sdr1_val = ppc_state.spr[SPR::SDR1];
pteg_addr = sdr1_val & 0xFE000000;
pteg_addr |= (sdr1_val & 0x01FF0000) | (((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6));
pteg_addr |= (hash & 0x3FF) << 6;
pteg_addr = (sdr1_val & 0xFFFF0000) |
(((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6)) |
((hash & 0x3FF) << 6);
if (pteg_addr >= last_ptab_area.start && pteg_addr <= last_ptab_area.end) {
return last_ptab_area.mem_ptr + (pteg_addr - last_ptab_area.start);
@@ -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) {
@@ -746,9 +782,9 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
{
TLBEntry *tlb_entry = &tlb1[(tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (tlb_entry->tag == tag) {
if (tlb_entry->tag != TLB_INVALID_TAG && (tlb_entry->tag & TLB_VPS_MASK) == tag) {
tlb_entry->tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", tag);
}
}
@@ -756,16 +792,16 @@ static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &
{
TLBEntry *tlb_entry = &tlb2[((tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
for (int i = 0; i < TLB2_WAYS; i++) {
if (tlb_entry[i].tag == tag) {
if (tlb_entry[i].tag != TLB_INVALID_TAG && (tlb_entry[i].tag & TLB_VPS_MASK) == tag) {
tlb_entry[i].tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", tag);
}
}
}
void tlb_flush_entry(uint32_t ea)
{
const uint32_t tag = ea & ~0xFFFUL;
const uint32_t tag = ea & TLB_VPS_MASK;
tlb_flush_primary_entry(itlb1_mode1, tag);
tlb_flush_secondary_entry(itlb2_mode1, tag);
tlb_flush_primary_entry(itlb1_mode2, tag);
@@ -915,6 +951,11 @@ static void mpc601_bat_update(uint32_t bat_reg)
}
}
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
{
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
static void ppc_ibat_update(uint32_t bat_reg)
{
int upper_reg_num;
@@ -963,7 +1004,6 @@ static void ppc_dbat_update(uint32_t bat_reg)
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
}
}
void mmu_pat_ctx_changed()
@@ -1304,7 +1344,7 @@ template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint
class MMUProfile : public BaseProfile {
public:
MMUProfile() : BaseProfile("PPC_MMU") {};
MMUProfile() : BaseProfile("PPC_MMU") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1352,7 +1392,7 @@ public:
vars.push_back({.name = "Unaligned Crosspage Writes Total",
.format = ProfileVarFmt::DEC,
.value = unaligned_crossp_w});
};
}
void reset() {
dmem_reads_total = 0;
@@ -1366,7 +1406,7 @@ public:
unaligned_writes = 0;
unaligned_crossp_r = 0;
unaligned_crossp_w = 0;
};
}
};
#endif
@@ -1378,7 +1418,7 @@ public:
class TLBProfile : public BaseProfile {
public:
TLBProfile() : BaseProfile("PPC:MMU:TLB") {};
TLBProfile() : BaseProfile("PPC:MMU:TLB") {}
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1410,14 +1450,14 @@ public:
vars.push_back({.name = "Number of replaced TLB entries",
.format = ProfileVarFmt::DEC,
.value = num_entry_replacements});
};
}
void reset() {
num_primary_dtlb_hits = 0;
num_secondary_dtlb_hits = 0;
num_dtlb_refills = 0;
num_entry_replacements = 0;
};
}
};
#endif
@@ -1447,7 +1487,8 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
default:
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;
@@ -1456,6 +1497,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;
@@ -1549,7 +1599,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;
}
@@ -1587,6 +1642,7 @@ void ppc_mmu_init()
if (is_601) {
// use 601-style unified BATs
ibat_update = &mpc601_bat_update;
dbat_update = &mpc601_dbat_update;
} else {
// use PPC-style BATs
ibat_update = &ppc_ibat_update;
+4 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -87,6 +87,7 @@ constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
typedef struct TLBEntry {
uint32_t tag;
+139 -62
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// General opcodes for the processor - ppcopcodes.cpp
#include <core/bitops.h>
#include <core/timermanager.h>
#include <core/mathutils.h>
#include "ppcemu.h"
@@ -684,10 +685,9 @@ void dppc_interpreter::ppc_rlwimi(uint32_t opcode) {
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
ppc_result_a = (ppc_result_a & ~mask) | (r & mask);
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -698,10 +698,9 @@ void dppc_interpreter::ppc_rlwinm(uint32_t opcode) {
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) |
(ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
ppc_result_a = r & mask;
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -709,15 +708,12 @@ void dppc_interpreter::ppc_rlwinm(uint32_t opcode) {
void dppc_interpreter::ppc_rlwnm(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_b &= 0x1F;
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
uint32_t mask = rot_mask(rot_mb, rot_me);
uint32_t rot = ppc_result_b & 0x1F;
uint32_t r = rot ? ((ppc_result_d << rot) |
(ppc_result_d >> (32 - rot))) : ppc_result_d;
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
ppc_result_a = r & mask;
if ((opcode & 0x01) == 1) {
if (opcode & 1) {
ppc_changecrf0(ppc_result_a);
}
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -819,6 +815,7 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
}
}
#if 0
static inline void calc_rtcl_value()
{
uint64_t new_ts = get_virt_time_ns();
@@ -832,22 +829,47 @@ static inline void calc_rtcl_value()
}
rtc_timestamp = new_ts;
}
#else
static inline void calc_rtcl_value()
{
uint64_t adj;
uint32_t adj_lo;
uint64_t new_ts = get_virt_time_ns();
uint64_t diff = new_ts - rtc_timestamp;
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
uint64_t rtc_l = adj + rtc_lo;
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
rtc_hi += (uint32_t)(rtc_l / ONE_BILLION_NS);
rtc_lo = rtc_l % ONE_BILLION_NS;
}
else {
rtc_lo = (uint32_t)rtc_l;
}
rtc_timestamp = new_ts;
}
#endif
static inline uint64_t calc_tbr_value()
{
uint64_t tbr_inc;
uint32_t tbr_inc_lo;
uint64_t adj;
uint32_t adj_lo;
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
_u32xu64(tbr_freq_ghz, diff, tbr_inc, tbr_inc_lo);
return (tbr_wr_value + tbr_inc);
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
return (tbr_wr_value + adj);
}
static inline uint32_t calc_dec_value() {
uint64_t dec_adj;
uint32_t dec_adj_lo;
uint64_t adj;
uint32_t adj_lo;
uint64_t diff = get_virt_time_ns() - dec_wr_timestamp;
_u32xu64(tbr_freq_ghz, diff, dec_adj, dec_adj_lo);
return (dec_wr_value - static_cast<uint32_t>(dec_adj));
_u32xu64(tbr_freq_ghz, diff, adj, adj_lo);
if (tbr_freq_shift)
adj = (adj << tbr_freq_shift) + (adj_lo >> (32 - tbr_freq_shift));
return (dec_wr_value - static_cast<uint32_t>(adj));
}
static void update_timebase(uint64_t mask, uint64_t new_val)
@@ -857,13 +879,11 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
tbr_wr_timestamp = get_virt_time_ns();
}
static uint32_t decrementer_timer_id = 0;
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
static void trigger_decrementer_exception() {
decrementer_timer_id = 0;
dec_wr_value = -1;
dec_wr_timestamp = get_virt_time_ns();
if (ppc_state.msr & MSR::EE) {
dec_exception_pending = false;
//LOG_F(WARNING, "decrementer exception triggered");
@@ -875,27 +895,58 @@ static void trigger_decrementer_exception() {
}
}
static void update_decrementer(uint32_t val) {
dec_wr_value = val;
dec_wr_timestamp = get_virt_time_ns();
static void trigger_timed_decrementer_exception() {
decrementer_timer_id = 0;
uint32_t new_val = calc_dec_value();
if (new_val >= 0 && new_val != uint32_t(-1)) {
new_val = -1;
}
update_decrementer(true, new_val, new_val);
trigger_decrementer_exception();
}
static void trigger_immediate_decrementer_exception() {
decrementer_timer_id = 0;
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
trigger_decrementer_exception();
}
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval) {
if (update_time_stamp) {
dec_wr_value = newval;
dec_wr_timestamp = get_virt_time_ns();
}
dec_exception_pending = false;
if (is_601)
return;
if (decrementer_timer_id) {
//LOG_F(WARNING, "decrementer cancel timer");
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
}
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
decrementer_timer_id = TimerManager::get_instance()->add_immediate_timer(
trigger_immediate_decrementer_exception
);
return;
}
// A count of zero should timeout after one tick so add one to the count
// but make sure the count doesn't overflow.
if (is_601) {
if (newval < uint32_t(-0x80))
newval += 0x80;
} else {
if (newval < uint32_t(-1))
newval += 1;
}
uint64_t time_out;
uint32_t time_out_lo;
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
_u32xu64(newval, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "new decrementer value: 0x%08X, interrupt after %llu ns", newval, time_out);
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
time_out,
trigger_decrementer_exception
trigger_timed_decrementer_exception
);
}
@@ -909,6 +960,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
}
@@ -943,8 +995,29 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
}
// fallthrough
case SPR::DEC_S:
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = calc_dec_value();
{
uint32_t val = calc_dec_value();
if (is_601)
val &= ~0x7F;
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
break;
}
case SPR::TBL_U:
case SPR::TBL_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
break;
}
case SPR::TBU_U:
case SPR::TBU_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
break;
}
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
@@ -961,6 +1034,7 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
}
@@ -1000,8 +1074,10 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
ppc_state.spr[RTCU_S] = rtc_hi = val;
break;
case SPR::DEC_S:
ppc_state.spr[DEC_S] = val;
update_decrementer(val);
if (is_601)
val &= ~0x7F;
update_decrementer(true, calc_dec_value(), val);
ppc_state.spr[SPR::DEC_S] = val;
break;
case SPR::TBL_S:
update_timebase(0xFFFFFFFF00000000ULL, val);
@@ -1036,6 +1112,7 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case 543:
ppc_state.spr[ref_spr] = val;
dbat_update(ref_spr);
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
ppc_state.spr[ref_spr] = val;
@@ -1383,27 +1460,26 @@ void dppc_interpreter::ppc_rfi(uint32_t opcode) {
return;
}
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_srr1_val = (ppc_state.spr[SPR::SRR1] & 0x87C0FF73UL);
uint32_t new_msr_val = (ppc_state.msr & ~0x87C0FF73UL);
// keep 0, 5-9, 16-23, 25-27, 30-31 bits; exclude POW, ILE, and Reserved bits.
const uint32_t msr_bits_to_replace = 0x87C0FF73UL;
const uint32_t msr_bits_to_clear = MSR::POW;
new_msr_val = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
ppc_msr_did_change(old_msr_val, new_msr_val);
uint32_t bits_from_srr1 = ppc_state.spr[SPR::SRR1] &
(msr_bits_to_replace & ~msr_bits_to_clear);
uint32_t new_msr_val = (ppc_state.msr & ~(msr_bits_to_replace | msr_bits_to_clear)) |
bits_from_srr1;
// generate External Interrupt Exception
// if CPU interrupt line is still asserted
if (ppc_state.msr & MSR::EE && int_pin) {
ppc_msr_did_change(ppc_state.msr, new_msr_val);
// setting MSR[EE] may enable pending exceptions
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending)) {
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
ppc_state.spr[SPR::SRR0] = save_srr0;
return;
}
if ((ppc_state.msr & MSR::EE) && dec_exception_pending) {
dec_exception_pending = false;
//LOG_F(WARNING, "decrementer exception from rfi msr:0x%X", ppc_state.msr);
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
ppc_exception_handler(Except_Type::EXC_DECR, 0);
if (int_pin) // check for pending external exceptions (higher priority)
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
else {
dec_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_DECR, 0);
}
ppc_state.spr[SPR::SRR0] = save_srr0;
return;
}
@@ -1551,10 +1627,10 @@ void dppc_interpreter::ppc_stu(uint32_t opcode) {
ea += ppc_result_a;
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
}
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
}
@@ -1576,7 +1652,7 @@ void dppc_interpreter::ppc_stux(uint32_t opcode) {
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
}
template void dppc_interpreter::ppc_stux<uint8_t>(uint32_t opcode);
@@ -1965,7 +2041,7 @@ void dppc_interpreter::ppc_eciwx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[282] && ear_enable)) {
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
}
@@ -1985,7 +2061,8 @@ void dppc_interpreter::ppc_ecowx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[282] && ear_enable)) {
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_state.spr[SPR::DSISR] = 0x00100000;
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
}
+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
+4
View File
@@ -407,6 +407,10 @@
0xFFF00100,0x7D453D2A,stswx,r10,r5,r7
0xFFF00100,0x7C0002E4,tlbia
0xFFF00100,0x7C004A64,tlbie,r9
0xFFF00100,0x7C202FA4,tlbld,r5
0xFFF00100,0x7C6007A4,tlbld,r0
0xFFF00100,0x7C203FE4,tlbli,r7
0xFFF00100,0x7C40FFE4,tlbli,r31
# various simplified (extended) mnemonics
0xFFF00100,0x60000000,nop
1 # Test data for PowerPC disassembler supplied as comma-separated values
407 0xFFF00100,0x7C430C32,rrib,r3,r2,r1 0xFFF00100,0x7C00003A,maskg,r0,r0,r0
408 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1 0xFFF00100,0x7E3EE43A,maskir,r30,r17,r28
409 0xFFF00100,0x7C410132,sle,r1,r2,r0 0xFFF00100,0x58411800,rlmi,r1,r2,r3,0,0
410 0xFFF00100,0x58411801,rlmi.,r1,r2,r3,0,0
411 0xFFF00100,0x7C430C32,rrib,r3,r2,r1
412 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1
413 0xFFF00100,0x7C410132,sle,r1,r2,r0
414 0xFFF00100,0x7C410133,sle.,r1,r2,r0
415 0xFFF00100,0x7C4101B2,sleq,r1,r2,r0
416 0xFFF00100,0x7C4101B3,sleq.,r1,r2,r0
+5 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -321,7 +321,8 @@ int main() {
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
int new_msr = (MSR::ME | MSR::IP | MSR::FP);
ppc_msr_did_change(ppc_state.msr, new_msr, false);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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++) {
+163 -28
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -51,6 +51,12 @@ 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 static_cast<uint32_t>(stoul(addr_str, NULL, 0));
@@ -86,6 +92,10 @@ static void show_help() {
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;
@@ -129,7 +139,12 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
for (; power_on && count > 0; count--) {
// 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;
@@ -143,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;
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;
}
}
@@ -224,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
@@ -324,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;
}
}
@@ -337,21 +352,127 @@ 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(PPCDisasmContext &ctx) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << dec;
return ctx.instr_addr;
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
ctx.instr_addr = address;
ctx.simplified = true;
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;
disasm(ctx);
cout << endl;
}
return ctx.instr_addr;
}
static void disasm_in(PPCDisasmContext &ctx, uint32_t address) {
ctx.instr_addr = address;
ctx.simplified = true;
disasm(ctx);
if (ctx.regs_in.size() > 0 || ctx.regs_out.size() > 0) {
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
}
}
static void disasm_out(PPCDisasmContext &ctx) {
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
cout << endl;
}
static void print_gprs() {
string reg_name;
int i;
@@ -360,7 +481,7 @@ static void print_gprs() {
reg_name = "r" + to_string(i);
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
COUT08X << get_reg(reg_name) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -373,7 +494,7 @@ static void print_gprs() {
for (auto &spr : sprs) {
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
COUT08X << get_reg(spr) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -390,11 +511,11 @@ static void print_fprs() {
for (int i = 0; i < 32; i++) {
reg_name = "f" + to_string(i);
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
setw(16) << setfill('0') << right << uppercase << hex << ppc_state.fpr[i].int64_r <<
COUT016X << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
setw(8) << setfill('0') << uppercase << hex << ppc_state.fpscr << setfill(' ') << endl;
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601;
@@ -487,7 +608,7 @@ void DppcDebugger::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) {
@@ -547,7 +668,7 @@ void DppcDebugger::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()) {
@@ -665,6 +786,9 @@ void DppcDebugger::enter_debugger() {
delete_prompt();
}
for (; --count >= 0;) {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
disasm_68k(1, addr);
exec_single_68k();
}
#endif
@@ -674,7 +798,10 @@ void DppcDebugger::enter_debugger() {
}
for (; --count >= 0;) {
addr = ppc_state.pc;
PPCDisasmContext ctx;
disasm_in(ctx, addr);
ppc_exec_single();
disasm_out(ctx);
}
}
} else if (cmd == "next" || cmd == "ni") {
@@ -785,6 +912,10 @@ void DppcDebugger::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 = "";
@@ -798,6 +929,10 @@ void DppcDebugger::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())
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -31,7 +31,7 @@ public:
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
};
}
void enter_debugger();
+5 -5
View File
@@ -8,12 +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/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/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"
@@ -24,12 +26,10 @@ platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
+11 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,9 +35,9 @@ 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;
this->aj_buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->buttons_state &= ~button_bit;
this->aj_buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
@@ -47,7 +47,7 @@ void AdbAppleJack::event_handler(const GamepadEvent& event) {
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->buttons_state = 0;
this->aj_buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
@@ -58,16 +58,16 @@ bool AdbAppleJack::get_register_0() {
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;
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->aj_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;
out_buf[2] = uint8_t(~this->aj_buttons_state >> 8);
out_buf[3] = ~this->aj_buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
@@ -94,7 +94,7 @@ void AdbAppleJack::set_register_3() {
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}
AdbAppleJack::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -52,7 +52,7 @@ public:
void set_register_3() override;
private:
uint32_t buttons_state = 0;
uint32_t aj_buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -133,7 +133,7 @@ static const PropMap AdbBus_Properties = {
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, AdbBus_Properties
AdbBus::create, {}, AdbBus_Properties, HWCompType::ADB_HOST
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+10 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -38,6 +38,7 @@ enum {
ADB_STAT_SRQ_ACTIVE = 1 << 0,
ADB_STAT_TIMEOUT = 1 << 1,
ADB_STAT_AUTOPOLL = 1 << 6,
ADB_STAT_RESPONSE = 1 << 7,
};
class AdbDevice; // forward declaration to prevent compiler errors
@@ -55,7 +56,7 @@ public:
void register_device(AdbDevice* dev_obj);
uint8_t process_command(const uint8_t* in_data, int data_size);
uint8_t get_output_count() { return this->output_count; };
uint8_t get_output_count() { return this->output_count; }
// Polls devices that have a service request flag set. Returns the talk
// command corresponding to the first device that responded with data, or
@@ -63,11 +64,11 @@ public:
uint8_t poll();
// callbacks meant to be called by devices
const uint8_t* get_input_buf() { return this->input_buf; };
uint8_t* get_output_buf() { return this->output_buf; };
uint8_t get_input_count() { return this->input_count; };
void set_output_count(uint8_t count) { this->output_count = count; };
bool already_answered() { return this->got_answer; };
const uint8_t* get_input_buf() { return this->input_buf; }
uint8_t* get_output_buf() { return this->output_buf; }
uint8_t get_input_count() { return this->input_count; }
void set_output_count(uint8_t count) { this->output_count = count; }
bool already_answered() { return this->got_answer; }
private:
std::vector<AdbDevice*> devices;
+9 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -37,7 +37,7 @@ int AdbDevice::device_postinit() {
this->host_obj->register_device(this);
return 0;
};
}
uint8_t AdbDevice::poll() {
if (!this->srq_flag) {
@@ -84,12 +84,16 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
switch(reg_num & 3) {
case 0:
this->set_register_0();
break;
case 1:
this->set_register_1();
break;
case 2:
this->set_register_2();
break;
case 3:
this->set_register_3();
break;
}
}
}
@@ -104,5 +108,5 @@ bool AdbDevice::get_register_3() {
}
uint8_t AdbDevice::gen_random_address() {
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
return TimerManager::get_instance()->current_time_ns() & 0xF;
}
+13 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -47,7 +47,7 @@ public:
virtual void reset() = 0;
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
virtual uint8_t get_address() { return this->my_addr; };
virtual uint8_t get_address() { return this->my_addr; }
// Attempts to poll the device. Returns the talk command corresponding to
// the device if it has data, 0 otherwise.
@@ -56,18 +56,19 @@ public:
protected:
uint8_t gen_random_address();
virtual bool get_register_0() { return false; };
virtual bool get_register_1() { return false; };
virtual bool get_register_2() { return false; };
virtual bool get_register_0() { return false; }
virtual bool get_register_1() { return false; }
virtual bool get_register_2() { return false; }
virtual bool get_register_3();
virtual void set_register_0() {};
virtual void set_register_1() {};
virtual void set_register_2() {};
virtual void set_register_3() {};
virtual void set_register_0() {}
virtual void set_register_1() {}
virtual void set_register_2() {}
virtual void set_register_3() {}
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
uint8_t srq_flag = 0;
uint8_t led_state = 0;
uint8_t my_addr = 0;
uint8_t dev_handler_id = 0;
bool got_collision = false;
+47 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,13 +35,18 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
if (this->pending_events.size() == 1) {
this->srq_flag = 1;
}
}
void AdbKeyboard::reset() {
this->my_addr = ADB_ADDR_KBD;
this->dev_handler_id = 2; // Extended ADB keyboard
this->exc_event_flag = 1;
this->srq_flag = 1; // enable service requests
this->srq_flag = 0; // don't process keyboard service requests yet
this->led_state = 0; // LEDs off
this->pending_events.clear();
}
@@ -53,6 +58,11 @@ bool AdbKeyboard::get_register_0() {
out_buf[0] = this->consume_pending_event();
out_buf[1] = this->consume_pending_event();
this->host_obj->set_output_count(2);
if (this->pending_events.empty()) {
this->srq_flag = 0;
}
return true;
}
@@ -68,19 +78,44 @@ uint8_t AdbKeyboard::consume_pending_event() {
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
this->pending_events.pop_front();
uint8_t key_state = 0;
if (event->flags & KEYBOARD_EVENT_DOWN) {
key_state = 0;
} else if (event->flags & KEYBOARD_EVENT_UP) {
key_state = 1;
} else {
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
if (this->dev_handler_id != 3) {
switch (event->key) {
case AdbKey_RightControl : event->key = AdbKey_Control; break;
case AdbKey_RightShift : event->key = AdbKey_Shift ; break;
case AdbKey_RightOption : event->key = AdbKey_Option ; break;
}
}
return (key_state << 7) | (event->key & 0x7F);
}
bool AdbKeyboard::get_register_2() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = 0;
out_buf[1] = this->led_state & 0x07;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_2() {
if (this->host_obj->get_input_count() < 2)
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
this->led_state = in_data[1] & 0x07;
}
bool AdbKeyboard::get_register_3() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
out_buf[1] = this->dev_handler_id;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_3() {
@@ -111,7 +146,7 @@ void AdbKeyboard::set_register_3() {
}
static const DeviceDescription AdbKeyboard_Descriptor = {
AdbKeyboard::create, {}, {}
AdbKeyboard::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
+9 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -46,6 +46,8 @@ public:
void event_handler(const KeyboardEvent& event);
bool get_register_0() override;
bool get_register_2() override;
bool get_register_3() override;
void set_register_2() override;
void set_register_3() override;
@@ -128,6 +130,10 @@ enum AdbKey {
AdbKey_Command = 0x37,
AdbKey_CapsLock = 0x39,
AdbKey_RightControl = 0x7d,
AdbKey_RightShift = 0x7b,
AdbKey_RightOption = 0x7c,
AdbKey_ArrowUp = 0x3e,
AdbKey_ArrowDown = 0x3d,
AdbKey_ArrowLeft = 0x3b,
+7 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -66,7 +66,7 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
@@ -84,7 +84,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
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;
buttons = ~buttons;
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
@@ -100,7 +100,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
*p = uint8_t((val & ((1 << bits) - 1)) | (((buttons >> button) & 1) << bits) | (*p << (bits + 1)));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -172,7 +172,7 @@ uint8_t AdbMouse::get_buttons_state() const {
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}
AdbMouse::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -70,7 +70,7 @@ enum DeviceClass {
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons_state, bool force);
bool get_register_0(uint8_t buttons, bool force);
uint8_t get_buttons_state() const;
private:
+54 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -21,11 +21,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Basic ATA device emulation. */
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
#include <loguru.hpp>
#include <cstring>
#include <cinttypes>
using namespace ata_interface;
@@ -75,7 +77,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;
@@ -108,7 +111,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (is_selected() && this->has_data()) {
if (this->is_selected() && this->has_data()) {
*this->cur_data_ptr++ = BYTESWAP_16(value);
this->chunk_cnt -= 2;
if (this->chunk_cnt <= 0) {
@@ -117,12 +120,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,8 +155,12 @@ 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) {
if (this->is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
}
break;
@@ -179,6 +192,38 @@ void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
this->r_dev_ctrl = new_ctrl;
}
int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
if (!this->xfer_cnt || !this->is_dma_xfer)
return 0;
int xfer_size = std::min(this->xfer_cnt, len);
if (this->xfer_cnt != len)
LOG_F(WARNING, "%s: xfer_cnt != len", this->name.c_str());
//for (int i = 0; i < xfer_size >> 1; i++)
// this->data_ptr[i] = BYTESWAP_16(this->data_ptr[i]);
std::memcpy(buf, this->data_ptr, xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
} else {
this->r_status &= ~BSY;
this->r_status |= DRQ;
}
return xfer_size;
}
int AtaBaseDevice::push_data(uint8_t *buf, int len) {
return 0;
}
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
return;
+8 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -43,10 +43,12 @@ public:
void set_host(IdeChannel* host, uint8_t dev_id) {
this->host_obj = host;
this->my_dev_id = dev_id;
};
}
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
int pull_data(uint8_t *buf, int len) override;
int push_data(uint8_t *buf, int len) override;
virtual int perform_command() = 0;
@@ -54,7 +56,7 @@ public:
void pdiag_callback() override {
this->r_error &= 0x7F;
};
}
virtual void device_reset(bool is_soft_reset);
virtual void device_set_signature();
@@ -103,6 +105,7 @@ protected:
int xfer_cnt = 0;
int chunk_cnt = 0;
int chunk_size = 0;
bool is_dma_xfer = false;
std::function<void()> post_xfer_action = nullptr;
};
+16 -10
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -56,7 +56,8 @@ enum ATA_Reg : int {
COMMAND = 0x07, // command (write)
ALT_STATUS = 0x16, // alt status (read)
DEV_CTRL = 0x16, // device control (write)
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
TIME_CONFIG = 0x20, // Apple ASIC specific timing configuration
INT_REG = 0x30, // Interrupt Register (read) 0x40 = int request (KeyLargo only)
};
/** ATAPI specific register offsets. */
@@ -142,8 +143,11 @@ enum ATA_Cmd : uint8_t {
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
READ_DMA = 0xC8,
READ_DMA_NR = 0xC9,
WRITE_DMA = 0xCA,
STANDBY_IMMEDIATE_E0 = 0xE0,
WRITE_DMA_NR = 0xCB,
STANDBY_IMMEDIATE = 0xE0,
SLEEP = 0xE6,
FLUSH_CACHE = 0xE7, // ATA-5
WRITE_BUFFER_DMA = 0xE9,
READ_BUFFER_DMA = 0xEB,
@@ -151,7 +155,7 @@ enum ATA_Cmd : uint8_t {
SET_FEATURES = 0xEF,
};
}; // namespace ata_interface
} // namespace ata_interface
/** Interface for ATA devices. */
class AtaInterface {
@@ -160,9 +164,11 @@ public:
virtual ~AtaInterface() = default;
virtual uint16_t read(const uint8_t reg_addr) = 0;
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
virtual int pull_data(uint8_t *buf, int len) { return 0; };
virtual int push_data(uint8_t *buf, int len) { return 0; };
virtual int get_device_id() = 0;
virtual void pdiag_callback() {};
virtual void pdiag_callback() {}
};
/** Dummy ATA device. */
@@ -178,12 +184,12 @@ public:
// to prevent the software from waiting for a long time
// for empty slots
return 0xFF7FU;
};
}
void write(const uint8_t reg_addr, const uint16_t val) override {};
void write(const uint8_t reg_addr, const uint16_t val) override {}
// invalid device ID means no real device is present
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; }
};
#endif // ATA_INTERFACE_H
+37 -23
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -191,7 +191,11 @@ int AtaHardDisk::perform_command() {
this->signal_data_ready();
break;
case SET_FEATURES:
if (this->r_features == 3) {
switch (this->r_features) {
case 2:
LOG_F(INFO, "%s: write cache enabled", this->name.c_str());
break;
case 3:
switch(this->r_sect_count >> 3) {
case 0:
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
@@ -201,8 +205,9 @@ int AtaHardDisk::perform_command() {
this->r_sect_count & 7);
break;
case 4:
this->cur_dma_mode = this->r_sect_count & 7;
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
this->r_sect_count & 7);
this->cur_dma_mode);
break;
default:
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
@@ -210,15 +215,19 @@ int AtaHardDisk::perform_command() {
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
} else {
break;
case 0xAA:
LOG_F(INFO, "%s: read look-ahead enabled", this->name.c_str());
break;
default:
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
this->name.c_str(), this->r_features);
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case STANDBY_IMMEDIATE_E0:
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
case STANDBY_IMMEDIATE:
LOG_F(INFO, "%s: immediate standby requested", this->name.c_str());
this->r_status &= ~BSY;
this->update_intrq(1);
break;
@@ -236,35 +245,40 @@ void AtaHardDisk::prepare_identify_info() {
std::memset(this->data_buf, 0, sizeof(this->data_buf));
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
buf_ptr[49] = 0x0200; // report LBA support
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
// Maximum number of logical sectors per data block that the device supports
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
WRITE_WORD_LE_A(&buf_ptr[47], 0x8000 | SECTORS_PER_INT);
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
// logical sectors that shall be transferred per data block for
// READ_MULTIPLE/WRITE_MULTIPLE commands.
if (this->sectors_per_int)
buf_ptr[59] = 0x100 | this->sectors_per_int;
WRITE_WORD_LE_A(&buf_ptr[59], 0x100 | this->sectors_per_int);
buf_ptr[ 1] = this->cylinders;
buf_ptr[ 3] = this->heads;
buf_ptr[ 6] = this->sectors;
WRITE_WORD_LE_A(&buf_ptr[ 1], this->cylinders);
WRITE_WORD_LE_A(&buf_ptr[ 3], this->heads);
WRITE_WORD_LE_A(&buf_ptr[ 6], this->sectors);
buf_ptr[57] = this->total_sectors & 0xFFFFU;
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
// report validity for the advanced PIO and MWDMA fields
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
// report LBA capacity
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
}
uint64_t AtaHardDisk::get_lba() {
if (this->r_dev_head & ATA_Dev_Head::LBA) {
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num);
return uint64_t(((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num));
} else { // translate old fashioned CHS addressing to LBA
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
uint8_t h = this->r_dev_head & 0xF;
@@ -274,7 +288,7 @@ uint64_t AtaHardDisk::get_lba() {
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
return -1ULL;
} else
return (this->heads * c + h) * this->sectors + s - 1;
return uint64_t((this->heads * c + h) * this->sectors + s - 1);
}
}
@@ -331,7 +345,7 @@ static const PropMap AtaHardDisk_Properties = {
};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties
AtaHardDisk::create, {}, AtaHardDisk_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
+4 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -71,6 +71,7 @@ private:
uint8_t sectors;
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
char * buffer = new char[1 <<17];
};
+3 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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();
+4 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -43,6 +43,7 @@ public:
// methods to be implemented in the particular device
int perform_command() override;
virtual void perform_packet_command() = 0;
virtual int get_config(uint8_t* pkt, uint8_t* buf) = 0;
virtual int request_data() = 0;
virtual bool data_available() = 0;
+97 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -30,7 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <machines/machineproperties.h>
#include <memaccess.h>
#include <cstring>
#include <string>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -114,7 +116,7 @@ void AtapiCdrom::perform_packet_command() {
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CAPACITY_10:
case ScsiCommand::READ_CAPACITY:
this->xfer_cnt = this->report_capacity(this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
@@ -157,6 +159,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");
}
@@ -168,8 +178,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");
}
@@ -178,11 +203,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");
}
@@ -203,6 +241,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(),
@@ -266,6 +316,18 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
break;
}
case ScsiCommand::GET_CONFIG: {
this->xfer_cnt = this->get_config(this->cmd_pkt, this->data_buf);
if (this->xfer_cnt == 0) {
this->present_status();
} else {
this->xfer_cnt = std::min((int)this->r_byte_count, this->xfer_cnt);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
}
default:
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
this->cmd_pkt[0]);
@@ -274,6 +336,29 @@ void AtapiCdrom::perform_packet_command() {
}
}
int AtapiCdrom::get_config(uint8_t* pkt, uint8_t* buf) {
std::memset(buf, 0, 16);
// Data length (4 bytes header + 8 bytes for one feature descriptor - 4 bytes for length field)
uint32_t data_len = 8;
buf[0] = (data_len >> 24) & 0xFF;
buf[1] = (data_len >> 16) & 0xFF;
buf[2] = (data_len >> 8) & 0xFF;
buf[3] = data_len & 0xFF;
// Feature Descriptor 1 - Set profile to CD-ROM
buf[6] = 0;
buf[7] = 0x08;
// Feature Descriptor 2 - Feature Code, Version 0
buf[8] = 0x00;
buf[9] = 0x01; // Core Feature Code
buf[10] = 0x03; // Persist and Current bits set
buf[11] = 0x04; // Additional Length
return 12;
}
int AtapiCdrom::request_data() {
// continuation of READ_CD above
@@ -309,11 +394,12 @@ uint16_t AtapiCdrom::get_data() {
area_end += 4; // Header
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4];
header[0] = msf.min;
header[1] = msf.sec;
header[2] = msf.frm;
header[3] = 0x01; // Mode 1
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
@@ -389,7 +475,7 @@ static const PropMap AtapiCdrom_Properties = {
};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties
AtapiCdrom::create, {}, AtapiCdrom_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -42,6 +42,8 @@ public:
void perform_packet_command() override;
int get_config(uint8_t* pkt, uint8_t* buf) override;
int request_data() override;
bool data_available() override {
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -139,7 +139,7 @@ bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
return true;
};
}
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+21 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
and interrupt handling.
*/
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
@@ -81,6 +82,21 @@ void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int siz
}
}
int IdeChannel::xfer_from(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->pull_data(buf, len);
}
int IdeChannel::xfer_to(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->push_data(buf, len);
}
void IdeChannel::assert_dmareq(uint64_t delay) {
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
this->channel_obj->xfer_retry();
});
}
int MacioIdeChannel::device_postinit() {
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
@@ -117,11 +133,11 @@ void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const in
}
static const DeviceDescription Ide0_Descriptor = {
MacioIdeChannel::create_first, {}, {}
MacioIdeChannel::create_first, {}, {}, HWCompType::IDE_BUS
};
static const DeviceDescription Ide1_Descriptor = {
MacioIdeChannel::create_second, {}, {}
MacioIdeChannel::create_second, {}, {}, HWCompType::IDE_BUS
};
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
+15 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define IDE_CHANNEL_H
#include <devices/common/ata/atadefs.h>
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
@@ -33,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
class IdeChannel : public HWComponent
class IdeChannel : public HWComponent, public DmaDevice
{
public:
IdeChannel(const std::string name);
@@ -41,8 +42,11 @@ public:
void register_device(int id, AtaInterface* dev_obj);
uint32_t read(const uint8_t reg_addr, const int size);
void write(const uint8_t reg_addr, const uint32_t val, const int size);
virtual uint32_t read(const uint8_t reg_addr, const int size);
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size);
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
void assert_pdiag() {
this->devices[0]->pdiag_callback();
@@ -60,6 +64,8 @@ public:
this->irq_callback(intrq_state);
}
void assert_dmareq(uint64_t delay);
protected:
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
@@ -74,7 +80,7 @@ private:
class MacioIdeChannel : public IdeChannel
{
public:
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
MacioIdeChannel(const std::string name) : IdeChannel(name) {}
~MacioIdeChannel() = default;
static std::unique_ptr<HWComponent> create_first() {
@@ -87,8 +93,8 @@ public:
int device_postinit() override;
uint32_t read(const uint8_t reg_addr, const int size);
void write(const uint8_t reg_addr, const uint32_t val, const int size);
virtual uint32_t read(const uint8_t reg_addr, const int size) override;
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size) override;
private:
uint32_t ch_config = 0; // timing configuration for this channel
+10 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -38,10 +38,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <vector>
AthensClocks::AthensClocks(uint8_t dev_addr)
{
AthensClocks::AthensClocks(uint8_t dev_addr) : I2CDevice() {
set_name("Athens");
supports_types(HWCompType::I2C_DEV);
this->my_addr = dev_addr;
@@ -75,10 +73,9 @@ bool AthensClocks::send_subaddress(uint8_t sub_addr)
bool AthensClocks::send_byte(uint8_t data)
{
switch (this->pos) {
switch (this->pos++) {
case 0:
this->reg_num = data;
this->pos++;
break;
case 1:
if (this->reg_num >= ATHENS_NUM_REGS) {
@@ -90,7 +87,7 @@ bool AthensClocks::send_byte(uint8_t data)
break;
default:
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
return false; // return NACK
//return false; // return NACK
}
return true;
}
@@ -103,6 +100,8 @@ bool AthensClocks::receive_byte(uint8_t* p_data)
int AthensClocks::get_sys_freq()
{
LOG_F(ERROR, "%s: sys clock calculation not implemented yet", this->name.c_str());
return 0;
}
@@ -118,7 +117,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 +149,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);
}
+5 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATHENS_H
#define ATHENS_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
@@ -47,10 +46,9 @@ enum AthensRegs: uint8_t {
P1 = 7
};
}; // namespace AthensRegs
} // namespace AthensRegs
class AthensClocks : public I2CDevice, public HWComponent
{
class AthensClocks : public I2CDevice {
public:
AthensClocks(uint8_t dev_addr);
AthensClocks(uint8_t dev_addr, const float crystal_freq);
+38 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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;
@@ -313,6 +313,15 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
case DMAReg::CMD_PTR_LO:
result = this->cmd_ptr;
break;
case DMAReg::INT_SELECT:
result = this->int_select;
break;
case DMAReg::BRANCH_SELECT:
result = this->branch_select;
break;
case DMAReg::WAIT_SELECT:
result = this->wait_select;
break;
default:
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
this->get_name().c_str(), offset);
@@ -427,9 +436,13 @@ 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();
} else if (got_bytes) {
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
this->get_name().c_str());
}
this->interpret_cmd();
@@ -441,7 +454,8 @@ void DMAChannel::xfer_to_device() {
this->xfer_dir = DMA_DIR_TO_DEV;
if (!this->dev_obj->xfer_to(this->queue_data, this->queue_len)) {
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();
}
@@ -449,6 +463,24 @@ void DMAChannel::xfer_to_device() {
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;
+16 -13
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -99,7 +99,7 @@ namespace DBDMA_Cmd {
NOP = 6,
STOP = 7
};
};
}
typedef std::function<void(void)> DbdmaCallback;
@@ -114,19 +114,22 @@ 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;
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;
};
}
protected:
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
+24 -21
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,15 +35,15 @@ enum DmaPullResult : int {
class DmaOutChannel {
public:
DmaOutChannel(std::string name) { this->name = name; };
DmaOutChannel(std::string name) { this->name = name; }
virtual bool is_out_active() { return true; };
virtual bool is_out_active() { return true; }
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
virtual int get_pull_data_remaining() { return 1; };
virtual void end_pull_data() { };
virtual int get_pull_data_remaining() { return 1; }
virtual void end_pull_data() {}
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -51,14 +51,14 @@ private:
class DmaInChannel {
public:
DmaInChannel(std::string name) { this->name = name; };
DmaInChannel(std::string name) { this->name = name; }
virtual bool is_in_active() { return true; };
virtual bool is_in_active() { return true; }
virtual int push_data(const char* src_ptr, int len) = 0;
virtual int get_push_data_remaining() { return 1; };
virtual void end_push_data() { };
virtual int get_push_data_remaining() { return 1; }
virtual void end_push_data() {}
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -68,9 +68,9 @@ private:
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
public:
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
DmaInChannel(name + std::string(" In")) { this->name = name; };
DmaInChannel(name + std::string(" In")) { this->name = name; }
std::string get_name(void) { return this->name; };
std::string get_name(void) { return this->name; }
private:
std::string name;
@@ -96,10 +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 int xfer_to(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;
@@ -110,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;
+10 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -35,6 +35,7 @@ enum HWCompType : uint64_t {
MMIO_DEV = 1ULL << 4, // memory mapped I/O device
PCI_HOST = 1ULL << 5, // PCI host
PCI_DEV = 1ULL << 6, // PCI device
NUBUS_DEV = 1ULL << 7, // Nubus device
I2C_HOST = 1ULL << 8, // I2C host
I2C_DEV = 1ULL << 9, // I2C device
ADB_HOST = 1ULL << 12, // ADB host
@@ -53,6 +54,7 @@ enum HWCompType : uint64_t {
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
MACHINE = 1ULL << 41, // machine root
};
/** Base class for HW components. */
@@ -63,22 +65,22 @@ public:
virtual std::string get_name(void) {
return this->name;
};
}
virtual void set_name(std::string name) {
this->name = name;
};
}
virtual bool supports_type(HWCompType type) {
return !!(this->supported_types & type);
};
}
virtual void supports_types(uint64_t types) {
this->supported_types = types;
};
}
virtual int device_postinit() {
return 0;
};
}
protected:
std::string name;
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+17 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <devices/common/hwcomponent.h>
#include <loguru.hpp>
#include <cinttypes>
@@ -35,8 +36,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
/** Base class for I2C devices */
class I2CDevice {
class I2CDevice : virtual public HWComponent {
public:
I2CDevice() {
supports_types(HWCompType::I2C_DEV);
}
virtual ~I2CDevice() = default;
virtual void start_transaction() = 0;
virtual bool send_subaddress(uint8_t sub_addr) = 0;
virtual bool send_byte(uint8_t data) = 0;
@@ -44,11 +50,11 @@ public:
};
/** Base class for I2C hosts */
class I2CBus {
class I2CBus : virtual public HWComponent {
public:
I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
};
}
virtual ~I2CBus() = default;
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
@@ -57,7 +63,7 @@ public:
}
this->dev_list[dev_addr] = dev_obj;
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
};
}
virtual bool start_transaction(uint8_t dev_addr) {
if (this->dev_list[dev_addr]) {
@@ -66,28 +72,28 @@ public:
} else {
return false;
}
};
}
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
};
}
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_byte(data);
};
}
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->receive_byte(p_data);
};
}
protected:
I2CDevice* dev_list[128]; /* list of registered I2C devices */
+7 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -54,17 +54,17 @@ void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
void I2CProm::start_transaction() {
this->pos = 0;
};
}
bool I2CProm::send_subaddress(uint8_t sub_addr) {
this->pos = sub_addr;
return true;
};
}
bool I2CProm::send_byte(uint8_t data) {
LOG_F(9, "I2CRom: 0x%X received", data);
return true;
};
}
bool I2CProm::receive_byte(uint8_t* p_data) {
if (this->pos >= this->rom_size) {
@@ -72,4 +72,4 @@ bool I2CProm::receive_byte(uint8_t* p_data) {
}
*p_data = this->data[this->pos++];
return true;
};
}
+4 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -24,14 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_PROM_H
#define I2C_PROM_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
#include <memory>
class I2CProm : public I2CDevice, public HWComponent
{
class I2CProm : public I2CDevice {
public:
I2CProm(uint8_t dev_addr, int size);
~I2CProm() = default;
+14 -14
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -43,7 +43,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Machine ID register for NuBus Power Macs.
It's located at physical address 0x5FFFFFFC and contains four bytes:
+0 uint16_t signature = 0xA55A
+1 uint8_t machine_type (3 - Power Mac)
+1 uint8_t machine_type (0x30 - Power Mac)
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
*/
class NubusMacID : public MMIODevice {
@@ -55,7 +55,7 @@ public:
this->id[2] = (id >> 8) & 0xFF;
this->id[3] = id & 0xFF;
supports_types(HWCompType::MMIO_DEV);
};
}
~NubusMacID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
@@ -67,10 +67,10 @@ public:
}
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
return 0;
};
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint8_t id[4];
@@ -88,19 +88,19 @@ public:
this->set_name(name);
supports_types(HWCompType::IOBUS_DEV);
this->data = data;
};
}
~BoardRegister() = default;
uint16_t iodev_read(uint32_t address) {
return this->data;
};
}
// appears read-only to guest
void iodev_write(uint32_t address, uint16_t value) {};
void iodev_write(uint32_t address, uint16_t value) {}
void update_bits(const uint16_t val, const uint16_t mask) {
this->data = (this->data & ~mask) | (val & mask);
};
}
private:
uint16_t data;
@@ -118,15 +118,15 @@ public:
this->id = id;
this->name = "Machine-id";
supports_types(HWCompType::MMIO_DEV);
};
}
~GossamerID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
return ((offset == 4 && size == 2) ? this->id : 0);
};
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint16_t id;
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+8 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nvram.h>
#include <devices/common/ofnvram.h>
#include <devices/deviceregistry.h>
#include <cinttypes>
@@ -46,6 +47,9 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
this->file_name = file_name;
this->ram_size = ram_size;
if (ram_size == 8192)
this->of_nvram_offset = OF_NVRAM_OFFSET;
// allocate memory storage and fill it with zeroes
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
@@ -99,7 +103,7 @@ void NVram::save() {
}
static const DeviceDescription Nvram_Descriptor = {
NVram::create, {}, {}
NVram::create, {}, {}, HWCompType::NVRAM
};
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
+5 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -45,11 +45,13 @@ public:
uint8_t read_byte(uint32_t offset);
void write_byte(uint32_t offset, uint8_t value);
uint32_t get_of_nvram_offset() { return of_nvram_offset; }
private:
std::string file_name; // file name for the backing file
uint16_t ram_size; // NVRAM size
std::unique_ptr<uint8_t[]> storage;
uint32_t of_nvram_offset = 0;
void init();
void save();
+12 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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();
}
@@ -67,7 +67,7 @@ bool OfConfigAppl::validate() {
// read OF partition header
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// validate partition signature and version
@@ -81,7 +81,7 @@ bool OfConfigAppl::validate() {
// read the entire partition into the local buffer
for (i = 0; i < this->size; i++) {
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
this->buf[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// verify partition checksum
@@ -161,7 +161,7 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
break;
case OF_VAR_TYPE_STR:
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - this->nvram_obj->get_of_nvram_offset();
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
if ((str_offset + str_len) > OF_CFG_SIZE) {
@@ -194,7 +194,7 @@ void OfConfigAppl::update_partition() {
// write the entire partition back to NVRAM
for (int i = 0; i < this->size; i++) {
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
this->nvram_obj->write_byte(this->nvram_obj->get_of_nvram_offset() + i, this->buf[i]);
}
}
@@ -266,8 +266,8 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
}
// remove the old string
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET],
&this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
std::memmove(&this->buf[top + str_len - this->nvram_obj->get_of_nvram_offset()],
&this->buf[top - this->nvram_obj->get_of_nvram_offset()], str_offset - top);
for (auto& var : of_vars) {
auto type = std::get<0>(var.second);
@@ -284,7 +284,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
// copy new string into NVRAM buffer char by char
i = 0;
for(char& ch : value) {
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
this->buf[top + i - this->nvram_obj->get_of_nvram_offset()] = ch == '\x0A' ? '\x0D' : ch;
i++;
}
@@ -591,7 +591,7 @@ 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
}
}
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -87,7 +87,7 @@ public:
// Old World implementation
class OfConfigAppl : public OfConfigImpl {
public:
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigAppl() = default;
bool validate();
@@ -108,7 +108,7 @@ private:
// New World implementation
class OfConfigChrp : public OfConfigImpl {
public:
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigChrp() = default;
bool validate();
+12 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -389,24 +389,28 @@ static const PropMap PsxPci1_Properties = {
new StrProperty("")},
};
static const std::vector<std::string> Chaos_Subdevices = {
"ControlVideo"
};
static const DeviceDescription Bandit1_Descriptor = {
Bandit::create_first, {}, Bandit1_Properties
Bandit::create_first, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Bandit2_Descriptor = {
Bandit::create_second, {}, Bandit2_Properties
Bandit::create_second, {}, Bandit2_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, PsxPci1_Properties
Bandit::create_psx_first, {}, PsxPci1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, {}, Chaos_Properties
Chaos::create, Chaos_Subdevices, Chaos_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription AspenPci1_Descriptor = {
AspenPci::create, {}, Bandit1_Properties
AspenPci::create, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
+9 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -71,7 +71,7 @@ enum {
*/
class BanditHost : public PCIHost, public MMIODevice {
public:
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
BanditHost(int bridge_num) { this->bridge_num = bridge_num; }
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
@@ -121,15 +121,15 @@ public:
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
};
}
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
};
}
static std::unique_ptr<HWComponent> create_psx_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
};
}
private:
std::unique_ptr<BanditPciDevice> my_pci_device;
@@ -146,7 +146,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
};
}
};
/**
@@ -159,7 +159,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
};
}
};
#endif // BANDIT_PCI_H
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -102,11 +102,11 @@ static const PropMap Dec21154Yosemite_Properties = {
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}
DecPciBridge::create, {}, {}, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+8 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -41,7 +41,10 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
this->pci_wr_stat = [](uint16_t val) {};
this->pci_wr_stat = [this](uint16_t val) {
this->status &= ~(0b1111100100000000 & val);
};
this->pci_wr_cmd = [this](uint16_t cmd) {
/*
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
@@ -54,7 +57,7 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
this->pci_notify_bar_change = [](int bar_num) {};
};
}
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+6 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -86,16 +86,16 @@ public:
virtual bool supports_io_space() {
return has_io_space;
};
}
/* I/O space access methods */
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
return false;
};
}
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
};
}
// configuration space access methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
+14 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -39,12 +39,12 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_memory_base = [this](uint16_t val) {
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_base_32 = ((this->memory_base & 0xfff0) << 16);
this->memory_base_32 = (((uint64_t)this->memory_base & 0xfff0) << 16);
};
this->pci_wr_memory_limit = [this](uint16_t val) {
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_limit_32 = ((this->memory_limit & 0xfff0) << 16) + 0x100000;
this->memory_limit_32 = (((uint64_t)this->memory_limit & 0xfff0) << 16) + 0x100000;
};
this->pci_wr_io_base = [this](uint8_t val) {
@@ -61,12 +61,13 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_pref_mem_base = [this](uint16_t val) {
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
((this->pref_mem_base & 0xfff0) << 16);
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
if ((this->io_base & 15) == 1)
@@ -85,16 +86,17 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
if ((this->pref_mem_cfg & 15) == 1)
this->pref_base_upper32 = val;
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
((this->pref_mem_base & 0xfff0) << 16);
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
if ((this->pref_mem_cfg & 15) == 1)
this->pref_limit_upper32 = val;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
};
}
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -40,9 +40,9 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
};
this->pci_wr_sec_status = [this](uint16_t val) {};
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
};
}
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);
+10 -10
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -43,16 +43,16 @@ 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;
};
}
// plugin interface for using in the derived classes
std::function<uint8_t()> pci_rd_primary_bus;
@@ -69,7 +69,7 @@ public:
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit();
virtual int device_postinit() override;
protected:
// PCI configuration space state
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -126,7 +126,7 @@ PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_H
this->io_limit_1 = (val & this->io_1_cfg);
this->io_limit_1_32 = this->io_limit_1 + 4;
};
};
}
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
@@ -219,5 +219,5 @@ bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t si
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
return this->pci_io_read_loop(offset, size, value);
return this->pci_io_write_loop(offset, size, value);
}
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
PCIDevice::PCIDevice(std::string name) : PCIBase(name, PCI_HEADER_TYPE_0, 6)
{
};
}
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
+4 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -23,7 +23,6 @@ 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>
@@ -90,7 +89,7 @@ void PCIHost::pci_unregister_device(int 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));
+9 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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>
@@ -64,14 +65,14 @@ public:
PCIHost() {
this->dev_map.clear();
io_space_devs.clear();
};
}
~PCIHost() = default;
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,
@@ -88,13 +89,13 @@ public:
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
};
}
virtual int pcihost_device_postinit();
virtual bool register_pci_int(PCIBase* dev_instance);
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
this->int_ctrl = int_ctrl_obj;
};
}
virtual InterruptCtrl *get_interrupt_controller();
protected:
+25 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -37,7 +37,7 @@ using namespace MeshScsi;
int MeshController::device_postinit() {
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
if (bus_obj) {
bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
bus_obj->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus_obj->attach_scsi_devices("2");
}
@@ -209,7 +209,16 @@ void MeshController::perform_command(const uint8_t cmd) {
this->sequencer();
break;
case SeqCmd::BusFree:
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// Don't release ACK if ATN is asserted. This condition indicates
// that the initiator wants to reject last message.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// Let the target switch to next bus phase if
// - both ACK and ATN are asserted so the target will reject last message
// - when in MESSAGE_IN phase to tell the target the initiator accepts last message
if (this->is_initiator && (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN) ||
this->bus_obj->current_phase() == ScsiPhase::MESSAGE_IN))
this->bus_obj->target_next_step();
// generate phase mismatch exception
// if the target is still connected
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
@@ -282,7 +291,11 @@ void MeshController::step_completed() {
}
void MeshController::report_error(const int error) {
switch(error) {
switch (error) {
case ARB_LOST:
this->exception |= EXC_ARB_LOST;
this->int_stat |= INT_EXCEPTION;
break;
case SEL_TIMEOUT:
this->exception |= EXC_SEL_TIMEOUT;
this->int_stat |= INT_EXCEPTION;
@@ -299,12 +312,16 @@ static const PropMap Mesh_properties = {
{"cdr_img2", new StrProperty("")},
};
static const std::vector<std::string> Mesh_Subdevices = {
"ScsiMesh"
};
static const DeviceDescription Mesh_Tnt_Descriptor = {
MeshController::create_for_tnt, {}, Mesh_properties
MeshController::create_for_tnt, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
static const DeviceDescription Mesh_Heathrow_Descriptor = {
MeshController::create_for_heathrow, {}, Mesh_properties
MeshController::create_for_heathrow, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
REGISTER_DEVICE(MeshTnt, Mesh_Tnt_Descriptor);
+7 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -91,7 +91,7 @@ namespace MeshScsi {
INT_ERROR = 1 << 2,
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
};
}; // namespace MeshScsi
} // namespace MeshScsi
class MeshBase {
public:
@@ -107,8 +107,8 @@ public:
~MeshStub() = default;
// registers access
uint8_t read(uint8_t reg_offset) override { return 0; };
void write(uint8_t reg_offset, uint8_t value) override {};
uint8_t read(uint8_t reg_offset) override { return 0; }
void write(uint8_t reg_offset, uint8_t value) override {}
};
class MeshController : public ScsiBusController, public MeshBase {
@@ -116,7 +116,7 @@ public:
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
this->chip_id = mesh_id;
this->reset(true);
};
}
~MeshController() = default;
static std::unique_ptr<HWComponent> create_for_tnt() {
+213 -102
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -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), DmaDevice()
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiPhysDevice("SC53C94", my_id), DmaDevice()
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
@@ -45,7 +45,7 @@ int Sc53C94::device_postinit()
{
ScsiBus* bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
if (bus) {
bus->register_device(7, static_cast<ScsiDevice*>(this));
bus->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus->attach_scsi_devices("");
}
@@ -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,29 @@ 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) {
static bool log_it = true;
if (log_it) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
log_it = false;
}
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
} else
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
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 +155,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 +262,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 +277,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 +311,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 +325,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 +427,6 @@ void Sc53C94::exec_next_command()
}
}
constexpr auto DATA_FIFO_MAX = 16;
void Sc53C94::fifo_push(const uint8_t data)
{
if (this->data_fifo_pos < DATA_FIFO_MAX) {
@@ -410,19 +455,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 +507,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 +528,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 +537,29 @@ 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->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
@@ -513,8 +568,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,13 +578,28 @@ void Sc53C94::sequencer()
this->sequencer();
break;
case ScsiPhase::DATA_IN:
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
if (!(this->is_dma_cmd)) {
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:
@@ -555,16 +625,22 @@ void Sc53C94::sequencer()
break;
case SeqState::RCV_STATUS:
case SeqState::RCV_MESSAGE:
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->rcv_data();
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->int_status = INTSTAT_SO;
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
}
}
break;
@@ -583,32 +659,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 +718,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();
}
@@ -752,38 +841,55 @@ void Sc53C94::dma_stop()
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
if (len > this->xfer_count + this->data_fifo_pos)
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
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));
// see if there are data bytes in the FIFO we want to grab first
if (this->data_fifo_pos) {
int fifo_bytes = std::min(this->data_fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->data_fifo_pos -= fifo_bytes;
this->xfer_count -= fifo_bytes;
len -= fifo_bytes;
bytes_moved += fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
return bytes_moved;
}
}
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
this->xfer_count = 0;
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
if (this->bus_obj->pull_data(this->target_id, buf, len)) {
bytes_moved += len;
this->xfer_count -= len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
}
return len;
return bytes_moved;
}
int Sc53C94::xfer_to(uint8_t *buf, int len) {
if (!this->xfer_count)
return 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.
@@ -792,6 +898,7 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
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;
@@ -806,16 +913,16 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
// 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);
len -= 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 len;
return bytes_moved;
}
static const PropMap Sc53C94_properties = {
@@ -823,8 +930,12 @@ static const PropMap Sc53C94_properties = {
{"cdr_img", new StrProperty("")},
};
static const std::vector<std::string> Sc53C94_Subdevices = {
"ScsiCurio"
};
static const DeviceDescription Sc53C94_Descriptor = {
Sc53C94::create, {}, Sc53C94_properties
Sc53C94::create, Sc53C94_Subdevices, Sc53C94_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
};
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
+43 -33
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -58,7 +58,7 @@ namespace Read {
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
//
};
};
}
/** 53C94 write registers */
namespace Write {
@@ -80,7 +80,7 @@ namespace Write {
Xfer_Cnt_Hi = 0xE, // Start Transfer Count Register High ; Am53CF94 extension
Data_Align = 0xF, // Data Alignment Register
};
};
}
/** NCR53C94/Am53CF94 commands. */
enum {
@@ -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,
@@ -175,19 +180,21 @@ namespace SeqState {
RCV_STATUS,
RCV_MESSAGE,
};
};
}
/** 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, public DmaDevice {
class Sc53C94 : public ScsiPhysDevice, 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);
@@ -221,23 +228,24 @@ public:
std::bind(&Sc53C94::dma_stop, this)
);
}
};
}
void set_drq_callback(DrqCb cb) {
this->drq_cb = cb;
}
// 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() {};
// ScsiPhysDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool has_data() override { return this->data_fifo_pos != 0; }
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {}
// DmaChannel methods
int xfer_from(uint8_t *buf, int len); // Must be marked override!
int xfer_to(uint8_t *buf, int len); // Must be marked 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();
@@ -260,7 +268,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;
@@ -272,6 +280,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;
@@ -287,6 +296,7 @@ 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;
+144 -41
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SCSI_H
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <array>
#include <cinttypes>
@@ -47,6 +48,7 @@ enum {
SCSI_CTRL_RST = 1 << 15,
};
/** SCSI bus phases. */
namespace ScsiPhase {
enum : int {
BUS_FREE = 0,
@@ -61,15 +63,17 @@ namespace ScsiPhase {
MESSAGE_OUT,
RESET,
};
};
}
/** SCSI status codes. */
namespace ScsiStatus {
enum : uint8_t {
GOOD = 0,
CHECK_CONDITION = 2,
};
};
}
/** Standard message codes. */
namespace ScsiMessage {
enum : uint8_t {
COMMAND_COMPLETE = 0,
@@ -80,15 +84,21 @@ namespace ScsiMessage {
HAS_DISCONNECT_PRIVILEDGE = 0x40,
IDENTIFY = 0x80,
};
};
}
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 {
@@ -97,6 +107,7 @@ enum ScsiCommand : uint8_t {
REQ_SENSE = 0x03,
FORMAT_UNIT = 0x04,
READ_BLK_LIMITS = 0x05,
REASSIGN = 0x07,
READ_6 = 0x08,
WRITE_6 = 0x0A,
SEEK_6 = 0x0B,
@@ -110,15 +121,24 @@ enum ScsiCommand : uint8_t {
DIAG_RESULTS = 0x1C,
SEND_DIAGS = 0x1D,
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
READ_CAPACITY_10 = 0x25,
READ_CAPACITY = 0x25,
READ_10 = 0x28,
WRITE_10 = 0x2A,
SEEK_10 = 0x2B,
VERIFY_WRITE_10 = 0x2E,
VERIFY_10 = 0x2F,
READ_LONG_10 = 0x35,
WRITE_BUFFER = 0x3B,
READ_BUFFER = 0x3C,
GET_CONFIG = 0x46,
GET_EVENT_STATUS_NOTIFY = 0x4A,
READ_DISC_INFO = 0x51,
MODE_SELECT_10 = 0x55,
MODE_SENSE_10 = 0x5A,
READ_12 = 0xA8,
WRITE_12 = 0xAA,
READ_DVD_STRUCTURE = 0xAD,
SET_SPEED = 0xBB,
// CD-ROM specific commands
READ_TOC = 0x43,
@@ -126,7 +146,7 @@ enum ScsiCommand : uint8_t {
READ_CD = 0xBE,
};
enum ScsiSense : int {
enum ScsiSense : uint8_t {
NO_SENSE = 0x0,
RECOVERED = 0x1,
NOT_READY = 0x2,
@@ -141,7 +161,7 @@ enum ScsiSense : int {
COMPLETED = 0xF
};
enum ScsiError : int {
enum ScsiError : uint8_t {
NO_ERROR = 0x00,
NO_SECTOR = 0x01,
WRITE_FAULT = 0x03,
@@ -155,6 +175,57 @@ enum ScsiError : int {
MEDIUM_NOT_PRESENT = 0x3A,
};
/** SCSI device types used in INQUIRY. */
namespace ScsiDevType {
enum : uint8_t {
DIRECT_ACCESS = 0,
SEQ_ACCESS = 1,
PRINTER = 2,
PROCESSOR = 3,
WRITE_ONCE = 4,
CD_ROM = 5,
SCANNER = 6,
OPT_MEMORY = 7,
MEDIUM_CHANGER = 8,
COMMUNICATION = 9,
UNKNOWN = 0x1F
};
};
/** SCSI device capacity flags. */
enum : uint8_t {
CAP_REL_ADDR = 1 << 7, // device supports relative addressing
CAP_W32_XFER = 1 << 6, // device supports 32-bit wide transfers
CAP_W16_XFER = 1 << 5, // device supports 16-bit wide transfers
CAP_SYNC_XFER = 1 << 4, // device supports synchronous transfers
CAP_LINKED_CMDS = 1 << 3, // device supports linked commands
CAP_CMD_QUEUE = 1 << 1, // device supports command queuing
CAP_CMD_SRST = 1 << 0, // device supports soft resets
};
/** Page control values for MODE SENSE. */
namespace PageControl {
enum : uint8_t {
CURRENT_VALUES = 0,
CHANGEABLE_VALUES = 1,
DEFAULT_VALUES = 2,
SAVED_VALUES = 3
};
};
/** Page numbers for MODE SENSE and MODE SELECT. */
enum ModePage : uint8_t {
ERROR_RECOVERY = 0x1,
DEV_FORMAT_PARAMS = 0x3,
RIGID_DISK_GEOMETRY = 0x4,
CDROM_PARAMS = 0xD,
CDROM_AUDIO = 0xE,
POWER_CONDITION = 0x1A,
CDROM_CAPABILITIES = 0x2A,
VENDOR_PAGE_31 = 0x31,
ALL_PAGES = 0x3F,
};
/** Standard SCSI bus timing values measured in ns. */
constexpr uint64_t BUS_SETTLE_DELAY = 400;
constexpr uint64_t BUS_FREE_DELAY = 800;
@@ -167,41 +238,72 @@ constexpr auto SCSI_MAX_DEVS = 8;
class ScsiBus;
typedef std::function<void()> action_callback;
class ScsiDevice : public HWComponent {
class ScsiPhysDevice : public ScsiPhysInterface, public HWComponent {
public:
ScsiDevice(std::string name, int my_id) {
ScsiPhysDevice(std::string name, int my_id) : ScsiPhysInterface(PHY_ID_SCSI) {
this->set_name(name);
supports_types(HWCompType::SCSI_DEV);
this->scsi_id = my_id;
this->lun = 0,
this->cur_phase = ScsiPhase::BUS_FREE;
};
~ScsiDevice() = default;
}
~ScsiPhysDevice() = default;
virtual void notify(ScsiMsg msg_type, int param);
// ScsiPhysInterface methods
bool last_sel_has_attention() override {
return this->last_selection_has_attention;
}
uint8_t last_sel_msg() override {
return this->last_selection_message;
}
void set_xfer_len(uint64_t len) override {
this->xfer_len = len;
}
void set_buffer(uint8_t *bptr) override {
this->buf_ptr = bptr;
}
void set_read_more_data_cb(more_data_cb_t cb) override {
this->read_more_data = cb;
}
void set_write_more_data_cb(more_data_cb_t cb) override {
this->write_more_data = cb;
}
void set_post_xfer_action(action_callback cb) override {
this->post_xfer_action = cb;
}
void set_status(uint8_t status_code) override {
this->status = status_code;
}
void set_eject_state(bool eject_allowed) override {
this->eject_allowed = eject_allowed;
}
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 void prepare_xfer();
virtual void switch_phase(const int new_phase) override;
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; };
virtual bool has_data() { return this->data_size != 0; }
virtual int xfer_data();
virtual int send_data(uint8_t* dst_ptr, int count);
virtual int rcv_data(const uint8_t* src_ptr, const int count);
virtual bool check_lun();
void illegal_command(const uint8_t* cmd);
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;
}
void report_error(uint8_t sense_key, uint8_t asc);
protected:
uint8_t cmd_buf[16] = {};
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
@@ -210,22 +312,24 @@ protected:
int initiator_id;
int cur_phase;
uint8_t* data_ptr = nullptr;
uint8_t* buf_ptr = nullptr;
int xfer_len;
int data_size;
int incoming_size;
uint8_t status;
int sense;
int asc;
int ascq;
int sksv;
int field;
bool last_selection_has_atention = false;
bool eject_allowed = true;
bool last_selection_has_attention = false;
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;
more_data_cb_t read_more_data = {};
more_data_cb_t write_more_data = {};
};
/** This class provides a higher level abstraction for the SCSI bus. */
@@ -245,7 +349,7 @@ public:
void attach_scsi_devices(const std::string bus_suffix);
// low-level state management
void register_device(int id, ScsiDevice* dev_obj);
void register_device(int id, ScsiPhysDevice* dev_obj);
int current_phase() const {
return this->cur_phase;
@@ -266,7 +370,7 @@ public:
uint16_t test_ctrl_lines(uint16_t mask);
// reading/writing data lines
uint8_t get_data_lines() { return this->data_lines; };
uint8_t get_data_lines() { return this->data_lines; }
// high-level control/status
int switch_phase(int id, int new_phase);
@@ -280,14 +384,13 @@ public:
bool push_data(const int id, const uint8_t* src_ptr, const int size);
int target_xfer_data();
void target_next_step();
bool negotiate_xfer(int& bytes_in, int& bytes_out);
protected:
void change_bus_phase(int initiator_id);
private:
// SCSI devices registered with this bus
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
std::array<ScsiPhysDevice*, SCSI_MAX_DEVS> devices;
// per-device state of the control lines
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
+259
View File
@@ -0,0 +1,259 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/scsi/scsiblockcmds.h>
#include <loguru.hpp>
#include <memaccess.h>
ScsiBlockCmds::ScsiBlockCmds(int cache_blocks) : BlockStorageDevice(cache_blocks) {
this->enable_cmd(ScsiCommand::READ_6);
this->enable_cmd(ScsiCommand::READ_10);
this->enable_cmd(ScsiCommand::READ_12);
this->enable_cmd(ScsiCommand::WRITE_6);
this->enable_cmd(ScsiCommand::WRITE_10);
this->enable_cmd(ScsiCommand::WRITE_12);
this->enable_cmd(ScsiCommand::START_STOP_UNIT);
this->enable_cmd(ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL);
this->enable_cmd(ScsiCommand::READ_CAPACITY);
this->add_page_getter(this, ModePage::ERROR_RECOVERY,
&ScsiBlockCmds::get_error_recovery_page);
}
void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags) {
this->medium_type = medium_type;
this->device_flags = dev_flags;
phy_impl->set_read_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->remain_size) {
*dsize = this->read_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
if (this->is_writeable) {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->remain_size) {
*dsize = this->write_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
} else {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
return false;
}
);
}
}
void ScsiBlockCmds::process_command() {
int next_phase;
// use non-disk buffer by default
phy_impl->set_buffer(this->buf_ptr);
switch(this->cdb_ptr[0]) {
case ScsiCommand::READ_6:
case ScsiCommand::READ_10:
case ScsiCommand::READ_12:
next_phase = this->read_new();
break;
case ScsiCommand::WRITE_6:
case ScsiCommand::WRITE_10:
case ScsiCommand::WRITE_12:
next_phase = this->write_new();
break;
case ScsiCommand::START_STOP_UNIT:
next_phase = this->start_stop_unit();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
phy_impl->set_eject_state((this->cdb_ptr[4] & 1) == 0);
next_phase = ScsiPhase::STATUS;
break;
case ScsiCommand::READ_CAPACITY:
next_phase = this->read_capacity();
break;
default:
ScsiCommonCmds::process_command();
return;
}
phy_impl->switch_phase(next_phase);
}
int ScsiBlockCmds::read_new() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for READ_6
if (this->cdb_ptr[0] == ScsiCommand::READ_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "READ: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->read_begin(nblocks));
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::write_new() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for WRITE_6
if (this->cdb_ptr[0] == ScsiCommand::WRITE_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "WRITE: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "WRITE: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->write_begin(nblocks));
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
phy_impl->set_post_xfer_action([this]() {
this->write_cache();
}
);
return ScsiPhase::DATA_OUT;
}
int ScsiBlockCmds::start_stop_unit() {
if (this->cdb_ptr[4] & 1) {
if (this->cdb_ptr[4] & 2)
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
} else {
if (this->cdb_ptr[4] & 2) {
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
}
}
return ScsiPhase::STATUS;
}
int ScsiBlockCmds::read_capacity() {
uint32_t lba = this->get_lba();
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ_CAPACITY: RelAdr bit set");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
if (!(this->cdb_ptr[8] & 1) && lba) {
LOG_F(ERROR, "READ_CAPACITY: non-zero LBA for PMI=0");
this->set_field_pointer(2),
this->invalid_cdb();
return ScsiPhase::STATUS;
}
uint32_t last_lba = this->size_blocks - 1;
uint32_t blk_len = this->block_size;
WRITE_DWORD_BE_A(&this->buf_ptr[0], last_lba);
WRITE_DWORD_BE_A(&this->buf_ptr[4], blk_len);
phy_impl->set_xfer_len(8);
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::format_block_descriptors(uint8_t* out_ptr) {
uint8_t density_code = 0;
uint32_t nblocks = std::min((int64_t)this->size_blocks, (int64_t)0xFFFFFFFFUL);
WRITE_DWORD_BE_A(&out_ptr[0], nblocks);
WRITE_DWORD_BE_A(&out_ptr[4], (density_code << 24) | (this->block_size & 0xFFFFFF));
return 8;
}
int ScsiBlockCmds::get_error_recovery_page(uint8_t ctrl, uint8_t subpage,
uint8_t *out_ptr, int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 6;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size);
return page_size;
}
uint32_t ScsiBlockCmds::get_lba() {
int cmd_len = this->get_cdb_length(this->cdb_ptr[0]);
switch(cmd_len) {
case 6:
return ((this->cdb_ptr[1] & 0x1F) << 16) | READ_WORD_BE_A(&this->cdb_ptr[2]);
case 10:
case 12:
return READ_DWORD_BE_U(&this->cdb_ptr[2]);
default:
ABORT_F("unsupported command length %d in get_lba", cmd_len);
}
}
+63
View File
@@ -0,0 +1,63 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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 SCSI_BLOCK_COMMANDS_H
#define SCSI_BLOCK_COMMANDS_H
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsicommoncmds.h>
#include <devices/storage/blockstoragedevice.h>
#include <cinttypes>
/** Base class for SCSI block device commands. */
class ScsiBlockCmds : public ScsiCommonCmds, public BlockStorageDevice {
public:
ScsiBlockCmds(int cache_blocks = 256);
~ScsiBlockCmds() = default;
void init_block_device(uint8_t medium_type, uint8_t dev_flags);
virtual int read_new();
virtual int write_new();
virtual int start_stop_unit();
virtual int read_capacity();
void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) override {
medium_type = this->medium_type;
dev_flags = this->device_flags;
}
int format_block_descriptors(uint8_t* out_ptr) override;
int get_error_recovery_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len);
protected:
virtual void process_command() override;
uint32_t get_lba();
uint8_t medium_type = 0;
uint8_t device_flags = 0;
};
#endif // SCSI_BLOCK_COMMANDS_H
+8 -20
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -49,7 +49,7 @@ ScsiBus::ScsiBus(const std::string name)
this->target_id = -1;
}
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
void ScsiBus::register_device(int id, ScsiPhysDevice* dev_obj)
{
if (this->devices[id] != nullptr) {
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
@@ -66,7 +66,7 @@ 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);
}
}
}
@@ -242,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);
}
}
@@ -298,18 +298,6 @@ void ScsiBus::target_next_step()
}
}
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
{
if (target_id < 0) {
LOG_F(ERROR, "%s: target_id is not set yet.", this->get_name().c_str());
}
else {
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
}
return true;
}
void ScsiBus::disconnect(int dev_id)
{
this->release_ctrl_lines(dev_id);
@@ -377,11 +365,11 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
}
static const DeviceDescription ScsiCurio_Descriptor = {
ScsiBus::create_ScsiCurio, {}, {}
ScsiBus::create_ScsiCurio, {}, {}, HWCompType::SCSI_BUS
};
static const DeviceDescription ScsiMesh_Descriptor = {
ScsiBus::create_ScsiMesh, {}, {}
ScsiBus::create_ScsiMesh, {}, {}, HWCompType::SCSI_BUS
};
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
+16 -13
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -95,8 +95,10 @@ void ScsiBusController::sequencer() {
if (this->fifo_pos) {
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
if (this->to_xfer <= 0)
if (this->to_xfer <= 0) {
this->bus_obj->target_next_step();
this->step_completed();
}
}
break;
case SeqState::SEND_CMD:
@@ -111,7 +113,6 @@ void ScsiBusController::sequencer() {
this->cur_state = SeqState::SEND_DATA;
break;
case ScsiPhase::DATA_IN:
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
}
@@ -144,12 +145,14 @@ void ScsiBusController::sequencer() {
break;
case SeqState::RCV_STATUS:
case SeqState::RCV_MESSAGE:
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_MESSAGE)
if (this->cur_state == SeqState::RCV_STATUS) {
this->bus_obj->target_next_step();
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
} else if (this->cur_state == SeqState::RCV_MESSAGE)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
this->bus_obj->target_next_step();
this->step_completed();
this->cur_state = SeqState::IDLE;
}
@@ -160,9 +163,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 +177,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 +189,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);
}
}
+12 -14
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -50,7 +50,7 @@ namespace Scsi_Bus_Controller {
RCV_STATUS,
RCV_MESSAGE,
};
};
}
/** Sequencer error codes. */
enum : int {
@@ -60,9 +60,9 @@ enum : int {
constexpr auto DATA_FIFO_DEPTH = 16;
class ScsiBusController : public ScsiDevice, public DmaDevice {
class ScsiBusController : public ScsiPhysDevice, public DmaDevice {
public:
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiPhysDevice(name, my_bus_id) {
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
}
~ScsiBusController() = default;
@@ -73,17 +73,15 @@ public:
virtual void step_completed() = 0;
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; };
// ScsiPhysDevice methods
void notify(ScsiNotification notif_type, int param) override;
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);
+74 -123
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -32,52 +32,88 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
static char my_vendor_id[] = "SONY ";
static char my_product_id[] = "CD-ROM CDU-8003A";
static char my_revision_id[] = "1.9a";
ScsiCdrom::ScsiCdrom(std::string name, int my_id) :
CdromDrive(), ScsiPhysDevice(name, my_id), ScsiCommonCmds()
{
this->set_phys_dev(this);
this->set_cdb_ptr(this->cmd_buf);
this->set_buf_ptr(this->data_buf);
this->set_error_callback(
[this](uint8_t sense_key, uint8_t asc) {
this->report_error(sense_key, asc);
//his->report_error(sense_key, asc);
this->invalid_cdb(); // HACK! to make CdromDrive::read_toc() work
}
);
this->set_read_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
if (this->remain_size) {
*dsize = this->read_more();
*dptr = (uint8_t *)this->data_cache.get();
return true;
} else
return false;
}
);
this->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
return false;
}
);
// populate device info for INQUIRY
this->dev_type = ScsiDevType::CD_ROM;
this->is_removable = true; // removable medium
this->std_versions = 2; // ISO vers=0, ECMA vers=0, ANSI vers=2 (SCSI-2)
this->resp_fmt = 2; // response data format: SCSI-2
this->cap_flags = CAP_SYNC_XFER; // supports synchronous transfers
this->set_vendor_id(my_vendor_id);
this->set_product_id(my_product_id);
this->set_revision_id(my_revision_id);
}
void ScsiCdrom::process_command()
{
uint32_t lba;
this->pre_xfer_action = nullptr;
this->post_xfer_action = nullptr;
if (this->verify_cdb() < 0) {
this->switch_phase(ScsiPhase::STATUS);
return;
}
// assume successful command execution
this->status = ScsiStatus::GOOD;
phy_impl->set_status(ScsiStatus::GOOD);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
// use internal data buffer by default
this->data_ptr = this->data_buf;
phy_impl->set_buffer(this->data_buf);
uint8_t* cmd = this->cmd_buf;
switch (cmd[0]) {
case ScsiCommand::TEST_UNIT_READY:
this->test_unit_ready();
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
break;
case ScsiCommand::MODE_SELECT_6:
this->mode_select_6(cmd[4]);
break;
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);
break;
case ScsiCommand::READ_CAPACITY_10:
case ScsiCommand::READ_CAPACITY:
this->read_capacity_10();
break;
case ScsiCommand::READ_10:
@@ -90,116 +126,38 @@ void ScsiCdrom::process_command()
// CD-ROM specific commands
case ScsiCommand::READ_TOC:
this->bytes_out = read_toc(cmd, this->data_buf);
phy_impl->set_xfer_len(read_toc(cmd, this->data_buf));
if (this->status == ScsiStatus::GOOD) {
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
break;
default:
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
this->illegal_command(cmd);
ScsiCommonCmds::process_command();
}
}
bool ScsiCdrom::prepare_data()
{
switch (this->cur_phase) {
case ScsiPhase::DATA_IN:
this->data_size = this->bytes_out;
break;
case ScsiPhase::DATA_OUT:
this->data_size = 0;
break;
case ScsiPhase::STATUS:
break;
default:
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
return false;
}
return true;
}
bool ScsiCdrom::get_more_data() {
if (this->data_left()) {
this->data_size = this->read_more();
this->data_ptr = (uint8_t *)this->data_cache.get();
}
return this->data_size != 0;
}
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
{
if (!check_lun())
return;
if (cmd_len == 6 && nblocks == 0)
nblocks = 256;
this->set_fpos(lba);
this->data_ptr = (uint8_t *)this->data_cache.get();
this->bytes_out = this->read_begin(nblocks, UINT32_MAX);
phy_impl->set_buffer((uint8_t *)this->data_cache.get());
phy_impl->set_xfer_len(this->read_begin(nblocks, UINT32_MAX));
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
int ScsiCdrom::test_unit_ready()
{
this->switch_phase(ScsiPhase::STATUS);
return ScsiError::NO_ERROR;
}
int ScsiCdrom::format_block_descriptors(uint8_t* out_ptr) {
uint8_t density_code = 1; // user data only, 2048 bytes per physical sector
void ScsiCdrom::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
WRITE_DWORD_BE_A(&out_ptr[0], (density_code << 24) | (this->size_blocks & 0xFFFFFF));
WRITE_DWORD_BE_A(&out_ptr[4], (this->block_size & 0xFFFFFF));
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());
}
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);
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;
}
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);
//etc.
if (alloc_len < 36) {
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
}
else {
memset(&this->data_buf[36], 0, alloc_len - 36);
}
this->bytes_out = alloc_len;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
return 8;
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
@@ -245,18 +203,17 @@ void ScsiCdrom::mode_sense_6()
this->data_buf[17] = 'p';
break;
default:
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
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;
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(),
page_code);
this->set_field_pointer(2), // error is in the 3rd byte
this->set_bit_pointer(5), // starting with bit 5
this->invalid_cdb();
this->switch_phase(ScsiPhase::STATUS);
return;
}
this->bytes_out = this->data_buf[0];
phy_impl->set_xfer_len(this->data_buf[0]);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
@@ -267,7 +224,7 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
if (!param_len)
return;
this->incoming_size = param_len;
phy_impl->set_xfer_len(param_len);
std::memset(&this->data_buf[0], 0, 512);
@@ -289,25 +246,19 @@ void ScsiCdrom::read_capacity_10()
if (!(this->cmd_buf[8] & 1) && lba) {
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", 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 = 8;
this->set_field_pointer(2),
this->invalid_cdb();
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (!check_lun())
return;
int last_lba = (int)this->size_blocks - 1;
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
WRITE_DWORD_BE_A(&this->data_buf[4], this->block_size);
this->bytes_out = 8;
phy_impl->set_xfer_len(8);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
+16 -13
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
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
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SCSI_CDROM_H
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsicommoncmds.h>
#include <devices/storage/cdromdrive.h>
#include <utils/imgfile.h>
@@ -32,19 +33,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
class ScsiCdrom : public CdromDrive, public ScsiDevice {
class ScsiCdrom : public ScsiPhysDevice, public CdromDrive, public ScsiCommonCmds {
public:
ScsiCdrom(std::string name, int my_id);
~ScsiCdrom() = default;
virtual void process_command() override;
virtual bool prepare_data() override;
virtual bool get_more_data() override;
protected:
int test_unit_ready();
bool is_device_ready() override { return true; }
// temporary implementation that should be elsewhere
void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) override {
medium_type = 1; // 120mm CD-ROM data only
dev_flags = 0;
}
// temporary implementation that should be elsewhere
int format_block_descriptors(uint8_t* out_ptr) override;
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
void inquiry();
void mode_select_6(uint8_t param_len);
void mode_sense_6();
@@ -54,11 +62,6 @@ private:
bool eject_allowed = true;
int bytes_out = 0;
uint8_t data_buf[2048] = {};
//inquiry info
char vendor_info[9] = "SONY ";
char prod_info[17] = "CD-ROM CDU-8003A";
char rev_info[5] = "1.9a";
};
#endif // SCSI_CDROM_H
+447
View File
@@ -0,0 +1,447 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
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/scsi/scsicommoncmds.h>
#include <loguru.hpp>
#include <memaccess.h>
ScsiCommonCmds::ScsiCommonCmds() {
this->enable_cmd(ScsiCommand::TEST_UNIT_READY);
this->enable_cmd(ScsiCommand::REQ_SENSE);
this->enable_cmd(ScsiCommand::INQUIRY);
this->enable_cmd(ScsiCommand::MODE_SENSE_6);
this->enable_cmd(ScsiCommand::MODE_SENSE_10);
}
void ScsiCommonCmds::process_command() {
int next_phase;
switch(this->cdb_ptr[0]) {
case ScsiCommand::TEST_UNIT_READY:
next_phase = this->test_unit_ready();
break;
case ScsiCommand::REQ_SENSE:
next_phase = this->request_sense_new();
break;
case ScsiCommand::INQUIRY:
next_phase = this->inquiry_new();
break;
case ScsiCommand::MODE_SENSE_6:
case ScsiCommand::MODE_SENSE_10:
next_phase = this->mode_sense();
break;
default:
LOG_F(ERROR, "no support for command 0x%X", this->cdb_ptr[0]);
this->invalid_command();
next_phase = ScsiPhase::STATUS;
}
phy_impl->switch_phase(next_phase);
}
// maps command group number to CDB length (SCSI-2 standard §7.2.1)
static const int CmdGroupLen[8] = {6, 10, 10, CMD_GRP_RESERVED, CMD_GRP_RESERVED, 12,
CMD_GRP_VENDOR_SPECIFIC, CMD_GRP_VENDOR_SPECIFIC};
int ScsiCommonCmds::get_cdb_length(uint8_t op_code) {
return CmdGroupLen[op_code >> 5];
}
int ScsiCommonCmds::verify_cdb() {
if (phy_impl->get_phy_id() == PHY_ID_ATAPI)
return 0; // don't try to verify ATAPI packets
int cdb_len = this->get_cdb_length(this->cdb_ptr[0]);
if (cdb_len < 0)
return 0; // don't know how to verify non-standard CDBs
// check the LUN field except for INQUIRY and REQ_SENSE
if ((this->cdb_ptr[0] != ScsiCommand::INQUIRY) &&
(this->cdb_ptr[0] != ScsiCommand::REQ_SENSE))
{
if (phy_impl->last_sel_has_attention() &&
(phy_impl->last_sel_msg() & ScsiMessage::IDENTIFY))
{
uint8_t lun = phy_impl->last_sel_msg() & 7;
if (!this->lun_supported(lun)) {
LOG_F(ERROR, "unsupported LUN 0x%X", lun);
this->invalid_lun();
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
return -1;
}
} else if (this->cdb_ptr[1] >> 5)
LOG_F(WARNING, "non-zero LUN 0x%X in CDB", this->cdb_ptr[1] >> 5);
}
// check the control field
uint8_t ctrl_byte = this->cdb_ptr[cdb_len - 1];
if (ctrl_byte & 3) {
if (this->linked_cmds_supported())
this->link_ctrl = ctrl_byte;
else {
LOG_F(ERROR, "flag/link bit set in CDB control: 0x%X", ctrl_byte);
this->invalid_cdb();
return -1;
}
}
return 0;
}
int ScsiCommonCmds::test_unit_ready() {
// Assume that LUN is okay and the status has been set to GOOD
if (!phy_impl->is_device_ready()) {
this->sense_key = ScsiSense::NOT_READY;
this->asc = phy_impl->not_ready_reason();
this->ascq = 0;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
return ScsiPhase::STATUS;
}
int ScsiCommonCmds::inquiry_new() {
int alloc_len = this->get_xfer_len();
int resp_len = 36; // standard response length
// go directly to the STATUS phase if alloc_len = 0
if (!alloc_len) {
LOG_F(WARNING, "INQUIRY: skip data transfer because alloc_len = 0");
return ScsiPhase::STATUS;
}
if (phy_impl->get_phy_id() == PHY_ID_SCSI) {
bool is_invalid = false;
if (this->cdb_ptr[1] & 1) {
LOG_F(ERROR, "INQUIRY: EVPD=1 not supported");
this->set_field_pointer(1);
this->set_bit_pointer(0);
is_invalid = true;
}
if (this->cdb_ptr[2]) {
LOG_F(ERROR, "INQUIRY: non-zero page code not supported");
this->set_field_pointer(2);
is_invalid = true;
}
if (is_invalid) {
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
std::memset(this->buf_ptr, 0, resp_len);
uint8_t lun = this->get_lun();
if (lun) {
// tell the host there is no device for this LUN
this->buf_ptr[0] = (3 << 5) | ScsiDevType::UNKNOWN;
LOG_F(WARNING, "INQUIRY: no device for LUN %d", lun);
} else {
this->buf_ptr[0] = this->dev_type;
this->buf_ptr[1] = ((this->is_removable) ? 0x80 : 0) | this->dev_type_mod;
this->buf_ptr[2] = this->std_versions;
this->buf_ptr[3] = this->resp_fmt;
this->buf_ptr[4] = 31; // additional length (n-5)
this->buf_ptr[7] = this->cap_flags;
std::memcpy(&this->buf_ptr[ 8], vendor_id, sizeof(this->vendor_id));
std::memcpy(&this->buf_ptr[16], product_id, sizeof(this->product_id));
std::memcpy(&this->buf_ptr[32], revision_id, sizeof(this->revision_id));
}
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
int ScsiCommonCmds::request_sense_new() {
int alloc_len = this->get_xfer_len();
int resp_len = 18; // standard response length
// go directly to the STATUS phase if alloc_len = 0
if (!alloc_len) {
LOG_F(WARNING, "REQ_SENSE: skip data transfer because alloc_len = 0");
return ScsiPhase::STATUS;
}
std::memset(this->buf_ptr, 0, resp_len);
this->buf_ptr[0] = 0x80 | 0x70; // valid bit + current errors
this->buf_ptr[7] = 10; // additional sense length
uint8_t lun = this->get_lun();
if (lun) // unsupported LUN
this->invalid_lun();
this->buf_ptr[ 2] = this->sense_key;
this->buf_ptr[12] = this->asc;
this->buf_ptr[13] = this->ascq;
if (this->sense_key == ScsiSense::ILLEGAL_REQ && this->field_ptr_valid) {
this->buf_ptr[15] = this->is_cdb_err ? 0xC0 : 0x80;
WRITE_WORD_BE_A(&this->buf_ptr[16], this->field_ptr);
if (this->bit_ptr_valid)
this->buf_ptr[15] |= (this->bit_ptr & 7) | 8;
}
this->reset_sense(); // clear last sense information
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
const char* Page_Control_Modes[4] = {
"CURRENT_VALUES",
"CHANGEABLE_VALUES",
"DEFAULT_VALUES",
"SAVED_VALUES"
};
int ScsiCommonCmds::mode_sense() {
uint8_t page_ctrl = this->cdb_ptr[2] >> 6;
if (page_ctrl == PageControl::SAVED_VALUES && !this->supports_params_saving()) {
LOG_F(ERROR, "MODE_SENSE: Page control mode (%s) not supported",
Page_Control_Modes[page_ctrl]);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(7), // starting with bit 7
this->illegal_request(ScsiError::SAVING_NOT_SUPPORTED, 0);
return ScsiPhase::STATUS;
}
uint8_t page_code = this->cdb_ptr[2] & 0x3F;
uint8_t subpage_code = this->cdb_ptr[3];
// MODE_SENSE_10 returns a bigger response
bool is_long_resp = this->cdb_ptr[0] == ScsiCommand::MODE_SENSE_10;
int alloc_len = this->get_xfer_len();
int resp_len = 0;
int resp_max_len = is_long_resp ? 65536 : 256;
uint8_t* out_ptr = this->buf_ptr;
uint8_t medium_type, dev_flags;
this->get_medium_type(medium_type, dev_flags);
// format response header
if (is_long_resp) { // MODE_SENSE_10
WRITE_WORD_BE_A(out_ptr, 0); // zero data_length -> to be adjusted later
out_ptr[2] = medium_type;
out_ptr[3] = dev_flags;
resp_len = 8; // initial response length
out_ptr += 8; // move data pointer past block descriptor length
WRITE_WORD_BE_A(&out_ptr[-2], 0); // zero block descriptor length
} else {
out_ptr[0] = 0; // zero data_length -> to be adjusted later
out_ptr[1] = medium_type;
out_ptr[2] = dev_flags;
resp_len = 4; // initial response length
out_ptr += 4; // move data pointer past block descriptor length
out_ptr[-1] = 0; // zero block descriptor length
}
// return block descriptor(s) unless
// it's ATAPI that doesn't use block descriptors
// block descriptors are disabled by the DBD bit
if (phy_impl->get_phy_id() == PHY_ID_SCSI) {
if (!(this->cdb_ptr[1] & 8)) { // if DBD=0
int desc_len = this->format_block_descriptors(out_ptr);
if (is_long_resp)
WRITE_WORD_BE_A(&out_ptr[-2], desc_len);
else
out_ptr[-1] = desc_len;
out_ptr += desc_len;
resp_len += desc_len;
} else
LOG_F(WARNING, "MODE_SENSE: block descriptor(s) disabled");
}
// return all pages if requested
if (page_code == ModePage::ALL_PAGES) {
for (const auto& [page_num, formatter] : this->getters) {
if (!page_num)
continue; // skip vendor specific page 0 - shall be returned last
int page_len = this->get_one_page(page_ctrl, page_num, 0,
out_ptr, resp_max_len - resp_len);
if (page_len < 0)
return ScsiPhase::STATUS;
out_ptr += page_len;
resp_len += page_len;
}
if (this->getters.count(0))
page_code = 0; // page 0 exists -> let the following code return it last
}
// return one page
if (page_code != ModePage::ALL_PAGES) {
if (this->getters.count(page_code)) {
int page_len = this->get_one_page(page_ctrl, page_code, subpage_code,
out_ptr, resp_max_len - resp_len);
if (page_len < 0)
return ScsiPhase::STATUS;
resp_len += page_len;
} else {
LOG_F(ERROR, "MODE_SENSE: page 0x%X not supported", page_code);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(5), // starting with bit 5
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// stuff final response into response header
if (is_long_resp)
WRITE_WORD_BE_A(&this->buf_ptr[0], resp_len - 2);
else
this->buf_ptr[0] = resp_len - 1;
phy_impl->set_xfer_len(std::min(alloc_len, resp_len));
return ScsiPhase::DATA_IN;
}
int ScsiCommonCmds::get_one_page(uint8_t ctrl, uint8_t page, uint8_t subpage,
uint8_t* out_ptr, int avail_len)
{
int len, err;
try_again:
len = this->getters[page](ctrl, subpage, &out_ptr[2], avail_len - 2);
if (len < 0) {
err = len;
if (err == FORMAT_ERR_DATA_TOO_BIG) {
ABORT_F("Internal buffer too small!");
// increase buffer size
// goto try_again;
} else if (err == FORMAT_ERR_BAD_CONTROL) {
LOG_F(ERROR, "MODE_SENSE: Page control (%s) not supported for page 0x%X",
Page_Control_Modes[ctrl], page);
this->set_field_pointer(2), // error in the 3rd byte
this->set_bit_pointer(7); // starting with bit 7
} else if (err == FORMAT_ERR_BAD_SUBPAGE) {
LOG_F(ERROR, "MODE_SENSE: unsupported subpage 0x%X for page 0x%X",
subpage, page);
this->set_field_pointer(3); // error in the 4th byte
} else
ABORT_F("MODE_SENSE: unknown getter error %d", err);
this->invalid_cdb();
return err;
}
out_ptr[0] = page;
out_ptr[1] = len;
return len + 2;
}
uint8_t ScsiCommonCmds::get_lun() {
if (phy_impl->get_phy_id() == PHY_ID_ATAPI)
return 0; // ATAPI doesn't support SCSI LUNs so bail out early
if (phy_impl->last_sel_has_attention() &&
(phy_impl->last_sel_msg() & ScsiMessage::IDENTIFY))
return phy_impl->last_sel_msg() & 7;
else
return this->cdb_ptr[1] >> 5;
}
uint32_t ScsiCommonCmds::get_xfer_len() {
int cmd_len = this->get_cdb_length(this->cdb_ptr[0]);
switch(cmd_len) {
case 6:
return this->cdb_ptr[4];
case 10:
return READ_WORD_BE_U(&this->cdb_ptr[7]);
case 12:
return READ_DWORD_BE_U(&this->cdb_ptr[6]);
default:
ABORT_F("unsupported command length %d in get_xfer_len", cmd_len);
}
}
void ScsiCommonCmds::reset_sense() {
this->sense_key = ScsiSense::NO_SENSE;
this->asc = ScsiError::NO_ERROR;
this->ascq = 0;
this->field_ptr_valid = false;
this->bit_ptr_valid = false;
}
void ScsiCommonCmds::invalid_lun() {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_LUN;
this->ascq = 0;
this->is_cdb_err = true;
this->field_ptr_valid = true;
this->field_ptr = 1; // error in the 2nd byte
this->bit_ptr_valid = true;
this->bit_ptr = 7; // MSB number of the invalid bitfield
}
void ScsiCommonCmds::invalid_cdb() {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->is_cdb_err = true;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
void ScsiCommonCmds::invalid_command() {
LOG_F(ERROR, "unsupported command: 0x%02x", this->cdb_ptr[0]);
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CMD;
this->ascq = 0;
this->is_cdb_err = true;
this->field_ptr_valid = true;
this->field_ptr = 0; // error in the 1st byte
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
void ScsiCommonCmds::illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb) {
this->sense_key = ScsiSense::ILLEGAL_REQ;
this->asc = asc;
this->ascq = ascq;
this->is_cdb_err = is_cdb;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
}
Loaded 100 of 219 files, more files were not shown because too many files have changed in this diff. Show more