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