Compare commits

..
132 Commits
Author SHA1 Message Date
dingusdev f660efcd54 Continued FPU fixes 2024-10-30 07:46:44 -07:00
dingusdev 5f826d6a9d More floating point fixes
Down to 752 failing tests
2024-10-27 12:51:16 -07:00
dingusdev 873f8632e4 More floating point fixes
Confirmed to partially fix Mac OS X installation screen errors
2024-10-26 16:16:52 -07:00
dingusdev af7c22e7b3 Compile fixes, pt. 2 2024-10-17 19:50:15 -07:00
dingusdev 28ec650e4f Compile fixes 2024-10-17 19:41:58 -07:00
dingusdev 329bcc68b1 Floating-point fix-ups
Largely to fix setting flags, but partially to fix the incorrect nan emulation
2024-10-17 08:00:27 -07:00
Maxim Poliakovski b3eb1f6419 machineyosemite: register stock hard drive. 2024-10-09 14:50:44 +02:00
Maxim Poliakovski 2132922c7b machineyosemite: attach CMD646 Ultra ATA controller. 2024-10-09 14:49:59 +02:00
Maxim Poliakovski 9915c15086 Initial CMD646U2 Ultra ATA controller emulation. 2024-10-09 14:49:09 +02:00
Keith Kaisershot 6df1c7dd9d Update documentation 2024-10-06 23:46:19 -07:00
Keith Kaisershot ec9987aab6 machinepippin: replace Mouse with AppleJack
Leave a keyboard attached for compatibility.
2024-10-06 23:45:27 -07:00
Keith Kaisershot 34e0ba84f1 Add AppleJack controller support, based on AdbMouse
All AppleJack controllers start in mouse emulation mode, behaving exactly like
ADB mice. Only upon receiving a Listen command on register 3 with handler ID
0x46 does the AppleJack switch protocols, albeit such a change consisting merely
of expanding register 0's buffer size to 4 bytes. In this state, the first 2
bytes remain defined as they are for an ADB mouse; the additional 16 bits carry
the respective states of each of the AppleJack controller's remaining 11 buttons
out of a possible supported 16.

For backward compatibility, honor both mouse clicks and shoulder button presses
on the host when considering the state of the emulated trigger buttons.
2024-10-06 23:43:50 -07:00
Keith Kaisershot d23f21b391 sdl: handle gamepad events
Add new GamepadButton enum with bits corresponding to AppleJack button bits.
Both the AppleJack controller and the SDL GameController coincidentally define
one d-pad, two shoulder buttons, four face buttons, and three system buttons.
This makes mapping modern game controllers to the AppleJack straightforward.
2024-10-06 23:28:05 -07:00
Keith Kaisershot 6696248158 adbbus: decouple ADB devices from CUDA
AdbMouse and AdbKeyboard are subdevices of the CUDA device alongside AdbBus.
This doesn't make sense because conceptually, ADB devices hang off of the ADB
bus, not CUDA itself. An ADB bus can exist without a CUDA present, for example
Egret on older 68K Macs and the PMU on newer Power Macs. Therefore, make the ADB
device list a subhierarchy of AdbBus instead. Add a new "adb_devices" property
belonging to AdbBus that can allow users to specify ADB devices on the command
line at machine creation time, independent of the emulated bus's host. Make this
property default to "Mouse,Keyboard" to preserve existing behavior.
2024-10-06 23:20:10 -07:00
dingusdev 02c8c8cde0 Fix bench + test compilation (again) 2024-09-30 20:35:33 -07:00
Maxim Poliakovski 64a5a17df0 heathrow: fix interrupt masking.
Use int_mask1/int_mask2 directly without changing int_events1/int_events2.
That permits interrupt generation on int_mask1/int_mask2 changes.
2024-09-28 23:17:14 +02:00
Maxim Poliakovski a649a688e7 grandcentral: fix interrupt masking.
Use int_mask directly without changing int_events.
That permits interrupt generation on int_mask changes.
2024-09-28 23:17:14 +02:00
dingusdev 8c42685e26 Slight compile fix 2024-09-24 21:17:48 -07:00
dingusdev 01ceaef8d7 Slightly delaying a race condition 2024-09-24 21:10:10 -07:00
joevt 55d7c8f09d bench1 fix 2 2024-09-24 21:07:51 -07:00
joevt 1f59eceacf bench1 fix 2024-09-24 21:07:42 -07:00
joevt e14ede2510 bench1: Add benchmark for ppc_exec. 2024-09-24 21:07:35 -07:00
joevt bc05593dd2 bench1: Changes to reduce variability.
Chooses the best time out of 200 times for each of the 5 runs. The number of bytes is 32KB.
Outputs a performance number MiB/s.
2024-09-24 20:45:14 -07:00
joevt 4a71dbe7bb bench1: Fixes and changes.
Change test size from 32KB to 8MB. The benchmark should last about 1 second.
Set power_on to true before running any ppc_exec_* functions.
2024-09-16 18:13:53 -07:00
dingusdev aed250a64d Taking benchmark fixes from the nuterpreter2 branch 2024-09-16 06:22:58 -07:00
dingusdev e2ad753f4a More clean-up 2024-09-15 18:31:36 -07:00
dingusdev 2ab23546ea One-line fix-up 2024-09-08 15:22:04 -07:00
dingusdev 9d9e826bb3 More code clean-up 2024-09-08 13:19:07 -07:00
joevt 3c2887f8c3 floppyimg: Add null floppy image converter check. 2024-09-03 06:19:07 -07:00
Rairii 8cc67b09c2 ppcmmu: Different expressions. 2024-09-03 06:09:45 -07:00
joevt bb3e89e3af ppcexceptions: Remove unused label. 2024-09-03 06:09:10 -07:00
joevt 172dab7431 Update Open Firmware documentation.
Add New World ROM Layout notes.
Add New World Firmware version notes.
Add punctation.
Move mention of OF main fcode image from the Open Firmware kernel description section to the boot process section.
2024-09-02 19:16:18 -07:00
joevt 78da2457e8 ppcexec: Simplify next event time calculation. 2024-09-02 19:00:33 -07:00
joevt 7e70432495 ppcexec: Remove unused g_icycles_base. 2024-09-02 18:58:07 -07:00
joevt c6060ad812 timermanager: Use decimal ints, not floats or hex. 2024-08-31 18:09:15 -07:00
joevt f09710a5f7 viacuda: Do shutdown.
Shutdown will enter the debugger or quit depending on the execution mode.
Quit is different from shutdown since it is triggered outside the guest by using the host Quit menu item.
2024-08-31 18:09:12 -07:00
Maxim Poliakovski de727db4c6 machineyosemite: use PCI slot names that better match device tree properties. 2024-08-29 13:19:00 +02:00
Maxim Poliakovski 671cd0c5da machineyosemite: set PCI IRQ maps. 2024-08-29 00:16:59 +02:00
Maxim Poliakovski ef62e8b965 New API for registering PCI interrupts. 2024-08-29 00:16:59 +02:00
dingusdev 8c44da655c Documentation additions 2024-08-26 06:48:55 -07:00
dingusdev b5850f1cd2 Slight clean-up to ppcexec 2024-08-26 06:48:40 -07:00
dingusdev 0a61970b29 Merge pull request #116 from mihaip/upstream-log
main: add more control over logging
2024-08-25 17:15:39 -07:00
Mihai Parparita 91a8e83f21 main: add more control over logging
Allow the verbosity to be adjusted.

Allow logging to be sent to stderr even when running in interpreter mode.

Allow uptime (time since program start) to be disabled. This makes it
easier to compare logs across successive runs.
2024-08-25 17:05:46 -07:00
Maxim Poliakovski 825314c869 atahd: clean up READ_MULTIPLE/WRITE_MULTIPLE. 2024-08-26 00:20:53 +02:00
dingusdev 8d9bc66a82 Merge pull request #115 from mihaip/upstream-multiple
Fixes for READ_MULTIPLE and WRITE_MULTIPLE commands
2024-08-25 06:38:15 -07:00
Mihai Parparita 52f4d847dd Fixes for READ_MULTIPLE and WRITE_MULTIPLE commands
We may be transferring less data than can fit in a chunk, so we need
to ensure that xfer_cnt is clamped to 0 when transferring the last
chunk (otherwise it remains negative, and has_data() will return true).

It's also possible that the transfer size is bigger than a chunk but not
an even multiple of the chunk size, so we need to ensure that we don't
try to transfer a whole chunk in the last iteration.

More correctly initialize the device identification struct, to report
the maximum (word 47) and current (word 59) number of blocks that can be
transferred with READ_MULTIPLE and WRITE_MULTIPLE commands.

Fix post_xfer_action to write the actual data size that was written,
as opposed to an entire chunk (which may be larger).
2024-08-24 22:51:07 -07:00
dingusdev ebf4b0e969 minor ATA tweaks
From @Wack0's branch
2024-08-24 12:58:19 -07:00
Maxim Poliakovski 47237ff87b Merge pull request #114 from mihaip/upstream-atahd-fix
Fix ATA HD initialization on Beige G3 when booting 9.2
2024-08-23 12:59:51 +02:00
Mihai Parparita 8d95aa5ed3 Fix ATA HD initialization on Beige G3 when booting 9.2
1f2256ec81a/7ee8b9b2 were referencing a multiple_sector_count field,
but it was never set. This was resulting in an error being returned
(`READ MULTIPLE with SET MULTIPLE==0`).` We actually should use
`sec_per_block``, which bd16b7c69e introduced.
2024-08-22 22:38:48 -07:00
dingusdev 7ee8b9b2f0 Add missing variable 2024-08-22 20:49:11 -07:00
dingusdevandRairii 1f2256ec81 Additional ATA commands
Mostly from Wack0's NT4 fork.

Co-Authored-By: Rairii <[email protected]>
2024-08-22 20:42:43 -07:00
Maxim Poliakovski 0518f2ae2f atahd: fix DIAGNOSTICS command. 2024-08-21 23:12:53 +02:00
Maxim Poliakovski 3bf088f2c8 atahd: fix RECALIBRATE command.
Although being optional in ATA-3 and absent in >= ATA-4,
RECALIBRATE is issued by Open Firmware 3.1.1 during device
initialization. If it fails, the drive is considered non-bootable.
2024-08-21 21:21:44 +02:00
Maxim Poliakovski bd16b7c69e atahd: implement mandatory SET_MULTIPLE_MODE command. 2024-08-21 21:21:44 +02:00
Maxim Poliakovski f5c91968a2 idechannel: split MacIO specific stuff into a separate class.
Now we got two classes: IdeChannel and MacioIdeChannel.
The former models a generic IDE channel so it can be used elsewhere.
The latter implements MacIO specific configuration register(s)
and interrupt signaling.
2024-08-20 16:55:31 +02:00
Maxim Poliakovski 4e78ac33c5 atabasedevice: disable device interrupts on reset. 2024-08-20 15:36:12 +02:00
Maxim Poliakovski e1acf5d160 Rename ppc_effective_address to ea. 2024-08-19 21:11:22 +02:00
dingusdev 047515d813 Merge pull request #112 from mihaip/upstream-ppc_effective_address
ppc: make ppc_effective_address into a local
2024-08-19 06:21:31 -07:00
Mihai Parparita bdbeb742d4 ppc: remove two unused global variables
Last use of grab_return was removed in f204caa907.
grab_breakpoint was added in 2bd717e293 but
never used.
2024-08-18 22:46:52 -07:00
Mihai Parparita e7d8e71297 ppc: make ppc_effective_address into a local
There's no reason for it to be a global, we always set it and use it
in instruction implementations, and we never read it directly.

Perhaps the compiler could optimize this away, but it's better to be
simpler (and also be easier to read).
2024-08-18 22:38:50 -07:00
Maxim Poliakovski a34e0a4737 PCI-to-PCI bridges now return true in supports_io_space().
Doing so ensures that accesses to the I/O space are broadcasted
to the PCI-to-PCI bridges automatically.
2024-08-17 01:01:53 +02:00
Maxim Poliakovski 2c026259b1 pcibridge: improve formatting. 2024-08-17 01:01:53 +02:00
Maxim Poliakovski cd36df5500 pcibridge: fix a bug in pci_io_write() caused by copy-and-paste coding. 2024-08-17 01:01:53 +02:00
Maxim Poliakovski 5ea7b8c5f8 Merge pull request #111 from mihaip/upstream-alignment
atapibasedevice: fix unaligned memory access
2024-08-16 12:56:08 +02:00
Mihai Parparita 372b9cae7a atapibasedevice: fix unaligned memory access
Both cmd_pkt and data_buf class members are cast to a uint16_t pointer,
so we need to make sure they are properly aligned, otherwise it is
undefined behavior.
2024-08-15 22:32:46 -07:00
Maxim Poliakovski 595478ed6f hwcomponent: add IDE_HOST component type. 2024-08-12 14:03:05 +02:00
dingusdev a2776ddae1 Documentation update - Aug. 11, 2024 2024-08-11 17:48:55 -07:00
Maxim Poliakovski f9338b8dd9 pcihost: broadcast I/O requests to PCI-to-PCI bridges. 2024-08-11 15:51:06 +02:00
dingusdev dee7090071 More documentation work 2024-08-07 22:38:35 -07:00
dingusdev 2a8e5538b2 Partially addressing Issue #109
It'll be better to use a keycode file in the future. This will hopefully do for now.
2024-08-04 15:02:48 -07:00
Maxim Poliakovski 20b2fb1bef viacuda: refactor emulation of the VIA registers.
Take the DDRA and DDRB registers into account as well because
there is software that tries to change state of the pins configured
as inputs.
This commit fixes Cuda for Rhapsody.
2024-08-04 21:43:06 +02:00
Maxim Poliakovski f096eef66d viacuda.h: cosmetic improvements. 2024-08-04 21:43:06 +02:00
Maxim Poliakovski 899000b647 Merge pull request #108 from mihaip/upstream-mmu-skip-mode1
ppcmmu: skip over mode 1 entries when doing PAT flushes
2024-08-01 12:09:35 +02:00
Mihai Parparita 76824fb602 ppcmmu: skip over mode 1 entries when doing PAT flushes
Mode 1 contains real addressing mode entries, which by definition cannot
be using segment registers. By skipping over them, we can shave off a
couple of seconds from the 10.2 boot time.
2024-07-31 23:08:36 -07:00
dingusdev 02af6da599 Merge pull request #106 from roytam1/pr-sdl-redraw
sdl: handle SDL_WINDOWEVENT_EXPOSED event to fix redrawing issue
2024-07-29 18:44:25 -07:00
roytam1 83afae5625 sdl: handle SDL_WINDOWEVENT_EXPOSED event to fix redrawing issue 2024-07-29 23:27:05 +08:00
dingusdev e5510dd9ae Merge pull request #105 from Wack0/fix-mouse-upstream
adbmouse: only send first two bytes in standard/classic protocol as per spec
2024-07-29 06:25:52 -07:00
Rairii 4d7c520f18 adbmouse: only send first two bytes in standard/classic protocol as per spec
Fixes any mouse driver that only supports the classic protocol and expects register 0 reads to return two bytes.
2024-07-29 11:37:54 +01:00
dingusdev 6f62f9dd98 Merge pull request #104 from mihaip/upstream-mmu-perf
ppcopcodes: avoid TLB flushes for noop SR changes
2024-07-28 14:06:18 -07:00
Mihai Parparita 31d7b056af ppcopcodes: avoid TLB flushes for noop SR changes
They happen surprisingly often, and flushing the TLB is expensive
because we need to walk over all entries.

Takes booting 10.2 on a Beige G3 from binary start to "Welcome to Macintosh"
from 58s to 38s on my machine.
2024-07-28 13:28:05 -07:00
Mihai Parparita 9b49603c72 memctrl: keep address_map sorted by address
We do a linear scan in find_range (which is called on all TLB misses) to
find the entries. The largest and most frequently hit entry is the
system memory (which starts at 0). By ensuring that it's the first entry
in the list, we end up only doing one iteration through the loop.
2024-07-28 13:27:48 -07:00
dingusdev f192d11758 Merge pull request #102 from mihaip/upstream-dev_id
atabasedevice: Set dev_id.
2024-07-27 14:40:16 -07:00
dingusdev ae08c083ea Merge pull request #103 from mihaip/upstream-fb_known_to_be_changed
Pass through draw_fb optimization metadata to Display class
2024-07-27 14:04:41 -07:00
Mihai Parparita dab9334c3a Pass through draw_fb optimization metadata to Display class
The JS implementation does content hashing to not blit unchanged
framebuffer contents (see mihaip/dingusppc@171ff2d407).
However, that is not necessary for the ATI adapters that already track
this and only set draw_fb if the framebuffer has actually changed.

Pass through a fb_known_to_be_changed for these cases, and also add an
optional update_skipped method (since the JS still wants to know when
the last logical screen update was).
2024-07-27 11:38:59 -07:00
joevtandRairii 7fdfd6109f atabasedevice: Set dev_id.
Extracted from @Wack0's Wack0/dingusppc-nt@529991bd78

Co-authored-by: Rairii <[email protected]>
2024-07-27 09:10:28 -07:00
dingusdev 7d6e87a0d3 Add stub for setting power messages 2024-07-26 07:31:31 -07:00
dingusdev a20ebade09 Add more things to gitignore 2024-07-26 07:31:06 -07:00
Maxim Poliakovski 8d6f77ea71 mesh: implement EnaParityCheck and DisParityCheck commands. 2024-07-25 22:18:43 +02:00
Maxim Poliakovski 19ecc4f945 mesh: fix writes to BusStatus0 & BusStatus1 registers. 2024-07-24 17:50:02 +02:00
dingusdev ebc618adea Merge pull request #100 from mihaip/upstream-uint64_t
Switch ImgFile to using uint64_t explicitly
2024-07-22 22:12:09 -07:00
Mihai Parparita 38669fd83b Switch ImgFile to using uint64_t explicitly
size_t and off_t are 32-bit values in Emscripten, which causes issues
with disk images larger than 4GB. Use the explicit type (which is more
consistent with the rest of the codebase anyway).
2024-07-22 21:48:57 -07:00
Maxim Poliakovski 211f8adc0e Improve MACE stub. 2024-07-23 01:39:15 +02:00
Maxim Poliakovski bda85a66df machinetnt: populate RAM banks from properties. 2024-07-22 17:45:48 +02:00
Maxim Poliakovski babd8d974f dbdma: fix cmd.resCount update. 2024-07-22 17:45:48 +02:00
Maxim Poliakovski 9fc5bbb951 sc53c94: fix interrupt status for CMD_MSG_ACCEPTED. 2024-07-19 03:38:55 +02:00
Maxim Poliakovski 3fe6e3c09e grandcentral: more elegant MeshStub with less checks. 2024-07-19 01:31:36 +02:00
Maxim Poliakovski 289a14dc7a scsidevice: release REQ before MESSAGE_IN phase. 2024-07-15 07:15:49 +02:00
Maxim Poliakovski ba9fcd100d mesh: extend stub to a full implementation. 2024-07-15 03:34:43 +02:00
Maxim Poliakovski 889dc32a0a New base class for SCSI host controllers. 2024-07-15 03:28:45 +02:00
Maxim Poliakovski f13f4e0023 grandcentral: break long lines. 2024-07-15 02:56:24 +02:00
Maxim Poliakovski 4a425c4ecf dbdma: introduce new DMA API. 2024-07-15 02:09:15 +02:00
Maxim Poliakovski 293e869acb dbdma: break long lines. 2024-07-15 02:09:15 +02:00
Maxim Poliakovski f3d7cd9dd7 cdromdrive: add support for raw CD images. 2024-07-15 01:48:46 +02:00
Maxim Poliakovski fd5498e16b blockstoragedevice: add support for raw images.
Raw images contain supplementary information like synchronization fields,
correction codes etc. that needs to be ignored/discarded when
reading/writing user data.
This commit establish a basic architecture for exchanging user data
between a virtual device and a raw image.
2024-07-15 01:48:46 +02:00
Maxim Poliakovski 55f91c5d3f scsicdrom: use READ_TOC implementation from cdromdrive.cpp 2024-07-15 01:28:42 +02:00
Maxim Poliakovski 0831182e39 scsihd: remove duplicated code. 2024-07-14 23:33:43 +02:00
Maxim Poliakovski 26153ca8ea scsihd: use ScsiError contants wherever applicable. 2024-07-14 23:12:53 +02:00
Maxim Poliakovski 7855770ca7 Use ScsiError constants instead of magic numbers. 2024-07-14 17:22:31 +02:00
Maxim Poliakovski a81156c3e3 cdromdrive: convert MSF values to BCD. 2024-07-11 21:27:38 +02:00
dingusdev f31c71e430 Merge pull request #99 from dyharlan/master
Do not test for equality when checking if ctrl is pressed.
2024-07-10 20:03:34 -07:00
dyharlan 7ba7bff3d5 Do not test for equality when checking if ctrl is pressed.
The initial change I committed worked fine before.
2024-07-11 10:38:57 +08:00
Maxim Poliakovski 11bb10b44b Taos: cleanup GPIO pins. 2024-07-11 02:44:40 +02:00
Maxim Poliakovski 378965cc3d Taos: properly handle color mode changes. 2024-07-11 02:44:40 +02:00
dingusdev 40b537767d Update hostevents_sdl.cpp
A further fix by dyharlan to fix the mouse grabbing
2024-07-10 07:51:23 -07:00
dingusdev e2e78c0682 Merge pull request #98 from dyharlan/master
Fix keyboard event bug where mouse grab combination won't work if SDL_GetModState
2024-07-10 07:04:53 -07:00
dyharlan 0267fc82c9 fix indent of change 2024-07-10 19:03:37 +08:00
dyharlan c4022f466f Fix modstate bug preventing mousegrab 2024-07-10 18:54:05 +08:00
dingusdev 17cdcc5560 Fixes issue #97 2024-06-30 06:53:44 -07:00
Maxim Poliakovski 5eaff7a8ce MPC106: break long lines. 2024-06-28 19:52:22 +02:00
Maxim Poliakovski 9d44ac0901 mpc106: fix includes. 2024-06-25 16:53:52 +02:00
dingusdev 606c9dd9a8 More compiler warning fixes 2024-06-24 19:40:20 -07:00
dingusdev ec7907ed71 Update CREDITS.md 2024-06-24 19:33:06 -07:00
dingusdev d1e20a72e3 Merge pull request #96 from kth5/kth5-gcc-14
Fix missing std::find_if and others with GCC 14.1.1
2024-06-24 18:23:37 -07:00
kth5 742662e4fc Fix missing std::find_if and others with GCC 14.1.1 2024-06-24 23:41:55 +02:00
dingusdev d3096ebaac Fixing compiler warnings, pt. 1 2024-06-21 08:01:21 -07:00
dingusdev c0e28b81a8 Gracefully exit upon EOF
Taken from #94 - Originally fixed by dressupgeekout  and refined by joevt
2024-06-16 07:28:40 -07:00
Maxim Poliakovski ce5edcb0c8 bebox.md: fix headers. 2024-06-15 22:21:34 +02:00
dingusdev a3743f0293 Starting documentation for more machines 2024-06-15 12:40:58 -07:00
dingusdev 92580f3515 Adding VSCode to gitignore 2024-06-14 19:55:42 +02:00
Mihai Parparita 50018010c7 Add instruction counters to CPU profiler
Keeps track of instructions (including operands) that are executed,
to see if there are any hotspots that could be optimized or fastpaths
that should be added.

Also adds a mode where CPU profiler data is periodically output, to
make it easier to get at these instruction counts during startup.
2024-06-14 19:55:42 +02:00
Maxim Poliakovski e4294d78bf machinepdm: use the real decrementer frequency. 2024-05-23 17:23:22 +02:00
dingusdev b73f5a157d Slightly expanding manual 2024-05-12 15:54:03 -07:00
109 changed files with 3608 additions and 1197 deletions

No files matched your search

