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