mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
123
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f070249f2 | ||
|
|
13e02f7978 | ||
|
|
317a34a761 | ||
|
|
72a33a1b8a | ||
|
|
ab5699d7f9 | ||
|
|
387686aaee | ||
|
|
21c6e24c7c | ||
|
|
4d42720af9 | ||
|
|
bf28e376ce | ||
|
|
8413e9245a | ||
|
|
019a15e6eb | ||
|
|
5b292af4d7 | ||
|
|
74c388c6ec | ||
|
|
0c05d4ff9f | ||
|
|
529fff7d4d | ||
|
|
3d5e2442d3 | ||
|
|
14bae3d789 | ||
|
|
ab874a0da9 | ||
|
|
ba4a5c7c44 | ||
|
|
e729b989bb | ||
|
|
320688dee7 | ||
|
|
1a0439a871 | ||
|
|
453f2a4a5b | ||
|
|
6cb2dc51fe | ||
|
|
cf951f6900 | ||
|
|
796ce78e54 | ||
|
|
54c5501e22 | ||
|
|
1ad1ab29b1 | ||
|
|
d2065c8d80 | ||
|
|
aa5ad2fad9 | ||
|
|
4666994a8b | ||
|
|
14cd5559f5 | ||
|
|
932739095a | ||
|
|
28796e3bda | ||
|
|
20a22a86e1 | ||
|
|
5ff0789e75 | ||
|
|
8b983ea103 | ||
|
|
409ec7015e | ||
|
|
e1e324b5d8 | ||
|
|
c8a9fb91c5 | ||
|
|
b670fab0f3 | ||
|
|
21a6b16102 | ||
|
|
8101c11ed8 | ||
|
|
8bb9037c21 | ||
|
|
f69d14063c | ||
|
|
a3ac1f4ec0 | ||
|
|
86cd4f0712 | ||
|
|
885be6ae56 | ||
|
|
50950fcfef | ||
|
|
583137f327 | ||
|
|
4d3cd65429 | ||
|
|
a35736dda3 | ||
|
|
dced15e63d | ||
|
|
13ccd42e16 | ||
|
|
855f43c2eb | ||
|
|
5f6f3624e1 | ||
|
|
c8185d0431 | ||
|
|
f547057bb6 | ||
|
|
6fc87fb982 | ||
|
|
d5f16cf4b6 | ||
|
|
57eb29e26c | ||
|
|
ed85c82556 | ||
|
|
bd7e3b264b | ||
|
|
246bb00ea6 | ||
|
|
f6f8d28001 | ||
|
|
253844cec5 | ||
|
|
bb16a5de2a | ||
|
|
72cf556a7c | ||
|
|
b3eb501277 | ||
|
|
14a352f497 | ||
|
|
a432e44483 | ||
|
|
26b7566179 | ||
|
|
b7fa82ab92 | ||
|
|
a3b248ea3d | ||
|
|
db5ab5f63c | ||
|
|
d542d9ef96 | ||
|
|
472f130e44 | ||
|
|
aa2f8c2664 | ||
|
|
fdef70cddd | ||
|
|
1082a0c029 | ||
|
|
0f4957cbf4 | ||
|
|
f78f05f53b | ||
|
|
6dd8b31b51 | ||
|
|
ed94cd2459 | ||
|
|
0f168677b2 | ||
|
|
d5f607e50f | ||
|
|
834006d311 | ||
|
|
8f6274ed8a | ||
|
|
e2a28ec287 | ||
|
|
5c5faa626e | ||
|
|
1e4014739c | ||
|
|
eade7a0a30 | ||
|
|
9fb34efcf3 | ||
|
|
d3dfbc05ca | ||
|
|
abf20ce712 | ||
|
|
90b3119b8f | ||
|
|
2c7a7c5c36 | ||
|
|
1b0ac89674 | ||
|
|
577ddb28a9 | ||
|
|
49cc164a11 | ||
|
|
0df52ad451 | ||
|
|
45ea0103ed | ||
|
|
172efccd1b | ||
|
|
21324e200f | ||
|
|
51e5c95a1b | ||
|
|
24fad9fec7 | ||
|
|
10015af36d | ||
|
|
4055dd07c4 | ||
|
|
6f86021ae6 | ||
|
|
c916954187 | ||
|
|
23de8c1c08 | ||
|
|
94e0691caa | ||
|
|
958bd0f8e6 | ||
|
|
b2bd9efbaa | ||
|
|
99ce46d510 | ||
|
|
78c438884c | ||
|
|
87633e7fdf | ||
|
|
57d97370f1 | ||
|
|
045e6d9d7f | ||
|
|
90b53a61ad | ||
|
|
7658707bd3 | ||
|
|
aad05628ea | ||
|
|
520518f2ac |
No files matched your search
@@ -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()
|
||||
|
||||
+9
-2
@@ -183,13 +183,20 @@ if (APPLE)
|
||||
set_target_properties(dingusppc PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER "${BUNDLE_ID}"
|
||||
MACOSX_BUNDLE_BUNDLE_NAME "DingusPPC"
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4b"
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4b"
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4c"
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4c"
|
||||
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
|
||||
# Placeholder for the icon file:
|
||||
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
|
||||
)
|
||||
|
||||
if (NOT IOS)
|
||||
set_target_properties(dingusppc PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/cmake/DingusPPCInfo.plist.in"
|
||||
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${BUNDLE_ID}"
|
||||
)
|
||||
endif()
|
||||
|
||||
find_library(COCOA_LIBRARY Cocoa)
|
||||
find_library(IOKIT_LIBRARY IOKit)
|
||||
find_library(COREAUDIO_LIBRARY CoreAudio)
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
- lefp
|
||||
- mathstuf
|
||||
- mrpapersonic
|
||||
- probonopd
|
||||
- Randrianasulu
|
||||
- roytam1
|
||||
- sdkmap
|
||||
@@ -58,6 +59,7 @@
|
||||
- Blitter.net
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- pagetable.com
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>CD-ROM image</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Viewer</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Alternate</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>public.iso-image</string>
|
||||
<string>com.roxio.disk-image-toast</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
|
||||
<key>UTImportedTypeDeclarations</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.disk-image</string>
|
||||
</array>
|
||||
<key>UTTypeDescription</key>
|
||||
<string>Toast disk image</string>
|
||||
<key>UTTypeIdentifier</key>
|
||||
<string>com.roxio.disk-image-toast</string>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
<dict>
|
||||
<key>public.filename-extension</key>
|
||||
<array>
|
||||
<string>toast</string>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/coresignal.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
class WindowEvent {
|
||||
public:
|
||||
@@ -119,6 +120,20 @@ public:
|
||||
uint8_t button;
|
||||
};
|
||||
|
||||
enum class CdromInsertionResult {
|
||||
SUCCESS,
|
||||
NO_DRIVE,
|
||||
MEDIA_PRESENT,
|
||||
IMAGE_OPEN_FAILED,
|
||||
};
|
||||
|
||||
class CdromImageEvent {
|
||||
public:
|
||||
std::string image_path;
|
||||
CdromInsertionResult result = CdromInsertionResult::NO_DRIVE;
|
||||
bool handled = false;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
static EventManager* get_instance() {
|
||||
@@ -131,6 +146,9 @@ public:
|
||||
void poll_events();
|
||||
void set_keyboard_locale(uint32_t keyboard_id);
|
||||
void post_keyboard_state_events();
|
||||
void post_cdrom_event(CdromImageEvent& event) {
|
||||
_cdrom_signal.emit(event);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
||||
@@ -152,6 +170,11 @@ public:
|
||||
_gamepad_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_cdrom_handler(T* inst, void (T::*func)(CdromImageEvent&)) {
|
||||
_cdrom_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_post_handler(T *inst, void (T::*func)()) {
|
||||
_post_signal.connect_method(inst, func);
|
||||
@@ -162,6 +185,7 @@ public:
|
||||
_mouse_signal.disconnect_all();
|
||||
_keyboard_signal.disconnect_all();
|
||||
_gamepad_signal.disconnect_all();
|
||||
_cdrom_signal.disconnect_all();
|
||||
_post_signal.disconnect_all();
|
||||
}
|
||||
|
||||
@@ -179,6 +203,7 @@ private:
|
||||
CoreSignal<const MouseEvent&> _mouse_signal;
|
||||
CoreSignal<const KeyboardEvent&> _keyboard_signal;
|
||||
CoreSignal<const GamepadEvent&> _gamepad_signal;
|
||||
CoreSignal<CdromImageEvent&> _cdrom_signal;
|
||||
CoreSignal<> _post_signal;
|
||||
|
||||
uint64_t events_captured = 0;
|
||||
|
||||
+125
-38
@@ -32,6 +32,20 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_l
|
||||
|
||||
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
|
||||
|
||||
bool g_swap_command_option = false;
|
||||
|
||||
static AdbKey swap_command_option(AdbKey key)
|
||||
{
|
||||
if (!g_swap_command_option)
|
||||
return key;
|
||||
switch (key) {
|
||||
case AdbKey_Option: return AdbKey_Command;
|
||||
case AdbKey_RightOption: return AdbKey_Command;
|
||||
case AdbKey_Command: return AdbKey_Option;
|
||||
default: return key;
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
|
||||
this->kbd_locale = keyboard_id;
|
||||
}
|
||||
@@ -44,8 +58,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 +138,55 @@ void EventManager::poll_events() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-Alt-Shift-+: speed up icnt_factor
|
||||
if (event.key.keysym.sym == SDLK_EQUALS &&
|
||||
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
|
||||
) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
int icnt_counter_val = increment_icnt_factor();
|
||||
LOG_F(INFO, "Incremented icnt_factor: %d", icnt_counter_val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-Alt-Shift--: slow down icnt_factor
|
||||
if (event.key.keysym.sym == SDLK_MINUS &&
|
||||
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
|
||||
) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
int icnt_counter_val = decrement_icnt_factor();
|
||||
LOG_F(INFO, "Decremented icnt_factor: %d", icnt_counter_val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Control-Alt-R: g_realtime toggle
|
||||
if (event.key.keysym.sym == SDLK_r && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT)) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
bool g_realtime_status = toggle_g_realtime();
|
||||
LOG_F(INFO, "g_realtime: %s", g_realtime_status ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -275,6 +322,35 @@ void EventManager::poll_events() {
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_DROPFILE: {
|
||||
const char* path = event.drop.file;
|
||||
// TODO: Distinguish CD-ROM and floppy images once dynamic
|
||||
// floppy insertion is supported.
|
||||
CdromImageEvent cdrom_event{};
|
||||
cdrom_event.image_path = path;
|
||||
this->post_cdrom_event(cdrom_event);
|
||||
|
||||
switch (cdrom_event.result) {
|
||||
case CdromInsertionResult::SUCCESS:
|
||||
LOG_F(INFO, "Inserted CD-ROM image: %s", path);
|
||||
break;
|
||||
case CdromInsertionResult::NO_DRIVE:
|
||||
LOG_F(ERROR, "Cannot insert CD-ROM image; no CD-ROM drive is available: %s",
|
||||
path);
|
||||
break;
|
||||
case CdromInsertionResult::MEDIA_PRESENT:
|
||||
LOG_F(ERROR, "Cannot insert CD-ROM image; eject the current media first: %s",
|
||||
path);
|
||||
break;
|
||||
case CdromInsertionResult::IMAGE_OPEN_FAILED:
|
||||
LOG_F(ERROR, "Cannot insert CD-ROM image: %s", path);
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_free(event.drop.file);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
@@ -285,6 +361,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 +377,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));
|
||||
ke.key = mod->adbkey;
|
||||
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(mod->scancode));
|
||||
count++;
|
||||
ke.key = swap_command_option(mod->adbkey);
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
this->_keyboard_signal.emit(ke);
|
||||
}
|
||||
if (!count)
|
||||
LOG_F(INFO, " (none)");
|
||||
|
||||
LOG_F(INFO, " Keys and Modifiers:");
|
||||
count = 0;
|
||||
for (int i = 0; i < numkeys; i++) {
|
||||
if (!states[i])
|
||||
continue;
|
||||
|
||||
count++;
|
||||
scancode = (SDL_Scancode)i;
|
||||
|
||||
Modifier_t *mod = modifiers;
|
||||
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
|
||||
if (mod->scancode == scancode) {
|
||||
LOG_F(INFO, " 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 +435,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)
|
||||
@@ -439,10 +526,10 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
|
||||
case SDLK_RCTRL: return AdbKey_RightControl;
|
||||
case SDLK_LSHIFT: return AdbKey_Shift;
|
||||
case SDLK_RSHIFT: return AdbKey_RightShift;
|
||||
case SDLK_LALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_RightOption;
|
||||
case SDLK_LGUI: return AdbKey_Command;
|
||||
case SDLK_RGUI: return AdbKey_Command;
|
||||
case SDLK_LALT: return swap_command_option(AdbKey_Option);
|
||||
case SDLK_RALT: return swap_command_option(AdbKey_RightOption);
|
||||
case SDLK_LGUI: return swap_command_option(AdbKey_Command);
|
||||
case SDLK_RGUI: return swap_command_option(AdbKey_Command);
|
||||
case SDLK_MENU: return AdbKey_Grave;
|
||||
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
|
||||
|
||||
@@ -486,9 +573,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 +590,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
|
||||
|
||||
+25
-29
@@ -30,51 +30,47 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
uint32_t TimerManager::add_absolute_timer(uint64_t timeout_ns, uint64_t interval, timer_cb cb)
|
||||
void TimerManager::add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb)
|
||||
{
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = timeout_ns;
|
||||
ti->interval_ns = interval;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
ti.timeout_ns = timeout_ns;
|
||||
ti.interval_ns = interval;
|
||||
ti.active = true;
|
||||
ti.cb = cb;
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(timer_desc);
|
||||
//if (this->timer_queue.remove_by_id(&ti))
|
||||
// LOG_F(ERROR, "timer was in queue!");
|
||||
this->timer_queue.push(&ti);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
void TimerManager::add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(this->get_time_now() + timeout, 0, cb);
|
||||
TimerManager::add_absolute_timer(ti, this->get_time_now() + timeout, 0, cb);
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_immediate_timer(timer_cb cb)
|
||||
void TimerManager::add_immediate_timer(TimerInfo &ti, timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(0, 0, cb);
|
||||
TimerManager::add_absolute_timer(ti, 0, 0, cb);
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(this->get_time_now() + delay, interval, cb);
|
||||
TimerManager::add_absolute_timer(ti, this->get_time_now() + delay, interval, cb);
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb)
|
||||
{
|
||||
return this->add_cyclic_timer(interval, interval, cb);
|
||||
this->add_cyclic_timer(ti, interval, interval, cb);
|
||||
}
|
||||
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
void TimerManager::cancel_timer(TimerInfo &ti)
|
||||
{
|
||||
this->timer_queue.remove_by_id(id);
|
||||
this->timer_queue.remove_by_id(&ti);
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
@@ -82,7 +78,7 @@ void TimerManager::cancel_timer(uint32_t id)
|
||||
|
||||
uint64_t TimerManager::process_timers()
|
||||
{
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
TimerInfo *cur_timer;
|
||||
uint64_t time_now = get_time_now();
|
||||
|
||||
{ // mtx scope
|
||||
@@ -95,7 +91,7 @@ uint64_t TimerManager::process_timers()
|
||||
cur_timer = this->timer_queue.top();
|
||||
} // ] mtx scope
|
||||
while (cur_timer->timeout_ns <= time_now) {
|
||||
this->timer_queue.remove_by_id(cur_timer->id);
|
||||
this->timer_queue.remove_by_id(cur_timer);
|
||||
uint64_t timeout_ns = cur_timer->timeout_ns;
|
||||
timer_cb cb = cur_timer->cb;
|
||||
|
||||
@@ -112,7 +108,7 @@ uint64_t TimerManager::process_timers()
|
||||
this->cb_active = true;
|
||||
|
||||
// invoke timer callback
|
||||
cb();
|
||||
cb(time_now, timeout_ns);
|
||||
|
||||
this->cb_active = false;
|
||||
|
||||
@@ -127,16 +123,16 @@ uint64_t TimerManager::process_timers()
|
||||
} // ] mtx scope
|
||||
}
|
||||
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
return cur_timer->timeout_ns - time_now;
|
||||
// return next timer's expiry
|
||||
return cur_timer->timeout_ns;
|
||||
}
|
||||
|
||||
void TimerManager::cancel_all_timers()
|
||||
{
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
TimerInfo *cur_timer;
|
||||
while (!this->timer_queue.empty()) {
|
||||
cur_timer = this->timer_queue.top();
|
||||
LOG_F(WARNING, "Canceling timer id:%u ns:%llu", cur_timer->id, cur_timer->timeout_ns);
|
||||
LOG_F(WARNING, "Canceling timer id:%llu ns:%llu", uint64_t(cur_timer), cur_timer->timeout_ns);
|
||||
this->timer_queue.pop();
|
||||
}
|
||||
}
|
||||
+16
-18
@@ -40,7 +40,7 @@ constexpr auto ONE_BILLION_NS = 1000000000;
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
typedef std::function<void()> timer_cb;
|
||||
typedef std::function<void(uint64_t timeout_ns, uint64_t time_now)> timer_cb;
|
||||
typedef std::function<void()> notify_changes_cb;
|
||||
|
||||
/** Extend std::priority_queue as suggested here:
|
||||
@@ -50,17 +50,17 @@ typedef std::function<void()> notify_changes_cb;
|
||||
template <typename T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
|
||||
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
|
||||
public:
|
||||
bool remove_by_id(const uint32_t id){
|
||||
bool remove_by_id(T id){
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
if (this->empty())
|
||||
return false;
|
||||
auto el = this->top();
|
||||
if (el->id == id) {
|
||||
if (el == id) {
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return true;
|
||||
}
|
||||
auto it = std::find_if(
|
||||
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == id; });
|
||||
this->c.begin(), this->c.end(), [id](const T& el) { return el == id; });
|
||||
if (it != this->c.end()) {
|
||||
this->c.erase(it);
|
||||
std::make_heap(this->c.begin(), this->c.end(), this->comp);
|
||||
@@ -93,18 +93,18 @@ private:
|
||||
};
|
||||
|
||||
typedef struct TimerInfo {
|
||||
uint32_t id;
|
||||
uint64_t timeout_ns; // timer expiry
|
||||
uint64_t interval_ns; // 0 for one-shot timers
|
||||
bool active = false; // set to true when added to the queue
|
||||
timer_cb cb; // timer callback
|
||||
} 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) {
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns ||
|
||||
(l.get()->timeout_ns == r.get()->timeout_ns && l.get()->id > r.get()->id);
|
||||
bool operator()(const TimerInfo *l, const TimerInfo *r) const {
|
||||
return l->timeout_ns > r->timeout_ns ||
|
||||
(l->timeout_ns == r->timeout_ns && l > r);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,15 +128,15 @@ 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);
|
||||
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
|
||||
uint32_t add_immediate_timer(timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(uint32_t id);
|
||||
void add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb);
|
||||
void add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb);
|
||||
void add_immediate_timer(TimerInfo &ti, timer_cb cb);
|
||||
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb);
|
||||
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(TimerInfo &ti);
|
||||
void cancel_all_timers();
|
||||
|
||||
uint64_t process_timers();
|
||||
@@ -146,13 +146,11 @@ private:
|
||||
TimerManager(){} // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
my_priority_queue<TimerInfo*, std::vector<TimerInfo*>, MyGtComparator> timer_queue;
|
||||
|
||||
std::function<uint64_t()> get_time_now;
|
||||
std::function<void()> notify_timer_changes;
|
||||
|
||||
std::atomic<uint32_t> id{0};
|
||||
|
||||
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
|
||||
bool cb_active = false; // true if a timer callback is executing
|
||||
};
|
||||
|
||||
@@ -23,9 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(You may also contact divingkxt or powermax2286 on Discord)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PPC_DECODE_HELPERS_H
|
||||
#define PPC_DECODE_HELPERS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// ============== Helpers for extracting operands from opcodes ================
|
||||
|
||||
#define decode_ops_sa(opcode) \
|
||||
int reg_s = (opcode >> 21) & 0x1F; \
|
||||
int reg_a = (opcode >> 16) & 0x1F;
|
||||
|
||||
#define decode_ops_da(opcode) \
|
||||
int reg_d = (opcode >> 21) & 0x1F; \
|
||||
int reg_a = (opcode >> 16) & 0x1F;
|
||||
|
||||
#define decode_ops_sab(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
int reg_b = (opcode >> 11) & 0x1F;
|
||||
|
||||
#define decode_ops_dab(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
int reg_b = (opcode >> 11) & 0x1F;
|
||||
|
||||
#define decode_ops_dasimm(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
int32_t simm = int32_t(int16_t(opcode));
|
||||
|
||||
#define decode_ops_sauimm(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
uint32_t uimm = uint16_t(opcode);
|
||||
|
||||
#define decode_ops_dauimm(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
uint32_t uimm = uint16_t(opcode);
|
||||
|
||||
// ================= Helpers for the original interpreter =====================
|
||||
// The helpers below do the same work as those above but also pre-load some
|
||||
// register values and place them into local variables.
|
||||
// That significantly reduces interpreter code.
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
decode_ops_dasimm(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsdauimm(opcode) \
|
||||
decode_ops_dauimm(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 0x1F; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssauimm(opcode) \
|
||||
decode_ops_sauimm(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfd_regsauimm(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
int reg_a = (opcode >> 16) & 0x1F; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_da(opcode) \
|
||||
decode_ops_da(opcode)
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
decode_ops_dab(opcode)
|
||||
|
||||
#define ppc_grab_s(opcode) \
|
||||
int reg_s = (opcode >> 21) & 0x1F; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
decode_ops_dab(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
decode_ops_sab(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
decode_ops_sab(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 0x1F; \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
unsigned rot_sh = (opcode >> 11) & 0x1F; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash_stswi(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
unsigned rot_sh = (opcode >> 11) & 0x1F; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
int reg_s = (opcode >> 21) & 0x1F; \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 0x1F; \
|
||||
uint32_t reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 0x1F; \
|
||||
int reg_b = (opcode >> 11) & 0x1F;
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
decode_ops_dab(opcode); \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpdia(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsia(opcode) \
|
||||
decode_ops_sa(opcode); \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsiab(opcode) \
|
||||
decode_ops_sab(opcode); \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 0x1F; \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
double db_test_a = GET_FPR(reg_a); \
|
||||
double db_test_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdab(opcode) \
|
||||
decode_ops_dab(opcode); \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdac(opcode) \
|
||||
decode_ops_da(opcode); \
|
||||
int reg_c = (opcode >> 6) & 0x1F; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_regsfpdabc(opcode) \
|
||||
decode_ops_dab(opcode); \
|
||||
int reg_c = (opcode >> 6) & 0x1F; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) \
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_fpresult_int(reg, ppc_result64_d) \
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d) \
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define FPR_INT(reg) \
|
||||
ppc_state.fpr[reg].int64_r
|
||||
|
||||
#endif // PPC_DECODE_HELPERS_H
|
||||
@@ -392,6 +392,13 @@ void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int
|
||||
}
|
||||
}
|
||||
|
||||
void fmt_rotateinsert(PPCDisasmContext* ctx, const char* opc, int dst, int src, int sh, int mb, int me) {
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
add_reg_in(ctx, "r%d", dst);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
/* Opcodes */
|
||||
|
||||
void opc_illegal(PPCDisasmContext* ctx) {
|
||||
@@ -522,7 +529,7 @@ void opc_rlwimi(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
fmt_rotateop(ctx, opcode, ra, rs, sh, mb, me, true);
|
||||
fmt_rotateinsert(ctx, opcode, ra, rs, sh, mb, me);
|
||||
}
|
||||
|
||||
void opc_rlwinm(PPCDisasmContext* ctx) {
|
||||
|
||||
+38
-12
@@ -126,6 +126,9 @@ enum SPR : int {
|
||||
SDA = 959,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
THRM1 = 1020,
|
||||
THRM2 = 1021,
|
||||
THRM3 = 1022,
|
||||
};
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
@@ -321,17 +324,22 @@ enum FPOP : int {
|
||||
|
||||
/** PowerPC exception types. */
|
||||
enum class Except_Type {
|
||||
EXC_SYSTEM_RESET = 1,
|
||||
EXC_MACHINE_CHECK,
|
||||
EXC_DSI,
|
||||
EXC_ISI,
|
||||
EXC_EXT_INT,
|
||||
EXC_ALIGNMENT,
|
||||
EXC_PROGRAM,
|
||||
EXC_NO_FPU,
|
||||
EXC_DECR,
|
||||
EXC_SYSCALL = 12,
|
||||
EXC_TRACE = 13
|
||||
EXC_SYSTEM_RESET = 0x01,
|
||||
EXC_MACHINE_CHECK = 0x02,
|
||||
EXC_DSI = 0x03,
|
||||
EXC_ISI = 0x04,
|
||||
EXC_EXT_INT = 0x05,
|
||||
EXC_ALIGNMENT = 0x06,
|
||||
EXC_PROGRAM = 0x07,
|
||||
EXC_NO_FPU = 0x08,
|
||||
EXC_DECR = 0x09,
|
||||
EXC_SYSCALL = 0x0C,
|
||||
EXC_TRACE = 0x0D,
|
||||
EXC_FP_ASSIST = 0x0E,
|
||||
EXC_PERF_MON_INT = 0x0F,
|
||||
EXC_INST_ADDR_BP = 0x13,
|
||||
EXC_SYS_MGMT_INT = 0x14,
|
||||
EXC_THRM_MGMT_INT = 0x17,
|
||||
};
|
||||
|
||||
/** Program Exception subclasses. */
|
||||
@@ -366,8 +374,14 @@ 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;
|
||||
extern bool thrm_exception_pending;
|
||||
|
||||
extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
|
||||
@@ -384,7 +398,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
|
||||
@@ -714,6 +729,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 */
|
||||
|
||||
/* icnt_factor control */
|
||||
extern int increment_icnt_factor();
|
||||
extern int decrement_icnt_factor();
|
||||
extern int get_icnt_factor();
|
||||
|
||||
/* 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;
|
||||
|
||||
+15
-37
@@ -39,8 +39,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
case Except_Type::EXC_DSI:
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0100;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
@@ -48,12 +51,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0200;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0300;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
@@ -62,56 +59,28 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
case Except_Type::EXC_THRM_MGMT_INT:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0900;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0C00;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0D00;
|
||||
break;
|
||||
|
||||
default:
|
||||
ABORT_F("Unknown exception occurred: %X\n", (unsigned)exception_type);
|
||||
break;
|
||||
}
|
||||
ppc_next_instruction_address = uint32_t(exception_type) << 8;
|
||||
|
||||
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
|
||||
uint32_t old_msr_val = ppc_state.msr;
|
||||
@@ -202,6 +171,15 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_THRM_MGMT_INT:
|
||||
exc_descriptor = "Thermal management interrupt exception occurred";
|
||||
break;
|
||||
|
||||
default:
|
||||
char buffer[100];
|
||||
snprintf(buffer, sizeof(buffer), "Exception 0x%X occurred", int(exception_type));
|
||||
exc_descriptor = buffer;
|
||||
}
|
||||
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
|
||||
+101
-20
@@ -73,6 +73,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;
|
||||
@@ -91,14 +128,10 @@ unsigned exec_flags; // execution control flags
|
||||
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;
|
||||
bool thrm_exception_pending = false;
|
||||
|
||||
/* 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;
|
||||
@@ -229,8 +262,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 +272,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
|
||||
}
|
||||
@@ -331,16 +361,33 @@ uint64_t get_virt_time_ns()
|
||||
}
|
||||
}
|
||||
|
||||
void set_virt_time_ns(uint64_t time_now)
|
||||
{
|
||||
if (g_realtime) {
|
||||
g_nanoseconds_base = cpu_now_ns() - time_now - 5000;
|
||||
} else {
|
||||
g_icycles = time_now >> icnt_factor;
|
||||
}
|
||||
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 uint64_t process_events()
|
||||
{
|
||||
exec_timer = false;
|
||||
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
|
||||
if (slice_ns == 0) {
|
||||
// execute 25.000 cycles
|
||||
// if there are no pending timers
|
||||
return g_icycles + 25000;
|
||||
}
|
||||
return g_icycles + (slice_ns >> icnt_factor) + 1;
|
||||
uint64_t next_ns = TimerManager::get_instance()->process_timers();
|
||||
return (
|
||||
(
|
||||
next_ns ?
|
||||
next_ns
|
||||
:
|
||||
TimerManager::get_instance()->current_time_ns() + 500'000
|
||||
) >> icnt_factor
|
||||
) + 1;
|
||||
}
|
||||
|
||||
static void force_cycle_counter_reload()
|
||||
@@ -349,6 +396,40 @@ static void force_cycle_counter_reload()
|
||||
exec_timer = true;
|
||||
}
|
||||
|
||||
int increment_icnt_factor()
|
||||
{
|
||||
uint64_t time_now = get_virt_time_ns();
|
||||
icnt_factor += 1;
|
||||
set_virt_time_ns(time_now);
|
||||
force_cycle_counter_reload();
|
||||
return icnt_factor;
|
||||
}
|
||||
|
||||
int decrement_icnt_factor()
|
||||
{
|
||||
if (icnt_factor > 0) {
|
||||
uint64_t time_now = get_virt_time_ns();
|
||||
icnt_factor -= 1;
|
||||
set_virt_time_ns(time_now);
|
||||
force_cycle_counter_reload();
|
||||
}
|
||||
return icnt_factor;
|
||||
}
|
||||
|
||||
int get_icnt_factor()
|
||||
{
|
||||
return icnt_factor;
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -1030,7 +1111,7 @@ static map<string, int> SPRName2Num = {
|
||||
{"DBAT2L", 541}, {"DBAT3U", 542}, {"DBAT3L", 543},
|
||||
{"HID0", SPR::HID0}, {"HID1", SPR::HID1}, {"IABR", 1010},
|
||||
{"DABR", 1013}, {"L2CR", 1017}, {"ICTC", 1019},
|
||||
{"THRM1", 1020}, {"THRM2", 1021}, {"THRM3", 1022},
|
||||
{"THRM1", SPR::THRM1}, {"THRM2", SPR::THRM2}, {"THRM3", SPR::THRM3},
|
||||
{"PIR", 1023}, {"TBL", SPR::TBL_S}, {"TBU", SPR::TBU_S},
|
||||
{"SDR1", SPR::SDR1}, {"MQ", SPR::MQ}, {"RTCU", SPR::RTCU_S},
|
||||
{"RTCL", SPR::RTCL_S}, {"DSISR", SPR::DSISR}, {"DAR", SPR::DAR},
|
||||
|
||||
@@ -21,14 +21,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdlib.h>
|
||||
#include <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include <cfenv>
|
||||
#include <cfloat>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
#include <stdlib.h>
|
||||
|
||||
inline static void ppc_update_cr1() {
|
||||
// copy FPSCR[FX|FEX|VX|OX] to CR1
|
||||
@@ -420,7 +421,7 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
|
||||
if (snan_single_check(reg_a) || snan_single_check(reg_b) || snan_single_check(reg_c)) {
|
||||
uint64_t qnan = 0x7FFC000000000000;
|
||||
ppc_store_fpresult_int(reg_d, qnan);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
}
|
||||
@@ -1239,6 +1240,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 +1279,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 +1296,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 +1319,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
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(You may also contact divingkxt or powermax2286 on Discord)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PPC_MACROS_H
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsdauimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssauimm(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfd_regsauimm(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define ppc_grab_s(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
int reg_b = (opcode >> 11) & 31;\
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
unsigned rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash_stswi(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
unsigned rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define FPR_INT(reg) \
|
||||
ppc_state.fpr[reg].int64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpdia(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsia(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsiab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
double db_test_a = GET_FPR(reg_a); \
|
||||
double db_test_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdac(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_regsfpdabc(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
+301
-278
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
//#define MMU_PROFILING // uncomment this to enable MMU profiling
|
||||
//#define TLB_PROFILING // uncomment this to enable SoftTLB profiling
|
||||
@@ -56,6 +57,7 @@ uint64_t iomem_writes_total = 0; // counts I/O memory writes
|
||||
uint64_t exec_reads_total = 0; // counts reads from executable memory
|
||||
uint64_t bat_transl_total = 0; // counts BAT translations
|
||||
uint64_t ptab_transl_total = 0; // counts page table translations
|
||||
uint64_t pat_flushes_total = 0; // counts full page-translation TLB flushes
|
||||
uint64_t unaligned_reads = 0; // counts unaligned reads
|
||||
uint64_t unaligned_writes = 0; // counts unaligned writes
|
||||
uint64_t unaligned_crossp_r = 0; // counts unaligned crosspage reads
|
||||
@@ -77,9 +79,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 +460,133 @@ 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;
|
||||
|
||||
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
|
||||
TLBE_CTX_TRACKED = 1 << 7, // entry pointer is in gTrackedIEntries or gTrackedDEntries
|
||||
};
|
||||
|
||||
constexpr uint16_t TLBE_FROM_TRANSLATION =
|
||||
TLBFlags::TLBE_FROM_BAT | TLBFlags::TLBE_FROM_PAT;
|
||||
|
||||
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;
|
||||
|
||||
// Track slots populated by either page or block address translation. Context
|
||||
// changes can then invalidate only populated slots without adding a generation
|
||||
// check to every TLB lookup.
|
||||
static std::vector<TLBEntry *> gTrackedIEntries;
|
||||
static std::vector<TLBEntry *> gTrackedDEntries;
|
||||
|
||||
// TLBE_FROM_* sources awaiting invalidation at the next context sync.
|
||||
static uint16_t gPendingIInvalidationSources = 0;
|
||||
static uint16_t gPendingDInvalidationSources = 0;
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
static void track_translated_entry(TLBEntry *tlb_entry)
|
||||
{
|
||||
if (!(tlb_entry->flags & TLBE_FROM_TRANSLATION) ||
|
||||
(tlb_entry->flags & TLBFlags::TLBE_CTX_TRACKED))
|
||||
return;
|
||||
|
||||
tlb_entry->flags |= TLBFlags::TLBE_CTX_TRACKED;
|
||||
if (tlb_type == TLBType::ITLB)
|
||||
gTrackedIEntries.push_back(tlb_entry);
|
||||
else
|
||||
gTrackedDEntries.push_back(tlb_entry);
|
||||
}
|
||||
|
||||
static void tlb_invalidate_tracked_entries(std::vector<TLBEntry *> &tracked_entries,
|
||||
uint16_t sources)
|
||||
{
|
||||
size_t retained_count = 0;
|
||||
for (TLBEntry *tlb_entry : tracked_entries) {
|
||||
uint16_t source = tlb_entry->flags & TLBE_FROM_TRANSLATION;
|
||||
if (source & sources) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
tlb_entry->flags &= ~TLBFlags::TLBE_CTX_TRACKED;
|
||||
} else if (source) {
|
||||
tracked_entries[retained_count++] = tlb_entry;
|
||||
} else {
|
||||
tlb_entry->flags &= ~TLBFlags::TLBE_CTX_TRACKED;
|
||||
}
|
||||
}
|
||||
tracked_entries.resize(retained_count);
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
static void tlb_invalidate_tracked_entries()
|
||||
{
|
||||
uint16_t *pending_sources;
|
||||
std::vector<TLBEntry *> *tracked_entries;
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
pending_sources = &gPendingIInvalidationSources;
|
||||
tracked_entries = &gTrackedIEntries;
|
||||
} else {
|
||||
pending_sources = &gPendingDInvalidationSources;
|
||||
tracked_entries = &gTrackedDEntries;
|
||||
}
|
||||
|
||||
if (!*pending_sources)
|
||||
return;
|
||||
|
||||
tlb_invalidate_tracked_entries(*tracked_entries, *pending_sources);
|
||||
*pending_sources = 0;
|
||||
}
|
||||
|
||||
static void schedule_tlb_invalidation(TLBType tlb_type, uint16_t sources_to_invalidate)
|
||||
{
|
||||
uint16_t *pending_sources;
|
||||
|
||||
if (tlb_type == TLBType::ITLB)
|
||||
pending_sources = &gPendingIInvalidationSources;
|
||||
else
|
||||
pending_sources = &gPendingDInvalidationSources;
|
||||
|
||||
if (!*pending_sources) {
|
||||
if (tlb_type == TLBType::ITLB)
|
||||
add_ctx_sync_action(&tlb_invalidate_tracked_entries<TLBType::ITLB>);
|
||||
else
|
||||
add_ctx_sync_action(&tlb_invalidate_tracked_entries<TLBType::DTLB>);
|
||||
}
|
||||
*pending_sources |= sources_to_invalidate;
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
static void promote_tlb_entry(TLBEntry *tlb1_entry, const TLBEntry *tlb2_entry)
|
||||
{
|
||||
uint16_t tracked = tlb1_entry->flags & TLBFlags::TLBE_CTX_TRACKED;
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
tlb1_entry->flags &= ~TLBFlags::TLBE_CTX_TRACKED;
|
||||
tlb1_entry->flags |= tracked;
|
||||
track_translated_entry<tlb_type>(tlb1_entry);
|
||||
}
|
||||
|
||||
// primary ITLB for all MMU modes
|
||||
static std::array<TLBEntry, TLB_SIZE> itlb1_mode1;
|
||||
static std::array<TLBEntry, TLB_SIZE> itlb1_mode2;
|
||||
@@ -546,6 +672,27 @@ void mmu_change_mode()
|
||||
}
|
||||
}
|
||||
|
||||
template <uint32_t way>
|
||||
static inline void tlb2_touch_way(TLBEntry *tlb_entry)
|
||||
{
|
||||
static_assert(way < TLB2_WAYS);
|
||||
|
||||
// Each pair is one branch of the four-way tree-based LRU. Mark the
|
||||
// selected way as most recently used, its sibling as the next replacement
|
||||
// candidate, and the other pair as less recently used.
|
||||
if constexpr (way < 2) {
|
||||
tlb_entry[0].lru_bits = way == 0 ? 0x3 : 0x2;
|
||||
tlb_entry[1].lru_bits = way == 1 ? 0x3 : 0x2;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
} else {
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = way == 2 ? 0x3 : 0x2;
|
||||
tlb_entry[3].lru_bits = way == 3 ? 0x3 : 0x2;
|
||||
}
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
static TLBEntry* tlb2_target_entry(uint32_t gp_va)
|
||||
{
|
||||
@@ -559,64 +706,32 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
|
||||
|
||||
// select the target from invalid blocks first
|
||||
if (tlb_entry[0].tag == TLB_INVALID_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;
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
return tlb_entry;
|
||||
} else if (tlb_entry[1].tag == TLB_INVALID_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;
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
return &tlb_entry[1];
|
||||
} else if (tlb_entry[2].tag == TLB_INVALID_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;
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
return &tlb_entry[2];
|
||||
} else if (tlb_entry[3].tag == TLB_INVALID_TAG) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x2;
|
||||
tlb_entry[3].lru_bits = 0x3;
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
return &tlb_entry[3];
|
||||
} else { // no free entries, replace an existing one according with the hLRU policy
|
||||
#ifdef TLB_PROFILING
|
||||
num_entry_replacements++;
|
||||
#endif
|
||||
if (tlb_entry[0].lru_bits == 0) {
|
||||
// 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;
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
return tlb_entry;
|
||||
} else if (tlb_entry[1].lru_bits == 0) {
|
||||
// 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;
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
return &tlb_entry[1];
|
||||
} else if (tlb_entry[2].lru_bits == 0) {
|
||||
// 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;
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
return &tlb_entry[2];
|
||||
} else {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x2;
|
||||
tlb_entry[3].lru_bits = 0x3;
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
return &tlb_entry[3];
|
||||
}
|
||||
}
|
||||
@@ -665,10 +780,12 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
tlb_entry = tlb2_target_entry<TLBType::ITLB>(tag);
|
||||
tlb_entry->tag = tag;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM |
|
||||
(tlb_entry->flags & TLBFlags::TLBE_CTX_TRACKED);
|
||||
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;
|
||||
track_translated_entry<TLBType::ITLB>(tlb_entry);
|
||||
} else {
|
||||
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
|
||||
}
|
||||
@@ -697,9 +814,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);
|
||||
@@ -737,11 +854,13 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
tlb_entry = tlb2_target_entry<TLBType::DTLB>(tag);
|
||||
tlb_entry->tag = tag;
|
||||
if (rgn_desc->type & RT_MMIO) { // MMIO region
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_IO;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_IO |
|
||||
(tlb_entry->flags & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->rgn_desc = rgn_desc;
|
||||
tlb_entry->dev_base_va = guest_va - (phys_addr - rgn_desc->start);
|
||||
} else { // memory region backed by host memory
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM |
|
||||
(tlb_entry->flags & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
|
||||
(phys_addr - rgn_desc->start);
|
||||
if (rgn_desc->type == RT_ROM) {
|
||||
@@ -752,6 +871,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
}
|
||||
}
|
||||
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
|
||||
track_translated_entry<TLBType::DTLB>(tlb_entry);
|
||||
return tlb_entry;
|
||||
} else {
|
||||
if (!is_dbg) {
|
||||
@@ -780,32 +900,16 @@ 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) {
|
||||
// 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;
|
||||
if (tlb_entry[0].tag == tag) {
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
} else if (tlb_entry[1].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;
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
tlb_entry = &tlb_entry[1];
|
||||
} else if (tlb_entry[2].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;
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
tlb_entry = &tlb_entry[2];
|
||||
} else if (tlb_entry[3].tag == tag) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x2;
|
||||
tlb_entry[3].lru_bits = 0x3;
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
tlb_entry = &tlb_entry[3];
|
||||
} else {
|
||||
return nullptr;
|
||||
@@ -813,6 +917,80 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
|
||||
return tlb_entry;
|
||||
}
|
||||
|
||||
struct TLBLookupResult {
|
||||
TLBEntry *primary_entry;
|
||||
TLBEntry *matched_entry; // nullptr if both TLBs missed
|
||||
bool primary_hit;
|
||||
};
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
static inline TLBLookupResult lookup_tlb(uint32_t guest_va, uint32_t tag)
|
||||
{
|
||||
TLBEntry *primary_entry;
|
||||
if constexpr (tlb_type == TLBType::ITLB) {
|
||||
primary_entry = &pCurITLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
} else {
|
||||
primary_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
}
|
||||
|
||||
if (primary_entry->tag == tag) {
|
||||
return TLBLookupResult{primary_entry, primary_entry, true};
|
||||
}
|
||||
return TLBLookupResult{
|
||||
primary_entry,
|
||||
lookup_secondary_tlb<tlb_type>(guest_va, tag),
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
// Returns true when the PTE.C bit was updated. Callers writing through a
|
||||
// primary entry use this to mirror the update into the secondary TLB.
|
||||
static inline bool prepare_dtlb_write(TLBEntry *tlb_entry, uint32_t guest_va)
|
||||
{
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Perform full page address translation to update the PTE.C bit.
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
tlb_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
return true;
|
||||
}
|
||||
|
||||
void mmu_dcbz(uint32_t opcode, uint32_t guest_va)
|
||||
{
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
TLBEntry *tlb_entry = lookup_tlb<TLBType::DTLB>(guest_va, tag).matched_entry;
|
||||
if (tlb_entry == nullptr) {
|
||||
// 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.
|
||||
prepare_dtlb_write(tlb_entry, guest_va);
|
||||
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
|
||||
@@ -830,16 +1008,15 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
|
||||
const uint32_t tag = vaddr & ~0xFFFUL;
|
||||
|
||||
// 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
|
||||
TLBLookupResult tlb_lookup = lookup_tlb<TLBType::ITLB>(vaddr, tag);
|
||||
tlb1_entry = tlb_lookup.primary_entry;
|
||||
if (tlb_lookup.primary_hit) { // primary ITLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_itlb_hits++;
|
||||
#endif
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
} else {
|
||||
// primary ITLB miss -> look up address in the secondary ITLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::ITLB>(vaddr, tag);
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_itlb_refills++;
|
||||
@@ -854,10 +1031,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
}
|
||||
#endif
|
||||
// refill the primary ITLB
|
||||
tlb1_entry->tag = tag;
|
||||
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;
|
||||
promote_tlb_entry<TLBType::ITLB>(tlb1_entry, tlb2_entry);
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
@@ -867,135 +1041,14 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
return host_va;
|
||||
}
|
||||
|
||||
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
|
||||
void tlb_flush_all_pat()
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb1[(tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag != TLB_INVALID_TAG && (tlb_entry->tag & TLB_VPS_MASK) == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", tag);
|
||||
}
|
||||
}
|
||||
#ifdef MMU_PROFILING
|
||||
pat_flushes_total++;
|
||||
#endif
|
||||
|
||||
static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &tlb2, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb2[((tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag != TLB_INVALID_TAG && (tlb_entry[i].tag & TLB_VPS_MASK) == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tlb_flush_entry(uint32_t ea)
|
||||
{
|
||||
const uint32_t tag = ea & TLB_VPS_MASK;
|
||||
tlb_flush_primary_entry(itlb1_mode1, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode1, tag);
|
||||
tlb_flush_primary_entry(itlb1_mode2, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode2, tag);
|
||||
tlb_flush_primary_entry(itlb1_mode3, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode3, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode1, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode1, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode2, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode2, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode3, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode3, tag);
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
static void tlb_flush_entries(std::array<TLBEntry, N> &tlb, TLBFlags type) {
|
||||
for (auto &tlb_el : tlb) {
|
||||
if (tlb_el.tag != TLB_INVALID_TAG && tlb_el.flags & type) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_entries(TLBFlags type)
|
||||
{
|
||||
// Mode 1 is real addressing and thus can't contain any PAT entries by definition.
|
||||
bool flush_mode1 = type != TLBE_FROM_PAT;
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb1_mode2, type);
|
||||
tlb_flush_entries(itlb1_mode3, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb2_mode2, type);
|
||||
tlb_flush_entries(itlb2_mode3, type);
|
||||
} else {
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb1_mode2, type);
|
||||
tlb_flush_entries(dtlb1_mode3, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb2_mode2, type);
|
||||
tlb_flush_entries(dtlb2_mode3, type);
|
||||
}
|
||||
}
|
||||
|
||||
bool gTLBFlushIBatEntries = false;
|
||||
bool gTLBFlushDBatEntries = false;
|
||||
bool gTLBFlushIPatEntries = false;
|
||||
bool gTLBFlushDPatEntries = false;
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_bat_entries()
|
||||
{
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
if (!gTLBFlushIBatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_BAT);
|
||||
gTLBFlushIBatEntries = false;
|
||||
} else {
|
||||
if (!gTLBFlushDBatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_BAT);
|
||||
gTLBFlushDBatEntries = false;
|
||||
}
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
tlb_invalidate_tracked_entries(gTrackedIEntries, TLBE_FROM_PAT);
|
||||
tlb_invalidate_tracked_entries(gTrackedDEntries, TLBE_FROM_PAT);
|
||||
}
|
||||
|
||||
static void mpc601_bat_update(uint32_t bat_reg)
|
||||
@@ -1023,20 +1076,14 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
// copy IBAT entry to DBAT entry
|
||||
*dbat_entry = *ibat_entry;
|
||||
} else {
|
||||
// disable the corresponding BAT paars
|
||||
// disable the corresponding BAT pairs
|
||||
ibat_entry->valid = false;
|
||||
dbat_entry->valid = false;
|
||||
}
|
||||
|
||||
// MPC601 has unified BATs so we're going to flush both ITLB and DTLB
|
||||
if (!gTLBFlushIBatEntries || !gTLBFlushIPatEntries || !gTLBFlushDBatEntries || !gTLBFlushDPatEntries) {
|
||||
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>);
|
||||
}
|
||||
// MPC601 has unified BATs, so they affect both translation contexts.
|
||||
schedule_tlb_invalidation(TLBType::ITLB, TLBE_FROM_TRANSLATION);
|
||||
schedule_tlb_invalidation(TLBType::DTLB, TLBE_FROM_TRANSLATION);
|
||||
}
|
||||
|
||||
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
|
||||
@@ -1062,11 +1109,8 @@ 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) {
|
||||
gTLBFlushIBatEntries = true;
|
||||
gTLBFlushIPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::ITLB>);
|
||||
}
|
||||
// A new IBAT can shadow an existing page translation.
|
||||
schedule_tlb_invalidation(TLBType::ITLB, TLBE_FROM_TRANSLATION);
|
||||
}
|
||||
|
||||
static void ppc_dbat_update(uint32_t bat_reg)
|
||||
@@ -1087,23 +1131,16 @@ 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) {
|
||||
gTLBFlushDBatEntries = true;
|
||||
gTLBFlushDPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
|
||||
}
|
||||
// A new DBAT can shadow an existing page translation.
|
||||
schedule_tlb_invalidation(TLBType::DTLB, TLBE_FROM_TRANSLATION);
|
||||
}
|
||||
|
||||
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.
|
||||
schedule_tlb_invalidation(TLBType::ITLB, TLBFlags::TLBE_FROM_PAT);
|
||||
schedule_tlb_invalidation(TLBType::DTLB, TLBFlags::TLBE_FROM_PAT);
|
||||
}
|
||||
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
@@ -1148,12 +1185,13 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
// look up guest virtual address in the primary and secondary TLBs
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
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
|
||||
TLBLookupResult tlb_lookup = lookup_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb1_entry = tlb_lookup.primary_entry;
|
||||
if (tlb_lookup.primary_hit) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
@@ -1168,8 +1206,7 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_dtlb_refills++;
|
||||
@@ -1189,7 +1226,7 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
@@ -1319,25 +1356,17 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
// look up guest virtual address in the primary and secondary TLBs
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
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
|
||||
TLBLookupResult tlb_lookup = lookup_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb1_entry = tlb_lookup.primary_entry;
|
||||
if (tlb_lookup.primary_hit) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
if (!(tlb1_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 (!(tlb1_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
tlb1_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
|
||||
if (prepare_dtlb_write(tlb1_entry, guest_va)) {
|
||||
// don't forget to update the secondary TLB as well
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry != nullptr) {
|
||||
@@ -1353,8 +1382,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
#endif
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_w + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_dtlb_refills++;
|
||||
@@ -1371,22 +1399,11 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
num_secondary_dtlb_hits++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(tlb2_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 (!(tlb2_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
tlb2_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
prepare_dtlb_write(tlb2_entry, guest_va);
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
@@ -1520,8 +1537,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) {
|
||||
@@ -1700,6 +1717,10 @@ public:
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = ptab_transl_total});
|
||||
|
||||
vars.push_back({.name = "Full PAT TLB Flushes Total",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = pat_flushes_total});
|
||||
|
||||
vars.push_back({.name = "Unaligned Reads Total",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = unaligned_reads});
|
||||
@@ -1725,6 +1746,7 @@ public:
|
||||
exec_reads_total = 0;
|
||||
bat_transl_total = 0;
|
||||
ptab_transl_total = 0;
|
||||
pat_flushes_total = 0;
|
||||
unaligned_reads = 0;
|
||||
unaligned_writes = 0;
|
||||
unaligned_crossp_r = 0;
|
||||
@@ -1894,13 +1916,12 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
TLBLookupResult tlb_lookup = lookup_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb1_entry = tlb_lookup.primary_entry;
|
||||
|
||||
do {
|
||||
if (tlb1_entry->tag != tag) {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (!tlb_lookup.primary_hit) {
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
if (tlb2_entry == nullptr) {
|
||||
// secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
@@ -1913,7 +1934,7 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
}
|
||||
else {
|
||||
tlb1_entry = tlb2_entry;
|
||||
@@ -1955,9 +1976,11 @@ static void invalidate_tlb_entries(std::array<TLBEntry, N> &tlb) {
|
||||
|
||||
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};
|
||||
gPendingIInvalidationSources = 0;
|
||||
gPendingDInvalidationSources = 0;
|
||||
gTrackedIEntries.clear();
|
||||
gTrackedDEntries.clear();
|
||||
|
||||
last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
mmu_exception_handler = ppc_exception_handler;
|
||||
|
||||
+2
-35
@@ -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;
|
||||
@@ -127,7 +93,8 @@ 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 tlb_flush_all_pat();
|
||||
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);
|
||||
|
||||
+124
-26
@@ -24,12 +24,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/bitops.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <core/mathutils.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
|
||||
static int junction_temperature = 24;
|
||||
static TimerInfo thermal_timer;
|
||||
|
||||
//Extract the registers desired and the values of the registers.
|
||||
|
||||
// Affects CR Field 0 - For integer operations
|
||||
@@ -730,6 +734,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 +750,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 +766,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 +779,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 +792,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 +804,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;
|
||||
@@ -813,6 +823,9 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "MTMSR: decrementer exception triggered");
|
||||
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
||||
} else if ((ppc_state.msr & MSR::EE) && thrm_exception_pending) {
|
||||
thrm_exception_pending = false;
|
||||
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
|
||||
} else if (ppc_state.msr & MSR::POW) [[unlikely]] {
|
||||
bool enter_sleep = false;
|
||||
|
||||
@@ -902,11 +915,11 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
static uint32_t decrementer_timer_id = 0;
|
||||
static TimerInfo decrementer_timer;
|
||||
|
||||
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
|
||||
|
||||
static void trigger_decrementer_exception() {
|
||||
static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
|
||||
if (ppc_state.msr & MSR::EE) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "decrementer exception triggered");
|
||||
@@ -918,8 +931,8 @@ static void trigger_decrementer_exception() {
|
||||
}
|
||||
}
|
||||
|
||||
static void trigger_timed_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
|
||||
decrementer_timer.active = 0;
|
||||
uint32_t new_val = calc_dec_value();
|
||||
if (new_val >= 0 && new_val != uint32_t(-1)) {
|
||||
new_val = -1;
|
||||
@@ -928,8 +941,8 @@ static void trigger_timed_decrementer_exception() {
|
||||
trigger_decrementer_exception();
|
||||
}
|
||||
|
||||
static void trigger_immediate_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
static void trigger_immediate_decrementer_exception(uint64_t, uint64_t) {
|
||||
decrementer_timer.active = 0;
|
||||
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
|
||||
trigger_decrementer_exception();
|
||||
}
|
||||
@@ -942,12 +955,12 @@ static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t
|
||||
|
||||
dec_exception_pending = false;
|
||||
|
||||
if (decrementer_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
|
||||
if (decrementer_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer);
|
||||
}
|
||||
|
||||
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
TimerManager::get_instance()->add_immediate_timer(decrementer_timer,
|
||||
trigger_immediate_decrementer_exception
|
||||
);
|
||||
return;
|
||||
@@ -967,12 +980,54 @@ static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t
|
||||
uint32_t time_out_lo;
|
||||
_u32xu64(newval, tbr_period_ns, time_out, time_out_lo);
|
||||
//LOG_F(WARNING, "new decrementer value: 0x%08X, interrupt after %llu ns", newval, time_out);
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(decrementer_timer,
|
||||
time_out,
|
||||
trigger_timed_decrementer_exception
|
||||
);
|
||||
}
|
||||
|
||||
static void update_thermal(uint64_t, uint64_t) {
|
||||
thermal_timer.active = 0;
|
||||
|
||||
uint32_t val = ppc_state.spr[SPR::THRM3];
|
||||
auto sampled_interval_timer_value = (val >> 1) & 0x1FFF;
|
||||
auto enabled = val & 1;
|
||||
|
||||
bool interrupt = false;
|
||||
for (int the_reg = 0; the_reg < 2; the_reg++) {
|
||||
val = ppc_state.spr[SPR::THRM1 + the_reg];
|
||||
uint32_t t_interrupt; // = (val >> 31) & 1;
|
||||
uint32_t t_int_valid; // = (val >> 30) & 1;
|
||||
uint32_t threshold = (val >> 23) & 0x7F;
|
||||
uint32_t t_int_direction = (val >> 2) & 1;
|
||||
uint32_t t_int_enable = (val >> 1) & 1;
|
||||
uint32_t valid = (val >> 0) & 1;
|
||||
|
||||
if (!valid) {
|
||||
t_interrupt = 0;
|
||||
t_int_valid = 0;
|
||||
} else {
|
||||
t_interrupt = t_int_direction ?
|
||||
junction_temperature < threshold
|
||||
:
|
||||
junction_temperature > threshold;
|
||||
t_int_valid = 1;
|
||||
interrupt |= t_int_enable && t_interrupt;
|
||||
}
|
||||
ppc_state.spr[SPR::THRM1 + the_reg] = (t_interrupt << 31) | (t_int_valid << 30) | (val & 0x3FFFFFFF);
|
||||
}
|
||||
|
||||
if (interrupt && enabled) {
|
||||
if (ppc_state.msr & MSR::EE) {
|
||||
thrm_exception_pending = false;
|
||||
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
|
||||
}
|
||||
else {
|
||||
thrm_exception_pending = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
ppc_grab_dab(opcode);
|
||||
uint32_t ref_spr = (reg_b << 5) | reg_a;
|
||||
@@ -991,12 +1046,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 +1063,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 +1073,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:
|
||||
@@ -1041,6 +1100,15 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
|
||||
break;
|
||||
}
|
||||
case SPR::THRM1:
|
||||
case SPR::THRM2: {
|
||||
uint32_t val = ppc_state.spr[ref_spr];
|
||||
ppc_state.gpr[reg_d] = val;
|
||||
break;
|
||||
}
|
||||
case SPR::THRM3:
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
break;
|
||||
default:
|
||||
// FIXME: Unknown SPR should be noop or illegal instruction.
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
@@ -1122,8 +1190,10 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case 533:
|
||||
case 534:
|
||||
case 535:
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
ibat_update(ref_spr);
|
||||
if (ppc_state.spr[ref_spr] != val) {
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
ibat_update(ref_spr);
|
||||
}
|
||||
break;
|
||||
case 536:
|
||||
case 537:
|
||||
@@ -1133,8 +1203,10 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case 541:
|
||||
case 542:
|
||||
case 543:
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
dbat_update(ref_spr);
|
||||
if (ppc_state.spr[ref_spr] != val) {
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
dbat_update(ref_spr);
|
||||
}
|
||||
break;
|
||||
case SPR::HID0:
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
@@ -1142,6 +1214,25 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
ppc_change_endian((val & 0x10000000) != 0);
|
||||
}
|
||||
break;
|
||||
case SPR::THRM1:
|
||||
case SPR::THRM2: {
|
||||
ppc_state.spr[ref_spr] = val & 0x3F800007;
|
||||
|
||||
if (thermal_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(thermal_timer);
|
||||
TimerManager::get_instance()->add_oneshot_timer(thermal_timer, USECS_TO_NSECS(20), update_thermal);
|
||||
break;
|
||||
}
|
||||
case SPR::THRM3: {
|
||||
ppc_state.spr[ref_spr] = val & 0x00003FFF;
|
||||
ppc_state.spr[SPR::THRM1] &= ~(3<<30);
|
||||
ppc_state.spr[SPR::THRM2] &= ~(3<<30);
|
||||
|
||||
if (thermal_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(thermal_timer);
|
||||
TimerManager::get_instance()->add_oneshot_timer(thermal_timer, USECS_TO_NSECS(20), update_thermal);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// FIXME: Unknown SPR should be noop or illegal instruction.
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
@@ -1503,14 +1594,18 @@ void dppc_interpreter::ppc_rfi(uint32_t opcode) {
|
||||
ppc_msr_did_change(ppc_state.msr, new_msr_val);
|
||||
|
||||
// setting MSR[EE] may enable pending exceptions
|
||||
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending)) {
|
||||
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending || thrm_exception_pending)) {
|
||||
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
|
||||
if (int_pin) // check for pending external exceptions (higher priority)
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
||||
else {
|
||||
else if (dec_exception_pending) {
|
||||
dec_exception_pending = false;
|
||||
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
||||
}
|
||||
else if (thrm_exception_pending) {
|
||||
thrm_exception_pending = false;
|
||||
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = save_srr0;
|
||||
return;
|
||||
}
|
||||
@@ -1606,12 +1701,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 +2164,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 +2186,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);
|
||||
@@ -2118,7 +2210,13 @@ void dppc_interpreter::ppc_tlbie(uint32_t opcode) {
|
||||
return;
|
||||
}
|
||||
|
||||
tlb_flush_entry(ppc_state.gpr[(opcode >> 11) & 0x1F]);
|
||||
// Ideally we would get the effective address via ppc_state.gpr[(opcode >> 11) & 0x1F]
|
||||
// and use that to identify entries to flush. But that is CPU-dependent (e.g.
|
||||
// on the 750 only bits 14-19 are used to find matching entries) and does not
|
||||
// map cleanly to the layout of our virtual TLB. The PowerPC specification
|
||||
// allows an implementation to be more lax and flush the entire TLB, so we
|
||||
// do that instead.
|
||||
tlb_flush_all_pat();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_tlbia(uint32_t opcode) {
|
||||
|
||||
+26
-10
@@ -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;
|
||||
@@ -1164,11 +1167,24 @@ void DppcDebugger::enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(0, [irq_bit](){
|
||||
static TimerInfo viaint_timer;
|
||||
TimerManager::get_instance()->add_oneshot_timer(viaint_timer, 0, [irq_bit](uint64_t, uint64_t){
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
via_obj->assert_int(irq_bit);
|
||||
});
|
||||
#endif
|
||||
} else if (cmd == "autograbmouse") {
|
||||
cmd = "";
|
||||
string value;
|
||||
int num;
|
||||
ss >> value;
|
||||
try {
|
||||
num = str2num(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
g_auto_grab_mouse = num;
|
||||
} else {
|
||||
if (!cmd.empty()) {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
|
||||
@@ -77,9 +77,6 @@ bool AdbAppleJack::get_register_0() {
|
||||
}
|
||||
|
||||
void AdbAppleJack::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Base class for Apple Desktop Bus devices. */
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
@@ -92,7 +93,8 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
this->set_register_2();
|
||||
break;
|
||||
case 3:
|
||||
this->set_register_3();
|
||||
if (this->host_obj->get_input_count() >= 2) // ensure we got enough data
|
||||
this->set_register_3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -107,6 +109,25 @@ bool AdbDevice::get_register_3() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbDevice::set_register_3() {
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
uint8_t new_addr = in_data[0] & 0xF;
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = new_addr;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = new_addr;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ADB Device: unknown handler ID = 0x%X", in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AdbDevice::gen_random_address() {
|
||||
return TimerManager::get_instance()->current_time_ns() & 0xF;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ protected:
|
||||
virtual void set_register_0() {}
|
||||
virtual void set_register_1() {}
|
||||
virtual void set_register_2() {}
|
||||
virtual void set_register_3() {}
|
||||
virtual void set_register_3();
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
|
||||
@@ -34,6 +34,7 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
}
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->keys_down.set(event.key, !(event.flags & KEYBOARD_EVENT_UP));
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
|
||||
if (this->pending_events.size() == 1) {
|
||||
@@ -46,8 +47,9 @@ void AdbKeyboard::reset() {
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 0; // don't process keyboard service requests yet
|
||||
this->led_state = 0; // LEDs off
|
||||
this->led_state = 7; // LEDs off (active low)
|
||||
this->pending_events.clear();
|
||||
this->keys_down.reset();
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_0() {
|
||||
@@ -92,9 +94,35 @@ uint8_t AdbKeyboard::consume_pending_event() {
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_2() {
|
||||
// Register 2 reflects the current modifier keys, and a zero value means
|
||||
// that the key is held down.
|
||||
static const struct {
|
||||
uint8_t key;
|
||||
uint8_t bit;
|
||||
} reg2_keys[] = {
|
||||
{ AdbKey_Delete, 14 },
|
||||
{ AdbKey_CapsLock, 13 },
|
||||
{ AdbKey_Power, 12 },
|
||||
{ AdbKey_Control, 11 },
|
||||
{ AdbKey_RightControl, 11 },
|
||||
{ AdbKey_Shift, 10 },
|
||||
{ AdbKey_RightShift, 10 },
|
||||
{ AdbKey_Option, 9 },
|
||||
{ AdbKey_RightOption, 9 },
|
||||
{ AdbKey_Command, 8 },
|
||||
{ AdbKey_KeypadClear, 7 },
|
||||
{ AdbKey_F14, 6 }, // Scroll Lock
|
||||
};
|
||||
|
||||
uint16_t reg2 = 0xFFF8 | this->led_state;
|
||||
for (const auto& key : reg2_keys) {
|
||||
if (this->keys_down[key.key])
|
||||
reg2 &= ~(1 << key.bit);
|
||||
}
|
||||
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = 0;
|
||||
out_buf[1] = this->led_state & 0x07;
|
||||
out_buf[0] = reg2 >> 8;
|
||||
out_buf[1] = reg2 & 0xFF;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
@@ -108,40 +136,18 @@ void AdbKeyboard::set_register_2() {
|
||||
this->led_state = in_data[1] & 0x07;
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 3: // extended keyboard protocol isn't supported yet
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
this->AdbDevice::set_register_3();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -47,13 +48,13 @@ public:
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_2() override;
|
||||
bool get_register_3() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
|
||||
private:
|
||||
std::deque<std::unique_ptr<KeyboardEvent>> pending_events;
|
||||
std::bitset<128> keys_down;
|
||||
|
||||
uint8_t consume_pending_event();
|
||||
};
|
||||
@@ -129,6 +130,7 @@ enum AdbKey {
|
||||
AdbKey_Option = 0x3a,
|
||||
AdbKey_Command = 0x37,
|
||||
AdbKey_CapsLock = 0x39,
|
||||
AdbKey_Power = 0x7f,
|
||||
|
||||
AdbKey_RightControl = 0x7d,
|
||||
AdbKey_RightShift = 0x7b,
|
||||
|
||||
@@ -142,28 +142,16 @@ bool AdbMouse::get_register_1() {
|
||||
}
|
||||
|
||||
void AdbMouse::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 4: // switch over to extended mouse protocol
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
this->AdbDevice::set_register_3();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +77,14 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
this->r_status &= ~DRQ;
|
||||
} else {
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
|
||||
if (!this->read_data_timer.active) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->read_data_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->read_data_timer.active = 0;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
@@ -121,17 +127,27 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
//LOG_F(INFO, "%s: write complete", name.c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
});
|
||||
if (this->write_done_timer.active)
|
||||
LOG_F(ERROR, "%s: write_done_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(write_done_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
write_done_timer.active = 0;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->signal_data_ready();
|
||||
});
|
||||
if (this->write_more_timer.active)
|
||||
LOG_F(ERROR, "%s: write_more_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->write_more_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->write_more_timer.active = 0;
|
||||
this->signal_data_ready();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +229,10 @@ int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
|
||||
if (!this->xfer_cnt) {
|
||||
this->is_dma_xfer = false;
|
||||
this->data_ptr = nullptr;
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
if (this->dma_pull_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_pull_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_pull_timer, 500, [this](uint64_t, uint64_t) {
|
||||
dma_pull_timer.active = 0;
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
@@ -240,7 +259,10 @@ int AtaBaseDevice::push_data(uint8_t *buf, int len) {
|
||||
this->is_dma_xfer = false;
|
||||
this->data_ptr = nullptr;
|
||||
this->cur_data_ptr = nullptr;
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
if (this->dma_push_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_push_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_push_timer, 500, [this](uint64_t, uint64_t) {
|
||||
dma_push_timer.active = 0;
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATA_BASE_DEVICE_H
|
||||
|
||||
#include <core/endianswap.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
@@ -108,6 +109,12 @@ protected:
|
||||
bool is_dma_xfer = false;
|
||||
|
||||
std::function<void()> post_xfer_action = nullptr;
|
||||
|
||||
TimerInfo read_data_timer;
|
||||
TimerInfo write_done_timer;
|
||||
TimerInfo write_more_timer;
|
||||
TimerInfo dma_pull_timer;
|
||||
TimerInfo dma_push_timer;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -289,7 +289,7 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
|
||||
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
|
||||
WRITE_WORD_LE_A(&buf_ptr[49], 0x0300); // report DMA and LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
@@ -307,8 +307,8 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
|
||||
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
|
||||
|
||||
// report validity for the advanced PIO and MWDMA fields
|
||||
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
|
||||
// report validity for the MWDMA fields
|
||||
WRITE_WORD_LE_A(&buf_ptr[53], 0x0002);
|
||||
|
||||
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
|
||||
|
||||
@@ -316,6 +316,8 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
|
||||
|
||||
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
|
||||
WRITE_WORD_LE_A(&buf_ptr[65], 120); // minimum MWDMA cycle time (ns)
|
||||
WRITE_WORD_LE_A(&buf_ptr[66], 120); // recommended MWDMA cycle time (ns)
|
||||
}
|
||||
|
||||
uint64_t AtaHardDisk::get_lba() {
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ATA_HARD_DISK_H
|
||||
#define ATA_HARD_DISK_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
@@ -74,6 +75,8 @@ private:
|
||||
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
|
||||
TimerInfo signal_ready_timer;
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
@@ -61,7 +71,8 @@ int AtapiCdrom::device_postinit() {
|
||||
|
||||
std::string cdr_image_path = GET_STR_PROP("cdr_img");
|
||||
if (!cdr_image_path.empty()) {
|
||||
this->insert_image(cdr_image_path);
|
||||
if (!this->insert_image(cdr_image_path))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -77,166 +88,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 +190,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 +314,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 = {
|
||||
|
||||
@@ -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->medium_present(); }
|
||||
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void perform_packet_command() override;
|
||||
|
||||
void set_lock_state(bool is_locked) override {
|
||||
this->drive_locked = is_locked ? 1 : 0;
|
||||
}
|
||||
|
||||
int get_config(uint8_t* pkt, uint8_t* buf) override;
|
||||
|
||||
int request_data() override;
|
||||
@@ -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;
|
||||
|
||||
@@ -91,8 +91,11 @@ int IdeChannel::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
|
||||
}
|
||||
|
||||
void IdeChannel::assert_dmareq(uint64_t delay) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
|
||||
if (this->dmareq_timer.active)
|
||||
LOG_F(WARNING, "%s: dmareq_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->dmareq_timer, delay, [this](uint64_t, uint64_t) {
|
||||
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
|
||||
this->dmareq_timer.active = false;
|
||||
this->channel_obj->xfer_retry();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef IDE_CHANNEL_H
|
||||
#define IDE_CHANNEL_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
@@ -74,6 +75,8 @@ private:
|
||||
AtaInterface* devices[2];
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
|
||||
TimerInfo dmareq_timer;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
|
||||
+44
-89
@@ -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>
|
||||
@@ -39,12 +40,6 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
void DMAChannel::set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb) {
|
||||
this->in_cb = in_cb;
|
||||
this->out_cb = out_cb;
|
||||
this->flush_cb = flush_cb;
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
@@ -99,14 +94,10 @@ void DMAChannel::interpret_cmd() {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
case DBDMA_Cmd::OUTPUT_LAST:
|
||||
this->xfer_to_device();
|
||||
if (this->out_cb)
|
||||
this->out_cb();
|
||||
break;
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
this->xfer_from_device();
|
||||
if (this->in_cb)
|
||||
this->in_cb();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -119,14 +110,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 +135,27 @@ void DMAChannel::interpret_cmd() {
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::interpret_until_blocked() {
|
||||
// Execute ready commands until a transfer is queued or the channel becomes idle/dead.
|
||||
while (this->is_active()) {
|
||||
this->interpret_cmd();
|
||||
if (this->cmd_in_progress)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::update_cmd() {
|
||||
if (this->cur_is_writable) {
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP)
|
||||
WRITE_WORD_LE_A(&this->cur_host->xfer_stat, this->ch_stat | CH_STAT_ACTIVE);
|
||||
|
||||
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::NOP)
|
||||
WRITE_WORD_LE_A(&this->cur_host->res_count, this->res_count);
|
||||
}
|
||||
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
|
||||
}
|
||||
|
||||
void DMAChannel::finish_cmd() {
|
||||
bool branch_taken = false;
|
||||
|
||||
@@ -186,17 +198,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;
|
||||
@@ -286,10 +290,13 @@ void DMAChannel::update_irq(uint8_t cmd_bits) {
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (int_ctrl) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
if (this->int_ctrl) {
|
||||
if (!this->interrupt_timer.active) {
|
||||
TimerManager::get_instance()->add_immediate_timer(this->interrupt_timer, [this](uint64_t, uint64_t) {
|
||||
this->interrupt_timer.active = 0;
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
}
|
||||
} else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
}
|
||||
@@ -338,7 +345,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->get_name().c_str());
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
value = BYTESWAP_32(value);
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
@@ -365,8 +372,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->ch_stat |= CH_STAT_FLUSH;
|
||||
if (this->dev_obj != nullptr)
|
||||
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;
|
||||
@@ -465,7 +471,7 @@ void DMAChannel::xfer_from_device() {
|
||||
this->get_name().c_str());
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
this->interpret_until_blocked();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_to_device() {
|
||||
@@ -482,7 +488,7 @@ void DMAChannel::xfer_to_device() {
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
this->interpret_until_blocked();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_retry() {
|
||||
@@ -515,9 +521,7 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get data or become idle
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
this->interpret_until_blocked();
|
||||
|
||||
// dequeue data if any
|
||||
if (this->queue_len) {
|
||||
@@ -550,9 +554,7 @@ DmaPushResult DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get buffer to fill in or become idle
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
this->interpret_until_blocked();
|
||||
|
||||
if (this->queue_len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
@@ -564,47 +566,12 @@ DmaPushResult DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
|
||||
// proceed with the DBDMA program if the buffer became exhausted
|
||||
if (!this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
this->interpret_until_blocked();
|
||||
}
|
||||
|
||||
return DmaPushResult::PushedData;
|
||||
}
|
||||
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (!this->is_active()) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::end_push_data() {
|
||||
if (!this->is_active()) {
|
||||
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
return this->is_active();
|
||||
}
|
||||
@@ -640,13 +607,7 @@ void DMAChannel::start() {
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
|
||||
// some DBDMA programs contain commands that don't transfer data
|
||||
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
|
||||
// We thus interprete the DBDMA program until a data transfer between
|
||||
// a device and memory is queued or the channel becomes idle/dead.
|
||||
while (!this->cmd_in_progress && this->is_active()) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
this->interpret_until_blocked();
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
@@ -658,13 +619,7 @@ void DMAChannel::resume() {
|
||||
|
||||
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
|
||||
|
||||
// some DBDMA programs contain commands that don't transfer data
|
||||
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
|
||||
// We thus interprete the DBDMA program until a data transfer between
|
||||
// a device and memory is queued or the channel becomes idle/dead.
|
||||
while (!this->cmd_in_progress && this->is_active()) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
this->interpret_until_blocked();
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DB_DMA_H
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -109,7 +110,6 @@ public:
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
void set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
@@ -125,10 +125,6 @@ public:
|
||||
bool is_in_active() override;
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
|
||||
DmaPushResult push_data(const char* src_ptr, int len) override;
|
||||
int get_pull_data_remaining() override { return this->queue_len; }
|
||||
int get_push_data_remaining() override { return this->queue_len; }
|
||||
void end_pull_data() override;
|
||||
void end_push_data() override;
|
||||
|
||||
bool dma_is_ready() override;
|
||||
void xfer_retry() override;
|
||||
@@ -141,6 +137,8 @@ public:
|
||||
protected:
|
||||
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
|
||||
void interpret_cmd(void);
|
||||
void interpret_until_blocked();
|
||||
void update_cmd();
|
||||
void finish_cmd();
|
||||
void xfer_quad(bool is_store);
|
||||
void update_irq(uint8_t cmd_bits);
|
||||
@@ -157,9 +155,6 @@ protected:
|
||||
private:
|
||||
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
||||
std::function<void(void)> in_cb = nullptr; // DMA channel in callback
|
||||
std::function<void(void)> out_cb = nullptr; // DMA channel out callback
|
||||
std::function<void(void)> flush_cb = nullptr; // DMA channel flush callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
@@ -179,6 +174,7 @@ private:
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
TimerInfo interrupt_timer;
|
||||
};
|
||||
|
||||
#endif // DB_DMA_H
|
||||
@@ -45,8 +45,6 @@ public:
|
||||
virtual bool is_out_active() { return true; }
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
virtual int get_pull_data_remaining() { return 1; }
|
||||
virtual void end_pull_data() {}
|
||||
|
||||
std::string get_name(void) { return this->name; }
|
||||
|
||||
@@ -60,8 +58,6 @@ public:
|
||||
|
||||
virtual bool is_in_active() { return true; }
|
||||
virtual DmaPushResult push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; }
|
||||
virtual void end_push_data() {}
|
||||
|
||||
std::string get_name(void) { return this->name; }
|
||||
|
||||
|
||||
@@ -51,10 +51,16 @@ int MeshController::device_postinit() {
|
||||
void MeshController::reset(bool is_hard_reset) {
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->fifo_pos = 0;
|
||||
this->to_xfer = 0;
|
||||
this->int_stat = 0;
|
||||
this->int_mask = 0;
|
||||
this->exception = 0;
|
||||
this->xfer_count = 0;
|
||||
this->src_id = 7;
|
||||
this->check_parity = true;
|
||||
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
|
||||
update_irq();
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
@@ -123,6 +129,7 @@ void MeshController::write(uint8_t reg_offset, uint8_t value) {
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
this->int_mask = value;
|
||||
update_irq();
|
||||
break;
|
||||
case MeshReg::Interrupt:
|
||||
this->int_stat &= ~(value & INT_MASK); // clear requested interrupt bits
|
||||
|
||||
@@ -78,7 +78,7 @@ void Sc53C94::reset_device()
|
||||
this->cur_step = 0;
|
||||
this->seq_step = 0;
|
||||
|
||||
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
|
||||
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
|
||||
this->int_status = 0;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ void Sc53C94::pseudo_dma_write(uint16_t data) {
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP) {
|
||||
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP && (cmd & CMD_OPCODE) != CMD_CLEAR_FIFO) {
|
||||
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -306,6 +306,7 @@ void Sc53C94::exec_command()
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_CLEAR_FIFO:
|
||||
this->on_reset = false; // unblock the command register
|
||||
this->data_fifo_pos = 0; // set the bottom of the data FIFO to zero
|
||||
this->data_fifo[0] = 0;
|
||||
exec_next_command();
|
||||
@@ -313,20 +314,21 @@ void Sc53C94::exec_command()
|
||||
case CMD_RESET_DEVICE:
|
||||
reset_device();
|
||||
this->on_reset = true; // block the command register
|
||||
this->update_irq();
|
||||
return;
|
||||
case CMD_RESET_BUS:
|
||||
LOG_F(INFO, "%s: resetting SCSI bus...", this->name.c_str());
|
||||
// assert RST line
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
// release RST line after 25 us
|
||||
if (my_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer_id);
|
||||
my_timer_id = 0;
|
||||
if (my_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer);
|
||||
my_timer.active = 0;
|
||||
}
|
||||
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(my_timer,
|
||||
USECS_TO_NSECS(25),
|
||||
[this]() {
|
||||
my_timer_id = 0;
|
||||
[this](uint64_t, uint64_t) {
|
||||
my_timer.active = 0;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & CFG1_DISR)) {
|
||||
@@ -475,25 +477,25 @@ uint8_t Sc53C94::fifo_pop()
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
if (this->seq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
if (this->seq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = 0;
|
||||
}
|
||||
|
||||
if (delay_ns) {
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
|
||||
delay_ns,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
} else {
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
[this]() {
|
||||
TimerManager::get_instance()->add_immediate_timer(this->seq_timer,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -708,8 +710,8 @@ void Sc53C94::notify(ScsiNotification notif_type, int param)
|
||||
case ScsiNotification::CONFIRM_SEL:
|
||||
if (this->target_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SC_53C94_H
|
||||
#define SC_53C94_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
|
||||
@@ -250,7 +251,7 @@ protected:
|
||||
private:
|
||||
uint8_t chip_id = 0;
|
||||
uint8_t my_bus_id = 0;
|
||||
uint32_t my_timer_id = 0;
|
||||
TimerInfo my_timer;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
uint8_t data_fifo[DATA_FIFO_MAX];
|
||||
@@ -278,7 +279,7 @@ private:
|
||||
uint8_t phase_latch = 0;
|
||||
|
||||
// sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
TimerInfo seq_timer;
|
||||
uint32_t cur_state = 0;
|
||||
uint32_t next_state = 0;
|
||||
SeqDesc* cmd_steps = nullptr;
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SCSI_H
|
||||
#define SCSI_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsiphysinterface.h>
|
||||
|
||||
@@ -175,6 +176,14 @@ enum ScsiCommand : uint8_t {
|
||||
READ_CD = 0xBE,
|
||||
};
|
||||
|
||||
/** START STOP UNIT command flags in CDB byte 4. */
|
||||
namespace ScsiStartStopUnit {
|
||||
enum : uint8_t {
|
||||
START = 1 << 0,
|
||||
LOAD_EJECT = 1 << 1,
|
||||
};
|
||||
}
|
||||
|
||||
enum ScsiSense : uint8_t {
|
||||
NO_SENSE = 0x0,
|
||||
RECOVERED = 0x1,
|
||||
@@ -200,8 +209,10 @@ enum ScsiError : uint8_t {
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
MEDIUM_CHANGED = 0x28,
|
||||
SAVING_NOT_SUPPORTED = 0x39,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
REMOVAL_PREVENTED = 0x53,
|
||||
};
|
||||
|
||||
/** SCSI device types used in INQUIRY. */
|
||||
@@ -248,7 +259,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 +318,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);
|
||||
@@ -359,6 +370,8 @@ protected:
|
||||
|
||||
more_data_cb_t read_more_data = {};
|
||||
more_data_cb_t write_more_data = {};
|
||||
|
||||
TimerInfo bus_settle_timer;
|
||||
};
|
||||
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
|
||||
@@ -30,8 +30,6 @@ ScsiBlockCmds::ScsiBlockCmds() {
|
||||
this->enable_cmd(ScsiCommand::WRITE_6);
|
||||
this->enable_cmd(ScsiCommand::WRITE_10);
|
||||
this->enable_cmd(ScsiCommand::WRITE_12);
|
||||
this->enable_cmd(ScsiCommand::VERIFY_6);
|
||||
this->enable_cmd(ScsiCommand::VERIFY_10);
|
||||
this->enable_cmd(ScsiCommand::START_STOP_UNIT);
|
||||
this->enable_cmd(ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL);
|
||||
this->enable_cmd(ScsiCommand::READ_CAPACITY);
|
||||
@@ -90,22 +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();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
case ScsiCommand::VERIFY_10:
|
||||
next_phase = this->verify_sector();
|
||||
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:
|
||||
@@ -119,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
|
||||
@@ -128,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();
|
||||
@@ -149,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
|
||||
@@ -158,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();
|
||||
@@ -184,60 +178,26 @@ int ScsiBlockCmds::write_new() {
|
||||
return ScsiPhase::DATA_OUT;
|
||||
}
|
||||
|
||||
int ScsiBlockCmds::verify_sector() {
|
||||
//TODO: implement the IMMED, BYTCMP, or FIXED bits
|
||||
|
||||
int nblocks = this->get_xfer_len();
|
||||
|
||||
// special case: zero transfer length means 256 blocks for VERIFY_6
|
||||
if (this->cdb_ptr[0] == ScsiCommand::VERIFY_6) {
|
||||
if (!nblocks)
|
||||
nblocks = 256;
|
||||
int ScsiBlockCmds::start_stop_unit() {
|
||||
if (this->cdb_ptr[4] & ScsiStartStopUnit::START) {
|
||||
if (this->cdb_ptr[4] & ScsiStartStopUnit::LOAD_EJECT)
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
|
||||
} else {
|
||||
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
|
||||
LOG_F(WARNING, "VERIFY: RelAdr bit set");
|
||||
this->set_field_pointer(1);
|
||||
this->set_bit_pointer(0);
|
||||
this->invalid_cdb();
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
if (this->cdb_ptr[4] & ScsiStartStopUnit::LOAD_EJECT)
|
||||
this->eject_medium();
|
||||
}
|
||||
|
||||
// go directly to the STATUS phase if nblocks = 0
|
||||
if (!nblocks) {
|
||||
LOG_F(WARNING, "VERIFY: skip because nblocks = 0");
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
auto lba = this->get_lba();
|
||||
auto size = this->blk_dev->get_size_in_blocks();
|
||||
|
||||
if (lba >= size || (uint64_t)lba + (uint64_t)nblocks > size) {
|
||||
LOG_F(WARNING, "VERIFY: out of range");
|
||||
this->invalid_cdb();
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
int ScsiBlockCmds::start_stop_unit() {
|
||||
if (this->cdb_ptr[4] & 1) {
|
||||
if (this->cdb_ptr[4] & 2)
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
|
||||
} else {
|
||||
if (this->cdb_ptr[4] & 2) {
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
|
||||
}
|
||||
}
|
||||
return ScsiPhase::STATUS;
|
||||
void ScsiBlockCmds::eject_medium() {
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -41,9 +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 verify_sector();
|
||||
virtual int read();
|
||||
virtual int write();
|
||||
virtual int start_stop_unit();
|
||||
virtual int read_capacity();
|
||||
|
||||
@@ -64,6 +63,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void process_command() override;
|
||||
virtual void eject_medium();
|
||||
|
||||
uint32_t get_lba();
|
||||
|
||||
|
||||
@@ -354,7 +354,8 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
if (!scsi_device->insert_image(path))
|
||||
ABORT_F("Could not insert CD-ROM image, %s", path.c_str());
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.",
|
||||
|
||||
@@ -31,10 +31,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
using namespace Scsi_Bus_Controller;
|
||||
|
||||
void ScsiBusController::seq_defer_state(uint64_t delay_ns) {
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
if (this->seq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
|
||||
delay_ns,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -170,8 +175,8 @@ void ScsiBusController::notify(ScsiNotification notif_type, int param) {
|
||||
case ScsiNotification::CONFIRM_SEL:
|
||||
if (this->dst_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = false;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SCSI_BUS_CTRL_H
|
||||
#define SCSI_BUS_CTRL_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
@@ -104,7 +105,7 @@ protected:
|
||||
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
TimerInfo seq_timer;
|
||||
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
int cur_bus_phase = 0;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -37,11 +37,14 @@ public:
|
||||
|
||||
virtual void process_command() override;
|
||||
|
||||
protected:
|
||||
bool is_device_ready() override { return this->is_ready; }
|
||||
void set_lock_state(bool is_locked) override {
|
||||
this->drive_locked = is_locked ? 1 : 0;
|
||||
ScsiPhysDevice::set_lock_state(is_locked);
|
||||
}
|
||||
|
||||
int get_apple_page_49(uint8_t subpage, uint8_t ctrl, uint8_t *out_ptr,
|
||||
int avail_len);
|
||||
protected:
|
||||
bool is_device_ready() override { return this->medium_present(); }
|
||||
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
|
||||
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
|
||||
@@ -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,31 @@ void ScsiCdromCmds::process_command() {
|
||||
phy_impl->switch_phase(next_phase);
|
||||
}
|
||||
|
||||
int ScsiCdromCmds:: read_toc_new() {
|
||||
int ScsiCdromCmds::test_unit_ready() {
|
||||
if (this->consume_media_change()) {
|
||||
this->sense_key = ScsiSense::UNIT_ATTENTION;
|
||||
this->asc = ScsiError::MEDIUM_CHANGED;
|
||||
this->ascq = 0;
|
||||
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
return ScsiCommonCmds::test_unit_ready();
|
||||
}
|
||||
|
||||
void ScsiCdromCmds::eject_medium() {
|
||||
if (this->drive_locked) {
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium eject prevented");
|
||||
this->field_ptr_valid = false;
|
||||
this->bit_ptr_valid = false;
|
||||
this->illegal_request(ScsiError::REMOVAL_PREVENTED, 2, false);
|
||||
} else {
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
|
||||
this->eject_image();
|
||||
}
|
||||
}
|
||||
|
||||
int ScsiCdromCmds:: read_toc() {
|
||||
uint8_t start_track, session_num;
|
||||
int tot_tracks, resp_len = 0;
|
||||
|
||||
@@ -212,3 +249,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;
|
||||
}
|
||||
@@ -35,8 +35,20 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void process_command() override;
|
||||
int test_unit_ready() override;
|
||||
void eject_medium() 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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -56,7 +56,7 @@ ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiPhysDevice(name, m
|
||||
}
|
||||
|
||||
void ScsiHardDisk::insert_image(std::string filename) {
|
||||
if (this->set_host_file(filename) < 0)
|
||||
if (!this->attach_image(filename))
|
||||
ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str());
|
||||
|
||||
this->is_writeable = true;
|
||||
@@ -177,7 +177,10 @@ void ScsiHardDisk::format() {
|
||||
if (this->cmd_buf[1] & 0x10)
|
||||
ABORT_F("%s: defect list isn't supported yet", this->name.c_str());
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(NS_PER_SEC, [this]() {
|
||||
if (this->phase_switch_timer.active)
|
||||
LOG_F(WARNING, "%s: phase_switch_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->phase_switch_timer, NS_PER_SEC, [this](uint64_t, uint64_t) {
|
||||
this->phase_switch_timer.active = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SCSI_HD_H
|
||||
#define SCSI_HD_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsiblockcmds.h>
|
||||
#include <devices/storage/blockstoragedevice.h>
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
void process_command() override;
|
||||
|
||||
protected:
|
||||
bool is_device_ready() override { return this->is_ready; }
|
||||
bool is_device_ready() override { return this->image_attached(); }
|
||||
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
@@ -55,6 +56,7 @@ protected:
|
||||
|
||||
private:
|
||||
uint8_t data_buf[2048] = {};
|
||||
TimerInfo phase_switch_timer;
|
||||
};
|
||||
|
||||
#endif // SCSI_HD_H
|
||||
@@ -31,15 +31,18 @@ void ScsiPhysDevice::notify(ScsiNotification notif_type, int param)
|
||||
if (notif_type == ScsiNotification::BUS_PHASE_CHANGE) {
|
||||
switch (param) {
|
||||
case ScsiPhase::RESET:
|
||||
LOG_F(9, "device %d: bus reset aknowledged", this->scsi_id);
|
||||
LOG_F(9, "device %d: bus reset acknowledged", this->scsi_id);
|
||||
break;
|
||||
case ScsiPhase::SELECTION:
|
||||
// check if something tries to select us
|
||||
if (this->bus_obj->get_data_lines() & (1 << scsi_id)) {
|
||||
LOG_F(9, "device %d selected", this->scsi_id);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
if (this->bus_settle_timer.active)
|
||||
LOG_F(ERROR, "%s: bus_settle_timer already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(bus_settle_timer,
|
||||
BUS_SETTLE_DELAY,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->bus_settle_timer.active = 0;
|
||||
// don't confirm selection if BSY or I/O are asserted
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+72
-56
@@ -36,11 +36,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static std::optional<uint32_t> rtc_start_time;
|
||||
static std::chrono::steady_clock::time_point rtc_start_host_time;
|
||||
|
||||
ViaCuda::ViaCuda() : I2CBus() {
|
||||
this->name = "ViaCuda";
|
||||
|
||||
@@ -99,21 +103,21 @@ ViaCuda::ViaCuda() : I2CBus() {
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_id = 0;
|
||||
if (this->sr_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer);
|
||||
this->sr_timer.active = 0;
|
||||
}
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
this->t1_timer.active = 0;
|
||||
}
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
this->t2_timer.active = 0;
|
||||
}
|
||||
if (this->treq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer_id);
|
||||
this->treq_timer_id = 0;
|
||||
if (this->treq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer);
|
||||
this->treq_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,9 +214,9 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
this->t1_timer.active = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
@@ -237,9 +241,9 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
this->t2_timer.active = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
@@ -250,10 +254,10 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->t2_timer,
|
||||
(this->via_clk_dur * (this->t2_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->t2_timer.active = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
@@ -304,12 +308,12 @@ void ViaCuda::activate_t1() {
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->t1_timer,
|
||||
(this->via_clk_dur * (this->t1_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// reload the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->t1_timer_id = 0;
|
||||
this->t1_timer.active = 0;
|
||||
this->assert_t1_int();
|
||||
if (this->via_acr & 0x40)
|
||||
this->activate_t1();
|
||||
@@ -382,14 +386,14 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
}
|
||||
|
||||
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_id = 0;
|
||||
if (this->sr_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer);
|
||||
this->sr_timer.active = 0;
|
||||
}
|
||||
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->sr_timer,
|
||||
timeout_ns,
|
||||
[this]() {
|
||||
this->sr_timer_id = 0;
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->sr_timer.active = 0;
|
||||
this->assert_sr_int();
|
||||
}
|
||||
);
|
||||
@@ -420,12 +424,14 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
process_packet();
|
||||
|
||||
// start response transaction
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
if (this->treq_timer.active)
|
||||
LOG_F(ERROR, "Cuda: treq_timer is already active");
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->treq_timer,
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
this->treq_timer.active = 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -618,7 +624,7 @@ void ViaCuda::autopoll_handler() {
|
||||
|
||||
// Don't send one-second packets if a command response is pending.
|
||||
// Unlike autopoll, time packets are not urgent enough to preempt.
|
||||
if (!this->treq || this->treq_timer_id || this->sr_timer_id) {
|
||||
if (!this->treq || this->treq_timer.active || this->sr_timer.active) {
|
||||
// ERS: track missed ticks for mode $02/$03 fallback
|
||||
if (this_time != this->last_time)
|
||||
this->one_sec_missed = true;
|
||||
@@ -790,7 +796,8 @@ void ViaCuda::pseudo_command() {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X SET_POWER_MESSAGES", cmd);
|
||||
this->power_messages_enabled = !!this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: power messages %s", this->power_messages_enabled ? "enabled" : "disabled");
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
@@ -798,7 +805,18 @@ void ViaCuda::pseudo_command() {
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
break;
|
||||
case CUDA_TIMER_TICKLE:
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X TIMER_TICKLE - Byte Sent: 0x%02x", cmd, this->in_buf[2]);
|
||||
// The guest re-arms the Cuda shutdown watchdog on every tickle; the
|
||||
// firmware counts it down at 16 counts/sec and powers the machine off
|
||||
// when it reaches zero. We track the count so an arm value change is
|
||||
// visible in the log, but never act on expiry to avoid spurious
|
||||
// power-offs if the guest stops tickling.
|
||||
if (this->tickle_value != this->in_buf[2]) {
|
||||
this->tickle_value = this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: timer tickle set to %d counts (%.1f s)", this->tickle_value,
|
||||
(double)this->tickle_value / 16.0);
|
||||
} else {
|
||||
LOG_F(9, "Cuda: timer tickle");
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_COMB_FMT_I2C:
|
||||
@@ -814,13 +832,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]);
|
||||
@@ -848,24 +864,24 @@ void ViaCuda::pseudo_command() {
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::set_start_time(std::chrono::local_seconds start_time)
|
||||
{
|
||||
// The Macintosh RTC counts local calendar seconds since January 1, 1904.
|
||||
auto mac_epoch = std::chrono::local_days{std::chrono::year{1904}/1/1};
|
||||
rtc_start_time = uint32_t((start_time - mac_epoch).count());
|
||||
rtc_start_host_time = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
uint32_t ViaCuda::calc_real_time() {
|
||||
std::chrono::time_point<std::chrono::system_clock> end;
|
||||
if (is_deterministic) {
|
||||
// March 24, 2001 was the public release date of Mac OS X.
|
||||
std::tm tm = {
|
||||
.tm_sec = 0,
|
||||
.tm_min = 0,
|
||||
.tm_hour = 12,
|
||||
.tm_mday = 24,
|
||||
.tm_mon = 3 - 1,
|
||||
.tm_year = 2001 - 1900,
|
||||
.tm_isdst = 0
|
||||
};
|
||||
end = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
} else {
|
||||
end = std::chrono::system_clock::now();
|
||||
if (rtc_start_time) {
|
||||
// We still want to advance time in deterministic mode, but tie it to
|
||||
// virtual time so that it's reproducible.
|
||||
uint64_t elapsed_seconds = is_deterministic ? get_virt_time_ns() / NS_PER_SEC :
|
||||
std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::steady_clock::now() - rtc_start_host_time).count();
|
||||
return uint32_t(*rtc_start_time + elapsed_seconds);
|
||||
}
|
||||
auto elapsed_systemclock = end - this->mac_epoch;
|
||||
auto elapsed_systemclock = std::chrono::system_clock::now() - this->mac_epoch;
|
||||
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
|
||||
return uint32_t(elapsed_seconds.count());
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
@@ -172,6 +173,10 @@ public:
|
||||
return std::unique_ptr<ViaCuda>(new ViaCuda());
|
||||
}
|
||||
|
||||
// Configure the initial RTC from a fixed time. If not set the current
|
||||
// wall time is used.
|
||||
static void set_start_time(std::chrono::local_seconds start_time);
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
@@ -198,20 +203,20 @@ private:
|
||||
uint32_t via_clk_freq; // 0.00078336 VIA clock periods per ns; 0 integer bits, 42 fraction bits (first 10 are implicit zeros)
|
||||
|
||||
// VIA internal state
|
||||
uint32_t sr_timer_id = 0;
|
||||
TimerInfo sr_timer;
|
||||
uint8_t last_orb = 0; // last value written to the ORB register.
|
||||
|
||||
// timer 1 state
|
||||
uint8_t via_t1ll; // low-order latch
|
||||
uint8_t via_t1lh; // high-order latch
|
||||
uint16_t t1_counter; // internal counter
|
||||
uint32_t t1_timer_id = 0;
|
||||
TimerInfo t1_timer;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
uint8_t via_t2ll; // low-order latch (write-only)
|
||||
uint16_t t2_counter; // internal counter
|
||||
uint32_t t2_timer_id = 0;
|
||||
TimerInfo t2_timer;
|
||||
uint64_t t2_start_time = 0;
|
||||
|
||||
// VIA interrupt related stuff
|
||||
@@ -225,7 +230,7 @@ private:
|
||||
uint8_t old_byteack;
|
||||
uint8_t treq;
|
||||
bool is_sync_state = false;
|
||||
uint32_t treq_timer_id = 0;
|
||||
TimerInfo treq_timer;
|
||||
uint8_t in_buf[CUDA_IN_BUF_SIZE];
|
||||
int32_t in_count;
|
||||
int max_in_count = 0;
|
||||
@@ -239,8 +244,10 @@ private:
|
||||
uint8_t one_sec_mode = 0;
|
||||
bool one_sec_first_pkt = true; // ERS: first one-sec pkt always mode $01
|
||||
bool one_sec_missed = false; // ERS: missed pkt -> fallback to mode $01
|
||||
bool file_server = false;
|
||||
bool mono_stable = false;
|
||||
bool file_server = false;
|
||||
bool mono_stable = false;
|
||||
bool power_messages_enabled = false;
|
||||
uint8_t tickle_value = 0; // last shutdown watchdog count from the guest
|
||||
uint8_t ipl_level = 0;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
|
||||
+35
-28
@@ -70,17 +70,17 @@ void Swim3Ctrl::reset()
|
||||
this->timer_val = 0;
|
||||
this->phase_lines = 0;
|
||||
|
||||
if (this->one_us_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer_id);
|
||||
this->one_us_timer_id = 0;
|
||||
if (this->one_us_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer);
|
||||
this->one_us_timer.active = 0;
|
||||
}
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 0;
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
this->step_timer.active = 0;
|
||||
}
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
this->access_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,8 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
return this->phase_lines;
|
||||
case Swim3Reg::Setup:
|
||||
return this->setup_reg;
|
||||
case Swim3Reg::Status_Mode0:
|
||||
return this->mode_reg;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & SWIM3_DRIVE_1) { // internal drive?
|
||||
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
|
||||
@@ -237,7 +239,7 @@ void Swim3Ctrl::do_step()
|
||||
// instruct the drive to perform single step in current direction
|
||||
this->int_drive->command(MacSuperdrive::CommandAddr::Do_Step, 0);
|
||||
if (--this->step_count == 0) {
|
||||
if (this->step_timer_id) {
|
||||
if (this->step_timer.active) {
|
||||
this->stop_stepping();
|
||||
}
|
||||
this->int_flags |= INT_STEP_DONE;
|
||||
@@ -253,12 +255,12 @@ void Swim3Ctrl::start_stepping()
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer.active) {
|
||||
LOG_F(ERROR, "SWIM3: another stepping action is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer.active) {
|
||||
LOG_F(ERROR, "SWIM3: stepping attempt while disk access is in progress!");
|
||||
return;
|
||||
}
|
||||
@@ -273,9 +275,9 @@ void Swim3Ctrl::start_stepping()
|
||||
|
||||
// step count > 1 requires periodic task
|
||||
if (this->step_count > 1) {
|
||||
this->step_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->step_timer,
|
||||
USECS_TO_NSECS(80),
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->do_step();
|
||||
}
|
||||
);
|
||||
@@ -288,21 +290,21 @@ void Swim3Ctrl::start_stepping()
|
||||
void Swim3Ctrl::stop_stepping()
|
||||
{
|
||||
// cancel stepping task
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 0;
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
this->step_timer.active = 0;
|
||||
}
|
||||
this->step_count = 0; // not sure this one is required
|
||||
}
|
||||
|
||||
void Swim3Ctrl::start_disk_access()
|
||||
{
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer.active) {
|
||||
LOG_F(ERROR, "SWIM3: another disk access is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer.active) {
|
||||
LOG_F(ERROR, "SWIM3: disk access attempt while stepping is in progress!");
|
||||
return;
|
||||
}
|
||||
@@ -317,9 +319,10 @@ void Swim3Ctrl::start_disk_access()
|
||||
|
||||
this->target_sect = this->first_sec;
|
||||
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
this->int_drive->sync_to_disk(),
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->access_timer.active = 0;
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
this->disk_access();
|
||||
}
|
||||
@@ -369,9 +372,10 @@ void Swim3Ctrl::disk_access()
|
||||
return;
|
||||
}
|
||||
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
delay,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->access_timer.active = 0;
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
@@ -380,9 +384,9 @@ void Swim3Ctrl::disk_access()
|
||||
void Swim3Ctrl::stop_disk_access()
|
||||
{
|
||||
// cancel disk access timer
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
this->access_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,9 +403,12 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
|
||||
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
|
||||
|
||||
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
if( this->one_us_timer.active)
|
||||
LOG_F(ERROR, "SWIM3: one_us_timer is already active");
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->one_us_timer,
|
||||
uint32_t(this->timer_val) * NS_PER_USEC,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->one_us_timer.active = 0;
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
update_irq();
|
||||
|
||||
@@ -140,9 +140,9 @@ private:
|
||||
uint8_t rd_line;
|
||||
int cur_state;
|
||||
|
||||
int one_us_timer_id = 0;
|
||||
int step_timer_id = 0;
|
||||
int access_timer_id = 0;
|
||||
TimerInfo one_us_timer;
|
||||
TimerInfo step_timer;
|
||||
TimerInfo access_timer;
|
||||
|
||||
uint64_t one_us_timer_start = 0;
|
||||
|
||||
|
||||
@@ -96,9 +96,9 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
AMIC::~AMIC()
|
||||
{
|
||||
if (this->pseudo_vbl_tid) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_tid);
|
||||
this->pseudo_vbl_tid = 0;
|
||||
if (this->pseudo_vbl_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_timer);
|
||||
this->pseudo_vbl_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +113,9 @@ int AMIC::device_postinit()
|
||||
}
|
||||
|
||||
// AMIC drives the VIA CA1 internally to generate 60.15 Hz interrupts
|
||||
this->pseudo_vbl_tid = TimerManager::get_instance()->add_cyclic_timer(
|
||||
TimerManager::get_instance()->add_cyclic_timer(pseudo_vbl_timer,
|
||||
static_cast<uint64_t>((1.0f/60.15) * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->viacuda->assert_ctrl_line(ViaLine::CA1);
|
||||
});
|
||||
|
||||
@@ -635,7 +635,10 @@ void AmicSndOutDma::update_irq() {
|
||||
uint8_t new_level = !!((this->dma_out_ctrl >> 4) & this->dma_out_ctrl);
|
||||
if (new_level != this->irq_level) {
|
||||
this->irq_level = new_level;
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
if (this->interrupt_timer.active)
|
||||
LOG_F(ERROR, "AMIC: interrupt_timer is already active");
|
||||
TimerManager::get_instance()->add_immediate_timer(interrupt_timer, [this](uint64_t, uint64_t) {
|
||||
interrupt_timer.active = 0;
|
||||
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef AMIC_H
|
||||
#define AMIC_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
@@ -133,6 +134,7 @@ private:
|
||||
InterruptCtrl *int_ctrl = nullptr;
|
||||
uint64_t snd_dma_irq_id = 0;
|
||||
uint8_t irq_level = 0;
|
||||
TimerInfo interrupt_timer;
|
||||
};
|
||||
|
||||
/** AMIC-specific floppy DMA implementation. */
|
||||
@@ -411,7 +413,7 @@ private:
|
||||
uint8_t via2_slot_ifr = 0x7F; // reverse logic
|
||||
uint8_t via2_slot_irq = 0; // normal logic
|
||||
|
||||
uint32_t pseudo_vbl_tid = 0; // ID for the pseudo-VBL timer
|
||||
TimerInfo pseudo_vbl_timer; // the pseudo-VBL timer
|
||||
|
||||
// AMIC subdevice instances
|
||||
Sc53C94* scsi;
|
||||
|
||||
@@ -295,7 +295,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
} else { // Interrupt related registers
|
||||
switch (offset) {
|
||||
case MIO_INT_EVENTS1:
|
||||
return BYTESWAP_32(this->int_events);
|
||||
return BYTESWAP_32(this->int_events & this->int_mask);
|
||||
case MIO_INT_MASK1:
|
||||
return BYTESWAP_32(this->int_mask);
|
||||
case MIO_INT_CLEAR1:
|
||||
@@ -303,7 +303,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
// so we return zero here as real HW does
|
||||
return 0;
|
||||
case MIO_INT_LEVELS1:
|
||||
return BYTESWAP_32(this->int_levels);
|
||||
return BYTESWAP_32(this->int_levels | (1<<0x0B));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ uint32_t MacIoTwo::mio_ctrl_read(uint32_t offset, int size) {
|
||||
|
||||
switch (offset & ~3) {
|
||||
case MIO_INT_EVENTS2:
|
||||
value = this->int_events >> 32;
|
||||
value = (this->int_events & this->int_mask) >> 32;
|
||||
break;
|
||||
case MIO_INT_MASK2:
|
||||
value = this->int_mask >> 32;
|
||||
@@ -300,7 +300,7 @@ uint32_t MacIoTwo::mio_ctrl_read(uint32_t offset, int size) {
|
||||
value = this->int_levels >> 32;
|
||||
break;
|
||||
case MIO_INT_EVENTS1:
|
||||
value = uint32_t(this->int_events);
|
||||
value = uint32_t(this->int_events & this->int_mask);
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
value = uint32_t(this->int_mask);
|
||||
|
||||
@@ -70,8 +70,10 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
};
|
||||
this->dacula->set_clut_entry_cb = [this](uint8_t index, uint8_t *colors) {
|
||||
this->set_palette_color(index, colors[0], colors[1], colors[2], 0xFF);
|
||||
this->draw_fb = true;
|
||||
};
|
||||
this->dacula->cursor_ctrl_cb = [this](bool cursor_on) {
|
||||
this->draw_fb = true;
|
||||
if (cursor_on) {
|
||||
this->dacula->measure_hw_cursor(this->fb_ptr - 16);
|
||||
this->cursor_ovl_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
@@ -82,6 +84,14 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
this->cursor_ovl_cb = nullptr;
|
||||
}
|
||||
};
|
||||
this->dacula->cursor_update_cb = [this]() {
|
||||
this->draw_fb = true;
|
||||
};
|
||||
this->dacula->video_mode_ctrl_cb = [this]() {
|
||||
this->change_display();
|
||||
};
|
||||
|
||||
this->draw_fb_is_dynamic = true;
|
||||
}
|
||||
|
||||
int PlatinumCtrl::device_postinit() {
|
||||
@@ -215,9 +225,10 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
uint8_t mon_levels = 0;
|
||||
|
||||
if (rgn_start == VRAM_REGION_BASE) {
|
||||
if (offset < this->vram_size)
|
||||
if (offset < this->vram_size) {
|
||||
this->draw_fb = true;
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
else
|
||||
} else
|
||||
LOG_F(WARNING, "%s: write to unmapped aperture address 0x%X",
|
||||
this->name.c_str(), this->fb_addr + offset);
|
||||
return;
|
||||
@@ -514,16 +525,19 @@ void PlatinumCtrl::enable_display() {
|
||||
switch (this->pixel_depth) {
|
||||
case 8:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_8bpp_indexed(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
case 16:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_15bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
case 32:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_32bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
@@ -564,6 +578,7 @@ void PlatinumCtrl::enable_display() {
|
||||
|
||||
this->blank_on = false;
|
||||
this->crtc_on = true;
|
||||
this->draw_fb = true;
|
||||
}
|
||||
|
||||
void PlatinumCtrl::disable_display() {
|
||||
@@ -586,12 +601,12 @@ void PlatinumCtrl::enable_cursor_int() {
|
||||
LOG_F(INFO, "%s: cursor interrupt frequency %lld ns", this->name.c_str(),
|
||||
cursor_int_freq);
|
||||
|
||||
if (this->cursor_task_id)
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_task_id);
|
||||
if (this->cursor_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
|
||||
this->cursor_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->cursor_timer,
|
||||
cursor_int_freq,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->update_irq(1, SWATCH_INT_CURSOR); // generate cursor interrupt
|
||||
}
|
||||
);
|
||||
|
||||
@@ -363,7 +363,7 @@ private:
|
||||
uint32_t swatch_int_mask = 0;
|
||||
uint32_t swatch_int_stat = 0;
|
||||
uint32_t cursor_line = 0;
|
||||
uint32_t cursor_task_id = 0;
|
||||
TimerInfo cursor_timer;
|
||||
|
||||
std::unique_ptr<uint8_t[]> vram_ptr = nullptr;
|
||||
std::unique_ptr<DisplayID> display_id = nullptr;
|
||||
|
||||
@@ -114,11 +114,13 @@ void AwacsBase::dma_in_data() {
|
||||
dbdma_ch->set_stat(sound_in_status);
|
||||
LOG_F(INFO, "%s: status:%x", this->name.c_str(), sound_in_status);
|
||||
|
||||
this->dma_in_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
if (this->dma_in_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_in_timer is already active", this->name.c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->dma_in_timer,
|
||||
10000,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->dma_in_timer_id = 0;
|
||||
this->dma_in_timer.active = 0;
|
||||
this->dma_in_data();
|
||||
});
|
||||
}
|
||||
@@ -130,9 +132,9 @@ void AwacsBase::dma_in_start() {
|
||||
}
|
||||
|
||||
void AwacsBase::dma_in_stop() {
|
||||
if (this->dma_in_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->dma_in_timer_id);
|
||||
this->dma_in_timer_id = 0;
|
||||
if (this->dma_in_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->dma_in_timer);
|
||||
this->dma_in_timer.active = 0;
|
||||
}
|
||||
LOG_F(ERROR, "%s: dma_in_stop", this->name.c_str());
|
||||
}
|
||||
@@ -199,7 +201,7 @@ uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size) {
|
||||
(AWAC_REV_SCREAMER << 20);
|
||||
break;
|
||||
case AWAC_CLIP_COUNT:
|
||||
value = this->clip_count;
|
||||
value = this->clip_count;
|
||||
this->clip_count = 0;
|
||||
break;
|
||||
case AWAC_BYTE_SWAP:
|
||||
@@ -221,7 +223,6 @@ void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
this->set_sample_rate((this->snd_ctrl_reg >> 8) & 7);
|
||||
break;
|
||||
|
||||
case AWAC_CODEC_CTRL_REG: {
|
||||
if (this->is_busy)
|
||||
return;
|
||||
|
||||
@@ -66,7 +66,7 @@ protected:
|
||||
SoundServer *snd_server; // SoundServer instance pointer
|
||||
DmaOutChannel *dma_out_ch; // DMA output channel instance pointer
|
||||
DmaInChannel *dma_in_ch; // DMA input channel instance pointer
|
||||
uint32_t dma_in_timer_id = 0;
|
||||
TimerInfo dma_in_timer;
|
||||
|
||||
int *sr_table; // pointer to the table of supported sample rates
|
||||
int max_sr_id; // maximum value for sample rate ID
|
||||
|
||||
+65
-28
@@ -28,8 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/sound/burgundy.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
BurgundyCodec::BurgundyCodec(std::string name) : MacioSndCodec(name)
|
||||
{
|
||||
BurgundyCodec::BurgundyCodec(std::string name) : MacioSndCodec(name) {
|
||||
supports_types(HWCompType::SND_CODEC);
|
||||
|
||||
static int burgundy_sample_rates[1] = { 44100 };
|
||||
@@ -39,59 +38,97 @@ BurgundyCodec::BurgundyCodec(std::string name) : MacioSndCodec(name)
|
||||
this->max_sr_id = 1;
|
||||
|
||||
this->set_sample_rate(0); // set default sample rate
|
||||
|
||||
this->reg_array[0x01] = 0x01010000; // ID 1 (Burgundy), Vendor 1 (Crystal), Version 0, Revision 0
|
||||
}
|
||||
|
||||
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 =
|
||||
(
|
||||
(
|
||||
9 |
|
||||
CODEC_STATUS::SENSE_MIC |
|
||||
CODEC_STATUS::SENSE_HEADPHONES
|
||||
) << CODEC_STATUS::SENSE_POS
|
||||
) |
|
||||
(this->data_byte << CODEC_STATUS::DATA_POS) |
|
||||
(this->read_pos << CODEC_STATUS::CURRENTBYTE_POS) |
|
||||
(this->byte_counter << CODEC_STATUS::BYTECOUNTER_POS) |
|
||||
(0 << CODEC_STATUS::INDICATOR_POS) |
|
||||
CODEC_STATUS::READY |
|
||||
(this->first_valid ? CODEC_STATUS::FIRST_VALID_BYTE : 0);
|
||||
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) {
|
||||
uint8_t reg_addr;
|
||||
uint8_t cur_byte;
|
||||
//uint8_t last_byte;
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = value;
|
||||
//this->set_sample_rate((this->snd_ctrl_reg & SOUND_CONTROL::RATE_MASK) >> SOUND_CONTROL::RATE_POS);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
this->last_ctrl_data = value;
|
||||
reg_addr = (value >> 12) & 0xFF;
|
||||
cur_byte = (value >> 8) & 3;
|
||||
//last_byte = (value >> 10) & 3;
|
||||
if (value & BURGUNDY_REG_WR) {
|
||||
uint32_t mask = 0xFFU << (cur_byte * 8);
|
||||
this->reg_array[reg_addr] = (this->reg_array[reg_addr] & ~mask) |
|
||||
((value & 0xFFU) << (cur_byte * 8));
|
||||
{
|
||||
this->last_ctrl_data = value & ~CODEC_CONTROL::BUSY;
|
||||
uint8_t write_byte = (value & CODEC_CONTROL::DATA_MASK) >> CODEC_CONTROL::DATA_POS;
|
||||
uint8_t reg_addr = (value & CODEC_CONTROL::ADDR_MASK) >> CODEC_CONTROL::ADDR_POS;
|
||||
uint8_t cur_byte = (value & CODEC_CONTROL::CURRENTBYTE_MASK) >> CODEC_CONTROL::CURRENTBYTE_POS;
|
||||
uint8_t last_byte = (value & CODEC_CONTROL::LASTBYTE_MASK) >> CODEC_CONTROL::LASTBYTE_POS;
|
||||
bool reset = value & CODEC_CONTROL::RESET;
|
||||
bool write = value & CODEC_CONTROL::WRITE;
|
||||
if (write) {
|
||||
if (reg_addr < BURGUNDY_NUM_REGS) {
|
||||
uint32_t mask = 0xFFU << (cur_byte * 8);
|
||||
this->reg_array[reg_addr] = (this->reg_array[reg_addr] & ~mask) |
|
||||
(write_byte << (cur_byte * 8));
|
||||
}
|
||||
} else {
|
||||
this->reg_addr = reg_addr;
|
||||
this->read_pos = cur_byte;
|
||||
this->data_byte = (this->reg_array[reg_addr] >> (cur_byte * 8)) & 0xFFU;
|
||||
this->first_valid = 1;
|
||||
this->reg_addr = reg_addr;
|
||||
this->read_pos = cur_byte;
|
||||
this->data_byte = ((reg_addr < BURGUNDY_NUM_REGS ? this->reg_array[reg_addr] : 0) >> (cur_byte * 8)) & 0xFFU;
|
||||
this->first_valid = true;
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(10), // not sure if this is the correct delay
|
||||
[this]() {
|
||||
this->first_valid = 0;
|
||||
if (this->first_valid_timer.active)
|
||||
LOG_F(ERROR, "%s: first_valid_timer is already active", this->name.c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->first_valid_timer,
|
||||
USECS_TO_NSECS(22), // average is approximately 22.6 µs on a real B&W G3
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->first_valid_timer.active = 0;
|
||||
this->first_valid = false;
|
||||
this->byte_counter = (this->byte_counter + 1) & 3;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AWAC_FRAME_COUNT:
|
||||
this->frame_count = 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);
|
||||
|
||||
@@ -24,20 +24,91 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef BURGUNDY_H
|
||||
#define BURGUNDY_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
BURGUNDY_REG_WR = 1 << 21,
|
||||
BURGUNDY_READY = 1 << 22,
|
||||
};
|
||||
|
||||
/** Number of internal registers implemented in Burgundy. */
|
||||
constexpr auto BURGUNDY_NUM_REGS = 123;
|
||||
|
||||
namespace SOUND_CONTROL { // 0x00
|
||||
enum {
|
||||
INSUBFRAME_MASK = 0x0000000F,
|
||||
INSUBFRAME_POS = 0,
|
||||
INSUBFRAME0 = 0x1,
|
||||
INSUBFRAME1 = 0x2,
|
||||
INSUBFRAME2 = 0x4,
|
||||
INSUBFRAME3 = 0x8,
|
||||
OUTSUBFRAME_MASK = 0x000000F0,
|
||||
OUTSUBFRAME_POS = 4,
|
||||
OUTSUBFRAME0 = 0x1,
|
||||
OUTSUBFRAME1 = 0x2,
|
||||
OUTSUBFRAME2 = 0x4,
|
||||
OUTSUBFRAME3 = 0x8,
|
||||
RATE_MASK = 0x00000700,
|
||||
RATE_POS = 8,
|
||||
RATE_44100 = 0x0,
|
||||
ERROR = 0x00000800,
|
||||
PORTCHANGE = 0x00001000,
|
||||
ERRORINT = 0x00002000,
|
||||
STATUSSUBFRAME_MASK = 0x00018000,
|
||||
STATUSSUBFRAME_POS = 15,
|
||||
STATUSSUBFRAME0 = 0x0,
|
||||
STATUSSUBFRAME1 = 0x1,
|
||||
STATUSSUBFRAME2 = 0x2,
|
||||
STATUSSUBFRAME3 = 0x3,
|
||||
};
|
||||
}
|
||||
|
||||
namespace CODEC_CONTROL { // 0x10
|
||||
enum {
|
||||
DATA_MASK = 0x000000FF,
|
||||
DATA_POS = 0,
|
||||
CURRENTBYTE_MASK = 0x00000300,
|
||||
CURRENTBYTE_POS = 8,
|
||||
LASTBYTE_MASK = 0x00000C00,
|
||||
LASTBYTE_POS = 10,
|
||||
ADDR_MASK = 0x000FF000,
|
||||
ADDR_POS = 12,
|
||||
RESET = 0x00100000, // should be set when current byte is 0
|
||||
WRITE = 0x00200000, // READ = 0
|
||||
BUSY = 0x01000000, // set when writing to CODEC_CONTROL, clear when done
|
||||
};
|
||||
}
|
||||
|
||||
namespace CODEC_STATUS { // 0x20
|
||||
enum {
|
||||
SENSE_MASK = 0x0000000F,
|
||||
SENSE_POS = 0,
|
||||
SENSE_MIC = 0x2,
|
||||
SENSE_HEADPHONES = 0x4,
|
||||
SENSE_HEADPHONES2 = 0x8, // 1 = line level mic (default) 0 = powered mic
|
||||
DATA_MASK = 0x00000FF0,
|
||||
DATA_POS = 4,
|
||||
CURRENTBYTE_MASK = 0x00003000,
|
||||
CURRENTBYTE_POS = 12,
|
||||
BYTECOUNTER_MASK = 0x0000C000,
|
||||
BYTECOUNTER_POS = 14,
|
||||
INDICATOR_MASK = 0x000F0000,
|
||||
INDICATOR_POS = 16,
|
||||
INDICATOR_TONECONTROL = 0x1,
|
||||
INDICATOR_OVERFLOW0 = 0x2,
|
||||
INDICATOR_OVERFLOW1 = 0x3,
|
||||
INDICATOR_OVERFLOW2 = 0x4,
|
||||
INDICATOR_INPUTLINECHG = 0x6,
|
||||
INDICATOR_THRESHOLD0 = 0xB,
|
||||
INDICATOR_THRESHOLD1 = 0xC,
|
||||
INDICATOR_THRESHOLD2 = 0xD,
|
||||
INDICATOR_THRESHOLD3 = 0xE,
|
||||
INDICATOR_TWILIGHTCMP = 0xF,
|
||||
READY = 0x00400000,
|
||||
FIRST_VALID_BYTE = 0x00800000, // wait for set, then wait for clear before reading data
|
||||
};
|
||||
}
|
||||
|
||||
class BurgundyCodec : public MacioSndCodec {
|
||||
public:
|
||||
BurgundyCodec(std::string name);
|
||||
@@ -51,12 +122,16 @@ 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;
|
||||
bool first_valid = false;
|
||||
TimerInfo first_valid_timer;
|
||||
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] = {};
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
cubeb *cubeb_ctx;
|
||||
cubeb_stream *out_stream;
|
||||
|
||||
uint32_t deterministic_poll_timer = 0;
|
||||
TimerInfo deterministic_poll_timer;
|
||||
timer_cb deterministic_poll_cb;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -167,23 +167,26 @@ static void status_callback(cubeb_stream *stream, void *user_data, cubeb_state s
|
||||
|
||||
int SoundServer::open_out_stream(uint32_t sample_rate, DmaOutChannel *dma_ch)
|
||||
{
|
||||
// Set up a cyclic-timer DMA drain callback. It keeps the guest sound DMA
|
||||
// advancing even if the host audio stream cannot be started, otherwise
|
||||
// the guest sound driver would stall forever waiting for DMA interrupts.
|
||||
impl->deterministic_poll_cb = [dma_ch](uint64_t, uint64_t) {
|
||||
if (!dma_ch->is_out_active()) {
|
||||
return;
|
||||
}
|
||||
// Drain the DMA buffer, but don't do anything else.
|
||||
while(1) {
|
||||
uint8_t *chunk;
|
||||
uint32_t chunk_size;
|
||||
if (DmaPullResult::MoreData == dma_ch->pull_data(1024, &chunk_size, &chunk)) {
|
||||
;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (is_deterministic) {
|
||||
impl->deterministic_poll_cb = [dma_ch] {
|
||||
if (!dma_ch->is_out_active()) {
|
||||
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) {
|
||||
uint8_t *chunk;
|
||||
uint32_t chunk_size;
|
||||
if (!dma_ch->pull_data(req_size, &chunk_size, &chunk)) {
|
||||
req_size -= chunk_size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
impl->status = SND_STREAM_OPENED;
|
||||
LOG_F(9, "Deterministic sound output callback set up.");
|
||||
return 0;
|
||||
@@ -225,20 +228,31 @@ int SoundServer::start_out_stream()
|
||||
{
|
||||
if (is_deterministic) {
|
||||
LOG_F(9, "Starting sound output deterministic polling.");
|
||||
impl->deterministic_poll_timer =
|
||||
TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
impl->deterministic_poll_timer, MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
|
||||
return 0;
|
||||
}
|
||||
return cubeb_stream_start(impl->out_stream);
|
||||
int res = cubeb_stream_start(impl->out_stream);
|
||||
if (res != CUBEB_OK) {
|
||||
// Fall back to draining the guest sound DMA via a cyclic timer so
|
||||
// that the guest sound driver does not stall waiting for DMA progress
|
||||
// that the failed host stream will never provide.
|
||||
if (!impl->deterministic_poll_timer.active) {
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
impl->deterministic_poll_timer, MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
|
||||
LOG_F(9, "Host sound output stream start failed; falling back to cyclic DMA drain.");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void SoundServer::close_out_stream()
|
||||
{
|
||||
if (!impl->out_stream)
|
||||
return;
|
||||
if (is_deterministic) {
|
||||
LOG_F(9, "Stopping sound output deterministic polling.");
|
||||
if (impl->deterministic_poll_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(impl->deterministic_poll_timer);
|
||||
impl->deterministic_poll_timer.active = 0;
|
||||
}
|
||||
if (!impl->out_stream) {
|
||||
impl->status = SND_STREAM_CLOSED;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,22 +39,45 @@ BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks,
|
||||
}
|
||||
|
||||
BlockStorageDevice::~BlockStorageDevice() {
|
||||
this->img_file.close();
|
||||
this->detach_image();
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_host_file(std::string file_path) {
|
||||
this->is_ready = false;
|
||||
|
||||
bool BlockStorageDevice::attach_image(const std::string& file_path) {
|
||||
if (!this->img_file.open(file_path))
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
this->size_bytes = this->img_file.size();
|
||||
this->is_ready = false;
|
||||
this->size_bytes = this->img_file.size();
|
||||
this->remain_size = 0;
|
||||
this->write_size = 0;
|
||||
this->data_offset = 0;
|
||||
|
||||
this->set_fpos(0);
|
||||
|
||||
this->is_ready = true;
|
||||
|
||||
return this->set_block_size(this->block_size);
|
||||
if (this->set_block_size(this->block_size) < 0) {
|
||||
this->detach_image();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BlockStorageDevice::detach_image() {
|
||||
if (!this->is_ready)
|
||||
return false;
|
||||
|
||||
this->is_ready = false;
|
||||
this->img_file.close();
|
||||
|
||||
this->size_bytes = 0;
|
||||
this->size_blocks = 0;
|
||||
this->cur_fpos = 0;
|
||||
this->write_size = 0;
|
||||
this->remain_size = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_block_size(const int blk_size) {
|
||||
|
||||
@@ -36,7 +36,10 @@ public:
|
||||
const uint64_t max_blocks=UINT64_MAX);
|
||||
~BlockStorageDevice();
|
||||
|
||||
int set_host_file(std::string file_path);
|
||||
bool attach_image(const std::string& file_path);
|
||||
bool detach_image();
|
||||
bool image_attached() const { return this->is_ready; }
|
||||
|
||||
int set_block_size(const int blk_size);
|
||||
|
||||
int set_fpos(const uint64_t lba);
|
||||
|
||||
+51
-293
@@ -21,8 +21,7 @@ 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 <core/hostevents.h>
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
@@ -31,12 +30,46 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
CdromDrive::CdromDrive() : BlockStorageDevice(31, CDR_STD_DATA_SIZE, 0xfffffffe) {
|
||||
EventManager::get_instance()->add_cdrom_handler(
|
||||
this, &CdromDrive::insert_image_event_handler);
|
||||
|
||||
this->is_writeable = false;
|
||||
}
|
||||
|
||||
void CdromDrive::insert_image(std::string filename) {
|
||||
if (this->set_host_file(filename) < 0)
|
||||
ABORT_F("Could not open CD-ROM image file, %s", filename.c_str());
|
||||
void CdromDrive::insert_image_event_handler(CdromImageEvent& event) {
|
||||
if (event.handled)
|
||||
return;
|
||||
|
||||
if (this->medium_present()) {
|
||||
event.result = CdromInsertionResult::MEDIA_PRESENT;
|
||||
return;
|
||||
}
|
||||
|
||||
event.handled = true;
|
||||
if (this->insert_image(event.image_path)) {
|
||||
this->media_change_pending = true;
|
||||
event.result = CdromInsertionResult::SUCCESS;
|
||||
} else {
|
||||
event.result = CdromInsertionResult::IMAGE_OPEN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
bool CdromDrive::consume_media_change() {
|
||||
bool pending = this->media_change_pending;
|
||||
this->media_change_pending = false;
|
||||
return pending;
|
||||
}
|
||||
|
||||
bool CdromDrive::insert_image(const std::string& filename) {
|
||||
if (this->medium_present()) {
|
||||
LOG_F(ERROR, "Cannot insert CD-ROM image while media is present");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->attach_image(filename)) {
|
||||
LOG_F(ERROR, "Could not open CD-ROM image file, %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
this->detect_raw_image();
|
||||
|
||||
@@ -47,6 +80,19 @@ void CdromDrive::insert_image(std::string filename) {
|
||||
// create Lead-out descriptor containing all data
|
||||
this->tracks[1] = {LEAD_OUT_TRK_NUM, /*.trk_num*/ 0x14, /*.adr_ctrl*/
|
||||
static_cast<uint32_t>(this->size_blocks + 1) /*.start_lba*/};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CdromDrive::eject_image() {
|
||||
if (!this->detach_image())
|
||||
return false;
|
||||
|
||||
this->num_tracks = 0;
|
||||
this->media_change_pending = false;
|
||||
std::memset(this->tracks, 0, sizeof(this->tracks));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CdromDrive::detect_raw_image() {
|
||||
@@ -72,152 +118,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 +130,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;
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -48,34 +74,46 @@ constexpr auto CDROM_MAX_TRACKS = 100;
|
||||
constexpr auto LEAD_OUT_TRK_NUM = 0xAA;
|
||||
constexpr auto CDR_STD_DATA_SIZE = 2048;
|
||||
|
||||
class CdromImageEvent;
|
||||
|
||||
class CdromDrive : public BlockStorageDevice {
|
||||
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() const { return this->image_attached(); }
|
||||
|
||||
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);
|
||||
bool insert_image(const std::string& filename);
|
||||
bool eject_image();
|
||||
|
||||
protected:
|
||||
std::function<void(uint8_t, uint8_t)> set_error;
|
||||
void insert_image_event_handler(CdromImageEvent& event);
|
||||
bool consume_media_change();
|
||||
|
||||
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
|
||||
bool media_change_pending = false; // pending guest notification
|
||||
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
|
||||
@@ -83,48 +83,65 @@ void AppleRamdac::iodev_write(uint32_t address, uint16_t value) {
|
||||
(this->clut_color[1] << 8) | this->clut_color[2];
|
||||
this->dac_addr++; // auto-increment CLUT address
|
||||
this->comp_index = 0;
|
||||
this->cursor_update_cb();
|
||||
}
|
||||
break;
|
||||
case RamdacRegs::MULTI:
|
||||
switch (this->dac_addr) {
|
||||
case RamdacRegs::CURSOR_POS_HI:
|
||||
#ifdef CURSOR_LO_DELAY // HACK: prevents artifacts in some cases, disabled by default
|
||||
if (this->cursor_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer_id);
|
||||
cursor_timer_id = 0;
|
||||
if (this->cursor_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
cursor_timer.active = 0;
|
||||
}
|
||||
this->cursor_xpos = (value << 8) | this->cursor_pos_lo;
|
||||
#else
|
||||
this->cursor_xpos = (value << 8) | (this->cursor_xpos & 0xff);
|
||||
#endif
|
||||
this->cursor_update_cb();
|
||||
break;
|
||||
case RamdacRegs::CURSOR_POS_LO:
|
||||
#ifdef CURSOR_LO_DELAY // HACK: prevents artifacts in some cases, disabled by default
|
||||
if (this->cursor_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer_id);
|
||||
if (this->cursor_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
cursor_timer_id = 0;
|
||||
cursor_timer.active = 0;
|
||||
}
|
||||
this->cursor_pos_lo = value;
|
||||
this->cursor_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
NS_PER_SEC / 60, [this]() {
|
||||
this->cursor_pos_lo = value;
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->cursor_timer,
|
||||
NS_PER_SEC / 60, [this](uint64_t, uint64_t) {
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
});
|
||||
cursor_timer.active = 0;
|
||||
this->cursor_update_cb();
|
||||
}
|
||||
);
|
||||
#else
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (value & 0x00ff);
|
||||
#endif
|
||||
this->cursor_update_cb();
|
||||
break;
|
||||
case RamdacRegs::MISC_CTRL:
|
||||
case RamdacRegs::MISC_CTRL: {
|
||||
if (bit_changed(this->dac_cr, value, 1)) {
|
||||
if (value & 2)
|
||||
this->cursor_ctrl_cb(true);
|
||||
else
|
||||
this->cursor_ctrl_cb(false);
|
||||
}
|
||||
int old_pix_width = this->get_pix_width();
|
||||
int old_clock_div = this->get_clock_div();
|
||||
this->dac_cr = value;
|
||||
int new_pix_width = this->get_pix_width();
|
||||
if (old_pix_width != new_pix_width || old_clock_div != this->get_clock_div()) {
|
||||
this->video_mode_ctrl_cb();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RamdacRegs::DBL_BUF_CTRL:
|
||||
this->dbl_buf_cr = value;
|
||||
if (this->dbl_buf_cr != value) {
|
||||
this->dbl_buf_cr = value;
|
||||
if (this->buffer_update_cb)
|
||||
this->buffer_update_cb();
|
||||
}
|
||||
break;
|
||||
case RamdacRegs::TEST_CTRL:
|
||||
this->tst_cr = value;
|
||||
|
||||
@@ -91,6 +91,7 @@ enum RamdacRegs : uint8_t {
|
||||
typedef std::function<void(uint8_t index, uint8_t *colors)> GetClutEntryCallback;
|
||||
typedef std::function<void(uint8_t index, uint8_t *colors)> SetClutEntryCallback;
|
||||
typedef std::function<void(bool cursor_on)> CursorCtrlCallback;
|
||||
typedef std::function<void()> VideoModeCtrlCallback;
|
||||
|
||||
class AppleRamdac : public HWComponent, public IobusDevice {
|
||||
public:
|
||||
@@ -117,6 +118,9 @@ public:
|
||||
GetClutEntryCallback get_clut_entry_cb = nullptr;
|
||||
SetClutEntryCallback set_clut_entry_cb = nullptr;
|
||||
CursorCtrlCallback cursor_ctrl_cb = nullptr;
|
||||
std::function<void()> cursor_update_cb = nullptr;
|
||||
std::function<void()> buffer_update_cb = nullptr;
|
||||
VideoModeCtrlCallback video_mode_ctrl_cb = nullptr;
|
||||
|
||||
protected:
|
||||
DacFlavour flavour;
|
||||
@@ -139,7 +143,7 @@ protected:
|
||||
uint32_t fb_pitch = 0;
|
||||
#ifdef CURSOR_LO_DELAY
|
||||
uint8_t cursor_pos_lo = 0;
|
||||
uint32_t cursor_timer_id = 0;
|
||||
TimerInfo cursor_timer;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+349
-55
@@ -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());
|
||||
@@ -409,7 +443,9 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
|
||||
bits_read_only |= bits_not_AKed; // the not AKed bits will remain unchanged
|
||||
|
||||
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
|
||||
break;
|
||||
WRITE_VALUE_AND_LOG(9);
|
||||
this->update_interrupt();
|
||||
return;
|
||||
}
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
new_value = value;
|
||||
@@ -578,12 +614,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;
|
||||
@@ -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
@@ -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;
|
||||
|
||||
+126
-39
@@ -48,6 +48,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// Big-endian VRAM aperture select bit; clear for the little-endian aperture.
|
||||
// See Apple patent US5793996A, cols. 17-18.
|
||||
constexpr uint32_t VRAM_BE_APERTURE = 0x800000;
|
||||
|
||||
namespace loguru {
|
||||
enum : Verbosity {
|
||||
Verbosity_RADACAL = loguru::Verbosity_INFO,
|
||||
@@ -118,8 +122,10 @@ ControlVideo::ControlVideo()
|
||||
};
|
||||
this->radacal->set_clut_entry_cb = [this](uint8_t index, uint8_t *colors) {
|
||||
this->set_palette_color(index, colors[0], colors[1], colors[2], 0xFF);
|
||||
this->draw_fb = true;
|
||||
};
|
||||
this->radacal->cursor_ctrl_cb = [this](bool cursor_on) {
|
||||
this->draw_fb = true;
|
||||
if (cursor_on) {
|
||||
this->radacal->measure_hw_cursor(this->fb_ptr - 16);
|
||||
this->cursor_ovl_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
@@ -130,6 +136,20 @@ ControlVideo::ControlVideo()
|
||||
this->cursor_ovl_cb = nullptr;
|
||||
}
|
||||
};
|
||||
this->radacal->cursor_update_cb = [this]() {
|
||||
this->draw_fb = true;
|
||||
};
|
||||
this->radacal->buffer_update_cb = [this]() {
|
||||
this->draw_fb = true;
|
||||
if (this->display_enabled) {
|
||||
this->update_fb_ptr();
|
||||
}
|
||||
};
|
||||
this->radacal->video_mode_ctrl_cb = [this]() {
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
};
|
||||
|
||||
// attach IOBus Device #2 0xF301B000 ; register RaDACal with the I/O controller
|
||||
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentralTnt"));
|
||||
@@ -137,6 +157,8 @@ ControlVideo::ControlVideo()
|
||||
|
||||
// initialize display identification
|
||||
this->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
|
||||
this->draw_fb_is_dynamic = true;
|
||||
}
|
||||
|
||||
void ControlVideo::change_one_bar(uint32_t &aperture, uint32_t aperture_size, uint32_t aperture_new, int bar_num) {
|
||||
@@ -216,7 +238,7 @@ static const char * get_name_controlreg(int offset) {
|
||||
uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
if (rgn_start == this->vram_base) {
|
||||
if (offset & 0x800000) { // repeats every 16MB
|
||||
if (offset & VRAM_BE_APERTURE) { // repeats every 16MB
|
||||
// HACK: writing to VRAM in 128bit mode with only the standard
|
||||
// bank populated seems to replicate the first 64bit portion of data
|
||||
// in the second 64bit portion. This "feature" is used by
|
||||
@@ -276,9 +298,38 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
} // if not VRAM_WIDE_MODE
|
||||
}
|
||||
|
||||
LOG_F(ERROR, "%s: read from little-endian aperture address 0x%X", this->name.c_str(),
|
||||
this->vram_base + offset);
|
||||
return 0;
|
||||
// Little-endian aperture, reverse bytes within each 16/32-bit pixel.
|
||||
uint32_t value;
|
||||
int pixel_width = this->radacal->get_pix_width();
|
||||
switch (pixel_width) {
|
||||
case 8:
|
||||
return this->read(rgn_start, offset | VRAM_BE_APERTURE, size);
|
||||
case 16:
|
||||
if (offset & (size - 1)) // unaligned access, handled below
|
||||
break;
|
||||
value = this->read(rgn_start,
|
||||
(offset ^ (size == 1 ? 1 : 0)) | VRAM_BE_APERTURE, size);
|
||||
if (size == 2)
|
||||
return BYTESWAP_16(value);
|
||||
if (size == 4)
|
||||
return (uint32_t(BYTESWAP_16(value >> 16)) << 16) | BYTESWAP_16(value);
|
||||
return value;
|
||||
case 32:
|
||||
if (offset & (size - 1)) // unaligned access, handled below
|
||||
break;
|
||||
value = this->read(rgn_start, (offset ^ (4 - size)) | VRAM_BE_APERTURE, size);
|
||||
return size == 4 ? BYTESWAP_32(value) : size == 2 ? BYTESWAP_16(value) : value;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported pixel width %d for little-endian VRAM read",
|
||||
this->name.c_str(), pixel_width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unaligned accesses can straddle pixels or VRAM banks. Split them
|
||||
// into smaller accesses so each uses the correct byte lanes.
|
||||
int half_size = size >> 1;
|
||||
return (this->read(rgn_start, offset, half_size) << (half_size * 8)) |
|
||||
this->read(rgn_start, offset + half_size, half_size);
|
||||
}
|
||||
|
||||
if (rgn_start == this->regs_base) {
|
||||
@@ -362,7 +413,8 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (rgn_start == this->vram_base) {
|
||||
if (offset & 0x800000) {
|
||||
this->draw_fb = true;
|
||||
if (offset & VRAM_BE_APERTURE) {
|
||||
if (this->enables & VRAM_WIDE_MODE) {
|
||||
// Note: we ignore access to 4MB range at 0xC00000 because it is undefined for VRAM_WIDE_MODE.
|
||||
// There is data there but it is not in the same order as the first 4MB.
|
||||
@@ -417,9 +469,36 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
}
|
||||
} // switch
|
||||
} // if not VRAM_WIDE_MODE
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: write to little-endian aperture address 0x%X", this->name.c_str(),
|
||||
this->vram_base + offset);
|
||||
} else { // little-endian aperture
|
||||
int pixel_width = this->radacal->get_pix_width();
|
||||
switch (pixel_width) {
|
||||
case 8:
|
||||
return this->write(rgn_start, offset | VRAM_BE_APERTURE, value, size);
|
||||
case 16:
|
||||
if (offset & (size - 1)) // unaligned access, handled below
|
||||
break;
|
||||
offset ^= size == 1 ? 1 : 0;
|
||||
if (size == 2)
|
||||
value = BYTESWAP_16(value);
|
||||
else if (size == 4)
|
||||
value = (uint32_t(BYTESWAP_16(value >> 16)) << 16) | BYTESWAP_16(value);
|
||||
return this->write(rgn_start, offset | VRAM_BE_APERTURE, value, size);
|
||||
case 32:
|
||||
if (offset & (size - 1)) // unaligned access, handled below
|
||||
break;
|
||||
offset ^= 4 - size;
|
||||
value = size == 4 ? BYTESWAP_32(value) : size == 2 ? BYTESWAP_16(value) : value;
|
||||
return this->write(rgn_start, offset | VRAM_BE_APERTURE, value, size);
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported pixel width %d for little-endian VRAM write",
|
||||
this->name.c_str(), pixel_width);
|
||||
return;
|
||||
}
|
||||
|
||||
// Split unaligned accesses as in the read path.
|
||||
int half_size = size >> 1;
|
||||
this->write(rgn_start, offset, value >> (half_size * 8), half_size);
|
||||
this->write(rgn_start, offset + half_size, value, half_size);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -517,12 +596,11 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
}
|
||||
break;
|
||||
case ControlRegs::MON_SENSE: {
|
||||
if (value & ~0x3F)
|
||||
LOG_F(ERROR, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
else
|
||||
LOG_F(9, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
// This is a nine-bit register (bits 6-8 are read-only sense
|
||||
// inputs that can be written back). Log unexpected values.
|
||||
VLOG_F((value & ~0x1FF) ? loguru::Verbosity_ERROR : 9,
|
||||
"%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
uint8_t dirs = ((value >> 3) & 7) ^ 7;
|
||||
uint8_t levels = ((value & 7) & dirs) | (dirs ^ 7);
|
||||
this->mon_sense = value & 0x3F;
|
||||
@@ -531,6 +609,7 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
break;
|
||||
case ControlRegs::MISC_ENABLES:
|
||||
if ((this->enables ^ value) & BLANK_DISABLE) {
|
||||
this->draw_fb = true;
|
||||
if (value & BLANK_DISABLE)
|
||||
this->blank_on = false;
|
||||
else {
|
||||
@@ -570,6 +649,31 @@ uint8_t* ControlVideo::GetVram()
|
||||
return &this->vram_ptr[0];
|
||||
}
|
||||
|
||||
void ControlVideo::update_fb_ptr()
|
||||
{
|
||||
this->fb_ptr = &this->vram_ptr[this->fb_base];
|
||||
if (swatch_params[ControlRegs::HAL-1] != swatch_params[ControlRegs::PIPE_DELAY-1] + 1 ||
|
||||
this->pixel_depth == 32 ||
|
||||
(this->pixel_depth == 16 && this->active_width == 1280)
|
||||
) {
|
||||
// don't know how to calculate offset from GBASE (fb_base); it is always hard coded as + 16 in the ndrv.
|
||||
this->fb_ptr += 16; // first 16 bytes are for 4 bpp HW cursor
|
||||
}
|
||||
else {
|
||||
/*
|
||||
Open Firmware frame buffer has these properties:
|
||||
- GBASE == 0 // no offset from vram_ptr
|
||||
- fb_ptr == vram_ptr // no offset from GBASE
|
||||
- active_width == ROW_WORDS (row_words) // no offset between rows
|
||||
- HAL == PIPE_DELAY + 1
|
||||
- depth_mode = 0 // 8 bit indexed
|
||||
*/
|
||||
}
|
||||
if (this->radacal->get_dbl_buf_cr() == 0 && this->vram_banks == 3) {
|
||||
this->fb_ptr += 0x200000;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlVideo::enable_display()
|
||||
{
|
||||
int new_width, new_height, clk_divisor;
|
||||
@@ -592,49 +696,30 @@ void ControlVideo::enable_display()
|
||||
this->active_width = new_width;
|
||||
this->active_height = new_height;
|
||||
|
||||
// set framebuffer parameters
|
||||
this->fb_ptr = &this->vram_ptr[this->fb_base];
|
||||
this->fb_pitch = this->row_words;
|
||||
if (~this->enables & SCAN_CONTROL) {
|
||||
this->fb_pitch >>= 1;
|
||||
}
|
||||
|
||||
this->pixel_depth = this->radacal->get_pix_width();
|
||||
if (swatch_params[ControlRegs::HAL-1] != swatch_params[ControlRegs::PIPE_DELAY-1] + 1 ||
|
||||
this->pixel_depth == 32 ||
|
||||
(this->pixel_depth == 16 && this->active_width == 1280)
|
||||
) {
|
||||
// don't know how to calculate offset from GBASE (fb_base); it is always hard coded as + 16 in the ndrv.
|
||||
this->fb_ptr += 16; // first 16 bytes are for 4 bpp HW cursor
|
||||
}
|
||||
else {
|
||||
/*
|
||||
Open Firmware frame buffer has these properties:
|
||||
- GBASE == 0 // no offset from vram_ptr
|
||||
- fb_ptr == vram_ptr // no offset from GBASE
|
||||
- active_width == ROW_WORDS (row_words) // no offset between rows
|
||||
- HAL == PIPE_DELAY + 1
|
||||
- depth_mode = 0 // 8 bit indexed
|
||||
*/
|
||||
}
|
||||
if (this->radacal->get_dbl_buf_cr() == 0 && this->vram_banks == 3) {
|
||||
this->fb_ptr += 0x200000;
|
||||
}
|
||||
|
||||
// get pixel depth from RaDACal
|
||||
this->pixel_depth = this->radacal->get_pix_width();
|
||||
this->update_fb_ptr();
|
||||
|
||||
switch (this->pixel_depth) {
|
||||
case 8:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_8bpp_indexed(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
case 16:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_15bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
case 32:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->draw_fb = false;
|
||||
this->convert_frame_32bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
@@ -682,6 +767,8 @@ void ControlVideo::enable_display()
|
||||
this->blank_on = true;
|
||||
this->crtc_on = false;
|
||||
}
|
||||
|
||||
this->draw_fb = true;
|
||||
}
|
||||
|
||||
void ControlVideo::disable_display()
|
||||
|
||||
@@ -131,6 +131,7 @@ protected:
|
||||
|
||||
void enable_display();
|
||||
void disable_display();
|
||||
void update_fb_ptr();
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
@@ -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;
|
||||
@@ -304,7 +310,7 @@ void Display::handle_events(const WindowEvent& wnd_event) {
|
||||
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
if (wnd_event.window_id == impl->disp_wnd_id) {
|
||||
SDL_RenderPresent(impl->renderer);
|
||||
video_ctrl->set_draw_fb();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -189,11 +189,12 @@ void ValkyrieVideo::disable_video_internal() {
|
||||
}
|
||||
|
||||
void ValkyrieVideo::schedule_mode_switch() {
|
||||
if (this->mode_timer_id)
|
||||
TimerManager::get_instance()->cancel_timer(this->mode_timer_id);
|
||||
if (this->mode_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(this->mode_timer);
|
||||
|
||||
this->mode_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
MSECS_TO_NSECS(3), [this] {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->mode_timer,
|
||||
MSECS_TO_NSECS(3), [this](uint64_t, uint64_t) {
|
||||
this->mode_timer.active = 0;
|
||||
this->enable_video_internal();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ private:
|
||||
uint8_t *vram_ptr = nullptr;
|
||||
int reg_shift = 3;
|
||||
|
||||
uint64_t mode_timer_id = 0;
|
||||
TimerInfo mode_timer;
|
||||
|
||||
void disable_video_internal();
|
||||
void enable_video_internal();
|
||||
|
||||
+10
-10
@@ -102,9 +102,9 @@ void VideoCtrlBase::start_refresh_task() {
|
||||
this->display.configure(this->active_width, this->active_height);
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->refresh_timer,
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// assert VBL interrupt
|
||||
this->vbl_cb(1);
|
||||
this->update_screen();
|
||||
@@ -117,10 +117,10 @@ void VideoCtrlBase::start_refresh_task() {
|
||||
}
|
||||
|
||||
uint64_t vbl_duration = static_cast<uint64_t>((double)hori_total * vert_blank / this->pixel_clock * NS_PER_SEC + 0.5);
|
||||
this->vbl_end_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
TimerManager::get_instance()-> add_cyclic_timer(this->vbl_end_timer,
|
||||
refresh_interval,
|
||||
refresh_interval + vbl_duration,
|
||||
[this]() {
|
||||
[this](uint64_t, uint64_t) {
|
||||
// deassert VBL interrupt
|
||||
this->vbl_cb(0);
|
||||
}
|
||||
@@ -128,13 +128,13 @@ void VideoCtrlBase::start_refresh_task() {
|
||||
}
|
||||
|
||||
void VideoCtrlBase::stop_refresh_task() {
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
this->refresh_task_id = 0;
|
||||
if (this->refresh_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_timer);
|
||||
this->refresh_timer.active = 0;
|
||||
}
|
||||
if (this->vbl_end_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id);
|
||||
this->vbl_end_task_id = 0;
|
||||
if (this->vbl_end_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_timer);
|
||||
this->vbl_end_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIDEO_CTRL_H
|
||||
#define VIDEO_CTRL_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/video/display.h>
|
||||
|
||||
@@ -113,8 +114,8 @@ protected:
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr = nullptr;
|
||||
int fb_pitch = 0;
|
||||
uint32_t refresh_task_id = 0;
|
||||
uint32_t vbl_end_task_id = 0;
|
||||
TimerInfo refresh_timer;
|
||||
TimerInfo vbl_end_timer;
|
||||
|
||||
// interrupt suff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
|
||||
@@ -29,14 +29,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <debugger/debugger.h>
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <utils/profiler.h>
|
||||
#include <main.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <CLI11.hpp>
|
||||
@@ -49,9 +52,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
extern bool g_auto_grab_mouse;
|
||||
extern bool g_swap_command_option;
|
||||
|
||||
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) {
|
||||
@@ -62,7 +67,7 @@ static void sigabrt_handler(int signum) {
|
||||
}
|
||||
|
||||
static string appDescription = string(
|
||||
"\nDingusPPC - Alpha 1.04b (7/26/2026) "
|
||||
"\nDingusPPC - Alpha 1.04c (10/4/2026) "
|
||||
"\nWritten by divingkatae, maximumspatium, "
|
||||
"\njoevt, mihaip, kkaisershot, et. al. "
|
||||
"\n(c) 2018-2026 The DingusPPC Dev Team. "
|
||||
@@ -73,6 +78,44 @@ static string appDescription = string(
|
||||
|
||||
static uint32_t keyboard_id = 0;
|
||||
|
||||
static std::optional<std::chrono::year_month_day> parse_calendar_date(const std::string& value)
|
||||
{
|
||||
if (value.size() != 10 || value[4] != '-' || value[7] != '-')
|
||||
return std::nullopt;
|
||||
for (size_t i = 0; i < value.size(); i++) {
|
||||
if (i != 4 && i != 7 && (value[i] < '0' || value[i] > '9'))
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::chrono::year_month_day date{
|
||||
std::chrono::year{std::stoi(value.substr(0, 4))},
|
||||
std::chrono::month{unsigned(std::stoi(value.substr(5, 2)))},
|
||||
std::chrono::day{unsigned(std::stoi(value.substr(8, 2)))}
|
||||
};
|
||||
if (!date.ok() || int(date.year()) == 0)
|
||||
return std::nullopt;
|
||||
return date;
|
||||
}
|
||||
|
||||
static std::optional<std::chrono::local_seconds> parse_start_date(std::string value, bool is_deterministic)
|
||||
{
|
||||
if (value.empty()) {
|
||||
if (!is_deterministic)
|
||||
return std::nullopt;
|
||||
// March 24, 2001 was the public release date of Mac OS X.
|
||||
value = "2001-03-24";
|
||||
}
|
||||
|
||||
auto date = *parse_calendar_date(value);
|
||||
int seconds_of_day = 12 * 60 * 60; // Noon
|
||||
if (!is_deterministic) {
|
||||
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
auto local_time = *std::localtime(&now);
|
||||
seconds_of_day = local_time.tm_hour * 60 * 60 + local_time.tm_min * 60 + local_time.tm_sec;
|
||||
}
|
||||
return std::chrono::local_days{date} + std::chrono::seconds{seconds_of_day};
|
||||
}
|
||||
|
||||
/// Check for an existing directory (returns error message if check fails)
|
||||
class WorkingDirectoryValidator : public CLI::detail::ExistingDirectoryValidator {
|
||||
public:
|
||||
@@ -96,6 +139,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 +148,15 @@ 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 start_date;
|
||||
string keyboard_string = "Eng_USA";
|
||||
|
||||
const std::map<std::string, int> kbd_map{
|
||||
@@ -119,45 +167,62 @@ 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("--start-date", start_date,
|
||||
"Set the guest RTC start date (YYYY-MM-DD), keeping the current local time; "
|
||||
"deterministic mode defaults to 2001-03-24 at noon")
|
||||
->check(CLI::Validator([](std::string& value) {
|
||||
return parse_calendar_date(value) ? std::string() :
|
||||
std::string("Expected a valid date in YYYY-MM-DD format");
|
||||
}, "YYYY-MM-DD"));
|
||||
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");
|
||||
emu->add_flag("--swap-command-option", g_swap_command_option,
|
||||
"Swap the Command and Option keys (physical Alt/AltGr becomes Command)");
|
||||
|
||||
auto list_cmd = app.add_subcommand("list",
|
||||
"Display available machine configurations and exit");
|
||||
|
||||
@@ -168,6 +233,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,10 +246,22 @@ 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;
|
||||
}
|
||||
|
||||
if (auto start_time = parse_start_date(start_date, is_deterministic))
|
||||
ViaCuda::set_start_time(*start_time);
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
@@ -249,7 +328,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 +349,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 +371,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 +402,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,12 +434,21 @@ void run_machine(std::string machine_str, char* rom_data,
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t deterministic_timer;
|
||||
if (is_deterministic) {
|
||||
static TimerInfo deterministic_timer;
|
||||
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.
|
||||
deterministic_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(1000), [] {
|
||||
TimerManager::get_instance()->add_cyclic_timer(deterministic_timer, MSECS_TO_NSECS(1000), [](uint64_t, uint64_t) {
|
||||
// We may be running after an exceptions or RFI changed the address
|
||||
// translation context. In those cases the PC address cannot be
|
||||
// translated (it would either be stale or invalid).
|
||||
if (exec_flags & (EXEF_EXCEPTION | EXEF_RFI)) {
|
||||
LOG_F(INFO, "TS=%016llu PC=0x%08x transition pending to PC=0x%08x",
|
||||
get_virt_time_ns(), ppc_state.pc, ppc_next_instruction_address);
|
||||
return;
|
||||
}
|
||||
|
||||
PPCDisasmContext ctx;
|
||||
ctx.instr_code = ppc_read_instruction(mmu_translate_imem(ppc_state.pc));
|
||||
ctx.instr_addr = ppc_state.pc;
|
||||
@@ -367,14 +462,17 @@ void run_machine(std::string machine_str, char* rom_data,
|
||||
|
||||
// set up system wide event polling using
|
||||
// default Macintosh polling rate of 11 ms
|
||||
uint32_t event_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
|
||||
static TimerInfo event_timer;
|
||||
TimerManager::get_instance()->add_cyclic_timer(event_timer, MSECS_TO_NSECS(11), [](uint64_t, uint64_t) {
|
||||
EventManager::get_instance()->poll_events();
|
||||
});
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
uint32_t profiling_timer;
|
||||
if (profiling_interval_ms > 0) {
|
||||
profiling_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(profiling_interval_ms), [] {
|
||||
profiling_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(profiling_interval_ms),
|
||||
[](uint64_t, uint64_t)
|
||||
{
|
||||
gProfilerObj->print_profile("PPC_CPU");
|
||||
});
|
||||
}
|
||||
@@ -382,15 +480,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 +503,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();
|
||||
|
||||
@@ -35,6 +35,8 @@ bool init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_EnableScreenSaver();
|
||||
|
||||
int num_joysticks = SDL_NumJoysticks();
|
||||
for (int i = 0; i < num_joysticks; ++i) {
|
||||
if (SDL_IsGameController(i)) {
|
||||
|
||||
@@ -67,8 +67,12 @@ ImgFile::~ImgFile() = default;
|
||||
|
||||
bool ImgFile::open(const std::string &img_path)
|
||||
{
|
||||
impl->backend = make_imgfile_backend(img_path);
|
||||
return !!impl->backend;
|
||||
auto backend = make_imgfile_backend(img_path);
|
||||
if (!backend)
|
||||
return false;
|
||||
|
||||
impl->backend = std::move(backend);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImgFile::close()
|
||||
|
||||
@@ -105,3 +105,26 @@ else:
|
||||
refill_primary_tlb(VA, PA)
|
||||
perform_memory_access(PA, ART)
|
||||
```
|
||||
|
||||
## Translation context invalidation
|
||||
|
||||
Guest operating systems can change BAT registers and page address translation
|
||||
state very frequently. XNU, for example, temporarily installs a DBAT mapping in
|
||||
some physical-memory access routines and restores the previous mapping shortly
|
||||
afterwards. DingusPPC applies the resulting TLB invalidation at the next context
|
||||
synchronization (`isync`, `rfi`, or `sc`), as the processor does. A BAT update
|
||||
must invalidate cached PAT translations as well as BAT translations because a
|
||||
new BAT can shadow a page mapping.
|
||||
|
||||
Scanning every primary and secondary TLB array at each synchronization is
|
||||
expensive. Instead, DingusPPC records pointers to slots populated by BAT or PAT
|
||||
translation in separate instruction and data vectors. Pending invalidations are
|
||||
combined by translation source, and synchronization visits only those tracked
|
||||
slots. Writes that leave a BAT register unchanged are ignored before scheduling
|
||||
any invalidation work.
|
||||
|
||||
Generation counters offer constant-time invalidation, but require an additional
|
||||
generation check on every TLB lookup. Tracking populated slots keeps the common
|
||||
hit path as a direct tag comparison. Its cost is paid at context synchronization
|
||||
and is proportional to the number of translated slots populated since the last
|
||||
invalidation.
|
||||
+17
-2
@@ -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
|
||||
@@ -67,6 +67,21 @@ Specify machine ID, where `machineid` is a short string identifier for the machi
|
||||
|
||||
Specifies working directory, where `path` is a string for the directory the emulator will grab files from.
|
||||
|
||||
```
|
||||
--start-date YYYY-MM-DD
|
||||
```
|
||||
|
||||
Start the guest RTC on the given date, using the current local time of day. The clock continues ticking, including across midnight. This is useful for running software with an expiration date, such as `--start-date=1997-03-01` for BeOS DR 8.2. Without a date override or deterministic mode, the RTC follows the host clock.
|
||||
|
||||
```
|
||||
--deterministic
|
||||
--deterministic-mode strict|interactive
|
||||
```
|
||||
|
||||
Enables deterministic mode, where the emulator behaves the same way every run. Meant to be a development or debugging aid, to remove variability between runs. Disk, NVRAM, and PRAM changes are not saved. The default `strict` mode ignores mouse and keyboard input; `interactive` mode allows input for interactive debugging.
|
||||
|
||||
The RTC defaults to `--start-date=2001-03-24`, unless a date is explicitly supplied. It starts at noon and advances the RTC with emulated time. Restarting the emulated machine starts the deterministic RTC from that date and noon again.
|
||||
|
||||
```
|
||||
--setenv args
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user