+8
View File
@@ -1,10 +1,14 @@
# Ignore binary files
out/
vcpkg/
*.bin
# Ignore compiled object files
.vs/
.vscode/
*.o
*.out
*.obj
*.d
# Ignore CMake system files
@@ -16,6 +20,9 @@ CMakeSettings.json
*.vcxproj
*.vcxproj.filters
# Ignore Visual Studio auto-save recovery folder
enc_temp_folder/
# Ignore CodeLite configuration files
*.workspace
*.workspace.*
@@ -30,6 +37,7 @@ dingusppc.exe
# Ignore system files
.DS_Store
Thumb.db
ehthumbs.db
# IDE ignores
build
+6 -2
View File
@@ -180,9 +180,13 @@ if (DPPC_BUILD_PPC_TESTS)
endif()
if (DPPC_BUILD_BENCHMARKS)
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
add_compile_options("-DPPC_BENCHMARKS")
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
)
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
# $<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
+12 -2
View File
@@ -7,13 +7,22 @@
- maximumspatium
- joevt
- mihaip
- kkaisershot
## Building
## NT4/PPC fork
- Wack0
## DevOps
- Waqar144
- webspacecreations
- leap0x7b
- sdkmap
- dressupgeekout
- kth5
- dyharlan
- roytam1
## Testing
@@ -29,6 +38,7 @@
- Emaculation
- GitHub
- PenguinPPC
- VirtuallyFun
- The makers of Loguru, SDL2, Capstone, and CLI11
- The developers of other PowerPC Mac emulators, past and present
- All those preserving the software of 68k and PowerPC Macs
- All those preserving the software and source code of 68k and PowerPC Macs
+76 -31
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -25,6 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "cpu/ppc/ppcmmu.h"
#include "devices/memctrl/mpc106.h"
#include <thirdparty/loguru/loguru.hpp>
#include <debugger/debugger.h>
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_on = false;
}
#endif
uint32_t cs_code[] = {
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
@@ -35,12 +42,15 @@ uint32_t cs_code[] = {
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
0x7C650194, 0x4E800020
0x7C650194, /* 0x4E800020 */ 0x00005AF0
};
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
constexpr uint32_t test_samples = 200;
constexpr uint32_t test_iterations = 5;
int main(int argc, char** argv) {
int i;
int i, j;
/* initialize logging */
loguru::g_preamble_date = false;
@@ -53,7 +63,7 @@ int main(int argc, char** argv) {
MPC106* grackle_obj = new MPC106;
/* we need some RAM */
if (!grackle_obj->add_ram_region(0, 0x9000)) {
if (!grackle_obj->add_ram_region(0, 0x1000 + test_size)) {
LOG_F(ERROR, "Could not create RAM region");
delete(grackle_obj);
return -1;
@@ -61,51 +71,86 @@ int main(int argc, char** argv) {
constexpr uint64_t tbr_freq = 16705000;
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
/* load executable code into RAM at address 0 */
for (i = 0; i < sizeof(cs_code); i++) {
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
}
srand(0xCAFEBABE);
for (i = 0; i < 32768; i++) {
mmu_write_vmem<uint8_t>(0x1000+i, rand() % 256);
LOG_F(INFO, "Test size: 0x%X", test_size);
LOG_F(INFO, "First few bytes:");
bool did_lf = false;
for (i = 0; i < test_size; i++) {
uint8_t val = rand() % 256;
mmu_write_vmem<uint8_t>(0x1000+i, val);
if (i < 64) {
printf("%02x", val);
did_lf = false;
if (i % 32 == 31) {
printf("\n");
did_lf = true;
}
}
}
if (!did_lf)
printf("\n");
#if 0
/* prepare benchmark code execution */
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = 0x8000; // len
ppc_state.gpr[5] = 0; // sum
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = test_size; // len
ppc_state.gpr[5] = 0; // sum
enter_debugger();
#endif
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = test_size; // len
ppc_state.gpr[5] = 0; // sum
power_on = true;
ppc_exec_until(0xC4);
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
uint32_t checksum = ppc_state.gpr[3];
// run the clock once for cache fill etc.
auto start_time = std::chrono::steady_clock::now();
auto end_time = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
for (i = 0; i < 5; i++) {
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = 0x8000; // len
ppc_state.gpr[5] = 0; // sum
auto start_time = std::chrono::steady_clock::now();
ppc_exec_until(0xC4);
auto end_time = std::chrono::steady_clock::now();
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
uint64_t overhead = -1;
for (j = 0; j < test_samples; j++) {
auto start_time = std::chrono::steady_clock::now();
auto end_time = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
if (time_elapsed.count() < overhead)
overhead = time_elapsed.count();
}
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
for (int theproc = 0; theproc < 2; theproc++) {
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
for (i = 0; i < test_iterations; i++) {
uint64_t best_sample = -1;
for (j = 0; j < test_samples; j++) {
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = test_size; // len
ppc_state.gpr[5] = 0; // sum
power_on = true;
auto start_time = std::chrono::steady_clock::now();
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
auto end_time = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
if (time_elapsed.count() < best_sample)
best_sample = time_elapsed.count();
}
if (ppc_state.gpr[3] != checksum)
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
best_sample -= overhead;
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
}
}
delete(grackle_obj);
+38 -1
View File
@@ -40,6 +40,8 @@ enum : uint32_t {
MOUSE_EVENT_BUTTON = 1 << 1,
KEYBOARD_EVENT_DOWN = 1 << 0,
KEYBOARD_EVENT_UP = 1 << 1,
GAMEPAD_EVENT_DOWN = 1 << 0,
GAMEPAD_EVENT_UP = 1 << 1,
};
class MouseEvent {
@@ -65,6 +67,36 @@ public:
uint16_t keys_state;
};
/* AppleJack bits 3-7 are supported but unused */
enum GamepadButton : uint8_t {
Red = 14,
Green = 15,
Yellow = 9,
Blue = 8,
FrontLeft = 0,
FrontMiddle = 1,
FrontRight = 2,
LeftTrigger = 17,
RightTrigger = 16,
Up = 10,
Down = 13,
Left = 11,
Right = 12,
};
class GamepadEvent {
public:
GamepadEvent() = default;
~GamepadEvent() = default;
uint32_t gamepad_id;
uint32_t flags;
uint8_t button;
};
class EventManager {
public:
static EventManager* get_instance() {
@@ -91,6 +123,11 @@ public:
_keyboard_signal.connect_method(inst, func);
}
template <typename T>
void add_gamepad_handler(T* inst, void (T::*func)(const GamepadEvent&)) {
_gamepad_signal.connect_method(inst, func);
}
template <typename T>
void add_post_handler(T *inst, void (T::*func)()) {
_post_signal.connect_method(inst, func);
@@ -110,13 +147,13 @@ private:
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
CoreSignal<const KeyboardEvent&> _keyboard_signal;
CoreSignal<const GamepadEvent&> _gamepad_signal;
CoreSignal<> _post_signal;
uint64_t events_captured = 0;
uint64_t unhandled_events = 0;
uint64_t key_downs = 0;
uint64_t key_ups = 0;
uint64_t mouse_motions = 0;
uint8_t buttons_state = 0;
};
+58 -2
View File
@@ -41,7 +41,7 @@ void EventManager::poll_events()
switch (event.type) {
case SDL_QUIT:
power_on = false;
power_off_reason = po_shut_down;
power_off_reason = po_quit;
break;
case SDL_WINDOWEVENT: {
@@ -56,7 +56,7 @@ void EventManager::poll_events()
case SDL_KEYUP: {
// Internal shortcuts to trigger mouse grab, intentionally not
// sent to the host.
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
toggle_mouse_grab(event.key);
}
@@ -130,6 +130,52 @@ void EventManager::poll_events()
}
break;
case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge;
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_DOWN;
this->_gamepad_signal.emit(ge);
}
break;
case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge;
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_UP;
this->_gamepad_signal.emit(ge);
}
break;
default:
unhandled_events++;
}
@@ -304,6 +350,16 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
case 0XE8: return AdbKey_6; // E-grave
case 0XEC: return AdbKey_LeftBracket; // I-grave
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
// Spanish keyboard
case 0XA1: return AdbKey_Comma; // Inverted question mark
case 0XBA: return AdbKey_6; // Backslash
case 0XE7: return AdbKey_Slash; // C-cedilla
case 0XF1: return AdbKey_Semicolon; // N-tilde
case 0X4000002f:
return AdbKey_LeftBracket; // Acute
case 0X40000034:
return AdbKey_Semicolon; // Acute
}
return -1;
}
+5 -5
View File
@@ -33,11 +33,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define NS_PER_SEC 1E9
#define USEC_PER_SEC 1E6
#define NS_PER_USEC 1000UL
#define NS_PER_MSEC 1E6
#define ONE_BILLION_NS 0x3B9ACA00UL
#define NS_PER_SEC 1000000000
#define USEC_PER_SEC 1000000
#define NS_PER_USEC 1000
#define NS_PER_MSEC 1000000
#define ONE_BILLION_NS 1000000000
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
+3 -3
View File
@@ -200,7 +200,7 @@ void dppc_interpreter::power_dozi() {
template <field_rc rec>
void dppc_interpreter::power_lscbx() {
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
uint32_t bytes_remaining = bytes_to_load;
@@ -212,7 +212,7 @@ void dppc_interpreter::power_lscbx() {
uint8_t shift_amount = 24;
while (bytes_remaining > 0) {
uint8_t return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
uint8_t return_value = mmu_read_vmem<uint8_t>(ea);
ppc_result_d |= return_value << shift_amount;
if (!shift_amount) {
@@ -225,7 +225,7 @@ void dppc_interpreter::power_lscbx() {
shift_amount -= 8;
}
ppc_effective_address++;
ea++;
bytes_remaining--;
if (return_value == matching_byte) {
+1
View File
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define _CRT_SECURE_NO_WARNINGS /* shut up MSVC regarding the unsafe strcpy/strcat */
#include "ppcdisasm.h"
#include <algorithm>
#include <cstring>
#include <functional> /* without this, MSVC doesn't understand std::function */
#include <iostream>
+3 -4
View File
@@ -303,15 +303,15 @@ extern unsigned exec_flags;
extern jmp_buf exc_env;
extern bool grab_return;
enum Po_Cause : int {
po_none,
po_starting_up,
po_quit,
po_quitting,
po_shut_down,
po_shutting_down,
po_restarting,
po_restart,
po_restarting,
po_disassemble_on,
po_disassemble_off,
po_enter_debugger,
@@ -330,7 +330,6 @@ extern bool is_64bit; // For PowerPC G5 Emulation
// Important Addressing Integers
extern uint32_t ppc_cur_instruction;
extern uint32_t ppc_effective_address;
extern uint32_t ppc_next_instruction_address;
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
+4 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
jmp_buf exc_env; /* Global exception environment. */
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
#ifdef CPU_PROFILING
exceptions_processed++;
@@ -135,7 +136,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
longjmp(exc_env, 2); /* return to the main execution loop. */
}
}
#endif
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
std::string exc_descriptor;
@@ -226,7 +227,7 @@ void ppc_alignment_exception(uint32_t ea)
case 0xcc000000: // lfdu
case 0xd4000000: // stfsu
case 0xdc000000: // stfdu
indirect_with_immediate_index:
// indirect with immediate index
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
break;
+43 -17
View File
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
#include "ppcemu.h"
#include "ppcmmu.h"
#include "ppcdisasm.h"
#include <algorithm>
#include <cstring>
@@ -61,11 +62,7 @@ Po_Cause power_off_reason = po_enter_debugger;
SetPRS ppc_state;
bool grab_return;
bool grab_breakpoint;
uint32_t ppc_cur_instruction; // Current instruction for the PPC
uint32_t ppc_effective_address;
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
unsigned exec_flags; // execution control flags
@@ -83,7 +80,6 @@ uint32_t glob_bb_start_la;
/* variables related to virtual time */
const bool g_realtime = false;
uint64_t g_nanoseconds_base;
uint64_t g_icycles_base;
uint64_t g_icycles;
int icnt_factor;
@@ -109,6 +105,9 @@ uint64_t num_supervisor_instrs;
uint64_t num_int_loads;
uint64_t num_int_stores;
uint64_t exceptions_processed;
#ifdef CPU_PROFILING_OPS
std::unordered_map<uint32_t, uint64_t> num_opcodes;
#endif
#include "utils/profiler.h"
#include <memory>
@@ -139,6 +138,30 @@ public:
vars.push_back({.name = "Exceptions processed",
.format = ProfileVarFmt::DEC,
.value = exceptions_processed});
// Generate top N op counts with readable names.
#ifdef CPU_PROFILING_OPS
PPCDisasmContext ctx;
ctx.instr_addr = 0;
ctx.simplified = false;
std::vector<std::pair<std::string, uint64_t>> op_name_counts;
for (const auto& pair : num_opcodes) {
ctx.instr_code = pair.first;
auto op_name = disassemble_single(&ctx);
op_name_counts.emplace_back(op_name, pair.second);
}
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
return b.second < a.second;
});
op_name_counts.resize(top_ops_size);
for (const auto& pair : op_name_counts) {
vars.push_back({.name = "Instruction " + pair.first,
.format = ProfileVarFmt::COUNT,
.value = pair.second,
.count_total = num_executed_instrs});
}
#endif
};
void reset() {
@@ -147,6 +170,9 @@ public:
num_int_loads = 0;
num_int_stores = 0;
exceptions_processed = 0;
#ifdef CPU_PROFILING_OPS
num_opcodes.clear();
#endif
};
};
@@ -289,11 +315,14 @@ void ppc_main_opcode()
{
#ifdef CPU_PROFILING
num_executed_instrs++;
#if defined(CPU_PROFILING_OPS)
num_opcodes[ppc_cur_instruction]++;
#endif
#endif
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
}
long long now_ns() {
static long long cpu_now_ns() {
#ifdef __APPLE__
return ConvertHostTimeToNanos2(mach_absolute_time());
#else
@@ -305,25 +334,25 @@ long long now_ns() {
uint64_t get_virt_time_ns()
{
if (g_realtime) {
return now_ns() - g_nanoseconds_base;
return cpu_now_ns() - g_nanoseconds_base;
} else {
return g_icycles << icnt_factor;
}
}
uint64_t process_events()
static uint64_t process_events()
{
exec_timer = false;
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
if (slice_ns == 0) {
// execute 10.000 cycles
// execute 25.000 cycles
// if there are no pending timers
return g_icycles + 10000;
return g_icycles + 25000;
}
return g_icycles + ((slice_ns + (1ULL << icnt_factor)) >> icnt_factor);
return g_icycles + (slice_ns >> icnt_factor) + 1;
}
void force_cycle_counter_reload()
static void force_cycle_counter_reload()
{
// tell the interpreter loop to reload cycle counter
exec_timer = true;
@@ -844,8 +873,6 @@ void initialize_ppc_opcode_tables(bool include_601) {
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq)
{
int i;
mem_ctrl_instance = mem_ctrl;
std::memset(&ppc_state, 0, sizeof(ppc_state));
@@ -864,8 +891,7 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601,
#ifdef __APPLE__
mach_timebase_info(&timebase_info);
#endif
g_nanoseconds_base = now_ns();
g_icycles_base = 0;
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
//icnt_factor = 6;
icnt_factor = 4;
@@ -926,7 +952,7 @@ static map<string, int> SPRName2Num = {
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1}
};
uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
string reg_name_u, reg_num_str;
unsigned reg_num;
map<string, int>::iterator spr;
+380 -59
View File
@@ -103,13 +103,23 @@ inline static void snan_double_check(int reg_a, int reg_b) {
ppc_state.fpscr |= FX | VX | VXSNAN;
}
inline static void max_double_check(double value_a, double value_b) {
if (((value_a == DBL_MAX) && (value_b == DBL_MAX)) ||
((value_a == -DBL_MAX) && (value_b == -DBL_MAX)))
ppc_state.fpscr |= FX | OX | XX | FI;
}
inline static bool check_qnan(int check_reg) {
uint64_t check_int = ppc_state.fpr[check_reg].int64_r;
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & ~(0xFFFULL << 52)) == 0ULL) &&
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
}
static double set_endresult_nan(double ppc_result_d) {
ppc_state.fpscr += (FX + VX);
return std::numeric_limits<double>::quiet_NaN();
}
static void fpresult_update(double set_result) {
if (std::isnan(set_result)) {
ppc_state.fpscr |= FPCC_FUNAN | FPRCD;
@@ -121,6 +131,18 @@ static void fpresult_update(double set_result) {
} else {
ppc_state.fpscr |= FPCC_ZERO;
}
if (std::fetestexcept(FE_OVERFLOW)) {
ppc_state.fpscr |= (OX + FX);
}
if (std::fetestexcept(FE_UNDERFLOW)) {
ppc_state.fpscr |= (UX + FX);
}
if (std::fetestexcept(FE_DIVBYZERO)) {
ppc_state.fpscr |= (ZX + FX);
}
std::feclearexcept(FE_ALL_EXCEPT);
if (std::isinf(set_result))
ppc_state.fpscr |= FPCC_FUNAN;
@@ -136,7 +158,7 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
((ppc_state.fpscr >> 3) & 0x1F));
if (fpscr_check)
@@ -151,10 +173,26 @@ void dppc_interpreter::ppc_fadd() {
ppc_grab_regsfpdab(ppc_cur_instruction);
snan_double_check(reg_a, reg_b);
max_double_check(val_reg_a, val_reg_b);
double ppc_dblresult64_d = val_reg_a + val_reg_b;
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
ppc_update_fex();
if (rec)
ppc_update_cr1();
@@ -170,8 +208,21 @@ void dppc_interpreter::ppc_fsub() {
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = val_reg_a - val_reg_b;
double inf = std::numeric_limits<double>::infinity();
if ((val_reg_a == inf) && (val_reg_b == inf)) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
ppc_update_fex();
if (rec)
ppc_update_cr1();
@@ -187,6 +238,27 @@ void dppc_interpreter::ppc_fdiv() {
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = val_reg_a / val_reg_b;
if (val_reg_b == 0.0) {
ppc_state.fpscr |= 0xa0000000;
ppc_dblresult64_d = -ppc_dblresult64_d;
}
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
ppc_state.fpscr |= VXIDI;
}
if ((val_reg_a == 0.0) && (val_reg_b == 0.0)) {
ppc_state.fpscr |= VXZDZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -204,9 +276,23 @@ void dppc_interpreter::ppc_fmul() {
snan_double_check(reg_a, reg_c);
double ppc_dblresult64_d = val_reg_a * val_reg_c;
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
}
@@ -222,9 +308,32 @@ void dppc_interpreter::ppc_fmadd() {
snan_single_check(reg_b);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
}
@@ -240,6 +349,27 @@ void dppc_interpreter::ppc_fmsub() {
snan_single_check(reg_b);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -258,9 +388,35 @@ void dppc_interpreter::ppc_fnmadd() {
snan_single_check(reg_b);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
}
@@ -276,6 +432,27 @@ void dppc_interpreter::ppc_fnmsub() {
snan_single_check(reg_b);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -291,10 +468,23 @@ void dppc_interpreter::ppc_fadds() {
ppc_grab_regsfpdab(ppc_cur_instruction);
snan_double_check(reg_a, reg_b);
max_double_check(val_reg_a, val_reg_b);
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
@@ -311,6 +501,19 @@ void dppc_interpreter::ppc_fsubs() {
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == inf)) ||
((val_reg_a == -inf) && (val_reg_b == -inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -328,6 +531,26 @@ void dppc_interpreter::ppc_fdivs() {
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
if (val_reg_b == 0.0) {
ppc_state.fpscr |= 0xa0000000;
ppc_dblresult64_d = -ppc_dblresult64_d;
}
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
ppc_state.fpscr |= VXIDI;
}
if ((val_reg_a == 0.0) && (val_reg_b == 0.0)) {
ppc_state.fpscr |= VXZDZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -345,9 +568,23 @@ void dppc_interpreter::ppc_fmuls() {
snan_double_check(reg_a, reg_c);
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
}
@@ -363,6 +600,23 @@ void dppc_interpreter::ppc_fmadds() {
snan_single_check(reg_b);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf)))
ppc_state.fpscr |= VXISI;
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -380,7 +634,25 @@ void dppc_interpreter::ppc_fmsubs() {
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
double inf = std::numeric_limits<double>::infinity();
if ((val_reg_a == inf) && (val_reg_b == inf))
ppc_state.fpscr |= VXISI;
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -399,6 +671,26 @@ void dppc_interpreter::ppc_fnmadds() {
snan_single_check(reg_b);
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf)))
ppc_state.fpscr |= VXISI;
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -417,6 +709,23 @@ void dppc_interpreter::ppc_fnmsubs() {
snan_single_check(reg_b);
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
if ((std::isinf(val_reg_a) && (val_reg_c == 0.0)) ||
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
double inf = std::numeric_limits<double>::infinity();
if ((val_reg_a == inf) && (val_reg_b == inf))
ppc_state.fpscr |= VXISI;
if (std::isnan(val_reg_a) || std::isnan(val_reg_b) || std::isnan(val_reg_c)) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
@@ -435,6 +744,10 @@ void dppc_interpreter::ppc_fabs() {
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
@@ -451,7 +764,11 @@ void dppc_interpreter::ppc_fnabs() {
snan_single_check(reg_b);
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
ppc_dblresult64_d = -ppc_dblresult64_d;
ppc_dblresult64_d = -ppc_dblresult64_d;
if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
@@ -470,6 +787,10 @@ void dppc_interpreter::ppc_fneg() {
double ppc_dblresult64_d = -(GET_FPR(reg_b));
if (std::isnan(GET_FPR(reg_b))) {
ppc_dblresult64_d = std::numeric_limits<double>::quiet_NaN();
}
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
@@ -664,20 +985,20 @@ template void dppc_interpreter::ppc_fctiwz<RC1>();
void dppc_interpreter::ppc_lfs() {
ppc_grab_regsfpdia(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ea);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
}
void dppc_interpreter::ppc_lfsu() {
ppc_grab_regsfpdia(ppc_cur_instruction);
if (reg_a) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ea);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
ppc_state.gpr[reg_a] = ppc_effective_address;
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -685,18 +1006,18 @@ void dppc_interpreter::ppc_lfsu() {
void dppc_interpreter::ppc_lfsx() {
ppc_grab_regsfpdiab(ppc_cur_instruction);
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t result = mmu_read_vmem<uint32_t>(ea);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
}
void dppc_interpreter::ppc_lfsux() {
ppc_grab_regsfpdiab(ppc_cur_instruction);
if (reg_a) {
ppc_effective_address = val_reg_a + val_reg_b;
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ea = val_reg_a + val_reg_b;
uint32_t result = mmu_read_vmem<uint32_t>(ea);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
ppc_state.gpr[reg_a] = ppc_effective_address;
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -704,20 +1025,20 @@ void dppc_interpreter::ppc_lfsux() {
void dppc_interpreter::ppc_lfd() {
ppc_grab_regsfpdia(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
}
void dppc_interpreter::ppc_lfdu() {
ppc_grab_regsfpdia(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += val_reg_a;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += val_reg_a;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -725,18 +1046,18 @@ void dppc_interpreter::ppc_lfdu() {
void dppc_interpreter::ppc_lfdx() {
ppc_grab_regsfpdiab(ppc_cur_instruction);
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
}
void dppc_interpreter::ppc_lfdux() {
ppc_grab_regsfpdiab(ppc_cur_instruction);
if (reg_a) {
ppc_effective_address = val_reg_a + val_reg_b;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
uint32_t ea = val_reg_a + val_reg_b;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -744,20 +1065,20 @@ void dppc_interpreter::ppc_lfdux() {
void dppc_interpreter::ppc_stfs() {
ppc_grab_regsfpsia(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a) ? val_reg_a : 0;
float result = ppc_state.fpr[reg_s].dbl64_r;
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a) ? val_reg_a : 0;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
}
void dppc_interpreter::ppc_stfsu() {
ppc_grab_regsfpsia(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += val_reg_a;
float result = ppc_state.fpr[reg_s].dbl64_r;
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += val_reg_a;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -765,18 +1086,18 @@ void dppc_interpreter::ppc_stfsu() {
void dppc_interpreter::ppc_stfsx() {
ppc_grab_regsfpsiab(ppc_cur_instruction);
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
float result = ppc_state.fpr[reg_s].dbl64_r;
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
}
void dppc_interpreter::ppc_stfsux() {
ppc_grab_regsfpsiab(ppc_cur_instruction);
if (reg_a) {
ppc_effective_address = val_reg_a + val_reg_b;
float result = ppc_state.fpr[reg_s].dbl64_r;
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = val_reg_a + val_reg_b;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -784,18 +1105,18 @@ void dppc_interpreter::ppc_stfsux() {
void dppc_interpreter::ppc_stfd() {
ppc_grab_regsfpsia(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
}
void dppc_interpreter::ppc_stfdu() {
ppc_grab_regsfpsia(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += val_reg_a;
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += val_reg_a;
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -803,16 +1124,16 @@ void dppc_interpreter::ppc_stfdu() {
void dppc_interpreter::ppc_stfdx() {
ppc_grab_regsfpsiab(ppc_cur_instruction);
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
}
void dppc_interpreter::ppc_stfdux() {
ppc_grab_regsfpsiab(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = val_reg_a + val_reg_b;
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = val_reg_a + val_reg_b;
mmu_write_vmem<uint64_t>(ea, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -820,8 +1141,8 @@ void dppc_interpreter::ppc_stfdux() {
void dppc_interpreter::ppc_stfiwx() {
ppc_grab_regsfpsiab(ppc_cur_instruction);
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint32_t>(ea, uint32_t(ppc_state.fpr[reg_s].int64_r));
}
// Floating Point Register Transfer
@@ -962,7 +1283,7 @@ void dppc_interpreter::ppc_fcmpo() {
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
cmp_c |= CRx_bit::CR_SO;
ppc_state.fpscr |= FX | VX;
ppc_state.fpscr |= FX | VX;
if (check_snan(reg_a) || check_snan(reg_b)) {
ppc_state.fpscr |= VXSNAN;
}
+19 -1
View File
@@ -82,18 +82,30 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
#define ppc_grab_regssab_stswx(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsab(opcode) \
int reg_a = (opcode >> 16) & 31;\
int reg_b = (opcode >> 11) & 31;\
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
#define ppc_grab_regssa(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssa_stmw(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
@@ -101,6 +113,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash_stswi(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31; \
+18 -11
View File
@@ -137,19 +137,19 @@ static BATResult ppc_block_address_translation(uint32_t la)
PPC_BAT_entry *bat_array;
bool bat_hit = false;
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
unsigned msr_pr = (ppc_state.msr & MSR::PR) != 0;
bat_array = (type == BATType::IBAT) ? ibat_array : dbat_array;
// Format: %XY
// X - supervisor access bit, Y - problem/user access bit
// Those bits are mutually exclusive
unsigned access_bits = ((msr_pr ^ 1) << 1) | msr_pr;
unsigned access_bits = ((!msr_pr) << 1) | msr_pr;
for (int bat_index = 0; bat_index < 4; bat_index++) {
PPC_BAT_entry* bat_entry = &bat_array[bat_index];
if ((bat_entry->access & access_bits) && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
if ((bat_entry->access & access_bits) != 0 && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
bat_hit = true;
#ifdef MMU_PROFILING
@@ -372,7 +372,7 @@ uint32_t tlb_size_mask = TLB_SIZE - 1;
// fake TLB entry for handling of unmapped memory accesses
uint64_t UnmappedVal = -1ULL;
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, 0};
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, {{0}}};
uint8_t CurITLBMode = {0xFF}; // current ITLB mode
uint8_t CurDTLBMode = {0xFF}; // current DTLB mode
@@ -797,21 +797,28 @@ static void tlb_flush_entries(std::array<TLBEntry, N> &tlb, TLBFlags type) {
template <const TLBType tlb_type>
void tlb_flush_entries(TLBFlags type)
{
TLBEntry *m1_tlb, *m2_tlb, *m3_tlb;
int i;
// Mode 1 is real addressing and thus can't contain any PAT entries by definition.
bool flush_mode1 = type != TLBE_FROM_PAT;
if (tlb_type == TLBType::ITLB) {
tlb_flush_entries(itlb1_mode1, type);
if (flush_mode1) {
tlb_flush_entries(itlb1_mode1, type);
}
tlb_flush_entries(itlb1_mode2, type);
tlb_flush_entries(itlb1_mode3, type);
tlb_flush_entries(itlb2_mode1, type);
if (flush_mode1) {
tlb_flush_entries(itlb2_mode1, type);
}
tlb_flush_entries(itlb2_mode2, type);
tlb_flush_entries(itlb2_mode3, type);
} else {
tlb_flush_entries(dtlb1_mode1, type);
if (flush_mode1) {
tlb_flush_entries(dtlb1_mode1, type);
}
tlb_flush_entries(dtlb1_mode2, type);
tlb_flush_entries(dtlb1_mode3, type);
tlb_flush_entries(dtlb2_mode1, type);
if (flush_mode1) {
tlb_flush_entries(dtlb2_mode1, type);
}
tlb_flush_entries(dtlb2_mode2, type);
tlb_flush_entries(dtlb2_mode3, type);
}
-13
View File
@@ -134,17 +134,4 @@ extern T mmu_read_vmem(uint32_t guest_va);
template <class T>
extern void mmu_write_vmem(uint32_t guest_va, T value);
//====================== Deprecated calls =========================
#if 0
extern void mem_write_byte(uint32_t addr, uint8_t value);
extern void mem_write_word(uint32_t addr, uint16_t value);
extern void mem_write_dword(uint32_t addr, uint32_t value);
extern void mem_write_qword(uint32_t addr, uint64_t value);
extern uint8_t mem_grab_byte(uint32_t addr);
extern uint16_t mem_grab_word(uint32_t addr);
extern uint32_t mem_grab_dword(uint32_t addr);
extern uint64_t mem_grab_qword(uint32_t addr);
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
#endif
#endif // PPCMMU_H
+124 -119
View File
@@ -47,7 +47,7 @@ void ppc_changecrf0(uint32_t set_result) {
}
// Affects the XER register's Carry Bit
inline void ppc_carry(uint32_t a, uint32_t b) {
inline static void ppc_carry(uint32_t a, uint32_t b) {
if (b < a) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
@@ -55,7 +55,7 @@ inline void ppc_carry(uint32_t a, uint32_t b) {
}
}
inline void ppc_carry_sub(uint32_t a, uint32_t b) {
inline static void ppc_carry_sub(uint32_t a, uint32_t b) {
if (b >= a) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
@@ -65,7 +65,7 @@ inline void ppc_carry_sub(uint32_t a, uint32_t b) {
// Affects the XER register's SO and OV Bits
inline void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
inline static void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
if (int32_t((a ^ b) & (a ^ d)) < 0) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
@@ -84,7 +84,7 @@ void do_ctx_sync() {
}
}
void add_ctx_sync_action(const CtxSyncCallback &cb) {
void add_ctx_sync_action(const CtxSyncCallback& cb) {
gCtxSyncCallbacks.push_back(cb);
}
@@ -666,7 +666,7 @@ template void dppc_interpreter::ppc_srawi<RC1>();
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me) {
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
uint32_t m2 = (uint32_t)(0xFFFFFFFFUL << (31 - rot_me));
uint32_t m2 = uint32_t(0xFFFFFFFFUL << (31 - rot_me));
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
}
@@ -728,8 +728,10 @@ void dppc_interpreter::ppc_mtsr() {
}
int reg_s = (ppc_cur_instruction >> 21) & 0x1F;
uint32_t grab_sr = (ppc_cur_instruction >> 16) & 0x0F;
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
mmu_pat_ctx_changed();
if (ppc_state.sr[grab_sr] != ppc_state.gpr[reg_s]) {
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
mmu_pat_ctx_changed();
}
}
void dppc_interpreter::ppc_mtsrin() {
@@ -741,8 +743,10 @@ void dppc_interpreter::ppc_mtsrin() {
}
ppc_grab_regssb(ppc_cur_instruction);
uint32_t grab_sr = ppc_result_b >> 28;
ppc_state.sr[grab_sr] = ppc_result_d;
mmu_pat_ctx_changed();
if (ppc_state.sr[grab_sr] != ppc_result_d) {
ppc_state.sr[grab_sr] = ppc_result_d;
mmu_pat_ctx_changed();
}
}
void dppc_interpreter::ppc_mfsr() {
@@ -969,8 +973,10 @@ void dppc_interpreter::ppc_mtspr() {
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::SDR1:
ppc_state.spr[ref_spr] = val;
mmu_pat_ctx_changed(); // adapt to SDR1 changes
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
mmu_pat_ctx_changed(); // adapt to SDR1 changes
}
break;
case SPR::RTCL_S:
calc_rtcl_value();
@@ -1389,7 +1395,6 @@ void dppc_interpreter::ppc_rfi() {
mmu_change_mode();
grab_return = true;
exec_flags = EXEF_RFI;
}
@@ -1467,16 +1472,16 @@ void dppc_interpreter::ppc_dcbtst() {
void dppc_interpreter::ppc_dcbz() {
ppc_grab_regsab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
ppc_effective_address &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
ea &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
// the following is not especially efficient but necessary
// to make BlockZero under Mac OS 8.x and later to work
mmu_write_vmem<uint64_t>(ppc_effective_address + 0, 0);
mmu_write_vmem<uint64_t>(ppc_effective_address + 8, 0);
mmu_write_vmem<uint64_t>(ppc_effective_address + 16, 0);
mmu_write_vmem<uint64_t>(ppc_effective_address + 24, 0);
mmu_write_vmem<uint64_t>(ea + 0, 0);
mmu_write_vmem<uint64_t>(ea + 8, 0);
mmu_write_vmem<uint64_t>(ea + 16, 0);
mmu_write_vmem<uint64_t>(ea + 24, 0);
}
@@ -1488,9 +1493,9 @@ void dppc_interpreter::ppc_st() {
num_int_stores++;
#endif
ppc_grab_regssa(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += reg_a ? ppc_result_a : 0;
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += reg_a ? ppc_result_a : 0;
mmu_write_vmem<T>(ea, ppc_result_d);
}
template void dppc_interpreter::ppc_st<uint8_t>();
@@ -1503,8 +1508,8 @@ void dppc_interpreter::ppc_stx() {
num_int_stores++;
#endif
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
mmu_write_vmem<T>(ea, ppc_result_d);
}
template void dppc_interpreter::ppc_stx<uint8_t>();
@@ -1518,10 +1523,10 @@ void dppc_interpreter::ppc_stu() {
#endif
ppc_grab_regssa(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += ppc_result_a;
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += ppc_result_a;
mmu_write_vmem<T>(ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -1538,9 +1543,9 @@ void dppc_interpreter::ppc_stux() {
#endif
ppc_grab_regssab(ppc_cur_instruction);
if (reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
mmu_write_vmem<T>(ppc_effective_address, ppc_result_d);
ppc_state.gpr[reg_a] = ppc_effective_address;
uint32_t ea = ppc_result_a + ppc_result_b;
mmu_write_vmem<T>(ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -1555,9 +1560,9 @@ void dppc_interpreter::ppc_sthbrx() {
num_int_stores++;
#endif
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
ppc_result_d = uint32_t(BYTESWAP_16(uint16_t(ppc_result_d)));
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
ppc_result_d = uint32_t(BYTESWAP_16(uint16_t(ppc_result_d)));
mmu_write_vmem<uint16_t>(ea, ppc_result_d);
}
void dppc_interpreter::ppc_stwcx() {
@@ -1565,11 +1570,11 @@ void dppc_interpreter::ppc_stwcx() {
num_int_stores++;
#endif
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
uint32_t ea = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
ppc_state.cr &= 0x0FFFFFFFUL; // clear CR0
ppc_state.cr |= (ppc_state.spr[SPR::XER] & XER::SO) >> 3; // copy XER[SO] to CR0[SO]
if (ppc_state.reserve) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
mmu_write_vmem<uint32_t>(ea, ppc_result_d);
ppc_state.reserve = false;
ppc_state.cr |= 0x20000000UL; // set CR0[EQ]
}
@@ -1580,27 +1585,27 @@ void dppc_interpreter::ppc_stwbrx() {
num_int_stores++;
#endif
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
ppc_result_d = BYTESWAP_32(ppc_result_d);
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
mmu_write_vmem<uint32_t>(ea, ppc_result_d);
}
void dppc_interpreter::ppc_stmw() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssa(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += reg_a ? ppc_result_a : 0;
ppc_grab_regssa_stmw(ppc_cur_instruction);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += reg_a ? ppc_result_a : 0;
/* what should we do if EA is unaligned? */
if (ppc_effective_address & 3) {
ppc_alignment_exception(ppc_effective_address);
if (ea & 3) {
ppc_alignment_exception(ea);
}
for (; reg_s <= 31; reg_s++) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
ppc_effective_address += 4;
mmu_write_vmem<uint32_t>(ea, ppc_state.gpr[reg_s]);
ea += 4;
}
}
@@ -1610,9 +1615,9 @@ void dppc_interpreter::ppc_lz() {
num_int_loads++;
#endif
ppc_grab_regsda(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += reg_a ? ppc_result_a : 0;
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += reg_a ? ppc_result_a : 0;
uint32_t ppc_result_d = mmu_read_vmem<T>(ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1626,11 +1631,11 @@ void dppc_interpreter::ppc_lzu() {
num_int_loads++;
#endif
ppc_grab_regsda(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
if ((reg_a != reg_d) && reg_a != 0) {
ppc_effective_address += ppc_result_a;
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
uint32_t ppc_result_a = ppc_effective_address;
ea += ppc_result_a;
uint32_t ppc_result_d = mmu_read_vmem<T>(ea);
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
@@ -1648,8 +1653,8 @@ void dppc_interpreter::ppc_lzx() {
num_int_loads++;
#endif
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = mmu_read_vmem<T>(ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1664,9 +1669,9 @@ void dppc_interpreter::ppc_lzux() {
#endif
ppc_grab_regsdab(ppc_cur_instruction);
if ((reg_a != reg_d) && reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
uint32_t ppc_result_d = mmu_read_vmem<T>(ppc_effective_address);
ppc_result_a = ppc_effective_address;
uint32_t ea = ppc_result_a + ppc_result_b;
uint32_t ppc_result_d = mmu_read_vmem<T>(ea);
ppc_result_a = ea;
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
@@ -1683,9 +1688,9 @@ void dppc_interpreter::ppc_lha() {
num_int_loads++;
#endif
ppc_grab_regsda(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a ? ppc_result_a : 0);
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a ? ppc_result_a : 0);
int16_t val = mmu_read_vmem<uint16_t>(ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
}
@@ -1695,11 +1700,11 @@ void dppc_interpreter::ppc_lhau() {
#endif
ppc_grab_regsda(ppc_cur_instruction);
if ((reg_a != reg_d) && reg_a != 0) {
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += ppc_result_a;
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += ppc_result_a;
int16_t val = mmu_read_vmem<uint16_t>(ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
uint32_t ppc_result_a = ppc_effective_address;
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
@@ -1712,10 +1717,10 @@ void dppc_interpreter::ppc_lhaux() {
#endif
ppc_grab_regsdab(ppc_cur_instruction);
if ((reg_a != reg_d) && reg_a != 0) {
ppc_effective_address = ppc_result_a + ppc_result_b;
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
uint32_t ea = ppc_result_a + ppc_result_b;
int16_t val = mmu_read_vmem<uint16_t>(ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
uint32_t ppc_result_a = ppc_effective_address;
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
else {
@@ -1728,8 +1733,8 @@ void dppc_interpreter::ppc_lhax() {
num_int_loads++;
#endif
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
int16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
int16_t val = mmu_read_vmem<uint16_t>(ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
}
@@ -1738,8 +1743,8 @@ void dppc_interpreter::ppc_lhbrx() {
num_int_loads++;
#endif
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = uint32_t(BYTESWAP_16(mmu_read_vmem<uint16_t>(ppc_effective_address)));
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = uint32_t(BYTESWAP_16(mmu_read_vmem<uint16_t>(ea)));
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1748,8 +1753,8 @@ void dppc_interpreter::ppc_lwbrx() {
num_int_loads++;
#endif
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = BYTESWAP_32(mmu_read_vmem<uint32_t>(ppc_effective_address));
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ppc_result_d = BYTESWAP_32(mmu_read_vmem<uint32_t>(ea));
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1759,9 +1764,9 @@ void dppc_interpreter::ppc_lwarx() {
#endif
// Placeholder - Get the reservation of memory implemented!
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
ppc_state.reserve = true;
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1770,12 +1775,12 @@ void dppc_interpreter::ppc_lmw() {
num_int_loads++;
#endif
ppc_grab_regsda(ppc_cur_instruction);
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
ppc_effective_address += (reg_a ? ppc_result_a : 0);
uint32_t ea = int32_t(int16_t(ppc_cur_instruction));
ea += (reg_a ? ppc_result_a : 0);
// How many words to load in memory - using a do-while for this
do {
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
ppc_effective_address += 4;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ea);
ea += 4;
reg_d++;
} while (reg_d < 32);
}
@@ -1785,31 +1790,31 @@ void dppc_interpreter::ppc_lswi() {
num_int_loads++;
#endif
ppc_grab_regsda(ppc_cur_instruction);
ppc_effective_address = reg_a ? ppc_result_a : 0;
uint32_t grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
grab_inb = grab_inb ? grab_inb : 32;
uint32_t ea = reg_a ? ppc_result_a : 0;
uint32_t grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
grab_inb = grab_inb ? grab_inb : 32;
while (grab_inb >= 4) {
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ea);
reg_d++;
if (reg_d >= 32) { // wrap around through GPR0
reg_d = 0;
}
ppc_effective_address += 4;
ea += 4;
grab_inb -= 4;
}
// handle remaining bytes
switch (grab_inb) {
case 1:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ea) << 24;
break;
case 2:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ea) << 16;
break;
case 3:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
ppc_state.gpr[reg_d] += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ea) << 16;
ppc_state.gpr[reg_d] += mmu_read_vmem<uint8_t>(ea + 2) << 8;
break;
default:
break;
@@ -1831,7 +1836,7 @@ void dppc_interpreter::ppc_lswx() {
}
*/
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t grab_inb = ppc_state.spr[SPR::XER] & 0x7F;
for (;;) {
@@ -1843,19 +1848,19 @@ void dppc_interpreter::ppc_lswx() {
case 0:
return;
case 1:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ea) << 24;
return;
case 2:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ea) << 16;
return;
case 3:
ppc_state.gpr[reg_d] = (mmu_read_vmem<uint16_t>(ppc_effective_address) << 16)
| (mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8);
ppc_state.gpr[reg_d] = (mmu_read_vmem<uint16_t>(ea) << 16)
| (mmu_read_vmem<uint8_t>(ea + 2) << 8);
return;
}
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ea);
reg_d = (reg_d + 1) & 0x1F; // wrap around through GPR0
ppc_effective_address += 4;
ea += 4;
grab_inb -= 4;
}
}
@@ -1864,31 +1869,31 @@ void dppc_interpreter::ppc_stswi() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssash(ppc_cur_instruction);
ppc_effective_address = reg_a ? ppc_result_a : 0;
ppc_grab_regssash_stswi(ppc_cur_instruction);
uint32_t ea = reg_a ? ppc_result_a : 0;
uint32_t grab_inb = rot_sh ? rot_sh : 32;
while (grab_inb >= 4) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
mmu_write_vmem<uint32_t>(ea, ppc_state.gpr[reg_s]);
reg_s++;
if (reg_s >= 32) { // wrap around through GPR0
reg_s = 0;
}
ppc_effective_address += 4;
ea += 4;
grab_inb -= 4;
}
// handle remaining bytes
switch (grab_inb) {
case 1:
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
mmu_write_vmem<uint8_t>(ea, ppc_state.gpr[reg_s] >> 24);
break;
case 2:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint16_t>(ea, ppc_state.gpr[reg_s] >> 16);
break;
case 3:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
mmu_write_vmem<uint16_t>(ea, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ea + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
break;
default:
break;
@@ -1899,31 +1904,31 @@ void dppc_interpreter::ppc_stswx() {
#ifdef CPU_PROFILING
num_int_stores++;
#endif
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t grab_inb = ppc_state.spr[SPR::XER] & 127;
ppc_grab_regssab_stswx(ppc_cur_instruction);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t grab_inb = ppc_state.spr[SPR::XER] & 127;
while (grab_inb >= 4) {
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
mmu_write_vmem<uint32_t>(ea, ppc_state.gpr[reg_s]);
reg_s++;
if (reg_s >= 32) { // wrap around through GPR0
reg_s = 0;
}
ppc_effective_address += 4;
ea += 4;
grab_inb -= 4;
}
// handle remaining bytes
switch (grab_inb) {
case 1:
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
mmu_write_vmem<uint8_t>(ea, ppc_state.gpr[reg_s] >> 24);
break;
case 2:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint16_t>(ea, ppc_state.gpr[reg_s] >> 16);
break;
case 3:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
mmu_write_vmem<uint16_t>(ea, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ea + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
break;
default:
break;
@@ -1939,13 +1944,13 @@ void dppc_interpreter::ppc_eciwx() {
}
ppc_grab_regsdab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
if (ppc_effective_address & 0x3) {
ppc_alignment_exception(ppc_effective_address);
if (ea & 0x3) {
ppc_alignment_exception(ea);
}
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
uint32_t ppc_result_d = mmu_read_vmem<uint32_t>(ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
@@ -1959,13 +1964,13 @@ void dppc_interpreter::ppc_ecowx() {
}
ppc_grab_regssab(ppc_cur_instruction);
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
if (ppc_effective_address & 0x3) {
ppc_alignment_exception(ppc_effective_address);
if (ea & 0x3) {
ppc_alignment_exception(ea);
}
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
mmu_write_vmem<uint32_t>(ea, ppc_result_d);
}
// TLB Instructions
+6
View File
@@ -36,6 +36,12 @@ using namespace std;
int ntested; // number of tested instructions
int nfailed; // number of failed instructions
#if defined(PPC_TESTS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_on = false;
}
#endif
void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2;
+11
View File
@@ -447,7 +447,9 @@ void enter_debugger() {
size_t separator_pos;
bool did_message = false;
uint32_t next_addr_ppc;
#ifdef ENABLE_68K_DEBUGGER
uint32_t next_addr_68k;
#endif
bool cmd_repeat;
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
@@ -468,6 +470,10 @@ void enter_debugger() {
power_off_reason = po_restarting;
break;
}
if (power_off_reason == po_quit) {
power_off_reason = po_quitting;
break;
}
power_on = true;
if (power_off_reason == po_starting_up) {
@@ -530,6 +536,11 @@ void enter_debugger() {
continue;
}
if (feof(stdin)) {
printf("eof -> quit\n");
cmd = "quit";
}
cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) {
cmd = last_cmd;
+100
View File
@@ -0,0 +1,100 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus AppleJack controller emulation. */
#include <devices/common/adb/adbapplejack.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <loguru.hpp>
AdbAppleJack::AdbAppleJack(std::string name) : AdbMouse(name, AdbMouse::TRACKBALL, 2, 7, 300) {
EventManager::get_instance()->add_gamepad_handler(this, &AdbAppleJack::event_handler);
}
void AdbAppleJack::event_handler(const GamepadEvent& event) {
uint32_t button_bit = 1 << event.button;
if (event.flags & GAMEPAD_EVENT_DOWN)
this->buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
else
this->buttons_changed = true;
}
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
}
bool AdbAppleJack::get_register_0() {
bool changed = this->triggers_changed || this->buttons_changed;
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
// AppleJack triggers always affect the mouse button bits.
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = ~this->buttons_state >> 8;
out_buf[3] = ~this->buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
}
return changed;
}
void AdbAppleJack::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case APPLEJACK_HANDLER_ID: // switch over to AppleJack protocol
this->dev_handler_id = in_data[1];
LOG_F(INFO, "%s: switched to AppleJack mode", this->name.c_str());
break;
default:
this->AdbMouse::set_register_3();
break;
}
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+60
View File
@@ -0,0 +1,60 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus AppleJack controller definitions. */
#ifndef ADB_APPLEJACK_H
#define ADB_APPLEJACK_H
#include <devices/common/adb/adbmouse.h>
#include <devices/common/hwcomponent.h>
#include <memory>
#include <string>
enum : uint8_t {
APPLEJACK_HANDLER_ID = 0x46,
};
class GamepadEvent;
class AdbAppleJack : public AdbMouse {
public:
AdbAppleJack(std::string name);
~AdbAppleJack() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbAppleJack>(new AdbAppleJack("ADB-APPLEJACK"));
}
void reset() override;
void event_handler(const GamepadEvent& event);
bool get_register_0() override;
void set_register_3() override;
private:
uint32_t buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
#endif // ADB_APPLEJACK_H
+31 -1
View File
@@ -25,6 +25,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/adb/adbdevice.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <sstream>
AdbBus::AdbBus(std::string name) {
this->set_name(name);
@@ -32,6 +34,30 @@ AdbBus::AdbBus(std::string name) {
this->devices.clear();
}
int AdbBus::device_postinit() {
std::string adb_device_list = GET_STR_PROP("adb_devices");
if (adb_device_list.empty())
return 0;
std::string adb_device;
std::istringstream adb_device_stream(adb_device_list);
while (getline(adb_device_stream, adb_device, ',')) {
string dev_name = "Adb" + adb_device;
if (dev_name == this->name)
continue; // don't register a second ADB bus
if (DeviceRegistry::device_registered(dev_name)) {
gMachineObj->add_device(dev_name, DeviceRegistry::get_descriptor(dev_name).m_create_func());
} else {
LOG_F(WARNING, "Unknown specified ADB device \"%s\"", adb_device.c_str());
}
}
return 0;
}
void AdbBus::register_device(AdbDevice* dev_obj) {
this->devices.push_back(dev_obj);
}
@@ -102,8 +128,12 @@ uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
return ADB_STAT_OK;
}
static const PropMap AdbBus_Properties = {
{"adb_devices", new StrProperty("Mouse,Keyboard")},
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, {}
AdbBus::create, {}, AdbBus_Properties
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+2
View File
@@ -51,6 +51,8 @@ public:
return std::unique_ptr<AdbBus>(new AdbBus("ADB-BUS"));
}
int device_postinit() override;
void register_device(AdbDevice* dev_obj);
uint8_t process_command(const uint8_t* in_data, int data_size);
uint8_t get_output_count() { return this->output_count; };
+25 -6
View File
@@ -28,7 +28,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <loguru.hpp>
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution) {
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset();
@@ -63,8 +64,10 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0() {
if (this->x_rel || this->y_rel || this->changed) {
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
uint8_t* p;
uint8_t* out_buf = this->host_obj->get_output_buf();
@@ -86,7 +89,7 @@ bool AdbMouse::get_register_0() {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((this->buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -100,13 +103,25 @@ bool AdbMouse::get_register_0() {
this->y_rel = 0;
this->changed = false;
this->host_obj->set_output_count(p - out_buf);
return true;
uint8_t count = (uint8_t)(p - out_buf);
// should never happen, but check just in case
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
count = UINT8_MAX;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1)
count = 2;
this->host_obj->set_output_count(count);
return should_update;
}
return false;
}
bool AdbMouse::get_register_0() {
return get_register_0(this->buttons_state, false);
}
bool AdbMouse::get_register_1() {
uint8_t* out_buf = this->host_obj->get_output_buf();
// Identifier
@@ -148,6 +163,10 @@ void AdbMouse::set_register_3() {
}
}
uint8_t AdbMouse::get_buttons_state() const {
return this->buttons_state;
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}
};
+24 -15
View File
@@ -35,19 +35,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class MouseEvent;
class AdbMouse : public AdbDevice {
public:
enum DeviceClass {
TABLET = 0,
MOUSE = 1,
TRACKBALL = 2,
};
public:
AdbMouse(std::string name);
AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution);
~AdbMouse() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbMouse>(new AdbMouse("ADB-MOUSE"));
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
return std::unique_ptr<AdbMouse>(
new AdbMouse("ADB-MOUSE", device_class, num_buttons, num_bits, resolution));
}
void reset() override;
@@ -57,6 +69,10 @@ public:
bool get_register_1() override;
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons_state, bool force);
uint8_t get_buttons_state() const;
private:
int32_t x_rel = 0;
int32_t y_rel = 0;
@@ -64,17 +80,10 @@ private:
int32_t y_abs = 0;
uint8_t buttons_state = 0;
bool changed = false;
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
uint8_t device_class;
int num_buttons;
int num_bits;
uint16_t resolution;
};
#endif // ADB_MOUSE_H
+10 -5
View File
@@ -46,6 +46,9 @@ void AtaBaseDevice::device_reset(bool is_soft_reset) {
// Diagnostic code
this->r_error = 1; // device 0 passed, device 1 passed or not present
// disable interrupts
this->r_dev_ctrl |= ATA_CTRL::IEN;
}
void AtaBaseDevice::device_set_signature() {
@@ -67,10 +70,11 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
this->chunk_cnt -= 2;
if (this->chunk_cnt <= 0) {
this->xfer_cnt -= this->chunk_size;
if (this->xfer_cnt <= 0)
if (this->xfer_cnt <= 0) {
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
else {
this->chunk_cnt = this->chunk_size;
} else {
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->update_intrq(1);
}
}
@@ -104,19 +108,20 @@ 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 (this->has_data()) {
if (is_selected() && this->has_data()) {
*this->cur_data_ptr++ = BYTESWAP_16(value);
this->chunk_cnt -= 2;
if (this->chunk_cnt <= 0) {
this->post_xfer_action();
this->xfer_cnt -= this->chunk_size;
if (this->xfer_cnt <= 0) { // transfer complete?
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
this->r_status &= ~BSY;
this->update_intrq(1);
} else {
this->cur_data_ptr = this->data_ptr;
this->chunk_cnt = this->chunk_size;
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
this->signal_data_ready();
}
}
+6 -2
View File
@@ -40,7 +40,10 @@ public:
AtaBaseDevice(const std::string name, uint8_t type);
~AtaBaseDevice() = default;
void set_host(IdeChannel* host) { this->host_obj = host; };
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;
@@ -89,10 +92,11 @@ protected:
uint8_t r_command;
uint8_t r_status;
uint8_t r_status_save;
uint8_t r_dev_ctrl = 0x08;
uint8_t r_dev_ctrl = 0x08 | ata_interface::ATA_CTRL::IEN; // disable interrupts
uint16_t *data_ptr = nullptr;
uint16_t *cur_data_ptr = nullptr;
alignas(uint16_t)
uint8_t data_buf[512] = {};
int xfer_cnt = 0;
int chunk_cnt = 0;
+1
View File
@@ -137,6 +137,7 @@ enum ATA_Cmd : uint8_t {
ATAPI_SERVICE = 0xA2,
READ_MULTIPLE = 0xC4,
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
READ_DMA = 0xC8,
WRITE_DMA = 0xCA,
STANDBY_IMMEDIATE_E0 = 0xE0,
+74 -11
View File
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <machines/machinebase.h>
#include <memaccess.h>
#include <bitset>
#include <cstring>
#include <fstream>
#include <string>
@@ -84,38 +85,79 @@ int AtaHardDisk::perform_command() {
switch (this->r_command) {
case NOP:
break;
case RECALIBRATE:
this->r_error = 0;
this->r_cylinder_lo = 0;
this->r_cylinder_hi = 0;
case ATAPI_SOFT_RESET: // for ATA devices, is a no-op
this->r_status &= ~BSY;
break;
case RECALIBRATE: // is optional in ATA-3; disappeared in >= ATA-4
// OF 3.1.1 won't boot off the drive that reports error for this command
this->r_cylinder_hi = 0;
this->r_cylinder_lo = 0;
this->r_dev_head &= 0xF0;
this->r_sect_num = (this->r_dev_head & ATA_Dev_Head::LBA) ? 0 : 1;
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case READ_MULTIPLE:
case READ_SECTOR:
case READ_SECTOR_NR: {
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
uint32_t ints_size = ATA_HD_SEC_SIZE;
if (this->r_command == READ_MULTIPLE) {
if (!this->sectors_per_int) {
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
this->r_status |= ERR;
this->r_status &= ~BSY;
break;
}
ints_size *= this->sectors_per_int;
}
hdd_img.read(buffer, offset, xfer_size);
this->data_ptr = (uint16_t *)this->buffer;
// those commands should generate IRQ for each sector
this->prepare_xfer(xfer_size, ATA_HD_SEC_SIZE);
this->prepare_xfer(xfer_size, ints_size);
this->signal_data_ready();
}
break;
case WRITE_MULTIPLE:
case WRITE_SECTOR:
case WRITE_SECTOR_NR: {
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
this->data_ptr = (uint16_t *)this->buffer;
this->cur_data_ptr = this->data_ptr;
this->prepare_xfer(sec_count * ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
uint32_t ints_size = ATA_HD_SEC_SIZE;
if (this->r_command == WRITE_MULTIPLE) {
if (!this->sectors_per_int) {
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
this->r_status |= ERR;
this->r_status &= ~BSY;
break;
}
ints_size *= this->sectors_per_int;
}
this->prepare_xfer(xfer_size, ints_size);
this->post_xfer_action = [this]() {
this->hdd_img.write(this->data_ptr, this->cur_fpos, this->chunk_size);
this->cur_fpos += this->chunk_size;
uint64_t write_len = (this->cur_data_ptr - this->data_ptr) * sizeof(this->data_ptr[0]);
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
this->cur_fpos += write_len;
};
this->r_status |= DRQ;
this->r_status &= ~BSY;
}
break;
case DIAGNOSTICS:
this->r_error = 1; // device 0 passed, device 1 passed or not present
this->device_set_signature();
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case READ_VERIFY: // verify sectors are readable, just no-op
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case INIT_DEV_PARAM:
// update fictive disk geometry with parameters from host
this->sectors = this->r_sect_count;
@@ -123,9 +165,20 @@ int AtaHardDisk::perform_command() {
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case DIAGNOSTICS:
this->r_error = 1;
this->device_set_signature();
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
this->name.c_str(), this->r_sect_count);
this->r_error |= ABRT;
this->r_status |= ERR;
} else {
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
this->r_sect_count);
this->sectors_per_int = this->r_sect_count;
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case FLUSH_CACHE: // used by the XNU kernel driver
this->r_status &= ~(BSY | DRQ | ERR);
@@ -186,6 +239,16 @@ void AtaHardDisk::prepare_identify_info() {
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
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;
// 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;
buf_ptr[ 1] = this->cylinders;
buf_ptr[ 3] = this->heads;
buf_ptr[ 6] = this->sectors;
+3 -2
View File
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#define ATA_HD_SEC_SIZE 512
#define SECTORS_PER_INT 16
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
#define ATA_BIOS_LIMIT 16514064
@@ -69,9 +70,9 @@ private:
uint8_t heads;
uint8_t sectors;
char * buffer = new char[1 <<17];
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
char * buffer = new char[1 <<17];
};
#endif // ATA_HARD_DISK_H
+5
View File
@@ -149,6 +149,11 @@ int AtapiBaseDevice::perform_command() {
this->r_status |= BSY;
switch (this->r_command) {
case ATAPI_SOFT_RESET:
this->device_reset(true);
this->device_set_signature();
this->r_status &= ~BSY;
break;
case ATAPI_PACKET:
this->data_ptr = (uint16_t *)this->cmd_pkt;
this->xfer_cnt = sizeof(this->cmd_pkt);
+1
View File
@@ -55,6 +55,7 @@ protected:
uint16_t r_byte_count;
bool status_expected = false;
alignas(uint16_t)
uint8_t cmd_pkt[12] = {};
};
+238
View File
@@ -0,0 +1,238 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller emulation. */
#include <devices/common/ata/cmd646.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
CmdIdeCtrl::CmdIdeCtrl() : PCIDevice("cmd-ide") {
this->supports_types(HWCompType::PCI_DEV | HWCompType::IDE_HOST);
// set up PCI configuration space header
this->vendor_id = this->subsys_vndr = PCI_VENDOR_SILICON_IMAGE;
this->device_id = this->subsys_id = DEV_ID_CMD646;
this->class_rev = ((MY_DEV_CLASS | this->prog_if) << 8) | MY_REV_ID;
this->max_lat = 4;
this->min_gnt = 2;
this->irq_pin = 1;
this->bars_cfg[0] = 0xFFFFFFF9; // Command block I/O space, primary channel
this->bars_cfg[1] = 0xFFFFFFFD; // Control block I/O space, primary channel
this->bars_cfg[2] = 0xFFFFFFF9; // Command block I/O space, secondary channel
this->bars_cfg[3] = 0xFFFFFFFD; // Control block I/O space, secondary channel
this->bars_cfg[4] = 0xFFFFFFF1; // Bus master I/O space, both channels
this->finish_config_bars();
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
gMachineObj->add_device("CmdAta0", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta0")));
gMachineObj->add_device("CmdAta1", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta1")));
this->ch0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta0"));
this->ch1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta1"));
this->ch0->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta0 INTRQ updated to %d", intrq_state);
this->update_irq(0, intrq_state);
});
this->ch1->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta1 INTRQ updated to %d", intrq_state);
this->update_irq(1, intrq_state);
});
}
uint32_t CmdIdeCtrl::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
if (reg_offs < 64)
return PCIDevice::pci_cfg_read(reg_offs, details);
if (details.size != 1)
ABORT_F("%s: non-byte read from PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
return this->read_config_reg(reg_offs + details.offset);
LOG_F(WARNING, "%s: reading config reg at 0x%X", this->name.c_str(), reg_offs);
return 0;
}
void CmdIdeCtrl::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) {
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, details);
return;
}
if (details.size != 1)
ABORT_F("%s: non-byte write to PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
this->write_config_reg(reg_offs + details.offset, value);
else
LOG_F(WARNING, "%s: writing config reg at 0x%X", this->name.c_str(), reg_offs);
}
void CmdIdeCtrl::notify_bar_change(int bar_num) {
if (bar_num >= 0 && bar_num <= 4)
this->io_bases[bar_num] = this->bars[bar_num] & ~3;
}
bool CmdIdeCtrl::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
*res = 0;
if ((offset & ~7) == this->io_bases[0]) {
*res = this->ch0->read(offset & 7, size);
} else if ((offset & ~7) == this->io_bases[2]) {
*res = this->ch1->read(offset & 7, size);
} else if ((offset & ~3) == this->io_bases[1]) {
*res = this->ch0->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~3) == this->io_bases[3]) {
*res = this->ch1->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
*res = this->read_bus_master_reg(offset & 0xF);
} else {
*res = 0xFFFFFFFFUL;
return false;
}
return true;
}
bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
if ((offset & ~7) == this->io_bases[0]) {
this->ch0->write(offset & 7, value, size);
} else if ((offset & ~7) == this->io_bases[2]) {
this->ch1->write(offset & 7, value, size);
} else if ((offset & ~3) == this->io_bases[1]) {
this->ch0->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~3) == this->io_bases[3]) {
this->ch1->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
this->write_bus_master_reg(offset & 0xF, value & 0xFFU);
} else
return false;
return true;
};
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
case ARTTIM0:
return this->addr_setup_time_0;
case DRWTIM0:
return this->data_rw_time_0;
case ARTTIM1:
return this->addr_setup_time_1;
case DRWTIM1:
return this->data_rw_time_1;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_config_reg(uint32_t reg_offset, uint8_t val) {
switch(reg_offset) {
case ARTTIM0:
this->addr_setup_time_0 = val;
LOG_F(9, "%s: ARTTIM0 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM0:
this->data_rw_time_0 = val;
LOG_F(9, "%s: DRWTIM0 set to 0x%X", this->name.c_str(), val);
break;
case ARTTIM1:
this->addr_setup_time_1 = val;
LOG_F(9, "%s: ARTTIM1 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM1:
this->data_rw_time_1 = val;
LOG_F(9, "%s: DRWTIM1 set to 0x%X", this->name.c_str(), val);
break;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
uint8_t CmdIdeCtrl::read_bus_master_reg(const uint8_t reg_offset) {
switch(reg_offset) {
case MRDMODE:
return this->mrdmode;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_bus_master_reg(const uint8_t reg_offset, const uint8_t val) {
switch(reg_offset) {
case MRDMODE:
if (val & BM_CH0_INT)
this->mrdmode &= ~BM_CH0_INT;
if (val & BM_CH1_INT)
this->mrdmode &= ~BM_CH1_INT;
this->mrdmode = (this->mrdmode & ~(BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT)) |
(val & (BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT));
LOG_F(INFO, "%s: MRDMODE set to 0x%X", this->name.c_str(), val);
if ((this->mrdmode & BM_CH0_INT) && !(this->mrdmode & BM_BLOCK_CH0_INT))
this->update_irq(0, 1);
if ((this->mrdmode & BM_CH1_INT) && !(this->mrdmode & BM_BLOCK_CH1_INT))
this->update_irq(1, 1);
break;
case UDIDETCR0:
this->udma_time_cr = val;
break;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
void CmdIdeCtrl::update_irq(const int ch_num, const uint8_t irq_level) {
bool forward_irq = !(this->mrdmode & (ch_num ? BM_BLOCK_CH1_INT : BM_BLOCK_CH0_INT));
if (irq_level)
this->mrdmode |= ch_num ? BM_CH1_INT : BM_CH0_INT;
else
this->mrdmode &= ~(ch_num ? BM_CH1_INT : BM_CH0_INT);
if (!irq_level || forward_irq)
this->irq_info.int_ctrl_obj->ack_int(this->irq_info.irq_id, irq_level);
}
static const DeviceDescription CmdIde_Descriptor = {
CmdIdeCtrl::create, {}, {}
};
REGISTER_DEVICE(CmdAta, CmdIde_Descriptor);
+115
View File
@@ -0,0 +1,115 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller definitions. */
#ifndef CMD646_IDE_H
#define CMD646_IDE_H
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/pci/pcidevice.h>
#include <memory>
#define DEV_ID_CMD646 0x646
#define MY_DEV_CLASS 0x010180 // mass storage | IDE controller | IDE master
#define MY_REV_ID 7
// Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel
#define DEV_CTRL_BLK_OFFSET 0x14
/** CMD646 control/status registers. */
enum {
ARTTIM0 = 0x53,
DRWTIM0 = 0x54,
ARTTIM1 = 0x55,
DRWTIM1 = 0x56,
};
/** CMD646 bus master registers. */
enum {
MRDMODE = 1, // misnomer, contains interrupt control/status bits (CMD646U2 specific)
UDIDETCR0 = 3, // Ultra DMA timing control register (CMD646U2 specific)
};
/** Bit definitions for the MRDMODE register. */
enum {
BM_CH0_INT = 1 << 2,
BM_CH1_INT = 1 << 3,
BM_BLOCK_CH0_INT = 1 << 4,
BM_BLOCK_CH1_INT = 1 << 5,
};
class CmdIdeCtrl : public PCIDevice {
public:
CmdIdeCtrl();
~CmdIdeCtrl() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<CmdIdeCtrl>(new CmdIdeCtrl());
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) override;
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) override;
int device_postinit() override {
this->irq_info = this->host_instance->register_pci_int(this);
return 0;
};
private:
void notify_bar_change(int bar_num);
uint8_t read_config_reg(uint32_t reg_offset);
void write_config_reg(uint32_t reg_offset, uint8_t val);
uint8_t read_bus_master_reg(const uint8_t reg_offset);
void write_bus_master_reg(const uint8_t reg_offset, const uint8_t val);
void update_irq(const int ch_num, const uint8_t irq_level);
// on reset, programming interface defaults to
// "both channels operating in native mode"
uint8_t prog_if = 0x0F;
uint32_t io_bases[5] = {};
IdeChannel *ch0 = nullptr;
IdeChannel *ch1 = nullptr;
// unknown default, set it to 2 clocks (60 ns)
uint8_t addr_setup_time_0 = 0x40; // address setup time for drive 0
uint8_t addr_setup_time_1 = 0x40; // address setup time for drive 1
uint8_t data_rw_time_0 = 0x00; // data read/write time for drive 0
uint8_t data_rw_time_1 = 0x00; // data read/write time for drive 1
uint8_t mrdmode = 0;
uint8_t udma_time_cr = 0;
IntDetails irq_info = {};
};
#endif // CMD646_IDE_H
+53 -38
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -22,8 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** IDE Channel (aka IDE port) emulation.
One IDE channel is capable of controlling up to two IDE devices.
This class handles device registration and passing of messages
IdeChannel class handles device registration and passing of messages
from and to the host.
MacioIdeChannel class implements MacIO specific registers
and interrupt handling.
*/
#include <devices/common/ata/atabasedevice.h>
@@ -51,62 +55,73 @@ IdeChannel::IdeChannel(const std::string name)
this->devices[1] = this->device_stub.get();
}
int IdeChannel::device_postinit() {
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id = this->int_ctrl->register_dev_int(
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
return 0;
}
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
if (id < 0 || id >= 2)
ABORT_F("%s: invalid device ID", this->name.c_str());
this->devices[id] = dev_obj;
((AtaBaseDevice*)dev_obj)->set_host(this);
((AtaBaseDevice*)dev_obj)->set_host(this, id);
}
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
{
if (reg_addr == TIME_CONFIG) {
if (size != 4) {
LOG_F(WARNING, "%s: non-DWORD read from the channel config", this->name.c_str());
}
return this->ch_config;
} else {
return this->devices[this->cur_dev]->read(reg_addr);
}
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size) {
return this->devices[this->cur_dev]->read(reg_addr);
}
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
{
if (reg_addr == TIME_CONFIG) {
if (size != 4) {
LOG_F(WARNING, "%s: non-DWORD write to the channel config", this->name.c_str());
}
this->ch_config = val;
} else {
// keep track of the currently selected device
if (reg_addr == DEVICE_HEAD) {
this->cur_dev = (val >> 4) & 1;
}
// keep track of the currently selected device
if (reg_addr == DEVICE_HEAD) {
this->cur_dev = (val >> 4) & 1;
}
// redirect register writes to both devices
for (auto& dev : this->devices) {
dev->write(reg_addr, val);
}
// redirect register writes to both devices
for (auto& dev : this->devices) {
dev->write(reg_addr, val);
}
}
int MacioIdeChannel::device_postinit() {
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id = this->int_ctrl->register_dev_int(
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
this->irq_callback = [this](const uint8_t intrq_state) {
this->int_ctrl->ack_int(this->irq_id, intrq_state);
};
return 0;
}
uint32_t MacioIdeChannel::read(const uint8_t reg_addr, const int size)
{
if (reg_addr == TIME_CONFIG) {
if (size != 4) {
LOG_F(WARNING, "%s: non-DWORD read from TIME_CONFIG", this->name.c_str());
}
return this->ch_config;
} else
return IdeChannel::read(reg_addr, size);
}
void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
{
if (reg_addr == TIME_CONFIG) {
if (size != 4) {
LOG_F(WARNING, "%s: non-DWORD write to TIME_CONFIG", this->name.c_str());
}
this->ch_config = val;
} else
IdeChannel::write(reg_addr, val, size);
}
static const DeviceDescription Ide0_Descriptor = {
IdeChannel::create_first, {}, {}
MacioIdeChannel::create_first, {}, {}
};
static const DeviceDescription Ide1_Descriptor = {
IdeChannel::create_second, {}, {}
MacioIdeChannel::create_second, {}, {}
};
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
+40 -19
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/hwinterrupt.h>
#include <cinttypes>
#include <functional>
#include <memory>
#include <string>
@@ -38,16 +39,6 @@ public:
IdeChannel(const std::string name);
~IdeChannel() = default;
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE0"));
}
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
}
int device_postinit() override;
void register_device(int id, AtaInterface* dev_obj);
uint32_t read(const uint8_t reg_addr, const int size);
@@ -55,26 +46,56 @@ public:
void assert_pdiag() {
this->devices[0]->pdiag_callback();
};
}
bool is_device1_present() {
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
}
void report_intrq(uint8_t intrq_state) {
this->int_ctrl->ack_int(this->irq_id, intrq_state);
void set_irq_callback(std::function<void(const uint8_t intrq_state)> cb) {
this->irq_callback = cb;
}
void report_intrq(uint8_t intrq_state) {
this->irq_callback(intrq_state);
}
protected:
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
private:
int cur_dev = 0;
uint32_t ch_config = 0; // timing configuration for this channel
AtaInterface* devices[2];
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
std::unique_ptr<AtaInterface> device_stub;
};
/** This class models an IDE channel specific to MacIO ASICs. */
class MacioIdeChannel : public IdeChannel
{
public:
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
~MacioIdeChannel() = default;
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE0"));
}
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE1"));
}
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);
private:
uint32_t ch_config = 0; // timing configuration for this channel
// interrupt stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
};
#endif // IDE_CHANNEL_H
+24 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -102,6 +102,7 @@ uint8_t DMAChannel::interpret_cmd() {
break;
case DBDMA_Cmd::INPUT_MORE:
case DBDMA_Cmd::INPUT_LAST:
this->xfer_from_device();
if (this->in_cb)
this->in_cb();
break;
@@ -194,8 +195,7 @@ void DMAChannel::finish_cmd() {
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
WRITE_WORD_LE_A(&cmd_desc[12], this->res_count);
this->queue_len = 0;
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
this->res_count = 0;
}
@@ -339,7 +339,9 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
// That means we need to update memory before channel operation
// is aborted to prevent data loss.
if (new_stat & CH_STAT_FLUSH) {
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST && this->flush_cb && (new_stat & CH_STAT_ACTIVE) && !(this->ch_stat & CH_STAT_DEAD)) {
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
!(this->ch_stat & CH_STAT_DEAD)) {
this->flush_cb();
} else {
// NOTE: because this implementation doesn't currently support
@@ -378,7 +380,8 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
break; // ingore writes to ChannelStatus
case DMAReg::CMD_PTR_HI:
if (value != 0) {
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x", this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
}
break;
case DMAReg::CMD_PTR_LO:
@@ -403,6 +406,20 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
}
}
void DMAChannel::xfer_from_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_FROM_DEV;
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
this->queue_len = 0;
this->finish_cmd();
}
this->interpret_cmd();
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
@@ -472,7 +489,8 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
void DMAChannel::end_pull_data() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
// dead or idle channel? -> no more data
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data", this->get_name().c_str());
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
this->get_name().c_str());
return;
}
+4 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -103,7 +103,7 @@ namespace DBDMA_Cmd {
typedef std::function<void(void)> DbdmaCallback;
class DMAChannel : public DmaBidirChannel {
class DMAChannel : public DmaBidirChannel, public DmaChannel {
public:
DMAChannel(std::string name) : DmaBidirChannel(name) {}
~DMAChannel() = default;
@@ -134,6 +134,7 @@ protected:
void finish_cmd();
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
void update_irq();
void xfer_from_device();
void start(void);
void resume(void);
@@ -164,4 +165,4 @@ private:
uint32_t irq_id = 0;
};
#endif /* DB_DMA_H */
#endif // DB_DMA_H
+50 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define DMA_CORE_H
#include <cstdint>
#include <cinttypes>
#include <string>
enum DmaPullResult : int {
@@ -75,4 +76,52 @@ private:
std::string name;
};
// ---------------------- New DMA API -------------------------
enum DmaMsg : unsigned {
CH_START = 1,
CH_STOP,
DATA_AVAIL,
};
enum XferDir : unsigned {
DMA_DIR_UNDEF = 0,
DMA_DIR_TO_DEV,
DMA_DIR_FROM_DEV,
};
class DmaChannel;
class DmaDevice {
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; };
protected:
DmaChannel* channel_obj = nullptr;
};
class DmaChannel {
public:
DmaChannel() = default;
~DmaChannel() = default;
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
void notify(DmaMsg msg) {};
protected:
DmaDevice* dev_obj = nullptr;
XferDir xfer_dir = DMA_DIR_UNDEF;
};
/*
TODO: write CONNECT macro that
- constructs both DmaChannel and DmaDevice objects
- calls connect() method on both objects
- initializes DMA interrupts
*/
#endif // DMA_CORE_H
+1
View File
@@ -46,6 +46,7 @@ enum HWCompType : uint64_t {
SCSI_HOST = 1ULL << 21, // SCSI host adapter
SCSI_DEV = 1ULL << 22, // SCSI device
IDE_BUS = 1ULL << 23, // IDE bus
IDE_HOST = 1ULL << 24, // IDE host controller
IDE_DEV = 1ULL << 25, // IDE device
SND_CODEC = 1ULL << 30, // sound codec
SND_SERVER = 1ULL << 31, // host sound server
+5
View File
@@ -88,4 +88,9 @@ public:
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
};
typedef struct {
InterruptCtrl *int_ctrl_obj;
uint32_t irq_id;
} IntDetails;
#endif // HW_INTERRUPT_H
+5 -5
View File
@@ -60,7 +60,7 @@ static uint32_t str2env(string& num_str) {
bool OfConfigAppl::validate() {
int i;
OfConfigHdrAppl hdr;
OfConfigHdrAppl hdr{};
if (this->nvram_obj == nullptr)
return false;
@@ -151,9 +151,9 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
// populate the remaining variables
for (auto& var : of_vars) {
auto name = var.first;
auto type = std::get<0>(var.second);
auto offset = std::get<1>(var.second);
auto& name = var.first;
auto type = std::get<0>(var.second);
auto offset = std::get<1>(var.second);
switch (type) {
case OF_VAR_TYPE_INT:
@@ -354,7 +354,7 @@ bool OfConfigChrp::validate()
if (!of_part_found)
return false;
OfConfigHdrChrp hdr;
OfConfigHdrChrp hdr{};
// read OF partition header
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
+1 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
+8 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -52,11 +52,12 @@ enum {
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
enum {
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_NVIDIA = 0x10DE,
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_SILICON_IMAGE = 0x1095,
PCI_VENDOR_NVIDIA = 0x10DE,
};
/** PCI BAR types */
@@ -142,7 +143,7 @@ protected:
void unmap_exp_rom_mem();
std::string pci_name; // human-readable device name
PCIHost* host_instance; // host bridge instance to call back
PCIHost* host_instance; // host bridge instance to call back
// PCI configuration space state (type 0, 1, and 2)
uint16_t vendor_id;
+14 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -165,14 +165,22 @@ void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
{
if (!(this->command & 1)) return false;
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
if (!(this->command & 1))
return false;
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
return false;
return this->pci_io_read_loop(offset, size, *res);
}
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
{
if (!(this->command & 1)) return false;
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
return this->pci_io_read_loop(offset, size, value);
if (!(this->command & 1))
return false;
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
return false;
return this->pci_io_write_loop(offset, size, value);
}
+1 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
+4
View File
@@ -50,6 +50,10 @@ public:
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);
bool supports_io_space() {
return true;
};
// plugin interface for using in the derived classes
std::function<uint8_t()> pci_rd_primary_bus;
std::function<void(uint8_t)> pci_wr_primary_bus;
+29 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -145,6 +145,27 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
return dev;
}
IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
bool dev_found = false;
int dev_fun_num = 0;
for (auto& dev : this->dev_map) {
if (dev.second == dev_instance) {
dev_fun_num = dev.first;
dev_found = true;
}
}
if (!dev_found)
ABORT_F("register_pci_int: requested device not found");
for (auto& irq : this->my_irq_map) {
if (irq.dev_fun_num == dev_fun_num)
return {this->int_ctrl, irq.irq_id};
}
ABORT_F("register_pci_int: no IRQ map for device 0x%X", dev_fun_num);
}
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
{
for (auto& dev : this->io_space_devs) {
@@ -168,11 +189,13 @@ bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
{
uint32_t res;
// broadcast I/O request to devices that support I/O space
// until a device returns true that means "request accepted"
if (pci_io_read_loop (offset, size, res)) {
if (pci_io_read_loop(offset, size, res))
return res;
}
// no device has accepted the request -> report error
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
@@ -187,9 +210,10 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
{
// broadcast I/O request to devices that support I/O space
// until a device returns true that means "request accepted"
if (pci_io_write_loop(offset, size, value)) {
if (pci_io_write_loop(offset, size, value))
return;
}
// no device has accepted the request -> report error
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
+20 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define PCI_HOST_H
#include <core/bitops.h>
#include <devices/common/hwinterrupt.h>
#include <endianswap.h>
#include <cinttypes>
@@ -49,6 +50,12 @@ typedef struct AccessDetails {
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
typedef struct {
const char * slot_name;
int dev_fun_num;
uint32_t irq_id;
} PciIrqMap;
class PCIBase;
class PCIBridgeBase;
@@ -81,10 +88,22 @@ public:
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
};
virtual IntDetails register_pci_int(PCIBase* dev_instance);
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
this->int_ctrl = int_ctrl_obj;
};
protected:
std::unordered_map<int, PCIBase*> dev_map;
std::vector<PCIBase*> io_space_devs;
std::vector<PCIBridgeBase*> bridge_devs;
std::vector<PciIrqMap> my_irq_map;
InterruptCtrl *int_ctrl = nullptr;
};
// Helpers for data conversion in the PCI Configuration space.
+130 -95
View File
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
#include <core/timermanager.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/scsi/mesh.h>
#include <devices/common/scsi/scsi.h>
@@ -35,6 +36,10 @@ 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->attach_scsi_devices("2");
}
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
@@ -45,15 +50,15 @@ int MeshController::device_postinit() {
void MeshController::reset(bool is_hard_reset) {
this->cur_cmd = SeqCmd::NoOperation;
this->fifo_cnt = 0;
this->fifo_pos = 0;
this->int_mask = 0;
this->exception = 0;
this->xfer_count = 0;
this->src_id = 7;
if (is_hard_reset) {
this->bus_stat = 0;
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
this->bus_stat = 0;
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
}
}
@@ -63,6 +68,8 @@ uint8_t MeshController::read(uint8_t reg_offset) {
return this->xfer_count & 0xFFU;
case MeshReg::XferCount1:
return (this->xfer_count >> 8) & 0xFFU;
case MeshReg::FIFO:
return this->fifo_pop();
case MeshReg::Sequence:
return this->cur_cmd;
case MeshReg::BusStatus0:
@@ -70,7 +77,7 @@ uint8_t MeshController::read(uint8_t reg_offset) {
case MeshReg::BusStatus1:
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
case MeshReg::FIFOCount:
return this->fifo_cnt;
return this->fifo_pos;
case MeshReg::Exception:
return this->exception;
case MeshReg::Error:
@@ -93,25 +100,26 @@ uint8_t MeshController::read(uint8_t reg_offset) {
}
void MeshController::write(uint8_t reg_offset, uint8_t value) {
uint16_t new_stat;
//uint16_t new_stat;
switch(reg_offset) {
case MeshReg::XferCount0:
this->xfer_count = (this->xfer_count & ~0xFFU) | value;
break;
case MeshReg::XferCount1:
this->xfer_count = (this->xfer_count & ~0xFF00U) | (value << 8);
break;
case MeshReg::FIFO:
this->fifo_push(value);
break;
case MeshReg::Sequence:
perform_command(value);
break;
case MeshReg::BusStatus0:
this->update_bus_status((this->bus_stat & 0xFF00U) | value);
break;
case MeshReg::BusStatus1:
new_stat = value << 8;
if (new_stat != this->bus_stat) {
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
if ((new_stat ^ this->bus_stat) & mask) {
if (new_stat & mask)
this->bus_obj->assert_ctrl_line(this->src_id, mask);
else
this->bus_obj->release_ctrl_line(this->src_id, mask);
}
}
this->bus_stat = new_stat;
}
this->update_bus_status((this->bus_stat & 0xFFU) | (value << 8));
break;
case MeshReg::IntMask:
this->int_mask = value;
@@ -143,21 +151,79 @@ void MeshController::perform_command(const uint8_t cmd) {
this->int_stat &= ~INT_CMD_DONE;
this->is_dma_cmd = !!(this->cur_cmd & 0x80);
switch (this->cur_cmd & 0xF) {
case SeqCmd::Arbitrate:
this->exception &= EXC_ARB_LOST;
this->bus_obj->release_ctrl_lines(this->src_id);
this->cur_state = SeqState::BUS_FREE;
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
this->sequencer();
break;
case SeqCmd::Select:
this->assert_atn = !!(this->cur_cmd & 0x20);
this->exception &= EXC_SEL_TIMEOUT;
this->cur_state = SeqState::SEL_BEGIN;
this->cur_state = Scsi_Bus_Controller::SeqState::SEL_BEGIN;
this->sequencer();
break;
case SeqCmd::Command:
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
LOG_F(WARNING, "%s: not in COMMAND phase", this->name.c_str());
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_CMD;
if (this->fifo_pos)
this->sequencer();
break;
case SeqCmd::Status:
if (this->bus_obj->current_phase() != ScsiPhase::STATUS)
LOG_F(WARNING, "%s: not in STATUS phase", this->name.c_str());
this->to_xfer = this->xfer_count;
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_STATUS;
this->sequencer();
break;
case SeqCmd::DataOut:
if (this->bus_obj->current_phase() != ScsiPhase::DATA_OUT)
LOG_F(WARNING, "%s: not in DATA OUT phase", this->name.c_str());
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
this->sequencer();
break;
case SeqCmd::DataIn:
if (this->bus_obj->current_phase() != ScsiPhase::DATA_IN)
LOG_F(WARNING, "%s: not in DATA IN phase", this->name.c_str());
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
this->sequencer();
break;
case SeqCmd::MessageOut:
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_OUT)
LOG_F(WARNING, "%s: not in MESSAGE OUT phase", this->name.c_str());
this->to_xfer = this->xfer_count;
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_MSG;
this->sequencer();
break;
case SeqCmd::MessageIn:
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_IN)
LOG_F(WARNING, "%s: not in MESSAGE IN phase", this->name.c_str());
this->to_xfer = this->xfer_count;
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_MESSAGE;
this->sequencer();
break;
case SeqCmd::BusFree:
LOG_F(INFO, "MESH: BusFree stub invoked");
this->int_stat |= INT_CMD_DONE;
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// generate phase mismatch exception
// if the target is still connected
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
this->exception |= EXC_PHASE_MM;
this->int_stat |= INT_EXCEPTION;
} else // say ok because we got the expected bus free phase
this->int_stat |= INT_CMD_DONE;
this->update_irq();
break;
case SeqCmd::EnaParityCheck:
this->check_parity = true;
break;
case SeqCmd::DisParityCheck:
this->check_parity = false;
break;
case SeqCmd::EnaReselect:
LOG_F(9, "MESH: EnaReselect stub invoked");
@@ -170,93 +236,62 @@ void MeshController::perform_command(const uint8_t cmd) {
case SeqCmd::ResetMesh:
this->reset(false);
this->int_stat |= INT_CMD_DONE;
update_irq();
break;
case SeqCmd::FlushFIFO:
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
this->int_stat |= INT_CMD_DONE;
this->fifo_pos = 0;
break;
default:
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
}
}
void MeshController::seq_defer_state(uint64_t delay_ns) {
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->cur_state = this->next_state;
this->sequencer();
});
void MeshController::update_bus_status(const uint16_t new_stat) {
uint16_t mask;
// update the lower part (BusStatus0)
if ((new_stat ^ this->bus_stat) & 0xFF) {
for (mask = SCSI_CTRL_REQ; mask >= SCSI_CTRL_IO; mask >>= 1) {
if ((new_stat ^ this->bus_stat) & mask) {
if (new_stat & mask)
this->bus_obj->assert_ctrl_line(this->src_id, mask);
else
this->bus_obj->release_ctrl_line(this->src_id, mask);
}
}
}
// update the upper part (BusStatus1)
if ((new_stat ^ this->bus_stat) & 0xFF00U) {
for (mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
if ((new_stat ^ this->bus_stat) & mask) {
if (new_stat & mask)
this->bus_obj->assert_ctrl_line(this->src_id, mask);
else
this->bus_obj->release_ctrl_line(this->src_id, mask);
}
}
}
this->bus_stat = new_stat;
}
void MeshController::sequencer()
{
switch (this->cur_state) {
case SeqState::IDLE:
break;
case SeqState::BUS_FREE:
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
this->next_state = SeqState::ARB_BEGIN;
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
} else { // continue waiting
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_FREE_DELAY);
}
break;
case SeqState::ARB_BEGIN:
if (!this->bus_obj->begin_arbitration(this->src_id)) {
LOG_F(ERROR, "MESH: arbitration error, bus not free!");
this->bus_obj->release_ctrl_lines(this->src_id);
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_CLEAR_DELAY);
break;
}
this->next_state = SeqState::ARB_END;
this->seq_defer_state(ARB_DELAY);
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->src_id) &&
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
} else { // arbitration lost
LOG_F(INFO, "MESH: arbitration lost!");
this->bus_obj->release_ctrl_lines(this->src_id);
this->exception |= EXC_ARB_LOST;
this->int_stat |= INT_EXCEPTION;
}
this->int_stat |= INT_CMD_DONE;
update_irq();
break;
case SeqState::SEL_BEGIN:
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->cur_cmd & 0x20);
this->next_state = SeqState::SEL_END;
this->seq_defer_state(SEL_TIME_OUT);
break;
case SeqState::SEL_END:
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
LOG_F(9, "MESH: selection completed");
} else { // selection timeout
this->bus_obj->disconnect(this->src_id);
this->cur_state = SeqState::IDLE;
this->exception |= EXC_SEL_TIMEOUT;
this->int_stat |= INT_EXCEPTION;
}
this->int_stat |= INT_CMD_DONE;
update_irq();
void MeshController::step_completed() {
this->int_stat |= INT_CMD_DONE;
update_irq();
}
void MeshController::report_error(const int error) {
switch(error) {
case SEL_TIMEOUT:
this->exception |= EXC_SEL_TIMEOUT;
this->int_stat |= INT_EXCEPTION;
break;
default:
ABORT_F("MESH: unimplemented sequencer state %d", this->cur_state);
}
}
void MeshController::update_irq() {
uint8_t new_irq = !!(this->int_stat & this->int_mask);
if (new_irq != this->irq) {
this->irq = new_irq;
this->int_ctrl->ack_int(this->irq_id, new_irq);
ABORT_F("%s: unhandled error %d", this->name.c_str(), error);
}
this->int_stat |= INT_CMD_DONE;
update_irq();
}
static const PropMap Mesh_properties = {
+78 -110
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -25,106 +25,96 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define MESH_H
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/scsibusctrl.h>
#include <cinttypes>
#include <memory>
class InterruptCtrl;
class ScsiBus;
// Chip ID returned by the MESH ASIC on TNT machines (Apple part 343S1146-a)
#define TntMeshID 0xE2
// Chip ID returned by the MESH cell inside the Heathrow ASIC
#define HeathrowMESHID 4
#define HeathrowMeshID 4
namespace MeshScsi {
/** MESH registers offsets. */
enum MeshReg : uint8_t {
XferCount0 = 0,
XferCount1 = 1,
FIFO = 2,
Sequence = 3,
BusStatus0 = 4,
BusStatus1 = 5,
FIFOCount = 6,
Exception = 7,
Error = 8,
IntMask = 9,
Interrupt = 0xA,
SourceID = 0xB,
DestID = 0xC,
SyncParms = 0xD,
MeshID = 0xE,
SelTimeOut = 0xF
};
// MESH registers offsets.
enum MeshReg : uint8_t {
XferCount0 = 0,
XferCount1 = 1,
FIFO = 2,
Sequence = 3,
BusStatus0 = 4,
BusStatus1 = 5,
FIFOCount = 6,
Exception = 7,
Error = 8,
IntMask = 9,
Interrupt = 0xA,
SourceID = 0xB,
DestID = 0xC,
SyncParms = 0xD,
MeshID = 0xE,
SelTimeOut = 0xF
};
/** MESH Sequencer commands. */
enum SeqCmd : uint8_t {
NoOperation = 0x0,
Arbitrate = 0x1,
Select = 0x2,
Command = 0x3,
Status = 0x4,
DataOut = 0x5,
DataIn = 0x6,
MessageOut = 0x7,
MessageIn = 0x8,
BusFree = 0x9,
EnaParityCheck = 0xA,
DisParityCheck = 0xB,
EnaReselect = 0xC,
DisReselect = 0xD,
ResetMesh = 0xE,
FlushFIFO = 0xF
};
// MESH Sequencer commands.
enum SeqCmd : uint8_t {
NoOperation = 0,
Arbitrate = 1,
Select = 2,
BusFree = 9,
EnaReselect = 0xC,
DisReselect = 0xD,
ResetMesh = 0xE,
FlushFIFO = 0xF,
};
// Exception register bits.
enum {
EXC_SEL_TIMEOUT = 1 << 0,
EXC_PHASE_MM = 1 << 1,
EXC_ARB_LOST = 1 << 2,
};
// Interrupt register bits.
enum {
INT_CMD_DONE = 1 << 0,
INT_EXCEPTION = 1 << 1,
INT_ERROR = 1 << 2,
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
};
enum SeqState : uint32_t {
IDLE = 0,
BUS_FREE,
ARB_BEGIN,
ARB_END,
SEL_BEGIN,
SEL_END,
SEND_MSG,
SEND_CMD,
CMD_COMPLETE,
XFER_BEGIN,
XFER_END,
SEND_DATA,
RCV_DATA,
RCV_STATUS,
RCV_MESSAGE,
};
/** Exception register bits. */
enum {
EXC_SEL_TIMEOUT = 1 << 0,
EXC_PHASE_MM = 1 << 1,
EXC_ARB_LOST = 1 << 2,
};
/** Interrupt register bits. */
enum {
INT_CMD_DONE = 1 << 0,
INT_EXCEPTION = 1 << 1,
INT_ERROR = 1 << 2,
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
};
}; // namespace MeshScsi
class MeshStub : public HWComponent {
class MeshBase {
public:
MeshBase() = default;
~MeshBase() = default;
virtual uint8_t read(uint8_t reg_offset) = 0;
virtual void write(uint8_t reg_offset, uint8_t value) = 0;
};
class MeshStub : public MeshBase {
public:
MeshStub() = default;
~MeshStub() = default;
// registers access
uint8_t read(uint8_t reg_offset) { return 0; };
void write(uint8_t reg_offset, uint8_t value) {};
uint8_t read(uint8_t reg_offset) override { return 0; };
void write(uint8_t reg_offset, uint8_t value) override {};
};
class MeshController : public HWComponent {
class MeshController : public ScsiBusController, public MeshBase {
public:
MeshController(uint8_t mesh_id) {
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
this->chip_id = mesh_id;
this->set_name("MESH");
this->reset(true);
};
~MeshController() = default;
@@ -134,55 +124,33 @@ public:
}
static std::unique_ptr<HWComponent> create_for_heathrow() {
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
return std::unique_ptr<MeshController>(new MeshController(HeathrowMeshID));
}
// MESH registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
// MeshBase methods
uint8_t read(uint8_t reg_offset) override;
void write(uint8_t reg_offset, uint8_t value) override;
// HWComponent methods
int device_postinit();
int device_postinit() override;
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
};
// ScsiBusController methods
void step_completed() override;
void report_error(const int error) override;
protected:
void reset(bool is_hard_reset);
void perform_command(const uint8_t cmd);
void seq_defer_state(uint64_t delay_ns);
void sequencer();
void update_irq();
void update_bus_status(const uint16_t new_stat);
private:
uint8_t chip_id;
uint8_t int_mask = 0;
uint8_t int_stat = 0;
uint8_t sync_params;
uint8_t src_id;
uint8_t dst_id;
uint8_t cur_cmd;
uint8_t error;
uint8_t fifo_cnt;
uint8_t exception = 0;
uint32_t xfer_count;
ScsiBus* bus_obj;
uint8_t exception = 0;
uint16_t bus_stat;
// Sequencer state
uint32_t seq_timer_id;
uint32_t cur_state;
uint32_t next_state;
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq = 0;
// DMA related stuff
DmaBidirChannel* dma_ch;
bool check_parity = true;
};
#endif // MESH_H
+3 -4
View File
@@ -172,7 +172,7 @@ uint16_t Sc53C94::pseudo_dma_read()
// remove one word from FIFO
data_word = (this->data_fifo[0] << 8) | this->data_fifo[1];
this->data_fifo_pos -= 2;
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
std::memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
// update DMA status
if (this->is_dma_cmd) {
@@ -328,8 +328,7 @@ void Sc53C94::exec_command()
this->bus_obj->target_next_step();
}
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->int_status = INTSTAT_SR;
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
this->update_irq();
exec_next_command();
break;
@@ -403,7 +402,7 @@ uint8_t Sc53C94::fifo_pop()
} else {
data = this->data_fifo[0];
this->data_fifo_pos--;
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
std::memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
}
return data;
+13 -10
View File
@@ -142,16 +142,17 @@ enum ScsiSense : int {
};
enum ScsiError : int {
NO_ERROR = 0x00,
NO_SECTOR = 0x01,
WRITE_FAULT = 0x03,
DEV_NOT_READY = 0x04,
INVALID_CMD = 0x20,
INVALID_LBA = 0x21,
INVALID_CDB = 0x24,
INVALID_LUN = 0x25,
WRITE_PROTECT = 0x27,
MEDIUM_NOT_PRESENT = 0x3A,
NO_ERROR = 0x00,
NO_SECTOR = 0x01,
WRITE_FAULT = 0x03,
DEV_NOT_READY = 0x04,
INVALID_CMD = 0x20,
INVALID_LBA = 0x21,
INVALID_CDB = 0x24,
INVALID_LUN = 0x25,
WRITE_PROTECT = 0x27,
SAVING_NOT_SUPPORTED = 0x39,
MEDIUM_NOT_PRESENT = 0x3A,
};
/** Standard SCSI bus timing values measured in ns. */
@@ -199,6 +200,8 @@ public:
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
+290
View File
@@ -0,0 +1,290 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file SCSI bus controller emulation. */
#include <core/timermanager.h>
#include <devices/common/scsi/scsibusctrl.h>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
using namespace Scsi_Bus_Controller;
void ScsiBusController::seq_defer_state(uint64_t delay_ns) {
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->cur_state = this->next_state;
this->sequencer();
});
}
void ScsiBusController::sequencer() {
switch (this->cur_state) {
case SeqState::IDLE:
break;
case SeqState::BUS_FREE:
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
this->next_state = SeqState::ARB_BEGIN;
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
} else { // continue waiting
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_FREE_DELAY);
}
break;
case SeqState::ARB_BEGIN:
if (!this->bus_obj->begin_arbitration(this->src_id)) {
LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str());
this->bus_obj->release_ctrl_lines(this->src_id);
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_CLEAR_DELAY);
break;
}
this->next_state = SeqState::ARB_END;
this->seq_defer_state(ARB_DELAY);
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->src_id) &&
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
this->step_completed();
} else { // arbitration lost
LOG_F(ERROR, "%s: arbitration lost!", this->name.c_str());
this->bus_obj->release_ctrl_lines(this->src_id);
this->report_error(ARB_LOST);
}
break;
case SeqState::SEL_BEGIN:
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->assert_atn);
this->next_state = SeqState::SEL_END;
this->seq_defer_state(SEL_TIME_OUT);
break;
case SeqState::SEL_END:
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
LOG_F(9, "%s: selection completed", this->name.c_str());
this->step_completed();
} else { // selection timeout
this->bus_obj->disconnect(this->src_id);
this->cur_state = SeqState::IDLE;
this->report_error(SEL_TIMEOUT);
}
break;
case SeqState::SEND_MSG:
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)
this->step_completed();
}
break;
case SeqState::SEND_CMD:
this->bus_obj->target_xfer_data();
if (!this->fifo_pos)
this->step_completed();
break;
case SeqState::XFER_BEGIN:
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
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();
}
break;
case SeqState::XFER_END:
if (this->is_initiator)
this->bus_obj->target_next_step();
this->step_completed();
break;
case SeqState::SEND_DATA:
if (this->bus_obj->push_data(this->dst_id, this->data_fifo, this->fifo_pos)) {
this->to_xfer -= this->fifo_pos;
this->fifo_pos = 0;
if (this->to_xfer <= 0) {
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
}
break;
case SeqState::RCV_DATA:
// check for unexpected bus phase changes
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
LOG_F(WARNING, "%s: phase mismatch!", this->name.c_str());
} else {
if (!this->rcv_data()) {
this->cur_state = SeqState::XFER_END;
this->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)
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;
}
break;
default:
ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(),
this->cur_state);
}
}
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
if (this->dst_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
seq_timer_id = 0;
this->cur_state = SeqState::SEL_END;
this->sequencer();
} else {
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
this->name.c_str());
}
break;
case ScsiMsg::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
#if 0
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
}
#endif
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
msg_type);
}
}
bool ScsiBusController::rcv_data() {
int req_count;
// return if REQ line is negated
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_REQ)) {
return false;
}
if (!this->to_xfer)
return false;
req_count = std::min(this->to_xfer, DATA_FIFO_DEPTH - this->fifo_pos);
this->bus_obj->pull_data(this->dst_id, &this->data_fifo[this->fifo_pos], req_count);
this->fifo_pos += req_count;
this->to_xfer -= req_count;
return true;
}
int ScsiBusController::send_data(uint8_t* dst_ptr, int count) {
if (dst_ptr == nullptr || !count)
return 0;
int actual_count = std::min(this->fifo_pos, count);
// move data out of the data FIFO
std::memcpy(dst_ptr, this->data_fifo, actual_count);
// remove the just readed data from the data FIFO
this->fifo_pos -= actual_count;
this->to_xfer -= actual_count;
if (this->fifo_pos > 0)
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->fifo_pos);
return actual_count;
}
int ScsiBusController::xfer_from(uint8_t *buf, int len) {
if (len > this->to_xfer + this->fifo_pos)
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
if (this->fifo_pos) {
int fifo_bytes = std::min(this->fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->fifo_pos -= fifo_bytes;
len -= fifo_bytes;
buf += fifo_bytes;
}
int dma_bytes = std::min(this->to_xfer, len);
if (this->bus_obj->pull_data(this->dst_id, buf, dma_bytes)) {
this->to_xfer -= dma_bytes;
if (this->to_xfer <= 0) {
this->xfer_count = this->to_xfer;
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
return 0;
}
return len;
}
void ScsiBusController::update_irq() {
uint8_t new_irq = !!(this->int_stat & this->int_mask);
if (new_irq != this->irq) {
this->irq = new_irq;
this->int_ctrl->ack_int(this->irq_id, new_irq);
}
}
void ScsiBusController::fifo_push(const uint8_t data) {
if (this->fifo_pos < DATA_FIFO_DEPTH) {
this->data_fifo[this->fifo_pos++] = data;
if (!this->xfer_count)
LOG_F(WARNING, "%s: zero xfer_count!", this->name.c_str());
if (--this->xfer_count == 0)
this->sequencer();
} else
this->sequencer();
}
uint8_t ScsiBusController::fifo_pop() {
uint8_t data = 0;
if (this->fifo_pos) {
data = this->data_fifo[0];
if (--this->fifo_pos)
std::memmove(this->data_fifo, &this->data_fifo[1], this->fifo_pos);
}
// see if we need to refill FIFO
if (!this->fifo_pos)
this->sequencer();
return data;
}
+122
View File
@@ -0,0 +1,122 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file SCSI bus controller definitions. */
#ifndef SCSI_BUS_CTRL_H
#define SCSI_BUS_CTRL_H
#include <devices/common/dmacore.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/scsi/scsi.h>
#include <cinttypes>
#include <string>
namespace Scsi_Bus_Controller {
/** SCSI sequencer states. */
enum SeqState : uint32_t {
IDLE = 0,
BUS_FREE,
ARB_BEGIN,
ARB_END,
SEL_BEGIN,
SEL_END,
SEND_MSG,
SEND_CMD,
CMD_COMPLETE,
XFER_BEGIN,
XFER_END,
SEND_DATA,
RCV_DATA,
RCV_STATUS,
RCV_MESSAGE,
};
};
/** Sequencer error codes. */
enum : int {
ARB_LOST = 1,
SEL_TIMEOUT,
};
#define DATA_FIFO_DEPTH 16
class ScsiBusController : public ScsiDevice, public DmaDevice {
public:
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
}
~ScsiBusController() = default;
// implements SCSI FSM
void sequencer();
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; };
bool rcv_data();
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
// DmaDevice methods
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
protected:
void seq_defer_state(uint64_t delay_ns);
void update_irq();
void fifo_push(const uint8_t data);
uint8_t fifo_pop();
ScsiBus* bus_obj = nullptr;
uint8_t src_id;
uint8_t dst_id;
bool is_dma_cmd = false;
bool is_initiator = true;
bool assert_atn = false;
// Data FIFO state
int fifo_pos = 0;
int to_xfer = 0;
uint32_t xfer_count = 0;
int bytes_out = 0;
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
// Sequencer state
uint32_t seq_timer_id = 0;
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
int cur_bus_phase = 0;
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq = 0;
uint8_t int_mask = 0;
uint8_t int_stat = 0;
};
#endif // SCSI_BUS_CTRL_H
+12 -82
View File
@@ -34,6 +34,11 @@ using namespace std;
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
{
this->set_error_callback(
[this](uint8_t sense_key, uint8_t asc) {
this->report_error(sense_key, asc);
}
);
}
void ScsiCdrom::process_command()
@@ -85,7 +90,11 @@ void ScsiCdrom::process_command()
// CD-ROM specific commands
case ScsiCommand::READ_TOC:
this->read_toc();
this->bytes_out = 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]);
@@ -239,7 +248,7 @@ void ScsiCdrom::mode_sense_6()
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 = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
@@ -270,85 +279,6 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
this->switch_phase(ScsiPhase::DATA_OUT);
}
void ScsiCdrom::read_toc()
{
int tot_tracks;
uint8_t start_track = this->cmd_buf[6];
uint16_t alloc_len = (this->cmd_buf[7] << 8) + this->cmd_buf[8];
bool is_msf = !!(this->cmd_buf[1] & 2);
if (this->cmd_buf[2] & 0xF) {
ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str());
}
if (!alloc_len) {
LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str());
return;
}
if (!start_track) { // special case: track zero (lead-in) as starting track
// return all tracks starting with track 1 plus lead-out
start_track = 1;
tot_tracks = this->num_tracks + 1;
} else if (start_track == LEAD_OUT_TRK_NUM) {
start_track = this->num_tracks + 1;
tot_tracks = 1;
} else if (start_track <= this->num_tracks) {
tot_tracks = (this->num_tracks - start_track) + 2;
} else {
LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(),
start_track);
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x24; // Invalid Field in CDB
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 6; // offset of start_track
this->switch_phase(ScsiPhase::STATUS);
return;
}
uint8_t* buf_ptr = this->data_buf;
int data_len = (tot_tracks * 8) + 2;
// write TOC data header
*buf_ptr++ = (data_len >> 8) & 0xFFU;
*buf_ptr++ = (data_len >> 0) & 0xFFU;
*buf_ptr++ = 1; // 1st track number
*buf_ptr++ = this->num_tracks; // last track number
for (int tx = 0; tx < tot_tracks; tx++) {
if ((buf_ptr - this->data_buf + 8) > alloc_len)
break; // exit the loop if the output buffer length is exhausted
TrackDescriptor& td = this->tracks[start_track + tx - 1];
*buf_ptr++ = 0; // reserved
*buf_ptr++ = td.adr_ctrl;
*buf_ptr++ = td.trk_num;
*buf_ptr++ = 0; // reserved
if (is_msf) {
AddrMsf msf = lba_to_msf(td.start_lba + 150);
*buf_ptr++ = 0; // reserved
*buf_ptr++ = msf.min;
*buf_ptr++ = msf.sec;
*buf_ptr++ = msf.frm;
} else {
*buf_ptr++ = (td.start_lba >> 24) & 0xFFU;
*buf_ptr++ = (td.start_lba >> 16) & 0xFFU;
*buf_ptr++ = (td.start_lba >> 8) & 0xFFU;
*buf_ptr++ = (td.start_lba >> 0) & 0xFFU;
}
}
this->bytes_out = alloc_len;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
void ScsiCdrom::read_capacity_10()
{
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
@@ -361,7 +291,7 @@ void ScsiCdrom::read_capacity_10()
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 = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 8;
-1
View File
@@ -48,7 +48,6 @@ protected:
void mode_select_6(uint8_t param_len);
void mode_sense_6();
void read_toc();
void read_capacity_10();
private:
+15 -7
View File
@@ -95,6 +95,7 @@ void ScsiDevice::next_step()
}
break;
case ScsiPhase::STATUS:
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
this->switch_phase(ScsiPhase::MESSAGE_IN);
break;
case ScsiPhase::MESSAGE_OUT:
@@ -221,13 +222,12 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
return count;
}
bool ScsiDevice::check_lun()
{
bool ScsiDevice::check_lun() {
if (this->cmd_buf[1] >> 5 != this->lun) {
LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x25; // Logical Unit Not Supported
this->asc = ScsiError::INVALID_LUN;
this->ascq = 0;
this->sksv = 0;
this->field = 0;
@@ -237,14 +237,22 @@ bool ScsiDevice::check_lun()
return true;
}
void ScsiDevice::illegal_command(const uint8_t *cmd)
{
void ScsiDevice::illegal_command(const uint8_t *cmd) {
LOG_F(ERROR, "%s: unsupported command: 0x%02x", this->name.c_str(), cmd[0]);
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x20; // Invalid command operation code
this->asc = ScsiError::INVALID_CMD;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 0;
this->switch_phase(ScsiPhase::STATUS);
}
void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = sense_key;
this->asc = asc;
this->ascq = 0;
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->switch_phase(ScsiPhase::STATUS);
}
+13 -60
View File
@@ -66,18 +66,12 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::TEST_UNIT_READY:
this->test_unit_ready();
break;
case ScsiCommand::REWIND:
this->illegal_command(cmd);
break;
case ScsiCommand::REQ_SENSE:
this->req_sense(cmd[4]);
break;
case ScsiCommand::FORMAT_UNIT:
this->format();
break;
case ScsiCommand::READ_BLK_LIMITS:
this->illegal_command(cmd);
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
@@ -86,36 +80,15 @@ void ScsiHardDisk::process_command() {
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->write(lba, cmd[4], 6);
break;
case ScsiCommand::SEEK_6:
this->illegal_command(cmd);
break;
case ScsiCommand::INQUIRY:
this->inquiry();
break;
case ScsiCommand::VERIFY_6:
this->illegal_command(cmd);
break;
case ScsiCommand::MODE_SELECT_6:
mode_select_6(cmd[4]);
break;
case ScsiCommand::RELEASE_UNIT:
this->illegal_command(cmd);
break;
case ScsiCommand::ERASE_6:
this->illegal_command(cmd);
break;
case ScsiCommand::MODE_SENSE_6:
this->mode_sense_6();
break;
case ScsiCommand::START_STOP_UNIT:
this->illegal_command(cmd);
break;
case ScsiCommand::DIAG_RESULTS:
this->illegal_command(cmd);
break;
case ScsiCommand::SEND_DIAGS:
this->illegal_command(cmd);
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
this->eject_allowed = (cmd[4] & 1) == 0;
this->switch_phase(ScsiPhase::STATUS);
@@ -135,29 +108,9 @@ void ScsiHardDisk::process_command() {
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
this->switch_phase(ScsiPhase::DATA_OUT);
break;
case ScsiCommand::VERIFY_10:
this->illegal_command(cmd);
break;
case ScsiCommand::READ_BUFFER:
read_buffer();
break;
case ScsiCommand::MODE_SENSE_10:
this->illegal_command(cmd);
break;
case ScsiCommand::READ_12:
this->illegal_command(cmd);
break;
// CD-ROM specific commands
case ScsiCommand::READ_TOC:
this->illegal_command(cmd);
break;
case ScsiCommand::SET_CD_SPEED:
this->illegal_command(cmd);
break;
case ScsiCommand::READ_CD:
this->illegal_command(cmd);
break;
default:
this->illegal_command(cmd);
}
@@ -205,7 +158,7 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
//if (!check_lun())
// return;
int next_phase;
//int next_phase;
int lun;
if (this->last_selection_has_atention) {
@@ -226,7 +179,7 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
}
else {
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
this->data_buf[12] = 0x25; // addition sense code = Logical Unit Not Supported
this->data_buf[12] = ScsiError::INVALID_LUN; // addition sense code = Logical Unit Not Supported
this->data_buf[13] = 0; // additional sense qualifier
this->data_buf[15] = 0; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
this->data_buf[16] = 0; // field pointer
@@ -339,9 +292,9 @@ void ScsiHardDisk::mode_sense_6() {
LOG_F(INFO, "%s: page_ctrl 1 CHANGEABLE VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
@@ -351,9 +304,9 @@ void ScsiHardDisk::mode_sense_6() {
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
@@ -363,7 +316,7 @@ void ScsiHardDisk::mode_sense_6() {
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x39; // Saving Parameters Not Supported
this->asc = SAVING_NOT_SUPPORTED;
this->ascq = 0;
this->sksv = 0;
this->field = 0;
@@ -428,9 +381,9 @@ void ScsiHardDisk::mode_sense_6() {
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 = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
@@ -438,9 +391,9 @@ void ScsiHardDisk::mode_sense_6() {
LOG_F(WARNING, "%s: unsupported page/subpage %02xh/%02xh in MODE_SENSE_6", this->name.c_str(), page_code, sub_page_code);
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 3;
this->switch_phase(ScsiPhase::STATUS);
return;
@@ -465,9 +418,9 @@ void ScsiHardDisk::read_capacity_10() {
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 = 0x24; // Invalid Field in CDB
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 8;
this->switch_phase(ScsiPhase::STATUS);
return;
+142 -116
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,24 +47,21 @@ ViaCuda::ViaCuda() {
// VIA reset clears all internal registers to logic 0
// except timers/counters and the shift register
// as stated in the 6522 datasheet
this->via_regs[VIA_A] = 0;
this->via_regs[VIA_B] = 0;
this->via_regs[VIA_DIRB] = 0;
this->via_regs[VIA_DIRA] = 0;
this->via_regs[VIA_IER] = 0;
this->via_regs[VIA_ACR] = 0;
this->via_regs[VIA_PCR] = 0;
this->via_regs[VIA_IFR] = 0;
this->via_porta = 0;
this->via_portb = 0;
this->via_ddrb = 0;
this->via_ddra = 0;
this->via_acr = 0;
this->via_pcr = 0;
// load maximum value into the timer registers for safety
// (not prescribed in the 6522 datasheet)
this->via_regs[VIA_T1LL] = 0xFF;
this->via_regs[VIA_T1LH] = 0xFF;
this->via_regs[VIA_T2CL] = 0xFF;
this->via_regs[VIA_T2CH] = 0xFF;
this->via_t1ll = 0xFF;
this->via_t1lh = 0xFF;
this->via_t2cl = 0xFF;
this->_via_ifr = 0; // all flags cleared
this->_via_ier = 0; // all interrupts disabled
this->_via_ifr = 0; // all flags cleared
this->_via_ier = 0; // all interrupts disabled
// intialize counters/timers
this->t1_counter = 0xFFFF;
@@ -138,73 +135,151 @@ void ViaCuda::cuda_init() {
uint8_t ViaCuda::read(int reg) {
uint8_t value;
/* reading from some VIA registers triggers special actions */
switch (reg & 0xF) {
case VIA_B:
value = (this->via_regs[VIA_B]);
break;
return this->via_portb; //(this->via_portb & ~this->via_ddrb) | this->last_orb;
case VIA_A:
case VIA_ANH:
value = this->via_regs[reg & 0xF];
LOG_F(WARNING, "Attempted read from VIA Port A!");
break;
case VIA_IER:
value = (this->_via_ier | 0x80); // bit 7 always reads as "1"
break;
case VIA_IFR:
value = this->_via_ifr;
break;
return this->via_porta;
case VIA_DIRB:
return this->via_ddrb;
case VIA_DIRA:
return this->via_ddra;
case VIA_T1CL:
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
value = this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
break;
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
case VIA_T1CH:
value = this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
break;
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
case VIA_T1LL:
return this->via_t1ll;
case VIA_T1LH:
return this->via_t1lh;
case VIA_T2CL:
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
value = this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
break;
return this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
case VIA_T2CH:
value = this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
break;
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
case VIA_SR:
value = this->via_regs[reg & 0xF];
value = this->via_sr;
this->_via_ifr &= ~VIA_IF_SR;
update_irq();
break;
default:
value = this->via_regs[reg & 0xF];
return value;
case VIA_ACR:
return this->via_acr;
case VIA_PCR:
return this->via_pcr;
case VIA_IFR:
return this->_via_ifr;
case VIA_IER:
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
}
return value;
return 0; // should never happen!
}
void ViaCuda::write(int reg, uint8_t value) {
this->via_regs[reg & 0xF] = value;
switch (reg & 0xF) {
case VIA_B:
this->write(value);
this->last_orb = value & this->via_ddrb;
this->via_portb = (this->via_portb & ~this->via_ddrb) | this->last_orb;
// ensure the proper VIA configuration before calling Cuda
if ((this->via_ddrb & 0x38) == 0x30)
this->write(this->via_portb);
break;
case VIA_A:
case VIA_ANH:
this->via_porta = value;
LOG_F(WARNING, "Attempted write to VIA Port A!");
break;
case VIA_DIRB:
this->via_ddrb = value;
LOG_F(9, "VIA_DIRB = 0x%X", value);
break;
case VIA_DIRA:
this->via_ddra = value;
LOG_F(9, "VIA_DIRA = 0x%X", value);
break;
case VIA_PCR:
LOG_F(9, "VIA_PCR = 0x%X", value);
case VIA_T1CL:
this->via_t1cl = value;
break;
case VIA_T1CH:
if (this->via_acr & 0xC0) {
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
}
// cancel active T1 timer task
if (this->t1_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
this->t1_timer_id = 0;
}
// clear T1 flag in IFR
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
// load initial value into counter 1
this->t1_counter = (value << 8) | this->via_t1cl;
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
// set up timout timer for T1
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
this->t1_timer_id = 0;
this->assert_t1_int();
}
);
break;
case VIA_T1LL:
this->via_t1ll = value;
break;
case VIA_T1LH:
this->via_t1lh = value;
break;
case VIA_T2CL:
this->via_t2cl = value;
break;
case VIA_T2CH:
if (this->via_acr & 0x20) {
ABORT_F("VIA T2 pulse count mode not supported!");
}
// cancel active T2 timer task
if (this->t2_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
this->t2_timer_id = 0;
}
// clear T2 flag in IFR
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
// load initial value into counter 2
this->t2_counter = (value << 8) | this->via_t2cl;
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
// set up timeout timer for T2
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
[this]() {
this->t2_timer_id = 0;
this->assert_t2_int();
}
);
break;
case VIA_SR:
this->via_sr = value;
this->_via_ifr &= ~VIA_IF_SR;
update_irq();
break;
case VIA_ACR:
this->via_acr = value;
LOG_F(9, "VIA_ACR = 0x%X", value);
break;
case VIA_PCR:
this->via_pcr = value;
LOG_F(9, "VIA_PCR = 0x%X", value);
break;
case VIA_IFR:
// for each "1" in value clear the corresponding flags
this->_via_ifr &= ~value;
@@ -219,62 +294,6 @@ void ViaCuda::write(int reg, uint8_t value) {
update_irq();
print_enabled_ints();
break;
case VIA_T1CH:
if (this->via_regs[VIA_ACR] & 0xC0) {
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
}
// cancel active T1 timer task
if (this->t1_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
this->t1_timer_id = 0;
}
// clear T1 flag in IFR
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
// load initial value into counter 1
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
// set up timout timer for T1
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
this->t1_timer_id = 0;
this->assert_t1_int();
}
);
break;
case VIA_T2CH:
if (this->via_regs[VIA_ACR] & 0x20) {
ABORT_F("VIA T2 pulse count mode not supported!");
}
// cancel active T2 timer task
if (this->t2_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
this->t2_timer_id = 0;
}
// clear T2 flag in IFR
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
// load initial value into counter 2
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
// set up timeout timer for T2
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
[this]() {
this->t2_timer_id = 0;
this->assert_t2_int();
}
);
break;
case VIA_SR:
this->_via_ifr &= ~VIA_IF_SR;
update_irq();
break;
}
}
@@ -368,7 +387,7 @@ void ViaCuda::write(uint8_t new_state) {
int new_tip = !!(new_state & CUDA_TIP);
int new_byteack = !!(new_state & CUDA_BYTEACK);
/* return if there is no state change */
// return if there is no state change
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
return;
@@ -377,7 +396,7 @@ void ViaCuda::write(uint8_t new_state) {
if (new_tip) {
if (new_byteack) {
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
this->via_portb |= CUDA_TREQ; // negate TREQ
this->treq = 1;
if (this->in_count) {
@@ -387,7 +406,7 @@ void ViaCuda::write(uint8_t new_state) {
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(13), // delay TREQ assertion for New World
[this]() {
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
this->via_portb &= ~CUDA_TREQ; // assert TREQ
this->treq = 0;
this->treq_timer_id = 0;
});
@@ -396,7 +415,7 @@ void ViaCuda::write(uint8_t new_state) {
this->in_count = 0;
} else {
LOG_F(9, "Cuda: enter sync state");
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
this->via_portb &= ~CUDA_TREQ; // assert TREQ
this->treq = 0;
this->in_count = 0;
this->out_count = 0;
@@ -405,9 +424,9 @@ void ViaCuda::write(uint8_t new_state) {
// send dummy byte as idle acknowledge or attention
schedule_sr_int(USECS_TO_NSECS(61));
} else {
if (this->via_regs[VIA_ACR] & 0x10) { // data transfer: Host --> Cuda
if (this->via_acr & 0x10) { // data transfer: Host --> Cuda
if (this->in_count < sizeof(this->in_buf)) {
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
this->in_buf[this->in_count++] = this->via_sr;
// tell the system we've read the byte after 71 usecs
schedule_sr_int(USECS_TO_NSECS(71));
} else {
@@ -423,22 +442,22 @@ void ViaCuda::write(uint8_t new_state) {
/* sends zeros to host ad infinitum */
void ViaCuda::null_out_handler() {
this->via_regs[VIA_SR] = 0;
this->via_sr = 0;
}
/* sends PRAM content to host ad infinitum */
void ViaCuda::pram_out_handler()
{
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
this->via_sr = this->pram_obj->read_byte(this->cur_pram_addr++);
}
/* sends data from out_buf until exhausted, then switches to next_out_handler */
void ViaCuda::out_buf_handler() {
if (this->out_pos < this->out_count) {
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
this->via_sr = this->out_buf[this->out_pos++];
if (!this->is_open_ended && this->out_pos >= this->out_count) {
// tell the host this will be the last byte
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
this->via_portb |= CUDA_TREQ; // negate TREQ
this->treq = 1;
}
} else if (this->is_open_ended) {
@@ -447,7 +466,7 @@ void ViaCuda::out_buf_handler() {
(this->*out_handler)();
} else {
this->out_count = 0;
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
this->via_portb |= CUDA_TREQ; // negate TREQ
this->treq = 1;
}
}
@@ -533,7 +552,7 @@ void ViaCuda::autopoll_handler() {
}
// assert TREQ
this->via_regs[VIA_B] &= ~CUDA_TREQ;
this->via_portb &= ~CUDA_TREQ;
this->treq = 0;
// draw guest system's attention
@@ -562,7 +581,7 @@ void ViaCuda::autopoll_handler() {
this->last_time = this_time;
// assert TREQ
this->via_regs[VIA_B] &= ~CUDA_TREQ;
this->via_portb &= ~CUDA_TREQ;
this->treq = 0;
// draw guest system's attention
@@ -691,6 +710,9 @@ void ViaCuda::pseudo_command() {
this->one_sec_mode = this->in_buf[2];
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_SET_POWER_MESSAGES:
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_READ_WRITE_I2C:
response_header(CUDA_PKT_PSEUDO, 0);
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
@@ -711,8 +733,12 @@ void ViaCuda::pseudo_command() {
power_on = false;
power_off_reason = po_restart;
break;
case CUDA_WARM_START:
case CUDA_POWER_DOWN:
LOG_F(INFO, "Cuda: system shutdown");
power_on = false;
power_off_reason = po_shut_down;
break;
case CUDA_WARM_START:
case CUDA_MONO_STABLE_RESET:
/* really kludge temp code */
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
@@ -733,7 +759,7 @@ uint32_t ViaCuda::calc_real_time() {
/* sends data from the current I2C to host ad infinitum */
void ViaCuda::i2c_handler() {
this->receive_byte(this->curr_i2c_addr, &this->via_regs[VIA_SR]);
this->receive_byte(this->curr_i2c_addr, &this->via_sr);
}
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes) {
@@ -810,7 +836,7 @@ void ViaCuda::i2c_comb_transaction(
}
static const vector<string> Cuda_Subdevices = {
"AdbBus", "AdbMouse", "AdbKeyboard"
"AdbBus"
};
static const DeviceDescription ViaCuda_Descriptor = {
+63 -51
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -57,22 +57,22 @@ class InterruptCtrl;
/** VIA register offsets. */
enum {
VIA_B = 0x00, /* input/output register B */
VIA_A = 0x01, /* input/output register A */
VIA_DIRB = 0x02, /* direction B */
VIA_DIRA = 0x03, /* direction A */
VIA_T1CL = 0x04, /* low-order timer 1 counter */
VIA_T1CH = 0x05, /* high-order timer 1 counter */
VIA_T1LL = 0x06, /* low-order timer 1 latches */
VIA_T1LH = 0x07, /* high-order timer 1 latches */
VIA_T2CL = 0x08, /* low-order timer 2 latches */
VIA_T2CH = 0x09, /* high-order timer 2 counter */
VIA_SR = 0x0A, /* shift register */
VIA_ACR = 0x0B, /* auxiliary control register */
VIA_PCR = 0x0C, /* periheral control register */
VIA_IFR = 0x0D, /* interrupt flag register */
VIA_IER = 0x0E, /* interrupt enable register */
VIA_ANH = 0x0F, /* input/output register A, no handshake */
VIA_B = 0x00, // input/output register B
VIA_A = 0x01, // input/output register A
VIA_DIRB = 0x02, // direction B
VIA_DIRA = 0x03, // direction A
VIA_T1CL = 0x04, // low-order timer 1 counter
VIA_T1CH = 0x05, // high-order timer 1 counter
VIA_T1LL = 0x06, // low-order timer 1 latches
VIA_T1LH = 0x07, // high-order timer 1 latches
VIA_T2CL = 0x08, // low-order timer 2 latches
VIA_T2CH = 0x09, // high-order timer 2 counter
VIA_SR = 0x0A, // shift register
VIA_ACR = 0x0B, // auxiliary control register
VIA_PCR = 0x0C, // periheral control register
VIA_IFR = 0x0D, // interrupt flag register
VIA_IER = 0x0E, // interrupt enable register
VIA_ANH = 0x0F, // input/output register A, no handshake
};
/** VIA interrupt flags */
@@ -93,11 +93,11 @@ enum class ViaLine {
CB2
};
/** Cuda communication signals. */
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
enum {
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
CUDA_BYTEACK = 0x10, /* byte acknowledge: 0 - true, 1 - false */
CUDA_TREQ = 0x08 /* Cuda requests transaction from host */
CUDA_TIP = 0x20, // transaction in progress
CUDA_BYTEACK = 0x10, // byte acknowledge/handshake
CUDA_TREQ = 0x08 // Cuda requests transaction from host
};
/** Cuda packet types. */
@@ -111,40 +111,41 @@ enum {
/** Cuda pseudo commands. */
enum {
CUDA_WARM_START = 0x00, /* warm start */
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
CUDA_GET_REAL_TIME = 0x03, /* get real time */
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
CUDA_SET_REAL_TIME = 0x09, /* set real time */
CUDA_POWER_DOWN = 0x0A, /* power down system */
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
CUDA_WARM_START = 0x00, // warm start
CUDA_START_STOP_AUTOPOLL = 0x01, // start/stop device auto-polling
CUDA_READ_MCU_MEM = 0x02, // read internal Cuda memory
CUDA_GET_REAL_TIME = 0x03, // get real time
CUDA_READ_PRAM = 0x07, // read parameter RAM
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
CUDA_SET_REAL_TIME = 0x09, // set real time
CUDA_POWER_DOWN = 0x0A, // power down system
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
CUDA_RESTART_SYSTEM = 0x11, // restart system
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
CUDA_SET_DEVICE_LIST = 0x19, // set device list
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
};
/** Cuda error codes. */
enum {
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
CUDA_ERR_BAD_PKT = 1, // invalid packet type
CUDA_ERR_BAD_CMD = 2, // invalid pseudo command
CUDA_ERR_BAD_SIZE = 3, // invalid packet size
CUDA_ERR_BAD_PAR = 4, // invalid parameter
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
};
#define CUDA_IN_BUF_SIZE 256
/** PRAM addresses within Cuda's internal memory */
/** PRAM addresses within Cuda's internal memory. */
#define CUDA_PRAM_START 0x100 // starting address of PRAM
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
@@ -176,12 +177,23 @@ public:
private:
// VIA virtual HW registers
uint8_t via_regs[16];
uint8_t via_portb = 0;
uint8_t via_porta = 0;
uint8_t via_ddrb = 0;
uint8_t via_ddra = 0;
uint8_t via_t1cl = 0xFF;
uint8_t via_t1ll = 0xFF;
uint8_t via_t1lh = 0xFF;
uint8_t via_t2cl = 0xFF;
uint8_t via_sr;
uint8_t via_acr = 0;
uint8_t via_pcr = 0;
float via_clk_dur; // one VIA clock duration = 1,27655 us
// VIA internal state
uint32_t sr_timer_id = 0;
uint8_t last_orb = 0; // last value written to the ORB register.
// timer 1 state
uint16_t t1_counter;
@@ -259,8 +271,8 @@ private:
/* I2C related methods */
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes);
void i2c_comb_transaction(
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes);
void i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1,
const uint8_t* in_buf, int in_bytes);
};
#endif /* VIACUDA_H */
#endif // VIACUDA_H
+65 -10
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -32,11 +32,24 @@ using namespace MaceEnet;
uint8_t MaceController::read(uint8_t reg_offset)
{
switch(reg_offset) {
case MaceReg::Interrupt:
LOG_F(INFO, "MACE: all interrupt flags cleared");
return 0;
case MaceReg::Rcv_Frame_Ctrl:
return this->rcv_fc;
case MaceReg::Interrupt: {
uint8_t ret_val = this->int_stat;
this->int_stat = 0;
LOG_F(9, "%s: all interrupt flags cleared", this->name.c_str());
return ret_val;
}
case MaceReg::Interrupt_Mask:
return this->int_mask;
case MaceReg::BIU_Config_Ctrl:
return this->biu_ctrl;
case MaceReg::Chip_ID_Lo:
return this->chip_id & 0xFFU;
case MaceReg::Chip_ID_Hi:
return (this->chip_id >> 8) & 0xFFU;
default:
LOG_F(INFO, "Reading MACE register %d", reg_offset);
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
}
return 0;
@@ -45,15 +58,57 @@ uint8_t MaceController::read(uint8_t reg_offset)
void MaceController::write(uint8_t reg_offset, uint8_t value)
{
switch(reg_offset) {
case MaceReg::Rcv_Frame_Ctrl:
this->rcv_fc = value;
break;
case MaceReg::Interrupt_Mask:
this->int_mask = value;
break;
case MaceReg::MAC_Config_Ctrl:
this->mac_cfg = value;
break;
case MaceReg::BIU_Config_Ctrl:
if (value & 1) {
LOG_F(INFO, "MACE Reset issued");
} else {
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
if (value & BIU_SWRST) {
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
value &= ~BIU_SWRST; // acknowledge soft reset
}
this->biu_ctrl = value;
break;
case MaceReg::PLS_Config_Ctrl:
if (value != 7)
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
this->name.c_str(), value);
break;
case MaceReg::Int_Addr_Config:
if ((value & IAC_LOGADDR) && (value & IAC_PHYADDR))
value &= ~IAC_PHYADDR;
if (value & (IAC_LOGADDR | IAC_PHYADDR))
this->addr_ptr = 0;
this->addr_cfg = value;
break;
case MaceReg::Log_Addr_Flt:
if (this->addr_cfg & IAC_LOGADDR) {
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
this->log_addr = (this->log_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
if (++this->addr_ptr >= 8) {
this->addr_cfg &= ~IAC_LOGADDR;
this->addr_ptr = 0;
}
}
break;
case MaceReg::Phys_Addr:
if (this->addr_cfg & IAC_PHYADDR) {
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
this->phys_addr = (this->phys_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
if (++this->addr_ptr >= 6) {
this->addr_cfg &= ~IAC_PHYADDR;
this->addr_ptr = 0;
}
}
break;
default:
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
LOG_F(INFO, "%s: writing 0x%X to register %d", this->name.c_str(),
value, reg_offset);
}
}
+64 -37
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,58 +24,74 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef MACE_H
#define MACE_H
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <cinttypes>
#include <memory>
// MACE Chip ID from AMD datasheet
// TODO: compare with real HW
#define MACE_ID 0x3940
/** Known MACE chip IDs. */
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
// MACE registers offsets
/** MACE registers offsets. */
// Refer to the Am79C940 datasheet for details
namespace MaceEnet {
enum MaceReg : uint8_t {
Rcv_FIFO = 0,
Xmit_FIFO = 1,
Xmit_Frame_Ctrl = 2,
Xmit_Frame_Stat = 3,
Xmit_Retry_Cnt = 4,
Rcv_Frame_Ctrl = 5,
Rcv_Frame_Stat = 6,
FIFO_Frame_Cnt = 7,
Interrupt = 8,
Interrupt_Mask = 9,
Poll = 10,
BIU_Config_Ctrl = 11,
FIFO_Config = 12,
MAC_Config_Ctrl = 13,
PLS_Config_Ctrl = 14,
PHY_Config_Ctrl = 15,
Chip_ID_Lo = 16,
Chip_ID_Hi = 17,
Int_Addr_Config = 18,
Log_Addr_Flt = 20,
Phys_Addr = 21,
Missed_Pkt_Cnt = 24,
Runt_Pkt_Cnt = 26, // not used in Macintosh?
Rcv_Collis_Cnt = 27, // not used in Macintosh?
User_Test = 29,
Rsrvd_Test_1 = 30, // not used in Macintosh?
Rsrvd_Test_2 = 31, // not used in Macintosh?
};
enum MaceReg : uint8_t {
Rcv_FIFO = 0,
Xmit_FIFO = 1,
Xmit_Frame_Ctrl = 2,
Xmit_Frame_Stat = 3,
Xmit_Retry_Cnt = 4,
Rcv_Frame_Ctrl = 5,
Rcv_Frame_Stat = 6,
FIFO_Frame_Cnt = 7,
Interrupt = 8,
Interrupt_Mask = 9,
Poll = 0x0A,
BIU_Config_Ctrl = 0x0B,
FIFO_Config = 0x0C,
MAC_Config_Ctrl = 0x0D,
PLS_Config_Ctrl = 0x0E,
PHY_Config_Ctrl = 0x0F,
Chip_ID_Lo = 0x10,
Chip_ID_Hi = 0x11,
Addr_Config = 0x12,
Log_Addr_Flt = 0x14,
Phys_Addr = 0x15,
Missed_Pkt_Cnt = 0x18,
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
User_Test = 0x1D,
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
};
/** Bit definitions for BIU_Config_Ctrl register. */
enum {
BIU_SWRST = 1 << 0,
};
/** Bit definitions for the internal configuration register. */
enum {
IAC_LOGADDR = 1 << 1,
IAC_PHYADDR = 1 << 2,
IAC_ADDRCHG = 1 << 7
};
}; // namespace MaceEnet
class MaceController : public HWComponent {
class MaceController : public DmaDevice, public HWComponent {
public:
MaceController(uint16_t id) { this->chip_id = id; };
MaceController(uint16_t id) {
this->chip_id = id;
this->set_name("MACE");
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
};
~MaceController() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
return std::unique_ptr<MaceController>(new MaceController(MACE_ID_REV_A2));
}
// MACE registers access
@@ -84,6 +100,17 @@ public:
private:
uint16_t chip_id; // per-instance MACE Chip ID
uint8_t addr_cfg = 0;
uint8_t addr_ptr = 0;
uint8_t rcv_fc = 1;
uint8_t biu_ctrl = 0;
uint8_t mac_cfg = 0;
uint64_t phys_addr = 0;
uint64_t log_addr = 0;
// interrupt stuff
uint8_t int_stat = 0;
uint8_t int_mask = 0;
};
#endif // MACE_H
+1 -1
View File
@@ -311,7 +311,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
fconv = new RawFloppyImg(img_path);
}
if (fconv->calc_phys_params()) {
if (fconv && fconv->calc_phys_params()) {
delete fconv;
return nullptr;
}
+35 -25
View File
@@ -107,15 +107,18 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
this->escc->set_dma_channel(3, this->escc_b_rx_dma.get());
// connect MESH (internal SCSI)
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
this->mesh = dynamic_cast<MeshBase*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
if (this->mesh == nullptr) {
LOG_F(WARNING, "%s: Mesh not found, using MeshStub instead", this->name.c_str());
this->mesh_stub = std::unique_ptr<MeshStub>(new MeshStub());
this->mesh = dynamic_cast<MeshController*>(this->mesh_stub.get());
this->mesh = dynamic_cast<MeshBase*>(this->mesh_stub.get());
} else {
MeshController *mesh_obj =
dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh_scsi"));
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
this->mesh->set_dma_channel(this->mesh_dma.get());
this->mesh_dma->connect(mesh_obj);
mesh_obj->connect(this->mesh_dma.get());
}
// connect external SCSI controller (Curio) to its DMA channel
@@ -126,6 +129,13 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
// connect Ethernet HW
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
this->enet_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_tx"));
this->enet_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Tx));
this->enet_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_rx"));
this->enet_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Rx));
this->enet_tx_dma->connect(this->mace);
this->enet_rx_dma->connect(this->mace);
this->mace->connect(this->enet_rx_dma.get());
// connect floppy disk HW
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
@@ -185,10 +195,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case 7: // VIA-CUDA
return this->viacuda->read((offset >> 9) & 0xF);
case 8: // MESH SCSI
if (this->mesh)
return this->mesh->read((offset >> 4) & 0xF);
else if (this->mesh_stub)
return this->mesh_stub->read((offset >> 4) & 0xF);
return this->mesh->read((offset >> 4) & 0xF);
case 9: // ENET-ROM
return ENET_ROM[(offset >> 4) & 0x7];
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
@@ -221,6 +228,10 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
return this->curio_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_FLOPPY:
return this->floppy_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ETH_XMIT:
return this->enet_tx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ETH_RCV:
return this->enet_rx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ESCC_A_XMIT:
return this->escc_a_tx_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_ESCC_A_RCV:
@@ -296,10 +307,7 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 8: // MESH SCSI
if (this->mesh)
this->mesh->write((offset >> 4) & 0xF, value);
else if (this->mesh_stub)
this->mesh_stub->write((offset >> 4) & 0xF, value);
this->mesh->write((offset >> 4) & 0xF, value);
break;
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
case 0xB: // IOBus device #2 ; RaDACal/DACula
@@ -315,7 +323,9 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
default: val = 0; break;
}
if (offset & 15) {
LOG_F(ERROR, "%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d", this->name.c_str(), offset, size, value, subdev_num - 9);
LOG_F(ERROR,
"%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d",
this->name.c_str(), offset, size, value, subdev_num - 9);
}
if (this->iobus_devs[subdev_num - 10] != nullptr) {
this->iobus_devs[subdev_num - 10]->iodev_write((offset >> 4) & 0x1F, val);
@@ -338,6 +348,12 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case MIO_GC_DMA_FLOPPY:
this->floppy_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ETH_XMIT:
this->enet_tx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ETH_RCV:
this->enet_rx_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_ESCC_A_XMIT:
this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
break;
@@ -354,7 +370,8 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_AUDIO_IN:
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN write @%02x.%c = %0*x", this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN write @%02x.%c = %0*x",
this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
//this->snd_in_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_GC_DMA_SCSI_MESH:
@@ -371,6 +388,7 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
switch (offset) {
case MIO_INT_MASK1:
this->int_mask = BYTESWAP_32(value);
this->signal_cpu_int(this->int_events & this->int_mask);
break;
case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR))
@@ -457,14 +475,8 @@ uint32_t GrandCentral::register_dma_int(IntSrc src_id) {
}
void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t irq_line_state) {
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
//#if 1
// if (irq_id & ~(INT_TO_IRQ_ID(0x12) | INT_TO_IRQ_ID(0x1A)))
// LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
// this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
// );
//#endif
// native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
@@ -472,8 +484,6 @@ void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t irq_line_state) {
this->int_events &= ~irq_id;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
@@ -493,7 +503,7 @@ void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
}
void GrandCentral::signal_cpu_int(uint32_t irq_id) {
if (this->int_events) {
if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -505,7 +515,7 @@ void GrandCentral::signal_cpu_int(uint32_t irq_id) {
}
void GrandCentral::clear_cpu_int() {
if (!this->int_events) {
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
+5 -6
View File
@@ -316,6 +316,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) {
case MIO_INT_MASK2:
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
this->signal_cpu_int();
break;
case MIO_INT_CLEAR2:
this->int_events2 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
@@ -325,6 +326,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
this->int_mask1 = BYTESWAP_32(value);
// copy IntMode bit to InterruptMask2 register
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
this->signal_cpu_int();
break;
case MIO_INT_CLEAR1:
if ((this->int_mask1 & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
@@ -455,7 +457,6 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
} else {
this->int_events2 &= ~irq_id;
}
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
@@ -476,7 +477,6 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
} else {
this->int_events1 &= ~irq_id;
}
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
@@ -531,7 +531,6 @@ void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
} else {
this->int_events2 &= ~irq_id;
}
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
@@ -548,7 +547,6 @@ void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
} else {
this->int_events1 &= ~irq_id;
}
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
@@ -591,7 +589,7 @@ void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
}
void HeathrowIC::signal_cpu_int() {
if (this->int_events1 || this->int_events2) {
if ((this->int_events1 & this->int_mask1) || (this->int_events2 & this->int_mask2)) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -603,7 +601,8 @@ void HeathrowIC::signal_cpu_int() {
void HeathrowIC::clear_cpu_int()
{
if (!this->int_events1 && !this->int_events2) {
if (!(this->int_events1 & this->int_mask1) && !(this->int_events2 & this->int_mask2) &&
this->cpu_int_latch) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "Heathrow: CPU INT latch cleared");
+5 -3
View File
@@ -175,10 +175,10 @@ private:
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
std::unique_ptr<MeshStub> mesh_stub = nullptr;
MaceController* mace;
MaceController* mace; // Ethernet cell within Curio
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
EsccController* escc; // ESCC serial controller
MeshController* mesh; // internal SCSI (fast)
EsccController* escc; // ESCC serial controller cell within Curio
MeshBase* mesh; // internal SCSI (fast)
Sc53C94* curio; // external SCSI (slow)
Swim3::Swim3Ctrl* swim3; // floppy disk controller
@@ -187,6 +187,8 @@ private:
std::unique_ptr<DMAChannel> snd_out_dma;
std::unique_ptr<DMAChannel> snd_in_dma;
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> enet_tx_dma;
std::unique_ptr<DMAChannel> enet_rx_dma;
std::unique_ptr<DMAChannel> escc_a_tx_dma;
std::unique_ptr<DMAChannel> escc_a_rx_dma;
std::unique_ptr<DMAChannel> escc_b_tx_dma;
+12 -1
View File
@@ -168,7 +168,18 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
entry->devobj = nullptr;
entry->mem_ptr = reg_content;
this->address_map.push_back(entry);
// Keep address_map sorted, that way the RAM region (which starts at 0 and
// is most often requested) will be found by find_range on the first
// iteration.
this->address_map.insert(
std::upper_bound(
this->address_map.begin(),
this->address_map.end(),
entry,
[](const auto& lhs, const auto& rhs) {
return lhs->start < rhs->start;
}),
entry);
LOG_F(INFO, "Added mem region 0x%X..0x%X (%s%s%s%s) -> 0x%X", start_addr, end,
entry->type & RT_ROM ? "ROM," : "",
+9 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,10 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <devices/memctrl/mpc106.h>
#include <loguru.hpp>
#include <algorithm>
#include <cinttypes>
#include <cstring>
#include <string>
@@ -60,7 +60,9 @@ int MPC106::device_postinit()
std::string pci_dev_name;
static const std::map<std::string, int> pci_slots = {
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}, {"pci_GPU", DEV_FUN(0x12,0)}
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)},
{"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)},
{"pci_GPU", DEV_FUN(0x12,0)}
};
for (auto& slot : pci_slots) {
@@ -72,6 +74,7 @@ int MPC106::device_postinit()
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id_PCI_A = this->int_ctrl->register_dev_int(IntSrc::PCI_A );
this->irq_id_PCI_B = this->int_ctrl->register_dev_int(IntSrc::PCI_B );
this->irq_id_PCI_C = this->int_ctrl->register_dev_int(IntSrc::PCI_C );
@@ -87,7 +90,7 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
return p.second == dev;
}
);
if (it == dev_map.end()) {
LOG_F(ERROR, "Interrupt from unknown device %s", dev->get_name().c_str());
}
@@ -100,7 +103,8 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
case DEV_FUN(0x0F,0): irq_id = this->irq_id_PCI_C ; break;
case DEV_FUN(0x12,0): irq_id = this->irq_id_PCI_GPU ; break;
default:
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x", dev->get_name().c_str(), it->first >> 3, it->first & 7);
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x",
dev->get_name().c_str(), it->first >> 3, it->first & 7);
return;
}
if (this->int_ctrl)
+2 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -36,6 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <cinttypes>
+58 -24
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -23,15 +23,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/storage/blockstoragedevice.h>
#include <cstring>
using namespace std;
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size, const uint64_t max_blocks) {
this->block_size = block_size;
this->cache_size = cache_blocks * this->block_size;
this->max_blocks = max_blocks;
// allocate device cache and fill it with zeroes
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks,
const uint32_t block_size,
const uint64_t max_blocks) {
this->block_size = block_size;
this->raw_blk_size = block_size;
this->cache_blocks = cache_blocks;
this->max_blocks = max_blocks;
this->is_ready = false;
this->cache_size = 0;
this->data_offset = 0;
}
BlockStorageDevice::~BlockStorageDevice() {
@@ -41,29 +46,61 @@ BlockStorageDevice::~BlockStorageDevice() {
int BlockStorageDevice::set_host_file(std::string file_path) {
this->is_ready = false;
if (!this->img_file.open(file_path)) {
if (!this->img_file.open(file_path))
return -1;
}
this->size_bytes = this->img_file.size();
this->size_blocks = this->size_bytes / this->block_size;
if (this->size_blocks > this->max_blocks)
return -1;
this->set_fpos(0);
this->is_ready = true;
return this->set_block_size(this->block_size);
}
int BlockStorageDevice::set_block_size(const int blk_size) {
this->raw_blk_size = blk_size;
if (this->is_ready) {
this->size_blocks = this->size_bytes / this->raw_blk_size;
if (this->size_blocks > this->max_blocks)
return -1;
}
this->cache_size = this->cache_blocks * this->raw_blk_size;
// allocate data cache and fill it with zeroes
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
return 0;
}
int BlockStorageDevice::set_fpos(const uint32_t lba) {
this->cur_fpos = lba * this->block_size;
this->cur_fpos = lba * this->raw_blk_size;
return 0;
}
void BlockStorageDevice::fill_cache(const int nblocks) {
uint32_t read_size = nblocks * this->raw_blk_size;
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
this->cur_fpos += read_size;
// extract block data from raw images while discarding anything else
if (this->raw_blk_size > this->block_size) {
char *cache_ptr = this->data_cache.get();
for (int blk = 0; blk < nblocks; blk++) {
memcpy(cache_ptr + blk * this->block_size,
cache_ptr + blk * this->raw_blk_size + this->data_offset,
this->block_size
);
}
}
}
int BlockStorageDevice::read_begin(int nblocks, uint32_t max_len) {
uint32_t xfer_len = std::min(this->cache_size, max_len);
uint32_t xfer_len = std::min(this->cache_blocks * this->block_size, max_len);
uint32_t read_size = nblocks * this->block_size;
if (read_size > xfer_len) {
this->remain_size = read_size - xfer_len;
@@ -72,28 +109,25 @@ int BlockStorageDevice::read_begin(int nblocks, uint32_t max_len) {
this->remain_size = 0;
}
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
this->cur_fpos += read_size;
this->fill_cache(read_size / this->block_size);
return read_size;
}
int BlockStorageDevice::read_more() {
uint32_t read_size;
if (!this->remain_size)
return 0;
if (this->remain_size > this->cache_size) {
this->remain_size -= this->cache_size;
read_size = this->cache_size;
uint32_t read_size = this->cache_blocks * this->block_size;
if (this->remain_size > read_size) {
this->remain_size -= read_size;
} else {
read_size = this->remain_size;
this->remain_size = 0;
}
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
this->cur_fpos += read_size;
this->fill_cache(read_size / this->block_size);
return read_size;
}
+9 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -32,12 +32,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class BlockStorageDevice {
public:
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512, const uint64_t max_blocks=0xffffffffffffffff);
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512,
const uint64_t max_blocks=0xffffffffffffffff);
~BlockStorageDevice();
void set_block_size(const int blk_size) { this->block_size = blk_size; };
int set_host_file(std::string file_path);
int set_block_size(const int blk_size);
int set_fpos(const uint32_t lba);
int read_begin(int nblocks, uint32_t max_len);
@@ -46,12 +46,17 @@ public:
int write_begin(char *buf, int nblocks);
protected:
void fill_cache(const int nblocks);
ImgFile img_file;
uint64_t size_bytes = 0; // image file size in bytes
uint64_t size_blocks = 0; // image file size in blocks
uint64_t max_blocks = 0; // maximum number of blocks supported
uint64_t cur_fpos = 0; // current image file pointer position
uint32_t block_size = 512; // physical block size
uint32_t raw_blk_size = 512; // block size for raw images (CD-ROM)
uint32_t data_offset = 0; // offset to block data for raw images
uint32_t cache_blocks = 0;
uint32_t cache_size = 0; // cache size
uint32_t remain_size = 0;
bool is_writeable = false;
+40 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -30,12 +30,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cstring>
#include <string>
CdromDrive::CdromDrive() : BlockStorageDevice(31, 2048, 0xfffffffe) {
CdromDrive::CdromDrive() : BlockStorageDevice(31, CDR_STD_DATA_SIZE, 0xfffffffe) {
this->is_writeable = false;
}
void CdromDrive::insert_image(std::string filename) {
this->set_host_file(filename);
if (this->set_host_file(filename) < 0)
ABORT_F("Could not open CD-ROM image file, %s", filename.c_str());
this->detect_raw_image();
// create single track descriptor
this->tracks[0] = {1, /*.trk_num*/ 0x14, /*.adr_ctrl*/ 0 /*.start_lba*/};
@@ -46,6 +49,29 @@ void CdromDrive::insert_image(std::string filename) {
static_cast<uint32_t>(this->size_blocks + 1) /*.start_lba*/};
}
bool CdromDrive::detect_raw_image() {
uint8_t block_hdr[16];
// let's see if the image data starts with the Mode 1/2 sync pattern
this->img_file.read(block_hdr, 0, sizeof(block_hdr));
for (int i = 1; i <= 10; i++)
if (block_hdr[i] != 0xFF)
return false;
if (block_hdr[0] != 0 || block_hdr[11] != 0)
return false;
// for now, we only support Mode 1 images
if (block_hdr[15] == 1) {
this->set_block_size(2352);
this->data_offset = 16;
return true;
}
return false;
}
static char cdrom_vendor_dingus_id[] = "DINGUS ";
static char cdrom_product_id[] = "DINGUS CD-ROM ";
static char cdrom_revision_id[] = "1.0 ";
@@ -138,8 +164,17 @@ uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
return 8;
}
uint8_t CdromDrive::hex_to_bcd(const uint8_t val) {
uint8_t hi = val / 10;
uint8_t lo = val % 10;
return (hi << 4) | lo;
}
AddrMsf CdromDrive::lba_to_msf(const int lba) {
return {lba / 4500, /*.min*/ (lba / 75) % 60, /*.sec*/ lba % 75 /*.frm*/};
return {hex_to_bcd( lba / 4500), /*.min*/
hex_to_bcd((lba / 75) % 60), /*.sec*/
hex_to_bcd( lba % 75) /*.frm*/
};
}
uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
@@ -207,7 +242,7 @@ uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
out_ptr += 4;
}
}
return data_len;
return alloc_len;
case 1: // Multi-session info
std::memset(data_ptr, 0, 12);
data_ptr[1] = 10; // TOC data length
+4 -1
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -46,6 +46,7 @@ typedef struct {
#define CDROM_MAX_TRACKS 100
#define LEAD_OUT_TRK_NUM 0xAA
#define CDR_STD_DATA_SIZE 2048
class CdromDrive : public BlockStorageDevice {
public:
@@ -69,7 +70,9 @@ public:
protected:
std::function<void(uint8_t, uint8_t)> set_error;
uint8_t hex_to_bcd(const uint8_t val);
AddrMsf lba_to_msf(const int lba);
bool detect_raw_image();
TrackDescriptor tracks[CDROM_MAX_TRACKS];
int num_tracks;
+2
View File
@@ -164,6 +164,8 @@ AtiMach64Gx::AtiMach64Gx()
insert_bits<uint32_t>(this->regs[ATI_GUI_STAT], 32, ATI_FIFO_CNT, ATI_FIFO_CNT_size);
set_bit(regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS); // because blank_on is true
this->draw_fb_is_dynamic = true;
}
void AtiMach64Gx::change_one_bar(uint32_t &aperture, uint32_t aperture_size,
+2
View File
@@ -144,6 +144,8 @@ ATIRage::ATIRage(uint16_t dev_id)
this->regs[ATI_GP_IO] = ((mon_code & 6) << 11) | ((mon_code & 1) << 8);
insert_bits<uint32_t>(this->regs[ATI_GUI_STAT], 32, ATI_FIFO_CNT, ATI_FIFO_CNT_size);
set_bit(regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS); // because blank_on is true
this->draw_fb_is_dynamic = true;
}
void ATIRage::change_one_bar(uint32_t &aperture, uint32_t aperture_size,
+11 -1
View File
@@ -41,9 +41,19 @@ public:
// Clears the display
void blank();
// Update the host framebuffer display. If the display adapter does its own
// dirty tracking, fb_known_to_be_changed will be set to true, so that the
// implementation can take that into account.
void update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb,
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb,
bool draw_hw_cursor, int cursor_x, int cursor_y);
bool draw_hw_cursor, int cursor_x, int cursor_y,
bool fb_known_to_be_changed);
// Called in cases where the framebuffer contents have not changed, so a
// normal update() call is not happening. Allows implementations that need
// to do per-frame bookkeeping to still do that.
void update_skipped();
void handle_events(const WindowEvent& wnd_event);
void setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
+9 -1
View File
@@ -97,6 +97,9 @@ void Display::handle_events(const WindowEvent& wnd_event) {
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
wnd_event.window_id == impl->disp_wnd_id)
impl->resizing = false;
if (wnd_event.sub_type == SDL_WINDOWEVENT_EXPOSED &&
wnd_event.window_id == impl->disp_wnd_id)
SDL_RenderPresent(impl->renderer);
}
void Display::blank() {
@@ -107,7 +110,8 @@ void Display::blank() {
void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb,
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb,
bool draw_hw_cursor, int cursor_x, int cursor_y) {
bool draw_hw_cursor, int cursor_x, int cursor_y,
bool fb_known_to_be_changed) {
if (impl->resizing)
return;
@@ -137,6 +141,10 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
SDL_RenderPresent(impl->renderer);
}
void Display::update_skipped() {
// SDL implementation does not care about skipped updates.
}
void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
int cursor_width, int cursor_height) {
uint8_t* dst_buf;
+17 -3
View File
@@ -91,7 +91,8 @@ uint32_t TaosVideo::read(uint32_t rgn_start, uint32_t offset, int size) {
case CRT_CTRL:
return this->crt_ctrl;
case GPIO_IN:
return ((this->mon_id << 29) | (vsync_active << 25)) & ~this->gpio_cfg;
return ((this->mon_id << GPIO_MONID) | (1 << GPIO_CDTRAY) |
(vsync_active << GPIO_VSYNC)) & ~this->gpio_cfg;
case INT_ENABLES:
return this->int_enables;
case TAOS_VERSION:
@@ -120,7 +121,10 @@ void TaosVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int s
this->row_words = value;
break;
case COLOR_MODE:
this->color_mode = value;
if (this->color_mode != value) {
this->color_mode = value;
enable_display();
}
break;
case VIDEO_MODE:
this->video_mode = value >> 30;
@@ -129,6 +133,8 @@ void TaosVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int s
if (bit_changed(this->crt_ctrl, value, ENABLE_VIDEO_OUT)) {
if (bit_set(value, ENABLE_VIDEO_OUT))
enable_display();
else
disable_display();
}
this->crt_ctrl = value;
break;
@@ -218,7 +224,15 @@ void TaosVideo::enable_display() {
this->start_refresh_task();
this->blank_on = false;
this->crtc_on = true;
this->crtc_on = true;
}
void TaosVideo::disable_display() {
this->stop_refresh_task();
this->blank_display();
this->blank_on = true;
this->crtc_on = false;
}
void TaosVideo::convert_frame_15bpp_indexed(uint8_t *dst_buf, int dst_pitch) {
+8
View File
@@ -111,6 +111,13 @@ enum {
MON_ID_VGA = 6 // GPIO_0 = "1", GPIO_1 = "1", GPIO_2 = "0"
};
/** Definitions for the GPIO pins. */
enum {
GPIO_MONID = 29, // GPIO 0..2 are monitor identification pins
GPIO_CDTRAY = 27, // GPIO 4: "1" - CD-ROM tray is closed
GPIO_VSYNC = 25, // GPIO 6: vertical synch input (active low)
};
/** Broktree Bt856 digital video encoder. */
class Bt856 : public I2CDevice, public HWComponent {
public:
@@ -174,6 +181,7 @@ public:
private:
void enable_display();
void disable_display();
void convert_frame_15bpp_indexed(uint8_t *dst_buf, int dst_pitch);
std::unique_ptr<AthensClocks> clk_gen = nullptr;
+4 -1
View File
@@ -81,7 +81,10 @@ void VideoCtrlBase::update_screen()
}
this->display.update(
this->convert_fb_cb, this->cursor_ovl_cb,
this->cursor_on, cursor_x, cursor_y);
this->cursor_on, cursor_x, cursor_y,
this->draw_fb_is_dynamic);
} else if (this->draw_fb_is_dynamic) {
this->display.update_skipped();
}
}
+5
View File
@@ -86,7 +86,12 @@ protected:
int pixel_format;
float pixel_clock;
float refresh_rate;
// Implementations may choose to track framebuffer writes and set draw_fb
// to false if updates can be skipped. If the do this, they should set
// draw_fb_is_dynamic at initialization time.
bool draw_fb = true;
bool draw_fb_is_dynamic = false;
uint32_t palette[256] = {0}; // internal DAC palette in RGBA format
+1
View File
@@ -98,6 +98,7 @@ static const map<string, string> PropHelp = {
{"serial_backend", "specifies the backend for the serial port"},
{"emmo", "enables/disables factory HW tests during startup"},
{"cpu", "specifies CPU"},
{"adb_devices", "specifies which ADB device(s) to attach"},
};
bool MachineFactory::add(const string& machine_id, MachineDescription desc)
+1 -1
View File
@@ -90,7 +90,7 @@ int initialize_pdm(std::string& id)
}
// Init virtual CPU and request MPC601
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, true, 7812500ULL);
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, true, 7833600ULL);
return 0;
}
+2
View File
@@ -74,6 +74,8 @@ static const PropMap Pippin_Settings = {
new IntProperty(0, vector<uint32_t>({0, 1, 4, 8, 16}))},
{"emmo",
new BinProperty(0)},
{"adb_devices",
new StrProperty("AppleJack,Keyboard")},
};
static vector<string> Pippin_Devices = {
+7 -2
View File
@@ -93,8 +93,13 @@ int initialize_tnt(std::string& id)
return -1;
}
// plug 16MB RAM DIMM into slot #0
memctrl_obj->insert_ram_dimm(0, DRAM_CAP_16MB);
// populate RAM banks from configuration properties
for (int bank_num = 0; bank_num <= 3; bank_num++) {
std::string bn = {char('1' + bank_num)};
int bank_size = GET_INT_PROP("rambank" + bn + "_size");
if (bank_size)
memctrl_obj->insert_ram_dimm(bank_num, bank_size * DRAM_CAP_1MB);
}
// allocate and map physical RAM
memctrl_obj->map_phys_ram();
+35 -2
View File
@@ -52,13 +52,43 @@ int initialize_yosemite(std::string& id)
// get pointer to the bridge of the secondary PCI bus
DecPciBridge *sec_bridge = dynamic_cast<DecPciBridge*>(gMachineObj->get_comp_by_name("Dec21154"));
// connect PCI devices
// attach PCI devices to the PCI bridges
grackle_obj->pci_register_device(DEV_FUN(16,0),
dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name("AtiRage128")));
grackle_obj->pci_register_device(DEV_FUN(13,0),
dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name("Dec21154")));
// register CMD646U2 PCI Ultra ATA Controller
sec_bridge->pci_register_device(DEV_FUN(1,0),
dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("CmdAta")));
sec_bridge->pci_register_device(DEV_FUN(5,0),
dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
InterruptCtrl *int_ctrl_obj =
dynamic_cast<InterruptCtrl*>(gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
static const std::vector<PciIrqMap> grackle_irq_map = {
{"pci_J12", DEV_FUN(0x10,0), 1 << 22} // GPU PCI slot, 66 MHz
};
grackle_obj->set_interrupt_controller(int_ctrl_obj);
grackle_obj->set_irq_map(grackle_irq_map);
// 33 MHz PCI devices behind the DEC21154 PCI-to-PCI bridge
static const std::vector<PciIrqMap> pci_bridge_irq_map = {
{"pci_FireWire", DEV_FUN(0x00,0), 1 << 21},
{"pci_UltraATA", DEV_FUN(0x01,0), 1 << 26},
{"pci_J11", DEV_FUN(0x02,0), 1 << 23},
{"pci_J10", DEV_FUN(0x03,0), 1 << 24},
{"pci_J9", DEV_FUN(0x04,0), 1 << 25},
{"pci_USB", DEV_FUN(0x06,0), 1 << 28}
};
sec_bridge->set_interrupt_controller(int_ctrl_obj);
sec_bridge->set_irq_map(pci_bridge_irq_map);
// allocate ROM region
if (!grackle_obj->add_rom_region(0xFFF00000, 0x100000)) {
LOG_F(ERROR, "Could not allocate ROM region!");
@@ -95,12 +125,15 @@ static const PropMap yosemite_settings = {
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
{"emmo",
new BinProperty(0)},
{"hdd_config",
new StrProperty("CmdAta0:0")},
{"cdr_config",
new StrProperty("Ide0:0")},
};
static vector<string> yosemite_devices = {
"Grackle", "Dec21154", "BurgundySnd", "Heathrow", "AtapiCdrom"
"Grackle", "Dec21154", "CmdAta", "BurgundySnd", "Heathrow", "AtaHardDisk",
"AtapiCdrom"
};
static const MachineDescription yosemite_descriptor = {
+57 -13
View File
@@ -53,16 +53,16 @@ static void sigabrt_handler(int signum) {
}
static string appDescription = string(
"\nDingusPPC - Alpha 1 (5/10/2024) "
"\nDingusPPC - Alpha 1.01 (10/31/2024) "
"\nWritten by divingkatae, maximumspatium, "
"\njoevt, mihaip, et. al. "
"\njoevt, mihaip, kkaisershot, et. al. "
"\n(c) 2018-2024 The DingusPPC Dev Team. "
"\nThis is a build intended for testing. "
"\nUse at your own discretion. "
"\n"
);
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode);
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode, uint32_t profiling_interval_ms);
int main(int argc, char** argv) {
@@ -72,19 +72,35 @@ int main(int argc, char** argv) {
app.allow_windows_style_options(); /* we want Windows-style options */
app.allow_extras();
bool realtime_enabled, debugger_enabled;
string machine_str;
bool realtime_enabled = false;
bool debugger_enabled = false;
string bootrom_path("bootrom.bin");
app.add_flag("-r,--realtime", realtime_enabled,
"Run the emulator in real-time");
app.add_flag("-d,--debugger", debugger_enabled,
"Enter the built-in debugger");
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
->check(CLI::ExistingFile);
bool log_to_stderr = false;
loguru::Verbosity log_verbosity = loguru::Verbosity_INFO;
bool log_no_uptime = false;
app.add_flag("--log-to-stderr", log_to_stderr,
"Send internal logging to stderr (instead of dingusppc.log)");
app.add_flag("--log-verbosity", log_verbosity,
"Adjust logging verbosity (default is 0 a.k.a. INFO)")
->check(CLI::Number);
app.add_flag("--log-no-uptime", log_no_uptime,
"Disable the uptime preamble of logged messages");
uint32_t profiling_interval_ms = 0;
#ifdef CPU_PROFILING
app.add_option("--profiling-interval-ms", profiling_interval_ms,
"Specifies periodic interval (in ms) at which to output CPU profiling information");
#endif
string machine_str;
CLI::Option* machine_opt = app.add_option("-m,--machine",
machine_str, "Specify machine ID");
@@ -112,20 +128,21 @@ int main(int argc, char** argv) {
if (debugger_enabled) {
if (realtime_enabled)
cout << "Both realtime and debugger enabled! Using debugger" << endl;
execution_mode = 1;
execution_mode = debugger;
}
/* initialize logging */
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
loguru::g_preamble_uptime = !log_no_uptime;
if (!execution_mode) {
if (execution_mode == interpreter && !log_to_stderr) {
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
loguru::init(argc, argv);
loguru::add_file("dingusppc.log", loguru::Append, 0);
loguru::add_file("dingusppc.log", loguru::Append, log_verbosity);
} else {
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
loguru::g_stderr_verbosity = log_verbosity;
loguru::init(argc, argv);
}
@@ -188,12 +205,21 @@ int main(int argc, char** argv) {
signal(SIGABRT, sigabrt_handler);
while (true) {
run_machine(machine_str, bootrom_path, execution_mode);
run_machine(machine_str, bootrom_path, execution_mode, profiling_interval_ms);
if (power_off_reason == po_restarting) {
LOG_F(INFO, "Restarting...");
power_on = true;
continue;
}
if (power_off_reason == po_shutting_down) {
if (execution_mode != debugger) {
LOG_F(INFO, "Shutdown.");
break;
}
LOG_F(INFO, "Shutdown...");
power_on = true;
continue;
}
break;
}
@@ -202,7 +228,7 @@ int main(int argc, char** argv) {
return 0;
}
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode) {
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode, uint32_t profiling_interval_ms) {
if (MachineFactory::create_machine_for_id(machine_str, bootrom_path) < 0) {
return;
}
@@ -213,11 +239,24 @@ void run_machine(std::string machine_str, std::string bootrom_path, uint32_t exe
EventManager::get_instance()->poll_events();
});
#ifdef CPU_PROFILING
uint32_t profiling_timer;
if (profiling_interval_ms > 0) {
profiling_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(profiling_interval_ms), [] {
gProfilerObj->print_profile("PPC_CPU");
});
}
#endif
switch (execution_mode) {
case interpreter:
power_off_reason = po_starting_up;
enter_debugger();
break;
case threaded_int:
power_off_reason = po_starting_up;
enter_debugger();
break;
case debugger:
power_off_reason = po_enter_debugger;
enter_debugger();
@@ -229,6 +268,11 @@ void run_machine(std::string machine_str, std::string bootrom_path, uint32_t exe
LOG_F(INFO, "Cleaning up...");
TimerManager::get_instance()->cancel_timer(event_timer);
#ifdef CPU_PROFILING
if (profiling_interval_ms > 0) {
TimerManager::get_instance()->cancel_timer(profiling_timer);
}
#endif
EventManager::get_instance()->disconnect_handlers();
delete gMachineObj.release();
}
+9 -1
View File
@@ -30,11 +30,19 @@ extern "C" void remap_appkit_menu_shortcuts();
#endif
bool init() {
if (SDL_Init(SDL_INIT_VIDEO)) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER)) {
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
return false;
}
int num_joysticks = SDL_NumJoysticks();
for (int i = 0; i < num_joysticks; ++i) {
if (SDL_IsGameController(i)) {
SDL_GameControllerOpen(i); /* only support one controller for now */
break;
}
}
#ifdef __APPLE__
remap_appkit_menu_shortcuts();
#endif
+3 -3
View File
@@ -515,7 +515,7 @@ namespace loguru
argv[argc] = nullptr;
}
static long long now_ns()
static long long loguru_now_ns()
{
return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
@@ -1578,7 +1578,7 @@ namespace loguru
}
}
#if LOGURU_VERBOSE_SCOPE_ENDINGS
auto duration_sec = static_cast<double>(now_ns() - _start_time_ns) / 1e9;
auto duration_sec = static_cast<double>(loguru_now_ns() - _start_time_ns) / 1e9;
#if LOGURU_USE_FMTLIB
auto buff = textprintf("{:.{}f} s: {:s}", duration_sec, LOGURU_SCOPE_TIME_PRECISION, _name);
#else
@@ -1596,7 +1596,7 @@ namespace loguru
if (_verbosity <= current_verbosity_cutoff()) {
std::lock_guard<std::recursive_mutex> lock(s_mutex);
_indent_stderr = (_verbosity <= g_stderr_verbosity);
_start_time_ns = now_ns();
_start_time_ns = loguru_now_ns();
vsnprintf(_name, sizeof(_name), format, vlist);
log_to_everywhere(1, _verbosity, _file, _line, "{ ", _name);
+3 -3
View File
@@ -37,10 +37,10 @@ public:
bool open(const std::string& img_path);
void close();
size_t size() const;
uint64_t size() const;
size_t read(void* buf, off_t offset, size_t length) const;
size_t write(const void* buf, off_t offset, size_t length);
uint64_t read(void* buf, uint64_t offset, uint64_t length) const;
uint64_t write(const void* buf, uint64_t offset, uint64_t length);
private:
class Impl; // Holds private fields
std::unique_ptr<Impl> impl;
+3 -3
View File
@@ -46,20 +46,20 @@ void ImgFile::close()
impl->stream.close();
}
size_t ImgFile::size() const
uint64_t ImgFile::size() const
{
impl->stream.seekg(0, impl->stream.end);
return impl->stream.tellg();
}
size_t ImgFile::read(void* buf, off_t offset, size_t length) const
uint64_t ImgFile::read(void* buf, uint64_t offset, uint64_t length) const
{
impl->stream.seekg(offset, std::ios::beg);
impl->stream.read((char *)buf, length);
return impl->stream.gcount();
}
size_t ImgFile::write(const void* buf, off_t offset, size_t length)
uint64_t ImgFile::write(const void* buf, uint64_t offset, uint64_t length)
{
impl->stream.seekg(offset, std::ios::beg);
impl->stream.write((const char *)buf, length);
+19 -2
View File
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "profiler.h"
#include <iomanip>
#include <iostream>
#include <vector>
@@ -50,6 +51,11 @@ void Profiler::print_profile(std::string name)
return;
}
// Set a locale so we get thousands separators when outputting numbers.
// Would be nice if we could use the default locale, but that does not
// appear to work.
std::cout.imbue(std::locale("en_US.UTF-8"));
std::cout << std::endl;
std::cout << "Summary of the profile '" << name << "':" << std::endl;
std::cout << "------------------------------------------" << std::endl;
@@ -61,13 +67,24 @@ void Profiler::print_profile(std::string name)
// ask the corresponding profile class to fill its variables for us
prof_it->second->populate_variables(vars);
int name_width = 10;
for (auto& var : vars) {
name_width = std::max(name_width, int(var.name.length()));
}
for (auto& var : vars) {
std::cout << std::left << std::setw(name_width) << var.name << " : ";
switch(var.format) {
case ProfileVarFmt::DEC:
std::cout << var.name << " : " << var.value << std::endl;
std::cout << var.value << std::endl;
break;
case ProfileVarFmt::HEX:
std::cout << var.name << " : " << std::hex << var.value << std::endl;
std::cout << std::hex << var.value << std::endl;
break;
case ProfileVarFmt::COUNT:
std::cout << var.value << std::fixed << std::setprecision(2) << " ("
<< (double(var.value) / double(var.count_total) * 100)
<< "%)" << std::endl;
break;
default:
std::cout << "Unknown value in variable " << var.name << std::endl;
+2 -1
View File
@@ -31,13 +31,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <vector>
enum class ProfileVarFmt { DEC, HEX };
enum class ProfileVarFmt { DEC, HEX, COUNT };
/** Define a special data type for profile variables. */
typedef struct ProfileVar {
std::string name;
ProfileVarFmt format;
uint64_t value;
uint64_t count_total;
} ProfileVar;
/** Base class for user-defined profiles. */
+2
View File
@@ -2,6 +2,8 @@ The Apple Desktop Bus is a bit-serial peripheral bus, Apple themselves cited a 2
The device commands are in the form of single byte strings. The first four bits are to signal which of the 16 devices are to be used. The next two bits are for which action to execute (talk, listen, flush, or reset). These are followed by two bits which determine the register to reference (register 0 is usually a communications register, while register 3 is used for device info).
Heathrow and Paddington-based Macintoshes have a Master Cell, which is a fully-featured ADB implementation for hardware, but isn't used by Mac OS itself.
# Commands
| Command Name | Number |
+10
View File
@@ -26,6 +26,16 @@ All registers are 32-bit here.
| Codec Status | 0x20 |
| Clipping Count | 0x30 |
| Byte Swapping | 0x40 |
| Frame Count | 0x50 |
##Sound Control Register bits
| Register | Bit Mask |
|:-------------------------:|:--------:|
| Input Subframe Select | 0x000F |
| Output Subframe Select | 0x00F0 |
| Sound Rate | 0x0700 |
| Error | 0x0800 |
Separate volume controls exist for the CD drive and the microphone.
+42
View File
@@ -0,0 +1,42 @@
The following document is intended primarily as a documentation on how the BeBox operates. It is currently not implemented in DingusPPC.
## BeBox
The BeBox is a dual PowerPC 603(e) CPU setup. As it was designed with the intent of using standard PC parts, it has both three PCI slots and five ISA slots. As it was made with media production as its primary audience, it contains both input and output RCA jacks, a microphone input, and MIDI ports.
It also has a unique 37-pin connector dubbed the Geekport to allow hobbyists to create unique devices.
### Known components
* MPC105 PCI Bridge (Codename: Eagle) - Predecessor to the MPC106 (Grackle); Used for bridging between the motherboard and PCI slots
* Intel 82378ZB - Used for bridging between the motherboard and ISA slots
* SYM53C810A - SCSI I/O Processor
* bq3285 - Used for the Real-Time Clock
### Motherboard registers
| Register name | Address | Default value |
|:---------------------------:|:--------------:|:--------------:|
| CPU 0 Interrupt Mask | 0x7FFFF0F0 | |
| CPU 1 Interrupt Mask | 0x7FFFF1F0 | |
| Interrupt sources | 0x7FFFF2F0 | |
| Cross-proccessor interrupts | 0x7FFFF3F0 | |
| Proc. resets, other stuff | 0x7FFFF4F0 | |
### Memory Map
| Region | Starting Address | Ending Address |
|:---------------------------:|:----------------:|:----------------:|
| Main Memory | 0x00000000 | 0x3FFFFFFF |
| Other Memory | 0x40000000 | 0x7FFFFFFF |
| ISA I/O | 0x80000000 | 0x807FFFFF |
| PCI I/O | 0x81000000 | 0xBEFFFFFF |
| PCI/ISA Interrupt Ack | 0xBFFFFFF0 | 0xBFFFFFFF |
| PCI Memory | 0xC0000000 | 0xFEFFFFFF |
| ROM/Flash | 0xFF000000 | 0xFFFFFFFF |
### Sources
* https://www.haiku-os.org/legacy-docs/benewsletter/Issue1-27.html
* https://www.cebix.net/downloads/bebox/82378zb.pdf
+1 -1
View File
@@ -84,7 +84,7 @@ are exceptions from this rule, for example, video memory.
When no translation for a virtual address was found in either cache, a full address
translation including the full page table walk is performed. This path is the
slowest one. Fortunately, the probabilty that this path will be taken seems to be
slowest one. Fortunately, the probability that this path will be taken seems to be
very low.
The complete algorithm looks like that:
@@ -1,11 +1,9 @@
The PowerPC is the main processor behind Power Macs. Currently, DingusPPC only implements the 32-bit variant.
The PowerPC is the main processor used for Power Macs. Currently, DingusPPC only implements the 32-bit variant.
# General Notes
All instructions are 32 bits wide, regardless of whether the PowerPC is in 32-bit or 64-bit mode.
Code execution generally begins at 0xFFF00100, which the reset exception vector.
# BATs
The 601 BATs are emulated by the Open Firmware.
@@ -27,17 +25,17 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
# Registers
| Register Type | Number | Purpose |
| :-------------------------------- | :--------------------- | :---------------------------------------------------- |
| General Purpose (GPR) | 32 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Floating Point (FPR) | 32 | Calculate, Store, and Load 32-bit or 64-bit floating-point numbers |
| Special Purpose (SPR) | Up to 1024 (in theory) | Store and load specialized 32-bit fixed-point numbers |
| Segment (SR) | 16 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Time Base Facility (TBR) | 2 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Condition Register | 1 | Stores conditions based on the results of fixed-point operations |
| Floating Point Condition Register | 1 | Stores conditions based on the results of floating-point operations |
| Vector Status and Control Register (VSCR) | 1 | Stores conditions based on the results of vector operations |
| Machine State Register | 1 | |
| Register Type | Number | Purpose |
| :----------------------------------------- | :--------------------- | :------------------------------------------------------------------ |
| General Purpose (GPR) | 32 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Floating Point (FPR) | 32 | Calculate, Store, and Load 32-bit or 64-bit floating-point numbers |
| Special Purpose (SPR) | Up to 1024 (in theory) | Store and load specialized 32-bit fixed-point numbers |
| Segment (SR) | 16 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Time Base Facility (TBR) | 2 | Calculate, Store, and Load 32-bit fixed-point numbers |
| Condition Register | 1 | Stores conditions based on the results of fixed-point operations |
| Floating Point Condition Register | 1 | Stores conditions based on the results of floating-point operations |
| Vector Status and Control Register (VSCR) | 1 | Stores conditions based on the results of vector operations |
| Machine State Register (MSR) | 1 | Stores the state of the processor |
# Special Registers
@@ -50,6 +48,9 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
| RTC Lower Register (RTCL) | 5 | (601 only) |
| Link Register (LR) | 8 | |
| Counter Quotient Register (CTR) | 9 | |
| Search Description Register (SDR1)| 25 | Specifies starting address of the page table |
| Save and Restore Register 0 (SRR0)| 26 | |
| Save and Restore Register 1 (SRR1)| 27 | |
| Vector Save/Restore | 256 | (G4+) |
| Time Base Lower (TBL) | 268 | (603+) |
| Time Base Upper (TBU) | 269 | (603+) |
@@ -58,7 +59,7 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
| Hardware Implementation 0 (HID0) | 1008 | |
| Hardware Implementation 1 (HID1) | 1009 | |
# HID 0
## HID 0
| Model | Bits Enabled |
| :------------ | :------------------ |
@@ -70,6 +71,34 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
| 604E | NHR |
| 750 (G3) | NHR, DOZE/NAP/SLEEP |
# Exceptions
nnn is either 0x000 or 0xFFF, depending on the 25th bit (0x40) set in the MSR. Usually, the 25th bit is set when booting up a system and unset after it is set.
| Exception | Address |
| :------------------------------------ | :--------- |
| System Reset | 0xnnn00100 |
| Machine Check | 0xnnn00200 |
| DSI | 0xnnn00300 |
| ISI | 0xnnn00400 |
| External Interrupt | 0xnnn00500 |
| Alignment | 0xnnn00600 |
| Program | 0xnnn00700 |
| Floating Point Unavailable | 0xnnn00800 |
| Decrementer | 0xnnn00900 |
| System Call | 0xnnn00C00 |
| Trace | 0xnnn00D00 |
| Performance Monitor (G3+) | 0xnnn00F00 |
| AltiVec Unavailable (G4+) | 0xnnn00F20 |
| Instruction Address Breakpoint (G3+) | 0xnnn01300 |
| System Management Interrupt (G3+) | 0xnnn01400 |
| AltiVec Assist (G4+) | 0xnnn01600 |
| Thermal Management Interrupt (G3+) | 0xnnn01700 |
# Endianness
PowerPC supports both big-endian and little-endian modes. Mac OS largely operates in big-endian mode, due to its 68k heritage.
# Eccentricities
* The HW Init routine used in the ROMs uses the DEC (decrement; SPR 22) register to measure CPU speed. With a PowerPC 601, the DEC register operates on the same frequency as RTC - 7.8125 MHz but uses only 25 most significant bits. In other words, it decrements by 128 at 1/7.8125 MHz.
@@ -80,4 +109,8 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
* The 603 relies on the instructions tlbld and tlbli to assist in TLB reloading.
* To accomodate for early programs compiled on PowerPC 601 Macs, the classic Mac OS has to emulate the POWER instructions that were removed from later processors.
* To accommodate for early programs compiled on PowerPC 601 Macs, the classic Mac OS has to emulate the POWER instructions that were removed from later processors.
# References
http://www.ibmfiles.com/ibmfiles/powerpc/itso_powerpc_inside_view.pdf
+71
View File
@@ -0,0 +1,71 @@
The Description-Based Direct Memory Access (DBDMA) relies on memory-based descriptions, minimizing CPU interrupts.
| Channel | Number |
|:-----------------:|:------:|
| SCSI0 | 0x0 |
| FLOPPY | 0x1 |
| ETHERNET TRANSMIT | 0x2 |
| ETHERNET RECIEVE | 0x3 |
| SCC TRANSMIT A | 0x4 |
| SCC RECIEVE A | 0x5 |
| SCC TRANSMIT B | 0x6 |
| SCC RECIEVE B | 0x7 |
| AUDIO OUT | 0x8 |
| AUDIO IN | 0x9 |
| SCSI1 | 0xA |
What's notable about the registers is that they are in little-endian format, thus Mac OS uses the stwbrx and lwbrx instructions to store values.
| Register | Offset |
|:-----------------:|:------:|
| ChannelControl | 0x00 |
| ChannelStatus | 0x04 |
| CommandPtrHi | 0x08 |
| CommandPtrLo | 0x0C |
| InterruptSelect | 0x10 |
| BranchSelect | 0x14 |
| WaitSelect | 0x18 |
| TransferMode | 0x1C |
| Data2PtrHi | 0x20 |
| Data2PtrLo | 0x24 |
| BranchPtrHi | 0x2C |
| BranchPtrLo | 0x30 |
| Command | Value |
|:-----------------:|:------:|
| OUTPUT_MORE | 0x0 |
| OUTPUT_LAST | 0x1 |
| INPUT_MORE | 0x2 |
| INPUT_LAST | 0x3 |
| STORE_QUAD | 0x4 |
| LOAD_QUAD | 0x5 |
| NOP | 0x6 |
| STOP | 0x7 |
| Key Name | Value |
|:-----------------:|:------:|
| KEY_STREAM0 | 0x0 |
| KEY_STREAM1 | 0x1 |
| KEY_STREAM2 | 0x2 |
| KEY_STREAM3 | 0x3 |
| KEY_REGS | 0x5 |
| KEY_SYSTEM | 0x6 |
| KEY_DEVICE | 0x7 |
## Control Register
| Value | Offset |
|:-----------:|:------:|
| Branch | 0x100 |
| Active | 0x400 |
| Dead | 0x800 |
| Wake | 0x1000 |
| Flush | 0x2000 |
| Pause | 0x4000 |
| Run | 0x8000 |
## References
* https://stuff.mit.edu/afs/sipb/contrib/doc/specs/protocol/chrp/chrp_io.pdf
* https://stuff.mit.edu/afs/sipb/contrib/doc/specs/protocol/chrp/chrp_hrpa.pdf
Loaded 100 of 109 files, more files were not shown because too many files have changed in this diff. Show more