mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6c48eff4b |
No files matched your search
+24
-29
@@ -183,20 +183,13 @@ 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.4c"
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4c"
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4b"
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4b"
|
||||
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)
|
||||
@@ -265,26 +258,28 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_CPU_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h")
|
||||
foreach(BENCHMARK bench1 bench2)
|
||||
add_executable(${BENCHMARK} "benchmark/${BENCHMARK}.cpp" ${BENCH_CPU_SOURCES}
|
||||
$<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
target_compile_definitions(${BENCHMARK} PRIVATE PPC_BENCHMARKS)
|
||||
target_link_libraries(${BENCHMARK} PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
target_compile_definitions(${BENCHMARK} PRIVATE SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(${BENCHMARK} PRIVATE capstone)
|
||||
endif()
|
||||
endforeach()
|
||||
add_compile_options("-DPPC_BENCHMARKS")
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
)
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
|
||||
# $<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
target_compile_definitions(bench1 PRIVATE SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 PRIVATE capstone)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
|
||||
@@ -4,12 +4,7 @@ General
|
||||
* Test your contributions to assure they do not break existing functionality.
|
||||
* Commits to the repo should be done by portions; that is, by individual functionalities of the program.
|
||||
* Don't use any disrespectful language.
|
||||
|
||||
AI Usage
|
||||
=======
|
||||
|
||||
* Do not use artificial intelligence to make contributions. This is due to authorship issues and licensing issues regarding AI usage.
|
||||
* Do not use artificial intelligence to write up issues or pull requests.
|
||||
|
||||
Code
|
||||
=======
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
- lefp
|
||||
- mathstuf
|
||||
- mrpapersonic
|
||||
- probonopd
|
||||
- Randrianasulu
|
||||
- roytam1
|
||||
- sdkmap
|
||||
@@ -59,7 +58,6 @@
|
||||
- Blitter.net
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- pagetable.com
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
|
||||
@@ -69,9 +69,16 @@ int main(int argc, char** argv) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
constexpr uint64_t bus_freq = 66'820'000ULL;
|
||||
constexpr uint64_t tbr_freq = bus_freq / 4;
|
||||
constexpr uint64_t core_freq = bus_freq * 7 / 2; // 233.87 MHz (CPU PLL ratio of 3.5)
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
|
||||
ppc_cpu_init(grackle_obj, {
|
||||
.version = PPC_VER::MPC750,
|
||||
.timebase_freq_hz = tbr_freq,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
|
||||
@@ -1,119 +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/>.
|
||||
*/
|
||||
|
||||
// Replay floating-point instructions and input registers captured while BeOS
|
||||
// PR1 GLTeapot renders. This measures the real opcode dispatcher and handlers,
|
||||
// including FPSCR maintenance, without guest boot, display, or timer overhead.
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfenv>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "bench2_data.h"
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_off(po_benchmark_exception);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void replay_sample(const FpuSample& sample) {
|
||||
if ((ppc_state.fpscr ^ sample.fpscr) & FPSCR::RN_MASK)
|
||||
set_host_rounding_mode(sample.fpscr & FPSCR::RN_MASK);
|
||||
ppc_state.fpscr = sample.fpscr;
|
||||
ppc_state.cr = sample.cr;
|
||||
ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r = sample.d;
|
||||
ppc_state.fpr[(sample.opcode >> 16) & 31].int64_r = sample.a;
|
||||
ppc_state.fpr[(sample.opcode >> 11) & 31].int64_r = sample.b;
|
||||
ppc_state.fpr[(sample.opcode >> 6) & 31].int64_r = sample.c;
|
||||
ppc_main_opcode(ppc_opcode_grabber, sample.opcode);
|
||||
}
|
||||
|
||||
static uint64_t check_replay() {
|
||||
uint64_t hash = 1469598103934665603ULL;
|
||||
auto mix = [&hash](uint64_t value) { hash = (hash ^ value) * 1099511628211ULL; };
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
for (const auto& sample : fpu_samples) {
|
||||
replay_sample(sample);
|
||||
mix(ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r);
|
||||
mix(ppc_state.fpscr);
|
||||
mix(ppc_state.cr);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc > 2 || (argc == 2 && std::strcmp(argv[1], "--check"))) {
|
||||
fprintf(stderr, "Usage: %s [--check]\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
|
||||
is_601 = false;
|
||||
initialize_ppc_opcode_table();
|
||||
ppc_msr_did_change(ppc_state.msr, MSR::ME | MSR::IP | MSR::FP, false);
|
||||
set_host_rounding_mode(0);
|
||||
power_on = true;
|
||||
|
||||
const uint64_t expected = check_replay();
|
||||
constexpr size_t sample_count = sizeof(fpu_samples) / sizeof(fpu_samples[0]);
|
||||
printf("GLTeapot FPU replay: %zu samples, checksum %016" PRIx64 "\n", sample_count, expected);
|
||||
if (!power_on)
|
||||
return 1;
|
||||
if (argc == 2 && !std::strcmp(argv[1], "--check"))
|
||||
return 0;
|
||||
|
||||
constexpr unsigned passes = 10000;
|
||||
constexpr unsigned trials = 9;
|
||||
// Warm the dispatcher, handlers and captured input data.
|
||||
for (unsigned pass = 0; pass < 100; pass++)
|
||||
for (const auto& sample : fpu_samples)
|
||||
replay_sample(sample);
|
||||
|
||||
std::vector<double> times;
|
||||
for (unsigned trial = 0; trial < trials; trial++) {
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
for (unsigned pass = 0; pass < passes; pass++)
|
||||
for (const auto& sample : fpu_samples)
|
||||
replay_sample(sample);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
if (!power_on || check_replay() != expected) {
|
||||
fprintf(stderr, "FPU replay changed its result during timing\n");
|
||||
return 1;
|
||||
}
|
||||
double ns = std::chrono::duration<double, std::nano>(end - start).count() /
|
||||
(uint64_t(passes) * sample_count);
|
||||
times.push_back(ns);
|
||||
printf("Trial %u: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
|
||||
trial + 1, ns, 1000.0 / ns);
|
||||
}
|
||||
std::sort(times.begin(), times.end());
|
||||
double median = times[times.size() / 2];
|
||||
printf("Median: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
|
||||
median, 1000.0 / median);
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,70 +0,0 @@
|
||||
<?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>
|
||||
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/coresignal.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
class WindowEvent {
|
||||
public:
|
||||
@@ -120,20 +119,6 @@ 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() {
|
||||
@@ -146,9 +131,6 @@ 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&)) {
|
||||
@@ -170,11 +152,6 @@ 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);
|
||||
@@ -185,7 +162,6 @@ public:
|
||||
_mouse_signal.disconnect_all();
|
||||
_keyboard_signal.disconnect_all();
|
||||
_gamepad_signal.disconnect_all();
|
||||
_cdrom_signal.disconnect_all();
|
||||
_post_signal.disconnect_all();
|
||||
}
|
||||
|
||||
@@ -203,7 +179,6 @@ 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;
|
||||
|
||||
+11
-55
@@ -32,20 +32,6 @@ 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;
|
||||
}
|
||||
@@ -138,23 +124,23 @@ void EventManager::poll_events() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-Alt-Shift-+: speed up icnt_factor
|
||||
// Control-Alt-Shift-+: increase instruction period
|
||||
if (event.key.keysym.sym == SDLK_EQUALS &&
|
||||
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
|
||||
) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
int icnt_counter_val = increment_icnt_factor();
|
||||
LOG_F(INFO, "Incremented icnt_factor: %d", icnt_counter_val);
|
||||
uint64_t instruction_period = increment_instruction_period();
|
||||
LOG_F(INFO, "Incremented instruction period: %d", (int)instruction_period);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-Alt-Shift--: slow down icnt_factor
|
||||
// Control-Alt-Shift--: decrease instruction period
|
||||
if (event.key.keysym.sym == SDLK_MINUS &&
|
||||
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
|
||||
) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
int icnt_counter_val = decrement_icnt_factor();
|
||||
LOG_F(INFO, "Decremented icnt_factor: %d", icnt_counter_val);
|
||||
uint64_t instruction_period = decrement_instruction_period();
|
||||
LOG_F(INFO, "Decremented instruction period: %d", (int)instruction_period);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -165,7 +151,6 @@ void EventManager::poll_events() {
|
||||
bool g_realtime_status = toggle_g_realtime();
|
||||
LOG_F(INFO, "g_realtime: %s", g_realtime_status ? "enabled" : "disabled");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Control-L: log toggle
|
||||
@@ -323,35 +308,6 @@ 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++;
|
||||
}
|
||||
@@ -402,7 +358,7 @@ void EventManager::post_keyboard_state_events() {
|
||||
continue;
|
||||
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(mod->scancode));
|
||||
count++;
|
||||
ke.key = swap_command_option(mod->adbkey);
|
||||
ke.key = mod->adbkey;
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
this->_keyboard_signal.emit(ke);
|
||||
}
|
||||
@@ -527,10 +483,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 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_LALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_RightOption;
|
||||
case SDLK_LGUI: return AdbKey_Command;
|
||||
case SDLK_RGUI: return AdbKey_Command;
|
||||
case SDLK_MENU: return AdbKey_Grave;
|
||||
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
|
||||
|
||||
|
||||
+30
-38
@@ -30,49 +30,51 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
void TimerManager::add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb)
|
||||
uint32_t TimerManager::add_absolute_timer(uint64_t timeout_ns, uint64_t interval, timer_cb cb)
|
||||
{
|
||||
if (ti.active)
|
||||
LOG_F(ERROR, "Timer %p is already active; cancel it before rescheduling", (void*)&ti);
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti.timeout_ns = timeout_ns;
|
||||
ti.interval_ns = interval;
|
||||
ti.active = true;
|
||||
ti.cb = cb;
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = timeout_ns;
|
||||
ti->interval_ns = interval;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(&ti);
|
||||
this->timer_queue.push(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
void TimerManager::add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb)
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
TimerManager::add_absolute_timer(ti, this->get_time_now() + timeout, 0, cb);
|
||||
return TimerManager::add_absolute_timer(this->get_time_now() + timeout, 0, cb);
|
||||
}
|
||||
|
||||
void TimerManager::add_immediate_timer(TimerInfo &ti, timer_cb cb)
|
||||
uint32_t TimerManager::add_immediate_timer(timer_cb cb)
|
||||
{
|
||||
TimerManager::add_absolute_timer(ti, 0, 0, cb);
|
||||
return TimerManager::add_absolute_timer(0, 0, cb);
|
||||
}
|
||||
|
||||
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
TimerManager::add_absolute_timer(ti, this->get_time_now() + delay, interval, cb);
|
||||
return TimerManager::add_absolute_timer(this->get_time_now() + delay, interval, cb);
|
||||
}
|
||||
|
||||
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb)
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
{
|
||||
this->add_cyclic_timer(ti, interval, interval, cb);
|
||||
return this->add_cyclic_timer(interval, interval, cb);
|
||||
}
|
||||
|
||||
void TimerManager::cancel_timer(TimerInfo &ti)
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
{
|
||||
this->timer_queue.remove_by_id(&ti);
|
||||
ti.active = false;
|
||||
this->timer_queue.remove_by_id(id);
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
@@ -80,7 +82,7 @@ void TimerManager::cancel_timer(TimerInfo &ti)
|
||||
|
||||
uint64_t TimerManager::process_timers()
|
||||
{
|
||||
TimerInfo *cur_timer;
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
uint64_t time_now = get_time_now();
|
||||
|
||||
{ // mtx scope
|
||||
@@ -93,7 +95,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);
|
||||
this->timer_queue.remove_by_id(cur_timer->id);
|
||||
uint64_t timeout_ns = cur_timer->timeout_ns;
|
||||
timer_cb cb = cur_timer->cb;
|
||||
|
||||
@@ -101,25 +103,16 @@ uint64_t TimerManager::process_timers()
|
||||
if (cur_timer->interval_ns) {
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
uint64_t timeout_ns_new = timeout_ns + cur_timer->interval_ns;
|
||||
if (timeout_ns_new <= time_now) {
|
||||
// Skip missed periods without changing the timer's phase.
|
||||
// Rebasing deadlines on time_now would align timers that
|
||||
// have the same period.
|
||||
const uint64_t periods_to_skip =
|
||||
((time_now - timeout_ns_new) / cur_timer->interval_ns) + 1;
|
||||
timeout_ns_new += periods_to_skip * cur_timer->interval_ns;
|
||||
}
|
||||
if (timeout_ns_new <= time_now)
|
||||
timeout_ns_new = time_now + cur_timer->interval_ns;
|
||||
cur_timer->timeout_ns = timeout_ns_new;
|
||||
this->timer_queue.push(cur_timer);
|
||||
} else {
|
||||
// One-shot callbacks may immediately reuse their TimerInfo.
|
||||
cur_timer->active = false;
|
||||
}
|
||||
|
||||
this->cb_active = true;
|
||||
|
||||
// invoke timer callback
|
||||
cb(time_now, timeout_ns);
|
||||
cb();
|
||||
|
||||
this->cb_active = false;
|
||||
|
||||
@@ -134,17 +127,16 @@ uint64_t TimerManager::process_timers()
|
||||
} // ] mtx scope
|
||||
}
|
||||
|
||||
// return next timer's expiry
|
||||
return cur_timer->timeout_ns;
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
return cur_timer->timeout_ns - time_now;
|
||||
}
|
||||
|
||||
void TimerManager::cancel_all_timers()
|
||||
{
|
||||
TimerInfo *cur_timer;
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
while (!this->timer_queue.empty()) {
|
||||
cur_timer = this->timer_queue.top();
|
||||
LOG_F(WARNING, "Canceling timer id:%llu ns:%llu", uint64_t(cur_timer), cur_timer->timeout_ns);
|
||||
LOG_F(WARNING, "Canceling timer id:%u ns:%llu", cur_timer->id, cur_timer->timeout_ns);
|
||||
this->timer_queue.pop();
|
||||
cur_timer->active = false;
|
||||
}
|
||||
}
|
||||
+18
-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(uint64_t timeout_ns, uint64_t time_now)> timer_cb;
|
||||
typedef std::function<void()> 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(T id){
|
||||
bool remove_by_id(const uint32_t id){
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
if (this->empty())
|
||||
return false;
|
||||
auto el = this->top();
|
||||
if (el == id) {
|
||||
if (el->id == 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; });
|
||||
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == 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; // maintained by TimerManager while queued
|
||||
timer_cb cb; // timer callback
|
||||
} TimerInfo;
|
||||
|
||||
// Custom comparator for sorting our timer queue in ascending order
|
||||
class MyGtComparator {
|
||||
public:
|
||||
bool operator()(const TimerInfo *l, const TimerInfo *r) const {
|
||||
return l->timeout_ns > r->timeout_ns ||
|
||||
(l->timeout_ns == r->timeout_ns && l > r);
|
||||
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) const {
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns ||
|
||||
(l.get()->timeout_ns == r.get()->timeout_ns && l.get()->id > r.get()->id);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -130,15 +130,13 @@ public:
|
||||
// return current virtual time in nanoseconds
|
||||
uint64_t current_time_ns() const { return get_time_now(); }
|
||||
|
||||
// Adding requires an inactive timer; cancel before rescheduling.
|
||||
// One-shot timers become inactive before their callback runs.
|
||||
// Cyclic timers remain active until canceled, including during callbacks.
|
||||
void add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb);
|
||||
void add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb);
|
||||
void add_immediate_timer(TimerInfo &ti, timer_cb cb);
|
||||
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb);
|
||||
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(TimerInfo &ti);
|
||||
// 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 cancel_all_timers();
|
||||
|
||||
uint64_t process_timers();
|
||||
@@ -148,11 +146,13 @@ private:
|
||||
TimerManager(){} // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<TimerInfo*, std::vector<TimerInfo*>, MyGtComparator> timer_queue;
|
||||
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<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,10 +23,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
|
||||
@@ -1,215 +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_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,13 +392,6 @@ 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) {
|
||||
@@ -529,7 +522,7 @@ void opc_rlwimi(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
fmt_rotateinsert(ctx, opcode, ra, rs, sh, mb, me);
|
||||
fmt_rotateop(ctx, opcode, ra, rs, sh, mb, me, true);
|
||||
}
|
||||
|
||||
void opc_rlwinm(PPCDisasmContext* ctx) {
|
||||
|
||||
+24
-27
@@ -126,9 +126,6 @@ enum SPR : int {
|
||||
SDA = 959,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
THRM1 = 1020,
|
||||
THRM2 = 1021,
|
||||
THRM3 = 1022,
|
||||
};
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
@@ -324,22 +321,17 @@ enum FPOP : int {
|
||||
|
||||
/** PowerPC exception types. */
|
||||
enum class Except_Type {
|
||||
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,
|
||||
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
|
||||
};
|
||||
|
||||
/** Program Exception subclasses. */
|
||||
@@ -381,7 +373,6 @@ void p_power_off(const char* file, int line, Po_Cause new_reason);
|
||||
|
||||
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
|
||||
@@ -479,8 +470,15 @@ typedef enum {
|
||||
// Placeholder value for cases where we don't have a currently-executing instruction.
|
||||
constexpr uint32_t NO_OPCODE = 0;
|
||||
|
||||
struct PPC_CPU_Config {
|
||||
uint32_t version;
|
||||
uint64_t timebase_freq_hz;
|
||||
uint64_t bus_freq_hz;
|
||||
uint64_t core_freq_hz;
|
||||
};
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, const PPC_CPU_Config& config);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop(uint32_t opcode);
|
||||
@@ -729,13 +727,12 @@ 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();
|
||||
/* instruction period control */
|
||||
extern uint64_t increment_instruction_period();
|
||||
extern uint64_t decrement_instruction_period();
|
||||
extern uint64_t get_instruction_period();
|
||||
|
||||
/* realtime clock control */
|
||||
extern bool g_realtime;
|
||||
/* toggle_g_realtime */
|
||||
extern bool toggle_g_realtime();
|
||||
|
||||
/* force_cycle_counter_reload */
|
||||
|
||||
+38
-16
@@ -39,11 +39,8 @@ 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:
|
||||
@@ -51,6 +48,12 @@ 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:
|
||||
@@ -59,28 +62,56 @@ 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:
|
||||
case Except_Type::EXC_DECR:
|
||||
case Except_Type::EXC_THRM_MGMT_INT:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
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;
|
||||
@@ -171,15 +202,6 @@ 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);
|
||||
|
||||
+115
-84
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "ppcdisasm.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@@ -36,7 +37,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <ctime>
|
||||
#include <mach/mach_time.h>
|
||||
#undef EXC_SYSCALL
|
||||
static struct mach_timebase_info timebase_info;
|
||||
static uint64_t
|
||||
ConvertHostTimeToNanos2(uint64_t host_time)
|
||||
{
|
||||
if (timebase_info.numer == timebase_info.denom)
|
||||
return host_time;
|
||||
long double answer = host_time;
|
||||
answer *= timebase_info.numer;
|
||||
answer /= timebase_info.denom;
|
||||
return (uint64_t)answer;
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
@@ -116,13 +129,22 @@ 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;
|
||||
bool thrm_exception_pending = false;
|
||||
|
||||
/* variables related to virtual time */
|
||||
bool g_realtime = false;
|
||||
uint64_t g_nanoseconds_base;
|
||||
uint64_t g_icycles;
|
||||
int icnt_factor;
|
||||
// Fixed-point nanoseconds, with four fractional bits. This provides enough
|
||||
// precision for the supported CPU clocks and over 36 years before overflow.
|
||||
using FixedNanoseconds = uint64_t;
|
||||
static constexpr int VIRT_TIME_FRAC_BITS = 4;
|
||||
static FixedNanoseconds g_virt_time;
|
||||
static FixedNanoseconds g_instruction_period;
|
||||
|
||||
static constexpr FixedNanoseconds instruction_period_for_frequency(uint64_t core_freq_hz)
|
||||
{
|
||||
return (((uint64_t)NS_PER_SEC << VIRT_TIME_FRAC_BITS) + core_freq_hz / 2) /
|
||||
core_freq_hz;
|
||||
}
|
||||
|
||||
/* global variables related to the timebase facility */
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
|
||||
@@ -275,18 +297,6 @@ PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
|
||||
/** Exception helpers. */
|
||||
|
||||
void ppc_illegalop(uint32_t opcode) {
|
||||
// Zero values are used as sentinels in the TNT ROM and are thus somewhat
|
||||
// common, don't log them.
|
||||
// Example: ciexit in Old World Open Firmware uses opcode 0.
|
||||
if (opcode) {
|
||||
PPCDisasmContext ctx;
|
||||
ctx.instr_code = opcode;
|
||||
ctx.instr_addr = 0;
|
||||
ctx.simplified = false;
|
||||
auto op_name = disassemble_single(&ctx);
|
||||
LOG_F(WARNING, "Illegal opcode exception raised for 0x%08x (decoded as %s). The PC was 0x%08x.", opcode, op_name.c_str(), ppc_state.pc);
|
||||
}
|
||||
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
@@ -345,7 +355,7 @@ void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
|
||||
|
||||
static long long cpu_now_ns() {
|
||||
#ifdef __APPLE__
|
||||
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
|
||||
return ConvertHostTimeToNanos2(mach_absolute_time());
|
||||
#else
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
@@ -357,7 +367,7 @@ uint64_t get_virt_time_ns()
|
||||
if (g_realtime) {
|
||||
return cpu_now_ns() - g_nanoseconds_base;
|
||||
} else {
|
||||
return g_icycles << icnt_factor;
|
||||
return g_virt_time >> VIRT_TIME_FRAC_BITS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +376,7 @@ 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;
|
||||
g_virt_time = time_now << VIRT_TIME_FRAC_BITS;
|
||||
}
|
||||
uint64_t time_new = get_virt_time_ns();
|
||||
if (g_realtime && time_new > time_now) {
|
||||
@@ -376,34 +386,16 @@ void set_virt_time_ns(uint64_t time_now)
|
||||
LOG_F(INFO, "time before: %lld after: %lld change: %lld", time_now, time_new, time_new - time_now);
|
||||
}
|
||||
|
||||
static constexpr uint64_t TIMER_POLL_INTERVAL_NS = 500'000;
|
||||
|
||||
static uint64_t process_events()
|
||||
static FixedNanoseconds process_events()
|
||||
{
|
||||
exec_timer = false;
|
||||
uint64_t next_ns = TimerManager::get_instance()->process_timers();
|
||||
if (g_realtime) {
|
||||
uint64_t time_now = get_virt_time_ns();
|
||||
uint64_t delay_ns;
|
||||
if (next_ns) {
|
||||
delay_ns = next_ns > time_now ? next_ns - time_now : 0;
|
||||
} else {
|
||||
delay_ns = TIMER_POLL_INTERVAL_NS;
|
||||
}
|
||||
// Host time and the instruction counter advance independently. Schedule
|
||||
// a relative instruction batch, capped so long deadlines still poll.
|
||||
// Comparing an absolute wall-time deadline with g_icycles can otherwise
|
||||
// make a fast interpreter process timers after every instruction.
|
||||
return g_icycles + (std::min(delay_ns, TIMER_POLL_INTERVAL_NS) >> icnt_factor) + 1;
|
||||
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
|
||||
if (slice_ns == 0) {
|
||||
// execute 25,000 instructions
|
||||
// if there are no pending timers
|
||||
return g_virt_time + 25'000 * g_instruction_period;
|
||||
}
|
||||
return (
|
||||
(
|
||||
next_ns ?
|
||||
next_ns
|
||||
:
|
||||
get_virt_time_ns() + TIMER_POLL_INTERVAL_NS
|
||||
) >> icnt_factor
|
||||
) + 1;
|
||||
return g_virt_time + (slice_ns << VIRT_TIME_FRAC_BITS);
|
||||
}
|
||||
|
||||
static void force_cycle_counter_reload()
|
||||
@@ -412,29 +404,29 @@ static void force_cycle_counter_reload()
|
||||
exec_timer = true;
|
||||
}
|
||||
|
||||
int increment_icnt_factor()
|
||||
uint64_t increment_instruction_period()
|
||||
{
|
||||
uint64_t time_now = get_virt_time_ns();
|
||||
icnt_factor += 1;
|
||||
g_instruction_period += 1;
|
||||
set_virt_time_ns(time_now);
|
||||
force_cycle_counter_reload();
|
||||
return icnt_factor;
|
||||
return g_instruction_period;
|
||||
}
|
||||
|
||||
int decrement_icnt_factor()
|
||||
uint64_t decrement_instruction_period()
|
||||
{
|
||||
if (icnt_factor > 0) {
|
||||
if (g_instruction_period > 0) {
|
||||
uint64_t time_now = get_virt_time_ns();
|
||||
icnt_factor -= 1;
|
||||
g_instruction_period -= 1;
|
||||
set_virt_time_ns(time_now);
|
||||
force_cycle_counter_reload();
|
||||
}
|
||||
return icnt_factor;
|
||||
return g_instruction_period;
|
||||
}
|
||||
|
||||
int get_icnt_factor()
|
||||
uint64_t get_instruction_period()
|
||||
{
|
||||
return icnt_factor;
|
||||
return g_instruction_period;
|
||||
}
|
||||
|
||||
bool toggle_g_realtime()
|
||||
@@ -456,7 +448,10 @@ typedef enum {
|
||||
template <ppc_exec_type_t exec_type, endian_switch endian>
|
||||
static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
uint64_t max_cycles = 0;
|
||||
FixedNanoseconds event_deadline = 0;
|
||||
// Keep these hot-loop values in registers.
|
||||
FixedNanoseconds virt_time = g_virt_time;
|
||||
FixedNanoseconds instruction_period = g_instruction_period;
|
||||
uint32_t page_start, eb_start, eb_end = 0;
|
||||
uint32_t opcode;
|
||||
PPCOpcode* opcode_grabber = ppc_opcode_grabber;
|
||||
@@ -479,21 +474,29 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
|
||||
|
||||
opcode = ppc_read_instruction(pc_real);
|
||||
ppc_main_opcode(opcode_grabber, opcode);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]]
|
||||
max_cycles = process_events();
|
||||
virt_time += instruction_period;
|
||||
g_virt_time = virt_time;
|
||||
if (virt_time >= event_deadline || exec_timer) [[unlikely]] {
|
||||
event_deadline = process_events();
|
||||
virt_time = g_virt_time;
|
||||
instruction_period = g_instruction_period;
|
||||
}
|
||||
|
||||
if (exec_flags) {
|
||||
if ((exec_flags & EXEF_SLEEP) && !(exec_flags & EXEF_EXCEPTION)) [[unlikely]] {
|
||||
while (power_on && (exec_flags & EXEF_SLEEP)) {
|
||||
max_cycles = process_events();
|
||||
event_deadline = process_events();
|
||||
virt_time = g_virt_time;
|
||||
instruction_period = g_instruction_period;
|
||||
if (!(exec_flags & EXEF_SLEEP)) {
|
||||
break;
|
||||
}
|
||||
if (max_cycles > g_icycles) {
|
||||
g_icycles = max_cycles;
|
||||
if (event_deadline > virt_time) {
|
||||
virt_time = event_deadline;
|
||||
} else {
|
||||
g_icycles++;
|
||||
virt_time += instruction_period;
|
||||
}
|
||||
g_virt_time = virt_time;
|
||||
}
|
||||
}
|
||||
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
|
||||
@@ -571,7 +574,7 @@ void ppc_exec_single()
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
|
||||
uint32_t opcode = ppc_read_instruction(pc_real);
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
g_icycles++;
|
||||
g_virt_time += g_instruction_period;
|
||||
process_events();
|
||||
|
||||
if (exec_flags) {
|
||||
@@ -1012,21 +1015,59 @@ void initialize_ppc_opcode_table() {
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_601, uint64_t tb_freq)
|
||||
static uint32_t get_cpu_pll_value(const PPC_CPU_Config& config)
|
||||
{
|
||||
switch (config.version) {
|
||||
case PPC_VER::MPC603EV:
|
||||
if (config.core_freq_hz * 2 == config.bus_freq_hz * 9)
|
||||
return 7; // 4.5:1 ratio
|
||||
if (config.core_freq_hz == config.bus_freq_hz * 5)
|
||||
return 11; // 5:1 ratio
|
||||
if (config.core_freq_hz * 2 == config.bus_freq_hz * 11)
|
||||
return 9; // 5.5:1 ratio
|
||||
break;
|
||||
case PPC_VER::MPC750:
|
||||
if (config.core_freq_hz * 2 == config.bus_freq_hz * 7)
|
||||
return 14; // 3.5:1 ratio
|
||||
if (config.core_freq_hz == config.bus_freq_hz * 6)
|
||||
return 13; // 6:1 ratio
|
||||
if (config.core_freq_hz == config.bus_freq_hz * 8)
|
||||
return 12; // 8:1 ratio
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ABORT_F("Unsupported CPU/bus frequency combination: %" PRIu64 "/%" PRIu64 " Hz",
|
||||
config.core_freq_hz, config.bus_freq_hz);
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, const PPC_CPU_Config& config)
|
||||
{
|
||||
if (!config.timebase_freq_hz || !config.bus_freq_hz || !config.core_freq_hz)
|
||||
ABORT_F("CPU clock frequencies must be non-zero");
|
||||
|
||||
mem_ctrl_instance = mem_ctrl;
|
||||
|
||||
int_pin = false;
|
||||
std::memset(&ppc_state, 0, sizeof(ppc_state));
|
||||
set_host_rounding_mode(0);
|
||||
|
||||
ppc_state.spr[SPR::PVR] = cpu_version;
|
||||
is_601 = (cpu_version >> 16) == 1;
|
||||
include_601 = !is_601 & do_include_601;
|
||||
ppc_state.spr[SPR::PVR] = config.version;
|
||||
switch (config.version) {
|
||||
case PPC_VER::MPC603EV:
|
||||
case PPC_VER::MPC750:
|
||||
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(config) << 28;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
is_601 = (config.version >> 16) == 1;
|
||||
include_601 = is_601;
|
||||
ppc_pow_mode = PPCPowMode::None;
|
||||
ppc_pow_hid0_mask = 0;
|
||||
|
||||
switch (cpu_version) {
|
||||
switch (config.version) {
|
||||
case PPC_VER::MPC603:
|
||||
case PPC_VER::MPC603E:
|
||||
case PPC_VER::MPC603EV:
|
||||
@@ -1052,26 +1093,17 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
|
||||
TimerManager::get_instance()->set_notify_changes_cb(&force_cycle_counter_reload);
|
||||
|
||||
// initialize time base facility
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info(&timebase_info);
|
||||
#endif
|
||||
g_nanoseconds_base = cpu_now_ns();
|
||||
g_icycles = 0;
|
||||
|
||||
// // // PDM cpu clock calculated at 0x403036CC in r3
|
||||
// icnt_factor = 11; // 1 instruction = 2048 ns = 0.488 MHz // 00068034 = 0.426036 MHz = 2347.219 ns // floppy doesn't work
|
||||
// icnt_factor = 10; // 1 instruction = 1024 ns = 0.977 MHz // 000D204C = 0.860236 MHz = 1162.471 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 9; // 1 instruction = 512 ns = 1.953 MHz // 001A6081 = 1.728641 MHz = 578.489 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 8; // 1 instruction = 256 ns = 3.906 MHz // 0034E477 = 3.466359 MHz = 288.487 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 7; // 1 instruction = 128 ns = 7.813 MHz // 0069E54C = 6.939980 MHz = 144.092 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 6; // 1 instruction = 64 ns = 15.625 MHz // 00D3E6F5 = 13.887221 MHz = 72.008 ns // (10..60] = 50, (60..73] = 66, (73..100] = 80 MHz
|
||||
// icnt_factor = 5; // 1 instruction = 32 ns = 31.250 MHz // 01A7B672 = 27.768434 MHz = 36.012 ns //
|
||||
icnt_factor = 4; // 1 instruction = 16 ns = 62.500 MHz // 034F0F0F = 55.512847 MHz = 18.013 ns // 6100/60 in Apple System Profiler
|
||||
// icnt_factor = 3; // 1 instruction = 8 ns = 125.000 MHz // 069E1E1E = 111.025694 MHz = 9.006 ns // (100...) MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 2; // 1 instruction = 4 ns = 250.000 MHz // 0D3C3C3C = 222.051388 MHz = 4.503 ns // (100...) MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 1; // 1 instruction = 2 ns = 500.000 MHz // 1A611A7B = 442.571387 MHz = 2.259 ns // (100...) MHz = invalid clock for PDM gestalt calculation
|
||||
// icnt_factor = 0; // 1 instruction = 1 ns = 1500.000 MHz // 3465B2D9 = 879.080153 MHz = 1.137 ns // (100...) MHz = invalid clock for PDM gestalt calculation
|
||||
g_virt_time = 0;
|
||||
g_instruction_period = instruction_period_for_frequency(config.core_freq_hz);
|
||||
|
||||
tbr_wr_timestamp = 0;
|
||||
rtc_timestamp = 0;
|
||||
tbr_wr_value = 0;
|
||||
uint64_t tb_freq = config.timebase_freq_hz;
|
||||
if (is_601)
|
||||
tb_freq <<= 7;
|
||||
tbr_freq_shift = 0;
|
||||
@@ -1124,14 +1156,13 @@ 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", SPR::THRM1}, {"THRM2", SPR::THRM2}, {"THRM3", SPR::THRM3},
|
||||
{"THRM1", 1020}, {"THRM2", 1021}, {"THRM3", 1022},
|
||||
{"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},
|
||||
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
|
||||
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
|
||||
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4}, {"EAR", SPR::EAR},
|
||||
|
||||
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
|
||||
// get value from supervisor index same as we do for SPR268 and SPR269
|
||||
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
|
||||
};
|
||||
|
||||
+20
-45
@@ -21,19 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
||||
|
||||
#include <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdlib.h>
|
||||
#include <cfenv>
|
||||
#include <cfloat>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__aarch64__)
|
||||
#include <arm_acle.h>
|
||||
#endif
|
||||
#include <cfloat>
|
||||
|
||||
inline static void ppc_update_cr1() {
|
||||
// copy FPSCR[FX|FEX|VX|OX] to CR1
|
||||
@@ -121,26 +116,6 @@ static double set_endresult_nan() {
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
#if FE_ALL_EXCEPT
|
||||
static int test_and_clear_fp_exceptions() {
|
||||
#if defined(__APPLE__) && defined(__aarch64__)
|
||||
// Darwin's FE_* masks match the ARM64 FPSR exception bits. Preserve
|
||||
// other status bits and avoid a second register read when clearing.
|
||||
uint64_t fpsr = __arm_rsr64("fpsr");
|
||||
int exceptions = fpsr & FE_ALL_EXCEPT;
|
||||
if (exceptions) {
|
||||
fpsr &= ~uint64_t(FE_ALL_EXCEPT);
|
||||
__arm_wsr64("fpsr", fpsr);
|
||||
}
|
||||
#else
|
||||
int exceptions = std::fetestexcept(FE_ALL_EXCEPT);
|
||||
if (exceptions)
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
#endif
|
||||
return exceptions;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void fpresult_update(double set_result) {
|
||||
if (std::isnan(set_result)) {
|
||||
ppc_state.fpscr |= FPCC_FUNAN | FPRCD;
|
||||
@@ -152,18 +127,18 @@ static void fpresult_update(double set_result) {
|
||||
} else {
|
||||
ppc_state.fpscr |= FPCC_ZERO;
|
||||
}
|
||||
#if FE_ALL_EXCEPT
|
||||
int exceptions = test_and_clear_fp_exceptions();
|
||||
if (exceptions & FE_OVERFLOW) {
|
||||
|
||||
if (std::fetestexcept(FE_OVERFLOW)) {
|
||||
ppc_state.fpscr |= (OX + FX);
|
||||
}
|
||||
if (exceptions & FE_UNDERFLOW) {
|
||||
if (std::fetestexcept(FE_UNDERFLOW)) {
|
||||
ppc_state.fpscr |= (UX + FX);
|
||||
}
|
||||
if (exceptions & FE_DIVBYZERO) {
|
||||
if (std::fetestexcept(FE_DIVBYZERO)) {
|
||||
ppc_state.fpscr |= (ZX + FX);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
|
||||
if (std::isinf(set_result))
|
||||
ppc_state.fpscr |= FPCC_FUNAN;
|
||||
@@ -445,7 +420,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);
|
||||
}
|
||||
@@ -1049,7 +1024,7 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1070,7 +1045,7 @@ void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1094,7 +1069,7 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1115,7 +1090,7 @@ void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1138,7 +1113,7 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1159,7 +1134,7 @@ void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1180,7 +1155,7 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1199,7 +1174,7 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
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
|
||||
+307
-276
@@ -31,7 +31,6 @@ 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
|
||||
@@ -57,7 +56,6 @@ 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
|
||||
@@ -378,9 +376,7 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
};
|
||||
}
|
||||
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
bool allow_mmio, bool allow_partial, bool is_dbg)
|
||||
{
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio, bool is_dbg) {
|
||||
MMIODevice *devobj = nullptr;
|
||||
uint8_t *host_va = nullptr;
|
||||
uint32_t dev_base = 0;
|
||||
@@ -434,18 +430,10 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
addr, addr + size - 1
|
||||
);
|
||||
} else {
|
||||
if (allow_partial) {
|
||||
if (!is_dbg)
|
||||
LOG_F(INFO, "DMA access to physical memory 0x%08X..0x%08X spans regions!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
size = cur_dma_rgn->end - addr + 1;
|
||||
} else {
|
||||
if (is_dbg) goto fail;
|
||||
ABORT_F("DMA access to physical memory 0x%08X..0x%08X spans regions!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
}
|
||||
if (is_dbg) goto fail;
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,23 +453,15 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
is_writable = true; // all MMIO devices must provide a write method
|
||||
}
|
||||
|
||||
return MapDmaResult{
|
||||
.type = cur_dma_rgn->type,
|
||||
.size = size,
|
||||
.is_writable = is_writable,
|
||||
.host_va = host_va,
|
||||
.dev_obj = devobj,
|
||||
.dev_base = dev_base,
|
||||
};
|
||||
return MapDmaResult{cur_dma_rgn->type, is_writable, host_va, devobj, dev_base};
|
||||
fail:
|
||||
return MapDmaResult{
|
||||
.type = RT_NONE
|
||||
};
|
||||
return MapDmaResult{RT_NONE, false, nullptr, nullptr, 0};
|
||||
}
|
||||
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
constexpr uint32_t TLB2_WAYS = 4;
|
||||
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
|
||||
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
PAGE_MEM = 1 << 0, // memory page backed by host memory
|
||||
@@ -491,14 +471,15 @@ enum TLBFlags : uint16_t {
|
||||
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;
|
||||
// PAT context changes are frequent, so implicitly invalidate PAT-derived
|
||||
// entries via a generation counter (instead of walking the TLB array and
|
||||
// clearing every time).
|
||||
static uint32_t gTLBPatGeneration = 0;
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
uint32_t tag; // use is_invalid() or matches_tag() for validity checks
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
@@ -512,100 +493,23 @@ typedef struct TLBEntry {
|
||||
};
|
||||
};
|
||||
uint32_t phys_tag;
|
||||
uint32_t reserved;
|
||||
uint32_t pat_generation;
|
||||
|
||||
bool is_invalid() const
|
||||
{
|
||||
return tag == TLB_INVALID_TAG ||
|
||||
((flags & TLBFlags::TLBE_FROM_PAT) &&
|
||||
pat_generation != gTLBPatGeneration);
|
||||
}
|
||||
|
||||
bool matches_tag(uint32_t tag_in) const
|
||||
{
|
||||
return tag == tag_in &&
|
||||
(!(flags & TLBFlags::TLBE_FROM_PAT) ||
|
||||
pat_generation == gTLBPatGeneration);
|
||||
}
|
||||
} TLBEntry;
|
||||
|
||||
// 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;
|
||||
@@ -691,27 +595,6 @@ 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)
|
||||
{
|
||||
@@ -724,33 +607,65 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
|
||||
}
|
||||
|
||||
// select the target from invalid blocks first
|
||||
if (tlb_entry[0].tag == TLB_INVALID_TAG) {
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
if (tlb_entry[0].is_invalid()) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x3;
|
||||
tlb_entry[1].lru_bits = 0x2;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
return tlb_entry;
|
||||
} else if (tlb_entry[1].tag == TLB_INVALID_TAG) {
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
} else if (tlb_entry[1].is_invalid()) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x2;
|
||||
tlb_entry[1].lru_bits = 0x3;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
return &tlb_entry[1];
|
||||
} else if (tlb_entry[2].tag == TLB_INVALID_TAG) {
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
} else if (tlb_entry[2].is_invalid()) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x3;
|
||||
tlb_entry[3].lru_bits = 0x2;
|
||||
return &tlb_entry[2];
|
||||
} else if (tlb_entry[3].tag == TLB_INVALID_TAG) {
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
} else if (tlb_entry[3].is_invalid()) {
|
||||
// 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;
|
||||
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) {
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x3;
|
||||
tlb_entry[1].lru_bits = 0x2;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
return tlb_entry;
|
||||
} else if (tlb_entry[1].lru_bits == 0) {
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x2;
|
||||
tlb_entry[1].lru_bits = 0x3;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
return &tlb_entry[1];
|
||||
} else if (tlb_entry[2].lru_bits == 0) {
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x3;
|
||||
tlb_entry[3].lru_bits = 0x2;
|
||||
return &tlb_entry[2];
|
||||
} else {
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
// 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;
|
||||
return &tlb_entry[3];
|
||||
}
|
||||
}
|
||||
@@ -799,12 +714,11 @@ 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 & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
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);
|
||||
tlb_entry->pat_generation = gTLBPatGeneration;
|
||||
} else {
|
||||
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
|
||||
}
|
||||
@@ -873,16 +787,14 @@ 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 & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_IO;
|
||||
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 & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
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) {
|
||||
if (rgn_desc->type == RT_ROM) {
|
||||
// redirect writes to the dummy page for ROM regions
|
||||
tlb_entry->host_va_offs_w = (int64_t)&dummy_page - tag;
|
||||
} else {
|
||||
@@ -890,7 +802,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);
|
||||
tlb_entry->pat_generation = gTLBPatGeneration;
|
||||
return tlb_entry;
|
||||
} else {
|
||||
if (!is_dbg) {
|
||||
@@ -919,16 +831,32 @@ 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[0].tag == tag) {
|
||||
tlb2_touch_way<0>(tlb_entry);
|
||||
} else if (tlb_entry[1].tag == tag) {
|
||||
tlb2_touch_way<1>(tlb_entry);
|
||||
if (tlb_entry[0].matches_tag(tag)) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x3;
|
||||
tlb_entry[1].lru_bits = 0x2;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
} else if (tlb_entry[1].matches_tag(tag)) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x2;
|
||||
tlb_entry[1].lru_bits = 0x3;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
tlb_entry = &tlb_entry[1];
|
||||
} else if (tlb_entry[2].tag == tag) {
|
||||
tlb2_touch_way<2>(tlb_entry);
|
||||
} else if (tlb_entry[2].matches_tag(tag)) {
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x3;
|
||||
tlb_entry[3].lru_bits = 0x2;
|
||||
tlb_entry = &tlb_entry[2];
|
||||
} else if (tlb_entry[3].tag == tag) {
|
||||
tlb2_touch_way<3>(tlb_entry);
|
||||
} else if (tlb_entry[3].matches_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;
|
||||
tlb_entry = &tlb_entry[3];
|
||||
} else {
|
||||
return nullptr;
|
||||
@@ -936,59 +864,20 @@ 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);
|
||||
// look up guest virtual address in the primary TLB
|
||||
TLBEntry *tlb_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
|
||||
if (!tlb_entry->matches_tag(tag)) {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb_entry == nullptr) {
|
||||
// secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
tlb_entry = dtlb2_refill(guest_va, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this was in a MMIO region, in which case we avoid doing the
|
||||
@@ -998,7 +887,15 @@ void mmu_dcbz(uint32_t opcode, uint32_t guest_va)
|
||||
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);
|
||||
if (!(tlb_entry->flags & TLBFlags::PAGE_WRITABLE)) {
|
||||
ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25);
|
||||
ppc_state.spr[SPR::DAR] = guest_va;
|
||||
mmu_exception_handler(Except_Type::EXC_DSI, 0);
|
||||
}
|
||||
if (!(tlb_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
tlb_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1027,15 +924,16 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
|
||||
const uint32_t tag = vaddr & ~0xFFFUL;
|
||||
|
||||
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
|
||||
// look up guest virtual address in the primary ITLB
|
||||
tlb1_entry = &pCurITLB1[(vaddr >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->matches_tag(tag)) { // 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 {
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
// primary ITLB miss -> look up address in the secondary ITLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::ITLB>(vaddr, tag);
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_itlb_refills++;
|
||||
@@ -1050,7 +948,11 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
}
|
||||
#endif
|
||||
// refill the primary ITLB
|
||||
promote_tlb_entry<TLBType::ITLB>(tlb1_entry, tlb2_entry);
|
||||
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;
|
||||
tlb1_entry->pat_generation = tlb2_entry->pat_generation;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
@@ -1060,14 +962,114 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
return host_va;
|
||||
}
|
||||
|
||||
void tlb_flush_all_pat()
|
||||
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
|
||||
{
|
||||
#ifdef MMU_PROFILING
|
||||
pat_flushes_total++;
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
tlb_invalidate_tracked_entries(gTrackedIEntries, TLBE_FROM_PAT);
|
||||
tlb_invalidate_tracked_entries(gTrackedDEntries, TLBE_FROM_PAT);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static bool gTLBFlushIBatEntries = false;
|
||||
static bool gTLBFlushDBatEntries = false;
|
||||
static bool gTLBInvalidatePatEntries = 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;
|
||||
}
|
||||
}
|
||||
|
||||
static void tlb_invalidate_pat_entries()
|
||||
{
|
||||
if (!gTLBInvalidatePatEntries)
|
||||
return;
|
||||
|
||||
gTLBPatGeneration++;
|
||||
if (gTLBPatGeneration == 0) { // Do a full flush when the counter wraps around
|
||||
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_PAT);
|
||||
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_PAT);
|
||||
}
|
||||
|
||||
gTLBInvalidatePatEntries = false;
|
||||
}
|
||||
|
||||
static void mpc601_bat_update(uint32_t bat_reg)
|
||||
@@ -1095,19 +1097,26 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
// copy IBAT entry to DBAT entry
|
||||
*dbat_entry = *ibat_entry;
|
||||
} else {
|
||||
// disable the corresponding BAT pairs
|
||||
// disable the corresponding BAT paars
|
||||
ibat_entry->valid = false;
|
||||
dbat_entry->valid = false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// MPC601 has unified BATs so we're going to flush both ITLB and DTLB
|
||||
if (!gTLBFlushIBatEntries) {
|
||||
gTLBFlushIBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
}
|
||||
if (!gTLBFlushDBatEntries) {
|
||||
gTLBFlushDBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
|
||||
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
|
||||
{
|
||||
// ppc_illegalop(opcode);
|
||||
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
static void ppc_ibat_update(uint32_t bat_reg)
|
||||
@@ -1128,8 +1137,11 @@ static void ppc_ibat_update(uint32_t bat_reg)
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
// A new IBAT can shadow an existing page translation.
|
||||
schedule_tlb_invalidation(TLBType::ITLB, TLBE_FROM_TRANSLATION);
|
||||
if (!gTLBFlushIBatEntries) {
|
||||
gTLBFlushIBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
}
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
|
||||
static void ppc_dbat_update(uint32_t bat_reg)
|
||||
@@ -1150,16 +1162,21 @@ 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;
|
||||
|
||||
// A new DBAT can shadow an existing page translation.
|
||||
schedule_tlb_invalidation(TLBType::DTLB, TLBE_FROM_TRANSLATION);
|
||||
if (!gTLBFlushDBatEntries) {
|
||||
gTLBFlushDBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
|
||||
void mmu_pat_ctx_changed()
|
||||
{
|
||||
// Page address translation context changed so 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 (!gTLBInvalidatePatEntries) {
|
||||
gTLBInvalidatePatEntries = true;
|
||||
add_ctx_sync_action(&tlb_invalidate_pat_entries);
|
||||
}
|
||||
}
|
||||
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
@@ -1204,13 +1221,12 @@ 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 and secondary TLBs
|
||||
// look up guest virtual address in the primary TLB
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool needs_swap = false;
|
||||
#endif
|
||||
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
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->matches_tag(tag)) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
@@ -1225,7 +1241,8 @@ 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 {
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_dtlb_refills++;
|
||||
@@ -1245,7 +1262,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
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
@@ -1375,17 +1392,25 @@ 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 and secondary TLBs
|
||||
// look up guest virtual address in the primary TLB
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool needs_swap = false;
|
||||
#endif
|
||||
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
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->matches_tag(tag)) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
if (prepare_dtlb_write(tlb1_entry, guest_va)) {
|
||||
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;
|
||||
|
||||
// don't forget to update the secondary TLB as well
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry != nullptr) {
|
||||
@@ -1401,7 +1426,8 @@ 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 {
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry == nullptr) {
|
||||
#ifdef TLB_PROFILING
|
||||
num_dtlb_refills++;
|
||||
@@ -1418,11 +1444,22 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
num_secondary_dtlb_hits++;
|
||||
}
|
||||
#endif
|
||||
prepare_dtlb_write(tlb2_entry, guest_va);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
@@ -1736,10 +1773,6 @@ 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});
|
||||
@@ -1765,7 +1798,6 @@ 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;
|
||||
@@ -1935,12 +1967,13 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
TLBLookupResult tlb_lookup = lookup_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
tlb1_entry = tlb_lookup.primary_entry;
|
||||
// look up guest virtual address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
|
||||
do {
|
||||
if (!tlb_lookup.primary_hit) {
|
||||
tlb2_entry = tlb_lookup.matched_entry;
|
||||
if (!tlb1_entry->matches_tag(tag)) {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry == nullptr) {
|
||||
// secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
@@ -1953,7 +1986,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
|
||||
promote_tlb_entry<TLBType::DTLB>(tlb1_entry, tlb2_entry);
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
}
|
||||
else {
|
||||
tlb1_entry = tlb2_entry;
|
||||
@@ -1989,16 +2022,14 @@ static void invalidate_tlb_entries(std::array<TLBEntry, N> &tlb) {
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
tlb_el.phys_tag = 0;
|
||||
tlb_el.reserved = 0;
|
||||
tlb_el.pat_generation = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_mmu_init()
|
||||
{
|
||||
gPendingIInvalidationSources = 0;
|
||||
gPendingDInvalidationSources = 0;
|
||||
gTrackedIEntries.clear();
|
||||
gTrackedDEntries.clear();
|
||||
gTLBPatGeneration = 0;
|
||||
gTLBInvalidatePatEntries = false;
|
||||
|
||||
last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
|
||||
+2
-4
@@ -71,7 +71,6 @@ typedef struct PATResult {
|
||||
/** DMA memory mapping result. */
|
||||
typedef struct MapDmaResult {
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
bool is_writable;
|
||||
// for memory regions
|
||||
uint8_t* host_va;
|
||||
@@ -90,12 +89,11 @@ extern std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
extern PPC_BAT_entry ibat_array[4];
|
||||
extern PPC_BAT_entry dbat_array[4];
|
||||
|
||||
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
bool allow_mmio = false, bool allow_partial = false, bool is_dbg = false);
|
||||
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio = false, bool is_dbg = false);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_all_pat();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
extern void mmu_dcbz(uint32_t opcode, uint32_t guest_va);
|
||||
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
|
||||
+150
-202
@@ -24,16 +24,12 @@ 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 <cpu/ppc/ppcdechelpers.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "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
|
||||
@@ -52,14 +48,30 @@ void ppc_changecrf0(uint32_t set_result) {
|
||||
}
|
||||
|
||||
// Affects the XER register's Carry Bit
|
||||
inline static void ppc_carry(uint64_t ppc_result_l) {
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~XER::CA) | ((ppc_result_l >> (32 - 29)) & XER::CA);
|
||||
inline static void ppc_carry(uint32_t a, uint32_t b) {
|
||||
if (b < a) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void ppc_carry_sub(uint32_t a, uint32_t b) {
|
||||
if (b >= a) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
}
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
inline static void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~XER::OV) |
|
||||
((int32_t((a ^ b) & (a ^ d)) < 0) ? (XER::SO | XER::OV) : 0);
|
||||
if (int32_t((a ^ b) & (a ^ d)) < 0) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::function<void()> CtxSyncCallback;
|
||||
@@ -99,9 +111,8 @@ template void dppc_interpreter::ppc_addi<SHFT1>(uint32_t opcode);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_addic(uint32_t opcode) {
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + uint32_t(simm);
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t ppc_result_d = (ppc_result_a + simm);
|
||||
ppc_carry(ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
@@ -113,10 +124,10 @@ template void dppc_interpreter::ppc_addic<RC1>(uint32_t opcode);
|
||||
template <field_carry carry, field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_add(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + ppc_result_b;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
uint32_t ppc_result_d = ppc_result_a + ppc_result_b;
|
||||
|
||||
if (carry)
|
||||
ppc_carry(ppc_result_l);
|
||||
ppc_carry(ppc_result_a, ppc_result_d);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -137,9 +148,14 @@ template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_adde(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + ppc_result_b + xer_ca;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
|
||||
|
||||
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -157,9 +173,14 @@ template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_addme(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + xer_ca + uint32_t(-1);
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t ppc_result_d = ppc_result_a + xer_ca - 1;
|
||||
|
||||
if (((xer_ca - 1) < 0xFFFFFFFFUL) || (ppc_result_d < ppc_result_a)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -176,10 +197,15 @@ template void dppc_interpreter::ppc_addme<RC1, OV1>(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_addze(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + xer_ca;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t grab_xer = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint32_t ppc_result_d = ppc_result_a + grab_xer;
|
||||
|
||||
if (ppc_result_d < ppc_result_a) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -195,19 +221,21 @@ template void dppc_interpreter::ppc_addze<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::ppc_subfic(uint32_t opcode) {
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + uint32_t(simm) + 1;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t ppc_result_d = simm - ppc_result_a;
|
||||
if (simm == -1)
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
else
|
||||
ppc_carry(~ppc_result_a, ppc_result_d);
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <field_carry carry, field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_subf(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + ppc_result_b + 1;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
uint32_t ppc_result_d = ppc_result_b - ppc_result_a;
|
||||
|
||||
if (carry)
|
||||
ppc_carry(ppc_result_l);
|
||||
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -228,10 +256,13 @@ template void dppc_interpreter::ppc_subf<CARRY1, RC1, OV1>(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_subfe(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + ppc_result_b + xer_ca;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint32_t ppc_result_d = ~ppc_result_a + ppc_result_b + grab_ca;
|
||||
if (grab_ca && ppc_result_b == 0xFFFFFFFFUL)
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
else
|
||||
ppc_carry(~ppc_result_a, ppc_result_d);
|
||||
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -248,10 +279,14 @@ template void dppc_interpreter::ppc_subfe<RC1, OV1>(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_subfme(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + xer_ca + uint32_t(-1);
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint32_t ppc_result_d = ~ppc_result_a + grab_ca - 1;
|
||||
|
||||
if (ppc_result_a == 0xFFFFFFFFUL && !grab_ca)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
else
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
|
||||
if (ov) {
|
||||
if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
@@ -273,10 +308,14 @@ template void dppc_interpreter::ppc_subfme<RC1, OV1>(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::ppc_subfze(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + xer_ca;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
ppc_carry(ppc_result_l);
|
||||
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
|
||||
uint32_t ppc_result_d = ~ppc_result_a + grab_ca;
|
||||
|
||||
if (!ppc_result_d && grab_ca) // special case: ppc_result_d = 0 and CA=1
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
else
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
|
||||
if (ov) {
|
||||
if (ppc_result_d && ppc_result_d == ppc_result_a)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
@@ -693,10 +732,10 @@ void dppc_interpreter::ppc_mtsr(uint32_t opcode) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
ppc_grab_s(opcode);
|
||||
int reg_s = (opcode >> 21) & 0x1F;
|
||||
uint32_t grab_sr = (opcode >> 16) & 0x0F;
|
||||
if (ppc_state.sr[grab_sr] != ppc_result_d) {
|
||||
ppc_state.sr[grab_sr] = ppc_result_d;
|
||||
if (ppc_state.sr[grab_sr] != ppc_state.gpr[reg_s]) {
|
||||
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
}
|
||||
@@ -763,9 +802,9 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
ppc_grab_s(opcode);
|
||||
uint32_t reg_s = (opcode >> 21) & 0x1F;
|
||||
uint32_t old_msr_val = ppc_state.msr;
|
||||
uint32_t new_msr_val = ppc_result_d;
|
||||
uint32_t new_msr_val = ppc_state.gpr[reg_s];
|
||||
if (!is_601) {
|
||||
ppc_change_endian((new_msr_val & MSR::LE) != 0);
|
||||
}
|
||||
@@ -780,9 +819,6 @@ 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;
|
||||
|
||||
@@ -872,11 +908,11 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
static TimerInfo decrementer_timer;
|
||||
static uint32_t decrementer_timer_id = 0;
|
||||
|
||||
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
|
||||
|
||||
static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
|
||||
static void trigger_decrementer_exception() {
|
||||
if (ppc_state.msr & MSR::EE) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "decrementer exception triggered");
|
||||
@@ -888,7 +924,8 @@ static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
|
||||
static void trigger_timed_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
uint32_t new_val = calc_dec_value();
|
||||
if (new_val >= 0 && new_val != uint32_t(-1)) {
|
||||
new_val = -1;
|
||||
@@ -897,7 +934,8 @@ static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
|
||||
trigger_decrementer_exception();
|
||||
}
|
||||
|
||||
static void trigger_immediate_decrementer_exception(uint64_t, uint64_t) {
|
||||
static void trigger_immediate_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
|
||||
trigger_decrementer_exception();
|
||||
}
|
||||
@@ -910,12 +948,12 @@ static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t
|
||||
|
||||
dec_exception_pending = false;
|
||||
|
||||
if (decrementer_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer);
|
||||
if (decrementer_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
|
||||
}
|
||||
|
||||
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
|
||||
TimerManager::get_instance()->add_immediate_timer(decrementer_timer,
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
trigger_immediate_decrementer_exception
|
||||
);
|
||||
return;
|
||||
@@ -935,53 +973,12 @@ 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);
|
||||
TimerManager::get_instance()->add_oneshot_timer(decrementer_timer,
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
time_out,
|
||||
trigger_timed_decrementer_exception
|
||||
);
|
||||
}
|
||||
|
||||
static void update_thermal(uint64_t, uint64_t) {
|
||||
|
||||
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;
|
||||
@@ -999,14 +996,14 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
switch (ref_spr) {
|
||||
case SPR::MQ:
|
||||
if (!(is_601 || include_601)) {
|
||||
ppc_illegalop(opcode);
|
||||
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_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
return;
|
||||
}
|
||||
calc_rtcl_value();
|
||||
@@ -1016,7 +1013,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
break;
|
||||
case SPR::RTCU_U:
|
||||
if (!is_601) {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
return;
|
||||
}
|
||||
calc_rtcl_value();
|
||||
@@ -1026,7 +1023,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
break;
|
||||
case SPR::DEC_U:
|
||||
if (!is_601) {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
return;
|
||||
}
|
||||
// fallthrough
|
||||
@@ -1054,15 +1051,6 @@ 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];
|
||||
@@ -1090,13 +1078,13 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
if (is_601 || include_601)
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
else
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
break;
|
||||
case SPR::RTCL_U:
|
||||
case SPR::RTCU_U:
|
||||
case SPR::DEC_U:
|
||||
if (!is_601) {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
break;
|
||||
case SPR::XER:
|
||||
@@ -1144,10 +1132,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case 533:
|
||||
case 534:
|
||||
case 535:
|
||||
if (ppc_state.spr[ref_spr] != val) {
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
ibat_update(ref_spr);
|
||||
}
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
ibat_update(ref_spr);
|
||||
break;
|
||||
case 536:
|
||||
case 537:
|
||||
@@ -1157,10 +1143,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case 541:
|
||||
case 542:
|
||||
case 543:
|
||||
if (ppc_state.spr[ref_spr] != val) {
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
dbat_update(ref_spr);
|
||||
}
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
dbat_update(ref_spr);
|
||||
break;
|
||||
case SPR::HID0:
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
@@ -1168,25 +1152,6 @@ 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;
|
||||
@@ -1211,7 +1176,7 @@ void dppc_interpreter::ppc_mftb(uint32_t opcode) {
|
||||
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1548,18 +1513,14 @@ 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 || thrm_exception_pending)) {
|
||||
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_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 if (dec_exception_pending) {
|
||||
else {
|
||||
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;
|
||||
}
|
||||
@@ -1579,25 +1540,27 @@ void dppc_interpreter::ppc_sc(uint32_t opcode) {
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_tw(uint32_t opcode) {
|
||||
ppc_grab_regsab(opcode);
|
||||
uint32_t reg_a = (opcode >> 11) & 0x1F;
|
||||
uint32_t reg_b = (opcode >> 16) & 0x1F;
|
||||
uint32_t ppc_to = (opcode >> 21) & 0x1F;
|
||||
if (((int32_t(ppc_result_a) < int32_t(ppc_result_b)) && (ppc_to & 0x10)) ||
|
||||
((int32_t(ppc_result_a) > int32_t(ppc_result_b)) && (ppc_to & 0x08)) ||
|
||||
((int32_t(ppc_result_a) == int32_t(ppc_result_b)) && (ppc_to & 0x04)) ||
|
||||
((ppc_result_a < ppc_result_b) && (ppc_to & 0x02)) ||
|
||||
((ppc_result_a > ppc_result_b) && (ppc_to & 0x01))) {
|
||||
if (((int32_t(ppc_state.gpr[reg_a]) < int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x10)) ||
|
||||
((int32_t(ppc_state.gpr[reg_a]) > int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x08)) ||
|
||||
((int32_t(ppc_state.gpr[reg_a]) == int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x04)) ||
|
||||
((ppc_state.gpr[reg_a] < ppc_state.gpr[reg_b]) && (ppc_to & 0x02)) ||
|
||||
((ppc_state.gpr[reg_a] > ppc_state.gpr[reg_b]) && (ppc_to & 0x01))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_twi(uint32_t opcode) {
|
||||
ppc_grab_regsasimm(opcode);
|
||||
int32_t simm = int32_t(int16_t(opcode));
|
||||
uint32_t reg_a = (opcode >> 16) & 0x1F;
|
||||
uint32_t ppc_to = (opcode >> 21) & 0x1F;
|
||||
if (((int32_t(ppc_result_a) < simm) && (ppc_to & 0x10)) ||
|
||||
((int32_t(ppc_result_a) > simm) && (ppc_to & 0x08)) ||
|
||||
((int32_t(ppc_result_a) == simm) && (ppc_to & 0x04)) ||
|
||||
(ppc_result_a < uint32_t(simm) && (ppc_to & 0x02)) ||
|
||||
(ppc_result_a > uint32_t(simm) && (ppc_to & 0x01))) {
|
||||
if (((int32_t(ppc_state.gpr[reg_a]) < simm) && (ppc_to & 0x10)) ||
|
||||
((int32_t(ppc_state.gpr[reg_a]) > simm) && (ppc_to & 0x08)) ||
|
||||
((int32_t(ppc_state.gpr[reg_a]) == simm) && (ppc_to & 0x04)) ||
|
||||
(ppc_state.gpr[reg_a] < uint32_t(simm) && (ppc_to & 0x02)) ||
|
||||
(ppc_state.gpr[reg_a] > uint32_t(simm) && (ppc_to & 0x01))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
@@ -1696,17 +1659,13 @@ void dppc_interpreter::ppc_stu(uint32_t opcode) {
|
||||
ppc_grab_regssa(opcode);
|
||||
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = ppc_result_a + int32_t(int16_t(opcode));
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += ppc_result_a;
|
||||
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
}
|
||||
else if (is_601) {
|
||||
// MPC601 permits RA=0 for POWER compatibility and suppresses the update.
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1727,13 +1686,8 @@ void dppc_interpreter::ppc_stux(uint32_t opcode) {
|
||||
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
}
|
||||
else if (is_601) {
|
||||
// MPC601 permits RA=0 for POWER compatibility and suppresses the update.
|
||||
uint32_t ea = ppc_result_b;
|
||||
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1800,8 +1754,8 @@ void dppc_interpreter::ppc_lz(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += reg_a ? ppc_result_a : 0;
|
||||
uint32_t ppc_result_d = mmu_read_vmem<T>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
@@ -1816,16 +1770,16 @@ void dppc_interpreter::ppc_lzu(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
if ((reg_a != reg_d) && (reg_a != 0)) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
if ((reg_a != reg_d) && reg_a != 0) {
|
||||
ea += ppc_result_a;
|
||||
uint32_t ppc_result_d = mmu_read_vmem<T>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_result_a = ea;
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1861,7 +1815,7 @@ void dppc_interpreter::ppc_lzux(uint32_t opcode) {
|
||||
ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1873,8 +1827,8 @@ void dppc_interpreter::ppc_lha(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += (reg_a ? ppc_result_a : 0);
|
||||
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, int32_t(val));
|
||||
@@ -1884,16 +1838,16 @@ void dppc_interpreter::ppc_lhau(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
ppc_grab_regsda(opcode);
|
||||
if ((reg_a != reg_d) && reg_a != 0) {
|
||||
uint32_t ea = simm;
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += ppc_result_a;
|
||||
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, int32_t(val));
|
||||
ppc_result_a = ea;
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1906,11 +1860,11 @@ void dppc_interpreter::ppc_lhaux(uint32_t opcode) {
|
||||
uint32_t ea = ppc_result_a + ppc_result_b;
|
||||
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, int32_t(val));
|
||||
ppc_result_a = ea;
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
else {
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1960,8 +1914,8 @@ void dppc_interpreter::ppc_lmw(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += (reg_a ? ppc_result_a : 0);
|
||||
// How many words to load in memory - using a do-while for this
|
||||
do {
|
||||
@@ -2018,7 +1972,7 @@ void dppc_interpreter::ppc_lswx(uint32_t opcode) {
|
||||
if ((reg_d == 0 && reg_a == 0) || (reg_d == reg_a) || (reg_d == reg_b)) {
|
||||
// UNTESTED! Does invalid form really cause exception?
|
||||
// G4 doesn't do exception
|
||||
ppc_illegalop(opcode);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -2171,13 +2125,7 @@ void dppc_interpreter::ppc_tlbie(uint32_t opcode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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();
|
||||
tlb_flush_entry(ppc_state.gpr[(opcode >> 11) & 0x1F]);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_tlbia(uint32_t opcode) {
|
||||
|
||||
@@ -1167,8 +1167,7 @@ void DppcDebugger::enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
static TimerInfo viaint_timer;
|
||||
TimerManager::get_instance()->add_oneshot_timer(viaint_timer, 0, [irq_bit](uint64_t, uint64_t){
|
||||
TimerManager::get_instance()->add_oneshot_timer(0, [irq_bit](){
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
via_obj->assert_int(irq_bit);
|
||||
});
|
||||
|
||||
@@ -77,6 +77,9 @@ 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,7 +21,6 @@ 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>
|
||||
@@ -93,8 +92,7 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
this->set_register_2();
|
||||
break;
|
||||
case 3:
|
||||
if (this->host_obj->get_input_count() >= 2) // ensure we got enough data
|
||||
this->set_register_3();
|
||||
this->set_register_3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -109,25 +107,6 @@ 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,7 +34,6 @@ 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) {
|
||||
@@ -47,9 +46,8 @@ 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 = 7; // LEDs off (active low)
|
||||
this->led_state = 0; // LEDs off
|
||||
this->pending_events.clear();
|
||||
this->keys_down.reset();
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_0() {
|
||||
@@ -94,35 +92,9 @@ 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] = reg2 >> 8;
|
||||
out_buf[1] = reg2 & 0xFF;
|
||||
out_buf[0] = 0;
|
||||
out_buf[1] = this->led_state & 0x07;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
@@ -136,18 +108,40 @@ 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:
|
||||
this->AdbDevice::set_register_3();
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ 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>
|
||||
@@ -48,13 +47,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();
|
||||
};
|
||||
@@ -130,7 +129,6 @@ enum AdbKey {
|
||||
AdbKey_Option = 0x3a,
|
||||
AdbKey_Command = 0x37,
|
||||
AdbKey_CapsLock = 0x39,
|
||||
AdbKey_Power = 0x7f,
|
||||
|
||||
AdbKey_RightControl = 0x7d,
|
||||
AdbKey_RightShift = 0x7b,
|
||||
|
||||
@@ -142,16 +142,28 @@ 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:
|
||||
this->AdbDevice::set_register_3();
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,13 +77,8 @@ 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);
|
||||
if (!this->read_data_timer.active) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->read_data_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->update_intrq(1);
|
||||
}
|
||||
);
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
@@ -126,25 +121,17 @@ 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());
|
||||
if (this->write_done_timer.active)
|
||||
LOG_F(ERROR, "%s: write_done_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(write_done_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
);
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
});
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
|
||||
if (this->write_more_timer.active)
|
||||
LOG_F(ERROR, "%s: write_more_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->write_more_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->signal_data_ready();
|
||||
}
|
||||
);
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->signal_data_ready();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,9 +213,7 @@ int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
|
||||
if (!this->xfer_cnt) {
|
||||
this->is_dma_xfer = false;
|
||||
this->data_ptr = nullptr;
|
||||
if (this->dma_pull_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_pull_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_pull_timer, 500, [this](uint64_t, uint64_t) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
@@ -255,9 +240,7 @@ int AtaBaseDevice::push_data(uint8_t *buf, int len) {
|
||||
this->is_dma_xfer = false;
|
||||
this->data_ptr = nullptr;
|
||||
this->cur_data_ptr = nullptr;
|
||||
if (this->dma_push_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_push_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_push_timer, 500, [this](uint64_t, uint64_t) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
|
||||
@@ -25,7 +25,6 @@ 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>
|
||||
|
||||
@@ -109,12 +108,6 @@ 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], 0x0300); // report DMA and LBA support
|
||||
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
@@ -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 MWDMA fields
|
||||
WRITE_WORD_LE_A(&buf_ptr[53], 0x0002);
|
||||
// report validity for the advanced PIO and MWDMA fields
|
||||
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
|
||||
|
||||
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
|
||||
|
||||
@@ -316,8 +316,6 @@ 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,7 +24,6 @@ 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>
|
||||
|
||||
@@ -75,8 +74,6 @@ 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
|
||||
@@ -67,17 +67,11 @@ int AtapiCdrom::device_postinit() {
|
||||
parse_device_path(cdr_config, bus_id, dev_num);
|
||||
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
if (!bus_obj) {
|
||||
LOG_F(ERROR, "%s: cdr_config device path %s does not specify a known IDE bus",
|
||||
this->name.c_str(), cdr_config.c_str());
|
||||
return -1;
|
||||
}
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string cdr_image_path = GET_STR_PROP("cdr_img");
|
||||
if (!cdr_image_path.empty()) {
|
||||
if (!this->insert_image(cdr_image_path))
|
||||
return -1;
|
||||
this->insert_image(cdr_image_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -105,12 +99,6 @@ void AtapiCdrom::perform_packet_command() {
|
||||
switch (this->cmd_pkt[0]) {
|
||||
case ScsiCommand::READ_CD:
|
||||
{
|
||||
// READ_CD currently bypasses the shared CD-ROM command dispatcher.
|
||||
if (!this->ready_for_command()) {
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
|
||||
}
|
||||
|
||||
bool is_device_ready() override { return this->medium_present(); }
|
||||
bool is_device_ready() override { return this->is_ready; }
|
||||
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
@@ -91,9 +91,7 @@ int IdeChannel::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
|
||||
}
|
||||
|
||||
void IdeChannel::assert_dmareq(uint64_t delay) {
|
||||
if (this->dmareq_timer.active)
|
||||
LOG_F(WARNING, "%s: dmareq_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->dmareq_timer, delay, [this](uint64_t, uint64_t) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
|
||||
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
|
||||
this->channel_obj->xfer_retry();
|
||||
});
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
@@ -75,8 +74,6 @@ private:
|
||||
AtaInterface* devices[2];
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
|
||||
TimerInfo dmareq_timer;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
|
||||
+75
-23
@@ -40,6 +40,12 @@ 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);
|
||||
@@ -94,10 +100,14 @@ 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 {
|
||||
@@ -135,15 +145,6 @@ 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)
|
||||
@@ -290,12 +291,10 @@ void DMAChannel::update_irq(uint8_t cmd_bits) {
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (this->int_ctrl) {
|
||||
if (!this->interrupt_timer.active) {
|
||||
TimerManager::get_instance()->add_immediate_timer(this->interrupt_timer, [this](uint64_t, uint64_t) {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
}
|
||||
if (int_ctrl) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
} else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
}
|
||||
@@ -344,7 +343,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:
|
||||
@@ -371,6 +370,8 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -470,7 +471,7 @@ void DMAChannel::xfer_from_device() {
|
||||
this->get_name().c_str());
|
||||
}
|
||||
|
||||
this->interpret_until_blocked();
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_to_device() {
|
||||
@@ -487,7 +488,7 @@ void DMAChannel::xfer_to_device() {
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_until_blocked();
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_retry() {
|
||||
@@ -520,7 +521,9 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get data or become idle
|
||||
this->interpret_until_blocked();
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
// dequeue data if any
|
||||
if (this->queue_len) {
|
||||
@@ -553,7 +556,9 @@ DmaPushResult DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get buffer to fill in or become idle
|
||||
this->interpret_until_blocked();
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
@@ -565,12 +570,47 @@ 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_until_blocked();
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -606,7 +646,13 @@ void DMAChannel::start() {
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
|
||||
this->interpret_until_blocked();
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
@@ -618,7 +664,13 @@ void DMAChannel::resume() {
|
||||
|
||||
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
|
||||
|
||||
this->interpret_until_blocked();
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
|
||||
@@ -29,7 +29,6 @@ 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>
|
||||
@@ -110,6 +109,7 @@ 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,6 +125,10 @@ 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;
|
||||
@@ -137,7 +141,6 @@ 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);
|
||||
@@ -155,6 +158,9 @@ 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;
|
||||
@@ -174,7 +180,6 @@ private:
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
TimerInfo interrupt_timer;
|
||||
};
|
||||
|
||||
#endif // DB_DMA_H
|
||||
@@ -45,6 +45,8 @@ 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; }
|
||||
|
||||
@@ -58,6 +60,8 @@ 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; }
|
||||
|
||||
|
||||
@@ -32,8 +32,6 @@ enum YosemiteGpioMask: uint8_t {
|
||||
GPIO_FWDET = 2, // FireWire detect
|
||||
};
|
||||
|
||||
constexpr uint32_t my_rev_id = 2;
|
||||
|
||||
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
@@ -41,7 +39,7 @@ DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
|
||||
// initialize PCI config header
|
||||
this->vendor_id = PCI_VENDOR_DEC;
|
||||
this->device_id = 0x0026;
|
||||
this->class_rev = DEVTYPE_PCI2PCI_BRIDGE | my_rev_id;
|
||||
this->class_rev = 0x06040002;
|
||||
this->cache_ln_sz = 0;
|
||||
this->command = 0;
|
||||
this->status = 0x2B0;
|
||||
|
||||
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PCI_BASE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidefs.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -53,6 +52,16 @@ enum {
|
||||
// Int_Pin and Int_Line registers (type 0, 1, and 2)
|
||||
};
|
||||
|
||||
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
||||
enum {
|
||||
PCI_VENDOR_ATI = 0x1002,
|
||||
PCI_VENDOR_DEC = 0x1011,
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
PCI_VENDOR_SILICON_IMAGE = 0x1095,
|
||||
PCI_VENDOR_NVIDIA = 0x10DE,
|
||||
};
|
||||
|
||||
/** PCI BAR types */
|
||||
enum PCIBarType : uint32_t {
|
||||
Unused = 0,
|
||||
|
||||
@@ -1,72 +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 PCI_DEFS_H
|
||||
#define PCI_DEFS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** PCI device class/subclass/programming interface definitions. */
|
||||
enum : uint8_t {
|
||||
DEVCLASS_UNCLASSIFIED = 0x00, // unclassified/legacy devices
|
||||
DEVCLASS_MASS_STORAGE_CTRL = 0x01, // mass storage controllers
|
||||
SUBCLASS_IDE_CTRL = 0x01, // IDE controller
|
||||
PROGIF_BUS_MASTER = 0x80, // bus master (DMA) capable
|
||||
DEVCLASS_DISPLAY_CTRL = 0x03, // display controllers
|
||||
SUBCLASS_VGA_COMPAT = 0x00, // VGA-compatible display controller
|
||||
SUBCLASS_NON_VGA = 0x80, // non-VGA display controller
|
||||
DEVCLASS_BRIDGE_DEVICE = 0x06, // various bridge devices
|
||||
SUBCLASS_HOST_BRIDGE = 0x00, // host-to-PCI bridge
|
||||
SUBCLASS_PCI2PCI_BRIDGE = 0x04, // PCI-to-PCI bridge
|
||||
DEVCLASS_SERIAL_BUS_CTRL = 0x0C, // serial bus controllers
|
||||
SUBCLASS_USB_CTRL = 0x03, // Universal serial bus (USB) controller
|
||||
PROGIF_OHCI = 0x10, // conforms to the OpenHCI specification
|
||||
DEVCLASS_UNASSIGNED = 0xFF
|
||||
};
|
||||
|
||||
/** Some common PCI device type definitions. */
|
||||
enum : uint32_t {
|
||||
DEVTYPE_HOST2PCI_BRIDGE = (DEVCLASS_BRIDGE_DEVICE << 24) |
|
||||
(SUBCLASS_HOST_BRIDGE << 16),
|
||||
DEVTYPE_PCI2PCI_BRIDGE = (DEVCLASS_BRIDGE_DEVICE << 24) |
|
||||
(SUBCLASS_PCI2PCI_BRIDGE << 16),
|
||||
DEVTYPE_VGA_COMPAT_VIDCTRL = (DEVCLASS_DISPLAY_CTRL << 24) |
|
||||
(SUBCLASS_VGA_COMPAT << 16),
|
||||
DEVTYPE_IDE_CTRL_BUS_MASTER = (DEVCLASS_MASS_STORAGE_CTRL << 24) |
|
||||
(SUBCLASS_IDE_CTRL << 16) | (PROGIF_BUS_MASTER << 8),
|
||||
DEVTYPE_USB_OHCI_CTRL = (DEVCLASS_SERIAL_BUS_CTRL << 24) |
|
||||
(SUBCLASS_USB_CTRL << 16) | (PROGIF_OHCI << 8),
|
||||
};
|
||||
|
||||
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
||||
enum : uint16_t {
|
||||
PCI_VENDOR_ATI = 0x1002,
|
||||
PCI_VENDOR_DEC = 0x1011,
|
||||
PCI_VENDOR_OPTi = 0x1045,
|
||||
PCI_VENDOR_TI = 0x104C, // common abbreviation for Texas Instruments
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
PCI_VENDOR_SILICON_IMAGE = 0x1095,
|
||||
PCI_VENDOR_NVIDIA = 0x10DE,
|
||||
PCI_VENDOR_IXMICRO = 0x10E0, // also known as Integrated Micro Solutions
|
||||
};
|
||||
|
||||
#endif // PCI_DEFS_H
|
||||
@@ -51,16 +51,10 @@ 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;
|
||||
@@ -129,7 +123,6 @@ 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 && (cmd & CMD_OPCODE) != CMD_CLEAR_FIFO) {
|
||||
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP) {
|
||||
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -306,7 +306,6 @@ 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();
|
||||
@@ -314,19 +313,20 @@ 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.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer);
|
||||
if (my_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer_id);
|
||||
my_timer_id = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(my_timer,
|
||||
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(25),
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
my_timer_id = 0;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & CFG1_DISR)) {
|
||||
@@ -475,22 +475,25 @@ uint8_t Sc53C94::fifo_pop()
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
if (this->seq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
if (this->seq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
}
|
||||
|
||||
if (delay_ns) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
} else {
|
||||
TimerManager::get_instance()->add_immediate_timer(this->seq_timer,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -705,7 +708,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);
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -29,7 +29,6 @@ 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>
|
||||
|
||||
@@ -251,7 +250,7 @@ protected:
|
||||
private:
|
||||
uint8_t chip_id = 0;
|
||||
uint8_t my_bus_id = 0;
|
||||
TimerInfo my_timer;
|
||||
uint32_t my_timer_id = 0;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
uint8_t data_fifo[DATA_FIFO_MAX];
|
||||
@@ -279,7 +278,7 @@ private:
|
||||
uint8_t phase_latch = 0;
|
||||
|
||||
// sequencer state
|
||||
TimerInfo seq_timer;
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = 0;
|
||||
uint32_t next_state = 0;
|
||||
SeqDesc* cmd_steps = nullptr;
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
|
||||
@@ -176,14 +175,6 @@ 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,
|
||||
@@ -209,10 +200,8 @@ 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. */
|
||||
@@ -370,8 +359,6 @@ 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. */
|
||||
|
||||
@@ -79,11 +79,6 @@ void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags,
|
||||
}
|
||||
|
||||
void ScsiBlockCmds::process_command() {
|
||||
if (!this->ready_for_command()) {
|
||||
phy_impl->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int next_phase;
|
||||
|
||||
// use non-disk buffer by default
|
||||
@@ -184,20 +179,17 @@ int ScsiBlockCmds::write() {
|
||||
}
|
||||
|
||||
int ScsiBlockCmds::start_stop_unit() {
|
||||
if (this->cdb_ptr[4] & ScsiStartStopUnit::START) {
|
||||
if (this->cdb_ptr[4] & ScsiStartStopUnit::LOAD_EJECT)
|
||||
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] & ScsiStartStopUnit::LOAD_EJECT)
|
||||
this->eject_medium();
|
||||
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();
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void process_command() override;
|
||||
virtual void eject_medium();
|
||||
|
||||
uint32_t get_lba();
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
ScsiBus::ScsiBus(const std::string name)
|
||||
{
|
||||
@@ -339,65 +338,28 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
}
|
||||
}
|
||||
|
||||
int default_cdrom_id = -1;
|
||||
std::string cdr_config = GET_STR_PROP("cdr_config");
|
||||
if (!cdr_config.empty()) {
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
parse_device_path(cdr_config, bus_id, dev_num);
|
||||
// Only consume SCSI paths; other buses handle their own CD-ROM configuration.
|
||||
if (bus_id.starts_with("Scsi")) {
|
||||
auto bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name_optional(bus_id));
|
||||
if (!bus_obj)
|
||||
ABORT_F("cdr_config device path %s does not specify a known SCSI bus", cdr_config.c_str());
|
||||
if (dev_num >= SCSI_MAX_DEVS)
|
||||
ABORT_F("Invalid SCSI ID in cdr_config device path %s", cdr_config.c_str());
|
||||
if (bus_obj == this) {
|
||||
if (this->devices[dev_num])
|
||||
ABORT_F("%s: cdr_config SCSI ID %u is already occupied", bus_id.c_str(), dev_num);
|
||||
default_cdrom_id = dev_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image_path = GET_STR_PROP("cdr_img" + bus_suffix);
|
||||
std::vector<std::string> cdrom_paths;
|
||||
if (!image_path.empty()) {
|
||||
// Keep empty entries, including the last one, as empty CD-ROM drives.
|
||||
size_t start = 0;
|
||||
size_t end;
|
||||
do {
|
||||
end = image_path.find(':', start);
|
||||
cdrom_paths.push_back(image_path.substr(start, end - start));
|
||||
start = end + 1;
|
||||
} while (end != std::string::npos);
|
||||
} else if (default_cdrom_id >= 0) {
|
||||
cdrom_paths.push_back("");
|
||||
}
|
||||
for (const auto& path : cdrom_paths) {
|
||||
if (default_cdrom_id >= 0) {
|
||||
scsi_id = default_cdrom_id;
|
||||
default_cdrom_id = -1;
|
||||
} else {
|
||||
// do two passes because we start at ID 3.
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we start at ID 3.
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 &&
|
||||
this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
}
|
||||
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiCdrom *scsi_device = new ScsiCdrom(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
if (!path.empty() && !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.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiCdrom *scsi_device = new ScsiCdrom(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,9 @@ 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) {
|
||||
if (this->seq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
@@ -173,7 +170,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);
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
@@ -105,7 +104,7 @@ protected:
|
||||
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
|
||||
|
||||
// Sequencer state
|
||||
TimerInfo seq_timer;
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
int cur_bus_phase = 0;
|
||||
|
||||
@@ -43,8 +43,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
bool is_device_ready() override { return this->medium_present(); }
|
||||
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
|
||||
bool is_device_ready() override { return this->is_ready; }
|
||||
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
|
||||
@@ -42,11 +42,6 @@ ScsiCdromCmds::ScsiCdromCmds() {
|
||||
}
|
||||
|
||||
void ScsiCdromCmds::process_command() {
|
||||
if (!this->ready_for_command()) {
|
||||
phy_impl->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int next_phase;
|
||||
|
||||
// use non-disk buffer by default
|
||||
@@ -67,30 +62,6 @@ void ScsiCdromCmds::process_command() {
|
||||
phy_impl->switch_phase(next_phase);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -35,8 +35,6 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void process_command() override;
|
||||
int test_unit_ready() override;
|
||||
void eject_medium() override;
|
||||
|
||||
int get_apple_page_49(uint8_t subpage, uint8_t ctrl,
|
||||
uint8_t *out_ptr, int avail_len);
|
||||
|
||||
@@ -109,33 +109,16 @@ int ScsiCommonCmds::verify_cdb() {
|
||||
}
|
||||
|
||||
int ScsiCommonCmds::test_unit_ready() {
|
||||
this->ready_for_command(true);
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
bool ScsiCommonCmds::ready_for_command(bool force_check) {
|
||||
// TUR forces a check from its handler; dispatch lets it and media-independent
|
||||
// commands through to ScsiCommonCmds.
|
||||
if (!force_check) {
|
||||
switch (this->cdb_ptr[0]) {
|
||||
case ScsiCommand::INQUIRY:
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Assume that LUN is okay and the status has been set to GOOD
|
||||
|
||||
if (!phy_impl->is_device_ready()) {
|
||||
this->sense_key = ScsiSense::NOT_READY;
|
||||
this->asc = phy_impl->not_ready_reason();
|
||||
this->ascq = 0;
|
||||
phy_impl->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
int ScsiCommonCmds::inquiry() {
|
||||
|
||||
@@ -98,8 +98,6 @@ protected:
|
||||
virtual void invalid_command();
|
||||
virtual void illegal_request(uint8_t asc, uint8_t ascq, bool is_cdb = true);
|
||||
|
||||
bool ready_for_command(bool force_check = false);
|
||||
|
||||
int get_one_page(uint8_t ctrl, uint8_t page, uint8_t subpage, uint8_t* out_ptr,
|
||||
int avail_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->attach_image(filename))
|
||||
if (this->set_host_file(filename) < 0)
|
||||
ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str());
|
||||
|
||||
this->is_writeable = true;
|
||||
@@ -177,9 +177,7 @@ void ScsiHardDisk::format() {
|
||||
if (this->cmd_buf[1] & 0x10)
|
||||
ABORT_F("%s: defect list isn't supported yet", this->name.c_str());
|
||||
|
||||
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) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(NS_PER_SEC, [this]() {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
@@ -41,7 +40,7 @@ public:
|
||||
void process_command() override;
|
||||
|
||||
protected:
|
||||
bool is_device_ready() override { return this->image_attached(); }
|
||||
bool is_device_ready() override { return this->is_ready; }
|
||||
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
@@ -56,7 +55,6 @@ protected:
|
||||
|
||||
private:
|
||||
uint8_t data_buf[2048] = {};
|
||||
TimerInfo phase_switch_timer;
|
||||
};
|
||||
|
||||
#endif // SCSI_HD_H
|
||||
@@ -31,17 +31,15 @@ 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 acknowledged", this->scsi_id);
|
||||
LOG_F(9, "device %d: bus reset aknowledged", 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);
|
||||
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,
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
BUS_SETTLE_DELAY,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
// 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;
|
||||
|
||||
+66
-96
@@ -36,15 +36,11 @@ 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";
|
||||
|
||||
@@ -103,17 +99,21 @@ ViaCuda::ViaCuda() : I2CBus() {
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer);
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
if (this->treq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer);
|
||||
if (this->treq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer_id);
|
||||
this->treq_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,12 +160,10 @@ uint8_t ViaCuda::read(int reg) {
|
||||
case VIA_T1LH:
|
||||
return this->via_t1lh;
|
||||
case VIA_T2CL:
|
||||
this->check_t2();
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
|
||||
case VIA_T2CH:
|
||||
this->check_t2();
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
case VIA_SR:
|
||||
value = this->via_sr;
|
||||
@@ -177,7 +175,6 @@ uint8_t ViaCuda::read(int reg) {
|
||||
case VIA_PCR:
|
||||
return this->via_pcr;
|
||||
case VIA_IFR:
|
||||
this->check_t2();
|
||||
return this->_via_ifr;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
@@ -213,8 +210,9 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
@@ -223,7 +221,7 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->via_t1lh = value;
|
||||
// load the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->activate_t1(TimerManager::get_instance()->current_time_ns());
|
||||
this->activate_t1();
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
@@ -239,15 +237,26 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2ll;
|
||||
this->activate_t2(TimerManager::get_instance()->current_time_ns());
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
(this->via_clk_dur * (this->t2_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->via_sr = value;
|
||||
@@ -284,58 +293,30 @@ uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t &star
|
||||
{
|
||||
// calculate current counter value based on elapsed time and timer frequency
|
||||
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
|
||||
// The loaded value remains visible during the initial half-clock delay.
|
||||
if (cur_time <= start_time)
|
||||
return last_val;
|
||||
uint64_t diff_hi;
|
||||
uint32_t diff_lo;
|
||||
_u32xu64(this->via_clk_freq, cur_time - start_time, diff_hi, diff_lo);
|
||||
return last_val - (diff_hi >> 10);
|
||||
}
|
||||
|
||||
void ViaCuda::activate_t1(uint64_t start_time) {
|
||||
void ViaCuda::activate_t1() {
|
||||
// TODO: delay for one phase 2 clock
|
||||
this->t1_start_time = start_time;
|
||||
uint64_t timeout = start_time +
|
||||
((this->via_clk_dur * (this->t1_counter + 3) + (uint64_t(1) << 36)) >> 37);
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
TimerManager::get_instance()->add_absolute_timer(this->t1_timer,
|
||||
timeout, 0,
|
||||
[this](uint64_t timeout_ns, uint64_t /*time_now*/) {
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
(this->via_clk_dur * (this->t1_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this]() {
|
||||
// reload the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
if (this->via_acr & 0x40)
|
||||
this->activate_t1(timeout_ns);
|
||||
this->activate_t1();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ViaCuda::activate_t2(uint64_t start_time) {
|
||||
// T2's one-shot interrupt occurs N + 1.5 VIA clocks after loading N.
|
||||
// Timer begins counting after 0.5 VIA clocks
|
||||
start_time += (this->via_clk_dur + (uint64_t(1) << 37)) >> 38;
|
||||
this->t2_start_time = start_time;
|
||||
// Timer ends N + 1 VIA clocks after start time.
|
||||
uint64_t timeout = start_time +
|
||||
((this->via_clk_dur * (this->t2_counter + 1) + (uint64_t(1) << 36)) >> 37);
|
||||
TimerManager::get_instance()->add_absolute_timer(
|
||||
this->t2_timer, timeout, 0, [this](uint64_t, uint64_t) { this->assert_t2_int(); });
|
||||
}
|
||||
|
||||
void ViaCuda::check_t2() {
|
||||
// The process_events is where assert_t2_int is supposed to happen,
|
||||
// but if a register read doesn't see that an interrupt happened
|
||||
// when the counter wraps, then Microseconds in classic Mac OS will
|
||||
// fail, so we call assert_t2_int here which sets the IFR register
|
||||
// makes the interrupt happen as soon as possible.
|
||||
auto tm = TimerManager::get_instance();
|
||||
if (this->t2_timer.active && tm->current_time_ns() >= this->t2_timer.timeout_ns) {
|
||||
tm->cancel_timer(this->t2_timer);
|
||||
this->assert_t2_int();
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::print_enabled_ints() {
|
||||
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
|
||||
|
||||
@@ -401,12 +382,14 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
}
|
||||
|
||||
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
if (this->sr_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer);
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->sr_timer,
|
||||
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
timeout_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->sr_timer_id = 0;
|
||||
this->assert_sr_int();
|
||||
}
|
||||
);
|
||||
@@ -437,13 +420,12 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
process_packet();
|
||||
|
||||
// start response transaction
|
||||
if (this->treq_timer.active)
|
||||
LOG_F(ERROR, "Cuda: treq_timer is already active");
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->treq_timer,
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -636,7 +618,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.active || this->sr_timer.active) {
|
||||
if (!this->treq || this->treq_timer_id || this->sr_timer_id) {
|
||||
// ERS: track missed ticks for mode $02/$03 fallback
|
||||
if (this_time != this->last_time)
|
||||
this->one_sec_missed = true;
|
||||
@@ -808,8 +790,7 @@ void ViaCuda::pseudo_command() {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
this->power_messages_enabled = !!this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: power messages %s", this->power_messages_enabled ? "enabled" : "disabled");
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X SET_POWER_MESSAGES", cmd);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
@@ -817,18 +798,7 @@ void ViaCuda::pseudo_command() {
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
break;
|
||||
case CUDA_TIMER_TICKLE:
|
||||
// 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");
|
||||
}
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X TIMER_TICKLE - Byte Sent: 0x%02x", cmd, this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_COMB_FMT_I2C:
|
||||
@@ -876,24 +846,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() {
|
||||
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);
|
||||
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();
|
||||
}
|
||||
auto elapsed_systemclock = std::chrono::system_clock::now() - this->mac_epoch;
|
||||
auto elapsed_systemclock = end - this->mac_epoch;
|
||||
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
|
||||
return uint32_t(elapsed_seconds.count());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ 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>
|
||||
|
||||
@@ -173,10 +172,6 @@ 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();
|
||||
|
||||
@@ -203,20 +198,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
|
||||
TimerInfo sr_timer;
|
||||
uint32_t sr_timer_id = 0;
|
||||
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
|
||||
TimerInfo t1_timer;
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
uint8_t via_t2ll; // low-order latch (write-only)
|
||||
uint16_t t2_counter; // internal counter
|
||||
TimerInfo t2_timer;
|
||||
uint32_t t2_timer_id = 0;
|
||||
uint64_t t2_start_time = 0;
|
||||
|
||||
// VIA interrupt related stuff
|
||||
@@ -230,7 +225,7 @@ private:
|
||||
uint8_t old_byteack;
|
||||
uint8_t treq;
|
||||
bool is_sync_state = false;
|
||||
TimerInfo treq_timer;
|
||||
uint32_t treq_timer_id = 0;
|
||||
uint8_t in_buf[CUDA_IN_BUF_SIZE];
|
||||
int32_t in_count;
|
||||
int max_in_count = 0;
|
||||
@@ -244,10 +239,8 @@ 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 power_messages_enabled = false;
|
||||
uint8_t tickle_value = 0; // last shutdown watchdog count from the guest
|
||||
bool file_server = false;
|
||||
bool mono_stable = false;
|
||||
uint8_t ipl_level = 0;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
@@ -273,9 +266,7 @@ private:
|
||||
void assert_t2_int();
|
||||
void schedule_sr_int(uint64_t timeout_ns);
|
||||
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t &start_time);
|
||||
void activate_t1(uint64_t start_time);
|
||||
void activate_t2(uint64_t start_time);
|
||||
void check_t2();
|
||||
void activate_t1();
|
||||
|
||||
// CUDA methods
|
||||
void cuda_init();
|
||||
|
||||
+28
-27
@@ -70,14 +70,17 @@ void Swim3Ctrl::reset()
|
||||
this->timer_val = 0;
|
||||
this->phase_lines = 0;
|
||||
|
||||
if (this->one_us_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer);
|
||||
if (this->one_us_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer_id);
|
||||
this->one_us_timer_id = 0;
|
||||
}
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 0;
|
||||
}
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +115,6 @@ 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);
|
||||
@@ -236,7 +237,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.active) {
|
||||
if (this->step_timer_id) {
|
||||
this->stop_stepping();
|
||||
}
|
||||
this->int_flags |= INT_STEP_DONE;
|
||||
@@ -252,12 +253,12 @@ void Swim3Ctrl::start_stepping()
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer.active) {
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: another stepping action is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer.active) {
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: stepping attempt while disk access is in progress!");
|
||||
return;
|
||||
}
|
||||
@@ -272,9 +273,9 @@ void Swim3Ctrl::start_stepping()
|
||||
|
||||
// step count > 1 requires periodic task
|
||||
if (this->step_count > 1) {
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->step_timer,
|
||||
this->step_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
USECS_TO_NSECS(80),
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->do_step();
|
||||
}
|
||||
);
|
||||
@@ -287,20 +288,21 @@ void Swim3Ctrl::start_stepping()
|
||||
void Swim3Ctrl::stop_stepping()
|
||||
{
|
||||
// cancel stepping task
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 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.active) {
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: another disk access is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer.active) {
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: disk access attempt while stepping is in progress!");
|
||||
return;
|
||||
}
|
||||
@@ -315,9 +317,9 @@ void Swim3Ctrl::start_disk_access()
|
||||
|
||||
this->target_sect = this->first_sec;
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->int_drive->sync_to_disk(),
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
this->disk_access();
|
||||
}
|
||||
@@ -367,9 +369,9 @@ void Swim3Ctrl::disk_access()
|
||||
return;
|
||||
}
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
@@ -378,8 +380,9 @@ void Swim3Ctrl::disk_access()
|
||||
void Swim3Ctrl::stop_disk_access()
|
||||
{
|
||||
// cancel disk access timer
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,11 +399,9 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
|
||||
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
|
||||
|
||||
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,
|
||||
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
uint32_t(this->timer_val) * NS_PER_USEC,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
update_irq();
|
||||
|
||||
@@ -140,9 +140,9 @@ private:
|
||||
uint8_t rd_line;
|
||||
int cur_state;
|
||||
|
||||
TimerInfo one_us_timer;
|
||||
TimerInfo step_timer;
|
||||
TimerInfo access_timer;
|
||||
int one_us_timer_id = 0;
|
||||
int step_timer_id = 0;
|
||||
int access_timer_id = 0;
|
||||
|
||||
uint64_t one_us_timer_start = 0;
|
||||
|
||||
|
||||
+27
-42
@@ -96,8 +96,9 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
AMIC::~AMIC()
|
||||
{
|
||||
if (this->pseudo_vbl_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_timer);
|
||||
if (this->pseudo_vbl_tid) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_tid);
|
||||
this->pseudo_vbl_tid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +113,9 @@ int AMIC::device_postinit()
|
||||
}
|
||||
|
||||
// AMIC drives the VIA CA1 internally to generate 60.15 Hz interrupts
|
||||
TimerManager::get_instance()->add_cyclic_timer(pseudo_vbl_timer,
|
||||
this->pseudo_vbl_tid = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>((1.0f/60.15) * NS_PER_SEC + 0.5f),
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->viacuda->assert_ctrl_line(ViaLine::CA1);
|
||||
});
|
||||
|
||||
@@ -634,9 +635,7 @@ 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;
|
||||
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) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
|
||||
});
|
||||
}
|
||||
@@ -688,10 +687,10 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
|
||||
MapDmaResult res = mmu_map_dma_mem(
|
||||
(this->snd_buf_num ? this->out_buf1 : this->out_buf0) + this->cur_buf_pos,
|
||||
len, false, true);
|
||||
len, false);
|
||||
*p_data = res.host_va;
|
||||
this->cur_buf_pos += res.size;
|
||||
*avail_len = res.size;
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
|
||||
@@ -724,19 +723,15 @@ DmaPushResult AmicFloppyDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
len = std::min((int)this->byte_count, len);
|
||||
|
||||
do {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false, true);
|
||||
uint8_t *p_data = res.host_va;
|
||||
if (!res.is_writable) {
|
||||
ABORT_F("AMIC: attempting DMA write to read-only memory");
|
||||
}
|
||||
std::memcpy(p_data, src_ptr, res.size);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
uint8_t *p_data = res.host_va;
|
||||
if (!res.is_writable) {
|
||||
ABORT_F("AMIC: attempting DMA write to read-only memory");
|
||||
}
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += res.size;
|
||||
this->byte_count -= res.size;
|
||||
src_ptr += res.size;
|
||||
len -= res.size;
|
||||
} while (len > 0);
|
||||
this->addr_ptr += len;
|
||||
this->byte_count -= len;
|
||||
if (!this->byte_count) {
|
||||
LOG_F(WARNING, "AMIC: DMA interrupts not implemented yet");
|
||||
}
|
||||
@@ -787,17 +782,12 @@ void AmicScsiDma::xfer_from_device() {
|
||||
|
||||
uint32_t len = this->dev_obj->tell_xfer_size(this);
|
||||
|
||||
do {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false, true);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_from(this, res.host_va, res.size);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
if (got_bytes < res.size)
|
||||
break;
|
||||
len -= res.size;
|
||||
} while (len > 0);
|
||||
int got_bytes = this->dev_obj->xfer_from(this, res.host_va, len);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
void AmicScsiDma::xfer_to_device() {
|
||||
@@ -808,17 +798,12 @@ void AmicScsiDma::xfer_to_device() {
|
||||
|
||||
uint32_t len = this->dev_obj->tell_xfer_size(this);
|
||||
|
||||
do {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false, true);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_to(this, res.host_va, res.size);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
if (got_bytes < res.size)
|
||||
break;
|
||||
len -= res.size;
|
||||
} while (len > 0);
|
||||
int got_bytes = this->dev_obj->xfer_to(this, res.host_va, len);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
void AmicScsiDma::xfer_retry() {
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
@@ -134,7 +133,6 @@ 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. */
|
||||
@@ -413,7 +411,7 @@ private:
|
||||
uint8_t via2_slot_ifr = 0x7F; // reverse logic
|
||||
uint8_t via2_slot_irq = 0; // normal logic
|
||||
|
||||
TimerInfo pseudo_vbl_timer; // the pseudo-VBL timer
|
||||
uint32_t pseudo_vbl_tid = 0; // ID for the pseudo-VBL timer
|
||||
|
||||
// AMIC subdevice instances
|
||||
Sc53C94* scsi;
|
||||
|
||||
@@ -41,14 +41,13 @@ NvramDev::NvramDev(NvramAddrHiDev *addr_hi) {
|
||||
|
||||
GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::IOBUS_HOST | HWCompType::MMIO_DEV |
|
||||
HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
supports_types(HWCompType::IOBUS_HOST | HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = MIO_DEV_ID_GRANDCENTRAL;
|
||||
this->status = 0x0200; // 9:DEVSEL
|
||||
this->class_rev = MACIO_DEVCLASS_ID | 2; // hardcoded revision = 2
|
||||
this->class_rev = 0xFF000002;
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
this->setup_bars({{0, 0xFFFE0000UL}}); // declare 128Kb of memory-mapped I/O space
|
||||
@@ -296,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 & this->int_mask);
|
||||
return BYTESWAP_32(this->int_events);
|
||||
case MIO_INT_MASK1:
|
||||
return BYTESWAP_32(this->int_mask);
|
||||
case MIO_INT_CLEAR1:
|
||||
@@ -304,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 | (1<<0x0B));
|
||||
return BYTESWAP_32(this->int_levels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +433,6 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask = BYTESWAP_32(value);
|
||||
this->clear_cpu_int();
|
||||
this->signal_cpu_int();
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
@@ -525,11 +523,15 @@ uint64_t GrandCentral::register_dma_int(IntSrc src_id) {
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
// MACIO_INT_MODE is 0: native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// MACIO_INT_MODE is 1: emulated mode: set IRQ bits in int_events on all transitions
|
||||
// native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events on all transitions
|
||||
|
||||
uint32_t old_levels = this->int_levels;
|
||||
uint32_t old_events = this->int_events;
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= (uint32_t)irq_id;
|
||||
} else {
|
||||
this->int_events &= ~(uint32_t)irq_id;
|
||||
}
|
||||
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
@@ -538,16 +540,7 @@ void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->int_levels &= ~(uint32_t)irq_id;
|
||||
}
|
||||
|
||||
if (
|
||||
irq_line_state != !!(old_levels & irq_id)
|
||||
&& (irq_line_state || (this->int_mask & MACIO_INT_MODE))
|
||||
) {
|
||||
this->int_events |= (uint32_t)irq_id;
|
||||
// Events remain latched until software writes InterruptClear.
|
||||
if (old_events != this->int_events) {
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
|
||||
@@ -44,9 +44,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** MacIO ASICs report themselves as devices with unassigned PCI class code. */
|
||||
constexpr uint32_t MACIO_DEVCLASS_ID = DEVCLASS_UNASSIGNED << 24;
|
||||
|
||||
/** PCI device IDs for various MacIO ASICs. */
|
||||
enum {
|
||||
MIO_DEV_ID_GRANDCENTRAL = 0x0002,
|
||||
@@ -362,10 +359,10 @@ private:
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
uint8_t cpu_id = 0xF0; // CPUID field (LSB of the MIO_OHARE_ID)
|
||||
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_OHARE_ID)
|
||||
uint8_t mon_id = 0x10; // Monitor ID (bits 23:16 of the MIO_OHARE_ID)
|
||||
uint8_t fp_id = 0x70; // Flat panel ID (MSB of the MIO_OHARE_ID)
|
||||
uint8_t cpu_id = 0xF0; // CPUID field (LSB of the MIO_HEAT_ID)
|
||||
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
|
||||
uint8_t mon_id = 0x10; // Monitor ID (bits 23:16 of the MIO_HEAT_ID)
|
||||
uint8_t fp_id = 0x70; // Flat panel ID (MSB of the MIO_HEAT_ID)
|
||||
|
||||
// Subdevice object pointers
|
||||
NVram* nvram; // NVRAM
|
||||
|
||||
@@ -38,7 +38,7 @@ MacIoBase::MacIoBase(std::string name, uint16_t dev_id, uint8_t rev) :
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = dev_id;
|
||||
this->class_rev = MACIO_DEVCLASS_ID + rev;
|
||||
this->class_rev = 0xFF000000 + rev;
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
// select memory mapped I/O size: 128Kb for Grand Central, 512Kb for others
|
||||
@@ -133,8 +133,8 @@ uint64_t MacIoBase::register_dma_int(IntSrc src_id) {
|
||||
}
|
||||
|
||||
void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
// MACIO_INT_MODE is 0: native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// MACIO_INT_MODE is 1: emulated mode: set IRQ bits in int_events on all transitions
|
||||
// native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events on all transitions
|
||||
#if 0
|
||||
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
|
||||
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events),
|
||||
@@ -142,9 +142,12 @@ void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
|
||||
);
|
||||
#endif
|
||||
uint64_t old_levels = this->int_levels;
|
||||
uint64_t old_events = this->int_events;
|
||||
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= irq_id;
|
||||
} else {
|
||||
this->int_events &= ~irq_id;
|
||||
}
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
@@ -152,16 +155,7 @@ void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
|
||||
if (
|
||||
irq_line_state != !!(old_levels & irq_id)
|
||||
&& (irq_line_state || (this->int_mask & MACIO_INT_MODE))
|
||||
) {
|
||||
this->int_events |= irq_id;
|
||||
// Events remain latched until software writes InterruptClear.
|
||||
if (old_events != this->int_events) {
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
|
||||
void MacIoBase::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
|
||||
@@ -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 & this->int_mask) >> 32;
|
||||
value = this->int_events >> 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 & this->int_mask);
|
||||
value = uint32_t(this->int_events);
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
value = uint32_t(this->int_mask);
|
||||
@@ -366,10 +366,7 @@ void MacIoTwo::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
|
||||
switch (offset & ~3) {
|
||||
case MIO_INT_MASK2:
|
||||
// Preserve the first bank and the read-only IntMode bit.
|
||||
this->int_mask = (this->int_mask & 0x80000000FFFFFFFFULL) |
|
||||
(uint64_t(value & ~MACIO_INT_MODE) << 32);
|
||||
this->clear_cpu_int();
|
||||
this->int_mask |= uint64_t(value & ~MACIO_INT_MODE) << 32;
|
||||
this->signal_cpu_int();
|
||||
break;
|
||||
case MIO_INT_CLEAR2:
|
||||
@@ -380,7 +377,6 @@ void MacIoTwo::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_mask = (this->int_mask & 0x7FFFFFFF00000000ULL) | value;
|
||||
// copy IntMode bit to InterruptMask2 register
|
||||
this->int_mask |= uint64_t(this->int_mask & MACIO_INT_MODE) << 32;
|
||||
this->clear_cpu_int();
|
||||
this->signal_cpu_int();
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
|
||||
+17
-34
@@ -40,7 +40,7 @@ MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
|
||||
// populate PCI config header
|
||||
this->vendor_id = PCI_VENDOR_MOTOROLA;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = DEVTYPE_HOST2PCI_BRIDGE | GRACKLE_REV_4_0;
|
||||
this->class_rev = 0x06000040;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 6;
|
||||
this->status = 0x80;
|
||||
@@ -314,41 +314,24 @@ void MPC106::setup_ram() {
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap GrackleGossamer_Properties = {
|
||||
{"pci_PERCH", new StrProperty("")},
|
||||
{"pci_A1" , new StrProperty("")},
|
||||
{"pci_B1" , new StrProperty("")},
|
||||
{"pci_C1" , new StrProperty("")},
|
||||
// {"pci_GPU" , new StrProperty("")},
|
||||
static const PropMap Grackle_Properties = {
|
||||
{"pci_PERCH",
|
||||
new StrProperty("")},
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
//{"pci_GPU",
|
||||
// new StrProperty("")},
|
||||
{"pci_J12",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap GrackleYosemite_Properties = {
|
||||
// {"pci_J12", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap GrackleBondi_Properties = {
|
||||
{"pci_A1" , new StrProperty("")},
|
||||
{"pci_B1" , new StrProperty("")},
|
||||
{"pci_C1" , new StrProperty("")},
|
||||
// {"pci_GPU" , new StrProperty("")},
|
||||
{"pci_PERCH", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription GrackleGossamer_Descriptor = {
|
||||
MPC106::create, {}, GrackleGossamer_Properties,
|
||||
static const DeviceDescription Grackle_Descriptor = {
|
||||
MPC106::create, {}, Grackle_Properties,
|
||||
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
static const DeviceDescription GrackleYosemite_Descriptor = {
|
||||
MPC106::create, {}, GrackleYosemite_Properties,
|
||||
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
static const DeviceDescription GrackleBondi_Descriptor = {
|
||||
MPC106::create, {}, GrackleBondi_Properties,
|
||||
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(GrackleGossamer, GrackleGossamer_Descriptor);
|
||||
REGISTER_DEVICE(GrackleYosemite, GrackleYosemite_Descriptor);
|
||||
REGISTER_DEVICE(GrackleBondi , GrackleBondi_Descriptor );
|
||||
REGISTER_DEVICE(Grackle, Grackle_Descriptor);
|
||||
@@ -42,8 +42,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Grackle ASIC revisions. */
|
||||
constexpr uint8_t GRACKLE_REV_4_0 = 0x40;
|
||||
class InterruptCtrl;
|
||||
|
||||
/** Grackle configuration space registers. */
|
||||
enum GrackleReg : uint32_t {
|
||||
|
||||
@@ -58,15 +58,7 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
|
||||
// initialize the CPUID register with the following CPU:
|
||||
// PowerPC 601 @ 90 MHz, bus frequency: 45 MHz
|
||||
this->cpu_id =
|
||||
( 0x3 << 28) | // Design Center: 3 = High-End RISC Design Center
|
||||
( 0 << 24) | // Upper ID: 0 = machine with registers wider than 8-bit
|
||||
(0x01 << 16) | // Lower ID: 1 = Platinum-based machine
|
||||
ClkSrc2 | // Clock Source: bits 15 and 6
|
||||
( 0 << 12) | // Motherboard ID: Catalyst motherboard with 1 MB of VRAM
|
||||
(CpuSpeed2::CPU_90_BUS_45 << 8)
|
||||
| // System/CPU Speed
|
||||
( 0 << 7) ; // CPU Type: 0 = 601, 1 = 603/604
|
||||
this->cpu_id = (0x3001 << 16) | ClkSrc2 | (CpuSpeed2::CPU_90_BUS_45 << 8);
|
||||
|
||||
this->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
|
||||
@@ -78,10 +70,8 @@ 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) {
|
||||
@@ -92,14 +82,6 @@ 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() {
|
||||
@@ -132,7 +114,7 @@ uint32_t PlatinumCtrl::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return read_mem(&this->vram_ptr[offset], size);
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: read from unmapped aperture address 0x%X",
|
||||
this->name.c_str(), VRAM_REGION_BASE + offset);
|
||||
this->name.c_str(), this->fb_addr + offset);
|
||||
return (uint32_t)-1;
|
||||
}
|
||||
}
|
||||
@@ -233,12 +215,11 @@ 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) {
|
||||
this->draw_fb = true;
|
||||
if (offset < this->vram_size)
|
||||
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(), VRAM_REGION_BASE + offset);
|
||||
this->name.c_str(), this->fb_addr + offset);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,10 +228,10 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->rom_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_TIMING:
|
||||
this->dram_timing = value & 0x1FFF;
|
||||
this->dram_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
this->dram_refresh = value & 0x7FF;
|
||||
this->dram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
@@ -260,22 +241,20 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
case PlatinumReg::BANK_5_BASE:
|
||||
case PlatinumReg::BANK_6_BASE:
|
||||
case PlatinumReg::BANK_7_BASE:
|
||||
this->bank_base[(offset >> 4) - PlatinumReg::BANK_0_BASE] = value & 0xFF700000U;
|
||||
this->bank_base[(offset >> 4) - PlatinumReg::BANK_0_BASE] = value;
|
||||
this->map_phys_ram();
|
||||
break;
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
if (this->fb_addr != value) {
|
||||
this->fb_addr = value;
|
||||
this->fb_offset = value & 0x3FFFFF;
|
||||
this->change_display();
|
||||
}
|
||||
this->fb_addr = value;
|
||||
this->fb_offset = value & 0x3FFFFF;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::ROW_WORDS:
|
||||
this->row_words = value & 0x7FF8;
|
||||
this->row_words = value & ~7;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::CLOCK_DIVISOR:
|
||||
this->clock_divisor = value & 0xFFU;
|
||||
this->clock_divisor = value;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_1:
|
||||
@@ -286,10 +265,10 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->half_bank = !!(this->vram_megs == 1 && (value & CFG1_FULL_BANKS));
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_2:
|
||||
this->fb_config_2 = value & 0x1FFF;
|
||||
this->fb_config_2 = value;
|
||||
break;
|
||||
case PlatinumReg::VMEM_PAGE_MODE:
|
||||
this->vmem_fp_mode = value & 1;
|
||||
this->vmem_fp_mode = value;
|
||||
break;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
value &= 7;
|
||||
@@ -300,7 +279,6 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
(this->display_id->read_monitor_sense(mon_levels, mon_dirs) ^ 7);
|
||||
break;
|
||||
case PlatinumReg::FB_RESET:
|
||||
value &= 7;
|
||||
if (value == 7 && this->crtc_on) {
|
||||
LOG_F(INFO, "%s: video disabled", this->name.c_str());
|
||||
this->reset_step = 0;
|
||||
@@ -336,10 +314,10 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
(value & (SENSE_LINE_OUTPUT_DATA | SYNCS_OUTPUT_ENABLE | FORCED_SYNC_LEVELS));
|
||||
break;
|
||||
case PlatinumReg::VRAM_REFRESH:
|
||||
this->vram_refresh = value & 0x7FF;
|
||||
this->vram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_CONFIG:
|
||||
this->swatch_config = (this->swatch_config & ~0xFFU) | (value & 0xFFU);
|
||||
this->swatch_config = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_INT_MASK:
|
||||
this->swatch_int_mask = value;
|
||||
@@ -347,7 +325,7 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
LOG_F(INFO, "%s: VBL interrupt enabled", this->name.c_str());
|
||||
break;
|
||||
case PlatinumReg::CURSOR_LINE:
|
||||
this->cursor_line = value & 0x7FF;
|
||||
this->cursor_line = value;
|
||||
if (this->swatch_int_mask & SWATCH_INT_CURSOR)
|
||||
this->enable_cursor_int();
|
||||
break;
|
||||
@@ -360,6 +338,7 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
//break;
|
||||
case PlatinumReg::SWATCH_HSERR:
|
||||
case PlatinumReg::SWATCH_HLFLN:
|
||||
case PlatinumReg::SWATCH_HEQ:
|
||||
case PlatinumReg::SWATCH_HSP:
|
||||
case PlatinumReg::SWATCH_HBWAY:
|
||||
case PlatinumReg::SWATCH_HBRST:
|
||||
@@ -374,15 +353,11 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
case PlatinumReg::SWATCH_VAL:
|
||||
case PlatinumReg::SWATCH_VFP:
|
||||
case PlatinumReg::SWATCH_VFPEQ:
|
||||
this->swatch_params[REG_TO_INDEX(offset >> 4)] = value & 0xFFF;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HEQ:
|
||||
this->swatch_params[REG_TO_INDEX(offset >> 4)] = value & 0xFF;
|
||||
this->swatch_params[REG_TO_INDEX(offset >> 4)] = value;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::TIMING_ADJUST:
|
||||
this->timing_adjust = value & 0xFFF;
|
||||
this->timing_adjust = value;
|
||||
break;
|
||||
case PlatinumReg::IRIDIUM_CONFIG:
|
||||
if (!(value & 1))
|
||||
@@ -539,19 +514,16 @@ 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;
|
||||
@@ -592,7 +564,6 @@ void PlatinumCtrl::enable_display() {
|
||||
|
||||
this->blank_on = false;
|
||||
this->crtc_on = true;
|
||||
this->draw_fb = true;
|
||||
}
|
||||
|
||||
void PlatinumCtrl::disable_display() {
|
||||
@@ -615,12 +586,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_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
if (this->cursor_task_id)
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_task_id);
|
||||
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->cursor_timer,
|
||||
this->cursor_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
cursor_int_freq,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
this->update_irq(1, SWATCH_INT_CURSOR); // generate cursor interrupt
|
||||
}
|
||||
);
|
||||
@@ -641,7 +612,7 @@ void PlatinumCtrl::update_irq(uint8_t irq_line_state, uint8_t irq_mask) {
|
||||
// ========================== Device registry stuff ==========================
|
||||
static const PropMap Platinum_Properties = {
|
||||
{"gfxmem_size",
|
||||
new IntProperty(4, std::vector<uint32_t>({1, 2, 4}))},
|
||||
new IntProperty(1, std::vector<uint32_t>({1, 2, 4}))},
|
||||
{"mon_id",
|
||||
new StrProperty("HiRes12-14in")},
|
||||
};
|
||||
|
||||
@@ -363,7 +363,7 @@ private:
|
||||
uint32_t swatch_int_mask = 0;
|
||||
uint32_t swatch_int_stat = 0;
|
||||
uint32_t cursor_line = 0;
|
||||
TimerInfo cursor_timer;
|
||||
uint32_t cursor_task_id = 0;
|
||||
|
||||
std::unique_ptr<uint8_t[]> vram_ptr = nullptr;
|
||||
std::unique_ptr<DisplayID> display_id = nullptr;
|
||||
|
||||
@@ -38,6 +38,7 @@ PsxCtrl::PsxCtrl(int bridge_num, std::string name)
|
||||
// add MMIO region for the PSX control registers
|
||||
this->add_mmio_region(0xF8000000, 0x70, this);
|
||||
|
||||
this->sys_id = 0x10000000; // PSX register dump from a 6500 at 68kmla
|
||||
this->set_revision_id(0x10); // PSX register dump from a 6500 at 68kmla
|
||||
this->set_bus_speed(PSX_BUS_SPEED_50); // set bus speed to 50 MHz by default
|
||||
}
|
||||
|
||||
@@ -92,13 +92,13 @@ public:
|
||||
void map_phys_ram();
|
||||
|
||||
private:
|
||||
uint32_t sys_id = 0x10000000; // PSX register dump from a 6500 at 68kmla
|
||||
uint32_t chip_rev = 0;
|
||||
uint32_t sys_config = 0;
|
||||
uint32_t rom_cfg = 0x000009D8;
|
||||
uint32_t dram_cfg = 0x00E18534;
|
||||
uint32_t dram_refresh = 0x001F0180;
|
||||
uint32_t flash_cfg = 0x00000038;
|
||||
uint32_t sys_id;
|
||||
uint32_t chip_rev;
|
||||
uint32_t sys_config;
|
||||
uint32_t rom_cfg;
|
||||
uint32_t dram_cfg;
|
||||
uint32_t dram_refresh;
|
||||
uint32_t flash_cfg;
|
||||
uint32_t pages_cfg[5] = {0x88888888,0x88888888,0x88888888,0x88888888,0x88888888};
|
||||
uint32_t bank_size[5] = {};
|
||||
std::unique_ptr<uint8_t[]> dram_ptr = nullptr;
|
||||
|
||||
@@ -114,12 +114,11 @@ 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);
|
||||
|
||||
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,
|
||||
this->dma_in_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10000,
|
||||
[this](uint64_t, uint64_t) {
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->dma_in_timer_id = 0;
|
||||
this->dma_in_data();
|
||||
});
|
||||
}
|
||||
@@ -131,8 +130,9 @@ void AwacsBase::dma_in_start() {
|
||||
}
|
||||
|
||||
void AwacsBase::dma_in_stop() {
|
||||
if (this->dma_in_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->dma_in_timer);
|
||||
if (this->dma_in_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->dma_in_timer_id);
|
||||
this->dma_in_timer_id = 0;
|
||||
}
|
||||
LOG_F(ERROR, "%s: dma_in_stop", this->name.c_str());
|
||||
}
|
||||
@@ -199,7 +199,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,6 +221,7 @@ 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
|
||||
TimerInfo dma_in_timer;
|
||||
uint32_t dma_in_timer_id = 0;
|
||||
|
||||
int *sr_table; // pointer to the table of supported sample rates
|
||||
int max_sr_id; // maximum value for sample rate ID
|
||||
|
||||
+28
-45
@@ -28,7 +28,8 @@ 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 };
|
||||
@@ -38,8 +39,6 @@ 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) {
|
||||
@@ -53,20 +52,9 @@ uint32_t BurgundyCodec::snd_ctrl_read(uint32_t offset, int size) {
|
||||
value = this->last_ctrl_data;
|
||||
break;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
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);
|
||||
value = (this->first_valid << 23) | BURGUNDY_READY |
|
||||
(this->byte_counter << 14) | (this->read_pos << 12) |
|
||||
(this->data_byte << 4);
|
||||
break;
|
||||
case AWAC_FRAME_COUNT:
|
||||
value = (uint32_t)(
|
||||
@@ -85,47 +73,42 @@ uint32_t BurgundyCodec::snd_ctrl_read(uint32_t offset, int size) {
|
||||
}
|
||||
|
||||
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);
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
//this->set_sample_rate((this->snd_ctrl_reg >> 8) & 7);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
{
|
||||
this->last_ctrl_data = value & ~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));
|
||||
}
|
||||
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));
|
||||
} else {
|
||||
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;
|
||||
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;
|
||||
|
||||
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 = false;
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(10), // not sure if this is the correct delay
|
||||
[this]() {
|
||||
this->first_valid = 0;
|
||||
this->byte_counter = (this->byte_counter + 1) & 3;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AWAC_FRAME_COUNT:
|
||||
this->frame_count = value;
|
||||
this->frame_count = BYTESWAP_32(value);
|
||||
this->frame_count_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -24,91 +24,20 @@ 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);
|
||||
@@ -126,8 +55,7 @@ private:
|
||||
uint32_t last_ctrl_data = 0;
|
||||
uint8_t byte_counter = 0;
|
||||
uint8_t reg_addr = 0;
|
||||
bool first_valid = false;
|
||||
TimerInfo first_valid_timer;
|
||||
uint8_t first_valid = 0;
|
||||
uint8_t read_pos = 0;
|
||||
uint8_t data_byte = 0;
|
||||
uint32_t frame_count = 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
cubeb *cubeb_ctx;
|
||||
cubeb_stream *out_stream;
|
||||
|
||||
TimerInfo deterministic_poll_timer;
|
||||
uint32_t deterministic_poll_timer = 0;
|
||||
timer_cb deterministic_poll_cb;
|
||||
};
|
||||
|
||||
@@ -167,26 +167,22 @@ 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.
|
||||
while(1) {
|
||||
uint8_t *chunk;
|
||||
uint32_t chunk_size;
|
||||
if (DmaPullResult::MoreData == dma_ch->pull_data(1024, &chunk_size, &chunk)) {
|
||||
;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
impl->status = SND_STREAM_OPENED;
|
||||
LOG_F(9, "Deterministic sound output callback set up.");
|
||||
return 0;
|
||||
@@ -227,35 +223,21 @@ int SoundServer::open_out_stream(uint32_t sample_rate, DmaOutChannel *dma_ch)
|
||||
int SoundServer::start_out_stream()
|
||||
{
|
||||
if (is_deterministic) {
|
||||
// DMA can restart after a STOP command without closing the output
|
||||
// stream; the timer may already be running.
|
||||
if (!impl->deterministic_poll_timer.active) {
|
||||
LOG_F(9, "Starting sound output deterministic polling.");
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
impl->deterministic_poll_timer, MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
return cubeb_stream_start(impl->out_stream);
|
||||
}
|
||||
|
||||
void SoundServer::close_out_stream()
|
||||
{
|
||||
if (impl->deterministic_poll_timer.active) {
|
||||
if (!impl->out_stream)
|
||||
return;
|
||||
if (is_deterministic) {
|
||||
LOG_F(9, "Stopping sound output deterministic polling.");
|
||||
TimerManager::get_instance()->cancel_timer(impl->deterministic_poll_timer);
|
||||
}
|
||||
if (!impl->out_stream) {
|
||||
impl->status = SND_STREAM_CLOSED;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,45 +39,22 @@ BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks,
|
||||
}
|
||||
|
||||
BlockStorageDevice::~BlockStorageDevice() {
|
||||
this->detach_image();
|
||||
this->img_file.close();
|
||||
}
|
||||
|
||||
bool BlockStorageDevice::attach_image(const std::string& file_path) {
|
||||
if (!this->img_file.open(file_path))
|
||||
return false;
|
||||
int BlockStorageDevice::set_host_file(std::string file_path) {
|
||||
this->is_ready = false;
|
||||
|
||||
this->is_ready = false;
|
||||
this->size_bytes = this->img_file.size();
|
||||
this->remain_size = 0;
|
||||
this->write_size = 0;
|
||||
this->data_offset = 0;
|
||||
if (!this->img_file.open(file_path))
|
||||
return -1;
|
||||
|
||||
this->size_bytes = this->img_file.size();
|
||||
|
||||
this->set_fpos(0);
|
||||
|
||||
this->is_ready = true;
|
||||
|
||||
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;
|
||||
return this->set_block_size(this->block_size);
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_block_size(const int blk_size) {
|
||||
|
||||
@@ -36,10 +36,7 @@ public:
|
||||
const uint64_t max_blocks=UINT64_MAX);
|
||||
~BlockStorageDevice();
|
||||
|
||||
bool attach_image(const std::string& file_path);
|
||||
bool detach_image();
|
||||
bool image_attached() const { return this->is_ready; }
|
||||
|
||||
int set_host_file(std::string file_path);
|
||||
int set_block_size(const int blk_size);
|
||||
|
||||
int set_fpos(const uint64_t lba);
|
||||
|
||||
@@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Virtual CD-ROM device implementation. */
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
@@ -30,46 +29,12 @@ 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_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;
|
||||
}
|
||||
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());
|
||||
|
||||
this->detect_raw_image();
|
||||
|
||||
@@ -80,19 +45,6 @@ bool CdromDrive::insert_image(const 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() {
|
||||
|
||||
@@ -74,22 +74,16 @@ 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;
|
||||
|
||||
bool medium_present() const { return this->image_attached(); }
|
||||
bool medium_present() { return this->is_ready; }
|
||||
|
||||
bool insert_image(const std::string& filename);
|
||||
bool eject_image();
|
||||
void insert_image(std::string filename);
|
||||
|
||||
protected:
|
||||
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();
|
||||
@@ -107,7 +101,6 @@ protected:
|
||||
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
|
||||
|
||||
@@ -83,62 +83,48 @@ 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.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
if (this->cursor_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer_id);
|
||||
cursor_timer_id = 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.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
if (this->cursor_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer_id);
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
cursor_timer_id = 0;
|
||||
}
|
||||
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_pos_lo = value;
|
||||
this->cursor_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
NS_PER_SEC / 60, [this]() {
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
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:
|
||||
if (this->dbl_buf_cr != value) {
|
||||
this->dbl_buf_cr = value;
|
||||
if (this->buffer_update_cb)
|
||||
this->buffer_update_cb();
|
||||
}
|
||||
this->dbl_buf_cr = value;
|
||||
break;
|
||||
case RamdacRegs::TEST_CTRL:
|
||||
this->tst_cr = value;
|
||||
|
||||
@@ -91,7 +91,6 @@ 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:
|
||||
@@ -118,9 +117,6 @@ 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;
|
||||
@@ -143,7 +139,7 @@ protected:
|
||||
uint32_t fb_pitch = 0;
|
||||
#ifdef CURSOR_LO_DELAY
|
||||
uint8_t cursor_pos_lo = 0;
|
||||
TimerInfo cursor_timer;
|
||||
uint32_t cursor_timer_id = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -443,9 +443,7 @@ 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);
|
||||
WRITE_VALUE_AND_LOG(9);
|
||||
this->update_interrupt();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
new_value = value;
|
||||
@@ -660,6 +658,8 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
|
||||
}
|
||||
|
||||
WRITE_VALUE_AND_LOG(9);
|
||||
if (reg_num == ATI_CRTC_INT_CNTL)
|
||||
this->update_interrupt();
|
||||
}
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset) {
|
||||
|
||||
+51
-143
@@ -48,10 +48,6 @@ 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,
|
||||
@@ -122,10 +118,8 @@ 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) {
|
||||
@@ -136,20 +130,6 @@ 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"));
|
||||
@@ -157,8 +137,6 @@ 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) {
|
||||
@@ -238,7 +216,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 & VRAM_BE_APERTURE) { // repeats every 16MB
|
||||
if (offset & 0x800000) { // 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
|
||||
@@ -298,38 +276,9 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
} // if not VRAM_WIDE_MODE
|
||||
}
|
||||
|
||||
// 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);
|
||||
LOG_F(ERROR, "%s: read from little-endian aperture address 0x%X", this->name.c_str(),
|
||||
this->vram_base + offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rgn_start == this->regs_base) {
|
||||
@@ -373,7 +322,7 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
case ControlRegs::MON_SENSE:
|
||||
value = (this->cur_mon_id << 6) | this->mon_sense;
|
||||
LOG_F(9, "%s: read MON_SENSE %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
case ControlRegs::MISC_ENABLES:
|
||||
value = this->enables;
|
||||
@@ -401,7 +350,7 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
uint32_t result = pci_conv_rd_data(value, value, details);
|
||||
if ((offset & 3) || (size != 4)) {
|
||||
LOG_F(WARNING, "%s: read %s %03x.%c = %08x -> %0*x", this->name.c_str(),
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -413,8 +362,7 @@ 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) {
|
||||
this->draw_fb = true;
|
||||
if (offset & VRAM_BE_APERTURE) {
|
||||
if (offset & 0x800000) {
|
||||
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.
|
||||
@@ -469,36 +417,9 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
}
|
||||
} // switch
|
||||
} // if not VRAM_WIDE_MODE
|
||||
} 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);
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: write to little-endian aperture address 0x%X", this->name.c_str(),
|
||||
this->vram_base + offset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -511,10 +432,10 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0x3FF;
|
||||
if (value & ~0x3FF)
|
||||
LOG_F(ERROR, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
else
|
||||
LOG_F(CONTROL, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
@@ -523,10 +444,10 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFU;
|
||||
if (value & ~0xFFU)
|
||||
LOG_F(ERROR, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
else
|
||||
LOG_F(CONTROL, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
@@ -548,10 +469,10 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFF;
|
||||
if (value & ~0xFFF)
|
||||
LOG_F(ERROR, "%s: write %s %03x.%c = %0*x", this->name.c_str(),
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
|
||||
else
|
||||
LOG_F(CONTROL, "%s: write %s %03x.%c = %0*x", this->name.c_str(),
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
|
||||
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
@@ -583,17 +504,12 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
} else
|
||||
this->swatch_ctrl = value;
|
||||
break;
|
||||
case ControlRegs::GBASE:{
|
||||
uint32_t old_value = this->fb_base;
|
||||
uint32_t new_value = value & 0x3FFFE0;
|
||||
if (new_value != old_value) {
|
||||
this->fb_base = new_value;
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
case ControlRegs::GBASE:
|
||||
this->fb_base = value & 0x3FFFE0;
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ControlRegs::ROW_WORDS:
|
||||
this->row_words = value & 0x7FE0;
|
||||
if (this->display_enabled) {
|
||||
@@ -601,11 +517,12 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
}
|
||||
break;
|
||||
case ControlRegs::MON_SENSE: {
|
||||
// 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);
|
||||
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);
|
||||
uint8_t dirs = ((value >> 3) & 7) ^ 7;
|
||||
uint8_t levels = ((value & 7) & dirs) | (dirs ^ 7);
|
||||
this->mon_sense = value & 0x3F;
|
||||
@@ -614,7 +531,6 @@ 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 {
|
||||
@@ -654,31 +570,6 @@ 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;
|
||||
@@ -701,30 +592,49 @@ 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;
|
||||
}
|
||||
// get pixel depth from RaDACal
|
||||
this->pixel_depth = this->radacal->get_pix_width();
|
||||
this->update_fb_ptr();
|
||||
|
||||
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
|
||||
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;
|
||||
@@ -772,8 +682,6 @@ void ControlVideo::enable_display()
|
||||
this->blank_on = true;
|
||||
this->crtc_on = false;
|
||||
}
|
||||
|
||||
this->draw_fb = true;
|
||||
}
|
||||
|
||||
void ControlVideo::disable_display()
|
||||
|
||||
@@ -131,7 +131,6 @@ protected:
|
||||
|
||||
void enable_display();
|
||||
void disable_display();
|
||||
void update_fb_ptr();
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
@@ -252,8 +252,8 @@ void Display::configure_dest() {
|
||||
|
||||
impl->dest_rect.w = std::round(scale * impl->display_w);
|
||||
impl->dest_rect.h = std::round(scale * impl->display_h);
|
||||
impl->dest_rect.x = std::round((impl->drawable_w - impl->dest_rect.w) / 2.0);
|
||||
impl->dest_rect.y = std::round((impl->drawable_h - impl->dest_rect.h) / 2.0);
|
||||
impl->dest_rect.x = std::round((impl->drawable_w - impl->dest_rect.w) / 2.0),
|
||||
impl->dest_rect.y = std::round((impl->drawable_h - impl->dest_rect.h) / 2.0),
|
||||
impl->renderer_scale_x = scale;
|
||||
impl->renderer_scale_y = scale;
|
||||
|
||||
@@ -310,7 +310,7 @@ void Display::handle_events(const WindowEvent& wnd_event) {
|
||||
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
if (wnd_event.window_id == impl->disp_wnd_id) {
|
||||
video_ctrl->set_draw_fb();
|
||||
SDL_RenderPresent(impl->renderer);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+13
-47
@@ -126,21 +126,18 @@ void ValkyrieVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, i
|
||||
|
||||
switch((offset >> this->reg_shift) & 0xFF) {
|
||||
case Valkyrie::csr_mode:
|
||||
{
|
||||
uint8_t old_mode = this->mode;
|
||||
if (value != old_mode) {
|
||||
if (value != this->mode) {
|
||||
auto old_mode = this->mode;
|
||||
this->mode = value;
|
||||
if (value & 0x80) { // is disabled
|
||||
if (!(old_mode & 0x80)) // was enabled
|
||||
if ((value ^ old_mode) & 0x80) {
|
||||
if (value & 0x80)
|
||||
this->disable_video_internal();
|
||||
}
|
||||
else { // is enabled and was disabled or is enabled and mode changed
|
||||
this->schedule_mode_switch();
|
||||
else
|
||||
this->schedule_mode_switch();
|
||||
}
|
||||
}
|
||||
LOG_F(INFO, "%s: mode reg set to 0x%X", this->name.c_str(), this->mode);
|
||||
break;
|
||||
}
|
||||
case Valkyrie::csr_depth:
|
||||
if (value != this->depth)
|
||||
this->schedule_mode_switch();
|
||||
@@ -192,11 +189,11 @@ void ValkyrieVideo::disable_video_internal() {
|
||||
}
|
||||
|
||||
void ValkyrieVideo::schedule_mode_switch() {
|
||||
if (this->mode_timer.active)
|
||||
TimerManager::get_instance()->cancel_timer(this->mode_timer);
|
||||
if (this->mode_timer_id)
|
||||
TimerManager::get_instance()->cancel_timer(this->mode_timer_id);
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->mode_timer,
|
||||
MSECS_TO_NSECS(3), [this](uint64_t, uint64_t) {
|
||||
this->mode_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
MSECS_TO_NSECS(3), [this] {
|
||||
this->enable_video_internal();
|
||||
});
|
||||
}
|
||||
@@ -208,56 +205,25 @@ void ValkyrieVideo::enable_video_internal() {
|
||||
this->pixel_clock = this->clk_gen->get_dot_freq();
|
||||
|
||||
// set video mode parameters
|
||||
// MHz shown is calculated by get_dot_freq, not the ideal pixel clock.
|
||||
switch(this->mode & 0x7F) {
|
||||
case PdmVideoMode::Rgb12in: // 0x2: // 512x384 60 Hz 15.667200 MHz
|
||||
new_width = 512;
|
||||
new_height = 384;
|
||||
hori_blank = 128;
|
||||
vert_blank = 23;
|
||||
break;
|
||||
case PdmVideoMode::Rgb13in: // 0x6: // 640x480 67 Hz 30.215314 MHz
|
||||
case PdmVideoMode::Rgb13in:
|
||||
new_width = 640;
|
||||
new_height = 480;
|
||||
hori_blank = 224;
|
||||
vert_blank = 45;
|
||||
break;
|
||||
case PdmVideoMode::Rgb16in: // 0x9: // 832x624 75 Hz 57.219340 MHz
|
||||
case PdmVideoMode::Rgb16in:
|
||||
new_width = 832;
|
||||
new_height = 624;
|
||||
hori_blank = 320;
|
||||
vert_blank = 43;
|
||||
break;
|
||||
case PdmVideoMode::VGA: // 0xB: // 640x480 60 Hz 25.203756 MHz
|
||||
case PdmVideoMode::VGA:
|
||||
new_width = 640;
|
||||
new_height = 480;
|
||||
hori_blank = 160;
|
||||
vert_blank = 45;
|
||||
break;
|
||||
case 0xC: // 800x600 60 Hz 39.880144 MHz
|
||||
new_width = 800;
|
||||
new_height = 600;
|
||||
hori_blank = 256;
|
||||
vert_blank = 28;
|
||||
break;
|
||||
case 0xD: // 800x600 72 Hz 49.850184 MHz
|
||||
new_width = 800;
|
||||
new_height = 600;
|
||||
hori_blank = 240;
|
||||
vert_blank = 66;
|
||||
break;
|
||||
case 0xE: // 1024x768 60 Hz 64.757760 MHz
|
||||
new_width = 1024;
|
||||
new_height = 768;
|
||||
hori_blank = 320;
|
||||
vert_blank = 38;
|
||||
break;
|
||||
case 0xF: // 1024x768 72 Hz 74.930088 MHz
|
||||
new_width = 1024;
|
||||
new_height = 768;
|
||||
hori_blank = 304; // These blanking numbers are for 70 Hz, not 72 Hz.
|
||||
vert_blank = 38; // There is no documentation for a 72 Hz mode?
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: invalid video mode 0x%X", this->name.c_str(), this->mode & 0x7F);
|
||||
return;
|
||||
|
||||
@@ -101,7 +101,7 @@ private:
|
||||
uint8_t *vram_ptr = nullptr;
|
||||
int reg_shift = 3;
|
||||
|
||||
TimerInfo mode_timer;
|
||||
uint64_t mode_timer_id = 0;
|
||||
|
||||
void disable_video_internal();
|
||||
void enable_video_internal();
|
||||
|
||||
+24
-26
@@ -101,42 +101,40 @@ void VideoCtrlBase::set_cursor_dirty() {
|
||||
void VideoCtrlBase::start_refresh_task() {
|
||||
this->display.configure(this->active_width, this->active_height);
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
if (this->vert_blank == 0) {
|
||||
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(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
// assert VBL interrupt
|
||||
this->vbl_cb(1);
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
if (vert_blank == 0) {
|
||||
LOG_F(ERROR, "Vertical blank is 0. Using 25 instead.");
|
||||
this->vert_blank = 25;
|
||||
vert_blank = 25;
|
||||
}
|
||||
|
||||
uint64_t vbl_duration = static_cast<uint64_t>((double)this->hori_total * this->vert_blank /
|
||||
this->pixel_clock * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
this->refresh_timer,
|
||||
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(
|
||||
refresh_interval,
|
||||
[this, vbl_duration](uint64_t timeout_ns, uint64_t) {
|
||||
this->vbl_cb(1); // assert VBL interrupt
|
||||
|
||||
if (this->vbl_end_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_timer);
|
||||
}
|
||||
TimerManager::get_instance()->add_absolute_timer(
|
||||
this->vbl_end_timer,
|
||||
timeout_ns + vbl_duration, 0,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->vbl_cb(0); // deassert VBL interrupt
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
refresh_interval + vbl_duration,
|
||||
[this]() {
|
||||
// deassert VBL interrupt
|
||||
this->vbl_cb(0);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::stop_refresh_task() {
|
||||
if (this->refresh_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_timer);
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
this->refresh_task_id = 0;
|
||||
}
|
||||
if (this->vbl_end_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_timer);
|
||||
if (this->vbl_end_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id);
|
||||
this->vbl_end_task_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ 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>
|
||||
|
||||
@@ -100,8 +99,8 @@ protected:
|
||||
int vert_blank = 0;
|
||||
int pixel_depth;
|
||||
int pixel_format;
|
||||
double pixel_clock; // float can represent all integers only up to 16 MHz
|
||||
float refresh_rate = 0;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
// Implementations may choose to track framebuffer writes and set draw_fb
|
||||
// to false if updates can be skipped. If they do this, they should set
|
||||
@@ -114,8 +113,8 @@ protected:
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr = nullptr;
|
||||
int fb_pitch = 0;
|
||||
TimerInfo refresh_timer;
|
||||
TimerInfo vbl_end_timer;
|
||||
uint32_t refresh_task_id = 0;
|
||||
uint32_t vbl_end_task_id = 0;
|
||||
|
||||
// interrupt suff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
|
||||
@@ -99,16 +99,19 @@ int MachineAlchemy::initialize(const std::string &id) {
|
||||
psx_obj->map_phys_ram();
|
||||
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 40000000ULL;
|
||||
uint64_t bus_freq = 40'000'000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
uint64_t core_freq = 180'000'000ULL;
|
||||
|
||||
psx_obj->set_bus_speed(PSX_BUS_SPEED_40);
|
||||
|
||||
// init virtual CPU and request MPC603ev
|
||||
ppc_cpu_init(psx_obj, PPC_VER::MPC603E, false, timebase_freq);
|
||||
|
||||
// CPU frequency is hardcoded to 225 MHz for now
|
||||
//ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
|
||||
// init virtual CPU and request MPC603e
|
||||
ppc_cpu_init(psx_obj, {
|
||||
.version = PPC_VER::MPC603E,
|
||||
.timebase_freq_hz = timebase_freq,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -126,8 +129,6 @@ static const PropMap pm6400_settings = {
|
||||
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32}))},
|
||||
{"hdd_config",
|
||||
new StrProperty("Ide0:0")},
|
||||
{"cdr_config",
|
||||
new StrProperty("ScsiMesh:3")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ int MachineBondi::initialize(const std::string &id) {
|
||||
LOG_F(INFO, "Building machine Bondi...");
|
||||
|
||||
// get pointer to the memory controller/primary PCI bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("GrackleBondi"));
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
grackle_obj->set_irq_map(grackle_irq_map);
|
||||
|
||||
MacIoTwo* mio_obj = dynamic_cast<MacIoTwo*>(gMachineObj->get_comp_by_name("Paddington"));
|
||||
@@ -88,14 +88,17 @@ int MachineBondi::initialize(const std::string &id) {
|
||||
setup_ram_slot("RAM_DIMM_2", 0x51, bank_2_size);
|
||||
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 66820000ULL;
|
||||
uint64_t bus_freq = 66'820'000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
uint64_t core_freq = bus_freq * 7 / 2; // 233.87 MHz (CPU PLL ratio of 3.5)
|
||||
|
||||
// initialize virtual CPU and request MPC750 CPU aka G3
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, timebase_freq);
|
||||
|
||||
// set CPU PLL ratio to 3.5
|
||||
ppc_state.spr[SPR::HID1] = 0xE << 28;
|
||||
ppc_cpu_init(grackle_obj, {
|
||||
.version = PPC_VER::MPC750,
|
||||
.timebase_freq_hz = timebase_freq,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -110,7 +113,7 @@ static const PropMap bondi_settings = {
|
||||
};
|
||||
|
||||
static std::vector<std::string> bondi_devices = {
|
||||
"GrackleBondi", "BurgundySnd", "Paddington", "AtaHardDisk", "AtapiCdrom"};
|
||||
"Grackle", "BurgundySnd", "Paddington", "AtaHardDisk", "AtapiCdrom"};
|
||||
|
||||
static const DeviceDescription MachineBondi_descriptor = {
|
||||
Machine::create<MachineBondi>, bondi_devices, bondi_settings
|
||||
|
||||
@@ -85,15 +85,6 @@ int MachineCatalyst::initialize(const std::string &id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Platinum uses the top 16 MB of the address space for ROM.
|
||||
// The installed 4 MB ROM appears four times within that range.
|
||||
for (uint32_t addr : {0xFF000000U, 0xFF400000U, 0xFF800000U}) {
|
||||
if (!platinum_obj->add_mem_mirror(addr, 0xFFC00000)) {
|
||||
LOG_F(ERROR, "Could not create ROM mirror!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// insert RAM DIMMs
|
||||
platinum_obj->insert_ram_dimm(0, GET_INT_PROP("rambank1_size") * DRAM_CAP_1MB);
|
||||
platinum_obj->insert_ram_dimm(1, GET_INT_PROP("rambank2_size") * DRAM_CAP_1MB);
|
||||
@@ -105,19 +96,30 @@ int MachineCatalyst::initialize(const std::string &id) {
|
||||
|
||||
std::string cpu = GET_STR_PROP("cpu");
|
||||
if (cpu == "601") {
|
||||
uint64_t bus_freq = 37'500'000ULL;
|
||||
uint64_t core_freq = 75'000'000ULL;
|
||||
|
||||
// init virtual CPU and request MPC601
|
||||
ppc_cpu_init(platinum_obj, PPC_VER::MPC601, true, 7833600ULL);
|
||||
ppc_cpu_init(platinum_obj, {
|
||||
.version = PPC_VER::MPC601,
|
||||
.timebase_freq_hz = 7'833'600ULL,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
}
|
||||
else if (cpu == "750") {
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 50000000ULL;
|
||||
uint64_t bus_freq = 50'000'000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
uint64_t core_freq = bus_freq * 8; // 400 MHz (matches G3 upgrade cards; CPU PLL ratio to 8)
|
||||
|
||||
// initialize virtual CPU and request MPC750 CPU aka G3
|
||||
ppc_cpu_init(platinum_obj, PPC_VER::MPC750, false, timebase_freq);
|
||||
|
||||
// set CPU PLL ratio to 3.5
|
||||
ppc_state.spr[SPR::HID1] = 0xE << 28;
|
||||
ppc_cpu_init(platinum_obj, {
|
||||
.version = PPC_VER::MPC750,
|
||||
.timebase_freq_hz = timebase_freq,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -132,8 +134,6 @@ static const PropMap pm7200_settings = {
|
||||
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank4_size",
|
||||
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"cdr_config",
|
||||
new StrProperty("ScsiCurio:3")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
{"cpu",
|
||||
|
||||
@@ -95,6 +95,7 @@ static const map<string, string> PropHelp = {
|
||||
{"serial_backend", "specifies the backend for the serial port"},
|
||||
{"emmo", "enables/disables factory HW tests during startup"},
|
||||
{"cpu", "specifies CPU"},
|
||||
{"cpu_freq", "specifies CPU frequency in MHz"},
|
||||
{"adb_devices", "specifies which ADB device(s) to attach"},
|
||||
{"pds", "specify device for the processsor direct slot"},
|
||||
};
|
||||
|
||||
+10
-21
@@ -46,20 +46,6 @@ static std::vector<PciIrqMap> psx_irq_map = {
|
||||
{"pci_F1", DEV_FUN(0x12,0), IntSrc::PCI_F},
|
||||
};
|
||||
|
||||
// TODO: move it to /cpu/ppc
|
||||
int get_cpu_pll_value(const uint64_t cpu_freq_hz) {
|
||||
switch (cpu_freq_hz / 1000000) {
|
||||
case 225:
|
||||
return 7; // 4.5:1 ratio
|
||||
case 250:
|
||||
return 11; // 5:1 ratio
|
||||
case 275:
|
||||
return 9; // 5.5:1 ratio
|
||||
default:
|
||||
ABORT_F("Unsupported CPU frequency %llu Hz", cpu_freq_hz);
|
||||
}
|
||||
}
|
||||
|
||||
class MachineGazelle : public Machine {
|
||||
public:
|
||||
static std::unique_ptr<HWComponent> create5500() {
|
||||
@@ -126,14 +112,17 @@ int MachineGazelle::initialize(const std::string &id) {
|
||||
psx_obj->set_bus_speed(PSX_BUS_SPEED_50);
|
||||
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 50000000ULL;
|
||||
uint64_t bus_freq = 50'000'000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
uint64_t core_freq = GET_INT_PROP("cpu_freq") * 1'000'000ULL; // 225, 250, or 275 MHz
|
||||
|
||||
// init virtual CPU and request MPC603ev
|
||||
ppc_cpu_init(psx_obj, PPC_VER::MPC603EV, false, timebase_freq);
|
||||
|
||||
// CPU frequency is hardcoded to 225 MHz for now
|
||||
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
|
||||
ppc_cpu_init(psx_obj, {
|
||||
.version = PPC_VER::MPC603EV,
|
||||
.timebase_freq_hz = timebase_freq,
|
||||
.bus_freq_hz = bus_freq,
|
||||
.core_freq_hz = core_freq,
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -145,10 +134,10 @@ static const PropMap pm6500_settings = {
|
||||
new IntProperty(32, std::vector<uint32_t>({ 4, 8, 16, 32, 64}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64}))},
|
||||
{"cdr_config",
|
||||
new StrProperty("ScsiMesh:3")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
{"cpu_freq",
|
||||
new IntProperty(225, std::vector<uint32_t>({225, 250, 275}))},
|
||||
{"hdd_config",
|
||||
new StrProperty("Ide0:0")},
|
||||
{"pci_F1",
|
||||
|
||||
Loaded 100 of 112 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user