Compare commits

..
3 Commits
Author SHA1 Message Date
dingusdev 5c5ff999bc Fixed NIA code 2024-12-19 21:36:04 -07:00
dingusdev 5a8d469ae8 Partial fix for bench 2024-12-19 07:21:13 -07:00
dingusdev 957016c7c9 First attempt at removing NIA global variable 2024-12-18 08:03:50 -07:00
189 changed files with 4010 additions and 6938 deletions

No files matched your search

-15
View File
@@ -97,21 +97,6 @@ if (NOT EMSCRIPTEN)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
# Warn if no audio backends were detected on Linux/Unix systems
if (UNIX AND NOT APPLE)
if (NOT USE_PULSE AND NOT USE_ALSA AND NOT USE_JACK AND
NOT USE_SNDIO AND NOT USE_OSS AND NOT USE_SUN)
message(WARNING
"No Cubeb audio backends detected on Linux/Unix system!\n"
"Audio will NOT work at runtime.\n"
"Please install development headers for at least one of:\n"
" - PulseAudio (libpulse-dev / pulseaudio-libs-devel)\n"
" - ALSA (libasound2-dev / alsa-lib-devel)\n"
" - JACK (libjack-dev / jack-audio-connection-kit-devel)\n"
" - sndio (libsndio-dev)")
endif()
endif()
endif()
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
-14
View File
@@ -23,25 +23,11 @@
- kth5
- dyharlan
- roytam1
- mrpapersonic
- Randrianasulu
- lefp
- mathstuf
- seanm
- erichelgeson
- alicela1n
## Testing
- LagLifeYT
## 3rd Party Libraries
- [Capstone](https://github.com/capstone-engine/capstone)
- [CLI11](https://github.com/CLIUtils/CLI11)
- [Loguru](https://github.com/emilk/loguru)
- [SDL 2](https://github.com/libsdl-org/SDL)
## Thanks
- 68kmla
+4 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -44,20 +44,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// cyclic rotation idioms that modern compilers will
// recognize and generate very compact code for
// involving specific machine instructions
// evolving specific machine instructions
inline unsigned ROTL_32(unsigned x, unsigned n) {
n &= 0x1F;
if (n)
return (x << n) | (x >> (32 - n));
return x;
return (x << n) | (x >> (32 - n));
}
inline unsigned ROTR_32(unsigned x, unsigned n) {
n &= 0x1F;
if (n)
return (x >> n) | (x << (32 - n));
return x;
return (x >> n) | (x << (32 - n));
}
#endif
+7 -28
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -36,15 +36,9 @@ public:
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's.
// We add our own custom events after that.
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE,
DPPC_WINDOWEVENT_WINDOW_BIGGER,
DPPC_WINDOWEVENT_WINDOW_SMALLER,
// Standard SDL window event types are uint8_t's, we add our own custom
// events after that.
WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
};
enum : uint32_t {
@@ -76,17 +70,7 @@ public:
uint32_t flags;
uint32_t key;
};
enum KeyboardLocale : uint32_t {
Eng_USA = 0,
Eng_GBR = 1,
Fra_FRA = 10,
Deu_DEU = 20,
Ita_ITA = 30,
Spa_ESP = 40,
Jpn_JPN = 80,
uint16_t keys_state;
};
/* AppleJack bits 3-7 are supported but unused */
@@ -126,11 +110,9 @@ public:
event_manager = new EventManager();
}
return event_manager;
}
};
void poll_events();
void set_keyboard_locale(uint32_t keyboard_id);
void post_keyboard_state_events();
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -161,19 +143,17 @@ public:
_window_signal.disconnect_all();
_mouse_signal.disconnect_all();
_keyboard_signal.disconnect_all();
_gamepad_signal.disconnect_all();
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
_gamepad_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {} // private constructor to implement a singleton
EventManager() {}; // private constructor to implement a singleton
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
@@ -186,7 +166,6 @@ private:
uint64_t key_downs = 0;
uint64_t key_ups = 0;
uint8_t buttons_state = 0;
uint32_t kbd_locale = 0;
};
#endif // EVENT_MANAGER_H
+49 -187
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -28,15 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
this->kbd_locale = keyboard_id;
}
void EventManager::poll_events() {
void EventManager::poll_events()
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -49,7 +45,7 @@ void EventManager::poll_events() {
break;
case SDL_WINDOWEVENT: {
WindowEvent we{};
WindowEvent we;
we.sub_type = event.window.event;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
@@ -58,112 +54,27 @@ void EventManager::poll_events() {
case SDL_KEYDOWN:
case SDL_KEYUP: {
if (event.key.repeat)
break;
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
if (event.key.keysym.sym == SDLK_g && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we;
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
toggle_mouse_grab(event.key);
}
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
WindowEvent we;
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-F: fullscreen
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-Shift-F: fullscreen reverse
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LSHIFT)) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-+: bigger
if (event.key.keysym.sym == SDLK_EQUALS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control--: smaller
if (event.key.keysym.sym == SDLK_MINUS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
loguru::Verbosity_INFO
:
loguru::Verbosity_MAX;
}
return;
}
// Control-D: debugger
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
power_on = false;
power_off_reason = po_enter_debugger;
}
return;
}
// Ralt+delete => ctrl+alt+del
if (event.key.keysym.sym == SDLK_DELETE && ((event.key.keysym.mod & KMOD_ALL) == KMOD_RALT) != 0) {
KeyboardEvent ke{};
ke.key = AdbKey_Control;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
key_downs++;
} else {
ke.flags = KEYBOARD_EVENT_UP;
key_ups++;
}
this->_keyboard_signal.emit(ke);
ke.key = AdbKey_Delete;
this->_keyboard_signal.emit(ke);
return;
}
int key_code = get_sdl_event_key_code(event.key, this->kbd_locale);
int key_code = get_sdl_event_key_code(event.key);
if (key_code != -1) {
KeyboardEvent ke{};
KeyboardEvent ke;
ke.key = key_code;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
@@ -174,7 +85,7 @@ void EventManager::poll_events() {
}
// Caps Lock is a special case, since it's a toggle key
if (ke.key == AdbKey_CapsLock) {
ke.flags = event.key.keysym.mod & KMOD_CAPS ?
ke.flags = SDL_GetModState() & KMOD_CAPS ?
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
}
this->_keyboard_signal.emit(ke);
@@ -185,7 +96,7 @@ void EventManager::poll_events() {
break;
case SDL_MOUSEMOTION: {
MouseEvent me{};
MouseEvent me;
me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel;
me.xabs = event.motion.x;
@@ -196,7 +107,7 @@ void EventManager::poll_events() {
break;
case SDL_MOUSEBUTTONDOWN: {
MouseEvent me{};
MouseEvent me;
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -213,7 +124,7 @@ void EventManager::poll_events() {
break;
case SDL_MOUSEBUTTONUP: {
MouseEvent me{};
MouseEvent me;
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -230,7 +141,7 @@ void EventManager::poll_events() {
break;
case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge{};
GamepadEvent ge;
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -253,7 +164,7 @@ void EventManager::poll_events() {
break;
case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge{};
GamepadEvent ge;
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -284,78 +195,8 @@ void EventManager::poll_events() {
this->_post_signal.emit();
}
void EventManager::post_keyboard_state_events() {
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
SDL_KeyboardEvent keyevent = { .type = SDL_KEYDOWN };
SDL_Scancode scancode;
KeyboardEvent ke{};
typedef struct {
SDL_Scancode scancode;
SDL_Keymod keymod;
AdbKey adbkey;
} Modifier_t;
static Modifier_t modifiers[] = {
SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift ,
SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift ,
SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control ,
SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl,
SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option ,
SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption ,
SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command ,
SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command ,
// SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear ,
SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock ,
// SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? ,
// SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 ,
SDL_SCANCODE_UNKNOWN
};
LOG_F(INFO, "Current keyboard state:");
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
if (!(modstate & mod->keymod))
continue;
LOG_F(INFO, " mod:%s", SDL_GetScancodeName(mod->scancode));
ke.key = mod->adbkey;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
}
for (int i = 0; i < numkeys; i++) {
if (!states[i])
continue;
scancode = (SDL_Scancode)i;
Modifier_t *mod = modifiers;
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
if (mod->scancode == scancode) {
LOG_F(INFO, " ignore:%s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
int key_code = get_sdl_event_key_code(keyevent, this->kbd_locale);
if (key_code != -1) {
ke.key = key_code;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
}
}
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
{
switch (event.keysym.sym) {
case SDLK_a: return AdbKey_A;
@@ -436,11 +277,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_PAGEDOWN: return AdbKey_PageDown;
case SDLK_LCTRL: return AdbKey_Control;
case SDLK_RCTRL: return AdbKey_RightControl;
case SDLK_RCTRL: return AdbKey_Control;
case SDLK_LSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_RightShift;
case SDLK_RSHIFT: return AdbKey_Shift;
case SDLK_LALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_RightOption;
case SDLK_RALT: return AdbKey_Option;
case SDLK_LGUI: return AdbKey_Command;
case SDLK_RGUI: return AdbKey_Command;
case SDLK_MENU: return AdbKey_Grave;
@@ -450,7 +291,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_DOWN: return AdbKey_ArrowDown;
case SDLK_LEFT: return AdbKey_ArrowLeft;
case SDLK_RIGHT: return AdbKey_ArrowRight;
;
case SDLK_KP_0: return AdbKey_Keypad0;
case SDLK_KP_1: return AdbKey_Keypad1;
case SDLK_KP_2: return AdbKey_Keypad2;
@@ -469,7 +310,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
;
case SDLK_F1: return AdbKey_F1;
case SDLK_F2: return AdbKey_F2;
case SDLK_F3: return AdbKey_F3;
@@ -490,11 +331,10 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
//Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
return AdbKey_JIS_Yen;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
case 0XBC:
return AdbKey_JIS_KP_Comma;
case 0X89:
return AdbKey_JIS_Eisu;
@@ -533,3 +373,25 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
}
return -1;
}
static void toggle_mouse_grab(const SDL_KeyboardEvent &event) {
SDL_Window *window = SDL_GetWindowFromID(event.windowID);
if (SDL_GetRelativeMouseMode()) {
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_SetWindowTitle(window, "DingusPPC Display");
} else {
// If the mouse is initially outside the window, move it to the middle,
// so that clicks are handled by the window (instead making it lose
// focus, at least with macOS hosts).
int mouse_x, mouse_y, window_x, window_y, window_width, window_height;
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
SDL_GetWindowPosition(window, &window_x, &window_y);
SDL_GetWindowSize(window, &window_width, &window_height);
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
mouse_y < window_y || mouse_y >= window_y + window_height) {
SDL_WarpMouseInWindow(window, window_width / 2, window_height / 2);
}
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_SetWindowTitle(window, "DingusPPC Display (Mouse Grabbed)");
}
}
-2
View File
@@ -19,8 +19,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cstdint>
#ifndef MATH_UTILS_H
#define MATH_UTILS_H
+15 -17
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,11 +31,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <vector>
#include <mutex>
constexpr auto NS_PER_SEC = 1000000000;
constexpr auto USEC_PER_SEC = 1000000;
constexpr auto NS_PER_USEC = 1000;
constexpr auto NS_PER_MSEC = 1000000;
constexpr auto ONE_BILLION_NS = 1000000000;
#define NS_PER_SEC 1000000000
#define USEC_PER_SEC 1000000
#define NS_PER_USEC 1000
#define NS_PER_MSEC 1000000
#define ONE_BILLION_NS 1000000000
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
@@ -64,13 +64,13 @@ public:
return true;
}
return false;
}
};
void push(T val)
{
std::lock_guard<std::recursive_mutex> lk(mtx);
std::priority_queue<T, Container, Compare>::push(val);
}
};
T pop()
{
@@ -78,7 +78,7 @@ public:
T val = std::priority_queue<T, Container, Compare>::top();
std::priority_queue<T, Container, Compare>::pop();
return val;
}
};
std::recursive_mutex& get_mtx()
{
@@ -111,20 +111,20 @@ public:
timer_manager = new TimerManager();
}
return timer_manager;
}
};
// callback for retrieving current time
void set_time_now_cb(const std::function<uint64_t()> &cb) {
this->get_time_now = cb;
}
};
// callback for acknowledging time changes
void set_notify_changes_cb(const timer_cb &cb) {
this->notify_timer_changes = cb;
}
};
// return current virtual time in nanoseconds
uint64_t current_time_ns() { return get_time_now(); }
uint64_t current_time_ns() { return get_time_now(); };
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
@@ -137,7 +137,7 @@ public:
private:
static TimerManager* timer_manager;
TimerManager(){} // private constructor to implement a singleton
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;
@@ -146,9 +146,7 @@ private:
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
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
};
#endif // TIMER_MANAGER_H
+46 -18
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// The Power-specific opcodes for the processor - ppcopcodes.cpp
// Any shared opcodes are in ppcopcodes.cpp
#include <core/bitops.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
@@ -53,6 +52,7 @@ void dppc_interpreter::power_abs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
@@ -84,6 +84,7 @@ void dppc_interpreter::power_clcs(uint32_t opcode) {
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template <field_rc rec, field_ov ov>
@@ -124,6 +125,7 @@ void dppc_interpreter::power_div(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
ppc_next_instruction();
}
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
@@ -158,6 +160,7 @@ void dppc_interpreter::power_divs(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
ppc_next_instruction();
}
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
@@ -182,6 +185,7 @@ void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
@@ -198,6 +202,7 @@ void dppc_interpreter::power_dozi(uint32_t opcode) {
ppc_result_d = simm - ppc_result_a;
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template <field_rc rec>
@@ -249,6 +254,7 @@ void dppc_interpreter::power_lscbx(uint32_t opcode) {
(is_match ? CRx_bit::CR_EQ : 0) |
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
}
ppc_next_instruction();
}
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
@@ -277,6 +283,7 @@ void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
@@ -291,6 +298,7 @@ void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
@@ -313,6 +321,7 @@ void dppc_interpreter::power_mul(uint32_t opcode) {
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
@@ -331,6 +340,7 @@ void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
@@ -342,8 +352,9 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
@@ -352,6 +363,7 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template <field_rc rec>
@@ -369,6 +381,7 @@ void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
@@ -380,7 +393,7 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_store_iresult_reg(reg_a, ppc_result_a);
@@ -388,6 +401,7 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
@@ -397,7 +411,7 @@ template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -407,6 +421,7 @@ void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
@@ -417,12 +432,13 @@ void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
@@ -431,7 +447,7 @@ template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -441,6 +457,7 @@ void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
@@ -461,6 +478,7 @@ void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
@@ -480,8 +498,9 @@ void dppc_interpreter::power_slq(uint32_t opcode) {
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
@@ -492,7 +511,7 @@ void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -504,6 +523,7 @@ void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
@@ -515,7 +535,7 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
@@ -523,12 +543,13 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
@@ -541,12 +562,13 @@ void dppc_interpreter::power_sre(uint32_t opcode) {
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
@@ -557,7 +579,7 @@ void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t r = (rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d);
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
@@ -571,6 +593,7 @@ void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r;
ppc_next_instruction();
}
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
@@ -583,12 +606,13 @@ void dppc_interpreter::power_sreq(uint32_t opcode) {
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
@@ -598,12 +622,13 @@ template <field_rc rec>
void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
@@ -612,7 +637,7 @@ template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
@@ -622,6 +647,7 @@ void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
@@ -631,7 +657,7 @@ template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
@@ -644,6 +670,7 @@ void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
@@ -660,12 +687,13 @@ void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
+2 -2
View File
@@ -253,9 +253,9 @@ const char* trap_cond[32] = {/*Trap conditions*/
"twlt", "", "", "", "twle", "", "", "",
"twne", "", "", "", "", "", "", ""};
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "dec", "",
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "", "",
"lr", "ctr", "", "", "", "", "", "",
"", "", "dsisr", "dar", "rtcu", "rtcl", "dec", "",
"", "", "dsisr", "dar", "", "", "dec", "",
"", "sdr1", "srr0", "srr1", "", "", "", ""};
const char* spr_index8[32] = {
+29 -60
View File
@@ -177,16 +177,14 @@ extern uint64_t rtc_timestamp;
extern uint64_t tbr_wr_value;
extern uint32_t dec_wr_value;
extern uint32_t tbr_freq_ghz;
extern uint32_t tbr_freq_shift;
extern uint64_t tbr_period_ns;
extern uint32_t rtc_lo, rtc_hi;
/* Flags for controlling interpreter execution. */
enum {
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
EXEF_RFI = 1 << 2, // RFI instruction executed
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2,
};
enum CR_select : int32_t {
@@ -245,54 +243,22 @@ enum FPSCR : uint32_t {
FX = 1UL << 31
};
/** Bit definitions for the Machine State Register (MSR). */
enum MSR : int {
// ----------------------------------------------------------------------------------------
// 64-bit // 32-bit // Notes for MPC601 (601), PowerPC (PPC),
// // // MPC750 (750), Altivec (AV), Power ISA (ISA)
// ----------------------------------------------------------------------------------------
LE = (1 << (63 - 63)), // 31 // Little-endian mode enable (not 601);
// Little-Endian Mode (ISA)
RI = (1 << (63 - 62)), // 30 // Recoverable exception (not 601);
// Recoverable Interrupt (ISA)
PM = (1 << (63 - 61)), // 29 // Performance monitor marked mode (750);
// Performance Monitor Mark (PMM for ISA)
// = (1 << (63 - 60)), // 28 // Reserved
DR = (1 << (63 - 59)), // 27 // Data address translation (DT on 601);
// Data Relocate (ISA)
IR = (1 << (63 - 58)), // 26 // Instruction address translation (IT on 601);
// Instruction Relocate (ISA)
IP = (1 << (63 - 57)), // 25 // Exception prefix (EP); Reserved (ISA)
// = (1 << (63 - 56)), // 24 // Reserved (AL for POWER)
FE1 = (1 << (63 - 55)), // 23 // Floating-point exception mode 1
BE = (1 << (63 - 54)), // 22 // Branch trace enable (Optional, not 601);
// Trace Enable (TE): Branch Trace (ISA)
SE = (1 << (63 - 53)), // 21 // Single-step trace enable (Optional);
// Trace Enable (TE): Single Step Trace (ISA)
FE0 = (1 << (63 - 52)), // 20 // Floating-point exception mode 0
ME = (1 << (63 - 51)), // 19 // Machine check enable;
// Machine Check Interrupt Enable (ISA)
FP = (1 << (63 - 50)), // 18 // Floating-point available
PR = (1 << (63 - 49)), // 17 // Privilege level; Problem State (ISA)
EE = (1 << (63 - 48)), // 16 // External exception enable (601);
// External interrupt enable
// ----------------------------------------------------------------------------------------
ILE = (1 << (63 - 47)), // 15 // Exception little-endian mode (not 601, not ISA)
TGPR = (1 << (63 - 46)), // 14 // Temporary GPR remapping (603e)
POW = (1 << (63 - 45)), // 13 // Power management enable (not 601, not ISA)
// = (1 << (63 - 44)), // 12 // Reserved
// = (1 << (63 - 42)), // 10 // Reserved
// S = (1 << (63 - 41)), // 9 // Secure (ISA)
// VSX = (1 << (63 - 40)), // 8 // VSX Available (ISA)
// = (1 << (63 - 39)), // 7 // Reserved
VEC = (1 << (63 - 38)), // 6 // AltiVec available (AV); Vector Available (ISA)
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// HV = (1ULL << (63 - 3)), // // Hypervisor State (ISA)
// ISF = (1ULL << (63 - 2)), // // Exception 64-bit mode (optional, PPC)
// = (1ULL << (63 - 1)), // // Reserved
// SF = (1ULL << (63 - 0)), // // Sixty-four bit mode (PowerPC, PowerISA)
// ----------------------------------------------------------------------------------------
LE = 0x1, //little endian mode
RI = 0x2,
DR = 0x10,
IR = 0x20,
IP = 0x40,
FE1 = 0x100,
BE = 0x200,
SE = 0x400,
FE0 = 0x800,
ME = 0x1000,
FP = 0x2000,
PR = 0x4000,
EE = 0x8000, //external interrupt
ILE = 0x10000,
POW = 0x40000
};
enum XER : uint32_t {
@@ -360,16 +326,21 @@ extern bool int_pin;
extern bool dec_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation
// Make execution deterministic (ignore external input, used a fixed date, etc.)
extern bool is_deterministic;
// Important Addressing Integers
extern uint32_t ppc_next_instruction_address;
//Instruction Handling
inline void ppc_next_instruction() {
ppc_state.pc += 4;
}
inline void ppc_set_instruction(uint32_t new_pc) {
ppc_state.pc = new_pc;
}
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
return READ_DWORD_BE_A(ptr);
@@ -675,16 +646,14 @@ template <field_rc rec> extern void power_srq(uint32_t opcode);
extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode);
extern void ppc_main_opcode(uint32_t opcode);
extern void ppc_exec(void);
extern void ppc_exec_single(void);
extern void ppc_exec_until(uint32_t goal_addr);
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
extern PPCOpcode* ppc_opcode_grabber;
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
/* debugging support API */
void print_fprs(void); /* print content of the floating-point registers */
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 */
+8 -11
View File
@@ -36,6 +36,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
#ifdef CPU_PROFILING
exceptions_processed++;
#endif
uint32_t ppc_next_instruction_address;
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
@@ -57,8 +58,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_ISI:
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_state.pc + 4;
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
}
@@ -66,7 +67,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags & ~EXEF_OPC_DECODER) {
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -90,7 +91,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_DECR:
if (exec_flags & ~EXEF_OPC_DECODER) {
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -114,20 +115,16 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
}
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
ppc_state.msr &= 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */
if (!is_601) {
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
}
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, new_msr_val, false);
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000;
}
exec_flags = EXEF_EXCEPTION;
ppc_set_instruction(ppc_next_instruction_address);
// perform context synchronization for recoverable exceptions
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
+120 -204
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcdisasm.h"
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
@@ -66,8 +65,6 @@ Po_Cause power_off_reason = po_enter_debugger;
SetPRS ppc_state;
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
unsigned exec_flags; // execution control flags
// FIXME: exec_timer is read by main thread ppc_main_opcode;
// written by audio dbdma DMAChannel::update_irq .. add_immediate_timer
@@ -92,7 +89,6 @@ uint64_t rtc_timestamp; // stores vCPU virtual time of the last RTC write
uint64_t tbr_wr_value; // last value written to the TBR
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a
// 32 bit fraction less than 1.0 (999.999999 MHz maximum).
uint32_t tbr_freq_shift; // If 32 bits is not sufficient, then include a shift.
uint64_t tbr_period_ns; // TBR/RTC period in ns expressed as a 64 bit value
// with 32 fractional bits (<1 Hz minimum).
uint64_t timebase_counter; // internal timebase counter
@@ -118,7 +114,7 @@ std::unordered_map<uint32_t, uint64_t> num_opcodes;
class CPUProfile : public BaseProfile {
public:
CPUProfile() : BaseProfile("PPC_CPU") {}
CPUProfile() : BaseProfile("PPC_CPU") {};
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -155,12 +151,9 @@ public:
op_name_counts.emplace_back(op_name, pair.second);
}
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
std::partial_sort(
op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(),
[](const auto& a, const auto& b) {
return b.second < a.second;
}
);
std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
return b.second < a.second;
});
op_name_counts.resize(top_ops_size);
for (const auto& pair : op_name_counts) {
vars.push_back({.name = "Instruction " + pair.first,
@@ -169,7 +162,7 @@ public:
.count_total = num_executed_instrs});
}
#endif
}
};
void reset() {
num_executed_instrs = 0;
@@ -180,7 +173,7 @@ public:
#ifdef CPU_PROFILING_OPS
num_opcodes.clear();
#endif
}
};
};
#endif
@@ -189,43 +182,12 @@ public:
primary opcode (bits 0...5) and modifier (bits 21...31). */
static PPCOpcode OpcodeGrabber[64 * 2048];
/** Alternate lookup table when floating point instructions are disabled.
Floating point instructions are mapped to ppc_fpu_off,
everything else is the same.*/
static PPCOpcode OpcodeGrabberNoFPU[64 * 2048];
void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address) {
ppc_state.msr = new_msr_val;
if ((old_msr_val ^ new_msr_val) & MSR::FP) {
bool newFP = (new_msr_val & MSR::FP) != 0;
ppc_opcode_grabber = newFP ? OpcodeGrabber : OpcodeGrabberNoFPU;
//LOG_F(INFO, "changed FP to %s", newFP ? "yes" : "no");
#if 1
exec_flags |= EXEF_OPC_DECODER;
if (set_next_instruction_address) {
// Even though we're setting an exception flag, we want normal
// instruction execution to continue.
ppc_next_instruction_address = ppc_state.pc + 4;
}
#else
power_on = false;
power_off_reason = po_endian_switch;
#endif
}
}
PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
/** Exception helpers. */
void ppc_illegalop(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
void ppc_fpu_off(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_NO_FPU, Exc_Cause::FPU_OFF);
}
void ppc_assert_int() {
int_pin = true;
if (ppc_state.msr & MSR::EE) {
@@ -243,7 +205,7 @@ void ppc_release_int() {
/** Opcode decoding functions. */
/* Dispatch using primary and modifier opcode */
void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
void ppc_main_opcode(uint32_t opcode)
{
#ifdef CPU_PROFILING
num_executed_instrs++;
@@ -251,7 +213,7 @@ void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
num_opcodes[opcode]++;
#endif
#endif
opcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
OpcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
}
static long long cpu_now_ns() {
@@ -303,7 +265,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
uint64_t max_cycles = 0;
uint32_t page_start, eb_start, eb_end = 0;
uint32_t opcode;
PPCOpcode* opcode_grabber = ppc_opcode_grabber;
uint32_t pc_old;
uint8_t* pc_real;
while (power_on) {
@@ -321,19 +283,17 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
pc_real = mmu_translate_imem(eb_start);
}
pc_old = ppc_state.pc;
opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode_grabber, opcode);
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]]
ppc_main_opcode(opcode);
if (g_icycles++ >= max_cycles || exec_timer)
max_cycles = process_events();
if (exec_flags) {
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
opcode_grabber = ppc_opcode_grabber;
}
// define next execution block
eb_start = ppc_next_instruction_address;
eb_start = ppc_state.pc;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
pc_real += (int)eb_start - (int)pc_old;
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
@@ -341,8 +301,9 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else { [[likely]]
ppc_state.pc += 4;
}
else {
[[likely]]
pc_real += 4;
}
@@ -363,7 +324,7 @@ void ppc_exec()
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
ppc_state.pc += 4;
}
while (power_on) {
@@ -377,22 +338,19 @@ void ppc_exec_single()
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
ppc_state.pc += 4;
exec_flags = 0;
return;
}
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
g_icycles++;
process_events();
if (exec_flags) {
ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
} else {
ppc_state.pc += 4;
}
}
@@ -402,11 +360,12 @@ void ppc_exec_single()
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
// outer interpreter loop
void ppc_exec_until(volatile uint32_t goal_addr) {
void ppc_exec_until(volatile uint32_t goal_addr)
{
if (setjmp(exc_env)) {
// process low-level exceptions
// LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc += 4;
}
while (power_on) {
@@ -427,7 +386,7 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
ppc_state.pc += 4;
}
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
@@ -446,107 +405,89 @@ Opcode table macros:
- r is for raw (adding custom entries to the table)
*/
#define OP(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
} \
} while (0)
#define OPX(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0)
#define OPXd(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<RC1, OV1>; \
} while (0)
#define OPXdc(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<carry, RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<carry, RC1, OV1>; \
} while (0)
#define OPla(opcode, subopcode, fn) \
do { \
for (uint32_t mod = 0; mod < 512; mod++) { \
OpcodeGrabber[((opcode) << 11) | (mod << 2) | (subopcode)] = fn; \
} \
} while (0)
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
} while (0)
#define OPr_fp(opcode, mod, fn) \
do { \
OPr(opcode, mod, fn); \
OpcodeGrabberNoFPU[((opcode) << 11) | (mod)] = ppc_fpu_off; \
} while (0)
#define OP(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr(opcode, mod, fn); \
} \
} while (0)
#define OP_fp(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OPr_fp(opcode, mod, fn); \
} \
} while (0)
#define OPX(opcode, subopcode, fn) OPr(opcode, (subopcode)<<1, fn)
#define OPX_fp(opcode, subopcode, fn) OPr_fp(opcode, (subopcode)<<1, fn)
#define OPXd(opcode, subopcode, fn) \
do { \
OPr(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXd_fp(opcode, subopcode, fn) \
do { \
OPr_fp(opcode, ((subopcode)<<1) | 0, fn<RC0>); \
OPr_fp(opcode, ((subopcode)<<1) | 1, fn<RC1>); \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<RC1, OV1>)); \
} while (0)
#define OPXdc(opcode, subopcode, fn, carry) \
do { \
OPr(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXdc_fp(opcode, subopcode, fn, carry) \
do { \
OPr_fp(opcode, ((subopcode)<<1) | 0, (fn<carry, RC0>)); \
OPr_fp(opcode, ((subopcode)<<1) | 1, (fn<carry, RC1>)); \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OPr(opcode, ((subopcode)<<1) | 0x000, (fn<carry, RC0, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x001, (fn<carry, RC1, OV0>)); \
OPr(opcode, ((subopcode)<<1) | 0x400, (fn<carry, RC0, OV1>)); \
OPr(opcode, ((subopcode)<<1) | 0x401, (fn<carry, RC1, OV1>)); \
} while (0)
#define OPla(opcode, subopcode, fn) \
do { \
for (uint32_t mod = 0; mod < 512; mod++) { \
OPr(opcode, (mod << 2) | (subopcode), fn); \
} \
} while (0)
#define OP31(subopcode, fn) OPX(31, subopcode, fn)
#define OP31_fp(subopcode, fn) OPX_fp(31, subopcode, fn)
#define OP31d(subopcode, fn) OPXd(31, subopcode, fn)
#define OP31od(subopcode, fn) OPXod(31, subopcode, fn)
#define OP31dc(subopcode, fn, carry) OPXdc(31, subopcode, fn, carry)
#define OP31cod(subopcode, fn, carry) OPXcod(31, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX_fp(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc(63, subopcode, fn, carry)
#define OP59d(subopcode, fn) OPXd_fp(59, (subopcode), fn)
#define OP59d(subopcode, fn) \
do { \
OPXd(59, (subopcode), fn); \
} while (0)
#define OP59cd(subopcode, fn) \
do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \
OPXd_fp(59, (ccccc << 5) | (subopcode), fn); \
OPXd(59, (ccccc << 5) | (subopcode), fn); \
} \
} while (0)
#define OP4_ccccc10xxxx(subopcode, fn) \
do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \
OPr(4, (ccccc << 6) | (subopcode), fn); \
} \
} while (0)
void initialize_ppc_opcode_table() {
auto opcodeGrabberSize = sizeof(OpcodeGrabber) / sizeof(OpcodeGrabber[0]);
std::fill_n(OpcodeGrabber, opcodeGrabberSize, ppc_illegalop);
std::fill_n(OpcodeGrabberNoFPU, opcodeGrabberSize, ppc_illegalop);
std::fill_n(OpcodeGrabber, 64 * 2048, ppc_illegalop);
OP(3, ppc_twi);
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
OP(7, ppc_mulli);
@@ -585,14 +526,14 @@ void initialize_ppc_opcode_table() {
OP(45, ppc_stu<uint16_t>);
OP(46, ppc_lmw);
OP(47, ppc_stmw);
OP_fp(48, ppc_lfs);
OP_fp(49, ppc_lfsu);
OP_fp(50, ppc_lfd);
OP_fp(51, ppc_lfdu);
OP_fp(52, ppc_stfs);
OP_fp(53, ppc_stfsu);
OP_fp(54, ppc_stfd);
OP_fp(55, ppc_stfdu);
OP(48, ppc_lfs);
OP(49, ppc_lfsu);
OP(50, ppc_lfd);
OP(51, ppc_lfdu);
OP(52, ppc_stfs);
OP(53, ppc_stfsu);
OP(54, ppc_stfd);
OP(55, ppc_stfdu);
OPla(16, 0x0, (dppc_interpreter::ppc_bc<LK0, AA0>)); // bc
OPla(16, 0x1, (dppc_interpreter::ppc_bc<LK1, AA0>)); // bcl
@@ -654,11 +595,11 @@ void initialize_ppc_opcode_table() {
OP31(375, ppc_lhaux);
OP31(533, ppc_lswx);
OP31(534, ppc_lwbrx);
OP31_fp(535, ppc_lfsx);
OP31_fp(567, ppc_lfsux);
OP31(535, ppc_lfsx);
OP31(567, ppc_lfsux);
OP31(597, ppc_lswi);
OP31_fp(599, ppc_lfdx);
OP31_fp(631, ppc_lfdux);
OP31(599, ppc_lfdx);
OP31(631, ppc_lfdux);
OP31(790, ppc_lhbrx);
OPr(31, (150<<1) | 1, ppc_stwcx); // No Rc=0 variant.
@@ -670,13 +611,13 @@ void initialize_ppc_opcode_table() {
OP31(439, ppc_stux<uint16_t>);
OP31(661, ppc_stswx);
OP31(662, ppc_stwbrx);
OP31_fp(663, ppc_stfsx);
OP31_fp(695, ppc_stfsux);
OP31(663, ppc_stfsx);
OP31(695, ppc_stfsux);
OP31(725, ppc_stswi);
OP31_fp(727, ppc_stfdx);
OP31_fp(759, ppc_stfdux);
OP31(727, ppc_stfdx);
OP31(759, ppc_stfdux);
OP31(918, ppc_sthbrx);
if (!is_601) OP31_fp(983, ppc_stfiwx);
if (!is_601) OP31(983, ppc_stfiwx);
OP31(310, ppc_eciwx);
OP31(438, ppc_ecowx);
@@ -796,12 +737,6 @@ void initialize_ppc_opcode_table() {
OP63d(i + 30, ppc_fnmsub);
OP63d(i + 31, ppc_fnmadd);
}
for (auto i = 0; i < opcodeGrabberSize; i++) {
if (OpcodeGrabberNoFPU[i] != ppc_fpu_off) {
OpcodeGrabberNoFPU[i] = OpcodeGrabber[i];
}
}
}
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_601, uint64_t tb_freq)
@@ -812,8 +747,8 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
set_host_rounding_mode(0);
ppc_state.spr[SPR::PVR] = cpu_version;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 & do_include_601;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 && do_include_601;
initialize_ppc_opcode_table();
@@ -827,31 +762,12 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
// // // PDM cpu clock calculated at 0x403036CC in r3
// icnt_factor = 11; // 1 instruction = 2048 ns = 0.488 MHz // 00068034 = 0.426036 MHz = 2347.219 ns // floppy doesn't work
// icnt_factor = 10; // 1 instruction = 1024 ns = 0.977 MHz // 000D204C = 0.860236 MHz = 1162.471 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 9; // 1 instruction = 512 ns = 1.953 MHz // 001A6081 = 1.728641 MHz = 578.489 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 8; // 1 instruction = 256 ns = 3.906 MHz // 0034E477 = 3.466359 MHz = 288.487 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 7; // 1 instruction = 128 ns = 7.813 MHz // 0069E54C = 6.939980 MHz = 144.092 ns // [0..10] MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 6; // 1 instruction = 64 ns = 15.625 MHz // 00D3E6F5 = 13.887221 MHz = 72.008 ns // (10..60] = 50, (60..73] = 66, (73..100] = 80 MHz
// icnt_factor = 5; // 1 instruction = 32 ns = 31.250 MHz // 01A7B672 = 27.768434 MHz = 36.012 ns //
icnt_factor = 4; // 1 instruction = 16 ns = 62.500 MHz // 034F0F0F = 55.512847 MHz = 18.013 ns // 6100/60 in Apple System Profiler
// icnt_factor = 3; // 1 instruction = 8 ns = 125.000 MHz // 069E1E1E = 111.025694 MHz = 9.006 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 2; // 1 instruction = 4 ns = 250.000 MHz // 0D3C3C3C = 222.051388 MHz = 4.503 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 1; // 1 instruction = 2 ns = 500.000 MHz // 1A611A7B = 442.571387 MHz = 2.259 ns // (100...) MHz = invalid clock for PDM gestalt calculation
// icnt_factor = 0; // 1 instruction = 1 ns = 1500.000 MHz // 3465B2D9 = 879.080153 MHz = 1.137 ns // (100...) MHz = invalid clock for PDM gestalt calculation
//icnt_factor = 6;
icnt_factor = 4;
tbr_wr_timestamp = 0;
rtc_timestamp = 0;
tbr_wr_value = 0;
if (is_601)
tb_freq <<= 7;
tbr_freq_shift = 0;
uint64_t x;
for (x = (tb_freq << 32) / NS_PER_SEC; x >> 32; x >>= 1)
tbr_freq_shift++;
tbr_freq_ghz = (uint32_t)x;
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq;
exec_flags = 0;
@@ -861,15 +777,13 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
dec_wr_value = 0;
uint32_t new_msr_val;
if (is_601) {
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */
new_msr_val = (MSR::ME + MSR::IP);
ppc_state.msr = (MSR::ME + MSR::IP);
} else {
new_msr_val = MSR::IP;
ppc_state.msr = MSR::IP;
ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL;
}
ppc_msr_did_change(new_msr_val, new_msr_val, false);
ppc_mmu_init();
@@ -882,6 +796,11 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif
}
void print_fprs() {
for (int i = 0; i < 32; i++)
cout << "FPR " << dec << i << " : " << ppc_state.fpr[i].dbl64_r << endl;
}
static map<string, int> SPRName2Num = {
{"XER", SPR::XER}, {"LR", SPR::LR}, {"CTR", SPR::CTR},
{"DEC", SPR::DEC_S}, {"PVR", SPR::PVR}, {"SPRG0", SPR::SPRG0},
@@ -924,11 +843,8 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
return ppc_state.pc;
}
if (reg_name_u == "MSR") {
if (is_write) {
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = (uint32_t)val;
ppc_msr_did_change(old_msr_val, new_msr_val, false);
}
if (is_write)
ppc_state.msr = (uint32_t)val;
return ppc_state.msr;
}
if (reg_name_u == "CR") {
+184 -100
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,24 +24,24 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
#include <stdlib.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
ppc_state.cr = (ppc_state.cr & ~CR_select::CR1_field) |
((ppc_state.fpscr >> 4) & CR_select::CR1_field);
((ppc_state.fpscr >> 4) & CR_select::CR1_field);
}
static int32_t round_to_nearest(double f) {
return static_cast<int32_t>(static_cast<int64_t> (std::floor(f + 0.5)));
return static_cast<int32_t>(static_cast<int64_t>(std::floor(f + 0.5)));
}
void set_host_rounding_mode(uint8_t mode) {
switch(mode & FPSCR::RN_MASK) {
switch (mode & FPSCR::RN_MASK) {
case 0:
std::fesetround(FE_TONEAREST);
break;
@@ -78,9 +78,9 @@ static int32_t round_to_neg_inf(double f) {
inline static bool check_snan(int check_reg) {
uint64_t check_int = FPR_INT(check_reg);
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & ~(0xFFFULL << 52)) != 0ULL) &&
((check_int & (0x1ULL << 51)) == 0ULL));
return (
((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & ~(0xFFFULL << 52)) != 0ULL) && ((check_int & (0x1ULL << 51)) == 0ULL));
}
inline static bool snan_single_check(int reg_a) {
@@ -107,7 +107,8 @@ inline static void max_double_check(double value_a, double value_b) {
inline static bool check_qnan(int check_reg) {
uint64_t check_int = FPR_INT(check_reg);
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
return (
((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
}
@@ -154,7 +155,8 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = (ppc_state.fpscr >> 22) & ppc_state.fpscr & 0x0F8;
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) & ((ppc_state.fpscr >> 3) & 0x1F));
if (fpscr_check)
ppc_state.fpscr |= VX;
else
@@ -171,8 +173,7 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
double ppc_dblresult64_d = val_reg_a + val_reg_b;
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -182,8 +183,7 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
if (snan_double_check(reg_a, reg_b)) {
uint64_t qnan = 0x7FFC000000000000;
ppc_store_fpresult_int(reg_d, qnan);
}
else {
} else {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
@@ -191,6 +191,8 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fadd<RC0>(uint32_t opcode);
@@ -221,6 +223,8 @@ void dppc_interpreter::ppc_fsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsub<RC0>(uint32_t opcode);
@@ -235,10 +239,6 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (is_601 && FPR_INT(reg_b) == 0x8000000000000000 && val_reg_a > 0) {
ppc_dblresult64_d = val_reg_b;
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
return;
}
@@ -246,6 +246,7 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (val_reg_b == 0.0) {
ppc_state.fpscr |= FX | VX;
ppc_dblresult64_d = -ppc_dblresult64_d;
}
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
@@ -262,8 +263,7 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (snan_double_check(reg_a, reg_b)) {
uint64_t qnan = 0x7FFC000000000000;
ppc_store_fpresult_int(reg_d, qnan);
}
else {
} else {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
@@ -271,6 +271,8 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fdiv<RC0>(uint32_t opcode);
@@ -305,6 +307,8 @@ void dppc_interpreter::ppc_fmul(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmul<RC0>(uint32_t opcode);
@@ -317,8 +321,7 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -344,6 +347,8 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmadd<RC0>(uint32_t opcode);
@@ -386,6 +391,8 @@ void dppc_interpreter::ppc_fmsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmsub<RC0>(uint32_t opcode);
@@ -429,6 +436,8 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmadd<RC0>(uint32_t opcode);
@@ -467,6 +476,8 @@ void dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmsub<RC0>(uint32_t opcode);
@@ -499,6 +510,8 @@ void dppc_interpreter::ppc_fadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fadds<RC0>(uint32_t opcode);
@@ -511,8 +524,7 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == inf)) ||
((val_reg_a == -inf) && (val_reg_b == -inf))) {
if (((val_reg_a == inf) && (val_reg_b == inf)) || ((val_reg_a == -inf) && (val_reg_b == -inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -530,6 +542,8 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsubs<RC0>(uint32_t opcode);
@@ -542,6 +556,7 @@ void dppc_interpreter::ppc_fdivs(uint32_t opcode) {
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
if (val_reg_b == 0.0) {
ppc_state.fpscr |= FX | VX;
ppc_dblresult64_d = -ppc_dblresult64_d;
}
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
@@ -570,6 +585,8 @@ void dppc_interpreter::ppc_fdivs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fdivs<RC0>(uint32_t opcode);
@@ -604,6 +621,8 @@ void dppc_interpreter::ppc_fmuls(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmuls<RC0>(uint32_t opcode);
@@ -639,6 +658,8 @@ void dppc_interpreter::ppc_fmadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmadds<RC0>(uint32_t opcode);
@@ -673,6 +694,8 @@ void dppc_interpreter::ppc_fmsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmsubs<RC0>(uint32_t opcode);
@@ -710,6 +733,8 @@ void dppc_interpreter::ppc_fnmadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmadds<RC0>(uint32_t opcode);
@@ -751,6 +776,8 @@ void dppc_interpreter::ppc_fnmsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmsubs<RC0>(uint32_t opcode);
@@ -768,6 +795,8 @@ void dppc_interpreter::ppc_fabs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fabs<RC0>(uint32_t opcode);
@@ -785,6 +814,8 @@ void dppc_interpreter::ppc_fnabs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnabs<RC0>(uint32_t opcode);
@@ -802,6 +833,8 @@ void dppc_interpreter::ppc_fneg(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fneg<RC0>(uint32_t opcode);
@@ -817,6 +850,8 @@ void dppc_interpreter::ppc_fsel(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsel<RC0>(uint32_t opcode);
@@ -826,7 +861,7 @@ template <field_rc rec>
void dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
ppc_grab_regsfpdb(opcode);
double testd2 = (double)(GET_FPR(reg_b));
double testd2 = (double)(GET_FPR(reg_b));
double ppc_dblresult64_d = std::sqrt(testd2);
if (snan_single_check(reg_b)) {
@@ -838,6 +873,8 @@ void dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsqrt<RC0>(uint32_t opcode);
@@ -859,6 +896,8 @@ void dppc_interpreter::ppc_fsqrts(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsqrts<RC0>(uint32_t opcode);
@@ -880,6 +919,8 @@ void dppc_interpreter::ppc_frsqrte(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_frsqrte<RC0>(uint32_t opcode);
@@ -900,6 +941,8 @@ void dppc_interpreter::ppc_frsp(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_frsp<RC0>(uint32_t opcode);
@@ -909,16 +952,14 @@ template <field_rc rec>
void dppc_interpreter::ppc_fres(uint32_t opcode) {
ppc_grab_regsfpdb(opcode);
double start_num = GET_FPR(reg_b);
double start_num = GET_FPR(reg_b);
double ppc_dblresult64_d = (float)(1.0 / start_num);
if (start_num == 0.0) {
ppc_state.fpscr |= FPSCR::ZX;
}
else if (std::isnan(start_num)) {
} else if (std::isnan(start_num)) {
ppc_state.fpscr |= FPSCR::VXSNAN;
}
else if (std::isinf(start_num)){
} else if (std::isinf(start_num)) {
ppc_state.fpscr &= 0xFFF9FFFF;
ppc_state.fpscr |= FPSCR::VXSNAN;
}
@@ -932,6 +973,8 @@ void dppc_interpreter::ppc_fres(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fres<RC0>(uint32_t opcode);
@@ -945,22 +988,21 @@ static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
if (check_snan(reg_b)) // issnan
if (check_snan(reg_b)) // issnan
ppc_state.fpscr |= FPSCR::VXSNAN;
if (ppc_state.fpscr & FPSCR::VE) {
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_floating_point_exception(opcode);
} else {
ppc_store_fpresult_int(reg_d, 0xFFF8000080000000ULL);
}
} else if (val_reg_b > static_cast<double>(0x7fffffff) ||
val_reg_b < -static_cast<double>(0x80000000)) {
} else if (val_reg_b > static_cast<double>(0x7fffffff) || val_reg_b < -static_cast<double>(0x80000000)) {
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
if (ppc_state.fpscr & FPSCR::VE) {
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_floating_point_exception(opcode);
} else {
if (val_reg_b >= 0.0f)
@@ -997,6 +1039,7 @@ static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
template <field_rc rec>
void dppc_interpreter::ppc_fctiw(uint32_t opcode) {
round_to_int(opcode, ppc_state.fpscr & 0x3, rec);
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fctiw<RC0>(uint32_t opcode);
@@ -1005,6 +1048,7 @@ template void dppc_interpreter::ppc_fctiw<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_fctiwz(uint32_t opcode) {
round_to_int(opcode, 1, rec);
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fctiwz<RC0>(uint32_t opcode);
@@ -1018,6 +1062,7 @@ void dppc_interpreter::ppc_lfs(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
@@ -1029,32 +1074,34 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfsx(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfd(uint32_t opcode) {
@@ -1063,6 +1110,7 @@ void dppc_interpreter::ppc_lfd(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
@@ -1074,31 +1122,35 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfdx(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfs(uint32_t opcode) {
@@ -1107,6 +1159,7 @@ void dppc_interpreter::ppc_stfs(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
@@ -1118,31 +1171,36 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfsx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfd(uint32_t opcode) {
@@ -1150,6 +1208,7 @@ void dppc_interpreter::ppc_stfd(uint32_t opcode) {
uint32_t ea = int32_t(int16_t(opcode));
ea += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
@@ -1160,16 +1219,19 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
ea += val_reg_a;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfdx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
@@ -1179,16 +1241,19 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
uint32_t ea = val_reg_a + val_reg_b;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_store_iresult_reg(reg_a, ea);
}
else {
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfiwx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint32_t>(opcode, ea, uint32_t(FPR_INT(reg_s)));
ppc_next_instruction();
}
// Floating Point Register Transfer
@@ -1200,6 +1265,8 @@ void dppc_interpreter::ppc_fmr(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmr<RC0>(uint32_t opcode);
@@ -1209,10 +1276,13 @@ template <field_601 for601, field_rc rec>
void dppc_interpreter::ppc_mffs(uint32_t opcode) {
int reg_d = (opcode >> 21) & 31;
ppc_store_fpresult_int(reg_d, uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL));
ppc_store_fpresult_int(
reg_d, uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL));
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mffs<NOT601, RC0>(uint32_t opcode);
@@ -1227,17 +1297,25 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
uint32_t cr_mask = 0;
if (fm == 0xFFU) // the fast case
if (fm == 0xFFU) // the fast case
cr_mask = 0xFFFFFFFFUL;
else { // the slow case
if (fm & 0x80) cr_mask |= 0xF0000000UL;
if (fm & 0x40) cr_mask |= 0x0F000000UL;
if (fm & 0x20) cr_mask |= 0x00F00000UL;
if (fm & 0x10) cr_mask |= 0x000F0000UL;
if (fm & 0x08) cr_mask |= 0x0000F000UL;
if (fm & 0x04) cr_mask |= 0x00000F00UL;
if (fm & 0x02) cr_mask |= 0x000000F0UL;
if (fm & 0x01) cr_mask |= 0x0000000FUL;
else { // the slow case
if (fm & 0x80)
cr_mask |= 0xF0000000UL;
if (fm & 0x40)
cr_mask |= 0x0F000000UL;
if (fm & 0x20)
cr_mask |= 0x00F00000UL;
if (fm & 0x10)
cr_mask |= 0x000F0000UL;
if (fm & 0x08)
cr_mask |= 0x0000F000UL;
if (fm & 0x04)
cr_mask |= 0x00000F00UL;
if (fm & 0x02)
cr_mask |= 0x000000F0UL;
if (fm & 0x01)
cr_mask |= 0x0000000FUL;
}
// ensure neither FEX nor VX will be changed
@@ -1248,6 +1326,8 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsf<RC0>(uint32_t opcode);
@@ -1270,6 +1350,8 @@ void dppc_interpreter::ppc_mtfsfi(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsfi<RC0>(uint32_t opcode);
@@ -1278,12 +1360,14 @@ template void dppc_interpreter::ppc_mtfsfi<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F;
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
}
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsb0<RC0>(uint32_t opcode);
@@ -1292,12 +1376,14 @@ template void dppc_interpreter::ppc_mtfsb0<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F;
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
ppc_state.fpscr |= (0x80000000UL >> crf_d);
}
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsb1<RC0>(uint32_t opcode);
@@ -1306,18 +1392,18 @@ template void dppc_interpreter::ppc_mtfsb1<RC1>(uint32_t opcode);
void dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1C;
int crf_s = (opcode >> 16) & 0x1C;
ppc_state.cr = (
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
);
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
// keep only the FPSCR bits that can be explicitly cleared
FPSCR::FX | FPSCR::OX |
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
));
ppc_state.cr =
((ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d));
ppc_state.fpscr &= ~(
(0xF0000000UL >> crf_s) &
(
// keep only the FPSCR bits that can be explicitly cleared
FPSCR::FX | FPSCR::OX | FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ | FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI));
ppc_next_instruction();
}
// Floating Point Comparisons
@@ -1336,20 +1422,19 @@ void dppc_interpreter::ppc_fcmpo(uint32_t opcode) {
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
ppc_state.fpscr |= VXVC;
}
}
else if (db_test_a < db_test_b) {
} else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
}
else if (db_test_a > db_test_b) {
} else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
}
else {
} else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
ppc_state.fpscr &= ~VE; // kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
ppc_next_instruction();
}
void dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
@@ -1362,18 +1447,17 @@ void dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
if (check_snan(reg_a) || check_snan(reg_b)) {
ppc_state.fpscr |= FX | VX | VXSNAN;
}
}
else if (db_test_a < db_test_b) {
} else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
}
else if (db_test_a > db_test_b) {
} else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
}
else {
} else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.fpscr &= ~VE; // kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
ppc_next_instruction();
}
+28 -80
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -311,7 +311,6 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
uint32_t dev_base = 0;
bool is_writable;
AddressMapEntry *cur_dma_rgn;
AddressMapEntry *next_dma_rgn;
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
if (!cur_dma_rgn) {
@@ -321,44 +320,9 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
}
if (addr + size - 1 > cur_dma_rgn->end) {
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
cur_dma_rgn->start, cur_dma_rgn->end,
uint64_t(cur_dma_rgn->mem_ptr),
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
);
else
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
cur_dma_rgn->start, cur_dma_rgn->end
);
next_dma_rgn = mem_ctrl_instance->find_range(cur_dma_rgn->end + 1);
if (next_dma_rgn) {
if (next_dma_rgn->type & (RT_ROM | RT_RAM))
LOG_F(WARNING, "next region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
next_dma_rgn->start, next_dma_rgn->end,
uint64_t(next_dma_rgn->mem_ptr),
uint64_t(next_dma_rgn->mem_ptr + next_dma_rgn->end - next_dma_rgn->start)
);
else
LOG_F(ERROR, "next region: 0x%08X..0x%08X",
next_dma_rgn->start, next_dma_rgn->end
);
}
if (next_dma_rgn &&
(cur_dma_rgn->type & (RT_ROM | RT_RAM)) &&
((cur_dma_rgn->type & (RT_ROM | RT_RAM)) == (next_dma_rgn->type & (RT_ROM | RT_RAM))) &&
(next_dma_rgn->mem_ptr == cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start + 1) &&
(addr + size - 1 <= next_dma_rgn->end)
) {
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
" The regions are the same type and adjacent in host and guest spaces.",
addr, addr + size - 1
);
} else {
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
addr, addr + size - 1
);
}
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!",
addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end
);
}
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {
@@ -421,9 +385,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurITLBMode != mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
switch(mmu_mode) {
case 0: // real address mode
pCurITLB1 = &itlb1_mode1[0];
pCurITLB2 = &itlb2_mode1[0];
@@ -432,6 +394,10 @@ void mmu_change_mode()
pCurITLB1 = &itlb1_mode2[0];
pCurITLB2 = &itlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
//LOG_F(ERROR, "instruction mmu mode 1 is invalid!"); // this happens alot. Maybe it's not invalid?
mmu_mode = 3;
case 3: // user mode with instruction translation enabled
pCurITLB1 = &itlb1_mode3[0];
pCurITLB2 = &itlb2_mode3[0];
@@ -444,9 +410,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurDTLBMode != mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
switch(mmu_mode) {
case 0: // real address mode
pCurDTLB1 = &dtlb1_mode1[0];
pCurDTLB2 = &dtlb2_mode1[0];
@@ -455,6 +419,10 @@ void mmu_change_mode()
pCurDTLB1 = &dtlb1_mode2[0];
pCurDTLB2 = &dtlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
LOG_F(ERROR, "data mmu mode 1 is invalid!");
mmu_mode = 3;
case 3: // user mode with data translation enabled
pCurDTLB1 = &dtlb1_mode3[0];
pCurDTLB2 = &dtlb2_mode3[0];
@@ -782,9 +750,9 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
{
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) {
if (tlb_entry->tag == tag) {
tlb_entry->tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", tag);
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
}
}
@@ -792,16 +760,16 @@ static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &
{
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) {
if (tlb_entry[i].tag == tag) {
tlb_entry[i].tag = TLB_INVALID_TAG;
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", tag);
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
}
}
}
void tlb_flush_entry(uint32_t ea)
{
const uint32_t tag = ea & TLB_VPS_MASK;
const uint32_t tag = ea & ~0xFFFUL;
tlb_flush_primary_entry(itlb1_mode1, tag);
tlb_flush_secondary_entry(itlb2_mode1, tag);
tlb_flush_primary_entry(itlb1_mode2, tag);
@@ -951,11 +919,6 @@ static void mpc601_bat_update(uint32_t bat_reg)
}
}
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
{
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
static void ppc_ibat_update(uint32_t bat_reg)
{
int upper_reg_num;
@@ -1004,6 +967,7 @@ static void ppc_dbat_update(uint32_t bat_reg)
gTLBFlushDPatEntries = true;
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
}
}
void mmu_pat_ctx_changed()
@@ -1344,7 +1308,7 @@ template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint
class MMUProfile : public BaseProfile {
public:
MMUProfile() : BaseProfile("PPC_MMU") {}
MMUProfile() : BaseProfile("PPC_MMU") {};
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1392,7 +1356,7 @@ public:
vars.push_back({.name = "Unaligned Crosspage Writes Total",
.format = ProfileVarFmt::DEC,
.value = unaligned_crossp_w});
}
};
void reset() {
dmem_reads_total = 0;
@@ -1406,7 +1370,7 @@ public:
unaligned_writes = 0;
unaligned_crossp_r = 0;
unaligned_crossp_w = 0;
}
};
};
#endif
@@ -1418,7 +1382,7 @@ public:
class TLBProfile : public BaseProfile {
public:
TLBProfile() : BaseProfile("PPC:MMU:TLB") {}
TLBProfile() : BaseProfile("PPC:MMU:TLB") {};
void populate_variables(std::vector<ProfileVar>& vars) {
vars.clear();
@@ -1450,14 +1414,14 @@ public:
vars.push_back({.name = "Number of replaced TLB entries",
.format = ProfileVarFmt::DEC,
.value = num_entry_replacements});
}
};
void reset() {
num_primary_dtlb_hits = 0;
num_secondary_dtlb_hits = 0;
num_dtlb_refills = 0;
num_entry_replacements = 0;
}
};
};
#endif
@@ -1487,8 +1451,7 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
default:
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
}
}
catch (std::invalid_argument& exc) {
} catch (std::invalid_argument& exc) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
@@ -1497,15 +1460,6 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
/* rethrow MMU exception */
throw exc;
}
catch (...) {
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
/* rethrow MMU exception */
throw(false);
}
/* restore MMU-related CPU state */
mmu_exception_handler = ppc_exception_handler;
@@ -1599,12 +1553,7 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
guest_pa = tlb1_entry->phys_tag | (guest_va & 0xFFFUL);
is_mapped = true;
} while (0);
}
catch (std::invalid_argument& exc) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
catch (...) {
} catch (std::invalid_argument& exc) {
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
is_mapped = false;
}
@@ -1642,7 +1591,6 @@ void ppc_mmu_init()
if (is_601) {
// use 601-style unified BATs
ibat_update = &mpc601_bat_update;
dbat_update = &mpc601_dbat_update;
} else {
// use PPC-style BATs
ibat_update = &ppc_ibat_update;
-1
View File
@@ -87,7 +87,6 @@ constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
typedef struct TLBEntry {
uint32_t tag;
+311 -268
View File
File diff suppressed because it is too large. Load diff
-4
View File
@@ -313,10 +313,6 @@ def gen_rot_opcode(opc_str, sh, mb, me):
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWINM.":
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1) + 1
elif opc_str == "RLWNM":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1)
elif opc_str == "RLWNM.":
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1) + 1
def extract_imm(line):
pos = 12
+5 -9
View File
@@ -46,7 +46,7 @@ void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++;
@@ -150,7 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
ntested++;
@@ -292,7 +292,7 @@ static void read_test_float_data() {
ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
ntested++;
@@ -302,11 +302,10 @@ static void read_test_float_data() {
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x"
<< hex << check_cr << endl;
<< hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -319,9 +318,6 @@ static void read_test_float_data() {
int main() {
is_601 = true;
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+1 -1
View File
@@ -73,7 +73,7 @@ static vector<PPCDisasmContext> read_test_data() {
/* put instruction mnemonic padded with trailing spaces */
idisasm << tokens[2];
idisasm << setw(streamsize(8) - (int)tokens[2].length()) << " ";
idisasm << setw(8 - (int)tokens[2].length()) << " ";
/* now add comma-separated operands */
for (i = 3; i < tokens.size(); i++) {
+1 -2
View File
@@ -2,7 +2,6 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(debugger OBJECT ${SOURCES})
+76 -214
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -51,15 +51,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define COUTX uppercase << hex
#define COUT0_X(w) setfill('0') << setw(w) << right << COUTX
#define COUT016X COUT0_X(16)
#define COUT08X COUT0_X(8)
#define COUT04X COUT0_X(4)
static uint32_t str2addr(string& addr_str) {
try {
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
return (uint32_t)stoul(addr_str, NULL, 0);
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + addr_str);
}
@@ -67,7 +61,7 @@ static uint32_t str2addr(string& addr_str) {
static uint32_t str2num(string& num_str) {
try {
return static_cast<uint32_t>(stol(num_str, NULL, 0));
return (uint32_t)stol(num_str, NULL, 0);
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + num_str);
}
@@ -75,49 +69,41 @@ static uint32_t str2num(string& num_str) {
static void show_help() {
cout << "Debugger commands:" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GPRs" << endl;
cout << " fregs -- dump content of the FPRs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " setmem X=V.T -- set memory at address X to value V of size T" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " regions -- dump memory regions" << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GRPs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
#ifdef PROFILER
cout << " profiler -- show stats related to the processor" << endl;
cout << " profiler -- show stats related to the processor" << endl;
#endif
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
#ifdef ENABLE_68K_DEBUGGER
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
#endif
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << " quit -- quit the debugger" << endl << endl;
cout << "Pressing ENTER will repeat last command." << endl;
}
@@ -125,7 +111,7 @@ static void show_help() {
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle;
uint8_t code[12]{};
uint8_t code[10];
size_t code_size;
uint64_t dis_addr;
@@ -137,14 +123,9 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cs_insn* insn = cs_malloc(cs_handle);
for (; power_on && count > 0; count--) {
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
for (int i = 0; i < sizeof(code); i++) {
try {
code[i] = mem_read_dbg(address + i, 1);
}
catch(...) {
printf("<memerror>");
}
code[i] = mem_read_dbg(address + i, 1);
}
const uint8_t *code_ptr = code;
@@ -158,16 +139,16 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
}
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
cout << COUTX << insn->address << " ";
cout << uppercase << hex << insn->address << " ";
cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << right << endl;
address = static_cast<uint32_t>(dis_addr);
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
address = dis_addr;
} else {
print_bin:
cout << COUTX << address << " ";
cout << uppercase << hex << address << " ";
cout << setfill(' ');
cout << setw(10) << left << "dc.w" << "$" << hex <<
((code[0] << 8) | code[1]) << right << endl;
((code[0] << 8) | code[1]) << endl;
address += 2;
}
}
@@ -178,7 +159,7 @@ print_bin:
}
/* emulator opcode table size --> 512 KB */
constexpr auto EMU_68K_TABLE_SIZE = 0x80000;
#define EMU_68K_TABLE_SIZE 0x80000
/** Execute one emulated 68k instruction. */
void exec_single_68k()
@@ -187,7 +168,7 @@ void exec_single_68k()
/* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */
cur_68k_pc = static_cast<uint32_t>(get_reg(string("R24")) - 2);
cur_68k_pc = get_reg(string("R24")) - 2;
/* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
@@ -197,7 +178,7 @@ void exec_single_68k()
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(NO_OPCODE, cur_68k_pc) * 8 + emu_table_virt;
/* grab the PPC PC too */
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
ppc_pc = get_reg(string("PC"));
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
@@ -206,7 +187,7 @@ void exec_single_68k()
one by one until the execution goes outside the opcode table. */
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single();
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
ppc_pc = get_reg(string("PC"));
}
/* Getting here means we're outside the emualtor opcode table.
@@ -239,22 +220,21 @@ void print_68k_regs()
for (i = 0; i < 8; i++) {
reg = "R" + to_string(i + 8);
cout << " D" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
}
for (i = 0; i < 7; i++) {
reg = "R" + to_string(i + 16);
cout << " A" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
}
cout << " A7 : " << COUT08X << get_reg(string("R1")) << endl;
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
cout << " PC : " << COUT08X << get_reg(string("R24")) - 2 << endl;
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
cout << " SR : " << COUT08X << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << " CCR : " << COUT08X << get_reg(string("R26")) << endl;
cout << dec << setfill(' ');
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
}
#endif // ENABLE_68K_DEBUGGER
@@ -340,7 +320,8 @@ static void dump_mem(string& params) {
cout << (char)val;
chars_per_line += cell_size;
} else {
cout << COUT0_X(cell_size * 2) << val << " ";
cout << setw(cell_size * 2) << setfill('0') << right;
cout << uppercase << hex << val << " ";
chars_per_line += cell_size * 2 + 2;
}
}
@@ -352,79 +333,6 @@ static void dump_mem(string& params) {
cout << endl << endl;
}
static void patch_mem(string& params) {
int value_size = 1;
uint32_t addr, value;
string addr_str, value_str, size_str;
if (params.find_first_of("=") == std::string::npos) {
cout << "setmem: not enough arguments specified. Try 'help'." << endl;
return;
}
addr_str = params.substr(0, params.find_first_of("="));
value_str = params.substr(params.find_first_of("=") + 1);
if (value_str.find_first_of(".") == std::string::npos) {
cout << "setmem: no value size specified. Try 'help'." << endl;
return;
}
size_str = value_str.substr(value_str.find_first_of(".") + 1);
value_str = value_str.substr(0, value_str.find_first_of("."));
switch (size_str.back()) {
case 'b':
case 'B':
value_size = 1;
break;
case 'w':
case 'W':
value_size = 2;
break;
case 'd':
case 'D':
value_size = 4;
break;
case 'q':
case 'Q':
value_size = 8;
break;
case 'c':
case 'C':
value_size = 1;
break;
default:
cout << "Invalid value size " << size_str << endl;
return;
}
try {
addr = str2addr(addr_str);
} catch (invalid_argument& exc) {
try {
// number conversion failed, trying reg name
addr = get_reg(addr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
}
try {
value = str2num(value_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
return;
}
try {
mem_write_dbg(addr, value, value_size);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
}
static uint32_t disasm(uint32_t count, uint32_t address) {
PPCDisasmContext ctx;
@@ -433,9 +341,9 @@ static uint32_t disasm(uint32_t count, uint32_t address) {
for (int i = 0; power_on && i < count; i++) {
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
cout << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_addr;
cout << ": " << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << endl;
}
return ctx.instr_addr;
}
@@ -445,10 +353,10 @@ static void print_gprs() {
int i;
for (i = 0; i < 32; i++) {
reg_name = "r" + to_string(i);
reg_name = "R" + to_string(i);
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
COUT08X << get_reg(reg_name) << setfill(' ');
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -457,11 +365,11 @@ static void print_gprs() {
}
}
array<string, 8> sprs = {"pc", "lr", "cr", "ctr", "xer", "msr", "srr0", "srr1"};
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
for (auto &spr : sprs) {
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
COUT08X << get_reg(spr) << setfill(' ');
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
if (i & 1) {
cout << endl;
@@ -473,46 +381,34 @@ static void print_gprs() {
}
}
static void print_fprs() {
string reg_name;
for (int i = 0; i < 32; i++) {
reg_name = "f" + to_string(i);
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
COUT016X << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601;
static void print_mmu_regs()
{
printf(" msr : %08X\n", ppc_state.msr);
printf("MSR : 0x%08X\n", ppc_state.msr);
printf("\nBAT registers:\n");
for (int i = 0; i < 4; i++) {
printf(" ibat%du : %08X ibat%dl : %08X\n",
printf("IBAT%dU : 0x%08X, IBAT%dL : 0x%08X\n",
i, ppc_state.spr[528+i*2],
i, ppc_state.spr[529+i*2]);
}
if (!is_601) {
for (int i = 0; i < 4; i++) {
printf(" dbat%du : %08X dbat%dl : %08X\n",
printf("DBAT%dU : 0x%08X, DBAT%dL : 0x%08X\n",
i, ppc_state.spr[536+i*2],
i, ppc_state.spr[537+i*2]);
}
}
printf("\n");
printf(" sdr1 : %08X\n", ppc_state.spr[SPR::SDR1]);
printf("SDR1 : 0x%08X\n", ppc_state.spr[SPR::SDR1]);
printf("\nSegment registers:\n");
for (int i = 0; i < 16; i++) {
printf(" %ssr%d : %08X\n", (i < 10) ? " " : "", i, ppc_state.sr[i]);
printf("SR%-2d : 0x%08X\n", i, ppc_state.sr[i]);
}
}
@@ -567,7 +463,6 @@ void DppcDebugger::enter_debugger() {
uint32_t next_addr_68k;
#endif
bool cmd_repeat;
int repeat_count = 0;
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
@@ -575,7 +470,7 @@ void DppcDebugger::enter_debugger() {
#ifndef _WIN32
struct winsize win_size_previous;
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_previous);
ioctl(0, TIOCGWINSZ, &win_size_previous);
#endif
while (1) {
@@ -614,7 +509,6 @@ void DppcDebugger::enter_debugger() {
power_off_reason = po_entered_debugger;
}
if (!did_message) {
cout << endl;
cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl;
did_message = true;
@@ -635,7 +529,7 @@ void DppcDebugger::enter_debugger() {
#ifndef _WIN32
struct winsize win_size_current;
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_current);
ioctl(0, TIOCGWINSZ, &win_size_current);
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
win_size_previous = win_size_current;
if (cmd.empty()) {
@@ -662,10 +556,6 @@ void DppcDebugger::enter_debugger() {
cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) {
cmd = last_cmd;
repeat_count++;
}
else {
repeat_count = 1;
}
if (cmd == "help") {
cmd = "";
@@ -673,10 +563,6 @@ void DppcDebugger::enter_debugger() {
} else if (cmd == "quit") {
cmd = "";
break;
} else if (cmd == "restart") {
cmd = "";
power_on = false;
power_off_reason = po_restart;
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
@@ -699,9 +585,6 @@ void DppcDebugger::enter_debugger() {
} else {
print_gprs();
}
} else if (cmd == "fregs") {
cmd = "";
print_fprs();
} else if (cmd == "mregs") {
cmd = "";
print_mmu_regs();
@@ -761,22 +644,15 @@ void DppcDebugger::enter_debugger() {
delete_prompt();
}
for (; --count >= 0;) {
addr = ppc_state.pc;
ppc_exec_single();
}
}
} else if (cmd == "next" || cmd == "ni") {
addr_str = "PC";
addr = static_cast<uint32_t>(get_reg(addr_str) + 4);
addr = (uint32_t)get_reg(addr_str) + 4;
ppc_exec_until(addr);
} else if (cmd == "until") {
if (cmd_repeat) {
delete_prompt();
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
}
else {
ss >> addr_str;
}
ss >> addr_str;
try {
addr = str2addr(addr_str);
if (context == 2) {
@@ -850,7 +726,7 @@ void DppcDebugger::enter_debugger() {
}
else {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
addr = get_reg(addr_str) - 2;
}
next_addr_68k = disasm_68k(1, addr);
#endif
@@ -861,7 +737,7 @@ void DppcDebugger::enter_debugger() {
}
else {
addr_str = "PC";
addr = static_cast<uint32_t>(get_reg(addr_str));
addr = (uint32_t)get_reg(addr_str);
}
next_addr_ppc = disasm(1, addr);
}
@@ -873,10 +749,6 @@ void DppcDebugger::enter_debugger() {
expr_str = "";
ss >> expr_str;
dump_mem(expr_str);
} else if (cmd == "setmem") {
expr_str = "";
ss >> expr_str;
patch_mem(expr_str);
#ifdef ENABLE_68K_DEBUGGER
} else if (cmd == "context") {
cmd = "";
@@ -890,10 +762,6 @@ void DppcDebugger::enter_debugger() {
cout << "Unknown debugging context: " << expr_str << endl;
}
#endif
} else if (cmd == "regions") {
cmd = "";
if (mem_ctrl_instance)
mem_ctrl_instance->dump_regions();
} else if (cmd == "printenv") {
cmd = "";
if (ofnvram->init())
@@ -905,15 +773,9 @@ void DppcDebugger::enter_debugger() {
ss >> var_name;
std::istream::sentry se(ss); // skip white space
getline(ss, value); // get everything up to eol
if (ofnvram->init()) {
cout << " Cannot open NVRAM" << endl;
if (ofnvram->init())
continue;
}
if (!ofnvram->setenv(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
ofnvram->setenv(var_name, value);
#ifndef _WIN32
} else if (cmd == "nvedit") {
cmd = "";
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,7 +31,7 @@ public:
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
}
};
void enter_debugger();
+4 -6
View File
@@ -8,14 +8,10 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
@@ -26,10 +22,12 @@ platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
+1 -1
View File
@@ -94,7 +94,7 @@ void AdbAppleJack::set_register_3() {
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}, HWCompType::ADB_DEV
AdbAppleJack::create, {}, {}
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
+1 -1
View File
@@ -133,7 +133,7 @@ static const PropMap AdbBus_Properties = {
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, AdbBus_Properties, HWCompType::ADB_HOST
AdbBus::create, {}, AdbBus_Properties
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+8 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <vector>
constexpr auto ADB_MAX_DATA_SIZE = 8;
#define ADB_MAX_DATA_SIZE 8
/** ADB status. */
enum {
@@ -55,7 +55,7 @@ public:
void register_device(AdbDevice* dev_obj);
uint8_t process_command(const uint8_t* in_data, int data_size);
uint8_t get_output_count() { return this->output_count; }
uint8_t get_output_count() { return this->output_count; };
// Polls devices that have a service request flag set. Returns the talk
// command corresponding to the first device that responded with data, or
@@ -63,11 +63,11 @@ public:
uint8_t poll();
// callbacks meant to be called by devices
const uint8_t* get_input_buf() { return this->input_buf; }
uint8_t* get_output_buf() { return this->output_buf; }
uint8_t get_input_count() { return this->input_count; }
void set_output_count(uint8_t count) { this->output_count = count; }
bool already_answered() { return this->got_answer; }
const uint8_t* get_input_buf() { return this->input_buf; };
uint8_t* get_output_buf() { return this->output_buf; };
uint8_t get_input_count() { return this->input_count; };
void set_output_count(uint8_t count) { this->output_count = count; };
bool already_answered() { return this->got_answer; };
private:
std::vector<AdbDevice*> devices;
+3 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -37,7 +37,7 @@ int AdbDevice::device_postinit() {
this->host_obj->register_device(this);
return 0;
}
};
uint8_t AdbDevice::poll() {
if (!this->srq_flag) {
@@ -84,16 +84,12 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
switch(reg_num & 3) {
case 0:
this->set_register_0();
break;
case 1:
this->set_register_1();
break;
case 2:
this->set_register_2();
break;
case 3:
this->set_register_3();
break;
}
}
}
@@ -108,5 +104,5 @@ bool AdbDevice::get_register_3() {
}
uint8_t AdbDevice::gen_random_address() {
return TimerManager::get_instance()->current_time_ns() & 0xF;
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
}
+9 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,7 +47,7 @@ public:
virtual void reset() = 0;
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
virtual uint8_t get_address() { return this->my_addr; }
virtual uint8_t get_address() { return this->my_addr; };
// Attempts to poll the device. Returns the talk command corresponding to
// the device if it has data, 0 otherwise.
@@ -56,15 +56,15 @@ public:
protected:
uint8_t gen_random_address();
virtual bool get_register_0() { return false; }
virtual bool get_register_1() { return false; }
virtual bool get_register_2() { return false; }
virtual bool get_register_0() { return false; };
virtual bool get_register_1() { return false; };
virtual bool get_register_2() { return false; };
virtual bool get_register_3();
virtual void set_register_0() {}
virtual void set_register_1() {}
virtual void set_register_2() {}
virtual void set_register_3() {}
virtual void set_register_0() {};
virtual void set_register_1() {};
virtual void set_register_2() {};
virtual void set_register_3() {};
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
+1 -9
View File
@@ -77,14 +77,6 @@ uint8_t AdbKeyboard::consume_pending_event() {
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
}
if (this->dev_handler_id != 3) {
switch (event->key) {
case AdbKey_RightControl : event->key = AdbKey_Control; break;
case AdbKey_RightShift : event->key = AdbKey_Shift ; break;
case AdbKey_RightOption : event->key = AdbKey_Option ; break;
}
}
return (key_state << 7) | (event->key & 0x7F);
}
@@ -119,7 +111,7 @@ void AdbKeyboard::set_register_3() {
}
static const DeviceDescription AdbKeyboard_Descriptor = {
AdbKeyboard::create, {}, {}, HWCompType::ADB_DEV
AdbKeyboard::create, {}, {}
};
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
-4
View File
@@ -128,10 +128,6 @@ enum AdbKey {
AdbKey_Command = 0x37,
AdbKey_CapsLock = 0x39,
AdbKey_RightControl = 0x7d,
AdbKey_RightShift = 0x7b,
AdbKey_RightOption = 0x7c,
AdbKey_ArrowUp = 0x3e,
AdbKey_ArrowDown = 0x3d,
AdbKey_ArrowLeft = 0x3b,
+12 -16
View File
@@ -29,9 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution
) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution)
{
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution) {
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset();
@@ -75,19 +73,10 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
int num_bits, total_bits;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
num_bits = total_bits = 7;
} else {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
uint8_t buttons_state = ~this->buttons_state;
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
int bits = this->num_bits;
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
: this->device_class == TABLET ? this->y_abs : this->y_rel;
if (val < (-1 << (bits - 1)))
@@ -100,7 +89,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -115,6 +104,13 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
this->changed = false;
uint8_t count = (uint8_t)(p - out_buf);
// should never happen, but check just in case
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
count = UINT8_MAX;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1)
count = 2;
this->host_obj->set_output_count(count);
return should_update;
}
@@ -172,7 +168,7 @@ uint8_t AdbMouse::get_buttons_state() const {
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}, HWCompType::ADB_DEV
AdbMouse::create, {}, {}
};
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
+4 -16
View File
@@ -27,7 +27,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
#include <cinttypes>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -76,8 +75,7 @@ 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); });
this->update_intrq(1);
}
}
return ret_data;
@@ -119,18 +117,12 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
if (this->xfer_cnt <= 0) { // transfer complete?
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);
});
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();
});
this->signal_data_ready();
}
}
}
@@ -154,10 +146,6 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
this->r_dev_head = value;
break;
case ATA_Reg::COMMAND:
if ((this->r_status & BSY) != 0) {
LOG_F(ERROR, "%s: tried to perform command %x when busy", name.c_str(), value);
break;
}
this->r_command = value;
if (is_selected() || this->r_command == DIAGNOSTICS) {
perform_command();
+7 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -43,18 +43,18 @@ public:
void set_host(IdeChannel* host, uint8_t dev_id) {
this->host_obj = host;
this->my_dev_id = dev_id;
}
};
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
virtual int perform_command() = 0;
int get_device_id() override { return this->my_dev_id; }
int get_device_id() override { return this->my_dev_id; };
void pdiag_callback() override {
this->r_error &= 0x7F;
}
};
virtual void device_reset(bool is_soft_reset);
virtual void device_set_signature();
@@ -62,7 +62,7 @@ public:
void update_intrq(uint8_t new_intrq_state);
void signal_data_ready();
bool has_data() const {
bool has_data() {
return data_ptr && xfer_cnt;
}
@@ -71,9 +71,7 @@ public:
}
protected:
bool is_selected() const {
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
}
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
void prepare_xfer(int xfer_size, int block_size);
@@ -84,7 +82,7 @@ protected:
IdeChannel* host_obj = nullptr;
// IDE aka task file registers
uint8_t r_error = 0;
uint8_t r_error;
uint8_t r_features;
uint8_t r_sect_count;
uint8_t r_sect_num;
+7 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -142,10 +142,8 @@ enum ATA_Cmd : uint8_t {
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
READ_DMA = 0xC8,
READ_DMA_NR = 0xC9,
WRITE_DMA = 0xCA,
WRITE_DMA_NR = 0xCB,
STANDBY_IMMEDIATE = 0xE0,
STANDBY_IMMEDIATE_E0 = 0xE0,
FLUSH_CACHE = 0xE7, // ATA-5
WRITE_BUFFER_DMA = 0xE9,
READ_BUFFER_DMA = 0xEB,
@@ -153,7 +151,7 @@ enum ATA_Cmd : uint8_t {
SET_FEATURES = 0xEF,
};
} // namespace ata_interface
}; // namespace ata_interface
/** Interface for ATA devices. */
class AtaInterface {
@@ -164,7 +162,7 @@ public:
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
virtual int get_device_id() = 0;
virtual void pdiag_callback() {}
virtual void pdiag_callback() {};
};
/** Dummy ATA device. */
@@ -180,12 +178,12 @@ public:
// to prevent the software from waiting for a long time
// for empty slots
return 0xFF7FU;
}
};
void write(const uint8_t reg_addr, const uint16_t val) override {}
void write(const uint8_t reg_addr, const uint16_t val) override {};
// invalid device ID means no real device is present
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; }
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
};
#endif // ATA_INTERFACE_H
+10 -21
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -191,11 +191,7 @@ int AtaHardDisk::perform_command() {
this->signal_data_ready();
break;
case SET_FEATURES:
switch (this->r_features) {
case 2:
LOG_F(INFO, "%s: write cache enabled", this->name.c_str());
break;
case 3:
if (this->r_features == 3) {
switch(this->r_sect_count >> 3) {
case 0:
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
@@ -205,9 +201,8 @@ int AtaHardDisk::perform_command() {
this->r_sect_count & 7);
break;
case 4:
this->cur_dma_mode = this->r_sect_count & 7;
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
this->cur_dma_mode);
this->r_sect_count & 7);
break;
default:
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
@@ -215,19 +210,15 @@ int AtaHardDisk::perform_command() {
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
break;
case 0xAA:
LOG_F(INFO, "%s: read look-ahead enabled", this->name.c_str());
break;
default:
} else {
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
this->name.c_str(), this->r_features);
}
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case STANDBY_IMMEDIATE:
LOG_F(INFO, "%s: immediate standby requested", this->name.c_str());
case STANDBY_IMMEDIATE_E0:
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
this->r_status &= ~BSY;
this->update_intrq(1);
break;
@@ -268,14 +259,12 @@ void AtaHardDisk::prepare_identify_info() {
// report LBA capacity
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
}
uint64_t AtaHardDisk::get_lba() {
if (this->r_dev_head & ATA_Dev_Head::LBA) {
return uint64_t(((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num));
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
(this->r_cylinder_lo << 8) | (this->r_sect_num);
} else { // translate old fashioned CHS addressing to LBA
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
uint8_t h = this->r_dev_head & 0xF;
@@ -285,7 +274,7 @@ uint64_t AtaHardDisk::get_lba() {
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
return -1ULL;
} else
return uint64_t((this->heads * c + h) * this->sectors + s - 1);
return (this->heads * c + h) * this->sectors + s - 1;
}
}
@@ -342,7 +331,7 @@ static const PropMap AtaHardDisk_Properties = {
};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties, HWCompType::IDE_DEV
AtaHardDisk::create, {}, AtaHardDisk_Properties
};
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
+6 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,15 +29,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
constexpr auto ATA_HD_SEC_SIZE = 512;
constexpr auto SECTORS_PER_INT = 16;
#define ATA_HD_SEC_SIZE 512
#define SECTORS_PER_INT 16
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
constexpr auto ATA_BIOS_LIMIT = 16514064;
#define ATA_BIOS_LIMIT 16514064
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
constexpr auto REAL_CHS_LIMIT = 267382800;
#define REAL_CHS_LIMIT 267382800
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
constexpr auto CHS_LIMIT = 267386880;
#define CHS_LIMIT 267386880
class AtaHardDisk : public AtaBaseDevice
{
@@ -71,7 +71,6 @@ private:
uint8_t sectors;
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
char * buffer = new char[1 <<17];
};
+1
View File
@@ -87,6 +87,7 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
return this->r_dev_head;
case ATA_Reg::STATUS:
this->update_intrq(0);
return this->r_status;
case ATA_Reg::ALT_STATUS:
if (this->r_status & BSY && this->data_available()) {
this->r_byte_count = this->request_data();
+12 -65
View File
@@ -31,7 +31,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <string>
#include <core/timermanager.h>
using namespace ata_interface;
@@ -158,14 +157,6 @@ void AtapiCdrom::perform_packet_command() {
case ScsiCommand::READ_6:
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
xfer_len = this->cmd_pkt[4];
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -177,23 +168,8 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
break;
case ScsiCommand::READ_10:
if (this->xfer_cnt > 0) {
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -202,24 +178,11 @@ void AtapiCdrom::perform_packet_command() {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
#if 0
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
#else
this->data_out_phase();
#endif
this->data_out_phase();
break;
case ScsiCommand::READ_12:
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
@@ -240,18 +203,6 @@ void AtapiCdrom::perform_packet_command() {
{
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
// Treat as a non-data command.
xfer_len = 0;
}
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
this->name.c_str(),
@@ -290,8 +241,7 @@ void AtapiCdrom::perform_packet_command() {
else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block =
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
}
@@ -302,8 +252,7 @@ void AtapiCdrom::perform_packet_command() {
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog + (disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count
}
@@ -358,12 +307,11 @@ uint16_t AtapiCdrom::get_data() {
area_end += 4; // Header
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
uint8_t header[4];
header[0] = msf.min;
header[1] = msf.sec;
header[2] = msf.frm;
header[3] = 0x01; // Mode 1
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
@@ -434,12 +382,11 @@ void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->r_status |= ATA_Status::ERR;
}
static const PropMap AtapiCdrom_Properties = {
static const PropMap AtapiCdromProperties = {
{"cdr_img", new StrProperty("")},
};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties, HWCompType::IDE_DEV
};
static const DeviceDescription AtapiCdromDescriptor =
{AtapiCdrom::create, {}, AtapiCdromProperties};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -139,7 +139,7 @@ bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
return true;
}
};
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
+4 -4
View File
@@ -31,14 +31,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
constexpr auto DEV_ID_CMD646 = 0x646;
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master
constexpr auto MY_REV_ID = 7;
#define DEV_ID_CMD646 0x646
#define MY_DEV_CLASS 0x010180 // mass storage | IDE controller | IDE master
#define MY_REV_ID 7
// Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14;
#define DEV_CTRL_BLK_OFFSET 0x14
/** CMD646 control/status registers. */
enum {
+2 -2
View File
@@ -117,11 +117,11 @@ void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const in
}
static const DeviceDescription Ide0_Descriptor = {
MacioIdeChannel::create_first, {}, {}, HWCompType::IDE_BUS
MacioIdeChannel::create_first, {}, {}
};
static const DeviceDescription Ide1_Descriptor = {
MacioIdeChannel::create_second, {}, {}, HWCompType::IDE_BUS
MacioIdeChannel::create_second, {}, {}
};
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -74,7 +74,7 @@ private:
class MacioIdeChannel : public IdeChannel
{
public:
MacioIdeChannel(const std::string name) : IdeChannel(name) {}
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
~MacioIdeChannel() = default;
static std::unique_ptr<HWComponent> create_first() {
@@ -95,7 +95,7 @@ private:
// interrupt stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
};
#endif // IDE_CHANNEL_H
+3 -26
View File
@@ -88,7 +88,7 @@ uint8_t DMAChannel::interpret_cmd() {
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
break;
}
this->queue_len = cmd_struct.req_count;
this->queue_len = cmd_struct.req_count;
if (this->queue_len) {
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
this->queue_data = res.host_va;
@@ -427,13 +427,9 @@ void DMAChannel::xfer_from_device() {
this->xfer_dir = DMA_DIR_FROM_DEV;
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
this->queue_len = 0;
this->finish_cmd();
} else if (got_bytes) {
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
this->get_name().c_str());
}
this->interpret_cmd();
@@ -445,8 +441,7 @@ void DMAChannel::xfer_to_device() {
this->xfer_dir = DMA_DIR_TO_DEV;
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
if (!this->dev_obj->xfer_to(this->queue_data, this->queue_len)) {
this->queue_len = 0;
this->finish_cmd();
}
@@ -454,24 +449,6 @@ void DMAChannel::xfer_to_device() {
this->interpret_cmd();
}
void DMAChannel::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
}
bool DMAChannel::is_ready() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
return false;
return true;
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
+13 -16
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -99,7 +99,7 @@ namespace DBDMA_Cmd {
NOP = 6,
STOP = 7
};
}
};
typedef std::function<void(void)> DbdmaCallback;
@@ -114,22 +114,19 @@ public:
void reg_write(uint32_t offset, uint32_t value, int size);
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
bool is_out_active() override;
bool is_in_active() override;
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
int 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 is_out_active();
bool is_in_active();
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
int push_data(const char* src_ptr, int len);
int get_pull_data_remaining() { return this->queue_len; }
int get_push_data_remaining() { return this->queue_len; }
void end_pull_data();
void end_push_data();
bool is_ready() override;
void xfer_retry() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
this->int_ctrl = int_ctrl_obj;
this->irq_id = irq_id;
}
};
protected:
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
@@ -166,7 +163,7 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
};
#endif // DB_DMA_H
+19 -22
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,15 +35,15 @@ enum DmaPullResult : int {
class DmaOutChannel {
public:
DmaOutChannel(std::string name) { this->name = name; }
DmaOutChannel(std::string name) { this->name = name; };
virtual bool is_out_active() { return true; }
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() {}
virtual int get_pull_data_remaining() { return 1; };
virtual void end_pull_data() { };
std::string get_name(void) { return this->name; }
std::string get_name(void) { return this->name; };
private:
std::string name;
@@ -51,14 +51,14 @@ private:
class DmaInChannel {
public:
DmaInChannel(std::string name) { this->name = name; }
DmaInChannel(std::string name) { this->name = name; };
virtual bool is_in_active() { return true; }
virtual bool is_in_active() { return true; };
virtual int push_data(const char* src_ptr, int len) = 0;
virtual int get_push_data_remaining() { return 1; }
virtual void end_push_data() {}
virtual int get_push_data_remaining() { return 1; };
virtual void end_push_data() { };
std::string get_name(void) { return this->name; }
std::string get_name(void) { return this->name; };
private:
std::string name;
@@ -68,9 +68,9 @@ private:
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
public:
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
DmaInChannel(name + std::string(" In")) { this->name = name; }
DmaInChannel(name + std::string(" In")) { this->name = name; };
std::string get_name(void) { return this->name; }
std::string get_name(void) { return this->name; };
private:
std::string name;
@@ -96,11 +96,10 @@ public:
DmaDevice() = default;
~DmaDevice() = default;
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
virtual void notify(DmaMsg msg) {}
virtual int xfer_from(uint8_t *buf, int len) { return len; }
virtual int xfer_to(uint8_t *buf, int len) { return len; }
virtual int tell_xfer_size() { return 0; }
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
virtual int xfer_to(uint8_t *buf, int len) { return len; };
protected:
DmaChannel* channel_obj = nullptr;
@@ -111,10 +110,8 @@ public:
DmaChannel() = default;
~DmaChannel() = default;
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; }
virtual void notify(DmaMsg msg) {}
virtual bool is_ready() { return false; }
virtual void xfer_retry() {}
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
void notify(DmaMsg msg) {};
protected:
DmaDevice* dev_obj = nullptr;
+6 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,7 +35,6 @@ enum HWCompType : uint64_t {
MMIO_DEV = 1ULL << 4, // memory mapped I/O device
PCI_HOST = 1ULL << 5, // PCI host
PCI_DEV = 1ULL << 6, // PCI device
NUBUS_DEV = 1ULL << 7, // Nubus device
I2C_HOST = 1ULL << 8, // I2C host
I2C_DEV = 1ULL << 9, // I2C device
ADB_HOST = 1ULL << 12, // ADB host
@@ -54,7 +53,6 @@ enum HWCompType : uint64_t {
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
MACHINE = 1ULL << 41, // machine root
};
/** Base class for HW components. */
@@ -65,22 +63,22 @@ public:
virtual std::string get_name(void) {
return this->name;
}
};
virtual void set_name(std::string name) {
this->name = name;
}
};
virtual bool supports_type(HWCompType type) {
return !!(this->supported_types & type);
}
};
virtual void supports_types(uint64_t types) {
this->supported_types = types;
}
};
virtual int device_postinit() {
return 0;
}
};
protected:
std::string name;
+5 -18
View File
@@ -30,11 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enum IntSrc : uint32_t {
INT_UNKNOWN = 0,
VIA_CUDA,
VIA2,
SCSI_MESH,
SCSI_CURIO,
SWIM3,
ESCC,
SCCA,
SCCB,
ETHERNET,
@@ -60,7 +58,6 @@ enum IntSrc : uint32_t {
PLANB,
VCI,
PLATINUM,
DMA_ALL,
DMA_SCSI_MESH,
DMA_SCSI_CURIO,
DMA_SWIM3,
@@ -83,16 +80,6 @@ enum IntSrc : uint32_t {
USB,
PIPPIN_E,
PIPPIN_F,
ZIVA,
PCI_CARDBUS,
MEDIA_BAY,
SLOT_ALL,
SLOT_0,
SLOT_1,
SLOT_2,
SLOT_PDS,
SLOT_VDS,
VBL,
};
/** Base class for interrupt controllers. */
@@ -102,17 +89,17 @@ public:
virtual ~InterruptCtrl() = default;
// register interrupt sources for a device
virtual uint64_t register_dev_int(IntSrc src_id) = 0;
virtual uint64_t register_dma_int(IntSrc src_id) = 0;
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt
virtual void ack_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
};
typedef struct {
InterruptCtrl *int_ctrl_obj;
uint64_t irq_id;
uint32_t irq_id;
} IntDetails;
#endif // HW_INTERRUPT_H
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,15 +31,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters.
*/
#include <devices/common/clockgen/athens.h>
#include <devices/common/i2c/athens.h>
#include <loguru.hpp>
#include <algorithm>
#include <cinttypes>
#include <vector>
AthensClocks::AthensClocks(uint8_t dev_addr) : I2CDevice() {
AthensClocks::AthensClocks(uint8_t dev_addr)
{
set_name("Athens");
supports_types(HWCompType::I2C_DEV);
this->my_addr = dev_addr;
@@ -73,9 +75,10 @@ bool AthensClocks::send_subaddress(uint8_t sub_addr)
bool AthensClocks::send_byte(uint8_t data)
{
switch (this->pos++) {
switch (this->pos) {
case 0:
this->reg_num = data;
this->pos++;
break;
case 1:
if (this->reg_num >= ATHENS_NUM_REGS) {
@@ -87,7 +90,7 @@ bool AthensClocks::send_byte(uint8_t data)
break;
default:
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
//return false; // return NACK
return false; // return NACK
}
return true;
}
@@ -100,8 +103,6 @@ bool AthensClocks::receive_byte(uint8_t* p_data)
int AthensClocks::get_sys_freq()
{
LOG_F(ERROR, "%s: sys clock calculation not implemented yet", this->name.c_str());
return 0;
}
@@ -117,7 +118,7 @@ int AthensClocks::get_dot_freq()
return 0;
}
float out_freq = 50000000.0; // for 800x600 72Hz
float out_freq = 0.0f;
int d2 = this->regs[AthensRegs::D2];
int n2 = this->regs[AthensRegs::N2];
@@ -149,7 +150,7 @@ int AthensClocks::get_dot_freq()
break;
}
LOG_F(INFO, "%s: dot clock frequency set to %f MHz", this->name.c_str(), out_freq / 1000000.0);
LOG_F(INFO, "%s: dot clock frequency set to %f Hz", this->name.c_str(), out_freq);
return static_cast<int>(out_freq + 0.5f);
}
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,11 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATHENS_H
#define ATHENS_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
constexpr auto ATHENS_NUM_REGS = 8;
#define ATHENS_NUM_REGS 8
/** Default external crystal oscillator frequency. */
constexpr auto ATHENS_XTAL = 31334400.0f;
@@ -46,9 +47,10 @@ enum AthensRegs: uint8_t {
P1 = 7
};
} // namespace AthensRegs
}; // namespace AthensRegs
class AthensClocks : public I2CDevice {
class AthensClocks : public I2CDevice, public HWComponent
{
public:
AthensClocks(uint8_t dev_addr);
AthensClocks(uint8_t dev_addr, const float crystal_freq);
+12 -20
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -27,22 +27,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <devices/common/hwcomponent.h>
#include <stdexcept>
#include <cstring>
#include <string>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept>
#include <string>
/** Base class for I2C devices */
class I2CDevice : virtual public HWComponent {
class I2CDevice {
public:
I2CDevice() {
supports_types(HWCompType::I2C_DEV);
}
virtual ~I2CDevice() = default;
virtual void start_transaction() = 0;
virtual bool send_subaddress(uint8_t sub_addr) = 0;
virtual bool send_byte(uint8_t data) = 0;
@@ -50,11 +42,11 @@ public:
};
/** Base class for I2C hosts */
class I2CBus : virtual public HWComponent {
class I2CBus {
public:
I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
}
};
virtual ~I2CBus() = default;
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
@@ -63,7 +55,7 @@ public:
}
this->dev_list[dev_addr] = dev_obj;
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
}
};
virtual bool start_transaction(uint8_t dev_addr) {
if (this->dev_list[dev_addr]) {
@@ -72,28 +64,28 @@ public:
} else {
return false;
}
}
};
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
}
};
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->send_byte(data);
}
};
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
if (!this->dev_list[dev_addr]) {
return false; /* no device -> no acknowledge */
}
return this->dev_list[dev_addr]->receive_byte(p_data);
}
};
protected:
I2CDevice* dev_list[128]; /* list of registered I2C devices */
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -54,17 +54,17 @@ void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
void I2CProm::start_transaction() {
this->pos = 0;
}
};
bool I2CProm::send_subaddress(uint8_t sub_addr) {
this->pos = sub_addr;
return true;
}
};
bool I2CProm::send_byte(uint8_t data) {
LOG_F(9, "I2CRom: 0x%X received", data);
return true;
}
};
bool I2CProm::receive_byte(uint8_t* p_data) {
if (this->pos >= this->rom_size) {
@@ -72,4 +72,4 @@ bool I2CProm::receive_byte(uint8_t* p_data) {
}
*p_data = this->data[this->pos++];
return true;
}
};
+4 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,12 +24,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_PROM_H
#define I2C_PROM_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <cinttypes>
#include <memory>
class I2CProm : public I2CDevice {
class I2CProm : public I2CDevice, public HWComponent
{
public:
I2CProm(uint8_t dev_addr, int size);
~I2CProm() = default;
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,10 +21,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file SAA7187 Digital video encoder emulation. */
#include <devices/video/saa7187.h>
#include <devices/common/i2c/saa7187.h>
#include <loguru.hpp>
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr) : I2CDevice() {
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr)
{
supports_types(HWCompType::I2C_DEV);
this->my_addr = dev_addr;
}
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef SAA7187_H
#define SAA7187_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
namespace Saa7187Regs {
@@ -115,9 +116,10 @@ enum Saa7187Regs : uint8_t { // i2c address is 0x44; fatman is at 0x46?
last_reg = 0x7e,
};
} // namespace Saa7187Regs
}; // namespace Saa7187Regs
class Saa7187VideoEncoder : public I2CDevice {
class Saa7187VideoEncoder : public I2CDevice, public HWComponent
{
public:
Saa7187VideoEncoder(uint8_t dev_addr);
~Saa7187VideoEncoder() = default;
+13 -13
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,10 +40,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
Machine ID register for NuBus Power Macs.
Machine ID register for Nubus Power Macs.
It's located at physical address 0x5FFFFFFC and contains four bytes:
+0 uint16_t signature = 0xA55A
+1 uint8_t machine_type (0x30 - Power Mac)
+1 uint8_t machine_type (3 - Power Mac)
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
*/
class NubusMacID : public MMIODevice {
@@ -55,7 +55,7 @@ public:
this->id[2] = (id >> 8) & 0xFF;
this->id[3] = id & 0xFF;
supports_types(HWCompType::MMIO_DEV);
}
};
~NubusMacID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
@@ -67,10 +67,10 @@ public:
}
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
return 0;
}
};
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
private:
uint8_t id[4];
@@ -88,19 +88,19 @@ public:
this->set_name(name);
supports_types(HWCompType::IOBUS_DEV);
this->data = data;
}
};
~BoardRegister() = default;
uint16_t iodev_read(uint32_t address) {
return this->data;
}
};
// appears read-only to guest
void iodev_write(uint32_t address, uint16_t value) {}
void iodev_write(uint32_t address, uint16_t value) {};
void update_bits(const uint16_t val, const uint16_t mask) {
this->data = (this->data & ~mask) | (val & mask);
}
};
private:
uint16_t data;
@@ -118,15 +118,15 @@ public:
this->id = id;
this->name = "Machine-id";
supports_types(HWCompType::MMIO_DEV);
}
};
~GossamerID() = default;
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
return ((offset == 4 && size == 2) ? this->id : 0);
}
};
/* not writable */
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
private:
uint16_t id;
-156
View File
@@ -1,156 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
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/>.
*/
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <fstream>
#include <sstream>
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
{
uint32_t sum = 0;
for (int i = 0; i < length; i++) {
// rotate sum left by one bit
if (sum & 0x80000000UL)
sum = (sum << 1) | 1;
else
sum = (sum << 1) | 0;
sum += data_ptr[i];
}
return sum;
}
int load_declaration_rom(const std::string rom_path, int slot_num)
{
std::ifstream rom_file;
int result = 0;
try {
rom_file.open(rom_path, std::ios::in | std::ios::binary);
if (rom_file.fail())
throw std::runtime_error("could not open declaration ROM image " + rom_path);
// determine image size
rom_file.seekg(0, std::ios::end);
uint64_t rom_size = rom_file.tellg();
if (rom_size > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// load it
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
rom_file.seekg(0, std::ios::beg);
rom_file.read((char *)rom_data.get(), rom_size);
// verify image data
uint8_t byte_lane = rom_data[rom_size - 1];
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF))
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid byte lane value");
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL)
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid test pattern");
if (rom_data[rom_size - 7] != 1)
throw std::runtime_error("declaration ROM image " + rom_path +
" has unsupported format");
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
// patch the CRC field of the format header to 0
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
// restore the CRC field value
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
if (test_crc != crc) {
std::stringstream err;
err << "declaration ROM image " + rom_path + " has invalid CRC, expected = 0x"
<< std::hex << crc << ", got = 0x" << std::hex << test_crc;
throw std::runtime_error(err.str());
}
int lanes_used = 0;
// count meaningful lanes in a data quad
for (int i = 0; i < 4; i++) {
if (byte_lane & (1 << i))
lanes_used++;
}
// padded_len is the size in bytes of all pages needed to contain all the bytes of the ROM
uint32_t padded_len =
uint32_t(((rom_size * 4 + lanes_used - 1) / lanes_used + 4095) / 4096 * 4096);
if (padded_len > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// calculate starting physical address of the ROM
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len))
throw std::runtime_error("could not allocate ROM space for declaration ROM image " +
rom_path);
int data_pos = int(rom_size) - 1;
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
// prepare new ROM data by copying over used lanes
// and padding unused lanes with 0xFF
// NOTE: speed uncritical - don't optimize!
for (int i = padded_len - 1; i >= 0; ) {
for (int b = 8; i>= 0 && b != 0; b >>= 1) {
if (data_pos >= 0 && (byte_lane & b))
new_data[i--] = rom_data[data_pos--];
else
new_data[i--] = 0xFF;
}
}
// move padded ROM data to the memory region
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
result = -1;
}
rom_file.close();
return result;
}
-30
View File
@@ -1,30 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
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 NUBUS_UTILS_H
#define NUBUS_UTILS_H
#include <cinttypes>
#include <string>
int load_declaration_rom(const std::string rom_path, int slot_num);
#endif // NUBUS_UTILS_H
+1 -5
View File
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nvram.h>
#include <devices/common/ofnvram.h>
#include <devices/deviceregistry.h>
#include <cinttypes>
@@ -47,9 +46,6 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
this->file_name = file_name;
this->ram_size = ram_size;
if (ram_size == 8192)
this->of_nvram_offset = OF_NVRAM_OFFSET;
// allocate memory storage and fill it with zeroes
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
@@ -103,7 +99,7 @@ void NVram::save() {
}
static const DeviceDescription Nvram_Descriptor = {
NVram::create, {}, {}, HWCompType::NVRAM
NVram::create, {}, {}
};
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
-2
View File
@@ -45,13 +45,11 @@ public:
uint8_t read_byte(uint32_t offset);
void write_byte(uint32_t offset, uint8_t value);
uint32_t get_of_nvram_offset() { return of_nvram_offset; }
private:
std::string file_name; // file name for the backing file
uint16_t ram_size; // NVRAM size
std::unique_ptr<uint8_t[]> storage;
uint32_t of_nvram_offset = 0;
void init();
void save();
+16 -15
View File
@@ -41,7 +41,7 @@ using namespace std;
static std::string hex2str(uint32_t n)
{
std::stringstream ss;
ss << setw(8) << right << setfill('0') << hex << n;
ss << setw(8) << setfill('0') << hex << n;
return ss.str();
}
@@ -67,7 +67,7 @@ bool OfConfigAppl::validate() {
// read OF partition header
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
}
// validate partition signature and version
@@ -81,7 +81,7 @@ bool OfConfigAppl::validate() {
// read the entire partition into the local buffer
for (i = 0; i < this->size; i++) {
this->buf[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
}
// verify partition checksum
@@ -161,7 +161,7 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
break;
case OF_VAR_TYPE_STR:
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - this->nvram_obj->get_of_nvram_offset();
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
if ((str_offset + str_len) > OF_CFG_SIZE) {
@@ -194,7 +194,7 @@ void OfConfigAppl::update_partition() {
// write the entire partition back to NVRAM
for (int i = 0; i < this->size; i++) {
this->nvram_obj->write_byte(this->nvram_obj->get_of_nvram_offset() + i, this->buf[i]);
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
}
}
@@ -266,8 +266,8 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
}
// remove the old string
std::memmove(&this->buf[top + str_len - this->nvram_obj->get_of_nvram_offset()],
&this->buf[top - this->nvram_obj->get_of_nvram_offset()], str_offset - top);
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET],
&this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
for (auto& var : of_vars) {
auto type = std::get<0>(var.second);
@@ -284,7 +284,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
// copy new string into NVRAM buffer char by char
i = 0;
for(char& ch : value) {
this->buf[top + i - this->nvram_obj->get_of_nvram_offset()] = ch == '\x0A' ? '\x0D' : ch;
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
i++;
}
@@ -322,9 +322,6 @@ bool OfConfigChrp::validate()
bool wip = true;
bool of_part_found = false;
if (this->nvram_obj == nullptr)
return false;
// search the entire 8KB NVRAM for CHRP OF config partition.
// Bail out if an unknown partition or free space is encountered.
// Skip over known partitions.
@@ -591,16 +588,20 @@ void OfConfigUtils::printenv() {
ReplaceAll(val, "\r\n", "\n");
ReplaceAll(val, "\r", "\n");
ReplaceAll(val, "\n", "\n "); // 34 spaces
cout << setw(34) << left << var.first << val << right << endl; // name column has width 34
cout << setw(34) << left << var.first << val << endl; // name column has width 34
}
}
bool OfConfigUtils::setenv(string var_name, string value)
void OfConfigUtils::setenv(string var_name, string value)
{
if (!this->open_container())
return false;
return;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
return this->cfg_impl->set_var(var_name, value);
if (!this->cfg_impl->set_var(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
}
+7 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -33,9 +33,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class NVram;
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
constexpr auto OF_NVRAM_OFFSET = 0x1800;
constexpr auto OF_NVRAM_SIG = 0x1275;
constexpr auto OF_CFG_SIZE = 0x800;
#define OF_NVRAM_OFFSET 0x1800
#define OF_NVRAM_SIG 0x1275
#define OF_CFG_SIZE 0x800
// OF Variable types
enum {
@@ -87,7 +87,7 @@ public:
// Old World implementation
class OfConfigAppl : public OfConfigImpl {
public:
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
~OfConfigAppl() = default;
bool validate();
@@ -108,7 +108,7 @@ private:
// New World implementation
class OfConfigChrp : public OfConfigImpl {
public:
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
~OfConfigChrp() = default;
bool validate();
@@ -134,7 +134,7 @@ public:
int init();
void printenv();
bool setenv(std::string var_name, std::string value);
void setenv(std::string var_name, std::string value);
protected:
bool open_container();
+5 -9
View File
@@ -389,28 +389,24 @@ static const PropMap PsxPci1_Properties = {
new StrProperty("")},
};
static const std::vector<std::string> Chaos_Subdevices = {
"ControlVideo"
};
static const DeviceDescription Bandit1_Descriptor = {
Bandit::create_first, {}, Bandit1_Properties, HWCompType::PCI_HOST
Bandit::create_first, {}, Bandit1_Properties
};
static const DeviceDescription Bandit2_Descriptor = {
Bandit::create_second, {}, Bandit2_Properties, HWCompType::PCI_HOST
Bandit::create_second, {}, Bandit2_Properties
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, PsxPci1_Properties, HWCompType::PCI_HOST
Bandit::create_psx_first, {}, PsxPci1_Properties
};
static const DeviceDescription Chaos_Descriptor = {
Chaos::create, Chaos_Subdevices, Chaos_Properties, HWCompType::PCI_HOST
Chaos::create, {}, Chaos_Properties
};
static const DeviceDescription AspenPci1_Descriptor = {
AspenPci::create, {}, Bandit1_Properties, HWCompType::PCI_HOST
AspenPci::create, {}, Bandit1_Properties
};
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
+9 -9
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -46,8 +46,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
constexpr auto BANDIT_DEV = 11; // Bandit's own device number
constexpr auto BANDIT_CAR_TYPE = 1 << 0; // Bandit config address type bit
#define BANDIT_DEV (11) // Bandit's own device number
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
/* Convenient macros for parsing CONFIG_ADDR fields. */
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
@@ -71,7 +71,7 @@ enum {
*/
class BanditHost : public PCIHost, public MMIODevice {
public:
BanditHost(int bridge_num) { this->bridge_num = bridge_num; }
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
@@ -121,15 +121,15 @@ public:
static std::unique_ptr<HWComponent> create_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
}
};
static std::unique_ptr<HWComponent> create_second() {
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
}
};
static std::unique_ptr<HWComponent> create_psx_first() {
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
}
};
private:
std::unique_ptr<BanditPciDevice> my_pci_device;
@@ -146,7 +146,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
}
};
};
/**
@@ -159,7 +159,7 @@ public:
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
}
};
};
#endif // BANDIT_PCI_H
+2 -2
View File
@@ -102,11 +102,11 @@ static const PropMap Dec21154Yosemite_Properties = {
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}, HWCompType::PCI_HOST | HWCompType::PCI_DEV
DecPciBridge::create, {}, {}
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties, HWCompType::PCI_HOST | HWCompType::PCI_DEV
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
+5 -10
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -41,10 +41,7 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
this->pci_wr_stat = [this](uint16_t val) {
this->status &= ~(0b1111100100000000 & val);
};
this->pci_wr_stat = [](uint16_t val) {};
this->pci_wr_cmd = [this](uint16_t cmd) {
/*
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
@@ -57,7 +54,7 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
this->pci_notify_bar_change = [](int bar_num) {};
}
};
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
@@ -194,8 +191,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
}
break;
@@ -204,8 +200,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
}
break;
+5 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,9 +47,7 @@ enum {
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2)
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
// Bridge Control (Type 1 and 2)
// Int_Pin and Int_Line registers (type 0, 1, and 2)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0); Bridge Control (Type 1 and 2); Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
@@ -86,16 +84,16 @@ public:
virtual bool supports_io_space() {
return has_io_space;
}
};
/* I/O space access methods */
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
return false;
}
};
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
return false;
}
};
// configuration space access methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
+10 -12
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -39,12 +39,12 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_memory_base = [this](uint16_t val) {
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_base_32 = (((uint64_t)this->memory_base & 0xfff0) << 16);
this->memory_base_32 = ((this->memory_base & 0xfff0) << 16);
};
this->pci_wr_memory_limit = [this](uint16_t val) {
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
this->memory_limit_32 = (((uint64_t)this->memory_limit & 0xfff0) << 16) + 0x100000;
this->memory_limit_32 = ((this->memory_limit & 0xfff0) << 16) + 0x100000;
};
this->pci_wr_io_base = [this](uint8_t val) {
@@ -61,13 +61,12 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
this->pci_wr_pref_mem_base = [this](uint16_t val) {
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
((this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
};
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
if ((this->io_base & 15) == 1)
@@ -86,17 +85,16 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
if ((this->pref_mem_cfg & 15) == 1)
this->pref_base_upper32 = val;
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
(((uint64_t)this->pref_mem_base & 0xfff0) << 16);
((this->pref_mem_base & 0xfff0) << 16);
};
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
if ((this->pref_mem_cfg & 15) == 1)
this->pref_limit_upper32 = val;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
0x100000;
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
};
}
};
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,9 +40,9 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
};
this->pci_wr_sec_status = [this](uint16_t val) {};
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
}
};
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
bool PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
// FIXME: constrain region to memory range
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
+8 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -43,16 +43,16 @@ public:
~PCIBridgeBase() = default;
// PCIHost methods
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
// PCIBase methods
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
bool supports_io_space() override {
bool supports_io_space() {
return true;
}
};
// plugin interface for using in the derived classes
std::function<uint8_t()> pci_rd_primary_bus;
@@ -69,7 +69,7 @@ public:
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit() override;
virtual int device_postinit();
protected:
// PCI configuration space state
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -126,7 +126,7 @@ PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_H
this->io_limit_1 = (val & this->io_1_cfg);
this->io_limit_1_32 = this->io_limit_1 + 4;
};
}
};
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
@@ -219,5 +219,5 @@ bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t si
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
return this->pci_io_write_loop(offset, size, value);
return this->pci_io_read_loop(offset, size, value);
}
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
PCIDevice::PCIDevice(std::string name) : PCIBase(name, PCI_HEADER_TYPE_0, 6)
{
}
};
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
{
+4 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/pci/pcibridge.h>
#include <devices/common/pci/pcihost.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinefactory.h>
#include <machines/machinebase.h>
#include <endianswap.h>
@@ -80,8 +81,7 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
// FIXME: need destructors to remove memory regions and downstream devices.
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs "
"a working destructor to unregister memory and downstream devices etc.)",
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor to unregister memory and downstream devices etc.)",
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
);
@@ -89,7 +89,7 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
gMachineObj->remove_device(dev_instance); // calls destructor of dev_instance since it is a unique_ptr in the device_map.
}
AddressMapEntry* PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
{
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
+6 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/bitops.h>
#include <devices/common/hwinterrupt.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <cinttypes>
@@ -65,14 +64,14 @@ public:
PCIHost() {
this->dev_map.clear();
io_space_devs.clear();
}
};
~PCIHost() = default;
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
virtual void pci_unregister_device(int dev_fun_num);
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
PCIBase *attach_pci_device(const std::string& dev_name, int slot_id,
@@ -89,13 +88,13 @@ public:
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
}
};
virtual int pcihost_device_postinit();
virtual bool register_pci_int(PCIBase* dev_instance);
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
this->int_ctrl = int_ctrl_obj;
}
};
virtual InterruptCtrl *get_interrupt_controller();
protected:
+4 -17
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -209,16 +209,7 @@ void MeshController::perform_command(const uint8_t cmd) {
this->sequencer();
break;
case SeqCmd::BusFree:
// Don't release ACK if ATN is asserted. This condition indicates
// that the initiator wants to reject last message.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// Let the target switch to next bus phase if
// - both ACK and ATN are asserted so the target will reject last message
// - when in MESSAGE_IN phase to tell the target the initiator accepts last message
if (this->is_initiator && (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN) ||
this->bus_obj->current_phase() == ScsiPhase::MESSAGE_IN))
this->bus_obj->target_next_step();
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
// generate phase mismatch exception
// if the target is still connected
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
@@ -308,16 +299,12 @@ static const PropMap Mesh_properties = {
{"cdr_img2", new StrProperty("")},
};
static const std::vector<std::string> Mesh_Subdevices = {
"ScsiMesh"
};
static const DeviceDescription Mesh_Tnt_Descriptor = {
MeshController::create_for_tnt, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
MeshController::create_for_tnt, {}, Mesh_properties
};
static const DeviceDescription Mesh_Heathrow_Descriptor = {
MeshController::create_for_heathrow, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
MeshController::create_for_heathrow, {}, Mesh_properties
};
REGISTER_DEVICE(MeshTnt, Mesh_Tnt_Descriptor);
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -91,7 +91,7 @@ namespace MeshScsi {
INT_ERROR = 1 << 2,
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
};
} // namespace MeshScsi
}; // namespace MeshScsi
class MeshBase {
public:
@@ -107,8 +107,8 @@ public:
~MeshStub() = default;
// registers access
uint8_t read(uint8_t reg_offset) override { return 0; }
void write(uint8_t reg_offset, uint8_t value) override {}
uint8_t read(uint8_t reg_offset) override { return 0; };
void write(uint8_t reg_offset, uint8_t value) override {};
};
class MeshController : public ScsiBusController, public MeshBase {
@@ -116,7 +116,7 @@ public:
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
this->chip_id = mesh_id;
this->reset(true);
}
};
~MeshController() = default;
static std::unique_ptr<HWComponent> create_for_tnt() {
+96 -209
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -72,19 +72,14 @@ void Sc53C94::reset_device()
this->data_fifo_pos = 0;
this->data_fifo[0] = 0;
this->sync_period = 5;
this->sync_offset = 0;
this->cur_step = 0;
this->seq_step = 0;
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
this->int_status = 0;
this->status = 0;
}
uint8_t Sc53C94::read(uint8_t reg_offset)
{
uint8_t bus_phase, int_flags;
uint8_t status, int_status;
switch (reg_offset) {
case Read::Reg53C94::Xfer_Cnt_LSB:
@@ -96,29 +91,18 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
case Read::Reg53C94::Command:
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
if (this->config2 & CFG2_ENF) {
static bool log_it = true;
if (log_it) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
log_it = false;
}
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
} else
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
return (this->status & 0xF8) | bus_phase;
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
return (this->status & 0xF8) | status;
case Read::Reg53C94::Int_Status:
int_flags = this->int_status;
if (this->irq) {
this->status &= ~(STAT_GE | STAT_PE | STAT_GCV);
this->int_status = 0;
this->seq_step = 0;
}
int_status = this->int_status;
this->seq_step = 0;
this->int_status = 0;
this->update_irq();
return int_flags;
return int_status;
case Read::Reg53C94::Seq_Step:
return this->seq_step;
case Read::Reg53C94::FIFO_Flags:
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
case Read::Reg53C94::Config_1:
return this->config1;
case Read::Reg53C94::Config_3:
@@ -155,9 +139,6 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
case Write::Reg53C94::Sel_Timeout:
this->sel_timeout = value;
break;
case Write::Reg53C94::Sync_Period:
this->sync_period = value;
break;
case Write::Reg53C94::Sync_Offset:
this->sync_offset = value;
break;
@@ -262,9 +243,9 @@ void Sc53C94::update_command_reg(uint8_t cmd)
void Sc53C94::exec_command()
{
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & CMD_OPCODE;
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
this->is_dma_cmd = !!(this->cmd_fifo[0] & CMD_ISDMA);
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
if (this->is_dma_cmd) {
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
@@ -277,8 +258,6 @@ void Sc53C94::exec_command()
}
}
this->cmd_steps = nullptr; // assume a single-step command for now
// simple commands will be executed immediately
// complex commands will be broken into multiple steps
// and handled by the sequencer
@@ -311,10 +290,9 @@ void Sc53C94::exec_command()
my_timer_id = 0;
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
});
if (!(config1 & CFG1_DISR)) {
if (!(config1 & 0x40)) {
LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str());
this->int_status = INTSTAT_SRST;
this->update_irq();
}
exec_next_command();
break;
@@ -325,86 +303,61 @@ void Sc53C94::exec_command()
this->int_status = INTSTAT_ICMD;
this->update_irq();
} else {
this->seq_step = 0;
this->cmd_steps = nullptr;
this->cur_state = SeqState::XFER_BEGIN;
this->sequencer();
}
break;
case CMD_COMPLETE_STEPS:
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
{(CMD_COMPLETE_STEPS << 8) + 1, SeqState::RCV_STATUS, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 2, SeqState::RCV_MESSAGE, 0, 0},
{(CMD_COMPLETE_STEPS << 8) + 3, SeqState::CMD_COMPLETE, 0, INTSTAT_SR | INTSTAT_SO}
};
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
}
this->cur_state = SeqState::RCV_STATUS;
this->seq_step = 0;
this->cmd_steps = complete_steps_desc;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
break;
case CMD_MSG_ACCEPTED:
// Don't release ACK if ATN is asserted.
// Executing this command with ATN true means that
// the initiator wants to reject the current message.
// That should be recognized and handled by the target.
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->is_initiator) {
this->bus_obj->target_next_step();
}
this->int_status |= INTSTAT_SR;
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
this->update_irq();
exec_next_command();
break;
case CMD_XFER_PAD_BYTES:
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
ABORT_F("%s: unsupported phase %d in CMD_XFER_PAD_BYTES",
this->name.c_str(), this->bus_obj->current_phase());
std::memset(this->data_fifo, 0, DATA_FIFO_MAX);
// FIXME: does the non-DMA version of this command use the transfer counter?
this->data_fifo_pos = std::min((int)this->set_xfer_count, DATA_FIFO_MAX);
this->cur_state = SeqState::SEND_CMD;
this->sequencer();
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND) {
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
}
break;
case CMD_RESET_ATN:
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
exec_next_command();
break;
case CMD_SELECT_NO_ATN:
static SeqDesc * sel_no_atn_desc = new SeqDesc[2]{
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
{(CMD_SELECT_NO_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_NO_ATN << 8) + 2, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_NO_ATN << 8) + 3, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = this->cur_step = 0;
this->seq_step = 0;
this->cmd_steps = sel_no_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN:
static SeqDesc * sel_with_atn_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG, INTSTAT_SR | INTSTAT_SO},
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
{(CMD_SELECT_WITH_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{(CMD_SELECT_WITH_ATN << 8) + 2, SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 3, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
{(CMD_SELECT_WITH_ATN << 8) + 4, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = this->cur_step = 0;
this->seq_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str());
break;
case CMD_SELECT_WITH_ATN_AND_STOP:
static SeqDesc * sel_with_atn_stop_desc = new SeqDesc[3]{
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG_EX, INTSTAT_SR | INTSTAT_SO},
{1, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = this->cur_step = 0;
this->bytes_out = 1; // set message length
this->cmd_steps = sel_with_atn_stop_desc;
this->cur_state = SeqState::BUS_FREE;
this->sequencer();
LOG_F(9, "%s: SELECT WITH ATN AND STOP command started", this->name.c_str());
break;
case CMD_ENA_SEL_RESEL:
exec_next_command();
break;
@@ -427,6 +380,8 @@ void Sc53C94::exec_next_command()
}
}
#define DATA_FIFO_MAX 16
void Sc53C94::fifo_push(const uint8_t data)
{
if (this->data_fifo_pos < DATA_FIFO_MAX) {
@@ -455,29 +410,19 @@ uint8_t Sc53C94::fifo_pop()
void Sc53C94::seq_defer_state(uint64_t delay_ns)
{
if (this->seq_timer_id) {
if (seq_timer_id) {
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
this->seq_timer_id = 0;
seq_timer_id = 0;
}
if (delay_ns) {
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
} else {
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
}
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
}
void Sc53C94::sequencer()
@@ -507,7 +452,7 @@ void Sc53C94::sequencer()
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
this->next_state = SeqState::SEL_BEGIN;
this->next_state = this->cmd_steps->next_step;
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
} else { // arbitration lost
LOG_F(INFO, "%s: arbitration lost!", this->name.c_str());
@@ -528,8 +473,8 @@ void Sc53C94::sequencer()
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
LOG_F(9, "%s: selection completed", this->name.c_str());
} else { // selection timeout
this->seq_step = 0;
this->int_status = INTSTAT_DIS;
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->bus_obj->disconnect(this->my_bus_id);
this->cur_state = SeqState::IDLE;
this->update_irq();
@@ -537,30 +482,29 @@ void Sc53C94::sequencer()
}
break;
case SeqState::SEND_MSG:
case SeqState::SEND_MSG_EX:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
} else {
this->bus_obj->target_xfer_data();
if (this->cur_state == SeqState::SEND_MSG_EX) {
this->notify(ScsiNotification::BUS_PHASE_CHANGE, ScsiPhase::MESSAGE_OUT);
} else {
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
if (this->cmd_steps)
this->bus_obj->target_next_step();
}
this->int_status = INTSTAT_SR;
this->update_irq();
break;
}
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
break;
case SeqState::SEND_CMD:
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
} else
this->bus_obj->target_xfer_data();
this->int_status |= INTSTAT_SR;
this->update_irq();
break;
}
this->bus_obj->target_xfer_data();
break;
case SeqState::CMD_COMPLETE:
this->int_status = INTSTAT_SR | INTSTAT_SO;
this->seq_step = this->cmd_steps->step_num;
this->int_status = this->cmd_steps->status;
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
@@ -569,8 +513,8 @@ void Sc53C94::sequencer()
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
if (this->is_dma_cmd) {
this->cur_state = SeqState::SEND_DATA;
break;
}
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
@@ -579,10 +523,6 @@ void Sc53C94::sequencer()
this->sequencer();
break;
case ScsiPhase::DATA_IN:
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
@@ -590,18 +530,6 @@ void Sc53C94::sequencer()
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
break;
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::MESSAGE_OUT:
this->cur_state = (this->cur_bus_phase == ScsiPhase::MESSAGE_OUT) ?
SeqState::SEND_MSG : SeqState::RCV_MESSAGE;
this->sequencer();
this->cur_state = SeqState::XFER_END;
this->sequencer();
break;
default:
ABORT_F("%s: unsupported phase %d in XFER_BEGIN", this->name.c_str(),
this->cur_bus_phase);
}
break;
case SeqState::XFER_END:
@@ -632,17 +560,11 @@ void Sc53C94::sequencer()
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
this->bus_obj->target_next_step();
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_REQ);
this->cur_state = SeqState::RCV_MESSAGE;
this->sequencer();
}
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
}
}
break;
@@ -661,46 +583,32 @@ void Sc53C94::update_irq()
}
}
void Sc53C94::notify(ScsiNotification notif_type, int param)
void Sc53C94::notify(ScsiMsg msg_type, int param)
{
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
switch (msg_type) {
case ScsiMsg::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;
seq_timer_id = 0;
this->cur_state = SeqState::SEL_END;
this->sequencer();
} else {
LOG_F(WARNING, "%s: invalid selection confirmation message ignored",
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
this->name.c_str());
}
break;
case ScsiNotification::BUS_PHASE_CHANGE:
case ScsiMsg::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
if (param == ScsiPhase::BUS_FREE) { // target want to disconnect
this->int_status = INTSTAT_DIS;
this->update_irq();
this->cur_state = SeqState::IDLE;
}
if (this->cmd_steps != nullptr) {
if (this->cur_bus_phase == this->cmd_steps->expected_phase) {
this->next_state = this->cmd_steps->next_state;
this->cmd_steps++;
this->seq_defer_state(0);
} else {
this->cur_step = this->cmd_steps->step_num;
this->seq_step = this->cur_step;
this->int_status = this->cmd_steps->status;
this->update_irq();
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE)
this->exec_next_command();
}
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
}
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
notif_type);
msg_type);
}
}
@@ -720,7 +628,8 @@ int Sc53C94::send_data(uint8_t* dst_ptr, int count)
if (this->data_fifo_pos > 0) {
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
} else if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
ABORT_F("%s: don't know what to do next!", this->name.c_str());
this->cmd_steps++;
this->cur_state = this->cmd_steps->next_step;
this->sequencer();
}
@@ -843,55 +752,38 @@ void Sc53C94::dma_stop()
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
int bytes_moved = 0;
if (len > this->xfer_count + this->data_fifo_pos)
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
if (this->cur_cmd != CMD_XFER || !this->is_dma_cmd ||
this->cur_bus_phase != ScsiPhase::DATA_IN) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
// see if there are data bytes in the FIFO we want to grab first
if (this->data_fifo_pos) {
int fifo_bytes = std::min(this->data_fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->data_fifo_pos -= fifo_bytes;
this->xfer_count -= fifo_bytes;
len -= fifo_bytes;
bytes_moved += fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return bytes_moved;
return 0;
}
}
if (this->bus_obj->pull_data(this->target_id, buf, len)) {
bytes_moved += len;
this->xfer_count -= len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
this->xfer_count = 0;
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
}
return bytes_moved;
return len;
}
int Sc53C94::xfer_to(uint8_t *buf, int len) {
int bytes_moved = 0;
if (!this->xfer_count || !this->is_dma_cmd) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
if (!this->xfer_count)
return len;
// Being in the DATA_OUT phase means that we're about to move
// a big chunk of data. The real device uses its FIFO as buffer.
@@ -900,7 +792,6 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
if (this->bus_obj->push_data(this->target_id, buf, len)) {
this->xfer_count -= len;
bytes_moved += len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
@@ -915,16 +806,16 @@ int Sc53C94::xfer_to(uint8_t *buf, int len) {
// fill in the data FIFO first
uint32_t fifo_bytes = std::min(len, DATA_FIFO_MAX - this->data_fifo_pos);
std::memcpy(&this->data_fifo[this->data_fifo_pos], buf, fifo_bytes);
len -= fifo_bytes;
this->data_fifo_pos += fifo_bytes;
this->xfer_count -= fifo_bytes;
bytes_moved += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->sequencer();
}
}
return bytes_moved;
return len;
}
static const PropMap Sc53C94_properties = {
@@ -932,12 +823,8 @@ static const PropMap Sc53C94_properties = {
{"cdr_img", new StrProperty("")},
};
static const std::vector<std::string> Sc53C94_Subdevices = {
"ScsiCurio"
};
static const DeviceDescription Sc53C94_Descriptor = {
Sc53C94::create, Sc53C94_Subdevices, Sc53C94_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
Sc53C94::create, {}, Sc53C94_properties
};
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
+30 -42
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -58,7 +58,7 @@ namespace Read {
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
//
};
}
};
/** 53C94 write registers */
namespace Write {
@@ -80,7 +80,7 @@ namespace Write {
Xfer_Cnt_Hi = 0xE, // Start Transfer Count Register High ; Am53CF94 extension
Data_Align = 0xF, // Data Alignment Register
};
}
};
/** NCR53C94/Am53CF94 commands. */
enum {
@@ -94,9 +94,9 @@ enum {
CMD_XFER = 0x10,
CMD_COMPLETE_STEPS = 0x11,
CMD_MSG_ACCEPTED = 0x12,
CMD_XFER_PAD_BYTES = 0x18,
//CMD_TRANSFER_PAD_BYTES = 0x18,
CMD_SET_ATN = 0x1A, // no interrupt
CMD_RESET_ATN = 0x1B, // no interrupt
//CMD_RESET_ATN = 0x1B, // no interrupt
// Target commands
//CMD_SEND_MESSAGE = 0x20,
@@ -111,13 +111,13 @@ enum {
//CMD_RECEIVE_DATA = 0x2A,
//CMD_RECEIVE_COMMAND_STEPS = 0x2B,
CMD_DMA_STOP = 0x04, // no interrupt
//CMD_ACCESS_FIFO_COMMAND = 0x05,
CMD_ACCESS_FIFO_COMMAND = 0x05,
// Idle Commands
//CMD_RESELECT_STEPS = 0x40,
CMD_SELECT_NO_ATN = 0x41,
CMD_SELECT_WITH_ATN = 0x42,
CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
//CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
CMD_ENA_SEL_RESEL = 0x44, // no interrupt
//CMD_DISABLE_SEL_RESEL = 0x45,
//CMD_SELECT_WITH_ATN3_STEPS = 0x46,
@@ -128,12 +128,14 @@ enum {
CMD_ISDMA = 0x80,
};
/** Status register bits. */
/** Status register bits. **/
enum {
STAT_PHASE_MASK = 0x07, // mask for I/O, Command and Message bits
STAT_GCV = 0x08, // Group Code Valid
//SCSI_CTRL_IO = 0x01, // Input/Output
//SCSI_CTRL_CD = 0x02, // Command/Data
//SCSI_CTRL_MSG = 0x04, // Message
//STAT_GCV = 0x08, // Group Code Valid
STAT_TC = 0x10, // Terminal count (NCR) / count to zero (AMD)
STAT_PE = 0x20, // Parity Error
//STAT_PE = 0x20, // Parity Error
STAT_GE = 0x40, // Gross Error (NCR) / Illegal Operation Error (AMD)
STAT_INT = 0x80, // Interrupt
};
@@ -150,12 +152,6 @@ enum {
INTSTAT_SEL = 0x01, // selected as a target without attention
};
/** Configuration register 1 bits. */
enum {
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
};
/** Configuration register 2 bits. */
enum {
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
};
@@ -170,7 +166,6 @@ namespace SeqState {
SEL_BEGIN,
SEL_END,
SEND_MSG,
SEND_MSG_EX,
SEND_CMD,
CMD_COMPLETE,
XFER_BEGIN,
@@ -180,15 +175,13 @@ namespace SeqState {
RCV_STATUS,
RCV_MESSAGE,
};
}
};
constexpr auto DATA_FIFO_MAX = 16;
/** Sequence descriptor for multistep commands. */
/** Sequence descriptor for sequencer commands. */
typedef struct {
int seq_id;
int next_step;
int step_num;
int expected_phase;
int next_state;
int status;
} SeqDesc;
@@ -204,7 +197,7 @@ public:
}
// HWComponent methods
int device_postinit() override;
int device_postinit();
// 53C94 registers access
uint8_t read(uint8_t reg_offset);
@@ -228,26 +221,23 @@ public:
std::bind(&Sc53C94::dma_stop, this)
);
}
}
};
void set_drq_callback(DrqCb cb) {
this->drq_cb = cb;
}
// ScsiDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; }
bool get_more_data() override { return false; }
bool has_data() override { return this->data_fifo_pos != 0; }
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {}
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return this->data_fifo_pos != 0; };
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
// DmaDevice methods
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
int tell_xfer_size() override {
return this->xfer_count;
}
// DmaChannel methods
int xfer_from(uint8_t *buf, int len); // Must be marked override!
int xfer_to(uint8_t *buf, int len); // Must be marked override!
protected:
void reset_device();
@@ -270,7 +260,7 @@ private:
uint32_t my_timer_id = 0;
uint8_t cmd_fifo[2];
uint8_t data_fifo[DATA_FIFO_MAX];
uint8_t data_fifo[16];
int cmd_fifo_pos = 0;
int data_fifo_pos = 0;
int bytes_out = 0;
@@ -282,7 +272,6 @@ private:
uint8_t int_status = 0;
uint8_t seq_step = 0;
uint8_t sel_timeout = 0;
uint8_t sync_period = 5;
uint8_t sync_offset = 0;
uint8_t clk_factor = 0;
uint8_t config1 = 0;
@@ -298,11 +287,10 @@ private:
uint8_t cur_cmd = 0;
bool is_dma_cmd = false;
int cur_bus_phase = 0;
uint8_t cur_step = 0; // internal step counter for multistep commands
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
// DMA related stuff
+23 -56
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -47,7 +47,6 @@ enum {
SCSI_CTRL_RST = 1 << 15,
};
/** SCSI bus phases. */
namespace ScsiPhase {
enum : int {
BUS_FREE = 0,
@@ -62,17 +61,15 @@ namespace ScsiPhase {
MESSAGE_OUT,
RESET,
};
}
};
/** SCSI status codes. */
namespace ScsiStatus {
enum : uint8_t {
GOOD = 0,
CHECK_CONDITION = 2,
};
}
};
/** Standard message codes. */
namespace ScsiMessage {
enum : uint8_t {
COMMAND_COMPLETE = 0,
@@ -83,21 +80,15 @@ namespace ScsiMessage {
HAS_DISCONNECT_PRIVILEDGE = 0x40,
IDENTIFY = 0x80,
};
}
};
/** Extended message codes. */
namespace ScsiExtMessage {
enum : uint8_t {
MODIFY_DATA_PTR = 0,
SYNCH_XFER_REQ = 1,
WIDE_XFER_REQ = 3,
};
}
/** Internal notification codes for our SCSI implementation. */
enum ScsiNotification : int {
enum ScsiMsg : int {
CONFIRM_SEL = 1,
BUS_PHASE_CHANGE,
SEND_CMD_BEGIN,
SEND_CMD_END,
MESSAGE_BEGIN,
MESSAGE_END,
};
enum ScsiCommand : uint8_t {
@@ -106,7 +97,6 @@ enum ScsiCommand : uint8_t {
REQ_SENSE = 0x03,
FORMAT_UNIT = 0x04,
READ_BLK_LIMITS = 0x05,
REASSIGN = 0x07,
READ_6 = 0x08,
WRITE_6 = 0x0A,
SEEK_6 = 0x0B,
@@ -123,21 +113,12 @@ enum ScsiCommand : uint8_t {
READ_CAPACITY_10 = 0x25,
READ_10 = 0x28,
WRITE_10 = 0x2A,
SEEK_10 = 0x2B,
VERIFY_WRITE_10 = 0x2E,
VERIFY_10 = 0x2F,
READ_LONG_10 = 0x35,
WRITE_BUFFER = 0x3B,
READ_BUFFER = 0x3C,
GET_CONFIG = 0x46,
GET_EVENT_STATUS_NOTIFY = 0x4A,
READ_DISC_INFO = 0x51,
MODE_SELECT_10 = 0x55,
MODE_SENSE_10 = 0x5A,
READ_12 = 0xA8,
WRITE_12 = 0xAA,
READ_DVD_STRUCTURE = 0xAD,
SET_SPEED = 0xBB,
// CD-ROM specific commands
READ_TOC = 0x43,
@@ -175,14 +156,14 @@ enum ScsiError : int {
};
/** Standard SCSI bus timing values measured in ns. */
constexpr uint64_t BUS_SETTLE_DELAY = 400;
constexpr uint64_t BUS_FREE_DELAY = 800;
constexpr uint64_t BUS_CLEAR_DELAY = 800;
constexpr uint64_t ARB_DELAY = 2400;
constexpr uint64_t SEL_ABORT_TIME = 200000;
constexpr uint64_t SEL_TIME_OUT = 250000000;
#define BUS_SETTLE_DELAY 400
#define BUS_FREE_DELAY 800
#define BUS_CLEAR_DELAY 800
#define ARB_DELAY 2400
#define SEL_ABORT_TIME 200000
#define SEL_TIME_OUT 250000000
constexpr auto SCSI_MAX_DEVS = 8;
#define SCSI_MAX_DEVS 8
class ScsiBus;
@@ -196,16 +177,15 @@ public:
this->scsi_id = my_id;
this->lun = 0,
this->cur_phase = ScsiPhase::BUS_FREE;
}
};
~ScsiDevice() = default;
virtual void notify(ScsiNotification notif_type, int param);
virtual void notify(ScsiMsg msg_type, int param);
virtual void next_step();
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
virtual void switch_phase(const int new_phase);
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; }
virtual bool has_data() { return this->data_size != 0; };
virtual int xfer_data();
virtual int send_data(uint8_t* dst_ptr, int count);
virtual int rcv_data(const uint8_t* src_ptr, const int count);
@@ -215,7 +195,6 @@ public:
virtual bool prepare_data() = 0;
virtual bool get_more_data() = 0;
virtual void process_command() = 0;
virtual void process_message();
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
this->bus_obj = bus_obj_ptr;
@@ -240,14 +219,11 @@ protected:
int ascq;
int sksv;
int field;
bool valid;
bool last_selection_has_atention = false;
uint8_t last_selection_message = 0;
ScsiBus* bus_obj;
int *seq_steps = nullptr;
action_callback pre_xfer_action = nullptr;
action_callback post_xfer_action = nullptr;
};
@@ -270,18 +246,9 @@ public:
// low-level state management
void register_device(int id, ScsiDevice* dev_obj);
int current_phase() const {
return this->cur_phase;
}
int get_initiator_id() const {
return this->initiator_id;
}
int get_target_id() const {
return this->target_id;
}
int current_phase() { return this->cur_phase; };
int get_initiator_id() { return this->initiator_id; };
int get_target_id() { return this->target_id; };
// reading/writing control lines
void assert_ctrl_line(int id, uint16_t mask);
@@ -290,7 +257,7 @@ public:
uint16_t test_ctrl_lines(uint16_t mask);
// reading/writing data lines
uint8_t get_data_lines() { return this->data_lines; }
uint8_t get_data_lines() { return this->data_lines; };
// high-level control/status
int switch_phase(int id, int new_phase);
+7 -11
View File
@@ -66,17 +66,15 @@ void ScsiBus::change_bus_phase(int initiator_id)
if (i == initiator_id)
continue; // don't notify the initiator
if (this->devices[i] != nullptr) {
this->devices[i]->notify(ScsiNotification::BUS_PHASE_CHANGE, this->cur_phase);
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
}
}
}
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
{
if (!(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
return;
}
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS,
"%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
uint16_t new_state = 0xFFFFU & mask;
@@ -95,9 +93,7 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
{
if (!(id >= 0 && id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
}
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
uint16_t new_state = 0;
@@ -242,7 +238,7 @@ void ScsiBus::confirm_selection(int target_id)
// notify initiator about selection confirmation from target
if (this->initiator_id >= 0) {
this->devices[this->initiator_id]->notify(ScsiNotification::CONFIRM_SEL, target_id);
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
}
}
@@ -377,11 +373,11 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
}
static const DeviceDescription ScsiCurio_Descriptor = {
ScsiBus::create_ScsiCurio, {}, {}, HWCompType::SCSI_BUS
ScsiBus::create_ScsiCurio, {}, {}
};
static const DeviceDescription ScsiMesh_Descriptor = {
ScsiBus::create_ScsiMesh, {}, {}, HWCompType::SCSI_BUS
ScsiBus::create_ScsiMesh, {}, {}
};
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
+9 -14
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -95,10 +95,8 @@ void ScsiBusController::sequencer() {
if (this->fifo_pos) {
this->bus_obj->target_xfer_data();
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
if (this->to_xfer <= 0) {
this->bus_obj->target_next_step();
if (this->to_xfer <= 0)
this->step_completed();
}
}
break;
case SeqState::SEND_CMD:
@@ -149,12 +147,9 @@ void ScsiBusController::sequencer() {
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
this->bus_obj->target_next_step();
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
} else if (this->cur_state == SeqState::RCV_MESSAGE)
if (this->cur_state == SeqState::RCV_MESSAGE)
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
this->bus_obj->target_next_step();
this->step_completed();
this->cur_state = SeqState::IDLE;
}
@@ -165,9 +160,9 @@ void ScsiBusController::sequencer() {
}
}
void ScsiBusController::notify(ScsiNotification notif_type, int param) {
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
if (this->dst_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
@@ -179,7 +174,7 @@ void ScsiBusController::notify(ScsiNotification notif_type, int param) {
this->name.c_str());
}
break;
case ScsiNotification::BUS_PHASE_CHANGE:
case ScsiMsg::BUS_PHASE_CHANGE:
this->cur_bus_phase = param;
#if 0
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
@@ -191,7 +186,7 @@ void ScsiBusController::notify(ScsiNotification notif_type, int param) {
break;
default:
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
notif_type);
msg_type);
}
}
+11 -11
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -50,7 +50,7 @@ namespace Scsi_Bus_Controller {
RCV_STATUS,
RCV_MESSAGE,
};
}
};
/** Sequencer error codes. */
enum : int {
@@ -58,7 +58,7 @@ enum : int {
SEL_TIMEOUT,
};
constexpr auto DATA_FIFO_DEPTH = 16;
#define DATA_FIFO_DEPTH 16
class ScsiBusController : public ScsiDevice, public DmaDevice {
public:
@@ -74,16 +74,16 @@ public:
virtual void report_error(const int error) = 0;
// ScsiDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; }
bool get_more_data() override { return false; }
bool has_data() override { return false; }
void notify(ScsiMsg msg_type, int param);
bool prepare_data() { return false; };
bool get_more_data() { return false; };
bool has_data() { return false; };
bool rcv_data();
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {}
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
// DmaDevice methods
int xfer_from(uint8_t *buf, int len) override;
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
protected:
void seq_defer_state(uint64_t delay_ns);
@@ -113,7 +113,7 @@ protected:
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
uint8_t int_mask = 0;
uint8_t int_stat = 0;
+28 -28
View File
@@ -65,9 +65,7 @@ void ScsiCdrom::process_command()
this->read(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
this->inquiry();
break;
case ScsiCommand::MODE_SELECT_6:
this->mode_select_6(cmd[4]);
@@ -153,53 +151,55 @@ int ScsiCdrom::test_unit_ready()
return ScsiError::NO_ERROR;
}
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
void ScsiCdrom::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
LOG_F(ERROR, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
}
int lun;
if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
LOG_F(9, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
LOG_F(9, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
}
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
data_ptr[1] = 0x80; // removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
this->data_buf[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
this->data_buf[1] = 0x80; // removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
alloc_len);
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
memset(&this->data_buf[36], 0, alloc_len - 36);
}
return alloc_len;
this->bytes_out = alloc_len;
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
this->switch_phase(ScsiPhase::DATA_IN);
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
+1 -1
View File
@@ -44,7 +44,7 @@ public:
protected:
int test_unit_ready();
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
void inquiry();
void mode_select_6(uint8_t param_len);
void mode_sense_6();
+13 -66
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,9 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
void ScsiDevice::notify(ScsiNotification notif_type, int param)
void ScsiDevice::notify(ScsiMsg msg_type, int param)
{
if (notif_type == ScsiNotification::BUS_PHASE_CHANGE) {
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
switch (param) {
case ScsiPhase::RESET:
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
@@ -45,11 +45,12 @@ void ScsiDevice::notify(ScsiNotification notif_type, int param)
return;
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
this->bus_obj->confirm_selection(this->scsi_id);
this->seq_steps = nullptr;
this->initiator_id = this->bus_obj->get_initiator_id();
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
this->last_selection_has_atention = true;
this->switch_phase(ScsiPhase::MESSAGE_OUT);
this->last_selection_has_atention = true;
this->last_selection_message = this->msg_buf[0];
//LOG_F(SCSIDEVICE, "%s: received message:0x%02x", this->get_name().c_str(), this->msg_buf[0]);
} else {
this->last_selection_has_atention = false;
this->switch_phase(ScsiPhase::COMMAND);
@@ -67,36 +68,8 @@ void ScsiDevice::switch_phase(const int new_phase)
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
}
bool ScsiDevice::allow_phase_change() {
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN | SCSI_CTRL_ACK) ==
(SCSI_CTRL_ATN | SCSI_CTRL_ACK))
ABORT_F("%s: reject message requested", this->name.c_str());
if (this->data_size || this->bus_obj->test_ctrl_lines(SCSI_CTRL_ACK))
return false;
else
return true;
}
void ScsiDevice::next_step()
{
// special case: data transfers during MESSAGE_IN phase
// require handshaking. Rejecting needs to be detected too.
if (bus_obj->current_phase() == ScsiPhase::MESSAGE_IN &&
!this->allow_phase_change())
return;
// check for pluggable sequences and follow them if applicable
if (this->seq_steps && *this->seq_steps >= 0) {
if (this->cur_phase == *this->seq_steps) {
this->seq_steps++;
if (*this->seq_steps >= 0) {
this->switch_phase(*this->seq_steps);
return;
}
}
}
switch (this->cur_phase) {
case ScsiPhase::DATA_OUT:
if (this->data_size >= this->incoming_size) {
@@ -123,8 +96,6 @@ void ScsiDevice::next_step()
break;
case ScsiPhase::STATUS:
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
this->data_ptr = this->msg_buf;
this->data_size = 1;
this->switch_phase(ScsiPhase::MESSAGE_IN);
break;
case ScsiPhase::MESSAGE_OUT:
@@ -133,7 +104,6 @@ void ScsiDevice::next_step()
case ScsiPhase::MESSAGE_IN:
case ScsiPhase::BUS_FREE:
this->bus_obj->release_ctrl_lines(this->scsi_id);
this->seq_steps = nullptr;
this->switch_phase(ScsiPhase::BUS_FREE);
break;
default:
@@ -167,6 +137,9 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
bytes_out = 0;
break;
case ScsiPhase::MESSAGE_IN:
this->data_ptr = this->msg_buf;
this->data_size = 1;
bytes_out = 1;
break;
default:
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
@@ -181,14 +154,14 @@ int ScsiDevice::xfer_data() {
switch (this->cur_phase) {
case ScsiPhase::MESSAGE_OUT:
if (this->bus_obj->pull_data(this->initiator_id, this->msg_buf, 1)) {
if (this->msg_buf[0] & ScsiMessage::IDENTIFY) {
if (this->msg_buf[0] & 0x80) {
LOG_F(9, "%s: IDENTIFY MESSAGE received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
this->next_step();
} else {
this->process_message();
ABORT_F("%s: unsupported message received, code = 0x%X",
this->name.c_str(), this->msg_buf[0]);
}
if (this->last_selection_has_atention)
this->last_selection_message = this->msg_buf[0];
}
break;
case ScsiPhase::COMMAND:
@@ -283,29 +256,3 @@ void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->switch_phase(ScsiPhase::STATUS);
}
void ScsiDevice::process_message() {
static int sdtr_response_seq[4] = {ScsiPhase::MESSAGE_OUT, ScsiPhase::MESSAGE_IN,
ScsiPhase::COMMAND, -1};
if (this->msg_buf[0] == 1) { // extended messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1) ||
!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[2], this->msg_buf[1]))
ABORT_F("%s: incomplete message received", this->name.c_str());
switch(this->msg_buf[2]) {
case ScsiExtMessage::SYNCH_XFER_REQ:
LOG_F(INFO, "%s: SDTR message received", this->name.c_str());
// confirm synchronous transfer capability by sending back the SDTR message
this->seq_steps = sdtr_response_seq;
this->data_ptr = this->msg_buf;
this->data_size = 5;
break;
default:
LOG_F(ERROR, "%s: unsupported message %d", this->name.c_str(), this->msg_buf[2]);
}
} else if ((this->msg_buf[0] >> 4) == 2) { // two-byte messages
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1))
ABORT_F("%s: incomplete message received", this->name.c_str());
}
}
+44 -77
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -34,9 +34,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
this->data_buf_size = 1 << 22;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
void ScsiHardDisk::insert_image(std::string filename) {
@@ -75,9 +72,6 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::FORMAT_UNIT:
this->format();
break;
case ScsiCommand::REASSIGN:
this->reassign();
break;
case ScsiCommand::READ_6:
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
this->read(lba, cmd[4], 6);
@@ -87,8 +81,7 @@ void ScsiHardDisk::process_command() {
this->write(lba, cmd[4], 6);
break;
case ScsiCommand::INQUIRY:
this->bytes_out = this->inquiry(cmd, this->data_buf);
this->switch_phase(ScsiPhase::DATA_IN);
this->inquiry();
break;
case ScsiCommand::MODE_SELECT_6:
mode_select_6(cmd[4]);
@@ -96,9 +89,6 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::MODE_SENSE_6:
this->mode_sense_6();
break;
case ScsiCommand::START_STOP_UNIT:
this->switch_phase(ScsiPhase::STATUS);
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
this->eject_allowed = (cmd[4] & 1) == 0;
this->switch_phase(ScsiPhase::STATUS);
@@ -219,42 +209,40 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
return ScsiError::NO_ERROR;
}
uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
int page_num = cmd_ptr[2];
int alloc_len = cmd_ptr[4];
void ScsiHardDisk::inquiry() {
int page_num = cmd_buf[2];
int alloc_len = cmd_buf[4];
if (page_num) {
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
}
if (alloc_len > 36) {
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
LOG_F(INFO, "%s: %d bytes requested in INQUIRY", this->name.c_str(), alloc_len);
}
int lun;
if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7",
this->name.c_str(), alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(), alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
alloc_len, cmd_ptr[1]);
lun = cmd_ptr[1] >> 5;
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(), alloc_len, cmd_buf[1]);
lun = cmd_buf[1] >> 5;
}
data_ptr[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
data_ptr[1] = 0; // non-removable media; 0x80 = removable media
data_ptr[2] = 2; // ANSI version: SCSI-2
data_ptr[3] = 1; // response data format
data_ptr[4] = 0x1F; // additional length
data_ptr[5] = 0;
data_ptr[6] = 0;
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&data_ptr[8], vendor_info, 8);
std::memcpy(&data_ptr[16], prod_info, 16);
std::memcpy(&data_ptr[32], rev_info, 4);
//std::memcpy(&data_ptr[36], serial_number, 8);
this->data_buf[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
this->data_buf[1] = 0; // non-removable media; 0x80 = removable media
this->data_buf[2] = 2; // ANSI version: SCSI-2
this->data_buf[3] = 1; // response data format
this->data_buf[4] = 0x1F; // additional length
this->data_buf[5] = 0;
this->data_buf[6] = 0;
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
std::memcpy(&this->data_buf[8], vendor_info, 8);
std::memcpy(&this->data_buf[16], prod_info, 16);
std::memcpy(&this->data_buf[32], rev_info, 4);
//std::memcpy(&this->data_buf[36], serial_number, 8);
//etc.
if (alloc_len < 36) {
@@ -262,10 +250,12 @@ uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
alloc_len);
}
else {
memset(&data_ptr[36], 0, alloc_len - 36);
memset(&this->data_buf[36], 0, alloc_len - 36);
}
return alloc_len;
this->bytes_out = alloc_len;
this->switch_phase(ScsiPhase::DATA_IN);
}
int ScsiHardDisk::send_diagnostic() {
@@ -309,6 +299,18 @@ void ScsiHardDisk::mode_sense_6() {
return;
}
if (page_ctrl == 2) {
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
this->sense = ScsiSense::ILLEGAL_REQ;
this->asc = ScsiError::INVALID_CDB;
this->ascq = 0;
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
this->field = 2;
this->switch_phase(ScsiPhase::STATUS);
return;
}
if (page_ctrl == 3) {
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
this->status = ScsiStatus::CHECK_CONDITION;
@@ -353,7 +355,7 @@ void ScsiHardDisk::mode_sense_6() {
// default values taken from Empire 540/1080S manual
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
WRITE_WORD_BE_U(&p_buf[10], 64); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&p_buf[10], 92); // sectors per track in the outermost zone
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
@@ -363,18 +365,6 @@ void ScsiHardDisk::mode_sense_6() {
got_page = true;
}
if (page_code == 4 || page_code == 0x3f) { // Rigid Disk Drive Geometry Page
page_size = 24;
p_buf[0] = 4; // page code
p_buf[1] = page_size - 2; // page length
std::memset(&p_buf[2], 0, 22);
int num_cylinders = this->total_blocks / 64 / 4;
p_buf[2] = (num_cylinders >> 16) & 0xFF;
WRITE_WORD_BE_U(&p_buf[3], num_cylinders & 0xFFFFU); // number of cylinders
p_buf[5] = 4; // number of heads
got_page = true;
}
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
if (sub_page_code != 0x00 && sub_page_code != 0xff)
goto bad_sub_page;
@@ -460,36 +450,19 @@ void ScsiHardDisk::format() {
});
}
void ScsiHardDisk::reassign() {
LOG_F(WARNING, "%s: attempt to reassign blocks on the disk!", this->name.c_str());
this->status = ScsiStatus::GOOD;
this->sense = ScsiSense::NO_SENSE;
this->asc = ScsiError::NO_ERROR;
this->valid = false;
TimerManager::get_instance()->add_oneshot_timer(
NS_PER_SEC, [this]() { this->switch_phase(ScsiPhase::STATUS); });
}
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
if (!check_lun())
return;
uint32_t transfer_size = transfer_len;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
std::memset(this->data_buf, 0, transfer_size);
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size);
@@ -501,18 +474,12 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size;
+4 -7
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -39,7 +39,7 @@ public:
void insert_image(std::string filename);
void process_command();
bool prepare_data();
bool get_more_data() { return false; }
bool get_more_data() { return false; };
protected:
int test_unit_ready();
@@ -49,8 +49,7 @@ protected:
void mode_sense_6();
void format();
void reassign();
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
void inquiry();
void read_capacity_10();
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
@@ -67,9 +66,7 @@ private:
bool eject_allowed = true;
int bytes_out = 0;
std::unique_ptr<uint8_t[]> data_buf_obj = nullptr;
uint8_t* data_buf = nullptr;
uint32_t data_buf_size = 0;
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
uint8_t error = ScsiError::NO_ERROR;
uint8_t msg_code = 0;
+43 -64
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/timermanager.h>
#include <devices/common/adb/adbbus.h>
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/viacuda.h>
#include <devices/deviceregistry.h>
@@ -40,7 +39,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ViaCuda::ViaCuda() : I2CBus() {
ViaCuda::ViaCuda() {
this->name = "ViaCuda";
supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST);
@@ -59,6 +58,7 @@ ViaCuda::ViaCuda() : I2CBus() {
// (not prescribed in the 6522 datasheet)
this->via_t1ll = 0xFF;
this->via_t1lh = 0xFF;
this->via_t2cl = 0xFF;
this->_via_ifr = 0; // all flags cleared
this->_via_ier = 0; // all interrupts disabled
@@ -204,9 +204,12 @@ void ViaCuda::write(int reg, uint8_t value) {
LOG_F(9, "VIA_DIRA = 0x%X", value);
break;
case VIA_T1CL:
this->via_t1ll = value; // writes to T1CL are redirected to T1LL
this->via_t1cl = value;
break;
case VIA_T1CH:
if (this->via_acr & 0xC0) {
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
}
// cancel active T1 timer task
if (this->t1_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
@@ -215,25 +218,33 @@ void ViaCuda::write(int reg, uint8_t value) {
// clear T1 flag in IFR
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
// load the high-order latch from the current T1CH value
this->via_t1lh = value;
// load the T1 counter from the corresponding latches
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
this->activate_t1();
// load initial value into counter 1
this->t1_counter = (value << 8) | this->via_t1cl;
// TODO: delay for one phase 2 clock
// 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(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
this->t1_timer_id = 0;
this->assert_t1_int();
}
);
break;
case VIA_T1LL:
this->via_t1ll = value;
break;
case VIA_T1LH:
this->via_t1lh = value;
// writes to T1LH clear T1 interrupt in the Apple VIA cell
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
break;
case VIA_T2CL:
this->via_t2ll = value; // writes to T2CL are redirected to T2LL
this->via_t2cl = value;
break;
case VIA_T2CH:
if (this->via_acr & 0x20) {
ABORT_F("VIA T2 pulse count mode not supported!");
}
// cancel active T2 timer task
if (this->t2_timer_id) {
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
@@ -243,7 +254,7 @@ void ViaCuda::write(int reg, uint8_t value) {
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
// load initial value into counter 2
this->t2_counter = (value << 8) | this->via_t2ll;
this->t2_counter = (value << 8) | this->via_t2cl;
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
@@ -262,7 +273,7 @@ void ViaCuda::write(int reg, uint8_t value) {
update_irq();
break;
case VIA_ACR:
this->via_acr = value & VIA_ACR_IMPL_BITS;
this->via_acr = value;
LOG_F(9, "VIA_ACR = 0x%X", value);
break;
case VIA_PCR:
@@ -271,8 +282,7 @@ void ViaCuda::write(int reg, uint8_t value) {
break;
case VIA_IFR:
// for each "1" in value clear the corresponding flags
// bit 7 is ignored
this->_via_ifr &= ~(value & 0x7F);
this->_via_ifr &= ~value;
update_irq();
break;
case VIA_IER:
@@ -291,28 +301,10 @@ uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last
{
// calculate current counter value based on elapsed time and timer frequency
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
uint32_t diff = uint32_t((cur_time - last_time) / this->via_clk_dur);
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
return last_val - diff;
}
void ViaCuda::activate_t1() {
// TODO: delay for one phase 2 clock
// 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(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
// reload the T1 counter from the corresponding latches
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
this->t1_timer_id = 0;
this->assert_t1_int();
if (this->via_acr & 0x40)
this->activate_t1();
}
);
}
void ViaCuda::print_enabled_ints() {
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
@@ -322,15 +314,15 @@ void ViaCuda::print_enabled_ints() {
}
}
void ViaCuda::update_irq() {
void ViaCuda::update_irq()
{
uint8_t active_ints = this->_via_ifr & this->_via_ier & 0x7F;
uint8_t irq_state = !!active_ints;
// let CPU know when irq_state is "1" or it changes from "1" to "0"
if (irq_state || (irq_state != (this->_via_ifr >> 7))) {
this->_via_ifr = (irq_state << 7) | (this->_via_ifr & 0x7F);
LOG_F(6, "%s: signal IRQ line change to 0x%X, IFR=0x%02X",
this->name.c_str(), irq_state, this->_via_ifr);
this->int_ctrl->ack_int(this->irq_id, irq_state);
if (active_ints != this->old_ifr) {
uint8_t new_irq = !!active_ints;
this->_via_ifr = (active_ints) | (new_irq << 7);
this->old_ifr = active_ints;
LOG_F(6, "VIA: assert IRQ, IFR=0x%02X", this->_via_ifr);
this->int_ctrl->ack_int(this->irq_id, new_irq);
}
}
@@ -369,7 +361,7 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
this->_via_ifr |= VIA_IF_CB1;
break;
case ViaLine::CB2:
this->_via_ifr |= VIA_IF_CB2;
this->_via_ifr |= VIA_IF_CB1;
break;
default:
ABORT_F("Assertion of unknown VIA line requested!");
@@ -543,11 +535,6 @@ void ViaCuda::process_adb_command() {
}
void ViaCuda::autopoll_handler() {
if (this->do_post_keyboard_state_events && !(!this->old_tip || !this->treq)) {
EventManager::get_instance()->post_keyboard_state_events();
this->do_post_keyboard_state_events = false;
}
uint8_t poll_command = this->autopoll_enabled ? this->adb_bus_obj->poll() : 0;
if (poll_command) {
@@ -613,11 +600,9 @@ void ViaCuda::pseudo_command() {
if (this->in_buf[2]) {
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
this->autopoll_enabled = true;
this->do_post_keyboard_state_events = true;
} else {
LOG_F(INFO, "Cuda: autopoll stopped");
this->autopoll_enabled = false;
this->do_post_keyboard_state_events = false;
}
response_header(CUDA_PKT_PSEUDO, 0);
break;
@@ -674,7 +659,7 @@ void ViaCuda::pseudo_command() {
case CUDA_SET_REAL_TIME: {
response_header(CUDA_PKT_PSEUDO, 0);
uint32_t real_time = this->calc_real_time();
uint32_t new_time = READ_DWORD_BE_U(&this->in_buf[2]);
uint32_t new_time = READ_DWORD_BE_U(&in_buf[2]);
this->time_offset = new_time - real_time;
break;
}
@@ -710,16 +695,15 @@ void ViaCuda::pseudo_command() {
this->out_buf[3] = this->poll_rate;
this->out_count++;
break;
case CUDA_SET_DEVICE_BITMAP:
case CUDA_SET_DEVICE_LIST:
response_header(CUDA_PKT_PSEUDO, 0);
this->device_mask = ((uint16_t)this->in_buf[2]) << 8;
this->device_mask |= ((uint16_t)this->in_buf[3]);
this->device_mask = ((uint16_t)in_buf[2]) >> 8;
this->device_mask += ((uint16_t)in_buf[3]);
break;
case CUDA_GET_DEVICE_BITMAP:
case CUDA_GET_DEVICE_LIST:
response_header(CUDA_PKT_PSEUDO, 0);
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
this->out_count += 2;
break;
case CUDA_ONE_SECOND_MODE:
LOG_F(INFO, "Cuda: One Second Interrupt Mode: %d", this->in_buf[2]);
@@ -727,17 +711,12 @@ 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);
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_READ_WRITE_I2C:
response_header(CUDA_PKT_PSEUDO, 0);
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]);
response_header(CUDA_PKT_PSEUDO, 0);
break;
case CUDA_COMB_FMT_I2C:
response_header(CUDA_PKT_PSEUDO, 0);
if (this->in_count >= 5) {
@@ -876,7 +855,7 @@ static const vector<string> Cuda_Subdevices = {
};
static const DeviceDescription ViaCuda_Descriptor = {
ViaCuda::create, Cuda_Subdevices, {}, HWCompType::ADB_HOST | HWCompType::I2C_HOST
ViaCuda::create, Cuda_Subdevices, {}
};
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
+27 -36
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,7 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Versatile interface adapter (VIA) is an old I/O controller that can be found
in nearly every Macintosh computer. In the 68k era, VIA was used to control
various peripheral devices. In a Power Macintosh, its function is limited
to the I/O interface with the Cuda MCU and some basic timer functionality.
to the I/O interface with the Cuda MCU. I therefore decided to put VIA
emulation code here.
Cuda MCU is a multipurpose IC built around a custom version of the Motorola
MC68HC05 microcontroller. It provides several functions including:
@@ -42,6 +43,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef VIACUDA_H
#define VIACUDA_H
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <devices/common/nvram.h>
@@ -51,7 +53,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class AdbBus;
class InterruptCtrl;
constexpr auto VIA_CLOCK_HZ = 783360;
#define VIA_CLOCK_HZ 783360
/** VIA register offsets. */
enum {
@@ -91,9 +93,6 @@ enum class ViaLine {
CB2
};
// for masking unimplemented bits in the Apple VIA cell.
constexpr uint8_t VIA_ACR_IMPL_BITS = 0x5C;
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
enum {
CUDA_TIP = 0x20, // transaction in progress
@@ -120,23 +119,17 @@ enum {
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
CUDA_SET_REAL_TIME = 0x09, // set real time
CUDA_POWER_DOWN = 0x0A, // power down system
CUDA_SET_POWER_UPTIME = 0x0B, // set power up time
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
CUDA_SEND_DFAC = 0x0E, // send dfac
CUDA_BATTERY_SWAP_SENSE = 0x10, // battery swap sense
CUDA_RESTART_SYSTEM = 0x11, // restart system
CUDA_SET_IPL_LEVEL = 0x12, // set IPL level
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
CUDA_SET_DEVICE_BITMAP = 0x19, // set device bitmap
CUDA_GET_DEVICE_BITMAP = 0x1A, // get device bitmap
CUDA_SET_DEVICE_LIST = 0x19, // set device list
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C
CUDE_TOGGLE_WAKEUP = 0x23, // toggle wake-up
CUDA_TIMER_TICKLE = 0x24, // set timer tickle
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
};
@@ -150,20 +143,18 @@ enum {
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
};
constexpr auto CUDA_IN_BUF_SIZE = 256;
#define CUDA_IN_BUF_SIZE 256
/** PRAM addresses within Cuda's internal memory. */
// = 0xA1; // byte, read/write 0x00 (Power Mac 6100)
// = 0xB3; // 2 bytes, write 0x3020 (Power Mac 6100)
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW
#define CUDA_PRAM_START 0x100 // starting address of PRAM
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
/** Latest Cuda Firmware version. */
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
#define CUDA_FW_VERSION_MAJOR 0x0002
#define CUDA_FW_VERSION_MINOR 0x0029
class ViaCuda : public I2CBus {
class ViaCuda : public HWComponent, public I2CBus {
public:
ViaCuda();
~ViaCuda();
@@ -190,6 +181,10 @@ private:
uint8_t via_porta = 0;
uint8_t via_ddrb = 0;
uint8_t via_ddra = 0;
uint8_t via_t1cl = 0xFF;
uint8_t via_t1ll = 0xFF;
uint8_t via_t1lh = 0xFF;
uint8_t via_t2cl = 0xFF;
uint8_t via_sr;
uint8_t via_acr = 0;
uint8_t via_pcr = 0;
@@ -201,23 +196,21 @@ private:
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;
uint16_t t1_counter;
uint32_t t1_timer_id = 0;
uint64_t t1_start_time = 0;
// timer 2 state
uint8_t via_t2ll; // low-order latch (write-only)
uint16_t t2_counter; // internal counter
uint16_t t2_counter;
uint32_t t2_timer_id = 0;
uint64_t t2_start_time = 0;
// VIA interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id;
uint8_t _via_ifr = 0;
uint8_t _via_ier = 0;
InterruptCtrl* int_ctrl;
uint32_t irq_id;
uint8_t _via_ifr;
uint8_t _via_ier;
uint8_t old_ifr = 0;
/* Cuda state. */
uint8_t old_tip;
@@ -248,7 +241,6 @@ private:
AdbBus* adb_bus_obj = nullptr;
bool autopoll_enabled = false;
bool do_post_keyboard_state_events = false;
// VIA methods
void print_enabled_ints(); // print enabled VIA interrupts and their sources
@@ -259,7 +251,6 @@ private:
void assert_t2_int();
void schedule_sr_int(uint64_t timeout_ns);
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t& last_time);
void activate_t1();
// CUDA methods
void cuda_init();
+1 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,8 +40,6 @@ struct DeviceDescription {
CreateFunc m_create_func;
std::vector<std::string> subdev_list;
PropMap properties;
uint64_t supports_types;
std::string description;
};
class DeviceRegistry
+16 -153
View File
@@ -35,7 +35,6 @@ BigMac::BigMac(uint8_t id) {
void BigMac::chip_reset() {
this->event_mask = 0xFFFFU; // disable HW events causing on-chip interrupts
this->rng_seed = (uint16_t)rand();
this->stat = 0;
this->phy_reset();
@@ -47,25 +46,13 @@ uint16_t BigMac::read(uint16_t reg_offset) {
switch (reg_offset) {
case BigMacReg::XIFC:
return this->tx_if_ctrl;
case BigMacReg::XCVR_IF:
return this->xcvr_if_ctrl;
case BigMacReg::CHIP_ID:
return this->chip_id;
case BigMacReg::TX_FIFO_TH:
return this->tx_fifo_tresh;
case BigMacReg::TX_FIFO_CSR:
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
case BigMacReg::RX_FIFO_CSR:
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
case BigMacReg::TX_PNTR:
return this->tx_ptr;
case BigMacReg::RX_PNTR:
return this->rx_ptr;
case BigMacReg::MIF_CSR:
return (this->mif_csr_old & ~Mif_Data_In) | (this->mii_in_bit << 3);
case BigMacReg::GLOB_STAT: {
uint16_t old_stat = this->stat;
this->stat = 0; // clear-on-read
this->stat = 0; // clear-on-read
return old_stat;
}
case BigMacReg::EVENT_MASK:
@@ -76,83 +63,22 @@ uint16_t BigMac::read(uint16_t reg_offset) {
return this->tx_reset;
case BigMacReg::TX_CONFIG:
return this->tx_config;
case BigMacReg::TX_MAX:
return this->tx_max;
case BigMacReg::TX_MIN:
return this->tx_min;
case BigMacReg::PEAK_ATT: {
uint8_t old_val = this->peak_attempts;
this->peak_attempts = 0; // clear-on-read
return old_val;
}
uint8_t old_val = this->peak_attempts;
this->peak_attempts = 0; // clear-on-read
return old_val;
}
case BigMacReg::NC_CNT:
return this->norm_coll_cnt;
case BigMacReg::NT_CNT:
return this->net_coll_cnt;
case BigMacReg::EX_CNT:
return this->excs_coll_cnt;
case BigMacReg::LT_CNT:
return this->late_coll_cnt;
case BigMacReg::RNG_SEED:
return this->rng_seed;
case BigMacReg::RX_FRM_CNT:
return this->rcv_frame_cnt;
case BigMacReg::RX_LE_CNT:
return this->len_err_cnt;
case BigMacReg::RX_AE_CNT:
return this->align_err_cnt;
case BigMacReg::RX_FE_CNT:
return this->fcs_err_cnt;
case BigMacReg::RX_CVE_CNT:
return this->cv_err_cnt;
case BigMacReg::RX_CONFIG:
return this->rx_config;
case BigMacReg::RX_MAX:
return this->rx_max;
case BigMacReg::RX_MIN:
return this->rx_min;
case BigMacReg::MEM_ADD:
return this->mem_add;
case BigMacReg::MEM_DATA_HI:
return this->mem_data_hi;
case BigMacReg::MEM_DATA_LO:
return this->mem_data_lo;
case BigMacReg::IPG_1:
return this->ipg1;
case BigMacReg::IPG_2:
return this->ipg2;
case BigMacReg::A_LIMIT:
return this->attempt_limit;
case BigMacReg::SLOT:
return this->slot_time;
case BigMacReg::PA_LEN:
return this->preamble_len;
case BigMacReg::PA_PAT:
return this->preamble_pat;
case BigMacReg::TX_SFD:
return this->tx_sfd;
case BigMacReg::JAM_SIZE:
return this->jam_size;
case BigMacReg::DEFER_TMR:
return this->defer_timer;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
return this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)];
case BigMacReg::HASH_TAB_0:
case BigMacReg::HASH_TAB_1:
case BigMacReg::HASH_TAB_2:
case BigMacReg::HASH_TAB_3:
return this->hash_table[(reg_offset >> 4) & 3];
case BigMacReg::AFR_0:
case BigMacReg::AFR_1:
case BigMacReg::AFR_2:
return this->addr_filters[((reg_offset >> 4) & 0xF) - 4];
case BigMacReg::AFC_R:
return this->addr_filt_mask;
default:
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(), reg_offset);
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
@@ -163,25 +89,16 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::XIFC:
this->tx_if_ctrl = value;
break;
case BigMacReg::XCVR_IF:
this->xcvr_if_ctrl = value;
break;
case BigMacReg::TX_FIFO_CSR:
this->tx_fifo_enable = !!(value & 1);
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
break;
case BigMacReg::TX_FIFO_TH:
this->tx_fifo_tresh = value;
break;
case BigMacReg::RX_FIFO_CSR:
this->rx_fifo_enable = !!(value & 1);
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
break;
case BigMacReg::TX_PNTR:
this->tx_ptr = value;
break;
case BigMacReg::RX_PNTR:
this->rx_ptr = value;
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
break;
case BigMacReg::MIF_CSR:
if (value & Mif_Data_Out_En) {
@@ -194,9 +111,6 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
}
this->mif_csr_old = value;
break;
case BigMacReg::MEM_ADD:
this->mem_add = value;
break;
case BigMacReg::EVENT_MASK:
this->event_mask = value;
break;
@@ -213,7 +127,7 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::TX_SW_RST:
if (value == 1) {
LOG_F(INFO, "%s: transceiver soft reset asserted", this->name.c_str());
this->tx_reset = 0; // acknowledge SW reset
this->tx_reset = 0; // acknowledge SW reset
}
break;
case BigMacReg::TX_CONFIG:
@@ -242,32 +156,10 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::RX_CONFIG:
this->rx_config = value;
break;
case BigMacReg::RX_MAX:
this->rx_max = value;
break;
case BigMacReg::RX_MIN:
this->rx_min = value;
break;
case BigMacReg::SLOT:
this->slot_time = value;
break;
case BigMacReg::PA_LEN:
this->preamble_len = value;
break;
case BigMacReg::PA_PAT:
this->preamble_pat = value;
break;
case BigMacReg::TX_SFD:
this->tx_sfd = value;
break;
case BigMacReg::JAM_SIZE:
this->jam_size = value;
break;
case BigMacReg::PEAK_ATT:
this->peak_attempts = value;
break;
case BigMacReg::DEFER_TMR:
this->defer_timer = value;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
break;
case BigMacReg::RX_FRM_CNT:
this->rcv_frame_cnt = value;
@@ -284,44 +176,15 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
case BigMacReg::RX_CVE_CNT:
this->cv_err_cnt = value;
break;
case BigMacReg::MAC_ADDR_0:
case BigMacReg::MAC_ADDR_1:
case BigMacReg::MAC_ADDR_2:
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
break;
case BigMacReg::HASH_TAB_0:
case BigMacReg::HASH_TAB_1:
case BigMacReg::HASH_TAB_2:
case BigMacReg::HASH_TAB_3:
this->hash_table[(reg_offset >> 4) & 3] = value;
break;
case BigMacReg::IPG_1:
this->ipg1 = value;
break;
case BigMacReg::IPG_2:
this->ipg2 = value;
break;
case BigMacReg::A_LIMIT:
this->attempt_limit = value;
break;
case BigMacReg::AFR_0:
case BigMacReg::AFR_1:
case BigMacReg::AFR_2:
this->addr_filters[((reg_offset >> 4) & 0xF) - 4] = value;
break;
case BigMacReg::AFC_R:
this->addr_filt_mask = value;
break;
case BigMacReg::CHIP_ID:
case BigMacReg::TX_SM:
case BigMacReg::RX_ST_MCHN:
LOG_F(WARNING, "%s: Attempted write to read-only register at 0x%X with 0x%X",
this->name.c_str(), reg_offset, value);
break;
default:
LOG_F(WARNING, "%s: unimplemented register at 0x%X is written with 0x%X",
this->name.c_str(), reg_offset, value);
}
}
@@ -581,11 +444,11 @@ void BigMac::srom_xmit_bit(const uint8_t bit_val) {
}
static const DeviceDescription BigMac_Heathrow_Descriptor = {
BigMac::create_for_heathrow, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
BigMac::create_for_heathrow, {}, {}
};
static const DeviceDescription BigMac_Paddington_Descriptor = {
BigMac::create_for_paddington, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
BigMac::create_for_paddington, {}, {}
};
REGISTER_DEVICE(BigMacHeathrow, BigMac_Heathrow_Descriptor);
+2 -49
View File
@@ -41,41 +41,21 @@ enum BigMacReg : uint16_t {
TX_FIFO_CSR = 0x100,
TX_FIFO_TH = 0x110,
RX_FIFO_CSR = 0x120,
MEM_ADD = 0x130, // Memory Address
MEM_DATA_HI = 0x140, // Memory Data High
MEM_DATA_LO = 0x150, // Memory Data Low
XCVR_IF = 0x160, // Transceiver IF Control
CHIP_ID = 0x170,
MIF_CSR = 0x180,
SROM_CSR = 0x190,
TX_PNTR = 0x1A0, // Apple: TX Pointer
RX_PNTR = 0x1B0, // Apple: RX Pointer
GLOB_STAT = 0x200, // Apple: kSTAT, Sun: Global Status Register
EVENT_MASK = 0x210, // ambiguously called INT_DISABLE in the Apple source
SROM_CSR = 0x190,
TX_SW_RST = 0x420,
TX_CONFIG = 0x430,
IPG_1 = 0x440, // Inter Packet Gap 1
IPG_2 = 0x450,
A_LIMIT = 0x460, // Attempt Limit
SLOT = 0x470,
PA_LEN = 0x480, // Apple: PA Len, Sun: PA Size
PA_PAT = 0x490,
TX_SFD = 0x4A0,
JAM_SIZE = 0x4B0,
TX_MAX = 0x4C0, // Max frame size
TX_MIN = 0x4D0, // Min frame size
PEAK_ATT = 0x4E0, // Apple: kPAREG, Sun: PeakAttempts Register
DEFER_TMR = 0x4F0, // Also called DCNT by Apple
NC_CNT = 0x500, // Normal Collision Counter
NT_CNT = 0x510, // Apple: Network Collision Counter
EX_CNT = 0x520, // Excessive Collision Counter
LT_CNT = 0x530, // Late Collision Counter
RNG_SEED = 0x540,
TX_SM = 0x550,
RX_SW_RST = 0x620,
RX_CONFIG = 0x630,
RX_MAX = 0x640,
RX_MIN = 0x650,
MAC_ADDR_2 = 0x660,
MAC_ADDR_1 = 0x670,
MAC_ADDR_0 = 0x680,
@@ -83,16 +63,11 @@ enum BigMacReg : uint16_t {
RX_LE_CNT = 0x6A0, // Length Error Counter
RX_AE_CNT = 0x6B0, // Alignment Error Counter
RX_FE_CNT = 0x6C0, // FCS Error Counter
RX_ST_MCHN = 0x6D0, // RX State Machine
RX_CVE_CNT = 0x6E0, // Code Violation Error Counter
HASH_TAB_3 = 0x700,
HASH_TAB_2 = 0x710,
HASH_TAB_1 = 0x720,
HASH_TAB_0 = 0x730,
AFR_2 = 0x740, // Address Filter 2
AFR_1 = 0x750, // Address Filter 1
AFR_0 = 0x760, // Address Filter 0
AFC_R = 0x770, // Address Filter Mask
};
/* MIF_CSR bit definitions. */
@@ -183,8 +158,7 @@ private:
// BigMac state
uint16_t tx_reset = 0; // self-clearing one-bit register
uint16_t tx_if_ctrl = 0;
uint16_t xcvr_if_ctrl = 0;
uint16_t rng_seed = 0;
uint16_t rng_seed;
uint16_t norm_coll_cnt = 0;
uint16_t net_coll_cnt = 0;
uint16_t excs_coll_cnt = 0;
@@ -202,29 +176,8 @@ private:
uint16_t rx_fifo_size = 0;
uint16_t hash_table[4] = {};
uint16_t mac_addr_flt[3] = {};
uint16_t addr_filters[3] = {};
uint16_t addr_filt_mask = 0;
uint16_t tx_config = 0;
uint16_t tx_sfd = 0;
uint16_t tx_ptr = 0;
uint16_t tx_min = 0;
uint16_t tx_max = 0;
uint16_t rx_config = 0;
uint16_t rx_ptr = 0;
uint16_t rx_min = 0;
uint16_t rx_max = 0;
uint16_t ipg1 = 0;
uint16_t ipg2 = 0;
uint16_t attempt_limit = 0;
uint16_t mem_add = 0;
uint16_t mem_data_hi = 0;
uint16_t mem_data_lo = 0;
uint16_t slot_time = 0;
uint16_t preamble_len = 0;
uint16_t preamble_pat = 0;
uint16_t jam_size = 0;
uint16_t defer_timer = 0;
// Interrupt state
uint16_t event_mask = 0xFFFFU; // inverted mask: 0 - enabled, 1 - disabled
+2 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -113,7 +113,7 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
}
static const DeviceDescription Mace_Descriptor = {
MaceController::create, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
MaceController::create, {}, {}
};
REGISTER_DEVICE(Mace, Mace_Descriptor);
+5 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
/** Known MACE chip IDs. */
constexpr auto MACE_ID_REV_B0 = 0x0940; // Darwin-0.3 source
constexpr auto MACE_ID_REV_A2 = 0x0941; // Darwin-0.3 source & Curio datasheet
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
/** MACE registers offsets. */
// Refer to the Am79C940 datasheet for details
@@ -79,7 +79,7 @@ namespace MaceEnet {
IAC_ADDRCHG = 1 << 7
};
} // namespace MaceEnet
}; // namespace MaceEnet
class MaceController : public DmaDevice, public HWComponent {
public:
@@ -87,7 +87,7 @@ public:
this->chip_id = id;
this->set_name("MACE");
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
}
};
~MaceController() = default;
static std::unique_ptr<HWComponent> create() {
+5 -5
View File
@@ -285,7 +285,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
if (!img_file.open(img_path)) {
img_file.close();
LOG_F(ERROR, "Could not open specified floppy image (\"%s\")!", img_path.c_str());
LOG_F(ERROR, "Could not open specified floppy image (%s)!", img_path.c_str());
return nullptr;
}
@@ -295,19 +295,19 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
switch(itype) {
case FlopImgType::RAW:
LOG_F(INFO, "Raw floppy image (\"%s\")", img_path.c_str());
LOG_F(INFO, "Raw floppy image");
fconv = new RawFloppyImg(img_path);
break;
case FlopImgType::DC42:
LOG_F(INFO, "Disk Copy 4.2 image (\"%s\")", img_path.c_str());
LOG_F(INFO, "Disk Copy 4.2 image");
fconv = new DiskCopy42Img(img_path);
break;
case FlopImgType::WOZ1:
case FlopImgType::WOZ2:
LOG_F(INFO, "WOZ v%s image (\"%s\")", (itype == FlopImgType::WOZ2) ? "2" : "1", img_path.c_str());
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
break;
default:
LOG_F(WARNING, "Unknown image format - assume RAW (\"%s\")", img_path.c_str());
LOG_F(WARNING, "Unknown image format - assume RAW");
fconv = new RawFloppyImg(img_path);
}
+8 -28
View File
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <string>
constexpr auto BLOCK_SIZE = 512; // size in bytes of a logical block
#define BLOCK_SIZE 512 // size in bytes of a logical block
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
@@ -50,33 +50,13 @@ public:
virtual int get_raw_disk_data(char* buf) = 0;
virtual int export_data(void) = 0;
int get_data_size() const {
return this->data_size;
}
int get_disk_rec_method() const {
return this->rec_method;
}
int get_number_of_tracks() const {
return this->num_tracks;
}
int get_number_of_sides() const {
return this->num_sides;
}
int get_sectors_per_side() const {
return this->num_sectors;
}
int get_rec_density() const {
return this->density;
}
uint8_t get_format_byte() const {
return this->format_byte;
}
int get_data_size() { return this->data_size; };
int get_disk_rec_method() { return this->rec_method; };
int get_number_of_tracks() { return this->num_tracks; };
int get_number_of_sides() { return this->num_sides; };
int get_sectors_per_side() { return this->num_sectors; };
int get_rec_density() { return this->density; };
uint8_t get_format_byte() { return this->format_byte; };
protected:
std::string img_path;
+9 -53
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,56 +21,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Macintosh Superdrive emulation. */
#include <core/timermanager.h>
#include <devices/floppy/floppyimg.h>
#include <devices/floppy/superdrive.h>
#include <loguru.hpp>
#include <cinttypes>
namespace loguru {
enum : Verbosity {
Verbosity_READWRITE = loguru::Verbosity_9,
Verbosity_SUPERDRIVE = loguru::Verbosity_9,
};
}
using namespace MacSuperdrive;
std::string MacSuperdrive::get_command_name(uint8_t addr)
{
switch (addr) {
#define one_command(x) case CommandAddr::x: return #x;
one_command(Step_Direction)
one_command(Do_Step)
one_command(Motor_On_Off)
one_command(Eject_Disk)
one_command(Reset_Eject_Latch)
one_command(Switch_Drive_Mode)
default: return "unknown";
}
}
std::string MacSuperdrive::get_status_name(uint8_t addr)
{
switch (addr) {
#define one_status(x) case StatusAddr::x: return #x;
one_status(Step_Status)
one_status(Motor_Status)
one_status(Eject_Latch)
one_status(Select_Head_0)
one_status(MFM_Support)
one_status(Double_Sided)
one_status(Drive_Exists)
one_status(Disk_In_Drive)
one_status(Write_Protect)
one_status(Track_Zero)
one_status(Select_Head_1)
one_status(Drive_Mode)
one_status(Drive_Ready)
one_status(Media_Kind)
default: return "unknown";
}
}
MacSuperDrive::MacSuperDrive(std::string name)
{
this->set_name(name);
@@ -96,8 +55,7 @@ void MacSuperDrive::reset_params()
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
LOG_F(SUPERDRIVE, "%s: command %-17s addr=0x%X, value=%d",
this->get_name().c_str(), get_command_name(addr).c_str(), addr, value);
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
switch(addr) {
case CommandAddr::Step_Direction:
@@ -109,10 +67,10 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
if (this->cur_track < 0)
this->cur_track = 0;
else if (this->cur_track >= this->num_tracks) {
LOG_F(ERROR, "%s: track:%d is greater than max track:%d",
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
LOG_F(ERROR, "%s: track:%d is greater than max track:%d", this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
this->cur_track = this->num_tracks - 1;
}
this->track_zero = this->cur_track == 0;
}
break;
case CommandAddr::Motor_On_Off:
@@ -162,6 +120,7 @@ void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
uint8_t MacSuperDrive::status(uint8_t addr)
{
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
uint8_t value;
switch(addr) {
@@ -193,7 +152,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
value = this->wr_protect ^ 1; // reverse logic
break;
case StatusAddr::Track_Zero:
value = this->cur_track != 0; // reverse logic
value = this->track_zero ^ 1; // reverse logic
break;
case StatusAddr::Select_Head_1:
value = this->cur_head = 1;
@@ -211,7 +170,6 @@ uint8_t MacSuperDrive::status(uint8_t addr)
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
value = 0;
}
LOG_F(SUPERDRIVE, "%s: status %-13s 0x%X = %d", this->get_name().c_str(), get_status_name(addr).c_str(), addr, value);
return value;
}
@@ -325,7 +283,7 @@ uint64_t MacSuperDrive::sync_to_disk()
{
uint64_t cur_time_ns, track_time_ns;
uint64_t track_delay = uint64_t(this->get_current_track_delay() * NS_PER_SEC);
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
// look how much ns have been elapsed since the last motor enabling
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
@@ -431,8 +389,6 @@ SectorHdr MacSuperDrive::current_sector_header()
char* MacSuperDrive::get_sector_data_ptr(int sector_num)
{
LOG_F(READWRITE, "%s: get_sector_data_ptr track:%d head:%d sector:%d",
this->get_name().c_str(), this->cur_track, this->cur_head, sector_num);
return this->disk_data.get() +
((this->track2lblk[this->cur_track] +
(this->cur_head * this->sectors_per_track[this->cur_track]) +
+4 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,7 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// convert number of bytes to disk time = nbytes * bits_per_byte * 2 us
#define MFM_BYTES_TO_DISK_TIME(bytes) USECS_TO_NSECS((bytes) * 8 * 2)
// timing constants for MFM disks
// timing constans for MFM disks
constexpr uint32_t MFM_INDX_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(146);
constexpr uint32_t MFM_ADR_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(22);
constexpr uint32_t MFM_SECT_DATA_DELAY = MFM_BYTES_TO_DISK_TIME(514);
@@ -94,9 +94,6 @@ typedef struct SectorHdr {
int format;
} SectorHdr;
std::string get_command_name(uint8_t addr);
std::string get_status_name(uint8_t addr);
class MacSuperDrive : public HWComponent {
public:
MacSuperDrive(std::string name);
@@ -128,6 +125,7 @@ private:
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
uint8_t is_ready;
uint8_t track_zero; // 1 - if head is at track zero
int step_dir; // step direction -1/+1
int cur_track; // track number the head is currently at
int cur_head; // current head number: 1 - upper, 0 - lower
@@ -160,6 +158,6 @@ private:
std::unique_ptr<char[]> disk_data;
};
} // namespace MacSuperdrive
}; // namespace MacSuperdrive
#endif // MAC_SUPERDRIVE_H
+8 -8
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -40,7 +40,7 @@ using namespace Swim3;
Swim3Ctrl::Swim3Ctrl()
{
this->name = "SWIM3";
supports_types(HWCompType::FLOPPY_CTRL);
this->supported_types = HWCompType::FLOPPY_CTRL;
this->reset();
@@ -98,7 +98,7 @@ int Swim3Ctrl::device_postinit()
}
return 0;
}
};
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
{
@@ -152,7 +152,7 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
{
uint8_t status_addr = 0;
uint8_t status_addr;
switch(reg_offset) {
case Swim3Reg::Timer:
@@ -290,8 +290,8 @@ 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;
}
this->step_timer_id = 0;
this->step_count = 0; // not sure this one is required
}
@@ -382,8 +382,8 @@ 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;
}
this->access_timer_id = 0;
}
void Swim3Ctrl::init_timer(const uint8_t start_val)
@@ -400,7 +400,7 @@ 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(
uint32_t(this->timer_val) * NS_PER_USEC,
this->timer_val * NS_PER_USEC,
[this]() {
this->timer_val = 0;
this->int_flags |= INT_TIMER_DONE;
@@ -440,7 +440,7 @@ static const PropMap Swim3_Properties = {
};
static const DeviceDescription Swim3_Descriptor = {
Swim3Ctrl::create, {}, Swim3_Properties, HWCompType::FLOPPY_CTRL
Swim3Ctrl::create, {}, Swim3_Properties
};
REGISTER_DEVICE(Swim3, Swim3_Descriptor);
+5 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -73,8 +73,7 @@ enum {
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
INT_SENSE = 0x10, // generates interrupts on sense line changes
INT_ERROR = 0x20, // missing in SWIM3 ERS but used in MkLinux/BeOS
INT_SENSE = 0x10, // unused by SWIM3 driver
};
// SWIM3 internal states.
@@ -101,7 +100,7 @@ public:
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
}
};
protected:
void reset();
@@ -148,10 +147,10 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
};
} // namespace Swim3
}; // namespace Swim3
#endif // SWIM3_H
+64 -121
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -54,8 +54,7 @@ AMIC::AMIC() : MMIODevice()
// connect internal SCSI controller
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->curio_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
this->curio_dma->connect(this->scsi);
this->scsi->connect(this->curio_dma.get());
this->scsi->set_dma_channel(this->curio_dma.get());
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
if (drq_state & 1)
via2_ifr |= VIA2_INT_SCSI_DRQ;
@@ -76,8 +75,8 @@ AMIC::AMIC() : MMIODevice()
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma>(new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, DMA1_INT_SOUND << DMA1_INT_SHIFT);
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, 2 << 8);
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
@@ -125,6 +124,8 @@ int AMIC::device_postinit()
uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
{
uint32_t phase_val;
// subdevices registers
switch(offset >> 12) {
case 0: // VIA1 registers
@@ -156,15 +157,14 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return (this->awacs->read_stat() >> (offset & 3) * 8) & 0xFF;
case AMICReg::Snd_Phase0:
case AMICReg::Snd_Phase1:
case AMICReg::Snd_Phase2: {
case AMICReg::Snd_Phase2:
// the sound phase register is organized as follows:
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
// into the DMA buffer and 'p' is an undocumented prescale value
// HWInit doesn't care about. Let's hope it will be sufficient
// to return 0 for prescale.
uint32_t phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
}
case AMICReg::Snd_Out_Ctrl:
return this->snd_out_ctrl;
case AMICReg::Snd_Out_DMA:
@@ -217,28 +217,8 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return this->floppy_dma->read_stat();
case SCC_DMA_Xmt_A_Ctrl:
return this->escc_xmit_a_dma->read_stat();
case SCC_RXA_Byte_Cnt_Hi:
return 0;
case SCC_RXA_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_A_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch A DMA Ctrl read @%x.%c = %0*x", offset,
SIZE_ARG(size), size * 2, value);
return value;
}
case SCC_DMA_Xmt_B_Ctrl:
return this->escc_xmit_b_dma->read_stat();
case SCC_RXB_Byte_Cnt_Hi:
return 0;
case SCC_RXB_Byte_Cnt_Lo:
return 0;
case SCC_DMA_Rcv_B_Ctrl: {
uint32_t value = std::rand() & (-1U >> (32 - size * 8));
LOG_F(WARNING, "AMIC SCC Receive Ch B DMA Ctrl read @%x.%c = %0*x",
offset, SIZE_ARG(size), size * 2, value);
return value;
}
default:
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
}
@@ -329,10 +309,11 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
break;
case AMICReg::VIA2_IFR:
// if bit 7 is set, clear the corresponding IRQ bit for each "1" in value
// writing any value to VIA2_IFR with bit 7 cleared has no effect
if (value & 0x80) {
this->via2_ifr &= ~(value & 0x7F);
this->update_via2_irq();
} else { // writing any value to VIA2_IFR with bit 7 cleared has no effect
LOG_F(WARNING, "%s: bit 7 of VIA2_IFR is cleared!", this->name.c_str());
}
break;
case AMICReg::VIA2_Slot_IER:
@@ -419,9 +400,9 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
if (value & 2) { // RUN bit set?
this->curio_dma->reinit(this->scsi_dma_base);
if (value & (1 << 6))
this->curio_dma->xfer_to_device();
this->scsi->real_dma_xfer_out();
else
this->curio_dma->xfer_from_device();
this->scsi->real_dma_xfer_in();
}
this->curio_dma->write_ctrl(value);
break;
@@ -467,63 +448,50 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
}
// ======================== Interrupt related stuff ==========================
uint64_t AMIC::register_dev_int(IntSrc src_id) {
uint32_t AMIC::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::VIA_CUDA : return CPU_INT_VIA1 << CPU_INT_SHIFT;
case IntSrc::VIA2 : return CPU_INT_VIA2 << CPU_INT_SHIFT;
case IntSrc::ESCC : return CPU_INT_ESCC << CPU_INT_SHIFT;
case IntSrc::ETHERNET : return CPU_INT_ENET << CPU_INT_SHIFT;
case IntSrc::DMA_ALL : return CPU_INT_ALL_DMA << CPU_INT_SHIFT;
case IntSrc::NMI : return CPU_INT_NMI << CPU_INT_SHIFT;
case IntSrc::DMA_SCSI_CURIO: return VIA2_INT_SCSI_DRQ << VIA2_INT_SHIFT;
case IntSrc::SLOT_ALL : return VIA2_INT_ALL_SLOT << VIA2_INT_SHIFT;
case IntSrc::SCSI_CURIO : return VIA2_INT_SCSI_IRQ << VIA2_INT_SHIFT;
case IntSrc::DAVBUS : return VIA2_INT_SOUND << VIA2_INT_SHIFT;
case IntSrc::SWIM3 : return VIA2_INT_SWIM3 << VIA2_INT_SHIFT;
case IntSrc::SLOT_0 : return SLOT_INT_SLOT_0 << SLOT_INT_SHIFT;
case IntSrc::SLOT_1 : return SLOT_INT_SLOT_1 << SLOT_INT_SHIFT;
case IntSrc::SLOT_2 : return SLOT_INT_SLOT_2 << SLOT_INT_SHIFT;
case IntSrc::SLOT_PDS : return SLOT_INT_SLOT_PDS << SLOT_INT_SHIFT;
case IntSrc::SLOT_VDS : return SLOT_INT_SLOT_VDS << SLOT_INT_SHIFT;
case IntSrc::VBL : return SLOT_INT_VBL << SLOT_INT_SHIFT;
case IntSrc::DMA_DAVBUS_Tx : return DMA1_INT_SOUND << DMA1_INT_SHIFT;
case IntSrc::VIA_CUDA:
return CPU_INT_VIA1;
case IntSrc::SCSI_CURIO:
return VIA2_INT_SCSI_IRQ << 8;
case IntSrc::SWIM3:
return VIA2_INT_SWIM3 << 8;
case IntSrc::NMI:
return CPU_INT_NMI;
default:
ABORT_F("AMIC: unknown interrupt source %d", src_id);
}
return 0;
}
uint64_t AMIC::register_dma_int(IntSrc src_id) {
uint32_t AMIC::register_dma_int(IntSrc src_id) {
ABORT_F("AMIC: register_dma_int() not implemented");
return 0;
}
void AMIC::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
// dispatch cascaded AMIC interrupts from various sources
// irq_id format: 00DDCCBBAA where
// - AA -> CPU interrupts
// - BB -> pseudo VIA2 interrupts
// - CC -> slot interrupts
if (irq_id >> SLOT_INT_SHIFT) {
this->ack_slot_int(irq_id >> SLOT_INT_SHIFT, irq_line_state);
} else if (irq_id >> VIA2_INT_SHIFT) {
this->ack_via2_int(irq_id >> VIA2_INT_SHIFT, irq_line_state);
} else if (irq_id >> CPU_INT_SHIFT) {
this->ack_cpu_int(irq_id >> CPU_INT_SHIFT, irq_line_state);
if (irq_id < 0x100) {
this->ack_cpu_int(irq_id, irq_line_state);
} else if (irq_id < 0x10000) {
this->ack_via2_int(irq_id >> 8, irq_line_state);
} else if (irq_id < 0x1000000) {
this->ack_slot_int(irq_id >> 16, irq_line_state);
} else {
ABORT_F("AMIC: unknown interrupt source ID 0x%llX", irq_id);
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
}
}
void AMIC::ack_slot_int(uint8_t slot_int, uint8_t irq_line_state) {
void AMIC::ack_slot_int(uint32_t irq_id, uint8_t irq_line_state) {
// CAUTION: reverse logic (0 - true, 1 - false) in the IFR register!
if (irq_line_state) {
this->via2_slot_ifr &= ~slot_int;
this->via2_slot_ifr &= ~irq_id;
} else {
this->via2_slot_ifr |= slot_int;
this->via2_slot_ifr |= irq_id;
}
uint8_t new_irq = !!(~this->via2_slot_ifr & this->via2_slot_ier & 0x7F);
if (new_irq != this->via2_slot_irq) {
@@ -541,26 +509,26 @@ void AMIC::update_via2_irq() {
}
}
void AMIC::ack_via2_int(uint8_t via2_int, uint8_t irq_line_state) {
void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_line_state) {
this->via2_ifr |= via2_int;
this->via2_ifr |= irq_id;
} else {
this->via2_ifr &= ~via2_int;
this->via2_ifr &= ~irq_id;
}
this->update_via2_irq();
}
void AMIC::ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state) {
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
if (this->int_ctrl & CPU_INT_MODE) { // 68k interrupt emulation mode?
if (irq_line_state) {
this->dev_irq_lines |= cpu_int;
this->dev_irq_lines |= irq_id;
} else {
this->dev_irq_lines &= ~cpu_int;
this->dev_irq_lines &= ~irq_id;
}
if (!(this->int_ctrl & CPU_INT_FLAG)) {
this->int_ctrl |= CPU_INT_FLAG;
ppc_assert_int();
LOG_F(5, "AMIC: CPU INT asserted, source: 0x%02x", cpu_int);
LOG_F(5, "AMIC: CPU INT asserted, source: %d", irq_id);
} else {
LOG_F(5, "AMIC: CPU INT already latched");
}
@@ -570,15 +538,15 @@ void AMIC::ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state) {
}
}
void AMIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
if (irq_id >> DMA1_INT_SHIFT) { // DMA Interrupt Flags 1
irq_id = (irq_id >> DMA1_INT_SHIFT) & 0xFFU;
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_id >= 0x100) { // DMA Interrupt Flags 1
irq_id = (irq_id >> 8) & 0xFFU;
if (irq_line_state)
this->dma_ifr1 |= irq_id;
else
this->dma_ifr1 &= ~irq_id;
} else if (irq_id >> DMA0_INT_SHIFT) { // DMA Interrupt Flags 0
irq_id = (irq_id >> DMA0_INT_SHIFT) & 0xFFU;
} else { // DMA Interrupt Flags 0
irq_id &= 0xFFU;
if (irq_line_state)
this->dma_ifr0 |= irq_id;
else
@@ -620,7 +588,7 @@ void AmicSndOutDma::update_irq() {
if (new_level != this->irq_level) {
this->irq_level = new_level;
TimerManager::get_instance()->add_immediate_timer([this] {
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
this->int_ctrl->ack_dma_int(this->irq_id, this->irq_level);
});
}
}
@@ -754,50 +722,25 @@ void AmicScsiDma::write_ctrl(uint8_t value)
}
}
bool AmicScsiDma::is_ready() {
return (this->stat & 2) ? true : false;
}
void AmicScsiDma::xfer_from_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_FROM_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
int AmicScsiDma::push_data(const char* src_ptr, int len)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
uint8_t *p_data = res.host_va;
std::memcpy(p_data, src_ptr, len);
int got_bytes = this->dev_obj->xfer_from(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
this->addr_ptr += len;
return 0;
}
void AmicScsiDma::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
uint32_t len = this->dev_obj->tell_xfer_size();
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
int got_bytes = this->dev_obj->xfer_to(res.host_va, len);
if (got_bytes > 0) {
this->addr_ptr += got_bytes;
}
}
void AmicScsiDma::xfer_retry() {
if (this->xfer_dir == DMA_DIR_UNDEF)
return;
if (this->xfer_dir == DMA_DIR_FROM_DEV)
this->xfer_from_device();
else
this->xfer_to_device();
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data)
{
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, req_len, false);
*p_data = res.host_va;
this->addr_ptr += req_len;
*avail_len = req_len;
return DmaPullResult::MoreData;
}
// =========================== Serial DMA stuff ===============================
@@ -823,14 +766,14 @@ DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len
uint8_t **p_data)
{
return DmaPullResult::NoMoreData;
}
};
static std::vector<std::string> Amic_Subdevices = {
"Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
};
static const DeviceDescription Amic_Descriptor = {
AMIC::create, Amic_Subdevices, {}, HWCompType::MMIO_DEV | HWCompType::INT_CTRL
AMIC::create, Amic_Subdevices, {}
};
REGISTER_DEVICE(Amic, Amic_Descriptor);
Loaded 100 of 189 files, more files were not shown because too many files have changed in this diff. Show more