mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7503941f23 | ||
|
|
293bb0018b | ||
|
|
ba62201573 | ||
|
|
94ffe31dda | ||
|
|
d0fb711842 | ||
|
|
090e852ecc | ||
|
|
b9d3456c44 | ||
|
|
7384b16548 | ||
|
|
8f6c4423e7 | ||
|
|
a0cc486580 | ||
|
|
810c3f9dd3 | ||
|
|
3ad54485ff | ||
|
|
64d4654e2e | ||
|
|
f22a333ae7 | ||
|
|
fd1b1bb8f1 | ||
|
|
dd5ecee284 | ||
|
|
f084bae478 | ||
|
|
beaae745bb | ||
|
|
1b63628e58 | ||
|
|
7a13951400 | ||
|
|
94e7bbd14a | ||
|
|
5ad23f5f88 | ||
|
|
cd2e0ad7da | ||
|
|
8e03b1c52a | ||
|
|
8cab662f6e | ||
|
|
8dff8a4238 | ||
|
|
904c1b177e | ||
|
|
a188a15bf6 | ||
|
|
6d8ce06052 | ||
|
|
fc0d722df0 | ||
|
|
b6dbbe2685 | ||
|
|
3430e108bd | ||
|
|
5b3e4f6552 | ||
|
|
357b838ac7 | ||
|
|
049f8b68c5 | ||
|
|
45a4965cd5 | ||
|
|
4e254fc972 | ||
|
|
21c6a80e2c | ||
|
|
0ea30ac041 | ||
|
|
98421734de | ||
|
|
e52317c8b5 | ||
|
|
2a83f5bddc | ||
|
|
716254c37c | ||
|
|
325cc8ac9f | ||
|
|
5cb6d66f18 | ||
|
|
6f87662a1d | ||
|
|
62793bb935 | ||
|
|
4ed0282ef3 | ||
|
|
47a9ccd73b | ||
|
|
96393c63d0 | ||
|
|
a811ff8aa3 | ||
|
|
8851daadc9 | ||
|
|
90debefc2a | ||
|
|
74c60fcd57 | ||
|
|
8652a5b8c4 | ||
|
|
25eac76d26 | ||
|
|
315e3d9f2a | ||
|
|
5f111d0929 |
No files matched your search
+20
-22
@@ -265,28 +265,26 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
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()
|
||||
file(GLOB BENCH_CPU_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h")
|
||||
foreach(BENCHMARK bench1 bench2)
|
||||
add_executable(${BENCHMARK} "benchmark/${BENCHMARK}.cpp" ${BENCH_CPU_SOURCES}
|
||||
$<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
target_compile_definitions(${BENCHMARK} PRIVATE PPC_BENCHMARKS)
|
||||
target_link_libraries(${BENCHMARK} PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
target_compile_definitions(${BENCHMARK} PRIVATE SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(${BENCHMARK} PRIVATE capstone)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
|
||||
@@ -4,7 +4,12 @@ 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
|
||||
=======
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(You may also contact divingkxt or powermax2286 on Discord)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Replay floating-point instructions and input registers captured while BeOS
|
||||
// PR1 GLTeapot renders. This measures the real opcode dispatcher and handlers,
|
||||
// including FPSCR maintenance, without guest boot, display, or timer overhead.
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfenv>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "bench2_data.h"
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_off(po_benchmark_exception);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void replay_sample(const FpuSample& sample) {
|
||||
if ((ppc_state.fpscr ^ sample.fpscr) & FPSCR::RN_MASK)
|
||||
set_host_rounding_mode(sample.fpscr & FPSCR::RN_MASK);
|
||||
ppc_state.fpscr = sample.fpscr;
|
||||
ppc_state.cr = sample.cr;
|
||||
ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r = sample.d;
|
||||
ppc_state.fpr[(sample.opcode >> 16) & 31].int64_r = sample.a;
|
||||
ppc_state.fpr[(sample.opcode >> 11) & 31].int64_r = sample.b;
|
||||
ppc_state.fpr[(sample.opcode >> 6) & 31].int64_r = sample.c;
|
||||
ppc_main_opcode(ppc_opcode_grabber, sample.opcode);
|
||||
}
|
||||
|
||||
static uint64_t check_replay() {
|
||||
uint64_t hash = 1469598103934665603ULL;
|
||||
auto mix = [&hash](uint64_t value) { hash = (hash ^ value) * 1099511628211ULL; };
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
for (const auto& sample : fpu_samples) {
|
||||
replay_sample(sample);
|
||||
mix(ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r);
|
||||
mix(ppc_state.fpscr);
|
||||
mix(ppc_state.cr);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc > 2 || (argc == 2 && std::strcmp(argv[1], "--check"))) {
|
||||
fprintf(stderr, "Usage: %s [--check]\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
|
||||
is_601 = false;
|
||||
initialize_ppc_opcode_table();
|
||||
ppc_msr_did_change(ppc_state.msr, MSR::ME | MSR::IP | MSR::FP, false);
|
||||
set_host_rounding_mode(0);
|
||||
power_on = true;
|
||||
|
||||
const uint64_t expected = check_replay();
|
||||
constexpr size_t sample_count = sizeof(fpu_samples) / sizeof(fpu_samples[0]);
|
||||
printf("GLTeapot FPU replay: %zu samples, checksum %016" PRIx64 "\n", sample_count, expected);
|
||||
if (!power_on)
|
||||
return 1;
|
||||
if (argc == 2 && !std::strcmp(argv[1], "--check"))
|
||||
return 0;
|
||||
|
||||
constexpr unsigned passes = 10000;
|
||||
constexpr unsigned trials = 9;
|
||||
// Warm the dispatcher, handlers and captured input data.
|
||||
for (unsigned pass = 0; pass < 100; pass++)
|
||||
for (const auto& sample : fpu_samples)
|
||||
replay_sample(sample);
|
||||
|
||||
std::vector<double> times;
|
||||
for (unsigned trial = 0; trial < trials; trial++) {
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
for (unsigned pass = 0; pass < passes; pass++)
|
||||
for (const auto& sample : fpu_samples)
|
||||
replay_sample(sample);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
if (!power_on || check_replay() != expected) {
|
||||
fprintf(stderr, "FPU replay changed its result during timing\n");
|
||||
return 1;
|
||||
}
|
||||
double ns = std::chrono::duration<double, std::nano>(end - start).count() /
|
||||
(uint64_t(passes) * sample_count);
|
||||
times.push_back(ns);
|
||||
printf("Trial %u: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
|
||||
trial + 1, ns, 1000.0 / ns);
|
||||
}
|
||||
std::sort(times.begin(), times.end());
|
||||
double median = times[times.size() / 2];
|
||||
printf("Median: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
|
||||
median, 1000.0 / median);
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -165,6 +165,7 @@ 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
|
||||
|
||||
+16
-4
@@ -32,14 +32,15 @@ TimerManager* TimerManager::timer_manager;
|
||||
|
||||
void TimerManager::add_absolute_timer(TimerInfo &ti, 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);
|
||||
|
||||
ti.timeout_ns = timeout_ns;
|
||||
ti.interval_ns = interval;
|
||||
ti.active = true;
|
||||
ti.cb = cb;
|
||||
|
||||
// add new timer to the timer queue
|
||||
//if (this->timer_queue.remove_by_id(&ti))
|
||||
// LOG_F(ERROR, "timer was in queue!");
|
||||
this->timer_queue.push(&ti);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
@@ -71,6 +72,7 @@ void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb c
|
||||
void TimerManager::cancel_timer(TimerInfo &ti)
|
||||
{
|
||||
this->timer_queue.remove_by_id(&ti);
|
||||
ti.active = false;
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
@@ -99,10 +101,19 @@ 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)
|
||||
timeout_ns_new = time_now + cur_timer->interval_ns;
|
||||
if (timeout_ns_new <= time_now) {
|
||||
// Skip missed periods without changing the timer's phase.
|
||||
// Rebasing deadlines on time_now would align timers that
|
||||
// have the same period.
|
||||
const uint64_t periods_to_skip =
|
||||
((time_now - timeout_ns_new) / cur_timer->interval_ns) + 1;
|
||||
timeout_ns_new += periods_to_skip * cur_timer->interval_ns;
|
||||
}
|
||||
cur_timer->timeout_ns = timeout_ns_new;
|
||||
this->timer_queue.push(cur_timer);
|
||||
} else {
|
||||
// One-shot callbacks may immediately reuse their TimerInfo.
|
||||
cur_timer->active = false;
|
||||
}
|
||||
|
||||
this->cb_active = true;
|
||||
@@ -134,5 +145,6 @@ void TimerManager::cancel_all_timers()
|
||||
cur_timer = this->timer_queue.top();
|
||||
LOG_F(WARNING, "Canceling timer id:%llu ns:%llu", uint64_t(cur_timer), cur_timer->timeout_ns);
|
||||
this->timer_queue.pop();
|
||||
cur_timer->active = false;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -95,7 +95,7 @@ private:
|
||||
typedef struct TimerInfo {
|
||||
uint64_t timeout_ns; // timer expiry
|
||||
uint64_t interval_ns; // 0 for one-shot timers
|
||||
bool active = false; // set to true when added to the queue
|
||||
bool active = false; // maintained by TimerManager while queued
|
||||
timer_cb cb; // timer callback
|
||||
} TimerInfo;
|
||||
|
||||
@@ -130,7 +130,9 @@ public:
|
||||
// return current virtual time in nanoseconds
|
||||
uint64_t current_time_ns() const { return get_time_now(); }
|
||||
|
||||
// creating and cancelling timers
|
||||
// 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);
|
||||
|
||||
+2
-1
@@ -734,7 +734,8 @@ extern int increment_icnt_factor();
|
||||
extern int decrement_icnt_factor();
|
||||
extern int get_icnt_factor();
|
||||
|
||||
/* toggle_g_realtime */
|
||||
/* realtime clock control */
|
||||
extern bool g_realtime;
|
||||
extern bool toggle_g_realtime();
|
||||
|
||||
/* force_cycle_counter_reload */
|
||||
|
||||
+33
-19
@@ -36,19 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#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;
|
||||
}
|
||||
#include <ctime>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
@@ -287,6 +275,18 @@ 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 +345,7 @@ void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
|
||||
|
||||
static long long cpu_now_ns() {
|
||||
#ifdef __APPLE__
|
||||
return ConvertHostTimeToNanos2(mach_absolute_time());
|
||||
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
|
||||
#else
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
@@ -376,16 +376,32 @@ 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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
return (
|
||||
(
|
||||
next_ns ?
|
||||
next_ns
|
||||
:
|
||||
TimerManager::get_instance()->current_time_ns() + 500'000
|
||||
get_virt_time_ns() + TIMER_POLL_INTERVAL_NS
|
||||
) >> icnt_factor
|
||||
) + 1;
|
||||
}
|
||||
@@ -1036,9 +1052,6 @@ 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;
|
||||
|
||||
@@ -1117,7 +1130,8 @@ static map<string, int> SPRName2Num = {
|
||||
{"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},
|
||||
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4}, {"EAR", SPR::EAR},
|
||||
|
||||
// get value from supervisor index same as we do for SPR268 and SPR269
|
||||
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
|
||||
};
|
||||
|
||||
+38
-14
@@ -31,6 +31,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__aarch64__)
|
||||
#include <arm_acle.h>
|
||||
#endif
|
||||
|
||||
inline static void ppc_update_cr1() {
|
||||
// copy FPSCR[FX|FEX|VX|OX] to CR1
|
||||
ppc_state.cr = (ppc_state.cr & ~CR_select::CR1_field) |
|
||||
@@ -117,6 +121,26 @@ 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;
|
||||
@@ -128,18 +152,18 @@ static void fpresult_update(double set_result) {
|
||||
} else {
|
||||
ppc_state.fpscr |= FPCC_ZERO;
|
||||
}
|
||||
|
||||
if (std::fetestexcept(FE_OVERFLOW)) {
|
||||
#if FE_ALL_EXCEPT
|
||||
int exceptions = test_and_clear_fp_exceptions();
|
||||
if (exceptions & FE_OVERFLOW) {
|
||||
ppc_state.fpscr |= (OX + FX);
|
||||
}
|
||||
if (std::fetestexcept(FE_UNDERFLOW)) {
|
||||
if (exceptions & FE_UNDERFLOW) {
|
||||
ppc_state.fpscr |= (UX + FX);
|
||||
}
|
||||
if (std::fetestexcept(FE_DIVBYZERO)) {
|
||||
if (exceptions & FE_DIVBYZERO) {
|
||||
ppc_state.fpscr |= (ZX + FX);
|
||||
}
|
||||
|
||||
std::feclearexcept(FE_ALL_EXCEPT);
|
||||
#endif
|
||||
|
||||
if (std::isinf(set_result))
|
||||
ppc_state.fpscr |= FPCC_FUNAN;
|
||||
@@ -1025,7 +1049,7 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1046,7 +1070,7 @@ void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1070,7 +1094,7 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1091,7 +1115,7 @@ void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1114,7 +1138,7 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1135,7 +1159,7 @@ void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,7 +1180,7 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1175,7 +1199,7 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
|
||||
ppc_store_iresult_reg(reg_a, ea);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
-9
@@ -378,7 +378,9 @@ 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 is_dbg) {
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
bool allow_mmio, bool allow_partial, bool is_dbg)
|
||||
{
|
||||
MMIODevice *devobj = nullptr;
|
||||
uint8_t *host_va = nullptr;
|
||||
uint32_t dev_base = 0;
|
||||
@@ -432,10 +434,18 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio, bool
|
||||
addr, addr + size - 1
|
||||
);
|
||||
} else {
|
||||
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
|
||||
);
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,9 +465,18 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio, bool
|
||||
is_writable = true; // all MMIO devices must provide a write method
|
||||
}
|
||||
|
||||
return MapDmaResult{cur_dma_rgn->type, is_writable, host_va, devobj, dev_base};
|
||||
return MapDmaResult{
|
||||
.type = cur_dma_rgn->type,
|
||||
.size = size,
|
||||
.is_writable = is_writable,
|
||||
.host_va = host_va,
|
||||
.dev_obj = devobj,
|
||||
.dev_base = dev_base,
|
||||
};
|
||||
fail:
|
||||
return MapDmaResult{RT_NONE, false, nullptr, nullptr, 0};
|
||||
return MapDmaResult{
|
||||
.type = RT_NONE
|
||||
};
|
||||
}
|
||||
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
@@ -863,7 +882,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
(tlb_entry->flags & TLBFlags::TLBE_CTX_TRACKED);
|
||||
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
|
||||
(phys_addr - rgn_desc->start);
|
||||
if (rgn_desc->type == RT_ROM) {
|
||||
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 {
|
||||
@@ -1088,7 +1107,7 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
|
||||
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
|
||||
{
|
||||
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
// ppc_illegalop(opcode);
|
||||
}
|
||||
|
||||
static void ppc_ibat_update(uint32_t bat_reg)
|
||||
|
||||
+3
-1
@@ -71,6 +71,7 @@ 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;
|
||||
@@ -89,7 +90,8 @@ 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 is_dbg = false);
|
||||
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
|
||||
bool allow_mmio = false, bool allow_partial = false, bool is_dbg = false);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
|
||||
+94
-133
@@ -52,30 +52,14 @@ void ppc_changecrf0(uint32_t set_result) {
|
||||
}
|
||||
|
||||
// Affects the XER register's Carry Bit
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
inline static void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
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;
|
||||
}
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~XER::OV) |
|
||||
((int32_t((a ^ b) & (a ^ d)) < 0) ? (XER::SO | XER::OV) : 0);
|
||||
}
|
||||
|
||||
typedef std::function<void()> CtxSyncCallback;
|
||||
@@ -115,8 +99,9 @@ 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);
|
||||
uint32_t ppc_result_d = (ppc_result_a + simm);
|
||||
ppc_carry(ppc_result_a, ppc_result_d);
|
||||
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);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
@@ -128,10 +113,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);
|
||||
uint32_t ppc_result_d = ppc_result_a + ppc_result_b;
|
||||
|
||||
uint64_t ppc_result_l = uint64_t(ppc_result_a) + ppc_result_b;
|
||||
uint32_t ppc_result_d = uint32_t(ppc_result_l);
|
||||
if (carry)
|
||||
ppc_carry(ppc_result_a, ppc_result_d);
|
||||
ppc_carry(ppc_result_l);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -152,14 +137,9 @@ 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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -177,14 +157,9 @@ 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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -201,15 +176,10 @@ 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 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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -225,21 +195,19 @@ template void dppc_interpreter::ppc_addze<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::ppc_subfic(uint32_t opcode) {
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
uint32_t ppc_result_d = ppc_result_b - ppc_result_a;
|
||||
|
||||
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);
|
||||
if (carry)
|
||||
ppc_carry_sub(ppc_result_a, ppc_result_b);
|
||||
ppc_carry(ppc_result_l);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -260,13 +228,10 @@ 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 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);
|
||||
|
||||
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);
|
||||
if (ov)
|
||||
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
@@ -283,14 +248,10 @@ 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 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;
|
||||
|
||||
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);
|
||||
if (ov) {
|
||||
if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
@@ -312,14 +273,10 @@ 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 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;
|
||||
|
||||
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);
|
||||
if (ov) {
|
||||
if (ppc_result_d && ppc_result_d == ppc_result_a)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
@@ -736,10 +693,10 @@ void dppc_interpreter::ppc_mtsr(uint32_t opcode) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
int reg_s = (opcode >> 21) & 0x1F;
|
||||
ppc_grab_s(opcode);
|
||||
uint32_t grab_sr = (opcode >> 16) & 0x0F;
|
||||
if (ppc_state.sr[grab_sr] != ppc_state.gpr[reg_s]) {
|
||||
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
|
||||
if (ppc_state.sr[grab_sr] != ppc_result_d) {
|
||||
ppc_state.sr[grab_sr] = ppc_result_d;
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
}
|
||||
@@ -806,9 +763,9 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
uint32_t reg_s = (opcode >> 21) & 0x1F;
|
||||
ppc_grab_s(opcode);
|
||||
uint32_t old_msr_val = ppc_state.msr;
|
||||
uint32_t new_msr_val = ppc_state.gpr[reg_s];
|
||||
uint32_t new_msr_val = ppc_result_d;
|
||||
if (!is_601) {
|
||||
ppc_change_endian((new_msr_val & MSR::LE) != 0);
|
||||
}
|
||||
@@ -932,7 +889,6 @@ static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
|
||||
}
|
||||
|
||||
static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
|
||||
decrementer_timer.active = 0;
|
||||
uint32_t new_val = calc_dec_value();
|
||||
if (new_val >= 0 && new_val != uint32_t(-1)) {
|
||||
new_val = -1;
|
||||
@@ -942,7 +898,6 @@ static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
|
||||
}
|
||||
|
||||
static void trigger_immediate_decrementer_exception(uint64_t, uint64_t) {
|
||||
decrementer_timer.active = 0;
|
||||
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
|
||||
trigger_decrementer_exception();
|
||||
}
|
||||
@@ -987,7 +942,6 @@ static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t
|
||||
}
|
||||
|
||||
static void update_thermal(uint64_t, uint64_t) {
|
||||
thermal_timer.active = 0;
|
||||
|
||||
uint32_t val = ppc_state.spr[SPR::THRM3];
|
||||
auto sampled_interval_timer_value = (val >> 1) & 0x1FFF;
|
||||
@@ -1045,14 +999,14 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
switch (ref_spr) {
|
||||
case SPR::MQ:
|
||||
if (!(is_601 || include_601)) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
return;
|
||||
}
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
break;
|
||||
case SPR::RTCL_U:
|
||||
if (!is_601) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
return;
|
||||
}
|
||||
calc_rtcl_value();
|
||||
@@ -1062,7 +1016,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
break;
|
||||
case SPR::RTCU_U:
|
||||
if (!is_601) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
return;
|
||||
}
|
||||
calc_rtcl_value();
|
||||
@@ -1072,7 +1026,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
break;
|
||||
case SPR::DEC_U:
|
||||
if (!is_601) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
return;
|
||||
}
|
||||
// fallthrough
|
||||
@@ -1136,13 +1090,13 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
if (is_601 || include_601)
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
else
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
break;
|
||||
case SPR::RTCL_U:
|
||||
case SPR::RTCU_U:
|
||||
case SPR::DEC_U:
|
||||
if (!is_601) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
break;
|
||||
case SPR::XER:
|
||||
@@ -1257,7 +1211,7 @@ void dppc_interpreter::ppc_mftb(uint32_t opcode) {
|
||||
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
|
||||
break;
|
||||
default:
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1625,27 +1579,25 @@ void dppc_interpreter::ppc_sc(uint32_t opcode) {
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_tw(uint32_t opcode) {
|
||||
uint32_t reg_a = (opcode >> 11) & 0x1F;
|
||||
uint32_t reg_b = (opcode >> 16) & 0x1F;
|
||||
ppc_grab_regsab(opcode);
|
||||
uint32_t ppc_to = (opcode >> 21) & 0x1F;
|
||||
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))) {
|
||||
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))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_twi(uint32_t opcode) {
|
||||
int32_t simm = int32_t(int16_t(opcode));
|
||||
uint32_t reg_a = (opcode >> 16) & 0x1F;
|
||||
ppc_grab_regsasimm(opcode);
|
||||
uint32_t ppc_to = (opcode >> 21) & 0x1F;
|
||||
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))) {
|
||||
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))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
@@ -1744,13 +1696,17 @@ void dppc_interpreter::ppc_stu(uint32_t opcode) {
|
||||
ppc_grab_regssa(opcode);
|
||||
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ea += ppc_result_a;
|
||||
uint32_t ea = ppc_result_a + int32_t(int16_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 = int32_t(int16_t(opcode));
|
||||
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1771,8 +1727,13 @@ 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_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1839,8 +1800,8 @@ void dppc_interpreter::ppc_lz(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
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);
|
||||
@@ -1855,16 +1816,16 @@ void dppc_interpreter::ppc_lzu(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
if ((reg_a != reg_d) && reg_a != 0) {
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
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);
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1900,7 +1861,7 @@ void dppc_interpreter::ppc_lzux(uint32_t opcode) {
|
||||
ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1912,8 +1873,8 @@ void dppc_interpreter::ppc_lha(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
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));
|
||||
@@ -1923,16 +1884,16 @@ void dppc_interpreter::ppc_lhau(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda(opcode);
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
if ((reg_a != reg_d) && reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
uint32_t ea = simm;
|
||||
ea += ppc_result_a;
|
||||
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
|
||||
ppc_store_iresult_reg(reg_d, int32_t(val));
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1945,11 +1906,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));
|
||||
uint32_t ppc_result_a = ea;
|
||||
ppc_result_a = ea;
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1999,8 +1960,8 @@ void dppc_interpreter::ppc_lmw(uint32_t opcode) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ea = int32_t(int16_t(opcode));
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
uint32_t ea = simm;
|
||||
ea += (reg_a ? ppc_result_a : 0);
|
||||
// How many words to load in memory - using a do-while for this
|
||||
do {
|
||||
@@ -2057,7 +2018,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_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
ppc_illegalop(opcode);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
if (!this->read_data_timer.active) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->read_data_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->read_data_timer.active = 0;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
);
|
||||
@@ -131,7 +130,6 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
LOG_F(ERROR, "%s: write_done_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(write_done_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
write_done_timer.active = 0;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
@@ -144,7 +142,6 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
LOG_F(ERROR, "%s: write_more_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->write_more_timer,
|
||||
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
|
||||
this->write_more_timer.active = 0;
|
||||
this->signal_data_ready();
|
||||
}
|
||||
);
|
||||
@@ -232,7 +229,6 @@ int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
|
||||
if (this->dma_pull_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_pull_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_pull_timer, 500, [this](uint64_t, uint64_t) {
|
||||
dma_pull_timer.active = 0;
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
@@ -262,7 +258,6 @@ int AtaBaseDevice::push_data(uint8_t *buf, int len) {
|
||||
if (this->dma_push_timer.active)
|
||||
LOG_F(ERROR, "%s: dma_push_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(dma_push_timer, 500, [this](uint64_t, uint64_t) {
|
||||
dma_push_timer.active = 0;
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
|
||||
@@ -67,6 +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");
|
||||
@@ -100,6 +105,12 @@ 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) {
|
||||
|
||||
@@ -95,7 +95,6 @@ void IdeChannel::assert_dmareq(uint64_t delay) {
|
||||
LOG_F(WARNING, "%s: dmareq_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->dmareq_timer, delay, [this](uint64_t, uint64_t) {
|
||||
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
|
||||
this->dmareq_timer.active = false;
|
||||
this->channel_obj->xfer_retry();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -293,7 +293,6 @@ void DMAChannel::update_irq(uint8_t cmd_bits) {
|
||||
if (this->int_ctrl) {
|
||||
if (!this->interrupt_timer.active) {
|
||||
TimerManager::get_instance()->add_immediate_timer(this->interrupt_timer, [this](uint64_t, uint64_t) {
|
||||
this->interrupt_timer.active = 0;
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ 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);
|
||||
@@ -39,7 +41,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 = 0x06040002;
|
||||
this->class_rev = DEVTYPE_PCI2PCI_BRIDGE | my_rev_id;
|
||||
this->cache_ln_sz = 0;
|
||||
this->command = 0;
|
||||
this->status = 0x2B0;
|
||||
|
||||
@@ -23,6 +23,7 @@ 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>
|
||||
@@ -52,16 +53,6 @@ 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,
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(You may also contact divingkxt or powermax2286 on Discord)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -323,12 +323,10 @@ void Sc53C94::exec_command()
|
||||
// release RST line after 25 us
|
||||
if (my_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer);
|
||||
my_timer.active = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(my_timer,
|
||||
USECS_TO_NSECS(25),
|
||||
[this](uint64_t, uint64_t) {
|
||||
my_timer.active = 0;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & CFG1_DISR)) {
|
||||
@@ -479,7 +477,6 @@ void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
if (this->seq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = 0;
|
||||
}
|
||||
|
||||
if (delay_ns) {
|
||||
@@ -487,7 +484,6 @@ void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
delay_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -495,7 +491,6 @@ void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
TimerManager::get_instance()->add_immediate_timer(this->seq_timer,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -711,7 +706,6 @@ void Sc53C94::notify(ScsiNotification notif_type, int param)
|
||||
if (this->target_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -79,6 +79,11 @@ 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
|
||||
|
||||
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
ScsiBus::ScsiBus(const std::string name)
|
||||
{
|
||||
@@ -338,29 +339,65 @@ 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()) {
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we start at ID 3.
|
||||
// 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.
|
||||
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 (!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);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,11 @@ 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);
|
||||
this->seq_timer.active = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
|
||||
delay_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer.active = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -176,7 +174,6 @@ void ScsiBusController::notify(ScsiNotification notif_type, int param) {
|
||||
if (this->dst_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer);
|
||||
this->seq_timer.active = false;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
|
||||
@@ -42,6 +42,11 @@ 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
|
||||
|
||||
@@ -109,16 +109,33 @@ int ScsiCommonCmds::verify_cdb() {
|
||||
}
|
||||
|
||||
int ScsiCommonCmds::test_unit_ready() {
|
||||
// Assume that LUN is okay and the status has been set to GOOD
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 ScsiPhase::STATUS;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiCommonCmds::inquiry() {
|
||||
|
||||
@@ -98,6 +98,8 @@ 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);
|
||||
|
||||
|
||||
@@ -180,7 +180,6 @@ void ScsiHardDisk::format() {
|
||||
if (this->phase_switch_timer.active)
|
||||
LOG_F(WARNING, "%s: phase_switch_timer is already active", this->get_name().c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->phase_switch_timer, NS_PER_SEC, [this](uint64_t, uint64_t) {
|
||||
this->phase_switch_timer.active = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ void ScsiPhysDevice::notify(ScsiNotification notif_type, int param)
|
||||
TimerManager::get_instance()->add_oneshot_timer(bus_settle_timer,
|
||||
BUS_SETTLE_DELAY,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->bus_settle_timer.active = 0;
|
||||
// don't confirm selection if BSY or I/O are asserted
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
return;
|
||||
|
||||
+41
-29
@@ -105,19 +105,15 @@ ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer);
|
||||
this->sr_timer.active = 0;
|
||||
}
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
this->t1_timer.active = 0;
|
||||
}
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
this->t2_timer.active = 0;
|
||||
}
|
||||
if (this->treq_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer);
|
||||
this->treq_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,10 +160,12 @@ 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;
|
||||
@@ -179,6 +177,7 @@ 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"
|
||||
@@ -216,7 +215,6 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer);
|
||||
this->t1_timer.active = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
@@ -225,7 +223,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();
|
||||
this->activate_t1(TimerManager::get_instance()->current_time_ns());
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
@@ -243,24 +241,13 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer);
|
||||
this->t2_timer.active = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2ll;
|
||||
// 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
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->t2_timer,
|
||||
(this->via_clk_dur * (this->t2_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->t2_timer.active = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
this->activate_t2(TimerManager::get_instance()->current_time_ns());
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->via_sr = value;
|
||||
@@ -297,30 +284,58 @@ 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() {
|
||||
void ViaCuda::activate_t1(uint64_t start_time) {
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
this->t1_start_time = start_time;
|
||||
uint64_t timeout = start_time +
|
||||
((this->via_clk_dur * (this->t1_counter + 3) + (uint64_t(1) << 36)) >> 37);
|
||||
// set up timout timer for T1
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->t1_timer,
|
||||
(this->via_clk_dur * (this->t1_counter + 3) + (uint64_t(1) << 36)) >> 37,
|
||||
[this](uint64_t, uint64_t) {
|
||||
TimerManager::get_instance()->add_absolute_timer(this->t1_timer,
|
||||
timeout, 0,
|
||||
[this](uint64_t timeout_ns, uint64_t /*time_now*/) {
|
||||
// reload the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->t1_timer.active = 0;
|
||||
this->assert_t1_int();
|
||||
if (this->via_acr & 0x40)
|
||||
this->activate_t1();
|
||||
this->activate_t1(timeout_ns);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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"};
|
||||
|
||||
@@ -388,12 +403,10 @@ 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);
|
||||
this->sr_timer.active = 0;
|
||||
}
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->sr_timer,
|
||||
timeout_ns,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->sr_timer.active = 0;
|
||||
this->assert_sr_int();
|
||||
}
|
||||
);
|
||||
@@ -431,7 +444,6 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer.active = 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -273,7 +273,9 @@ 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();
|
||||
void activate_t1(uint64_t start_time);
|
||||
void activate_t2(uint64_t start_time);
|
||||
void check_t2();
|
||||
|
||||
// CUDA methods
|
||||
void cuda_init();
|
||||
|
||||
@@ -72,15 +72,12 @@ void Swim3Ctrl::reset()
|
||||
|
||||
if (this->one_us_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer);
|
||||
this->one_us_timer.active = 0;
|
||||
}
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
this->step_timer.active = 0;
|
||||
}
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
this->access_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +289,6 @@ void Swim3Ctrl::stop_stepping()
|
||||
// cancel stepping task
|
||||
if (this->step_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer);
|
||||
this->step_timer.active = 0;
|
||||
}
|
||||
this->step_count = 0; // not sure this one is required
|
||||
}
|
||||
@@ -322,7 +318,6 @@ void Swim3Ctrl::start_disk_access()
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
this->int_drive->sync_to_disk(),
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->access_timer.active = 0;
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
this->disk_access();
|
||||
}
|
||||
@@ -375,7 +370,6 @@ void Swim3Ctrl::disk_access()
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->access_timer,
|
||||
delay,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->access_timer.active = 0;
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
@@ -386,7 +380,6 @@ void Swim3Ctrl::stop_disk_access()
|
||||
// cancel disk access timer
|
||||
if (this->access_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer);
|
||||
this->access_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +401,6 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->one_us_timer,
|
||||
uint32_t(this->timer_val) * NS_PER_USEC,
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->one_us_timer.active = 0;
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
update_irq();
|
||||
|
||||
+35
-23
@@ -98,7 +98,6 @@ AMIC::~AMIC()
|
||||
{
|
||||
if (this->pseudo_vbl_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_timer);
|
||||
this->pseudo_vbl_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,7 +637,6 @@ void AmicSndOutDma::update_irq() {
|
||||
if (this->interrupt_timer.active)
|
||||
LOG_F(ERROR, "AMIC: interrupt_timer is already active");
|
||||
TimerManager::get_instance()->add_immediate_timer(interrupt_timer, [this](uint64_t, uint64_t) {
|
||||
interrupt_timer.active = 0;
|
||||
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
|
||||
});
|
||||
}
|
||||
@@ -690,10 +688,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);
|
||||
len, false, true);
|
||||
*p_data = res.host_va;
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
this->cur_buf_pos += res.size;
|
||||
*avail_len = res.size;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
|
||||
@@ -726,15 +724,19 @@ DmaPushResult AmicFloppyDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
len = std::min((int)this->byte_count, len);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
this->addr_ptr += len;
|
||||
this->byte_count -= len;
|
||||
this->addr_ptr += res.size;
|
||||
this->byte_count -= res.size;
|
||||
src_ptr += res.size;
|
||||
len -= res.size;
|
||||
} while (len > 0);
|
||||
if (!this->byte_count) {
|
||||
LOG_F(WARNING, "AMIC: DMA interrupts not implemented yet");
|
||||
}
|
||||
@@ -785,12 +787,17 @@ void AmicScsiDma::xfer_from_device() {
|
||||
|
||||
uint32_t len = this->dev_obj->tell_xfer_size(this);
|
||||
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
do {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false, true);
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_from(this, res.host_va, len);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void AmicScsiDma::xfer_to_device() {
|
||||
@@ -801,12 +808,17 @@ void AmicScsiDma::xfer_to_device() {
|
||||
|
||||
uint32_t len = this->dev_obj->tell_xfer_size(this);
|
||||
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
do {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false, true);
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_to(this, res.host_va, len);
|
||||
if (got_bytes > 0) {
|
||||
this->addr_ptr += got_bytes;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void AmicScsiDma::xfer_retry() {
|
||||
|
||||
@@ -41,13 +41,14 @@ 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 = 0xFF000002;
|
||||
this->class_rev = MACIO_DEVCLASS_ID | 2; // hardcoded revision = 2
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
this->setup_bars({{0, 0xFFFE0000UL}}); // declare 128Kb of memory-mapped I/O space
|
||||
@@ -433,6 +434,7 @@ 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:
|
||||
@@ -523,15 +525,11 @@ uint64_t GrandCentral::register_dma_int(IntSrc src_id) {
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
// 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
|
||||
// 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
|
||||
|
||||
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;
|
||||
}
|
||||
uint32_t old_levels = this->int_levels;
|
||||
uint32_t old_events = this->int_events;
|
||||
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
@@ -540,7 +538,16 @@ void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->int_levels &= ~(uint32_t)irq_id;
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
|
||||
@@ -44,6 +44,9 @@ 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,
|
||||
@@ -359,10 +362,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_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)
|
||||
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)
|
||||
|
||||
// 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 = 0xFF000000 + rev;
|
||||
this->class_rev = MACIO_DEVCLASS_ID + 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) {
|
||||
// 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
|
||||
// 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
|
||||
#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,12 +142,9 @@ 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
|
||||
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;
|
||||
}
|
||||
uint64_t old_levels = this->int_levels;
|
||||
uint64_t old_events = this->int_events;
|
||||
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
@@ -155,7 +152,16 @@ void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MacIoBase::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
|
||||
@@ -366,7 +366,10 @@ void MacIoTwo::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
|
||||
switch (offset & ~3) {
|
||||
case MIO_INT_MASK2:
|
||||
this->int_mask |= uint64_t(value & ~MACIO_INT_MODE) << 32;
|
||||
// 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->signal_cpu_int();
|
||||
break;
|
||||
case MIO_INT_CLEAR2:
|
||||
@@ -377,6 +380,7 @@ 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:
|
||||
|
||||
+34
-17
@@ -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 = 0x06000040;
|
||||
this->class_rev = DEVTYPE_HOST2PCI_BRIDGE | GRACKLE_REV_4_0;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 6;
|
||||
this->status = 0x80;
|
||||
@@ -314,24 +314,41 @@ void MPC106::setup_ram() {
|
||||
}
|
||||
}
|
||||
|
||||
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 GrackleGossamer_Properties = {
|
||||
{"pci_PERCH", new StrProperty("")},
|
||||
{"pci_A1" , new StrProperty("")},
|
||||
{"pci_B1" , new StrProperty("")},
|
||||
{"pci_C1" , new StrProperty("")},
|
||||
// {"pci_GPU" , new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Grackle_Descriptor = {
|
||||
MPC106::create, {}, Grackle_Properties,
|
||||
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,
|
||||
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Grackle, Grackle_Descriptor);
|
||||
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 );
|
||||
@@ -42,7 +42,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class InterruptCtrl;
|
||||
/** Grackle ASIC revisions. */
|
||||
constexpr uint8_t GRACKLE_REV_4_0 = 0x40;
|
||||
|
||||
/** Grackle configuration space registers. */
|
||||
enum GrackleReg : uint32_t {
|
||||
|
||||
@@ -58,7 +58,15 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
|
||||
// initialize the CPUID register with the following CPU:
|
||||
// PowerPC 601 @ 90 MHz, bus frequency: 45 MHz
|
||||
this->cpu_id = (0x3001 << 16) | ClkSrc2 | (CpuSpeed2::CPU_90_BUS_45 << 8);
|
||||
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->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
|
||||
@@ -124,7 +132,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(), this->fb_addr + offset);
|
||||
this->name.c_str(), VRAM_REGION_BASE + offset);
|
||||
return (uint32_t)-1;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +238,7 @@ void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
} else
|
||||
LOG_F(WARNING, "%s: write to unmapped aperture address 0x%X",
|
||||
this->name.c_str(), this->fb_addr + offset);
|
||||
this->name.c_str(), VRAM_REGION_BASE + offset);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,10 +247,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;
|
||||
this->dram_timing = value & 0x1FFF;
|
||||
break;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
this->dram_refresh = value;
|
||||
this->dram_refresh = value & 0x7FF;
|
||||
break;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
@@ -252,20 +260,22 @@ 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;
|
||||
this->bank_base[(offset >> 4) - PlatinumReg::BANK_0_BASE] = value & 0xFF700000U;
|
||||
this->map_phys_ram();
|
||||
break;
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
this->fb_addr = value;
|
||||
this->fb_offset = value & 0x3FFFFF;
|
||||
this->change_display();
|
||||
if (this->fb_addr != value) {
|
||||
this->fb_addr = value;
|
||||
this->fb_offset = value & 0x3FFFFF;
|
||||
this->change_display();
|
||||
}
|
||||
break;
|
||||
case PlatinumReg::ROW_WORDS:
|
||||
this->row_words = value & ~7;
|
||||
this->row_words = value & 0x7FF8;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::CLOCK_DIVISOR:
|
||||
this->clock_divisor = value;
|
||||
this->clock_divisor = value & 0xFFU;
|
||||
this->change_display();
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_1:
|
||||
@@ -276,10 +286,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;
|
||||
this->fb_config_2 = value & 0x1FFF;
|
||||
break;
|
||||
case PlatinumReg::VMEM_PAGE_MODE:
|
||||
this->vmem_fp_mode = value;
|
||||
this->vmem_fp_mode = value & 1;
|
||||
break;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
value &= 7;
|
||||
@@ -290,6 +300,7 @@ 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;
|
||||
@@ -325,10 +336,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;
|
||||
this->vram_refresh = value & 0x7FF;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_CONFIG:
|
||||
this->swatch_config = value;
|
||||
this->swatch_config = (this->swatch_config & ~0xFFU) | (value & 0xFFU);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_INT_MASK:
|
||||
this->swatch_int_mask = value;
|
||||
@@ -336,7 +347,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;
|
||||
this->cursor_line = value & 0x7FF;
|
||||
if (this->swatch_int_mask & SWATCH_INT_CURSOR)
|
||||
this->enable_cursor_int();
|
||||
break;
|
||||
@@ -349,7 +360,6 @@ 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:
|
||||
@@ -364,11 +374,15 @@ 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;
|
||||
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->change_display();
|
||||
break;
|
||||
case PlatinumReg::TIMING_ADJUST:
|
||||
this->timing_adjust = value;
|
||||
this->timing_adjust = value & 0xFFF;
|
||||
break;
|
||||
case PlatinumReg::IRIDIUM_CONFIG:
|
||||
if (!(value & 1))
|
||||
@@ -627,7 +641,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(1, std::vector<uint32_t>({1, 2, 4}))},
|
||||
new IntProperty(4, std::vector<uint32_t>({1, 2, 4}))},
|
||||
{"mon_id",
|
||||
new StrProperty("HiRes12-14in")},
|
||||
};
|
||||
|
||||
@@ -38,7 +38,6 @@ 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;
|
||||
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 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 pages_cfg[5] = {0x88888888,0x88888888,0x88888888,0x88888888,0x88888888};
|
||||
uint32_t bank_size[5] = {};
|
||||
std::unique_ptr<uint8_t[]> dram_ptr = nullptr;
|
||||
|
||||
@@ -120,7 +120,6 @@ void AwacsBase::dma_in_data() {
|
||||
10000,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->dma_in_timer.active = 0;
|
||||
this->dma_in_data();
|
||||
});
|
||||
}
|
||||
@@ -134,7 +133,6 @@ 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);
|
||||
this->dma_in_timer.active = 0;
|
||||
}
|
||||
LOG_F(ERROR, "%s: dma_in_stop", this->name.c_str());
|
||||
}
|
||||
|
||||
@@ -118,7 +118,6 @@ void BurgundyCodec::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->first_valid_timer,
|
||||
USECS_TO_NSECS(22), // average is approximately 22.6 µs on a real B&W G3
|
||||
[this](uint64_t, uint64_t) {
|
||||
this->first_valid_timer.active = 0;
|
||||
this->first_valid = false;
|
||||
this->byte_counter = (this->byte_counter + 1) & 3;
|
||||
});
|
||||
|
||||
@@ -227,9 +227,13 @@ int SoundServer::open_out_stream(uint32_t sample_rate, DmaOutChannel *dma_ch)
|
||||
int SoundServer::start_out_stream()
|
||||
{
|
||||
if (is_deterministic) {
|
||||
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);
|
||||
// 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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int res = cubeb_stream_start(impl->out_stream);
|
||||
@@ -250,7 +254,6 @@ void SoundServer::close_out_stream()
|
||||
{
|
||||
if (impl->deterministic_poll_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(impl->deterministic_poll_timer);
|
||||
impl->deterministic_poll_timer.active = 0;
|
||||
}
|
||||
if (!impl->out_stream) {
|
||||
impl->status = SND_STREAM_CLOSED;
|
||||
|
||||
@@ -92,7 +92,6 @@ void AppleRamdac::iodev_write(uint32_t address, uint16_t value) {
|
||||
#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);
|
||||
cursor_timer.active = 0;
|
||||
}
|
||||
this->cursor_xpos = (value << 8) | this->cursor_pos_lo;
|
||||
#else
|
||||
@@ -105,13 +104,11 @@ void AppleRamdac::iodev_write(uint32_t address, uint16_t value) {
|
||||
if (this->cursor_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->cursor_timer);
|
||||
this->cursor_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
cursor_timer.active = 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_xpos = (this->cursor_xpos & 0xff00) | (this->cursor_pos_lo & 0x00ff);
|
||||
cursor_timer.active = 0;
|
||||
this->cursor_update_cb();
|
||||
}
|
||||
);
|
||||
|
||||
+22
-17
@@ -321,7 +321,7 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int 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);
|
||||
this->name.c_str(), pixel_width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -373,7 +373,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 +401,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;
|
||||
@@ -491,7 +491,7 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
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);
|
||||
this->name.c_str(), pixel_width);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -511,10 +511,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 +523,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 +548,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,12 +583,17 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
} else
|
||||
this->swatch_ctrl = value;
|
||||
break;
|
||||
case ControlRegs::GBASE:
|
||||
this->fb_base = value & 0x3FFFE0;
|
||||
if (this->display_enabled) {
|
||||
this->enable_display();
|
||||
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();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ControlRegs::ROW_WORDS:
|
||||
this->row_words = value & 0x7FE0;
|
||||
if (this->display_enabled) {
|
||||
@@ -599,8 +604,8 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
// 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);
|
||||
"%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;
|
||||
@@ -651,7 +656,7 @@ uint8_t* ControlVideo::GetVram()
|
||||
|
||||
void ControlVideo::update_fb_ptr()
|
||||
{
|
||||
this->fb_ptr = &this->vram_ptr[this->fb_base];
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+43
-10
@@ -126,18 +126,21 @@ void ValkyrieVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, i
|
||||
|
||||
switch((offset >> this->reg_shift) & 0xFF) {
|
||||
case Valkyrie::csr_mode:
|
||||
if (value != this->mode) {
|
||||
auto old_mode = this->mode;
|
||||
{
|
||||
uint8_t old_mode = this->mode;
|
||||
if (value != old_mode) {
|
||||
this->mode = value;
|
||||
if ((value ^ old_mode) & 0x80) {
|
||||
if (value & 0x80)
|
||||
if (value & 0x80) { // is disabled
|
||||
if (!(old_mode & 0x80)) // was enabled
|
||||
this->disable_video_internal();
|
||||
else
|
||||
this->schedule_mode_switch();
|
||||
}
|
||||
else { // is enabled and was disabled or is enabled and mode changed
|
||||
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();
|
||||
@@ -194,7 +197,6 @@ void ValkyrieVideo::schedule_mode_switch() {
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(this->mode_timer,
|
||||
MSECS_TO_NSECS(3), [this](uint64_t, uint64_t) {
|
||||
this->mode_timer.active = 0;
|
||||
this->enable_video_internal();
|
||||
});
|
||||
}
|
||||
@@ -206,25 +208,56 @@ 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::Rgb13in:
|
||||
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
|
||||
new_width = 640;
|
||||
new_height = 480;
|
||||
hori_blank = 224;
|
||||
vert_blank = 45;
|
||||
break;
|
||||
case PdmVideoMode::Rgb16in:
|
||||
case PdmVideoMode::Rgb16in: // 0x9: // 832x624 75 Hz 57.219340 MHz
|
||||
new_width = 832;
|
||||
new_height = 624;
|
||||
hori_blank = 320;
|
||||
vert_blank = 43;
|
||||
break;
|
||||
case PdmVideoMode::VGA:
|
||||
case PdmVideoMode::VGA: // 0xB: // 640x480 60 Hz 25.203756 MHz
|
||||
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;
|
||||
|
||||
+22
-20
@@ -101,28 +101,32 @@ 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 / refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(this->refresh_timer,
|
||||
refresh_interval,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// assert VBL interrupt
|
||||
this->vbl_cb(1);
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
if (vert_blank == 0) {
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
if (this->vert_blank == 0) {
|
||||
LOG_F(ERROR, "Vertical blank is 0. Using 25 instead.");
|
||||
vert_blank = 25;
|
||||
this->vert_blank = 25;
|
||||
}
|
||||
|
||||
uint64_t vbl_duration = static_cast<uint64_t>((double)hori_total * vert_blank / this->pixel_clock * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()-> add_cyclic_timer(this->vbl_end_timer,
|
||||
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,
|
||||
refresh_interval,
|
||||
refresh_interval + vbl_duration,
|
||||
[this](uint64_t, uint64_t) {
|
||||
// deassert VBL interrupt
|
||||
this->vbl_cb(0);
|
||||
[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();
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -130,11 +134,9 @@ void VideoCtrlBase::start_refresh_task() {
|
||||
void VideoCtrlBase::stop_refresh_task() {
|
||||
if (this->refresh_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_timer);
|
||||
this->refresh_timer.active = 0;
|
||||
}
|
||||
if (this->vbl_end_timer.active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_timer);
|
||||
this->vbl_end_timer.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ protected:
|
||||
int vert_blank = 0;
|
||||
int pixel_depth;
|
||||
int pixel_format;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
double pixel_clock; // float can represent all integers only up to 16 MHz
|
||||
float refresh_rate = 0;
|
||||
|
||||
// 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
|
||||
|
||||
@@ -126,6 +126,8 @@ 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("Grackle"));
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("GrackleBondi"));
|
||||
grackle_obj->set_irq_map(grackle_irq_map);
|
||||
|
||||
MacIoTwo* mio_obj = dynamic_cast<MacIoTwo*>(gMachineObj->get_comp_by_name("Paddington"));
|
||||
@@ -110,7 +110,7 @@ static const PropMap bondi_settings = {
|
||||
};
|
||||
|
||||
static std::vector<std::string> bondi_devices = {
|
||||
"Grackle", "BurgundySnd", "Paddington", "AtaHardDisk", "AtapiCdrom"};
|
||||
"GrackleBondi", "BurgundySnd", "Paddington", "AtaHardDisk", "AtapiCdrom"};
|
||||
|
||||
static const DeviceDescription MachineBondi_descriptor = {
|
||||
Machine::create<MachineBondi>, bondi_devices, bondi_settings
|
||||
|
||||
@@ -85,6 +85,15 @@ 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);
|
||||
@@ -123,6 +132,8 @@ 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",
|
||||
|
||||
@@ -145,6 +145,8 @@ 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)},
|
||||
{"hdd_config",
|
||||
|
||||
@@ -136,7 +136,7 @@ int MachineGossamer::initialize(const std::string &id) {
|
||||
LOG_F(INFO, "Building machine Gossamer...");
|
||||
|
||||
// get pointer to the memory controller/PCI host bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("GrackleGossamer"));
|
||||
grackle_obj->set_irq_map(grackle_irq_map);
|
||||
|
||||
// configure the Gossamer system register
|
||||
@@ -235,11 +235,11 @@ static const PropMap gossamer_tower_settings = {
|
||||
};
|
||||
|
||||
static std::vector<std::string> pmg3_devices = {
|
||||
"Grackle", "ScreamerSnd", "Heathrow", "AtaHardDisk", "AtapiCdrom"
|
||||
"GrackleGossamer", "ScreamerSnd", "Heathrow", "AtaHardDisk", "AtapiCdrom"
|
||||
};
|
||||
|
||||
static std::vector<std::string> pmg3twr_devices = {
|
||||
"Grackle", "ScreamerSnd", "Heathrow", "AtaHardDisk", "AtapiCdrom"
|
||||
"GrackleGossamer", "ScreamerSnd", "Heathrow", "AtaHardDisk", "AtapiCdrom"
|
||||
};
|
||||
|
||||
static const DeviceDescription MachineGossamerDesktop_descriptor = {
|
||||
|
||||
@@ -158,6 +158,8 @@ static const PropMap pm6100_settings = {
|
||||
new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)},
|
||||
{"pds",
|
||||
new StrProperty("")},
|
||||
{"cdr_config",
|
||||
new StrProperty("ScsiCurio:3")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
@@ -88,6 +88,8 @@ static const PropMap Pippin_settings = {
|
||||
new IntProperty(0, std::vector<uint32_t>({0, 1, 4, 8, 16}))},
|
||||
{"rambank4_size",
|
||||
new IntProperty(0, std::vector<uint32_t>({0, 1, 4, 8, 16}))},
|
||||
{"cdr_config",
|
||||
new StrProperty("ScsiCurio:3")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
{"adb_devices",
|
||||
|
||||
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
@@ -151,15 +152,16 @@ void parse_device_path(std::string dev_path, std::string& bus_id, uint32_t& dev_
|
||||
dev_num = -1;
|
||||
|
||||
size_t delimiter_pos = dev_path.find(":");
|
||||
if (delimiter_pos == std::string::npos)
|
||||
if (delimiter_pos == std::string::npos || delimiter_pos == 0)
|
||||
ABORT_F("Invalid device path %s", dev_path.c_str());
|
||||
|
||||
bus_id = dev_path.substr(0, delimiter_pos);
|
||||
|
||||
try {
|
||||
dev_num = (uint32_t)strtoul(dev_path.substr(delimiter_pos+1).c_str(), 0, 0);
|
||||
} catch (std::string bad_string) {
|
||||
ABORT_F("Invalid device number %s in device path %s", bad_string.c_str(),
|
||||
dev_path.c_str());
|
||||
}
|
||||
std::string number = dev_path.substr(delimiter_pos + 1);
|
||||
char* end;
|
||||
errno = 0;
|
||||
unsigned long value = strtoul(number.c_str(), &end, 0);
|
||||
if (end == number.c_str() || *end || errno == ERANGE || value > UINT32_MAX)
|
||||
ABORT_F("Invalid device number %s in device path %s", number.c_str(), dev_path.c_str());
|
||||
dev_num = (uint32_t)value;
|
||||
}
|
||||
@@ -123,6 +123,15 @@ int MachineTnt::initialize(const std::string &id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Hammerhead 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 (!memctrl_obj->add_mem_mirror(addr, 0xFFC00000)) {
|
||||
LOG_F(ERROR, "Could not create ROM mirror!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// populate RAM banks from configuration properties
|
||||
for (int bank_num = 0; bank_num <= 12; bank_num++) {
|
||||
std::string bn = std::to_string(bank_num);
|
||||
@@ -172,6 +181,7 @@ static const PropMap pm7500_settings_ ## cpu = { \
|
||||
{"rambank10_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
|
||||
{"rambank11_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
|
||||
{"rambank12_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", new StrProperty(# cpu, std::vector<std::string>({"601", "604", "604e", "750"}))}, \
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ int MachineYosemite::initialize(const std::string &id) {
|
||||
LOG_F(INFO, "Building machine Yosemite...");
|
||||
|
||||
// get pointer to the memory controller/primary PCI bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("GrackleYosemite"));
|
||||
grackle_obj->set_irq_map(grackle_irq_map);
|
||||
|
||||
// get pointer to the bridge of the secondary PCI bus
|
||||
@@ -132,7 +132,7 @@ static const PropMap yosemite_settings = {
|
||||
};
|
||||
|
||||
static std::vector<std::string> yosemite_devices = {
|
||||
"Grackle",
|
||||
"GrackleYosemite",
|
||||
"Dec21154Yosemite",
|
||||
"CmdAta",
|
||||
"BurgundySnd",
|
||||
|
||||
@@ -179,6 +179,8 @@ int main(int argc, char** argv) {
|
||||
->check(WorkingDirectory)->capture_default_str();
|
||||
auto bootrom_opt = emu->add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
|
||||
->check(CLI::ExistingFile)->capture_default_str();
|
||||
emu->add_flag("--realtime", g_realtime,
|
||||
"Advance guest timers using the host clock");
|
||||
auto deterministic_opt = emu->add_flag("--deterministic", is_deterministic,
|
||||
"Use deterministic execution");
|
||||
emu->add_option("--start-date", start_date,
|
||||
@@ -234,6 +236,10 @@ int main(int argc, char** argv) {
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
deterministic_interactive = deterministic_mode == "interactive";
|
||||
if (g_realtime && is_deterministic && !deterministic_interactive) {
|
||||
return app.exit(CLI::ValidationError("--realtime",
|
||||
"Use --deterministic-mode=interactive with realtime timing"));
|
||||
}
|
||||
|
||||
if (*list_cmd) {
|
||||
if (sub_arg == "machines") {
|
||||
@@ -327,6 +333,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
cout << "BootROM path: " << bootrom_path << endl;
|
||||
cout << "Execution mode: " << execution_mode << endl;
|
||||
if (g_realtime)
|
||||
cout << "Guest timers use the host clock." << endl;
|
||||
if (is_deterministic) {
|
||||
cout << "Using deterministic execution mode; disk, NVRAM, and PRAM changes will not be saved." << endl;
|
||||
if (deterministic_interactive) {
|
||||
|
||||
@@ -25,8 +25,11 @@
|
||||
| 0x50000000 | 0x5FFFFFFF | IO Devices |
|
||||
| 0x5FFFFFFC | | "cpuid", really a Machine ID |
|
||||
| 0x60000000 | 0xEFFFFFFF | NuBus "super slot" space |
|
||||
| 0xF1000000 | 0xFFBFFFFF | NuBus "standard slot" space |
|
||||
| 0xFFC00000 | 0xFFFFFFFF | ROM |
|
||||
| 0xF1000000 | 0xFEFFFFFF | NuBus "standard slot" space |
|
||||
| 0xFF000000 | 0xFFFFFFFF | ROM alias |
|
||||
|
||||
The high ROM alias range is documented in Apple's
|
||||
[6100/7100/8100 Developer Note, Table 2-5](https://www.macdat.net/files/pdf/apple/developer_notes/power_macintosh_6100_7100_8100.pdf#page=36).
|
||||
|
||||
### IO Bus
|
||||
|
||||
@@ -90,9 +93,18 @@
|
||||
* 0xFEE00000 - Grackle CONFIG_DATA (0x4 bytes, all redirected to 0xXXXXXCFF)
|
||||
|
||||
### ROM / Misc Area (0xFF000000 - 0xFFFFFFFF)
|
||||
* 0xFF000000 - ?
|
||||
|
||||
* 0xFF000004 - "cpuid", really a machine ID
|
||||
On TNT/Tsunami (Hammerhead) and Catalyst (Platinum), the 4 MB ROM repeats at
|
||||
`0xFF000000`, `0xFF400000`, `0xFF800000`, and `0xFFC00000`. Both controllers
|
||||
use the full 16 MB range for ROM; the ROM chips receive only PowerPC address bits
|
||||
10–28 ([9600 schematic, sheet 6](https://www.macdat.net/files/pdf/apple/schematics/apple/powermac_9600.pdf#page=6),
|
||||
[7200 schematic, sheet 9](https://www.macdat.net/files/pdf/apple/schematics/apple/powermac_7200.pdf#page=9)).
|
||||
|
||||
Gossamer differs: Grackle selects ROM with RCS0 (`0xFF800000–0xFFFFFFFF`),
|
||||
while RCS1 (`0xFF000000–0xFF7FFFFF`) enables board-status buffers, including
|
||||
the machine ID at `0xFF000004`. Do not apply the TNT aliases to this range
|
||||
([Gossamer schematic, sheet 7](https://www.macdat.net/files/pdf/apple/schematics/apple/powermac_g3_gossamer.pdf#page=7),
|
||||
[MPC106 manual, §1.2.3](https://www.nxp.com/docs/en/reference-manual/MPC106UM.pdf)).
|
||||
|
||||
* 0xFFC00000 - 0xFFFFFFFF
|
||||
Mac OS ROM Area
|
||||
@@ -103,4 +115,4 @@
|
||||
|
||||
* 0xFFF00100 - Reset Area (where the ROM begins executing)
|
||||
* 0xFFF10000 - Nanokernel Code
|
||||
* 0xFFF20000 - HW Init
|
||||
* 0xFFF20000 - HW Init
|
||||
+10
-3
@@ -73,14 +73,20 @@ Specifies working directory, where `path` is a string for the directory the emul
|
||||
|
||||
Start the guest RTC on the given date, using the current local time of day. The clock continues ticking, including across midnight. This is useful for running software with an expiration date, such as `--start-date=1997-03-01` for BeOS DR 8.2. Without a date override or deterministic mode, the RTC follows the host clock.
|
||||
|
||||
```
|
||||
--realtime
|
||||
```
|
||||
|
||||
Advance the CPU timebase, decrementer, and device timers using elapsed host time, instead of instruction counts. This keeps double click delays, keyboard repeat, sleeps, and timeouts tied to wall time, improving usability of user interfaces. Control-Alt-R toggles this mode while running.
|
||||
|
||||
```
|
||||
--deterministic
|
||||
--deterministic-mode strict|interactive
|
||||
```
|
||||
|
||||
Enables deterministic mode, where the emulator behaves the same way every run. Meant to be a development or debugging aid, to remove variability between runs. Disk, NVRAM, and PRAM changes are not saved. The default `strict` mode ignores mouse and keyboard input; `interactive` mode allows input for interactive debugging.
|
||||
Enables deterministic mode, where the emulator behaves the same way every run. Meant to be a development or debugging aid, to remove variability between runs. Disk, NVRAM, and PRAM changes are not saved. Audio output is also disabled, since we cannot control when the host would try to access it. The default `strict` mode ignores mouse and keyboard input; `interactive` mode allows input for interactive debugging.
|
||||
|
||||
The RTC defaults to `--start-date=2001-03-24`, unless a date is explicitly supplied. It starts at noon and advances the RTC with emulated time. Restarting the emulated machine starts the deterministic RTC from that date and noon again.
|
||||
The RTC defaults to `--start-date=2001-03-24`, unless a date is explicitly supplied. It starts at noon and advances the RTC with emulated time. Restarting the emulated machine starts the deterministic RTC from that date and noon again. With `--realtime`, it advances at wall-clock rate from that fixed date and noon.
|
||||
|
||||
```
|
||||
--setenv args
|
||||
@@ -209,7 +215,7 @@ The debugger is enabled here, due to the presence of `-d`. The CD ROM image will
|
||||
|
||||
## Keyboard Shortcuts
|
||||
|
||||
You can use these keyboard commands while the emulator is running in real-time mode:
|
||||
You can use these keyboard commands while the emulator is running:
|
||||
|
||||
* Control-G: mouse grab
|
||||
* Control-S: scale quality
|
||||
@@ -219,6 +225,7 @@ You can use these keyboard commands while the emulator is running in real-time m
|
||||
* Control--: smaller
|
||||
* Control-L: log toggle
|
||||
* Control-D: debugger
|
||||
* Control-Alt-R: toggle realtime guest timing
|
||||
|
||||
## Accessing Open Firmware
|
||||
|
||||
|
||||
Reference in new issue
Block a user