Compare commits

..
Author SHA1 Message Date
Mihai Parparita c6c48eff4b ppc: Model configurable CPU frequencies
Virtual time previously advanced by a fixed 16 ns per interpreted
instruction, making every CPU behave like the legacy 62.5 MHz model
regardless of the selected machine. G3 guests also received ad hoc HID1
values from individual machine implementations, while Gazelle supported
several frequencies that could not share that logic.

Require each machine to provide its hardware-appropriate bus, core, and
timebase clocks through one `PPC_CPU_Config` configuration object. We can then
derive things from it (e.g. supported MPC603ev and MPC750 HID1 PLL encodings).
We can also populate the `include_601` global based on `version` instead of a
separate flag.

To model time with more flexibility, we now use 60.4 fixed-point nanoseconds for
instruction timing. This lets us have a broad set of frequencies and still
support running the CPU for ~35 years of virtual time before it overflows.

This results in two emulation accuracy improvements:
- Tiger successfully gets to the Finder. The virtual time we were exposing to
  the guest was advancing too quickly, preventing loginwindow from connecting
  before WindowServer's internal five-second no-client timer expired.
  The server then exited normally,  loginwindow aborted when it could not
  establish its CoreGraphics connection, and we remained stuck at the last
  textual output from a verbose boot ("Waiting for IFC").
- Animations are now more accurate (e.g. Mac OS X dock icon bouncing is no
  longer too fast on a G3)
2026-08-13 20:27:34 -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
53 changed files with 1515 additions and 969 deletions

No files matched your search

