Commit Graph
247 Commits
Author SHA1 Message Date
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
dingusdev 7658707bd3 Add missing return statements 2026-07-29 18:49:54 -07: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
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
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 4ca03953d7 ppcemu: Fix EAR spr exception. 2026-03-08 10:42:22 -07:00
Maxim Poliakovski 6092882a45 ppcopcodes: fix bit test in eciwx/ecowx. 2026-02-22 18:17:29 +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
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
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 facbd05b9e ppcopcodes: Add missing break. 2025-07-25 07:14:05 -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
dingusdev c1ed416b58 Revert "display: Remove resizing flag."
This reverts commit c781ba8fab.
2025-04-23 21:08:45 -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 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
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 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
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 f3dec30c27 Add missing PR bit checks 2025-02-26 20:40:41 -07:00
joevt 82a48899f0 Change ppc_opcode_grabber to a variable. 2025-02-10 07:01:32 -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
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
dingusdev 47969d9d50 Reverting tweak
Restoring Virtus Player back to 'normal'
2024-12-07 20:49:00 -07:00
joevt cea889bde5 ppcopcodes: Cleanup lzu lzux lhau lhaux. 2024-12-07 06:34:00 -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
joevt b512702fbb ppcopcodes: Fix indent in ppc_mtsr. 2024-12-03 06:52:20 -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
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
joevt 549cb2284c Revert "Tweaking conditional branch instructions"
This reverts commit 0835e6f9f4.
2024-11-27 08:20:05 -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
Maxim Poliakovski 04280ecda4 Revert "Fix LR update in bc instructions"
This reverts commit 5a0a7b12e4.
2024-11-25 21:56:32 +01: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 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
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
Maxim Poliakovski e1acf5d160 Rename ppc_effective_address to ea. 2024-08-19 21:11:22 +02: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