Compare commits

...
2118 Commits
Author SHA1 Message Date
joevt 7503941f23 display_sdl: Replace comma with semi-colons. 2026-11-26 10:22:20 -07:00
joevt 293bb0018b mpc106: Different slots for different machines. 2026-11-26 08:36:55 -07:00
joevt ba62201573 videoctrl: Init refresh_rate. 2026-11-23 08:12:24 -07:00
joevt 94ffe31dda videoctrl: pixel_clock should be double.
So that it can represent pixel clocks exactly above 16.777216 MHz.
2026-11-23 08:12:21 -07:00
dingusdev d0fb711842 Slight update on AI rules 2026-11-10 00:09:51 +00:00
Maxim Poliakovski 090e852ecc dec21154: use constants for PCI class ID and revision. 2026-11-05 23:43:07 +01:00
Maxim Poliakovski b9d3456c44 mpc106: use named constants for PCI class ID and revision. 2026-11-04 16:57:33 +01:00
Maxim Poliakovski 7384b16548 PCI class ID for MacIO ASICs is now a named constant. 2026-11-04 16:21:15 +01:00
Maxim Poliakovski 8f6c4423e7 Move common PCI definitions to pcidefs.h 2026-11-03 15:25:56 +01:00
Mihai Parparita a0cc486580 mpc106: remove duplicated properties
`pci_J12` causes a duplicated property warning, and makes the
`AtiMach64Gx` default value from machineyosemite.cpp not work. Since
it's a Yosemite-only slot, it seems reasonable for only the machine
to define.

Also removes the similarly duplicted `pci_GPU` property, which had
already been commented out in 40c82785c9.
2026-11-01 19:21:23 -07:00
joevt 810c3f9dd3 platinum: Write protect read-only bits. 2026-10-31 19:56:07 -07:00
joevt 3ad54485ff platinum: Default gfxmem_size to 4 MB.
So we can get all the graphics modes without adding to the command line.

We don't default to max RAM because adding RAM doesn't add more
capabilities and the top end is much greater than with VRAM.
2026-10-31 18:59:27 -07:00
joevt 64d4654e2e platinum: Add comment for cpu_id calculation. 2026-10-31 18:55:31 -07:00
joevt f22a333ae7 platinum: Fix address in unmapped log message.
offset is relative to VRAM_REGION_BASE, not whatever is in fb_addr.
2026-10-31 16:33:46 -07:00
joevt fd1b1bb8f1 control: Update display only if base changes. 2026-10-30 21:05:15 -07:00
joevt dd5ecee284 control: Fix indent. 2026-10-30 18:24:29 -07:00
joevt f084bae478 control: Remove extra spaces. 2026-10-30 18:24:21 -07:00
joevt beaae745bb ppcmmu: Add size to MapDmaResult.
A DMA range might span more than one region. Return info for the first
region only.
2026-10-25 15:33:50 -07:00
joevt 1b63628e58 ppcopcodes: Overflow optional operation omit. 2026-10-23 17:27:09 -07:00
joevt 7a13951400 psx: Initialize class fields.
Use values from the PSX ERS document instead of leaving them random.
2026-10-21 20:26:27 -07:00
joevt 94e7bbd14a platinum: Update display only if base changes.
Corum III in BeOS sets base address often.
2026-10-20 06:17:31 -07:00
joevt 5ad23f5f88 valkyrie: Add missing display modes. 2026-10-19 07:01:34 -07:00
joevt cd2e0ad7da valkyrie: Fix display mode change detection.
The mode should change even if the display disable flag doesn't change.
2026-10-19 07:01:06 -07:00
joevt 8e03b1c52a ppcexec: Add EAR register for disassembly.
BeOS uses the EAR register. This name map is used when listing the
values of input and output registers in disassembly.
2026-10-19 06:56:12 -07:00
joevt 8cab662f6e ppcexec: Use get_virt_time_ns exclusively. 2026-10-19 06:17:30 -07:00
joevt 8dff8a4238 ppcexec: Add comment for Open Firmware illegal op. 2026-10-19 06:16:44 -07:00
Mihai Parparita 904c1b177e benchmark: Add an FPU-focused benchmark
Complement bench1's integer workload with a replay through the real FPU
opcode dispatcher. The 512 instruction and register snapshots are based
on observed FPU operations while running GLTeapot on BeOS PR1.

Report median host time per instruction and provide a checksum mode for
checking that different implementations produce the same results,
without guest boot, display updates, or timer overhead.
2026-10-16 18:13:30 -07:00
Mihai Parparita a188a15bf6 ppc: Reduce floating-point exception handling overhead
Combine the host exception checks and only clear exceptions when needed.
On Apple ARM64, use ACLE intrinsics to read and update FPSR directly,
preserving unrelated status bits. Skip these checks when FE_ALL_EXCEPT
is zero.

On an M2 Max, the FPU replay benchmark drops from 32.6 ns/instruction to
21.3 ns with combined checks and 17.9 ns with the ARM64 helpers, giving
roughly 1.5x and 1.8x throughput respectively.
2026-10-16 18:13:30 -07:00
joevt 6d8ce06052 macio: Interrupt when event gets set.
First, fix when event gets set. Previously, for emulated mode, event was
always set even if the irq_line_state is unchanged. Now, the event gets
set only when the level transitions.

For native mode, event is set only when level transitions from 0 to 1.
This remains correct behavior.

Second, call signal_cpu_int only if event changed. Previously, it was
always called even if irq_lane_state or int_event are unchanged.
2026-10-15 18:33:00 -07:00
joevt fc0d722df0 macio: Fix MIO_OHARE_ID comments.
Because this is the name of the enum.
2026-10-15 18:27:24 -07:00
joevt b6dbbe2685 macio: Clarify ack_int_common comments. 2026-10-15 07:05:03 -07:00
joevt 3430e108bd videoctrl: VBL deassert relative to assert time.
The de-assert time should be relative to expected assert time to ensure
that it occurs before next assert time.
2026-10-15 06:26:21 -07:00
joevt 5b3e4f6552 videoctrl: Add missing this. 2026-10-15 06:23:04 -07:00
Mihai Parparita 357b838ac7 macio: Keep interrupt events and CPU IRQ state consistent
Apply the Grand Central fixes from dingusdev/dingusppc#240 to O'Hare,
Heathrow, and Paddington; the Heathrow ERS shows that it expects to
have the same behavior:
- Reevaluate the CPU interrupt when either mask changes, releasing it
  if no pending events remain enabled in either bank (section 7.1).
- Keep events latched until software writes InterruptClear, even if a
  device deasserts its interrupt line or repeats an assertion (sections
  7.2.1 and 7.2.5).
- Replace writable InterruptMask2 bits instead of ORing them, allowing
  sources to be disabled while preserving the read-only IntMode bit
  (section 7.2.6).
2026-10-14 17:43:14 -07:00
Mihai Parparita 049f8b68c5 machines: repeat 4 MB ROM in 16 MB mapped space
Per the Hammerhead ERS the ROM region is 0xFF000000-0xFFFFFFFF. We were
only mapping the ROM at the uppermost 4 MB of that (0xFFC00000). The fact
that copies are returned at other addresses in that range is not
explicitly stated in the ERS, but it does appear to be emprically true.
It's also corroborated by the 9600 wiring diagram, which shows only enough
address bits for 4MB being used for the ROM.

Also does the same fix for Platinum/7200, which has the same mapping and
address bits, and adds some notes about this to the documentation.

Fixes SheepShaver in BeOS guests, which was using 0xFF000000 to get at
the hardware ROM (see https://github.com/cebix/macemu/blob/96e512bd6376e78a2869f16dcc8a9028bce5ee72/BasiliskII/src/BeOS/SheepDriver/sheep_driver.c#L454).
2026-10-14 15:46:43 -07:00
Mihai Parparita 45a4965cd5 grandcentral: Keep interrupt events and CPU IRQ state consistent
Two correctness fixes, based on the Grand Central ERS:
- Reevaluate the CPU interrupt when the mask changes, releasing it if
  no pending events remain enabled (section 6.1).
- Keep events latched until software writes InterruptClear, even if a
  device deasserts its interrupt line or repeats an assertion (section
  6.2.1).

This fixes occasional freezes on BeOS (especially in realtime mode).
Previously, the CPU interrupt could remain asserted with no enabled
events, trapping BeOS in its interrupt handler.
2026-10-14 15:32:24 -07:00
4e254fc972 viacuda: Keep timer 2 rollover and interrupt timing in sync
T2 readback wrapped after N+1 clocks, but its interrupt was scheduled
for N+3. Mac OS Microseconds could see a wrapped counter with no pending
interrupt, then clear the newly asserted interrupt by reading T2CL. The
one-shot timer would never be serviced or rearmed.

Abuse paces its intro text by repeatedly calling Microseconds until 150
ms have elapsed. This tight polling loop exposes the race. Once the
interrupt is lost, the OS stops accumulating elapsed timer periods,
while the hardware counter keeps wrapping. Microseconds then cycles
within a roughly 84 ms window instead of advancing monotonically, so the
150 ms wait can no longer complete normally. The guest keeps running,
but the text's pacing loop effectively stalls, accounting for the
reported frozen or extremely slow scrolling.

Use a shared time origin for counter readback and the N+1.5-clock
interrupt, including the initial half-clock delay. Before reading T2 or
IFR, also assert any overdue interrupt and cancel its queued callback,
so realtime reads and acknowledgments don't depend on timer polling.

Verified native Abuse intro and gameplay, native and Emscripten builds,
and 84 timer checks covering rollover, acknowledgment and overdue reads.

Co-Authored-By: joevt <[email protected]>
Co-Authored-By: Mihai Parparita <[email protected]>
2026-10-13 21:41:03 -07:00
Mihai Parparita 21c6a80e2c timermanager: Preserve phase when rescheduling overdue timers
We would reschedule timers based on their interval and the current time, which
would cause timers with the same interval to get aligned. This may be not be
desired (if a subsystem has two intentionally out-of-phase timers), so we
instead advance the timer based on its previously scheduled time and multiples
of the interval.

Not strictly necessary for the codebase as it stands today (we no longer use
two cyclic intervals for the VBL interval) but it still seems like a worthwhile
correctness improvement, if we decide to reintroduce that approach.
2026-10-13 19:17:31 -07:00
Mihai Parparita 0ea30ac041 videoctrl: Avoid two cyclic timers for VBL interval
We were relying on two separate cyclic timers for the VBL interval, but
in realtime mode we may end up falling behind in timer execution, and the exact
phase may not be preserved. In the worst case they would end up exactly aligned,
and the VBL interval would be effectively lost (the guest polls for the VBL bit
and would never see it)

Switch to only one cyclic timer, which repeatedly sets a one-shot timer for
the VBL end.
2026-10-13 19:17:31 -07:00
joevt 98421734de viacuda: Remove clock drift from T1 rearm.
Use the expected end time as the start time for the next iteration
rather than using the current time. This removes accumulative lag that
process_events might introduce.
2026-10-13 06:20:32 -07:00
joevt e52317c8b5 ppcopcodes: Reduce rA != 0 checks.
By separating (rA != 0) handling from (rA == 0 && is_601) handling.
2026-10-13 06:20:24 -07:00
Mihai Parparita 2a83f5bddc Create empty CD-ROM drives for SCSI-based machines
We only created SCSI CD-ROM drives when an image was supplied at
startup, so later insertion requests had no drive to go to. The
Beige G3 already worked because its ATAPI drive is always created.

Extend the ATAPI approach (where a `cdr_config` property defines the bus
where a CD-ROM drive should be attached) for SCSI-based machines too.
Use it to define default drive on the appropriate bus for PDM, TNT,
Catalyst, Alchemy, Gazelle, and Pippin. Supplying images at startup still
uses the existing drive allocation behavior.
2026-10-11 15:44:22 -07:00
Mihai Parparita 716254c37c Handle CD-ROM commands when no media is present
The 7300 ROM tries to read from an empty CD-ROM drive during boot.
We would try to transfer data from an unallocated buffer and crash.

Return NOT READY / MEDIUM NOT PRESENT for reads, capacity requests,
and TOC requests. Also covers the separate ATAPI READ CD path. This
matches the behavior described in ATAPI 2.6 section 8.5 and the
per-command error tables:
https://www.grix.it/UserFiles/marco.c/INF-8020.pdf
2026-10-11 15:44:22 -07:00
Mihai Parparita 325cc8ac9f ppcopcodes: Reuse operand decode helpers
Use existing helpers for more instructions instructions (twi, mtsr,
mtmsr, etc.). Prompted by the recent fix for tw - these were all correct
already, but might as well make things more uniform.
2026-10-11 15:32:26 -07:00
Mihai Parparita 5cb6d66f18 ppc: Fix reversed operands in tw opcode implementation
The manual decode swapped rA and rB. Fix thix by using the standard
`ppc_grab_regsab` decode helper.

Fixes Macintosh Common Lisp 4.2 hanging at startup (with 7.5.5 booting
using the 7500 ROM).
2026-10-11 15:32:26 -07:00
Mihai Parparita 6f87662a1d ppcexec: Avoid excessive timer polling in realtime mode
When the interpreter can run faster than realtime (depends on the
host system's performance), we would end up checking timer more
frequently.

This is because the `max_cycles` value returned by `process_events()`
was based on the absolute timer deadline converted to instruction
counts. Once `g_icycles` got ahead of that value, we would check timers
after every instruction.

Instead, use the time remaining until the next timer to schedule an
instruction batch relative to `g_icycles`, capped using the existing
500us polling interval.
2026-10-09 19:10:36 -07:00
Mihai Parparita 62793bb935 ppc: make illegal instructions more obvious
Log a warning whenever an illegal opcode exception is being raised,
since it's usually a clue that we have a correctness bug.

Just a warning (as opposed to an error) because the guest OS may handle
the exception and continue execution.
2026-10-09 19:10:02 -07:00
Mihai Parparita 4ed0282ef3 ppc: allow rA=0 for 601 integer store-update instructions
Normally rA (where the effective address is stored) cannot be 0, but the
MPC601 user manual explicitly says that it's allowed for POWER
compatibility (the update is skipped in that case).

Fixes mouse movement in Barrack under on the 6100, which would previously
stop executing because of an illegal opcode exeception being raised
(and unhandled).
2026-10-09 19:10:02 -07:00
joevt 47a9ccd73b ppcopcodes: Add parenthesis in conditional.
Makes the statement look nicer - symmetry!
2026-10-08 20:26:42 -07:00
joevt 96393c63d0 ppcopcodes: Don't redefine ppc_result_a.
It is defined by the ppc_grab_* macro.
2026-10-08 20:21:44 -07:00
Mihai Parparita a811ff8aa3 ppcexec: Use recommended Apple API for getting the realtime clock
The documentation for `mach_absolute_time` recommends replacing it with
`clock_gettime_nsec_np(CLOCK_UPTIME_RAW)`. The latter is also slightly
simpler to use (no need for initialization and a conversion step).
2026-10-08 17:57:13 -07:00
Mihai Parparita 8851daadc9 hostevents_sdl: prevent realtime toggle keyboard shortcut from reaching the guest
Matches the behavior of other internal keyboard shortcuts.
2026-10-08 17:56:05 -07:00
Mihai Parparita 90debefc2a main: allow realtime mode to be enabled at startup
Adds a --realtime CLI flag to enable realtime mode immediately at
startup.

Also tweaks documentation to mention the Control-Alt-R realtime toggle
and the relationship between the realtime mode and deterministic mode.
2026-10-08 17:56:05 -07:00
joevt 74c60fcd57 ppcopcodes: Carry calculation conditional cut. 2026-10-07 06:22:28 -07:00
joevt 8652a5b8c4 ppcopcodes: Remove blank line. 2026-10-07 06:22:01 -07:00
joevt 25eac76d26 ppcopcodes: Rename grab_ca or grab_xer to xer_ca. 2026-10-07 06:21:53 -07:00
Mihai Parparita 315e3d9f2a timermanager: Make shared TimerInfo structs safer to use
With the shared `TimerInfo` structs refactor from 529fff7d, it's easier
to accidentally enqueue the same timer multiple twice. Help the the
programmer out by logging an error if the timer is already `active` when
adding it. To also reduce the boilerplate, one-shot timers and and
cancellation automatically clear the flag.

The error could be upgraded to a CHECK_F once we're more confident that
we've fixed all of the callsites.
2026-10-06 19:08:45 -07:00
Mihai Parparita 5f111d0929 soundserver_cubeb: Avoid enqueueing the deterministic poll timer twice
Solarian II repeatedly restarts sound DMA without the stream being
closed, and thus we would end up in `SoundServer::start_out_stream`
without going through `close_out_stream`. The `add_cyclic_timer` did
call did not check if the timer was already active, and we would end up
with a duplicate entry in the timer queue, which slowdowns and other
incorrect behavior.

Fixed by checking the `active` flag, like all of the other callsites.
2026-10-06 19:08:45 -07:00
Mihai Parparita 3f070249f2 control: suppress MON_SENSE logspam during startup
When the Displays Enabler extension would load under Mac OS 7.6.1 and
the 7300 ROM, there would be several hundred ERROR level lines about
MON_SENSE register writes with unexpected values (more than 5 bits set).

These were actually harmless (they had the read-only sense input bits
6-8), tweak the mask so that they remain at level 9.
2026-10-01 18:10:00 -07:00
Mihai Parparita 13e02f7978 control: skip no-op display updates
Makes both flavors of Control enable the `draw_fb_is_dynamic` optimization,
which lets us skip SDL screen update when the the framebuffer content
has not changed.

Improve BeOS PR1 booting on the 7300 from 15.8-46s to 13.9-14.2. The
variability appears to be due to time spent in `SDL_RenderPresent`,
per https://developer.apple.com/documentation/metal/onscreen-presentation
this may block on macOS (with the Metal backend) until the next display
refresh, and we were generating a lot more frames to present before.

Also improves smoothness of the BeOS GL Teapot demo (the displayed
framerate does not change since the timer is driven by instruction
cycles, which don't change).
2026-10-01 06:25:55 -07:00
joevt 317a34a761 swim3: Add reading of Read Mode register.
This is documented in the SWIM3 ERS as:
2026-09-30 21:19:54 -07:00
dingusdev 72a33a1b8a Version 1.04c Prep 2026-09-30 18:18:04 -07:00
Mihai Parparita ab5699d7f9 control: handle reads and writes from the little-endian aperture
BeOS DR8.2 and DR8.3 use this - not handling it was causing graphical
corruption during boot.

We do the operation as usual in big endian mode (which handles the bank
logic) and then byte-swap the results. Note that the byte swapping
depends on the bit width, not the payload length (patent US5640545A
is presumed to describe some of the logic)
2026-09-30 17:03:16 -07:00
Mihai Parparita 387686aaee viacuda: Allow a specific RTC time to be set
Makes it possible to run time-limited OS versions like BeOS DR8.2
(which does not work after 1997-04-01).

This is now also used for deterministic mode (which had already been
hardcoding a 2001-03-24 RTC time).

Also document both flags in the manual.
2026-09-30 16:57:54 -07:00
Mihai Parparita 21c6e24c7c display: Refresh display when RAMDAC pixel width changes
When changing the bit depth, there are two display attributes that change: the
frame buffer pitch and the pixel width.

Mac OS (7.6.1) and BeOS (R3) do those updates in different order: Mac OS updates
the pixel width first, then the frame buffer pitch; BeOS does the opposite.

For Control and Platinum video, those are handled in separate components
(`ControlVideo`/`PlatinumCtrl` vs. `AppleRamdac`), and only the former had the
ability to trigger display configuration updates (which determines the
`convert_fb_cb` function that is selected). BeOS would thus be left with a stale
value, leading to display corruption.

To fix this, add a pixel width update callback (similar to the hardware cursor
change one) and use it to trigger a display configuration update from the
`AppleRamdac` side.
2026-09-28 06:22:03 -07:00
joevt 4d42720af9 adbkeyboard: Fix get_register_3.
The format of register 3 is incorrect. Use the adbdevice implementation.
2026-09-27 15:54:23 -07:00
joevt bf28e376ce adbdevice: Remove set_register_3 duplicate code. 2026-09-27 15:53:05 -07:00
joevt 8413e9245a dbdma: Add missing this. 2026-09-27 09:34:50 -07:00
joevt 019a15e6eb dbdma: Remove extra spaces. 2026-09-27 09:28:15 -07:00
Mihai Parparita 5b292af4d7 adbkeyboard: Improve register 2 emulation
We were defaulting the contents of register 2 to zeros, but that
actually means an active state (modifier key is being held down and/or
an LED is on, see Table 8-11 in "Guide to Macintosh Family Hardware
(2nd Edition, 1990)"). We should default to 1, and also actually track
and report modifier key state.

This affected the BeOS boot chooser - it gets modifiers from
register 2, and the 0 value made it think that all modifiers were being
held. In turn that would make it bring up the "choose device" screen,
instead of automatically continuing with the previously-selected one.

Classic Mac OS was not affected (e.g. for hold down shift to disable
extensions) because it consumes key updates from register 0 and
maintains its own modifier state.
2026-09-26 15:12:11 -07:00
joevt 74c388c6ec atabasedevice: Queue single read data interrupt. 2026-09-26 08:59:00 -07:00
joevt 0c05d4ff9f ppcopcodes: Add emulation of THRMn registers.
Required for booting Mac OS 9.2.2 on iMac.
2026-09-25 20:31:30 -07:00
joevt 529fff7d4d timermanager: Pre-allocate TimerInfo.
Remove std::shared_ptr allocation/deallocation of TimerInfo structs.
2026-09-25 20:12:05 -07:00
joevt 3d5e2442d3 timermanager: Return next_ns from process_timers.
The point of this change is that g_icycles might not always be the
current time. For example, when g_realtime is true.

process_timers now returns the next time a timer needs to be processed.
Don't subtract time_now, because for realtime mode, the time has changed
since time_now was captured, especially for timers that take a long time
to process.

When there's no timer pending, process_events will return a time of now
+ 0.5 ms for when process_timers should be called again.
2026-09-23 07:06:26 -07:00
joevt 14bae3d789 timermanager: Add time parameters to callback. 2026-09-23 07:04:04 -07:00
joevt ab874a0da9 ppcexceptions: Remove duplicate exception handling code. 2026-09-22 20:29:12 -07:00
joevt ba4a5c7c44 ppcemu: Define more PPC exceptions. 2026-09-22 20:26:38 -07:00
joevt e729b989bb ppcemu: Specify PPC exception values. 2026-09-22 20:26:10 -07:00
joevt 320688dee7 ppcmmu: Fix spelling. 2026-09-22 20:19:00 -07:00
Mihai Parparita 1a0439a871 ppcmmu: Flush all PAT-derived TLB entries for the tlbie instruction
This fixes booting Mac OS 8.6 hanging at the Happy Mac on the iMac G3.
During boot, as part of installing the nanokernel, the OS attempts to do
a full TLB flush via a series of `tlbie` instructions. We were trying to
respect the effective address that's specified in the instruction, but
the semantics of how it should be interpreted are different on the 750
CPU - the [user manual](https://www.nxp.com/docs/en/reference-manual/MPC750UM.pdf)
says:

> The `tlbie` instruction invalidates all TLB entries indexed by the EA,
> and operates on both the instruction and data TLBs simultaneously
> invalidating four TLB entries. The index corresponds to bits 14-19 of the EA.

We were not respecting the bits 14-19 part (`TLB_VPS_MASK` matched bits
4-19), and thus not matching all expected entries. The stale entries
would remain, leading to unexpected behavior.

Rather than trying to more precisely model the 750 behavior, we instead
flush all PAT-derived TLB entries. This matches QEMU's approach (see
qemu/qemu@3dcfb74fd4) and is allowed by
[the PowerPC specification](http://refspecs.linux-foundation.org/PPC_hrm.2005mar31.pdf):

> For example, the tlbie instruction may be implemented to purge all TLB
> entries in a congruence class (that is, all TLB entries indexed by the
> specified effective address which can include corresponding entries in
> data and instruction TLBs) **or the entire TLB**.

As of #219 a full flush is not that expensive, thus this does not
materially affect performance. The goal of the guest OS is a full TLB
flush anyway (hence the sweep of `tlbie` instructions), so we don't end
up doing too many extra lookups after they're done.

For #184
2026-09-16 18:33:16 -07:00
dingusdev 453f2a4a5b MESH: Add missing IRQ update when writing to IntMask 2026-09-13 22:21:26 -07:00
dingusdev 6cb2dc51fe Add missing reset values for MESH 2026-09-13 22:20:44 -07:00
joevt cf951f6900 sc53c94: Allow CLEAR_FIFO after RESET_DEVICE part 3. 2026-09-08 07:10:01 -07:00
dingusdev 796ce78e54 Move Burgundy namespaces to the header 2026-09-07 22:46:37 -07:00
joevt 54c5501e22 burgundy: Add a mic and headphones.
To make sure we get stereo input and output capability.
2026-09-07 22:41:38 -07:00
joevt 1ad1ab29b1 burgundy: Define all bits of the main registers.
Move register definition from .h to .cpp
2026-09-07 22:41:00 -07:00
joevt d2065c8d80 burgundy: Set ID and Vendor registers.
Necessary for classic Mac OS. These are from real B&W G3.
2026-09-07 22:38:44 -07:00
joevt aa5ad2fad9 burgundy: Range check register address. 2026-09-07 22:38:23 -07:00
joevt 4666994a8b burgundy: Increase first_valid time.
Measured ≈22.6 µs on a real B&W G3.
2026-09-07 22:34:57 -07:00
joevt 14cd5559f5 burgundy: Change first_valid to bool. 2026-09-07 22:29:11 -07:00
joevt 932739095a burgundy: Remove extra byte swap. 2026-09-07 22:27:31 -07:00
joevt 28796e3bda burgundy: Remove extra spaces. 2026-09-07 22:27:18 -07:00
joevt 20a22a86e1 sc53c94: Remove extra spaces. 2026-09-07 22:26:44 -07:00
dingusdevandjoevt 5ff0789e75 sc53c94: Allow CLEAR_FIFO after RESET_DEVICE part 2.
Co-Authored-By: joevt <[email protected]>
2026-09-07 22:25:24 -07:00
joevt 8b983ea103 sc53c94: Update IRQ after RESET_DEVICE.
Everywhere that int_status is changed, update_irq must be called to
update irq and status.
2026-09-05 07:57:03 -07:00
joevt 409ec7015e sc53c94: Allow CLEAR_FIFO after RESET_DEVICE.
For Open Firmware reset-scsi compatibility.
2026-09-05 07:56:50 -07:00
joevt e1e324b5d8 maciotwo: Apply mask when reading int events.
The event is still pending even if masked. It will cause an interrupt
when it is unmasked unless it is cleared. Tested on real B&W G3.
2026-09-03 07:37:00 -07:00
joevt c8a9fb91c5 grandcentral: Apply mask when reading int events.
The event is still pending even if masked. It will cause an interrupt
when it is unmasked unless it is cleared. Tested on real Power Mac 8600.
2026-09-03 07:36:39 -07:00
joevt b670fab0f3 grandcentral: Always set DMA interrupt 11.
This interrupt is reserved and is therefore always set.
Tested on a real Power Mac 8600.
2026-09-03 07:36:30 -07:00
Mihai Parparita 21a6b16102 cdrom: Support inserting and ejecting media
Let empty CD-ROM drives accept image insertion events and report the
change to the guest. Guest eject requests now detach the backing image,
and insertion is rejected while media is still present.

SDL handles dropped files through the shared event path. The macOS
bundle also registers ISO and Toast images for app-icon drops.
2026-09-01 06:47:03 -07:00
Mihai Parparita 8101c11ed8 scsi: Delegate medium ejection to devices
Keep START STOP UNIT decoding in ScsiBlockCmds while letting devices
override only the eject action. The default behavior is unchanged.
2026-09-01 06:47:03 -07:00
Mihai Parparita 8bb9037c21 blockstorage: Add image attach and detach helpers
Make backing-image lifetime explicit and reset generic transfer state
when an image is detached. Keep device-specific media behavior in callers.
2026-09-01 06:47:03 -07:00
Mihai Parparita f69d14063c scsi: Name START STOP UNIT flags 2026-09-01 06:47:03 -07:00
joevt a3ac1f4ec0 awacs: Remove blank line. 2026-08-29 07:56:44 -07:00
joevt 86cd4f0712 awacs: Remove extra spaces. 2026-08-29 07:56:37 -07:00
joevt 885be6ae56 atirage: Consolidate ATI_CRTC_INT_CNTL handling. 2026-08-29 07:05:43 -07:00
Mihai Parparita 50950fcfef imgfile: Keep the current image if opening another fails
Create the replacement backend before swapping it in. This lets callers
try a new image without losing the one that is already open.
2026-08-23 17:57:00 -07:00
joevt 583137f327 dbdma: Remove unused callbacks. 2026-08-23 16:29:03 -07:00
Mihai Parparita 4d3cd65429 dma: Remove the old pull/push completion API
b63b6583 removed the old ESCC DMA implementation, taking the last users
of end_pull_data(), end_push_data(), and get_push_data_remaining() with
it. 9fb34efc later removed the last get_pull_data_remaining() call from
the sound server.

Nothing has called these hooks since. Remove them from DmaOutChannel,
DmaInChannel, and DMAChannel instead of carrying dead completion paths
alongside the DMA interfaces that are still in use.
2026-08-21 22:51:37 -07:00
Mihai Parparita a35736dda3 dbdma: Interpret command lists until STOP
With #214 we started to advertise the IDE DMA support from #192 to
guests. That appeared to break booting Mac OS 8.x, at least on the Beige
G3: the startup disk was not even detected.

Mac OS 8.1 sets up an IDE DMA read as INPUT_MORE, then a NOP with its i
field set to always, then STOP, which clears the channel's ACTIVE bit.
The emulated transfer completion path interpreted only one following
descriptor, so it stopped at NOP. NOP raised the interrupt, but STOP was
never reached and the channel stayed active. The Mac OS X driver is more
tolerant of this, which is why it was not an issue there.

The DBDMA Specification, section 1.4, says: "The target fetches command
entries and performs the command-entry-specified data-transfer operation,
processing command entries until a STOP entry is reached". Keep
interpreting ready commands until a transfer blocks or the channel stops,
as start() and resume() already did. This is closer to the hardware
behavior, and empirically lets Mac OS 8.1 boot again.
2026-08-21 22:51:37 -07:00
Mihai Parparita dced15e63d ppc: Ignore unchanged BAT register writes
Avoids unncessary TLB invalidations.
2026-08-20 22:54:26 -07:00
Mihai Parparita 13ccd42e16 ppcmmu: Track translated entries for invalidation
XNU frequently changes BAT and PAT mappings for physical-memory access.
Each  resulting context synchronization can walk tens of thousands of TLB
entries, which consumes a lot of time.

Record the instruction and data TLB slots populated by BAT or PAT and
invalidate only those slots. Pending invalidations are coalesced by source,
and BAT updates cover PAT-derived entries because a new BAT can shadow a page
mapping.

Saves another 0.7 secondss in the time it takes to boot Mac OS X 10.3 to
the WindowServer (compared to the generational PAT invalidation).
2026-08-20 22:54:26 -07:00
Mihai Parparita 855f43c2eb ppcmmu: Revert generational PAT invalidation
PAT generation counters make invalidation constant-time by adding a
generation check to every TLB lookup, but they added a per-access overhead
to compare generation counters. I am swithcing to an alternate approach
(explicitly tracking populated entries, which can also be used for
BAT-derived entries), and am removing this first to make that diff
easier to read.

This logically reverts the work from #199 (the TLB helper refactoring
from #203 prevents a mechanical revert).
2026-08-20 22:54:26 -07:00
Maxim Poliakovski 5f6f3624e1 ppcdechelpers.h: split operand decoding and value loading.
Also remove duplicated code wherever possible.
2026-08-18 16:25:03 +02:00
joevt c8185d0431 scsiphysdevice: Fix spelling. 2026-08-18 06:55:45 -07:00
joevt f547057bb6 ppcdisasm: Fix rlwimi input register list.
The destination register is also an input since only some bits are
modified.
2026-08-18 06:55:11 -07:00
probonopd 6fc87fb982 input: add --swap-command-option to swap the Command and Option keys 2026-08-17 20:32:56 -07:00
Maxim Poliakovski d5f16cf4b6 Rename ppcmacros.h to ppcdechelpers.h & cleanup formatting. 2026-08-17 14:11:55 +02:00
probonopd 57eb29e26c soundserver: drain guest sound DMA via cyclic timer when host stream fails to start
If the host audio stream cannot be started (e.g. no working output device),
the guest sound DMA never advances because the cubeb callback that pulls
data is never invoked. The guest sound driver then stalls forever waiting
for DMA interrupts and the system hangs during boot. Fall back to draining
the DMA via a cyclic timer, as is already done in deterministic mode, so
the guest sees DMA progress even though there is no audible output.
2026-08-16 18:28:41 -07:00
probonopd ed85c82556 viacuda: accept TIMER_TICKLE and SET_POWER_MESSAGES pseudo commands
Log both commands at INFO instead of WARNING. Track the shutdown watchdog
count from TIMER_TICKLE and never act on expiry so the guest cannot be
powered off spuriously when it stops tickling.
2026-08-16 18:28:07 -07:00
Mihai Parparita bd7e3b264b ata: Advertise multiword DMA support
Followup to #192. That implemented DMA support, but did not advertise
it via the IDENTIFY command. While the 10.0 public beta used it
unconditionally, later releases will only use it if the hardware
reports the MWDMA bit.

Takes booting 10.3 (to WindowServer startup) from ~60 seconds to ~47 seconds on my machine.
2026-08-16 14:34:31 -07:00
Mihai Parparita 246bb00ea6 main: Guard deterministic PC logging during transitions
I happened to get a crash when running with deterministic mode because
an exception occurred right when when the periodic logging timer fired,
and the PC address not valid under the new mapping.
2026-08-16 14:11:00 -07:00
Mihai Parparita f6f8d28001 sdl: allow screensaver
SDL defaults to disabling the screensaver, which on macOS hosts also
means that the display or machine will not sleep. This is appropriate
for games, but not for a regular windowed application like DingusPPC (if
a session is left running in the background).
2026-08-15 14:43:38 -07:00
Mihai Parparita 253844cec5 ppcmmu: Add helpers for repeated TLB operations
Helps a bit with some of the code duplication introduced in #203.
2026-08-14 19:26:02 -07:00
Mihai Parparita bb16a5de2a ati: Latch enabled display interrupts until acknowledged
More accurately model the VBL interrupt behavior of ATI chips. When VBL
begins, set the interrupt-pending bits and derive the PCI IRQ from each
pending bit and its matching enable bit. Keep the pending state and PCI IRQ
asserted until the guest driver acknowledges the event, even if VBL has
already ended.

The interrupt may therefore be asserted for less or more time than the
physical VBL interval, depending on when the guest acknowledges it.

This allows the driver to acknowledge the interrupt and resume other work
while VBL may still be active. Previously the PCI IRQ followed the entire
VBL interval, so it could remain asserted after the pending event had been
acknowledged.

Track the PCI IRQ output level and notify the interrupt controller only when
that level changes.
2026-08-11 22:16:52 -07:00
Mihai Parparita 72cf556a7c ati: Fix VBLANK status field updates
insert_bits expects its final argument to be the field width, but both ATI
VBL callbacks passed the current VBL state. When VBL ended, that meant
using zero as the width, so the update was a no-op. After the first vertical
blank began, the ATI_CRTC_VBLANK status bit was never cleared, confusing
guest code that polls the live VBL state.
2026-08-11 22:16:52 -07:00
joevt b3eb501277 main: Remove allow_windows_style_options. 2026-08-11 07:45:20 -07:00
joevt 14a352f497 hostevents_sdl: Add log off to Control-L hotkey. 2026-08-09 21:52:51 -07:00
joevt a432e44483 hostevents_sdl: Fix logging of keyboard state. 2026-08-09 21:38:08 -07:00
Aliceandjoevt 26b7566179 hostevents_sdl: Add icnt_factor and g_realtime shortcuts.
Added controls to increment/decrement icnt_factor and toggle g_realtime
for testing and debugging purposes.
Control Alt Shift = -> increment_icnt_factor();
Control Alt Shift - -> decrement_icnt_factor();
Control Alt r -> toggle_g_realtime();

Co-Authored-By: joevt <[email protected]>
2026-08-09 21:28:22 -07:00
joevt b7fa82ab92 hostevents_sdl: Fix comment spacing. 2026-08-09 21:13:08 -07:00
joevt a3b248ea3d ppcemu: Use ppc_off_reason setter.
Makes things slightly cleaner and helps debugging. Changes to
ppc_off_reason can be logged.
2026-08-09 21:04:04 -07:00
joevt db5ab5f63c display_sdl: Make auto grab mouse optional.
Add a command line option to enable auto grab.
Default to the previous behavior before the auto grab feature was added.

Add a debugger command to enable or disable auto grab.

Notes:
Auto grab mouse currently only works for graphics controllers and guest
OSs that use a hardware cursor and only if the emulation sets
cursor_dirty to true (i.e. not emulation that uses cursor_ovl_cb).
2026-08-09 21:01:00 -07:00
Maxim Poliakovski d542d9ef96 scsicdromcmds: move page handler 0x31 to the end of the source. 2026-08-09 20:17:15 +02:00
dingusdev 472f130e44 Tweak the manual
Suits current changes
2026-08-09 08:08:44 -07:00
joevt aa2f8c2664 main: Move setenv option to emulation commands. 2026-08-09 08:07:00 -07:00
joevt fdef70cddd main: Rename --realtime to --run.
Because it has nothing to do with timing.
2026-08-09 08:06:51 -07:00
joevt 1082a0c029 main: CLI11 changes.
Add --help-all option.
Move emulation options to an empty named subcommand.
Show defaults for --workingdir and --bootrom.
If --bootrom is not specified then validate the default.
2026-08-08 17:05:23 -07:00
probonopd 0f4957cbf4 display: show mouse grab state and shortcut in the window title
The window title now reflects whether the mouse is grabbed and how to toggle
it, so the user knows how to release the automatic grab and move the pointer
to other windows, or how to re-grab it.
2026-08-08 15:29:05 -07:00
probonopd f78f05f53b display: auto-grab the mouse when the guest draws its own cursor
While a guest cursor is drawn, the host mouse is now grabbed automatically
so the guest cursor can reach every screen area and the host pointer cannot
wander off the window. The grab is released again when the guest cursor
disappears, and re-established when the window regains focus, because SDL
may drop the grab on focus loss. A manual grab with Ctrl+G is sticky and
overrides the automatic behavior.
2026-08-08 15:29:05 -07:00
probonopd 6dd8b31b51 display: hide the SDL host pointer when the guest draws its own cursor
When the guest OS draws a hardware cursor into the framebuffer, the SDL
host pointer was still shown on top, so the user saw two cursors that did
not track each other. Hide the host pointer while a guest cursor is drawn
and show it again otherwise, so the user can aim the mouse at the window
when no guest cursor is present.
2026-08-08 15:29:05 -07:00
probonopd ed94cd2459 scsicdrom: Register Apple features mode page (0x31) for ATAPI CD-ROM
Move the Page 0x31 getter from ScsiCdrom into ScsiCdromCmds so it is also
registered for the ATAPI CD-ROM, which Mac OS queries via MODE_SENSE.
2026-08-08 14:33:39 -07:00
probonopd 0f168677b2 atapibasedevice: Clear BSY and signal interrupt on unsupported ATA command
The default case in perform_command() set the ABRT/ERR flags but left BSY
asserted and never fired the interrupt. Open Firmware therefore hung
waiting on the ATAPI CD-ROM after issuing commands it does not support
(e.g. 0xEC IDENTIFY_DEVICE during the boot device probe).
2026-08-08 14:33:39 -07:00
Mihai Parparita d5f607e50f core: mark non-mutating methods as const 2026-08-08 12:49:12 -07:00
joevt 834006d311 dbdma: Fix STORE_QUAD and LOAD_QUAD. 2026-08-08 06:51:03 -07:00
Mihai Parparita 8f6274ed8a ppcmmu: Ignore dcbz for MMIO regions
The ATI drivers uses dcbz to simulate a write-combining buffer when
sending HOST_DATA payloads.

The intent is something like this (on real hardware):

```
dcbz:
    cache line = [0, 0, 0, 0, 0, 0, 0, 0]
    ATI sees nothing

following stores:
    cache line = [A, B, C, D, E, F, G, H]
    ATI still sees nothing

dcbf or eviction:
    write back [A, B, C, D, E, F, G, H]
    ATI receives one completed cache line
```

With our previous cacheless implementation, the behavior was more like this:
```
dcbz:
    ATI immediately receives [0, 0, 0, 0, 0, 0, 0, 0]

following stores:
    ATI then receives [A, B, C, D, E, F, G, H]

dcbf:
    no-op
```

The zero-ed out values have side effects (32 pixels of black being
written), so the intermediate state was visible.

The truly correct fix is to fully model the data cache, and do an
eventual write back of the modified cache lines with their final values,
but that is very invasive (and likely to be slow).

We instead just make `dcbz` a no-op for MMIO regions, which lets us
avoid that intermediate state and unintended side effects.
2026-08-08 06:46:01 -07:00
Mihai Parparita e2a28ec287 atirage: Handle SGRAM color register blits
The Mac OS 8.6 driver enables color-register writes without enabling
block writes to update SGRAM state. Treat that command as a
register-only operation instead of sending it through the VRAM blitter,
while retaining the documented destination tiling side effects.

This prevents the command from producing stray pixels near the menu
bar and Control Strip.

References:
- ATI 3D Rage LT Pro Register Reference Guide, pp. 5-21--5-24.
- ATI Rage Pro and Derivatives Programmer's Guide, pp. 6-11--6-19.
2026-08-07 08:05:42 -07:00
Mihai Parparita 5c5faa626e atirage: Support general-pattern source blits
Mac OS 8.6 uses general and rotated source trajectories when drawing
Finder icons and the Control Strip. Preserve both source size/start
composites and repeat their first and second rectangles according to
SRC_CNTL.

Use the documented signed source coordinates and inclusive scissors
while advancing the source for clipped destination pixels. Unbounded
blits continue to use the existing linear trajectory.

References:
- ATI 3D Rage LT Pro Register Reference Guide, pp. 5-21--5-31 and
  5-39--5-42.
- ATI Rage Pro and Derivatives Programmer's Guide, pp. 6-11--6-19,
  6-31--6-33, and 6-42.
2026-08-07 08:05:42 -07:00
Mihai Parparita 1e4014739c atirage: Support solid and color host rectangle fills
Mac OS 8.6 programs GUI_TRAJ_CNTL to set draw-engine direction and
issues fills through several destination register initiators. Model the
composite register, destination initiators, signed inclusive scissors,
tiling side effects, and Always_1 source selection.

Accept source mix 7 independently of the unused background mix for
solid fills, and consume 8-bit HOST_DATA writes in trajectory order.
This lets the desktop paint and prevents host uploads from being
reversed or clipped.

References:
- ATI 3D Rage LT Pro Register Reference Guide, pp. 5-8--5-12,
  5-33, 5-39--5-42, 5-47--5-51, 5-58, and 5-64--5-65.
- ATI Rage Pro and Derivatives Programmer's Guide, pp. 6-5,
  6-11--6-19, and 6-27--6-29.
2026-08-07 08:05:42 -07:00
joevt eade7a0a30 ppcmmu: Fix indenting. 2026-08-07 06:47:41 -07:00
joevt 9fb34efcf3 soundserver_cubeb: Don't use get_pull_data_remaining.
Just pull data until the DMA buffer is empty.
2026-08-06 20:38:40 -07:00
joevt d3dfbc05ca soundserver_cubeb: Use enum name for pull_data. 2026-08-06 20:38:32 -07:00
Mihai Parparita abf20ce712 Allow different levels of determinism (#201)
Add an "interactive" mode that allows user input, but still disables
hard drive and PRAM persistence.
2026-08-06 19:03:48 -07:00
joevt 90b3119b8f dbdma: Use update_cmd for flush also. 2026-08-06 07:47:26 -07:00
Mihai Parparita 2c7a7c5c36 ppcmmu: Use generational flush for PAT entries
We end up flushing all entries very frequently (hundreds of thousands of times
during Mac OS X boot), and were spending a lot of time in `tlb_flush_entries`
walking through the array. We can instead store a generation counter and
make invalidation be a simple increment. This does make validity checks slightly
more expensive, but it appears to be a net win. On my machine it takes booting
the Mac OS X public meta to the Finder from ~58 seconds to ~35 seconds.
2026-08-06 07:33:54 -07:00
Mihai Parparita 1b0ac89674 ppcmmu: Move TLB internals into implementation
`TLBEntry` and its cache constants and flags are used exclusively by
ppcmmu.cpp. Keep them out of the public MMU header so future TLB changes
do not expand its interface.

This required a small fix in dbdma.cpp since it was implicitly relying on
an include that we removed.

Also declare `gTLBFlush*` variables as static to make it explicit that we
don't expect them to be accessed outside of ppcmmu.cpp.
2026-08-06 07:33:54 -07:00
joevt 577ddb28a9 dbdma: Add update_cmd. 2026-08-05 19:39:27 -07:00
joevt 49cc164a11 dbdma: Add comment. 2026-08-05 19:38:34 -07:00
dingusdev 0df52ad451 Workflows - Use MSVC instead of MSYS2 for Windows 2026-08-05 19:28:45 -07:00
Mihai Parparita 45ea0103ed dbdma: update xferStatus and resCount when handling FLUSH command (#198)
Per the DBDMA spec (section 15.4.3), this is required. Fixes a hang
when booting 9.0 and 9.0.4 on the Beige G3 (they would get stuck in a
loop polling the `xferStatus.active` field).
2026-08-05 18:43:52 -07:00
Mihai Parparita 172efccd1b cpu: remove unused global variables (#197)
Last glob_bb_start_la use was removed in d83fdd8866.

Last last_read_area, last_write_area, and last_exec_area uses were removed
in c9d4cc3321.
2026-08-05 18:43:25 -07:00
joevt 21324e200f burgundy: Implement AWAC_FRAME_COUNT.
Just count frame times using virtual time.
Should probably use real time since audio doesn't use virtual time.
2026-08-04 19:11:54 -07:00
joevt 51e5c95a1b burgundy: Implement AWAC_SOUND_CTRL_REG.
Placeholder for now.
2026-08-04 19:02:09 -07:00
joevt 24fad9fec7 burgundy: Rename value variable.
Read and Write should use the same variable name for the value.
2026-08-04 19:01:48 -07:00
dingusdev 10015af36d Merge pull request #195 from mihaip/upstream-fix-boot
atapicdrom: fix spurious reads during Mac OS boot
2026-08-03 22:23:39 -07:00
Mihai Parparita 4055dd07c4 atapicdrom: fix spurious reads during Mac OS boot
Fixes a couple of regressions after the generic SCSI command refactor:
- `not_ready_reason` was missing an override, so we were not actually returning
  `MEDIUM_NOT_PRESENT`
- `status_good()` was unconditionally called before every command, including for
  `REQ_SENSE`. It cleared `sense_key`, thus we were not returning the correct
   state back.
2026-08-03 22:18:42 -07:00
Maxim Poliakovski 6f86021ae6 atapicdrom: add missing check for being ready. 2026-08-04 03:33:04 +02:00
dingusdev c916954187 Add missing VX and FEX updates 2026-08-01 11:32:07 -07:00
Maxim Poliakovski 23de8c1c08 scsicdromcmds: reimplement SET_CD_SPEED.
Also remove the corresponding stub from atapicdrom.cpp
2026-07-31 02:40:05 +02:00
Maxim Poliakovski 94e0691caa scsi*cmds: undo temporary renames. 2026-07-31 01:21:20 +02:00
Maxim Poliakovski 958bd0f8e6 cdromdrive: remove implementations of SCSI commands.
This source should contain anything related to
the physical properties of a CD/DVD drive like
mechanical capabilities, formats supported as well as
handling of the underlying images.
2026-07-31 01:08:03 +02:00
Maxim Poliakovski b2bd9efbaa atapicdrom: use generic MODE_SENSE_x implementation. 2026-07-31 00:54:23 +02:00
Maxim Poliakovski 99ce46d510 scsicdromcmds: implement CD-ROM audio control page. 2026-07-31 00:38:39 +02:00
Maxim Poliakovski 78c438884c scsiphysinterface: rename set_eject_state to set_lock_state. 2026-07-30 23:56:16 +02:00
Maxim Poliakovski 87633e7fdf scsicdromcmds: add CD capabilities and mechanical status page. 2026-07-30 23:00:44 +02:00
Maxim Poliakovski 57d97370f1 cdromdrive: add mechanical properties and capabilities. 2026-07-30 23:00:25 +02:00
Maxim Poliakovski 045e6d9d7f atapicdrom: use generic SCSI commands, part 1. 2026-07-30 18:47:32 +02:00
Maxim Poliakovski 90b53a61ad atapibasedevice: implement ATAPI PHY for ScsiPhysInterface.
This permits reusing of generic SCSI commands that
don't contain anything related to the particular
physical layer.
2026-07-30 13:55:12 +02:00
dingusdev 7658707bd3 Add missing return statements 2026-07-29 18:49:54 -07:00
Maxim Poliakovski aad05628ea scsiphysinterface: add sense_key to set_status().
SCSI devices don't need that because it's usually stored
internally and returned during REQUEST SENSE command.
On the contrary, ATAPI devices always report sense key
in the upper bits of the error register.
2026-07-30 01:27:45 +02:00
Maxim Poliakovski 520518f2ac scsiblockcmds: improve a couple of logging messages. 2026-07-30 01:27:26 +02:00
joevt f5dbb4fa43 macio: Add more names for feature control bits. 2026-07-24 20:58:21 -07:00
dingusdev 79f1edc102 Adding additional regs in AMIC 2026-07-24 20:58:04 -07:00
Tim Jarzombekandjoevt 3ecf59233c amic: Make RcvDma fields unique_ptr like XmitDma.
From earlier commit:
"amic: Emulate SCC receive DMA registers instead of returning random
values."

Co-Authored-By: joevt <[email protected]>
2026-07-24 07:44:02 -07:00
joevt baeed79f12 amic: Add all the SCC DMA registers. 2026-07-23 20:56:53 -07:00
dingusdev f1c46cdc6d Last minute typo fixes 2026-07-24 00:32:06 +02:00
joevt 0779a171e0 scsi.h: add more defs to ScsiMessage and ScsiExtMessage. 2026-07-24 00:32:06 +02:00
Maxim Poliakovski b9e94b20b4 Revert "Appending ATA device identification stub"
ATAPI devices should NOT implement ATA IDENTIFY DRIVE
command (ECh) to avoid their false identification as ATA
drives. They should implement ATAPI IDENTIFY DEVICE
command (A1h) instead.

This reverts commit da7c8a4579.
2026-07-18 17:03:23 +02:00
joevt fd9899ae87 dbdma: xfer_quad improvements and fixes.
- Make the method call less confusing.
  - Use cur_host instead of passing cmd_struct.
  - Pass a boolean to differentiate LOAD_QUAD and STORE_QUAD.
- Use xfer_size instead of req_count for res_count.
- Don't LOAD_QUAD to read-only DBDMA command.
2026-07-15 07:52:16 -07:00
joevt ff911cc056 dbdma: Add is_active to more methods. 2026-07-15 07:11:18 -07:00
joevt 7af1235b8e dbdma: Flush only applies to INPUT commands. 2026-07-14 20:25:11 -07:00
joevt 06ea4a844e dbdma: Add is_active. 2026-07-14 20:23:41 -07:00
joevt 813350f14a dbdma: Remove superfluous update_irq method. 2026-07-14 19:57:37 -07:00
joevt 4bcd96e6b1 dbdma: Save current dbdma cmd host address.
Use the saved address for finish_cmd.
2026-07-14 19:24:03 -07:00
joevt 83775309e9 dbdma: Set res_count at beginning of command.
Don't need to reset it at the end of a command.
2026-07-14 18:52:22 -07:00
joevt 2a3b6d9cb7 dmacore: Rename is_ready.
So that it is not confused with other contexts.
2026-07-14 18:48:10 -07:00
joevt 538970d659 openfirmware.md: Add note about PCI2 PRSNT bits. 2026-07-14 18:45:38 -07:00
joevt fce52eacfb dbdma: Remove interpret_cmd result. 2026-07-14 07:59:22 -07:00
dingusdev a832d9cf90 Version 1.04b Prep 2026-07-13 10:37:28 -07:00
dingusdev e5b8ff49e4 Restore clearing CH_STAT_FLUSH
This is still required so that the MacTest Pro (Nov. 99) CD can boot up.
2026-07-13 08:30:35 -07:00
dingusdev 5e7c660622 Merge pull request #193 from mihaip/upstream-ati-blit
atirage: Implement source rectangle blitting
2026-07-13 07:39:51 -07:00
Mihai Parparita d9d7257d46 atirage: Also set the draw_fb flag for fill_rect
Happened to notice that we were not marking the framebuffer as dirty
when doing this update. Liekly not an issue in practice since there are
usually other updates, but might as well be correct.
2026-07-12 22:42:17 -07:00
Mihai Parparita 8cecc9b20b atirage: Implement source rectangle blitting
Implement the accelerated same-format source-copy operation (used by the
Mac OS X Public Beta when dragging windows).

Supports raw 8, 15, 16, and 32 bpp copies. Rejects unsupported mixes,
format conversions, partial write masks, color comparison, and source
trajectory modes.
2026-07-12 22:41:30 -07:00
dingusdev 42e617fde9 Merge pull request #192 from mihaip/upstream-ata-dma-take2
ata: Implement DMA transfers
2026-07-11 17:52:36 -07:00
Mihai Parparita 017a4a48b1 atahd: Implement hard disk DMA commands
Add read/write DMA command support to ATA hard disks (can mostly reuse the PIO paths).
2026-07-11 17:45:41 -07:00
Mihai Parparita bf1c9654c4 ata: Implement reusable DMA data transfers
Implement push_data in AtaBaseDevice using the device transfer buffer and
post-transfer callback.

Advance the read data pointer across DMA pulls so a transfer can span
multiple DBDMA descriptors, and clear the DMA state when transfers finish.
2026-07-11 17:44:48 -07:00
dingusdev 6c48fc1f91 BigMac: Typo squatting 2026-07-10 19:58:56 -07:00
joevt e259d8e2b2 machinealchemy: fix box id & emmo. 2026-07-08 14:39:34 +02:00
joevt 3d25cc592d machinegazelle: fix box id & emmo. 2026-07-08 14:17:08 +02:00
dingusdev da7c8a4579 Appending ATA device identification stub 2026-07-07 20:11:22 -07:00
Maxim Poliakovski bf2f7e5217 machinetnt: fix IOBus address for Board register 2.
Also file a bug in Open Firmware 1.0.5 that reads
PCI2 PRSNT bits from wrong location.
2026-07-08 04:05:54 +02:00
Maxim Poliakovski 5f49182c5b atapibasedevice: update two log messages. 2026-07-08 00:26:32 +02:00
joevt d4cb1fe872 machinegazelle: Add pm5500 and tam machines. 2026-07-07 17:01:35 +02:00
Maxim Poliakovski f8a2b19947 machinealchemy: activate factory tests if requested.
Please note that factory tests don't work
out of the box in Alchemy due to a bug in POST.
You need to patch the ROM first.
2026-07-07 13:50:22 +02:00
Maxim Poliakovski 2db1cc160e machinegossamer: activate factory tests if requested. 2026-07-07 13:50:22 +02:00
Maxim Poliakovski b81920fcb2 maciotwo: remove everything related to EMMO.
EMMO should be activated in the particular machine expert
because the location of that bit is board specific.
2026-07-07 13:38:52 +02:00
Mihai Parparita 01eb1356f5 utils: Use mmap for disk images in deterministic mode (#190)
We were reading the entire disk image into a stringstream for
deterministic mode, which is slow and memory-intensive. Instead on POSIX
hosts we can use `mmap` to lazily map the disk image into memory, allowing
it to be streamed in as the guest actually needs data from it.

Helps with iteration speed when debugging via deterministic mode.
2026-07-07 11:06:55 +02:00
Mihai Parparita f964359738 ata: Demote split DMA pull diagnostic
Mac OS X Public Beta commonly drives one ATA DMA transfer through
multiple DBDMA descriptors, so a single ATA pull can be smaller or larger
than the current descriptor request without indicating an error.

Reduce the logging level to avoid logspam during boot.
2026-07-07 11:06:55 +02:00
Mihai Parparita 36420c55b9 dbdma: Report residual descriptor byte counts
We were treating resCount as a "result" count, but it's actually a "residual"
count that reports how many bytes from a descriptor were not transferred
when processing a command. We now correctly handle partial descriptors.

This ended up being necessary for the 10.0 public beta bringup too (the
`AppleUltra66ATA::stopDma` implementation in xnu-103 computes the number
of bytes transferred by subtracting `resCount` from `reqCount`).
2026-07-07 11:06:55 +02:00
dingusdev aef197841b Remove SNAN checks from FABS, FNABS, and FNEG
None of these checks are required
2026-07-05 18:47:37 -07:00
Maxim Poliakovski e557bc1709 atirage: support non-32bpp rectangle fills.
Factored out of efa9d1c4c2984900f8d513abface0dc25c883d31

This is a temporary solution until the full drawing engine
is implemented.
2026-07-05 12:37:18 +02:00
Mihai Parparita 6a53025df9 atimach64defs.h: add enum for internal pixel formats.
Replace raw numbers in atirage.cpp with the appropriate
constants.
2026-07-05 12:26:09 +02:00
Maxim Poliakovski 9e70b3ce3f macio.h: remove board specific definitions. 2026-07-04 23:35:12 +02:00
Maxim Poliakovski 398ab2f7f6 maciobase: common support for IOBus devices. 2026-07-04 18:21:41 +02:00
Mihai Parparita c5d24e98a3 ppcexec: Respect CPU-specific POW behavior (#188)
Followup to #186 - select `MSR[POW]` handling mode once during CPU
initialization instead of treating every processor as `HID0`-gated.

We match documented (and QEMU) behavior:
- 603/7xx CPUs require `HID0` doze, nap, or sleep bits before we enter
  the emulator sleep loop
- 604-family CPUs use just for `POW` directly
- 601 does not support `POW` at all
2026-07-03 18:13:10 -07:00
joevt 37da4d3162 dmacore: Add DmaPushResult. 2026-07-02 08:10:04 -07:00
joevt 3e9397c478 dbdma: Set queue_len after all other fields.
If queue_len is a flag to determine when data is queued, then it
probably should be set last so that the other fields are valid when
another thread decides to act on the queued data.
2026-07-02 08:07:54 -07:00
joevt 3daa2b73d1 sc53c94: Remove obselete DMA stuff. 2026-07-02 07:52:29 -07:00
Mihai Parparita 79a06c55a4 ppcexec: Emulate PowerPC sleep on MSR POW (#186)
xnu-123.5 and similar vintage kernls enter the PowerPC 750 powersave mode
when the scheduler has no runnable work. `machine_idle_ppc` selects HID0
doze or nap, records a nap timestamp, then executes mtmsr with MSR[POW]
set. It stays in a loop there (in case the power saving had no effect
immediately) - it expects execution to resume at the `machine_idle_ret`
label (when an interrupt occurs), which ends up returning from the
function.

We model this state explicitly:
- When mtmsr sets MSR[POW] with the HID0 doze/nap/sleep flags, set a new
  EXEF_SLEEP flag.
- When EXEF_SLEEP is set, keep processing host events without advancing
  the guest PC.

Towards getting the 10.0 public beta to boot (#154) - before this we
would enter the DPPC debugger shortly after this instruction (due to a
bogus MSR LE flag eventually being set). Now we make more progress and
end up in a "Still waiting for root device" loop (presumably something
at the ATA layer)
2026-07-02 06:59:43 -07:00
Maxim Poliakovski 9561edcea2 sc53c94: remove obsolete DMA code. 2026-07-01 19:56:15 +02:00
Maxim Poliakovski ba34d78a7c grandcentral: fix interrupt clearing.
Fix an issue introduced in 4d9f6f33ee
2026-07-01 19:56:15 +02:00
dingusdev ecf8e4f1e1 Fix AWACS Codec Ctrl
Fixed enough to where the test in MacTech Pro passes
2026-07-01 07:33:17 -07:00
Maxim Poliakovski 2c2ad48a22 machinegazelle: configure PSX. 2026-06-27 12:33:45 +02:00
dingusdev 8d1d22416a Further FPU fixes
Now only 472 floating point tests fail
2026-06-26 22:24:48 -07:00
dingusdev 103a06536c Small PPC Floating-Point fixes 2026-06-26 07:44:38 -07:00
Maxim Poliakovski f1472e6f0e Add Alchemy machines emulation. 2026-06-22 23:38:21 +02:00
Maxim Poliakovski 4d9f6f33ee maciotwo: support partial writes to the control registers. 2026-06-21 22:14:09 +02:00
Maxim Poliakovski d8aa33f207 macio.h: add definition for Entry Systems Support register.
Rename and document MIO_AUX_CTL register as well.
2026-06-21 13:45:36 +02:00
Maxim Poliakovski 293f594cdc maciotwo: support partial/spanning reads from control registers. 2026-06-21 02:28:25 +02:00
dingusdev f3a5e48216 Fixed a slight message in compile message 2026-06-18 21:43:23 -07:00
joevt dd5ba1dcfc dbdma: Fix setting of gp channel control bits. 2026-06-18 20:06:44 -07:00
joevt d3483523d6 dbdma: Fix spelling. 2026-06-18 20:06:35 -07:00
joevt 67418b07b0 dbdma: Maintain and report res_count. 2026-06-18 20:06:12 -07:00
joevt cbe840ff3f dbdma: Set flush status when doing flush command. 2026-06-18 19:43:52 -07:00
joevt 290c575503 dbdma: Fix indenting of flush handler. 2026-06-18 19:43:30 -07:00
dingusdev 19c9266bbe MSVC compilation fix for Benchmark
Temp solution
2026-06-18 07:56:12 -07:00
joevt 811951ab91 memctrlbase: Add enums for larger DIMMs. 2026-06-17 07:03:21 -07:00
joevt a3c6d25cc5 grandcentral: Improve IOBus device 3/5 comments. 2026-06-17 07:02:12 -07:00
dingusdev 3ae509f83d More Cmake fixing 2026-06-16 21:27:15 -07:00
dingusdev 44fa69be65 CMake Workflows fix 2026-06-16 21:09:40 -07:00
Maxim Poliakovski 0a3277b286 psx: add setters for sys_id and bus_speed. 2026-06-16 13:38:10 +02:00
joevt b2660e2920 memaccess: Check compile time endianness. 2026-06-10 18:47:58 -07:00
Maxim Poliakovski 92bb6d1054 display.h: use existing macros instead of code duplication. 2026-06-08 13:02:21 +02:00
Maxim Poliakovski 619acb0109 memaccess.h: add read/write macros for native-endian DWORDs. 2026-06-08 13:02:21 +02:00
Maxim Poliakovski 0e2ffa7863 Move endianswap.h to core/* 2026-06-07 21:10:51 +02:00
Maxim Poliakovski 0e03cac082 Move memaccess.h to core/* 2026-06-07 20:32:46 +02:00
joevt 8f3f7cfe70 display: Add separate accessors for dest fb.
The destination framebuffer may be little endian or big endian.
For SDL2, the destination framebuffer's endianness matches the host's
CPU endianness.
2026-06-06 07:47:35 -07:00
joevt e70ab21787 machinefactory: Make a faster adler32. 2026-06-06 07:35:12 -07:00
joevt da7d2f9a92 romidentity: Separate New World product families. 2026-06-06 07:24:15 -07:00
joevt d2950ae319 romidentity: Add PowerBook 5300. 2026-06-06 07:23:24 -07:00
joevt 0e589ce1f6 debugger: Schedule viaint in ppc exec loop. 2026-06-05 19:23:23 -07:00
joevt 2f9c2408b2 pcicardbusbridge: Add PC Card specific BARs. 2026-06-04 19:04:40 -07:00
joevt 375749c48a dec21154: Add FWDET notes. 2026-06-04 19:02:01 -07:00
joevt fdb17a014b dec21154: Add more GPIO handling. 2026-06-04 19:00:37 -07:00
joevt c5a9f949c9 dec21154: Fix pserr_event_dis write.
Only the middle six bits are writable.
2026-06-04 19:00:31 -07:00
joevt 54a1eb49f7 ppcmmu: Add a debug version of mmu_map_dma_mem.
This is for the DPPC debugger, not for debugging DPPC.
2026-06-02 20:34:26 -07:00
joevt b665629168 ppcemu: Remove unused timebase_counter global. 2026-06-02 20:33:55 -07:00
Natalia Portillo 6407f1a566 main.cpp: change log verbosity flag from add_flag to add_option for better clarity 2026-06-02 19:19:25 -07:00
joevt 5abd37530d machinegossamer: Add system register comments. 2026-06-01 20:26:21 -07:00
Maxim Poliakovski 0f14a075cc dbdma: fix pausing/resuming of channel execution.
Suspend execution only if the ACTIVE bit is set.
Resume execution only if the channel was previously suspended.
2026-06-02 02:47:47 +02:00
joevt fcc912e1a8 romidentity: Note PowerBook5,9 ROM variant. 2026-06-01 08:09:25 -07:00
joevt d94c30a743 romidentity: Fix PowerMac11,2 description. 2026-06-01 08:04:44 -07:00
Nat Portillo 14b17a6e25 Fix SuperDrive behaviour when there is no disk in. (#182) 2026-05-31 20:58:13 -07:00
Maxim Poliakovski b291c28b35 atahd: implement stub for IDLE IMMEDIATE.
Mac OS 9.0.4 sometimes expects this command to be implemented.
2026-05-30 00:34:06 +02:00
Maxim Poliakovski 3f16b18bbd atadefs.h: add IDLE IMMEDIATE command code. 2026-05-30 00:34:06 +02:00
Maxim Poliakovski b63b658343 escc: remove old DMA implementation. 2026-05-29 23:36:24 +02:00
Maxim Poliakovski a68bd5b07e escc: switch to new DMA API. 2026-05-29 23:36:24 +02:00
Maxim Poliakovski 767811b952 dbdma: send notification messages to devices. 2026-05-29 23:36:24 +02:00
Maxim Poliakovski 30d95e1409 dmacore: add support for several channels per device. 2026-05-29 23:22:16 +02:00
Maxim Poliakovski 4138074789 dbdma: rewrite CH_STAT update logic. 2026-05-29 23:16:07 +02:00
Maxim Poliakovski 41f4af948f grandcentral: implement DMA interrupt clearing. 2026-05-29 21:22:56 +02:00
Maxim Poliakovski e4acb57429 escc: improve a couple of logging statements. 2026-05-29 19:41:11 +02:00
Maxim Poliakovski 745f5c85a9 dmacore.h: extend definitions and rename DMA messages. 2026-05-29 18:52:43 +02:00
Maxim Poliakovski 60825ce664 maciotwo: add dispatchers for the ESCC A DMA channels. 2026-05-29 18:14:08 +02:00
Maxim Poliakovski ee1b1dd873 maciotwo: clear DMA interrupt flags. 2026-05-29 17:48:55 +02:00
Maxim Poliakovski 3c1308d006 maciobase: implement DMA interrupt clearing. 2026-05-29 17:21:08 +02:00
joevt c28408fd80 scsi: Semicolon instead of comma. 2026-05-29 06:58:24 -07:00
joevt 3367db4494 scsi: Fix spelling of IS_TARGET_ROUTINE_NUMBER. 2026-05-29 06:52:05 -07:00
joevt ff8e98c26c mace: Fix name of datasheet. 2026-05-29 06:51:53 -07:00
joevt fe80d14e8a ppcmmu: uintptr_t (not size_t) for host pointers. 2026-05-29 06:51:32 -07:00
joevt a8dfc8d15c grandcentral: Decode entire DMA range.
Only DMA channels 0..0xA actually exist, but the range extends to 0x7F.
2026-05-27 06:43:40 -07:00
Maxim Poliakovski 0f4b4c0f67 dbdma.cpp: fix CommandPtrLo update.
Some Apple docs state that the CommandPtrLo can be written
if both the run and active bits are cleared.
Later docs say that only the active bit needs to be cleared.
Fix the code to conform to the logic of the latter.
2026-05-18 22:01:41 +02:00
Maxim Poliakovski 3f6f05694f maciotwo: add dispatchers for the ESCC B DMA channels. 2026-05-18 14:14:58 +02:00
Maxim Poliakovski cfde7ee045 escc: implement LTPC registers and logic.
LTPC aka LocalTalk Patch Chip or LocalTalk Protocol Controller
is a HW extension to the ESCC cell in a MacIO chip that is able
to detect the Abort sequence or End-Of-Packet specified in the
LocalTalk protocol.
This extension aims at reducing busy-waiting in SW.
2026-05-18 02:01:55 +02:00
Maxim Poliakovski c8ae8e7407 dbdma.h: add update_ch_stat() method. 2026-05-18 01:50:45 +02:00
Maxim Poliakovski 73e9a72f3d z85c30.h: reformat register descriptions. 2026-05-18 01:42:39 +02:00
Maxim Poliakovski ad9a9dbf80 escc: set SYNC/HUNT bit when SDLC mode is enabled.
The SYNC/HUNT bit in RR0 is set when the SDLC mode is enabled
and the receiver is disabled. Failing to do that will cause
the LocalTalk driver to wait forever for the line to become
ready for transmission.
2026-05-18 01:42:39 +02:00
Maxim Poliakovski ab1f9c59bc dbdma: fix endianness for STORE_QUAD targeting MMIO. 2026-05-16 00:13:16 +02:00
Stefanos Stefanidis 7e8526aa52 Implement ATA command 0xE5. (#179)
* Implement ATA command 0xE5.

* Correct a typo.
2026-05-14 20:15:47 -07:00
joevt 240f9e194e scsihd: Remove 8 GiB limit. 2026-05-12 07:10:15 -07:00
joevt 5a6a8fb26f sc53c94: Make read method use single return path.
Calculate the value that is read which will be used for logging later.
2026-05-12 07:08:58 -07:00
Maxim Poliakovski 2a85161b3a atahd: implement SEEK command.
Drive Setup 1.1 fails to recognize drives
that don't  support SEEK.
2026-05-03 19:02:11 +02:00
Maxim Poliakovski 3ab8e5c213 scsibusctrl: de-assert REQ between STATUS and MESSAGE IN.
REQ is checked after the MESH Status command by the
native SCSI Manager 4.3. If it's asserted the emulation
will hang.
2026-05-03 17:43:05 +02:00
Maxim Poliakovski 1b3a6b062c maciotwo: prevent logging when writing to MIO_INT_LEVELS1. 2026-05-03 14:59:04 +02:00
Maxim Poliakovski f0bb36b9da maciotwo: add Valkyrie interrupt registration. 2026-05-03 13:40:40 +02:00
Maxim Poliakovski c385b131d7 macio.h: remove documentation comment.
It has already been moved to zdocs/developers/heathrow.md
2026-05-03 13:07:12 +02:00
dingusdev 4bfb352b63 Add missing include in imgfile 2026-05-02 19:29:34 -07:00
Maxim Poliakovski b50a04fc79 Initial Valkyrie video controller emulation. 2026-05-03 03:25:58 +02:00
dingusdev dbcdbe7eb3 Start rules against AI 2026-04-20 13:40:34 -07:00
Maxim Poliakovski fe424df9a0 sc53c94: implement accesses to Config 4 register. 2026-04-19 23:29:17 +02:00
Maxim Poliakovski ca7a8e8163 sc53c94: implement bus phase latch. 2026-04-19 23:29:17 +02:00
Maxim Poliakovski 8bcd8829cb sc53c94: improve DMA transfer handling. 2026-04-19 23:29:17 +02:00
Maxim Poliakovski 7a1babc5e9 scsi.h: fix and clean up ScsiCommand definition. 2026-04-19 23:29:17 +02:00
Maxim Poliakovski 883c404601 scsicommoncmds: remove superfluous logging statement. 2026-04-19 23:29:17 +02:00
joevt d94bf01163 debugger: More parsing bat changes.
- For MPC601, ibat#l should be bat#.
- For non-MPC601, ibat#l should be dbat#l for dbats.
- Don't show info for invalid bats on MPC601.
2026-04-18 11:41:54 -07:00
joevt 20ed0f7620 hmc: Cleanup formatting and indenting. 2026-04-18 08:11:30 -07:00
Maxim Poliakovski 32912aac52 sc53c94.h: extend Config 2 bit definition. 2026-04-18 15:04:43 +02:00
Maxim Poliakovski dc7a97abbf scsicdrom: switch to generic ScsiCdromCmds. 2026-04-18 13:26:12 +02:00
Maxim Poliakovski b1fd435e2e New class ScsiCdromCmds. 2026-04-18 13:26:12 +02:00
Cacodemon345 afa7458131 videoctrl: Do not attempt recursively swapping.
Fixes stack overflow crashes when booting maciNTtosh ARC firmware.

Note from joevt: Fixes a problem in the previous commit which does not
exist in the original source of the previous commit.
2026-04-15 20:17:14 -07:00
joevt ecb397de57 ofnvram: Remove redundant "ok" message.
"ok" is output by debugger.cpp which handles the prompt.
2026-04-15 20:08:40 -07:00
joevt d0260d1fdf ofnvram: Simplify checksum expressions.
These methods were extracted from Open Firmware Forth code but we can
make things more readable in C++.
2026-04-15 20:07:39 -07:00
joevt 2f951acdee ofnvram: Add f-segment? flag.
This is an Apple Network Server flag. It is unused on other versions of
Open Firmware.
2026-04-15 20:03:06 -07:00
joevt 9dc3cb978e machinefactory: Use print_all_info. 2026-04-15 19:47:09 -07:00
joevt 621150f2f4 debugger: Fix disasm endian changes. 2026-04-15 19:44:10 -07:00
Maxim Poliakovski ffade95fb9 atapi: rename data_out_phase() to data_in_phase().
That closely matches the SCSI terminology:
data-in:  host <-- device
data-out: host --> device
2026-04-15 16:47:32 +02:00
Maxim Poliakovski 290d8d3fcd atapibasedevice: fix packets for Rhapsody.
ATAPI devices use 12-byte packets by default.
Support for bigger packets is indicated in the first word
of the IDENTIFY ATAPI DEVICE response.

Installers for Rhapsody/Mac OS X Server 1.x send 16-byte packets
instead ignoring the device packet length.
This fix will reject extraneous packet bytes so the Rhapsody
installers will work as they do in the real hardware.
2026-04-14 00:58:09 +02:00
joevt 265615e9f3 timermanager: Make sure the correct timer is popped.
Pop using the ID just in case some other thread pushes a timer with
higher priority to the priority queue.
2026-04-12 19:43:52 -07:00
joevt b5693f29ce timermanager: Fix cyclic timer next timeout. 2026-04-12 19:42:32 -07:00
joevt cb48f59eeb timermanager: Remove duplicate code. 2026-04-12 19:41:20 -07:00
joevt b65c228593 timermanager: Create notify_changes_cb type. 2026-04-12 19:40:00 -07:00
joevt 1ac01add3a timermanager: Deterministic sort.
If nanoseconds are equal then sort by id which is never equal.
2026-04-12 18:51:37 -07:00
Rairii 09c1248be7 CPU and memory controller endian changes.
===============
Rairii changes:

memctrlbase: The memory controller may have an endian swap mode.
mpc106: Only mmio regions need endian swap and only if PCIR_LE_MODE is
set.

videoctrl: Add framebuffer_in_main_memory flag. Use needs_swap_endian.

debugger: Fix disasm for little endian mode.

ppcmmu: little endian mode requires munging of the data and instruction
addresses, affecting the 3 least significant bits.

ppcexec: pc_real is always recalculated during little endian mode
because instructions are swapped every 8 bytes (due to the address
munging).

==============
joevt changes:

Add SUPPORTS_MEMORY_CTRL_ENDIAN_MODE for memory controller.
Use cmake -DDPPC_SUPPORT_PPC_LE=ON to enable.

Add SUPPORTS_PPC_LITTLE_ENDIAN_MODE for CPU.
Use cmake -DDPPC_SUPPORT_MEM_LE=ON to enable.

Add ppc_change_endian to handle endian switch for MPC601 (uses HID0
instead of MSR) and later PPC CPUs.

Add is_LE flag to ppc_state to indicate little endian mode for all
processor versions.

Create separate ppc_exec_inner template functions for little and big
endian.

Switch endian mode in the ppc_exec outer functions when power_off_reason
is po_endian_switch.

Since MPC601 doesn't have ILE and LE bits, remove that code for that
CPU.

videoctrl: Uses templated methods. See next commit for a fix that this
change introduces.
2026-04-12 10:06:32 -07:00
joevt 25860025b0 Add debug option LOG_INSTRUCTIONS.
Adds a log that remembers the last 16 million instructions.
2026-04-12 09:38:14 -07:00
joevt a3bc3a4d04 soundserver_cubeb: Set pointers to null after destroy.
This will make the shutdown method reusable.
2026-04-12 08:35:08 -07:00
joevt 807f961b56 soundserver_cubeb: Use callback type. 2026-04-12 08:34:26 -07:00
joevt 1d75f7ba38 soundserver_cubeb: Use correct endian macros. 2026-04-12 08:34:05 -07:00
joevt 04e0dd188c romidentity: Add more New World Macs. 2026-04-11 18:43:44 -07:00
joevt 008413817a romidentity: Add more Mac OS ROM files. 2026-04-11 18:43:26 -07:00
joevt 0bf6f8b47f romidentity: Add Old World ROM 64-bit checksum.
The 32-bit checksum of Old World ROMs only covers the first 3 MiB.
Some Old World ROMs may have differences only in the last 1 MiB.
Therefore, include the 64-bit checksum which covers all 4 MiB.

Verify ROM size before trying to read from config_info.
2026-04-11 18:29:45 -07:00
joevt 7aacd5c703 ppcmmu: Initialize bat structs after bat regs.
Needed for machine restart.
2026-04-11 13:36:58 -07:00
joevt 688ec133c5 ppcexec: Initialize int_pin.
Problems happen if this is true after a restart.
2026-04-11 13:22:44 -07:00
joevt ed28c8e9a6 display_sdl: Add SDL_SetWindowKeyboardGrab.
To capture the Alt+Tab or the Meta/Super key in Linux/Windows.
Not necessary in macOS for the Command key, and macOS doesn't let you
capture Command-Tab.
2026-04-11 10:31:53 -07:00
joevt e689d62067 debugger: Parse BAT registers. 2026-04-11 10:26:06 -07:00
joevt 52631da7c7 atimach64gx: Fix comments. 2026-04-11 10:18:55 -07:00
joevt 5bfc9a3f75 atirage: Fix comments. 2026-04-11 10:18:53 -07:00
joevt 94ee77e9a4 atirage: Log clock_sel and vertical blank. 2026-04-11 10:18:36 -07:00
joevt b3975cc11a spdram: Add EDO. 2026-04-06 19:16:59 -07:00
joevt f7b5a440e8 dbdma: Use saved_cmd_bits. 2026-04-04 17:17:13 -07:00
Copilotandjarz 798af27514 dbdma: Fix update_irq bug in finish_cmd.
Co-authored-by: jarz <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
2026-04-04 17:16:52 -07:00
joevt dd1cc7da61 scsihd: Fix compiler warnings. 2026-04-04 14:43:51 -07:00
joevt 39a4c7fc05 scsiblockcmds: Fix compiler warnings. 2026-04-04 14:43:43 -07:00
Copilotandjarz a2b0ca42d3 gitignore: Add build folders.
Co-authored-by: jarz <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
2026-04-04 08:53:19 -07:00
Maxim Poliakovski 8955be1eaa Move Apple copyright page to ScsiBlockcmds class. 2026-04-01 21:06:47 +02:00
Maxim Poliakovski 4931bcb6ff scsiblockcmds: allow setting density code from outside. 2026-04-01 21:06:47 +02:00
Maxim Poliakovski 9c003a8b64 scsiblockcmds: don't inherit from BlockStorageDevice. 2026-04-01 21:06:47 +02:00
Maxim Poliakovski 00068dd4af blockstoragedevice: add a couple of getters. 2026-04-01 21:06:47 +02:00
joevt dfea8fa2cd debugger: Show register values during stepping.
So you don't need to use regs after every instruction.
2026-03-31 07:55:21 -07:00
joevt 07f781bf56 debugger: Disassemble instructions while stepping. 2026-03-31 07:54:57 -07:00
joevt 91f5ccc3f9 ppcmmu: Simplify pteg address calculation.
Maybe the optimizer can do it or maybe not.
2026-03-31 07:39:45 -07:00
Maxim Poliakovski 995da89bda scsiblockcmds: fix block descriptor.
SCSI-3 standard specifies a slightly different format for
the short block descriptor applied to direct-access devices.
2026-03-24 20:15:53 +01:00
dingusdev d1d496fda9 Version Prep 2026-03-23 19:30:44 -07:00
joevt bf7fc5fb5a viacuda: Postpone onesec timer if SR int pending. 2026-03-23 07:26:19 -07:00
joevt e275635697 main: Cancel all timers before restart.
Some devices do not cancel their timers when destructed.
If they exist after restart, then bad things can happen.
2026-03-22 17:15:53 -07:00
joevt d8d7ebd40c timermanager: Check for empty queue before remove. 2026-03-22 17:15:35 -07:00
joevt fa6abacf4e hostevents: mouse relative coordinates are signed. 2026-03-22 17:14:06 -07:00
joevt ef8c83108c CLI11: Update to v2.6.2. 2026-03-20 07:00:38 -07:00
joevt 0b32714200 README: Cleanup and add some cmake notes. 2026-03-19 19:33:00 -07:00
joevt c6f17a846b escc: Make W7Prime a peer of WR7.
This simplifies the switch statement and storage of register values.
2026-03-14 15:56:50 -07:00
joevt fb02b15063 escc: Update brg_clock_src when it changes. 2026-03-14 15:55:35 -07:00
joevt ff3e66ecd7 adbmouse: Use parameter for buttons state.
- Rename the parameter from buttons_state to buttons so it is not
  confused with the class data member.

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

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

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

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

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

This change forces handling of the individual DIMM sizes.

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

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

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

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

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

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

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

This change hopes to grab all the keys being pressed and post events for
all of them when the ADB bus is ready.
2025-06-29 06:49:15 -07:00
joevt dbadbb4cce hostevents_sdl: Remove superfluous semicolons. 2025-06-29 06:48:51 -07:00
joevt 23b142008f hostevents_sdl: Use key mods from the SDL key event.
No reason to call SDL_GetModState separately.
2025-06-29 06:48:40 -07:00
joevt d3e0b743bb hostevents_sdl: Add key for entering debugger.
Because Control-C (sigint) in terminal window isn't always reliable (for
example, release version launched from Xcode).
2025-06-29 06:48:33 -07:00
joevt 91410f3690 hostevents_sdl: Control-L toggles max logging. 2025-06-29 06:48:23 -07:00
joevt 5412fbc198 Remove superfluous semicolons. 2025-06-27 19:01:14 -07:00
joevt 3f830eb5b5 hostevents_sdl: Ignore repeat events.
SDL2 will send a key down event multiple times (with the repeat flag
set) after the first key down event for the same key.
2025-06-27 18:57:35 -07:00
joevt 7ed8bda0fe adbkeyboard: Support Device Handler ID 3.
Device Handler ID 3 returns separate key codes for the right control,
option, and shift keys.
2025-06-27 18:55:55 -07:00
joevt 3eaf38b1d8 adbdevice: Remove redundant arithmetic. 2025-06-27 18:55:47 -07:00
joevt bad8adc0c3 adbdevice: Fix listen. 2025-06-27 18:54:09 -07:00
joevt 5ed44f73cd hostevents: Include gamepad handler.
For some reason this handler was not included with other input handlers
for disconnect or disable.
2025-06-27 18:54:05 -07:00
joevt 7b7dc90158 hostevents: Add keyboard_locale.
Add a keyboard locale field instead of passing it as a parameter to
poll_events.
2025-06-27 18:54:01 -07:00
joevt 8c05e8ac82 hostevents: Remove unused keys_state field. 2025-06-27 18:53:54 -07:00
Maxim Poliakovski 53a393a2c2 More superfluous semicolon removal. 2025-06-24 23:53:34 +02:00
Maxim Poliakovski 7fbc250128 machineid.h: remove superfluous semicolon. 2025-06-24 23:53:34 +02:00
Maxim Poliakovski b351b578b7 maciotwo.cpp: remove superfluous mesh_dma checks. 2025-06-22 13:02:28 +02:00
Maxim Poliakovski 8de664b708 dbdma.h: remove superfluous semicolon. 2025-06-22 12:51:47 +02:00
Maxim Poliakovski 6c12c34297 dmacore.h: remove superfluous semicolon. 2025-06-22 12:51:47 +02:00
joevt 1fae4d28ac maciotwo: Standardize log message format. 2025-06-22 12:16:40 +02:00
joevt 881c0f7d4e maciotwo: Add interrupts for OHare part 2. 2025-06-22 12:16:40 +02:00
joevt 4a824cd9aa maciotwo: Fix indent part 2. 2025-06-22 12:16:40 +02:00
joevt 33e351926f maciotwo: Add interrupts for OHare. 2025-06-22 12:16:40 +02:00
joevt 3f57d072ec maciotwo: Fix indent. 2025-06-22 12:16:40 +02:00
joevt 0f17a04b2f maciotwo: Fix grammar. 2025-06-20 07:03:04 -07:00
joevt fbfbfb4b33 grandcentral: Fix grammar. 2025-06-20 07:02:55 -07:00
Maxim Poliakovski af25d41375 grandcentral: move simple methods to macio.h 2025-06-18 22:59:13 +02:00
Maxim Poliakovski 508c4fa461 macio.h: reorganize, improve comments. 2025-06-17 16:35:33 +02:00
Maxim Poliakovski 20eec5cdc8 Remove ohare.cpp source. 2025-06-17 16:17:11 +02:00
Maxim Poliakovski 6b50f85bfc Switch to MacIoTwo's OHare. 2025-06-17 16:17:11 +02:00
Maxim Poliakovski a27ba815e4 Remove heathrow.cpp source. 2025-06-17 16:07:05 +02:00
Maxim Poliakovski 6142033397 machinebondi: switch to Paddington. 2025-06-17 16:07:05 +02:00
Maxim Poliakovski 7674bc3677 machineyosemite: switch to Paddington. 2025-06-17 16:03:59 +02:00
Maxim Poliakovski 157bd6de88 Switch to MacIoTwo's Heathrow. 2025-06-17 15:52:46 +02:00
Maxim Poliakovski 53eafa5f24 New class MacIoTwo for OHare/Heathrow/Paddington emulation. 2025-06-17 15:27:48 +02:00
Maxim Poliakovski 2701a72598 New class MacIoBase.
Contains common building blocks for various MacIO ASICs.
2025-06-17 15:27:48 +02:00
Maxim Poliakovski 5b1c832a05 Remove duplications of INT_TO_IRQ_ID macro. 2025-06-17 15:27:48 +02:00
Maxim Poliakovski c317ed8b42 ppcmmu: fix TLB invalidation again. 2025-06-17 13:08:31 +02:00
dingusdevandSean McBride 253cffbaca More Loguru fixes for BSD OSes
Co-Authored-By: Sean McBride <[email protected]>
2025-06-03 20:31:44 -07:00
joevt 60558ebf71 videoctrl: Template endianness.
The methods don't need to be virtual.
2025-06-02 05:55:28 -07:00
joevt a1a22cb1ef displayid: Add comments to read_monitor_sense. 2025-06-02 05:55:16 -07:00
joevt 723e84930b superdrive: Add logging. 2025-05-31 14:53:47 -07:00
joevt b7a4e14ee9 floppyimg: Include the path in log messages.
Because there can be more than one floppy.
2025-05-31 14:53:34 -07:00
joevt bd9d7ea275 swim3: Clear timer id to 0 only when cancelling.
Maybe cancel_timer should take a reference and set it to zero for us?
2025-05-31 14:49:24 -07:00
joevt ca77b141a6 machinefactory: iMac G4 has 4.4.1f1. 2025-05-30 19:05:43 -07:00
Maxim Poliakovski 2068803c6b amic: simplify VIA2_IFR writes. 2025-05-29 15:40:26 +02:00
joevt 35f2ce14f1 Add type and description to device descriptors.
Add supports_types to device descriptors so that we can determine
supported types without having to create the hardware device.
Add description so that each device can have an optional description.
2025-05-28 17:58:08 +02:00
joevt 6f00113554 Move MeshTnt to GrandCentralTnt.
Also create GrandCentralCatalyst which doesn't include Mesh.
2025-05-27 07:57:16 -07:00
joevt a8b6a16e1a Move ScsiCurio to Sc53C94. 2025-05-27 07:56:26 -07:00
joevt 393854dee0 heathrow: Spelling. 2025-05-27 07:52:10 -07:00
joevt bbbaf00b9a Move ScsiMesh to MeshTnt and MeshHeathrow. 2025-05-27 07:51:37 -07:00
Rairii bf396600ba displayid: Modify default EDID.
Wrap 8 bytes per line.
Add these modes:
    IBM     :   720x400    87.849542 Hz   9:5     39.444 kHz     35.500000 MHz
    DMT 0x0f:  1024x768i   86.957532 Hz   4:3     35.522 kHz     44.900000 MHz
    DMT 0x24:  1280x1024   75.024675 Hz   5:4     79.976 kHz    135.000000 MHz
    Apple   :  1152x870    75.061550 Hz 192:145   68.681 kHz    100.000000 MHz
2025-05-27 07:10:29 -07:00
Maxim Poliakovski 143498f5dd scsihd: implement MODE SENSE, page 4.
Page 4 aka Rigid Disk Drive Geometry Parameters
is required for the rz_disk driver in MkLinux.
2025-05-26 21:37:19 +02:00
Maxim Poliakovski eb61ab8c61 viacuda: implement T1 free-run mode. 2025-05-26 21:37:19 +02:00
Maxim Poliakovski 89139f3bae viacuda: fix VIA T2 emulation. 2025-05-26 21:31:26 +02:00
Maxim Poliakovski 2419731dbc viacuda: fix VIA T1 one-shot emulation.
Implement T1 to closely match the Apple VIA cell spec.
2025-05-26 21:31:26 +02:00
dingusdev 8258b7fb28 Further code cleanup 2025-05-23 06:31:42 -07:00
dingusdev 3646732db3 Fix soundserver_cubeb compilation warnings 2025-05-22 06:37:43 -07:00
joevt 224d869bdd pcibase: Implement status register write.
Writing a 1 to a status register bit will clear that bit. The following bits can be cleared:
- 15 Detected Parity Error
- 14 Signaled System Error
- 13 Received Master Abort
- 12 Received Target Abort
- 11 Signaled Target Abort
-  8 Master Data Parity Error
2025-05-22 06:27:24 -07:00
joevt 69490df8f8 pcicardbusbridge: Fix pci_io_write. 2025-05-22 06:26:55 -07:00
dingusdev 27e99edfeb Start SCSI reassign cmd 2025-05-21 19:44:37 -07:00
Maxim Poliakovski 101d8aa885 ppcmmu: fix TLB invalidation.
The PowerPC manual says that `tlbie` only considers
bits 4-19 of the EA. Set the mask accordingly.
2025-05-21 18:42:57 +02:00
Maxim Poliakovski 9f9160c956 Cleanup devices/CMakeLists.txt 2025-05-09 12:45:06 +02:00
dingusdev af055e0519 Manual tweaks 2025-05-04 17:40:48 -07:00
joevt f2f048d435 hostevents: Fix mouse grab for multiple displays.
Create a mouse grab toggle event to toggle the mouse grab using the current window. After the toggle event is transmitted, transmit a mouse grab changed event so that all windows can update their title.
2025-05-03 06:04:07 -07:00
joevt a62a1dcd09 machinebondi: Grackle machines use separate banks.
For the set of grackle machines, you can change the machine argument without having to change the ram bank sizes arguments.
For example, all grackle machines can specify 1 GiB using two 512 MiB ram banks.
2025-05-01 06:53:04 -07:00
joevt 74da4e148d debugger: Ensure cout fill changes back to right. 2025-04-29 06:31:15 -07:00
joevt c0cd18323e profiler: Ensure cout fill changes back to right. 2025-04-29 06:30:19 -07:00
joevt b848ea2300 ofnvram: Explicitly set cout fill direction. 2025-04-28 19:40:03 -07:00
joevt f9f77f78a8 ofnvram: Set cout fill direction back to right. 2025-04-28 19:39:55 -07:00
joevt f7b88cf5ee machinefactory: Set cout fill to right.
Always set the fill direction explicitly in case someone set it to left elsewhere.
2025-04-28 07:05:32 -07:00
joevt 72dbafdb3f debugger: Format 68K register dump.
Fix alignment and use 8 hex digits for each register.
2025-04-28 07:00:57 -07:00
joevt f55d5c9002 debugger: Use FILENO defines. 2025-04-28 15:05:40 +02:00
dingusdev 65d414bd4e Fixing compile issues 2025-04-28 15:05:40 +02:00
joevt fa5e8b0bf8 amic: Return random value for SCC DMA Rcv.
This allows Mac OS 8.5 and Mac OS 8.5.1 to boot from SCSI of Power Mac 6100.
2025-04-28 15:05:40 +02:00
joevt b05dec8778 viacuda: Add some memory address notes.
These are registers used during boot of Mac OS 8.5 from SCSI on Power Mac 6100.
2025-04-27 09:27:02 -07:00
joevt 24a18f7769 amic: Define local variable in minimum scope. 2025-04-27 07:33:30 -07:00
joevt a74ad4b1d1 amic: Add some register notes.
These are registers used during boot of Mac OS 8.5 from SCSI.
2025-04-27 07:32:33 -07:00
joevt 6c430b7d83 poweropcodes: Use ROTR_32 where possible. 2025-04-24 19:16:43 -07:00
dingusdev 2ce4e13170 ROTL_32 header fixes 2025-04-24 06:36:11 -07:00
joevt 746f461c5b ppcopcodes: Use ROTL_32 where possible. 2025-04-24 06:34:52 -07:00
joevt 00be8ce606 display: Fix update_mouse_grab.
Need to ungrab the mouse to move it.
2025-04-24 06:34:18 -07:00
joevt a1f15228fd display: Fix Visual Studio compiler warnings. 2025-04-24 06:34:04 -07:00
joevt 16762ab9e3 bitops: Handle rotate count 0. 2025-04-24 06:33:54 -07:00
joevt 28c497e455 bitops: Spelling. 2025-04-24 06:33:31 -07:00
joevt 5b3043c372 ppcfpopcodes: Remove redundant expression. 2025-04-24 06:33:22 -07:00
joevt 0019681be4 Properly merge "display: Remove resizing flag." 2025-04-23 21:12:03 -07:00
dingusdev c1ed416b58 Revert "display: Remove resizing flag."
This reverts commit c781ba8fab.
2025-04-23 21:08:45 -07:00
joevt 72ef266d07 display: Update grabbed mouse when resizing.
If the window's size is reduced such that the grabbed mouse is no longer inside the window, then a mouse click will go to another app. Therefore, check the mouse position and update if necessary every time the window changes size.
2025-04-23 06:56:25 -07:00
joevt c781ba8fab display: Remove resizing flag.
It doesn't do anything useful yet and setting the resizing flag to true stops updates if the window doesn't actually change size.
2025-04-23 06:50:24 -07:00
joevt c6013f076a ppcmmu: Fix DMA for adjacent cross region ranges.
If a DMA range extends beyond the end of a region into a second region of the same type (either RAM or ROM), and the regions are adjacent in both the guest and host address spaces, then allow the DMA to proceed.
2025-04-23 06:32:28 -07:00
joevt 9c6a7de45f ppcopcodes: Remove unnecessary type casts. 2025-04-23 06:15:38 -07:00
joevt 47c66666bb display: Add zoom and fullscreen no letterbox.
Added a third full screen mode which removes letterbox or pillarbox black bars.
Added Control-- and control-+ to decrease or increase the scale by a factor of 2^(1/8). This means the scale doubles or halves after pressing the same key 8 times.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

For backward compatibility, honor both mouse clicks and shoulder button presses
on the host when considering the state of the emulated trigger buttons.
2024-10-06 23:43:50 -07:00
Keith Kaisershot d23f21b391 sdl: handle gamepad events
Add new GamepadButton enum with bits corresponding to AppleJack button bits.
Both the AppleJack controller and the SDL GameController coincidentally define
one d-pad, two shoulder buttons, four face buttons, and three system buttons.
This makes mapping modern game controllers to the AppleJack straightforward.
2024-10-06 23:28:05 -07:00
Keith Kaisershot 6696248158 adbbus: decouple ADB devices from CUDA
AdbMouse and AdbKeyboard are subdevices of the CUDA device alongside AdbBus.
This doesn't make sense because conceptually, ADB devices hang off of the ADB
bus, not CUDA itself. An ADB bus can exist without a CUDA present, for example
Egret on older 68K Macs and the PMU on newer Power Macs. Therefore, make the ADB
device list a subhierarchy of AdbBus instead. Add a new "adb_devices" property
belonging to AdbBus that can allow users to specify ADB devices on the command
line at machine creation time, independent of the emulated bus's host. Make this
property default to "Mouse,Keyboard" to preserve existing behavior.
2024-10-06 23:20:10 -07:00
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
dingusdev ce9a1a6d9e A bit more clean-up 2024-05-09 19:09:06 -07:00
dingusdev a95b06f703 Minor code clean-up 2024-05-08 07:07:32 -07:00
joevt 226c097b81 escc: Update RR0 if no character is available.
The RR0_RX_CHARACTER_AVAILABLE bit is cleared after the character is read in receive_byte, but clear it anyway in read_reg when there's no character available just in case a character that was available somehow becomes unavailable.
2024-05-07 06:45:01 -07:00
Maxim Poliakovski a18658fc16 machinetnt: break long lines. 2024-05-07 08:40:08 +02:00
Maxim Poliakovski 971f6d79be scsicdrom: reduce code duplication. 2024-05-07 08:37:52 +02:00
Maxim Poliakovski ed67ab81a3 scsicdrom: switch off info log in INQUIRY. 2024-05-07 08:37:52 +02:00
Maxim Poliakovski 07304781ea scsicdrom: improve MODE_SELECT_6 stub. 2024-05-07 08:37:52 +02:00
joevt 941a405cf8 escc: Implement RR8 and WR8.
Normally, the Port_B_Data or Port_A_Data address is used to directly access RR8 or WR8, but setting the register pointer in Port_B_Cmd or Port_A_Cmd to RR8/WR8 is another option.
Update write_regs[WR8] and read_regs[RR8] for possible debugging purposes.
2024-05-06 21:11:36 -07:00
joevt b60d3061b7 escc: WR9 fixes.
Update write_regs[WR9] even though most or all of the bits are in master_int_cntrl.
Fix hardware reset for WR9. It's supposed to leave WR9_NO_VECTOR | WR9_VECTOR_INCLUDES_STATUS unchanged.
Fix channel reset for WR9. It's supposed to clear WR9_INTERRUPT_MASKING_WITHOUT_INTACK.
2024-05-06 21:11:21 -07:00
joevt 82e22174d6 escc: Set RR1 All Sent flag.
Helps booting Mac OS 8.1, etc.
2024-05-06 20:49:59 -07:00
joevt cf9811d03a escc: Read ch_a is missing register pointer reset. 2024-05-06 20:37:22 -07:00
joevt 19f06fb3a2 escc: Init or reset values in constructor.
Constructor should set all values to something so they are not random.
2024-05-06 07:28:04 -07:00
joevt 5710758dd7 escc: Add z85c30 register names. 2024-05-06 07:27:47 -07:00
joevt 181e1d2e46 escc: Add Channel Enhancement registers. 2024-05-06 07:23:05 -07:00
joevt 59fba285b5 adbmouse: Add tablet and more bits and buttons.
Add absolute coordinates for tablets. Absolute coordinates is relative to window so it can't work for multiple displays? Doesn't work for single display without mouse driver modification.
Add arbitrary number of buttons. Previously, only one mouse button was supported.
Add arbitrary number of bits. Previously, only 7 bits per axis was supported which is good enough for relative movement but not absolute movement.
2024-05-06 06:49:15 -07:00
joevt fdf8543c7e displayid: Update some display mode info. 2024-05-05 08:44:40 -07:00
joevt 86d8ae0911 soundserver_cubeb: Verify buffer is not null. 2024-05-05 06:52:59 -07:00
joevt 900e58f0ad swim3: Set write protect by default.
Until write support is added.
2024-05-01 06:52:11 -07:00
joevt 62e80c0c2f superdrive: Add name. 2024-05-01 06:52:01 -07:00
joevt 3483bebdb4 ati: Fix ver_blank calculation. 2024-04-25 06:52:00 -07:00
joevt 11d61359c1 dbdma: Add data callbacks.
Allow the dbdma program to initiate reading/writing by adding in and out callbacks.
Support the DBDMA flush command by adding a flush callback. If the transfer completes, then clear the flush flag, otherwise leave it unchanged.
Clear the flush flag after it is copied to the xferStatus of the DBDMA command.
2024-04-24 07:09:56 -07:00
joevt 30afcb6ddc ppcmmu: Allow map dma for last byte of region.
cur_dma_rgn->end is the last byte of a region. It is not the byte after the region. Therefore, subtract 1 from size before doing compare.

Also add more detail to the abort messages.
2024-04-24 06:50:53 -07:00
joevt ad45ce8499 ppcmmu: Make dummy pages two pages.
In case we need a write to span a page boundary.
2024-04-24 06:49:11 -07:00
joevt 9a489d13f4 machinetnt: Add 604 cpu option. 2024-04-24 06:48:52 -07:00
joevt 721c70166c control: Fix 1280x960 and 1280x1024 15bpp.
Change the fb_ptr. This also affects the hardware cursor.
Tested with 4MB of VRAM.
2024-04-24 06:48:41 -07:00
joevt 861c2d4f04 athens: Allow P2_MUX bit 6 to be 1.
For modes 12 inch RGB 512x384@60 and VGA 800x600@72.
2024-04-24 06:48:27 -07:00
joevt da203b69c5 escc: One return path for read. 2024-04-24 06:48:02 -07:00
joevt 159fe8d48e escc: Attempt to add DBDMA support.
Move dma channels from EsccController to EsccChannel.
Add DBDMA callbacks.
2024-04-24 06:46:35 -07:00
joevt 6adba32238 atirage: Update VBLANK bit.
It should not remain set.
2024-04-23 21:35:47 -07:00
joevt d96da6434f atirage: Redraw framebuffer if DAC or fb changes. 2024-04-23 21:35:34 -07:00
joevt 5f37421ceb atirage: Add ability to read from PCI option rom.
Usually there is not PCI option rom if the chip is built-in to the motherboard such as in the Beige G3.
2024-04-23 08:01:54 -07:00
dingusdev 6f64e729c8 Tweak logging value for compiling 2024-04-23 07:59:23 -07:00
joevt 288e088f8a atirage: Fix hardware cursor update.
Switching from Watch to Arrow cursor at vertical position zero (top of the screen) would sometimes cut off the top half of the Arrow cursor. The following changes fix this:

Use the new cursor_dirty flag to signal when the cursor should be updated. This reduces the number of cursor updates and doesn't depend on registers being accessed in a specific order.

Set the cursor_dirty flag for any change that should cause the hardware cursor to be updated:
- CUR_CLR0, CUR_CLR1: Cursor color changes. We don't check if the colors actually changed (all cursors are usually black and white). Rather, writes to these registers usually means the cursor bytes have changed or will change.
- CUR_OFFSET: Offset to cursor bytes.
- CUR_VERT_OFF: First vertical line of cursor to draw.
Other changes that don't require the cursor to be updated:
- CUR_HORZ_OFF: Horizontal offset of cursor position. The cursor is unchanged - just need to adjust the drawing position.
- CUR_HORZ_VERT_POSN: The cursor is unchanged - only the drawing position is changed.
The only thing that could change the cursor that we don't check is a change to the cursor bytes.
2024-04-23 07:58:20 -07:00
joevt 3797fdbf1b atirage: Move fb_pitch calculation. 2024-04-23 07:55:51 -07:00
joevt 3036f4676d Use default window size in constructor.
The window size should be changed later by the mon_id property.
2024-04-23 07:27:52 -07:00
joevt e14b6677b2 displayid: Fix non-extended sense codes.
Sense codes for displays like the 12 inch RGB display (512x384) weren't working since they had the extended part set to 0xff.
Related to issues #25.
Also added some descriptive information and sizes which may be used for UI purposes such as creating a menu of displays to choose from. The sizes may be used to set the default window size for the display.
2024-04-23 06:52:38 -07:00
joevt 76f966845d viacuda: Use timer ids instead of timer flags. 2024-04-23 06:44:02 -07:00
joevt 288d97f24c atimach64gx: Add missing WRITE_VALUE_AND_LOG.
This commit fixes conflict resolution mistakes in the following commits:
"atimach64gx: Let crtc_update calculate fb_ptr."
"atimach64gx: Redraw only when necessary."

"atimach64gx: Log unhandled overlay registers." was mistakenly included in "atimach64gx: Let crtc_update calculate fb_ptr.". The OVR_ registers were included because they may be needed for 2D acceleration in System 7.5.3 and later.
2024-04-23 06:43:08 -07:00
joevt 755dd7f60a atimach64gx: Redraw only when necessary. 2024-04-22 20:13:37 -07:00
joevt e6d669d187 atimach64gx: Check end of regs region.
There's only up to 256 regs.
2024-04-22 20:02:38 -07:00
joevt 0d1a2d3010 atimach64gx: Cleanup. 2024-04-22 20:00:54 -07:00
joevt 51af94f12d atimach64gx: Add properties. 2024-04-22 20:00:38 -07:00
joevt 8d7ca7fb03 scsibus: Use bus name in log messages. 2024-04-22 07:50:01 -07:00
joevt bc691a9d86 scsibus: Check for invalid target_id. 2024-04-22 07:48:37 -07:00
joevt 2c79171be6 atimach64gx: Fix CONFIG_CNTL and MM_REGS_OFFSET.
Init them to defaults.
Make CONFIG_CNTL 8 bytes so unaligned read/write is easier.
Write changes to CONFIG_CNTL even if offset + size is > 4.
Log aperture change only if first byte (LSB) of CONFIG_CNTL is written. The driver might only write to the 2 most significant bytes which won't affect aperture size.
Offset and size are applied to the destination, not to source value, so we shouldn't use extract_bits when logging value.
Use ATI bitfield enums in switch statement.
2024-04-22 07:48:00 -07:00
joevt e91432f939 atimach64gx: Fix interrupts.
Required for moving the mouse.
2024-04-22 07:33:08 -07:00
joevt ea7b9db078 atimach64gx: Reset comp_index to 0. 2024-04-22 07:32:51 -07:00
joevt a22bc34816 viacuda: Fix get/set time and one sec modes.
The first packet the one sec mode should send is a mode 1 real time packet, same as GET_REAL_TIME.
A mode 2 packet is the same but doesn't include the time.
2024-04-22 07:22:49 -07:00
joevt 2b76d8a53a viacuda: Remove parameters from pseudo_command.
They are incomplete or unused (includes cmd and count but not the data and the count isn't used). Might as well get everything from the class fields in_buf and in_count.
2024-04-22 07:11:22 -07:00
joevt 5f6b924004 appleramdac: Cursor lo-byte position delay option. 2024-04-22 14:51:16 +02:00
Maxim Poliakovski dfd4d82693 machinepippin: connect Taos. 2024-04-22 00:15:29 +02:00
Maxim Poliakovski e5282f9852 Initial Taos emulation. 2024-04-22 00:15:29 +02:00
Maxim Poliakovski b2c342e453 atimach64gx: break long lines. 2024-04-21 23:16:35 +02:00
Maxim Poliakovski 3aad040f28 mesh: improve exception register emulation. 2024-04-21 23:04:12 +02:00
Maxim Poliakovski e722ef3e8a memctrlbase: add get_region_hostmem_ptr(). 2024-04-21 23:04:12 +02:00
Maxim Poliakovski e94be9acee scsibus: break long lines, fix indentation. 2024-04-21 23:04:12 +02:00
joevt ae5a1331b6 atimach64gx: Remove abort for not loaded ROM.
Allows emulating non-ROM variant of a PCI card by just removing the ROM file.
2024-04-21 13:56:42 -07:00
joevt a0052b7b9a appleramdac: Use local variable during loop. 2024-04-21 13:55:44 -07:00
joevt 503ee92528 appleramdac: Always change cursor position.
Tests in Open Firmware confirm that writing to CURSOR_POS_LO will change the cursor position even if a write to CURSOR_POS_HI doesn't happen.
2024-04-21 13:41:06 -07:00
joevt 6c3715cc32 atimach64gx: Let crtc_update calculate fb_ptr.
Move the calculation to crtc_update where we calculate everything else (including bits per pixel which is needed for the fb_pitch calculation).
2024-04-21 13:25:05 -07:00
dingusdev a5416f521a Added a note for the 603 2024-04-21 11:11:56 -07:00
joevt a8023bb41b ppcmmu: Remove last_dma_area.
DMA may happen on CPU and audio threads but update of last_dma_area is not thread safe.
2024-04-21 09:13:42 -07:00
dingusdev fa01699786 Slight formatting fix 2024-04-21 08:59:18 -07:00
dingusdev 5f1150cf4e Initial expansion of documentation 2024-04-21 08:44:03 -07:00
joevt 5022ac89b4 ppcexec: Improve realtime. 2024-04-21 07:16:47 -07:00
joevt 382246905b videoctrl: Init palette to black. 2024-04-21 06:06:13 -07:00
joevt a5241d27c1 viacuda: Cleanup. 2024-04-21 06:03:32 -07:00
joevt 4479ecb1bb viacuda: One exit path for read. 2024-04-21 06:03:17 -07:00
joevt b454ab45fe viacuda: Spelling. 2024-04-21 06:02:52 -07:00
joevt d06d80619e viacuda: Add 1 Sec Timer, fix Get/Set Real Time.
GET_REAL_TIME was using the wrong offset and wasn't setting out_count.

May need to add time zone offset which could be different between host and guest.
get-time and set-time can be tested in Open Firmware.
SET_REAL_TIME is used by the Date/Time Control Panel when you change the date.
It is unknown what method Mac OS uses to get the time at boot. Mac OS 8.6 does not use GET_REAL_TIME during boot, so the time is left as 12:00 AM Jan 1, 1904.
2024-04-21 06:01:40 -07:00
Maxim Poliakovski 9a70c3bdb0 Remove bogus atirage128.cpp 2024-04-15 17:17:04 +02:00
dingusdev 103ef6169c Continued expanding zdocs 2024-04-15 07:52:09 -07:00
dingusdev 1a165ff64c Update manual.md 2024-04-15 07:28:30 -07:00
dingusdev 8cbbb2ed50 Initial preparation for a release 2024-04-15 07:01:51 -07:00
Maxim Poliakovski 781d9b46da athens: allow setting custom XTAL frequency. 2024-04-15 14:38:46 +02:00
Maxim Poliakovski ffa221192d athens: use component's name in logging messages. 2024-04-15 14:21:08 +02:00
Maxim Poliakovski 751f964139 athens: clean up initialization. 2024-04-15 14:21:08 +02:00
joevt 14f75d834a macio: Add list of OHare/Heathrow bits. 2024-04-12 19:54:34 -07:00
Maxim Poliakovski 96efc99a00 control: clean up register bit definitions. 2024-04-11 17:50:50 +02:00
Maxim Poliakovski 45d2c8854d Revert "macio: Add fatman bits register."
This reverts commit 8aaf211c5b.
2024-04-11 17:18:20 +02:00
Maxim Poliakovski c22843f238 appleramdac: vendor ID for AT&T fabbed RAMDACs. 2024-04-11 17:10:44 +02:00
joevt 1c5009fcb0 amic: Add more registers. 2024-04-10 20:59:34 -07:00
joevt bd63d1dcda platinum: Validity check before enable display. 2024-04-10 20:56:51 -07:00
joevt 8aaf211c5b macio: Add fatman bits register.
This register is used in the control ndrv to detect presence of connected S-Video or composite video display.
2024-04-10 20:48:29 -07:00
joevt 8cc5838efe control: More register bits. 2024-04-10 20:48:12 -07:00
joevt 4b965c623b machinetnt: Add more Power Macs. 2024-04-10 20:36:59 -07:00
joevt be27ceed00 machinetnt: Remove sixty6 and mesh properties.
Use the presence of the devices in the MachineDescription to determine these.
2024-04-10 20:19:43 -07:00
joevt 1d75730d44 dbdma: Do interrupt on main thread.
These may be triggered by other threads (such as for audio) so use the timer manager to handle them in the main thread.
2024-04-10 19:17:49 -07:00
joevt 95d74a6940 scsihd: Check Lun for INQUIRY.
INQUIRY now returns 0x7f for device type if LUN doesn't match. INQUIRY can get LUN from CDB or from IDENTIFY message.
2024-04-10 19:02:01 -07:00
joevt c6ea3a374e control: Fix PAL/NTSC interlaced display. 2024-04-10 07:32:35 -07:00
joevt e8ce805f2a poweropcodes: Remove power_setsoov.
None of the POWER opcodes uses it now, plus it is a duplicate of ppc_setsoov (though ppc_setsoov is inline so it would have to be moved to be able to use it in poweropcodes.cpp?
2024-04-10 07:30:06 -07:00
joevt 3d898ebdf3 poweropcodes: Cleanup power_rot_mask.
Use U instead of UL. U will use the smallest size that can fit all the unsigned bytes. Since 0xFFFFFFFF fits in 32 bits, the 0xFFFFFFFFU is a uint32_t.
2024-04-10 07:29:56 -07:00
joevt f45b7c47c8 poweropcodes: Fix srq.
Test bit 26 of rB instead of testing for >= 0x20 to determine which operation to perform.
2024-04-10 07:29:46 -07:00
joevt 916cb47b9d poweropcodes: Fix srlq.
Test bit 26 of rB instead of testing for >= 0x20 to determine which operation to perform.
2024-04-10 07:29:37 -07:00
joevt bce816139b poweropcodes: Fix sreq.
Including bits of rot_sh in the rA and MQ calculations is nonsensical since it is a rotation count and not a source of bits to be extracted or rotated.
The mask is not complicated, so we don't need to use power_rot_mask.
2024-04-10 07:29:28 -07:00
joevt 24bce16c4d poweropcodes: Fix srea.
Fix carry flag calculation. Anding with the rotation count (n = rB) is nonsensical.
(r & ~mask) is the rotated word ANDed with the complement of the generated mask of n zeros followed by 32 - n ones.
The manual says this 32-bit result is ORed together. This means all the bits are ORed together which is equivalent to saying 0 if all zeros and 1 if any ones. In other words: (r & ~mask) != 0.
This boolean is ANDed with bit 0 of rS to produce the carry. int32_t(rS) < 0 will test bit 0. The && operator will treat each side as a boolean so you can exclude "!= 0" tests.
2024-04-10 07:29:20 -07:00
joevt a928c67913 poweropcodes: Fix sraq.
If bit 26 of rB is set then the mask should be all ones.
If bit 26 of rB is set then rA should be all ones or all zeros (depending on the sign bit of rA).
2024-04-10 07:29:11 -07:00
joevt 2b8f510603 poweropcodes: Fix slq.
Test bit 26 of rB instead of using >= 0x20 to determine which operation to perform.
The two operations need to be switched such that rA is cleared when bit 26 is set.
Don't forget to store the result in rA.
2024-04-10 07:28:58 -07:00
joevt e8273ecc61 poweropcodes: Fix sllq.
Test bit 26 of rB instead of using >= 0x20 to determine which operation to perform.
Since the mask is not complicated, we don't need to use power_rot_mask.
2024-04-10 07:28:46 -07:00
joevt e1f31a2da3 poweropcodes: Fix rrib.
It is redundant to test bit 0 of rS and then use bit 0 of rS in the case when bit 0 of rS is set.
In the case when bit 0 of rS is not set, using bit 0 or rS is incorrect since it results in no change of rA.
2024-04-10 07:26:52 -07:00
joevt d897acfd3c poweropcodes: Fix nabs.
Calculate overflow first before calculating condition codes because the overflow condition is copied from XER.
2024-04-10 07:26:32 -07:00
joevt 1e57ac408a poweropcodes: Fix mul.
Operands are supposed to be twos complement numbers.
Calculate overflow first before calculating condition codes because the overflow condition is copied from XER.
Fix OV calculation. Previously, it was using power_setsoov which I think is only for add and subtract operations.
Fix CR calcalation. It's supposed to depend on the low order 32 bits that are placed into MQ.
2024-04-10 07:26:24 -07:00
joevt ef8522e101 poweropcodes: Fix maskg.
The condition code register depends on rA, not rD since rA contains the result.
2024-04-10 07:26:16 -07:00
joevt c71d856a08 poweropcodes: Fix lscbx.
- Fix CR calculation. It depends on whether a match occurred and only the EQ flag is affected.
- Remove bytes_copied. We can subtract bytes_remaining from bytes_to_load to calculate that.
- Initialize ppc_result_d to zero so that bitmask is not needed to add new bytes to it. This is ok since the manual says that bytes that are not loaded are undefined.
2024-04-10 07:26:07 -07:00
joevt df7ff76404 poweropcodes: Fix doz.
Calculate overflow first before calculating condition codes because the overflow condition is copied from XER.
Fix OV calculation. Previously, it was using power_setsoov which I think is only for add and subtract operations. doz does a subtract but only if the result is supposed to be positive, therefore a negative result indicates an overflow.
2024-04-10 07:22:50 -07:00
joevt 0d1ce68d19 poweropcodes: Fix divs.
dividend and divisor are supposed to be a twos compliment numbers.
Fix OV calculation. Previously, it was using power_setsoov which I think is only for add and subtract operations.
Fix CR calculation. It depends on the remainder, not the quotient.
2024-04-10 07:22:41 -07:00
joevt 88aa249ce1 poweropcodes: Fix div.
dividend is supposed to be a twos compliment number.
Fix test for dividend = -0x80000000 and divisor = -1. Previously, the test was assuming dividend was a 32-bit value from rA.
Fix OV calculation. Previously, it was using power_setsoov which I think is only for add and subtract operations.
Fix CR calculation. It depends on the remainder, not the quotient.
2024-04-10 07:22:34 -07:00
joevt ff626ae0b5 poweropcodes: Fix clcs.
For MPC601 CPUs, all values of rA return 64 though the manual says undefined values of rA produce undefined results.
For non-MPC601 CPUs, if this instruction is included (such as for risu DPPC) then return results that are obtained from a G4 running Mac OS 9.2.2.
2024-04-10 07:22:26 -07:00
joevt 529f23d836 poweropcodes: Fix abs.
Making a negative value positive requires unary negate operator rather than binary and operator since negative numbers are stored using twos compliment.
If ov is set then clear overflow when overflow doesn't happen.
2024-04-10 07:22:18 -07:00
joevt cb88bab67d ppcopcodes: Fixes for SPRs.
- Rename DEC to DEC_S and add DEC_U.
- MQ, RTCL_U, RTCU_U, and DEC_U should cause an illegal instruction program exception for non-MPC601 CPUs. The exception handler of classic Mac OS uses this to emulate the instruction.
- For mtspr, the SPRs RTCL_U, RTCU_U, and DEC_U are treated as no-op on MPC601.
- For debugging, use the supervisor instead of the user SPR number as the index for storing the values for RTC, TB, and DEC.
- For debugging, RTC, TB, and DEC should be updated after each access. Previously, mfspr and mtspr would only update the half of RTC and TB that was being accessed instead of both halves.
2024-04-10 07:21:54 -07:00
joevt 67a5c39b1c ppcopcodes: Add Privileged exception for SPRs.
Accessing an SPR with bit 4 set (> 15) requires supervisor privilege and should cause a supervisor-level instruction exception (privileged instruction type program exception).
2024-04-10 07:21:23 -07:00
joevt 0273867c49 ppcopcodes: Cleanup ppc_changecrf0.
- Use one assignment to set ppc_state.cr.
- Use enums for CR and XER bits.
- Use < to check sign bit.
2024-04-10 06:47:10 -07:00
joevt 1e50d88183 ppcopcodes: Use macro to grab instruction fields. 2024-04-10 06:46:46 -07:00
joevt 29a832c68d ppcopcodes: Use < 0 instead of & 0x8000000. 2024-04-10 06:45:31 -07:00
joevt cb05bd05eb cpu: Add ppc_grab_regssash macro.
This macro is like ppc_grab_regssa but includes rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
2024-04-10 06:43:34 -07:00
joevt 4f45d7de35 cpu: Add cpu options to ppc_cpu_init.
The first option is a flag that enables MPC601 (POWER) instructions for CPUs that are not MPC601.
This can be useful for the following reasons:
1) To produce results similar to classic Mac OS which emulates MPC601 instructions on CPUs that don't implement MPC601 instructions. This option is used to compare the risu traces produced in Mac OS 9 on a G3 or G4 with DPPC.
2) May increase performance in apps that use POWER instructions on emulated machines with CPUs that are not MPC601. It is not known if any such apps exist but there could be since Apple included MPC601 emulation in classic Mac OS.
2024-04-10 06:43:18 -07:00
joevt a6ba9a0554 memaccess: Add addr type cast. 2024-04-09 21:19:04 -07:00
dingusdev 9c95bc17fe Implement VX and FEX updates for mtfsfi 2024-04-09 21:11:09 -07:00
dingusdev 2c94cfee03 Removing currently unneeded functions 2024-04-09 18:34:36 -07:00
joevt 3c16870f86 ppcmmu: Replace defines.
They may interfere with system headers.
2024-04-09 07:57:48 -07:00
dingusdev 22f45902ca Merge pull request #89 from sdkmap/master
Enhanced GitHub Actions Workflow for DingusPPC Build Automation
2024-04-09 06:58:36 -07:00
sdkmap 28b1eb8524 CI
one commit.
2024-04-09 12:56:06 +03:00
Maxim Poliakovski 1c8702d67a Add missing credits. 2024-04-09 01:51:51 +02:00
Mihai Parparita cf4913deb0 bandit: Fix regression in non-Aspen PCI bridge
Refactor from e7da98b6bd accidentally
made the non-Aspen PCI code path for CONFIG_ADDR writes by a no-op.
2024-04-08 15:41:19 -05:00
Maxim Poliakovski bdd441b1b6 Add machinepippin.cpp to /machines. 2024-04-08 00:56:00 +02:00
Maxim Poliakovski 4c9fe06229 Implement Aspen memory controller. 2024-04-08 00:44:24 +02:00
Maxim Poliakovski e7da98b6bd bandit: implement Aspen style PCI bridge. 2024-04-08 00:44:24 +02:00
Maxim Poliakovski dcdfaabedf dbdma: skip transfer commands with reqCount=0. 2024-04-07 20:39:24 +02:00
Maxim Poliakovski 524daa45a5 ppcexec.cpp: fix compilation with Apple Clang 10. 2024-04-07 20:39:24 +02:00
Maxim Poliakovski 073b8fd981 atimach64defs: add ATI_DP_CHAIN_MSK register definition. 2024-04-07 18:48:52 +02:00
Maxim Poliakovski d7749e0a2c awacs: small cosmetic improvements. 2024-04-07 18:48:52 +02:00
Maxim Poliakovski 7972a0f2a8 hammerhead: use instance name in logging messages. 2024-04-07 18:48:52 +02:00
Maxim Poliakovski 19dcb43658 pcibase.h: remove superfluous spaces. 2024-04-07 18:48:52 +02:00
joevt 9ed1a118e6 ppcmmu: Check sizeof(T) explicitly.
I don't know if the compiler is smart enough to figure out that ((guest_va & 0xFFF) + sizeof(T)) > 0x1000) is always false when sizeof(T) == 1 so we'll add a check for sizeof(T) > 1.
2024-04-07 08:59:05 -07:00
dingusdev a5a5410515 Continued fixing floating-point ops 2024-04-07 08:58:38 -07:00
dingusdev 40a4ca31b9 More minor floating-point clean-up 2024-04-07 07:23:30 -07:00
dingusdev 7f44ab2262 Minor fixes to floating point 2024-04-06 17:31:03 -07:00
dingusdev 123c927b1a Another refactor for floating points
FCMPO and FCMPU passes the tests now*
2024-04-06 11:02:03 -07:00
joevt 74274f164d G3 CPU upgrade property. 2024-04-04 19:05:59 -07:00
joevt 5c2bd0b3bb machines: Don't override existing properties. 2024-04-04 19:04:33 -07:00
joevt d0a5a1e7be Add ability to override built-in GPU. 2024-04-04 19:04:06 -07:00
joevt 077e6ebae5 machineid: Don't decode board register address.
All addresses return the same value. Converted for Board Register 1 and Board Register 66.
2024-04-03 19:53:03 -07:00
joevt abe0c14301 scsibus: push_data of zero bytes is ok.
It just means the data hasn't been put on the fifo yet.
2024-04-03 19:51:50 -07:00
joevt 61576d4032 sc53c94: Check drq_cb. 2024-04-03 19:35:58 -07:00
joevt 782a8d2c3c sc53c94: CMD_COMPLETE_STEPS includes INTSTAT_SO.
Last step of CMD_COMPLETE_STEPS includes INTSTAT_SO to indicate to CurioSCSIController::fsmCompleting that it returned both a status byte and a message byte in the FIFO.
2024-04-03 19:35:27 -07:00
joevt e619dd2493 sc53c94: CMD_COMPLETE and XFER_END goes to IDLE.
CMD_COMPLETE and XFER_END goes to the IDLE sequence state so that reentry doesn't cause a second interrupt.
2024-04-03 19:35:13 -07:00
joevt 8a1055ed1b sc53c94: Add DBDMA support.
- For pdm/amic, real_dma_xfer is called when SCSI_DMA_Ctrl has the run bit set.
- For tnt/grandcentral, dma_wait is called when the DBDMA is started (run bit is set). It will call real_dma_xfer when the phase and sequence are DATA_IN/RCV_DATA or DATA_OUT/SEND_DATA.
- dma_wait and real_dma_xfer uses a one shot timer instead of a loop to continue doing DMA while also giving time to the CPU. This and the above changes handles the case where the DBDMA is started before setting up the transfer phase and sequence.
- dma_stop will stop the one shot timer when the DBDMA channel is stopped.
2024-04-03 19:19:42 -07:00
joevt ff766b10eb sc53c94: Add seq_id to sequence descriptor.
The seq_id can be used for logging the current command and step number.
2024-04-03 18:43:46 -07:00
joevt ceb2276098 sc53c94: Move chip_id to xfer_count.
Method for reading chip_id needs verification.
2024-04-03 18:43:40 -07:00
joevt 82f4d05f4b sc53c94: Set timer_id to zero.
If a timer is not in progress then set its timer_id to zero. Also, don't start a newer timer if an existing one is still in progress.
2024-04-03 18:36:53 -07:00
joevt 8a81cb4f9c sc53c94: Use enums. 2024-04-03 18:12:00 -07:00
joevt 1504bd2227 sc53c94: Move DATA_FIFO_MAX from header.
Headers shouldn't make defines that are not meant to be used outside the source file.
2024-04-03 18:11:07 -07:00
dingusdev 475f894582 Comment out log message 2024-04-02 19:21:56 -07:00
joevt 7007e002e6 macio: Make interrupt flags atomic.
So they can be modified by other threads.
2024-04-02 19:05:57 -07:00
joevt 9af1b1a720 control: Narrow the scope of local variable. 2024-04-01 22:12:20 -07:00
joevt ca9657baf1 control: Update little-endian error message. 2024-04-01 22:12:05 -07:00
joevt 3e347746f9 control: Don't abort when setting little endian.
If this gets set accidentally, (such as while playing in Open Firmware), allow the user to change it back.
2024-04-01 22:11:35 -07:00
joevt b5987afaa6 control: Implement BAR update. 2024-04-01 22:11:30 -07:00
joevt ea46d08835 appleramdac: Allow read from CLUT part 2. 2024-04-01 21:47:59 -07:00
joevt 789114cc7d control: Save CNT_TST and MON_SENSE.
These are writable registers that should return what was written to them.
2024-04-01 21:34:26 -07:00
joevt cf292fafcb control: vram changes.
Allow VRAM presence only in optional bank.

control: Implement banks.

The BAR is 64MB.
The little-endian/big-endian ranges repeat every 16MB.
An endian range can be addressed in d128 (wide) mode or d64 mode.
In d128 mode, there is a 4MB range followed by an undefined 4MB range. bytes 0..7 belong to the standard bank and bytes 8..15 belong to the optional bank.
In d64 mode:
- 2MB mirror ranges at 0MB and 2MB (both have the same read/write behavor: write to both banks or read from the standard bank.
- 2MB standard bank rage at 4MB.
- 2MB optional bank range at 6MB.
2024-04-01 21:17:17 -07:00
joevt 08fca7de69 control: Recalc framebuffer after each change. 2024-04-01 20:58:46 -07:00
joevt b42437c458 control: Mask unmodifiable bits. 2024-04-01 19:01:03 -07:00
joevt 98e1787f93 machines: Remove duplicate gfxmem_size properties. 2024-04-01 18:28:13 -07:00
joevt 7a0ec0ecd3 README: Grammar. 2024-04-01 18:23:39 -07:00
dingusdev 55b9f8bbe5 bzero -> memset 2024-04-01 08:03:12 -07:00
joevt 2968645f2e scsihd: Allow INQUIRY allocation length != 36.
Truncate for < 36 and zero fill for > 36.
2024-04-01 08:02:17 -07:00
joevt 92dea0e404 scsihd: Include invalid field info.
For CHECK_CONDITION status from READ_CAPACITY_10.
2024-04-01 08:01:09 -07:00
joevt bfd3077bd0 scsicdrom: Check Lun for INQUIRY.
INQUIRY now returns 0x7f for device type if LUN doesn't match. INQUIRY can get LUN from CDB or from IDENTIFY message.
2024-04-01 08:00:41 -07:00
joevt 2d1616894d appleramdac: Allow read from CLUT. 2024-04-01 07:39:20 -07:00
joevt 7c203b40c8 appleramdac: Reset comp_index on address change. 2024-04-01 07:37:16 -07:00
joevt 2f63a2fa17 appleramdac: Add other vendor id. 2024-04-01 07:10:55 -07:00
joevt e3e065a6d7 appleramdac: Register comments. 2024-04-01 06:47:25 -07:00
dingusdev afd8ba8cf2 Slight adjustment for the readme 2024-03-31 15:09:57 -07:00
dingusdev 43d87b4791 Temp revert for icnt_factor
We should, at minimum, make icnt_factor adjustable. That said, powermax is suggesting we develop a more sophisticated scheduler.
2024-03-31 14:13:45 -07:00
joevt 6267685920 ppcexec: Make EXEF_TIMER separate variable. 2024-03-31 12:15:48 -07:00
joevt 48882f3fec ppcexec: Adjust icnt_factor.
So that 1000 ms takes ≈ 1 second in Open Firmware on 4 GHz Intel CPU.
2024-03-31 11:51:04 -07:00
joevt 0ac54ea1ea ppcexec: Add host time option. 2024-03-31 11:50:55 -07:00
joevt 4395ce01d7 ohare: Update name of Mesh device. 2024-03-30 17:56:19 -07:00
joevt 2c097da12d grandcentral: Add escc DMA. 2024-03-30 14:55:24 -07:00
joevt 5f316dc7a4 grandcentral: Adjust audio in DMA logging. 2024-03-30 12:49:33 -07:00
joevt 02a475e113 sc53c94: Remove duplicate bus_obj.
sc53c94 is a ScsiDevice which has its own bus_obj which is set by register_device.
2024-03-30 11:56:59 -07:00
joevt 338bbe27a8 scsihd: Implement REQ_SENSE.
Returns error information stored in class fields: sense, asc, ascq, sksv, and field.
2024-03-30 11:56:37 -07:00
joevt 44564065f6 scsihd: Changes for MODE_SENSE_6.
Return CHECK_CONDITION for unsupported page_ctrl or page or subpage.
Handle the all pages code 0x3F.
2024-03-30 11:56:02 -07:00
dingusdev c54ec7be2d Use memset instead of bzero 2024-03-30 11:19:32 -07:00
joevt 274e380b34 scsicdrom: Allow INQUIRY allocation length != 36.
Truncate for < 36 and zero fill for > 36.
2024-03-30 11:16:41 -07:00
joevt e872f08273 scsicdrom: Include invalid field info.
For CHECK_CONDITION status from READ_CAPACITY_10 and READ_TOC.
2024-03-30 11:00:01 -07:00
joevt a6fda3b787 scsicdrom: Handle MODE_SENSE_6 unsupported page.
Return CHECK_CONDITION status instead of abort. To Do: apply change to scshhd.
2024-03-30 10:59:43 -07:00
joevt a48851888f scsihd: Setup data_ptr for STATUS and MESSAGE_IN.
bytes_out is used instead of the removed cur_buf_cnt.
data_ptr is setup by prepare_data instead of process_command.
Not sure why scsicdrom doesn't set bytes_out in prepare_data.
2024-03-30 08:37:10 -07:00
joevt f1abb66f9a atahd: Add STANDBY_IMMEDIATE. 2024-03-30 08:30:37 -07:00
joevt c999c51d77 scsicdrom, scsihd: Check lun.
READ_CAPACITY_10, READ_6, and READ_10 now checks LUN that is included in CDB and returns a CHECK_CONDITION if it doesn't match.
2024-03-29 19:12:06 -07:00
joevt 6bb5227ee1 scsihd: Abort if RelAdr bit of READ_10.
Like scsicdrom does.
2024-03-29 19:01:42 -07:00
joevt cefe8698da scsihd: Add PREVENT_ALLOW_MEDIUM_REMOVAL.
Like scsicdrom has.
2024-03-29 19:01:32 -07:00
joevt 4be6bad526 scsicdrom: Fix compiler warning. 2024-03-29 19:00:38 -07:00
joevt d3c913e384 scsicdrom: Cleanup.
- Use macros for reading 2 byte or 4 byte big endian data. block_size is assumed to be < 64K so WRITE_DWORD_BE_A will write two leading zeros.
- Scalar pass by value parameters don't need to be const.
- Remove some unnecessary locals.
2024-03-29 18:53:13 -07:00
joevt a868f4eee4 scsihd: Cleanup.
Use this qualifier.
Use macros for reading 2 byte or 4 byte big endian data.
2024-03-29 18:53:04 -07:00
joevt 44da89979f scsihd: Use device name in abort message. 2024-03-29 18:52:52 -07:00
joevt a79f07e4dc scsicdrom: Move mode_select_6.
Make it a separate method like scsihd. It also checks the incoming param size. If it's zero then the phase is not switched. Is that wrong? Still probably unfinished.
2024-03-29 18:52:30 -07:00
Maxim Poliakovski e17a96f5ec atirage: break long lines. 2024-03-29 21:21:58 +01:00
joevt 5062508940 scsicdrom: Rename mode_sense_6.
To match scsihd.
2024-03-29 07:56:48 -07:00
joevt 9cf91328c1 scsicdrom: Move inquiry info to class fields.
Like scsihd.
2024-03-29 07:56:44 -07:00
joevt 6a30ef7017 scsicdrom: Fields inited by parent class.
They don't need to be reinitialized.
2024-03-29 07:56:31 -07:00
Maxim Poliakovski 71dabf5334 atahd: break long lines. 2024-03-29 12:46:57 +01:00
joevt 155b8cdad9 atahd: Support inexact CHS.
The total size needs to have 3 factors cylinders, heads, & sectors. Imagine a disk having a total size with 3 prime factors 3 x 5 x 11. 15 cannot be assigned to heads because that would only leave 11 for sectors and cylinders. Therefore, test all heads and sectors combinations. If the third factor for cylinders is not found, then choose 16 heads, then the minimum number of sectors, and finally the maximum number of cylinders. The loop could be changed to skip values of heads that are not a factor, but it doesn't take any time to try them all.
2024-03-28 21:07:12 -07:00
joevt 96dc02b249 atahd: Make sure disk is not too big. 2024-03-28 21:07:08 -07:00
Maxim Poliakovski eaddcab0ba atahd: don't register device for empty images.
Workaround for the case when no hard disk image
was specified. The device instance is still there
but it won't be visible by the guest OS.
2024-03-29 03:54:09 +01:00
joevt d9b02ecd8d ppcmmu: Check 8 byte alignment spanning pages. 2024-03-28 07:53:03 -07:00
joevt b9c12e44a4 ppcopcodes: Cleanup 3. 2024-03-28 07:36:40 -07:00
joevt 58ed5bb56e ppcexec: Opcode initialization to one function.
Move all opcode initialization to initialize_ppc_opcode_tables.
Some opcodes are illegal for some processors.
2024-03-28 07:35:57 -07:00
joevt 094f44e92c ppcopcodes: Make MQ read only on non-601 CPUs. 2024-03-28 07:29:50 -07:00
joevt 566706dd62 ppctests: Fix compiler warnings. 2024-03-28 07:17:38 -07:00
joevt 60a76e9348 ppcexec: Fix branch check in ppc_exec_single. 2024-03-28 07:17:13 -07:00
joevt 1d9b0f7fa5 macio: Add MIO_AUX_CTRL enum. 2024-03-28 07:10:05 -07:00
joevt f55ad323b4 ppcdisasm: Fix order of operands.
For cntlzw, extsh, extsb.
2024-03-28 07:09:50 -07:00
joevt 78558e4c52 debugger: Ensure space between opcode and operand.
Instructions that are 8 characters or longer (such as mtdbat3l) did not have a space between opcode and operand. Now there is always a space. The width of the opcode column is unchanged except for those opcodes that have 8 or more characters.
2024-03-28 06:54:23 -07:00
joevt c9d4cc3321 ppcmmu: Remove old and slow code. 2024-03-27 20:13:45 -07:00
joevt 0f8a464157 ppcmmu: Use MSR enums for calculating mmu_mode. 2024-03-27 18:44:59 -07:00
joevt e4a675babb ppcmmu: Remove line feed from log messages. 2024-03-27 18:44:42 -07:00
joevt 5b4ed01bec ppcexec: Make separate enum for shift instructions. 2024-03-27 18:43:46 -07:00
joevt 64df253053 ppcexec: Rename bool function enums.
Use "logical" since the functions deal with multiple bits instead of a single boolean value and because the 601 manual calls them Logical Instructions.
Use "ppc" for the enums because logical_and is defined elsewhere and because the original DPPC code used these names for those functions.
2024-03-27 18:43:35 -07:00
joevt d8129bd643 ppcexec: Add comments for macros. 2024-03-27 18:43:15 -07:00
joevt 60a4738694 Add stub for pci_unregister_device. 2024-03-27 18:23:27 -07:00
joevt 9ade14e076 memctrlbase: fix possible memory leak. 2024-03-27 14:08:20 +01:00
Maxim Poliakovski 6aa54b8dda ppcexec: break long lines, improve indentation. 2024-03-27 13:55:05 +01:00
Maxim Poliakovski 0ff911cc26 poweropcodes: cosmetic improvements. 2024-03-27 03:45:22 +01:00
Maxim Poliakovski b5b14b2f9d ppcopcodes: cosmetic improvements. 2024-03-27 03:36:17 +01:00
Maxim Poliakovski 2b6f41e0d0 poweropcodes: use XER constants instead of magic numbers. 2024-03-27 03:36:17 +01:00
Maxim Poliakovski 9b429cc751 ppcopcodes: replace magic numbers with XER constants. 2024-03-27 03:36:17 +01:00
dingusdev ec56dffd19 Adding missing includes 2024-03-26 19:25:05 -07:00
dingusdev a09f2093b5 Optimize register initialization
Courtesy of joevt, adapted to fit the C++ standard
2024-03-26 18:52:56 -07:00
dingusdev b15d3be88a Moving is_601 up, so the opcodes get initialized correctly 2024-03-26 18:41:16 -07:00
joevt a26628ed50 bandit: Add delayed aack register. 2024-03-26 07:34:08 -07:00
joevt 0b5a798343 atimach64gx: Fix ATI_CRTC_GEN_CNTL.
Add call to crtc_update.
Maybe consider AK and EN bits (placeholder for now).
2024-03-26 07:31:49 -07:00
joevt 224ae50e91 ppcexec: Make more instructions illegal for 601. 2024-03-26 06:50:33 -07:00
joevt 03d7728d46 ppcexec: Use macros to assign subopcode functions. 2024-03-26 06:50:17 -07:00
joevt 19ba15f2f1 ppc: Separate enums for separate fields. 2024-03-26 06:44:26 -07:00
joevt 9da9967b83 ppcopcodes: Cleanup 2. 2024-03-26 06:37:45 -07:00
dingusdev 1510c45ecb Fixed 601 flags 2024-03-26 06:36:32 -07:00
dingusdev 9b76c9fe3e Fix for mffs in opcode table 2024-03-25 20:04:13 -07:00
Maxim Poliakovski ea4564c827 machinepdm: implement extended RAM. 2024-03-26 00:39:33 +01:00
Maxim Poliakovski 0a97e4e038 hmc: implement extended memory for PDM. 2024-03-26 00:39:33 +01:00
Maxim Poliakovski 8e19164977 memctrlbase: introduce add_mem_mirror_common(). 2024-03-26 00:39:33 +01:00
Maxim Poliakovski ab60bb8d0b memctrlbase: cosmetic improvements. 2024-03-26 00:39:33 +01:00
dingusdev c7ca4d9b97 Merge pull request #80 from dingusdev/cpu-refactor2
Use templating for interpreter
2024-03-25 08:01:51 -07:00
dingusdev 3c3d0b46db Merge branch 'master' into cpu-refactor2 2024-03-25 07:45:21 -07:00
joevt f08d9ba81e ppcexec: Fix templated lhzux. 2024-03-25 07:43:34 -07:00
joevt 15a9ffd340 ppcopcodes: Indent. 2024-03-25 07:42:17 -07:00
joevt b9aae48517 ppcopcodes: Fix templated st. 2024-03-25 07:37:54 -07:00
joevt e2864ab08c ppcopcodes: Fix templated add. 2024-03-25 07:37:52 -07:00
joevt effe0198ce ppcexec: Fix bcctr templated parameters. 2024-03-25 07:36:46 -07:00
joevt c5ac862cef debugger: Add list of input and output registers.
So the debugger can show them during stepping.
The fmt_* functions now take a PPCDisasmContext instead of just the ctx->instr_str so that they can alter the context.
Some fmt_* functions have an alternate (e.g. fmt_twoop_in for fmt_twoop) to indicate a difference in input/output registers.
The mtsrin and mfsrin instructions use a register to indicate which sr register to use.
The string instructions may affect multiple registers but only the first is included in the list.
Removed some extra blank lines.

Fixes:
lscbx: Add r0 check.
mftb: Do simplified if the spr is illegal. Maybe should do illegal opcode instead?
2024-03-24 19:34:29 -07:00
joevt cd77e361ab ppcexceptions: Use MSR enums. 2024-03-24 18:53:05 -07:00
joevt bc5fd44172 ppcmmu: Don't log mmu_mode 1. 2024-03-24 18:52:49 -07:00
dingusdev c781820bf6 Continued table fixes 2024-03-24 17:43:14 -07:00
dingusdev 30802affd4 Continued fixes for tables 2024-03-24 17:24:36 -07:00
dingusdev eab021a5cb Regression fixes 2024-03-24 16:34:42 -07:00
dingusdev 505b5e6468 Slight tweak to PPC Macros 2024-03-24 15:35:11 -07:00
dingusdev 5631485465 Cleaning up templating 2024-03-24 14:06:07 -07:00
joevt fafbd9a04f mmiodevice: Move SIZE_ARG macro from pcibase. 2024-03-24 13:03:31 -07:00
joevt bc582e64cc dbdma: Clear cmd_in_progress before callback.
Because the callback might start DMA commands.
2024-03-24 13:01:12 -07:00
joevt df0044a110 dbdma: Make sure interrupt controller is set. 2024-03-24 13:00:58 -07:00
joevt 503556196a dbdma: Add missing flags, fields, comments. 2024-03-24 13:00:33 -07:00
joevt fd961f9ff9 Fix Analyzer warnings.
In Xcode, type Command-Shift-B to analyze every source file or Command-Shift-Control-B to analyze the current source file.

For pseudo_dma_read report FIFO underrun and init data_word in that case.
2024-03-24 12:56:11 -07:00
joevt e3411670cb videoctrl: Add cursor_dirty flag.
If the flag is set when it comes time to draw the cursor again, then call setup_hw_cursor to update the cursor before drawing the cursor.
2024-03-24 12:45:52 -07:00
joevt d134107aba atirage: Draw frame buffer only when it changes. 2024-03-24 12:45:30 -07:00
joevt 5de1c23aba adbbus: Don't abort. 2024-03-24 12:35:11 -07:00
joevt 72b257e5d1 atirage: Improve draw_hw_cursor loops.
- Read 8 bytes at a time instead of just 1.
- Remove multiply operations from loop. We just need increments or additions.
- Change compares with int to compares with zero.
2024-03-24 12:27:44 -07:00
joevt 9d0bae2d03 atirage: Add offset to cursor X position.
CUR_HORZ_OFF becomes non-zero when the cursor needs to be drawn to the left of the left edge of the frame buffer.

CUR_VERT_OFF is handled differently. When CUR_VERT_OFF is non-zero, CUR_OFFSET is changed to point to the first line of the cursor that will be drawn, so CUR_VERT_OFF is the number of lines to remove from the total height of the cursor.
Alternatively, we could handle CUR_VERT_OFF the same way as CUR_HORZ_OFF by leaving the cursor height constant, drawing the cursor starting from the CUR_VERT_OFF line, and adjusting cursor Y position by negative CUR_VERT_OFF.
2024-03-24 12:26:10 -07:00
joevt ad6d5e9ec9 atimach64gx: Improve draw_hw_cursor loops.
- Read 8 bytes at a time instead of just 1.
- Remove multiply operations from loop. We just need increments or additions.
- Change compares with int to compares with zero.
2024-03-24 12:25:55 -07:00
joevt 6462ceef24 atimach64gx: Add offset to cursor X position.
CUR_HORZ_OFF becomes non-zero when the cursor needs to be drawn to the left of the left edge of the frame buffer.

CUR_VERT_OFF is handled differently. When CUR_VERT_OFF is non-zero, CUR_OFFSET is changed to point to the first line of the cursor that will be drawn, so CUR_VERT_OFF is the number of lines to remove from the total height of the cursor.
Alternatively, we could handle CUR_VERT_OFF the same way as CUR_HORZ_OFF by leaving the cursor height constant, drawing the cursor starting from the CUR_VERT_OFF line, and adjusting cursor Y position by negative CUR_VERT_OFF.
2024-03-24 12:25:35 -07:00
dingusdev c281b27220 Attempted templating for interpreter 2024-03-24 12:21:19 -07:00
joevt 1d5502dc3c ppcemu: Make flags atomic.
For flags that might be accessed by other threads.
2024-03-22 19:04:51 -07:00
dingusdev 4ef3c792de Refactoring interpreter, pt. 1
Reduce the number of global variables used by interpreter
2024-03-22 08:01:29 -07:00
joevt a5aac5754c machinetnt: Add Bandit2 option. 2024-03-20 07:38:56 -07:00
joevt 23903a969d Add get_comp_by_name_optional. 2024-03-20 07:38:48 -07:00
joevt 78020c4794 Add Bandit2 and properties for Chaos. 2024-03-20 07:38:39 -07:00
Maxim Poliakovski 682f1900ae zdocs: add PDM RAM documentation. 2024-03-20 12:16:10 +01:00
Maxim Poliakovski a9cb0cfb2a atahd: report correct CHS parameters & capacity.
This is required for Open Firmware 2.x to boot Mac OS X
and OpenDarwin.
2024-03-20 12:16:10 +01:00
Mihai Parparita fc6a4872d6 Ensure that NVRAM is persisted when exiting the debugger after an abort
The SIGABRT handler is not invoked by the abort() call in the loguru
fatal handler, but either way it's not necessary (it does its own abort).

Switch to explicitly cleaning up the machine object, which as a side
effect in the destructor chain will persist the NVRAM.
2024-03-20 12:16:10 +01:00
dingusdev 284f58dec4 Continued build fixing 2024-03-16 19:24:40 -07:00
joevt e51bc0cea5 scsihd: Reorder switch statement.
Order by case value to match scsicdrom.
2024-03-16 17:44:09 -07:00
dingusdev da9770c99b Attempted build fix 2024-03-16 13:45:28 -07:00
joevt 266d45e13a timermanager: Make immediate timer more immediate. 2024-03-16 11:46:40 -07:00
joevt 703662cb5b timermanager: Add some thread safety. 2024-03-16 11:46:30 -07:00
joevt 833f74dce6 timemanager: Remove unnecessary parameter. 2024-03-16 11:36:41 -07:00
joevt 014aa90462 timemanager: Remove timer minimum timeout. 2024-03-16 11:36:25 -07:00
joevt f5dcaebbf8 timemanager: 0 is also < a positive integer. 2024-03-16 11:36:10 -07:00
dingusdev 02a9e8d886 Partial fix for writing qwords 2024-03-15 22:00:54 -07:00
joevt 4fe8cf76bb control: Fix framebuffer start for OF and macOS. 2024-03-15 10:27:48 -07:00
joevt d4ee43179c control: 15bpp mode is big endian. 2024-03-15 10:27:33 -07:00
joevt 5afe1f1a25 control: MISC_ENABLES is a 12 bit register. 2024-03-15 10:27:24 -07:00
joevt 7eb9a66837 atimach64gx: Calculate vert_blank.
So it's not always zero.
2024-03-15 10:16:44 -07:00
joevt aa33a1644c control: Support unaligned read and size != 4. 2024-03-15 09:29:36 -07:00
joevt c42e1f28d6 atimach64gx: Fix fb_pitch calculation.
Also, move the calculation to crtc_update where we calculate everything else (including bits per pixel which is needed for the fb_pitch calculation.
2024-03-15 09:20:06 -07:00
joevt fe21108f08 atimach64gx: Implement hardware cursor. 2024-03-15 08:50:34 -07:00
joevt 81f3b95914 atimach64gx: Add write CRTC_INT_CNTL.
Required for interrupt handling.
2024-03-15 07:57:47 -07:00
joevt 2daad2d223 atimach64gx: Add write ATI_CRTC_VLINE_CRNT_VLINE.
Maybe for interrupts.
2024-03-15 07:03:57 -07:00
joevt 09becbfb04 atimach64gx: Add write ATI_CRTC_H_TOTAL_DISP.
For debugging.
2024-03-15 07:03:46 -07:00
joevt 1f9f2d2cf1 sixty6: Add support for sixty6 video output. 2024-03-14 20:06:55 -07:00
joevt 939d6d42bb machineproperties: More binary property values. 2024-03-14 19:16:54 -07:00
joevt 45a9d45e3f Add SCSI devices.
scsibus has a new method attach_scsi_devices which is used by all machines to populate a SCSI bus with one or more hard drives or CD-ROM drives.

HDDs are specified by the hdd_img property.
CDs are specified by the cdr_img property.
Multiple images are delimited by a colon :

attach_scsi_devices is called by the scsi controller after the scsi controller has attached itself to the scsi bus.
The bus suffix is applied to the property name.
Curio has no suffix so it will use hdd_img and cdr_img properties.
Mesh is expected to have a suffix of 2 so it will use hdd_img2 and cdr_img2 properties.

HDDs will skip SCSI ID 3 unless 7 HDDs are added, in which case, the seventh HDD will use ID 3.
CDs will start at SCSI ID 3, go to 7, then down to 0.
SCSI IDs are skipped if a device is already using that SCSI ID.

ScsiCdrom and ScsiHD no longer use REGISTER_DEVICE or DeviceDescription or PropMap which is normal for devices that can have multiple instances.
2024-03-14 19:12:11 -07:00
Mihai Parparita cfca42e577 Add basic support for multiple hard disks in the 6100
We treat the hdd_img parameter as a colon-separated list of disk
images and create additional SCSI HD devices as needed.
2024-03-14 19:11:54 -07:00
joevt 4c9b125cc8 amic: Add modem port transmit DMA. 2024-03-14 08:05:42 -07:00
joevt e1e00c951b sc53c94: Split real_dma_xfer.
Create real_dma_xfer_out and real_dma_xfer_in methods.
2024-03-14 08:01:07 -07:00
joevt bc5153dd4a ppcmmu: Make sure dummy page is 8 byte aligned. 2024-03-13 21:45:56 -07:00
joevt aed74479fd ppcmmu: Handle undefined mmu mode. 2024-03-13 21:38:26 -07:00
joevt c14974d167 sc53c94: Init class fields. 2024-03-13 21:37:08 -07:00
joevt f07de5401d sc53c94: Add registers and comments. 2024-03-13 21:25:28 -07:00
dingusdev faf066f2b9 Fixed building 2024-03-13 21:17:04 -07:00
joevt 06640844e9 scsihd: Allow read and write > 4 GB. 2024-03-13 21:09:55 -07:00
joevt bfc703a556 scsihd: Add sector_size.
Replace HDD_SECTOR_SIZE with class field sector_size.
2024-03-13 21:06:18 -07:00
joevt ec01993d84 scsihd: Make seek and rewind illegal. 2024-03-13 18:42:25 -07:00
joevt 5a54b6a761 scsicdrom: Rename read_capacity_10.
Like scsihd.
2024-03-13 07:50:32 -07:00
joevt a605c435b6 scsicdrom: Move test_unit_ready.
Make it a separate method like scsihd.
2024-03-13 07:50:20 -07:00
joevt 05da1708eb scsihd: Remove unused cur_buf_cnt. 2024-03-13 07:46:12 -07:00
joevt 3f826b8971 scsi: Add illegal_command method.
- scsicdrom now logs unsupported commands instead of abort.
2024-03-13 07:45:50 -07:00
joevt de8388f9a7 scsihd: Rename img_buffer to data_buf.
To match scsicdrom.
2024-03-13 07:44:52 -07:00
joevt 569f782a60 scsihd: Rename hdd_img to disk_img. 2024-03-13 07:44:43 -07:00
dingusdev 96b9b6a375 Fixed building 2024-03-12 21:30:38 -07:00
dingusdev 410502fa7e Merge branch 'master' of https://github.com/dingusdev/dingusppc 2024-03-12 21:15:49 -07:00
Maxim Poliakovski a8cd73cc69 hammerhead: remove MACH_TYPE_CATALYST definition.
Catalyst uses another memory controller (Platinum)
that significantly differs from Hammerhead.
Low-level board constants don't match too.
2024-03-12 17:41:12 +01:00
Maxim Poliakovski 54ce23d0a8 platinum: cleanup non-DWORD register reads. 2024-03-12 17:29:19 +01:00
Maxim Poliakovski 2d68b72dbd platinum: use meaningful name for 'register _4B'. 2024-03-12 17:05:47 +01:00
joevt 091cf4337c scsidevice: Remember SELECT_WITH_ATN message.
It might be an IDENTIFY message which contains a LUN number.
2024-03-12 08:01:52 -07:00
joevt ff9b8a59e2 scsibus: Change control lines for MESSAGE_IN. 2024-03-12 07:49:43 -07:00
joevt 6e4544450e platinum: Add register _4B. 2024-03-12 07:07:43 -07:00
joevt d4922beefe platinum: Don't ignore read/write of size != 4.
For reading, we'll return values such that dumping bytes or words or longs in Open Firmware will produce the same info in all cases.
2024-03-12 07:07:36 -07:00
joevt 6f37ff9ea3 platinum: Convert register offset to index.
Same as control.
2024-03-12 07:06:05 -07:00
joevt 1dfa671405 hammerhead: Add Motherboard ID Burst ROM flag. 2024-03-12 07:05:09 -07:00
joevt eb1d5d0a6d atimach64gx: Make sure refresh rate is reasonable. 2024-03-11 20:27:00 -07:00
joevt a190d5cbd9 atimach64gx: Handle all pixel formats. 2024-03-11 20:26:07 -07:00
joevt ab647ec0eb atimach64gx: Move pixel clock calculation. 2024-03-11 20:25:32 -07:00
joevt 1fb9e37ec5 scsidevice: Add check_lun.
This will create a CHECK_CONDITON if the LUN doesn't match.
2024-03-11 20:24:24 -07:00
joevt bcd057d45b atimach64gx: Don't recalculate if nothing changed. 2024-03-11 19:25:42 -07:00
joevt 0a63e2946d atimach64gx: Init some fields. 2024-03-11 19:25:18 -07:00
dingusdev b63e42ecf2 Temporarily removing SOFT RESET ATA command
Not implemented properly. Will re-implement soon.
2024-03-11 19:05:13 -07:00
joevt ee2ec7fe54 atimach64gx: Update VGA unsupported mode message. 2024-03-11 08:00:48 -07:00
joevt 1f63342c96 atimach64gx: Handle disabled display. 2024-03-11 08:00:38 -07:00
joevt 6e094a8edb atirage: Remove crtc_enable. 2024-03-11 07:55:15 -07:00
joevt 2ece059c5e atapi: Add ATAPI_SOFT_RESET command.
I don't know if this is correct.
2024-03-11 07:19:11 -07:00
joevt 7866675a55 debugger: Auto increment after disassemble.
Pressing return after disassembling some instructions should cause the next instruction to disassemble.
2024-03-11 07:13:40 -07:00
joevt 619579bee3 debugger: Add instruction bytes to disassembly.
8 characters for address, 8 characters for instruction hex, followed by instruction.
2024-03-11 07:13:07 -07:00
joevt b5dbaff748 debugger: Don't echo auto-repeated commands. 2024-03-11 07:12:57 -07:00
joevt a0ce1efabe display_sdl: Add Mouse Grabbed to window title.
Necessary when the window is created after a restart while mouse is grabbed.
2024-03-11 07:10:26 -07:00
dingusdev 3fd45abad8 Merge pull request #79 from leap0x7b/patch-1
Fix build on Fedora
2024-03-11 06:52:06 -07:00
leap123 c1b557fbb9 Fix build on Fedora 2024-03-11 13:01:43 +07:00
joevt babefd09f3 atimach64gx: Rename enable_crtc_internal. 2024-03-10 17:02:38 -07:00
joevt 578e5dc063 atimach64gx: Remove disable_crtc_internal. 2024-03-10 17:02:29 -07:00
joevt 2a290ff9c1 atimach64gx: Remove crtc_enable. 2024-03-10 17:02:18 -07:00
joevt bfd60155b6 atimach64gx: Fix DAC_CNTL for non-byte access.
If offset is 2, a size of 2 will also overwrite byte 3.
2024-03-10 17:00:47 -07:00
joevt df09a1e3bf atimach64gx: Register cleanup.
- Use register number instead of offset.
- Have one exit path from the read_reg and write_reg methods.
2024-03-10 16:59:11 -07:00
joevt 3cced5e29b atimach64gx: Use register field names. 2024-03-10 16:58:36 -07:00
joevt bd5ecf8cbb atimach64gx: Init CRTC_DISPLAY_DIS. 2024-03-10 16:54:48 -07:00
joevt 3e6f7ef541 atimach64gx: Init FIFO_CNT. 2024-03-10 16:54:31 -07:00
joevt ac5b434641 atimach64gx: Add verbose_pixel_format.
It is used to log the pixel format/depth.
2024-03-09 17:57:27 -07:00
joevt 00f917f52e atimach64gx: Add io_access_allowed.
This method is used by both pci_io_read and pci_io_write to determine if ISA type I/O access is allowed.
The SPARSE_IO_BASE I/O address is defined. This I/O range is not defined by an I/O BAR.
2024-03-09 17:54:05 -07:00
joevt a11770961e Add pci_find_device for pci type 0 requests. 2024-03-09 17:49:51 -07:00
joevt b0d33a5385 Add pmg3twr machine description. 2024-03-09 17:48:04 -07:00
joevt 2d8f2422b3 dbmda: Fix dma output res_count update.
Use this->res_count to track amount of data transferred.
2024-03-09 06:47:48 -07:00
joevt 0166059d1b dbdma: Add set_stat method.
A hardware device may have status flags connected to 8 status bits of the DBDMA engine.
2024-03-09 06:45:06 -07:00
joevt 50fcb45b88 awacs: Add dma input stub. 2024-03-09 06:20:24 -07:00
joevt 29d13aef09 dma: Add is_active method for input channels.
Since DBDMA contains an input and output channel, rename the existing is_active method to is_out_active.
2024-03-09 06:20:13 -07:00
joevt 31036b8dee grandcentral: Add sound in DMA. 2024-03-09 06:03:33 -07:00
joevt 6f231f3367 grandcentral: IOBus changes.
- Add IOBusDevice (nvram_addr_hi_dev) for NVRAM addr hi.
- Add IOBusDevice (nvram_dev) for NVRAM data.
- Make all IOBusDevices use the same code.
- Log error if 4 least significant bits of offset are not zero.
- Correctly byte swap the value before passing it to the IOBusDevice.
- When reading, duplicate the bytes in a word or dword like a real Power Mac does.
2024-03-09 06:02:23 -07:00
joevt 97f08f21b7 appleramdac: Add get_clut_entry_cb. 2024-03-08 21:02:41 -07:00
joevt 9a26016ed4 memctrlbase: Clear RAM to zero. 2024-03-08 20:58:41 -07:00
joevt f541613c6b mpc106: Fix RAM allocation.
Fix bank_end calculation (left shift 28 instead of 30).
Handle unorderred and discontinous ranges.
2024-03-08 20:58:04 -07:00
joevt 6931b2944b mpc106: Allow multiple of the same PCI device.
Grackle allows attaching different PCI devices. This change allows attach multiple of the same PCI device. To make the name unique in the machine map, the name of the PCI slot is appended to the device name.
2024-03-08 20:57:47 -07:00
dingusdev 3b3634bf5f Continued cleanup for bcl 2024-03-08 19:28:51 -07:00
joevt 0af9d0c972 chario: Cleanup. 2024-03-08 19:27:42 -07:00
dingusdev daeecbe99e Clean-up bc and bcl
Using templating to make the code a touch more readable
2024-03-08 19:22:25 -07:00
joevt 5d9194d03d atimach64gx: Add config read/write stub. 2024-03-08 08:00:21 -07:00
Maxim Poliakovski 3c7ce3de8b Merge pull request #62 from mihaip/upstream-cuda-restart
Add support for the CUDA_RESTART_SYSTEM command
2024-03-08 15:25:02 +01:00
dingusdev e56d4e63f4 Merge pull request #76 from mihaip/upstream-mouse-grab2
Add a basic mouse grab mode
2024-03-08 07:10:10 -07:00
Mihai Parparita 57e6e90002 Add support for the CUDA_RESTART_SYSTEM command
There are cases where when it's necessary (e.g. given uninitialized NVRAM,
the Beige G3 with the 10.2 install CD inserted will update the boot
device and restart to boot from it).

Restart support was done by wrapping the ppc_exec function in a loop and
checking for a restart power off reason. We also need to disconnect all
event listeners, since they will be recreated when the machine is
re-initialized.
2024-03-07 23:32:23 -08:00
Mihai Parparita c7d2eb87ac Initialize MMU recently used regions in ppc_mmu_init
More encapsulated and allows re-initialization.
2024-03-07 23:31:56 -08:00
Mihai Parparita 7226fe5303 Ensure that video controller refresh task timer is stopped when the object is destroyed. 2024-03-07 23:31:56 -08:00
Mihai Parparita 10af336cd1 Ensure that VIA timers are stopped when the object is destroyed. 2024-03-07 23:31:56 -08:00
Mihai Parparita f218a38294 Ensure that AMIC pseudo-VBL timer is stopped when the object is destroyed. 2024-03-07 23:31:44 -08:00
dingusdev 2f326a8199 Compile fix for CharIO in VS2022
For some reason, it wouldn't define the symbol when trying to compile with Clang.
2024-03-07 20:57:40 -07:00
dingusdev eb07a3c2f1 Templating bclr to match with bcctr 2024-03-07 20:44:36 -07:00
joevt 04526012f9 grandcentral: Add Ethernet ROM. 2024-03-07 07:59:13 -07:00
joevt b5bb214920 ohare: Interrupt fixes.
Based on work done for grandcentral.
2024-03-07 07:58:54 -07:00
joevt 1e587b0848 chario: Move static variable to class. 2024-03-07 07:48:11 -07:00
joevt 97727e0d1e escc: Return NULL if nothing to read. 2024-03-07 07:47:41 -07:00
joevt 723eab59d6 escc: Include port name in log messages. 2024-03-07 07:40:30 -07:00
joevt 1421ccc81e escc: Add dma stub. 2024-03-07 07:30:06 -07:00
joevt e1d43b8eb2 ppcopcodes: Cleanup branch instructions. 2024-03-07 06:56:37 -07:00
joevt 67bd47f11f ppcopcodes: Fixes for bcctr(l)?.
Add MPC601 variants. Variants that decrement and test the ctr are invalid bon't don't appear to trigger an exception. The manual says MPC601 can decrement the counter. Other CPUs do not decrement the counter but will branch based on the value.
2024-03-07 06:55:54 -07:00
joevt e44676e491 ppcfpopcodes: Template mffs variants. 2024-03-07 06:45:46 -07:00
joevt 7b4d513e22 videoctrl: Add change resolution support.
PDM defaults to 640x480.
If you set --mon_id to MacRGB12in then it would draw 512x384 inside a 640x480 window.
If you set --mon_id to Multiscan20in then it would try to draw 832x624 inside a 640x480 window and crash.
If you set the Monitors control panel to switch multiscan display from 640x480 to 832x624 and  restart then it would crash.
Now it will correctly change the window size every time the mode changes.
2024-03-06 21:44:10 -07:00
joevt 5b51cd06c0 atimach64gx: Add register names.
For logging.
2024-03-06 21:20:23 -07:00
joevt 052a47734f macio: Add DMA interrupts. 2024-03-06 21:19:04 -07:00
joevt 54767bf97d More interrupts.
- Add all the interrupts including DMA.
- Modify the Interrupt to IRQ_ID translation so the interrupts belonging to the first set of 32 interrupts don't need to be shifted.
2024-03-06 19:17:16 -07:00
joevt e5bace03f7 Abort if register_dma_int.
Make register_dma_int cause Abort for heathrow and ohare like it does for amic.
2024-03-06 19:17:03 -07:00
joevt 691fcfb657 atimach64gx: PCI BAR changes.
Support changing BAR address.
2024-03-06 18:58:15 -07:00
joevt 49f7da4402 atimach64gx: Remove second column.
It incorrectly implies a relationship between items on the same row.
2024-03-06 18:57:52 -07:00
joevt 6c0ca42fff atimach64defs: Add more registers and bit fields. 2024-03-06 18:57:30 -07:00
Maxim Poliakovski 30c6cbefbd ppcexec: fix indentation, break long lines. 2024-03-06 23:28:40 +01:00
joevt 5a049642ea atirage: Add VBL callback. 2024-03-06 07:50:03 -07:00
joevt b168459007 atirage: Calculate vert_blank. 2024-03-06 07:42:51 -07:00
joevt d5c7b5f537 atirage: Add write CRTC_INT_CNTL. 2024-03-06 07:41:12 -07:00
joevt 506ed000a0 atirage: Add write CONFIG_STAT0. 2024-03-06 07:04:59 -07:00
joevt b92e9216f4 atirage: Add write CRTC_VLINE_CRNT_VLINE.
For VLINE interrupt (but Mac OS X doesn't use enable VLINE interrupt).
2024-03-06 07:04:40 -07:00
joevt 6ff5079df8 atirage: Init CRTC_DISPLAY_DIS. 2024-03-06 07:04:25 -07:00
joevt d686fc04f4 atirage: Fix crtc_update.
Add pixel format and pixel clock to the list of fields that will initiate a recalculation.
If frame rate is less than 24 or greater than 120 then assume 60Hz.
2024-03-05 08:02:50 -07:00
joevt 9aef78be4f atirage: Modify write CLOCK_CNTL.
Consider write-only bits: ATI_CLOCK_STROBE can't be read so clear it.
8 bits at Offset 2 is PLL_DATA. If we don't modify PLL_DATA, then insert the current value of PLL_DATA into the value that will be read from ATI_CLOCK_CNTL.
2024-03-05 08:02:20 -07:00
joevt f6b1c080ad atirage: Init FIFO_CNT of GUI_STAT. 2024-03-05 07:54:19 -07:00
joevt d4fa85688d atirage: Check both offset and size.
When checking if a particular byte of a register is accessed, check both the starting position (offset) and ending position (offset + size) of the bytes being access.
2024-03-05 07:52:12 -07:00
joevt 20b4a33c00 ppcexec: Remove EXHAUSTIVE_DEBUG. 2024-03-05 07:05:03 -07:00
joevt f61055ebc0 ppcexec: Convert if to switch for ppc_opcode19. 2024-03-05 07:03:16 -07:00
joevt 777a02cbe9 pci: Use SIZE_ARG for logging arg size.
The SIZE_ARG macro defined in pcibase can be used outside pcibase with a small modification.
2024-03-04 21:16:46 -07:00
joevt 61b1940397 pci: Add command register mask.
The mask represents the list of bits that are allowed to change in the command register of PCI config space.
2024-03-04 21:16:38 -07:00
joevt eef6d267c3 atirage: PCI BAR changes.
- Add BAR 2 decode. This BAR isn't actually used by Mac OS X, but decode it anyway just in case.
- Support updating of BARs (using change_one_bar method).
2024-03-04 21:13:07 -07:00
joevt 9c48c296c8 atirage: Register cleanup.
- Use register number instead of offset.
- Have one exit path from the read_reg and write_reg methods.
2024-03-04 21:11:56 -07:00
joevt 214c61669a videoctrl: Add pixel_format.
pixel_format is different than pixel_depth.
pixel_format depends on the GPU. A GPU might have multiple formats for the same depth.
We store this in videoctrl so that we can detect changes in pixel_format like we do for pixel_depth and active_width and active_height.
2024-03-04 21:11:42 -07:00
joevt fb0396923f Fix dma STORE_QUAD and LOAD_QUAD.
When fetching DMA command, make sure to convert little endian fields to host endianness (i.e. don't use memcpy).
When fetching DMA command, return the host address of the DMA command for LOAD_QUAD. Maybe this address should be cached whenever this->cmdptr changes?
When fetching DMA command, return whether the DMA command is writable.
For LOAD_QUAD, pass the address of the DMA command to xfer_quad.
Always log unexpected DMA command values.
Write full 32-bit value for LOAD_QUAD.
Write reqCount to resCount.
2024-03-04 20:38:07 -07:00
joevt 6503a300cc Add PCI interrupt method.
A PCI device passes an interrupt to its host. The host will determine from the PCI device which interrupt to trigger.
2024-03-04 07:47:20 -07:00
joevt be80595834 Remove obsolete pci config type 1 methods.
pci_find_device is the method used to pass pci config type 1 methods to child PCI devices.
2024-03-04 07:47:08 -07:00
joevt 54bda0ea95 pci: Change pci_conv_rd_data unaligned.
pci_conv_rd_data can be used to handle unaligned or 64-bit accesses in mmio regions if it's modified to include the next 32-bit value.
For pci config accesses, grackle repeats the 32-bit value. bandit uses a seemingly random number for the next 32-bit value, but we'll make it work like grackle.
2024-03-03 20:06:13 -07:00
joevt 6d23e18c11 pci: Add PCI CardBus bridge.
PCCard is used by PowerBook G3 Wallstreet in Open Firmware 2.0.1.
CardBus is probed in New World Macs starting from at least Open Firmware 4.1.9f1 sometime after Open Firmware 3.1.1.

- Create PCIBase from common stuff in PCIDevice.
- Add PCIBridgeBase. These have a primary bus number, secondary bus number, and subordinate bus number which are used to determine if PCI type 1 config cycle should be passed.
- Change PCIBridge to use PCIBridgeBase instead of PCIDevice.
- Add PCICardBusBridge which uses PCIBridgeBase.
2024-03-03 16:00:55 -07:00
joevt 5f8e7fcb73 pci: Log invalid BAR values.
For example, Old World Macs have versions of Open Firmware that don't support 512 MB BARs correctly. They may attempt to set such a BAR to 0x90000000 (a 256 MB boundary) instead of 0xA0000000 (the next available 512 MB boundary).
2024-03-03 15:49:59 -07:00
joevt 214b52a96a machinefactory: Fix spelling. 2024-03-03 15:13:29 -07:00
joevt d426d0faeb Add settings when adding pci device. 2024-03-03 15:01:39 -07:00
joevt ebb51addd7 debugger: Allow interrupt of disassembly.
Part of the "debugger: Fix interrupt signal." commit.
2024-03-03 14:36:24 -07:00
joevt c64fab6ecb heathrow: Align read/write messages. 2024-03-03 12:03:06 -07:00
joevt 696bd6f316 mpc106: Remove pci_read and pci_write.
Because they are only called once and are small enough to include in read and write methods like they are in BanditHost.
2024-03-03 11:56:37 -07:00
joevt 7a3a661e2a platinum: Allow reading swatch registers. 2024-03-03 11:47:03 -07:00
joevt f0949d296d platinum: Don't abort. 2024-03-03 11:46:40 -07:00
joevt d2ebcb24b9 platinum: Use calculated fb_ptr for HW cursor. 2024-03-03 10:43:57 -07:00
joevt 644087b592 platinum: Fix fb_ptr calculation. 2024-03-03 10:43:40 -07:00
joevt be2f5273d1 platinum: Init bank_base.
Because the constructor doesn't do it.
2024-03-03 10:43:25 -07:00
joevt 10053a8a1b atirage: Rename variable.
To match other occurrences in the same file.
2024-03-02 20:49:25 -07:00
joevt 9cefaec49c atirage: Spelling. 2024-03-02 20:44:39 -07:00
joevt 55b79c1518 atirage: Use register bit field names. 2024-03-02 20:44:08 -07:00
joevt c2ab86d4ba atirage: Do something for hw cursor invert pixels.
Try a 50% alpha blend with black.
2024-03-02 20:43:54 -07:00
joevt 0e5fcde1e9 atirage: Add CUR_HORZ_VERT_OFF name. 2024-03-02 17:27:45 -07:00
joevt 002cce886c atirage: Indent. 2024-03-02 17:15:39 -07:00
joevt 151ea2ece4 atimach64defs: Add register bit fields. 2024-03-02 17:15:25 -07:00
joevt 568882a2ea atimach64defs: Sort addresses in descending order. 2024-03-02 17:14:59 -07:00
joevt f38d6d73f4 atimach64defs: Add more device IDs. 2024-03-02 17:08:31 -07:00
joevt 569893861d heathrow: Don't set lat_timer.
It will be set by firmware.
2024-03-02 16:42:49 -07:00
joevt e81ac6f61e Add PERCH slot.
So you can connect a USB controller or whatever to it.
2024-03-02 16:02:19 -07:00
joevt 177098c957 debugger: Fix interrupt signal.
Typing Control-C in Terminal app causes an interrupt signal that should enter the DPPC debugger but this only worked once since the signal handler never returned. Even if the signal handler reenabled the signal somehow, it calls enter_debugger recursively which is strange since the earlier calls to enter_debugger would never return.

Now the signal handler just sets a flag (power_on) which can be used to exit any loop (emulator loops, stepping loops, disassembly loops, dumping loops).

Main always calls enter_debugger now which calls the ppc_exec loop. The power_on flag will exit the ppc_exec loop to return to the debugger. Recursion of enter_debugger is eliminated except for calls to loguru's ABORT_F.

An enum power_off_reason is used to indicate why the power_on flag is set to false and to determine what happens next.
2024-03-02 12:57:02 -07:00
joevt 1e78512c95 Rename Curio and Mesh. 2024-03-02 11:12:45 -07:00
joevt 1b147151f0 videoctrl: Rename get_palette_color.
So it matches set_palette_color.
2024-03-02 08:59:02 -07:00
joevt ad8a26616f scsidevice: Add LUN field.
This may make it possible for multiple LUNs to be added to the same target ID.
For now just use LUN #0.
2024-03-02 08:52:09 -07:00
joevt 8f28823217 scsi: Initialize cur_phase. 2024-03-02 08:51:45 -07:00
joevt b509df78df Don't allow vert_blank to be 0. 2024-03-02 08:37:44 -07:00
joevt 5876cc7e17 bandit: Fix indent. 2024-03-02 08:09:42 -07:00
joevt de73a36399 ppcmmu: Move defines to the top. 2024-03-02 07:58:25 -07:00
dingusdev c9aed600b6 More opcode clean-up 2024-03-02 07:57:15 -07:00
joevt 318e035344 ppcmmu: Shorten tlb_flush_entries. 2024-03-02 07:56:26 -07:00
joevt cd097232cb ppcmmu: Shorten tlb_flush_entry.
Don't need a weird short loop.
2024-03-02 07:56:17 -07:00
joevt b7b783b6be ppcmmu: Shorten ppc_mmu_init.
Also, initialize all the fields.
2024-03-02 07:50:02 -07:00
joevt 968f503d80 debugger: Improve my_sprintf for short strings.
Don't need to repeat snprintf with memory allocation if the string is short.
2024-03-02 07:24:17 -07:00
joevt 7fc92e236b Fix extract_bits and insert_bits.
(1 << len) is actually 1 when len is (sizeof(T)*8) so we need to special case that. len is usually constant so the compare won't be compiled.
2024-03-02 06:54:58 -07:00
joevt 3062a29b78 Add clear_bit and set_bit. 2024-03-02 06:54:45 -07:00
joevt 3bea3ec3d8 ppcmmu: Fix compiler warnings. 2024-03-01 20:12:42 -07:00
joevt 0f66d454c1 ppcmmu: Cleanup the cleanup. 2024-03-01 20:05:10 -07:00
joevt 6738d7472e ppcmmu: Add a function to get phys address.
Since the function is for the debugger during stepping or disassembly, don't do extra logging.
2024-03-01 19:48:52 -07:00
joevt 500f38a496 ppcmmu: Add phys address to mmu_translate_imem.
For debugging.
2024-03-01 19:45:09 -07:00
joevt 3a5a70b56d ppcmmu: Allow convert virtual to physical address.
The TLBEntries allow converting virtual guest address to virtual host address but there's no easy way to get a guest physical address for debugging purposes.
Add a phys_tag field to fix that.
2024-03-01 19:42:25 -07:00
joevt 15e132c824 cmake: Add header files in CMakeLists.txt.
So they will appear in Xcode project.

mkdir -p dingusppc/build-xcode
cd       dingusppc/build-xcode
cmake -G Xcode ..
xcodebuild -configuration Release
2024-03-01 19:41:43 -07:00
dingusdev 2b3cf58b8a Continued clean-up 2024-03-01 19:40:46 -07:00
joevt 2998796c2c pci: Fix log message for PCI rom exceptions.
It should log device name, not just "PCIDevice".
2024-03-01 08:02:01 -07:00
joevt 3978d0754d CD-ROM: Add max blocks check.
The code does not support more than 2^32 - 2 blocks because of this expression: static_cast<uint32_t>(this->size_blocks + 1)
2024-03-01 08:01:31 -07:00
joevt 655b9a17e1 psx: Set name of Psx memory controller.
For the logs.
2024-03-01 07:59:33 -07:00
joevt 84a694d4c2 nvram: Output nvram file name in error message.
So that you don't see identical messages "Could not restore NVRAM content from the given file."
Instead, one will mention nvram.bin and the other will mention pram.bin.
2024-03-01 07:59:19 -07:00
dingusdev ebac8b92ba Clean-up for loading instructions
Expanding the scope of the clean-up from lscbx to other loading/storing instructions.
2024-03-01 07:57:46 -07:00
joevt 6a4326af39 poweropcodes: lscbx cleanup. 2024-03-01 07:46:04 -07:00
joevt 6a51e8a1c9 debugger: regs command needs to reset setfill.
So printenv will fill with spaces after regs.
2024-03-01 07:28:58 -07:00
joevt 006a90f681 debugger: Some commands should not repeat.
Entering a blank command causes the last command to repeat. This doesn't make sense for the following commands:
help, quit, regs, context, printenv, setenv, nvedit, amicint, viaint.
2024-03-01 07:26:34 -07:00
joevt 17983e7fad debugger: Fix setenv command to allow spaces.
To allow setting boot-command to "0 bootr -v debug=0x144" for example.
2024-03-01 07:13:41 -07:00
joevt a15b1805fb debugger: Fix handling of empty commands.
An empty command should not be reported as an unknown command.
An empty command should not repeat an unknown command.
2024-03-01 07:08:12 -07:00
joevt 11e0bd79b0 debugger: Work around Xcode Terminal.app issue.
If debugging with Xcode using Terminal.app for the console, Terminal.app may send empty lines to the dingusppc debugger while resizing the Terminal.app window and it will do this forever.
As a workaround, use std::cin.clear() to clear the input buffer before getline and loop until the terminal window size is not changing or the input line is not empty.
2024-03-01 06:56:20 -07:00
Mihai Parparita bfbf4cb453 Add a basic mouse grab mode
Take 2 of 587eb48f61. We now implement
this at the SDL level, which works cross-platform and allows us to
ensure that the guest never gets the Control-G event.
2024-02-29 22:58:50 -08:00
dingusdev 229509a067 Add help for mregs 2024-02-29 21:48:04 -07:00
joevt ff5c43e6cb debugger: Add mregs command.
To dump more registers.
2024-02-29 21:46:44 -07:00
joevt 7cd3aae753 debugger: Fix repeated until.
The loop needs to be do while instead of while do.
2024-02-29 18:57:11 -07:00
joevt fe05b1de12 Fix compiler warnings.
Xcode build has compiler warnings involving loss of precision. Remove them by adding type casts. Check results in some cases for overflow.
2024-02-29 18:49:14 -07:00
joevt 1903c8b557 debugger: Fix reg_op for floating point registers. 2024-02-29 18:48:59 -07:00
joevt 456a96042f debugger: Shorten try catch in reg_op.
Because SPGR0 matches SPR but stoul causes an exception.
2024-02-29 07:55:09 -07:00
joevt 888df0ac53 debugger: Add more register names for reg_op.
So the debugger can output their values.
2024-02-29 07:46:16 -07:00
joevt 18afe91a82 atirage: Use convert frame big-endian methods. 2024-02-26 14:46:31 +01:00
Maxim Poliakovski b8d0ed39d9 atirage: fix FB pitch calculation. 2024-02-26 14:21:53 +01:00
Maxim Poliakovski 0c3f399de3 poweropcodes: fix compiler warning. 2024-02-24 22:51:05 +01:00
Maxim Poliakovski 45ccabb11d poweropcodes: improve lscbx emulation. 2024-02-24 22:46:54 +01:00
dingusdev d71a213c4b Continued clean-up, part 3 2024-02-22 19:46:34 -07:00
dingusdev 8e9123bdce Slightly less clumsy check for compiler 2024-02-21 07:14:21 -07:00
dingusdev 2e3e65f3e7 Moving vid_enable_seq
Visual C complains about this being in the wrong place
2024-02-21 07:07:18 -07:00
dingusdev 9db53a4e3f Updating CMakeLists file 2024-02-21 06:32:24 -07:00
joevt c2e098e535 zdocs: Add Open Firmware $find bug description. 2024-02-20 18:28:59 -07:00
joevt a6de2c2b44 zdocs: Fix Open Firmware startvec notes.
Fields 488 to 48c are not part of the startvec struct. They are for the fcode file struct used by byte-load-file.
2024-02-20 18:28:51 -07:00
dingusdev 9dad9ea38b Revert Memory exceptions use mmu handler. 2024-02-20 18:22:55 -07:00
dingusdev 1d938c93b6 Mask fixes for sr(*) 2024-02-20 18:15:08 -07:00
joevt 35bc1bcb44 poweropcodes: Fix sriq. 2024-02-20 18:07:38 -07:00
joevt 1438ebc12a poweropcodes: Fix compiler warnings. 2024-02-20 18:07:26 -07:00
joevt 61b29f6fab ppcexceptions: Memory exceptions use mmu handler. 2024-02-20 18:07:04 -07:00
dingusdev fb9b6886fa Add stdio for Windows serial 2024-02-20 18:05:11 -07:00
joevt 0e3eaf724b ppcfpopcodes: Fix stfs*, attempt #2. 2024-02-20 02:04:02 +01:00
joevt 2a05ccbee1 ppcfpopcodes: Fix fres.
Don't convert to float until the end.
2024-02-20 02:03:41 +01:00
joevt 59bee01c0a ppcfpopcodes: Fix fmsubs inf nan check.
There's probably still an issue with the inf_nan check
using reg_a for the first value instead of reg_a * reg_c.
This will probably need rewriting anyway.
2024-02-20 02:02:58 +01:00
joevt 4e4c8d71be ppcfpopcodes: Fix fadds inf nan check. 2024-02-20 02:01:55 +01:00
joevt c7ae31dfce ppcfpopcodes: Spaces. 2024-02-20 02:01:37 +01:00
joevt 2ea80b0aab ppcopcodes: Cleanup. 2024-02-20 01:59:54 +01:00
joevt 5bbf5ee3af ppcopcodes: Fix divw overflow result. 2024-02-20 01:59:40 +01:00
joevt 748e9c5d86 ppcopcodes: Write protect XER zero bits. 2024-02-20 01:59:01 +01:00
joevt 8764beba39 ppcopcodes: Fix lswx.
- Remove invalid form check unless you know for sure it's supposed to cause an exception.
- Add register skip for 601 CPU. This needs testing.
2024-02-20 01:57:00 +01:00
joevt 1fc551fae0 Fix yosemite machine description name. 2024-02-20 01:54:03 +01:00
joevt 8baf722343 Spelling. 2024-02-20 01:53:32 +01:00
joevt cf4ce01ddd ppcopcodes: set DSISR for alignment exception. 2024-02-20 01:22:55 +01:00
joevt 57d919e424 appleramdac: HW cursor fixes.
- Add mask so that hardware cursor cannot be drawn beyond the right edge of the frame buffer.
- Add invert pixels. Invert pixels are used in the I-beam cursor and the Watch cursor.
2024-02-20 01:00:50 +01:00
joevt b0dc893a05 dma: Add name to dma classes.
For logging purposes, each DMA channel should have a name.
2024-02-19 15:30:20 +01:00
Maxim Poliakovski f5bb484226 sc53c94: fix interrupt reporting. 2024-02-19 15:30:20 +01:00
dingusdev 29f3ffd474 Continued clean-up, part 2 2024-02-18 07:06:27 -07:00
dingusdev b160e38f8f Continued code clean-up 2024-02-16 06:55:13 -07:00
Maxim Poliakovski bc2714ab2a platinum: handle non-DWORD register accesses. 2024-02-15 15:35:17 +01:00
dingusdev 38d94e509f Further code cleanup 2024-02-14 22:19:08 -07:00
dingusdev ec23a532f6 Minor clean-up for branching instructions 2024-02-12 20:59:04 -07:00
joevt 8a800062dd grandcentral: Add DMA channel enum. 2024-02-12 14:06:19 +01:00
Maxim Poliakovski cf14144d5b machinetnt: add Power Macintosh 7300. 2024-02-12 02:45:29 +01:00
Maxim Poliakovski 28e7a806b4 grandcentral: use MeshStub on machines without MESH. 2024-02-12 02:38:38 +01:00
Maxim Poliakovski a0e56aa4cf grandcentral: connect external SCSI HW. 2024-02-12 02:17:09 +01:00
Maxim Poliakovski b3e3b73159 grandcentral: connect MESH HW. 2024-02-12 02:17:09 +01:00
Maxim Poliakovski 046452fc56 mesh: various improvements. 2024-02-12 02:17:09 +01:00
Maxim Poliakovski e77b8785ff grandcentral: wire SWIM3 DMA interrupt. 2024-02-12 02:01:01 +01:00
Maxim Poliakovski 061fc5a24d hwinterrupt: remove deprecated SCSI0 & SCSI1. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski cb8c2cb450 Wire CONTROL interrupt. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski 98d661eda1 Wire PLATINUM interrupt. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski 8ddbc9c427 Wire SCSI_MESH interrupt. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski 5902cd5c28 Wire SCSI_CURIO interrupt. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski ce2f6ddadd grandcentral: cleanup interrupt acknowledgement. 2024-02-12 01:46:21 +01:00
Maxim Poliakovski cdc5589bcf hwinterrupt: new interrupt definitions (joevt's work). 2024-02-12 01:42:59 +01:00
joevt 833534bdaa machinecatalyst: Cleanup board register 1. 2024-02-11 23:11:10 +01:00
Maxim Poliakovski 8d30fea63b platinum: implement video emulation. 2024-02-11 22:59:43 +01:00
Maxim Poliakovski 7d06c5b37a control: use RaDACal emulation from appleramdac. 2024-02-11 22:59:43 +01:00
Maxim Poliakovski dd95468d74 New source for TNT RAMDAC emulation (DACula & RaDACal). 2024-02-11 22:59:43 +01:00
Maxim Poliakovski 478bd31dc7 dbdma.h: add missing include. 2024-02-11 22:59:43 +01:00
Maxim Poliakovski 44b1d34cc7 control: support interlaced modes. 2024-02-11 22:22:27 +01:00
joevt d0b0b8070c ppcopcodes: Fix l*ux? invalid form check.
Invalid form is (reg_a == reg_d) || reg_a == 0.
Therefore, valid form is (reg_a != reg_d) && reg_a != 0
!(a || b) == !a && !b
2024-02-11 07:41:13 -07:00
joevt 996857b10d endianswap: Add parenthesis around macros. 2024-02-11 07:40:42 -07:00
joevt fd81d7b040 ppcfpopcodes: Fix load float.
Type casting an int to a float assigns the value of the int to the float which is not what is needed here.
2024-02-11 07:40:17 -07:00
joevt 267a9448ea ppctest: Fix floating-point tests.
genppctests.py
- Fix incorrect bits for some floating-point instruction opcodes or fields.
- Use separate register for FP results like DolphinPPCTests does.
- Remove extra FMULS.
- Use a regular expression for parsing ppcfloattest.txt. Don't parse the values, just put them in the output ppcloattests.csv file.

ppcfloattest.txt
- Clear crf0 and crf7 because we only care about crf1.
- Use values from DolphinPPCTests (0.0, 0.5, 1.0, 3.5, DBL_MAX, FLT_MAX, 2.4679999352, 4.9359998704, etc.). Some of the values were rounded. This will un-round them. Specify snan or qnan instead of nan.
- One of the FCMPO and FCMPU tests had qnan instead of snan input values.

ppcfloattest.csv
- Regenerate this file using the updated genppctests.py which uses the updated ppcfloattest.txt.

ppctests
- Update double_from_string to be able to parse the new values (snan, qnan, FLT_MAX, DBL_MAX).
2024-02-10 14:56:21 -07:00
joevt 01e45d656e ppcfpopcodes: Update header date. 2024-02-10 14:47:46 -07:00
joevt 9199b1e520 ppcfpopcodes: Fix multiply add opcodes.
Use std::fma for all of them for max accuracy.
For single precision opcodes, convert only the result, not the operands.
2024-02-10 14:19:09 -07:00
joevt 3be22dac99 ppcfpopcodes: No float cast for operand check. 2024-02-10 14:18:49 -07:00
joevt ff895aa8a4 ppcfpopcodes: Remove some globals.
ppc_result64_d and ppc_dblresult64_d don't need to be globals. The rest are unused.
2024-02-10 13:56:07 -07:00
joevt c9c4280e6e ppcfpopcodes: No float cast for operand check. 2024-02-10 13:02:49 -07:00
joevt dac9c1e52c ppcfpopcodes: Fix fctiw* round to nearest.
0.3 should not round up to 1.
2024-02-10 12:58:58 -07:00
joevt a7e6ab33a1 ppcfpopcodes: Make fctiw* results QNaN. 2024-02-10 12:58:29 -07:00
joevt 6c49b87a06 ppcopcodes: Fix rlwnm when shift > 31. 2024-02-10 12:54:41 -07:00
joevt 29e5bbdcc0 ppcopcodes: Fix divw. 2024-02-10 12:54:12 -07:00
joevt 4fcb357e2f ppcfpopcodes: add 601 variant of mffs. 2024-02-10 12:51:48 -07:00
joevt ddb5259464 ppcexec: Make illegal operations per CPU model. 2024-02-10 12:51:00 -07:00
dingusdev 52dfc0cf93 Slightly faster typecasting 2024-01-31 08:06:33 -07:00
Maxim Poliakovski ad58d102df machinecatalyst: implement board register 1. 2024-01-30 00:34:24 +01:00
Maxim Poliakovski 9847f5ba6c machinecatalyst: remove video properties.
They will be implemented in the Platinum source.
2024-01-30 00:34:24 +01:00
Maxim Poliakovski 5f06be6226 control: implement HW cursor rendering. 2024-01-19 23:48:22 +01:00
Maxim Poliakovski a68afbf79a videoctrl: add one more cursor rendering callback. 2024-01-19 23:48:22 +01:00
joevt bf425884fb ppcopcodes: Add ppc_grab_dab.
For instructions that don't use the general purpose registers.
2024-01-19 12:09:24 +01:00
joevt 4430fd89a9 ppcopcodes: Fix subfic. 2024-01-19 12:00:55 +01:00
Maxim Poliakovski 7432369162 display_sdl.cpp: improve formatting and add license header. 2024-01-19 09:48:54 +01:00
Maxim Poliakovski 43dc9ed88a control: remove unused defines and variables. 2024-01-19 09:48:54 +01:00
Maxim Poliakovski d413e4a278 control: incorporate recent HW knowledge. 2024-01-19 09:48:54 +01:00
joevt 5c460c9f3b videoctrl: Add VBL callback.
Allows overriding the method used to post interrupts.
2024-01-13 00:41:08 +01:00
joevt cf9237f7d6 control: Fixes.
- Fix video vram endianness. It should behave like RAM.
- Add read for registers ENABLE, INT_STATUS, INT_ENABLE.
- Add write for registers CNTTST, INT_ENABLE.
- Add support for 16bpp and 32bpp.
- Add vbl interrupt.
2024-01-13 00:41:08 +01:00
dingusdev a0b1d6394a Another revert
This affects Virtus VR - With the lmw checks, the opening sign doesn't display and the intro crashes sooner
2024-01-07 17:45:05 -07:00
dingusdev c6af1e31fe Partial revert of previous commit 2024-01-07 17:21:11 -07:00
dingusdev a5ce6a806f CPU clean-up 2024-01-07 17:04:51 -07:00
dingusdev a59475af1c Further lha(*) fixes 2024-01-05 19:10:05 -07:00
dingusdev 1cc1ac2e68 Fixing lha(*) opcodes 2024-01-05 17:19:03 -07:00
dingusdev 924b80574a Further fix from last commit 2024-01-05 15:53:56 -07:00
dingusdev f3a759c80d CPU code clean-up 2024-01-05 15:11:37 -07:00
dingusdev 79ee8543f5 Merge pull request #77 from mihaip/upstream-machineid
machinepdm: fix machine ID
2024-01-03 07:44:38 -07:00
Maxim Poliakovski 9b30dfb474 ppcfpopcodes: refactor fctiw/fctiwz emulation. 2024-01-03 01:27:21 +01:00
joevt 0100e67ebf ppcfpopcodes: Fix fctiw/fctiwz. 2024-01-03 01:07:53 +01:00
joevt bd419912b5 ppcfpopcodes: Fix stfs*.
It should try to convert its operand to a single precision
floating point number at least.
2024-01-02 21:53:03 +01:00
Maxim Poliakovski cb85d358d1 Remove unused globals. 2024-01-02 17:51:12 +01:00
Maxim Poliakovski 5b114c2412 ppcopcodes: refactor mtcrf emulation. 2024-01-02 17:44:35 +01:00
Maxim Poliakovski c25b027de4 ppcfpopcodes: fix mtfsf emulation. 2024-01-02 17:21:08 +01:00
Maxim Poliakovski 8595dd7d99 ppcfpopcodes: fix mtfsfi emulation. 2024-01-02 17:21:08 +01:00
joevt 61a90e2cfb ppcfpopcodes: Fix mcrfs. 2024-01-02 15:52:30 +01:00
Maxim Poliakovski 593508df22 Refactor subfze. 2024-01-02 13:44:56 +01:00
joevt 1f3505f371 ppcopcodes: Fix subfze. 2024-01-02 13:44:13 +01:00
Maxim Poliakovski 679e80a7c3 atahd: basic commands for disk I/O. 2023-12-30 16:23:00 +01:00
Maxim Poliakovski ebdefb5acd atabasedevice: transfer data in chunks. 2023-12-30 16:23:00 +01:00
Mihai Parparita e36e1cf282 machinepdm: fix machine ID
Handle 4 byte reads from the machine ID MMIO region. Also change the 6100
machine ID to match the one used by MAME.
2023-12-29 23:31:16 +00:00
Maxim Poliakovski fef5bde0c7 Refactor recent subfme fix. 2023-12-24 02:56:47 +01:00
joevt dc00879419 ppcopcodes: Fix subfme. 2023-12-24 02:36:34 +01:00
joevt bae488fd97 ppcfpopcodes: Fix lfs* opcodes. 2023-12-22 13:11:13 +01:00
joevt 0a8c1df968 ppcopcodes: Fix sraw. 2023-12-19 16:30:02 +01:00
joevt 4c49558120 ppcopcodes: Fix subfe. 2023-12-19 14:57:41 +01:00
Maxim Poliakovski 750f91e339 ppcemu.h: add enum for XER bits. 2023-12-19 14:57:41 +01:00
Maxim Poliakovski d24b5d21b8 CRx_bit enum stores masks for now. 2023-12-19 14:27:57 +01:00
Maxim Poliakovski 9dbfde1a4c Cleanup previous commit. 2023-12-19 13:15:10 +01:00
joevt 7f229b0fe8 ppcfpopcodes: Fix fcmpo/fcmpu.
It was always changing CR1 (starting at CR bit 4) instead of the CR selected by crfD.
Also, it was clearing all but the FL,FG,FE,FU bits of FPRF of FPSCR.
2023-12-19 13:15:10 +01:00
Maxim Poliakovski 920c2024be Revert "Add a basic mouse grab mode when running on macOS"
This reverts commit 587eb48f61.
2023-12-19 13:15:10 +01:00
dingusdev 2a0f391113 Compilation fix for machineproperties.cpp 2023-12-17 20:04:10 -07:00
dingusdev c3b770ef17 Merge pull request #74 from mihaip/upstream-mouse-grab
Add a basic mouse grab mode when running on macOS
2023-12-15 18:03:45 -07:00
dingusdev a14fbe865f Merge pull request #75 from mihaip/upstream-extended-adb
Add basic support for the extended ADB mouse protocol.
2023-12-15 18:02:56 -07:00
Mihai Parparita ae0bb838bf Add basic support for the extended ADB mouse protocol.
We now respond to the switch to device handler ID 4 and the register 1
read (as described by https://developer.apple.com/library/archive/technotes/hw/hw_01.html#Extended).

We don't yet use the extra precision bits in the register 0.
2023-12-15 16:04:27 -08:00
Mihai Parparita 587eb48f61 Add a basic mouse grab mode when running on macOS
Adds a "Grab Mouse" command to the "Window" menu which toggles
SDL_SetRelativeMouseMode. That "traps" the mouse to the current window
(and hides it) which makes it less annoying to deal with the separate
acceleration curves of the host and guest OS.

This needs to be done via AppKit code since SDL does not have a
cross-platform way to add menu commands.

I also looked into the extended ADB mouse protocol but it does not
appear to do that we want. If we use it to report a device class of
classAbsolute (0) the acceleration curve changes to a flat response
(we end up using 'accl' 0 from https://github.com/elliotnunn/supermario/blob/9dd3c4bef84df2ea30f5ec2c5e97b043e8267b3f/base/SuperMarioProj.1994-02-09/Resources/MiscROMRsrcs.r#L64-L76)
but the coordinates are still interpreted as being deltas. If I use a
device type 4 (Absolute pointing devices) then the mouse position is
never queried. Per https://68kmla.org/bb/index.php?threads/anyone-have-an-adb-graphics-tablet-or-joystick.39128/
all tablet devices end up using custom drivers.
2023-12-15 15:38:32 -08:00
dingusdev 0e0de638d4 Update loguru from the master branch 2023-12-11 07:45:51 -07:00
Maxim Poliakovski fd92d86954 mesh: add MESH TNT variant. 2023-12-11 08:05:39 +01:00
dingusdev c41f5355fd Merge pull request #73 from mihaip/upstream-scsi-name
Fix uninitialized value read in the ScsiHardDisk constructor
2023-12-10 10:58:25 -07:00
Mihai Parparita ea9de4feaf Fix uninitialized value read in the ScsiHardDisk constructor
The call to the ScsiDevice superclass was using the name field (which
was not initialized yet) instead of the name constructor argument
2023-12-10 08:58:12 -08:00
Maxim Poliakovski 114737db41 scsicdrom: use CdromDrive as base class. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski bf278af950 scsidevice: add get_more_data() method.
It is required for supporting large data transfers split
into multiple chunks.
2023-12-10 00:19:44 +01:00
Maxim Poliakovski e1b231882e cdromdrive: declare some methods virtual. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski fa04cde25d machinetnt: more control of machine configuration. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski 705dd390e9 grandcentral: respect size when reading from IOBus devices. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski 078aa79270 grandcentral: remove board register 1 stub. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski a1ad0a3e07 machineid: implement BoardRegister class. 2023-12-10 00:19:44 +01:00
Maxim Poliakovski 858f699750 hammerhead: add configuration accessors. 2023-12-10 00:19:44 +01:00
dingusdev 7cf3d9cd94 Merge pull request #72 from mihaip/upstream-ub
Avoid some undefined behavior
2023-12-08 06:45:44 -07:00
joevt c28e1fa0be ppcmmu: Fix write accesses to read-only memory. 2023-12-08 11:15:04 +01:00
Mihai Parparita e9bc8926ab Avoid some undefined behavior
The `SubOpcode31Grabber[1024] = { ppc_illegalop }` initializer only
populates the first entry with ppc_illegalop (at least on some compilers),
switch to explicitly initializing the entire array with std::fill_n.

Also fix a couple of sign and overflow issues flagged by the Xcode
undefined behavior sanitizer.
2023-12-07 23:59:49 -08:00
dingusdev 4d7204debc Merge pull request #71 from mihaip/upstream-ati-rage
Add support for more ATI Rage video modes
2023-12-07 18:03:51 -07:00
Mihai Parparitaandjoevt 30ded5e803 Add support for more ATI Rage video modes
Cherrypicks a small piece of joevt/dingusppc@117ca1e449
so that booting from the 10.2 CD gets past it trying to change the video
mode to 15bpp.

Co-authored-by: joevt <[email protected]>
2023-12-07 00:16:48 -08:00
Maxim Poliakovski 65a343ce5c Clean up names for SCSI devices. 2023-12-04 22:41:01 +01:00
Maxim Poliakovski 8841c3e7f9 scsihd: more commands. 2023-12-04 21:41:55 +01:00
Maxim Poliakovski 1e4579a076 Improve SCSI state machine. 2023-12-04 21:41:55 +01:00
Maxim Poliakovski be2721cd67 scsihd: cleanup, fixes and more commands. 2023-12-04 21:41:55 +01:00
Maxim Poliakovski 58281520d3 Implement writes to SCSI Pseudo-DMA register. 2023-12-04 21:41:55 +01:00
Maxim Poliakovski 58dacfa263 amic: improve VIA2_IFR and VIA2_IER emulation. 2023-12-04 21:41:55 +01:00
Maxim Poliakovski ae903082d8 amic: implement SCSI DRQ callback. 2023-12-04 21:41:55 +01:00
joevt 9e54fb88f8 memaccess: Fix unaligned 8 byte read. 2023-12-04 15:31:19 +01:00
dingusdev 5859b4cd66 Delete _config.yml
RIP Page that no one really cared about
2023-12-04 06:57:48 -07:00
Maxim Poliakovski 8a987afefd Merge pull request #70 from mihaip/upstream-adb-cleanup
Remove obsolete ADB_Bus class
2023-12-04 11:10:11 +01:00
Mihai Parparita 1a859669eb Remove obsolete ADB_Bus class
Superseded by e9d91175c4 and subsequent
changes.
2023-12-03 23:15:25 -08:00
dingusdev 56f2480caa Update cubeb 2023-12-03 14:34:49 -07:00
joevt 0096d063dd pdmonboard: Add 2, 4, 15, 24 bpp support. 2023-12-03 20:38:01 +01:00
joevt 7c3bb41728 videoctrl: Add more convert frame methods.
Also rename 1bpp and 8bpp methods to 1bpp_indexed and 8bpp_indexed.
2023-12-03 20:38:01 +01:00
Maxim Poliakovski 99ae0c3d31 ppcemu.h: add PVR definition for MPC604e. 2023-12-03 20:05:19 +01:00
Mihai Parparita 6582536591 Inline ppc_set_cur_instruction
It's used in the main emulator loop (ppc_exec_inner), and the function
call overhead adds up.

By inlining it, time to boot to the Finder using a 7.1.2 install CD
and a 6100 ROM goes from ~6700ms to ~6400ms (with clang 14 on a
M2 Max)
2023-12-02 15:12:02 -08:00
dingusdev 628d7249b1 Update gitignore for CodeLite project files 2023-12-01 16:11:32 -07:00
dingusdev 7eb2fd23c3 Fixing typos 2023-12-01 14:04:26 -07:00
Maxim Poliakovski 46961711e4 amic: stub for Ch-B serial xmit DMA. 2023-12-01 22:01:48 +01:00
Maxim Poliakovski 819d475181 poweropcodes: fix div emulation.
Clean up power_doz and power_maskir as well.
2023-12-01 20:41:22 +01:00
dingusdev 07030378c8 Non-US keyboard support started
This is quite unfinished, but should get some of the major targets started.
2023-12-01 10:23:41 -07:00
dingusdev 277be165b6 Merge pull request #67 from mihaip/upstream-power
Fix emulation of doz, dozi, and nabs POWER instructions
2023-12-01 07:48:38 -07:00
Mihai Parparita 1b4de3b64e Fix emulation of doz, dozi, and nabs POWER instructions
doz and dozi were storing the result into the wrong register.

nabs was not taking into account two's complement storage of numbers
and was just setting the signed bit.

These two instructions are used in the implementation of text
measurement in native QuickDraw on 7.1.2/the PDM ROM, and the incorrect
values were resulting in nothing being rendered. With the fix text
appears when booting from the 7.1.2 CD.
2023-12-01 01:34:12 -08:00
Maxim Poliakovski a1d8f8aa4e ppctests: fix test cases with SNaN/QNaN operands. 2023-11-30 17:44:46 +01:00
Maxim Poliakovski 8c3dfe94c7 ppcfpopcodes: infinities should set FPCC_FUNAN. 2023-11-30 12:53:10 +01:00
Maxim Poliakovski 0a9107b602 ppcfloattests.csv: remove unrelated CR7 changes. 2023-11-30 12:28:32 +01:00
Maxim Poliakovski 680cab52f3 ppcfpopcodes: fix ppc_fadds. 2023-11-30 12:06:44 +01:00
Maxim Poliakovski 6abb07e61b Add rounding control for the host FPU. 2023-11-30 12:06:44 +01:00
Maxim Poliakovski b59c2be12d ppcfpopcodes: fix fpresult_update(). 2023-11-30 12:06:44 +01:00
Maxim Poliakovski d49d03846f ppcemu: fix and beatify FPSCR enum. 2023-11-30 12:06:44 +01:00
Maxim Poliakovski b51670cb25 ppcfpopcodes: improve mffs, mtfsb0 and mtfsb1. 2023-11-30 12:06:44 +01:00
Maxim Poliakovski 487c6c2c7c ppcfpopcodes: remove dead code. 2023-11-30 12:06:44 +01:00
dingusdev 87b8a8e0a0 Correcting multiply tests 2023-11-28 19:02:48 -07:00
Maxim Poliakovski 47e0c23e64 Fix CR1 updates for floating-point instructions. 2023-11-28 16:31:51 +01:00
dingusdev dd454689e0 Fixes for condition reg move instructions 2023-11-28 07:06:04 -07:00
Maxim Poliakovski 94872b3ebb Store SCSI bus object pointer during registration. 2023-11-24 19:48:07 +01:00
Maxim Poliakovski 9ae863d7c4 sc53c94: add is_dma_cmd member variable. 2023-11-24 19:48:07 +01:00
Maxim Poliakovski 457accf329 scsi: define READ_BUFFER and WRITE_BUFFER commands. 2023-11-24 19:48:07 +01:00
Maxim Poliakovski b9c1ecf65f Merge pull request #66 from mihaip/upstream-pending-events
Fix keyboard events occasionally being dropped
2023-11-24 19:17:51 +01:00
Mihai Parparita d08b486db0 Fix keyboard events occasionally being dropped
AdbKeyboard would copy the event into its own fields and set the
changed field, so that we could return the event when register was 0.
However, if a subsequent event was received before ADB polling, the
previous event would be overwritten and lost.

Fix this by maintaining a queue of events, so that we can return
everything since the last poll.
2023-11-24 10:08:16 -08:00
Maxim Poliakovski d37d83c5b6 Merge pull request #64 from mihaip/upstream-a-key
Fix "a" key always being as as a keyup
2023-11-24 11:35:18 +01:00
Mihai Parparita d45bba924d Fix "a" key always being as as a keyup
We were using an empty value on the second byte of the ADB keyboard
register 0, but that maps to the "a" key. This manifested itself
as the Key Caps DA never showing the "a" key as being down.

Switch to a non-existent key for the second byte.
2023-11-23 22:39:06 -08:00
dingusdev 69f7fbe703 Update README.md
More accurately reflects DPPC's current status
2023-11-23 20:59:49 -07:00
dingusdev 4753ba5361 Continued clean-up 2023-11-23 16:56:58 -07:00
Maxim Poliakovski ada68ffc71 machinegossamer: add primary IDE hard disk drive. 2023-11-22 17:35:14 +01:00
Maxim Poliakovski 446b1b8d99 atahd: various improvements implementing basic commands. 2023-11-22 17:35:14 +01:00
Maxim Poliakovski 27ff05607c atadefs: bit definitions for the device/head register. 2023-11-22 17:35:14 +01:00
Maxim Poliakovski f2558cd379 atabasedevice: data transfers to host. 2023-11-22 17:35:14 +01:00
Maxim Poliakovski 4f76a4ead2 Move signal_data_ready() to atabasedevice. 2023-11-22 17:35:14 +01:00
dingusdev 7835aec034 Further CPU cleanup 2023-11-21 08:06:50 -07:00
dingusdev f4f035682c Fixed cfloat include 2023-11-19 20:34:40 -07:00
dingusdev d1f9b5631a Added missing include for cfloat 2023-11-19 20:07:00 -07:00
dingusdev d92ae6136a CPU code clean-up in progress
Happened to fix one case in the process.
2023-11-19 17:56:30 -07:00
Maxim Poliakovski be633d3872 soundserver_cubeb: remove soundio code. 2023-11-15 19:01:54 +01:00
Maxim Poliakovski 453930ff75 awacs: pausing sound output DMA channel. 2023-11-15 19:01:54 +01:00
Maxim Poliakovski b7341d0ab8 amic: implement sound out DMA IRQ. 2023-11-15 19:01:54 +01:00
Maxim Poliakovski f814822ca3 timermanager: support for timers that expire immediately. 2023-11-15 19:01:54 +01:00
Maxim Poliakovski c3f2c9e84c awac-pdm: improve read_stat(). 2023-11-15 19:01:54 +01:00
dingusdev 074a760b6a FP compare fixes
This is the start of several fixes for the floating point emulation.
2023-11-13 07:30:31 -07:00
dingusdev 931060db7c Merge pull request #61 from mihaip/upstream-imgfile
Move disk image reading to be behind an ImgFile class
2023-11-10 06:29:33 -07:00
Maxim Poliakovski 417f988ca0 Merge pull request #57 from mihaip/upstreaming2
Remap Cocoa/macOS menu item key modifiers
2023-11-10 08:16:54 +01:00
Mihai Parparita d4c9db7fcf Move disk image reading to be behind an ImgFile class
Allows different implementations for different platforms (the JS
build relies on browser APIs to stream disk images over the network).

Setting aside the JS build, this also reduces some code duplication.
2023-11-09 21:49:28 -08:00
Maxim Poliakovski 04956c19d5 Fix tiny tipo in adbdevice.h 2023-11-09 11:51:33 +01:00
Maxim Poliakovski b350beafa8 Merge pull request #56 from mihaip/upstreaming
Implement the ADB keyboard
2023-11-09 11:47:50 +01:00
Maxim Poliakovski 37cca00e13 Merge pull request #60 from mihaip/upstream-postinit
machinebase: fully initialize devices registered by other devices
2023-11-08 13:55:09 +01:00
Mihai Parparita e5c50640e3 machinebase: fully initialize devices registered by other devices
postinit_devices() may cause additional devices to be registered
(e.g. PCI hosts will register their cards). We were not calling
device_postinit on those devices, because the iterator over the
device map was set up at the start of the loop.

Keep looping until we've actually initialized all devices in the map.
2023-11-08 00:11:41 -08:00
Maxim Poliakovski 351ac78e4b Merge pull request #59 from mihaip/upstream-amic-dma
amic: don't reset cur_buf_pos if we've drained the DMA buffer
2023-11-08 08:20:50 +01:00
Mihai Parparita e011d86742 amic: don't reset cur_buf_pos if we've drained the DMA buffer
Otherwise if pull_data is called again, it will think that it still
has data available in the buffer (rem_len will be non-zero) and
random data at the buffer location will be returned.

This manifested itself as noise being played back in the JS
implementation of the SoundServer. The cubeb implementation was not
affected because it stops polling once it's told it has no more
data in the buffer. Both approaches are valid (the JS version pads
data with silence), and the DMA buffer should support both.
2023-11-06 22:33:00 -08:00
dingusdev f019902f41 Merge pull request #58 from mihaip/iwyu
Clean up #includes
2023-11-03 06:12:00 -07:00
Mihai Parparita 35c86ad6bf Clean up #includes
Result of running IWYU (https://include-what-you-use.org/) and
applying most of the suggestions about unncessary includes and
forward declarations.

Was motivated by observing that <thread> was being included in
ppcopcodes.cpp even though it was unused (found while researching
the use of threads), but seems generally good to help with build
times and correctness.
2023-11-03 00:33:47 -07:00
dingusdev 6ffc2b2f10 Optimize string word instructions
Partially unrolled the loop. Boots 7.1.2 Disk Tools slightly faster.
2023-10-29 17:23:31 -07:00
Mihai Parparita ec155bf7ba Remap Cocoa/macOS menu item key modifiers
As part of adding ADB keyboard support (#56), we're now running into
conflicts between the guest and host OS keyboard shortcuts when running
on macOS hosts.

SDL2 unconditionally adds some menu items to the "Window" menu, and
there are built-in ones too. As a workaround, we now iterate over all
menu items are swap out command for control, since the the latter is
generally unused in classic Mac OS.
2023-10-29 12:16:01 -07:00
dingusdev 8cad7ee509 Merge pull request #55 from mihaip/upstreaming
Add Emscripten build target
2023-10-27 12:24:56 -07:00
Mihai Parparita 1f7edfdb3b Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.

This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).

For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.

The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.

[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-10-25 22:25:53 -07:00
dingusdev 55a354406a Merge pull request #54 from mihaip/upstreaming
Upstream small changes from the Infinite Mac fork
2023-10-22 06:55:20 -07:00
Mihai Parparita a9fd2453a4 Make assertion messages more visible when we drop into the debugger.
Log output may be sent to a file, ensure that the reason why we're
aborting execution is visible.
2023-10-19 07:50:58 -07:00
Mihai Parparita ea0eae467d Add assertion for valid SCSI IDs when updating control lines
Would have flagged the out-of-bounds write fixed by
dingusdev/dingusppc@36cb84eaaa sooner.
2023-10-19 07:49:23 -07:00
Mihai Parparita 5a5ae9fd16 Exit with a non-0 exit code if there are errors
More correct behavior (and makes the Infinite Mac wrapper not close
the emulated Mac, which it does when it thinks there was a graceful
shutdown).
2023-10-18 23:14:15 -07:00
Mihai Parparita 838ccdd7b4 Fix for building on with GCC on ARM
The x86intrin.h intrinsics header is not available in that case.
2023-10-18 23:13:05 -07:00
Maxim Poliakovski cfb1999caf soundserver: fix double freeing. 2023-10-18 16:18:54 +02:00
Maxim Poliakovski 36cb84eaaa mesh: fix write-out-of-bounds to BusStatus1. 2023-10-18 11:21:38 +02:00
Mihai Parparita 73272b28dd Implement the ADB keyboard
Besides generating KeyboardEvents in the SDL event handler and
returning the key state in the register 0 reads of the AdbKeyboard
device, we also needed to generalize the ADB bus polling a bit. We now
check all devices that have the service request bit set, instead of
hardcoding the mouse.

The SDL key event -> ADB raw key code mapping is based on BasiliskII/
SheepShaver's, but cleaned up a bit.
2023-10-11 23:43:20 -07:00
Maxim Poliakovski aa5ef742f6 atirage: return meaningful value for GUI_STAT:GUI_FIFO. 2023-10-10 02:31:09 +02:00
Maxim Poliakovski 47d2e235a3 atirage: prevent big-endian accesses outside VRAM.
The simplest solution is to cut the aperture size by the amount
of video RAM installed. This way, accesses to the big-endian
aperture located above the installed VRAM will be catched and
reported by the MMU.
2023-10-03 14:18:12 +02:00
Maxim Poliakovski 576912dd55 displayid: prevent reading past EDID data. 2023-10-03 00:42:03 +02:00
joevt 5b366e592c Fix spelling. 2023-10-02 15:06:51 +02:00
joevt 170a9d78e7 Fix comment. 2023-10-02 15:06:06 +02:00
Maxim Poliakovski 63b10175bf mesh: stubs for BusFree and EnaReselect commands. 2023-10-02 15:01:27 +02:00
Maxim Poliakovski a5fb124e69 pdmonboard: switch to mmu_map_dma_mem. 2023-10-02 15:00:12 +02:00
Maxim Poliakovski 72d45fb0de amic: switch DMA code to mmu_map_dma_mem. 2023-10-02 14:48:25 +02:00
Maxim Poliakovski f754f63f8f dbdma: fix LOAD_QUAD and STORE_QUAD to work with MMIO. 2023-10-02 14:46:52 +02:00
Maxim Poliakovski 8cf290c034 ppcmmu: add mmu_map_dma_mem method. 2023-10-02 02:20:42 +02:00
Maxim Poliakovski b408a02ef9 dbdma: implement LOAD_QUAD, STORE_QUAD and NOP. 2023-09-30 17:09:45 +02:00
joevt 67146028bf ppcmmu: Add 64-bit accesses to I/O.
Also add an exception for unaligned 64 bit. 64 bit accesses require dword alignment.
2023-09-30 00:29:01 +02:00
joevt acdb14a10a Recalculate execution block after RFI.
While booting Mac OS X 10.2 installer CD, a return from RFI didn't change the instruction address virtual memory page but did change the physical memory page so we must always recalculate the physical address after RFI.
Perhaps there are other cases where this may be required?
2023-09-26 00:13:11 +02:00
joevt dcd4384d46 Fix eb_end calculation.
- Subtract one so that it can't overflow to zero.
- Use page_start as the base so mask operation is not required.
- Recalculate it only when the page changes.
2023-09-26 00:04:07 +02:00
joevt 8348370142 Add separate flags for instruction and data TLBs.
The same flag was being used for flushing both instruction and data TLBs so sometimes a flush for one TLB list would not occur if the flag was cleared when flushing the other TLB list.
2023-09-25 23:42:32 +02:00
joevt 6b3cdad877 ppcmmu: Fix BAT update.
Need to schedule flush of both BAT and PAT type TLBs because BAT takes precedence over PAT which means updating a BAT can invalidate a PAT.
2023-09-25 23:27:00 +02:00
joevt 6b40caf63a ppcmmu: fix setting of LRU bits. 2023-09-25 23:17:57 +02:00
Maxim Poliakovski 99f596ea19 cdromdrive: clean-up and extend READ_TOC command. 2023-09-25 23:17:57 +02:00
joevt 637844269f atapicdrom: Implement sector areas for Read CD.
The disk cache is unchanged. data_ptr continues to be only used for the user data sector area for each block. The other sector areas (synch, header, etc.) are filled in while reading.

has_data and get_data exist as a way to bypass data_ptr for parts of the transfer outside the user data sector area of each block. The default behaviour is defined in atabasedevice and is overridden by atapicdrom for the Read CD command. atapicdrom has a flag doing_sector_areas to control the behavior of the get_data method. When the flag is true, the sector_areas, current_block, and current_block_byte are used for selecting the correct data from one of the sector areas. The Read CD command initializes those variables. xfer_cnt remains the total number of bytes to be transferred and is now not necessarily the same as the number of disk image blocks read into the disk cache.

lba_to_msf is used to fill in the header. The values was not verified using a real CD.

Mac OS X just cares about the Mode in the header. For now, only the synch and header and user data areas are filled in. The other areas read as all zeros.
2023-09-25 12:22:17 +02:00
joevt ec5bf8e985 atapicdrom: Implement READ(6) and READ(10). 2023-09-25 12:22:17 +02:00
joevt 4bbc5ab0af CD-ROM: Fix interpretation of session number.
In Read TOC format 2, Mac OS X passes zero for Session Number. I believe Read TOC is supposed to return the first session starting from that number so it should return info for Session 1 as it would if Mac OS X passed 1 for the Session Number.
2023-09-25 12:22:17 +02:00
Maxim Poliakovski 6cfde29f00 heathrow: implement native interrupt mode. 2023-09-25 12:22:17 +02:00
Maxim Poliakovski c115a887d8 heathrow: fix processing of emulated interrupts. 2023-09-25 02:14:29 +02:00
Maxim Poliakovski 4cdb81e822 mesh: fix Arbitrate command for OS X. 2023-09-24 22:36:44 +02:00
Maxim Poliakovski f4f7edcc28 heathrow: add Ethernet DBDMA channels. 2023-09-22 00:11:19 +02:00
Maxim Poliakovski ae97d7bcc7 Improve zdoc/bmac documentation. 2023-09-22 00:10:19 +02:00
Maxim Poliakovski 5f48a3ab5b bigmac: support more registers. 2023-09-22 00:09:17 +02:00
Maxim Poliakovski 9db3076a48 dbdma: support INT_SELECT & WAIT_SELECT registers. 2023-09-20 00:45:39 +02:00
Maxim Poliakovski 6eb6a5892d bigmac: fix/improve PHY interface. 2023-09-20 00:44:08 +02:00
Maxim Poliakovski 0ebcd15a3d heathrow: connect DMA channel for MESH. 2023-09-19 14:19:15 +02:00
Maxim Poliakovski 04acf120d6 dbdma: support optinal CommandPtrHi register.
It's written with zero in OS X. This dummy implementation
is meant to reduce log warnings.
2023-09-19 14:16:13 +02:00
Maxim Poliakovski 278799795c Disable decrementer exceptions for MPC601. 2023-09-18 21:20:59 +02:00
Maxim Poliakovski c47cbb354d Add is_601 flag for selecting MPC601 specific behavior. 2023-09-18 21:20:59 +02:00
Maxim Poliakovski 8ff2125312 Revert "Minor checks for Data Cache opcodes and LMW"
This reverts commit fd6327ab62.
2023-09-18 21:20:59 +02:00
Maxim Poliakovski a69763c6de dbdma: noop incomplete LOAD_QUAD & STORE_QUAD. 2023-09-18 20:20:25 +02:00
dingusdev 5e32b599d6 Merge branch 'master' of https://github.com/dingusdev/dingusppc 2023-09-04 07:22:27 -07:00
dingusdev fd6327ab62 Minor checks for Data Cache opcodes and LMW 2023-09-04 07:21:00 -07:00
Mihai Parparita 732977db27 Minimal changes to get an Emscripten build
Disable stack traces in loguru (excinfo.h is not available in Emscripten)
and set Emscripten linker flags.
2023-08-30 23:12:43 -07:00
Maxim Poliakovski 45528bfc6d ppcmmu: fix flushing of the secondary ITLB. 2023-08-22 23:36:48 +02:00
Maxim Poliakovski c690049246 Merge pull request #47 from joevt/ofnvram-branch
ofnvram changes
2023-08-22 08:24:57 +02:00
Maxim Poliakovski 932f2bbceb ppcopcodes: fix stwcx. emulation. 2023-08-21 04:50:02 +02:00
dingusdev a7ef177164 Preliminary DBDMA expansion 2023-08-13 16:38:15 -07:00
joevt 300965ab10 Decrementer exception changes. 2023-08-10 00:46:04 +02:00
Maxim Poliakovski d2e7c9a5df ppcexceptions: fix next address for decrementer exceptions. 2023-08-09 12:53:48 +02:00
Maxim Poliakovski ee9c692115 mesh: implement more register reads. 2023-08-09 01:40:09 +02:00
Maxim Poliakovski de1f0c8a9b ppc_mmu: rename reg_desc to rgn_desc to improve readability. 2023-08-07 13:56:49 +02:00
Maxim Poliakovski 52a64168d7 Clean up previous merge. 2023-08-07 13:45:26 +02:00
Maxim Poliakovski b571ff8412 Revert "ppcmmu: Add 64-bit accesses to I/O"
This reverts commit 16123dea45.
2023-08-07 13:06:11 +02:00
Maxim Poliakovski 762319055c Merge pull request #50 from joevt/mmu-changes-branch
mmu changes
2023-08-07 12:58:46 +02:00
Maxim Poliakovski cd9ccb66ed adbkeyboard: fix compiler warning. 2023-08-07 12:51:09 +02:00
joevt ac64f9e30d ppcmmu: Fix mmio read/write offset calculation.
For TLBs referencing an mmio region, calculate an offset that will translate a guest virtual address to an offset in the mmio region.
2023-08-04 20:16:13 -07:00
joevt 16123dea45 ppcmmu: Add 64-bit accesses to I/O
Also add an exception for unaligned 64 bit. 64 bit accesses require dword alignment.
2023-08-04 20:16:13 -07:00
joevt 814260f0b6 ppcmmu: Reduce unmapped physical memory logging.
Don't log consecutive accesses to unmapped physical memory addresses. This saves a couple hundred thousand lines in the log in some cases.
This is only a partial fix. Any access that isn't logged should be queued and output if a log message is output that is not this log message or after a time period.
2023-08-04 20:16:13 -07:00
joevt 439509b408 Fix New World NVRAM limits calculations.
It was possible to corrupt New World nvram using dingusppc setenv command.

- setenv must call get_config_vars to set data_length so that it can calculate free space.
- data_length represents the number of bytes taken by nvram variables including the terminating null for the value (name, '=', value, '\0'). Previously, it did not include the terminating null.
- The list of variables and values ends at a '\0' or at pos == 4096 bytes. Previously, data_length wouldn't get set if pos >= 4096.
- Allow setenv to create new nvram variables.
- Since data_length now represents the total number of used bytes, free_space now represents the actual free space, so use > free_space (instead of >= free_space) to determine insufficient space.
- While parsing nvram variable name, do not read beyond 4096 bytes.
- Use a different error message for each problem that can occur while parsing nvram variable name.
2023-08-04 20:11:59 -07:00
joevt 07f57a1e9b Remove extra semi-colons. 2023-08-04 20:11:59 -07:00
joevt 0c9ddaccf7 Fix dppc debugger printenv of multiline variables.
If a nvram variable has CRLF or CR, replace them with LF so each line appears on a new line in the console output.
Also, add indent to each line so that each line appears only in the value column and not in the name column.
2023-08-04 20:11:59 -07:00
dingusdev b23bb04dac Start fix for SCSI Hard Drive 2023-08-02 07:53:19 -07:00
dingusdev a7601c36bd Started work on keyboard input 2023-08-01 22:43:11 -07:00
Maxim Poliakovski 1a883ba73e viacuda: implement basic autopolling. 2023-08-02 00:07:17 +02:00
Maxim Poliakovski 2e50b364c4 adbmouse: emulate single button mouse. 2023-08-01 23:58:29 +02:00
Maxim Poliakovski b4b41a47b2 hostevents: dispatch mouse button events. 2023-08-01 23:57:16 +02:00
Maxim Poliakovski 5b90a3e21d AMIC: rework and improve interrupts. 2023-08-01 17:42:52 +02:00
Maxim Poliakovski ca83f7e8ef pdmonboard: switch to new video controller API. 2023-08-01 17:41:02 +02:00
Maxim Poliakovski 337a9d6dd0 videoctrl: generate VBL interrupts. 2023-08-01 17:37:50 +02:00
Maxim Poliakovski ddf139a659 Extend TimerManager API a bit. 2023-08-01 17:36:29 +02:00
Maxim Poliakovski 6b8fe50f50 hostevents: add prost-processing signal. 2023-08-01 17:21:17 +02:00
Maxim Poliakovski 233ab778b6 adbmouse: support for movement data in R0. 2023-08-01 17:18:46 +02:00
Maxim Poliakovski 4872af1053 control: use new refresh task control. 2023-07-31 03:53:13 +02:00
Maxim Poliakovski 0ca1ebf724 atimach64gx: use new refresh task control. 2023-07-31 03:52:17 +02:00
Maxim Poliakovski 632479b1ba atirage: use new refresh task control. 2023-07-31 03:46:16 +02:00
Maxim Poliakovski 9b81891467 pdmonboard: use new refresh task control. 2023-07-31 03:36:17 +02:00
Maxim Poliakovski 7b2e1d90e6 Move refresh task control to VideoCtrlBase. 2023-07-31 03:34:02 +02:00
Maxim Poliakovski 6fa6b4d4dc Rework the EventManager to use CoreSignal. 2023-07-27 02:40:32 +02:00
Maxim Poliakovski 6efe6f13a9 Add new CoreSignal class. 2023-07-27 02:38:21 +02:00
Maxim Poliakovski c254749493 viacuda: connect to new AdbBus device. 2023-07-26 04:50:05 +02:00
Maxim Poliakovski fd9f8c90a5 Basic ADB mouse device emulation.
For now, it solely handles the basic ADB commands.
2023-07-26 04:40:20 +02:00
Maxim Poliakovski 0a0761c7e0 AdbDevice - the base class for ADB devices. 2023-07-26 04:35:07 +02:00
Maxim Poliakovski e9d91175c4 Add AdbBus class and device. 2023-07-26 04:29:08 +02:00
Maxim Poliakovski 0c0166b565 viacuda: fix packet response protocol.
Cuda needs to negate TREQ before sending the last byte of a
fixed-length response to avoid transfering an extraneous byte.
2023-07-26 04:22:08 +02:00
Maxim Poliakovski 7bb7ff9f0f heathrow: human-readable DBDMA channel names. 2023-07-24 15:20:52 +02:00
Maxim Poliakovski c2cd076662 machinebase: fix log statement warning. 2023-07-23 16:50:14 +02:00
Maxim Poliakovski a9f73e7384 hwcomponent: fix size of the component type enum. 2023-07-23 16:32:00 +02:00
Maxim Poliakovski 14c7d18bdb Revert "Prevents crashing for Big Mac"
This reverts commit 5787d49e9b.
2023-07-23 16:28:31 +02:00
dingusdev 5787d49e9b Prevents crashing for Big Mac
For some reason, on Windows, whether it be VS2022 or Clang, it will crash when trying to write to a Big Mac register if you don't specify the exact name of the component within Heathrow.

This commit fixes that.
2023-07-22 15:15:33 -07:00
Maxim Poliakovski 25150268cd ppcexceptions: fix ISI exception target address. 2023-07-10 14:06:20 +02:00
Maxim Poliakovski f7a1412ec7 atapibasedevice: fix task file initialization on reset. 2023-07-09 02:10:48 +02:00
Maxim Poliakovski a424d48447 bigmac: implement software reset registers. 2023-07-08 23:30:44 +02:00
Maxim Poliakovski e76e3afa87 Improve zdoc/bmac documentation. 2023-07-08 21:33:10 +02:00
Maxim Poliakovski 482fe3eb80 bigmac: MAC serial EEPROM emulation. 2023-07-08 21:32:26 +02:00
Maxim Poliakovski 4de2afc0c5 bigmac: fix Gossamer PHY stuff. 2023-07-08 14:35:23 +02:00
Maxim Poliakovski 742003b6f3 Basic BigMac Ethernet controller emulation.
Emulates MII and some PHY configuration registers.
2023-07-08 01:27:01 +02:00
Maxim Poliakovski 10b8366219 hwcomponent: add Ethernet MAC type. 2023-07-08 01:23:18 +02:00
dingusdev 4364c89fd4 Slight clean-up for execution type 2023-06-19 22:36:27 -07:00
dingusdev d11d693b52 Compilation fix for VS 2023-06-19 22:36:09 -07:00
Maxim Poliakovski 357fc3a73a machineyosemite: attach ATAPI CD-ROM. 2023-06-18 23:44:12 +02:00
Maxim Poliakovski 1051a7fb9b machinegossamer: attach ATAPI CD-ROM. 2023-06-18 23:43:08 +02:00
Maxim Poliakovski 0687b0c60e New ATAPI CD-ROM implementation. 2023-06-18 23:36:46 +02:00
Maxim Poliakovski fc26be3e24 atapibasedevice: implement PIO transfers.
Also move ATAPI CD-ROM related stuff to separate
source and implement various helpers.
2023-06-18 23:33:57 +02:00
Maxim Poliakovski f733859e28 heathrow: support for IDE interrupts. 2023-06-18 23:31:28 +02:00
Maxim Poliakovski a4cac2df81 atabasedevice: interrupt support. 2023-06-18 23:30:06 +02:00
Maxim Poliakovski 4886b4d52a Add base class for CD-ROM drives. 2023-06-18 23:28:41 +02:00
Maxim Poliakovski 3c5a0ad8c1 Add BlockStorageDevice class. 2023-06-18 23:27:10 +02:00
Maxim Poliakovski ac267b3daa idechannel: support devices registration and interrupts. 2023-06-18 23:24:19 +02:00
Maxim Poliakovski cb347434d3 hwinterrupt: add IDE interrupts. 2023-06-18 23:22:51 +02:00
Maxim Poliakovski 3a7e3c1986 Initial support for device path properties. 2023-06-18 23:15:08 +02:00
Maxim Poliakovski d113c4cf7a ATAPI Features bit definitions. 2023-06-18 23:06:04 +02:00
Maxim Poliakovski 7a8b534c07 More SCSI commands and error codes. 2023-06-18 23:04:02 +02:00
Maxim Poliakovski 73d0356058 ppcopcodes: fix dcbz for BlockZero in Mac OS 8.x 2023-06-17 20:57:48 +02:00
Maxim Poliakovski ee7b2838bc One more attempt to fix GCC build. 2023-05-30 19:55:46 +02:00
Maxim Poliakovski 6f247f64cd ScsiBus: add missing include. 2023-05-30 19:51:07 +02:00
Maxim Poliakovski 0b2fd60308 Fix Gazelle crash by adding PCI slot properties. 2023-05-30 19:48:40 +02:00
Maxim Poliakovski f809124a2e Improve SCSI bus registration. 2023-05-30 19:46:27 +02:00
Maxim Poliakovski 586828b375 Base class for ATAPI devices. 2023-05-15 17:57:20 +02:00
Maxim Poliakovski e36150a5ca Add ATAPI commands, clean up formatting. 2023-05-15 17:57:20 +02:00
Maxim Poliakovski 0f8e68d4bf Rework ATA reset logic. 2023-05-15 17:57:20 +02:00
Maxim Poliakovski c543d0936c machineyosemite: add SCSI0 bus. 2023-04-24 22:57:16 +02:00
Maxim Poliakovski daca3a27d6 soundserver: silence some logging messages. 2023-04-23 21:40:21 +02:00
Maxim Poliakovski 26374366c7 awacs: minor improvements (proper initialization). 2023-04-23 21:32:41 +02:00
Maxim Poliakovski 22798fe14e Fix compilation of the audio codec classes. 2023-04-23 21:04:24 +02:00
Maxim Poliakovski 44478b6937 heathrow: implement floppy DMA interrupts. 2023-04-22 22:53:20 +02:00
Maxim Poliakovski 57ea3c2e66 dbdma: implement interrupt processing. 2023-04-22 22:52:03 +02:00
Maxim Poliakovski 03595c3940 Merge remote-tracking branch 'origin/machine-yosemite' 2023-04-21 12:49:58 +02:00
Maxim Poliakovski ed48766e5f atahd: cosmetic improvements. 2023-04-17 09:56:03 +02:00
Maxim Poliakovski a7f4d418fc main: fix interpreter invokation. 2023-04-17 02:24:31 +02:00
Maxim Poliakovski 4093c6e83c amic: fix SCSI DMA to match newer MMU API. 2023-04-17 01:32:29 +02:00
Maxim Poliakovski cf0d361918 Merge 'hard-disks' branch. 2023-04-17 01:20:38 +02:00
Maxim Poliakovski 09da0c6109 nvram: use smart pointers, fix initialization. 2023-04-17 00:03:36 +02:00
Maxim Poliakovski 2f562e7761 Convert ATI register offsets to DWORD format. 2023-04-11 01:25:00 +02:00
Maxim Poliakovski b07b700b36 Refactor ATI Mach64 GX emulation. 2023-04-10 22:19:55 +02:00
Maxim Poliakovski 616d0728fd videoctrl: support guest rendered HW cursors. 2023-04-07 23:16:18 +02:00
Maxim Poliakovski 74a49d1568 atirage: major refactoring. 2023-04-07 23:16:18 +02:00
Maxim Poliakovski 3e545bdef9 Handling host events in video controllers. 2023-04-02 03:01:13 +02:00
Maxim Poliakovski f1c898b17e Initial host event manager. 2023-04-02 03:01:13 +02:00
Maxim Poliakovski 49f47c5f3f bandit: attach devices from the CLI. 2023-04-02 03:01:13 +02:00
Maxim Poliakovski 888d919ae7 videoctrl: refactor palette access. 2023-04-02 03:01:13 +02:00
Maxim Poliakovski e01fea87a9 More bitops. 2023-04-02 03:01:13 +02:00
dingusdev f181e721b0 Fixed compilation for Visual Studio 2023-03-19 07:55:26 -07:00
Maxim Poliakovski c188d0251a ofnvram: support CHRP style OF config partition. 2023-02-25 18:14:42 +01:00
Maxim Poliakovski d76433f112 heathrow: properly relocate memory space. 2023-02-25 18:14:42 +01:00
Maxim Poliakovski 422639411d Initial Burgundy sound codec emulation. 2023-02-25 18:14:42 +01:00
Maxim Poliakovski 5d7450df90 heathrow: locate sound HW by type.
That allows using sound codecs other than Screamer with Heathrow.
2023-02-25 18:14:42 +01:00
Maxim Poliakovski 3234f21cab Overhaul audio codec classes. 2023-02-25 18:14:42 +01:00
Maxim Poliakovski 2fb23e210e Grackle: implement some register reads to avoid warnings. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski fdf0ebbf6c machineyosemite: implement RAM modules. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski 597c077b19 Implement PPC decrementer. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski 71b2e6c1fa dbdma: implement optional command branching.
This feature is used by New World BootROMs for producing
error beeps with different duration and count.
2023-02-15 02:36:40 +01:00
Maxim Poliakovski 196154bb7b machineyosemite: use Heathrow as I/O controller for now. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski 92c558f44b Initial Yosemite emulation. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski ad2fc290ec Initial DEC 21154 P2P bridge emulation. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski 299f0d3a9f Accept 1MB New World Boot ROMs. 2023-02-15 02:36:40 +01:00
Maxim Poliakovski 9fcf5ba51a ppcmmu: fix bug in mmu_change_mode(). 2023-02-15 02:18:31 +01:00
Maxim Poliakovski 094b3b5312 Fix Cuda response protocol. 2023-02-08 21:26:11 +01:00
Maxim Poliakovski 7e5451a97d Cosmetics: break long lines, fix indentation. 2023-02-08 11:41:37 +01:00
Maxim Poliakovski 8231ecd466 Merge pull request #43 from joevt/PCI-bridge-and-multi-function-support
Pci bridge and multi function support
2023-02-07 00:41:50 +01:00
joevt 1d33ea2beb Grackle: Update readme. 2023-02-05 07:17:29 -08:00
joevt bee24b166d Add method to attach PCI device with new name.
- Added an overloaded version of attach_pci_device which takes a suffix string that can be used to make a device name unique so that multiple devices of the same class can be added to a machine. The method returns a PCIDevice which can be easily used to attach more PCI devices if it is a PCIHost.
2023-02-05 07:17:29 -08:00
joevt f61854a0ae Add has_io_space flag.
PCIDevice
- supports_io_space method now uses a flag has_io_space which is automatically set for PCI bridges or PCI devices that have an I/O BAR.

atirage
- Devices that have I/O BARs don't need a supports_io_space method.

mpc106
- Devices that don't have I/O methods don't need a supports_io_space method.
2023-02-05 07:17:28 -08:00
joevt 99eb93f9e1 Add set_irq_pin method.
A multi-function device may have functions of the same class (e.g. a USB device with two OHCI functions) but each function should be initialized with a different interrupt pin.
2023-02-05 07:17:28 -08:00
joevt be45a6a020 Add PCI bridge and multi-function device support.
Add PCI bridge and multi-function device support.
Overview:
- A multi-function device is two or more PCIDevices with the same device number but one device is function zero (as with currently implemented PCIDevices) and the other functions have function numbers between 1 and 7. The device number and function number are properties of the PCIDevice's parent PCIHost connection.
- A PCIBridge is a PCIHost (it can connect child PCI devices) and a PCIDevice (it has config space, BARs, and expansion ROM).
- A PCIDevice has Type 0 header. It has 6 BARs.
- A PCIBridge has Type 1 header. It has 2 BARs. The config space registers beginning from offset 0x18 differ from those of a PCIDevice.

Possible future modifications:
- Add a PCICardBus class. It is a PCIHost. It has Type 2 header. It has one BAR. The first 20 bytes match Type 0 and Type 1 headers. These exist in New World Macs. They allow hot-plug of PCI devices.
- Split base PCI registers (first 16 bytes) into a PCIBase class. Type 1 and 2 have two or one BAR but I think all 6 BARs belong in PCIBase class anyway.
- Split PCIHost into two classes: Currently existing PCIHosts (Bandit, Grackle) are PCIHost and PCIRoot (they have the broadcast I/O requests functionality) while PCIBridge is PCIHost only - it can propagate I/O requests but does not originate the broadcast.
- pci_register_mmio_region should maybe return a pointer to a region struct so that it can be used for unregistering or modifying the region's range. This may be useful for PCI bridges which have ranges that may constrain memory BARs of their downstream devices.

PCIDevice
- Moved expansion ROM BAR handling to a separate function pci_wr_exp_rom_bar so that it can be used by both PCI devices and PCI bridges which have the ROM BAR in different locations. It now supports unmapping expansion ROM. Also made exp_rom_bar not writable if there's no ROM.
- Added num_bars field which specifies the number of valid BARs since Type 0, 1, and 2 headers have different number of BARs.
- map_exp_rom_mem now properly unmaps expansion ROM (using new function unmap_exp_rom_mem) before mapping it again.
- Added function set_multi_function which modifies hdr_type to indicate if a device has other functions. This is to be applied only to devices with function number 0.

PCIHost
- When attaching a PCI device, it will check if it's a multi-function device (there exists an attached function that is not zero) and adjust hdr_type of function 0 of the device accordingly.
- Attached PCI bridges are added to a list of PCI bridges attached to the host.
- Added pci_io_read_loop and pci_io_write_loop which loop through attached PCI devices to find one that will perform the action for the given I/O address without logging an error (since some other device might perform the action).
- Added pci_io_read_broadcast and pci_io_write_broadcast which are used by a PCI root (bandit/grackle). They will log an error if the action is not performed. They should probably do a machine check exception to match real Power Macs.
- pci_find_device (used by PCI root) will recursively find a PCIDevice for type 1 config register accesses.
- Logging from PCIHost now includes the name of the PCIHost instead of just "PCIHost" because there can be multiple PCI hosts.

PCIBridge
- Sets num_bars to 2 and hdr_type to 1.
- I/O ranges set in the config registers are handled correctly by pci_io_read and pci_io_write.
- Memory ranges set in the config registers do not currently affect memory mmio regions. It is assumed that Open Firmware and the OS will set the ranges and BARs correctly to allow all BARs to be accessed fully.

bandit, mpc106
- Bandit and Grackle now call pci_io_read_broadcast and pci_io_read_broadcast to pass I/O accesses to downstream PCI devices.
- Chaos is modified to work like Bandit even though it will never have PCI bridges attached or devices that support I/O accesses. It's simpler this way.
2023-02-05 07:17:28 -08:00
joevt b472123746 Standardize PCIDevice slot_id for PCIHost.
PCIHost
- PCIHosts (bandit and grackle) now use device number and function number for identifying attached PCIDevices. A macro DEV_FUN is added to calculate this new slot_id. Bandit no longer uses IDSEL. Grackle no longer uses only device number.

machinecatalyst, machinegossamer, machinetnt
- Use DEV_FUN to attach PCI devices by device number and function number.
2023-02-05 06:57:04 -08:00
joevt fd2e6c5b09 Fix ATIRage I/O accesses.
- Don't log anything if the I/O access is not for this device. A different device might handle it.
- Don't return true for I/O access if an I/O access is not performed. Otherwise the I/O access won't be passed to other devices.
2023-02-05 01:22:01 -08:00
joevt f7280c316b Fix 64 bit BAR.
A 64 bit BAR has least significant 32 bits first as in the original pull request.
2023-02-05 01:22:01 -08:00
Maxim Poliakovski cc17035e67 pcidevice: improve BAR configuration. 2023-02-04 17:57:46 +01:00
Maxim Poliakovski 654ff0219c Merge pull request #42 from joevt/64-bit-BARs
64 bit BAR support
2023-02-04 12:43:57 +01:00
joevt 8862a73ef1 Merge remote-tracking branch 'upstream/master' into 64-bit-BARs 2023-02-02 21:14:05 -08:00
Maxim Poliakovski 5e61b473f0 mpc106: support reading back CONFIG_ADDR. 2023-02-02 12:45:44 +01:00
joevt 2a64f547cc Add 64-bit BAR support.
While dingusppc only emulates 32-bit Macs (for now), it is possible for a 32-bit Power Mac to use a PCIe card that has 64-bit BARs.

finish_config_bars is added to scan the cfg values of the BARs and determine their type. The type is stored separately so that it does not need to be determined again.
The type can be I/O (16 or 32 bit) or Mem (20 or 32 or 64 bit). A 64 bit bar is two BARs, the second contains the most significant 32 bits.

set_bar_value uses the stored type instead of trying to determine the type itself. It is always called even when the firmware is doing sizing. For sizing, It does the job of setting the bar value so do_bar_sizing is now just a stub.

Every PCIDevice that has a BAR needs to call finish_config_bars after setting up the cfg values just as they need to setup the cfg values. Since they need to do both, maybe the cfg values should be arguments of finish_config_bars, then finish_config_bars() should be renamed config_bars().
2023-02-02 02:47:34 -08:00
joevt fba2ff4231 Corrections for refactors.
- Macros need parenthesis to enforce operation order when expanded.
- Fix device and register numbers in log messages.
- Unmapped I/O space reads don't necessarily return 0xffffffff. That's only for config space reads. Just return 0. Unhandled I/O space read should probably cause a memory check (TEA - Transfer Error Acknowledge) exception as it does on a Power Mac 8600.
2023-02-02 02:47:34 -08:00
Maxim Poliakovski e64aab1577 Rename data conversion helpers for PCI config.
Reword some descriptions for better understanding.
2023-02-02 02:22:47 +01:00
Maxim Poliakovski 36dee46e9b mpc106: refactor PCI read and write methods. 2023-02-02 02:22:47 +01:00
Maxim Poliakovski 99e92a5679 mpc106: rewrite control registers handling. 2023-02-02 00:21:55 +01:00
Maxim Poliakovski ec97a671d8 bandit: refactor host read and write methods. 2023-02-01 16:21:49 +01:00
Maxim Poliakovski 31db015105 pcihost: refactor data access helpers. 2023-01-31 23:20:31 +01:00
Maxim Poliakovski 2b6716be5c mesh: arbitration and selection commands. 2023-01-26 00:34:17 +01:00
Maxim Poliakovski 449cc96612 Basic MESH emulation. 2023-01-25 20:58:30 +01:00
Maxim Poliakovski bcd443779a machinegossamer: add internal SCSI bus. 2023-01-25 20:56:51 +01:00
Maxim Poliakovski 6b6e92d3d9 scsi: change positions of SEL, BSY and RST bits.
New positions match better MESH internal bits.
2023-01-25 20:53:34 +01:00
Maxim Poliakovski 289ddf10b7 bandit: clean up PCI device connection. 2023-01-23 14:06:39 +01:00
Maxim Poliakovski 699b62373a Merge pull request #41 from joevt/fix-pci-unaligned
Fix PCI config r/w of byte and word and unaligned.
2023-01-23 13:26:06 +01:00
joevt 4100a80f96 Fix PCI config r/w of byte and word and unaligned.
dingusppc could not read bytes from offset 1,2,3 or words from offset 2.
dingusppc did not read words from offset 1,3 and longs from offset 1,2,3 in the same way as a real Power Mac 8600 or B&W G3.
This commit fixes those issues.

- Added pci_cfg_rev_read. It takes a 32 bit value from offset 0 and returns a value of the specified size using bytes starting from the specified offset. Offsets 4,5, & 6 wrap around to 0,1, & 2 respectively. The result bytes are in flipped order as required by the read method (so a value of 0x12345678 is returned as 0x78563412)
A real Power Mac 8600 might return a random byte for offset 4, 5, 6 for vci0 but usually not for pci1. A B&W G3 seems to always wrap around correctly. We won't read random bytes, and we won't read a default such as 00 or FF. We'll do the wrap around which makes the most sense because writing 0x12345678 to any offset and reading from the same offset should produce the value that was written.

- Added pci_cfg_rev_write. It takes a 32 bit value from offset 0, and modifies a specified number of bytes starting at a specified offset with the offset wrapping around to 0 if it exceeds 3. The modified bytes take their new values from the flipped bytes passed to pci_cfg_write. When size is 4, the original value is not used since all bytes will be modified.

Basically, those two functions handle all the sizes and all the offsets and replace calls to BYTESWAP_32, read_mem or read_mem_rev, and write_mem or write_mem_rev.
read_mem_rev, as it was used by pcidevice and some other places, could read beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always read the wrong byte or word if they were not at offset 0. Same for read_mem as used by mpc106.
write_mem_rev, as it was used by pcidevice and some other places, could write beyond offset 3 if it were ever passed a reg_offs value that did not have offset as 0. Since the offset was always zero, it would always write the wrong byte or word if they were not at offset 0. Same for write_mem as used by mpc106.

pcidevice:
- The logging macros should be used to handle all config register access logging.
- Unaligned PCI config register accesses will be output as ERROR instead of WARNING.
- The logging macros include the offset and size. They also include the value for named registers or for writes.
- Added MMIODevice read and write methods so that PCIDevice is not abstract if a PCIDevice doesn't override the read and write method since some PCIDevices don't have MMIO.

pcihost:
- Added pci_find_device stub for handling PCI bridges in future commit.

bandit and mpc106:
- PCI host controllers will handle all PCI config access alignment and sizing. A PCIDevice will always access config registers as 32 bits on a 4 byte boundary. The AccessDetails passed to a PCIDevice config read or write method is there only for logging purposes.

bandit:
- Common MMIO code is moved to new BanditHost class so both Bandit and Chaos can use it. PCI related code is moved to new BanditPCI class.
- Simplify IDSEL to/from PCI device number conversion by removing the shift or subtract.
- Remove BANDIT_ID_SEL check. The IDSEL conversion to PCI device number can find the bandit PCI device.
- For logging, make best guess of PCI device number from invalid IDSEL - the result is always reasonable for device 0x00 to 0x0A when accessing config register 0x00 (as one would do when scanning for PCI devices like lspci does).

mpc106:
- Common config space code is put in cfg_setup. It handles extracting the offset.
- Added code to log access to unimplemented config registers of grackle.
- Don't call setup_ram when writing to config registers that setup_ram doesn't use.
- pci_cfg_read calls READ_DWORD_LE_A and pci_cfg_write calls WRITE_DWORD_LE_A. When reading or writing memory that is organized as little endian dwords, such as my_pci_cfg_hdr of mpc106, the function should explicitly state that it's little endian so that the emulator may be ported one day to a CPU architecture that is not little endian.

atirage:
- The changes correctly place user_cfg at byte 0x40 instead of 0x43 and writes the correct byte depending on size and offset.
2023-01-16 00:09:44 -08:00
Maxim Poliakovski 136aeca8f2 Fix Gossamer system register. 2023-01-11 23:49:20 +01:00
Maxim Poliakovski 8d01440558 Improve previous (cosmetics & code duplication). 2023-01-11 23:36:16 +01:00
Maxim Poliakovski e510c11be2 Merge pull request #40 from joevt/master
Gazelle fixes, PCI changes and additions, MMIO changes, etc.
2023-01-11 23:05:15 +01:00
joevt 19adb54cd8 Fix compiler warnings.
These were detected by github Actions but not by Xcode.
2023-01-11 01:17:13 -08:00
joevt f2db6bd066 Add missing header. 2023-01-11 01:17:13 -08:00
joevt 1b221bc0bd Fix compiler warnings: never executed. 2023-01-11 01:17:12 -08:00
joevt 85d0900d7d Fix compiler warnings: possible misuse of comma. 2023-01-11 01:17:12 -08:00
joevt 5294a8b71c Fix compiler warnings: unused variables. 2023-01-11 01:17:12 -08:00
joevt 46bc8567e9 Fix compiler warnings: uninitialized variables.
- mpc601_block_address_translation will now return 0 for prot and pa when bat_hit is false (when the if statement is not positive during the for loop). The calling function doesn't care what prot and pa are when bat_hit is false, but we do this to remove the compiler warining.
- For tlb_flush_entry, the compiler thinks m might not always be in the range 0 to 5 so tlb1 and tlb2 might not get initialized by the switch statement. Add default to get around this warning.
2023-01-11 01:17:12 -08:00
joevt 64fec88436 Fix compiler warnings: cast loses precision.
Use explicit cast when converting large integer types to smaller integer types when it is known that the most significant bytes are not required.
For pcidevice, check the ROM file size before casting to int. We'll allow expansion ROM sizes up to 4MB but usually they are 64K, sometimes 128K, rarely 256K.
for machinefactory, change the type to size_t so that it can correctly get the size of files that are larger than 4GB; it already checks the file size is 4MB before we need to cast to uint32_t.
For floppyimg, check the image size before casting to int. For raw images, only allow files up to 2MB. For DiskCopy42 images, it already checks the file size, so do the cast after that.
2023-01-11 01:17:12 -08:00
joevt bd5a88f02f Ignore Xcode project files. 2023-01-11 01:17:12 -08:00
joevt b61a7c4aea Log something from machine initialization.
The machine type and its corresponding source file name should appear once in the log output.
2023-01-11 01:17:12 -08:00
joevt 2f08a0b327 Fix Gossamer machineID allocation size.
When the allocation is logged, it will look appear like this:
Added mmio region 0xFF000004..0xFF000FFF (Machine-id)
instead of like this:
Added mmio region 0xFF000004..0xFF001003 (Machine-id)
2023-01-11 00:05:23 -08:00
joevt 52fa30b71d Add ability to unregister mmio region.
mmio regions are registered when a PCI BAR is set. Add the ability to reverse that - for when a PCI BAR is changed.
2023-01-11 00:05:23 -08:00
joevt 911acb4bc2 Remove MPC106 RAM allocation failed error.
It might not be an error - usually it just means that it was already allocated so demote this message to a warning.

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

HWComponent name should be set as early as possible in the constructor so it can be used in log messages.
PCIDevice should set name of HWComponent (through MMIODevice) in its constructor, using the name that is given to its constructor.
For Bandit and Grackle, they don't need to set the HWComponent name since its PCIDevice constructor will now do it.
Chaos is not a PCIDevice so it should set the MMIODevice name itself.
Why does PCIDevice have a name that is separate from the HWComponent name?
2023-01-11 00:05:23 -08:00
joevt 5aaae40d94 Add Nvidia vendor ID.
In case you want to emulate an Nvidia GPU in the future (for Core Image, etc.)
2023-01-11 00:05:23 -08:00
joevt 190718fbee Add BAR 0 to control.
BAR 0 exists on a real Power Mac 8600 and the dingusppc 7500.

On a Power Mac 8600, the initial value is 0x84000003. In Open Firmware, you can write to all bits of the BAR and read the value back except the 2 least significant bits are always %11. Bit 0 indicates I/O space. Bit 1 is reserved and should be zero so maybe this is not a real I/O space BAR. 0x8400000 is written to the BAR by Open Firmware. It doesn't look like a normal I/O address which are usually 16 bits.

On the emulated 7500, 0x02000000 is written to the BAR by Open Firmware sometime during probe-all. The BAR did not behave as it does in the Power Mac 8600. This commit fixes that.

Two questions remain:
1) Which fcode writes to the BAR? Is it the probe fcode or is it the control fcode? There's no config-_! in the control fcode.
2) What is the purpose of the BAR? Writing to it can cause a hang. The testbits code below seems to succeed - it restores the original value after reading the result of testing each bit and before displaying the result. The values shown for the MSB (0x84 on the 8600 and 0x02 on the 7500) could be three flag bits.

```
dev vci0
: testbits { adr ; org }
	cr
	adr config-l@ dup -> org ." original : " 8 u.r cr
	20 0 do
		1 1f i - << dup 8 u.r ."  : "
		adr config-l!
		adr config-l@
		org adr config-l!
		8 u.r cr
	loop
	;

15810 testbits \ 15810 is the address of the BAR on the emulated 7500.
```
2023-01-11 00:05:23 -08:00
joevt 37c352955c Allow bit 1 of I/O BARs to be set.
Usually bit 1 of I/O BARs is 0 since it is reserved, but control has an I/O BAR where this bit is set.
bar_cfg is used to determine the default values of the least significant bits (2 bits for I/O BARs and 4 bits for Memory BARs).
The upper bits of bar_cfg determine which bits can be set and also determines the size of the BAR.
2023-01-11 00:05:23 -08:00
joevt fb56a6b536 Fix gazelle sys-id.
It should match AAPL,cpu-id property from real Power Mac 6500.
2023-01-11 00:05:23 -08:00
Maxim Poliakovski 74b457819a Update .gitignore 2023-01-09 00:40:48 +01:00
Maxim Poliakovski 0118b347f3 Clean up build scripts. 2023-01-08 23:29:25 +01:00
Maxim Poliakovski 101a8d33b0 Manage Windows build dependencies with vcpkg. 2023-01-08 22:27:13 +01:00
Maxim Poliakovski eb3f978c7b Update Capstone and fix its compilation. 2022-12-30 22:31:51 +01:00
Maxim Poliakovski 9ea4a465f4 machinegazelle: tiny comment improvement. 2022-12-23 23:45:26 +01:00
Maxim Poliakovski 41a34ffab6 Basic Gazelle (PM 6500) emulation. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski 8002737124 Basic O'Hare I/O controller emulation. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski 7ba8921649 ppcemu: add PVR for 603ev. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski a1d9fcfa9d Basic PSX memory controller emulation. 2022-12-23 17:19:46 +01:00
Maxim Poliakovski 648dfcd47b ppcmmu: fix BAT state updates. 2022-12-20 14:58:45 +01:00
Maxim Poliakovski f6e208267e bandit: more config space registers. 2022-12-19 01:28:16 +01:00
Maxim Poliakovski 24ccdabedc bandit: add PSX style PCI bridge. 2022-12-18 23:40:56 +01:00
Maxim Poliakovski a189c94980 scsihd: fix READ_CAPACITY_10 command.
Also bump internal buffer size to 2 MB
to temporarily fix buffer overflows.
2022-12-14 16:14:53 +01:00
Maxim Poliakovski dee225ee8f atabasedevice: add ATAPI signature at device reset. 2022-12-12 15:07:19 +01:00
Maxim Poliakovski 52bb87b72a Improve ATA interface. 2022-12-12 02:36:56 +01:00
Maxim Poliakovski 78528a1a16 floppyimg: correct format for MFM DC42 images. 2022-12-12 02:27:42 +01:00
dingusdev 0dd9a3d9b1 Further ATA cmd work 2022-12-11 16:08:43 -07:00
Maxim Poliakovski df02f5053b floppyimg: initial support for Disk Copy 4.2 images. 2022-12-11 23:00:52 +01:00
Maxim Poliakovski 86b0174b13 Fix previous. 2022-12-09 01:07:08 +01:00
Maxim Poliakovski daf3ecde4e More ATA interface cleanup. 2022-12-09 01:03:09 +01:00
dingusdev 1e9ec5d7ae Start ATA command support 2022-12-08 15:29:04 -07:00
Maxim Poliakovski 2537751fa7 Clean up ATA interface. 2022-12-08 08:04:09 +01:00
Maxim Poliakovski df1a56305a atabasedevice: rework task file registers. 2022-12-08 00:16:10 +01:00
Maxim Poliakovski 6173a782f2 Implement ATA hard disk stub. 2022-12-07 23:36:56 +01:00
Maxim Poliakovski a892842b8f Refactor ATA/IDE classes. 2022-12-07 22:36:25 +01:00
dingusdev 58908621e6 IDE refinements 2022-12-05 08:42:51 -07:00
dingusdev 311538b81d Fix IDE functionality 2022-11-26 21:34:54 -07:00
Maxim Poliakovski 14bcb6c08a Clean up previous commit. 2022-11-23 20:28:09 +01:00
joevt 09d374f626 Log PCI config write values MSB first
Writes to config registers of invalid or non-existent PCI devices are logged. They should be logged with most significant byte first.
The values enter the methods in reverse byte order so they need to be byte swapped (except when size is 1) for logging.
The result is that this command in Open Firmware:
`12345678 16800 config-l!`
will log this:
`VCI0 err: write attempt to non-existing VCI device ??:0d.0 @00.l = 12345678`
2022-11-23 19:55:05 +01:00
joevt 072d5ae330 Fix Expansion ROM BAR writes
The bits that can be set are the enable bit (bit 0) plus the bits represented by exp_bar_cfg which is determined by the size of the ROM which is calculated to be a power of 2 and a minimum of 2K.
2022-11-23 12:25:28 +01:00
Maxim Poliakovski 3b0e2c677d dbdma: disable two logging messages. 2022-11-18 18:07:32 +01:00
Maxim Poliakovski 4f05d3dae6 swim3: implement reading the Step register. 2022-11-18 18:06:46 +01:00
Maxim Poliakovski d96351763f swim3: emulate on-chip 1 us timer. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski a0dd1884b3 macio: properly wire floppy DMA. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski a4ff58e9ee New floppy access logic with improved timing. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 447941abe0 machinetnt: fix default RAM allocation. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 9835b96e87 floppyimg: assume raw image by default. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 9f4c248e4c Rework DBDMA logic for bidirectional channels. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 98ccef732f TimerManager: more microseconds related constants. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski dac50fe0fb GrandCentral: fix DMA dispatching. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 76e0fab33a superdrive: implement eject disk command. 2022-11-17 18:03:18 +01:00
Maxim Poliakovski 585c5fd4ca Guess low-level floppy disk format based on image size.
Also add fdd_fmt property for manually specifying disk
format.
2022-11-17 18:03:18 +01:00
dingusdev a58ce8aeb3 Slight tweak to lscbx 2022-11-15 08:01:57 -07:00
dingusdev 8f99510af0 Fixed lscbx 2022-11-15 07:40:37 -07:00
Maxim Poliakovski 13684f7c0b scsicdrom: implement READ_CAPACITY_10 command. 2022-11-14 02:08:05 +01:00
Maxim Poliakovski 5f0358a347 Implement basic SCSI CD-ROM emulation. 2022-11-14 00:55:05 +01:00
dingusdev 647ae456e5 Slight typo squash for lscbx 2022-11-12 20:18:33 -07:00
dingusdev 1b7ff084ab Cleaned lscbx 2022-11-12 20:17:04 -07:00
dingusdev 1ed6e25d1b Removed redundant variable
Slight clean-up for lswi and lswx
2022-11-12 20:16:29 -07:00
Maxim Poliakovski db17e19699 scsi_hd: cosmetic improvements. 2022-11-10 18:22:44 +01:00
Maxim Poliakovski 3de89eaaf7 Silence SCSI logging messages. 2022-11-08 00:33:38 +01:00
Maxim Poliakovski d50152dd1a scsi_hd: clean up TEST UNIT READY command. 2022-11-08 00:32:45 +01:00
Maxim Poliakovski 2f02ea4276 sc53c94: release ATN line after MESSAGE_OUT. 2022-11-08 00:30:19 +01:00
Maxim Poliakovski b2ef809de1 scsi_hd: fix write command. 2022-11-07 22:04:02 +01:00
Maxim Poliakovski c87fc10376 amic: implement SCSI DMA. 2022-11-07 21:56:27 +01:00
Maxim Poliakovski a00b87790b sc3c94: implement real DMA. 2022-11-07 12:34:55 +01:00
Maxim Poliakovski ca5f81417f sc53c94: refactor state machine. 2022-11-07 12:34:42 +01:00
Maxim Poliakovski 40a02cc0f7 scsidevice: refactor states. 2022-11-07 12:24:02 +01:00
Maxim Poliakovski 49331635b2 scsi_hd: determine image file size with stat(). 2022-11-07 12:15:08 +01:00
Maxim Poliakovski 0c4da80c93 sc53c94: small cosmetic fixes. 2022-11-02 23:23:37 +01:00
Maxim Poliakovski 7bc4b8840a scsi_bus: fix device selection bug. 2022-11-02 23:21:46 +01:00
Maxim Poliakovski 5a59b97257 Sc53C94: implement cycle completion commands. 2022-11-02 22:28:43 +01:00
Maxim Poliakovski 5a33fba75e ScsiDevice: command completion states. 2022-11-02 21:28:30 +01:00
Maxim Poliakovski 0c74ebbc45 scsi_bus: support status and message in. 2022-11-02 21:27:18 +01:00
Maxim Poliakovski 2865a611e7 Sc53C94: implement reading the FIFO register. 2022-11-02 21:19:31 +01:00
Maxim Poliakovski f2be286515 scsi_bus: fix asserting control lines. 2022-11-01 02:52:30 +01:00
Maxim Poliakovski 2c3a5c3b8f Sc53C94: reading current transfer count. 2022-11-01 02:12:09 +01:00
Maxim Poliakovski c54c1cdb65 Sc53C94: improve status register. 2022-11-01 02:11:06 +01:00
Maxim Poliakovski 8abefb8f8d machinepdm: properly insert SCSI hard disk image.
Skip SCSI hard disk registration if no disk image was given.
2022-11-01 01:17:50 +01:00
Maxim Poliakovski 6ffe28a8a4 Implement SCSI Pseudo-DMA register on PDM. 2022-11-01 01:17:50 +01:00
Maxim Poliakovski 7ab44886c4 Sc53C94: implement information transfer command. 2022-11-01 01:17:50 +01:00
Maxim Poliakovski fbfae98d6d scsi_bus: packet data transfers. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski c7ceb9d6b9 sc53c94: fix setting internal transfer counter. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski 3f2b77fd59 amic: basic writing to the VIA2 IFR. 2022-10-31 23:21:35 +01:00
Maxim Poliakovski 3050986164 Stop tracking CMakeSettings.json 2022-10-31 01:07:57 +01:00
Maxim Poliakovski c28fd138c2 nvram: fix initialization bug. 2022-10-31 01:01:46 +01:00
dingusdev b480903c7a Slight code clean-up
Prevents crashing
2022-10-30 15:38:09 -07:00
Maxim Poliakovski 46a0e82258 scsi_hd: some fixes and improvements. 2022-10-27 14:19:58 +02:00
Maxim Poliakovski a58c9b1a62 ScsiDevice: fix process_command() signature. 2022-10-27 14:07:20 +02:00
Maxim Poliakovski f3cd5b8b36 sc53c94: fix sending commands to SCSI devices. 2022-10-27 13:49:41 +02:00
dingusdev 2065f3588b Inquiry cmd fixed 2022-10-26 09:30:05 -07:00
dingusdev f792b38ea3 Started SCSI command reading 2022-10-26 09:18:32 -07:00
Maxim Poliakovski 4f6bd16f3a sc53c94: support selection and command transfer. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski c51ea575ca scsi_bus: various fixes and improvements. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski 9efac80271 scsi_hd: fix notify() method. 2022-10-25 03:03:15 +02:00
Maxim Poliakovski eeb576a927 Improve ScsiDevice class. 2022-10-25 02:53:21 +02:00
dingusdev 3af9729e5b Modest refactoring for SCSI HDs 2022-10-23 16:45:58 -07:00
Maxim Poliakovski de082626ab Merge pull request #38 from joevt/master
pcidevice: fix struct offset in the expansion ROM header.
2022-10-23 21:25:08 +02:00
joevt 9f1d613a2d Fix PCI struct offset size
The Pointer to PCI Data Structure is supposed to be two bytes. It is described in the PCI Firmware Specification Revision 3.0, section 5.1.1. PCI Expansion ROM Header Format.
The pointer is two bytes at 0x18. The pointer is supposed to be a multiple of 4 which means there's always at least two bytes of padding after the pointer. Some BIOS firmware images may use the 2 bytes following the pointer for other purposes (plus additional bytes before the PCI Data Structure) so we cannot assume the bytes will be zero.
Some PCI expansion ROMs may include both BIOS and Open Firmware images.
2022-10-23 00:26:32 -07:00
Maxim Poliakovski a085d55d13 machinepdm: attach SCSI HD to the main bus, ID 0. 2022-10-22 23:42:37 +02:00
Maxim Poliakovski c2abc89a3b Fix SCSI HD interface so it can be added to a bus. 2022-10-22 23:41:19 +02:00
dingusdev aa1d23e08b Fixed hard disk support
Compiles, still unfinished
2022-10-22 11:41:52 -07:00
dingusdev ee9573327c Reorganized hard disk code
Not compiling yet.
2022-10-08 16:51:54 -07:00
Maxim Poliakovski f27dd94945 Merge pull request #34 from joevt/master
RTC and TBR fixes
2022-09-24 16:40:37 +02:00
joevt 6f0d3b48ba Fix TBR range
Fixed an issue where TBR doesn't have full 64-bit range. The original calculation was 64 bit and ended with a ÷ 10^9. This means the max for the upper 32 bits is 2^32/10^9 = 4. The solution is to use a multiplication method that supports a 96 bit product. core/mathutils.h contains functions for that. TBR driving frequency is assumed to be less than 1 GHz. Some minor modification is required for future > 1 GHz support.
2022-09-15 21:22:37 -07:00
joevt b665f2cb4e Fix RTC units
Fixed an issue where get-msecs-601 and get-msecs-60x were not returning the same value. RTC was being calculated using timebase frequency instead of nanosecond frequency. 601 uses RTC. 60x uses TBR. On a real Mac, a G3 CPU won't have a RTC and accessing RTC would cause an exception. This is not the case for dingusppc but I don't think that's a problem.
2022-09-15 21:05:08 -07:00
joevt ed424ad544 Fix setting RTC
Fixed an issue where setting RTC upper or lower doesn't adjust the other (since the current time has changed since the last timestamp).
2022-09-15 20:59:56 -07:00
joevt 50dbd5eccd Fix RTC not always updating
Fixed an issue where RTC was not being updated if only the upper 32 bits (seconds) was read.
Also simplified things by always updating the timestamp instead of only when the seconds changes.
2022-09-15 20:54:22 -07:00
joevt 01d7d6bac3 Make accessing RTC or TBR not affect the other
Fixed an issue where the following would cause inconsistent results (tb in the left column would sometimes decrement instead of always incrementing):
2 0 do 2 0 do cr tb@ 8 u.r ." ." 8 u.r loop 2 0 do cr 12 spaces rtc@ 8 u.r ." ." 8 u.r loop 2 0 do cr tb@ 8 u.r ." ." 8 u.r space rtc@ 8 u.r ." ." 8 u.r loop loop

RTC and TBR could not be used simultaneously because they are both incremented by an amount based on the last time stamp but that time stamp can be changed by accessing either RTC or TBR. The solution is to have a different time stamp for each.
2022-09-15 20:21:54 -07:00
joevt ce925f5e56 Fix RTC upper
Fixed a typo that caused rtc@ to always return 0 for the upper 32 bits (represents seconds).
The problem could cause the following to hang on Power Mac 7500:
cr 2000 0 do get-msecs u. 1 ms loop
2022-09-15 19:34:46 -07:00
Maxim Poliakovski a7403195ba Merge pull request #33 from dingusdev/revert-32-master
Revert "PCI fixes"
2022-09-03 01:27:56 +02:00
dingusdev a61dd5701a Initial prototyping for hard disks 2022-09-01 22:10:52 -07:00
394 changed files with 57753 additions and 64842 deletions

No files matched your search

+268 -18
View File
@@ -1,43 +1,293 @@
name: CMake
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
build-linux:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: install_dependencies
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/linux
key: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
- name: init_submodules
run: git submodule update --init --recursive
sudo apt-get install -y -qq libsdl2-dev ninja-build ccache
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/linux
CCACHE_BASEDIR: ${{ github.workspace }}
run: cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-macos:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- runner: macos-latest
arch: arm64
brew_prefix: /opt/homebrew
- runner: macos-15-intel
arch: x86_64
brew_prefix: /usr/local
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
key: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew install sdl2 ccache ninja
- name: Configure CMake
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
export PATH="${{ matrix.brew_prefix }}/opt/ccache/libexec:$PATH"
cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-macOS-${{ matrix.arch }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-windows-msys2:
runs-on: windows-latest
timeout-minutes: 45
env:
MSYSTEM: MINGW64
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/msys
key: windows-msys-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: windows-msys-ccache-${{ env.BUILD_TYPE }}-
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
cmake
ninja
git
mingw-w64-x86_64-cmake
mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-ninja
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-ccache
- name: Build
shell: msys2 {0}
run: |
echo "Running build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
export CHERE_INVOKING=yes
export MSYS=winsymlinks:native
export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
export CCACHE_DIR="${GITHUB_WORKSPACE}/.ccache/msys"
export CCACHE_DEPEND=1
ccache --zero-stats || true
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
ccache --show-stats || true
echo "Finished build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Test
shell: msys2 {0}
run: |
cd build
ctest --output-on-failure --parallel
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSYS
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-windows-vsbuild:
runs-on: windows-latest
timeout-minutes: 45
env:
VCPKG_FEATURE_FLAGS: binarycaching
strategy:
fail-fast: false
matrix:
include:
- name: clang
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: CLANG
- name: msvc
generator: Ninja
cmake_args: ""
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSVC
- name: msbuild
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSBUILD
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
# Configures MSVC/Clang environment natively for all subsequent steps
- name: Setup MSVC Developer Command Prompt
uses: TheMrMilchmann/setup-msvc-dev@v4
with:
arch: x64
- name: Setup msbuild
uses: microsoft/setup-msbuild@v3
- name: Install vcpkg packages
shell: cmd
run: '"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows'
- name: Install Ninja
if: matrix.generator == 'Ninja'
run: choco install ninja -y
- name: Cache ccache
if: matrix.generator == 'Ninja'
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
key: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install ccache
if: matrix.generator == 'Ninja'
run: choco install ccache -y
- name: Configure & Build
shell: cmd
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
mkdir build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cd build
cmake -S .. -B . -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON ${{ matrix.ccache_args }} -DCMAKE_TOOLCHAIN_FILE=%VCPKG_INSTALLATION_ROOT%\scripts\buildsystems\vcpkg.cmake
cmake --build . --config ${{ env.BUILD_TYPE }} --parallel
cd ..
- name: ccache stats
if: matrix.generator == 'Ninja'
shell: cmd
run: |
ccache --show-stats
if %errorlevel% neq 0 echo ccache stats unavailable
- name: Test
working-directory: ${{github.workspace}}/build
shell: cmd
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.name }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-${{ matrix.upload_suffix }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
+26
View File
@@ -1,14 +1,34 @@
# Ignore binary files
out/
vcpkg/
*.bin
# Ignore compiled object files
.vs/
.vscode/
*.o
*.out
*.obj
*.d
# Ignore CMake system files
CMakeFiles
cmake_install.cmake
# Ignore Visual Studio configuration files
CMakeSettings.json
*.vcxproj
*.vcxproj.filters
# Ignore Visual Studio auto-save recovery folder
enc_temp_folder/
# Ignore CodeLite configuration files
*.workspace
*.workspace.*
compile_commands.json
*.session
*.tags
# Ignore generated executables
dingusppc
@@ -17,8 +37,14 @@ dingusppc.exe
# Ignore system files
.DS_Store
Thumb.db
ehthumbs.db
# IDE ignores
build
build*/
build-*
*.dir
*.user
DerivedData
*.xcodeproj/project.xcworkspace
*.xcodeproj/xcuserdata
+188 -68
View File
@@ -1,21 +1,52 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.14)
project(dingusppc)
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(PlatformGlob)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
if (NOT WIN32)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
else()
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/SDL2/include/")
if (UNIX AND NOT APPLE)
find_package (Threads)
if (NOT WIN32 AND NOT EMSCRIPTEN)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
if (UNIX AND NOT APPLE)
find_package (Threads)
endif()
elseif (WIN32) # Windows build relies on vcpkg
# pick up system wide vcpkg if exists
if (DEFINED ENV{VCPKG_ROOT} AND EXISTS $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
message(STATUS "Using system vcpkg at $ENV{VCPKG_ROOT}")
set(vcpkg_toolchain_file $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
# check Github Actions vcpkg installation
elseif (DEFINED ENV{VCPKG_INSTALLATION_ROOT} AND EXISTS $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
message(STATUS "Using system vcpkg at $ENV{VCPKG_INSTALLATION_ROOT}")
set(vcpkg_toolchain_file $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
# otherwise, fetch vcpkg from Github
else()
message(STATUS "Fetching latest vcpkg from Github...")
include(FetchContent)
FetchContent_Declare(vcpkg GIT_REPOSITORY https://github.com/microsoft/vcpkg.git)
FetchContent_MakeAvailable(vcpkg)
set(vcpkg_toolchain_file ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake)
endif()
set(CMAKE_TOOLCHAIN_FILE ${vcpkg_toolchain_file})
find_package(SDL2 CONFIG REQUIRED)
add_compile_definitions(SDL_MAIN_HANDLED)
endif()
if (EMSCRIPTEN)
message(STATUS "Targeting Emscripten")
# loguru tries to include excinfo.h, which is not available under Emscripten.
add_compile_definitions(LOGURU_STACKTRACES=0)
endif()
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
@@ -24,9 +55,6 @@ option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
option(DPPC_68K_DEBUGGER "Enable 68k debugging" OFF)
if (DPPC_68K_DEBUGGER)
# Build capstone as static library.
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
# Turn off anything unnecessary.
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "")
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "")
@@ -56,6 +84,19 @@ if (DPPC_68K_DEBUGGER)
add_subdirectory(thirdparty/capstone EXCLUDE_FROM_ALL)
endif()
option (DPPC_SUPPORT_PPC_LE "Enable PPC little endian mode" OFF)
option (DPPC_SUPPORT_MEM_LE "Enable memory controller little endian mode" OFF)
if (DPPC_SUPPORT_PPC_LE)
ADD_DEFINITIONS(-DSUPPORTS_PPC_LITTLE_ENDIAN_MODE=1)
else()
ADD_DEFINITIONS(-DSUPPORTS_PPC_LITTLE_ENDIAN_MODE=0)
endif()
if (DPPC_SUPPORT_MEM_LE)
ADD_DEFINITIONS(-DSUPPORTS_MEMORY_CTRL_ENDIAN_MODE=1)
else()
ADD_DEFINITIONS(-DSUPPORTS_MEMORY_CTRL_ENDIAN_MODE=0)
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/core")
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
@@ -64,18 +105,27 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
#set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "Build libsoundio example programs")
#set(BUILD_TESTS OFF CACHE BOOL "Build libsoundio tests")
#set(BUILD_DYNAMIC_LIBS ON CACHE BOOL "Build libsoundio dynamic libs")
#set(BUILD_STATIC_LIBS ON CACHE BOOL "Build libsoundio static libs")
if (NOT EMSCRIPTEN)
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
#add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/libsoundio")
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
# Warn if no audio backends were detected on Linux/Unix systems
if (UNIX AND NOT APPLE)
if (NOT USE_PULSE AND NOT USE_ALSA AND NOT USE_JACK AND
NOT USE_SNDIO AND NOT USE_OSS AND NOT USE_SUN)
message(WARNING
"No Cubeb audio backends detected on Linux/Unix system!\n"
"Audio will NOT work at runtime.\n"
"Please install development headers for at least one of:\n"
" - PulseAudio (libpulse-dev / pulseaudio-libs-devel)\n"
" - ALSA (libasound2-dev / alsa-lib-devel)\n"
" - JACK (libjack-dev / jack-audio-connection-kit-devel)\n"
" - sndio (libsndio-dev)")
endif()
endif()
endif()
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
@@ -87,20 +137,30 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/utils"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/CLI11/"
# ${SDL2_INCLUDE_DIRS})
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
# "${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
# ${LIBSOUNDIO_HEADERS})
"${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/*.c"
"${PROJECT_SOURCE_DIR}/*.hpp"
"${PROJECT_SOURCE_DIR}/*.h")
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/*.c"
"${PROJECT_SOURCE_DIR}/*.hpp"
"${PROJECT_SOURCE_DIR}/*.h")
#get_directory_property(LIBSOUNDIO_LIBS DIRECTORY thirdparty/libsoundio DEFINITION LIBSOUNDIO_LIBS)
if (APPLE)
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
list(APPEND SOURCES ${APPLE_SOURCES})
endif()
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
if (APPLE)
add_executable(dingusppc MACOSX_BUNDLE ${SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
else()
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
@@ -108,20 +168,78 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
if (WIN32)
target_link_libraries(dingusppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
ws2_32
cubeb)
else()
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
endif()
if (APPLE)
# Identify if we are targeting iOS or macOS
if (IOS)
set(BUNDLE_ID "com.dingusdev.dingusppc-ios")
message(STATUS "Configuring for iOS Bundle")
else()
set(BUNDLE_ID "com.dingusdev.dingusppc")
message(STATUS "Configuring for macOS Bundle")
endif()
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "${BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "DingusPPC"
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4c"
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4c"
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
# Placeholder for the icon file:
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
)
if (NOT IOS)
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/cmake/DingusPPCInfo.plist.in"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${BUNDLE_ID}"
)
endif()
find_library(COCOA_LIBRARY Cocoa)
find_library(IOKIT_LIBRARY IOKit)
find_library(COREAUDIO_LIBRARY CoreAudio)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
target_link_libraries(dingusppc PRIVATE
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREAUDIO_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
)
if (IOS)
target_link_libraries(dingusppc PRIVATE "-framework Foundation" "-framework UIKit")
endif()
endif()
if (WIN32)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(dingusppc PRIVATE SDL_MAIN_HANDLED)
elseif (EMSCRIPTEN)
target_link_libraries(dingusppc PRIVATE
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
"-gsource-map"
# 256 MB max for emulated Mac RAM, plus 32 MB of emulator overhead
"-s INITIAL_MEMORY=301989888"
"-s MODULARIZE"
"-s EXPORT_ES6"
"-s EXPORT_NAME=emulator"
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
else()
target_link_libraries(dingusppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
if (APPLE)
find_library(COCOA_LIBRARY Cocoa)
target_link_libraries(dingusppc PRIVATE ${COCOA_LIBRARY})
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(dingusppc capstone-static)
target_link_libraries(dingusppc PRIVATE capstone)
endif()
if (DPPC_BUILD_PPC_TESTS)
@@ -134,37 +252,39 @@ if (DPPC_BUILD_PPC_TESTS)
$<TARGET_OBJECTS:loguru>)
if (WIN32)
target_link_libraries(testppc
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
cubeb)
target_link_libraries(testppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(testppc PRIVATE SDL_MAIN_HANDLED)
else()
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(testppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(testppc capstone-static)
target_link_libraries(testppc PRIVATE capstone)
endif()
endif()
if (DPPC_BUILD_BENCHMARKS)
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (DPPC_68K_DEBUGGER)
target_link_libraries(bench1 capstone-static)
endif()
file(GLOB BENCH_CPU_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h")
foreach(BENCHMARK bench1 bench2)
add_executable(${BENCHMARK} "benchmark/${BENCHMARK}.cpp" ${BENCH_CPU_SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_compile_definitions(${BENCHMARK} PRIVATE PPC_BENCHMARKS)
target_link_libraries(${BENCHMARK} PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (WIN32)
target_compile_definitions(${BENCHMARK} PRIVATE SDL_MAIN_HANDLED)
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(${BENCHMARK} PRIVATE capstone)
endif()
endforeach()
endif()
if (DPPC_BUILD_PPC_TESTS)
@@ -174,7 +294,7 @@ if (DPPC_BUILD_PPC_TESTS)
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
"$<TARGET_FILE_DIR:$<TARGET_PROPERTY:NAME>>")
endif()
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
-28
View File
@@ -1,28 +0,0 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "clang_cl_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64" ],
"variables": []
}
]
}
+6
View File
@@ -5,6 +5,12 @@ General
* Commits to the repo should be done by portions; that is, by individual functionalities of the program.
* Don't use any disrespectful language.
AI Usage
=======
* Do not use artificial intelligence to make contributions. This is due to authorship issues and licensing issues regarding AI usage.
* Do not use artificial intelligence to write up issues or pull requests.
Code
=======
+67
View File
@@ -0,0 +1,67 @@
# DingusPPC
## Developers
- divingkatae
- joevt
- kkaisershot
- maximumspatium
- mihaip
## ATI Rage Support (WIP)
- Cacodemon345
## NT4/PPC fork
- Wack0
## DevOps
- alicela1n
- calmsacibis995
- claunia
- dressupgeekout
- dyharlan
- erichelgeson
- jarz
- kth5
- leap0x7b
- lefp
- mathstuf
- mrpapersonic
- probonopd
- Randrianasulu
- roytam1
- sdkmap
- seanm
- Waqar144
- webspacecreations
## Testing
- LagLifeYT
## 3rd Party Libraries
- [Capstone](https://github.com/capstone-engine/capstone)
- [CLI11](https://github.com/CLIUtils/CLI11)
- [Loguru](https://github.com/emilk/loguru)
- [SDL 2](https://github.com/libsdl-org/SDL)
## Thanks
- 68kmla
- AppleFritter
- Archive.org
- Bitsavers
- Blitter.net
- Emaculation
- GitHub
- pagetable.com
- 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 and source code of 68k and PowerPC Macs
+61 -25
View File
@@ -1,30 +1,38 @@
# DingusPPC
Written by divingkatae and maximumspatium
Written by The DingusPPC Development Team
(who are Divingkatae, maximumspatium, joevt, mihaip, kkaisershot, Cacodemon345, Wack0, et. al. Check CREDITS.md for more info)
Be warned the program is highly unfinished and could use a lot of testing. Any feedback is welcome.
## Philosophy of Use
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs
accurately (except for QEMU).
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the PowerMac G3 Beige.
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but
also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old
World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
## Implemented Features
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World
PowerPC Macs, and the Pippin.
This emulator has a debugging environment, complete with a disassembler.
## How to Use
This program currently uses the command prompt to work.
There are a few command line arguments one must enter when starting the program.
There are a few command line arguments one can enter when starting the program.
```
-r, --realtime
-r, --run
```
Run the emulator in runtime.
Run the emulator. Currently only goes to an interpreter.
```
-d, --debugger
@@ -36,54 +44,87 @@ Enter the interactive debugger.
-b, --bootrom TEXT:FILE
```
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
Specifies the Boot ROM path. It otherwise looks for bootrom.bin.
```
-m, --machine TEXT
```
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
Specify machine ID. Otherwise, the emulator will attempt to determine machine ID from the boot rom otherwise.
As of now, only the Power Macintosh G3 Beige is implemented.
As of now, the most complete machines are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3 Beige.
To go into to the debugger regardless of how you started the emulator, press Control and C on the terminal window.
## How to Compile
You need to install development tools first.
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
At minimum, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
Clone the repository using the appropriate command:
```
git clone https://github.com/dingusdev/dingusppc
```
If this is from a mirror, replace the argument with the source you want to use instead.
You will also have to recursive clone or run
```
git submodule update --init --recursive
```
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
This is because the CubeB, Capstone, and SDL2 modules are not included by default.
For SDL2, Linux users may also have to run:
```
sudo apt install libsdl2-dev
```
macOS users can use Homebrew or MacPorts to install SDL2.
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
For Raspbian, you may also need the following command:
```
sudo apt install doxygen graphviz
```
To build the project in a Unix-like environment, create a build folder, change the directory to the build folder,
and use `cmake` to create the `Makefile` files in that build folder.
Use `make` to do the building. You don't need to execute `cmake` again unless you add/remove/change options or
source files.
For example, to build the project in a Unix-like environment, you will need to run
the following commands in the OS terminal:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make dingusppc
make
```
You may specify another build type using the variable CMAKE_BUILD_TYPE.
Future versions may drop SDL 2 as a requirement.
You may specify another build type using the variable `CMAKE_BUILD_TYPE`.
Each build type should have its own build folder.
For Raspbian, you may also need the following command:
```
sudo apt install doxygen graphviz
mkdir build-debug
cd build-debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
```
## Testing
DingusPPC includes a test suite for verifying the correctness of its PowerPC CPU
emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -DCMAKE_BUILD_TYPE=Release -DDPPC_BUILD_PPC_TESTS=True ..
make testppc
```
@@ -94,8 +135,3 @@ make testppc
- 2 GB of RAM
- 2 GB of Hard Disk Space
- Graphics Card with a minimum resolution of 800*600
## Compiler Requirements
- GCC 4.7 or newer (i.e. CodeBlocks 13.12 or newer)
- Visual Studio 2013 or newer
-1
View File
@@ -1 +0,0 @@
theme: jekyll-theme-minimal
+130 -35
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,8 +23,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <chrono>
#include "cpu/ppc/ppcemu.h"
#include "cpu/ppc/ppcmmu.h"
#include "devices/mpc106.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_off(po_benchmark_exception);
}
#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,57 +63,142 @@ 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;
}
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
constexpr uint64_t tbr_freq = 16705000;
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++) {
mem_write_dword(i*4, cs_code[i]);
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
mmu_write_vmem<uint32_t>(0, i * 4, cs_code[i]);
}
srand(0xCAFEBABE);
for (i = 0; i < 32768; i++) {
mem_write_byte(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>(0, 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);
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
#ifdef _MSC_VER
#pragma message("PPC endian mode enabled")
#else
#warning PPC endian mode enabled
#endif
LOG_F(INFO, "PPC endian mode enabled");
#else
#ifdef _MSC_VER
#pragma message("PPC endian mode disabled")
#else
#warning PPC endian mode disabled
#endif
LOG_F(INFO, "PPC endian mode disabled");
#endif
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
#ifdef _MSC_VER
#pragma message("Memory endian mode enabled")
#else
#warning Memory endian mode enabled
#endif
LOG_F(INFO, "Memory endian mode enabled");
#else
#ifdef _MSC_VER
#pragma message("Memory endian mode disabled")
#else
#warning Memory endian mode disabled
#endif
LOG_F(INFO, "Memory endian mode disabled");
#endif
#ifdef LOG_INSTRUCTIONS
#ifdef _MSC_VER
#pragma message("Log instructions enabled")
#else
#warning Log instructions enabled
#endif
LOG_F(INFO, "Log instructions enabled");
#else
#ifdef _MSC_VER
#pragma message("Log instructions disabled")
#else
#warning Log instructions disabled
#endif
LOG_F(INFO, "Log instructions disabled");
#endif
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);
+119
View File
@@ -0,0 +1,119 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Replay floating-point instructions and input registers captured while BeOS
// PR1 GLTeapot renders. This measures the real opcode dispatcher and handlers,
// including FPSCR maintenance, without guest boot, display, or timer overhead.
#include <cpu/ppc/ppcemu.h>
#include <thirdparty/loguru/loguru.hpp>
#include <algorithm>
#include <cfenv>
#include <chrono>
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <vector>
#include "bench2_data.h"
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_off(po_benchmark_exception);
}
#endif
static void replay_sample(const FpuSample& sample) {
if ((ppc_state.fpscr ^ sample.fpscr) & FPSCR::RN_MASK)
set_host_rounding_mode(sample.fpscr & FPSCR::RN_MASK);
ppc_state.fpscr = sample.fpscr;
ppc_state.cr = sample.cr;
ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r = sample.d;
ppc_state.fpr[(sample.opcode >> 16) & 31].int64_r = sample.a;
ppc_state.fpr[(sample.opcode >> 11) & 31].int64_r = sample.b;
ppc_state.fpr[(sample.opcode >> 6) & 31].int64_r = sample.c;
ppc_main_opcode(ppc_opcode_grabber, sample.opcode);
}
static uint64_t check_replay() {
uint64_t hash = 1469598103934665603ULL;
auto mix = [&hash](uint64_t value) { hash = (hash ^ value) * 1099511628211ULL; };
std::feclearexcept(FE_ALL_EXCEPT);
for (const auto& sample : fpu_samples) {
replay_sample(sample);
mix(ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r);
mix(ppc_state.fpscr);
mix(ppc_state.cr);
}
return hash;
}
int main(int argc, char** argv) {
if (argc > 2 || (argc == 2 && std::strcmp(argv[1], "--check"))) {
fprintf(stderr, "Usage: %s [--check]\n", argv[0]);
return 2;
}
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
is_601 = false;
initialize_ppc_opcode_table();
ppc_msr_did_change(ppc_state.msr, MSR::ME | MSR::IP | MSR::FP, false);
set_host_rounding_mode(0);
power_on = true;
const uint64_t expected = check_replay();
constexpr size_t sample_count = sizeof(fpu_samples) / sizeof(fpu_samples[0]);
printf("GLTeapot FPU replay: %zu samples, checksum %016" PRIx64 "\n", sample_count, expected);
if (!power_on)
return 1;
if (argc == 2 && !std::strcmp(argv[1], "--check"))
return 0;
constexpr unsigned passes = 10000;
constexpr unsigned trials = 9;
// Warm the dispatcher, handlers and captured input data.
for (unsigned pass = 0; pass < 100; pass++)
for (const auto& sample : fpu_samples)
replay_sample(sample);
std::vector<double> times;
for (unsigned trial = 0; trial < trials; trial++) {
std::feclearexcept(FE_ALL_EXCEPT);
auto start = std::chrono::steady_clock::now();
for (unsigned pass = 0; pass < passes; pass++)
for (const auto& sample : fpu_samples)
replay_sample(sample);
auto end = std::chrono::steady_clock::now();
if (!power_on || check_replay() != expected) {
fprintf(stderr, "FPU replay changed its result during timing\n");
return 1;
}
double ns = std::chrono::duration<double, std::nano>(end - start).count() /
(uint64_t(passes) * sample_count);
times.push_back(ns);
printf("Trial %u: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
trial + 1, ns, 1000.0 / ns);
}
std::sort(times.begin(), times.end());
double median = times[times.size() / 2];
printf("Median: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
median, 1000.0 / median);
return 0;
}
File diff suppressed because it is too large. Load diff
+70
View File
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>CD-ROM image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.iso-image</string>
<string>com.roxio.disk-image-toast</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>Toast disk image</string>
<key>UTTypeIdentifier</key>
<string>com.roxio.disk-image-toast</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>toast</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
+21
View File
@@ -0,0 +1,21 @@
# Detect platform suffix
if (EMSCRIPTEN)
set(PLATFORM_SUFFIX "_js$")
else()
set(PLATFORM_SUFFIX "_sdl|_cubeb$")
endif()
# Function to perform a platform-specific glob
function(platform_glob RESULT_VAR)
set(PLATFORM_SOURCES)
foreach(GLOB_PATTERN ${ARGN})
file(GLOB GLOB_RESULT ${GLOB_PATTERN})
foreach(FILE_PATH ${GLOB_RESULT})
get_filename_component(BASE_NAME ${FILE_PATH} NAME_WE)
if("${BASE_NAME}" MATCHES ${PLATFORM_SUFFIX} OR NOT "${BASE_NAME}" MATCHES "_js$|_sdl|_cubeb$")
list(APPEND PLATFORM_SOURCES ${FILE_PATH})
endif()
endforeach()
endforeach()
set(${RESULT_VAR} ${PLATFORM_SOURCES} PARENT_SCOPE)
endfunction()
+6 -2
View File
@@ -2,7 +2,11 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
)
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(core OBJECT ${SOURCES})
target_link_libraries(core)
if (EMSCRIPTEN)
target_link_libraries(core PRIVATE)
else()
target_link_libraries(core PRIVATE SDL2::SDL2)
endif()
+100
View File
@@ -0,0 +1,100 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Non-standard low-level bitwise operations. */
#ifndef BIT_OPS_H
#define BIT_OPS_H
#include <cinttypes>
#if defined(__GNUG__) && !defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) // GCC, mybe ICC but not Clang
# include <x86intrin.h>
# define ROTL_32(x, n) (_rotl((x), (n)))
# define ROTR_32(x, n) (_rotr((x), (n)))
#elif defined(_MSC_VER) // MSVC
# include <intrin.h>
# define ROTL_32(x, n) (_rotl((x), (n)))
# define ROTR_32(x, n) (_rotr((x), (n)))
#else
// cyclic rotation idioms that modern compilers will
// recognize and generate very compact code for
// involving specific machine instructions
inline unsigned ROTL_32(unsigned x, unsigned n) {
n &= 0x1F;
if (n)
return (x << n) | (x >> (32 - n));
return x;
}
inline unsigned ROTR_32(unsigned x, unsigned n) {
n &= 0x1F;
if (n)
return (x >> n) | (x << (32 - n));
return x;
}
#endif
template <class T>
inline T extract_bits(T val, int pos, int len) {
return (val >> pos) & ((len == sizeof(T) * 8) ? (T)-1 : ((T)1 << len) - 1);
}
template <class T>
inline void insert_bits(T &old_val, T new_val, int pos, int len) {
T mask = ((len == sizeof(T) * 8) ? (T)-1 : ((T)1 << len) - 1) << pos;
old_val = (old_val & ~mask) | ((new_val << pos) & mask);
}
/* Return true if the specified bit is different in the given numbers. */
static inline bool bit_changed(uint64_t old_val, uint64_t new_val, int bit_num) {
return (old_val ^ new_val) & (1ULL << bit_num);
}
static inline bool bit_set(const uint64_t val, const int bit_num) {
return !!(val & (1ULL << bit_num));
}
template <class T>
inline void clear_bit(T &val, const int bit_num) {
val &= ~((T)1 << bit_num);
}
template <class T>
inline void set_bit(T &val, const int bit_num) {
val |= ((T)1 << bit_num);
}
static inline uint32_t extract_with_wrap_around(uint32_t val, int pos, int size) {
return (uint32_t)((((uint64_t)val << 32) | val) >> ((8 - (pos & 3) - size) << 3)) &
((1LL << (size << 3)) - 1);
}
#endif // BIT_OPS_H
+90
View File
@@ -0,0 +1,90 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Poor man's signals & slots mechanism implementation. */
// Inspired by http://schneegans.github.io/tutorials/2015/09/20/signal-slot
#ifndef CORE_SIGNAL_H
#define CORE_SIGNAL_H
#include <functional>
#include <map>
template <typename... Args>
class CoreSignal {
public:
CoreSignal() = default;
~CoreSignal() = default;
// Connects a std::function type slot to the signal.
// The return value can be used to disconnect the slot.
int connect_func(std::function<void(Args...)> const& slot) const {
_slots.insert(std::make_pair(++_current_id, slot));
return _current_id;
}
// Connects a class method type slot to the signal.
// The return value can be used to disconnect the slot.
template <typename T>
int connect_method(T *inst, void (T::*func)(Args...)) {
return connect_func([=](Args... args) {
(inst->*func)(args...);
});
}
// Calls all connected slots.
void emit(Args... args) const {
if (!_is_enabled) {
return;
}
for (auto const& it : _slots) {
it.second(args...);
}
}
void disconnect(int id) {
_slots.erase(id);
}
void disconnect_all() {
_slots.clear();
}
void disable() {
_is_enabled = false;
}
void enable() {
_is_enabled = true;
}
bool is_enabled() const {
return _is_enabled;
}
private:
mutable std::map<int, std::function<void(Args...)>> _slots;
mutable unsigned int _current_id { 0 };
mutable bool _is_enabled { true };
};
#endif // CORE_SIGNAL_H
+103
View File
@@ -0,0 +1,103 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Macros for performing byte swapping for quick endian conversion.
It will try to use the fast built-in machine instructions first
and fall back to the slow conversion if none were found.
*/
#ifndef ENDIAN_SWAP_H
#define ENDIAN_SWAP_H
#ifdef __GNUG__ /* GCC, ICC and Clang */
# define BYTESWAP_16(x) (__builtin_bswap16 (x))
# define BYTESWAP_32(x) (__builtin_bswap32 (x))
# define BYTESWAP_64(x) (__builtin_bswap64 (x))
#elif _MSC_VER /* MSVC */
# include <stdlib.h>
# define BYTESWAP_16(x) (_byteswap_ushort (x))
# define BYTESWAP_32(x) (_byteswap_ulong (x))
# define BYTESWAP_64(x) (_byteswap_uint64 (x))
#elif __has_include(<byteswap.h>) /* Many unixes */
# include <byteswap.h>
# define BYTESWAP_16(x) (bswap_16(x))
# define BYTESWAP_32(x) (bswap_32(x))
# define BYTESWAP_64(x) (bswap_64(x))
// TODO: C++23 has std::byteswap
#else
// #warning is not standard until C++23:
//
// # warning "Unknown byte swapping built-ins (do it the slow way)!"
# include <cstdint>
// Most optimizing compilers will translate these functions directly
// into their native instructions (e.g. bswap on x86).
inline std::uint16_t byteswap_16_impl(std::uint16_t x)
{
return (x >> 8) | (x << 8);
}
inline std::uint32_t byteswap_32_impl(std::uint32_t x)
{
return (
((x & UINT32_C(0x000000FF)) << 24)
| ((x & UINT32_C(0x0000FF00)) << 8)
| ((x & UINT32_C(0x00FF0000)) >> 8)
| ((x & UINT32_C(0xFF000000)) >> 24)
);
}
inline std::uint64_t byteswap_64_impl(std::uint64_t x)
{
return (
((x & UINT64_C(0x00000000000000FF)) << 56)
| ((x & UINT64_C(0x000000000000FF00)) << 40)
| ((x & UINT64_C(0x0000000000FF0000)) << 24)
| ((x & UINT64_C(0x00000000FF000000)) << 8)
| ((x & UINT64_C(0x000000FF00000000)) >> 8)
| ((x & UINT64_C(0x0000FF0000000000)) >> 24)
| ((x & UINT64_C(0x00FF000000000000)) >> 40)
| ((x & UINT64_C(0xFF00000000000000)) >> 56)
);
}
# define BYTESWAP_16(x) (byteswap_16_impl(x))
# define BYTESWAP_32(x) (byteswap_32_impl(x))
# define BYTESWAP_64(x) (byteswap_64_impl(x))
#endif
#define BYTESWAP_SIZED(val, size) \
((size) == 2 ? BYTESWAP_16(val) : (size) == 4 ? BYTESWAP_32(val) : (val))
#endif /* ENDIAN_SWAP_H */
+217
View File
@@ -0,0 +1,217 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef EVENT_MANAGER_H
#define EVENT_MANAGER_H
#include <core/coresignal.h>
#include <cinttypes>
#include <string>
class WindowEvent {
public:
WindowEvent() = default;
~WindowEvent() = default;
uint16_t sub_type;
uint32_t window_id;
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's.
// We add our own custom events after that.
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
};
enum : uint32_t {
MOUSE_EVENT_MOTION = 1 << 0,
MOUSE_EVENT_BUTTON = 1 << 1,
KEYBOARD_EVENT_DOWN = 1 << 0,
KEYBOARD_EVENT_UP = 1 << 1,
GAMEPAD_EVENT_DOWN = 1 << 0,
GAMEPAD_EVENT_UP = 1 << 1,
};
class MouseEvent {
public:
MouseEvent() = default;
~MouseEvent() = default;
uint32_t flags;
int32_t xrel;
int32_t yrel;
uint32_t xabs;
uint32_t yabs;
uint8_t buttons_state;
};
class KeyboardEvent {
public:
KeyboardEvent() = default;
~KeyboardEvent() = default;
uint32_t flags;
uint32_t key;
};
enum KeyboardLocale : uint32_t {
Eng_USA = 0,
Eng_GBR = 1,
Fra_FRA = 10,
Deu_DEU = 20,
Ita_ITA = 30,
Spa_ESP = 40,
Jpn_JPN = 80,
};
/* AppleJack bits 3-7 are supported but unused */
enum GamepadButton : uint8_t {
Red = 14,
Green = 15,
Yellow = 9,
Blue = 8,
FrontLeft = 0,
FrontMiddle = 1,
FrontRight = 2,
LeftTrigger = 17,
RightTrigger = 16,
Up = 10,
Down = 13,
Left = 11,
Right = 12,
};
class GamepadEvent {
public:
GamepadEvent() = default;
~GamepadEvent() = default;
uint32_t gamepad_id;
uint32_t flags;
uint8_t button;
};
enum class CdromInsertionResult {
SUCCESS,
NO_DRIVE,
MEDIA_PRESENT,
IMAGE_OPEN_FAILED,
};
class CdromImageEvent {
public:
std::string image_path;
CdromInsertionResult result = CdromInsertionResult::NO_DRIVE;
bool handled = false;
};
class EventManager {
public:
static EventManager* get_instance() {
if (!event_manager) {
event_manager = new EventManager();
}
return event_manager;
}
void poll_events();
void set_keyboard_locale(uint32_t keyboard_id);
void post_keyboard_state_events();
void post_cdrom_event(CdromImageEvent& event) {
_cdrom_signal.emit(event);
}
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
_window_signal.connect_method(inst, func);
}
template <typename T>
void add_mouse_handler(T *inst, void (T::*func)(const MouseEvent&)) {
_mouse_signal.connect_method(inst, func);
}
template <typename T>
void add_keyboard_handler(T* inst, void (T::*func)(const KeyboardEvent&)) {
_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_cdrom_handler(T* inst, void (T::*func)(CdromImageEvent&)) {
_cdrom_signal.connect_method(inst, func);
}
template <typename T>
void add_post_handler(T *inst, void (T::*func)()) {
_post_signal.connect_method(inst, func);
}
void disconnect_handlers() {
_window_signal.disconnect_all();
_mouse_signal.disconnect_all();
_keyboard_signal.disconnect_all();
_gamepad_signal.disconnect_all();
_cdrom_signal.disconnect_all();
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
_gamepad_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {} // private constructor to implement a singleton
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
CoreSignal<const KeyboardEvent&> _keyboard_signal;
CoreSignal<const GamepadEvent&> _gamepad_signal;
CoreSignal<CdromImageEvent&> _cdrom_signal;
CoreSignal<> _post_signal;
uint64_t events_captured = 0;
uint64_t unhandled_events = 0;
uint64_t key_downs = 0;
uint64_t key_ups = 0;
uint8_t buttons_state = 0;
uint32_t kbd_locale = 0;
};
#endif // EVENT_MANAGER_H
+625
View File
@@ -0,0 +1,625 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/hostevents.h>
#include <core/coresignal.h>
#include <cpu/ppc/ppcemu.h>
#include <devices/common/adb/adbkeyboard.h>
#include <loguru.hpp>
#include <SDL.h>
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
bool g_swap_command_option = false;
static AdbKey swap_command_option(AdbKey key)
{
if (!g_swap_command_option)
return key;
switch (key) {
case AdbKey_Option: return AdbKey_Command;
case AdbKey_RightOption: return AdbKey_Command;
case AdbKey_Command: return AdbKey_Option;
default: return key;
}
}
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
this->kbd_locale = keyboard_id;
}
void EventManager::poll_events() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
events_captured++;
switch (event.type) {
case SDL_QUIT:
power_off(po_quit);
break;
case SDL_WINDOWEVENT: {
WindowEvent we{};
we.sub_type = event.window.event;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
break;
case SDL_KEYDOWN:
case SDL_KEYUP: {
if (event.key.repeat)
break;
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
if (event.key.keysym.sym == SDLK_g && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we;
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-Shift-F: fullscreen reverse
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LSHIFT)) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-+: bigger
if (event.key.keysym.sym == SDLK_EQUALS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control--: smaller
if (event.key.keysym.sym == SDLK_MINUS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-Alt-Shift-+: speed up icnt_factor
if (event.key.keysym.sym == SDLK_EQUALS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
int icnt_counter_val = increment_icnt_factor();
LOG_F(INFO, "Incremented icnt_factor: %d", icnt_counter_val);
}
return;
}
// Control-Alt-Shift--: slow down icnt_factor
if (event.key.keysym.sym == SDLK_MINUS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
int icnt_counter_val = decrement_icnt_factor();
LOG_F(INFO, "Decremented icnt_factor: %d", icnt_counter_val);
}
return;
}
// Control-Alt-R: g_realtime toggle
if (event.key.keysym.sym == SDLK_r && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT)) {
if (event.type == SDL_KEYUP) {
bool g_realtime_status = toggle_g_realtime();
LOG_F(INFO, "g_realtime: %s", g_realtime_status ? "enabled" : "disabled");
}
return;
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::Verbosity new_verbosity = loguru::g_stderr_verbosity;
if (new_verbosity < loguru::Verbosity_INFO)
new_verbosity = loguru::Verbosity_INFO;
else if (new_verbosity < loguru::Verbosity_MAX)
new_verbosity = loguru::Verbosity_MAX;
else
new_verbosity = loguru::Verbosity_OFF;
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
LOG_F(INFO, "g_stderr_verbosity: %d", new_verbosity);
loguru::g_stderr_verbosity = new_verbosity;
}
return;
}
// Control-D: debugger
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
power_off(po_enter_debugger);
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((event.key.keysym.mod & KMOD_ALL) == KMOD_RALT) != 0) {
KeyboardEvent ke{};
ke.key = AdbKey_Control;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
key_downs++;
} else {
ke.flags = KEYBOARD_EVENT_UP;
key_ups++;
}
this->_keyboard_signal.emit(ke);
ke.key = AdbKey_Delete;
this->_keyboard_signal.emit(ke);
return;
}
int key_code = get_sdl_event_key_code(event.key, this->kbd_locale);
if (key_code != -1) {
KeyboardEvent ke{};
ke.key = key_code;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
key_downs++;
} else {
ke.flags = KEYBOARD_EVENT_UP;
key_ups++;
}
// Caps Lock is a special case, since it's a toggle key
if (ke.key == AdbKey_CapsLock) {
ke.flags = event.key.keysym.mod & KMOD_CAPS ?
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
}
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, "Unknown key %x pressed", event.key.keysym.sym);
}
}
break;
case SDL_MOUSEMOTION: {
MouseEvent me{};
me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel;
me.xabs = event.motion.x;
me.yabs = event.motion.y;
me.flags = MOUSE_EVENT_MOTION;
this->_mouse_signal.emit(me);
}
break;
case SDL_MOUSEBUTTONDOWN: {
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
case SDL_BUTTON_RIGHT : adb_button = 1; break;
default : adb_button = event.button.button - 1;
}
me.buttons_state = (this->buttons_state |= (1 << adb_button));
me.xabs = event.button.x;
me.yabs = event.button.y;
me.flags = MOUSE_EVENT_BUTTON;
this->_mouse_signal.emit(me);
}
break;
case SDL_MOUSEBUTTONUP: {
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
case SDL_BUTTON_RIGHT : adb_button = 1; break;
default : adb_button = event.button.button - 1;
}
me.buttons_state = (this->buttons_state &= ~(1 << adb_button));
me.xabs = event.button.x;
me.yabs = event.button.y;
me.flags = MOUSE_EVENT_BUTTON;
this->_mouse_signal.emit(me);
}
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;
case SDL_DROPFILE: {
const char* path = event.drop.file;
// TODO: Distinguish CD-ROM and floppy images once dynamic
// floppy insertion is supported.
CdromImageEvent cdrom_event{};
cdrom_event.image_path = path;
this->post_cdrom_event(cdrom_event);
switch (cdrom_event.result) {
case CdromInsertionResult::SUCCESS:
LOG_F(INFO, "Inserted CD-ROM image: %s", path);
break;
case CdromInsertionResult::NO_DRIVE:
LOG_F(ERROR, "Cannot insert CD-ROM image; no CD-ROM drive is available: %s",
path);
break;
case CdromInsertionResult::MEDIA_PRESENT:
LOG_F(ERROR, "Cannot insert CD-ROM image; eject the current media first: %s",
path);
break;
case CdromInsertionResult::IMAGE_OPEN_FAILED:
LOG_F(ERROR, "Cannot insert CD-ROM image: %s", path);
break;
}
SDL_free(event.drop.file);
}
break;
default:
unhandled_events++;
}
}
// perform post-processing
this->_post_signal.emit();
}
void EventManager::post_keyboard_state_events() {
int count;
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
SDL_KeyboardEvent keyevent = { .type = SDL_KEYDOWN };
SDL_Scancode scancode;
KeyboardEvent ke{};
typedef struct {
SDL_Scancode scancode;
SDL_Keymod keymod;
AdbKey adbkey;
} Modifier_t;
static Modifier_t modifiers[] = {
{ SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift },
{ SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift },
{ SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control },
{ SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl },
{ SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option },
{ SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption },
{ SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command },
{ SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command },
// { SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear },
{ SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock },
// { SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? },
// { SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 },
{ SDL_SCANCODE_UNKNOWN },
};
LOG_F(INFO, "Current keyboard state:");
LOG_F(INFO, " Modifiers:");
count = 0;
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
if (!(modstate & mod->keymod))
continue;
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(mod->scancode));
count++;
ke.key = swap_command_option(mod->adbkey);
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
}
if (!count)
LOG_F(INFO, " (none)");
LOG_F(INFO, " Keys and Modifiers:");
count = 0;
for (int i = 0; i < numkeys; i++) {
if (!states[i])
continue;
count++;
scancode = (SDL_Scancode)i;
Modifier_t *mod = modifiers;
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
if (mod->scancode == scancode) {
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " Key: %s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
int key_code = get_sdl_event_key_code(keyevent, this->kbd_locale);
if (key_code != -1) {
ke.key = key_code;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, " Unknown key %x pressed", keyevent.keysym.sym);
}
}
if (!count)
LOG_F(INFO, " (none)");
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
{
switch (event.keysym.sym) {
case SDLK_a: return AdbKey_A;
case SDLK_b: return AdbKey_B;
case SDLK_c: return AdbKey_C;
case SDLK_d: return AdbKey_D;
case SDLK_e: return AdbKey_E;
case SDLK_f: return AdbKey_F;
case SDLK_g: return AdbKey_G;
case SDLK_h: return AdbKey_H;
case SDLK_i: return AdbKey_I;
case SDLK_j: return AdbKey_J;
case SDLK_k: return AdbKey_K;
case SDLK_l: return AdbKey_L;
case SDLK_m: return AdbKey_M;
case SDLK_n: return AdbKey_N;
case SDLK_o: return AdbKey_O;
case SDLK_p: return AdbKey_P;
case SDLK_q: return AdbKey_Q;
case SDLK_r: return AdbKey_R;
case SDLK_s: return AdbKey_S;
case SDLK_t: return AdbKey_T;
case SDLK_u: return AdbKey_U;
case SDLK_v: return AdbKey_V;
case SDLK_w: return AdbKey_W;
case SDLK_x: return AdbKey_X;
case SDLK_y: return AdbKey_Y;
case SDLK_z: return AdbKey_Z;
case SDLK_1: return AdbKey_1;
case SDLK_2: return AdbKey_2;
case SDLK_3: return AdbKey_3;
case SDLK_4: return AdbKey_4;
case SDLK_5: return AdbKey_5;
case SDLK_6: return AdbKey_6;
case SDLK_7: return AdbKey_7;
case SDLK_8: return AdbKey_8;
case SDLK_9: return AdbKey_9;
case SDLK_0: return AdbKey_0;
case SDLK_ESCAPE: return AdbKey_Escape;
case SDLK_BACKQUOTE: return AdbKey_Grave;
case SDLK_MINUS: return AdbKey_Minus;
case SDLK_EQUALS: return AdbKey_Equal;
case SDLK_LEFTBRACKET: return AdbKey_LeftBracket;
case SDLK_RIGHTBRACKET: return AdbKey_RightBracket;
case SDLK_BACKSLASH: return AdbKey_Backslash;
case SDLK_SEMICOLON: return AdbKey_Semicolon;
case SDLK_QUOTE: return AdbKey_Quote;
case SDLK_COMMA: return AdbKey_Comma;
case SDLK_PERIOD: return AdbKey_Period;
case SDLK_SLASH: return AdbKey_Slash;
// Convert shifted variants to unshifted
case SDLK_EXCLAIM: return AdbKey_1;
case SDLK_AT: return AdbKey_2;
case SDLK_HASH: return AdbKey_3;
case SDLK_DOLLAR: return AdbKey_4;
case SDLK_UNDERSCORE: return AdbKey_Minus;
case SDLK_PLUS: return AdbKey_Equal;
case SDLK_COLON: return AdbKey_Semicolon;
case SDLK_QUOTEDBL: return AdbKey_Quote;
case SDLK_LESS: return AdbKey_Comma;
case SDLK_GREATER: return AdbKey_Period;
case SDLK_QUESTION: return AdbKey_Slash;
case SDLK_TAB: return AdbKey_Tab;
case SDLK_RETURN: return AdbKey_Return;
case SDLK_SPACE: return AdbKey_Space;
case SDLK_BACKSPACE: return AdbKey_Delete;
case SDLK_DELETE: return AdbKey_ForwardDelete;
case SDLK_INSERT: return AdbKey_Help;
case SDLK_HOME: return AdbKey_Home;
case SDLK_HELP: return AdbKey_Home;
case SDLK_END: return AdbKey_End;
case SDLK_PAGEUP: return AdbKey_PageUp;
case SDLK_PAGEDOWN: return AdbKey_PageDown;
case SDLK_LCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_RightControl;
case SDLK_LSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_RightShift;
case SDLK_LALT: return swap_command_option(AdbKey_Option);
case SDLK_RALT: return swap_command_option(AdbKey_RightOption);
case SDLK_LGUI: return swap_command_option(AdbKey_Command);
case SDLK_RGUI: return swap_command_option(AdbKey_Command);
case SDLK_MENU: return AdbKey_Grave;
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
case SDLK_UP: return AdbKey_ArrowUp;
case SDLK_DOWN: return AdbKey_ArrowDown;
case SDLK_LEFT: return AdbKey_ArrowLeft;
case SDLK_RIGHT: return AdbKey_ArrowRight;
case SDLK_KP_0: return AdbKey_Keypad0;
case SDLK_KP_1: return AdbKey_Keypad1;
case SDLK_KP_2: return AdbKey_Keypad2;
case SDLK_KP_3: return AdbKey_Keypad3;
case SDLK_KP_4: return AdbKey_Keypad4;
case SDLK_KP_5: return AdbKey_Keypad5;
case SDLK_KP_6: return AdbKey_Keypad6;
case SDLK_KP_7: return AdbKey_Keypad7;
case SDLK_KP_9: return AdbKey_Keypad9;
case SDLK_KP_8: return AdbKey_Keypad8;
case SDLK_KP_PERIOD: return AdbKey_KeypadDecimal;
case SDLK_KP_PLUS: return AdbKey_KeypadPlus;
case SDLK_KP_MINUS: return AdbKey_KeypadMinus;
case SDLK_KP_MULTIPLY: return AdbKey_KeypadMultiply;
case SDLK_KP_DIVIDE: return AdbKey_KeypadDivide;
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
case SDLK_F1: return AdbKey_F1;
case SDLK_F2: return AdbKey_F2;
case SDLK_F3: return AdbKey_F3;
case SDLK_F4: return AdbKey_F4;
case SDLK_F5: return AdbKey_F5;
case SDLK_F6: return AdbKey_F6;
case SDLK_F7: return AdbKey_F7;
case SDLK_F8: return AdbKey_F8;
case SDLK_F9: return AdbKey_F9;
case SDLK_F10: return AdbKey_F10;
case SDLK_F11: return AdbKey_F11;
case SDLK_F12: return AdbKey_F12;
case SDLK_PRINTSCREEN: return AdbKey_F13;
case SDLK_SCROLLLOCK: return AdbKey_F14;
case SDLK_PAUSE: return AdbKey_F15;
// International keyboard support
// Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
else
return -1;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
return AdbKey_JIS_KP_Comma;
case 0X89:
return AdbKey_JIS_Eisu;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL2):
return AdbKey_JIS_Kana;
// German keyboard
case 0XB4: return AdbKey_Slash;
case 0X5E: return AdbKey_ISO1;
case 0XDF: return AdbKey_Minus; // Eszett
case 0XE4: return AdbKey_LeftBracket; // A-umlaut
case 0XF6: return AdbKey_Semicolon; // O-umlaut
case 0XFC: return AdbKey_LeftBracket; // U-umlaut
// French keyboard
case 0X29: return AdbKey_Minus; // Right parenthesis
case 0X43: return AdbKey_KeypadMultiply; // Star/Mu
// 0XB2 is superscript 2. Which Mac key should this one map to?
case 0XF9: return AdbKey_Quote; // U-grave
// Italian keyboard
case 0XE0: return AdbKey_9; // A-grave
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;
}
+51
View File
@@ -0,0 +1,51 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cstdint>
#ifndef MATH_UTILS_H
#define MATH_UTILS_H
inline void _u32xu64(uint32_t a, uint64_t b, uint32_t &hi, uint64_t &lo)
{
uint64_t p0 = (b & 0xffffffff) * a;
uint64_t p1 = (b >> 32) * a;
lo = p0 + (p1 << 32);
hi = (p1 >> 32) + (lo < p0);
}
inline void _u32xu64(uint32_t a, uint64_t b, uint64_t &hi, uint32_t &lo)
{
uint64_t p0 = (b & 0xffffffff) * a;
uint64_t p1 = (b >> 32) * a;
lo = (uint32_t)p0;
hi = (p0 >> 32) + p1;
}
inline void _u64xu64(uint64_t a, uint64_t b, uint64_t &hi, uint64_t &lo)
{
uint32_t p0h; uint64_t p0l; _u32xu64((uint32_t)b, a, p0h, p0l);
uint64_t p1h; uint32_t p1l; _u32xu64(b >> 32, a, p1h, p1l);
lo = p0l + ((uint64_t)p1l << 32);
hi = p0h + p1h + (lo < p0l);
}
#endif // MATH_UTILS_H
+246
View File
@@ -0,0 +1,246 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Set of macros for accessing host memory in units of various sizes
and endianness.
*/
#ifndef MEM_ACCESS_H
#define MEM_ACCESS_H
#include <core/endianswap.h>
#include <loguru.hpp>
#include <cinttypes>
#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
#undef __BIG_ENDIAN__
#define __BIG_ENDIAN__ 1
#else
#undef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
/* read an unaligned big-endian WORD (16bit) */
#define READ_WORD_BE_U( addr) ((((uint8_t*)(addr))[0] << 8) | ((uint8_t*)(addr))[1])
/* read an unaligned big-endian DWORD (32bit) */
#define READ_DWORD_BE_U(addr) \
((((uint8_t*)(addr))[0] << 24) | (((uint8_t*)(addr))[1] << 16) | \
(((uint8_t*)(addr))[2] << 8) | ((uint8_t*)(addr))[3] )
/* read an unaligned big-endian QWORD (64bit) */
#define READ_QWORD_BE_U(addr) \
((uint64_t(((uint8_t*)(addr))[0]) << 56) | (uint64_t(((uint8_t*)(addr))[1]) << 48) | \
(uint64_t(((uint8_t*)(addr))[2]) << 40) | (uint64_t(((uint8_t*)(addr))[3]) << 32) | \
(uint64_t(((uint8_t*)(addr))[4]) << 24) | ( ((uint8_t*)(addr))[5] << 16) | \
( ((uint8_t*)(addr))[6] << 8) | ((uint8_t*)(addr))[7] )
/* read an unaligned little-endian WORD (16bit) */
#define READ_WORD_LE_U( addr) ((((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0])
/* read an unaligned little-endian DWORD (32bit) */
#define READ_DWORD_LE_U(addr) \
((((uint8_t*)(addr))[3] << 24) | (((uint8_t*)(addr))[2] << 16) | \
(((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] )
/* read an unaligned little-endian QWORD (64bit) */
#define READ_QWORD_LE_U(addr) \
((uint64_t(((uint8_t*)(addr))[7]) << 56) | (uint64_t(((uint8_t*)(addr))[6]) << 48) | \
(uint64_t(((uint8_t*)(addr))[5]) << 40) | (uint64_t(((uint8_t*)(addr))[4]) << 32) | \
(uint64_t(((uint8_t*)(addr))[3]) << 24) | ( ((uint8_t*)(addr))[2] << 16) | \
( ((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] )
/* write an unaligned big-endian WORD (16bit) */
#define WRITE_WORD_BE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = ((val) >> 8); \
((uint8_t*)(addr))[1] = (uint8_t)(val); \
} while (0)
/* write an unaligned big-endian DWORD (32bit) */
#define WRITE_DWORD_BE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = ((val) >> 24); \
((uint8_t*)(addr))[1] = ((val) >> 16); \
((uint8_t*)(addr))[2] = ((val) >> 8); \
((uint8_t*)(addr))[3] = (uint8_t)(val); \
} while (0)
/* write an unaligned big-endian QWORD (64bit) */
#define WRITE_QWORD_BE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = ((uint64_t)(val) >> 56); \
((uint8_t*)(addr))[1] = ((uint64_t)(val) >> 48); \
((uint8_t*)(addr))[2] = ((uint64_t)(val) >> 40); \
((uint8_t*)(addr))[3] = ((uint64_t)(val) >> 32); \
((uint8_t*)(addr))[4] = ( (val) >> 24); \
((uint8_t*)(addr))[5] = ( (val) >> 16); \
((uint8_t*)(addr))[6] = ( (val) >> 8); \
((uint8_t*)(addr))[7] = (uint8_t)(val) ; \
} while (0)
/* write an unaligned little-endian WORD (16bit) */
#define WRITE_WORD_LE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = (uint8_t)(val); \
((uint8_t*)(addr))[1] = ((val) >> 8); \
} while (0)
/* write an unaligned little-endian DWORD (32bit) */
#define WRITE_DWORD_LE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = (uint8_t)(val); \
((uint8_t*)(addr))[1] = ((val) >> 8); \
((uint8_t*)(addr))[2] = ((val) >> 16); \
((uint8_t*)(addr))[3] = ((val) >> 24); \
} while (0)
/* write an unaligned little-endian QWORD (64bit) */
#define WRITE_QWORD_LE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = (uint8_t)(val) ; \
((uint8_t*)(addr))[1] = ( (val) >> 8); \
((uint8_t*)(addr))[2] = ( (val) >> 16); \
((uint8_t*)(addr))[3] = ( (val) >> 24); \
((uint8_t*)(addr))[4] = ((uint64_t)(val) >> 32); \
((uint8_t*)(addr))[5] = ((uint64_t)(val) >> 40); \
((uint8_t*)(addr))[6] = ((uint64_t)(val) >> 48); \
((uint8_t*)(addr))[7] = ((uint64_t)(val) >> 56); \
} while (0)
#ifdef __LITTLE_ENDIAN__
#define READ_WORD_BE_A( addr) (BYTESWAP_16(*((uint16_t*)(addr))))
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)(addr))))
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)(addr))))
#define READ_WORD_LE_A( addr) (*(uint16_t*)(addr))
#define READ_DWORD_LE_A(addr) (*(uint32_t*)(addr))
#define READ_QWORD_LE_A(addr) (*(uint64_t*)(addr))
#define WRITE_WORD_BE_A( addr, val) (*((uint16_t*)(addr)) = BYTESWAP_16(val))
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)(addr)) = BYTESWAP_32(val))
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)(addr)) = BYTESWAP_64(val))
#define WRITE_WORD_LE_A( addr, val) (*((uint16_t*)(addr)) = (val))
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)(addr)) = (val))
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)(addr)) = (val))
#else // __BIG_ENDIAN__
#define READ_WORD_LE_A( addr) (BYTESWAP_16(*((uint16_t*)(addr))))
#define READ_DWORD_LE_A(addr) (BYTESWAP_32(*((uint32_t*)(addr))))
#define READ_QWORD_LE_A(addr) (BYTESWAP_64(*((uint64_t*)(addr))))
#define READ_WORD_BE_A( addr) (*(uint16_t*)(addr))
#define READ_DWORD_BE_A(addr) (*(uint32_t*)(addr))
#define READ_QWORD_BE_A(addr) (*(uint64_t*)(addr))
#define WRITE_WORD_LE_A( addr, val) (*((uint16_t*)(addr)) = BYTESWAP_16(val))
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)(addr)) = BYTESWAP_32(val))
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)(addr)) = BYTESWAP_64(val))
#define WRITE_WORD_BE_A( addr, val) (*((uint16_t*)(addr)) = (val))
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)(addr)) = (val))
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)(addr)) = (val))
#endif // __BIG_ENDIAN__
/* read an aligned native-endian DWORD */
#define READ_DWORD_NE_A READ_DWORD_LE_A // native-endian = little-endian for now
/* write an aligned native-endian DWORD */
#define WRITE_DWORD_NE_A WRITE_DWORD_LE_A // native-endian = little-endian for now
/* read value of the specified size from memory starting at addr,
perform byte swapping when necessary so that the source
byte order remains unchanged. */
inline uint32_t read_mem(const uint8_t* buf, uint32_t size) {
switch (size) {
case 4:
return READ_DWORD_BE_A(buf);
break;
case 2:
return READ_WORD_BE_A(buf);
break;
case 1:
return *buf;
break;
default:
LOG_F(WARNING, "READ_MEM: invalid size %d!", size);
return 0;
}
}
/* read value of the specified size from memory starting at addr,
perform byte swapping when necessary so that the destination data
will be in the reversed byte order. */
inline uint32_t read_mem_rev(const uint8_t* buf, uint32_t size) {
switch (size) {
case 4:
return READ_DWORD_LE_A(buf);
break;
case 2:
return READ_WORD_LE_A(buf);
break;
case 1:
return *buf;
break;
default:
LOG_F(WARNING, "READ_MEM_REV: invalid size %d!", size);
return 0;
}
}
/* write the specified value of the specified size to memory pointed
to by addr, perform necessary byte swapping so that the byte order
of the destination remains unchanged. */
inline void write_mem(uint8_t* buf, uint32_t value, uint32_t size) {
switch (size) {
case 4:
WRITE_DWORD_BE_A(buf, value);
break;
case 2:
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
break;
case 1:
*buf = value & 0xFF;
break;
default:
LOG_F(WARNING, "WRITE_MEM: invalid size %d!", size);
}
}
/* write the specified value of the specified size to memory pointed
to by addr, perform necessary byte swapping so that the destination
data in memory will be in the reversed byte order. */
inline void write_mem_rev(uint8_t* buf, uint32_t value, uint32_t size) {
switch (size) {
case 4:
WRITE_DWORD_LE_A(buf, value);
break;
case 2:
WRITE_WORD_LE_A(buf, value & 0xFFFFU);
break;
case 1:
*buf = value & 0xFF;
break;
default:
LOG_F(WARNING, "WRITE_MEM_REV: invalid size %d!", size);
}
}
#endif // MEM_ACCESS_H
+74 -63
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,114 +26,125 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <memory>
#include <mutex>
TimerManager* TimerManager::timer_manager;
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
void TimerManager::add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb)
{
if (!timeout || timeout <= MIN_TIMEOUT_NS) {
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", timeout);
}
if (ti.active)
LOG_F(ERROR, "Timer %p is already active; cancel it before rescheduling", (void*)&ti);
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + timeout;
ti->interval_ns = 0;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
ti.timeout_ns = timeout_ns;
ti.interval_ns = interval;
ti.active = true;
ti.cb = cb;
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
this->timer_queue.push(&ti);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
void TimerManager::add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb)
{
if (!interval || interval <= MIN_TIMEOUT_NS) {
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", interval);
}
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + interval;
ti->interval_ns = interval;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
TimerManager::add_absolute_timer(ti, this->get_time_now() + timeout, 0, cb);
}
void TimerManager::cancel_timer(uint32_t id)
void TimerManager::add_immediate_timer(TimerInfo &ti, timer_cb cb)
{
TimerInfo* cur_timer = this->timer_queue.top().get();
if (cur_timer->id == id) {
this->timer_queue.pop();
} else {
this->timer_queue.remove_by_id(id);
}
TimerManager::add_absolute_timer(ti, 0, 0, cb);
}
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb)
{
TimerManager::add_absolute_timer(ti, this->get_time_now() + delay, interval, cb);
}
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb)
{
this->add_cyclic_timer(ti, interval, interval, cb);
}
void TimerManager::cancel_timer(TimerInfo &ti)
{
this->timer_queue.remove_by_id(&ti);
ti.active = false;
if (!this->cb_active) {
this->notify_timer_changes();
}
}
uint64_t TimerManager::process_timers(uint64_t time_now)
uint64_t TimerManager::process_timers()
{
TimerInfo* cur_timer;
TimerInfo *cur_timer;
uint64_t time_now = get_time_now();
{ // mtx scope
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
if (this->timer_queue.empty()) {
return 0ULL;
}
// scan for expired timers
cur_timer = this->timer_queue.top().get();
while (cur_timer->timeout_ns <= time_now ||
cur_timer->timeout_ns <= (time_now + MIN_TIMEOUT_NS)) {
cur_timer = this->timer_queue.top();
} // ] mtx scope
while (cur_timer->timeout_ns <= time_now) {
this->timer_queue.remove_by_id(cur_timer);
uint64_t timeout_ns = cur_timer->timeout_ns;
timer_cb cb = cur_timer->cb;
// re-arm cyclic timers
if (cur_timer->interval_ns) {
auto new_timer = this->timer_queue.top();
new_timer->timeout_ns = time_now + cur_timer->interval_ns;
this->timer_queue.pop();
this->timer_queue.push(new_timer);
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
uint64_t timeout_ns_new = timeout_ns + cur_timer->interval_ns;
if (timeout_ns_new <= time_now) {
// Skip missed periods without changing the timer's phase.
// Rebasing deadlines on time_now would align timers that
// have the same period.
const uint64_t periods_to_skip =
((time_now - timeout_ns_new) / cur_timer->interval_ns) + 1;
timeout_ns_new += periods_to_skip * cur_timer->interval_ns;
}
cur_timer->timeout_ns = timeout_ns_new;
this->timer_queue.push(cur_timer);
} else {
// remove one-shot timers from queue
this->timer_queue.pop();
// One-shot callbacks may immediately reuse their TimerInfo.
cur_timer->active = false;
}
this->cb_active = true;
// invoke timer callback
cb();
cb(time_now, timeout_ns);
this->cb_active = false;
// process next timer
{ // [ mtx scope
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
if (this->timer_queue.empty()) {
return 0ULL;
}
cur_timer = this->timer_queue.top().get();
cur_timer = this->timer_queue.top();
} // ] mtx scope
}
// return time slice in nanoseconds until next timer's expiry
return cur_timer->timeout_ns - time_now;
// return next timer's expiry
return cur_timer->timeout_ns;
}
void TimerManager::cancel_all_timers()
{
TimerInfo *cur_timer;
while (!this->timer_queue.empty()) {
cur_timer = this->timer_queue.top();
LOG_F(WARNING, "Canceling timer id:%llu ns:%llu", uint64_t(cur_timer), cur_timer->timeout_ns);
this->timer_queue.pop();
cur_timer->active = false;
}
}
+75 -36
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,23 +22,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef TIMER_MANAGER_H
#define TIMER_MANAGER_H
#include <atomic>
#include <algorithm>
#include <cinttypes>
#include <functional>
#include <memory>
#include <queue>
#include <vector>
#include <mutex>
using namespace std;
constexpr auto NS_PER_SEC = 1000000000;
constexpr auto USEC_PER_SEC = 1000000;
constexpr auto NS_PER_USEC = 1000;
constexpr auto NS_PER_MSEC = 1000000;
constexpr auto ONE_BILLION_NS = 1000000000;
#define MIN_TIMEOUT_NS 200
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
#define NS_PER_SEC 1E9
#define ONE_BILLION_NS 0x3B9ACA00UL
#define USECS_TO_NSECS(us) (us) * 1000
typedef function<void()> timer_cb;
typedef std::function<void(uint64_t timeout_ns, uint64_t time_now)> timer_cb;
typedef std::function<void()> notify_changes_cb;
/** Extend std::priority_queue as suggested here:
https://stackoverflow.com/a/36711682
@@ -47,31 +50,61 @@ typedef function<void()> timer_cb;
template <typename T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
public:
bool remove_by_id(const uint32_t id){
bool remove_by_id(T id){
std::lock_guard<std::recursive_mutex> lk(mtx);
if (this->empty())
return false;
auto el = this->top();
if (el == id) {
std::priority_queue<T, Container, Compare>::pop();
return true;
}
auto it = std::find_if(
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == id; });
this->c.begin(), this->c.end(), [id](const T& el) { return el == id; });
if (it != this->c.end()) {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
return true;
} else {
return false;
}
};
return false;
}
void push(T val)
{
std::lock_guard<std::recursive_mutex> lk(mtx);
std::priority_queue<T, Container, Compare>::push(val);
}
T pop()
{
std::lock_guard<std::recursive_mutex> lk(mtx);
T val = std::priority_queue<T, Container, Compare>::top();
std::priority_queue<T, Container, Compare>::pop();
return val;
}
std::recursive_mutex& get_mtx()
{
return mtx;
}
private:
std::recursive_mutex mtx;
};
typedef struct TimerInfo {
uint32_t id;
uint64_t timeout_ns; // timer expiry
uint64_t interval_ns; // 0 for one-shot timers
bool active = false; // maintained by TimerManager while queued
timer_cb cb; // timer callback
} TimerInfo;
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
return l.get()->timeout_ns > r.get()->timeout_ns;
bool operator()(const TimerInfo *l, const TimerInfo *r) const {
return l->timeout_ns > r->timeout_ns ||
(l->timeout_ns == r->timeout_ns && l > r);
}
};
@@ -82,40 +115,46 @@ public:
timer_manager = new TimerManager();
}
return timer_manager;
};
}
// callback for retrieving current time
void set_time_now_cb(const function<uint64_t()> &cb) {
void set_time_now_cb(const std::function<uint64_t()> &cb) {
this->get_time_now = cb;
};
}
// callback for acknowledging time changes
void set_notify_changes_cb(const timer_cb &cb) {
void set_notify_changes_cb(const notify_changes_cb &cb) {
this->notify_timer_changes = cb;
};
}
// return current virtual time in nanoseconds
uint64_t current_time_ns() { return get_time_now(); };
uint64_t current_time_ns() const { return get_time_now(); }
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
void cancel_timer(uint32_t id);
// Adding requires an inactive timer; cancel before rescheduling.
// One-shot timers become inactive before their callback runs.
// Cyclic timers remain active until canceled, including during callbacks.
void add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb);
void add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb);
void add_immediate_timer(TimerInfo &ti, timer_cb cb);
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb);
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(TimerInfo &ti);
void cancel_all_timers();
uint64_t process_timers(uint64_t time_now);
uint64_t process_timers();
private:
static TimerManager* timer_manager;
TimerManager(){}; // private constructor to implement a singleton
TimerManager(){} // private constructor to implement a singleton
// timer queue
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
my_priority_queue<TimerInfo*, std::vector<TimerInfo*>, MyGtComparator> timer_queue;
function<uint64_t()> get_time_now;
function<void()> notify_timer_changes;
std::function<uint64_t()> get_time_now;
std::function<void()> notify_timer_changes;
uint32_t id = 0;
bool cb_active = false; // true if a timer callback is executing
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
bool cb_active = false; // true if a timer callback is executing
};
#endif // TIMER_MANAGER_H
+9 -1
View File
@@ -1,6 +1,14 @@
include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
)
# The use of volatile is deprecated, but we still need it to avoid function
# parameters being clobbered when using setjmp/longjmp.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-volatile)
endif()
add_library(cpu_ppc OBJECT ${SOURCES})
+467 -332
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,191 +22,244 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// The Power-specific opcodes for the processor - ppcopcodes.cpp
// Any shared opcodes are in ppcopcodes.cpp
#include "ppcemu.h"
#include "ppcmmu.h"
#include <array>
#include <cmath>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <stdio.h>
#include <loguru.hpp>
#include <core/bitops.h>
#include <cpu/ppc/ppcdechelpers.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
// Affects the XER register's SO and OV Bits
inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
ppc_state.spr[SPR::XER] |= 0xC0000000UL;
} else {
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
}
}
#include <stdint.h>
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
uint32_t m1 = 0xFFFFFFFFU >> rot_mb;
uint32_t m2 = 0xFFFFFFFFU << (31 - rot_me);
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
}
void dppc_interpreter::power_abs() {
ppc_grab_regsda();
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_abs(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsda(opcode);
if (ppc_result_a == 0x80000000) {
ppc_result_d = ppc_result_a;
if (oe_flag)
ppc_state.spr[SPR::XER] |= 0xC0000000;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_result_regd();
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
void dppc_interpreter::power_clcs() {
ppc_grab_regsda();
switch (reg_a) {
case 12: //instruction cache line size
case 13: //data cache line size
case 14: //minimum line size
case 15: //maximum line size
ppc_result_d = 64;
break;
default:
ppc_result_d = 0;
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_clcs(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_da(opcode);
switch (reg_a & 15) {
case 0:
case 1:
case 2:
case 3:
case 0xC: //instruction cache line size
case 0xD: //data cache line size
case 0xE: //minimum line size
case 0xF: //maximum line size
ppc_result_d = is_601 ? 0x40 : 0x20; break;
case 4:
case 5:
case 6: ppc_result_d = 0x20; break;
case 7: ppc_result_d = is_601 ? 1 : 0; break;
case 8:
case 9: ppc_result_d = is_601 ? 8 : 4; break;
case 0xA:
case 0xB: ppc_result_d = is_601 ? 0x8000 : 0x4000; break;
}
ppc_store_result_regd();
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
void dppc_interpreter::power_div() {
ppc_grab_regsdab();
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_div(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsdab(opcode);
if (oe_flag)
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
if (rc_flag)
ppc_changecrf0(ppc_result_d);
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
int32_t divisor = ppc_result_b;
int64_t quotient;
int32_t remainder;
ppc_store_result_regd();
}
void dppc_interpreter::power_divs() {
ppc_grab_regsdab();
ppc_result_d = ppc_result_a / ppc_result_b;
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
if (oe_flag)
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
if (rc_flag)
ppc_changecrf0(ppc_result_d);
ppc_store_result_regd();
}
void dppc_interpreter::power_doz() {
ppc_grab_regsdab();
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
ppc_result_d = 0;
if (dividend == -0x80000000 && divisor == -1) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else if (!divisor) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_result_d = ppc_result_b - ppc_result_a;
quotient = dividend / divisor;
remainder = dividend % divisor;
ppc_result_d = uint32_t(quotient);
if (ov) {
if (((quotient >> 31) + 1) & ~1) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
}
if (rc_flag)
ppc_changecrf0(ppc_result_d);
if (oe_flag)
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
if (rec)
ppc_changecrf0(remainder);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
void dppc_interpreter::power_dozi() {
ppc_grab_regsdasimm();
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_divs(uint32_t opcode) {
uint32_t ppc_result_d;
int32_t remainder;
ppc_grab_regsdab(opcode);
if (!ppc_result_b) { // handle the "anything / 0" case
ppc_result_d = -1;
remainder = ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
ppc_result_d = 0x80000000U;
remainder = 0;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else { // normal signed devision
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
if (rec)
ppc_changecrf0(remainder);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
ppc_result_b - ppc_result_a : 0;
if (ov) {
if (int32_t(ppc_result_d) < 0) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_dozi(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsdasimm(opcode);
if (((int32_t)ppc_result_a) > simm) {
ppc_result_d = 0;
} else {
ppc_result_d = simm - ppc_result_a;
}
ppc_store_result_rega();
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
void dppc_interpreter::power_lscbx() {
ppc_grab_regsdab();
ppc_effective_address = (reg_a == 0) ? ppc_result_b : ppc_result_a + ppc_result_b;
template <field_rc rec>
void dppc_interpreter::power_lscbx(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint8_t return_value = 0;
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7f);
uint32_t bytes_copied = 0;
uint8_t matching_byte = (uint8_t)((ppc_state.spr[SPR::XER] & 0xFF00) >> 8);
uint32_t byte_offset = 0;
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
uint32_t bytes_remaining = bytes_to_load;
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
uint32_t ppc_result_d = 0;
bool is_match = false;
//for storing each byte
uint32_t bitmask = 0;
uint32_t shift_amount = 0;
// for storing each byte
uint8_t shift_amount = 24;
while (bytes_to_load > 0) {
if (byte_offset == 24) {
reg_d = (reg_d + 1) % 32;
ppc_result_d = 0xFFFFFFFF;
ppc_store_result_regd();
}
while (bytes_remaining > 0) {
uint8_t return_value = mmu_read_vmem<uint8_t>(opcode, ea);
switch (byte_offset) {
case 0:
bitmask = 0x00FFFFFF;
ppc_result_d |= return_value << shift_amount;
if (!shift_amount) {
if (reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
reg_d = (reg_d + 1) & 0x1F;
ppc_result_d = 0;
shift_amount = 24;
break;
case 8:
bitmask = 0xFF00FFFF;
shift_amount = 16;
break;
case 16:
bitmask = 0xFFFF00FF;
shift_amount = 8;
break;
case 24:
bitmask = 0xFFFFFF00;
shift_amount = 0;
break;
} else {
shift_amount -= 8;
}
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
// return_value = mem_grab_byte(ppc_effective_address);
ppc_result_d = (ppc_result_d & bitmask) | (return_value << shift_amount);
ppc_store_result_regd();
bytes_copied++;
ea++;
bytes_remaining--;
if (return_value == matching_byte) {
//Match has been found - Time to break out
is_match = true;
break;
}
byte_offset += 8;
if (byte_offset == 32) {
byte_offset = 0;
}
ppc_effective_address++;
bytes_to_load--;
}
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & 0xFFFFFF80) | bytes_copied;
// store partially loaded register if any
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
if (rc_flag)
ppc_changecrf0(ppc_result_d);
if (rec) {
ppc_state.cr =
(ppc_state.cr & 0x0FFFFFFFUL) |
(is_match ? CRx_bit::CR_EQ : 0) |
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
}
}
void dppc_interpreter::power_maskg() {
ppc_grab_regssab();
uint32_t mask_start = ppc_result_d & 31;
uint32_t mask_end = ppc_result_b & 31;
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_grab_regssab(opcode);
uint32_t mask_start = ppc_result_d & 0x1F;
uint32_t mask_end = ppc_result_b & 0x1F;
uint32_t insert_mask = 0;
if (mask_start < (mask_end + 1)) {
@@ -221,318 +274,400 @@ void dppc_interpreter::power_maskg() {
ppc_result_a = insert_mask;
if (rc_flag)
ppc_changecrf0(ppc_result_d);
ppc_store_result_rega();
}
void dppc_interpreter::power_maskir() {
ppc_grab_regssab();
ppc_result_a = (ppc_result_d & ppc_result_b) | (~(ppc_result_b) & ppc_result_a);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_mul() {
ppc_grab_regsdab();
uint64_t product;
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
ppc_result_d = ((uint32_t)(product >> 32));
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
template <field_rc rec>
void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_mul(uint32_t opcode) {
ppc_grab_regsdab(opcode);
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
ppc_state.spr[SPR::MQ] = uint32_t(product);
if (ov) {
if (uint64_t(product >> 31) + 1 & ~1) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_result_regd();
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
void dppc_interpreter::power_nabs() {
ppc_grab_regsda();
ppc_result_d = (0x80000000 | ppc_result_a);
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
if (rc_flag)
ppc_changecrf0(ppc_result_d);
void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
ppc_store_result_regd();
}
void dppc_interpreter::power_rlmi() {
ppc_grab_regssab();
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
unsigned rot_sh = ppc_result_b & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
if (rc_flag)
if ((opcode & 0x01) == 1)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_rrib() {
ppc_grab_regssab();
template <field_rc rec>
void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_d & 0x80000000) {
ppc_result_a |= ((ppc_result_d & 0x80000000) >> ppc_result_b);
if (int32_t(ppc_result_d) < 0) {
ppc_result_a |= (0x80000000U >> rot_sh);
} else {
ppc_result_a &= ~((ppc_result_d & 0x80000000) >> ppc_result_b);
ppc_result_a &= ~(0x80000000U >> rot_sh);
}
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sle() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sleq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sliq() {
ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_slliq() {
ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sllq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
if (ppc_result_b >= 0x20) {
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
}
else {
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
}
template <field_rc rec>
void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (rc_flag)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
}
void dppc_interpreter::power_slq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
if (ppc_result_b >= 0x20) {
ppc_result_a = ppc_result_d << rot_sh;
if (ppc_result_b & 0x20) {
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
} else {
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1U << rot_sh) - 1)));
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
}
if (rc_flag)
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
}
void dppc_interpreter::power_sraiq() {
ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
uint32_t mask = (1 << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= 0x20000000UL;
} else {
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
ppc_result_a = ppc_result_d << rot_sh;
}
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sraq() {
ppc_grab_regssab();
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (1 << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= 0x20000000UL;
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = ((ppc_result_d << ppc_result_b) | (ppc_result_d >> (ppc_result_b)));
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_sre() {
ppc_grab_regssab();
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
unsigned rot_sh = ppc_result_b & 31;
template <field_rc rec>
void dppc_interpreter::power_sre(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
if (rc_flag)
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_srea() {
ppc_grab_regssab();
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t mask = -1U >> rot_sh;
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & rot_sh)) {
ppc_state.spr[SPR::XER] |= 0x20000000UL;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
}
void dppc_interpreter::power_sreq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((rot_sh & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = rot_sh;
if (rc_flag)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
}
void dppc_interpreter::power_sriq() {
ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (rot_sh)));
if (rc_flag)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
}
void dppc_interpreter::power_srliq() {
ppc_grab_regssa();
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r;
if (rc_flag)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
}
void dppc_interpreter::power_srlq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b >= 0x20) {
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
}
else {
} else {
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
}
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
void dppc_interpreter::power_srq() {
ppc_grab_regssab();
unsigned rot_sh = ppc_result_b & 31;
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
if (ppc_result_b >= 0x20) {
template <field_rc rec>
void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
if (rc_flag)
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_result_rega();
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode);
+215
View File
@@ -0,0 +1,215 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PPC_DECODE_HELPERS_H
#define PPC_DECODE_HELPERS_H
#include <cinttypes>
// ============== Helpers for extracting operands from opcodes ================
#define decode_ops_sa(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
int reg_a = (opcode >> 16) & 0x1F;
#define decode_ops_da(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
int reg_a = (opcode >> 16) & 0x1F;
#define decode_ops_sab(opcode) \
decode_ops_sa(opcode); \
int reg_b = (opcode >> 11) & 0x1F;
#define decode_ops_dab(opcode) \
decode_ops_da(opcode); \
int reg_b = (opcode >> 11) & 0x1F;
#define decode_ops_dasimm(opcode) \
decode_ops_da(opcode); \
int32_t simm = int32_t(int16_t(opcode));
#define decode_ops_sauimm(opcode) \
decode_ops_sa(opcode); \
uint32_t uimm = uint16_t(opcode);
#define decode_ops_dauimm(opcode) \
decode_ops_da(opcode); \
uint32_t uimm = uint16_t(opcode);
// ================= Helpers for the original interpreter =====================
// The helpers below do the same work as those above but also pre-load some
// register values and place them into local variables.
// That significantly reduces interpreter code.
#define ppc_grab_regsdasimm(opcode) \
decode_ops_dasimm(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdauimm(opcode) \
decode_ops_dauimm(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsasimm(opcode) \
int reg_a = (opcode >> 16) & 0x1F; \
int32_t simm = int32_t(int16_t(opcode)); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssauimm(opcode) \
decode_ops_sauimm(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_crfd_regsauimm(opcode) \
int crf_d = (opcode >> 21) & 0x1C; \
int reg_a = (opcode >> 16) & 0x1F; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_da(opcode) \
decode_ops_da(opcode)
#define ppc_grab_dab(opcode) \
decode_ops_dab(opcode)
#define ppc_grab_s(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
#define ppc_grab_regsdab(opcode) \
decode_ops_dab(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab(opcode) \
decode_ops_sab(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab_stswx(opcode) \
decode_ops_sab(opcode); \
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) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
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) \
decode_ops_sa(opcode); \
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) \
decode_ops_sa(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash(opcode) \
decode_ops_sa(opcode); \
unsigned rot_sh = (opcode >> 11) & 0x1F; \
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) \
decode_ops_sa(opcode); \
unsigned rot_sh = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsda(opcode) \
decode_ops_da(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdb(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
uint32_t reg_b = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdb(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F;
#define ppc_grab_regsfpdiab(opcode) \
decode_ops_dab(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdia(opcode) \
decode_ops_da(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsia(opcode) \
decode_ops_sa(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsiab(opcode) \
decode_ops_sab(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpsab(opcode) \
int reg_a = (opcode >> 16) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
int crf_d = (opcode >> 21) & 0x1C; \
double db_test_a = GET_FPR(reg_a); \
double db_test_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdab(opcode) \
decode_ops_dab(opcode); \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdac(opcode) \
decode_ops_da(opcode); \
int reg_c = (opcode >> 6) & 0x1F; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_grab_regsfpdabc(opcode) \
decode_ops_dab(opcode); \
int reg_c = (opcode >> 6) & 0x1F; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_store_iresult_reg(reg, ppc_result) \
ppc_state.gpr[reg] = ppc_result
#define ppc_store_fpresult_int(reg, ppc_result64_d) \
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d) \
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
#endif // PPC_DECODE_HELPERS_H
+856 -320
View File
File diff suppressed because it is too large. Load diff
+6 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,12 +24,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <string>
#include <vector>
typedef struct PPCDisasmContext {
uint32_t instr_addr;
uint32_t instr_code;
std::string instr_str;
bool simplified; /* true if we should output simplified mnemonics */
std::vector<std::string> regs_in;
std::vector<std::string> regs_out;
} PPCDisasmContext;
std::string disassemble_single(PPCDisasmContext* ctx);
+524 -397
View File
File diff suppressed because it is too large. Load diff
+171 -55
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,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++;
@@ -38,78 +39,61 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
case Except_Type::EXC_DSI:
case Except_Type::EXC_ALIGNMENT:
case Except_Type::EXC_PROGRAM:
case Except_Type::EXC_NO_FPU:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0100;
break;
case Except_Type::EXC_MACHINE_CHECK:
if (!(ppc_state.msr & 0x1000)) {
if (!(ppc_state.msr & MSR::ME)) {
/* TODO: handle internal checkstop */
}
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0200;
break;
case Except_Type::EXC_DSI:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0300;
break;
case Except_Type::EXC_ISI:
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
ppc_next_instruction_address = 0x0400;
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
}
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags & ~EXEF_TIMER) {
case Except_Type::EXC_DECR:
case Except_Type::EXC_THRM_MGMT_INT:
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
}
ppc_next_instruction_address = 0x0500;
break;
case Except_Type::EXC_ALIGNMENT:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0600;
break;
case Except_Type::EXC_PROGRAM:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0700;
break;
case Except_Type::EXC_NO_FPU:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0800;
break;
case Except_Type::EXC_DECR:
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0900;
break;
case Except_Type::EXC_SYSCALL:
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0C00;
break;
case Except_Type::EXC_TRACE:
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0D00;
break;
default:
ABORT_F("Unknown exception occured: %X\n", exception_type);
ABORT_F("Unknown exception occurred: %X\n", (unsigned)exception_type);
break;
}
ppc_next_instruction_address = uint32_t(exception_type) << 8;
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
ppc_state.msr &= 0xFFFB1041;
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) | ((ppc_state.msr >> 16) & 1);
if (!is_601) {
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, new_msr_val, false);
if (ppc_state.msr & 0x40) {
if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000;
}
@@ -123,22 +107,25 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
mmu_change_mode();
if (exception_type != Except_Type::EXC_EXT_INT) {
if (exception_type != Except_Type::EXC_EXT_INT && exception_type != Except_Type::EXC_DECR) {
if (!power_on && power_off_reason == po_endian_switch) [[unlikely]] {
power_on = true;
}
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;
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
exc_descriptor = "System reset exception occured";
exc_descriptor = "System reset exception occurred";
break;
case Except_Type::EXC_MACHINE_CHECK:
exc_descriptor = "Machine check exception occured";
exc_descriptor = "Machine check exception occurred";
break;
case Except_Type::EXC_DSI:
@@ -147,6 +134,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
exc_descriptor = "DSI/ISI exception: unmapped memory access";
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
exc_descriptor = "DSI/ISI exception: access protection violation";
else if (ppc_state.spr[SPR::DSISR] & 0x00100000)
exc_descriptor = "DSI exception: External access is disabled";
else {
if (exception_type == Except_Type::EXC_DSI)
exc_descriptor = "DSI exception";
@@ -156,33 +145,160 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
exc_descriptor = "External interrupt exception occured";
exc_descriptor = "External interrupt exception occurred";
break;
case Except_Type::EXC_ALIGNMENT:
exc_descriptor = "Alignment exception occured";
exc_descriptor = "Alignment exception occurred";
break;
case Except_Type::EXC_PROGRAM:
exc_descriptor = "Program exception occured";
exc_descriptor = "Program exception occurred";
break;
case Except_Type::EXC_NO_FPU:
exc_descriptor = "Floating-Point unavailable exception occured";
exc_descriptor = "Floating-Point unavailable exception occurred";
break;
case Except_Type::EXC_DECR:
exc_descriptor = "Decrementer exception occured";
exc_descriptor = "Decrementer exception occurred";
break;
case Except_Type::EXC_SYSCALL:
exc_descriptor = "Syscall exception occured";
exc_descriptor = "Syscall exception occurred";
break;
case Except_Type::EXC_TRACE:
exc_descriptor = "Trace exception occured";
exc_descriptor = "Trace exception occurred";
break;
case Except_Type::EXC_THRM_MGMT_INT:
exc_descriptor = "Thermal management interrupt exception occurred";
break;
default:
char buffer[100];
snprintf(buffer, sizeof(buffer), "Exception 0x%X occurred", int(exception_type));
exc_descriptor = buffer;
}
throw std::invalid_argument(exc_descriptor);
}
void ppc_floating_point_exception(uint32_t opcode) {
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
ppc_state.pc, opcode);
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
}
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
{
uint32_t dsisr;
switch (opcode & 0xfc000000) {
case 0x80000000: // lwz
case 0x90000000: // stw
case 0xa0000000: // lhz
case 0xa8000000: // lha
case 0xb0000000: // sth
case 0xb8000000: // lmw
case 0xc0000000: // lfs
case 0xc8000000: // lfd
case 0xd0000000: // stfs
case 0xd8000000: // stfd
case 0x84000000: // lwzu
case 0x94000000: // stwu
case 0xa4000000: // lhzu
case 0xac000000: // lhau
case 0xb4000000: // sthu
case 0xbc000000: // stmw
case 0xc4000000: // lfsu
case 0xcc000000: // lfdu
case 0xd4000000: // stfsu
case 0xdc000000: // stfdu
// indirect with immediate index
dsisr = ((opcode >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((opcode >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
break;
case 0x7c000000:
switch (opcode & 0xfc0007ff) {
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
case 0x7c0002aa: // lwax (64-bit only)
case 0x7c00042a: // lswx
case 0x7c0004aa: // lswi
case 0x7c00052a: // stswx
case 0x7c0005aa: // stswi
case 0x7c0002ea: // lwaux (64 bit only)
case 0x7c00012c: // stwcx
case 0x7c00042c: // lwbrx
case 0x7c00052c: // stwbrx
case 0x7c00062c: // lhbrx
case 0x7c00072c: // sthbrx
case 0x7c00026c: // eciwx // MPC7451
case 0x7c00036c: // ecowx // MPC7451
case 0x7c00002e: // lwzx
case 0x7c00012e: // stwx
case 0x7c00022e: // lhzx
case 0x7c0002ae: // lhax
case 0x7c00032e: // sthx
case 0x7c00042e: // lfsx
case 0x7c0004ae: // lfdx
case 0x7c00052e: // stfsx
case 0x7c0005ae: // stfdx
case 0x7c00006e: // lwzux
case 0x7c00016e: // stwux
case 0x7c00026e: // lhzux
case 0x7c0002ee: // lhaux
case 0x7c00036e: // sthux
case 0x7c00046e: // lfsux
case 0x7c0004ee: // lfdux
case 0x7c00056e: // stfsux
case 0x7c0005ee: // stfdux
indirect_with_index:
dsisr = ((opcode << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
| ((opcode << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
| ((opcode << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
break;
case 0x7c0007ec:
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
goto indirect_with_index;
/* fallthrough */
default:
goto unexpected_instruction;
}
break;
default:
unexpected_instruction:
dsisr = 0;
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
opcode);
}
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
// Undefined for dcbz.
dsisr |= ((opcode >> 16) & 0x000003e0);
if ((opcode & 0xfc000000) == 0xb8000000) { // lmw
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((opcode & 0xfc0007ff) == 0x7c0004aa) { // lswi
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((opcode & 0xfc0007ff) == 0x7c00042a) { // lswx
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else {
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
dsisr |= ((opcode >> 16) & 0x0000001f);
}
ppc_state.spr[SPR::DSISR] = dsisr;
ppc_state.spr[SPR::DAR] = ea;
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
}
+931 -591
View File
File diff suppressed because it is too large. Load diff
+1119 -761
View File
File diff suppressed because it is too large. Load diff
+1071 -1054
View File
File diff suppressed because it is too large. Load diff
+31 -53
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,12 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef PPCMMU_H
#define PPCMMU_H
#include <devices/memctrl/memctrlbase.h>
#include <array>
#include <cinttypes>
#include <functional>
#include <vector>
class MMIODevice;
/* Uncomment this to exhaustive MMU integrity checks. */
//#define MMU_INTEGRITY_CHECKS
@@ -70,64 +68,44 @@ typedef struct PATResult {
uint8_t pte_c_status; // status of the C bit of the PTE
} PATResult;
#define PAGE_SIZE_BITS 12
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
#define PAGE_MASK ~(PAGE_SIZE - 1)
#define TLB_SIZE 4096
#define TLB2_WAYS 4
#define TLB_INVALID_TAG 0xFFFFFFFF
/** DMA memory mapping result. */
typedef struct MapDmaResult {
uint32_t type;
uint32_t size;
bool is_writable;
// for memory regions
uint8_t* host_va;
// for MMIO regions
MMIODevice* dev_obj;
uint32_t dev_base;
} MapDmaResult;
typedef struct TLBEntry {
uint32_t tag;
uint16_t flags;
uint16_t lru_bits;
union {
int64_t host_va_offs_r;
AddressMapEntry* reg_desc;
};
int64_t host_va_offs_w;
int64_t unused;
} TLBEntry;
enum TLBFlags : uint16_t {
PAGE_MEM = 1 << 0, // memory page backed by host memory
PAGE_IO = 1 << 1, // memory mapped I/O page
PAGE_NOPHYS = 1 << 2, // no physical storage for this page (unmapped)
TLBE_FROM_BAT = 1 << 3, // TLB entry has been translated with BAT
TLBE_FROM_PAT = 1 << 4, // TLB entry has been translated with PAT
PAGE_WRITABLE = 1 << 5, // page is writable
PTE_SET_C = 1 << 6, // tells if C bit of the PTE needs to be updated
};
constexpr uint32_t PPC_PAGE_SIZE_BITS = 12;
constexpr uint32_t PPC_PAGE_SIZE = (1 << PPC_PAGE_SIZE_BITS);
constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
extern std::function<void(uint32_t bat_reg)> ibat_update;
extern std::function<void(uint32_t bat_reg)> dbat_update;
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size);
extern PPC_BAT_entry ibat_array[4];
extern PPC_BAT_entry dbat_array[4];
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
bool allow_mmio = false, bool allow_partial = false, bool is_dbg = false);
extern void mmu_change_mode(void);
extern void mmu_pat_ctx_changed();
extern void tlb_flush_entry(uint32_t ea);
extern void tlb_flush_all_pat();
extern void mmu_dcbz(uint32_t opcode, uint32_t guest_va);
extern void ppc_set_cur_instruction(const uint8_t* ptr);
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
uint8_t *mmu_translate_imem(uint32_t vaddr);
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
template <class T>
extern T mmu_read_vmem(uint32_t guest_va);
extern T mmu_read_vmem(uint32_t opcode, uint32_t guest_va);
template <class T>
extern void mmu_write_vmem(uint32_t guest_va, T value);
//====================== 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
extern void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value);
#endif // PPCMMU_H
+1458 -1463
View File
File diff suppressed because it is too large. Load diff
Regular → Executable
+77 -187
View File
@@ -1,3 +1,5 @@
import re
def gen_ppc_opcode(opc_str, imm):
if opc_str == "ADD":
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x10A << 1)
@@ -100,53 +102,53 @@ def gen_ppc_opcode(opc_str, imm):
elif opc_str == "EXTSH.":
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1) + 1
elif opc_str == "FABS":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1)
return (0x3F << 26) + (3 << 21) + (0 << 16) + (4 << 11) + (0x108 << 1)
elif opc_str == "FABS.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1) + 1
return (0x3F << 26) + (3 << 21) + (0 << 16) + (4 << 11) + (0x108 << 1) + 1
elif opc_str == "FADD":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
elif opc_str == "FADD.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
elif opc_str == "FADDS":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
elif opc_str == "FADDS.":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
elif opc_str == "FCMPO":
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11) + (0x20 << 1)
elif opc_str == "FCMPU":
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11)
elif opc_str == "FCTIW":
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1)
elif opc_str == "FCTIW.":
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1) + 1
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1) + 1
elif opc_str == "FCTIWZ":
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1)
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1)
elif opc_str == "FCTIWZ.":
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1) + 1
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1) + 1
elif opc_str == "FDIV":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
elif opc_str == "FDIV.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
elif opc_str == "FDIVS":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
elif opc_str == "FDIVS.":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
elif opc_str == "FMADD":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
elif opc_str == "FMADD.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
elif opc_str == "FMADDS":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
elif opc_str == "FMADDS.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
elif opc_str == "FMUL":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
elif opc_str == "FMUL.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1) + 1
elif opc_str == "FMULS":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
elif opc_str == "FMULS.":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1) + 1
elif opc_str == "FNABS":
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
elif opc_str == "FNABS.":
@@ -155,42 +157,40 @@ def gen_ppc_opcode(opc_str, imm):
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
elif opc_str == "FNEG.":
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
elif opc_str == "FMULS.":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
elif opc_str == "FMSUB":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
elif opc_str == "FMSUB.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
elif opc_str == "FMSUBS":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
elif opc_str == "FMSUBS.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
elif opc_str == "FNMADD":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
elif opc_str == "FNMADD.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
elif opc_str == "FNMADDS":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
elif opc_str == "FNMADDS.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
elif opc_str == "FNMSUB":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
elif opc_str == "FNMSUB.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
elif opc_str == "FNMSUBS":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
elif opc_str == "FNMSUBS.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
elif opc_str == "FRES":
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x18 << 1)
elif opc_str == "FSUB":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
elif opc_str == "FSUB.":
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1) + 1
elif opc_str == "FSUBS":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
elif opc_str == "FSUBS.":
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1) + 1
elif opc_str == "MULHW":
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
elif opc_str == "MULHW.":
@@ -313,6 +313,10 @@ def gen_rot_opcode(opc_str, sh, mb, me):
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWINM.":
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1) + 1
elif opc_str == "RLWNM":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWNM.":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1) + 1
def extract_imm(line):
pos = 12
@@ -403,6 +407,8 @@ if __name__ == "__main__":
out_file.write("\n")
floatRE = re.compile('^([\w]+\.?) +(?:\((\w+)\) )?:: (?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?FPSCR: (0x\w+) \| CR: (0x\w+)$')
with open("ppcfloattest.txt", "r") as in_file:
with open("ppcfloattests.csv", "w") as out_file:
lineno = 0
@@ -410,153 +416,37 @@ if __name__ == "__main__":
lineno += 1
line = line.strip()
opcode = (line[0:8]).rstrip().upper()
out_file.write(opcode+ ",")
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
p = floatRE.match(line)
if p:
opcode = p.group(1).upper();
out_file.write(opcode+ ",")
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
pos = 10
checkstring = ''
while pos < len(line):
if (line[pos].isalnum()):
checkstring += line[pos]
if ("RTN" in checkstring):
if (line[pos+1:pos+2] == "I"):
out_file.write(",round=RNI")
checkstring = ''
else:
out_file.write(",round=RTN")
checkstring = ''
pos += 1
elif ("RTZ" in checkstring):
if p.group(2) == "RTNI":
out_file.write(",round=RNI")
elif p.group(2) == "RTN":
out_file.write(",round=RTN")
elif p.group(2) == "RTZ":
out_file.write(",round=RTZ")
checkstring = ''
pos += 1
elif ("RTPI" in checkstring):
elif p.group(2) == "RTPI":
out_file.write(",round=RPI")
checkstring = ''
pos += 1
elif ("VE" in checkstring):
elif p.group(2) == "VE":
out_file.write(",round=VEN")
checkstring = ''
pos += 1
elif ("frD" in checkstring):
out_file.write(",frD=0x" + line[pos+4:pos+20])
checkstring = ''
elif ("frA" in checkstring): #sloppy temp code
check2 = line[pos+1:pos+10]
if ("-inf" in check2):
out_file.write(",frA=-inf")
elif ("inf" in check2):
out_file.write(",frA=inf")
pos += 1
elif ("nan" in check2):
out_file.write(",frA=nan")
pos += 1
elif ("-0." or "-2." or "-4." or \
"-6." or "-8." or "-7." or\
"-5." or "-3." or "-1." or \
"-9." in check2):
get_pos = line[pos+2:pos+16].strip("|")
out_file.write(",frA=" + get_pos.strip())
elif ("0." or "2." or "4." or \
"6." or "8." or "7." or\
"5." or "3." or "1." or \
"9." in check2):
get_pos = line[pos+2:pos+15]
out_file.write(",frA=" + get_pos.strip())
checkstring = ''
elif ("frB" in checkstring): #sloppy temp code
check2 = line[pos+1:pos+10]
if ("-inf" in check2):
out_file.write(",frB=-inf")
elif ("inf" in check2):
out_file.write(",frB=inf")
pos += 1
elif ("nan" in check2):
out_file.write(",frB=nan")
pos += 1
elif ("-0." or "-2." or "-4." or \
"-6." or "-8." or "-7." or\
"-5." or "-3." or "-1." or \
"-9." in check2):
get_pos = line[pos+2:pos+16].strip("|")
out_file.write(",frB=" + get_pos.strip())
elif ("0." or "2." or "4." or \
"6." or "8." or "7." or\
"5." or "3." or "1." or \
"9." in check2):
get_pos = line[pos+2:pos+15]
out_file.write(",frB=" + get_pos.strip())
checkstring = ''
elif ("frC" in checkstring): #sloppy temp code
check2 = line[pos+1:pos+10]
if ("-inf" in check2):
out_file.write(",frC=-inf")
elif ("inf" in check2):
out_file.write(",frC=inf")
pos += 1
elif ("nan" in check2):
out_file.write(",frC=nan")
pos += 1
elif ("-0." or "-2." or "-4." or \
"-6." or "-8." or "-7." or\
"-5." or "-3." or "-1." or \
"-9." in check2):
get_pos = line[pos+2:pos+16].strip("|")
out_file.write(",frC=" + get_pos.strip())
elif ("0." or "2." or "4." or \
"6." or "8." or "7." or\
"5." or "3." or "1." or \
"9." in check2):
get_pos = line[pos+2:pos+15]
out_file.write(",frC=" + get_pos.strip())
checkstring = ''
elif ("FPSCR" in checkstring):
out_file.write(",FPSCR=" + line[pos+3:pos+13])
checkstring = ''
elif ("CR" in checkstring):
out_file.write(",CR=0x0" + line[pos+6:pos+14])
checkstring = ''
pos += 1
elif p.group(2) != None:
print("Warning: line: [%d] unknown round \"%s\"\n" % (lineno, p.group(2)))
# reg_id = line[pos:pos+4]
# if reg_id.startswith("frD"):
# out_file.write(",frD=" + line[pos+4:pos+22])
# pos += 24
# elif reg_id.startswith("frA"):
# out_file.write(",frA=" + line[pos+4:pos+14])
# pos += 16
# elif reg_id.startswith("frB"):
# out_file.write(",frB=" + line[pos+4:pos+14])
# pos += 16
# elif reg_id.startswith("frC"):
# out_file.write(",frC=" + line[pos+4:pos+14])
# pos += 16
# elif reg_id.startswith("FPSCR:"):
# out_file.write(",FPSCR=" + line[pos+7:pos+17])
# pos += 19
# elif reg_id.startswith("CR:"):
# out_file.write(",CR=" + line[pos+4:pos+14])
# pos += 17
# elif reg_id.startswith("VE)"):
# out_file.write("round=VEN" + line[pos+4:pos+20])
# pos += 17
# elif reg_id.startswith("TN)"):
# out_file.write("round=RTN" + line[pos+4:pos+20])
# pos += 17
# elif reg_id.startswith("TZ)"):
# out_file.write("round=RTZ" + line[pos+4:pos+20])
# pos += 17
# elif reg_id.startswith("NI)"):
# out_file.write("round=RNI" + line[pos+4:pos+20])
# pos += 17
# elif reg_id.startswith("PI)"):
# out_file.write("round=RPI" + line[pos+4:pos+20])
# pos += 17
# else:
# out_file.write("Unknown reg ID" + reg_id)
# break
if p.group(3) != None:
out_file.write(",%s=%s" % (p.group(3), p.group(4)))
if p.group(5) != None:
out_file.write(",%s=%s" % (p.group(5), p.group(6)))
if p.group(7) != None:
out_file.write(",%s=%s" % (p.group(7), p.group(8)))
if p.group(9) != None:
out_file.write(",%s=%s" % (p.group(9), p.group(10)))
out_file.write("\n")
out_file.write(",FPSCR=%s" % p.group(11))
out_file.write(",CR=%s" % p.group(12))
out_file.write("\n")
else:
print("Warning: line: [%d] \"%s\"\n" % (lineno, line))
+4
View File
@@ -407,6 +407,10 @@
0xFFF00100,0x7D453D2A,stswx,r10,r5,r7
0xFFF00100,0x7C0002E4,tlbia
0xFFF00100,0x7C004A64,tlbie,r9
0xFFF00100,0x7C202FA4,tlbld,r5
0xFFF00100,0x7C6007A4,tlbld,r0
0xFFF00100,0x7C203FE4,tlbli,r7
0xFFF00100,0x7C40FFE4,tlbli,r31
# various simplified (extended) mnemonics
0xFFF00100,0x60000000,nop
1 # Test data for PowerPC disassembler supplied as comma-separated values
407 0xFFF00100,0x7C430C32,rrib,r3,r2,r1 0xFFF00100,0x7C00003A,maskg,r0,r0,r0
408 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1 0xFFF00100,0x7E3EE43A,maskir,r30,r17,r28
409 0xFFF00100,0x7C410132,sle,r1,r2,r0 0xFFF00100,0x58411800,rlmi,r1,r2,r3,0,0
410 0xFFF00100,0x58411801,rlmi.,r1,r2,r3,0,0
411 0xFFF00100,0x7C430C32,rrib,r3,r2,r1
412 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1
413 0xFFF00100,0x7C410132,sle,r1,r2,r0
414 0xFFF00100,0x7C410133,sle.,r1,r2,r0
415 0xFFF00100,0x7C4101B2,sleq,r1,r2,r0
416 0xFFF00100,0x7C4101B3,sleq.,r1,r2,r0
+2015 -2015
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+92 -58
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,25 +21,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "../ppcdisasm.h"
#include "../ppcemu.h"
#include <cfenv>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int ntested; /* number of tested instructions */
int nfailed; /* number of failed instructions */
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;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_cur_instruction = opcode;
ppc_main_opcode();
ppc_main_opcode(ppc_opcode_grabber, opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++;
@@ -111,7 +118,7 @@ static void read_test_data() {
continue;
}
opcode = stoul(tokens[1], NULL, 16);
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
dest = 0;
src1 = 0;
@@ -121,15 +128,15 @@ static void read_test_data() {
for (i = 2; i < tokens.size(); i++) {
if (tokens[i].rfind("rD=", 0) == 0) {
dest = stoul(tokens[i].substr(3), NULL, 16);
dest = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
} else if (tokens[i].rfind("rA=", 0) == 0) {
src1 = stoul(tokens[i].substr(3), NULL, 16);
src1 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
} else if (tokens[i].rfind("rB=", 0) == 0) {
src2 = stoul(tokens[i].substr(3), NULL, 16);
src2 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
} else if (tokens[i].rfind("XER=", 0) == 0) {
check_xer = stoul(tokens[i].substr(4), NULL, 16);
check_xer = (uint32_t)stoul(tokens[i].substr(4), NULL, 16);
} else if (tokens[i].rfind("CR=", 0) == 0) {
check_cr = stoul(tokens[i].substr(3), NULL, 16);
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
} else {
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
<< endl;
@@ -143,9 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0;
ppc_cur_instruction = opcode;
ppc_main_opcode();
ppc_main_opcode(ppc_opcode_grabber, opcode);
ntested++;
@@ -164,14 +169,38 @@ static void read_test_data() {
}
}
double double_from_string(string str) {
if (str == "snan")
return std::numeric_limits<double>::signaling_NaN();
if (str == "qnan")
return std::numeric_limits<double>::quiet_NaN();
if (str == "-FLT_MAX")
return -std::numeric_limits<float>::max();
if (str == "-FLT_MIN")
return -std::numeric_limits<float>::min();
if (str == "-DBL_MAX")
return -std::numeric_limits<double>::max();
if (str == "-DBL_MIN")
return -std::numeric_limits<double>::min();
if (str == "FLT_MIN")
return std::numeric_limits<float>::min();
if (str == "FLT_MAX")
return std::numeric_limits<float>::max();
if (str == "DBL_MIN")
return std::numeric_limits<double>::min();
if (str == "DBL_MAX")
return std::numeric_limits<double>::max();
return stod(str, NULL);
}
static void read_test_float_data() {
string line, token;
int i, lineno;
uint32_t opcode, dest, src1, src2, check_xer, check_cr, check_fpscr;
uint64_t dest_64, src1_64, src2_64;
uint32_t opcode, src1, src2, check_cr, check_fpscr;
uint64_t dest_64;
//float sfp_dest, sfp_src1, sfp_src2, sfp_src3;
double dfp_dest, dfp_src1, dfp_src2, dfp_src3;
double dfp_src1, dfp_src2, dfp_src3;
string rounding_mode;
ifstream tf2stream("ppcfloattests.csv");
@@ -186,7 +215,7 @@ static void read_test_float_data() {
lineno++;
if (line.empty() || !line.rfind("#", 0))
continue; /* skip empty/comment lines */
continue; // skip empty/comment lines
istringstream lnstream(line);
@@ -201,54 +230,35 @@ static void read_test_float_data() {
continue;
}
opcode = stoul(tokens[1], NULL, 16);
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
src1 = 0;
src2 = 0;
check_xer = 0;
check_cr = 0;
check_fpscr = 0;
//sfp_dest = 0.0;
//sfp_src1 = 0.0;
//sfp_src2 = 0.0;
//sfp_src3 = 0.0;
dfp_dest = 0.0;
dfp_src1 = 0.0;
dfp_src2 = 0.0;
dfp_src3 = 0.0;
dest_64 = 0;
// switch to default rounding
fesetround(FE_TONEAREST);
for (i = 2; i < tokens.size(); i++) {
if (tokens[i].rfind("frD=", 0) == 0) {
dest_64 = stoull(tokens[i].substr(4), NULL, 16);
} else if (tokens[i].rfind("frA=", 0) == 0) {
dfp_src1 = stod(tokens[i].substr(4), NULL);
dfp_src1 = double_from_string(tokens[i].substr(4));
} else if (tokens[i].rfind("frB=", 0) == 0) {
dfp_src2 = stod(tokens[i].substr(4), NULL);
dfp_src2 = double_from_string(tokens[i].substr(4));
} else if (tokens[i].rfind("frC=", 0) == 0) {
dfp_src3 = stod(tokens[i].substr(4), NULL);
dfp_src3 = double_from_string(tokens[i].substr(4));
} else if (tokens[i].rfind("round=", 0) == 0) {
rounding_mode = tokens[i].substr(6, 3);
ppc_state.fpscr = 0;
if (rounding_mode.compare("RTN") == 0) {
ppc_state.fpscr = 0x0;
} else if (rounding_mode.compare("RTZ") == 0) {
ppc_state.fpscr = 0x1;
} else if (rounding_mode.compare("RPI") == 0) {
ppc_state.fpscr = 0x2;
} else if (rounding_mode.compare("RNI") == 0) {
ppc_state.fpscr = 0x3;
} else if (rounding_mode.compare("VEN") == 0) {
ppc_state.fpscr = FPSCR::VE;
} else {
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
<< ". Exiting..." << endl;
exit(0);
}
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
check_fpscr = (uint32_t)stoul(tokens[i].substr(6), NULL, 16);
} else if (tokens[i].rfind("CR=", 0) == 0) {
check_cr = stoul(tokens[i].substr(3), NULL, 16);
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
} else {
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
<< endl;
@@ -256,28 +266,47 @@ static void read_test_float_data() {
}
}
if (rounding_mode.compare("RTN") == 0) {
update_fpscr(0);
} else if (rounding_mode.compare("RTZ") == 0) {
update_fpscr(1);
} else if (rounding_mode.compare("RPI") == 0) {
update_fpscr(2);
} else if (rounding_mode.compare("RNI") == 0) {
update_fpscr(3);
} else if (rounding_mode.compare("VEN") == 0) {
update_fpscr(FPSCR::VE);
} else {
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
<< ". Exiting..." << endl;
exit(0);
}
ppc_state.gpr[3] = src1;
ppc_state.gpr[4] = src2;
ppc_state.fpr[3].dbl64_r = dfp_src1;
ppc_state.fpr[4].dbl64_r = dfp_src2;
ppc_state.fpr[5].dbl64_r = dfp_src3;
ppc_state.fpr[3].dbl64_r = 0;
ppc_state.fpr[4].dbl64_r = dfp_src1;
ppc_state.fpr[5].dbl64_r = dfp_src2;
ppc_state.fpr[6].dbl64_r = dfp_src3;
ppc_state.cr = 0;
ppc_state.cr = 0;
ppc_cur_instruction = opcode;
ppc_main_opcode();
ppc_main_opcode(ppc_opcode_grabber, opcode);
ntested++;
// switch to default rounding
fesetround(FE_TONEAREST);
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x"
<< hex << check_cr << endl;
<< hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -288,7 +317,12 @@ static void read_test_float_data() {
}
int main() {
initialize_ppc_opcode_tables(); //kludge
is_601 = true;
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
int new_msr = (MSR::ME | MSR::IP | MSR::FP);
ppc_msr_did_change(ppc_state.msr, new_msr, false);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+6 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -65,15 +65,15 @@ static vector<PPCDisasmContext> read_test_data() {
}
ctx = {0};
ctx.instr_addr = stoul(tokens[0], NULL, 16);
ctx.instr_code = stoul(tokens[1], NULL, 16);
ctx.instr_addr = (uint32_t)stoul(tokens[0], NULL, 16);
ctx.instr_code = (uint32_t)stoul(tokens[1], NULL, 16);
/* build disassembly string out of comma-separated parts */
ostringstream idisasm;
/* put instruction mnemonic padded with trailing spaces */
idisasm << tokens[2];
idisasm << setw(8 - tokens[2].length()) << "";
idisasm << setw(streamsize(8) - (int)tokens[2].length()) << " ";
/* now add comma-separated operands */
for (i = 3; i < tokens.size(); i++) {
+2 -1
View File
@@ -2,6 +2,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_library(debugger OBJECT ${SOURCES})
+597 -109
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,12 +19,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/memaccess.h>
#include <core/timermanager.h>
#include <cpu/ppc/ppcdisasm.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ofnvram.h>
#include "memaccess.h"
#include <utils/profiler.h>
#include <array>
@@ -50,9 +52,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define COUTX uppercase << hex
#define COUT0_X(w) setfill('0') << setw(w) << right << COUTX
#define COUT016X COUT0_X(16)
#define COUT08X COUT0_X(8)
#define COUT04X COUT0_X(4)
extern bool g_auto_grab_mouse;
static uint32_t str2addr(string& addr_str) {
try {
return stoul(addr_str, NULL, 0);
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + addr_str);
}
@@ -60,7 +70,7 @@ static uint32_t str2addr(string& addr_str) {
static uint32_t str2num(string& num_str) {
try {
return stol(num_str, NULL, 0);
return static_cast<uint32_t>(stol(num_str, NULL, 0));
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + num_str);
}
@@ -68,62 +78,78 @@ static uint32_t str2num(string& num_str) {
static void show_help() {
cout << "Debugger commands:" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GRPs" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GPRs" << endl;
cout << " fregs -- dump content of the FPRs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " setmem X=V.T -- set memory at address X to value V of size T" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " regions -- dump memory regions" << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
#ifdef PROFILER
cout << " profiler -- show stats related to the processor" << endl;
cout << " profiler -- show stats related to the processor" << endl;
#endif
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
#ifdef ENABLE_68K_DEBUGGER
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
#endif
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << " quit -- quit the debugger" << endl << endl;
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl;
cout << " autograbmouse H -- auto grab the mouse if H is not zero." << endl;
cout << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
cout << "Pressing ENTER will repeat last command." << endl;
}
#ifdef ENABLE_68K_DEBUGGER
static void disasm_68k(uint32_t count, uint32_t address) {
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle;
uint8_t code[10];
uint8_t code[12]{};
size_t code_size;
uint64_t dis_addr;
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
cout << "Capstone initialization error" << endl;
return;
return address;
}
cs_insn* insn = cs_malloc(cs_handle);
for (; count > 0; count--) {
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
for (; power_on && count > 0; count--) {
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1);
try {
code[i] = mem_read_dbg(address + i, 1);
}
catch(...) {
printf("<memerror>");
}
}
const uint8_t *code_ptr = code;
@@ -137,26 +163,27 @@ static void disasm_68k(uint32_t count, uint32_t address) {
}
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
cout << uppercase << hex << insn->address << " ";
cout << COUTX << insn->address << " ";
cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
address = dis_addr;
cout << setw(10) << left << insn->mnemonic << insn->op_str << right << endl;
address = static_cast<uint32_t>(dis_addr);
} else {
print_bin:
cout << uppercase << hex << address << " ";
cout << COUTX << address << " ";
cout << setfill(' ');
cout << setw(10) << left << "dc.w" << "$" << hex <<
((code[0] << 8) | code[1]) << endl;
((code[0] << 8) | code[1]) << right << endl;
address += 2;
}
}
cs_free(insn, 1);
cs_close(&cs_handle);
return address;
}
/* emulator opcode table size --> 512 KB */
#define EMU_68K_TABLE_SIZE 0x80000
constexpr auto EMU_68K_TABLE_SIZE = 0x80000;
/** Execute one emulated 68k instruction. */
void exec_single_68k()
@@ -165,26 +192,26 @@ void exec_single_68k()
/* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */
cur_68k_pc = get_reg(string("R24")) - 2;
cur_68k_pc = static_cast<uint32_t>(get_reg(string("R24")) - 2);
/* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
/* calculate address of the current opcode table entry as follows:
get_word(68k_PC) * entry_size + table_base */
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(NO_OPCODE, cur_68k_pc) * 8 + emu_table_virt;
/* grab the PPC PC too */
ppc_pc = get_reg(string("PC"));
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
/* because the first two PPC instructions for each emulated 68k once
/* because the first two PPC instructions for each emulated 68k opcode
are resided in the emulator opcode table, we need to execute them
one by one until the execution goes outside the opcode table. */
while (ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single();
ppc_pc = get_reg(string("PC"));
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
}
/* Getting here means we're outside the emualtor opcode table.
@@ -199,8 +226,8 @@ void exec_until_68k(uint32_t target_addr)
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
while (target_addr != (get_reg(string("R24")) - 2)) {
ppc_pc = get_reg(string("PC"));
while (power_on && target_addr != (get_reg(string("R24")) - 2)) {
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
ppc_exec_single();
@@ -217,21 +244,22 @@ void print_68k_regs()
for (i = 0; i < 8; i++) {
reg = "R" + to_string(i + 8);
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " D" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
for (i = 0; i < 7; i++) {
reg = "R" + to_string(i + 16);
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
cout << " A" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
}
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
cout << " A7 : " << COUT08X << get_reg(string("R1")) << endl;
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
cout << " PC : " << COUT08X << get_reg(string("R24")) - 2 << endl;
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << " SR : " << COUT08X << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
cout << " CCR : " << COUT08X << get_reg(string("R26")) << endl;
cout << dec << setfill(' ');
}
#endif // ENABLE_68K_DEBUGGER
@@ -317,8 +345,7 @@ static void dump_mem(string& params) {
cout << (char)val;
chars_per_line += cell_size;
} else {
cout << setw(cell_size * 2) << setfill('0') << right;
cout << uppercase << hex << val << " ";
cout << COUT0_X(cell_size * 2) << val << " ";
chars_per_line += cell_size * 2 + 2;
}
}
@@ -330,28 +357,232 @@ static void dump_mem(string& params) {
cout << endl << endl;
}
static void disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
static void patch_mem(string& params) {
int value_size = 1;
uint32_t addr, value;
string addr_str, value_str, size_str;
ctx.instr_addr = address;
ctx.simplified = true;
if (params.find_first_of("=") == std::string::npos) {
cout << "setmem: not enough arguments specified. Try 'help'." << endl;
return;
}
for (int i = 0; i < count; i++) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << uppercase << hex << ctx.instr_addr;
cout << " " << disassemble_single(&ctx) << endl;
addr_str = params.substr(0, params.find_first_of("="));
value_str = params.substr(params.find_first_of("=") + 1);
if (value_str.find_first_of(".") == std::string::npos) {
cout << "setmem: no value size specified. Try 'help'." << endl;
return;
}
size_str = value_str.substr(value_str.find_first_of(".") + 1);
value_str = value_str.substr(0, value_str.find_first_of("."));
switch (size_str.back()) {
case 'b':
case 'B':
value_size = 1;
break;
case 'w':
case 'W':
value_size = 2;
break;
case 'd':
case 'D':
value_size = 4;
break;
case 'q':
case 'Q':
value_size = 8;
break;
case 'c':
case 'C':
value_size = 1;
break;
default:
cout << "Invalid value size " << size_str << endl;
return;
}
try {
addr = str2addr(addr_str);
} catch (invalid_argument& exc) {
try {
// number conversion failed, trying reg name
addr = get_reg(addr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
}
try {
value = str2num(value_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
try {
mem_write_dbg(addr, value, value_size);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
}
static uint32_t disasm(PPCDisasmContext &ctx) {
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
bool needs_swap = false;
if (mem_ctrl_instance != nullptr)
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
#endif
uint8_t* real_addr = mmu_translate_imem(ctx.instr_addr);
ctx.instr_code =
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
needs_swap ? READ_DWORD_LE_A(real_addr) :
#endif
READ_DWORD_BE_A(real_addr);
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << dec;
return ctx.instr_addr;
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
ctx.instr_addr = address;
ctx.simplified = true;
for (int i = 0; power_on && i < count; i++) {
disasm(ctx);
cout << endl;
}
return ctx.instr_addr;
}
static void disasm_in(PPCDisasmContext &ctx, uint32_t address) {
ctx.instr_addr = address;
ctx.simplified = true;
disasm(ctx);
if (ctx.regs_in.size() > 0 || ctx.regs_out.size() > 0) {
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
}
}
static void disasm_out(PPCDisasmContext &ctx) {
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
cout << endl;
}
#ifdef LOG_INSTRUCTIONS
void dumpinstructionlog(uint64_t num) {
if (InstructionNumber == 0)
return;
if (num > InstructionNumber) {
num = InstructionNumber;
}
if (num > InstructionLogSize) {
num = InstructionLogSize;
}
printf("Dumping last %llu of %llu instructions:\n", num, InstructionNumber);
uint64_t i, end;
i = (InstructionNumber - num) & (InstructionLogSize - 1);
end = (InstructionNumber) & (InstructionLogSize - 1);
do {
if (!power_on)
break;
InstructionRec * irec = &InstructionLog[i];
PPCDisasmContext ctx;
ctx.kinds = 0;
ctx.level = 0;
ctx.simplified = true;
ctx.instr_code = irec->ins;
ctx.instr_addr = irec->addr;
std::string name = get_name(irec->addr, irec->paddr, nullptr, nullptr, 0);
cout << COUT08X << ctx.instr_addr;
if (irec->paddr != irec->addr) {
cout << "->" << COUT08X << irec->paddr;
}
if (!name.empty()) {
cout << " " << setw(27) << left << setfill(' ') << name;
}
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << dec;
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
bool got_msr = false;
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":";
if (reg_name == "msr") {
cout << irec->msr;
got_msr = true;
}
else
cout << "?";
}
cout << " }" << dec;
}
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << "?";
}
cout << " }" << dec;
}
if (!got_msr) {
cout << " misc{" << COUTX;
cout << " " << "msr" << ":";
cout << irec->msr;
cout << " }" << dec;
}
cout << endl;
i++;
if (i >= InstructionLogSize)
i = 0;
} while (i != end);
}
#endif
static void print_gprs() {
string reg_name;
int i;
for (i = 0; i < 32; i++) {
reg_name = "R" + to_string(i);
reg_name = "r" + to_string(i);
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name);
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
COUT08X << get_reg(reg_name) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -360,11 +591,11 @@ static void print_gprs() {
}
}
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
array<string, 8> sprs = {"pc", "lr", "cr", "ctr", "xer", "msr", "srr0", "srr1"};
for (auto &spr : sprs) {
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr);
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
COUT08X << get_reg(spr) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -376,11 +607,71 @@ static void print_gprs() {
}
}
static void print_fprs() {
string reg_name;
for (int i = 0; i < 32; i++) {
reg_name = "f" + to_string(i);
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
COUT016X << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601;
static void print_mmu_regs()
{
printf(" msr : %08X\n", ppc_state.msr);
printf("\nBAT registers:\n");
for (int i = 0; i < 4 + (is_601 ? 0 : 4); i++) {
PPC_BAT_entry *bat_entry = i < 4 ? ibat_array : dbat_array;
bat_entry = &bat_entry[i & 3];
printf(" %sbat%du : %08X %sbat%dl : %08X",
is_601 ? "" : i < 4 ? "i" : "d",
i & 3, ppc_state.spr[528+i*2],
is_601 ? "" : i < 4 ? "i" : "d",
i & 3, ppc_state.spr[529+i*2]
);
if (!is_601 || bat_entry->valid) {
printf(" ; range : %08X..%08X -> %08X..%08X access : %s%s protection : %s%s",
bat_entry->bepi, bat_entry->bepi + ~bat_entry->hi_mask,
bat_entry->phys_hi, bat_entry->phys_hi + ~bat_entry->hi_mask,
bat_entry->access & 2 ? is_601 ? "Ks" : "Vs" : "__",
bat_entry->access & 1 ? is_601 ? "Ku" : "Vp" : "__",
bat_entry->prot & 2 ? "P" : "_",
bat_entry->prot & 1 ? "P" : "_"
);
if (is_601) {
printf(" (%s)", "valid");
}
} else {
printf(" ; range : %8s..%8s -> %8s..%8s access : %s%s protection : %s%s",
"", "", "", "", "__", "__", "_", "_"
);
printf(" (%s)", "invalid");
}
printf("\n");
}
printf("\n");
printf(" sdr1 : %08X\n", ppc_state.spr[SPR::SDR1]);
printf("\nSegment registers:\n");
for (int i = 0; i < 16; i++) {
printf(" %ssr%d : %08X\n", (i < 10) ? " " : "", i, ppc_state.sr[i]);
}
}
#ifndef _WIN32
#include <signal.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
static struct sigaction old_act_sigint, new_act_sigint;
static struct sigaction old_act_sigterm, new_act_sigterm;
@@ -402,42 +693,141 @@ static void mysig_handler(int signum)
}
#endif
void enter_debugger() {
static void delete_prompt() {
#ifndef _WIN32
// move up, carriage return (move to column 0), erase from cursor to end of line
cout << "\e[A\r\e[0K";
#endif
}
DppcDebugger::DppcDebugger() {
}
void DppcDebugger::enter_debugger() {
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
inst_string, inst_num_str, profile_name, sub_cmd;
uint32_t addr, inst_grab;
std::stringstream ss;
int log_level, context;
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;
int repeat_count = 0;
unique_ptr<OfNvramUtils> ofnvram = unique_ptr<OfNvramUtils>(new OfNvramUtils);
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
context = 1; /* start with the PowerPC context */
cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl;
#ifndef _WIN32
struct winsize win_size_previous;
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_previous);
#endif
while (1) {
cout << "dingusdbg> ";
if (power_off_reason == po_shut_down) {
set_power_off_reason(po_shutting_down);
break;
}
if (power_off_reason == po_restart) {
set_power_off_reason(po_restarting);
break;
}
if (power_off_reason == po_quit) {
set_power_off_reason(po_quitting);
break;
}
power_on = true;
/* reset string stream */
ss.str("");
ss.clear();
if (power_off_reason == po_starting_up) {
set_power_off_reason(po_none);
cmd = "go";
}
else if (power_off_reason == po_disassemble_on) {
inp = "si 1000000000";
ss.str("");
ss.clear();
ss.str(inp);
ss >> cmd;
}
else if (power_off_reason == po_disassemble_off) {
set_power_off_reason(po_none);
cmd = "go";
}
else
{
if (power_off_reason == po_enter_debugger) {
set_power_off_reason(po_entered_debugger);
}
if (!did_message) {
cout << endl;
cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl;
did_message = true;
}
cmd = "";
getline(cin, inp, '\n');
ss.str(inp);
ss >> cmd;
printf("%08X: dingusdbg> ", ppc_state.pc);
if (cmd.empty() && !last_cmd.empty()) {
while (power_on) {
/* reset string stream */
ss.str("");
ss.clear();
cmd = "";
std::cin.clear();
getline(cin, inp, '\n');
ss.str(inp);
ss >> cmd;
#ifndef _WIN32
struct winsize win_size_current;
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_current);
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
win_size_previous = win_size_current;
if (cmd.empty()) {
continue;
}
}
#endif
break;
}
}
if (power_off_reason == po_signal_interrupt) {
set_power_off_reason(po_enter_debugger);
// ignore command if interrupt happens because the input line is probably incomplete.
last_cmd = "";
continue;
}
if (feof(stdin)) {
printf("eof -> quit\n");
cmd = "quit";
}
cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) {
cmd = last_cmd;
cout << cmd << endl;
repeat_count++;
}
else {
repeat_count = 1;
}
if (cmd == "help") {
cmd = "";
show_help();
} else if (cmd == "quit") {
cmd = "";
break;
} else if (cmd == "restart") {
cmd = "";
power_off(po_restart);
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
ss >> profile_name;
@@ -450,6 +840,7 @@ void enter_debugger() {
}
}
else if (cmd == "regs") {
cmd = "";
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
print_68k_regs();
@@ -457,6 +848,12 @@ void enter_debugger() {
} else {
print_gprs();
}
} else if (cmd == "fregs") {
cmd = "";
print_fprs();
} else if (cmd == "mregs") {
cmd = "";
print_mmu_regs();
} else if (cmd == "set") {
ss >> expr_str;
@@ -501,21 +898,40 @@ void enter_debugger() {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
disasm_68k(1, addr);
exec_single_68k();
}
#endif
} else {
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
addr = ppc_state.pc;
PPCDisasmContext ctx;
disasm_in(ctx, addr);
ppc_exec_single();
disasm_out(ctx);
}
}
} else if (cmd == "next" || cmd == "ni") {
addr_str = "PC";
addr = get_reg(addr_str) + 4;
addr = static_cast<uint32_t>(get_reg(addr_str) + 4);
ppc_exec_until(addr);
} else if (cmd == "until") {
ss >> addr_str;
if (cmd_repeat) {
delete_prompt();
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
}
else {
ss >> addr_str;
}
try {
addr = str2addr(addr_str);
if (context == 2) {
@@ -529,8 +945,9 @@ void enter_debugger() {
cout << exc.what() << endl;
}
} else if (cmd == "go") {
cmd = "";
power_on = true;
ppc_exec(); // won't return!
ppc_exec();
} else if (cmd == "disas" || cmd == "da") {
expr_str = "";
ss >> expr_str;
@@ -569,10 +986,10 @@ void enter_debugger() {
try {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
disasm_68k(inst_grab, addr);
next_addr_68k = disasm_68k(inst_grab, addr);
#endif
} else {
disasm(inst_grab, addr);
next_addr_ppc = disasm(inst_grab, addr);
}
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
@@ -582,25 +999,64 @@ void enter_debugger() {
try {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
addr = next_addr_68k;
}
else {
addr_str = "R24";
addr = get_reg(addr_str);
disasm_68k(1, addr - 2);
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
}
next_addr_68k = disasm_68k(1, addr);
#endif
} else {
if (cmd_repeat) {
delete_prompt();
addr = next_addr_ppc;
}
else {
addr_str = "PC";
addr = get_reg(addr_str);
disasm(1, addr);
addr = static_cast<uint32_t>(get_reg(addr_str));
}
next_addr_ppc = disasm(1, addr);
}
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
}
#ifdef LOG_INSTRUCTIONS
} else if (cmd == "dumpinstructionlog") {
cmd = "";
uint64_t count;
expr_str = "";
ss >> expr_str;
if (expr_str.length() > 0) {
try {
count = str2num(expr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
count = 0;
}
} else {
count = InstructionNumber;
}
if (count)
dumpinstructionlog(count);
} else if (cmd == "clearinstructionlog") {
cmd = "";
InstructionNumber = 0;
#endif
} else if (cmd == "dump") {
expr_str = "";
ss >> expr_str;
dump_mem(expr_str);
} else if (cmd == "setmem") {
expr_str = "";
ss >> expr_str;
patch_mem(expr_str);
#ifdef ENABLE_68K_DEBUGGER
} else if (cmd == "context") {
cmd = "";
expr_str = "";
ss >> expr_str;
if (expr_str == "ppc" || expr_str == "PPC") {
@@ -611,19 +1067,33 @@ void enter_debugger() {
cout << "Unknown debugging context: " << expr_str << endl;
}
#endif
} else if (cmd == "regions") {
cmd = "";
if (mem_ctrl_instance)
mem_ctrl_instance->dump_regions();
} else if (cmd == "printenv") {
cmd = "";
if (ofnvram->init())
continue;
ofnvram->printenv();
} else if (cmd == "setenv") {
cmd = "";
string var_name, value;
ss >> var_name;
ss >> value;
if (ofnvram->init())
std::istream::sentry se(ss); // skip white space
getline(ss, value); // get everything up to eol
if (ofnvram->init()) {
cout << " Cannot open NVRAM" << endl;
continue;
ofnvram->setenv(var_name, value);
}
if (!ofnvram->setenv(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
#ifndef _WIN32
} else if (cmd == "nvedit") {
cmd = "";
cout << "===== press CNTRL-C to save =====" << endl;
// save original terminal state
@@ -673,6 +1143,7 @@ void enter_debugger() {
#endif
#ifdef DEBUG_CPU_INT
} else if (cmd == "amicint") {
cmd = "";
string value;
int irq_id;
ss >> value;
@@ -686,6 +1157,7 @@ void enter_debugger() {
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
int_ctrl->ack_int(irq_id, 1);
} else if (cmd == "viaint") {
cmd = "";
string value;
int irq_bit;
ss >> value;
@@ -695,13 +1167,29 @@ void enter_debugger() {
cout << exc.what() << endl;
continue;
}
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
ppc_state.pc -= 4;
via_obj->assert_int(irq_bit);
static TimerInfo viaint_timer;
TimerManager::get_instance()->add_oneshot_timer(viaint_timer, 0, [irq_bit](uint64_t, uint64_t){
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
via_obj->assert_int(irq_bit);
});
#endif
} else if (cmd == "autograbmouse") {
cmd = "";
string value;
int num;
ss >> value;
try {
num = str2num(value);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
continue;
}
g_auto_grab_mouse = num;
} else {
cout << "Unknown command: " << cmd << endl;
continue;
if (!cmd.empty()) {
cout << "Unknown command: " << cmd << endl;
cmd = "";
}
}
last_cmd = cmd;
}
+20 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,6 +22,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DEBUGGER_H_
#define DEBUGGER_H_
void enter_debugger(void);
#include <memory>
class DppcDebugger {
public:
static DppcDebugger* get_instance() {
if (!debugger_obj) {
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
}
void enter_debugger();
private:
inline static std::unique_ptr<DppcDebugger> debugger_obj{nullptr};
explicit DppcDebugger(); // private constructor to implement a singleton
};
#endif // DEBUGGER_H_
+42 -15
View File
@@ -1,21 +1,48 @@
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(PlatformGlob)
include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
)
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.h"
)
add_library(devices OBJECT ${SOURCES})
target_link_libraries(devices PRIVATE cubeb)
if (EMSCRIPTEN)
target_link_libraries(devices PRIVATE)
else()
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
endif()
-472
View File
@@ -1,472 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 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/>.
*/
/** ADB bus definitions
Simulates Apple Desktop Bus (ADB) bus
*/
#include <devices/common/adb/adb.h>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#if 0
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#include <thirdparty/SDL2/include/SDL_keycode.h>
#include <thirdparty/SDL2/include/SDL_mouse.h>
#include <thirdparty/SDL2/include/SDL_stdinc.h>
#endif
using namespace std;
ADB_Bus::ADB_Bus() {
// set data streams as clear
this->adb_mouse_register0 = 0x8080;
input_stream_len = 0;
output_stream_len = 2;
adb_keybd_register3 = 0x6201;
adb_mouse_register3 = 0x6302;
keyboard_access_no = adb_encoded;
mouse_access_no = adb_relative;
}
bool ADB_Bus::listen(int device, int reg) {
if (device == keyboard_access_no) {
if (adb_keybd_listen(reg)) {
return true;
} else {
return false;
}
} else if (device == mouse_access_no) {
if (adb_mouse_listen(reg)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
bool ADB_Bus::talk(int device, int reg, uint16_t value) {
// temp code
return false;
}
bool ADB_Bus::bus_reset() {
// temp code
return true;
}
bool ADB_Bus::set_addr(int dev_addr, int new_addr) {
// temp code
return false;
}
bool ADB_Bus::flush(int dev_addr) {
// temp code
return false;
}
bool ADB_Bus::adb_keybd_listen(int reg) {
if (reg == 3) {
output_data_stream[0] = (adb_keybd_register3 >> 8);
output_data_stream[1] = (adb_keybd_register3 & 0xff);
return true;
}
#if 0
while (SDL_PollEvent(&adb_keybd_evt)) {
// Poll our SDL key event for any keystrokes.
switch (adb_keybd_evt.type) {
case SDL_KEYDOWN:
switch (adb_keybd_evt.key.keysym.sym) {
case SDLK_a:
ask_key_pressed = 0x00;
break;
case SDLK_s:
ask_key_pressed = 0x01;
break;
case SDLK_d:
ask_key_pressed = 0x02;
break;
case SDLK_f:
ask_key_pressed = 0x03;
break;
case SDLK_h:
ask_key_pressed = 0x04;
break;
case SDLK_g:
ask_key_pressed = 0x05;
break;
case SDLK_z:
ask_key_pressed = 0x06;
break;
case SDLK_x:
ask_key_pressed = 0x07;
break;
case SDLK_c:
ask_key_pressed = 0x08;
break;
case SDLK_v:
ask_key_pressed = 0x09;
break;
case SDLK_b:
ask_key_pressed = 0x0B;
break;
case SDLK_q:
ask_key_pressed = 0x0C;
break;
case SDLK_w:
ask_key_pressed = 0x0D;
break;
case SDLK_e:
ask_key_pressed = 0x0E;
break;
case SDLK_r:
ask_key_pressed = 0x0F;
break;
case SDLK_y:
ask_key_pressed = 0x10;
break;
case SDLK_t:
ask_key_pressed = 0x11;
break;
case SDLK_1:
ask_key_pressed = 0x12;
break;
case SDLK_2:
ask_key_pressed = 0x13;
break;
case SDLK_3:
ask_key_pressed = 0x14;
break;
case SDLK_4:
ask_key_pressed = 0x15;
break;
case SDLK_6:
ask_key_pressed = 0x16;
break;
case SDLK_5:
ask_key_pressed = 0x17;
break;
case SDLK_EQUALS:
ask_key_pressed = 0x18;
break;
case SDLK_9:
ask_key_pressed = 0x19;
break;
case SDLK_7:
ask_key_pressed = 0x1A;
break;
case SDLK_MINUS:
ask_key_pressed = 0x1B;
break;
case SDLK_8:
ask_key_pressed = 0x1C;
break;
case SDLK_0:
ask_key_pressed = 0x1D;
break;
case SDLK_RIGHTBRACKET:
ask_key_pressed = 0x1E;
break;
case SDLK_o:
ask_key_pressed = 0x1F;
break;
case SDLK_u:
ask_key_pressed = 0x20;
break;
case SDLK_LEFTBRACKET:
ask_key_pressed = 0x21;
break;
case SDLK_i:
ask_key_pressed = 0x22;
break;
case SDLK_p:
ask_key_pressed = 0x23;
break;
case SDLK_RETURN:
ask_key_pressed = 0x24;
break;
case SDLK_l:
ask_key_pressed = 0x25;
break;
case SDLK_j:
ask_key_pressed = 0x26;
break;
case SDLK_QUOTE:
ask_key_pressed = 0x27;
break;
case SDLK_k:
ask_key_pressed = 0x28;
break;
case SDLK_SEMICOLON:
ask_key_pressed = 0x29;
break;
case SDLK_BACKSLASH:
ask_key_pressed = 0x2A;
break;
case SDLK_COMMA:
ask_key_pressed = 0x2B;
break;
case SDLK_SLASH:
ask_key_pressed = 0x2C;
break;
case SDLK_n:
ask_key_pressed = 0x2D;
break;
case SDLK_m:
ask_key_pressed = 0x2E;
break;
case SDLK_PERIOD:
ask_key_pressed = 0x2F;
break;
case SDLK_BACKQUOTE:
ask_key_pressed = 0x32;
break;
case SDLK_ESCAPE:
ask_key_pressed = 0x35;
break;
case SDLK_LEFT:
ask_key_pressed = 0x3B;
break;
case SDLK_RIGHT:
ask_key_pressed = 0x3C;
break;
case SDLK_DOWN:
ask_key_pressed = 0x3D;
break;
case SDLK_UP:
ask_key_pressed = 0x3E;
break;
case SDLK_KP_PERIOD:
ask_key_pressed = 0x41;
break;
case SDLK_KP_MULTIPLY:
ask_key_pressed = 0x43;
break;
case SDLK_KP_PLUS:
ask_key_pressed = 0x45;
break;
case SDLK_DELETE:
ask_key_pressed = 0x47;
break;
case SDLK_KP_DIVIDE:
ask_key_pressed = 0x4B;
break;
case SDLK_KP_ENTER:
ask_key_pressed = 0x4C;
break;
case SDLK_KP_MINUS:
ask_key_pressed = 0x4E;
break;
case SDLK_KP_0:
ask_key_pressed = 0x52;
break;
case SDLK_KP_1:
ask_key_pressed = 0x53;
break;
case SDLK_KP_2:
ask_key_pressed = 0x54;
break;
case SDLK_KP_3:
ask_key_pressed = 0x55;
break;
case SDLK_KP_4:
ask_key_pressed = 0x56;
break;
case SDLK_KP_5:
ask_key_pressed = 0x57;
break;
case SDLK_KP_6:
ask_key_pressed = 0x58;
break;
case SDLK_KP_7:
ask_key_pressed = 0x59;
break;
case SDLK_KP_8:
ask_key_pressed = 0x5B;
break;
case SDLK_KP_9:
ask_key_pressed = 0x5C;
break;
case SDLK_BACKSPACE:
// ask_key_pressed = 0x33;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x40;
break;
case SDLK_CAPSLOCK:
// ask_key_pressed = 0x39;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x20;
break;
case SDLK_RALT:
case SDLK_RCTRL: // Temp key for Control key
// ask_key_pressed = 0x36;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x8;
break;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
// ask_key_pressed = 0x38;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x4;
break;
case SDLK_LALT:
// ask_key_pressed = 0x3A;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x2;
break;
case SDLK_LCTRL: // Temp key for the Command/Apple key
// ask_key_pressed = 0x37;
confirm_ask_reg_2 = true;
mod_key_pressed = 0x1;
break;
default:
break;
}
if (adb_keybd_register0 & 0x8000) {
adb_keybd_register0 &= 0x7FFF;
adb_keybd_register0 &= (ask_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
} else if (adb_keybd_register0 & 0x80) {
adb_keybd_register0 &= 0xFF7F;
adb_keybd_register0 &= (ask_key_pressed);
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
}
// check if mod keys are being pressed
if (confirm_ask_reg_2) {
adb_keybd_register0 |= (mod_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register2 >> 8);
output_data_stream[1] = (adb_keybd_register2 & 0xff);
}
break;
case SDL_KEYUP:
if (!(adb_keybd_register0 & 0x8000)) {
adb_keybd_register0 |= 0x8000;
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
} else if (adb_keybd_register0 & 0x80)
adb_keybd_register0 |= 0x0080;
output_data_stream[0] = (adb_keybd_register0 >> 8);
output_data_stream[1] = (adb_keybd_register0 & 0xff);
if (confirm_ask_reg_2) {
adb_keybd_register2 &= (mod_key_pressed << 8);
output_data_stream[0] = (adb_keybd_register2 >> 8);
output_data_stream[1] = (adb_keybd_register2 & 0xff);
confirm_ask_reg_2 = false;
}
}
}
#endif
if ((reg != 1)) {
return true;
} else {
return false;
}
}
bool ADB_Bus::adb_mouse_listen(int reg) {
if ((reg != 0) | (reg != 3)) {
return false;
}
#if 0
while (SDL_PollEvent(&adb_mouse_evt)) {
if (adb_mouse_evt.motion.x) {
this->adb_mouse_register0 &= 0x7F;
if (adb_mouse_evt.motion.xrel < 0) {
if (adb_mouse_evt.motion.xrel <= -64) {
this->adb_mouse_register0 |= 0x7F;
} else if (adb_mouse_evt.motion.xrel >= 63) {
this->adb_mouse_register0 |= 0x3F;
} else {
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
}
}
}
if (adb_mouse_evt.motion.y) {
this->adb_mouse_register0 &= 0x7F00;
if (adb_mouse_evt.motion.yrel < 0) {
if (adb_mouse_evt.motion.yrel <= -64) {
this->adb_mouse_register0 |= 0x7F00;
} else if (adb_mouse_evt.motion.yrel >= 63) {
this->adb_mouse_register0 |= 0x3F00;
} else {
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
}
}
}
switch (adb_mouse_evt.type) {
case SDL_MOUSEBUTTONDOWN:
this->adb_mouse_register0 &= 0x7FFF;
case SDL_MOUSEBUTTONUP:
this->adb_mouse_register0 |= 0x8000;
}
}
#endif
if (reg == 0) {
output_data_stream[0] = (adb_mouse_register0 >> 8);
output_data_stream[1] = (adb_mouse_register0 & 0xff);
} else if (reg == 3) {
output_data_stream[0] = (adb_mouse_register3 >> 8);
output_data_stream[1] = (adb_mouse_register3 & 0xff);
}
return true;
}
uint8_t ADB_Bus::get_input_byte(int offset) {
return input_data_stream[offset];
}
uint8_t ADB_Bus::get_output_byte(int offset) {
return output_data_stream[offset];
}
int ADB_Bus::get_input_len() {
return input_stream_len;
}
int ADB_Bus::get_output_len() {
return output_stream_len;
}
-100
View File
@@ -1,100 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ADB_H
#define ADB_H
#include <cinttypes>
#if 0
#include <thirdparty/SDL2/include/SDL.h>
#include <thirdparty/SDL2/include/SDL_events.h>
#endif
enum adb_default_values {
adb_reserved0,
adb_reserved1,
adb_encoded,
adb_relative,
adb_absolute,
adb_reserved5,
adb_reserved6,
adb_reserved7,
adb_other8,
adb_other9,
adb_other10,
adb_other11,
adb_other12,
adb_other13,
adb_other14,
adb_other15
};
class ADB_Bus {
public:
ADB_Bus();
~ADB_Bus() = default;
bool listen(int device, int reg);
bool talk(int device, int reg, uint16_t value);
bool bus_reset();
bool set_addr(int dev_addr, int new_addr);
bool flush(int dev_addr);
bool adb_keybd_listen(int reg);
bool adb_mouse_listen(int reg);
uint8_t get_input_byte(int offset);
uint8_t get_output_byte(int offset);
int get_input_len();
int get_output_len();
private:
int keyboard_access_no;
int mouse_access_no;
// Keyboard Variables
uint16_t adb_keybd_register0;
uint16_t adb_keybd_register2;
uint16_t adb_keybd_register3;
//SDL_Event adb_keybd_evt;
uint8_t ask_key_pressed;
uint8_t mod_key_pressed;
bool confirm_ask_reg_2;
// Mouse Variables
//SDL_Event adb_mouse_evt;
uint16_t adb_mouse_register0;
uint16_t adb_mouse_register3;
uint8_t input_data_stream[16]; // temp buffer
int input_stream_len;
uint8_t output_data_stream[16]; // temp buffer
int output_stream_len;
};
#endif /* ADB_H */
+97
View File
@@ -0,0 +1,97 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @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->aj_buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->aj_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->aj_buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
}
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->aj_buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = uint8_t(~this->aj_buttons_state >> 8);
out_buf[3] = ~this->aj_buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
}
return changed;
}
void AdbAppleJack::set_register_3() {
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, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+60
View File
@@ -0,0 +1,60 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @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 aj_buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
#endif // ADB_APPLEJACK_H
+139
View File
@@ -0,0 +1,139 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus emulation. */
#include <devices/common/adb/adbbus.h>
#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);
supports_types(HWCompType::ADB_HOST);
this->devices.clear();
}
int AdbBus::device_postinit() {
std::string adb_device_list = GET_STR_PROP("adb_devices");
if (adb_device_list.empty())
return 0;
std::string adb_device;
std::istringstream adb_device_stream(adb_device_list);
while (getline(adb_device_stream, adb_device, ',')) {
std::string dev_name = "Adb" + adb_device;
if (dev_name == this->name)
continue; // don't register a second ADB bus
if (DeviceRegistry::device_registered(dev_name)) {
gMachineObj->add_device(dev_name, DeviceRegistry::get_descriptor(dev_name).m_create_func());
} else {
LOG_F(WARNING, "Unknown specified ADB device \"%s\"", adb_device.c_str());
}
}
return 0;
}
void AdbBus::register_device(AdbDevice* dev_obj) {
this->devices.push_back(dev_obj);
}
uint8_t AdbBus::poll() {
for (auto dev : this->devices) {
uint8_t dev_poll = dev->poll();
if (dev_poll) {
return dev_poll;
}
}
return 0;
}
uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
uint8_t dev_addr, dev_reg;
this->output_count = 0;
if (!data_size)
return ADB_STAT_OK;
uint8_t cmd_byte = in_data[0];
uint8_t cmd = cmd_byte & 0xF;
if(!cmd) { // SendReset
LOG_F(9, "%s: SendReset issued", this->name.c_str());
for (auto dev : this->devices)
dev->reset();
} else if (cmd == 1) { // Flush
dev_addr = cmd_byte >> 4;
LOG_F(9, "%s: Flush issued, dev_addr=0x%X", this->name.c_str(), dev_addr);
} else if ((cmd & 0xC) == 8) { // Listen
dev_addr = cmd_byte >> 4;
dev_reg = cmd_byte & 3;
LOG_F(9, "%s: Listen R%d issued, dev_addr=0x%X", this->name.c_str(),
dev_reg, dev_addr);
this->input_buf = in_data + 1;
this->input_count = data_size - 1;
for (auto dev : this->devices)
dev->listen(dev_addr, dev_reg);
} else if ((cmd & 0xC) == 0xC) { // Talk
dev_addr = cmd_byte >> 4;
dev_reg = cmd_byte & 3;
LOG_F(9, "%s: Talk R%d issued, dev_addr=0x%X", this->name.c_str(),
dev_reg, dev_addr);
this->got_answer = false;
for (auto dev : this->devices) {
this->got_answer = dev->talk(dev_addr, dev_reg);
if (this->got_answer) {
break;
}
}
if (!this->got_answer)
return ADB_STAT_TIMEOUT;
} else {
LOG_F(ERROR, "%s: unsupported ADB command 0x%X", this->name.c_str(), cmd_byte);
}
return ADB_STAT_OK;
}
static const PropMap AdbBus_Properties = {
{"adb_devices", new StrProperty("Mouse,Keyboard")},
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, AdbBus_Properties, HWCompType::ADB_HOST
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+83
View File
@@ -0,0 +1,83 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus definitions. */
#ifndef ADB_BUS_H
#define ADB_BUS_H
#include <devices/common/hwcomponent.h>
#include <memory>
#include <string>
#include <vector>
constexpr auto ADB_MAX_DATA_SIZE = 8;
/** ADB status. */
enum {
ADB_STAT_OK = 0,
ADB_STAT_SRQ_ACTIVE = 1 << 0,
ADB_STAT_TIMEOUT = 1 << 1,
ADB_STAT_AUTOPOLL = 1 << 6,
ADB_STAT_RESPONSE = 1 << 7,
};
class AdbDevice; // forward declaration to prevent compiler errors
class AdbBus : public HWComponent {
public:
AdbBus(std::string name);
~AdbBus() = default;
static std::unique_ptr<HWComponent> create() {
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; }
// Polls devices that have a service request flag set. Returns the talk
// command corresponding to the first device that responded with data, or
// 0 if no device responded.
uint8_t poll();
// callbacks meant to be called by devices
const uint8_t* get_input_buf() { return this->input_buf; }
uint8_t* get_output_buf() { return this->output_buf; }
uint8_t get_input_count() { return this->input_count; }
void set_output_count(uint8_t count) { this->output_count = count; }
bool already_answered() { return this->got_answer; }
private:
std::vector<AdbDevice*> devices;
bool got_answer = false;
const uint8_t* input_buf = nullptr;
uint8_t output_buf[ADB_MAX_DATA_SIZE] = {};
uint8_t input_count = 0;
uint8_t output_count = 0;
};
#endif // ADB_BUS_H
+133
View File
@@ -0,0 +1,133 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Base class for Apple Desktop Bus devices. */
#include <loguru.hpp>
#include <core/timermanager.h>
#include <devices/common/adb/adbdevice.h>
#include <devices/common/adb/adbbus.h>
#include <machines/machinebase.h>
AdbDevice::AdbDevice(std::string name) {
this->set_name(name);
this->supports_types(HWCompType::ADB_DEV);
}
int AdbDevice::device_postinit() {
// register itself with the ADB host
this->host_obj = dynamic_cast<AdbBus*>(gMachineObj->get_comp_by_type(HWCompType::ADB_HOST));
this->host_obj->register_device(this);
return 0;
}
uint8_t AdbDevice::poll() {
if (!this->srq_flag) {
return 0;
}
bool has_data = this->get_register_0();
if (!has_data) {
return 0;
}
// Register 0 in bits 0-1 (both 0)
// Talk command in bits 2-3 (both 1)
// Device address in bits 4-7
return 0xC | (this->my_addr << 4);
}
bool AdbDevice::talk(const uint8_t dev_addr, const uint8_t reg_num) {
if (dev_addr == this->my_addr && !this->got_collision) {
// see if another device already responded to this command
if (this->host_obj->already_answered()) {
this->got_collision = true;
return false;
}
switch(reg_num & 3) {
case 0:
return this->get_register_0();
case 1:
return this->get_register_1();
case 2:
return this->get_register_2();
case 3:
return this->get_register_3();
default:
return false;
}
} else {
return false;
}
}
void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
if (dev_addr == this->my_addr) {
switch(reg_num & 3) {
case 0:
this->set_register_0();
break;
case 1:
this->set_register_1();
break;
case 2:
this->set_register_2();
break;
case 3:
if (this->host_obj->get_input_count() >= 2) // ensure we got enough data
this->set_register_3();
break;
}
}
}
bool AdbDevice::get_register_3() {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = this->gen_random_address() | (this->exc_event_flag << 6) |
(this->srq_flag << 5);
out_buf[1] = this->dev_handler_id;
this->host_obj->set_output_count(2);
return true;
}
void AdbDevice::set_register_3() {
const uint8_t* in_data = this->host_obj->get_input_buf();
uint8_t new_addr = in_data[0] & 0xF;
switch (in_data[1]) {
case 0:
this->my_addr = new_addr;
this->srq_flag = !!(in_data[0] & 0x20);
break;
case 0xFE: // move to a new address if there was no collision
if (!this->got_collision) {
this->my_addr = new_addr;
}
break;
default:
LOG_F(WARNING, "ADB Device: unknown handler ID = 0x%X", in_data[1]);
}
}
uint8_t AdbDevice::gen_random_address() {
return TimerManager::get_instance()->current_time_ns() & 0xF;
}
+79
View File
@@ -0,0 +1,79 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Base class for Apple Desktop Bus devices. */
#ifndef ADB_DEVICE_H
#define ADB_DEVICE_H
#include <devices/common/hwcomponent.h>
#include <string>
/** Common ADB device addresses/types. */
enum {
ADB_ADDR_KBD = 2, // keyboards
ADB_ADDR_RELPOS = 3, // relative position devices (mouse)
ADB_ADDR_ABSPOS = 4, // absolute position devices (graphic tablets)
};
class AdbBus; // forward declaration to prevent compiler errors
class AdbDevice : public HWComponent {
public:
AdbDevice(std::string name);
~AdbDevice() = default;
int device_postinit() override;
virtual void reset() = 0;
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
virtual uint8_t get_address() { return this->my_addr; }
// Attempts to poll the device. Returns the talk command corresponding to
// the device if it has data, 0 otherwise.
uint8_t poll();
protected:
uint8_t gen_random_address();
virtual bool get_register_0() { return false; }
virtual bool get_register_1() { return false; }
virtual bool get_register_2() { return false; }
virtual bool get_register_3();
virtual void set_register_0() {}
virtual void set_register_1() {}
virtual void set_register_2() {}
virtual void set_register_3();
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
uint8_t led_state = 0;
uint8_t my_addr = 0;
uint8_t dev_handler_id = 0;
bool got_collision = false;
AdbBus* host_obj = nullptr;
};
#endif // ADB_DEVICE_H
+158
View File
@@ -0,0 +1,158 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus Keyboard emulation. */
#include <devices/common/adb/adbkeyboard.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <loguru.hpp>
AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
EventManager::get_instance()->add_keyboard_handler(this, &AdbKeyboard::event_handler);
this->reset();
}
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
this->keys_down.set(event.key, !(event.flags & KEYBOARD_EVENT_UP));
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
if (this->pending_events.size() == 1) {
this->srq_flag = 1;
}
}
void AdbKeyboard::reset() {
this->my_addr = ADB_ADDR_KBD;
this->dev_handler_id = 2; // Extended ADB keyboard
this->exc_event_flag = 1;
this->srq_flag = 0; // don't process keyboard service requests yet
this->led_state = 7; // LEDs off (active low)
this->pending_events.clear();
this->keys_down.reset();
}
bool AdbKeyboard::get_register_0() {
if (this->pending_events.empty()) {
return false;
}
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = this->consume_pending_event();
out_buf[1] = this->consume_pending_event();
this->host_obj->set_output_count(2);
if (this->pending_events.empty()) {
this->srq_flag = 0;
}
return true;
}
uint8_t AdbKeyboard::consume_pending_event() {
if (this->pending_events.empty()) {
// In most cases we have only one pending event when the host polls us,
// but we need to fill two entries of the output buffer. We need to set
// the key status bit to 1 (released), and the key to a non-existent
// one (0x7F). Otherwise if we leave it empty, the host will think that
// the 'a' key (code 0) is pressed (status 0).
return 0xFF;
}
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
this->pending_events.pop_front();
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
if (this->dev_handler_id != 3) {
switch (event->key) {
case AdbKey_RightControl : event->key = AdbKey_Control; break;
case AdbKey_RightShift : event->key = AdbKey_Shift ; break;
case AdbKey_RightOption : event->key = AdbKey_Option ; break;
}
}
return (key_state << 7) | (event->key & 0x7F);
}
bool AdbKeyboard::get_register_2() {
// Register 2 reflects the current modifier keys, and a zero value means
// that the key is held down.
static const struct {
uint8_t key;
uint8_t bit;
} reg2_keys[] = {
{ AdbKey_Delete, 14 },
{ AdbKey_CapsLock, 13 },
{ AdbKey_Power, 12 },
{ AdbKey_Control, 11 },
{ AdbKey_RightControl, 11 },
{ AdbKey_Shift, 10 },
{ AdbKey_RightShift, 10 },
{ AdbKey_Option, 9 },
{ AdbKey_RightOption, 9 },
{ AdbKey_Command, 8 },
{ AdbKey_KeypadClear, 7 },
{ AdbKey_F14, 6 }, // Scroll Lock
};
uint16_t reg2 = 0xFFF8 | this->led_state;
for (const auto& key : reg2_keys) {
if (this->keys_down[key.key])
reg2 &= ~(1 << key.bit);
}
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = reg2 >> 8;
out_buf[1] = reg2 & 0xFF;
this->host_obj->set_output_count(2);
return true;
}
void AdbKeyboard::set_register_2() {
if (this->host_obj->get_input_count() < 2)
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
this->led_state = in_data[1] & 0x07;
}
void AdbKeyboard::set_register_3() {
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case 1:
case 2:
this->dev_handler_id = in_data[1];
break;
case 3: // extended keyboard protocol isn't supported yet
break;
default:
this->AdbDevice::set_register_3();
}
}
static const DeviceDescription AdbKeyboard_Descriptor = {
AdbKeyboard::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
+188
View File
@@ -0,0 +1,188 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus Keyboard definitions. */
#ifndef ADB_KEYBOARD_H
#define ADB_KEYBOARD_H
#include <devices/common/adb/adbdevice.h>
#include <devices/common/hwcomponent.h>
#include <bitset>
#include <deque>
#include <memory>
#include <string>
class KeyboardEvent;
class AdbKeyboard : public AdbDevice {
public:
AdbKeyboard(std::string name);
~AdbKeyboard() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbKeyboard>(new AdbKeyboard("ADB-KEYBOARD"));
}
void reset() override;
void event_handler(const KeyboardEvent& event);
bool get_register_0() override;
bool get_register_2() override;
void set_register_2() override;
void set_register_3() override;
private:
std::deque<std::unique_ptr<KeyboardEvent>> pending_events;
std::bitset<128> keys_down;
uint8_t consume_pending_event();
};
// ADB Extended Keyboard raw key codes (most of which eventually became virtual
// key codes, see HIToolbox/Events.h).
enum AdbKey {
AdbKey_A = 0x00,
AdbKey_B = 0x0b,
AdbKey_C = 0x08,
AdbKey_D = 0x02,
AdbKey_E = 0x0e,
AdbKey_F = 0x03,
AdbKey_G = 0x05,
AdbKey_H = 0x04,
AdbKey_I = 0x22,
AdbKey_J = 0x26,
AdbKey_K = 0x28,
AdbKey_L = 0x25,
AdbKey_M = 0x2e,
AdbKey_N = 0x2d,
AdbKey_O = 0x1f,
AdbKey_P = 0x23,
AdbKey_Q = 0x0c,
AdbKey_R = 0x0f,
AdbKey_S = 0x01,
AdbKey_T = 0x11,
AdbKey_U = 0x20,
AdbKey_V = 0x09,
AdbKey_W = 0x0d,
AdbKey_X = 0x07,
AdbKey_Y = 0x10,
AdbKey_Z = 0x06,
AdbKey_1 = 0x12,
AdbKey_2 = 0x13,
AdbKey_3 = 0x14,
AdbKey_4 = 0x15,
AdbKey_5 = 0x17,
AdbKey_6 = 0x16,
AdbKey_7 = 0x1a,
AdbKey_8 = 0x1c,
AdbKey_9 = 0x19,
AdbKey_0 = 0x1d,
AdbKey_Minus = 0x1b,
AdbKey_Equal = 0x18,
AdbKey_LeftBracket = 0x21,
AdbKey_RightBracket = 0x1e,
AdbKey_Backslash = 0x2a,
AdbKey_Semicolon = 0x29,
AdbKey_Quote = 0x27,
AdbKey_Comma = 0x2b,
AdbKey_Period = 0x2f,
AdbKey_Slash = 0x2c,
AdbKey_Tab = 0x30,
AdbKey_Return = 0x24,
AdbKey_Space = 0x31,
AdbKey_Delete = 0x33,
AdbKey_ForwardDelete = 0x75,
AdbKey_Help = 0x72,
AdbKey_Home = 0x73,
AdbKey_End = 0x77,
AdbKey_PageUp = 0x74,
AdbKey_PageDown = 0x79,
AdbKey_Grave = 0x32,
AdbKey_Escape = 0x35,
AdbKey_Control = 0x36,
AdbKey_Shift = 0x38,
AdbKey_Option = 0x3a,
AdbKey_Command = 0x37,
AdbKey_CapsLock = 0x39,
AdbKey_Power = 0x7f,
AdbKey_RightControl = 0x7d,
AdbKey_RightShift = 0x7b,
AdbKey_RightOption = 0x7c,
AdbKey_ArrowUp = 0x3e,
AdbKey_ArrowDown = 0x3d,
AdbKey_ArrowLeft = 0x3b,
AdbKey_ArrowRight = 0x3c,
AdbKey_Keypad0 = 0x52,
AdbKey_Keypad1 = 0x53,
AdbKey_Keypad2 = 0x54,
AdbKey_Keypad3 = 0x55,
AdbKey_Keypad4 = 0x56,
AdbKey_Keypad5 = 0x57,
AdbKey_Keypad6 = 0x58,
AdbKey_Keypad7 = 0x59,
AdbKey_Keypad9 = 0x5c,
AdbKey_Keypad8 = 0x5b,
AdbKey_KeypadDecimal = 0x41,
AdbKey_KeypadPlus = 0x45,
AdbKey_KeypadMinus = 0x4e,
AdbKey_KeypadMultiply = 0x43,
AdbKey_KeypadDivide = 0x4b,
AdbKey_KeypadEnter = 0x4c,
AdbKey_KeypadEquals = 0x51,
AdbKey_KeypadClear = 0x47,
AdbKey_F1 = 0x7a,
AdbKey_F2 = 0x78,
AdbKey_F3 = 0x63,
AdbKey_F4 = 0x76,
AdbKey_F5 = 0x60,
AdbKey_F6 = 0x61,
AdbKey_F7 = 0x62,
AdbKey_F8 = 0x64,
AdbKey_F9 = 0x65,
AdbKey_F10 = 0x6d,
AdbKey_F11 = 0x67,
AdbKey_F12 = 0x6f,
AdbKey_F13 = 0x69,
AdbKey_F14 = 0x6b,
AdbKey_F15 = 0x71,
AdbKey_ISO1= 0x0A,
AdbKey_JIS_Yen = 0x5D,
AdbKey_JIS_Underscore = 0x5E,
AdbKey_JIS_KP_Comma = 0x5F,
AdbKey_JIS_Eisu = 0x66,
AdbKey_JIS_Kana = 0x68,
};
#endif // ADB_KEYBOARD_H
+166
View File
@@ -0,0 +1,166 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus Mouse emulation. */
#include <core/memaccess.h>
#include <devices/common/adb/adbmouse.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <loguru.hpp>
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();
}
void AdbMouse::event_handler(const MouseEvent& event) {
if (event.flags & MOUSE_EVENT_MOTION) {
this->x_rel += event.xrel;
this->y_rel += event.yrel;
this->x_abs = event.xabs;
this->y_abs = event.yabs;
if (this->device_class == TABLET)
this->changed = true;
} else if (event.flags & MOUSE_EVENT_BUTTON) {
this->buttons_state = event.buttons_state & ((1 << this->num_buttons) - 1);
this->x_abs = event.xabs;
this->y_abs = event.yabs;
this->changed = true;
}
}
void AdbMouse::reset() {
this->my_addr = ADB_ADDR_RELPOS;
this->dev_handler_id = 1;
this->exc_event_flag = 1;
this->srq_flag = 1; // enable service requests
this->x_rel = 0;
this->y_rel = 0;
this->x_abs = 0;
this->y_abs = 0;
this->buttons_state = 0;
this->changed = false;
}
bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
uint8_t* p;
uint8_t* out_buf = this->host_obj->get_output_buf();
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
int num_bits, total_bits;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
num_bits = total_bits = 7;
} else {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
buttons = ~buttons;
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
: this->device_class == TABLET ? this->y_abs : this->y_rel;
if (val < (-1 << (bits - 1)))
val = -1 << (bits - 1);
else if (val >= (1 << (bits - 1)))
val = (1 << (bits - 1)) - 1;
int bits_remaining = total_bits;
p = &out_buf[axis];
int button = axis;
bits = 7;
while (bits_remaining > 0) {
*p = uint8_t((val & ((1 << bits) - 1)) | (((buttons >> button) & 1) << bits) | (*p << (bits + 1)));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
button += 2;
bits = 3;
}
}
// reset accumulated motion data and button change flag
this->x_rel = 0;
this->y_rel = 0;
this->changed = false;
uint8_t count = (uint8_t)(p - out_buf);
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
out_buf[0] = 'a';
out_buf[1] = 'p';
out_buf[2] = 'p';
out_buf[3] = 'l';
// Slightly higher resolution of 300 units per inch
WRITE_WORD_BE_A(&out_buf[4], resolution);
out_buf[6] = device_class;
out_buf[7] = num_buttons;
this->host_obj->set_output_count(8);
return true;
}
void AdbMouse::set_register_3() {
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case 1:
case 2:
case 4: // switch over to extended mouse protocol
this->dev_handler_id = in_data[1];
break;
default:
this->AdbDevice::set_register_3();
}
}
uint8_t AdbMouse::get_buttons_state() const {
return this->buttons_state;
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}, HWCompType::ADB_DEV
};
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
+89
View File
@@ -0,0 +1,89 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Apple Desktop Bus Mouse definitions. */
#ifndef ADB_MOUSE_H
#define ADB_MOUSE_H
#include <devices/common/adb/adbdevice.h>
#include <devices/common/hwcomponent.h>
#include <memory>
#include <string>
//#define ABSOLUTE
class MouseEvent;
class AdbMouse : public AdbDevice {
public:
enum DeviceClass {
TABLET = 0,
MOUSE = 1,
TRACKBALL = 2,
};
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() {
#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;
void event_handler(const MouseEvent& event);
bool get_register_0() override;
bool get_register_1() override;
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons, bool force);
uint8_t get_buttons_state() const;
private:
int32_t x_rel = 0;
int32_t y_rel = 0;
int32_t x_abs = 0;
int32_t y_abs = 0;
uint8_t buttons_state = 0;
bool changed = false;
uint8_t device_class;
int num_buttons;
int num_bits;
uint16_t resolution;
};
#endif // ADB_MOUSE_H
+290
View File
@@ -0,0 +1,290 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Basic ATA device emulation. */
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
#include <loguru.hpp>
#include <cstring>
#include <cinttypes>
using namespace ata_interface;
AtaBaseDevice::AtaBaseDevice(const std::string name, uint8_t type) {
this->set_name(name);
supports_types(HWCompType::IDE_DEV);
this->device_type = type;
device_reset(false);
device_set_signature();
}
void AtaBaseDevice::device_reset(bool is_soft_reset) {
LOG_F(INFO, "%s: %s-reset triggered", this->name.c_str(),
is_soft_reset ? "soft" : "hard");
// 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() {
this->r_sect_count = 1;
this->r_sect_num = 1;
this->r_dev_head = 0;
// set ATA protocol signature
this->r_cylinder_lo = 0;
this->r_cylinder_hi = 0;
this->r_status = DRDY | DSC; // DSC=1 is required for ATA devices
}
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (this->has_data()) {
uint16_t ret_data = this->get_data();
this->chunk_cnt -= 2;
if (this->chunk_cnt <= 0) {
this->xfer_cnt -= this->chunk_size;
if (this->xfer_cnt <= 0) {
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
} else {
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
if (!this->read_data_timer.active) {
TimerManager::get_instance()->add_oneshot_timer(this->read_data_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->update_intrq(1);
}
);
}
}
}
return ret_data;
} else {
return 0xFFFFU;
}
case ATA_Reg::ERROR:
return this->r_error;
case ATA_Reg::SEC_COUNT:
return this->r_sect_count;
case ATA_Reg::SEC_NUM:
return this->r_sect_num;
case ATA_Reg::CYL_LOW:
return this->r_cylinder_lo;
case ATA_Reg::CYL_HIGH:
return this->r_cylinder_hi;
case ATA_Reg::DEVICE_HEAD:
return this->r_dev_head;
case ATA_Reg::STATUS:
this->update_intrq(0);
return this->r_status;
case ATA_Reg::ALT_STATUS:
return this->r_status;
default:
LOG_F(WARNING, "Attempted to read unknown IDE register: %x", reg_addr);
return 0;
}
}
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (this->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;
//LOG_F(INFO, "%s: write complete", name.c_str());
if (this->write_done_timer.active)
LOG_F(ERROR, "%s: write_done_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(write_done_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->r_status &= ~BSY;
this->update_intrq(1);
}
);
} else {
this->cur_data_ptr = this->data_ptr;
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
if (this->write_more_timer.active)
LOG_F(ERROR, "%s: write_more_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(this->write_more_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->signal_data_ready();
}
);
}
}
}
break;
case ATA_Reg::FEATURES:
this->r_features = value;
break;
case ATA_Reg::SEC_COUNT:
this->r_sect_count = value;
break;
case ATA_Reg::SEC_NUM:
this->r_sect_num = value;
break;
case ATA_Reg::CYL_LOW:
this->r_cylinder_lo = value;
break;
case ATA_Reg::CYL_HIGH:
this->r_cylinder_hi = value;
break;
case ATA_Reg::DEVICE_HEAD:
this->r_dev_head = value;
break;
case ATA_Reg::COMMAND:
if ((this->r_status & BSY) != 0) {
LOG_F(ERROR, "%s: tried to perform command %x when busy", name.c_str(), value);
break;
}
this->r_command = value;
if (this->is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
}
break;
case ATA_Reg::DEV_CTRL:
this->device_control(value);
break;
default:
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
}
}
void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
// perform ATA Soft Reset if requested
if ((this->r_dev_ctrl ^ new_ctrl) & SRST) {
if (new_ctrl & SRST) { // SRST set -> phase 0 aka self-test
this->r_status |= BSY;
this->device_reset(true);
} else { // SRST cleared -> phase 1 aka signature and error report
if (!this->my_dev_id && this->host_obj->is_device1_present())
this->r_error |= 0x80;
this->device_set_signature();
this->r_status &= ~BSY;
if (this->my_dev_id && this->r_error == 1) {
this->host_obj->assert_pdiag();
}
}
}
this->r_dev_ctrl = new_ctrl;
}
int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
if (!this->xfer_cnt || !this->is_dma_xfer)
return 0;
int xfer_size = std::min(this->xfer_cnt, len);
if (this->xfer_cnt != len) {
LOG_F(9, "%s: DMA pull size differs from descriptor, remaining=%d requested=%d",
this->name.c_str(), this->xfer_cnt, len);
}
//for (int i = 0; i < xfer_size >> 1; i++)
// this->data_ptr[i] = BYTESWAP_16(this->data_ptr[i]);
std::memcpy(buf, this->data_ptr, xfer_size);
this->data_ptr = (uint16_t *)((uint8_t *)this->data_ptr + xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
this->is_dma_xfer = false;
this->data_ptr = nullptr;
if (this->dma_pull_timer.active)
LOG_F(ERROR, "%s: dma_pull_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(dma_pull_timer, 500, [this](uint64_t, uint64_t) {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
} else {
this->r_status &= ~BSY;
this->r_status |= DRQ;
}
return xfer_size;
}
int AtaBaseDevice::push_data(uint8_t *buf, int len) {
if (!this->xfer_cnt || !this->is_dma_xfer)
return 0;
int xfer_size = std::min(this->xfer_cnt, len);
std::memcpy(this->cur_data_ptr, buf, xfer_size);
this->cur_data_ptr = (uint16_t *)((uint8_t *)this->cur_data_ptr + xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
this->post_xfer_action();
this->is_dma_xfer = false;
this->data_ptr = nullptr;
this->cur_data_ptr = nullptr;
if (this->dma_push_timer.active)
LOG_F(ERROR, "%s: dma_push_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(dma_push_timer, 500, [this](uint64_t, uint64_t) {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
} else {
this->r_status &= ~BSY;
this->r_status |= DRQ;
}
return xfer_size;
}
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
return;
this->intrq_state = new_intrq_state;
this->host_obj->report_intrq(new_intrq_state);
}
void AtaBaseDevice::prepare_xfer(int xfer_size, int block_size) {
this->chunk_cnt = std::min(xfer_size, block_size);
this->xfer_cnt = xfer_size;
this->chunk_size = block_size;
}
void AtaBaseDevice::signal_data_ready() {
this->r_status |= DRQ;
this->r_status &= ~BSY;
this->update_intrq(1);
}
+120
View File
@@ -0,0 +1,120 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Base class for ATA devices. */
#ifndef ATA_BASE_DEVICE_H
#define ATA_BASE_DEVICE_H
#include <core/endianswap.h>
#include <core/timermanager.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/hwcomponent.h>
#include <cinttypes>
#include <string>
#include <functional>
class IdeChannel;
class AtaBaseDevice : public HWComponent, public AtaInterface
{
public:
AtaBaseDevice(const std::string name, uint8_t type);
~AtaBaseDevice() = default;
void set_host(IdeChannel* host, uint8_t dev_id) {
this->host_obj = host;
this->my_dev_id = dev_id;
}
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
int pull_data(uint8_t *buf, int len) override;
int push_data(uint8_t *buf, int len) override;
virtual int perform_command() = 0;
int get_device_id() override { return this->my_dev_id; }
void pdiag_callback() override {
this->r_error &= 0x7F;
}
virtual void device_reset(bool is_soft_reset);
virtual void device_set_signature();
void device_control(const uint8_t new_ctrl);
void update_intrq(uint8_t new_intrq_state);
void signal_data_ready();
bool has_data() const {
return data_ptr && xfer_cnt;
}
uint16_t get_data() {
return BYTESWAP_16(*this->data_ptr++);
}
protected:
bool is_selected() const {
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
}
void prepare_xfer(int xfer_size, int block_size);
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
uint8_t intrq_state = 0; // INTRQ deasserted
IdeChannel* host_obj = nullptr;
// IDE aka task file registers
uint8_t r_error = 0;
uint8_t r_features;
uint8_t r_sect_count;
uint8_t r_sect_num;
uint8_t r_cylinder_lo;
uint8_t r_cylinder_hi;
uint8_t r_dev_head;
uint8_t r_command;
uint8_t r_status;
uint8_t r_status_save;
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;
int chunk_size = 0;
bool is_dma_xfer = false;
std::function<void()> post_xfer_action = nullptr;
TimerInfo read_data_timer;
TimerInfo write_done_timer;
TimerInfo write_more_timer;
TimerInfo dma_pull_timer;
TimerInfo dma_push_timer;
};
#endif // ATA_BASE_DEVICE_H
+197
View File
@@ -0,0 +1,197 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file ATA interface definitions. */
#ifndef ATA_INTERFACE_H
#define ATA_INTERFACE_H
#include <cinttypes>
namespace ata_interface {
/** Device IDs according with the Apple ATA zero/one specification. */
enum {
DEVICE_ID_INVALID = -1,
DEVICE_ID_ZERO = 0,
DEVICE_ID_ONE = 1
};
/** Device types. */
enum {
DEVICE_TYPE_UNKNOWN = -1,
DEVICE_TYPE_ATA = 0,
DEVICE_TYPE_ATAPI = 1,
};
/** ATA register offsets. */
enum ATA_Reg : int {
DATA = 0x00, // 16-bit data (read & write)
ERROR = 0x01, // error (read)
FEATURES = 0x01, // features (write)
SEC_COUNT = 0x02, // sector count
SEC_NUM = 0x03, // sector number
CYL_LOW = 0x04, // cylinder low
CYL_HIGH = 0x05, // cylinder high
DEVICE_HEAD = 0x06, // device/head
STATUS = 0x07, // status (read)
COMMAND = 0x07, // command (write)
ALT_STATUS = 0x16, // alt status (read)
DEV_CTRL = 0x16, // device control (write)
TIME_CONFIG = 0x20, // Apple ASIC specific timing configuration
INT_REG = 0x30, // Interrupt Register (read) 0x40 = int request (KeyLargo only)
};
/** ATAPI specific register offsets. */
enum ATAPI_Reg : int {
INT_REASON = 0x2, // interrupt reason (read-only)
BYTE_COUNT_LO = 0x4, // byte count (bits 0-7)
BYTE_COUNT_HI = 0x5, // byte count (bits 8-15)
};
/** ATAPI Interrupt Reason bits. */
enum ATAPI_Int_Reason : uint8_t {
CoD = 1 << 0,
IO = 1 << 1,
RELEASE = 1 << 2,
};
/** ATAPI Features bits. */
enum ATAPI_Features : uint8_t {
DMA = 1 << 0,
OVERLAP = 1 << 1
};
/** Device/Head register bits. */
enum ATA_Dev_Head : uint8_t {
LBA = 1 << 6,
};
/** Status register bits. */
enum ATA_Status : uint8_t {
ERR = 0x01,
IDX = 0x02,
CORR = 0x04,
DRQ = 0x08,
DSC = 0x10,
DWF = 0x20,
DRDY = 0x40,
BSY = 0x80
};
/** Error register bits. */
enum ATA_Error : uint8_t {
ANMF = 0x01, //no address mark
TK0NF = 0x02, //track 0 not found
ABRT = 0x04, //abort command
MCR = 0x08,
IDNF = 0x10, //id mark not found
MC = 0x20, //media change request
UNC = 0x40,
BBK = 0x80, //bad block
};
/** Bit definition for the device control register. */
enum ATA_CTRL : uint8_t {
IEN = 0x02,
SRST = 0x04,
HOB = 0x80,
};
/* ATA commands. */
enum ATA_Cmd : uint8_t {
NOP = 0x00,
ATAPI_SOFT_RESET = 0x08,
RECALIBRATE = 0x10,
ATAPI_COMMAND_MODE_SENSE6 = 0x1A,
READ_SECTOR = 0x20,
READ_SECTOR_NR = 0x21,
READ_LONG = 0x22,
READ_SECTOR_EXT = 0x24,
WRITE_SECTOR = 0x30,
WRITE_SECTOR_NR = 0x31,
WRITE_LONG = 0x32,
READ_VERIFY = 0x40,
ATAPI_COMMAND_GET_CONFIG = 0x46,
FORMAT_TRACKS = 0x50,
SEEK = 0x70,
DIAGNOSTICS = 0x90,
INIT_DEV_PARAM = 0x91,
ATAPI_PACKET = 0xA0,
ATAPI_IDFY_DEV = 0xA1,
ATAPI_SERVICE = 0xA2,
ATAPI_READ_DVD_STRUCTURE = 0xAD,
READ_MULTIPLE = 0xC4,
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
READ_DMA = 0xC8,
READ_DMA_NR = 0xC9,
WRITE_DMA = 0xCA,
WRITE_DMA_NR = 0xCB,
STANDBY_IMMEDIATE = 0xE0,
IDLE_IMMEDIATE = 0xE1,
CHECK_POWER_MODE = 0xE5,
SLEEP = 0xE6,
FLUSH_CACHE = 0xE7, // ATA-5
WRITE_BUFFER_DMA = 0xE9,
READ_BUFFER_DMA = 0xEB,
IDENTIFY_DEVICE = 0xEC,
SET_FEATURES = 0xEF,
};
} // namespace ata_interface
/** Interface for ATA devices. */
class AtaInterface {
public:
AtaInterface() = default;
virtual ~AtaInterface() = default;
virtual uint16_t read(const uint8_t reg_addr) = 0;
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
virtual int pull_data(uint8_t *buf, int len) { return 0; };
virtual int push_data(uint8_t *buf, int len) { return 0; };
virtual int get_device_id() = 0;
virtual void pdiag_callback() {}
};
/** Dummy ATA device. */
class AtaNullDevice : public AtaInterface {
public:
AtaNullDevice() = default;
~AtaNullDevice() = default;
uint16_t read(const uint8_t reg_addr) override {
// return all one's except DD7 if no device is present
// DD7 corresponds to the BSY bit of the status register
// The host should have a pull-down resistor on DD7
// to prevent the software from waiting for a long time
// for empty slots
return 0xFF7FU;
}
void write(const uint8_t reg_addr, const uint16_t val) override {}
// invalid device ID means no real device is present
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; }
};
#endif // ATA_INTERFACE_H
+396
View File
@@ -0,0 +1,396 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file ATA hard disk emulation. */
#include <core/memaccess.h>
#include <devices/common/ata/atahd.h>
#include <devices/deviceregistry.h>
#include <devices/common/ata/idechannel.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <bitset>
#include <cstring>
#include <fstream>
#include <string>
using namespace ata_interface;
AtaHardDisk::AtaHardDisk(std::string name) : AtaBaseDevice(name, DEVICE_TYPE_ATA) {
}
int AtaHardDisk::device_postinit() {
std::string hdd_config = GET_STR_PROP("hdd_config");
if (hdd_config.empty()) {
LOG_F(ERROR, "%s: hdd_config property is empty", this->name.c_str());
return -1;
}
std::string hdd_image_path = GET_STR_PROP("hdd_img");
if (hdd_image_path.empty())
return 0;
std::string bus_id;
uint32_t dev_num;
parse_device_path(hdd_config, bus_id, dev_num);
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
bus_obj->register_device(dev_num, this);
this->insert_image(hdd_image_path);
return 0;
}
void AtaHardDisk::insert_image(std::string filename) {
if (!this->hdd_img.open(filename)) {
ABORT_F("%s: could not open image file \"%s\"", this->name.c_str(),
filename.c_str());
}
this->img_size = this->hdd_img.size();
uint64_t sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
this->total_sectors = (uint32_t)sectors;
if (sectors != this->total_sectors) {
ABORT_F("%s: image file \"%s\" is too big", this->name.c_str(),
filename.c_str());
}
this->calc_chs_params();
}
int AtaHardDisk::perform_command() {
this->r_status |= BSY;
this->r_error = 0;
switch (this->r_command) {
case NOP:
break;
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:
case READ_DMA:
case READ_DMA_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;
bool is_dma_cmd = this->r_command == READ_DMA ||
this->r_command == READ_DMA_NR;
uint32_t ints_size = is_dma_cmd ? xfer_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;
this->prepare_xfer(xfer_size, ints_size);
if (is_dma_cmd) {
this->is_dma_xfer = true;
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY | DSC;
// TODO: Model ATA DMAREQ as a latched signal instead of relying
// on this delay to avoid racing DBDMA command startup.
this->host_obj->assert_dmareq(500);
} else {
// PIO commands generate IRQ for each sector or multiple block.
this->signal_data_ready();
}
}
break;
case WRITE_MULTIPLE:
case WRITE_SECTOR:
case WRITE_SECTOR_NR:
case WRITE_DMA:
case WRITE_DMA_NR: {
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
bool is_dma_cmd = this->r_command == WRITE_DMA ||
this->r_command == WRITE_DMA_NR;
uint32_t ints_size = is_dma_cmd ? xfer_size : ATA_HD_SEC_SIZE;
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
this->data_ptr = (uint16_t *)this->buffer;
this->cur_data_ptr = this->data_ptr;
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]() {
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;
};
if (is_dma_cmd) {
this->is_dma_xfer = true;
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY | DSC;
// TODO: Model ATA DMAREQ as a latched signal instead of relying
// on this delay to avoid racing DBDMA command startup.
this->host_obj->assert_dmareq(500);
} else {
this->r_status |= DRQ;
this->r_status &= ~BSY;
}
}
break;
case CHECK_POWER_MODE:
this->r_sect_count = 0xFF; // always active or idle
this->r_status |= DRDY;
this->r_status &= ~BSY;
break;
case SEEK:
this->r_status |= DSC;
this->r_status &= ~BSY;
this->update_intrq(1);
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;
this->heads = (this->r_dev_head & 0xF) + 1;
this->r_status &= ~BSY;
this->update_intrq(1);
break;
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);
this->update_intrq(1);
break;
case IDENTIFY_DEVICE:
this->prepare_identify_info();
this->data_ptr = (uint16_t *)this->data_buf;
this->prepare_xfer(ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
this->signal_data_ready();
break;
case SET_FEATURES:
switch (this->r_features) {
case 2:
LOG_F(INFO, "%s: write cache enabled", this->name.c_str());
break;
case 3:
switch(this->r_sect_count >> 3) {
case 0:
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
break;
case 1:
LOG_F(INFO, "%s: PIO transfer mode set to 0x%X", this->name.c_str(),
this->r_sect_count & 7);
break;
case 4:
this->cur_dma_mode = this->r_sect_count & 7;
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
this->cur_dma_mode);
break;
default:
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
this->r_sect_count);
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
break;
case 0xAA:
LOG_F(INFO, "%s: read look-ahead enabled", this->name.c_str());
break;
default:
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
this->name.c_str(), this->r_features);
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case STANDBY_IMMEDIATE:
LOG_F(INFO, "%s: immediate standby requested", this->name.c_str());
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case IDLE_IMMEDIATE:
LOG_F(INFO, "%s: immediate idle requested", this->name.c_str());
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY;
this->update_intrq(1);
break;
default:
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
this->r_status &= ~BSY;
this->r_status |= ERR;
return -1;
}
return 0;
}
void AtaHardDisk::prepare_identify_info() {
uint16_t *buf_ptr = (uint16_t *)this->data_buf;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
WRITE_WORD_LE_A(&buf_ptr[49], 0x0300); // report DMA and LBA support
// Maximum number of logical sectors per data block that the device supports
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
WRITE_WORD_LE_A(&buf_ptr[47], 0x8000 | SECTORS_PER_INT);
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
// logical sectors that shall be transferred per data block for
// READ_MULTIPLE/WRITE_MULTIPLE commands.
if (this->sectors_per_int)
WRITE_WORD_LE_A(&buf_ptr[59], 0x100 | this->sectors_per_int);
WRITE_WORD_LE_A(&buf_ptr[ 1], this->cylinders);
WRITE_WORD_LE_A(&buf_ptr[ 3], this->heads);
WRITE_WORD_LE_A(&buf_ptr[ 6], this->sectors);
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
// report validity for the MWDMA fields
WRITE_WORD_LE_A(&buf_ptr[53], 0x0002);
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
// report LBA capacity
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
WRITE_WORD_LE_A(&buf_ptr[65], 120); // minimum MWDMA cycle time (ns)
WRITE_WORD_LE_A(&buf_ptr[66], 120); // recommended MWDMA cycle time (ns)
}
uint64_t AtaHardDisk::get_lba() {
if (this->r_dev_head & ATA_Dev_Head::LBA) {
return uint64_t(((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num));
} else { // translate old fashioned CHS addressing to LBA
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
uint8_t h = this->r_dev_head & 0xF;
uint8_t s = this->r_sect_num;
if (!s) {
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
return -1ULL;
} else
return uint64_t((this->heads * c + h) * this->sectors + s - 1);
}
}
void AtaHardDisk::calc_chs_params() {
unsigned num_blocks, heads, sectors, max_sectors, cylinders, max_cylinders;
LOG_F(INFO, "%s: total sectors %d", this->name.c_str(), this->total_sectors);
if (this->total_sectors >= REAL_CHS_LIMIT) {
heads = 16;
sectors = 255;
cylinders = 65535;
LOG_F(WARNING, "%s: exceeds max CHS translation",
this->name.c_str());
goto done;
}
// use PC BIOS limit to keep number of sectors small for smaller disks
if (this->total_sectors >= ATA_BIOS_LIMIT) {
max_sectors = 255;
max_cylinders = 65535;
} else {
max_sectors = 63;
max_cylinders = 16383;
}
num_blocks = this->total_sectors;
for (heads = 16; heads > 0; heads--)
for (sectors = max_sectors; sectors > 0; sectors--)
if (!(num_blocks % (heads * sectors)))
if (heads * sectors * max_cylinders >= num_blocks) {
cylinders = num_blocks / (heads * sectors);
goto done;
}
heads = 16;
sectors = (num_blocks + heads * max_cylinders - 1) / (heads * max_cylinders);
cylinders = (num_blocks + heads * sectors - 1) / (heads * sectors);
LOG_F(WARNING, "%s: could not find a suitable CHS translation; increased sectors to %d",
this->name.c_str(), heads * sectors * cylinders);
done:
this->heads = heads;
this->sectors = sectors;
this->cylinders = cylinders;
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), cylinders,
heads, sectors);
}
static const PropMap AtaHardDisk_Properties = {
{"hdd_img", new StrProperty("")},
};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
+82
View File
@@ -0,0 +1,82 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file ATA hard disk definitions. */
#ifndef ATA_HARD_DISK_H
#define ATA_HARD_DISK_H
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <utils/imgfile.h>
#include <string>
constexpr auto ATA_HD_SEC_SIZE = 512;
constexpr auto SECTORS_PER_INT = 16;
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
constexpr auto ATA_BIOS_LIMIT = 16514064;
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
constexpr auto REAL_CHS_LIMIT = 267382800;
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
constexpr auto CHS_LIMIT = 267386880;
class AtaHardDisk : public AtaBaseDevice
{
public:
AtaHardDisk(std::string name);
~AtaHardDisk() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AtaHardDisk>(new AtaHardDisk("ATA-HD"));
}
int device_postinit() override;
void insert_image(std::string filename);
int perform_command() override;
protected:
void prepare_identify_info();
uint64_t get_lba();
void calc_chs_params();
private:
ImgFile hdd_img;
uint64_t img_size = 0;
uint32_t total_sectors = 0;
uint64_t cur_fpos = 0;
// fictive disk geometry for CHS-to-LBA translation
uint16_t cylinders;
uint8_t heads;
uint8_t sectors;
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
char * buffer = new char[1 <<17];
TimerInfo signal_ready_timer;
};
#endif // ATA_HARD_DISK_H
+257
View File
@@ -0,0 +1,257 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Basic ATAPI interface emulation. */
#include <core/endianswap.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atapibasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
using namespace ata_interface;
AtapiBaseDevice::AtapiBaseDevice(const std::string name)
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI), ScsiPhysInterface(PHY_ID_ATAPI) {
}
void AtapiBaseDevice::device_set_signature() {
this->r_int_reason = 1; // shadows ATA r_sect_count
this->r_sect_num = 1; // required for protocol identification in OF 2.x
this->r_dev_head = 0;
// set ATAPI protocol signature
this->r_byte_count = 0xEB14;
this->r_status_save = this->r_status; // for restoring on the first command
this->r_status = 0;
}
uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (has_data()) {
uint16_t ret_data = get_data();
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0) {
this->r_status &= ~DRQ;
if ((this->r_int_reason & ATAPI_Int_Reason::IO) &&
!(this->r_int_reason & ATAPI_Int_Reason::CoD)
) {
if (this->data_available()) {
this->r_status &= ~DRQ;
this->r_status |= BSY;
// Is this going to work here?
// The interrupt happens before returning ret_data.
this->update_intrq(1);
}
else if (this->status_expected) {
this->present_status();
}
}
}
return ret_data;
} else {
return 0xFFFFU;
}
case ATA_Reg::ERROR:
return this->r_error;
case ATAPI_Reg::INT_REASON:
return this->r_int_reason;
case ATA_Reg::SEC_NUM:
return this->r_sect_num;
case ATAPI_Reg::BYTE_COUNT_LO:
return this->r_byte_count & 0xFFU;
case ATAPI_Reg::BYTE_COUNT_HI:
return (this->r_byte_count >> 8) & 0xFFU;
case ATA_Reg::DEVICE_HEAD:
return this->r_dev_head;
case ATA_Reg::STATUS:
this->update_intrq(0);
case ATA_Reg::ALT_STATUS:
if ((this->r_status & BSY) && this->data_available()) {
this->r_byte_count = this->request_data();
this->data_in_phase();
}
return this->r_status;
default:
LOG_F(WARNING, "%s: read from unknown register 0x%X", this->name.c_str(),
reg_addr);
return 0;
}
}
void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (!(this->r_int_reason & ATAPI_Int_Reason::IO)) { // host --> device?
if (this->r_int_reason & ATAPI_Int_Reason::CoD) { // command phase?
if (this->xfer_cnt > 0) {
*this->data_ptr++ = BYTESWAP_16(value);
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0) {
this->r_status &= ~DRQ;
this->perform_packet_command();
}
}
} else { // data-out phase
if (this->xfer_cnt > 0) {
*this->data_ptr++ = BYTESWAP_16(value);
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0)
this->r_status &= ~DRQ;
}
}
}
break;
case ATA_Reg::FEATURES:
this->r_features = value;
break;
case ATA_Reg::SEC_COUNT:
case ATA_Reg::SEC_NUM:
break; // unused in ATAPI, NoOp them here for compatibility
case ATAPI_Reg::BYTE_COUNT_LO:
this->r_byte_count = (this->r_byte_count & 0xFF00U) | (value & 0xFFU);
break;
case ATAPI_Reg::BYTE_COUNT_HI:
this->r_byte_count = (this->r_byte_count & 0xFFU) | ((value & 0xFFU) << 8);
break;
case ATA_Reg::DEVICE_HEAD:
this->r_dev_head = value;
break;
case ATA_Reg::COMMAND:
this->r_command = value;
if (is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
}
break;
case ATA_Reg::DEV_CTRL:
this->device_control(value);
break;
default:
LOG_F(WARNING, "%s: write to unknown register 0x%X", this->name.c_str(), reg_addr);
}
}
int AtapiBaseDevice::perform_command() {
this->r_error &= ~ATA_Error::ABRT;
this->r_status &= ~ATA_Status::ERR;
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);
this->r_int_reason &= ~ATAPI_Int_Reason::IO; // host->device
this->r_int_reason |= ATAPI_Int_Reason::CoD; // command packet
this->r_status |= DRQ;
this->r_status &= ~BSY;
break;
case ATAPI_IDFY_DEV:
std::memset(this->data_buf, 0, 512);
this->data_buf[0] = 0xC0;
this->data_buf[1] = 0x85;
this->data_ptr = (uint16_t *)this->data_buf;
this->xfer_cnt = 512;
this->status_expected = false;
this->data_in_phase();
break;
case SET_FEATURES:
switch (this->r_features) {
case 3: // set transfer mode
LOG_F(INFO, "%s: xfer_type=0x%X, mode=0x%X", this->name.c_str(),
this->r_sect_count >> 3, this->r_sect_count & 7);
break;
default:
LOG_F(ERROR, "%s: unsupported subcommand 0x%X in SET_FEATURES",
this->name.c_str(), this->r_features);
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
default:
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), this->r_command);
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
this->r_status &= ~BSY;
this->update_intrq(1);
}
return 0;
}
void AtapiBaseDevice::data_in_phase() {
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
this->signal_data_ready();
}
void AtapiBaseDevice::present_status() {
this->r_int_reason |= ATAPI_Int_Reason::IO;
this->r_int_reason |= ATAPI_Int_Reason::CoD;
this->r_status &= ~DRQ;
this->r_status &= ~BSY;
this->update_intrq(1);
}
void AtapiBaseDevice::switch_phase(const int new_phase) {
switch(new_phase) {
case ScsiPhase::DATA_IN:
this->data_in_phase();
break;
case ScsiPhase::DATA_OUT:
this->r_int_reason &= ATAPI_Int_Reason::IO; // host->device
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
this->signal_data_ready();
break;
case ScsiPhase::STATUS:
this->present_status();
break;
default:
LOG_F(WARNING, "ATAPI PHY: unsupported phase %d switch_phase", new_phase);
}
}
void AtapiBaseDevice::set_status(uint8_t status_code, uint8_t sense_key) {
switch(status_code) {
case ScsiStatus::GOOD:
this->status_expected = true;
this->r_error = 0;
this->r_status &= ~ATA_Status::ERR;
break;
case ScsiStatus::CHECK_CONDITION:
this->status_expected = true;
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
break;
default:
LOG_F(WARNING, "ATAPI PHY: unsupported status %d set_status", status_code);
}
}
+83
View File
@@ -0,0 +1,83 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Base class for ATAPI devices. */
#ifndef ATAPI_BASE_DEVICE_H
#define ATAPI_BASE_DEVICE_H
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <cinttypes>
#include <string>
class AtapiBaseDevice : public AtaBaseDevice, public ScsiPhysInterface
{
public:
AtapiBaseDevice(const std::string name);
~AtapiBaseDevice() = default;
void device_set_signature() override;
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
// ScsiPhysInterface methods
void set_lock_state(bool is_locked) override {};
void set_xfer_len(uint64_t len) override {
this->xfer_cnt = len;
this->r_byte_count = len;
}
void set_buffer(uint8_t *buf_ptr) override {
this->data_ptr = (uint16_t*)buf_ptr;
}
void set_status(uint8_t status_code, uint8_t sense_key) override;
void switch_phase(const int new_phase) override;
void set_read_more_data_cb(more_data_cb_t cb) override {};
void set_write_more_data_cb(more_data_cb_t cb) override {};
void set_post_xfer_action(action_callback cb) override {};
// methods to be implemented in the particular device
int perform_command() override;
virtual void perform_packet_command() = 0;
virtual int get_config(uint8_t* pkt, uint8_t* buf) = 0;
virtual int request_data() = 0;
virtual bool data_available() = 0;
// methods with default implementation
virtual void data_in_phase();
virtual void present_status();
protected:
uint8_t r_int_reason;
uint16_t r_byte_count;
bool status_expected = false;
alignas(uint16_t)
uint8_t cmd_pkt[12] = {};
};
#endif // ATAPI_BASE_DEVICE_H
+346
View File
@@ -0,0 +1,346 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file ATAPI CDROM implementation. */
#include <core/memaccess.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/atapicdrom.h>
#include <devices/common/ata/idechannel.h>
#include <devices/deviceregistry.h>
#include <machines/machinebase.h>
#include <machines/machineproperties.h>
#include <cstring>
#include <string>
#include <core/timermanager.h>
using namespace ata_interface;
static char cdrom_vendor_id[] = "DINGUS ";
static char cdrom_product_id[] = "DINGUS CD-ROM ";
static char cdrom_revision_id[] = "1.0 ";
AtapiCdrom::AtapiCdrom(std::string name) : AtapiBaseDevice(name) {
this->set_phys_dev(this);
this->set_cdb_ptr(this->cmd_pkt);
this->set_buf_ptr(this->data_buf);
// populate device info for INQUIRY
this->dev_type = ScsiDevType::CD_ROM;
this->is_removable = true; // removable medium
this->std_versions = 2; // ANSI version: SCSI-2
this->resp_fmt = 0x21; // ATAPI Version + response data format
this->set_vendor_id(cdrom_vendor_id);
this->set_product_id(cdrom_product_id);
this->set_revision_id(cdrom_revision_id);
}
int AtapiCdrom::device_postinit() {
std::string cdr_config = GET_STR_PROP("cdr_config");
if (cdr_config.empty()) {
LOG_F(ERROR, "%s: cdr_config property is empty", this->name.c_str());
return -1;
}
std::string bus_id;
uint32_t dev_num;
parse_device_path(cdr_config, bus_id, dev_num);
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
if (!bus_obj) {
LOG_F(ERROR, "%s: cdr_config device path %s does not specify a known IDE bus",
this->name.c_str(), cdr_config.c_str());
return -1;
}
bus_obj->register_device(dev_num, this);
std::string cdr_image_path = GET_STR_PROP("cdr_img");
if (!cdr_image_path.empty()) {
if (!this->insert_image(cdr_image_path))
return -1;
}
return 0;
}
void AtapiCdrom::perform_packet_command() {
uint32_t lba, xfer_len;
this->r_status |= BSY;
this->sector_areas = 0;
if (this->doing_sector_areas) {
this->doing_sector_areas = false;
LOG_F(WARNING, "%s: doing_sector_areas reset", this->name.c_str());
}
// Assume successful command execution
if (this->cmd_pkt[0] == ScsiCommand::REQ_SENSE) {
// For REQ_SENSE we only set the status, status_good() also resets
// sense_key, which we'll need to return.
this->set_status(ScsiStatus::GOOD, 0);
} else {
this->status_good();
}
switch (this->cmd_pkt[0]) {
case ScsiCommand::READ_CD:
{
// READ_CD currently bypasses the shared CD-ROM command dispatcher.
if (!this->ready_for_command()) {
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
// Treat as a non-data command.
xfer_len = 0;
}
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
this->name.c_str(),
this->cmd_pkt[0], this->cmd_pkt[1], this->cmd_pkt[2], this->cmd_pkt[3], this->cmd_pkt[4], this->cmd_pkt[5],
this->cmd_pkt[6], this->cmd_pkt[7], this->cmd_pkt[8], this->cmd_pkt[9], this->cmd_pkt[10], this->cmd_pkt[11]
);
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->sector_areas = cmd_pkt[9];
this->doing_sector_areas = true;
this->current_block = lba;
this->current_block_byte = 0;
int bytes_prolog = 0;
int bytes_data = 0;
int bytes_epilog = 0;
// For Mode 1 CD-ROMs:
if (this->sector_areas & 0x80) bytes_prolog += 12; // Sync
if (this->sector_areas & 0x20) bytes_prolog += 4; // Header
if (this->sector_areas & 0x40) bytes_prolog += 0; // SubHeader
if (this->sector_areas & 0x10) bytes_data += 2048; // User
if (this->sector_areas & 0x08) bytes_epilog += 288; // Auxiliary
if (this->sector_areas & 0x02) bytes_epilog += 294; // ErrorFlags
if (this->sector_areas & 0x01) bytes_epilog += 96; // SubChannel
int bytes_per_block = bytes_prolog + bytes_data + bytes_epilog;
int disk_image_byte_count;
if (bytes_per_block == 0) {
disk_image_byte_count = 0xffff;
}
else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block =
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
}
// add partial block
disk_image_byte_count += disk_image_byte_count_partial_block;
}
}
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count
}
this->r_byte_count = bytes_received;
this->xfer_cnt = bytes_received;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_in_phase();
break;
}
case ScsiCommand::GET_CONFIG: {
this->xfer_cnt = this->get_config(this->cmd_pkt, this->data_buf);
if (this->xfer_cnt == 0) {
this->present_status();
} else {
this->xfer_cnt = std::min((int)this->r_byte_count, this->xfer_cnt);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
}
break;
}
default:
ScsiCdromCmds::process_command();
}
}
int AtapiCdrom::get_config(uint8_t* pkt, uint8_t* buf) {
std::memset(buf, 0, 16);
// Data length (4 bytes header + 8 bytes for one feature descriptor - 4 bytes for length field)
uint32_t data_len = 8;
buf[0] = (data_len >> 24) & 0xFF;
buf[1] = (data_len >> 16) & 0xFF;
buf[2] = (data_len >> 8) & 0xFF;
buf[3] = data_len & 0xFF;
// Feature Descriptor 1 - Set profile to CD-ROM
buf[6] = 0;
buf[7] = 0x08;
// Feature Descriptor 2 - Feature Code, Version 0
buf[8] = 0x00;
buf[9] = 0x01; // Core Feature Code
buf[10] = 0x03; // Persist and Current bits set
buf[11] = 0x04; // Additional Length
return 12;
}
int AtapiCdrom::request_data() {
// continuation of READ_CD above
this->data_ptr = (uint16_t*)this->data_cache.get();
this->xfer_cnt = this->read_more();
return this->xfer_cnt;
}
static const uint8_t mode_1_sync[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
uint16_t AtapiCdrom::get_data() {
uint16_t ret_data;
if (doing_sector_areas) {
// For Mode 1 CD-ROMs:
int area_start;
int area_end = 0;
ret_data = 0xffff;
if (this->sector_areas & 0x80) {
area_start = area_end;
area_end += 12; // Sync
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = BYTESWAP_16(*((uint16_t*)(&mode_1_sync[current_block_byte - area_start])));
}
}
if (this->sector_areas & 0x20) {
area_start = area_end;
area_end += 4; // Header
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
if (this->sector_areas & 0x40) {
area_start = area_end;
area_end += 0; // SubHeader
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = 0;
}
}
if (this->sector_areas & 0x10) {
area_start = area_end;
area_end += 2048; // User
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = AtaBaseDevice::get_data();
}
}
if (this->sector_areas & 0x08) {
area_start = area_end;
area_end += 288; // Auxiliary
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = 0;
}
}
if (this->sector_areas & 0x02) {
area_start = area_end;
area_end += 294; // ErrorFlags
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = 0;
}
}
if (this->sector_areas & 0x01) {
area_start = area_end;
area_end += 96; // SubChannel
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
ret_data = 0;
}
}
current_block_byte += 2;
if (current_block_byte >= area_end)
current_block_byte = 0;
}
else {
ret_data = AtaBaseDevice::get_data();
}
return ret_data;
}
void AtapiCdrom::status_good() {
this->sense_key = 0;
this->set_status(ScsiStatus::GOOD, this->sense_key);
}
void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->sense_key = sense_key;
this->asc = asc;
this->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
static const PropMap AtapiCdrom_Properties = {
{"cdr_img", new StrProperty("")},
};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties, HWCompType::IDE_DEV
};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
+72
View File
@@ -0,0 +1,72 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file ATAPI CDROM definitions. */
#ifndef ATAPI_CDROM_H
#define ATAPI_CDROM_H
#include <devices/common/ata/atapibasedevice.h>
#include <devices/common/scsi/scsicdromcmds.h>
#include <string>
class AtapiCdrom : public AtapiBaseDevice, public ScsiCdromCmds {
public:
AtapiCdrom(std::string name);
~AtapiCdrom() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
}
bool is_device_ready() override { return this->medium_present(); }
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
int device_postinit() override;
void perform_packet_command() override;
void set_lock_state(bool is_locked) override {
this->drive_locked = is_locked ? 1 : 0;
}
int get_config(uint8_t* pkt, uint8_t* buf) override;
int request_data() override;
bool data_available() override {
return this->data_left() != 0;
}
void status_good();
void status_error(uint8_t sense_key, uint8_t asc);
uint16_t get_data();
private:
bool doing_sector_areas = false;
uint8_t sector_areas;
uint32_t current_block;
uint16_t current_block_byte;
};
#endif // ATAPI_CDROM_H
+238
View File
@@ -0,0 +1,238 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller emulation. */
#include <devices/common/ata/cmd646.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
CmdIdeCtrl::CmdIdeCtrl() : PCIDevice("cmd-ide") {
this->supports_types(HWCompType::PCI_DEV | HWCompType::IDE_HOST);
// set up PCI configuration space header
this->vendor_id = this->subsys_vndr = PCI_VENDOR_SILICON_IMAGE;
this->device_id = this->subsys_id = DEV_ID_CMD646;
this->class_rev = ((MY_DEV_CLASS | this->prog_if) << 8) | MY_REV_ID;
this->max_lat = 4;
this->min_gnt = 2;
this->irq_pin = 1;
this->bars_cfg[0] = 0xFFFFFFF9; // Command block I/O space, primary channel
this->bars_cfg[1] = 0xFFFFFFFD; // Control block I/O space, primary channel
this->bars_cfg[2] = 0xFFFFFFF9; // Command block I/O space, secondary channel
this->bars_cfg[3] = 0xFFFFFFFD; // Control block I/O space, secondary channel
this->bars_cfg[4] = 0xFFFFFFF1; // Bus master I/O space, both channels
this->finish_config_bars();
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
gMachineObj->add_device("CmdAta0", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta0")));
gMachineObj->add_device("CmdAta1", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta1")));
this->ch0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta0"));
this->ch1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta1"));
this->ch0->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta0 INTRQ updated to %d", intrq_state);
this->update_irq(0, intrq_state);
});
this->ch1->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta1 INTRQ updated to %d", intrq_state);
this->update_irq(1, intrq_state);
});
}
uint32_t CmdIdeCtrl::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
if (reg_offs < 64)
return PCIDevice::pci_cfg_read(reg_offs, details);
if (details.size != 1)
ABORT_F("%s: non-byte read from PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
return this->read_config_reg(reg_offs + details.offset);
LOG_F(WARNING, "%s: reading config reg at 0x%X", this->name.c_str(), reg_offs);
return 0;
}
void CmdIdeCtrl::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) {
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, details);
return;
}
if (details.size != 1)
ABORT_F("%s: non-byte write to PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
this->write_config_reg(reg_offs + details.offset, value);
else
LOG_F(WARNING, "%s: writing config reg at 0x%X", this->name.c_str(), reg_offs);
}
void CmdIdeCtrl::notify_bar_change(int bar_num) {
if (bar_num >= 0 && bar_num <= 4)
this->io_bases[bar_num] = this->bars[bar_num] & ~3;
}
bool CmdIdeCtrl::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
*res = 0;
if ((offset & ~7) == this->io_bases[0]) {
*res = this->ch0->read(offset & 7, size);
} else if ((offset & ~7) == this->io_bases[2]) {
*res = this->ch1->read(offset & 7, size);
} else if ((offset & ~3) == this->io_bases[1]) {
*res = this->ch0->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~3) == this->io_bases[3]) {
*res = this->ch1->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
*res = this->read_bus_master_reg(offset & 0xF);
} else {
*res = 0xFFFFFFFFUL;
return false;
}
return true;
}
bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
if ((offset & ~7) == this->io_bases[0]) {
this->ch0->write(offset & 7, value, size);
} else if ((offset & ~7) == this->io_bases[2]) {
this->ch1->write(offset & 7, value, size);
} else if ((offset & ~3) == this->io_bases[1]) {
this->ch0->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~3) == this->io_bases[3]) {
this->ch1->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
this->write_bus_master_reg(offset & 0xF, value & 0xFFU);
} else
return false;
return true;
}
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
case ARTTIM0:
return this->addr_setup_time_0;
case DRWTIM0:
return this->data_rw_time_0;
case ARTTIM1:
return this->addr_setup_time_1;
case DRWTIM1:
return this->data_rw_time_1;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_config_reg(uint32_t reg_offset, uint8_t val) {
switch(reg_offset) {
case ARTTIM0:
this->addr_setup_time_0 = val;
LOG_F(9, "%s: ARTTIM0 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM0:
this->data_rw_time_0 = val;
LOG_F(9, "%s: DRWTIM0 set to 0x%X", this->name.c_str(), val);
break;
case ARTTIM1:
this->addr_setup_time_1 = val;
LOG_F(9, "%s: ARTTIM1 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM1:
this->data_rw_time_1 = val;
LOG_F(9, "%s: DRWTIM1 set to 0x%X", this->name.c_str(), val);
break;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
uint8_t CmdIdeCtrl::read_bus_master_reg(const uint8_t reg_offset) {
switch(reg_offset) {
case MRDMODE:
return this->mrdmode;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_bus_master_reg(const uint8_t reg_offset, const uint8_t val) {
switch(reg_offset) {
case MRDMODE:
if (val & BM_CH0_INT)
this->mrdmode &= ~BM_CH0_INT;
if (val & BM_CH1_INT)
this->mrdmode &= ~BM_CH1_INT;
this->mrdmode = (this->mrdmode & ~(BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT)) |
(val & (BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT));
LOG_F(INFO, "%s: MRDMODE set to 0x%X", this->name.c_str(), val);
if ((this->mrdmode & BM_CH0_INT) && !(this->mrdmode & BM_BLOCK_CH0_INT))
this->update_irq(0, 1);
if ((this->mrdmode & BM_CH1_INT) && !(this->mrdmode & BM_BLOCK_CH1_INT))
this->update_irq(1, 1);
break;
case UDIDETCR0:
this->udma_time_cr = val;
break;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
void CmdIdeCtrl::update_irq(const int ch_num, const uint8_t irq_level) {
bool forward_irq = !(this->mrdmode & (ch_num ? BM_BLOCK_CH1_INT : BM_BLOCK_CH0_INT));
if (irq_level)
this->mrdmode |= ch_num ? BM_CH1_INT : BM_CH0_INT;
else
this->mrdmode &= ~(ch_num ? BM_CH1_INT : BM_CH0_INT);
if (!irq_level || forward_irq)
this->pci_interrupt(irq_level);
}
static const DeviceDescription CmdIde_Descriptor = {
CmdIdeCtrl::create, {}, {}
};
REGISTER_DEVICE(CmdAta, CmdIde_Descriptor);
+108
View File
@@ -0,0 +1,108 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller definitions. */
#ifndef CMD646_IDE_H
#define CMD646_IDE_H
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/pci/pcidevice.h>
#include <memory>
constexpr auto DEV_ID_CMD646 = 0x646;
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master
constexpr auto MY_REV_ID = 7;
// Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14;
/** CMD646 control/status registers. */
enum {
ARTTIM0 = 0x53,
DRWTIM0 = 0x54,
ARTTIM1 = 0x55,
DRWTIM1 = 0x56,
};
/** CMD646 bus master registers. */
enum {
MRDMODE = 1, // misnomer, contains interrupt control/status bits (CMD646U2 specific)
UDIDETCR0 = 3, // Ultra DMA timing control register (CMD646U2 specific)
};
/** Bit definitions for the MRDMODE register. */
enum {
BM_CH0_INT = 1 << 2,
BM_CH1_INT = 1 << 3,
BM_BLOCK_CH0_INT = 1 << 4,
BM_BLOCK_CH1_INT = 1 << 5,
};
class CmdIdeCtrl : public PCIDevice {
public:
CmdIdeCtrl();
~CmdIdeCtrl() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<CmdIdeCtrl>(new CmdIdeCtrl());
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) override;
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) override;
private:
void notify_bar_change(int bar_num);
uint8_t read_config_reg(uint32_t reg_offset);
void write_config_reg(uint32_t reg_offset, uint8_t val);
uint8_t read_bus_master_reg(const uint8_t reg_offset);
void write_bus_master_reg(const uint8_t reg_offset, const uint8_t val);
void update_irq(const int ch_num, const uint8_t irq_level);
// on reset, programming interface defaults to
// "both channels operating in native mode"
uint8_t prog_if = 0x0F;
uint32_t io_bases[5] = {};
IdeChannel *ch0 = nullptr;
IdeChannel *ch1 = nullptr;
// unknown default, set it to 2 clocks (60 ns)
uint8_t addr_setup_time_0 = 0x40; // address setup time for drive 0
uint8_t addr_setup_time_1 = 0x40; // address setup time for drive 1
uint8_t data_rw_time_0 = 0x00; // data read/write time for drive 0
uint8_t data_rw_time_1 = 0x00; // data read/write time for drive 1
uint8_t mrdmode = 0;
uint8_t udma_time_cr = 0;
};
#endif // CMD646_IDE_H
+146
View File
@@ -0,0 +1,146 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** IDE Channel (aka IDE port) emulation.
One IDE channel is capable of controlling up to two IDE devices.
IdeChannel class handles device registration and passing of messages
from and to the host.
MacioIdeChannel class implements MacIO specific registers
and interrupt handling.
*/
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/hwcomponent.h>
#include <devices/deviceregistry.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <cinttypes>
#include <memory>
#include <string>
using namespace ata_interface;
IdeChannel::IdeChannel(const std::string name)
{
this->set_name(name);
this->supports_types(HWCompType::IDE_BUS);
this->device_stub = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
this->devices[0] = this->device_stub.get();
this->devices[1] = this->device_stub.get();
}
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, id);
}
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)
{
// 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);
}
}
int IdeChannel::xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) {
return this->devices[this->cur_dev]->pull_data(buf, len);
}
int IdeChannel::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
return this->devices[this->cur_dev]->push_data(buf, len);
}
void IdeChannel::assert_dmareq(uint64_t delay) {
if (this->dmareq_timer.active)
LOG_F(WARNING, "%s: dmareq_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(this->dmareq_timer, delay, [this](uint64_t, uint64_t) {
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
this->channel_obj->xfer_retry();
});
}
int MacioIdeChannel::device_postinit() {
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
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 = {
MacioIdeChannel::create_first, {}, {}, HWCompType::IDE_BUS
};
static const DeviceDescription Ide1_Descriptor = {
MacioIdeChannel::create_second, {}, {}, HWCompType::IDE_BUS
};
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
REGISTER_DEVICE(Ide1, Ide1_Descriptor);
+110
View File
@@ -0,0 +1,110 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file IDE Channel (aka IDE port) definitions. */
#ifndef IDE_CHANNEL_H
#define IDE_CHANNEL_H
#include <core/timermanager.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <cinttypes>
#include <functional>
#include <memory>
#include <string>
class IdeChannel : public HWComponent, public DmaDevice
{
public:
IdeChannel(const std::string name);
~IdeChannel() = default;
void register_device(int id, AtaInterface* dev_obj);
virtual uint32_t read(const uint8_t reg_addr, const int size);
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size);
int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) override;
int xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) override;
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 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);
}
void assert_dmareq(uint64_t delay);
protected:
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
private:
int cur_dev = 0;
AtaInterface* devices[2];
std::unique_ptr<AtaInterface> device_stub;
TimerInfo dmareq_timer;
};
/** 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;
virtual uint32_t read(const uint8_t reg_addr, const int size) override;
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size) override;
private:
uint32_t ch_config = 0; // timing configuration for this channel
// interrupt stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
};
#endif // IDE_CHANNEL_H
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,23 +31,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters.
*/
#include <devices/common/i2c/athens.h>
#include <devices/common/clockgen/athens.h>
#include <loguru.hpp>
#include <algorithm>
#include <cinttypes>
#include <vector>
AthensClocks::AthensClocks(uint8_t dev_addr)
{
supports_types(HWCompType::I2C_DEV);
AthensClocks::AthensClocks(uint8_t dev_addr) : I2CDevice() {
set_name("Athens");
this->my_addr = dev_addr;
// set up power on values
// This initialization is not prescribed
// but let's set them to acceptable values anyway
this->regs[AthensRegs::D2] = 2;
this->regs[AthensRegs::N2] = 2;
// set P2_MUX2 on power up as follows:
// - dot clock VCO is disabled
// - dot clock = reference clock / 2
this->regs[AthensRegs::P2_MUX2] = 0x62;
}
AthensClocks::AthensClocks(uint8_t dev_addr, const float crystal_freq)
: AthensClocks(dev_addr)
{
this->xtal_freq = crystal_freq;
}
void AthensClocks::start_transaction()
{
this->pos = 0; // reset read/write position
@@ -55,30 +67,27 @@ void AthensClocks::start_transaction()
bool AthensClocks::send_subaddress(uint8_t sub_addr)
{
LOG_F(INFO, "Athens: subaddress set to 0x%X", sub_addr);
LOG_F(INFO, "%s: subaddress set to 0x%X", this->name.c_str(), sub_addr);
return true;
}
bool AthensClocks::send_byte(uint8_t data)
{
switch (this->pos) {
switch (this->pos++) {
case 0:
this->reg_num = data;
this->pos++;
break;
case 1:
if (this->reg_num >= ATHENS_NUM_REGS) {
LOG_F(WARNING, "Athens: invalid register number %d", this->reg_num);
LOG_F(WARNING, "%s: invalid register number %d", this->name.c_str(),
this->reg_num);
return false; // return NACK
}
this->regs[this->reg_num] = data;
if (reg_num == 3) {
LOG_F(INFO, "Athens: dot clock frequency set to %d Hz", get_dot_freq());
}
break;
default:
LOG_F(WARNING, "Athens: too much data received!");
return false; // return NACK
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
//return false; // return NACK
}
return true;
}
@@ -91,6 +100,8 @@ bool AthensClocks::receive_byte(uint8_t* p_data)
int AthensClocks::get_sys_freq()
{
LOG_F(ERROR, "%s: sys clock calculation not implemented yet", this->name.c_str());
return 0;
}
@@ -101,12 +112,12 @@ int AthensClocks::get_dot_freq()
22, 27, 28, 31, 35, 37, 38, 42, 49, 55, 56, 78, 125
};
if (this->regs[AthensRegs::P2_MUX2] & 0xC0) {
LOG_F(INFO, "Athens: dot clock disabled");
if (this->regs[AthensRegs::P2_MUX2] & 0x80) {
LOG_F(INFO, "%s: dot clock disabled", this->name.c_str());
return 0;
}
float out_freq = 0.0f;
float out_freq = 50000000.0; // for 800x600 72Hz
int d2 = this->regs[AthensRegs::D2];
int n2 = this->regs[AthensRegs::N2];
@@ -114,29 +125,31 @@ int AthensClocks::get_dot_freq()
int post_div = 1 << (3 - (this->regs[AthensRegs::P2_MUX2] & 3));
if (std::find(D2_commons.begin(), D2_commons.end(), d2) == D2_commons.end()) {
LOG_F(WARNING, "Athens: untested D2 value %d", d2);
LOG_F(WARNING, "%s: untested D2 value %d", this->name.c_str(), d2);
}
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
LOG_F(WARNING, "Athens: untested N2 value %d", d2);
LOG_F(WARNING, "%s: untested N2 value %d", this->name.c_str(), d2);
}
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
switch (mux) {
case 0: // clock source -> dot cock VCO
out_freq = ATHENS_XTAL * ((float)n2 / (float)(d2 * post_div));
out_freq = this->xtal_freq * ((float)n2 / (float)(d2 * post_div));
break;
case 1: // clock source -> system clock VCO
LOG_F(WARNING, "Athens: system clock VCO not supported yet!");
LOG_F(WARNING, "%s: system clock VCO not supported yet!", this->name.c_str());
break;
case 2: // clock source -> crystal frequency
out_freq = ATHENS_XTAL / post_div;
out_freq = this->xtal_freq / post_div;
break;
case 3:
LOG_F(WARNING, "Athens: attempt to use reserved Mux value!");
LOG_F(WARNING, "%s: attempt to use reserved Mux value!", this->name.c_str());
break;
}
LOG_F(INFO, "%s: dot clock frequency set to %f MHz", this->name.c_str(), out_freq / 1000000.0);
return static_cast<int>(out_freq + 0.5f);
}
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,14 +24,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATHENS_H
#define ATHENS_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
#define ATHENS_NUM_REGS 8
constexpr auto ATHENS_NUM_REGS = 8;
constexpr auto ATHENS_XTAL = 31334400.0f; // external crystal oscillator frequency
/** Default external crystal oscillator frequency. */
constexpr auto ATHENS_XTAL = 31334400.0f;
namespace AthensRegs {
@@ -46,12 +46,12 @@ enum AthensRegs: uint8_t {
P1 = 7
};
}; // namespace AthensRegs
} // namespace AthensRegs
class AthensClocks : public I2CDevice, public HWComponent
{
class AthensClocks : public I2CDevice {
public:
AthensClocks(uint8_t dev_addr);
AthensClocks(uint8_t dev_addr, const float crystal_freq);
~AthensClocks() = default;
// I2CDevice methods
@@ -68,8 +68,9 @@ private:
uint8_t my_addr = 0;
uint8_t reg_num = 0;
int pos = 0;
float xtal_freq = ATHENS_XTAL;
uint8_t regs[ATHENS_NUM_REGS];
uint8_t regs[ATHENS_NUM_REGS] = {};
};
#endif // ATHENS_H
+504 -135
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,215 +21,566 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Descriptor-based direct memory access emulation. */
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <core/timermanager.h>
#include <cpu/ppc/ppcmmu.h>
#include <devices/common/dbdma.h>
#include <devices/common/dmacore.h>
#include <endianswap.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/mmiodevice.h>
#include <devices/memctrl/memctrlbase.h>
#include <cinttypes>
#include <cstring>
#include <loguru.hpp>
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
{
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
this->start_cb = start_cb;
this->stop_cb = stop_cb;
}
void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
/* load DMACmd from physical memory */
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16);
/* Load DMACmd from physical memory. */
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
if (is_writable) *is_writable = res.is_writable;
DMACmd* cmd_host = (DMACmd*)res.host_va;
p_cmd->req_count = READ_WORD_LE_A(&cmd_host->req_count);
p_cmd->cmd_bits = cmd_host->cmd_bits;
p_cmd->cmd_key = cmd_host->cmd_key;
p_cmd->address = READ_DWORD_LE_A(&cmd_host->address);
p_cmd->cmd_arg = READ_DWORD_LE_A(&cmd_host->cmd_arg);
p_cmd->res_count = READ_WORD_LE_A(&cmd_host->res_count);
p_cmd->xfer_stat = READ_WORD_LE_A(&cmd_host->xfer_stat);
return cmd_host;
}
uint8_t DMAChannel::interpret_cmd() {
void DMAChannel::interpret_cmd() {
DMACmd cmd_struct;
MapDmaResult res;
get_next_cmd(this->cmd_ptr, &cmd_struct);
if (this->cmd_in_progress) {
// if there is data remaining to transfer then the command is not finished
if (this->queue_len)
return;
this->ch_stat &= ~CH_STAT_WAKE; /* clear wake bit (DMA spec, 5.5.3.4) */
// if there is no data remaining to transfer then the command is finished
// and the program should procede to the next command
this->finish_cmd();
}
switch (cmd_struct.cmd_key >> 4) {
case 0:
LOG_F(9, "Executing DMA Command OUTPUT_MORE");
this->cur_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &this->cur_is_writable);
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
this->cur_cmd = cmd_struct.cmd_key >> 4;
switch (this->cur_cmd) {
case DBDMA_Cmd::OUTPUT_MORE:
case DBDMA_Cmd::OUTPUT_LAST:
case DBDMA_Cmd::INPUT_MORE:
case DBDMA_Cmd::INPUT_LAST:
if (cmd_struct.cmd_key & 7) {
LOG_F(ERROR, "Key > 0 not implemented");
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
break;
}
if (cmd_struct.cmd_bits & 0x3F) {
LOG_F(ERROR, "non-zero i/b/w not implemented");
break;
if (cmd_struct.req_count) {
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
this->queue_data = res.host_va;
this->res_count = cmd_struct.req_count;
this->queue_len = cmd_struct.req_count; // don't set queue_len until all the other fields are set
this->cmd_in_progress = true;
switch (this->cur_cmd) {
case DBDMA_Cmd::OUTPUT_MORE:
case DBDMA_Cmd::OUTPUT_LAST:
this->xfer_to_device();
break;
case DBDMA_Cmd::INPUT_MORE:
case DBDMA_Cmd::INPUT_LAST:
this->xfer_from_device();
break;
}
} else {
this->queue_len = 0;
this->res_count = 0;
this->finish_cmd();
}
// this->dma_cb->dma_push(
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
// cmd_struct.req_count);
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
this->queue_len = cmd_struct.req_count;
this->cmd_ptr += 16;
break;
case 1:
LOG_F(9, "Executing DMA Command OUTPUT_LAST");
if (cmd_struct.cmd_key & 7) {
LOG_F(ERROR, "Key > 0 not implemented");
break;
case DBDMA_Cmd::STORE_QUAD:
if ((cmd_struct.cmd_key & 7) != 6)
LOG_F(ERROR, "%s: Invalid key %d in STORE_QUAD", this->get_name().c_str(),
cmd_struct.cmd_key & 7);
this->xfer_quad(true);
break;
case DBDMA_Cmd::LOAD_QUAD:
if ((cmd_struct.cmd_key & 7) != 6) {
LOG_F(ERROR, "%s: Invalid key %d in LOAD_QUAD", this->get_name().c_str(),
cmd_struct.cmd_key & 7);
}
if (cmd_struct.cmd_bits & 0x3F) {
LOG_F(ERROR, "non-zero i/b/w not implemented");
break;
}
// this->dma_cb->dma_push(
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
// cmd_struct.req_count);
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
this->queue_len = cmd_struct.req_count;
this->cmd_ptr += 16;
this->xfer_quad(false);
break;
case 2:
LOG_F(ERROR, "Unsupported DMA Command INPUT_MORE");
case DBDMA_Cmd::NOP:
this->finish_cmd();
break;
case 3:
LOG_F(ERROR, "Unsupported DMA Command INPUT_LAST");
break;
case 4:
LOG_F(ERROR, "Unsupported DMA Command STORE_QUAD");
break;
case 5:
LOG_F(ERROR, "Unsupported DMA Command LOAD_QUAD");
break;
case 6:
LOG_F(INFO, "Unsupported DMA Command NOP");
break;
case 7:
LOG_F(INFO, "DMA Command: 7 (STOP)");
case DBDMA_Cmd::STOP:
this->ch_stat &= ~CH_STAT_ACTIVE;
this->cmd_in_progress = false;
this->finish_cmd();
break;
default:
LOG_F(ERROR, "Unsupported DMA command 0x%X", cmd_struct.cmd_key >> 4);
LOG_F(ERROR, "%s: Unsupported DMA command 0x%X", this->get_name().c_str(),
this->cur_cmd);
this->ch_stat |= CH_STAT_DEAD;
this->ch_stat &= ~CH_STAT_ACTIVE;
}
return (cmd_struct.cmd_key >> 4);
}
void DMAChannel::interpret_until_blocked() {
// Execute ready commands until a transfer is queued or the channel becomes idle/dead.
while (this->is_active()) {
this->interpret_cmd();
if (this->cmd_in_progress)
break;
}
}
void DMAChannel::update_cmd() {
if (this->cur_is_writable) {
if (this->cur_cmd < DBDMA_Cmd::STOP)
WRITE_WORD_LE_A(&this->cur_host->xfer_stat, this->ch_stat | CH_STAT_ACTIVE);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP)
WRITE_WORD_LE_A(&this->cur_host->res_count, this->res_count);
}
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
}
void DMAChannel::finish_cmd() {
bool branch_taken = false;
// save interrupt bits from the completing command before cmd_ptr may change
uint8_t saved_cmd_bits = this->cur_host->cmd_bits;
// all commands except STOP update cmd.xferStatus and
// perform actions under control of "i" interrupt, "b" branch, and "w" wait bits
if (this->cur_cmd < DBDMA_Cmd::STOP) {
// react to cmd.w (wait) bits
if (saved_cmd_bits & 3) {
bool cond = true;
if ((saved_cmd_bits & 3) != 3) {
uint16_t wt_mask = this->wait_select >> 16;
cond = (this->ch_stat & wt_mask) == (this->wait_select & wt_mask);
if ((saved_cmd_bits & 3) == 2) {
cond = !cond; // wait if cond = false
}
}
if (cond)
return;
}
this->ch_stat &= ~CH_STAT_BT;
// react to cmd.b (branch) bits
if (saved_cmd_bits & 0xC) {
bool cond = true;
if ((saved_cmd_bits & 0xC) != 0xC) {
uint16_t br_mask = this->branch_select >> 16;
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
if ((saved_cmd_bits & 0xC) == 0x8) {
cond = !cond; // branch if cond = false
}
}
if (cond) {
this->cmd_ptr = READ_DWORD_LE_A(&this->cur_host->cmd_arg);
branch_taken = true;
this->ch_stat |= CH_STAT_BT;
}
}
}
this->update_cmd();
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
this->cmd_ptr += 16;
// use the interrupt bits saved before cmd_ptr was advanced or branched
if (this->cur_cmd < DBDMA_Cmd::STOP) {
this->update_irq(saved_cmd_bits);
}
this->cmd_in_progress = false;
}
void DMAChannel::xfer_quad(bool is_store) {
MapDmaResult res;
uint32_t addr = READ_DWORD_LE_A(&this->cur_host->address);
uint16_t req_count = READ_WORD_LE_A (&this->cur_host->req_count);
uint32_t cmd_arg = READ_DWORD_LE_A(&this->cur_host->cmd_arg);
// parse and fix reqCount
uint32_t xfer_size = req_count & 7;
if (xfer_size & 4) {
xfer_size = 4;
} else if (xfer_size & 2) {
xfer_size = 2;
} else {
xfer_size = 1;
}
this->res_count = req_count; // this is the value that gets written to cmd.resCount
if (addr & (xfer_size - 1)) {
LOG_F(ERROR, "%s: QUAD address 0x%08x is not aligned!", this->get_name().c_str(), addr);
addr &= ~(xfer_size - 1);
}
res = mmu_map_dma_mem(addr, xfer_size, true);
// prepare data pointers and perform data transfer
if (is_store) {
if (res.type & RT_MMIO) {
res.dev_obj->write(res.dev_base, addr - res.dev_base,
BYTESWAP_SIZED(cmd_arg, xfer_size), xfer_size);
} else if (res.is_writable) {
switch (xfer_size) {
case 1: *res.host_va = cmd_arg; break;
case 2: WRITE_WORD_LE_A(res.host_va, cmd_arg); break;
case 4: WRITE_DWORD_LE_A(res.host_va, cmd_arg); break;
}
} else {
LOG_F(ERROR, "SOS: DMA access is not to RAM %08X!\n", addr);
}
} else {
uint32_t value;
if (res.type & RT_MMIO) {
value = res.dev_obj->read(res.dev_base, addr - res.dev_base, xfer_size);
} else {
switch (xfer_size) {
case 1: value = *res.host_va; break;
case 2: value = READ_WORD_LE_A(res.host_va); break;
case 4: value = READ_DWORD_LE_A(res.host_va); break;
default: value = 0; break;
}
}
if (!this->cur_is_writable)
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
else
WRITE_DWORD_LE_A(&this->cur_host->cmd_arg, value);
}
if (this->cur_host->cmd_bits & 0xC)
ABORT_F("%s: cmd_bits.b should be zero for LOAD/STORE_QUAD!",
this->get_name().c_str());
this->finish_cmd();
}
void DMAChannel::update_irq(uint8_t cmd_bits) {
// STOP doesn't generate interrupts
if (this->cur_cmd < DBDMA_Cmd::STOP) {
// react to cmd.i (interrupt) bits
if (cmd_bits & 0x30) {
bool cond = true;
if ((cmd_bits & 0x30) != 0x30) {
uint16_t int_mask = this->int_select >> 16;
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
if ((cmd_bits & 0x30) == 0x20) {
cond = !cond; // generate interrupt if cond = false
}
}
if (cond) {
if (this->int_ctrl) {
if (!this->interrupt_timer.active) {
TimerManager::get_instance()->add_immediate_timer(this->interrupt_timer, [this](uint64_t, uint64_t) {
this->int_ctrl->ack_dma_int(this->irq_id, 1);
});
}
} else
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
}
}
}
}
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
uint32_t res = 0;
uint32_t result = 0;
if (size != 4) {
LOG_F(WARNING, "Unsupported non-DWORD read from DMA channel");
return 0;
}
switch (offset) {
switch (offset & ~3) {
case DMAReg::CH_CTRL:
res = 0; /* ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74) */
result = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
break;
case DMAReg::CH_STAT:
res = BYTESWAP_32(this->ch_stat);
result = this->ch_stat;
break;
case DMAReg::CMD_PTR_LO:
result = this->cmd_ptr;
break;
case DMAReg::INT_SELECT:
result = this->int_select;
break;
case DMAReg::BRANCH_SELECT:
result = this->branch_select;
break;
case DMAReg::WAIT_SELECT:
result = this->wait_select;
break;
default:
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
this->get_name().c_str(), offset);
}
return res;
if ((offset & 3) || size != 4)
return BYTESWAP_SIZED(result >> ((offset & 3) * 8), size);
else
return BYTESWAP_32(result);
}
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
uint16_t mask, old_stat, new_stat;
uint16_t mask, data;
if (size != 4) {
LOG_F(WARNING, "Unsupported non-DWORD write to DMA channel");
return;
ABORT_F("%s: non-DWORD writes to a DMA channel not supported",
this->get_name().c_str());
}
value = BYTESWAP_32(value);
old_stat = this->ch_stat;
value = BYTESWAP_32(value);
switch (offset) {
case DMAReg::CH_CTRL:
mask = value >> 16;
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
LOG_F(INFO, "New ChannelStatus value = 0x%X", new_stat);
mask = value >> 16;
data = value & 0xFFFF;
if ((new_stat & CH_STAT_RUN) != (old_stat & CH_STAT_RUN)) {
if (new_stat & CH_STAT_RUN) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->start();
} else {
new_stat &= ~CH_STAT_ACTIVE;
new_stat &= ~CH_STAT_DEAD;
this->ch_stat = new_stat;
this->abort();
}
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
if (new_stat & CH_STAT_PAUSE) {
new_stat &= ~CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->pause();
// update general purpose channel status & control bits s0...s7
// if requested (needed for interrupt generation)
if (mask & 0xFF)
this->ch_stat = (this->ch_stat & ~(mask & 0xFF)) | (data & mask & 0xFF);
// flush bit can be set at the same time the run bit is cleared.
// That means we need to update memory before channel operation
// is aborted to prevent data loss.
if (mask & CH_STAT_FLUSH) {
// FLUSH=1 should update memory for INPUT_MORE & INPUT_LAST commands
// when the channel is active and not dead.
// Setting FLUSH to 0 has no effect.
if (data & CH_STAT_FLUSH) {
if (
(this->cur_cmd == DBDMA_Cmd::INPUT_MORE || this->cur_cmd == DBDMA_Cmd::INPUT_LAST) &&
this->is_active()
) {
this->ch_stat |= CH_STAT_FLUSH;
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_FLUSH);
this->update_cmd();
}
}
this->ch_stat &= ~CH_STAT_FLUSH;
}
if (new_stat & CH_STAT_FLUSH) {
LOG_F(WARNING, "DMA flush not implemented!");
new_stat &= ~CH_STAT_FLUSH;
this->ch_stat = new_stat;
if (mask & CH_STAT_RUN) {
if (data & CH_STAT_RUN) {
// some drivers clear the PAUSE bit while setting the RUN bit.
// Clear the PAUSE bit without resuming the channel operation
// in this case.
if (mask & CH_STAT_PAUSE) {
if (data & CH_STAT_PAUSE)
ABORT_F("%s: Attempt to set both run and pause bits at the same time",
this->get_name().c_str());
else
this->ch_stat &= ~CH_STAT_PAUSE;
}
if (!(this->ch_stat & CH_STAT_ACTIVE)) {
this->ch_stat |= CH_STAT_ACTIVE | CH_STAT_RUN;
this->start();
}
} else {
if (this->ch_stat & CH_STAT_ACTIVE) {
this->abort();
this->update_irq(this->cur_host->cmd_bits);
this->cmd_in_progress = false;
}
this->ch_stat &= ~(CH_STAT_RUN | CH_STAT_ACTIVE | CH_STAT_DEAD);
}
} else if (mask & CH_STAT_PAUSE) {
if (data & CH_STAT_PAUSE) {
if (this->ch_stat & CH_STAT_ACTIVE)
this->pause();
this->ch_stat |= CH_STAT_PAUSE;
this->ch_stat &= ~CH_STAT_ACTIVE;
} else {
this->ch_stat &= ~CH_STAT_PAUSE;
if (!(this->ch_stat & CH_STAT_ACTIVE) && this->is_paused) {
this->is_paused = false;
this->ch_stat |= CH_STAT_ACTIVE;
this->resume();
}
}
} else if (mask & CH_STAT_WAKE) {
if (data & CH_STAT_WAKE && !(this->ch_stat & CH_STAT_ACTIVE)) {
this->ch_stat |= CH_STAT_ACTIVE;
this->resume();
}
}
break;
case DMAReg::CH_STAT:
break; /* ingore writes to ChannelStatus */
case DMAReg::CMD_PTR_LO:
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
this->cmd_ptr = value;
LOG_F(INFO, "CommandPtrLo set to 0x%X", this->cmd_ptr);
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);
}
break;
case DMAReg::CMD_PTR_LO:
if (!(this->ch_stat & CH_STAT_ACTIVE)) { // DBDMA spec 5.5.4 (disagrees with 2.9.1.3)
this->cmd_ptr = value;
LOG_F(9, "%s: CommandPtrLo set to 0x%X%s", this->get_name().c_str(),
this->cmd_ptr, (this->ch_stat & CH_STAT_RUN) ? " while running!" : "");
} else
LOG_F(WARNING, "%s: CommandPtrLo update skipped", this->get_name().c_str());
break;
case DMAReg::INT_SELECT:
this->int_select = value & 0xFF00FFUL;
break;
case DMAReg::BRANCH_SELECT:
this->branch_select = value & 0xFF00FFUL;
break;
case DMAReg::WAIT_SELECT:
this->wait_select = value & 0xFF00FFUL;
break;
default:
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
LOG_F(WARNING, "%s: Unsupported DMA channel register write at 0x%X",
this->get_name().c_str(), offset);
}
}
void DMAChannel::xfer_from_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_FROM_DEV;
int got_bytes = this->dev_obj->xfer_from(this, this->queue_data, this->queue_len);
this->queue_data += got_bytes;
this->res_count -= got_bytes;
this->queue_len -= got_bytes;
if (!this->queue_len) {
this->finish_cmd();
} else if (got_bytes) {
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
this->get_name().c_str());
}
this->interpret_until_blocked();
}
void DMAChannel::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
int got_bytes = this->dev_obj->xfer_to(this, this->queue_data, this->queue_len);
this->queue_data += got_bytes;
this->res_count -= got_bytes;
this->queue_len -= got_bytes;
if (!this->queue_len) {
this->finish_cmd();
}
this->interpret_until_blocked();
}
void DMAChannel::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
bool DMAChannel::dma_is_ready() {
if (!this->is_active() ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP
)
return false;
return true;
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
/* dead or idle channel? -> no more data */
LOG_F(WARNING, "Dead/idle channel -> no more data");
if (!this->is_active()) {
// dead or idle channel? -> no more data
LOG_F(WARNING, "%s: Dead/idle channel -> no more data", this->get_name().c_str());
return DmaPullResult::NoMoreData;
}
/* interpret DBDMA program until we get data or become idle */
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
this->interpret_cmd();
}
// interpret DBDMA program until we get data or become idle
this->interpret_until_blocked();
/* dequeue data if any */
// dequeue data if any
if (this->queue_len) {
if (this->queue_len >= req_len) {
LOG_F(9, "Return req_len = %d data", req_len);
LOG_F(9, "%s: Return req_len = %d data", this->get_name().c_str(), req_len);
*p_data = this->queue_data;
*avail_len = req_len;
this->queue_len -= req_len;
this->res_count -= req_len;
this->queue_data += req_len;
} else { /* return less data than req_len */
LOG_F(9, "Return queue_len = %d data", this->queue_len);
} else { // return less data than req_len
LOG_F(9, "%s: Return queue_len = %d data", this->get_name().c_str(),
this->queue_len);
*p_data = this->queue_data;
*avail_len = this->queue_len;
this->res_count -= this->queue_len;
this->queue_len = 0;
}
return DmaPullResult::MoreData; /* tell the caller there is more data */
return DmaPullResult::MoreData; // tell the caller there is more data
}
return DmaPullResult::NoMoreData; /* tell the caller there is no more data */
return DmaPullResult::NoMoreData; // tell the caller there is no more data
}
bool DMAChannel::is_active()
{
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
DmaPushResult DMAChannel::push_data(const char* src_ptr, int len) {
if (!this->is_active()) {
LOG_F(WARNING, "%s: Attempt to push data to dead/idle channel",
this->get_name().c_str());
return DmaPushResult::NoData;
}
// interpret DBDMA program until we get buffer to fill in or become idle
this->interpret_until_blocked();
if (this->queue_len) {
len = std::min((int)this->queue_len, len);
std::memcpy(this->queue_data, src_ptr, len);
this->queue_data += len;
this->res_count -= len;
this->queue_len -= len;
}
// proceed with the DBDMA program if the buffer became exhausted
if (!this->queue_len) {
this->interpret_until_blocked();
}
return DmaPushResult::PushedData;
}
bool DMAChannel::is_out_active() {
return this->is_active();
}
bool DMAChannel::is_in_active() {
return this->is_active();
}
bool DMAChannel::is_active() {
if ((this->ch_stat & CH_STAT_DEAD) || !(this->ch_stat & CH_STAT_ACTIVE)) {
return false;
}
else {
@@ -237,34 +588,52 @@ bool DMAChannel::is_active()
}
}
void DMAChannel::start()
{
void DMAChannel::start() {
if (this->ch_stat & CH_STAT_PAUSE) {
LOG_F(WARNING, "Cannot start DMA channel, PAUSE bit is set");
LOG_F(WARNING, "%s: Cannot start DMA channel, PAUSE bit is set",
this->get_name().c_str());
this->ch_stat &= ~CH_STAT_ACTIVE; // TODO: Test this in Open Firmware.
return;
}
LOG_F(INFO, "Starting DMA channel, stat = 0x%X", this->ch_stat);
this->queue_len = 0;
this->start_cb();
this->cmd_in_progress = false;
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_START);
if (this->start_cb)
this->start_cb();
this->interpret_until_blocked();
}
void DMAChannel::resume() {
if (this->ch_stat & CH_STAT_PAUSE) {
LOG_F(WARNING, "Cannot resume DMA channel, PAUSE bit is set");
LOG_F(WARNING, "%s: Cannot resume DMA channel, PAUSE bit is set",
this->get_name().c_str());
return;
}
LOG_F(INFO, "Resuming DMA channel");
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
this->interpret_until_blocked();
}
void DMAChannel::abort() {
LOG_F(INFO, "Aborting DMA channel");
LOG_F(9, "%s: Aborting DMA channel", this->get_name().c_str());
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_STOP);
if (this->stop_cb)
this->stop_cb();
}
void DMAChannel::pause() {
LOG_F(INFO, "Pausing DMA channel");
this->stop_cb();
LOG_F(INFO, "%s: Pausing DMA channel", this->get_name().c_str());
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_STOP);
if (this->stop_cb)
this->stop_cb();
this->is_paused = true;
}
+114 -33
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,71 +29,152 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DB_DMA_H
#define DB_DMA_H
#include <core/timermanager.h>
#include <devices/common/dmacore.h>
#include <cinttypes>
#include <functional>
class InterruptCtrl;
/** DBDMA Channel registers offsets */
enum DMAReg : uint32_t {
CH_CTRL = 0,
CH_STAT = 4,
CMD_PTR_LO = 12,
CH_CTRL = 0,
CH_STAT = 4,
CMD_PTR_HI = 8, // not implemented
CMD_PTR_LO = 12,
INT_SELECT = 16,
BRANCH_SELECT = 20,
WAIT_SELECT = 24,
// TANSFER_MODES = 28,
// DATA_2_PTR_HI = 32, // not implemented
// DATA_2_PTR_LO = 36,
// RESERVED_1 = 40,
// ADDRESS_HI = 44,
// RESERVED_2_0 = 48,
// RESERVED_2_1 = 52,
// RESERVED_2_2 = 56,
// RESERVED_2_3 = 60,
// UNIMPLEMENTED = 64,
// UNDEFINED = 128,
};
/** Channel Status bits (DBDMA spec, 5.5.3) */
enum {
CH_STAT_ACTIVE = 0x400,
CH_STAT_DEAD = 0x800,
CH_STAT_WAKE = 0x1000,
CH_STAT_FLUSH = 0x2000,
CH_STAT_PAUSE = 0x4000,
CH_STAT_RUN = 0x8000
enum : uint16_t {
CH_STAT_S0 = 0x0001, // general purpose status and control
CH_STAT_S1 = 0x0002, // general purpose status and control
CH_STAT_S2 = 0x0004, // general purpose status and control
CH_STAT_S3 = 0x0008, // general purpose status and control
CH_STAT_S4 = 0x0010, // general purpose status and control
CH_STAT_S5 = 0x0020, // general purpose status and control
CH_STAT_S6 = 0x0040, // general purpose status and control
CH_STAT_S7 = 0x0080, // general purpose status and control
CH_STAT_BT = 0x0100, // hardware status bit
CH_STAT_ACTIVE = 0x0400, // hardware status bit
CH_STAT_DEAD = 0x0800, // hardware status bit
CH_STAT_WAKE = 0x1000, // command bit set by software and cleared by hardware once the action has been performed
CH_STAT_FLUSH = 0x2000, // command bit set by software and cleared by hardware once the action has been performed
CH_STAT_PAUSE = 0x4000, // control bit set and cleared by software
CH_STAT_RUN = 0x8000 // control bit set and cleared by software
};
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
typedef struct DMACmd {
uint16_t req_count;
uint8_t cmd_bits;
uint8_t cmd_key;
uint32_t address;
uint32_t cmd_arg;
uint16_t res_count;
uint16_t xfer_stat;
uint16_t req_count;
uint8_t cmd_bits; // wait: & 3, branch: & 0xC, interrupt: & 0x30, reserved: & 0xc0
uint8_t cmd_key; // key: & 7, reserved: & 8, cmd: >> 4
uint32_t address;
uint32_t cmd_arg;
uint16_t res_count;
uint16_t xfer_stat;
} DMACmd;
namespace DBDMA_Cmd {
enum : uint8_t {
OUTPUT_MORE = 0,
OUTPUT_LAST = 1,
INPUT_MORE = 2,
INPUT_LAST = 3,
STORE_QUAD = 4,
LOAD_QUAD = 5,
NOP = 6,
STOP = 7
};
}
typedef std::function<void(void)> DbdmaCallback;
class DMAChannel : public DmaOutChannel {
class DMAChannel : public DmaBidirChannel, public DmaChannel {
public:
DMAChannel() = default;
DMAChannel(std::string name) : DmaBidirChannel(name) {}
~DMAChannel() = default;
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
uint32_t reg_read(uint32_t offset, int size);
void reg_write(uint32_t offset, uint32_t value, int size);
bool is_active();
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
void set_stat(uint8_t new_stat) {
this->ch_stat = (this->ch_stat & 0xff00) | new_stat;
}
void update_ch_stat(uint8_t mask, uint8_t new_val) {
this->ch_stat = (this->ch_stat & ~mask) | new_val;
}
bool is_out_active() override;
bool is_in_active() override;
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
DmaPushResult push_data(const char* src_ptr, int len) override;
bool dma_is_ready() override;
void xfer_retry() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
this->int_ctrl = int_ctrl_obj;
this->irq_id = irq_id;
}
protected:
void get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
uint8_t interpret_cmd(void);
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
void interpret_cmd(void);
void interpret_until_blocked();
void update_cmd();
void finish_cmd();
void xfer_quad(bool is_store);
void update_irq(uint8_t cmd_bits);
void xfer_from_device();
void xfer_to_device();
void start(void);
void resume(void);
void abort(void);
void pause(void);
bool is_active();
private:
std::function<void(void)> start_cb; // DMA channel start callback
std::function<void(void)> stop_cb; // DMA channel stop callback
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
uint16_t ch_stat = 0;
uint32_t cmd_ptr = 0;
uint16_t ch_stat = 0;
uint32_t cmd_ptr = 0;
uint32_t queue_len = 0;
uint8_t* queue_data = 0;
uint32_t res_count = 0;
uint32_t int_select = 0;
uint32_t branch_select = 0;
uint32_t wait_select = 0;
uint32_t queue_len;
uint8_t* queue_data;
bool cmd_in_progress = false;
bool is_paused = false;
uint8_t cur_cmd;
DMACmd * cur_host = nullptr; // host virtual address of current command
bool cur_is_writable = false; // current command is writable
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
TimerInfo interrupt_timer;
};
#endif /* DB_DMA_H */
#endif // DB_DMA_H
+114 -9
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,27 +24,132 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DMA_CORE_H
#define DMA_CORE_H
#include <cstdint>
#include <cinttypes>
#include <string>
enum DmaPullResult : int {
MoreData, // data source has more data to be pulled
NoMoreData, // data source has no more data to be pulled
};
enum DmaPushResult : int {
NoData = -1, // data source is not running
PushedData = 0, // data was pushed
};
class DmaOutChannel {
public:
virtual bool is_active() { return true; };
DmaOutChannel(std::string name) { this->name = name; }
virtual bool is_out_active() { return true; }
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
std::string get_name(void) { return this->name; }
private:
std::string name;
};
class DmaInChannel {
public:
DmaInChannel(std::string name) { this->name = name; }
virtual bool is_in_active() { return true; }
virtual DmaPushResult push_data(const char* src_ptr, int len) = 0;
std::string get_name(void) { return this->name; }
private:
std::string name;
};
// Base class for bidirectional DMA channels.
class DmaBidirChannel {
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
public:
virtual bool is_active() { return true; };
virtual int push_data(const char* src_ptr, int len) = 0;
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
DmaInChannel(name + std::string(" In")) { this->name = name; }
std::string get_name(void) { return this->name; }
private:
std::string name;
};
// ---------------------- New DMA API -------------------------
/** DMA channel types. */
enum DmaChannelType : unsigned {
DMA_CH_TYPE_UNDEF = 0,
DMA_CH_TYPE_IN, // unidirectional channel, host <--- device
DMA_CH_TYPE_OUT, // unidirectional channel, host ---> device
DMA_CH_TYPE_BIDIR, // bidirectional channel, host <--> device
};
/** DMA messages. */
enum DmaMsg : unsigned {
DMA_MSG_START = 1,
DMA_MSG_STOP,
DMA_MSG_FLUSH,
DMA_MSG_DATA_AVAIL,
};
/** DMA transfer direction constants. */
enum XferDir : unsigned {
DMA_DIR_UNDEF = 0,
DMA_DIR_TO_DEV,
DMA_DIR_FROM_DEV,
};
class DmaChannel;
class DmaDevice {
public:
DmaDevice() = default;
~DmaDevice() = default;
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
virtual void notify(DmaChannel *ch_obj, DmaMsg msg) {}
virtual int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) { return len; }
virtual int xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) { return len; }
virtual int tell_xfer_size(DmaChannel *ch_obj) { return 0; }
protected:
DmaChannel* channel_obj = nullptr;
};
class DmaChannel {
public:
DmaChannel(const uint32_t id = 1) { this->ch_id = id; }
DmaChannel(const DmaChannelType type, const uint32_t id = 1) {
this->ch_type = type;
this->ch_id = id;
}
~DmaChannel() = default;
// setters/getters
void set_id(const uint32_t id) { this->ch_id = id; }
uint32_t get_id() { return this->ch_id; }
void set_type(const DmaChannelType type) { this->ch_type = type; }
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; }
virtual void notify(DmaMsg msg) {}
virtual bool dma_is_ready() { return false; }
virtual void xfer_retry() {}
protected:
DmaDevice* dev_obj = nullptr;
uint32_t ch_id = 0; // support for several channels per device
DmaChannelType ch_type = DMA_CH_TYPE_BIDIR;
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
+38 -29
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,26 +26,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
/** types of different HW components */
enum HWCompType {
UNKNOWN = 0ULL, /* unknown component type */
MEM_CTRL = 1ULL << 0, /* memory controller */
NVRAM = 1ULL << 1, /* non-volatile random access memory */
ROM = 1ULL << 2, /* read-only memory */
RAM = 1ULL << 3, /* random access memory */
MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */
PCI_HOST = 1ULL << 5, /* PCI host */
PCI_DEV = 1ULL << 6, /* PCI device */
I2C_HOST = 1ULL << 8, /* I2C host */
I2C_DEV = 1ULL << 9, /* I2C device */
ADB_HOST = 1ULL << 12, /* ADB host */
ADB_DEV = 1ULL << 13, /* ADB device */
INT_CTRL = 1ULL << 16, /* interrupt controller */
SCSI_BUS = 1ULL << 20, /* SCSI bus */
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
SCSI_DEV = 1ULL << 22, /* SCSI device */
SND_SERVER = 1ULL << 31, /* host sound server */
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
enum HWCompType : uint64_t {
UNKNOWN = 0ULL, // unknown component type
MEM_CTRL = 1ULL << 0, // memory controller
NVRAM = 1ULL << 1, // non-volatile random access memory
ROM = 1ULL << 2, // read-only memory
RAM = 1ULL << 3, // random access memory
MMIO_DEV = 1ULL << 4, // memory mapped I/O device
PCI_HOST = 1ULL << 5, // PCI host
PCI_DEV = 1ULL << 6, // PCI device
NUBUS_DEV = 1ULL << 7, // Nubus device
I2C_HOST = 1ULL << 8, // I2C host
I2C_DEV = 1ULL << 9, // I2C device
ADB_HOST = 1ULL << 12, // ADB host
ADB_DEV = 1ULL << 13, // ADB device
IOBUS_HOST = 1ULL << 14, // IOBus host
IOBUS_DEV = 1ULL << 15, // IOBus device
INT_CTRL = 1ULL << 16, // interrupt controller
SCSI_BUS = 1ULL << 20, // SCSI bus
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
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
MACHINE = 1ULL << 41, // machine root
};
/** Base class for HW components. */
@@ -56,26 +65,26 @@ public:
virtual std::string get_name(void) {
return this->name;
};
}
virtual void set_name(std::string name) {
this->name = name;
};
}
virtual bool supports_type(HWCompType type) {
return !!(this->supported_types & type);
};
}
virtual void supports_types(uint64_t types) {
this->supported_types = types;
};
}
virtual int device_postinit() {
return 0;
};
}
protected:
std::string name;
uint64_t supported_types = HWCompType::UNKNOWN;
};
#endif /* HW_COMPONENT_H */
#endif // HW_COMPONENT_H
+79 -14
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,13 +27,73 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
//#define DEBUG_CPU_INT // uncomment this to enable hacks for debugging HW interrupts
/** Enumerator for various interrupt sources. */
enum IntSrc : int {
VIA_CUDA = 1,
SCSI1 = 2,
SWIM3 = 3,
SCC = 4,
ETHERNET = 5,
NMI = 6,
enum IntSrc : uint32_t {
INT_UNKNOWN = 0,
VIA_CUDA,
VIA2,
SCSI_MESH,
SCSI_CURIO,
SWIM3,
ESCC,
SCCA,
SCCB,
ETHERNET,
NMI,
EXT1,
IDE0,
IDE1,
DAVBUS,
PERCH1,
PERCH2,
PCI_A,
PCI_B,
PCI_C,
PCI_D,
PCI_E,
PCI_F,
PCI_GPU,
PCI_PERCH,
BANDIT1,
BANDIT2,
CONTROL,
SIXTY6,
PLANB,
VCI,
PLATINUM,
DMA_ALL,
DMA_SCSI_MESH,
DMA_SCSI_CURIO,
DMA_SWIM3,
DMA_IDE0,
DMA_IDE1,
DMA_SCCA_Tx,
DMA_SCCA_Rx,
DMA_SCCB_Tx,
DMA_SCCB_Rx,
DMA_DAVBUS_Tx,
DMA_DAVBUS_Rx,
DMA_ETHERNET_Tx,
DMA_ETHERNET_Rx,
FIREWIRE,
PCI_J12,
PCI_J11,
PCI_J10,
PCI_J9,
ATA,
USB,
PIPPIN_E,
PIPPIN_F,
ZIVA,
PCI_CARDBUS,
MEDIA_BAY,
SLOT_ALL,
SLOT_0,
SLOT_1,
SLOT_2,
SLOT_PDS,
SLOT_VDS,
VBL,
VALKYRIE,
};
/** Base class for interrupt controllers. */
@@ -43,12 +103,17 @@ public:
virtual ~InterruptCtrl() = default;
// register interrupt sources for a device
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
virtual uint64_t register_dev_int(IntSrc src_id) = 0;
virtual uint64_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
};
typedef struct {
InterruptCtrl *int_ctrl_obj;
uint64_t irq_id;
} IntDetails;
#endif // HW_INTERRUPT_H
+22 -14
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,14 +27,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <stdexcept>
#include <cstring>
#include <string>
#include <devices/common/hwcomponent.h>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept>
#include <string>
/** Base class for I2C devices */
class I2CDevice {
class I2CDevice : virtual public HWComponent {
public:
I2CDevice() {
supports_types(HWCompType::I2C_DEV);
}
virtual ~I2CDevice() = default;
virtual void start_transaction() = 0;
virtual bool send_subaddress(uint8_t sub_addr) = 0;
virtual bool send_byte(uint8_t data) = 0;
@@ -42,11 +50,11 @@ public:
};
/** Base class for I2C hosts */
class I2CBus {
class I2CBus : virtual public HWComponent {
public:
I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
};
}
virtual ~I2CBus() = default;
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
@@ -55,7 +63,7 @@ public:
}
this->dev_list[dev_addr] = dev_obj;
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
};
}
virtual bool start_transaction(uint8_t dev_addr) {
if (this->dev_list[dev_addr]) {
@@ -64,28 +72,28 @@ public:
} else {
return false;
}
};
}
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
};
}
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_byte(data);
};
}
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->receive_byte(p_data);
};
}
protected:
I2CDevice* dev_list[128]; /* list of registered I2C devices */
+7 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
#include <memory>
I2CProm::I2CProm(uint8_t dev_addr, int size)
{
@@ -55,17 +54,17 @@ void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
void I2CProm::start_transaction() {
this->pos = 0;
};
}
bool I2CProm::send_subaddress(uint8_t sub_addr) {
this->pos = sub_addr;
return true;
};
}
bool I2CProm::send_byte(uint8_t data) {
LOG_F(9, "I2CRom: 0x%X received", data);
return true;
};
}
bool I2CProm::receive_byte(uint8_t* p_data) {
if (this->pos >= this->rom_size) {
@@ -73,4 +72,4 @@ bool I2CProm::receive_byte(uint8_t* p_data) {
}
*p_data = this->data[this->pos++];
return true;
};
}
+4 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,14 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_PROM_H
#define I2C_PROM_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
#include <memory>
class I2CProm : public I2CDevice, public HWComponent
{
class I2CProm : public I2CDevice {
public:
I2CProm(uint8_t dev_addr, int size);
~I2CProm() = default;
+57 -16
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/hwcomponent.h>
#include <devices/common/mmiodevice.h>
#include <devices/ioctrl/macio.h>
#include <cinttypes>
#include <loguru.hpp>
#include <string>
/**
@file Contains definitions for PowerMacintosh machine ID registers.
@file Contains definitions for Power Macintosh machine ID registers.
The machine ID register is a memory-based register containing hardcoded
values the system software can read to identify machine/board it's running on.
@@ -37,10 +40,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
Machine ID register for Nubus Power Macs.
Machine ID register for NuBus Power Macs.
It's located at physical address 0x5FFFFFFC and contains four bytes:
+0 uint16_t signature = 0xA55A
+1 uint8_t machine_type (3 - PowerMac)
+1 uint8_t machine_type (0x30 - Power Mac)
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
*/
class NubusMacID : public MMIODevice {
@@ -52,20 +55,57 @@ public:
this->id[2] = (id >> 8) & 0xFF;
this->id[3] = id & 0xFF;
supports_types(HWCompType::MMIO_DEV);
};
}
~NubusMacID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
return (offset < 4 ? this->id[offset] : 0);
};
if (size == 4 && offset == 0) {
return *(uint32_t*)this->id;
}
if (size == 1 && offset < 4) {
return this->id[offset];
}
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
return 0;
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint8_t id[4];
};
/**
TNT-style machines and derivatives provide two board registers
telling whether some particular piece of HW is installed or not.
Both board registers are attached to the IOBus of the I/O controller.
See machines/machinetnt.cpp for further details.
**/
class BoardRegister : public HWComponent, public IobusDevice {
public:
BoardRegister(std::string name, const uint16_t data) {
this->set_name(name);
supports_types(HWCompType::IOBUS_DEV);
this->data = data;
}
~BoardRegister() = default;
uint16_t iodev_read(uint32_t address) {
return this->data;
}
// appears read-only to guest
void iodev_write(uint32_t address, uint16_t value) {}
void update_bits(const uint16_t val, const uint16_t mask) {
this->data = (this->data & ~mask) | (val & mask);
}
private:
uint16_t data;
};
/**
The machine ID for the Gossamer board is accesible at 0xFF000004 (phys).
It contains a 16-bit value revealing machine's capabilities like bus speed,
@@ -75,20 +115,21 @@ private:
class GossamerID : public MMIODevice {
public:
GossamerID(const uint16_t id) {
this->id = id, this->name = "Machine-id";
this->id = id;
this->name = "Machine-id";
supports_types(HWCompType::MMIO_DEV);
};
}
~GossamerID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
return ((!offset && size == 2) ? this->id : 0);
};
return ((offset == 4 && size == 2) ? this->id : 0);
}
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
private:
uint16_t id;
};
#endif /* MACHINE_ID_H */
#endif // MACHINE_ID_H
+6 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -36,4 +36,7 @@ public:
virtual ~MMIODevice() = default;
};
#define SIZE_ARG(size) (size == 4 ? 'l' : size == 2 ? 'w' : \
size == 1 ? 'b' : '0' + size)
#endif /* MMIO_DEVICE_H */
+156
View File
@@ -0,0 +1,156 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/memaccess.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <cinttypes>
#include <fstream>
#include <sstream>
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
{
uint32_t sum = 0;
for (int i = 0; i < length; i++) {
// rotate sum left by one bit
if (sum & 0x80000000UL)
sum = (sum << 1) | 1;
else
sum = (sum << 1) | 0;
sum += data_ptr[i];
}
return sum;
}
int load_declaration_rom(const std::string rom_path, int slot_num)
{
std::ifstream rom_file;
int result = 0;
try {
rom_file.open(rom_path, std::ios::in | std::ios::binary);
if (rom_file.fail())
throw std::runtime_error("could not open declaration ROM image " + rom_path);
// determine image size
rom_file.seekg(0, std::ios::end);
uint64_t rom_size = rom_file.tellg();
if (rom_size > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// load it
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
rom_file.seekg(0, std::ios::beg);
rom_file.read((char *)rom_data.get(), rom_size);
// verify image data
uint8_t byte_lane = rom_data[rom_size - 1];
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF))
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid byte lane value");
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL)
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid test pattern");
if (rom_data[rom_size - 7] != 1)
throw std::runtime_error("declaration ROM image " + rom_path +
" has unsupported format");
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
// patch the CRC field of the format header to 0
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
// restore the CRC field value
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
if (test_crc != crc) {
std::stringstream err;
err << "declaration ROM image " + rom_path + " has invalid CRC, expected = 0x"
<< std::hex << crc << ", got = 0x" << std::hex << test_crc;
throw std::runtime_error(err.str());
}
int lanes_used = 0;
// count meaningful lanes in a data quad
for (int i = 0; i < 4; i++) {
if (byte_lane & (1 << i))
lanes_used++;
}
// padded_len is the size in bytes of all pages needed to contain all the bytes of the ROM
uint32_t padded_len =
uint32_t(((rom_size * 4 + lanes_used - 1) / lanes_used + 4095) / 4096 * 4096);
if (padded_len > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// calculate starting physical address of the ROM
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len))
throw std::runtime_error("could not allocate ROM space for declaration ROM image " +
rom_path);
int data_pos = int(rom_size) - 1;
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
// prepare new ROM data by copying over used lanes
// and padding unused lanes with 0xFF
// NOTE: speed uncritical - don't optimize!
for (int i = padded_len - 1; i >= 0; ) {
for (int b = 8; i>= 0 && b != 0; b >>= 1) {
if (data_pos >= 0 && (byte_lane & b))
new_data[i--] = rom_data[data_pos--];
else
new_data[i--] = 0xFF;
}
}
// move padded ROM data to the memory region
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
result = -1;
}
rom_file.close();
return result;
}
+30
View File
@@ -0,0 +1,30 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef NUBUS_UTILS_H
#define NUBUS_UTILS_H
#include <cinttypes>
#include <string>
int load_declaration_rom(const std::string rom_path, int slot_num);
#endif // NUBUS_UTILS_H
+19 -12
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,14 +19,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nvram.h>
#include <devices/common/ofnvram.h>
#include <devices/deviceregistry.h>
#include <cinttypes>
#include <cstring>
#include <fstream>
#include <iostream>
#include <loguru.hpp>
/** @file Non-volatile RAM implementation.
@@ -46,15 +47,17 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
this->file_name = file_name;
this->ram_size = ram_size;
this->storage = new uint8_t[ram_size];
if (ram_size == 8192)
this->of_nvram_offset = OF_NVRAM_OFFSET;
// allocate memory storage and fill it with zeroes
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
this->init();
}
NVram::~NVram() {
this->save();
if (this->storage)
delete this->storage;
}
uint8_t NVram::read_byte(uint32_t offset) {
@@ -74,15 +77,19 @@ void NVram::init() {
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) ||
!f.read((char*)&data_size, sizeof(data_size)) ||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
!f.read((char*)this->storage, this->ram_size)) {
LOG_F(WARNING, "Could not restore NVRAM content from the given file.");
memset(this->storage, 0, sizeof(this->ram_size));
!f.read((char*)this->storage.get(), this->ram_size)) {
LOG_F(WARNING, "Could not restore NVRAM content from the given file \"%s\".", this->file_name.c_str());
memset(this->storage.get(), 0, this->ram_size);
}
f.close();
}
void NVram::save() {
if (is_deterministic) {
LOG_F(INFO, "Skipping NVRAM write to \"%s\" in deterministic mode", this->file_name.c_str());
return;
}
ofstream f(this->file_name, ios::out | ios::binary);
/* write file identification */
@@ -90,13 +97,13 @@ void NVram::save() {
f.write((char*)&this->ram_size, sizeof(this->ram_size));
/* write NVRAM content */
f.write((char*)this->storage, this->ram_size);
f.write((char*)this->storage.get(), this->ram_size);
f.close();
}
static const DeviceDescription Nvram_Descriptor = {
NVram::create, {}, {}
NVram::create, {}, {}, HWCompType::NVRAM
};
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
+6 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -45,11 +45,13 @@ public:
uint8_t read_byte(uint32_t offset);
void write_byte(uint32_t offset, uint8_t value);
uint32_t get_of_nvram_offset() { return of_nvram_offset; }
private:
std::string file_name; // file name for the backing file
uint16_t ram_size; // NVRAM size
uint8_t* storage;
std::unique_ptr<uint8_t[]> storage;
uint32_t of_nvram_offset = 0;
void init();
void save();
+397 -95
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,27 +19,35 @@ 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 Utilities for working with the Apple Open Firmware NVRAM partition. */
/** Utilities for working with Apple Open Firmware and CHRP NVRAM partitions. */
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <devices/common/ofnvram.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <devices/common/nvram.h>
#include <machines/machinebase.h>
#include <memaccess.h>
#include <cinttypes>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <tuple>
using namespace std;
static std::string hex2str(uint32_t n)
{
std::stringstream ss;
ss << setw(8) << right << setfill('0') << hex << n;
return ss.str();
}
static uint32_t str2env(string& num_str) {
try {
return stoul(num_str, NULL, 0);
return (uint32_t)stoul(num_str, NULL, 0);
} catch (invalid_argument& exc) {
try {
string num_str2 = string("0x") + num_str;
@@ -50,23 +58,16 @@ static uint32_t str2env(string& num_str) {
}
}
int OfNvramUtils::init()
{
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
return this->nvram_obj == nullptr;
}
bool OfNvramUtils::validate()
{
int i;
OfNvramHdr hdr;
bool OfConfigAppl::validate() {
int i;
OfConfigHdrAppl hdr{};
if (this->nvram_obj == nullptr)
return false;
// read OF partition header
for (i = 0; i < sizeof(OfNvramHdr); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// validate partition signature and version
@@ -75,23 +76,22 @@ bool OfNvramUtils::validate()
this->size = hdr.num_pages * 256;
if (this->size != 0x800)
if (this->size != OF_CFG_SIZE)
return false;
// read the entire partition into the local buffer
for (i = 0; i < this->size; i++) {
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
this->buf[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
}
// verify partition checksum
if (this->checksum_partition() ^ 0xFFFFU)
if (this->checksum_partition() != 0xFFFFU)
return false;
return true;
}
uint16_t OfNvramUtils::checksum_partition()
{
uint16_t OfConfigAppl::checksum_partition() {
uint32_t acc = 0;
for (int i = 0; i < this->size; i += 2) {
@@ -101,26 +101,7 @@ uint16_t OfNvramUtils::checksum_partition()
return acc + (acc >> 16);
}
void OfNvramUtils::update_partition()
{
// set checksum in the header to zero
this->buf[4] = 0;
this->buf[5] = 0;
// calculate new checksum
uint16_t checksum = this->checksum_partition();
checksum = checksum ? ~checksum : 0xFFFFU;
// stuff it into the header
WRITE_WORD_BE_A(&this->buf[4], checksum);
// write the entire partition back to NVRAM
for (int i = 0; i < this->size; i++) {
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
}
}
static const string flag_names[8] = {
static const string flag_names[] = {
"little-endian?",
"real-mode?",
"auto-boot?",
@@ -128,8 +109,10 @@ static const string flag_names[8] = {
"fcode-debug?",
"oem-banner?",
"oem-logo?",
"use-nvramrc?"
"use-nvramrc?",
"f-segment?" // ANS only
};
constexpr int num_flags = sizeof(flag_names) / sizeof(flag_names[0]);
static const map<string, std::tuple<int, uint16_t>> of_vars = {
// name, type, offset
@@ -154,61 +137,77 @@ static const map<string, std::tuple<int, uint16_t>> of_vars = {
{"boot-command", {OF_VAR_TYPE_STR, 0x58}},
};
void OfNvramUtils::printenv()
{
int i;
const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
this->_config_vars.clear();
if (!this->validate()) {
cout << "Invalid Open Firmware partition content!" << endl;
return;
if (!this->validate())
return _config_vars;
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
// populate flags
for (unsigned i = 0; i < num_flags; i++) {
_config_vars.push_back(std::make_pair(flag_names[i],
(int32_t(of_flags << i) < 0) ? "true" : "false"));
}
uint8_t of_flags = this->buf[12];
cout << endl;
// print flags
for (i = 0; i < 8; i++) {
cout << setw(20) << left << flag_names[i] <<
(((of_flags << i) & 0x80) ? "true" : "false") << endl;
}
// print the remaining variables
// populate the remaining variables
for (auto& var : of_vars) {
auto type = std::get<0>(var.second);
auto offset = std::get<1>(var.second);
cout << setw(20) << left << var.first;
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:
cout << hex << READ_DWORD_BE_A(&this->buf[offset]) << endl;
_config_vars.push_back(std::make_pair(name,
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
break;
case OF_VAR_TYPE_STR:
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - this->nvram_obj->get_of_nvram_offset();
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
for (i = 0; i < str_len; i++) {
char ch = *(char *)&(this->buf[str_offset + i]);
if (ch == '\x0D') cout << endl; else cout << ch;
if ((str_offset + str_len) > OF_CFG_SIZE) {
cout << "string property too long - skip it" << endl;
break;
}
cout << endl;
char prop_val[OF_CFG_SIZE] = "";
memcpy(prop_val, &this->buf[str_offset], str_len);
prop_val[str_len] = '\0';
_config_vars.push_back(std::make_pair(name, prop_val));
}
}
cout << endl;
return _config_vars;
}
void OfNvramUtils::setenv(string var_name, string value)
{
void OfConfigAppl::update_partition() {
// set checksum in the header to zero
this->buf[4] = 0;
this->buf[5] = 0;
// calculate new checksum
uint16_t checksum = this->checksum_partition();
checksum = ~checksum;
// stuff checksum into the header
WRITE_WORD_BE_A(&this->buf[4], checksum);
// write the entire partition back to NVRAM
for (int i = 0; i < this->size; i++) {
this->nvram_obj->write_byte(this->nvram_obj->get_of_nvram_offset() + i, this->buf[i]);
}
}
bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
int i, flag;
if (!this->validate()) {
cout << "Invalid Open Firmware partition content!" << endl;
return;
}
if (!this->validate())
return false;
// check if the user tries to change a flag
for (i = 0; i < 8; i++) {
for (i = 0; i < num_flags; i++) {
if (var_name == flag_names[i]) {
if (value == "true")
flag = 1;
@@ -216,27 +215,26 @@ void OfNvramUtils::setenv(string var_name, string value)
flag = 0;
else {
cout << "Invalid property value: " << value << endl;
return;
return false;
}
uint8_t flag_bit = 0x80U >> i;
uint8_t of_flags = this->buf[12];
uint32_t flag_bit = 0x80000000U >> i;
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
if (flag)
of_flags |= flag_bit;
else
of_flags &= ~flag_bit;
this->buf[12] = of_flags;
WRITE_DWORD_BE_A(&this->buf[12], of_flags);
this->update_partition();
cout << " ok" << endl; // mimic Forth
return;
return true;
}
}
// see if one of the standard properties should be changed
if (of_vars.find(var_name) == of_vars.end()) {
cout << "Attempt to change unknown variable " << var_name << endl;
return;
return false;
}
auto type = std::get<0>(of_vars.at(var_name));
@@ -248,16 +246,15 @@ void OfNvramUtils::setenv(string var_name, string value)
num = str2env(value);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
return false;
}
WRITE_DWORD_BE_A(&this->buf[offset], num);
this->update_partition();
cout << " ok" << endl; // mimic Forth
} else {
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]);
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
OfNvramHdr *hdr = (OfNvramHdr *)&this->buf[0];
OfConfigHdrAppl *hdr = (OfConfigHdrAppl *)&this->buf[0];
uint16_t here = READ_WORD_BE_A(&hdr->here);
uint16_t top = READ_WORD_BE_A(&hdr->top);
@@ -266,11 +263,13 @@ void OfNvramUtils::setenv(string var_name, string value)
uint16_t new_top = top + str_len - value.length();
if (new_top < here) {
cout << "No room in the heap!" << endl;
return;
return false;
}
// remove the old string
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET], &this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
std::memmove(&this->buf[top + str_len - this->nvram_obj->get_of_nvram_offset()],
&this->buf[top - this->nvram_obj->get_of_nvram_offset()], str_offset - top);
for (auto& var : of_vars) {
auto type = std::get<0>(var.second);
auto offset = std::get<1>(var.second);
@@ -286,7 +285,7 @@ void OfNvramUtils::setenv(string var_name, string value)
// copy new string into NVRAM buffer char by char
i = 0;
for(char& ch : value) {
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
this->buf[top + i - this->nvram_obj->get_of_nvram_offset()] = ch == '\x0A' ? '\x0D' : ch;
i++;
}
@@ -299,7 +298,310 @@ void OfNvramUtils::setenv(string var_name, string value)
// update physical NVRAM
this->update_partition();
cout << " ok" << endl; // mimic Forth
}
return true;
}
uint8_t OfConfigChrp::checksum_hdr(const uint8_t* data)
{
uint16_t sum = data[0];
for (int i = 2; i < 16; i++) {
sum += data[i];
if (sum >= 256)
sum = (sum + 1) & 0xFFU;
}
return sum;
}
bool OfConfigChrp::validate()
{
int i, pos, len;
uint8_t sig;
bool wip = true;
bool of_part_found = false;
if (this->nvram_obj == nullptr)
return false;
// search the entire 8KB NVRAM for CHRP OF config partition.
// Bail out if an unknown partition or free space is encountered.
// Skip over known partitions.
for (pos = 0; wip && pos < 8192;) {
sig = this->nvram_obj->read_byte(pos);
switch (sig) {
case NVRAM_SIG_OF_ENV:
of_part_found = true;
// fall-through
case NVRAM_SIG_FREE:
wip = false;
break;
case NVRAM_SIG_VPD:
case NVRAM_SIG_DIAG:
case NVRAM_SIG_OF_CFG:
case NVRAM_SIG_MAC_OS:
case NVRAM_SIG_ERR_LOG:
// skip valid partitions we're not interested in
len = (this->nvram_obj->read_byte(pos + 2) << 8) |
this->nvram_obj->read_byte(pos + 3);
if (!len || (len * 16) >= 8192)
break;
pos += len * 16;
break;
default:
wip = false;
}
}
if (!of_part_found)
return false;
OfConfigHdrChrp hdr{};
// read OF partition header
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(pos + i);
}
len = BYTESWAP_16(hdr.length) * 16;
// sanity checks
if (hdr.sig != NVRAM_SIG_OF_ENV || len < 16 || len > (4096 + sizeof(OfConfigHdrChrp)))
return false;
// calculate partition header checksum
uint8_t chk_sum = this->checksum_hdr((uint8_t*)&hdr);
if (chk_sum != hdr.checksum)
return false;
len -= sizeof(OfConfigHdrChrp);
pos += sizeof(OfConfigHdrChrp);
this->data_offset = pos;
// read the entire partition into the local buffer
for (i = 0; i < len; i++) {
this->buf[i] = this->nvram_obj->read_byte(pos + i);
}
return true;
}
const OfConfigImpl::config_dict& OfConfigChrp::get_config_vars() {
int len;
this->_config_vars.clear();
this->data_length = 0;
if (!this->validate())
return _config_vars;
for (int pos = 0; pos < 4096;) {
char *pname = (char *)&this->buf[pos];
bool got_name = false;
// scan property name until '=' is encountered
// or max length is reached
for (len = 0; ; pos++, len++) {
if (len >= 32) {
cout << "name > 31 chars" << endl;
break;
}
if (pos >= 4096) {
cout << "no = sign before end of partition" << endl;
break;
}
if (pname[len] == '=') {
if (len) {
got_name = true;
}
else {
cout << "got = sign but no name" << endl;
}
break;
}
if (pname[len] == '\0') {
if (len) {
cout << "no = sign before termminating null" << endl;
}
else {
// empty property name -> free space reached
}
break;
}
}
if (!got_name) {
break;
}
char prop_name[32];
memcpy(prop_name, pname, len);
prop_name[len] = '\0';
pos++; // skip past '='
char *pval = (char *)&this->buf[pos];
// determine property value length
for (len = 0; pos < 4096; pos++, len++) {
if (pval[len] == '\0')
break;
}
// ensure each property value is null-terminated
if (pos >= 4096) {
cout << "ran off partition end" << endl;
break;
}
this->_config_vars.push_back(std::make_pair(prop_name, pval));
pos++; // skip past null terminator
this->data_length = pos; // point to after null
}
//cout << "Read " << this->data_length << " bytes from nvram." << endl;
return this->_config_vars;
}
bool OfConfigChrp::update_partition() {
unsigned pos = 0;
memset(this->buf, 0, 4096);
for (auto& var : this->_config_vars) {
if ((pos + var.first.length() + var.second.length() + 2) > 4096) {
cout << "No room in the partition!" << endl;
return false;
}
memcpy(&this->buf[pos], var.first.c_str(), var.first.length());
pos += var.first.length();
this->buf[pos++] = '=';
memcpy(&this->buf[pos], var.second.c_str(), var.second.length());
pos += var.second.length();
this->buf[pos++] = '\0';
}
// write the entire partition back to NVRAM
for (int i = 0; i < 4096; i++) {
this->nvram_obj->write_byte(this->data_offset + i, this->buf[i]);
}
//cout << "Wrote " << pos << " bytes to nvram." << endl;
return true;
}
bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
if (!this->validate())
return false;
// see if we're about to change a flag
if (var_name.back() == '?') {
if (value != "true" && value != "false") {
cout << "Flag value can be 'true' or 'false'" << endl;
return false;
}
}
unsigned free_space = 4096 - this->data_length;
bool found = false;
// see if the user tries to change an existing property
for (auto& var : this->_config_vars) {
if (var.first == var_name) {
found = true;
if (value.length() > var.second.length()) {
if ((value.length() - var.second.length()) > free_space) {
cout << "No room for updated nvram variable!" << endl;
return false;
}
}
var.second = value;
break;
}
}
if (!found) {
if ((var_name.length() + value.length() + 2) > free_space) {
cout << "No room for new nvram variable!" << endl;
return false;
}
this->_config_vars.push_back(std::make_pair(var_name, value));
}
return this->update_partition();
}
int OfConfigUtils::init()
{
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
return this->nvram_obj == nullptr;
}
bool OfConfigUtils::open_container() {
OfConfigImpl* cfg_obj;
if (this->cfg_impl == nullptr) {
cfg_obj = new OfConfigAppl(this->nvram_obj);
if (cfg_obj->validate()) {
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
return true;
} else {
delete(cfg_obj);
cfg_obj = new OfConfigChrp(this->nvram_obj);
if (cfg_obj->validate()) {
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
return true;
} else {
delete(cfg_obj);
}
}
} else {
return this->cfg_impl->validate();
}
cout << "No valid Open Firmware partition found!" << endl;
return false;
}
static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
}
return str;
}
void OfConfigUtils::printenv() {
if (!this->open_container())
return;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
for (auto& var : vars) {
std::string val = var.second;
ReplaceAll(val, "\r\n", "\n");
ReplaceAll(val, "\r", "\n");
ReplaceAll(val, "\n", "\n "); // 34 spaces
cout << setw(34) << left << var.first << val << right << endl; // name column has width 34
}
}
bool OfConfigUtils::setenv(string var_name, string value)
{
if (!this->open_container())
return false;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
return this->cfg_impl->set_var(var_name, value);
}
+100 -20
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,20 +19,29 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Apple/CHRP Open Firmware NVRAM partition definitions. */
#ifndef OF_NVRAM_H
#define OF_NVRAM_H
#include <devices/common/nvram.h>
#include <cinttypes>
#include <memory>
#include <string>
#include <utility>
#include <vector>
/** @file Utilities for working with the Apple Open Firmware NVRAM partition. */
class NVram;
#define OF_NVRAM_OFFSET 0x1800
#define OF_NVRAM_SIG 0x1275
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
constexpr auto OF_NVRAM_OFFSET = 0x1800;
constexpr auto OF_NVRAM_SIG = 0x1275;
constexpr auto OF_CFG_SIZE = 0x800;
// OF Variable types
enum {
OF_VAR_TYPE_INT = 1,
OF_VAR_TYPE_STR = 2,
OF_VAR_TYPE_INT = 1, // integer
OF_VAR_TYPE_STR = 2, // string
OF_VAR_TYPE_FLG = 3, // boolean flag
};
typedef struct {
@@ -42,26 +51,97 @@ typedef struct {
uint16_t checksum; // >nv.checksum partition checksum
uint16_t here; // >nv.here offset to the next free byte (offset of after last string length; = 0x185c)
uint16_t top; // >nv.top offset to the last free byte (offset of string with lowest offset; < 0x2000)
} OfNvramHdr;
} OfConfigHdrAppl;
class OfNvramUtils {
/** ================== CHRP NVRAM partition definitions. ================== */
/** CHRP NVRAM partition signatures. */
enum {
NVRAM_SIG_OF_CFG = 0x50, // of-config (unused in Power Macintosh)
NVRAM_SIG_VPD = 0x52, // of-vpd (unused in Power Macintosh)
NVRAM_SIG_DIAG = 0x5F, // diagnostics partition
NVRAM_SIG_OF_ENV = 0x70, // common partition with OF environment vars
NVRAM_SIG_ERR_LOG = 0x72, // post-err-log
NVRAM_SIG_FREE = 0x7F, // free space
NVRAM_SIG_MAC_OS = 0xA0, // APL,MacOS75
};
typedef struct {
uint8_t sig; // partition signature, must be 0x70
uint8_t checksum; // partition header checksum (sig, length & name)
uint16_t length; // partition length in 16-byte blocks
char name[12]; // null-terminated partition name
} OfConfigHdrChrp;
// - interface
class OfConfigImpl {
public:
OfNvramUtils() = default;
~OfNvramUtils() = default;
using config_dict = std::vector<std::pair<std::string, std::string>>;
virtual ~OfConfigImpl() = default;
virtual bool validate() = 0;
virtual const config_dict& get_config_vars() = 0;
virtual bool set_var(std::string& name, std::string& val) = 0;
};
// Old World implementation
class OfConfigAppl : public OfConfigImpl {
public:
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigAppl() = default;
bool validate();
const config_dict& get_config_vars();
bool set_var(std::string& var_name, std::string& value);
protected:
uint16_t checksum_partition();
void update_partition();
private:
NVram* nvram_obj = nullptr;
uint8_t buf[OF_CFG_SIZE];
int size = 0;
config_dict _config_vars;
};
// New World implementation
class OfConfigChrp : public OfConfigImpl {
public:
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
~OfConfigChrp() = default;
bool validate();
const config_dict& get_config_vars();
bool set_var(std::string& var_name, std::string& value);
protected:
uint8_t checksum_hdr(const uint8_t* data);
bool update_partition();
private:
NVram* nvram_obj = nullptr;
uint8_t buf[4096];
unsigned data_offset = 0; // offset to the OF config data
unsigned data_length = 0; // length of the OF config data
config_dict _config_vars;
};
class OfConfigUtils {
public:
OfConfigUtils() = default;
~OfConfigUtils() = default;
int init();
void printenv();
void setenv(std::string var_name, std::string value);
bool setenv(std::string var_name, std::string value);
protected:
bool validate();
uint16_t checksum_partition();
void update_partition();
bool open_container();
private:
NVram* nvram_obj = nullptr;
int size = 0;
uint8_t buf[0x800];
std::unique_ptr<OfConfigImpl> cfg_impl = nullptr;
NVram* nvram_obj = nullptr;
};
#endif // OF_NVRAM_H
+295 -280
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,15 +19,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Bandit ARBus-to-PCI Bridge emulation. */
/** Bandit/Chaos ARBus-to-PCI Bridge emulation. */
#include <core/endianswap.h>
#include <devices/common/pci/bandit.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <memaccess.h>
#include <cinttypes>
@@ -40,27 +39,15 @@ const int MultiplyDeBruijnBitPosition2[] =
/** finds the position of the bit that is set */
#define WHAT_BIT_SET(val) (MultiplyDeBruijnBitPosition2[(uint32_t)(val * 0x077CB531U) >> 27])
Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
BanditPciDevice::BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev)
: PCIDevice(name)
{
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
// add memory mapped I/O region for Bandit control registers
// This region has the following layout:
// base_addr + 0x000000 --> I/O space
// base_addr + 0x800000 --> CONFIG_ADDR
// base_addr + 0xC00000 --> CONFIG_DATA
// base_addr + 0x1000000 --> pass-through memory space (not included below)
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
supports_types(HWCompType::PCI_DEV);
// prepare the PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = 0x0001;
this->class_rev = 0x06000003;
this->device_id = dev_id;
this->class_rev = 0x06000000 | (rev & 0xFFU);
this->cache_ln_sz = 8;
this->command = 0x16;
@@ -73,183 +60,69 @@ Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
// This initialization is implied by the device functionality.
this->addr_mask = 3 << ((bridge_num & 3) * 2);
this->name = name;
// initial PCI number + chip mode: big endian, interrupts & VGA space disabled
this->mode_ctrl = ((bridge_num & 3) << 2) | 3;
this->rd_hold_off_cnt = 8;
}
uint32_t Bandit::pci_cfg_read(uint32_t reg_offs, uint32_t size)
uint32_t BanditPciDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
if (reg_offs < 64) {
return PCIDevice::pci_cfg_read(reg_offs, size);
return PCIDevice::pci_cfg_read(reg_offs, details);
}
switch (reg_offs) {
case BANDIT_ADDR_MASK:
return BYTESWAP_32(this->addr_mask);
return this->addr_mask;
case BANDIT_MODE_SELECT:
return this->mode_ctrl;
case BANDIT_ARBUS_RD_HOLD_OFF:
return this->rd_hold_off_cnt;
case BANDIT_DELAYED_AACK: // BANDIT_ONS
return 0;
default:
LOG_F(WARNING, "%s: reading from unimplemented config register at 0x%X",
this->pci_name.c_str(), reg_offs);
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
}
return 0;
}
void Bandit::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
void BanditPciDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, size);
PCIDevice::pci_cfg_write(reg_offs, value, details);
return;
}
switch (reg_offs) {
case BANDIT_ADDR_MASK:
this->addr_mask = BYTESWAP_32(value);
this->addr_mask = value;
this->verbose_address_space();
break;
return;
case BANDIT_MODE_SELECT:
this->mode_ctrl = value;
return;
case BANDIT_ARBUS_RD_HOLD_OFF:
this->rd_hold_off_cnt = value & 0x1F;
return;
case BANDIT_DELAYED_AACK:
// implement this for CATALYST and Platinum
return;
default:
LOG_F(WARNING, "%s: writing to unimplemented config register at 0x%X",
this->pci_name.c_str(), reg_offs);
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
}
}
uint32_t Bandit::read(uint32_t rgn_start, uint32_t offset, int size)
{
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
uint32_t result, idsel;
if (offset & BANDIT_CONFIG_SPACE) {
if (offset & 0x00400000) {
fun_num = (this->config_addr >> 8) & 7;
reg_offs = this->config_addr & 0xFCU;
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
if (this->config_addr & BANDIT_CAR_TYPE) {
bus_num = (this->config_addr >> 16) & 255;
dev_num = (this->config_addr >> 11) & 31;
LOG_F(
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
if (!SINGLE_BIT_SET(idsel)) {
LOG_F(
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
this->name.c_str(), idsel, this->config_addr,
fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
if (idsel == BANDIT_ID_SEL) { // access to myself
result = this->pci_cfg_read(reg_offs, size);
} else {
if (this->dev_map.count(idsel)) {
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
} else {
dev_num = WHAT_BIT_SET(idsel) + 11;
LOG_F(
ERROR, "%s err: read attempt from non-existing PCI device ??:%02x.%x @%02x.%c",
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
}
} else {
result = this->config_addr;
}
} else { // I/O space access
// broadcast I/O request to devices that support I/O space
// until a device returns true that means "request accepted"
for (auto& dev : this->io_space_devs) {
if (dev->pci_io_read(offset, size, &result)) {
return result;
}
}
LOG_F(ERROR, "%s: attempt to read from unmapped PCI I/O space, offset=0x%X",
this->name.c_str(), offset);
}
return result;
}
void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
uint32_t idsel;
if (offset & BANDIT_CONFIG_SPACE) {
if (offset & 0x00400000) {
fun_num = (this->config_addr >> 8) & 7;
reg_offs = this->config_addr & 0xFCU;
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
if (this->config_addr & BANDIT_CAR_TYPE) {
bus_num = (this->config_addr >> 16) & 255;
dev_num = (this->config_addr >> 11) & 31;
LOG_F(
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
return;
}
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
if (!SINGLE_BIT_SET(idsel)) {
LOG_F(
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
this->name.c_str(), idsel, this->config_addr,
fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
return;
}
if (idsel == BANDIT_ID_SEL) { // access to myself
this->pci_cfg_write(reg_offs, value, size);
return;
}
if (this->dev_map.count(idsel)) {
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
} else {
dev_num = WHAT_BIT_SET(idsel) + 11;
LOG_F(
ERROR, "%s err: write attempt to non-existing PCI device ??:%02x.%x @%02x.%c = %0*x",
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
}
} else {
this->config_addr = BYTESWAP_32(value);
}
} else { // I/O space access
// broadcast I/O request to devices that support I/O space
// until a device returns true that means "request accepted"
for (auto& dev : this->io_space_devs) {
if (dev->pci_io_write(offset, value, size)) {
return;
}
}
LOG_F(ERROR, "%s: attempt to write to unmapped PCI I/O space, offset=0x%X",
this->name.c_str(), offset);
}
}
void Bandit::verbose_address_space()
void BanditPciDevice::verbose_address_space()
{
uint32_t mask;
int bit_pos;
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
if (!this->addr_mask) {
return;
}
LOG_F(INFO, "%s address spaces:", this->get_name().c_str());
// verbose coarse aka 256MB memory regions
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
@@ -268,8 +141,187 @@ void Bandit::verbose_address_space()
}
}
Chaos::Chaos(std::string name) : PCIHost()
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
{
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
return pci_io_read_broadcast(offset & 0x007FFFFF, size);
case 4:
case 5:
// CONFIG_ADDR
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
case 6:
// CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
PCIBase *device;
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
details.flags |= PCI_CONFIG_READ;
if (device) {
uint32_t value = device->pci_cfg_read(reg_offs, details);
// bytes 4 to 7 are random on bandit but
// we choose to repeat bytes 0 to 3 like grackle
return pci_conv_rd_data(value, value, details);
}
LOG_READ_NON_EXISTENT_PCI_DEVICE();
return 0xFFFFFFFFUL; // PCI spec §6.1
case 7:
// Interrupt
LOG_F(ERROR, "%s: Interrupt Acknowledge Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
}
return 0;
}
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
pci_io_write_broadcast(offset & 0x007FFFFF, size, value);
break;
case 4:
case 5:
// CONFIG_ADDR
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
break;
case 6:
// CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
PCIBase *device;
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
details.flags |= PCI_CONFIG_WRITE;
if (device) {
if (size == 4 && !details.offset) { // aligned DWORD writes -> fast path
device->pci_cfg_write(reg_offs, BYTESWAP_32(value), details);
return;
}
// otherwise perform necessary data transformations -> slow path
uint32_t old_val = details.size == 4 ? 0 : device->pci_cfg_read(reg_offs, details);
uint32_t new_val = pci_conv_wr_data(old_val, value, details);
device->pci_cfg_write(reg_offs, new_val, details);
return;
}
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
break;
case 7:
// Special
LOG_F(ERROR, "%s: Special Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
}
}
inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
int &dev_num, int &fun_num, uint8_t &reg_offs,
AccessDetails &details, PCIBase *&device)
{
details.size = size;
details.offset = offset & 3;
fun_num = FUN_NUM();
reg_offs = REG_NUM();
if (this->config_addr & BANDIT_CAR_TYPE) { // type 1 configuration command
details.flags = PCI_CONFIG_TYPE_1;
bus_num = BUS_NUM();
dev_num = DEV_NUM();
device = pci_find_device(bus_num, dev_num, fun_num);
return;
}
details.flags = PCI_CONFIG_TYPE_0;
bus_num = 0; // use dummy value for bus number
if (is_aspen)
dev_num = (this->config_addr >> 11) + 11; // IDSEL = 1 << (dev_num + 11)
else {
uint32_t idsel = this->config_addr & 0xFFFFF800U;
if (!SINGLE_BIT_SET(idsel)) {
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
this->name.c_str(), (uint32_t)this->config_addr);
device = NULL;
return;
}
dev_num = WHAT_BIT_SET(idsel);
}
device = pci_find_device(dev_num, fun_num);
}
int BanditHost::device_postinit() {
return this->pcihost_device_postinit();
}
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
: BanditHost(bridge_num)
{
this->name = name;
supports_types(HWCompType::PCI_HOST);
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
// add memory mapped I/O region for Bandit control registers
// This region has the following layout:
// base_addr + 0x00000000 --> I/O space
// base_addr + 0x00800000 --> CONFIG_ADDR
// base_addr + 0x00C00000 --> CONFIG_DATA
// base_addr + 0x00E00000 --> Special(W)/Interrupt(R)
// base_addr + 0x01000000 --> pass-through memory space ; grandcentral exists here for pci1
mem_ctrl->add_mmio_region(base_addr, bridge_num == 1 ? 0x01000000 : 0x02000000, this);
// connnect Bandit PCI device
this->my_pci_device = std::unique_ptr<BanditPciDevice>(
new BanditPciDevice(bridge_num, name, dev_id, rev)
);
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
}
Chaos::Chaos(std::string name) : BanditHost(0)
{
this->name = name;
supports_types(HWCompType::PCI_HOST);
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
@@ -280,126 +332,89 @@ Chaos::Chaos(std::string name) : PCIHost()
// base_addr + 0x800000 --> CONFIG_ADDR
// base_addr + 0xC00000 --> CONFIG_DATA
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
}
AspenPci::AspenPci(std::string name) : BanditHost(1) {
this->name = name;
supports_types(HWCompType::PCI_HOST);
this->is_aspen = true;
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
// add memory mapped I/O region for Aspen PCI control registers
// This region has the following layout:
// base_addr + 0x800000 --> CONFIG_ADDR
// base_addr + 0xC00000 --> CONFIG_DATA
mem_ctrl->add_mmio_region(0xF2000000UL, 0x01000000, this);
}
uint32_t Chaos::read(uint32_t rgn_start, uint32_t offset, int size)
{
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
uint32_t result, idsel;
static const PropMap Bandit1_Properties = {
{"pci_A1",
new StrProperty("")},
{"pci_B1",
new StrProperty("")},
{"pci_C1",
new StrProperty("")},
};
if (offset & BANDIT_CONFIG_SPACE) {
if (offset & 0x00400000) {
fun_num = (this->config_addr >> 8) & 7;
reg_offs = this->config_addr & 0xFCU;
static const PropMap Bandit2_Properties = {
{"pci_D2",
new StrProperty("")},
{"pci_E2",
new StrProperty("")},
{"pci_F2",
new StrProperty("")},
};
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
if (this->config_addr & BANDIT_CAR_TYPE) {
bus_num = (this->config_addr >> 16) & 255;
dev_num = (this->config_addr >> 11) & 31;
LOG_F(
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
static const PropMap Chaos_Properties = {
{"vci_D",
new StrProperty("")},
{"vci_E",
new StrProperty("")},
};
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
static const PropMap PsxPci1_Properties = {
{"pci_A1",
new StrProperty("")},
{"pci_B1",
new StrProperty("")},
{"pci_C1",
new StrProperty("")},
{"pci_E1",
new StrProperty("")},
{"pci_F1",
new StrProperty("")},
};
if (!SINGLE_BIT_SET(idsel)) {
LOG_F(
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
this->name.c_str(), idsel, this->config_addr,
fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
if (this->dev_map.count(idsel)) {
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
} else {
dev_num = WHAT_BIT_SET(idsel) + 11;
LOG_F(
ERROR, "%s err: read attempt from non-existing VCI device ??:%02x.%x @%02x.%c",
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
);
return 0xFFFFFFFFUL; // PCI spec §6.1
}
} else {
result = this->config_addr;
}
} else { // I/O space access
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
return 0;
}
return result;
}
void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
uint32_t idsel;
if (offset & BANDIT_CONFIG_SPACE) {
if (offset & 0x00400000) {
fun_num = (this->config_addr >> 8) & 7;
reg_offs = this->config_addr & 0xFCU;
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
if (this->config_addr & BANDIT_CAR_TYPE) {
bus_num = (this->config_addr >> 16) & 255;
dev_num = (this->config_addr >> 11) & 31;
LOG_F(
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
return;
}
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
if (!SINGLE_BIT_SET(idsel)) {
LOG_F(
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
this->name.c_str(), idsel, this->config_addr,
fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
return;
}
if (this->dev_map.count(idsel)) {
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
} else {
dev_num = WHAT_BIT_SET(idsel) + 11;
LOG_F(
ERROR, "%s err: write attempt to non-existing VCI device ??:%02x.%x @%02x.%c = %0*x",
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
);
}
} else {
this->config_addr = BYTESWAP_32(value);
}
} else { // I/O space access
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
}
}
static const std::vector<std::string> Chaos_Subdevices = {
"ControlVideo"
};
static const DeviceDescription Bandit1_Descriptor = {
Bandit::create_first, {}, {}
Bandit::create_first, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Bandit2_Descriptor = {
Bandit::create_second, {}, Bandit2_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, PsxPci1_Properties, HWCompType::PCI_HOST
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, {}, {}
Chaos::create, Chaos_Subdevices, Chaos_Properties, HWCompType::PCI_HOST
};
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
static const DeviceDescription AspenPci1_Descriptor = {
AspenPci::create, {}, Bandit1_Properties, HWCompType::PCI_HOST
};
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
REGISTER_DEVICE(AspenPci1, AspenPci1_Descriptor);
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
+101 -37
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,10 +19,19 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Bandit ARBus-to-PCI bridge definitions.
/** Bandit/Chaos ARBus-to-PCI bridge definitions.
The Bandit ASIC is a custom ARBus-to-PCI bridge used in the second
generation of the Power Macintosh computer equipped with the PCI bus.
Bandit is a custom ARBus-to-PCI bridge used in the second generation
of the Power Macintosh computer equipped with the PCI bus.
Chaos is a custom ARBus-to-PCI bridge that provides a specialized
PCI-like bus for video called VCI. This 64-bit bus runs at the same
frequency as the CPU bus (40-50 MHz) and connects video input/output
devices with the CPU bus.
Chaos seems to be a Bandit variant without PCI configuration space.
It's assumed to be present in some PCI Power Macintosh models of the
first generation.
*/
#ifndef BANDIT_PCI_H
@@ -36,66 +45,121 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <memory>
#include <string>
#include <unordered_map>
#define BANDIT_ID_SEL (1 << 0) // Bandit's own IDSEL
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
#define BANDIT_CONFIG_SPACE 0x00800000 // Bandit Config Space bit
constexpr auto BANDIT_DEV = 11; // Bandit's own device number
constexpr auto BANDIT_CAR_TYPE = 1 << 0; // Bandit config address type bit
/* Convenient macros for parsing CONFIG_ADDR fields. */
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
#define DEV_NUM() ((this->config_addr >> 11) & 0x1FU)
#define FUN_NUM() ((this->config_addr >> 8) & 0x07U)
#define REG_NUM() ((this->config_addr ) & 0xFCU)
/** Bandit specific configuration registers. */
enum {
BANDIT_ADDR_MASK = 0x48,
BANDIT_ADDR_MASK = 0x48,
BANDIT_MODE_SELECT = 0x50,
BANDIT_ARBUS_RD_HOLD_OFF = 0x58,
BANDIT_DELAYED_AACK = 0x60,
};
/** checks if one bit is set at time, return 0 if not */
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
class Bandit : public PCIHost, public PCIDevice {
/*
Common functionality for Bandit/Chaos PCI host bridge.
*/
class BanditHost : public PCIHost, public MMIODevice {
public:
Bandit(int bridge_num, std::string name);
~Bandit() = default;
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
};
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
BanditHost(int bridge_num) { this->bridge_num = bridge_num; }
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
int device_postinit() override;
protected:
uint32_t config_addr;
int bridge_num;
bool is_aspen = false;
private:
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
int &fun_num, uint8_t &reg_offs, AccessDetails &details,
PCIBase *&device);
};
/*
PCI device for Bandit (but not for Chaos).
*/
class BanditPciDevice : public PCIDevice {
public:
BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev);
~BanditPciDevice() = default;
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
protected:
void verbose_address_space();
private:
uint32_t base_addr;
uint32_t config_addr;
uint32_t addr_mask;
uint32_t mode_ctrl; // controls various chip modes/features
uint32_t rd_hold_off_cnt;
};
/** Chaos is a custom ARBus-to-PCI bridge that provides a specialized
PCI-like bus for video called VCI. This 64-bit bus runs at the same
frequency as the CPU bus (40-50 MHz) and provides an interface
between video input/output devices and the CPU bus.
/*
Bandit HLE emulation class.
*/
class Chaos : public PCIHost, public MMIODevice {
class Bandit : public BanditHost {
public:
Bandit(int bridge_num, std::string name, int dev_id=1, int rev=3);
~Bandit() = default;
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
}
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
}
static std::unique_ptr<HWComponent> create_psx_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
}
private:
std::unique_ptr<BanditPciDevice> my_pci_device;
uint32_t base_addr;
};
/**
Chaos HLE emulation class.
*/
class Chaos : public BanditHost {
public:
Chaos(std::string name);
~Chaos() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
};
}
};
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
/**
Aspen PCI Bridge HLE emulation class.
*/
class AspenPci : public BanditHost {
public:
AspenPci(std::string name);
~AspenPci() = default;
private:
std::string name;
uint32_t config_addr;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
}
};
#endif // BANDIT_PCI_H
+132
View File
@@ -0,0 +1,132 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** DEC 21154 PCI-to-PCI bridge emulation. */
#include <devices/common/hwcomponent.h>
#include <devices/common/pci/dec21154.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <cinttypes>
enum YosemiteGpioMask: uint8_t {
GPIO_FWDET = 2, // FireWire detect
};
constexpr uint32_t my_rev_id = 2;
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
{
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
// initialize PCI config header
this->vendor_id = PCI_VENDOR_DEC;
this->device_id = 0x0026;
this->class_rev = DEVTYPE_PCI2PCI_BRIDGE | my_rev_id;
this->cache_ln_sz = 0;
this->command = 0;
this->status = 0x2B0;
}
uint32_t DecPciBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
if (reg_offs < 64) {
return PCIBridge::pci_cfg_read(reg_offs, details);
}
switch (reg_offs) {
case CHIP_CTRL:
return (this->arb_ctrl << 16) | (this-> diag_ctrl << 8) | this->chip_ctrl;
case PSERR_EVENT_DIS:
return (this->gpio_out_en << 16) | (this->gpio_out_data << 8) | this->pserr_event_dis;
case SEC_CLK_CTRL:
return this->sec_clock_ctrl;
default:
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
}
return 0;
}
void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
if (reg_offs < 64) {
PCIBridge::pci_cfg_write(reg_offs, value, details);
return;
}
switch (reg_offs) {
case CHIP_CTRL:
this->chip_ctrl = value & 0xFFU;
this->diag_ctrl = (value >> 8) & 0xFFU;
this->arb_ctrl = value >> 16;
break;
case PSERR_EVENT_DIS:
this->pserr_event_dis = value & 0x7EU;
this->gpio_out_data = (value >> 8) & 0xFFU;
this->gpio_out_en = (value >> 16) & 0xFFU;
{
uint8_t bits_to_set = gpio_out_data >> 4;
uint8_t bits_to_clr = gpio_out_data & 0xFU;
this->gpio_out_data_val |= bits_to_set;
this->gpio_out_data_val &= ~bits_to_clr;
}
{
uint8_t bits_to_set = gpio_out_en >> 4;
uint8_t bits_to_clr = gpio_out_en & 0xFU;
this->gpio_out_en_val |= bits_to_set;
this->gpio_out_en_val &= ~bits_to_clr;
}
break;
case SEC_CLK_CTRL:
this->sec_clock_ctrl = value & 0xFFFFU;
break;
default:
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
}
}
static const PropMap Dec21154Yosemite_Properties = {
{"pci_FireWire",
new StrProperty("")},
{"pci_UltraATA",
new StrProperty("")},
{"pci_J11",
new StrProperty("")},
{"pci_J10",
new StrProperty("")},
{"pci_J9",
new StrProperty("")},
{"pci_USB",
new StrProperty("")},
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties, HWCompType::PCI_HOST | HWCompType::PCI_DEV
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
REGISTER_DEVICE(Dec21154Yosemite, Dec21154Yosemite_Descriptor);
+68
View File
@@ -0,0 +1,68 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** DEC 21154 PCI-to-PCI bridge definitions. */
#ifndef DEC_P2P_H
#define DEC_P2P_H
#include <devices/common/pci/pcibridge.h>
#include <cinttypes>
#include <string>
enum {
CHIP_CTRL = 0x40,
PSERR_EVENT_DIS = 0x64,
SEC_CLK_CTRL = 0x68,
};
class DecPciBridge : public PCIBridge {
public:
DecPciBridge(std::string name);
~DecPciBridge() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154"));
}
static std::unique_ptr<HWComponent> create_yosemite() {
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154Yosemite"));
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
private:
uint8_t chip_ctrl = 0;
uint8_t diag_ctrl = 0;
uint16_t arb_ctrl = 0x0200;
uint8_t pserr_event_dis = 0;
uint8_t gpio_out_data = 0;
uint8_t gpio_out_en = 0;
uint8_t gpio_in_data = 0;
uint16_t sec_clock_ctrl = 0;
uint8_t gpio_out_data_val = 0;
uint8_t gpio_out_en_val = 0;
};
#endif // DEC_P2P_H
+326
View File
@@ -0,0 +1,326 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <devices/common/pci/pcibase.h>
#include <loguru.hpp>
#include <cinttypes>
#include <fstream>
#include <cstring>
#include <string>
PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
{
this->name = name;
this->hdr_type = hdr_type;
this->num_bars = num_bars;
this->pci_rd_stat = [this]() { return this->status; };
this->pci_rd_cmd = [this]() { return this->command; };
this->pci_rd_bist = []() { return 0; };
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
this->pci_wr_stat = [this](uint16_t val) {
this->status &= ~(0b1111100100000000 & val);
};
this->pci_wr_cmd = [this](uint16_t cmd) {
/*
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
Or the mmio regions should be enabled/disabled.
*/
this->command = cmd & this->command_cfg;
};
this->pci_wr_bist = [](uint8_t val) {};
this->pci_wr_lat_timer = [this](uint8_t val) { this->lat_timer = val; };
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
this->pci_notify_bar_change = [](int bar_num) {};
}
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_DEV_ID:
return (this->device_id << 16) | (this->vendor_id);
case PCI_CFG_STAT_CMD:
return (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
case PCI_CFG_CLASS_REV:
return this->class_rev;
case PCI_CFG_DWORD_3:
return (pci_rd_bist() << 24) | (this->hdr_type << 16) |
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
}
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
return 0;
}
void PCIBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_STAT_CMD:
this->pci_wr_stat(value >> 16);
this->pci_wr_cmd(value & 0xFFFFU);
break;
case PCI_CFG_DWORD_3:
this->pci_wr_bist(value >> 24);
this->pci_wr_lat_timer((value >> 8) & 0xFF);
this->pci_wr_cache_lnsz(value & 0xFF);
break;
default:
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
}
}
void PCIBase::setup_bars(std::vector<BarConfig> cfg_data)
{
for (auto cfg_entry : cfg_data) {
if (cfg_entry.bar_num > this->num_bars) {
ABORT_F("BAR number %d out of range", cfg_entry.bar_num);
}
this->bars_cfg[cfg_entry.bar_num] = cfg_entry.bar_cfg;
}
this->finish_config_bars();
}
int PCIBase::attach_exp_rom_image(const std::string img_path)
{
std::ifstream img_file;
int result = 0;
this->exp_bar_cfg = 0; // tell the world we got no ROM for now
try {
img_file.open(img_path, std::ios::in | std::ios::binary);
if (img_file.fail()) {
throw std::runtime_error("could not open specified ROM dump image");
}
// validate image file
uint8_t buf[4] = { 0 };
img_file.seekg(0, std::ios::beg);
img_file.read((char *)buf, sizeof(buf));
if (buf[0] != 0x55 || buf[1] != 0xAA) {
throw std::runtime_error("invalid expansion ROM signature");
}
// determine image size
img_file.seekg(0, std::ios::end);
size_t exp_rom_image_size = img_file.tellg();
if (exp_rom_image_size > 4*1024*1024) {
throw std::runtime_error("expansion ROM file too large");
}
// verify PCI struct offset
uint16_t pci_struct_offset = 0;
img_file.seekg(0x18, std::ios::beg);
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
if (pci_struct_offset > exp_rom_image_size) {
throw std::runtime_error("invalid PCI structure offset");
}
// verify PCI struct signature
img_file.seekg(pci_struct_offset, std::ios::beg);
img_file.read((char *)buf, sizeof(buf));
if (buf[0] != 'P' || buf[1] != 'C' || buf[2] != 'I' || buf[3] != 'R') {
throw std::runtime_error("unexpected PCI struct signature");
}
// find minimum rom size for the rom file (power of 2 >= 0x800)
for (this->exp_rom_size = 1 << 11; this->exp_rom_size < exp_rom_image_size; this->exp_rom_size <<= 1) {}
// ROM image ok - go ahead and load it
this->exp_rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[this->exp_rom_size]);
img_file.seekg(0, std::ios::beg);
img_file.read((char *)this->exp_rom_data.get(), exp_rom_image_size);
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
if (exp_rom_image_size == this->exp_rom_size) {
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
this->get_name().c_str(), this->exp_rom_size);
}
else {
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
this->get_name().c_str(), (int)exp_rom_image_size, this->exp_rom_size);
}
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "%s: %s", this->get_name().c_str(), exc.what());
result = -1;
}
img_file.close();
return result;
}
void PCIBase::set_bar_value(int bar_num, uint32_t value)
{
uint32_t bar_cfg = this->bars_cfg[bar_num];
switch (bars_typ[bar_num]) {
case PCIBarType::Unused:
return;
case PCIBarType::Io_16_Bit:
case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
}
break;
case PCIBarType::Mem_20_Bit:
case PCIBarType::Mem_32_Bit:
case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
}
break;
case PCIBarType::Mem_64_Bit_Hi:
this->bars[bar_num] = value & bar_cfg;
break;
}
if (value != 0xFFFFFFFFUL) // don't notify the device during BAR sizing
this->pci_notify_bar_change(bar_num);
}
void PCIBase::finish_config_bars()
{
for (int bar_num = 0; bar_num < this->num_bars; bar_num++) {
uint32_t bar_cfg = this->bars_cfg[bar_num];
if (!bar_cfg) // skip unimplemented BARs
continue;
if (bar_cfg & 1) {
bars_typ[bar_num] = (bar_cfg & 0xffff0000) ? PCIBarType::Io_32_Bit :
PCIBarType::Io_16_Bit;
has_io_space = true;
}
else {
int pci_space_type = (bar_cfg >> 1) & 3;
switch (pci_space_type) {
case 0:
bars_typ[bar_num] = PCIBarType::Mem_32_Bit;
break;
case 1:
bars_typ[bar_num] = PCIBarType::Mem_20_Bit;
break;
case 2:
if (bar_num >= num_bars - 1) {
ABORT_F("%s: BAR %d cannot be 64-bit",
this->get_name().c_str(), bar_num);
}
else if (this->bars_cfg[bar_num+1] == 0) {
ABORT_F("%s: 64-bit BAR %d has zero for upper 32 bits",
this->get_name().c_str(), bar_num);
}
else {
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
bars_typ[bar_num ] = PCIBarType::Mem_64_Bit_Hi;
}
break;
default:
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
this->get_name().c_str(), pci_space_type, bar_num);
} // switch pci_space_type
}
} // for bar_num
}
void PCIBase::map_exp_rom_mem()
{
uint32_t rom_addr = this->exp_rom_bar & this->exp_bar_cfg;
if (rom_addr) {
if (this->exp_rom_addr != rom_addr) {
this->unmap_exp_rom_mem();
uint32_t rom_size = ~this->exp_bar_cfg + 1;
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
this->exp_rom_addr = rom_addr;
}
}
else {
this->unmap_exp_rom_mem();
}
}
void PCIBase::unmap_exp_rom_mem()
{
if (this->exp_rom_addr) {
uint32_t rom_size = ~this->exp_bar_cfg + 1;
this->host_instance->pci_unregister_mmio_region(exp_rom_addr, rom_size, this);
this->exp_rom_addr = 0;
}
}
void PCIBase::pci_wr_exp_rom_bar(uint32_t data)
{
if (!this->exp_bar_cfg) {
return;
}
if ((data & this->exp_bar_cfg) == this->exp_bar_cfg) {
// doing sizing
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
} else {
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
if (this->exp_rom_bar & 1) {
this->map_exp_rom_mem();
}
else {
this->unmap_exp_rom_mem();
}
}
}
void PCIBase::pci_interrupt(uint8_t irq_line_state) {
if (!(this->command & 0x0400)) {
if (!this->int_details.int_ctrl_obj)
this->host_instance->register_pci_int(this);
if (this->int_details.int_ctrl_obj && this->int_details.irq_id)
this->int_details.int_ctrl_obj->ack_int(this->int_details.irq_id, irq_line_state);
else
LOG_F(ERROR, "Unhandled interrupt from device %s", this->get_name().c_str());
/* A pci device should set the interrupt status bit when an interrupt occurs
* and it should clear the interrupt status bit when its interrupt bits are cleared.
* The interrupt status bit is new to PCI Local Bus Specification Revision 2.3
* and Power Macs use PCI Local Bus Specification Revision 2.0. Some PCI cards
* might not implement this bit.
*/
//this->status |= 0x0008;
}
}
+248
View File
@@ -0,0 +1,248 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PCI_BASE_H
#define PCI_BASE_H
#include <devices/common/mmiodevice.h>
#include <devices/common/pci/pcidefs.h>
#include <devices/common/pci/pcihost.h>
#include <cinttypes>
#include <functional>
#include <memory>
#include <string>
#include <vector>
/** PCI configuration space header types */
enum PCIHeaderType : uint8_t {
PCI_HEADER_TYPE_0 = 0, // PCI Device
PCI_HEADER_TYPE_1 = 1, // PCI-PCI Bridge
PCI_HEADER_TYPE_2 = 2, // PCI-To-Cardbus Bridge
};
/** PCI configuration space registers offsets */
enum {
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
PCI_CFG_STAT_CMD = 0x04, // command/status register
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2)
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
// Bridge Control (Type 1 and 2)
// Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI BAR types */
enum PCIBarType : uint32_t {
Unused = 0,
Io_16_Bit,
Io_32_Bit,
Mem_20_Bit, // legacy type for < 1MB memory
Mem_32_Bit,
Mem_64_Bit_Lo,
Mem_64_Bit_Hi
};
typedef struct {
uint32_t bar_num;
uint32_t bar_cfg;
} BarConfig;
class PCIBase : public MMIODevice {
friend class PCIHost;
public:
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
virtual ~PCIBase() = default;
virtual bool supports_io_space() {
return has_io_space;
}
/* I/O space access methods */
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
return false;
}
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
}
// configuration space access methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
// plugin interface for using in the derived classes
std::function<uint16_t()> pci_rd_stat;
std::function<void(uint16_t)> pci_wr_stat;
std::function<uint16_t()> pci_rd_cmd;
std::function<void(uint16_t)> pci_wr_cmd;
std::function<uint8_t()> pci_rd_bist;
std::function<void(uint8_t)> pci_wr_bist;
std::function<uint8_t()> pci_rd_lat_timer;
std::function<void(uint8_t)> pci_wr_lat_timer;
std::function<uint8_t()> pci_rd_cache_lnsz;
std::function<void(uint8_t)> pci_wr_cache_lnsz;
std::function<void(int)> pci_notify_bar_change;
int attach_exp_rom_image(const std::string img_path);
virtual void set_host(PCIHost* host_instance) {
this->host_instance = host_instance;
}
virtual void set_multi_function(bool is_multi_function) {
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
}
virtual void set_irq_pin(uint8_t irq_pin) {
this->irq_pin = irq_pin;
}
virtual void set_int_details(IntDetails &int_details) {
this->int_details = int_details;
}
virtual void pci_interrupt(uint8_t irq_line_state);
// MMIODevice methods
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
protected:
void set_bar_value(int bar_num, uint32_t value);
void setup_bars(std::vector<BarConfig> cfg_data);
void finish_config_bars();
void pci_wr_exp_rom_bar(uint32_t data);
void map_exp_rom_mem();
void unmap_exp_rom_mem();
PCIHost* host_instance; // host bridge instance to call back
// PCI configuration space state (type 0, 1, and 2)
uint16_t vendor_id;
uint16_t device_id;
uint16_t command = 0;
uint16_t status = 0;
uint32_t class_rev; // class code and revision id
uint8_t cache_ln_sz = 0; // cache line size
uint8_t lat_timer = 0; // latency timer
uint8_t hdr_type; // header type, single function
uint8_t cap_ptr = 0; // capabilities ptr
uint8_t irq_pin = 0;
uint8_t irq_line = 0;
bool has_io_space = false;
int num_bars; // number of BARs. Type 0:6, type 1:2, type 2:1 (4K)
uint32_t bars[6] = { 0 }; // BARs (base address registers)
uint32_t bars_cfg[6] = { 0 }; // configuration values for BARs
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for BARs
// PCI configuration space state (type 0 and 1)
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
uint32_t exp_rom_bar = 0; // expansion ROM base address register
uint32_t exp_rom_addr = 0; // expansion ROM base address
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
std::unique_ptr<uint8_t[]> exp_rom_data;
// 0 = not writable; 1 = bit is enabled in command register
uint16_t command_cfg = 0xffff - (1<<3) - (1<<7); // disable: special cycles and stepping
IntDetails int_details = { 0 };
};
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
switch (details.size << 2 | details.offset) {
case 0x04: return (uint8_t) value;
case 0x05: return (uint8_t)(value >> 8);
case 0x06: return (uint8_t)(value >> 16);
case 0x07: return (uint8_t)(value >> 24);
case 0x08: return (uint16_t) value;
case 0x09: return (uint16_t) (value >> 8);
case 0x0a: return (uint16_t) (value >> 16);
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
case 0x10: return value;
case 0x11: return (value >> 8) | (value << 24);
case 0x12: return (value >> 16) | (value << 16);
case 0x13: return (value >> 24) | (value << 8);
default: return 0xffffffff;
}
}
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
VLOG_F( \
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
"%s: read unimplemented config register @%02x.%c", \
this->name.c_str(), reg_offs + details.offset, \
SIZE_ARG(details.size) \
); \
} } while(0)
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
VLOG_F( \
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
"%s: %s %s register @%02x.%c = %0*x", \
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
SIZE_ARG(details.size), \
details.size * 2, pci_cfg_log(value, details) \
)
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
} } while(0)
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
LOG_F( \
ERROR, \
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
SIZE_ARG(details.size) \
)
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
LOG_F( \
ERROR, \
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
SIZE_ARG(details.size), \
details.size * 2, BYTESWAP_SIZED(value, details.size) \
)
#endif /* PCI_BASE_H */
+188
View File
@@ -0,0 +1,188 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/common/pci/pcibridge.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h>
#include <loguru.hpp>
PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1, 2)
{
this->pci_rd_memory_base = [this]() { return this->memory_base; };
this->pci_rd_memory_limit = [this]() { return this->memory_limit; };
this->pci_rd_io_base = [this]() { return this->io_base; };
this->pci_rd_io_limit = [this]() { return this->io_limit; };
this->pci_rd_pref_mem_base = [this]() { return this->pref_mem_base; };
this->pci_rd_pref_mem_limit = [this]() { return this->pref_mem_limit; };
this->pci_rd_io_base_upper16 = [this]() { return this->io_base_upper16; };
this->pci_rd_io_limit_upper16 = [this]() { return this->io_limit_upper16; };
this->pci_rd_pref_base_upper32 = [this]() { return this->pref_base_upper32; };
this->pci_rd_pref_limit_upper32 = [this]() { return this->pref_limit_upper32; };
this->pci_wr_memory_base = [this](uint16_t val) {
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_base_32 = (((uint64_t)this->memory_base & 0xfff0) << 16);
};
this->pci_wr_memory_limit = [this](uint16_t val) {
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_limit_32 = (((uint64_t)this->memory_limit & 0xfff0) << 16) + 0x100000;
};
this->pci_wr_io_base = [this](uint8_t val) {
this->io_base = (val & this->io_cfg) | (this->io_cfg & 15);
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) | ((this->io_base & 0xf0) << 8);
};
this->pci_wr_io_limit = [this](uint8_t val) {
this->io_limit = (val & this->io_cfg) | (this->io_cfg & 15);
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
((this->io_limit & 0xf0) << 8)) + 0x1000;
};
this->pci_wr_pref_mem_base = [this](uint16_t val) {
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
if ((this->io_base & 15) == 1)
this->io_base_upper16 = val;
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) |
((this->io_base & 0xf0) << 8);
};
this->pci_wr_io_limit_upper16 = [this](uint16_t val) {
if ((this->io_limit & 15) == 1)
this->io_limit_upper16 = val;
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
((this->io_limit & 0xf0) << 8)) + 0x1000;
};
this->pci_wr_pref_base_upper32 = [this](uint32_t val) {
if ((this->pref_mem_cfg & 15) == 1)
this->pref_base_upper32 = val;
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
if ((this->pref_mem_cfg & 15) == 1)
this->pref_limit_upper32 = val;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
};
}
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_BAR0:
case PCI_CFG_BAR1:
return this->bars[(reg_offs - 0x10) >> 2];
case PCI_CFG_IO_BASE:
return (this->pci_rd_sec_status() << 16) |
(this->pci_rd_io_limit() << 8) | (this->pci_rd_io_base());
case PCI_CFG_MEMORY_BASE:
return (this->pci_rd_memory_limit() << 16) | (this->pci_rd_memory_base());
case PCI_CFG_PREF_MEM_BASE:
return (this->pci_rd_pref_mem_limit() << 16) | (this->pci_rd_pref_mem_base());
case PCI_CFG_PREF_BASE_UPPER32:
return this->pci_rd_pref_base_upper32();
case PCI_CFG_PREF_LIMIT_UPPER32:
return this->pci_rd_pref_limit_upper32();
case PCI_CFG_IO_BASE_UPPER16:
return (this->pci_rd_io_limit_upper16() << 16) | (this->pci_rd_io_base_upper16());
case PCI_CFG_DWORD_13:
return cap_ptr;
case PCI_CFG_BRIDGE_ROM_ADDRESS:
return exp_rom_bar;
default:
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
}
}
void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_BAR0:
case PCI_CFG_BAR1:
this->set_bar_value((reg_offs - 0x10) >> 2, value);
break;
case PCI_CFG_IO_BASE:
this->pci_wr_sec_status(value >> 16);
this->pci_wr_io_limit(value >> 8);
this->pci_wr_io_base(value & 0xFFU);
break;
case PCI_CFG_MEMORY_BASE:
this->pci_wr_memory_limit(value >> 16);
this->pci_wr_memory_base(value & 0xFFFFU);
break;
case PCI_CFG_PREF_MEM_BASE:
this->pci_wr_pref_mem_limit(value >> 16);
this->pci_wr_pref_mem_base(value & 0xFFFFU);
break;
case PCI_CFG_PREF_BASE_UPPER32:
this->pci_wr_pref_base_upper32(value);
break;
case PCI_CFG_PREF_LIMIT_UPPER32:
this->pci_wr_pref_limit_upper32(value);
break;
case PCI_CFG_IO_BASE_UPPER16:
this->pci_wr_io_limit_upper16(value >> 16);
this->pci_wr_io_base_upper16(value & 0xFFFFU);
break;
case PCI_CFG_BRIDGE_ROM_ADDRESS:
this->pci_wr_exp_rom_bar(value);
break;
default:
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
break;
}
}
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;
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_write_loop(offset, size, value);
}
+108
View File
@@ -0,0 +1,108 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PCI_BRIDGE_H
#define PCI_BRIDGE_H
#include <devices/common/pci/pcibridgebase.h>
#include <devices/common/pci/pcihost.h>
#include <cinttypes>
#include <string>
/** PCI configuration space registers offsets */
enum {
PCI_CFG_IO_BASE = 0x1C, // IO_BASE.b, IO_LIMIT.b, SEC_STATUS.w
PCI_CFG_MEMORY_BASE = 0x20, // MEMORY_BASE.w, MEMORY_LIMIT.w
PCI_CFG_PREF_MEM_BASE = 0x24, // PREF_MEMORY_BASE.w, PREF_MEMORY_LIMIT.w
PCI_CFG_PREF_BASE_UPPER32 = 0x28, // PREF_BASE_UPPER32
PCI_CFG_PREF_LIMIT_UPPER32 = 0x2c, // PREF_LIMIT_UPPER32
PCI_CFG_IO_BASE_UPPER16 = 0x30, // IO_BASE_UPPER16.w, IO_LIMIT_UPPER16.w
PCI_CFG_BRIDGE_ROM_ADDRESS = 0x38, // BRIDGE_ROM_ADDRESS
};
class PCIBridge : public PCIBridgeBase {
public:
PCIBridge(std::string name);
~PCIBridge() = default;
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
// plugin interface for using in the derived classes
std::function<uint8_t()> pci_rd_io_base;
std::function<void(uint8_t)> pci_wr_io_base;
std::function<uint8_t()> pci_rd_io_limit;
std::function<void(uint8_t)> pci_wr_io_limit;
std::function<uint16_t()> pci_rd_memory_base;
std::function<void(uint16_t)> pci_wr_memory_base;
std::function<uint16_t()> pci_rd_memory_limit;
std::function<void(uint16_t)> pci_wr_memory_limit;
std::function<uint16_t()> pci_rd_pref_mem_base;
std::function<void(uint16_t)> pci_wr_pref_mem_base;
std::function<uint16_t()> pci_rd_pref_mem_limit;
std::function<void(uint16_t)> pci_wr_pref_mem_limit;
std::function<uint32_t()> pci_rd_pref_base_upper32;
std::function<void(uint32_t)> pci_wr_pref_base_upper32;
std::function<uint32_t()> pci_rd_pref_limit_upper32;
std::function<void(uint32_t)> pci_wr_pref_limit_upper32;
std::function<uint16_t()> pci_rd_io_base_upper16;
std::function<void(uint16_t)> pci_wr_io_base_upper16;
std::function<uint16_t()> pci_rd_io_limit_upper16;
std::function<void(uint16_t)> pci_wr_io_limit_upper16;
protected:
// PCI configuration space state
uint8_t io_base = 0;
uint8_t io_limit = 0;
uint16_t memory_base = 0;
uint16_t memory_limit = 0;
uint16_t pref_mem_base = 0;
uint16_t pref_mem_limit = 0;
uint32_t pref_base_upper32 = 0;
uint32_t pref_limit_upper32 = 0;
uint16_t io_base_upper16 = 0;
uint16_t io_limit_upper16 = 0;
// 0 = not writable, 0xf0 = supports 16 bit I/O range, 0xf1 = supports 32 bit I/O range
uint8_t io_cfg = 0xf0;
// 0 = not writable, 0xfff0 = supports 32 bit memory range
uint16_t memory_cfg = 0xfff0;
// 0 = not writable, 0xfff0 = supports 32 bit prefetchable memory range,
// 0xfff1 = supports 64 bit prefetchable memory range
uint16_t pref_mem_cfg = 0xfff0;
// calculated address ranges
uint32_t io_base_32 = 0;
uint32_t io_limit_32 = 0;
uint64_t memory_base_32 = 0;
uint64_t memory_limit_32 = 0;
uint64_t pref_mem_base_64 = 0;
uint64_t pref_mem_limit_64 = 0;
};
#endif /* PCI_BRIDGE_H */
+91
View File
@@ -0,0 +1,91 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/memaccess.h>
#include <devices/common/pci/pcibridgebase.h>
PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars) : PCIBase(name, hdr_type, num_bars)
{
this->pci_rd_primary_bus = [this]() { return this->primary_bus; };
this->pci_rd_secondary_bus = [this]() { return this->secondary_bus; };
this->pci_rd_subordinate_bus = [this]() { return this->subordinate_bus; };
this->pci_rd_sec_latency_timer = [this]() { return this->sec_latency_timer; };
this->pci_rd_sec_status = [this]() { return this->sec_status; };
this->pci_rd_bridge_control = [this]() { return this->bridge_control; };
this->pci_wr_primary_bus = [this](uint8_t val) { this->primary_bus = val; };
this->pci_wr_secondary_bus = [this](uint8_t val) { this->secondary_bus = val; };
this->pci_wr_subordinate_bus = [this](uint8_t val) { this->subordinate_bus = val; };
this->pci_wr_sec_latency_timer = [this](uint8_t val) {
this->sec_latency_timer = (this->sec_latency_timer & ~this->sec_latency_timer_cfg) |
(val & this->sec_latency_timer_cfg);
};
this->pci_wr_sec_status = [this](uint16_t val) {};
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
}
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
// FIXME: constrain region to memory range
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
}
bool PCIBridgeBase::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
}
uint32_t PCIBridgeBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_PRIMARY_BUS:
return (this->pci_rd_sec_latency_timer() << 24) |
(this->pci_rd_subordinate_bus() << 16) |
(this->pci_rd_secondary_bus() << 8) |
(this->pci_rd_primary_bus());
case PCI_CFG_DWORD_15:
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
default:
return PCIBase::pci_cfg_read(reg_offs, details);
}
}
void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_PRIMARY_BUS:
this->pci_wr_sec_latency_timer(value >> 24);
this->pci_wr_subordinate_bus(value >> 16);
this->pci_wr_secondary_bus(value >> 8);
this->pci_wr_primary_bus(value & 0xFFU);
break;
case PCI_CFG_DWORD_15:
this->irq_line = value >> 24;
this->pci_wr_bridge_control(value >> 16);
break;
default:
return PCIBase::pci_cfg_write(reg_offs, value, details);
}
}
int PCIBridgeBase::device_postinit() {
return this->pcihost_device_postinit();
}
+87
View File
@@ -0,0 +1,87 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PCI_BRIDGE_BASE_H
#define PCI_BRIDGE_BASE_H
#include <devices/deviceregistry.h>
#include <devices/common/pci/pcibase.h>
#include <devices/common/pci/pcihost.h>
#include <cinttypes>
#include <string>
#include <unordered_map>
#include <vector>
/** PCI configuration space registers offsets (type 1 and 2) */
enum {
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
};
class PCIBridgeBase : public PCIHost, public PCIBase {
friend class PCIHost;
public:
PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars);
~PCIBridgeBase() = default;
// PCIHost methods
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool supports_io_space() override {
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;
std::function<uint8_t()> pci_rd_secondary_bus;
std::function<void(uint8_t)> pci_wr_secondary_bus;
std::function<uint8_t()> pci_rd_subordinate_bus;
std::function<void(uint8_t)> pci_wr_subordinate_bus;
std::function<uint8_t()> pci_rd_sec_latency_timer;
std::function<void(uint8_t)> pci_wr_sec_latency_timer;
std::function<uint16_t()> pci_rd_sec_status;
std::function<void(uint16_t)> pci_wr_sec_status;
std::function<uint16_t()> pci_rd_bridge_control;
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit() override;
protected:
// PCI configuration space state
uint8_t primary_bus = 0;
uint8_t secondary_bus = 0;
uint8_t subordinate_bus = 0;
uint8_t sec_latency_timer = 0; // if supportss r/w then must reset to 0
uint16_t sec_status = 0;
uint16_t bridge_control = 0;
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
uint8_t sec_latency_timer_cfg = 0xff;
};
#endif /* PCI_BRIDGE_BASE_H */
+241
View File
@@ -0,0 +1,241 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/memaccess.h>
#include <devices/common/pci/pcicardbusbridge.h>
typedef struct {
// CardBus Registers
/* 0x00 */ uint32_t Event;
/* 0x04 */ uint32_t Mask;
/* 0x08 */ uint32_t PresentState;
/* 0x0C */ uint32_t Force;
/* 0x10 */ uint32_t Control;
/* 0x14 */ uint32_t Reserved[4];
/* 0x20 */ uint32_t UserDefined20h[504];
// 16-Bit Registers
/* 0x800 */ uint8_t IDAndRevision;
/* 0x801 */ uint8_t IFStatus;
/* 0x802 */ uint8_t PowerAndResetDrvControl;
/* 0x803 */ uint8_t InterruptAndGeneralControl;
/* 0x804 */ uint8_t CardStatusChange;
/* 0x805 */ uint8_t CardStatusChangeInterruptConfiguration;
/* 0x806 */ uint8_t AddressWindowEnable;
/* 0x807 */ uint8_t IOControl;
/* 0x808 */ uint16_t IOAdd0Start;
/* 0x80A */ uint16_t IOAdd0Stop;
/* 0x80C */ uint16_t IOAdd1Start;
/* 0x80E */ uint16_t IOAdd1Stop;
/* 0x810 */ uint16_t SysMemAdd0Start;
/* 0x812 */ uint16_t SysMemAdd0Stop;
/* 0x814 */ uint16_t CardMemoryOffsetAdd0;
/* 0x816 */ uint16_t UserDefined814h;
/* 0x818 */ uint16_t SysMemAdd1Start;
/* 0x81A */ uint16_t SysMemAdd1Stop;
/* 0x81C */ uint16_t CardMemoryOffsetAdd1;
/* 0x81E */ uint16_t UserDefined81Ch;
/* 0x820 */ uint16_t SysMemAdd2Start;
/* 0x822 */ uint16_t SysMemAdd2Stop;
/* 0x824 */ uint16_t CardMemoryOffsetAdd2;
/* 0x826 */ uint16_t UserDefined824h;
/* 0x828 */ uint16_t SysMemAdd3Start;
/* 0x82A */ uint16_t SysMemAdd3Stop;
/* 0x82C */ uint16_t CardMemoryOffsetAdd3;
/* 0x82E */ uint16_t UserDefined82Ch;
/* 0x830 */ uint16_t SysMemAdd4Start;
/* 0x832 */ uint16_t SysMemAdd4Stop;
/* 0x834 */ uint16_t CardMemoryOffsetAdd4;
/* 0x836 */ uint16_t UserDefined834h;
/* 0x838 */ uint32_t UserDefined838h[4];
/* 0x840 */ uint8_t SysMemAdd0MappingStartUp;
/* 0x841 */ uint8_t SysMemAdd1MappingStartUp;
/* 0x842 */ uint8_t SysMemAdd2MappingStartUp;
/* 0x843 */ uint8_t SysMemAdd3MappingStartUp;
/* 0x844 */ uint8_t SysMemAdd4MappingStartUp;
/* 0x845 */ uint8_t UserDefined845h;
/* 0x846 */ uint16_t UserDefined846h;
/* 0x848 */ uint32_t UserDefined848h[494];
} CardBusStatusAnfControlRegisters;
PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_2, 1)
{
this->pci_rd_memory_base_0 = [this]() { return this->memory_base_0 ; };
this->pci_rd_memory_limit_0 = [this]() { return this->memory_limit_0 ; };
this->pci_rd_memory_base_1 = [this]() { return this->memory_base_1 ; };
this->pci_rd_memory_limit_1 = [this]() { return this->memory_limit_1 ; };
this->pci_rd_io_base_0 = [this]() { return this->io_base_0 ; };
this->pci_rd_io_limit_0 = [this]() { return this->io_limit_0 ; };
this->pci_rd_io_base_1 = [this]() { return this->io_base_1 ; };
this->pci_rd_io_limit_1 = [this]() { return this->io_limit_1 ; };
this->pci_wr_memory_base_0 = [this](uint32_t val) {
this->memory_base_0 = val & this->memory_0_cfg;
this->memory_base_0_32 = this->memory_base_0;
};
this->pci_wr_memory_limit_0 = [this](uint32_t val) {
this->memory_limit_0 = val & this->memory_0_cfg;
this->memory_limit_0_32 = this->memory_limit_0 + 0x1000;
};
this->pci_wr_memory_base_1 = [this](uint32_t val) {
this->memory_base_1 = val & this->memory_1_cfg;
this->memory_base_1_32 = this->memory_base_1;
};
this->pci_wr_memory_limit_1 = [this](uint32_t val) {
this->memory_limit_1 = val & this->memory_1_cfg;
this->memory_limit_1_32 = this->memory_limit_1 + 0x1000;
};
this->pci_wr_io_base_0 = [this](uint32_t val) {
this->io_base_0 = (val & this->io_0_cfg) | (io_0_cfg & 3);
this->io_base_0_32 = (this->io_base_0 & ~3);
};
this->pci_wr_io_limit_0 = [this](uint32_t val) {
this->io_limit_0 = (val & this->io_0_cfg);
this->io_limit_0_32 = this->io_limit_0 + 4;
};
this->pci_wr_io_base_1 = [this](uint32_t val) {
this->io_base_1 = (val & this->io_1_cfg) | (io_1_cfg & 3);
this->io_base_1_32 = (this->io_base_1 & ~3);
};
this->pci_wr_io_limit_1 = [this](uint32_t val) {
this->io_limit_1 = (val & this->io_1_cfg);
this->io_limit_1_32 = this->io_limit_1 + 4;
};
}
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_BAR0:
return this->bars[(reg_offs - 0x10) >> 2];
case PCI_CFG_CB_CAPABILITIES:
return (this->pci_rd_sec_status() << 16) | cap_ptr;
case PCI_CFG_CB_MEMORY_BASE_0:
return this->pci_rd_memory_base_0();
case PCI_CFG_CB_MEMORY_LIMIT_0:
return this->pci_rd_memory_limit_0();
case PCI_CFG_CB_MEMORY_BASE_1:
return this->pci_rd_memory_base_0();
case PCI_CFG_CB_MEMORY_LIMIT_1:
return this->pci_rd_memory_limit_0();
case PCI_CFG_CB_IO_BASE_0:
return this->pci_rd_io_base_0();
case PCI_CFG_CB_IO_LIMIT_0:
return this->pci_rd_io_limit_0();
case PCI_CFG_CB_IO_BASE_1:
return this->pci_rd_io_base_0();
case PCI_CFG_CB_IO_LIMIT_1:
return this->pci_rd_io_limit_0();
case PCI_CFG_CB_SUBSYSTEM_IDS:
return (this->subsys_id << 16) | (this->subsys_vndr);
case PCI_CFG_CB_LEGACY_MODE_BASE:
return this->legacy_mode_base;
case PCI_CFG_CB_SOCKET_DMA_0:
return this->dreq_pin;
case PCI_CFG_CB_SOCKET_DMA_1:
return this->dma_base;
default:
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
}
}
void PCICardbusBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
{
switch (reg_offs) {
case PCI_CFG_BAR0:
this->set_bar_value((reg_offs - 0x10) >> 2, value);
break;
case PCI_CFG_CB_CAPABILITIES:
this->pci_wr_sec_status(value >> 16);
break;
case PCI_CFG_CB_MEMORY_BASE_0:
this->pci_wr_memory_base_0(value);
break;
case PCI_CFG_CB_MEMORY_LIMIT_0:
this->pci_wr_memory_limit_0(value);
break;
case PCI_CFG_CB_MEMORY_BASE_1:
this->pci_wr_memory_base_0(value);
break;
case PCI_CFG_CB_MEMORY_LIMIT_1:
this->pci_wr_memory_limit_0(value);
break;
case PCI_CFG_CB_IO_BASE_0:
this->pci_wr_io_base_0(value);
break;
case PCI_CFG_CB_IO_LIMIT_0:
this->pci_wr_io_limit_0(value);
break;
case PCI_CFG_CB_IO_BASE_1:
this->pci_wr_io_base_0(value);
break;
case PCI_CFG_CB_IO_LIMIT_1:
this->pci_wr_io_limit_0(value);
break;
#if 0
// FIXME: handle legacy_mode_base and dma_base changes here
case PCI_CFG_CB_LEGACY_MODE_BASE:
this->legacy_mode_base = value;
break;
case PCI_CFG_CB_SOCKET_DMA_0:
this->dreq_pin = value & DREQ_PIN_MASK;
break;
case PCI_CFG_CB_SOCKET_DMA_1:
this->dma_base = (value & DDMA_EXTMODE_MASK) | (value & (0xFFFF & ~DDMA_EXTMODE_MASK));
break;
#endif
default:
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
break;
}
}
bool PCICardbusBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
{
if (!(this->command & 1)) return false;
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
#if 0
// FIXME: check legacy_mode_base and dma_base here
#endif
return this->pci_io_read_loop(offset, size, *res);
}
bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
{
if (!(this->command & 1)) return false;
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
#if 0
// FIXME: check legacy_mode_base and dma_base here
#endif
return this->pci_io_write_loop(offset, size, value);
}
+136
View File
@@ -0,0 +1,136 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PCI_CARDBUSBRIDGE_H
#define PCI_CARDBUSBRIDGE_H
#include <devices/deviceregistry.h>
#include <devices/common/pci/pcibridgebase.h>
#include <devices/common/pci/pcihost.h>
#include <cinttypes>
#include <string>
#include <unordered_map>
#include <vector>
/** PCI configuration space registers offsets */
enum {
PCI_CFG_CB_CAPABILITIES = 0x14, // CB_CAPABILITIES.b, 0.b, CB_SEC_STATUS.w
PCI_CFG_CB_MEMORY_BASE_0 = 0x1C,
PCI_CFG_CB_MEMORY_LIMIT_0 = 0x20,
PCI_CFG_CB_MEMORY_BASE_1 = 0x24,
PCI_CFG_CB_MEMORY_LIMIT_1 = 0x28,
PCI_CFG_CB_IO_BASE_0 = 0x2C,
PCI_CFG_CB_IO_LIMIT_0 = 0x30,
PCI_CFG_CB_IO_BASE_1 = 0x34,
PCI_CFG_CB_IO_LIMIT_1 = 0x38,
PCI_CFG_CB_SUBSYSTEM_IDS = 0x40, // CB_SUBSYSTEM_VENDOR_ID.w, CB_SUBSYSTEM_ID.w
PCI_CFG_CB_LEGACY_MODE_BASE = 0x44,
PCI_CFG_CB_SOCKET_DMA_0 = 0x94,
PCI_CFG_CB_SOCKET_DMA_1 = 0x98,
};
/** PC Card bits */
enum {
DREQ_PIN_MASK = 3,
DREQ_NO_DMA = 0, // 0 = Socket is not configured for DMA
DREQ_USES_SPKR = 1,
DREQ_USES_IOIS16 = 2,
DREQ_USES_INPACK = 3,
DDMA_BASE_MASK = (0xFFF0),
DDMA_EXTMODE_MASK = (1 << 3),
DDMA_EXTMODE_DISABLE = (0 << 3),
DDMA_EXTMODE_ENABLE = (1 << 3),
DDMA_XFERSIZE_8_BITS = (0 << 1),
DDMA_XFERSIZE_16_BITS = (1 << 1),
DDMA_XFERSIZE_2 = (2 << 1),
DDMA_XFERSIZE_3 = (3 << 1),
DDMA_ENABLE = (1 << 0),
DDMA_DISABLE = (0 << 0),
};
class PCICardbusBridge : public PCIBridgeBase {
public:
PCICardbusBridge(std::string name);
~PCICardbusBridge() = default;
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
// plugin interface for using in the derived classes
std::function<uint32_t()> pci_rd_memory_base_0;
std::function<void(uint32_t)> pci_wr_memory_base_0;
std::function<uint32_t()> pci_rd_memory_limit_0;
std::function<void(uint32_t)> pci_wr_memory_limit_0;
std::function<uint32_t()> pci_rd_memory_base_1;
std::function<void(uint32_t)> pci_wr_memory_base_1;
std::function<uint32_t()> pci_rd_memory_limit_1;
std::function<void(uint32_t)> pci_wr_memory_limit_1;
std::function<uint32_t()> pci_rd_io_base_0;
std::function<void(uint32_t)> pci_wr_io_base_0;
std::function<uint32_t()> pci_rd_io_limit_0;
std::function<void(uint32_t)> pci_wr_io_limit_0;
std::function<uint32_t()> pci_rd_io_base_1;
std::function<void(uint32_t)> pci_wr_io_base_1;
std::function<uint32_t()> pci_rd_io_limit_1;
std::function<void(uint32_t)> pci_wr_io_limit_1;
protected:
// PCI configuration space state
uint32_t memory_base_0 = 0;
uint32_t memory_limit_0 = 0;
uint32_t memory_base_1 = 0;
uint32_t memory_limit_1 = 0;
uint32_t io_base_0 = 0;
uint32_t io_limit_0 = 0;
uint32_t io_base_1 = 0;
uint32_t io_limit_1 = 0;
uint16_t subsys_id = 0;
uint16_t subsys_vndr = 0;
uint32_t legacy_mode_base = 0;
uint32_t dreq_pin = DREQ_NO_DMA;
uint32_t dma_base = 0 | DDMA_EXTMODE_DISABLE | DDMA_XFERSIZE_8_BITS | DDMA_DISABLE;
// 0 = not writable
uint32_t memory_0_cfg = 0xfffff000;
uint32_t memory_1_cfg = 0xfffff000;
// 0 = not writable, 0x0000fffc = supports 16 bit I/O range, 0xfffffffd = supports 32 bit I/O range
uint32_t io_0_cfg = 0x0000fffc;
uint32_t io_1_cfg = 0x0000fffc;
// calculated address ranges
uint32_t memory_base_0_32 = 0;
uint32_t memory_limit_0_32 = 0;
uint32_t memory_base_1_32 = 0;
uint32_t memory_limit_1_32 = 0;
uint32_t io_base_0_32 = 0;
uint32_t io_limit_0_32 = 0;
uint32_t io_base_1_32 = 0;
uint32_t io_limit_1_32 = 0;
};
#endif /* PCI_CARDBUSBRIDGE_H */
Loaded 100 of 394 files, more files were not shown because too many files have changed in this diff. Show more