+6
View File
@@ -228,6 +228,11 @@ jobs:
- 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
@@ -266,6 +271,7 @@ jobs:
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()
+2 -2
View File
@@ -29,10 +29,10 @@ This program currently uses the command prompt to work.
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
+10 -4
View File
@@ -29,8 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_on = false;
power_off_reason = po_benchmark_exception;
power_off(po_benchmark_exception);
}
#endif
@@ -70,9 +69,16 @@ int main(int argc, char** argv) {
return -1;
}
constexpr uint64_t tbr_freq = 16705000;
constexpr uint64_t bus_freq = 66'820'000ULL;
constexpr uint64_t tbr_freq = bus_freq / 4;
constexpr uint64_t core_freq = bus_freq * 7 / 2; // 233.87 MHz (CPU PLL ratio of 3.5)
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
ppc_cpu_init(grackle_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = tbr_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
/* load executable code into RAM at address 0 */
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
+2 -2
View File
@@ -52,7 +52,7 @@ public:
}
// Calls all connected slots.
void emit(Args... args) {
void emit(Args... args) const {
if (!_is_enabled) {
return;
}
@@ -77,7 +77,7 @@ public:
_is_enabled = true;
}
bool is_enabled() {
bool is_enabled() const {
return _is_enabled;
}
+77 -33
View File
@@ -44,8 +44,7 @@ void EventManager::poll_events() {
switch (event.type) {
case SDL_QUIT:
power_on = false;
power_off_reason = po_quit;
power_off(po_quit);
break;
case SDL_WINDOWEVENT: {
@@ -125,21 +124,55 @@ void EventManager::poll_events() {
}
return;
}
// Control-Alt-Shift-+: increase instruction period
if (event.key.keysym.sym == SDLK_EQUALS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
uint64_t instruction_period = increment_instruction_period();
LOG_F(INFO, "Incremented instruction period: %d", (int)instruction_period);
}
return;
}
// Control-Alt-Shift--: decrease instruction period
if (event.key.keysym.sym == SDLK_MINUS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
uint64_t instruction_period = decrement_instruction_period();
LOG_F(INFO, "Decremented instruction period: %d", (int)instruction_period);
}
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");
}
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
loguru::Verbosity_INFO
:
loguru::Verbosity_MAX;
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_on = false;
power_off_reason = po_enter_debugger;
power_off(po_enter_debugger);
}
return;
}
@@ -285,6 +318,7 @@ void EventManager::poll_events() {
}
void EventManager::post_keyboard_state_events() {
int count;
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
@@ -300,46 +334,54 @@ void EventManager::post_keyboard_state_events() {
} 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
{ 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, " mod:%s", SDL_GetScancodeName(mod->scancode));
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(mod->scancode));
count++;
ke.key = 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, " ignore:%s", SDL_GetScancodeName(scancode));
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
LOG_F(INFO, " Key: %s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
@@ -350,9 +392,11 @@ void EventManager::post_keyboard_state_events() {
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
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)
@@ -486,9 +530,9 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_SCROLLLOCK: return AdbKey_F14;
case SDLK_PAUSE: return AdbKey_F15;
//International keyboard support
// International keyboard support
//Japanese keyboard
// Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
@@ -503,18 +547,18 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL2):
return AdbKey_JIS_Kana;
//German keyboard
// 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
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?
// 0XB2 is superscript 2. Which Mac key should this one map to?
case 0XF9: return AdbKey_Quote; // U-grave
// Italian keyboard
+2 -2
View File
@@ -102,7 +102,7 @@ typedef struct TimerInfo {
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) const {
return l.get()->timeout_ns > r.get()->timeout_ns ||
(l.get()->timeout_ns == r.get()->timeout_ns && l.get()->id > r.get()->id);
}
@@ -128,7 +128,7 @@ public:
}
// 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_absolute_timer(uint64_t timeout_ns, uint64_t interval, timer_cb cb);
+26 -2
View File
@@ -366,6 +366,11 @@ enum Po_Cause : int {
extern bool power_on;
extern Po_Cause power_off_reason;
void p_set_power_off_reason(const char* file, int line, Po_Cause new_reason);
void p_power_off(const char* file, int line, Po_Cause new_reason);
#define set_power_off_reason(r) p_set_power_off_reason(__FILE__, __LINE__, r)
#define power_off(r) p_power_off(__FILE__, __LINE__, r)
extern bool int_pin;
extern bool dec_exception_pending;
@@ -384,7 +389,8 @@ enum class PPCPowMode : uint8_t {
extern PPCPowMode ppc_pow_mode;
extern uint32_t ppc_pow_hid0_mask;
// Make execution deterministic (ignore external input, used a fixed date, etc.)
// Enable deterministic timing and non-persistent state. The selected mode may
// still permit external input.
extern bool is_deterministic;
// Important Addressing Integers
@@ -464,8 +470,15 @@ typedef enum {
// Placeholder value for cases where we don't have a currently-executing instruction.
constexpr uint32_t NO_OPCODE = 0;
struct PPC_CPU_Config {
uint32_t version;
uint64_t timebase_freq_hz;
uint64_t bus_freq_hz;
uint64_t core_freq_hz;
};
// Function prototypes
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, const PPC_CPU_Config& config);
extern void ppc_mmu_init();
void ppc_illegalop(uint32_t opcode);
@@ -714,6 +727,17 @@ extern void ppc_change_endian(bool newLE);
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
/* instruction period control */
extern uint64_t increment_instruction_period();
extern uint64_t decrement_instruction_period();
extern uint64_t get_instruction_period();
/* toggle_g_realtime */
extern bool toggle_g_realtime();
/* force_cycle_counter_reload */
static void force_cycle_counter_reload();
#ifdef LOG_INSTRUCTIONS
typedef struct {
uint64_t cycle;
+173 -47
View File
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcdisasm.h"
#include <algorithm>
#include <cinttypes>
#include <chrono>
#include <cstring>
#include <iostream>
@@ -73,6 +74,43 @@ bool is_deterministic = false;
bool power_on = false;
Po_Cause power_off_reason = po_enter_debugger;
const char * get_po_name(Po_Cause reason) {
#define onename(x) case x: return #x;
switch (reason) {
onename(po_none)
onename(po_starting_up)
onename(po_quit)
onename(po_quitting)
onename(po_shut_down)
onename(po_shutting_down)
onename(po_restart)
onename(po_restarting)
onename(po_disassemble_on)
onename(po_disassemble_off)
onename(po_enter_debugger)
onename(po_entered_debugger)
onename(po_signal_interrupt)
onename(po_benchmark_exception)
onename(po_endian_switch)
default: return "unknown";
}
#undef onename
}
void p_set_power_off_reason(const char* file, int line, Po_Cause new_reason) {
if (new_reason != power_off_reason) {
power_off_reason = new_reason;
#if 1
LOG_F(INFO, "power_off_reason changed to %s at \"%s\":%d", get_po_name(new_reason), file, line);
#endif
}
}
void p_power_off(const char* file, int line, Po_Cause new_reason) {
power_on = false;
p_set_power_off_reason(file, line, new_reason);
}
SetPRS ppc_state;
#ifdef LOG_INSTRUCTIONS
uint32_t pcp;
@@ -92,16 +130,21 @@ volatile bool exec_timer;
bool int_pin = false; // interrupt request pin state: true - asserted
bool dec_exception_pending = false;
/* copy of local variable bb_start_la. Need for correct
calculation of CPU cycles after setjmp that clobbers
non-volatile local variables. */
uint32_t glob_bb_start_la;
/* variables related to virtual time */
const bool g_realtime = false;
bool g_realtime = false;
uint64_t g_nanoseconds_base;
uint64_t g_icycles;
int icnt_factor;
// Fixed-point nanoseconds, with four fractional bits. This provides enough
// precision for the supported CPU clocks and over 36 years before overflow.
using FixedNanoseconds = uint64_t;
static constexpr int VIRT_TIME_FRAC_BITS = 4;
static FixedNanoseconds g_virt_time;
static FixedNanoseconds g_instruction_period;
static constexpr FixedNanoseconds instruction_period_for_frequency(uint64_t core_freq_hz)
{
return (((uint64_t)NS_PER_SEC << VIRT_TIME_FRAC_BITS) + core_freq_hz / 2) /
core_freq_hz;
}
/* global variables related to the timebase facility */
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
@@ -229,8 +272,7 @@ void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_nex
ppc_next_instruction_address = ppc_state.pc + 4;
}
#else
power_on = false;
power_off_reason = po_endian_switch;
power_off(po_endian_switch);
#endif
}
}
@@ -240,14 +282,12 @@ void ppc_change_endian(bool newLE) {
if (ppc_state.is_LE != newLE) {
LOG_F(INFO, "changed endian to %s", newLE ? "LE" : "BE");
ppc_state.is_LE = newLE;
power_on = false;
power_off_reason = po_endian_switch;
power_off(po_endian_switch);
}
#else
if (newLE) {
LOG_F(ERROR, "unsupported endian %s", newLE ? "LE" : "BE");
power_on = false;
power_off_reason = po_enter_debugger;
power_off(po_enter_debugger);
}
#endif
}
@@ -327,20 +367,35 @@ uint64_t get_virt_time_ns()
if (g_realtime) {
return cpu_now_ns() - g_nanoseconds_base;
} else {
return g_icycles << icnt_factor;
return g_virt_time >> VIRT_TIME_FRAC_BITS;
}
}
static uint64_t process_events()
void set_virt_time_ns(uint64_t time_now)
{
if (g_realtime) {
g_nanoseconds_base = cpu_now_ns() - time_now - 5000;
} else {
g_virt_time = time_now << VIRT_TIME_FRAC_BITS;
}
uint64_t time_new = get_virt_time_ns();
if (g_realtime && time_new > time_now) {
g_nanoseconds_base += 2 * (time_new - time_now);
time_new = get_virt_time_ns();
}
LOG_F(INFO, "time before: %lld after: %lld change: %lld", time_now, time_new, time_new - time_now);
}
static FixedNanoseconds process_events()
{
exec_timer = false;
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
if (slice_ns == 0) {
// execute 25.000 cycles
// execute 25,000 instructions
// if there are no pending timers
return g_icycles + 25000;
return g_virt_time + 25'000 * g_instruction_period;
}
return g_icycles + (slice_ns >> icnt_factor) + 1;
return g_virt_time + (slice_ns << VIRT_TIME_FRAC_BITS);
}
static void force_cycle_counter_reload()
@@ -349,6 +404,40 @@ static void force_cycle_counter_reload()
exec_timer = true;
}
uint64_t increment_instruction_period()
{
uint64_t time_now = get_virt_time_ns();
g_instruction_period += 1;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
return g_instruction_period;
}
uint64_t decrement_instruction_period()
{
if (g_instruction_period > 0) {
uint64_t time_now = get_virt_time_ns();
g_instruction_period -= 1;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
}
return g_instruction_period;
}
uint64_t get_instruction_period()
{
return g_instruction_period;
}
bool toggle_g_realtime()
{
uint64_t time_now = get_virt_time_ns();
g_realtime = !g_realtime;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
return g_realtime;
}
typedef enum {
main,
until,
@@ -359,7 +448,10 @@ typedef enum {
template <ppc_exec_type_t exec_type, endian_switch endian>
static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
{
uint64_t max_cycles = 0;
FixedNanoseconds event_deadline = 0;
// Keep these hot-loop values in registers.
FixedNanoseconds virt_time = g_virt_time;
FixedNanoseconds instruction_period = g_instruction_period;
uint32_t page_start, eb_start, eb_end = 0;
uint32_t opcode;
PPCOpcode* opcode_grabber = ppc_opcode_grabber;
@@ -382,21 +474,29 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode_grabber, opcode);
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]]
max_cycles = process_events();
virt_time += instruction_period;
g_virt_time = virt_time;
if (virt_time >= event_deadline || exec_timer) [[unlikely]] {
event_deadline = process_events();
virt_time = g_virt_time;
instruction_period = g_instruction_period;
}
if (exec_flags) {
if ((exec_flags & EXEF_SLEEP) && !(exec_flags & EXEF_EXCEPTION)) [[unlikely]] {
while (power_on && (exec_flags & EXEF_SLEEP)) {
max_cycles = process_events();
event_deadline = process_events();
virt_time = g_virt_time;
instruction_period = g_instruction_period;
if (!(exec_flags & EXEF_SLEEP)) {
break;
}
if (max_cycles > g_icycles) {
g_icycles = max_cycles;
if (event_deadline > virt_time) {
virt_time = event_deadline;
} else {
g_icycles++;
virt_time += instruction_period;
}
g_virt_time = virt_time;
}
}
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
@@ -474,7 +574,7 @@ void ppc_exec_single()
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(ppc_opcode_grabber, opcode);
g_icycles++;
g_virt_time += g_instruction_period;
process_events();
if (exec_flags) {
@@ -915,21 +1015,59 @@ void initialize_ppc_opcode_table() {
}
}
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_601, uint64_t tb_freq)
static uint32_t get_cpu_pll_value(const PPC_CPU_Config& config)
{
switch (config.version) {
case PPC_VER::MPC603EV:
if (config.core_freq_hz * 2 == config.bus_freq_hz * 9)
return 7; // 4.5:1 ratio
if (config.core_freq_hz == config.bus_freq_hz * 5)
return 11; // 5:1 ratio
if (config.core_freq_hz * 2 == config.bus_freq_hz * 11)
return 9; // 5.5:1 ratio
break;
case PPC_VER::MPC750:
if (config.core_freq_hz * 2 == config.bus_freq_hz * 7)
return 14; // 3.5:1 ratio
if (config.core_freq_hz == config.bus_freq_hz * 6)
return 13; // 6:1 ratio
if (config.core_freq_hz == config.bus_freq_hz * 8)
return 12; // 8:1 ratio
break;
default:
break;
}
ABORT_F("Unsupported CPU/bus frequency combination: %" PRIu64 "/%" PRIu64 " Hz",
config.core_freq_hz, config.bus_freq_hz);
}
void ppc_cpu_init(MemCtrlBase* mem_ctrl, const PPC_CPU_Config& config)
{
if (!config.timebase_freq_hz || !config.bus_freq_hz || !config.core_freq_hz)
ABORT_F("CPU clock frequencies must be non-zero");
mem_ctrl_instance = mem_ctrl;
int_pin = false;
std::memset(&ppc_state, 0, sizeof(ppc_state));
set_host_rounding_mode(0);
ppc_state.spr[SPR::PVR] = cpu_version;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 & do_include_601;
ppc_state.spr[SPR::PVR] = config.version;
switch (config.version) {
case PPC_VER::MPC603EV:
case PPC_VER::MPC750:
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(config) << 28;
break;
default:
break;
}
is_601 = (config.version >> 16) == 1;
include_601 = is_601;
ppc_pow_mode = PPCPowMode::None;
ppc_pow_hid0_mask = 0;
switch (cpu_version) {
switch (config.version) {
case PPC_VER::MPC603:
case PPC_VER::MPC603E:
case PPC_VER::MPC603EV:
@@ -959,25 +1097,13 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
mach_timebase_info(&timebase_info);
#endif
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
// // // PDM cpu clock calculated at 0x403036CC in r3
// icnt_factor = 11; // 1 instruction = 2048 ns = 0.488 MHz // 00068034 = 0.426036 MHz = 2347.219 ns // floppy doesn't work
// icnt_factor = 10; // 1 instruction = 1024 ns = 0.977 MHz // 000D204C = 0.860236 MHz = 1162.471 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 9; // 1 instruction = 512 ns = 1.953 MHz // 001A6081 = 1.728641 MHz = 578.489 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 8; // 1 instruction = 256 ns = 3.906 MHz // 0034E477 = 3.466359 MHz = 288.487 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 7; // 1 instruction = 128 ns = 7.813 MHz // 0069E54C = 6.939980 MHz = 144.092 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 6; // 1 instruction = 64 ns = 15.625 MHz // 00D3E6F5 = 13.887221 MHz = 72.008 ns // (10..60] = 50, (60..73] = 66, (73..100] = 80 MHz
// icnt_factor = 5; // 1 instruction = 32 ns = 31.250 MHz // 01A7B672 = 27.768434 MHz = 36.012 ns //
icnt_factor = 4; // 1 instruction = 16 ns = 62.500 MHz // 034F0F0F = 55.512847 MHz = 18.013 ns // 6100/60 in Apple System Profiler
// icnt_factor = 3; // 1 instruction = 8 ns = 125.000 MHz // 069E1E1E = 111.025694 MHz = 9.006 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 2; // 1 instruction = 4 ns = 250.000 MHz // 0D3C3C3C = 222.051388 MHz = 4.503 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 1; // 1 instruction = 2 ns = 500.000 MHz // 1A611A7B = 442.571387 MHz = 2.259 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 0; // 1 instruction = 1 ns = 1500.000 MHz // 3465B2D9 = 879.080153 MHz = 1.137 ns // (100...) MHz = invalid clock for PDM gestalt calculation
g_virt_time = 0;
g_instruction_period = instruction_period_for_frequency(config.core_freq_hz);
tbr_wr_timestamp = 0;
rtc_timestamp = 0;
tbr_wr_value = 0;
uint64_t tb_freq = config.timebase_freq_hz;
if (is_601)
tb_freq <<= 7;
tbr_freq_shift = 0;
+13 -2
View File
@@ -1239,6 +1239,9 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
// copy FPR[reg_b] to FPSCR under control of cr_mask
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (FPR_INT(reg_b) & cr_mask);
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1275,6 +1278,9 @@ void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
}
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1289,6 +1295,9 @@ void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
ppc_state.fpscr |= (0x80000000UL >> crf_d);
}
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1309,8 +1318,10 @@ void dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
));
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI));
ppc_update_vx();
ppc_update_fex();
}
// Floating Point Comparisons
+148 -75
View File
@@ -77,9 +77,6 @@ uint64_t num_entry_replacements = 0; // number of entry replacements
#endif // TLB_PROFILING
/** remember recently used physical memory regions for quicker translation. */
AddressMapEntry last_read_area;
AddressMapEntry last_write_area;
AddressMapEntry last_exec_area;
AddressMapEntry last_ptab_area;
/** Dummy pages for catching writes to physical read-only pages */
@@ -461,6 +458,58 @@ fail:
return MapDmaResult{RT_NONE, false, nullptr, nullptr, 0};
}
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
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
};
// PAT context changes are frequent, so implicitly invalidate PAT-derived
// entries via a generation counter (instead of walking the TLB array and
// clearing every time).
static uint32_t gTLBPatGeneration = 0;
typedef struct TLBEntry {
uint32_t tag; // use is_invalid() or matches_tag() for validity checks
uint16_t flags;
uint16_t lru_bits;
union {
struct { // for memory pages
int64_t host_va_offs_r;
int64_t host_va_offs_w;
};
struct { // for MMIO pages
AddressMapEntry* rgn_desc;
int64_t dev_base_va;
};
};
uint32_t phys_tag;
uint32_t pat_generation;
bool is_invalid() const
{
return tag == TLB_INVALID_TAG ||
((flags & TLBFlags::TLBE_FROM_PAT) &&
pat_generation != gTLBPatGeneration);
}
bool matches_tag(uint32_t tag_in) const
{
return tag == tag_in &&
(!(flags & TLBFlags::TLBE_FROM_PAT) ||
pat_generation == gTLBPatGeneration);
}
} TLBEntry;
// primary ITLB for all MMU modes
static std::array<TLBEntry, TLB_SIZE> itlb1_mode1;
static std::array<TLBEntry, TLB_SIZE> itlb1_mode2;
@@ -558,28 +607,28 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
}
// select the target from invalid blocks first
if (tlb_entry[0].tag == TLB_INVALID_TAG) {
if (tlb_entry[0].is_invalid()) {
// update LRU bits
tlb_entry[0].lru_bits = 0x3;
tlb_entry[1].lru_bits = 0x2;
tlb_entry[2].lru_bits &= 0x1;
tlb_entry[3].lru_bits &= 0x1;
return tlb_entry;
} else if (tlb_entry[1].tag == TLB_INVALID_TAG) {
} else if (tlb_entry[1].is_invalid()) {
// update LRU bits
tlb_entry[0].lru_bits = 0x2;
tlb_entry[1].lru_bits = 0x3;
tlb_entry[2].lru_bits &= 0x1;
tlb_entry[3].lru_bits &= 0x1;
return &tlb_entry[1];
} else if (tlb_entry[2].tag == TLB_INVALID_TAG) {
} else if (tlb_entry[2].is_invalid()) {
// update LRU bits
tlb_entry[0].lru_bits &= 0x1;
tlb_entry[1].lru_bits &= 0x1;
tlb_entry[2].lru_bits = 0x3;
tlb_entry[3].lru_bits = 0x2;
return &tlb_entry[2];
} else if (tlb_entry[3].tag == TLB_INVALID_TAG) {
} else if (tlb_entry[3].is_invalid()) {
// update LRU bits
tlb_entry[0].lru_bits &= 0x1;
tlb_entry[1].lru_bits &= 0x1;
@@ -669,6 +718,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
(phys_addr - rgn_desc->start);
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
tlb_entry->pat_generation = gTLBPatGeneration;
} else {
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
}
@@ -697,9 +747,9 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
// check block protection
if (!bat_res.prot || ((bat_res.prot & 1) && is_write)) {
if (!is_dbg)
LOG_F(9, "BAT DSI exception in TLB2 refill!");
LOG_F(9, "BAT DSI exception in TLB2 refill!");
if (!is_dbg)
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0);
@@ -752,6 +802,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
}
}
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
tlb_entry->pat_generation = gTLBPatGeneration;
return tlb_entry;
} else {
if (!is_dbg) {
@@ -780,27 +831,27 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
tlb_entry = &pCurDTLB2[((guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
}
if (tlb_entry->tag == tag) {
if (tlb_entry[0].matches_tag(tag)) {
// update LRU bits
tlb_entry[0].lru_bits = 0x3;
tlb_entry[1].lru_bits = 0x2;
tlb_entry[2].lru_bits &= 0x1;
tlb_entry[3].lru_bits &= 0x1;
} else if (tlb_entry[1].tag == tag) {
} else if (tlb_entry[1].matches_tag(tag)) {
// update LRU bits
tlb_entry[0].lru_bits = 0x2;
tlb_entry[1].lru_bits = 0x3;
tlb_entry[2].lru_bits &= 0x1;
tlb_entry[3].lru_bits &= 0x1;
tlb_entry = &tlb_entry[1];
} else if (tlb_entry[2].tag == tag) {
} else if (tlb_entry[2].matches_tag(tag)) {
// update LRU bits
tlb_entry[0].lru_bits &= 0x1;
tlb_entry[1].lru_bits &= 0x1;
tlb_entry[2].lru_bits = 0x3;
tlb_entry[3].lru_bits = 0x2;
tlb_entry = &tlb_entry[2];
} else if (tlb_entry[3].tag == tag) {
} else if (tlb_entry[3].matches_tag(tag)) {
// update LRU bits
tlb_entry[0].lru_bits &= 0x1;
tlb_entry[1].lru_bits &= 0x1;
@@ -813,6 +864,49 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
return tlb_entry;
}
void mmu_dcbz(uint32_t opcode, uint32_t guest_va)
{
const uint32_t tag = guest_va & ~0xFFFUL;
// look up guest virtual address in the primary TLB
TLBEntry *tlb_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (!tlb_entry->matches_tag(tag)) {
// primary TLB miss -> look up address in the secondary TLB
tlb_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
if (tlb_entry == nullptr) {
// secondary TLB miss ->
// perform full address translation and refill the secondary TLB
tlb_entry = dtlb2_refill(guest_va, 1);
}
}
// Check if this was in a MMIO region, in which case we avoid doing the
// write, so that this intermediate state is not visible to the device
// (usually a dcbz is done to prepare a cache line as a write buffer, and
// the real values are written later).
if (tlb_entry->flags & TLBFlags::PAGE_IO) {
// Still do the same checks that mmu_write_vmem would have done to
// disallow writes to read-only regions.
if (!(tlb_entry->flags & TLBFlags::PAGE_WRITABLE)) {
ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25);
ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0);
}
if (!(tlb_entry->flags & TLBFlags::PTE_SET_C)) {
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
tlb_entry->flags |= TLBFlags::PTE_SET_C;
}
return;
}
// the following is not especially efficient but necessary
// to make BlockZero under Mac OS 8.x and later to work
mmu_write_vmem<uint64_t>(opcode, guest_va + 0, 0);
mmu_write_vmem<uint64_t>(opcode, guest_va + 8, 0);
mmu_write_vmem<uint64_t>(opcode, guest_va + 16, 0);
mmu_write_vmem<uint64_t>(opcode, guest_va + 24, 0);
}
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
{
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
@@ -832,7 +926,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
// look up guest virtual address in the primary ITLB
tlb1_entry = &pCurITLB1[(vaddr >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (tlb1_entry->tag == tag) { // primary ITLB hit -> fast path
if (tlb1_entry->matches_tag(tag)) { // primary ITLB hit -> fast path
#ifdef TLB_PROFILING
num_primary_itlb_hits++;
#endif
@@ -858,6 +952,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
tlb1_entry->flags = tlb2_entry->flags;
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
tlb1_entry->phys_tag = tlb2_entry->phys_tag;
tlb1_entry->pat_generation = tlb2_entry->pat_generation;
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
}
@@ -943,10 +1038,9 @@ void tlb_flush_entries(TLBFlags type)
}
}
bool gTLBFlushIBatEntries = false;
bool gTLBFlushDBatEntries = false;
bool gTLBFlushIPatEntries = false;
bool gTLBFlushDPatEntries = false;
static bool gTLBFlushIBatEntries = false;
static bool gTLBFlushDBatEntries = false;
static bool gTLBInvalidatePatEntries = false;
template <const TLBType tlb_type>
void tlb_flush_bat_entries()
@@ -964,38 +1058,18 @@ void tlb_flush_bat_entries()
}
}
template <const TLBType tlb_type>
void tlb_flush_pat_entries()
static void tlb_invalidate_pat_entries()
{
if (tlb_type == TLBType::ITLB) {
if (!gTLBFlushIPatEntries)
return;
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_PAT);
gTLBFlushIPatEntries = false;
} else {
if (!gTLBFlushDPatEntries)
return;
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_PAT);
gTLBFlushDPatEntries = false;
}
}
if (!gTLBInvalidatePatEntries)
return;
template <const TLBType tlb_type>
void tlb_flush_all_entries()
{
if (tlb_type == TLBType::ITLB) {
if (!gTLBFlushIBatEntries && !gTLBFlushIPatEntries)
return;
tlb_flush_entries<TLBType::ITLB>((TLBFlags)(TLBE_FROM_BAT | TLBE_FROM_PAT));
gTLBFlushIBatEntries = false;
gTLBFlushIPatEntries = false;
} else {
if (!gTLBFlushDBatEntries && !gTLBFlushDPatEntries)
return;
tlb_flush_entries<TLBType::DTLB>((TLBFlags)(TLBE_FROM_BAT | TLBE_FROM_PAT));
gTLBFlushDBatEntries = false;
gTLBFlushDPatEntries = false;
gTLBPatGeneration++;
if (gTLBPatGeneration == 0) { // Do a full flush when the counter wraps around
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_PAT);
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_PAT);
}
gTLBInvalidatePatEntries = false;
}
static void mpc601_bat_update(uint32_t bat_reg)
@@ -1029,14 +1103,15 @@ static void mpc601_bat_update(uint32_t bat_reg)
}
// MPC601 has unified BATs so we're going to flush both ITLB and DTLB
if (!gTLBFlushIBatEntries || !gTLBFlushIPatEntries || !gTLBFlushDBatEntries || !gTLBFlushDPatEntries) {
if (!gTLBFlushIBatEntries) {
gTLBFlushIBatEntries = true;
gTLBFlushIPatEntries = true;
gTLBFlushDBatEntries = true;
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::ITLB>);
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
}
if (!gTLBFlushDBatEntries) {
gTLBFlushDBatEntries = true;
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
}
mmu_pat_ctx_changed();
}
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
@@ -1062,11 +1137,11 @@ static void ppc_ibat_update(uint32_t bat_reg)
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
if (!gTLBFlushIBatEntries || !gTLBFlushIPatEntries) {
if (!gTLBFlushIBatEntries) {
gTLBFlushIBatEntries = true;
gTLBFlushIPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::ITLB>);
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
}
mmu_pat_ctx_changed();
}
static void ppc_dbat_update(uint32_t bat_reg)
@@ -1087,22 +1162,20 @@ static void ppc_dbat_update(uint32_t bat_reg)
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
if (!gTLBFlushDBatEntries || !gTLBFlushDPatEntries) {
if (!gTLBFlushDBatEntries) {
gTLBFlushDBatEntries = true;
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
}
mmu_pat_ctx_changed();
}
void mmu_pat_ctx_changed()
{
// Page address translation context changed so we need to flush
// all PAT entries from both ITLB and DTLB
if (!gTLBFlushIPatEntries || !gTLBFlushDPatEntries) {
gTLBFlushIPatEntries = true;
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::ITLB>);
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::DTLB>);
// Page address translation context changed so invalidate all PAT entries
// from both ITLB and DTLB.
if (!gTLBInvalidatePatEntries) {
gTLBInvalidatePatEntries = true;
add_ctx_sync_action(&tlb_invalidate_pat_entries);
}
}
@@ -1153,7 +1226,7 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
bool needs_swap = false;
#endif
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
if (tlb1_entry->matches_tag(tag)) { // primary TLB hit -> fast path
#ifdef TLB_PROFILING
num_primary_dtlb_hits++;
#endif
@@ -1324,7 +1397,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
bool needs_swap = false;
#endif
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
if (tlb1_entry->matches_tag(tag)) { // primary TLB hit -> fast path
#ifdef TLB_PROFILING
num_primary_dtlb_hits++;
#endif
@@ -1520,8 +1593,8 @@ static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va ARG
} else
#endif
{
result = (result << 8) | mmu_read_vmem<uint8_t>(opcode, guest_va);
}
result = (result << 8) | mmu_read_vmem<uint8_t>(opcode, guest_va);
}
}
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
} else if (sizeof(T) == sizeof(uint64_t) && munged) {
@@ -1898,7 +1971,7 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
do {
if (tlb1_entry->tag != tag) {
if (!tlb1_entry->matches_tag(tag)) {
// primary TLB miss -> look up address in the secondary TLB
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
if (tlb2_entry == nullptr) {
@@ -1949,15 +2022,15 @@ static void invalidate_tlb_entries(std::array<TLBEntry, N> &tlb) {
tlb_el.host_va_offs_r = 0;
tlb_el.host_va_offs_w = 0;
tlb_el.phys_tag = 0;
tlb_el.reserved = 0;
tlb_el.pat_generation = 0;
}
}
void ppc_mmu_init()
{
last_read_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
last_write_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
gTLBPatGeneration = 0;
gTLBInvalidatePatEntries = false;
last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
mmu_exception_handler = ppc_exception_handler;
+1 -34
View File
@@ -24,8 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef PPCMMU_H
#define PPCMMU_H
#include <devices/memctrl/memctrlbase.h>
#include <cinttypes>
#include <functional>
@@ -84,38 +82,6 @@ typedef struct MapDmaResult {
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);
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
typedef struct TLBEntry {
uint32_t tag;
uint16_t flags;
uint16_t lru_bits;
union {
struct { // for memory pages
int64_t host_va_offs_r;
int64_t host_va_offs_w;
};
struct { // for MMIO pages
AddressMapEntry* rgn_desc;
int64_t dev_base_va;
};
};
uint32_t phys_tag;
uint32_t reserved;
} 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
};
extern std::function<void(uint32_t bat_reg)> ibat_update;
extern std::function<void(uint32_t bat_reg)> dbat_update;
@@ -128,6 +94,7 @@ extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmi
extern void mmu_change_mode(void);
extern void mmu_pat_ctx_changed();
extern void tlb_flush_entry(uint32_t ea);
extern void mmu_dcbz(uint32_t opcode, uint32_t guest_va);
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
+13 -6
View File
@@ -730,6 +730,7 @@ void dppc_interpreter::ppc_mtsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
int reg_s = (opcode >> 21) & 0x1F;
uint32_t grab_sr = (opcode >> 16) & 0x0F;
@@ -745,6 +746,7 @@ void dppc_interpreter::ppc_mtsrin(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_regssb(opcode);
uint32_t grab_sr = ppc_result_b >> 28;
@@ -760,6 +762,7 @@ void dppc_interpreter::ppc_mfsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
int reg_d = (opcode >> 21) & 0x1F;
uint32_t grab_sr = (opcode >> 16) & 0x0F;
@@ -772,6 +775,7 @@ void dppc_interpreter::ppc_mfsrin(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_regsdb(opcode);
uint32_t grab_sr = ppc_result_b >> 28;
@@ -784,6 +788,7 @@ void dppc_interpreter::ppc_mfmsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
uint32_t reg_d = (opcode >> 21) & 0x1F;
ppc_state.gpr[reg_d] = ppc_state.msr;
@@ -795,6 +800,7 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
uint32_t reg_s = (opcode >> 21) & 0x1F;
uint32_t old_msr_val = ppc_state.msr;
@@ -991,12 +997,14 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
case SPR::MQ:
if (!(is_601 || include_601)) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::RTCL_U:
if (!is_601) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
calc_rtcl_value();
ppc_state.gpr[reg_d] =
@@ -1006,6 +1014,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
case SPR::RTCU_U:
if (!is_601) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
calc_rtcl_value();
ppc_state.gpr[reg_d] =
@@ -1015,6 +1024,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
case SPR::DEC_U:
if (!is_601) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
// fallthrough
case SPR::DEC_S:
@@ -1606,12 +1616,7 @@ void dppc_interpreter::ppc_dcbz(uint32_t opcode) {
ea &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
// the following is not especially efficient but necessary
// to make BlockZero under Mac OS 8.x and later to work
mmu_write_vmem<uint64_t>(opcode, ea + 0, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 8, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 16, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 24, 0);
mmu_dcbz(opcode, ea);
}
@@ -2074,6 +2079,7 @@ void dppc_interpreter::ppc_eciwx(uint32_t opcode) {
// error if EAR[E] != 1
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
return;
}
ppc_grab_regsdab(opcode);
@@ -2095,6 +2101,7 @@ void dppc_interpreter::ppc_ecowx(uint32_t opcode) {
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_state.spr[SPR::DSISR] = 0x00100000;
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
return;
}
ppc_grab_regssab(opcode);
+24 -9
View File
@@ -58,6 +58,8 @@ using namespace std;
#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 static_cast<uint32_t>(stoul(addr_str, NULL, 0));
@@ -116,6 +118,8 @@ static void show_help() {
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;
@@ -726,21 +730,21 @@ void DppcDebugger::enter_debugger() {
while (1) {
if (power_off_reason == po_shut_down) {
power_off_reason = po_shutting_down;
set_power_off_reason(po_shutting_down);
break;
}
if (power_off_reason == po_restart) {
power_off_reason = po_restarting;
set_power_off_reason(po_restarting);
break;
}
if (power_off_reason == po_quit) {
power_off_reason = po_quitting;
set_power_off_reason(po_quitting);
break;
}
power_on = true;
if (power_off_reason == po_starting_up) {
power_off_reason = po_none;
set_power_off_reason(po_none);
cmd = "go";
}
else if (power_off_reason == po_disassemble_on) {
@@ -751,13 +755,13 @@ void DppcDebugger::enter_debugger() {
ss >> cmd;
}
else if (power_off_reason == po_disassemble_off) {
power_off_reason = po_none;
set_power_off_reason(po_none);
cmd = "go";
}
else
{
if (power_off_reason == po_enter_debugger) {
power_off_reason = po_entered_debugger;
set_power_off_reason(po_entered_debugger);
}
if (!did_message) {
cout << endl;
@@ -794,7 +798,7 @@ void DppcDebugger::enter_debugger() {
}
if (power_off_reason == po_signal_interrupt) {
power_off_reason = po_enter_debugger;
set_power_off_reason(po_enter_debugger);
// ignore command if interrupt happens because the input line is probably incomplete.
last_cmd = "";
continue;
@@ -821,8 +825,7 @@ void DppcDebugger::enter_debugger() {
break;
} else if (cmd == "restart") {
cmd = "";
power_on = false;
power_off_reason = po_restart;
power_off(po_restart);
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
@@ -1169,6 +1172,18 @@ void DppcDebugger::enter_debugger() {
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 {
if (!cmd.empty()) {
cout << "Unknown command: " << cmd << endl;
+40 -3
View File
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace ata_interface;
AtapiBaseDevice::AtapiBaseDevice(const std::string name)
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI) {
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI), ScsiPhysInterface(PHY_ID_ATAPI) {
}
void AtapiBaseDevice::device_set_signature() {
@@ -90,7 +90,7 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
case ATA_Reg::STATUS:
this->update_intrq(0);
case ATA_Reg::ALT_STATUS:
if (this->r_status & BSY && this->data_available()) {
if ((this->r_status & BSY) && this->data_available()) {
this->r_byte_count = this->request_data();
this->data_in_phase();
}
@@ -201,12 +201,14 @@ int AtapiBaseDevice::perform_command() {
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::IO; // device->host
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
this->signal_data_ready();
}
@@ -218,3 +220,38 @@ void AtapiBaseDevice::present_status() {
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);
}
}
+21 -1
View File
@@ -25,11 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#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
class AtapiBaseDevice : public AtaBaseDevice, public ScsiPhysInterface
{
public:
AtapiBaseDevice(const std::string name);
@@ -40,6 +42,24 @@ public:
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;
+29 -176
View File
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/ata/atadefs.h>
#include <devices/common/ata/atapicdrom.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/scsi/scsi.h> // ATAPI CDROM reuses SCSI commands (sic!)
#include <devices/deviceregistry.h>
#include <machines/machinebase.h>
#include <machines/machineproperties.h>
@@ -36,12 +35,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace ata_interface;
AtapiCdrom::AtapiCdrom(std::string name) : CdromDrive(), AtapiBaseDevice(name) {
this->set_error_callback(
[this](uint8_t sense_key, uint8_t asc) {
this->status_error(sense_key, asc);
}
);
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() {
@@ -77,166 +87,16 @@ void AtapiCdrom::perform_packet_command() {
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::TEST_UNIT_READY:
if (this->medium_present())
this->status_good();
else
this->status_error(ScsiSense::NOT_READY, ScsiError::MEDIUM_NOT_PRESENT);
this->present_status();
break;
case ScsiCommand::REQ_SENSE:
xfer_len = this->request_sense(this->data_buf, this->sense_key, this->asc, this->ascq);
if (!xfer_len) {
this->present_status();
} else {
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
}
break;
case ScsiCommand::INQUIRY:
this->xfer_cnt = this->inquiry(this->cmd_pkt, this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
break;
case ScsiCommand::START_STOP_UNIT:
if ((this->cmd_pkt[4] & 3) == 2) {
LOG_F(WARNING, "CD-ROM eject requested");
}
this->status_good();
this->present_status();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
LOG_F(INFO, "%s: medium removal %s", this->name.c_str(),
this->cmd_pkt[4] & 1 ? "prevented" : "allowed");
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CAPACITY:
this->xfer_cnt = this->report_capacity(this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
break;
case ScsiCommand::READ_TOC:
this->status_good();
xfer_len = this->read_toc(this->cmd_pkt, this->data_buf);
if (!xfer_len) {
this->present_status();
} else {
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
this->data_ptr = (uint16_t*)this->data_buf;
this->data_in_phase();
}
break;
case ScsiCommand::MODE_SENSE_6:
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
}
break;
case ScsiCommand::MODE_SENSE_10:
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
}
break;
case ScsiCommand::READ_6:
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
xfer_len = this->cmd_pkt[4];
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_in_phase();
break;
case ScsiCommand::READ_10:
if (this->xfer_cnt > 0) {
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
#if 0
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->data_in_phase(); });
#else
this->data_in_phase();
#endif
break;
case ScsiCommand::READ_12:
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_in_phase();
break;
case ScsiCommand::SET_CD_SPEED:
LOG_F(INFO, "%s: speed set to %d kBps", this->name.c_str(),
READ_WORD_BE_U(&this->cmd_pkt[2]));
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CD:
{
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
@@ -329,10 +189,7 @@ void AtapiCdrom::perform_packet_command() {
break;
}
default:
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
this->cmd_pkt[0]);
this->status_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CMD);
this->present_status();
ScsiCdromCmds::process_command();
}
}
@@ -456,18 +313,14 @@ uint16_t AtapiCdrom::get_data() {
}
void AtapiCdrom::status_good() {
this->status_expected = true;
this->r_error = 0;
this->sense_key = 0;
this->r_status &= ~ATA_Status::ERR;
this->set_status(ScsiStatus::GOOD, this->sense_key);
}
void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->status_expected = true;
this->sense_key = sense_key;
this->asc = asc;
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
this->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
static const PropMap AtapiCdrom_Properties = {
+10 -6
View File
@@ -25,11 +25,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define ATAPI_CDROM_H
#include <devices/common/ata/atapibasedevice.h>
#include <devices/storage/cdromdrive.h>
#include <devices/common/scsi/scsicdromcmds.h>
#include <string>
class AtapiCdrom : public CdromDrive, public AtapiBaseDevice {
class AtapiCdrom : public AtapiBaseDevice, public ScsiCdromCmds {
public:
AtapiCdrom(std::string name);
~AtapiCdrom() = default;
@@ -38,10 +38,17 @@ public:
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
}
bool is_device_ready() override { return this->is_ready; }
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;
@@ -54,11 +61,8 @@ public:
void status_error(uint8_t sense_key, uint8_t asc);
uint16_t get_data();
private:
uint8_t sense_key = 0;
uint8_t asc = 0;
uint8_t ascq = 0;
private:
bool doing_sector_areas = false;
uint8_t sector_areas;
uint32_t current_block;
+20 -14
View File
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/dmacore.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/mmiodevice.h>
#include <devices/memctrl/memctrlbase.h>
#include <cinttypes>
#include <cstring>
@@ -119,14 +120,14 @@ void DMAChannel::interpret_cmd() {
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(false);
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);
}
this->xfer_quad(true);
this->xfer_quad(false);
break;
case DBDMA_Cmd::NOP:
this->finish_cmd();
@@ -144,6 +145,18 @@ void DMAChannel::interpret_cmd() {
}
}
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;
@@ -186,17 +199,9 @@ void DMAChannel::finish_cmd() {
this->ch_stat |= CH_STAT_BT;
}
}
if (this->cur_is_writable)
WRITE_WORD_LE_A(&this->cur_host->xfer_stat, this->ch_stat | CH_STAT_ACTIVE);
}
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP && this->cur_is_writable) {
WRITE_WORD_LE_A(&this->cur_host->res_count, this->res_count);
}
this->update_cmd();
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
this->cmd_ptr += 16;
@@ -367,6 +372,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
this->dev_obj->notify(this, DMA_MSG_FLUSH);
if (this->flush_cb)
this->flush_cb();
this->update_cmd();
}
}
this->ch_stat &= ~CH_STAT_FLUSH;
@@ -426,10 +432,10 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
}
break;
case DMAReg::CMD_PTR_LO:
if (!(this->ch_stat & CH_STAT_ACTIVE)) {
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", this->get_name().c_str(),
this->cmd_ptr);
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;
+1
View File
@@ -141,6 +141,7 @@ public:
protected:
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
void interpret_cmd(void);
void update_cmd();
void finish_cmd();
void xfer_quad(bool is_store);
void update_irq(uint8_t cmd_bits);
+4 -4
View File
@@ -248,7 +248,7 @@ enum ModePage : uint8_t {
DEV_FORMAT_PARAMS = 0x3,
RIGID_DISK_GEOMETRY = 0x4,
CDROM_PARAMS = 0xD,
CDROM_AUDIO = 0xE,
CDROM_AUDIO_CONTROL = 0xE,
POWER_CONDITION = 0x1A,
CDROM_CAPABILITIES = 0x2A,
VENDOR_PAGE_31 = 0x31,
@@ -307,12 +307,12 @@ public:
this->post_xfer_action = cb;
}
void set_status(uint8_t status_code) override {
void set_status(uint8_t status_code, uint8_t sense_key) override {
this->status = status_code;
}
void set_eject_state(bool eject_allowed) override {
this->eject_allowed = eject_allowed;
void set_lock_state(bool is_locked) override {
this->eject_allowed = !is_locked;
}
virtual void notify(ScsiNotification notif_type, int param);
+8 -8
View File
@@ -88,18 +88,18 @@ void ScsiBlockCmds::process_command() {
case ScsiCommand::READ_6:
case ScsiCommand::READ_10:
case ScsiCommand::READ_12:
next_phase = this->read_new();
next_phase = this->read();
break;
case ScsiCommand::WRITE_6:
case ScsiCommand::WRITE_10:
case ScsiCommand::WRITE_12:
next_phase = this->write_new();
next_phase = this->write();
break;
case ScsiCommand::START_STOP_UNIT:
next_phase = this->start_stop_unit();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
phy_impl->set_eject_state((this->cdb_ptr[4] & 1) == 0);
phy_impl->set_lock_state((this->cdb_ptr[4] & 1) != 0);
next_phase = ScsiPhase::STATUS;
break;
case ScsiCommand::READ_CAPACITY:
@@ -113,7 +113,7 @@ void ScsiBlockCmds::process_command() {
phy_impl->switch_phase(next_phase);
}
int ScsiBlockCmds::read_new() {
int ScsiBlockCmds::read() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for READ_6
@@ -122,7 +122,7 @@ int ScsiBlockCmds::read_new() {
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ: RelAdr bit set");
LOG_F(WARNING, "READ: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
@@ -143,7 +143,7 @@ int ScsiBlockCmds::read_new() {
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::write_new() {
int ScsiBlockCmds::write() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for WRITE_6
@@ -152,7 +152,7 @@ int ScsiBlockCmds::write_new() {
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "WRITE: RelAdr bit set");
LOG_F(WARNING, "WRITE: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
@@ -194,7 +194,7 @@ int ScsiBlockCmds::read_capacity() {
uint32_t lba = this->get_lba();
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ_CAPACITY: RelAdr bit set");
LOG_F(WARNING, "READ_CAPACITY: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
+2 -2
View File
@@ -41,8 +41,8 @@ public:
void init_block_device(uint8_t medium_type, uint8_t dev_flags,
uint8_t density_code, bool is_apple_compliant);
virtual int read_new();
virtual int write_new();
virtual int read();
virtual int write();
virtual int start_stop_unit();
virtual int read_capacity();
-28
View File
@@ -47,8 +47,6 @@ ScsiCdrom::ScsiCdrom(std::string name, int my_id) : ScsiPhysDevice(name, my_id)
this->set_vendor_id(my_vendor_id);
this->set_product_id(my_product_id);
this->set_revision_id(my_revision_id);
this->add_page_getter(this, 49, &ScsiCdrom::get_apple_page_49);
}
void ScsiCdrom::process_command() {
@@ -80,32 +78,6 @@ void ScsiCdrom::process_command() {
// Apple SCSI/ATAPI driver requests this page in the case of a device error.
// PearPC implements it under the name "Apple Features".
// I couldn't find any drive whose firmware supports it.
int ScsiCdrom::get_apple_page_49(uint8_t subpage, uint8_t ctrl, uint8_t *out_ptr,
int avail_len)
{
LOG_F(WARNING, "Page 0x31 requested");
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 6;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size);
out_ptr[0] = '.';
out_ptr[1] = 'A';
out_ptr[2] = 'p';
out_ptr[3] = 'p';
return page_size;
}
void ScsiCdrom::mode_select_6(uint8_t param_len)
{
if (!param_len)
+5 -3
View File
@@ -37,12 +37,14 @@ public:
virtual void process_command() override;
void set_lock_state(bool is_locked) override {
this->drive_locked = is_locked ? 1 : 0;
ScsiPhysDevice::set_lock_state(is_locked);
}
protected:
bool is_device_ready() override { return this->is_ready; }
int get_apple_page_49(uint8_t subpage, uint8_t ctrl, uint8_t *out_ptr,
int avail_len);
void mode_select_6(uint8_t param_len);
private:
+126 -2
View File
@@ -29,6 +29,16 @@ ScsiCdromCmds::ScsiCdromCmds() {
this->set_phys_block_dev(this);
this->enable_cmd(ScsiCommand::READ_TOC);
this->enable_cmd(ScsiCommand::SET_CD_SPEED);
this->add_page_getter(this, ModePage::CDROM_AUDIO_CONTROL,
&ScsiCdromCmds::get_cdrom_audio_control_page);
this->add_page_getter(this, ModePage::CDROM_CAPABILITIES,
&ScsiCdromCmds::get_cd_capabilities_page);
this->add_page_getter(this, ModePage::VENDOR_PAGE_31,
&ScsiCdromCmds::get_apple_page_49);
}
void ScsiCdromCmds::process_command() {
@@ -39,7 +49,10 @@ void ScsiCdromCmds::process_command() {
switch(this->cdb_ptr[0]) {
case ScsiCommand::READ_TOC:
next_phase = this->read_toc_new();
next_phase = this->read_toc();
break;
case ScsiCommand::SET_CD_SPEED:
next_phase = this->set_cd_speed();
break;
default:
ScsiBlockCmds::process_command();
@@ -49,7 +62,7 @@ void ScsiCdromCmds::process_command() {
phy_impl->switch_phase(next_phase);
}
int ScsiCdromCmds:: read_toc_new() {
int ScsiCdromCmds:: read_toc() {
uint8_t start_track, session_num;
int tot_tracks, resp_len = 0;
@@ -212,3 +225,114 @@ int ScsiCdromCmds:: read_toc_new() {
return ScsiPhase::DATA_IN;
}
int ScsiCdromCmds::set_cd_speed() {
phy_impl->set_status(ScsiStatus::GOOD);
uint16_t new_rd_speed = READ_WORD_BE_U(&this->cdb_ptr[2]);
if (new_rd_speed == 0xFFFFU || new_rd_speed > this->max_rd_speed)
this->cur_rd_speed = this->max_rd_speed;
else
this->cur_rd_speed = new_rd_speed;
LOG_F(INFO, "SET_CD_SPEED: drive speed set to %d kBps", this->cur_rd_speed);
return ScsiPhase::STATUS;
}
int ScsiCdromCmds::get_cd_capabilities_page(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 28; // min length defined in MMC-3
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size); // clear everything
out_ptr[ 0] = this->read_cap;
out_ptr[ 1] = this->write_cap;
out_ptr[ 2] = this->fmt_support;
out_ptr[ 3] = this->ext_support;
out_ptr[ 4] = (this->mech_type << 5) | this->sw_lock_sup |
(this->drive_locked << 1) | (this->prevent_jump << 2) |
(this->sw_eject_sup << 3);
out_ptr[ 5] = this->more_support;
out_ptr[15] = this->dgt_out_desc;
WRITE_WORD_BE_A(&out_ptr[ 6], this->max_rd_speed); // max read speed
WRITE_WORD_BE_A(&out_ptr[ 8], this->max_vol_levs); // max of volume levels
WRITE_WORD_BE_A(&out_ptr[10], (this->cache_size / 1024)); // buffer size kB
WRITE_WORD_BE_A(&out_ptr[12], this->cur_rd_speed); // current read speed
return page_size;
}
int ScsiCdromCmds::get_cdrom_audio_control_page(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 14;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size); // clear everything
out_ptr[ 0] = (1 << 2); // Immed defaults to 1, SOTC defaults to 0
// logical block per second of audio playback defaults to 75
WRITE_WORD_BE_A(&out_ptr[4], 75);
out_ptr[ 6] = 0x01; // Left Channel
out_ptr[ 7] = 0xFF; // Volume (0-255)
out_ptr[ 8] = 0x02; // Right Channel
out_ptr[ 9] = 0xFF; // Volume (0-255)
out_ptr[10] = 0x04; // Output Port 2
out_ptr[11] = 0x00; // Volume (0-255)
out_ptr[12] = 0x08; // Output Port 3
out_ptr[13] = 0x00; // Volume (0-255)
return page_size;
}
// Apple SCSI/ATAPI driver requests this page in the case of a device error.
// PearPC implements it under the name "Apple Features".
int ScsiCdromCmds::get_apple_page_49(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len)
{
LOG_F(WARNING, "Page 0x31 requested");
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 6;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size);
out_ptr[0] = '.';
out_ptr[1] = 'A';
out_ptr[2] = 'p';
out_ptr[3] = 'p';
return page_size;
}
+11 -1
View File
@@ -36,7 +36,17 @@ public:
protected:
virtual void process_command() override;
int read_toc_new();
int get_apple_page_49(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len);
int read_toc();
int set_cd_speed();
int get_cd_capabilities_page(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len);
int get_cdrom_audio_control_page(uint8_t subpage, uint8_t ctrl,
uint8_t *out_ptr, int avail_len);
};
#endif // SCSI_CDROM_COMMANDS_H
+9 -9
View File
@@ -39,10 +39,10 @@ void ScsiCommonCmds::process_command() {
next_phase = this->test_unit_ready();
break;
case ScsiCommand::REQ_SENSE:
next_phase = this->request_sense_new();
next_phase = this->request_sense();
break;
case ScsiCommand::INQUIRY:
next_phase = this->inquiry_new();
next_phase = this->inquiry();
break;
case ScsiCommand::MODE_SENSE_6:
case ScsiCommand::MODE_SENSE_10:
@@ -85,7 +85,7 @@ int ScsiCommonCmds::verify_cdb() {
if (!this->lun_supported(lun)) {
LOG_F(ERROR, "unsupported LUN 0x%X", lun);
this->invalid_lun();
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
return -1;
}
} else if (this->cdb_ptr[1] >> 5)
@@ -115,13 +115,13 @@ int ScsiCommonCmds::test_unit_ready() {
this->sense_key = ScsiSense::NOT_READY;
this->asc = phy_impl->not_ready_reason();
this->ascq = 0;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
return ScsiPhase::STATUS;
}
int ScsiCommonCmds::inquiry_new() {
int ScsiCommonCmds::inquiry() {
int alloc_len = this->get_xfer_len();
int resp_len = 36; // standard response length
@@ -178,7 +178,7 @@ int ScsiCommonCmds::inquiry_new() {
return ScsiPhase::DATA_IN;
}
int ScsiCommonCmds::request_sense_new() {
int ScsiCommonCmds::request_sense() {
int alloc_len = this->get_xfer_len();
int resp_len = 18; // standard response length
@@ -420,7 +420,7 @@ void ScsiCommonCmds::invalid_cdb() {
this->ascq = 0;
this->is_cdb_err = true;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
void ScsiCommonCmds::invalid_command() {
@@ -433,7 +433,7 @@ void ScsiCommonCmds::invalid_command() {
this->field_ptr_valid = true;
this->field_ptr = 0; // error in the 1st byte
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
void ScsiCommonCmds::illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb) {
@@ -442,5 +442,5 @@ void ScsiCommonCmds::illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb) {
this->ascq = ascq;
this->is_cdb_err = is_cdb;
phy_impl->set_status(ScsiStatus::CHECK_CONDITION);
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
}
+2 -2
View File
@@ -87,8 +87,8 @@ public:
protected:
virtual void process_command();
virtual int test_unit_ready();
virtual int inquiry_new();
virtual int request_sense_new();
virtual int inquiry();
virtual int request_sense();
virtual int mode_sense();
virtual uint8_t get_lun();
virtual uint32_t get_xfer_len();
+2 -2
View File
@@ -47,13 +47,13 @@ public:
virtual int get_phy_id() { return this->phy_id; };
virtual bool is_device_ready() { return true; }
virtual void set_eject_state(bool eject_allowed) = 0;
virtual void set_lock_state(bool is_locked) = 0;
virtual uint8_t not_ready_reason() { return 0; }
virtual bool last_sel_has_attention() { return false; }
virtual uint8_t last_sel_msg() { return 0; }
virtual void set_xfer_len(uint64_t len) = 0;
virtual void set_buffer(uint8_t *buf_ptr) = 0;
virtual void set_status(uint8_t status_code) = 0;
virtual void set_status(uint8_t status_code, uint8_t sense_key = 0) = 0;
virtual void switch_phase(const int new_phase) = 0;
virtual void set_read_more_data_cb(more_data_cb_t cb) = 0;
virtual void set_write_more_data_cb(more_data_cb_t cb) = 0;
+2 -4
View File
@@ -814,13 +814,11 @@ void ViaCuda::pseudo_command() {
break;
case CUDA_RESTART_SYSTEM:
LOG_F(INFO, "Cuda: system restart");
power_on = false;
power_off_reason = po_restart;
power_off(po_restart);
break;
case CUDA_POWER_DOWN:
LOG_F(INFO, "Cuda: system shutdown");
power_on = false;
power_off_reason = po_shut_down;
power_off(po_shut_down);
break;
case CUDA_SET_POWER_UPTIME: {
uint32_t alarm_time = READ_DWORD_BE_U(&this->in_buf[2]);
+25 -6
View File
@@ -42,23 +42,34 @@ BurgundyCodec::BurgundyCodec(std::string name) : MacioSndCodec(name)
}
uint32_t BurgundyCodec::snd_ctrl_read(uint32_t offset, int size) {
uint32_t result = 0;
uint32_t value = 0;
switch (offset) {
case AWAC_SOUND_CTRL_REG:
value = this->snd_ctrl_reg;
break;
case AWAC_CODEC_CTRL_REG:
result = this->last_ctrl_data;
value = this->last_ctrl_data;
break;
case AWAC_CODEC_STATUS_REG:
result = (this->first_valid << 23) | BURGUNDY_READY |
(this->byte_counter << 14) | (this->read_pos << 12) |
(this->data_byte << 4);
value = (this->first_valid << 23) | BURGUNDY_READY |
(this->byte_counter << 14) | (this->read_pos << 12) |
(this->data_byte << 4);
break;
case AWAC_FRAME_COUNT:
value = (uint32_t)(
(
(TimerManager::get_instance()->current_time_ns() - frame_count_start_time) * this->sr_table[0]
+ 500000000
) / 1000000000 + this->frame_count
);
break;
default:
LOG_F(ERROR, "%s: read from unsupported register 0x%X", this->name.c_str(),
offset);
}
return BYTESWAP_32(result);
return BYTESWAP_32(value);
}
void BurgundyCodec::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
@@ -69,6 +80,10 @@ void BurgundyCodec::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
value = BYTESWAP_32(value);
switch (offset) {
case AWAC_SOUND_CTRL_REG:
this->snd_ctrl_reg = BYTESWAP_32(value);
//this->set_sample_rate((this->snd_ctrl_reg >> 8) & 7);
break;
case AWAC_CODEC_CTRL_REG:
this->last_ctrl_data = value;
reg_addr = (value >> 12) & 0xFF;
@@ -92,6 +107,10 @@ void BurgundyCodec::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
});
}
break;
case AWAC_FRAME_COUNT:
this->frame_count = BYTESWAP_32(value);
this->frame_count_start_time = TimerManager::get_instance()->current_time_ns();
break;
default:
LOG_F(ERROR, "%s: write to unsupported register 0x%X", this->name.c_str(),
offset);
+3
View File
@@ -51,12 +51,15 @@ public:
}
private:
uint32_t snd_ctrl_reg = 0x1011;
uint32_t last_ctrl_data = 0;
uint8_t byte_counter = 0;
uint8_t reg_addr = 0;
uint8_t first_valid = 0;
uint8_t read_pos = 0;
uint8_t data_byte = 0;
uint32_t frame_count = 0;
uint64_t frame_count_start_time = 0;
uint32_t reg_array[BURGUNDY_NUM_REGS] = {};
};
+4 -5
View File
@@ -134,7 +134,7 @@ static long sound_out_callback(cubeb_stream* stream, void* user_data,
out_frames = 0;
while (req_frames > 0) {
if (!dma_ch->pull_data((uint32_t)req_frames << 2, &got_len, &p_in)) {
if (DmaPullResult::MoreData == dma_ch->pull_data((uint32_t)req_frames << 2, &got_len, &p_in)) {
if ((in_buf = (int16_t*)p_in)) {
frames = got_len >> 2;
@@ -173,12 +173,11 @@ int SoundServer::open_out_stream(uint32_t sample_rate, DmaOutChannel *dma_ch)
return;
}
// Drain the DMA buffer, but don't do anything else.
int req_size = std::max(dma_ch->get_pull_data_remaining(), 1024);
while (req_size > 0) {
while(1) {
uint8_t *chunk;
uint32_t chunk_size;
if (!dma_ch->pull_data(req_size, &chunk_size, &chunk)) {
req_size -= chunk_size;
if (DmaPullResult::MoreData == dma_ch->pull_data(1024, &chunk_size, &chunk)) {
;
} else {
break;
}
-290
View File
@@ -21,8 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Virtual CD-ROM device implementation. */
#include <core/memaccess.h>
#include <devices/common/scsi/scsi.h> // reuse SCSI definitions
#include <devices/storage/cdromdrive.h>
#include <loguru.hpp>
@@ -72,152 +70,6 @@ bool CdromDrive::detect_raw_image() {
return false;
}
static char cdrom_vendor_dingus_id[] = "DINGUS ";
static char cdrom_product_id[] = "DINGUS CD-ROM ";
static char cdrom_revision_id[] = "1.0 ";
uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", "CdromDrive");
}
if (alloc_len > 36) {
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", "CdromDrive");
}
data_ptr[0] = 5; // device type: CD-ROM
data_ptr[1] = 0x80; // removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 0x21; // ATAPI Version + response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0;
std::memcpy(&data_ptr[8], cdrom_vendor_dingus_id, 8);
std::memcpy(&data_ptr[16], cdrom_product_id, 16);
std::memcpy(&data_ptr[32], cdrom_revision_id, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
LOG_F(ERROR, "%s: allocation length too small: %d", "CdromDrive",
alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
}
return alloc_len;
}
uint32_t CdromDrive::mode_sense_ex(bool is_sense_6, uint8_t* cmd_ptr, uint8_t* data_ptr) {
uint8_t *resp_ptr;
uint8_t page_code = cmd_ptr[2] & 0x3F;
uint8_t alloc_len = is_sense_6 ? READ_WORD_BE_U(&cmd_ptr[4]) : READ_WORD_BE_U(&cmd_ptr[7]);
std::memset(data_ptr, 0, alloc_len);
data_ptr[0] = 0; // initial data size MSB
data_ptr[1] = 6; // initial data size LSB
data_ptr[2] = 1; // medium type: 120mm CD-ROM
data_ptr[3] = 0; // device-specific parameter
data_ptr[4] = 0;
data_ptr[5] = 0;
data_ptr[6] = 0; // block description length MSB
data_ptr[7] = 0; // block description length LSB
resp_ptr = data_ptr + 8;
resp_ptr[0] = page_code;
switch (page_code) {
case ModePage::ERROR_RECOVERY:
resp_ptr[1] = 6; // data size
std::memset(&resp_ptr[2], 0, 6);
data_ptr[1] += 8; // adjust overall length
break;
case ModePage::CDROM_AUDIO:
resp_ptr[1] = 16; // page length
std::memset(&resp_ptr[2], 0, 16);
resp_ptr[2] = (1 << 2); //immediately return status
WRITE_WORD_BE_A(&resp_ptr[6], 75); // logical block per second of audio playback
resp_ptr[8] = 0x01; // Left Channel
resp_ptr[9] = 0xFF; // Volume (0-255)
resp_ptr[10] = 0x02; // Right Channel
resp_ptr[11] = 0xFF; // Volume (0-255)
resp_ptr[12] = 0x04; // Output Port 2
resp_ptr[13] = 0x00; // Volume (0-255)
resp_ptr[14] = 0x08; // Output Port 3
resp_ptr[15] = 0x00; // Volume (0-255)
data_ptr[1] += 8; // adjust overall length
break;
case ModePage::POWER_CONDITION:
resp_ptr[1] = 10; // page length
std::memset(&resp_ptr[2], 0, 10);
resp_ptr[3] = 0; //idle and standby off
WRITE_DWORD_BE_A(&resp_ptr[4], 0); // Idle Timer (100ms units)
WRITE_DWORD_BE_A(&resp_ptr[8], 0); // Standby Timer (100ms units)
data_ptr[1] += 12; // adjust overall length
break;
case ModePage::CDROM_CAPABILITIES:
resp_ptr[1] = 18; // page data length
std::memset(&resp_ptr[2], 0, 18);
resp_ptr[2] = 0x03; // supports reading CD-R and CD-E
resp_ptr[3] = 0x00; // doesn't support writing to CD-R and CD-E
resp_ptr[6] = (1 << 5) | (1 << 3) | (1 << 0); // tray type + eject + lock support
WRITE_WORD_BE_A(&resp_ptr[ 8], 706); // report 4x speed
WRITE_WORD_BE_A(&resp_ptr[10], 2); // supports audio on/off only
WRITE_WORD_BE_A(&resp_ptr[12], 512); // 512Kb cache
WRITE_WORD_BE_A(&resp_ptr[14], 706); // report current speed (4x)
data_ptr[1] += 20; // adjust overall length
break;
case ModePage::VENDOR_PAGE_31:
resp_ptr[1] = 14; // page data length
std::memset(&resp_ptr[2], 0, 14);
resp_ptr[8] = 0x31;
resp_ptr[9] = 6;
resp_ptr[10] = '.';
resp_ptr[11] = 'A';
resp_ptr[12] = 'p';
resp_ptr[13] = 'p';
data_ptr[1] += 2; // adjust overall length
break;
default:
LOG_F(ERROR, "ATAPI CD-ROM: Invalid Page Code 0x%x", page_code);
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
return 0;
}
return data_ptr[1] + 2; // return total response length
}
uint32_t CdromDrive::request_sense(uint8_t *data_ptr, uint8_t sense_key,
uint8_t asc, uint8_t ascq) {
std::memset(data_ptr, 0, 18);
data_ptr[ 0] = 0x80 | 0x70; // valid + current error
data_ptr[ 2] = sense_key;
data_ptr[ 7] = 10; // additional sense length
data_ptr[12] = asc;
data_ptr[13] = ascq;
return 18;
}
uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
WRITE_DWORD_BE_A(data_ptr, static_cast<uint32_t>(this->size_blocks));
WRITE_DWORD_BE_A(&data_ptr[4], this->block_size);
return 8;
}
uint8_t CdromDrive::hex_to_bcd(const uint8_t val) {
uint8_t hi = val / 10;
uint8_t lo = val % 10;
@@ -230,145 +82,3 @@ AddrMsf CdromDrive::lba_to_msf(const int lba) {
hex_to_bcd( lba % 75) /*.frm*/
};
}
uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int tot_tracks, data_len;
uint8_t start_track, session_num;
uint8_t* out_ptr;
uint16_t alloc_len = READ_WORD_BE_U(&cmd_ptr[7]);
bool is_msf = !!(cmd_ptr[1] & 2);
// ATAPI specific handling of the format field
uint8_t format = cmd_ptr[2] & 7;
if (!format) {
format = cmd_ptr[9] >> 6;
}
if (!alloc_len)
return 0;
switch(format) {
case 0: // Formatted TOC
start_track = cmd_ptr[6];
if (!start_track) { // special case: track zero (lead-in) as starting track
// return all tracks starting with track 1 plus lead-out
start_track = 1;
tot_tracks = this->num_tracks + 1;
} else if (start_track == LEAD_OUT_TRK_NUM) {
start_track = this->num_tracks + 1;
tot_tracks = 1;
} else if (start_track <= this->num_tracks) {
tot_tracks = (this->num_tracks - start_track) + 2;
} else {
LOG_F(ERROR, "CDROM: invalid starting track %d in READ_TOC", start_track);
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
return 0;
}
out_ptr = data_ptr;
data_len = (tot_tracks * 8) + 4;
// write TOC data header
WRITE_WORD_BE_A(out_ptr, data_len - 2);
out_ptr[2] = 1; // 1st track number
out_ptr[3] = this->num_tracks; // last track number
out_ptr += 4;
for (int tx = 0; tx < tot_tracks; tx++) {
if ((out_ptr - data_ptr + 8) > alloc_len)
break; // exit the loop if the output buffer length is exhausted
TrackDescriptor& td = this->tracks[start_track + tx - 1];
*out_ptr++ = 0; // reserved
*out_ptr++ = td.adr_ctrl;
*out_ptr++ = td.trk_num;
*out_ptr++ = 0; // reserved
if (is_msf) {
AddrMsf msf = lba_to_msf(td.start_lba + 150);
*out_ptr++ = 0; // reserved
*out_ptr++ = msf.min;
*out_ptr++ = msf.sec;
*out_ptr++ = msf.frm;
} else {
WRITE_DWORD_BE_A(out_ptr, td.start_lba);
out_ptr += 4;
}
}
return alloc_len;
case 1: // Multi-session info
std::memset(data_ptr, 0, 12);
data_ptr[1] = 10; // TOC data length
data_ptr[2] = 1; // first session number
data_ptr[3] = 1; // last session number
data_ptr[5] = this->tracks[0].adr_ctrl;
data_ptr[6] = 1;
if (is_msf) {
AddrMsf msf = lba_to_msf(this->tracks[0].start_lba + 150);
data_ptr[ 8] = 0; // reserved
data_ptr[ 9] = msf.min;
data_ptr[10] = msf.sec;
data_ptr[11] = msf.frm;
}
return 12;
case 2: // Raw TOC
session_num = cmd_ptr[6];
if (!session_num)
session_num = 1;
if (session_num > 1) {
LOG_F(ERROR, "CDROM: invalid session number %d", session_num);
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
return 0;
}
std::memset(data_ptr, 0, 48);
out_ptr = data_ptr;
// prepare data header
out_ptr[1] = 46; // TOC data length
out_ptr[2] = 1; // first session number
out_ptr[3] = 1; // last session number
out_ptr += 4;
// descriptor #1 -> first track
out_ptr[0] = session_num;
out_ptr[1] = this->tracks[0].adr_ctrl;
out_ptr[3] = 0xA0; // point -> first track
out_ptr[8] = 1; // first track number
out_ptr += 11;
// descriptor #2 -> last track
out_ptr[0] = session_num;
out_ptr[1] = this->tracks[0].adr_ctrl;
out_ptr[3] = 0xA1; // point -> last track
out_ptr[8] = 1; // last track number
out_ptr += 11;
// descriptor #3 -> lead-out
out_ptr[0] = session_num;
out_ptr[1] = this->tracks[0].adr_ctrl;
out_ptr[3] = 0xA2; // point -> lead-out
if (is_msf) {
AddrMsf msf = lba_to_msf(this->tracks[1].start_lba + 150);
out_ptr[ 7] = 0; // reserved
out_ptr[ 8] = msf.min;
out_ptr[ 9] = msf.sec;
out_ptr[10] = msf.frm;
} else {
WRITE_DWORD_BE_U(&out_ptr[7], this->tracks[1].start_lba);
}
out_ptr += 11;
// descriptor #4 -> data track
out_ptr[0] = session_num;
out_ptr[1] = this->tracks[0].adr_ctrl;
out_ptr[3] = 1; // point -> data track
if (is_msf) {
AddrMsf msf = lba_to_msf(this->tracks[0].start_lba + 150);
out_ptr[ 7] = 0; // reserved
out_ptr[ 8] = msf.min;
out_ptr[ 9] = msf.sec;
out_ptr[10] = msf.frm;
}
return 48;
default:
LOG_F(ERROR, "CDROM: unsupported format in READ_TOC");
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
return 0;
}
}
+43 -12
View File
@@ -29,6 +29,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <functional>
/** CD/DVD drive read/write capabilities. */
enum CdDriveCapabilities : uint8_t {
CDCAP_CDR_READ = 0x01,
CDCAP_CDE_READ = 0x02,
CDCAP_CDR_WRITE = 0x01,
CDCAP_CDE_WRITE = 0x02,
};
/** Support for various disk formats and outputs. */
enum CdDriveFormatSupport : uint8_t {
CDFMT_AUDIO_PLAY = 1 << 0,
CDFMT_COMPOSITE = 1 << 1,
CDFMT_PORT_1 = 1 << 2,
CDFMT_PORT_2 = 1 << 3,
CDFMT_MODE2_FORM1 = 1 << 4,
CDFMT_MODE2_FORM2 = 1 << 5,
CDFMT_MULTI_SESSION = 1 << 6,
};
/** Loading mechanism types. */
enum MechanismType : uint8_t {
LDTYPE_CADDY = 0,
LDTYPE_TRAY = 1,
LDTYPE_POPUP = 2,
};
/* Original CD-ROM addressing mode expressed
in minutes, seconds and frames */
typedef struct {
@@ -53,29 +79,34 @@ public:
CdromDrive();
virtual ~CdromDrive() = default;
void set_error_callback(std::function<void(uint8_t, uint8_t)>&& err_cb) {
this->set_error = std::move(err_cb);
}
bool medium_present() { return this->is_ready; }
void insert_image(std::string filename);
virtual uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
virtual uint32_t mode_sense_ex(bool is_sense_6, uint8_t *cmd_ptr, uint8_t *data_ptr);
virtual uint32_t request_sense(uint8_t *data_ptr, uint8_t sense_key, uint8_t asc,
uint8_t ascq);
virtual uint32_t report_capacity(uint8_t *data_ptr);
virtual uint32_t read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr);
protected:
std::function<void(uint8_t, uint8_t)> set_error;
uint8_t hex_to_bcd(const uint8_t val);
AddrMsf lba_to_msf(const int lba);
bool detect_raw_image();
TrackDescriptor tracks[CDROM_MAX_TRACKS];
int num_tracks;
// drive capabilities
uint8_t read_cap = CdDriveCapabilities::CDCAP_CDE_READ |
CdDriveCapabilities::CDCAP_CDR_READ;
uint8_t write_cap = 0; // no write support
uint8_t fmt_support = 0;
uint8_t ext_support = 0;
uint8_t mech_type = MechanismType::LDTYPE_TRAY;
uint8_t sw_lock_sup = 1; // drive supports locking/unlocking via SW
uint8_t sw_eject_sup = 1; // drive supports ejecting via SW
uint8_t drive_locked = 0; // 1 - drive is currently locked
uint8_t prevent_jump = 0; // prevent jumper not present
uint8_t more_support = 0;
uint16_t max_rd_speed = 706; // defaults to 4x
uint16_t max_vol_levs = 2; // audio can be only turned on and off
uint16_t cur_rd_speed = 706; // defaults to 4x
uint8_t dgt_out_desc = 0; // digital output format description
};
#endif // CD_ROM_DRIVE_H
+36 -11
View File
@@ -41,6 +41,19 @@ enum {
ATI_PIX_FMT_ARGB8888 = 6,
};
/* Draw engine data-path values. */
enum {
ATI_DP_COLOR_SRC_BKGD_CLR = 0,
ATI_DP_COLOR_SRC_FRGD_CLR = 1,
ATI_DP_COLOR_SRC_HOST = 2,
ATI_DP_COLOR_SRC_BLIT = 3,
ATI_DP_MONO_SRC_ALWAYS_1 = 0,
ATI_DP_MIX_SRC = 7,
ATI_SRC_TRAJ_UNBOUNDED = 0,
ATI_SRC_TRAJ_PATTERN = 1,
ATI_SRC_TRAJ_ROTATED = 3,
};
/** Mach64 register offsets. */
enum {
ATI_CRTC_H_TOTAL_DISP = 0x000, // 0x0000
@@ -485,22 +498,30 @@ enum {
ATI_SRC_PITCH = 22, ATI_SRC_PITCH_size = 10,
ATI_SRC_X = 0x061, // 0x0184
ATI_SRC_X_pos = 0, ATI_SRC_X_size = 13,
ATI_SRC_X_pos = 0, ATI_SRC_X_size = 14,
ATI_SRC_Y = 0x062, // 0x0188
ATI_SRC_Y_pos = 0, ATI_SRC_Y_size = 15,
ATI_SRC_Y_X = 0x063, // 0x018C
ATI_SRC_WIDTH1 = 0x064, // 0x0190
ATI_SRC_WIDTH1_pos = 0, ATI_SRC_WIDTH1_size = 14,
ATI_SRC_HEIGHT1 = 0x065, // 0x0194
ATI_SRC_HEIGHT1_pos = 0, ATI_SRC_HEIGHT1_size = 15,
ATI_SRC_HEIGHT1_WIDTH1 = 0x066, // 0x0198
ATI_SRC_X_START = 0x067, // 0x019C
ATI_SRC_X_START_pos = 0, ATI_SRC_X_START_size = 14,
ATI_SRC_Y_START = 0x068, // 0x01A0
ATI_SRC_Y_START_pos = 0, ATI_SRC_Y_START_size = 15,
ATI_SRC_Y_X_START = 0x069, // 0x01A4
ATI_SRC_WIDTH2 = 0x06A, // 0x01A8
ATI_SRC_WIDTH2_pos = 0, ATI_SRC_WIDTH2_size = 14,
ATI_SRC_HEIGHT2 = 0x06B, // 0x01AC
ATI_SRC_HEIGHT2_pos = 0, ATI_SRC_HEIGHT2_size = 15,
ATI_SRC_HEIGHT2_WIDTH2 = 0x06C, // 0x01B0
ATI_SRC_CNTL = 0x06D, // 0x01B4
ATI_SRC_COLOR_REG_WRITE_EN = 13,
ATI_SRC_BLOCK_WRITE_EN = 14,
ATI_SCALE_OFF = 0x070, // 0x01C0
ATI_SCALE_WIDTH = 0x077, // 0x01DC
ATI_SCALE_HEIGHT = 0x078, // 0x01E0
@@ -509,6 +530,8 @@ enum {
ATI_SCALE_Y_INC = 0x07D, // 0x01F4
ATI_SCALE_VACC = 0x07E, // 0x01F8
ATI_SCALE_3D_CNTL = 0x07F, // 0x01FC
ATI_HOST_DATA0 = 0x080, // 0x0200
ATI_HOST_DATA15 = 0x08F, // 0x023C
ATI_HOST_CNTL = 0x090, // 0x0240
ATI_BM_HOSTDATA = 0x091, // 0x0244
ATI_BM_ADDR = 0x092, // 0x0248
@@ -520,10 +543,10 @@ enum {
ATI_PAT_CNTL = 0x0A2, // 0x0288
ATI_SC_LEFT = 0x0A8, // 0x02A0
ATI_SC_LEFT_pos = 0, ATI_SC_LEFT_size = 13,
ATI_SC_LEFT_pos = 0, ATI_SC_LEFT_size = 14,
ATI_SC_RIGHT = 0x0A9, // 0x02A4
ATI_SC_RIGHT_pos = 0, ATI_SC_RIGHT_size = 13,
ATI_SC_RIGHT_pos = 0, ATI_SC_RIGHT_size = 14,
ATI_SC_LEFT_RIGHT = 0x0AA, // 0x02A8
@@ -599,14 +622,16 @@ enum {
ATI_SRC_PATT_EN = 16, // VT/GT
ATI_SRC_PATT_ROT_EN = 17, // VT/GT
ATI_SRC_LINEAR_EN = 18, // VT/GT
ATI_SRC_LINE_X_DIR = 19, // VT/GT
ATI_SRC_TRACK_DST = 20, // VT/GT
ATI_PAT_MONO_EN = 23, // GT
ATI_PAT_CLR_4x2_EN = 24, // VT/GT
ATI_PAT_CLR_8x1_EN = 25, // VT/GT
ATI_HOST_BYTE_ALIGN = 26, // VT/GT
ATI_HOST_BIG_ENDIAN_EN = 28, // VT/GT
ATI_SRC_BYTE_ALIGN = 29, // VT/GT
ATI_SRC_BYTE_ALIGN = 19, // VT/GT
ATI_SRC_LINE_X_DIR = 20, // VT/GT
ATI_SRC_8x8x8_BRUSH = 21, // GT
ATI_FAST_FILL_EN = 22, // GT
ATI_SRC_TRACK_DST = 23, // VT/GT
ATI_PAT_MONO_EN = 24, // GT
ATI_PAT_CLR_4x2_EN = 25, // VT/GT
ATI_PAT_CLR_8x1_EN = 26, // VT/GT
ATI_HOST_BYTE_ALIGN = 28, // VT/GT
ATI_HOST_BIG_ENDIAN_EN = 29, // VT/GT
ATI_GUI_STAT = 0x0CE, // 0x0338
ATI_GUI_ACTIVE = 0,
+20 -17
View File
@@ -525,6 +525,7 @@ void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
WRITE_VALUE_AND_LOG(ATIINTERRUPT);
this->update_interrupt();
return;
}
case ATI_CRTC_GEN_CNTL:
@@ -904,7 +905,7 @@ void AtiMach64Gx::get_cursor_position(int& x, int& y) {
int AtiMach64Gx::device_postinit()
{
this->vbl_cb = [this](uint8_t irq_line_state) {
insert_bits<uint32_t>(this->regs[ATI_CRTC_INT_CNTL], irq_line_state, ATI_CRTC_VBLANK, irq_line_state);
insert_bits<uint32_t>(this->regs[ATI_CRTC_INT_CNTL], irq_line_state, ATI_CRTC_VBLANK, 1);
if (irq_line_state) {
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT);
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT);
@@ -914,26 +915,28 @@ int AtiMach64Gx::device_postinit()
#endif
}
bool do_interrupt =
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT_EN) ||
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT_EN) ||
#if 1
#else
bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_VSYNC_INT_EN) ||
#endif
0;
LOG_F(ATIINTERRUPT, "%s: irq_line_state:%d do_interrupt:%d CRTC_INT_CNTL:%08x",
this->name.c_str(), irq_line_state, do_interrupt,
this->regs[ATI_CRTC_INT_CNTL]);
if (do_interrupt) {
this->pci_interrupt(irq_line_state);
}
this->update_interrupt();
};
return 0;
}
void AtiMach64Gx::update_interrupt()
{
uint32_t int_cntl = this->regs[ATI_CRTC_INT_CNTL];
bool new_pci_irq_line_state =
(bit_set(int_cntl, ATI_CRTC_VBLANK_INT_EN) &&
bit_set(int_cntl, ATI_CRTC_VBLANK_INT)) ||
(bit_set(int_cntl, ATI_CRTC_VLINE_INT_EN) &&
bit_set(int_cntl, ATI_CRTC_VLINE_INT));
if (new_pci_irq_line_state != this->pci_irq_line_state) {
this->pci_irq_line_state = new_pci_irq_line_state;
LOG_F(ATIINTERRUPT, "%s: pci_irq_line_state:%d CRTC_INT_CNTL:%08x",
this->name.c_str(), this->pci_irq_line_state, int_cntl);
this->pci_interrupt(this->pci_irq_line_state);
}
}
// ========================== IBM RGB514 related code ==========================
const char* AtiMach64Gx::rgb514_get_reg_name(uint32_t reg_addr)
{
+2
View File
@@ -76,8 +76,10 @@ protected:
private:
void change_one_bar(uint32_t &aperture, uint32_t aperture_size, uint32_t aperture_new, int bar_num);
void update_interrupt();
uint32_t regs[256] = {}; // internal registers
bool pci_irq_line_state = false;
int vram_size;
+348 -54
View File
@@ -37,6 +37,28 @@ static const int mach64_post_div[8] = {
3, 5, 6, 12 // alternate post dividers
};
static int32_t mach64_extract_signed(uint32_t value, int pos, int width) {
value = extract_bits<uint32_t>(value, pos, width);
return static_cast<int32_t>(value << (32 - width)) >> (32 - width);
}
static bool mach64_clip_axis(int coord, int increment, uint32_t length,
int scissor_min, int scissor_max,
int& skip, uint32_t& clipped_length) {
int first = increment > 0 ? scissor_min - coord : coord - scissor_max;
int last = increment > 0 ? scissor_max - coord : coord - scissor_min;
first = std::max(first, 0);
last = std::min(last, int(length) - 1);
if (first > last) {
return false;
}
skip = first;
clipped_length = last - first + 1;
return true;
}
/* Human readable Mach64 HW register names for easier debugging. */
static const std::map<uint16_t, std::string> mach64_reg_names = {
#define one_reg_name(x) {ATI_ ## x, #x}
@@ -266,6 +288,13 @@ uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) {
case ATI_GUI_STAT:
result = uint64_t(this->cmd_fifo_size << 16); // HACK: pretend empty FIFO
break;
case ATI_GUI_TRAJ_CNTL:
result = 0;
insert_bits<uint64_t>(result, this->regs[ATI_DST_CNTL], 0, 16);
insert_bits<uint64_t>(result, this->regs[ATI_SRC_CNTL], 16, 8);
insert_bits<uint64_t>(result, this->regs[ATI_PAT_CNTL], 24, 3);
insert_bits<uint64_t>(result, this->regs[ATI_HOST_CNTL], 28, 2);
break;
case ATI_DP_BKGD_CLR:
case ATI_DP_FRGD_CLR:
uint32_t pix_fmt = extract_bits<uint32_t>(
@@ -320,6 +349,11 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
uint32_t old_value = this->regs[reg_num];
uint32_t new_value;
if (reg_num >= ATI_HOST_DATA0 && reg_num <= ATI_HOST_DATA15) {
this->write_host_data(value, size);
return;
}
if (offset || size != 4) { // slow path
if ((offset + size) > 4) {
ABORT_F("%s: unaligned DWORD writes not implemented", this->name.c_str());
@@ -578,12 +612,43 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
break;
case ATI_SRC_HEIGHT1_WIDTH1:
new_value = value;
this->regs[ATI_SRC_HEIGHT1] = extract_bits<uint32_t>(value, 0, 16);
this->regs[ATI_SRC_WIDTH1] = extract_bits<uint32_t>(value, 16, 16);
this->regs[ATI_SRC_HEIGHT1] = extract_bits<uint32_t>(value, 0, ATI_SRC_HEIGHT1_size);
this->regs[ATI_SRC_WIDTH1] = extract_bits<uint32_t>(value, 16, ATI_SRC_WIDTH1_size);
break;
case ATI_SRC_Y_X_START:
new_value = value;
this->regs[ATI_SRC_Y_START] = extract_bits<uint32_t>(value, 0, ATI_SRC_Y_START_size);
this->regs[ATI_SRC_X_START] = extract_bits<uint32_t>(value, 16, ATI_SRC_X_START_size);
break;
case ATI_SRC_HEIGHT2_WIDTH2:
new_value = value;
this->regs[ATI_SRC_HEIGHT2] = extract_bits<uint32_t>(value, 0, ATI_SRC_HEIGHT2_size);
this->regs[ATI_SRC_WIDTH2] = extract_bits<uint32_t>(value, 16, ATI_SRC_WIDTH2_size);
break;
case ATI_SC_LEFT_RIGHT:
new_value = value;
this->regs[ATI_SC_LEFT] = extract_bits<uint32_t>(value, 0, ATI_SC_LEFT_size);
this->regs[ATI_SC_RIGHT] = extract_bits<uint32_t>(value, 16, ATI_SC_RIGHT_size);
break;
case ATI_SC_TOP_BOTTOM:
new_value = value;
this->regs[ATI_SC_TOP] = extract_bits<uint32_t>(value, 0, ATI_SC_TOP_size);
this->regs[ATI_SC_BOTTOM] = extract_bits<uint32_t>(value, 16, ATI_SC_BOTTOM_size);
break;
case ATI_GUI_TRAJ_CNTL:
new_value = value;
insert_bits<uint32_t>(this->regs[ATI_DST_CNTL], value, 0, 16);
insert_bits<uint32_t>(this->regs[ATI_SRC_CNTL], value >> 16, 0, 8);
insert_bits<uint32_t>(this->regs[ATI_PAT_CNTL], value >> 24, 0, 3);
insert_bits<uint32_t>(this->regs[ATI_HOST_CNTL], value >> 28, 0, 2);
break;
case ATI_DST_WIDTH:
case ATI_DST_HEIGHT_WIDTH:
case ATI_DST_X_WIDTH:
case ATI_DST_WIDTH_HEIGHT:
this->begin_drawing(reg_num, value);
new_value = this->regs[reg_num];
break;
case ATI_DST_BRES_LNTH:
this->begin_drawing(reg_num, value);
break;
@@ -593,6 +658,8 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
}
WRITE_VALUE_AND_LOG(9);
if (reg_num == ATI_CRTC_INT_CNTL)
this->update_interrupt();
}
bool ATIRage::io_access_allowed(uint32_t offset) {
@@ -968,7 +1035,7 @@ void ATIRage::get_cursor_position(int& x, int& y) {
int ATIRage::device_postinit()
{
this->vbl_cb = [this](uint8_t irq_line_state) {
insert_bits<uint32_t>(this->regs[ATI_CRTC_INT_CNTL], irq_line_state, ATI_CRTC_VBLANK, irq_line_state);
insert_bits<uint32_t>(this->regs[ATI_CRTC_INT_CNTL], irq_line_state, ATI_CRTC_VBLANK, 1);
if (irq_line_state) {
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT);
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT);
@@ -978,29 +1045,69 @@ int ATIRage::device_postinit()
#endif
}
bool do_interrupt =
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT_EN) ||
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT_EN) ||
#if 1
#else
bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_VSYNC_INT_EN) ||
#endif
0;
if (do_interrupt) {
this->pci_interrupt(irq_line_state);
}
this->update_interrupt();
};
return 0;
}
void ATIRage::update_interrupt()
{
uint32_t int_cntl = this->regs[ATI_CRTC_INT_CNTL];
bool new_pci_irq_line_state =
(bit_set(int_cntl, ATI_CRTC_VBLANK_INT_EN) &&
bit_set(int_cntl, ATI_CRTC_VBLANK_INT)) ||
(bit_set(int_cntl, ATI_CRTC_VLINE_INT_EN) &&
bit_set(int_cntl, ATI_CRTC_VLINE_INT));
if (new_pci_irq_line_state != this->pci_irq_line_state) {
this->pci_irq_line_state = new_pci_irq_line_state;
this->pci_interrupt(this->pci_irq_line_state);
}
}
// =================================== Draw Engine =====================================
void ATIRage::begin_drawing(uint32_t initiator, uint32_t value) {
switch(initiator) {
case ATI_DST_HEIGHT_WIDTH:
this->regs[ATI_DST_HEIGHT_WIDTH] = value;
this->draw_rect(extract_bits<uint32_t>(value, 16, 14), extract_bits<uint32_t>(value, 0, 15));
case ATI_DST_WIDTH: {
uint32_t width = extract_bits<uint32_t>(value, ATI_DST_WIDTH_pos, ATI_DST_WIDTH_size);
this->regs[ATI_DST_WIDTH] = width;
if (!bit_set(value, DST_WIDTH_FILL_DIS)) {
this->draw_rect(
width,
extract_bits<uint32_t>(
this->regs[ATI_DST_HEIGHT], ATI_DST_HEIGHT_pos, ATI_DST_HEIGHT_size));
}
break;
}
case ATI_DST_HEIGHT_WIDTH: {
uint32_t width = extract_bits<uint32_t>(value, 16, ATI_DST_WIDTH_size);
uint32_t height = extract_bits<uint32_t>(value, 0, ATI_DST_HEIGHT_size);
this->regs[ATI_DST_HEIGHT_WIDTH] = value;
this->regs[ATI_DST_WIDTH] = width;
this->regs[ATI_DST_HEIGHT] = height;
this->draw_rect(width, height);
break;
}
case ATI_DST_X_WIDTH: {
uint32_t width = extract_bits<uint32_t>(value, 16, ATI_DST_WIDTH_size);
this->regs[ATI_DST_X_WIDTH] = value;
this->regs[ATI_DST_X] = extract_bits<uint32_t>(value, 0, ATI_DST_X_size);
this->regs[ATI_DST_WIDTH] = width;
this->draw_rect(
width,
extract_bits<uint32_t>(
this->regs[ATI_DST_HEIGHT], ATI_DST_HEIGHT_pos, ATI_DST_HEIGHT_size));
break;
}
case ATI_DST_WIDTH_HEIGHT: {
uint32_t width = extract_bits<uint32_t>(value, 0, ATI_DST_WIDTH_size);
uint32_t height = extract_bits<uint32_t>(value, 16, ATI_DST_HEIGHT_size);
this->regs[ATI_DST_WIDTH_HEIGHT] = value;
this->regs[ATI_DST_WIDTH] = width;
this->regs[ATI_DST_HEIGHT] = height;
this->draw_rect(width, height);
break;
}
default:
LOG_F(WARNING, "%s: unimplemented engine operation, initiator=0x%X", this->name.c_str(),
initiator);
@@ -1008,14 +1115,34 @@ void ATIRage::begin_drawing(uint32_t initiator, uint32_t value) {
}
void ATIRage::draw_rect(uint32_t width, uint32_t height) {
uint8_t frgd_src = extract_bits<uint32_t>(this->regs[ATI_DP_SRC], ATI_DP_FRGD_SRC, ATI_DP_FRGD_SRC_size);
uint8_t bkgd_src = extract_bits<uint32_t>(this->regs[ATI_DP_SRC], ATI_DP_BKGD_SRC, ATI_DP_BKGD_SRC_size);
uint8_t mono_src = extract_bits<uint32_t>(this->regs[ATI_DP_SRC], ATI_DP_MONO_SRC, ATI_DP_MONO_SRC_size);
uint8_t frgd_src = extract_bits<uint32_t>(
this->regs[ATI_DP_SRC], ATI_DP_FRGD_SRC, ATI_DP_FRGD_SRC_size);
uint8_t mono_src = extract_bits<uint32_t>(
this->regs[ATI_DP_SRC], ATI_DP_MONO_SRC, ATI_DP_MONO_SRC_size);
uint32_t src_cntl = this->regs[ATI_SRC_CNTL];
if (frgd_src == 1 && !mono_src) { // rectangle fill with foreground color
this->fill_rect(width, height);
} else if (frgd_src == 3 && !mono_src) { // rectangle copy from the blit source
this->host_data_active = false;
// Color register blits update SGRAM state rather than VRAM.
if (bit_set(src_cntl, ATI_SRC_COLOR_REG_WRITE_EN) &&
!bit_set(src_cntl, ATI_SRC_BLOCK_WRITE_EN)) {
this->finish_rect(width, height);
return;
}
if ((frgd_src == ATI_DP_COLOR_SRC_BKGD_CLR || frgd_src == ATI_DP_COLOR_SRC_FRGD_CLR) &&
mono_src == ATI_DP_MONO_SRC_ALWAYS_1) {
uint32_t color = frgd_src == ATI_DP_COLOR_SRC_BKGD_CLR ? this->regs[ATI_DP_BKGD_CLR]
: this->regs[ATI_DP_FRGD_CLR];
this->fill_rect(width, height, color);
this->finish_rect(width, height);
} else if (frgd_src == ATI_DP_COLOR_SRC_HOST &&
mono_src == ATI_DP_MONO_SRC_ALWAYS_1) {
this->start_host_rect(width, height);
} else if (frgd_src == ATI_DP_COLOR_SRC_BLIT &&
mono_src == ATI_DP_MONO_SRC_ALWAYS_1) {
this->blit_rect(width, height);
this->finish_rect(width, height);
} else {
LOG_F(WARNING, "%s: unimplemented rectangle draw op, DP_SRC=0x%08X, DP_MIX=0x%08X, "
"DP_PIX_WIDTH=0x%08X, SRC_CNTL=0x%08X", this->name.c_str(),
@@ -1024,14 +1151,29 @@ void ATIRage::draw_rect(uint32_t width, uint32_t height) {
}
}
void ATIRage::fill_rect(uint32_t dst_width, uint32_t dst_height) {
uint8_t frgd_mix = extract_bits<uint32_t>(this->regs[ATI_DP_MIX], ATI_DP_FRGD_MIX, ATI_DP_FRGD_MIX_size);
uint8_t bkgd_mix = extract_bits<uint32_t>(this->regs[ATI_DP_MIX], ATI_DP_BKGD_MIX, ATI_DP_BKGD_MIX_size);
void ATIRage::finish_rect(uint32_t width, uint32_t height) {
int dst_x = mach64_extract_signed(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = mach64_extract_signed(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
int x_delta = int(width);
int y_delta = int(height);
// check for non-trivial operations
if (frgd_mix != 7 || bkgd_mix != 3) {
LOG_F(WARNING, "%s: unimplemented rectangle fill op, DP_FRGD_MIX=0x%X, DP_BKGD_MIX=0x%X",
this->name.c_str(), frgd_mix, bkgd_mix);
if (bit_set(this->regs[ATI_DST_CNTL], ATI_DST_X_TILE)) {
dst_x += bit_set(this->regs[ATI_DST_CNTL], ATI_DST_X_DIR) ? x_delta : -x_delta;
insert_bits<uint32_t>(this->regs[ATI_DST_X], dst_x, ATI_DST_X_pos, ATI_DST_X_size);
}
if (bit_set(this->regs[ATI_DST_CNTL], ATI_DST_Y_TILE)) {
dst_y += bit_set(this->regs[ATI_DST_CNTL], ATI_DST_Y_DIR) ? y_delta : -y_delta;
insert_bits<uint32_t>(this->regs[ATI_DST_Y], dst_y, ATI_DST_Y_pos, ATI_DST_Y_size);
}
}
void ATIRage::fill_rect(uint32_t dst_width, uint32_t dst_height, uint32_t color) {
uint8_t frgd_mix = extract_bits<uint32_t>(this->regs[ATI_DP_MIX], ATI_DP_FRGD_MIX,
ATI_DP_FRGD_MIX_size);
if (frgd_mix != ATI_DP_MIX_SRC) {
LOG_F(WARNING, "%s: unimplemented rectangle fill op, DP_FRGD_MIX=0x%X",
this->name.c_str(), frgd_mix);
return;
}
@@ -1077,16 +1219,31 @@ void ATIRage::fill_rect(uint32_t dst_width, uint32_t dst_height) {
// grab trajectory params
int dst_offs = extract_bits<uint32_t>(this->regs[ATI_DST_OFF_PITCH], ATI_DST_OFFSET, ATI_DST_OFFSET_size);
int dst_pitch = extract_bits<uint32_t>(this->regs[ATI_DST_OFF_PITCH], ATI_DST_PITCH, ATI_DST_PITCH_size);
int dst_x = extract_bits<uint32_t>(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = extract_bits<uint32_t>(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
int dst_x = mach64_extract_signed(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = mach64_extract_signed(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
dst_offs *= 8;
dst_pitch *= 8 * bytes_per_pixel;
int x_inc = (this->regs[ATI_DST_CNTL] & 1) ? 1 : -1;
int y_inc = (this->regs[ATI_DST_CNTL] & 2) ? 1 : -1;
int x_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_X_DIR) ? 1 : -1;
int y_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_Y_DIR) ? 1 : -1;
uint32_t pix = this->regs[ATI_DP_FRGD_CLR] & this->regs[ATI_DP_WRITE_MSK];
int sc_left = mach64_extract_signed(this->regs[ATI_SC_LEFT], ATI_SC_LEFT_pos, ATI_SC_LEFT_size);
int sc_right = mach64_extract_signed(
this->regs[ATI_SC_RIGHT], ATI_SC_RIGHT_pos, ATI_SC_RIGHT_size);
int sc_top = mach64_extract_signed(this->regs[ATI_SC_TOP], ATI_SC_TOP_pos, ATI_SC_TOP_size);
int sc_bottom = mach64_extract_signed(
this->regs[ATI_SC_BOTTOM], ATI_SC_BOTTOM_pos, ATI_SC_BOTTOM_size);
int x_skip, y_skip;
if (!mach64_clip_axis(dst_x, x_inc, dst_width, sc_left, sc_right, x_skip, dst_width) ||
!mach64_clip_axis(dst_y, y_inc, dst_height, sc_top, sc_bottom, y_skip, dst_height)) {
return;
}
dst_x += x_skip * x_inc;
dst_y += y_skip * y_inc;
uint32_t pix = color & this->regs[ATI_DP_WRITE_MSK];
switch (dst_pix_fmt) {
case ATI_PIX_FMT_8BPP:
@@ -1140,6 +1297,74 @@ void ATIRage::fill_rect(uint32_t dst_width, uint32_t dst_height) {
this->draw_fb = true;
}
void ATIRage::start_host_rect(uint32_t dst_width, uint32_t dst_height) {
uint8_t frgd_mix = extract_bits<uint32_t>(this->regs[ATI_DP_MIX], ATI_DP_FRGD_MIX,
ATI_DP_FRGD_MIX_size);
uint8_t host_pix_fmt = extract_bits<uint32_t>(this->regs[ATI_DP_PIX_WIDTH], ATI_DP_HOST_PIX_WIDTH,
ATI_DP_HOST_PIX_WIDTH_size);
uint8_t dst_pix_fmt = extract_bits<uint32_t>(this->regs[ATI_DP_PIX_WIDTH], ATI_DP_DST_PIX_WIDTH,
ATI_DP_DST_PIX_WIDTH_size);
if (frgd_mix != ATI_DP_MIX_SRC || host_pix_fmt != ATI_PIX_FMT_8BPP ||
dst_pix_fmt != ATI_PIX_FMT_8BPP || this->regs[ATI_CLR_CMP_CNTL]) {
LOG_F(WARNING, "%s: unsupported color host rectangle, DP_MIX=0x%08X, "
"DP_PIX_WIDTH=0x%08X, CLR_CMP_CNTL=0x%08X", this->name.c_str(),
this->regs[ATI_DP_MIX], this->regs[ATI_DP_PIX_WIDTH],
this->regs[ATI_CLR_CMP_CNTL]);
return;
}
this->host_dst_width = dst_width;
this->host_dst_height = dst_height;
this->host_dst_col = 0;
this->host_dst_row = 0;
this->host_data_active = true;
}
void ATIRage::write_host_data(uint32_t value, uint32_t size) {
if (!this->host_data_active) {
return;
}
int dst_offs = extract_bits<uint32_t>(
this->regs[ATI_DST_OFF_PITCH], ATI_DST_OFFSET, ATI_DST_OFFSET_size) *
8;
int dst_pitch =
extract_bits<uint32_t>(this->regs[ATI_DST_OFF_PITCH], ATI_DST_PITCH, ATI_DST_PITCH_size) * 8;
int dst_x = mach64_extract_signed(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = mach64_extract_signed(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
int sc_left = mach64_extract_signed(this->regs[ATI_SC_LEFT], ATI_SC_LEFT_pos, ATI_SC_LEFT_size);
int sc_right = mach64_extract_signed(
this->regs[ATI_SC_RIGHT], ATI_SC_RIGHT_pos, ATI_SC_RIGHT_size);
int sc_top = mach64_extract_signed(this->regs[ATI_SC_TOP], ATI_SC_TOP_pos, ATI_SC_TOP_size);
int sc_bottom = mach64_extract_signed(
this->regs[ATI_SC_BOTTOM], ATI_SC_BOTTOM_pos, ATI_SC_BOTTOM_size);
int x_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_X_DIR) ? 1 : -1;
int y_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_Y_DIR) ? 1 : -1;
uint8_t write_mask = this->regs[ATI_DP_WRITE_MSK];
for (uint32_t byte = 0; byte < size && this->host_data_active; byte++) {
int shift = x_inc > 0 ? int(byte) * 8 : int(size - byte - 1) * 8;
uint8_t pixel = value >> shift;
int x = dst_x + int(this->host_dst_col) * x_inc;
int y = dst_y + int(this->host_dst_row) * y_inc;
if (x >= sc_left && x <= sc_right && y >= sc_top && y <= sc_bottom) {
uint8_t* dst = &this->vram_ptr[dst_offs + y * dst_pitch + x];
*dst = (*dst & ~write_mask) | (pixel & write_mask);
this->draw_fb = true;
}
if (++this->host_dst_col >= this->host_dst_width) {
this->host_dst_col = 0;
if (++this->host_dst_row >= this->host_dst_height) {
this->host_data_active = false;
this->finish_rect(this->host_dst_width, this->host_dst_height);
}
}
}
}
void ATIRage::blit_rect(uint32_t dst_width, uint32_t dst_height) {
uint8_t frgd_mix = extract_bits<uint32_t>(this->regs[ATI_DP_MIX], ATI_DP_FRGD_MIX,
ATI_DP_FRGD_MIX_size);
@@ -1168,7 +1393,11 @@ void ATIRage::blit_rect(uint32_t dst_width, uint32_t dst_height) {
uint32_t pixel_mask = bytes_per_pixel == 4 ? 0xFFFFFFFFU :
((1U << (bytes_per_pixel * 8)) - 1);
if (frgd_mix != 7 || this->regs[ATI_SRC_CNTL] || this->regs[ATI_CLR_CMP_CNTL] ||
uint32_t src_cntl = this->regs[ATI_SRC_CNTL];
bool supported_src_trajectory = src_cntl == ATI_SRC_TRAJ_UNBOUNDED ||
src_cntl == ATI_SRC_TRAJ_PATTERN || src_cntl == ATI_SRC_TRAJ_ROTATED;
if (frgd_mix != ATI_DP_MIX_SRC || !supported_src_trajectory || this->regs[ATI_CLR_CMP_CNTL] ||
src_pix_fmt != dst_pix_fmt || !bytes_per_pixel ||
(this->regs[ATI_DP_WRITE_MSK] & pixel_mask) != pixel_mask) {
LOG_F(WARNING, "%s: unsupported rectangle blit, DP_SRC=0x%08X, DP_MIX=0x%08X, "
@@ -1179,27 +1408,92 @@ void ATIRage::blit_rect(uint32_t dst_width, uint32_t dst_height) {
return;
}
int src_offs = extract_bits<uint32_t>(this->regs[ATI_SRC_OFF_PITCH], ATI_SRC_OFFSET,
ATI_SRC_OFFSET_size) * 8;
int src_pitch = extract_bits<uint32_t>(this->regs[ATI_SRC_OFF_PITCH], ATI_SRC_PITCH,
ATI_SRC_PITCH_size) * 8 * bytes_per_pixel;
int src_x = extract_bits<uint32_t>(this->regs[ATI_SRC_X], ATI_SRC_X_pos, ATI_SRC_X_size);
int src_y = extract_bits<uint32_t>(this->regs[ATI_SRC_Y], ATI_SRC_Y_pos, ATI_SRC_Y_size);
int src_offs = extract_bits<uint32_t>(
this->regs[ATI_SRC_OFF_PITCH], ATI_SRC_OFFSET, ATI_SRC_OFFSET_size) *
8;
int src_pitch = extract_bits<uint32_t>(
this->regs[ATI_SRC_OFF_PITCH], ATI_SRC_PITCH, ATI_SRC_PITCH_size) *
8 * bytes_per_pixel;
int src_x = mach64_extract_signed(this->regs[ATI_SRC_X], ATI_SRC_X_pos, ATI_SRC_X_size);
int src_y = mach64_extract_signed(this->regs[ATI_SRC_Y], ATI_SRC_Y_pos, ATI_SRC_Y_size);
int src_x_start = mach64_extract_signed(
this->regs[ATI_SRC_X_START], ATI_SRC_X_START_pos, ATI_SRC_X_START_size);
int src_y_start = mach64_extract_signed(
this->regs[ATI_SRC_Y_START], ATI_SRC_Y_START_pos, ATI_SRC_Y_START_size);
uint32_t src_width1 = extract_bits<uint32_t>(
this->regs[ATI_SRC_WIDTH1], ATI_SRC_WIDTH1_pos, ATI_SRC_WIDTH1_size);
uint32_t src_height1 = extract_bits<uint32_t>(
this->regs[ATI_SRC_HEIGHT1], ATI_SRC_HEIGHT1_pos, ATI_SRC_HEIGHT1_size);
uint32_t src_width2 = extract_bits<uint32_t>(
this->regs[ATI_SRC_WIDTH2], ATI_SRC_WIDTH2_pos, ATI_SRC_WIDTH2_size);
uint32_t src_height2 = extract_bits<uint32_t>(
this->regs[ATI_SRC_HEIGHT2], ATI_SRC_HEIGHT2_pos, ATI_SRC_HEIGHT2_size);
int dst_offs = extract_bits<uint32_t>(this->regs[ATI_DST_OFF_PITCH], ATI_DST_OFFSET,
ATI_DST_OFFSET_size) * 8;
int dst_pitch = extract_bits<uint32_t>(this->regs[ATI_DST_OFF_PITCH], ATI_DST_PITCH,
ATI_DST_PITCH_size) * 8 * bytes_per_pixel;
int dst_x = extract_bits<uint32_t>(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = extract_bits<uint32_t>(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
if ((src_cntl == ATI_SRC_TRAJ_PATTERN && (!src_width1 || !src_height1)) ||
(src_cntl == ATI_SRC_TRAJ_ROTATED &&
(!src_width1 || !src_height1 || !src_width2 || !src_height2))) {
LOG_F(WARNING, "%s: invalid rectangle blit source trajectory, SRC_CNTL=0x%08X, "
"SRC_HEIGHT1_WIDTH1=0x%08X, SRC_HEIGHT2_WIDTH2=0x%08X", this->name.c_str(),
src_cntl, this->regs[ATI_SRC_HEIGHT1_WIDTH1],
this->regs[ATI_SRC_HEIGHT2_WIDTH2]);
return;
}
int x_inc = (this->regs[ATI_DST_CNTL] & 1) ? 1 : -1;
int y_inc = (this->regs[ATI_DST_CNTL] & 2) ? 1 : -1;
int dst_offs = extract_bits<uint32_t>(
this->regs[ATI_DST_OFF_PITCH], ATI_DST_OFFSET, ATI_DST_OFFSET_size) *
8;
int dst_pitch = extract_bits<uint32_t>(
this->regs[ATI_DST_OFF_PITCH], ATI_DST_PITCH, ATI_DST_PITCH_size) *
8 * bytes_per_pixel;
int dst_x = mach64_extract_signed(this->regs[ATI_DST_X], ATI_DST_X_pos, ATI_DST_X_size);
int dst_y = mach64_extract_signed(this->regs[ATI_DST_Y], ATI_DST_Y_pos, ATI_DST_Y_size);
int x_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_X_DIR) ? 1 : -1;
int y_inc = bit_set(this->regs[ATI_DST_CNTL], ATI_DST_Y_DIR) ? 1 : -1;
int sc_left = mach64_extract_signed(this->regs[ATI_SC_LEFT], ATI_SC_LEFT_pos, ATI_SC_LEFT_size);
int sc_right = mach64_extract_signed(
this->regs[ATI_SC_RIGHT], ATI_SC_RIGHT_pos, ATI_SC_RIGHT_size);
int sc_top = mach64_extract_signed(this->regs[ATI_SC_TOP], ATI_SC_TOP_pos, ATI_SC_TOP_size);
int sc_bottom = mach64_extract_signed(
this->regs[ATI_SC_BOTTOM], ATI_SC_BOTTOM_pos, ATI_SC_BOTTOM_size);
int x_skip, y_skip;
if (!mach64_clip_axis(dst_x, x_inc, dst_width, sc_left, sc_right, x_skip, dst_width) ||
!mach64_clip_axis(dst_y, y_inc, dst_height, sc_top, sc_bottom, y_skip, dst_height)) {
return;
}
dst_x += x_skip * x_inc;
dst_y += y_skip * y_inc;
for (uint32_t y = 0; y < dst_height; y++) {
uint8_t* src_row = &this->vram_ptr[src_offs + (src_y + int(y) * y_inc) * src_pitch];
uint8_t* dst_row = &this->vram_ptr[dst_offs + (dst_y + int(y) * y_inc) * dst_pitch];
for (int sx = src_x, dx = dst_x, width = dst_width; width-- > 0; sx += x_inc, dx += x_inc) {
uint32_t src_row_index = y_skip + y;
int sy;
if (src_cntl == ATI_SRC_TRAJ_PATTERN) {
sy = src_y + int(src_row_index % src_height1) * y_inc;
} else if (src_cntl == ATI_SRC_TRAJ_ROTATED && src_row_index >= src_height1) {
sy = src_y_start + int((src_row_index - src_height1) % src_height2) * y_inc;
} else {
sy = src_y + int(src_row_index) * y_inc;
}
uint8_t* src_row = &this->vram_ptr[src_offs + sy * src_pitch];
int dy = dst_y + int(y) * y_inc;
uint8_t* dst_row = &this->vram_ptr[dst_offs + dy * dst_pitch];
for (uint32_t x = 0; x < dst_width; x++) {
uint32_t src_col_index = x_skip + x;
int sx;
if (src_cntl == ATI_SRC_TRAJ_PATTERN) {
sx = src_x + int(src_col_index % src_width1) * x_inc;
} else if (src_cntl == ATI_SRC_TRAJ_ROTATED && src_row_index > 0) {
sx = src_x_start + int(src_col_index % src_width2) * x_inc;
} else if (src_cntl == ATI_SRC_TRAJ_ROTATED && src_col_index >= src_width1) {
sx = src_x_start + int((src_col_index - src_width1) % src_width2) * x_inc;
} else {
sx = src_x + int(src_col_index) * x_inc;
}
int dx = dst_x + int(x) * x_inc;
uint8_t* src_pixel = &src_row[sx * bytes_per_pixel];
uint8_t* dst_pixel = &dst_row[dx * bytes_per_pixel];
for (int byte = 0; byte < bytes_per_pixel; byte++) {
+12 -1
View File
@@ -89,16 +89,27 @@ protected:
private:
void change_one_bar(uint32_t &aperture, uint32_t aperture_size,
uint32_t aperture_new, int bar_num);
void update_interrupt();
void begin_drawing(uint32_t initiator, uint32_t value);
void draw_rect(uint32_t width, uint32_t height);
void fill_rect(uint32_t dst_width, uint32_t dst_height);
void finish_rect(uint32_t width, uint32_t height);
void fill_rect(uint32_t dst_width, uint32_t dst_height, uint32_t color);
void blit_rect(uint32_t dst_width, uint32_t dst_height);
void start_host_rect(uint32_t dst_width, uint32_t dst_height);
void write_host_data(uint32_t value, uint32_t size);
uint32_t regs[512] = {}; // internal registers
uint8_t plls[64] = {}; // internal PLL registers
uint8_t cmd_fifo_size = 0;
bool pci_irq_line_state = false;
bool host_data_active = false;
uint32_t host_dst_width = 0;
uint32_t host_dst_height = 0;
uint32_t host_dst_col = 0;
uint32_t host_dst_row = 0;
// Video RAM variables
std::unique_ptr<uint8_t[]> vram_ptr;
+62 -1
View File
@@ -26,6 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cmath>
#include <string>
bool g_auto_grab_mouse = false;
static const char * get_full_screen_mode_string(int scale_mode) {
#define onemode(x) case Display::x: return #x ;
switch(scale_mode) {
@@ -49,6 +51,10 @@ public:
SDL_Texture* disp_texture = 0;
SDL_Texture* cursor_texture = 0;
SDL_Rect cursor_rect; // destination rectangle for cursor drawing
bool show_host_cursor = true; // desired SDL host pointer visibility
bool guest_cursor_drawn = false; // guest is drawing its own cursor
bool was_grabbed = false; // last reported grab state
bool manual_grab = false; // grab toggled on with Ctrl+G
int display_w;
int display_h;
double drawable_w;
@@ -312,6 +318,16 @@ void Display::handle_events(const WindowEvent& wnd_event) {
if (wnd_event.window_id == impl->disp_wnd_id) {
SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
SDL_SetWindowKeyboardGrab(impl->display_wnd, SDL_TRUE);
if (g_auto_grab_mouse) {
// When the window (re)gains focus (e.g. the user clicks it), SDL
// may have dropped the relative mouse grab on focus loss. Re-grab
// it so the guest cursor keeps working; this is the reliable
// re-grab trigger instead of polling every frame.
if (impl->guest_cursor_drawn && !impl->manual_grab && !SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_TRUE);
this->update_window_title();
}
}
}
break;
@@ -394,9 +410,11 @@ void Display::toggle_mouse_grab()
{
if (SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_FALSE);
impl->manual_grab = false;
} else {
this->update_mouse_grab(true);
SDL_SetRelativeMouseMode(SDL_TRUE);
impl->manual_grab = true;
}
}
@@ -434,7 +452,9 @@ void Display::update_window_title()
std::to_string(impl->display_w) + "x" + std::to_string(impl->display_h)
+ " " + std::to_string(int(std::round(impl->renderer_scale_x * 100))) + "%";
if (is_grabbed)
new_window_title += " (🖱 Grabbed)";
new_window_title += " (Grabbed, Ctrl+G to release)";
else if (!g_auto_grab_mouse || impl->guest_cursor_drawn)
new_window_title += " (Press Ctrl+G to grab)";
if (new_window_title != old_window_title)
SDL_SetWindowTitle(impl->display_wnd, new_window_title.c_str());
@@ -466,6 +486,47 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
SDL_RenderClear(impl->renderer);
SDL_RenderCopy(impl->renderer, impl->disp_texture, NULL, &impl->dest_rect);
if (g_auto_grab_mouse) {
bool is_grabbed = SDL_GetRelativeMouseMode();
// The guest draws its own cursor into the framebuffer (hardware cursor).
// When such a cursor session starts, auto-grab the host mouse so the
// pointer cannot leave the window and the guest cursor can reach every
// screen area. When the session ends, release an automatic grab again so
// the user can move the pointer to other windows. A manual grab (Ctrl+G)
// is sticky and is neither grabbed nor released automatically.
if (draw_hw_cursor) {
if (!impl->guest_cursor_drawn && !impl->manual_grab && !is_grabbed) {
this->update_mouse_grab(true);
SDL_SetRelativeMouseMode(SDL_TRUE);
is_grabbed = true;
}
} else {
if (!impl->manual_grab && is_grabbed) {
SDL_SetRelativeMouseMode(SDL_FALSE);
is_grabbed = false;
}
}
// The guest draws its own cursor into the framebuffer. Even without a
// grab, keep the SDL host pointer hidden so the user never sees a second
// cursor that does not track the guest one. When the guest cursor is not
// drawn (e.g. firmware), show the host pointer so the user can aim and
// click.
bool want_host_cursor = !draw_hw_cursor;
if (impl->show_host_cursor != want_host_cursor) {
impl->show_host_cursor = want_host_cursor;
SDL_ShowCursor(want_host_cursor ? SDL_ENABLE : SDL_DISABLE);
}
// Let the window title reflect the current grab/cursor state.
if (is_grabbed != impl->was_grabbed || draw_hw_cursor != impl->guest_cursor_drawn) {
impl->was_grabbed = is_grabbed;
impl->guest_cursor_drawn = draw_hw_cursor;
this->update_window_title();
}
}
// draw HW cursor if enabled
if (draw_hw_cursor) {
impl->cursor_rect.x = cursor_x * impl->renderer_scale_x + impl->dest_rect.x;
+9 -6
View File
@@ -99,16 +99,19 @@ int MachineAlchemy::initialize(const std::string &id) {
psx_obj->map_phys_ram();
// configure CPU clocks
uint64_t bus_freq = 40000000ULL;
uint64_t bus_freq = 40'000'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = 180'000'000ULL;
psx_obj->set_bus_speed(PSX_BUS_SPEED_40);
// init virtual CPU and request MPC603ev
ppc_cpu_init(psx_obj, PPC_VER::MPC603E, false, timebase_freq);
// CPU frequency is hardcoded to 225 MHz for now
//ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
// init virtual CPU and request MPC603e
ppc_cpu_init(psx_obj, {
.version = PPC_VER::MPC603E,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
+8 -5
View File
@@ -88,14 +88,17 @@ int MachineBondi::initialize(const std::string &id) {
setup_ram_slot("RAM_DIMM_2", 0x51, bank_2_size);
// configure CPU clocks
uint64_t bus_freq = 66820000ULL;
uint64_t bus_freq = 66'820'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = bus_freq * 7 / 2; // 233.87 MHz (CPU PLL ratio of 3.5)
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
ppc_cpu_init(grackle_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
+17 -6
View File
@@ -96,19 +96,30 @@ int MachineCatalyst::initialize(const std::string &id) {
std::string cpu = GET_STR_PROP("cpu");
if (cpu == "601") {
uint64_t bus_freq = 37'500'000ULL;
uint64_t core_freq = 75'000'000ULL;
// init virtual CPU and request MPC601
ppc_cpu_init(platinum_obj, PPC_VER::MPC601, true, 7833600ULL);
ppc_cpu_init(platinum_obj, {
.version = PPC_VER::MPC601,
.timebase_freq_hz = 7'833'600ULL,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
}
else if (cpu == "750") {
// configure CPU clocks
uint64_t bus_freq = 50000000ULL;
uint64_t bus_freq = 50'000'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = bus_freq * 8; // 400 MHz (matches G3 upgrade cards; CPU PLL ratio to 8)
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(platinum_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
ppc_cpu_init(platinum_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
}
return 0;
+1
View File
@@ -95,6 +95,7 @@ static const map<string, string> PropHelp = {
{"serial_backend", "specifies the backend for the serial port"},
{"emmo", "enables/disables factory HW tests during startup"},
{"cpu", "specifies CPU"},
{"cpu_freq", "specifies CPU frequency in MHz"},
{"adb_devices", "specifies which ADB device(s) to attach"},
{"pds", "specify device for the processsor direct slot"},
};
+10 -19
View File
@@ -46,20 +46,6 @@ static std::vector<PciIrqMap> psx_irq_map = {
{"pci_F1", DEV_FUN(0x12,0), IntSrc::PCI_F},
};
// TODO: move it to /cpu/ppc
int get_cpu_pll_value(const uint64_t cpu_freq_hz) {
switch (cpu_freq_hz / 1000000) {
case 225:
return 7; // 4.5:1 ratio
case 250:
return 11; // 5:1 ratio
case 275:
return 9; // 5.5:1 ratio
default:
ABORT_F("Unsupported CPU frequency %llu Hz", cpu_freq_hz);
}
}
class MachineGazelle : public Machine {
public:
static std::unique_ptr<HWComponent> create5500() {
@@ -126,14 +112,17 @@ int MachineGazelle::initialize(const std::string &id) {
psx_obj->set_bus_speed(PSX_BUS_SPEED_50);
// configure CPU clocks
uint64_t bus_freq = 50000000ULL;
uint64_t bus_freq = 50'000'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = GET_INT_PROP("cpu_freq") * 1'000'000ULL; // 225, 250, or 275 MHz
// init virtual CPU and request MPC603ev
ppc_cpu_init(psx_obj, PPC_VER::MPC603EV, false, timebase_freq);
// CPU frequency is hardcoded to 225 MHz for now
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
ppc_cpu_init(psx_obj, {
.version = PPC_VER::MPC603EV,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
@@ -147,6 +136,8 @@ static const PropMap pm6500_settings = {
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64}))},
{"emmo",
new BinProperty(0)},
{"cpu_freq",
new IntProperty(225, std::vector<uint32_t>({225, 250, 275}))},
{"hdd_config",
new StrProperty("Ide0:0")},
{"pci_F1",
+8 -5
View File
@@ -188,14 +188,17 @@ int MachineGossamer::initialize(const std::string &id) {
i2c_bus->register_device(0x53, perch_id);
// configure CPU clocks
uint64_t bus_freq = 66820000ULL;
uint64_t bus_freq = 66'820'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = bus_freq * 7 / 2; // 233.87 MHz (CPU PLL ratio of 3.5)
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
ppc_cpu_init(grackle_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
+14 -1
View File
@@ -87,16 +87,24 @@ int MachinePdm::initialize(const std::string &id) {
LOG_F(INFO, "Building machine PDM...");
uint16_t machine_id;
uint64_t bus_freq;
uint64_t core_freq;
// get raw pointer to HMC object
HMC* hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
if (id == "pm6100") {
machine_id = 0x3010;
bus_freq = 30'000'000ULL;
core_freq = 60'000'000ULL;
} else if (id == "pm7100") {
machine_id = 0x3012;
bus_freq = 33'000'000ULL;
core_freq = 66'000'000ULL;
} else if (id == "pm8100") {
machine_id = 0x3013;
bus_freq = 40'000'000ULL;
core_freq = 80'000'000ULL;
} else {
LOG_F(ERROR, "Unknown machine ID: %s!", id.c_str());
return -1;
@@ -136,7 +144,12 @@ int MachinePdm::initialize(const std::string &id) {
setup_pds();
// Init virtual CPU and request MPC601
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, true, 7833600ULL);
ppc_cpu_init(hmc_obj, {
.version = PPC_VER::MPC601,
.timebase_freq_hz = 7'833'600ULL,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
+6 -1
View File
@@ -74,7 +74,12 @@ int MachinePippin::initialize(const std::string &id) {
aspen_obj->insert_ram_dimm(3, GET_INT_PROP("rambank4_size")); // RAM expansion slot
// init virtual CPU
ppc_cpu_init(aspen_obj, PPC_VER::MPC603, false, 16500000ULL);
ppc_cpu_init(aspen_obj, {
.version = PPC_VER::MPC603,
.timebase_freq_hz = 16'500'000ULL,
.bus_freq_hz = 33'000'000ULL,
.core_freq_hz = 66'000'000ULL,
});
return 0;
}
+26 -8
View File
@@ -136,21 +136,39 @@ int MachineTnt::initialize(const std::string &id) {
// init virtual CPU
std::string cpu = GET_STR_PROP("cpu");
if (cpu == "604e")
ppc_cpu_init(memctrl_obj, PPC_VER::MPC604E, false, 12500000ULL);
ppc_cpu_init(memctrl_obj, {
.version = PPC_VER::MPC604E,
.timebase_freq_hz = 12'500'000ULL,
.bus_freq_hz = 50'000'000ULL,
.core_freq_hz = 200'000'000ULL, // 200 MHz
});
else if (cpu == "604")
ppc_cpu_init(memctrl_obj, PPC_VER::MPC604, false, 12500000ULL);
ppc_cpu_init(memctrl_obj, {
.version = PPC_VER::MPC604,
.timebase_freq_hz = 12'500'000ULL,
.bus_freq_hz = 50'000'000ULL,
.core_freq_hz = 150'000'000ULL, // 150 MHz
});
else if (cpu == "601")
ppc_cpu_init(memctrl_obj, PPC_VER::MPC601, true, 7833600ULL);
ppc_cpu_init(memctrl_obj, {
.version = PPC_VER::MPC601,
.timebase_freq_hz = 7'833'600ULL,
.bus_freq_hz = 50'000'000ULL,
.core_freq_hz = 100'000'000ULL, // 100 MHz
});
else if (cpu == "750") {
// configure CPU clocks
uint64_t bus_freq = 50000000ULL;
uint64_t bus_freq = 50'000'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = bus_freq * 6; // 300 MHz (matches G3 upgrade cards; CPU PLL ratio of 6)
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(memctrl_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
ppc_cpu_init(memctrl_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
}
return 0;
+8 -5
View File
@@ -100,14 +100,17 @@ int MachineYosemite::initialize(const std::string &id) {
setup_ram_slot("RAM_DIMM_4", 0x53, GET_INT_PROP("rambank4_size"));
// configure CPU clocks
uint64_t bus_freq = 66820000ULL;
uint64_t bus_freq = 100'000'000ULL;
uint64_t timebase_freq = bus_freq / 4;
uint64_t core_freq = bus_freq * 7 / 2; // 350 MHz (CPU PLL ratio of 3.5)
// initialize virtual CPU and request MPC750 CPU aka G3
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, timebase_freq);
// set CPU PLL ratio to 3.5
ppc_state.spr[SPR::HID1] = 0xE << 28;
ppc_cpu_init(grackle_obj, {
.version = PPC_VER::MPC750,
.timebase_freq_hz = timebase_freq,
.bus_freq_hz = bus_freq,
.core_freq_hz = core_freq,
});
return 0;
}
+62 -31
View File
@@ -49,9 +49,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#endif
using namespace std;
extern bool g_auto_grab_mouse;
static void sigint_handler(int signum) {
power_on = false;
power_off_reason = po_signal_interrupt;
power_off(po_signal_interrupt);
}
static void sigabrt_handler(int signum) {
@@ -96,6 +97,7 @@ const WorkingDirectoryValidator WorkingDirectory;
void run_machine(
std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode
,const std::vector<std::string> &env_vars
,bool deterministic_interactive
,uint32_t profiling_interval_ms
);
@@ -104,11 +106,14 @@ int main(int argc, char** argv) {
uint32_t execution_mode = interpreter;
CLI::App app(appDescription);
app.allow_windows_style_options(); /* we want Windows-style options */
app.allow_extras();
bool realtime_enabled = false;
bool debugger_enabled = false;
app.set_help_all_flag("--help-all", "Print this help message, help for subcommands, and exit");
bool debugger_skip = true;
bool debugger_enter = false;
bool deterministic_interactive = false;
string deterministic_mode = "strict";
string keyboard_string = "Eng_USA";
const std::map<std::string, int> kbd_map{
@@ -119,45 +124,53 @@ int main(int argc, char** argv) {
string bootrom_path("bootrom.bin");
string working_directory_path(".");
auto execution_mode_group = app.add_option_group("execution mode")
auto emu = app.add_subcommand("", "Emulation");
auto execution_mode_group = emu->add_option_group("execution mode")
->require_option(-1);
execution_mode_group->add_flag("-r,--realtime", realtime_enabled,
"Run the emulator in real-time");
execution_mode_group->add_flag("-d,--debugger", debugger_enabled,
execution_mode_group->add_flag("-r,--run", debugger_skip,
"Run the emulator immediately (skip enterring the built-in debugger)");
execution_mode_group->add_flag("-d,--debugger", debugger_enter,
"Enter the built-in debugger");
app.add_option("-k,--keyboard", keyboard_string, "Specify keyboard ID");
app.add_option("-w,--workingdir", working_directory_path, "Specifies working directory")
->check(WorkingDirectory);
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
->check(CLI::ExistingFile);
app.add_flag("--deterministic", is_deterministic,
"Make execution deterministic");
emu->add_option("-k,--keyboard", keyboard_string, "Specify keyboard ID");
emu->add_option("-w,--workingdir", working_directory_path, "Specifies working directory")
->check(WorkingDirectory)->capture_default_str();
auto bootrom_opt = emu->add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
->check(CLI::ExistingFile)->capture_default_str();
auto deterministic_opt = emu->add_flag("--deterministic", is_deterministic,
"Use deterministic execution");
emu->add_option("--deterministic-mode", deterministic_mode,
"Select deterministic features (strict or interactive)")
->needs(deterministic_opt)
->check(CLI::IsMember({"strict", "interactive"}));
bool log_to_stderr = false;
loguru::Verbosity log_verbosity = loguru::Verbosity_INFO;
bool log_no_uptime = false;
app.add_flag("--log-to-stderr", log_to_stderr,
emu->add_flag("--log-to-stderr", log_to_stderr,
"Send internal logging to stderr (instead of dingusppc.log)");
app.add_option("--log-verbosity", log_verbosity,
emu->add_option("--log-verbosity", log_verbosity,
"Adjust logging verbosity (default is 0 a.k.a. INFO)")
->check(CLI::Number);
app.add_flag("--log-no-uptime", log_no_uptime,
emu->add_flag("--log-no-uptime", log_no_uptime,
"Disable the uptime preamble of logged messages");
std::vector<std::string> env_vars;
app.add_option("--setenv", env_vars, "Set Open Firmware variables at startup")
emu->add_option("--setenv", env_vars, "Set Open Firmware variables at startup")
->take_all();
uint32_t profiling_interval_ms = 0;
#ifdef CPU_PROFILING
app.add_option("--profiling-interval-ms", profiling_interval_ms,
emu->add_option("--profiling-interval-ms", profiling_interval_ms,
"Specifies periodic interval (in ms) at which to output CPU profiling information");
#endif
string machine_str;
CLI::Option* machine_opt = app.add_option("-m,--machine",
CLI::Option* machine_opt = emu->add_option("-m,--machine",
machine_str, "Specify machine ID");
emu->add_flag("--auto-grab-mouse", g_auto_grab_mouse,
"The guest cursor causes mouse to be grabbed");
auto list_cmd = app.add_subcommand("list",
"Display available machine configurations and exit");
@@ -168,6 +181,8 @@ int main(int argc, char** argv) {
CLI11_PARSE(app, argc, argv);
deterministic_interactive = deterministic_mode == "interactive";
if (*list_cmd) {
if (sub_arg == "machines") {
MachineFactory::list_machines();
@@ -179,7 +194,16 @@ int main(int argc, char** argv) {
return 0;
}
if (debugger_enabled) {
if (bootrom_opt->count() == 0) {
// it was not specified on the command line, so validate the default file name.
std::string msg = bootrom_opt->get_validator()->operator()(bootrom_path);
if (!msg.empty()) {
CLI::ParseError e(msg, CLI::ExitCodes::ValidationError);
return app.exit(e);
}
}
if (debugger_enter || !debugger_skip) {
execution_mode = debugger;
}
@@ -249,7 +273,12 @@ int main(int argc, char** argv) {
cout << "BootROM path: " << bootrom_path << endl;
cout << "Execution mode: " << execution_mode << endl;
if (is_deterministic) {
cout << "Using deterministic execution mode, input will be ignored." << endl;
cout << "Using deterministic execution mode; disk, NVRAM, and PRAM changes will not be saved." << endl;
if (deterministic_interactive) {
cout << "Mouse and keyboard input enabled; execution will not be fully deterministic." << endl;
} else {
cout << "Mouse and keyboard input will be ignored." << endl;
}
}
if (!init()) {
@@ -265,7 +294,7 @@ int main(int argc, char** argv) {
// Make sure the reason for the failure is visible (it may have been
// sent to the logfile only).
cerr << message.preamble << message.indentation << message.prefix << message.message << endl;
power_off_reason = po_enter_debugger;
set_power_off_reason(po_enter_debugger);
DppcDebugger::get_instance()->enter_debugger();
// Ensure that NVRAM and other state is persisted before we terminate.
@@ -287,6 +316,7 @@ int main(int argc, char** argv) {
rom_size,
execution_mode,
env_vars,
deterministic_interactive,
profiling_interval_ms);
if (power_off_reason == po_restarting) {
LOG_F(INFO, "Restarting...");
@@ -317,6 +347,7 @@ void run_machine(std::string machine_str, char* rom_data,
size_t rom_size,
uint32_t execution_mode,
const std::vector<std::string> &env_vars,
bool deterministic_interactive,
uint32_t
#ifdef CPU_PROFILING
profiling_interval_ms
@@ -348,8 +379,8 @@ void run_machine(std::string machine_str, char* rom_data,
}
}
uint32_t deterministic_timer;
if (is_deterministic) {
uint32_t deterministic_timer = 0;
if (is_deterministic && !deterministic_interactive) {
EventManager::get_instance()->disable_input_handlers();
// Log the PC and instruction every second to make it easier to validate
// that execution is the same every time.
@@ -382,15 +413,15 @@ void run_machine(std::string machine_str, char* rom_data,
switch (execution_mode) {
case interpreter:
power_off_reason = po_starting_up;
set_power_off_reason(po_starting_up);
DppcDebugger::get_instance()->enter_debugger();
break;
case threaded_int:
power_off_reason = po_starting_up;
set_power_off_reason(po_starting_up);
DppcDebugger::get_instance()->enter_debugger();
break;
case debugger:
power_off_reason = po_enter_debugger;
set_power_off_reason(po_enter_debugger);
DppcDebugger::get_instance()->enter_debugger();
break;
default:
@@ -405,7 +436,7 @@ void run_machine(std::string machine_str, char* rom_data,
TimerManager::get_instance()->cancel_timer(profiling_timer);
}
#endif
if (is_deterministic) {
if (is_deterministic && !deterministic_interactive) {
TimerManager::get_instance()->cancel_timer(deterministic_timer);
}
TimerManager::get_instance()->cancel_all_timers();
+2 -2
View File
@@ -38,10 +38,10 @@ DingusPPC uses two windows when booted up; a command line window and a monitor w
DingusPPC is operated using the command line interface. As such, we will list the commands as required. These commands are separated by spaces.
```
-r, --realtime
-r, --run
```
Run the emulator in runtime (using the interpreter).
Run the emulator (using the interpreter).
```
-d, --debugger