Compare commits

..
Author SHA1 Message Date
dingusdevandjoevt e1a0adde8b Fixing compilation
Co-Authored-By: joevt <[email protected]>
2024-12-21 14:06:40 -07:00
dingusdev c25ad96e3a initial attempt to remove global variable exec_flags 2024-12-20 21:25:50 -07:00
93 changed files with 1758 additions and 2172 deletions

No files matched your search

+3 -2
View File
@@ -28,9 +28,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <debugger/debugger.h> #include <debugger/debugger.h>
#if defined(PPC_BENCHMARKS) #if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) { uint32_t ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags) {
power_on = false; power_on = false;
power_off_reason = po_benchmark_exception; power_off_reason = po_benchmark_exception;
return 0;
} }
#endif #endif
@@ -105,7 +106,7 @@ int main(int argc, char** argv) {
ppc_state.gpr[3] = 0x1000; // buf ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = test_size; // len ppc_state.gpr[4] = test_size; // len
ppc_state.gpr[5] = 0; // sum ppc_state.gpr[5] = 0; // sum
enter_debugger(); DppcDebugger::get_instance()->enter_debugger();
#endif #endif
ppc_state.pc = 0; ppc_state.pc = 0;
+2 -13
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -73,17 +73,6 @@ public:
uint16_t keys_state; uint16_t keys_state;
}; };
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,
};
/* AppleJack bits 3-7 are supported but unused */ /* AppleJack bits 3-7 are supported but unused */
enum GamepadButton : uint8_t { enum GamepadButton : uint8_t {
Red = 14, Red = 14,
@@ -123,7 +112,7 @@ public:
return event_manager; return event_manager;
}; };
void poll_events(uint32_t kbd_locale); void poll_events();
template <typename T> template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) { void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
+14 -14
View File
@@ -28,10 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager; 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); static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
void EventManager::poll_events(uint32_t kbd_locale) { void EventManager::poll_events()
{
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
@@ -44,7 +45,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_WINDOWEVENT: { case SDL_WINDOWEVENT: {
WindowEvent we{}; WindowEvent we;
we.sub_type = event.window.event; we.sub_type = event.window.event;
we.window_id = event.window.windowID; we.window_id = event.window.windowID;
this->_window_signal.emit(we); this->_window_signal.emit(we);
@@ -64,16 +65,16 @@ void EventManager::poll_events(uint32_t kbd_locale) {
// Control-S: scale quality // Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) { if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) { if (event.type == SDL_KEYUP) {
WindowEvent we{}; WindowEvent we;
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE; we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID; we.window_id = event.window.windowID;
this->_window_signal.emit(we); this->_window_signal.emit(we);
} }
return; return;
} }
int key_code = get_sdl_event_key_code(event.key, kbd_locale); int key_code = get_sdl_event_key_code(event.key);
if (key_code != -1) { if (key_code != -1) {
KeyboardEvent ke{}; KeyboardEvent ke;
ke.key = key_code; ke.key = key_code;
if (event.type == SDL_KEYDOWN) { if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN; ke.flags = KEYBOARD_EVENT_DOWN;
@@ -95,7 +96,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_MOUSEMOTION: { case SDL_MOUSEMOTION: {
MouseEvent me{}; MouseEvent me;
me.xrel = event.motion.xrel; me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel; me.yrel = event.motion.yrel;
me.xabs = event.motion.x; me.xabs = event.motion.x;
@@ -106,7 +107,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_MOUSEBUTTONDOWN: { case SDL_MOUSEBUTTONDOWN: {
MouseEvent me{}; MouseEvent me;
Uint8 adb_button; Uint8 adb_button;
switch (event.button.button) { switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break; case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -123,7 +124,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_MOUSEBUTTONUP: { case SDL_MOUSEBUTTONUP: {
MouseEvent me{}; MouseEvent me;
Uint8 adb_button; Uint8 adb_button;
switch (event.button.button) { switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break; case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -140,7 +141,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_CONTROLLERBUTTONDOWN: { case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge{}; GamepadEvent ge;
switch (event.cbutton.button) { switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break; case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break; case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -163,7 +164,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break; break;
case SDL_CONTROLLERBUTTONUP: { case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge{}; GamepadEvent ge;
switch (event.cbutton.button) { switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break; case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break; case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -195,7 +196,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
} }
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) { switch (event.keysym.sym) {
case SDLK_a: return AdbKey_A; case SDLK_a: return AdbKey_A;
@@ -330,8 +331,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
//Japanese keyboard //Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3): 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): case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore; return AdbKey_JIS_Underscore;
case 0XBC: case 0XBC:
-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/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <cstdint>
#ifndef MATH_UTILS_H #ifndef MATH_UTILS_H
#define MATH_UTILS_H #define MATH_UTILS_H
+7 -9
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (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 <vector>
#include <mutex> #include <mutex>
constexpr auto NS_PER_SEC = 1000000000; #define NS_PER_SEC 1000000000
constexpr auto USEC_PER_SEC = 1000000; #define USEC_PER_SEC 1000000
constexpr auto NS_PER_USEC = 1000; #define NS_PER_USEC 1000
constexpr auto NS_PER_MSEC = 1000000; #define NS_PER_MSEC 1000000
constexpr auto ONE_BILLION_NS = 1000000000; #define ONE_BILLION_NS 1000000000
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC #define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC #define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
@@ -146,9 +146,7 @@ private:
std::function<void()> notify_timer_changes; std::function<void()> notify_timer_changes;
std::atomic<uint32_t> id{0}; std::atomic<uint32_t> id{0};
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.
// 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
}; };
#endif // TIMER_MANAGER_H #endif // TIMER_MANAGER_H
+120 -90
View File
@@ -35,7 +35,7 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
} }
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_abs(uint32_t opcode) { uint32_t dppc_interpreter::power_abs(uint32_t opcode) {
uint32_t ppc_result_d; uint32_t ppc_result_d;
ppc_grab_regsda(opcode); ppc_grab_regsda(opcode);
if (ppc_result_a == 0x80000000) { if (ppc_result_a == 0x80000000) {
@@ -52,14 +52,15 @@ void dppc_interpreter::power_abs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d); ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_clcs(uint32_t opcode) { uint32_t dppc_interpreter::power_clcs(uint32_t opcode) {
uint32_t ppc_result_d; uint32_t ppc_result_d;
ppc_grab_da(opcode); ppc_grab_da(opcode);
switch (reg_a & 15) { switch (reg_a & 15) {
@@ -83,10 +84,11 @@ void dppc_interpreter::power_clcs(uint32_t opcode) {
} }
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_div(uint32_t opcode) { uint32_t dppc_interpreter::power_div(uint32_t opcode) {
uint32_t ppc_result_d; uint32_t ppc_result_d;
ppc_grab_regsdab(opcode); ppc_grab_regsdab(opcode);
@@ -123,15 +125,16 @@ void dppc_interpreter::power_div(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder; ppc_state.spr[SPR::MQ] = remainder;
return 0;
} }
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_divs(uint32_t opcode) { uint32_t dppc_interpreter::power_divs(uint32_t opcode) {
uint32_t ppc_result_d; uint32_t ppc_result_d;
int32_t remainder; int32_t remainder;
ppc_grab_regsdab(opcode); ppc_grab_regsdab(opcode);
@@ -157,15 +160,16 @@ void dppc_interpreter::power_divs(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder; ppc_state.spr[SPR::MQ] = remainder;
return 0;
} }
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_doz(uint32_t opcode) { uint32_t dppc_interpreter::power_doz(uint32_t opcode) {
ppc_grab_regsdab(opcode); ppc_grab_regsdab(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ? uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
ppc_result_b - ppc_result_a : 0; ppc_result_b - ppc_result_a : 0;
@@ -181,14 +185,15 @@ void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_changecrf0(ppc_result_d); ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_dozi(uint32_t opcode) { uint32_t dppc_interpreter::power_dozi(uint32_t opcode) {
uint32_t ppc_result_d; uint32_t ppc_result_d;
ppc_grab_regsdasimm(opcode); ppc_grab_regsdasimm(opcode);
if (((int32_t)ppc_result_a) > simm) { if (((int32_t)ppc_result_a) > simm) {
@@ -197,10 +202,11 @@ void dppc_interpreter::power_dozi(uint32_t opcode) {
ppc_result_d = simm - ppc_result_a; ppc_result_d = simm - ppc_result_a;
} }
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_lscbx(uint32_t opcode) { uint32_t dppc_interpreter::power_lscbx(uint32_t opcode) {
ppc_grab_regsdab(opcode); ppc_grab_regsdab(opcode);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0); uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
@@ -248,13 +254,15 @@ void dppc_interpreter::power_lscbx(uint32_t opcode) {
(is_match ? CRx_bit::CR_EQ : 0) | (is_match ? CRx_bit::CR_EQ : 0) |
((ppc_state.spr[SPR::XER] & XER::SO) >> 3); ((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
} }
return 0;
} }
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_maskg(uint32_t opcode) { uint32_t dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
uint32_t mask_start = ppc_result_d & 0x1F; uint32_t mask_start = ppc_result_d & 0x1F;
uint32_t mask_end = ppc_result_b & 0x1F; uint32_t mask_end = ppc_result_b & 0x1F;
@@ -276,13 +284,14 @@ void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_maskir(uint32_t opcode) { uint32_t dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b); ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
@@ -290,13 +299,14 @@ void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_mul(uint32_t opcode) { uint32_t dppc_interpreter::power_mul(uint32_t opcode) {
ppc_grab_regsdab(opcode); ppc_grab_regsdab(opcode);
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b); int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32); uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
@@ -311,16 +321,18 @@ void dppc_interpreter::power_mul(uint32_t opcode) {
} }
if (rec) if (rec)
ppc_changecrf0(uint32_t(product)); ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov> template <field_rc rec, field_ov ov>
void dppc_interpreter::power_nabs(uint32_t opcode) { uint32_t dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_grab_regsda(opcode); ppc_grab_regsda(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a; uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
@@ -330,14 +342,15 @@ void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d); ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d); ppc_store_iresult_reg(reg_d, ppc_result_d);
return 0;
} }
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode); template uint32_t dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode); template uint32_t dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_rlmi(uint32_t opcode) { uint32_t dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F; unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F; unsigned rot_me = (opcode >> 1) & 0x1F;
@@ -352,10 +365,11 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_rrib(uint32_t opcode) { uint32_t dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -369,13 +383,14 @@ void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sle(uint32_t opcode) { uint32_t dppc_interpreter::power_sle(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -388,13 +403,14 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sle<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sle<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) { uint32_t dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d; uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
@@ -407,13 +423,14 @@ void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sliq(uint32_t opcode) { uint32_t dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode); ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh; ppc_result_a = ppc_result_d << rot_sh;
@@ -423,13 +440,14 @@ void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) { uint32_t dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode); ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d; 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); uint32_t mask = power_rot_mask(0, 31 - rot_sh);
@@ -441,13 +459,14 @@ void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sllq(uint32_t opcode) { uint32_t dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -461,13 +480,14 @@ void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_slq(uint32_t opcode) { uint32_t dppc_interpreter::power_slq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -482,13 +502,14 @@ void dppc_interpreter::power_slq(uint32_t opcode) {
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d; 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_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_slq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_slq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sraiq(uint32_t opcode) { uint32_t dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode); ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1; uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh; ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
@@ -504,13 +525,14 @@ void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sraq(uint32_t opcode) { uint32_t dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1; uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
@@ -529,13 +551,14 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sre(uint32_t opcode) { uint32_t dppc_interpreter::power_sre(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -547,13 +570,14 @@ void dppc_interpreter::power_sre(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sre<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sre<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_srea(uint32_t opcode) { uint32_t dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh; ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
@@ -571,13 +595,14 @@ void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r; ppc_state.spr[SPR::MQ] = r;
return 0;
} }
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_srea<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_srea<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sreq(uint32_t opcode) { uint32_t dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = -1U >> rot_sh; uint32_t mask = -1U >> rot_sh;
@@ -589,13 +614,14 @@ void dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_sriq(uint32_t opcode) { uint32_t dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode); ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh; ppc_result_a = 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_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
@@ -604,13 +630,14 @@ void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) { uint32_t dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode); ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d; 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); unsigned mask = power_rot_mask(rot_sh, 31);
@@ -622,13 +649,14 @@ void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) { uint32_t dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d; uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
@@ -644,13 +672,14 @@ void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::power_srq(uint32_t opcode) { uint32_t dppc_interpreter::power_srq(uint32_t opcode) {
ppc_grab_regssab(opcode); ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F; unsigned rot_sh = ppc_result_b & 0x1F;
@@ -666,7 +695,8 @@ void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a); ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a); ppc_store_iresult_reg(reg_a, ppc_result_a);
return 0;
} }
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::power_srq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::power_srq<RC1>(uint32_t opcode);
+197 -201
View File
@@ -47,7 +47,7 @@ enum EXEC_MODE:uint32_t {
enum endian_switch { big_end = 0, little_end = 1 }; enum endian_switch { big_end = 0, little_end = 1 };
typedef void (*PPCOpcode)(uint32_t opcode); typedef uint32_t (*PPCOpcode)(uint32_t opcode);
union FPR_storage { union FPR_storage {
double dbl64_r; // double floating-point representation double dbl64_r; // double floating-point representation
@@ -182,10 +182,9 @@ extern uint32_t rtc_lo, rtc_hi;
/* Flags for controlling interpreter execution. */ /* Flags for controlling interpreter execution. */
enum { enum {
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2, // RFI instruction executed EXEF_RFI = 1 << 2,
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
}; };
enum CR_select : int32_t { enum CR_select : int32_t {
@@ -300,8 +299,6 @@ enum Exc_Cause : uint32_t {
TRAP = 1 << (31 - 14), TRAP = 1 << (31 - 14),
}; };
extern unsigned exec_flags;
extern jmp_buf exc_env; extern jmp_buf exc_env;
enum Po_Cause : int { enum Po_Cause : int {
@@ -327,8 +324,7 @@ extern bool int_pin;
extern bool dec_exception_pending; extern bool dec_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras extern bool include_601; // For non-PowerPC 601 emulation with 601 extras (matches Mac OS 9 environment which can emulate MPC 601 instructions)
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool is_altivec; // For Altivec Emulation extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation extern bool is_64bit; // For PowerPC G5 Emulation
@@ -410,7 +406,7 @@ constexpr uint32_t NO_OPCODE = 0;
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq); extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
extern void ppc_mmu_init(); extern void ppc_mmu_init();
void ppc_illegalop(uint32_t opcode); uint32_t ppc_illegalop(uint32_t opcode);
void ppc_assert_int(); void ppc_assert_int();
void ppc_release_int(); void ppc_release_int();
@@ -421,8 +417,10 @@ void set_host_rounding_mode(uint8_t mode);
void update_fpscr(uint32_t new_fpscr); void update_fpscr(uint32_t new_fpscr);
/* Exception handlers. */ /* Exception handlers. */
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits); uint32_t ppc_exception_handler(
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits); Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags = 0);
[[noreturn]] uint32_t dbg_exception_handler(
Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags);
void ppc_floating_point_exception(uint32_t opcode); void ppc_floating_point_exception(uint32_t opcode);
void ppc_alignment_exception(uint32_t opcode, uint32_t ea); void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
@@ -435,203 +433,203 @@ extern void do_ctx_sync(void);
// The functions used by the PowerPC processor // The functions used by the PowerPC processor
namespace dppc_interpreter { namespace dppc_interpreter {
template <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode); template <field_lk l, field_601 for601> extern uint32_t ppc_bcctr(uint32_t opcode);
template <field_lk l> extern void ppc_bclr(uint32_t opcode); template <field_lk l> extern uint32_t ppc_bclr(uint32_t opcode);
extern void ppc_crand(uint32_t opcode); extern uint32_t ppc_crand(uint32_t opcode);
extern void ppc_crandc(uint32_t opcode); extern uint32_t ppc_crandc(uint32_t opcode);
extern void ppc_creqv(uint32_t opcode); extern uint32_t ppc_creqv(uint32_t opcode);
extern void ppc_crnand(uint32_t opcode); extern uint32_t ppc_crnand(uint32_t opcode);
extern void ppc_crnor(uint32_t opcode); extern uint32_t ppc_crnor(uint32_t opcode);
extern void ppc_cror(uint32_t opcode); extern uint32_t ppc_cror(uint32_t opcode);
extern void ppc_crorc(uint32_t opcode); extern uint32_t ppc_crorc(uint32_t opcode);
extern void ppc_crxor(uint32_t opcode); extern uint32_t ppc_crxor(uint32_t opcode);
extern void ppc_isync(uint32_t opcode); extern uint32_t ppc_isync(uint32_t opcode);
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode); template <logical_fun logical_op, field_rc rec> extern uint32_t ppc_logical(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add(uint32_t opcode); template <field_carry carry, field_rc rec, field_ov ov> extern uint32_t ppc_add(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_adde(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_adde(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_addme(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_addme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_addze(uint32_t opcode);
extern void ppc_cmp(uint32_t opcode); extern uint32_t ppc_cmp(uint32_t opcode);
extern void ppc_cmpl(uint32_t opcode); extern uint32_t ppc_cmpl(uint32_t opcode);
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_cntlzw(uint32_t opcode);
extern void ppc_dcbf(uint32_t opcode); extern uint32_t ppc_dcbf(uint32_t opcode);
extern void ppc_dcbi(uint32_t opcode); extern uint32_t ppc_dcbi(uint32_t opcode);
extern void ppc_dcbst(uint32_t opcode); extern uint32_t ppc_dcbst(uint32_t opcode);
extern void ppc_dcbt(uint32_t opcode); extern uint32_t ppc_dcbt(uint32_t opcode);
extern void ppc_dcbtst(uint32_t opcode); extern uint32_t ppc_dcbtst(uint32_t opcode);
extern void ppc_dcbz(uint32_t opcode); extern uint32_t ppc_dcbz(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_divw(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_divw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_divwu(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_divwu(uint32_t opcode);
extern void ppc_eciwx(uint32_t opcode); extern uint32_t ppc_eciwx(uint32_t opcode);
extern void ppc_ecowx(uint32_t opcode); extern uint32_t ppc_ecowx(uint32_t opcode);
extern void ppc_eieio(uint32_t opcode); extern uint32_t ppc_eieio(uint32_t opcode);
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode); template <class T, field_rc rec>extern uint32_t ppc_exts(uint32_t opcode);
extern void ppc_icbi(uint32_t opcode); extern uint32_t ppc_icbi(uint32_t opcode);
extern void ppc_mftb(uint32_t opcode); extern uint32_t ppc_mftb(uint32_t opcode);
extern void ppc_lhaux(uint32_t opcode); extern uint32_t ppc_lhaux(uint32_t opcode);
extern void ppc_lhax(uint32_t opcode); extern uint32_t ppc_lhax(uint32_t opcode);
extern void ppc_lhbrx(uint32_t opcode); extern uint32_t ppc_lhbrx(uint32_t opcode);
extern void ppc_lwarx(uint32_t opcode); extern uint32_t ppc_lwarx(uint32_t opcode);
extern void ppc_lwbrx(uint32_t opcode); extern uint32_t ppc_lwbrx(uint32_t opcode);
template <class T> extern void ppc_lzx(uint32_t opcode); template <class T> extern uint32_t ppc_lzx(uint32_t opcode);
template <class T> extern void ppc_lzux(uint32_t opcode); template <class T> extern uint32_t ppc_lzux(uint32_t opcode);
extern void ppc_mcrxr(uint32_t opcode); extern uint32_t ppc_mcrxr(uint32_t opcode);
extern void ppc_mfcr(uint32_t opcode); extern uint32_t ppc_mfcr(uint32_t opcode);
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mulhwu(uint32_t opcode);
template <field_rc rec> extern void ppc_mulhw(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mulhw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_mullw(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_mullw(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_neg(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_neg(uint32_t opcode);
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode); template <field_direction shift, field_rc rec> extern uint32_t ppc_shift(uint32_t opcode);
template <field_rc rec> extern void ppc_sraw(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_sraw(uint32_t opcode);
template <field_rc rec> extern void ppc_srawi(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_srawi(uint32_t opcode);
template <class T> extern void ppc_stx(uint32_t opcode); template <class T> extern uint32_t ppc_stx(uint32_t opcode);
template <class T> extern void ppc_stux(uint32_t opcode); template <class T> extern uint32_t ppc_stux(uint32_t opcode);
extern void ppc_stfiwx(uint32_t opcode); extern uint32_t ppc_stfiwx(uint32_t opcode);
extern void ppc_sthbrx(uint32_t opcode); extern uint32_t ppc_sthbrx(uint32_t opcode);
extern void ppc_stwcx(uint32_t opcode); extern uint32_t ppc_stwcx(uint32_t opcode);
extern void ppc_stwbrx(uint32_t opcode); extern uint32_t ppc_stwbrx(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf(uint32_t opcode); template <field_carry carry, field_rc rec, field_ov ov> extern uint32_t ppc_subf(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfe(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_subfe(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfme(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_subfme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t ppc_subfze(uint32_t opcode);
extern void ppc_sync(uint32_t opcode); extern uint32_t ppc_sync(uint32_t opcode);
extern void ppc_tlbia(uint32_t opcode); extern uint32_t ppc_tlbia(uint32_t opcode);
extern void ppc_tlbie(uint32_t opcode); extern uint32_t ppc_tlbie(uint32_t opcode);
extern void ppc_tlbli(uint32_t opcode); extern uint32_t ppc_tlbli(uint32_t opcode);
extern void ppc_tlbld(uint32_t opcode); extern uint32_t ppc_tlbld(uint32_t opcode);
extern void ppc_tlbsync(uint32_t opcode); extern uint32_t ppc_tlbsync(uint32_t opcode);
extern void ppc_tw(uint32_t opcode); extern uint32_t ppc_tw(uint32_t opcode);
extern void ppc_lswi(uint32_t opcode); extern uint32_t ppc_lswi(uint32_t opcode);
extern void ppc_lswx(uint32_t opcode); extern uint32_t ppc_lswx(uint32_t opcode);
extern void ppc_stswi(uint32_t opcode); extern uint32_t ppc_stswi(uint32_t opcode);
extern void ppc_stswx(uint32_t opcode); extern uint32_t ppc_stswx(uint32_t opcode);
extern void ppc_mfsr(uint32_t opcode); extern uint32_t ppc_mfsr(uint32_t opcode);
extern void ppc_mfsrin(uint32_t opcode); extern uint32_t ppc_mfsrin(uint32_t opcode);
extern void ppc_mtsr(uint32_t opcode); extern uint32_t ppc_mtsr(uint32_t opcode);
extern void ppc_mtsrin(uint32_t opcode); extern uint32_t ppc_mtsrin(uint32_t opcode);
extern void ppc_mcrf(uint32_t opcode); extern uint32_t ppc_mcrf(uint32_t opcode);
extern void ppc_mtcrf(uint32_t opcode); extern uint32_t ppc_mtcrf(uint32_t opcode);
extern void ppc_mfmsr(uint32_t opcode); extern uint32_t ppc_mfmsr(uint32_t opcode);
extern void ppc_mfspr(uint32_t opcode); extern uint32_t ppc_mfspr(uint32_t opcode);
extern void ppc_mtmsr(uint32_t opcode); extern uint32_t ppc_mtmsr(uint32_t opcode);
extern void ppc_mtspr(uint32_t opcode); extern uint32_t ppc_mtspr(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb0(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mtfsb0(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mtfsb1(uint32_t opcode);
extern void ppc_mcrfs(uint32_t opcode); extern uint32_t ppc_mcrfs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmr(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmr(uint32_t opcode);
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode); template <field_601 for601, field_rc rec> extern uint32_t ppc_mffs(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mtfsf(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_mtfsfi(uint32_t opcode);
template <field_shift shift> extern void ppc_addi(uint32_t opcode); template <field_shift shift> extern uint32_t ppc_addi(uint32_t opcode);
template <field_rc rec> extern void ppc_addic(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_addic(uint32_t opcode);
template <field_shift shift> extern void ppc_andirc(uint32_t opcode); template <field_shift shift> extern uint32_t ppc_andirc(uint32_t opcode);
template <field_lk l, field_aa a> extern void ppc_b(uint32_t opcode); template <field_lk l, field_aa a> extern uint32_t ppc_b(uint32_t opcode);
template <field_lk l, field_aa a> extern void ppc_bc(uint32_t opcode); template <field_lk l, field_aa a> extern uint32_t ppc_bc(uint32_t opcode);
extern void ppc_cmpi(uint32_t opcode); extern uint32_t ppc_cmpi(uint32_t opcode);
extern void ppc_cmpli(uint32_t opcode); extern uint32_t ppc_cmpli(uint32_t opcode);
template <class T> extern void ppc_lz(uint32_t opcode); template <class T> extern uint32_t ppc_lz(uint32_t opcode);
template <class T> extern void ppc_lzu(uint32_t opcode); template <class T> extern uint32_t ppc_lzu(uint32_t opcode);
extern void ppc_lha(uint32_t opcode); extern uint32_t ppc_lha(uint32_t opcode);
extern void ppc_lhau(uint32_t opcode); extern uint32_t ppc_lhau(uint32_t opcode);
extern void ppc_lmw(uint32_t opcode); extern uint32_t ppc_lmw(uint32_t opcode);
extern void ppc_mulli(uint32_t opcode); extern uint32_t ppc_mulli(uint32_t opcode);
template <field_shift shift> extern void ppc_ori(uint32_t opcode); template <field_shift shift> extern uint32_t ppc_ori(uint32_t opcode);
extern void ppc_rfi(uint32_t opcode); extern uint32_t ppc_rfi(uint32_t opcode);
extern void ppc_rlwimi(uint32_t opcode); extern uint32_t ppc_rlwimi(uint32_t opcode);
extern void ppc_rlwinm(uint32_t opcode); extern uint32_t ppc_rlwinm(uint32_t opcode);
extern void ppc_rlwnm(uint32_t opcode); extern uint32_t ppc_rlwnm(uint32_t opcode);
extern void ppc_sc(uint32_t opcode); extern uint32_t ppc_sc(uint32_t opcode);
template <class T> extern void ppc_st(uint32_t opcode); template <class T> extern uint32_t ppc_st(uint32_t opcode);
template <class T> extern void ppc_stu(uint32_t opcode); template <class T> extern uint32_t ppc_stu(uint32_t opcode);
extern void ppc_stmw(uint32_t opcode); extern uint32_t ppc_stmw(uint32_t opcode);
extern void ppc_subfic(uint32_t opcode); extern uint32_t ppc_subfic(uint32_t opcode);
extern void ppc_twi(uint32_t opcode); extern uint32_t ppc_twi(uint32_t opcode);
template <field_shift shift> extern void ppc_xori(uint32_t opcode); template <field_shift shift> extern uint32_t ppc_xori(uint32_t opcode);
extern void ppc_lfs(uint32_t opcode); extern uint32_t ppc_lfs(uint32_t opcode);
extern void ppc_lfsu(uint32_t opcode); extern uint32_t ppc_lfsu(uint32_t opcode);
extern void ppc_lfsx(uint32_t opcode); extern uint32_t ppc_lfsx(uint32_t opcode);
extern void ppc_lfsux(uint32_t opcode); extern uint32_t ppc_lfsux(uint32_t opcode);
extern void ppc_lfd(uint32_t opcode); extern uint32_t ppc_lfd(uint32_t opcode);
extern void ppc_lfdu(uint32_t opcode); extern uint32_t ppc_lfdu(uint32_t opcode);
extern void ppc_lfdx(uint32_t opcode); extern uint32_t ppc_lfdx(uint32_t opcode);
extern void ppc_lfdux(uint32_t opcode); extern uint32_t ppc_lfdux(uint32_t opcode);
extern void ppc_stfs(uint32_t opcode); extern uint32_t ppc_stfs(uint32_t opcode);
extern void ppc_stfsu(uint32_t opcode); extern uint32_t ppc_stfsu(uint32_t opcode);
extern void ppc_stfsx(uint32_t opcode); extern uint32_t ppc_stfsx(uint32_t opcode);
extern void ppc_stfsux(uint32_t opcode); extern uint32_t ppc_stfsux(uint32_t opcode);
extern void ppc_stfd(uint32_t opcode); extern uint32_t ppc_stfd(uint32_t opcode);
extern void ppc_stfdu(uint32_t opcode); extern uint32_t ppc_stfdu(uint32_t opcode);
extern void ppc_stfdx(uint32_t opcode); extern uint32_t ppc_stfdx(uint32_t opcode);
extern void ppc_stfdux(uint32_t opcode); extern uint32_t ppc_stfdux(uint32_t opcode);
template <field_rc rec> extern void ppc_fadd(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fsub(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmul(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmul(uint32_t opcode);
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fdiv(uint32_t opcode);
template <field_rc rec> extern void ppc_fadds(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmuls(uint32_t opcode);
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fdivs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fnmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fnmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fnmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fnmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fabs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fnabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fneg(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fneg(uint32_t opcode);
template <field_rc rec> extern void ppc_fsel(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fsel(uint32_t opcode);
template <field_rc rec> extern void ppc_fres(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fres(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fsqrts(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fsqrt(uint32_t opcode);
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_frsqrte(uint32_t opcode);
template <field_rc rec> extern void ppc_frsp(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_frsp(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fctiw(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode); template <field_rc rec> extern uint32_t ppc_fctiwz(uint32_t opcode);
extern void ppc_fcmpo(uint32_t opcode); extern uint32_t ppc_fcmpo(uint32_t opcode);
extern void ppc_fcmpu(uint32_t opcode); extern uint32_t ppc_fcmpu(uint32_t opcode);
// Power-specific instructions // Power-specific instructions
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_abs(uint32_t opcode);
extern void power_clcs(uint32_t opcode); extern uint32_t power_clcs(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_div(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_div(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_divs(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_divs(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_doz(uint32_t opcode);
extern void power_dozi(uint32_t opcode); extern uint32_t power_dozi(uint32_t opcode);
template <field_rc rec> extern void power_lscbx(uint32_t opcode); template <field_rc rec> extern uint32_t power_lscbx(uint32_t opcode);
template <field_rc rec> extern void power_maskg(uint32_t opcode); template <field_rc rec> extern uint32_t power_maskg(uint32_t opcode);
template <field_rc rec> extern void power_maskir(uint32_t opcode); template <field_rc rec> extern uint32_t power_maskir(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_mul(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_mul(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_nabs(uint32_t opcode); template <field_rc rec, field_ov ov> extern uint32_t power_nabs(uint32_t opcode);
extern void power_rlmi(uint32_t opcode); extern uint32_t power_rlmi(uint32_t opcode);
template <field_rc rec> extern void power_rrib(uint32_t opcode); template <field_rc rec> extern uint32_t power_rrib(uint32_t opcode);
template <field_rc rec> extern void power_sle(uint32_t opcode); template <field_rc rec> extern uint32_t power_sle(uint32_t opcode);
template <field_rc rec> extern void power_sleq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sleq(uint32_t opcode);
template <field_rc rec> extern void power_sliq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sliq(uint32_t opcode);
template <field_rc rec> extern void power_slliq(uint32_t opcode); template <field_rc rec> extern uint32_t power_slliq(uint32_t opcode);
template <field_rc rec> extern void power_sllq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sllq(uint32_t opcode);
template <field_rc rec> extern void power_slq(uint32_t opcode); template <field_rc rec> extern uint32_t power_slq(uint32_t opcode);
template <field_rc rec> extern void power_sraiq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sraiq(uint32_t opcode);
template <field_rc rec> extern void power_sraq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sraq(uint32_t opcode);
template <field_rc rec> extern void power_sre(uint32_t opcode); template <field_rc rec> extern uint32_t power_sre(uint32_t opcode);
template <field_rc rec> extern void power_srea(uint32_t opcode); template <field_rc rec> extern uint32_t power_srea(uint32_t opcode);
template <field_rc rec> extern void power_sreq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sreq(uint32_t opcode);
template <field_rc rec> extern void power_sriq(uint32_t opcode); template <field_rc rec> extern uint32_t power_sriq(uint32_t opcode);
template <field_rc rec> extern void power_srliq(uint32_t opcode); template <field_rc rec> extern uint32_t power_srliq(uint32_t opcode);
template <field_rc rec> extern void power_srlq(uint32_t opcode); template <field_rc rec> extern uint32_t power_srlq(uint32_t opcode);
template <field_rc rec> extern void power_srq(uint32_t opcode); template <field_rc rec> extern uint32_t power_srq(uint32_t opcode);
} // namespace dppc_interpreter } // namespace dppc_interpreter
// AltiVec instructions // AltiVec instructions
@@ -642,16 +640,14 @@ template <field_rc rec> extern void power_srq(uint32_t opcode);
extern uint64_t get_virt_time_ns(void); extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode); extern uint32_t ppc_main_opcode(uint32_t opcode);
extern void ppc_exec(void); extern void ppc_exec(void);
extern void ppc_exec_single(void); extern void ppc_exec_single(void);
extern void ppc_exec_until(uint32_t goal_addr); extern void ppc_exec_until(uint32_t goal_addr);
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size); 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 */ /* 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 */ 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 */ void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
+10 -13
View File
@@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
jmp_buf exc_env; /* Global exception environment. */ jmp_buf exc_env; /* Global exception environment. */
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS) #if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) { uint32_t ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags) {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
exceptions_processed++; exceptions_processed++;
#endif #endif
@@ -57,7 +57,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break; break;
case Except_Type::EXC_ISI: case Except_Type::EXC_ISI:
if (exec_flags & ~EXEF_OPC_DECODER) { if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address; ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else { } else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL; ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
@@ -66,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break; break;
case Except_Type::EXC_EXT_INT: case Except_Type::EXC_EXT_INT:
if (exec_flags & ~EXEF_OPC_DECODER) { if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address; ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else { } else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4; ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -90,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break; break;
case Except_Type::EXC_DECR: case Except_Type::EXC_DECR:
if (exec_flags & ~EXEF_OPC_DECODER) { if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address; ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else { } else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4; ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -114,14 +114,9 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
} }
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits; ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
uint32_t old_msr_val = ppc_state.msr; ppc_state.msr &= 0xFFFB1041;
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */ /* copy MSR[ILE] to MSR[LE] */
if (!is_601) { ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
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);
if (ppc_state.msr & MSR::IP) { if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000; ppc_next_instruction_address |= 0xFFF00000;
@@ -140,10 +135,12 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
if (exception_type != Except_Type::EXC_EXT_INT && exception_type != Except_Type::EXC_DECR) { if (exception_type != Except_Type::EXC_EXT_INT && exception_type != Except_Type::EXC_DECR) {
longjmp(exc_env, 2); /* return to the main execution loop. */ longjmp(exc_env, 2); /* return to the main execution loop. */
} }
return exec_flags;
} }
#endif #endif
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) { [[noreturn]] uint32_t dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags) {
std::string exc_descriptor; std::string exc_descriptor;
switch (exception_type) { switch (exception_type) {
@@ -316,5 +313,5 @@ unexpected_instruction:
ppc_state.spr[SPR::DSISR] = dsisr; ppc_state.spr[SPR::DSISR] = dsisr;
ppc_state.spr[SPR::DAR] = ea; ppc_state.spr[SPR::DAR] = ea;
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0); ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0, 0);
} }
+56 -130
View File
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcdisasm.h" #include "ppcdisasm.h"
#include <algorithm> #include <algorithm>
#include <chrono>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <map> #include <map>
@@ -68,7 +67,6 @@ SetPRS ppc_state;
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA 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; // FIXME: exec_timer is read by main thread ppc_main_opcode;
// written by audio dbdma DMAChannel::update_irq .. add_immediate_timer // written by audio dbdma DMAChannel::update_irq .. add_immediate_timer
volatile bool exec_timer; volatile bool exec_timer;
@@ -154,12 +152,9 @@ public:
op_name_counts.emplace_back(op_name, pair.second); op_name_counts.emplace_back(op_name, pair.second);
} }
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20)); size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
std::partial_sort( std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), return b.second < a.second;
[](const auto& a, const auto& b) { });
return b.second < a.second;
}
);
op_name_counts.resize(top_ops_size); op_name_counts.resize(top_ops_size);
for (const auto& pair : op_name_counts) { for (const auto& pair : op_name_counts) {
vars.push_back({.name = "Instruction " + pair.first, vars.push_back({.name = "Instruction " + pair.first,
@@ -188,48 +183,17 @@ public:
primary opcode (bits 0...5) and modifier (bits 21...31). */ primary opcode (bits 0...5) and modifier (bits 21...31). */
static PPCOpcode OpcodeGrabber[64 * 2048]; 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. */ /** Exception helpers. */
void ppc_illegalop(uint32_t opcode) { uint32_t ppc_illegalop(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); return ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
}
void ppc_fpu_off(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_NO_FPU, Exc_Cause::FPU_OFF);
} }
void ppc_assert_int() { void ppc_assert_int() {
int_pin = true; int_pin = true;
if (ppc_state.msr & MSR::EE) { if (ppc_state.msr & MSR::EE) {
LOG_F(5, "CPU ExtIntHandler called"); LOG_F(5, "CPU ExtIntHandler called");
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0); ppc_exception_handler(Except_Type::EXC_EXT_INT, 0, 0);
} else { } else {
LOG_F(5, "CPU IRQ ignored!"); LOG_F(5, "CPU IRQ ignored!");
} }
@@ -242,7 +206,7 @@ void ppc_release_int() {
/** Opcode decoding functions. */ /** Opcode decoding functions. */
/* Dispatch using primary and modifier opcode */ /* Dispatch using primary and modifier opcode */
void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode) uint32_t ppc_main_opcode(uint32_t opcode)
{ {
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
num_executed_instrs++; num_executed_instrs++;
@@ -250,7 +214,7 @@ void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
num_opcodes[opcode]++; num_opcodes[opcode]++;
#endif #endif
#endif #endif
opcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode); return OpcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
} }
static long long cpu_now_ns() { static long long cpu_now_ns() {
@@ -302,7 +266,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
uint64_t max_cycles = 0; uint64_t max_cycles = 0;
uint32_t page_start, eb_start, eb_end = 0; uint32_t page_start, eb_start, eb_end = 0;
uint32_t opcode; uint32_t opcode;
PPCOpcode* opcode_grabber = ppc_opcode_grabber; uint32_t exec_flags; // execution control flags
uint8_t* pc_real; uint8_t* pc_real;
while (power_on) { while (power_on) {
@@ -316,19 +280,15 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
eb_start = ppc_state.pc; eb_start = ppc_state.pc;
page_start = eb_start & PPC_PAGE_MASK; page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1; eb_end = page_start + PPC_PAGE_SIZE - 1;
exec_flags = 0;
pc_real = mmu_translate_imem(eb_start); pc_real = mmu_translate_imem(eb_start);
} }
opcode = ppc_read_instruction(pc_real); opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode_grabber, opcode); exec_flags = ppc_main_opcode(opcode);
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]] if (g_icycles++ >= max_cycles || exec_timer)
max_cycles = process_events(); max_cycles = process_events();
if (exec_flags) { if (exec_flags) {
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
opcode_grabber = ppc_opcode_grabber;
}
// define next execution block // define next execution block
eb_start = ppc_next_instruction_address; eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) { if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
@@ -339,7 +299,6 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
pc_real = mmu_translate_imem(eb_start); pc_real = mmu_translate_imem(eb_start);
} }
ppc_state.pc = eb_start; ppc_state.pc = eb_start;
exec_flags = 0;
} else { [[likely]] } else { [[likely]]
ppc_state.pc += 4; ppc_state.pc += 4;
pc_real += 4; pc_real += 4;
@@ -373,23 +332,23 @@ void ppc_exec()
/** Execute one PPC instruction. */ /** Execute one PPC instruction. */
void ppc_exec_single() void ppc_exec_single()
{ {
uint32_t exec_flags = 0;
if (setjmp(exc_env)) { if (setjmp(exc_env)) {
// process low-level exceptions // process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!"); //LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address; ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
return; return;
} }
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc); uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
uint32_t opcode = ppc_read_instruction(pc_real); uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(ppc_opcode_grabber, opcode); exec_flags = ppc_main_opcode(opcode);
g_icycles++; g_icycles++;
process_events(); process_events();
if (exec_flags) { if (exec_flags) {
ppc_state.pc = ppc_next_instruction_address; ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
} else { } else {
ppc_state.pc += 4; ppc_state.pc += 4;
} }
@@ -401,10 +360,11 @@ void ppc_exec_single()
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size); template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
// outer interpreter loop // 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)) { if (setjmp(exc_env)) {
// process low-level exceptions // process low-level exceptions
// LOG_F(9, "PPC-EXEC: low_level exception raised!"); //LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address; ppc_state.pc = ppc_next_instruction_address;
} }
@@ -452,39 +412,17 @@ for (uint32_t mod = 0; mod < 2048; mod++) { \
} \ } \
} while (0) } while (0)
#define OP_fp(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | mod] = ppc_fpu_off; \
} \
} while (0)
#define OPX(opcode, subopcode, fn) \ #define OPX(opcode, subopcode, fn) \
do { \ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0) } while (0)
#define OPX_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1)] = ppc_fpu_off; \
} while (0)
#define OPXd(opcode, subopcode, fn) \ #define OPXd(opcode, subopcode, fn) \
do { \ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
} while (0) } while (0)
#define OPXd_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
} while (0)
#define OPXod(opcode, subopcode, fn) \ #define OPXod(opcode, subopcode, fn) \
do { \ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
@@ -499,14 +437,6 @@ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
} while (0) } while (0)
#define OPXdc_fp(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \ #define OPXcod(opcode, subopcode, fn, carry) \
do { \ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \ OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
@@ -528,33 +458,36 @@ do { \
} while (0) } while (0)
#define OP31(subopcode, fn) OPX(31, subopcode, fn) #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 OP31d(subopcode, fn) OPXd(31, subopcode, fn)
#define OP31od(subopcode, fn) OPXod(31, subopcode, fn) #define OP31od(subopcode, fn) OPXod(31, subopcode, fn)
#define OP31dc(subopcode, fn, carry) OPXdc(31, subopcode, fn, carry) #define OP31dc(subopcode, fn, carry) OPXdc(31, subopcode, fn, carry)
#define OP31cod(subopcode, fn, carry) OPXcod(31, subopcode, fn, carry) #define OP31cod(subopcode, fn, carry) OPXcod(31, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX_fp(63, subopcode, fn) #define OP63(subopcode, fn) OPX(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn) #define OP63d(subopcode, fn) OPXd(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry) #define OP63dc(subopcode, fn, carry) OPXdc(63, subopcode, fn, carry)
#define OP59d(subopcode, fn) \ #define OP59d(subopcode, fn) \
do { \ do { \
OPXd_fp(59, (subopcode), fn); \ OPXd(59, (subopcode), fn); \
} while (0) } while (0)
#define OP59cd(subopcode, fn) \ #define OP59cd(subopcode, fn) \
do { \ do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \ 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) } while (0)
void initialize_ppc_opcode_table() { void initialize_ppc_opcode_table() {
auto opcodeGrabberSize = sizeof(OpcodeGrabber) / sizeof(OpcodeGrabber[0]); std::fill_n(OpcodeGrabber, 64 * 2048, ppc_illegalop);
std::fill_n(OpcodeGrabber, opcodeGrabberSize, ppc_illegalop);
std::fill_n(OpcodeGrabberNoFPU, opcodeGrabberSize, ppc_illegalop);
OP(3, ppc_twi); OP(3, ppc_twi);
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented. //OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
OP(7, ppc_mulli); OP(7, ppc_mulli);
@@ -593,14 +526,14 @@ void initialize_ppc_opcode_table() {
OP(45, ppc_stu<uint16_t>); OP(45, ppc_stu<uint16_t>);
OP(46, ppc_lmw); OP(46, ppc_lmw);
OP(47, ppc_stmw); OP(47, ppc_stmw);
OP_fp(48, ppc_lfs); OP(48, ppc_lfs);
OP_fp(49, ppc_lfsu); OP(49, ppc_lfsu);
OP_fp(50, ppc_lfd); OP(50, ppc_lfd);
OP_fp(51, ppc_lfdu); OP(51, ppc_lfdu);
OP_fp(52, ppc_stfs); OP(52, ppc_stfs);
OP_fp(53, ppc_stfsu); OP(53, ppc_stfsu);
OP_fp(54, ppc_stfd); OP(54, ppc_stfd);
OP_fp(55, ppc_stfdu); OP(55, ppc_stfdu);
OPla(16, 0x0, (dppc_interpreter::ppc_bc<LK0, AA0>)); // bc OPla(16, 0x0, (dppc_interpreter::ppc_bc<LK0, AA0>)); // bc
OPla(16, 0x1, (dppc_interpreter::ppc_bc<LK1, AA0>)); // bcl OPla(16, 0x1, (dppc_interpreter::ppc_bc<LK1, AA0>)); // bcl
@@ -662,11 +595,11 @@ void initialize_ppc_opcode_table() {
OP31(375, ppc_lhaux); OP31(375, ppc_lhaux);
OP31(533, ppc_lswx); OP31(533, ppc_lswx);
OP31(534, ppc_lwbrx); OP31(534, ppc_lwbrx);
OP31_fp(535, ppc_lfsx); OP31(535, ppc_lfsx);
OP31_fp(567, ppc_lfsux); OP31(567, ppc_lfsux);
OP31(597, ppc_lswi); OP31(597, ppc_lswi);
OP31_fp(599, ppc_lfdx); OP31(599, ppc_lfdx);
OP31_fp(631, ppc_lfdux); OP31(631, ppc_lfdux);
OP31(790, ppc_lhbrx); OP31(790, ppc_lhbrx);
OPr(31, (150<<1) | 1, ppc_stwcx); // No Rc=0 variant. OPr(31, (150<<1) | 1, ppc_stwcx); // No Rc=0 variant.
@@ -678,13 +611,13 @@ void initialize_ppc_opcode_table() {
OP31(439, ppc_stux<uint16_t>); OP31(439, ppc_stux<uint16_t>);
OP31(661, ppc_stswx); OP31(661, ppc_stswx);
OP31(662, ppc_stwbrx); OP31(662, ppc_stwbrx);
OP31_fp(663, ppc_stfsx); OP31(663, ppc_stfsx);
OP31_fp(695, ppc_stfsux); OP31(695, ppc_stfsux);
OP31(725, ppc_stswi); OP31(725, ppc_stswi);
OP31_fp(727, ppc_stfdx); OP31(727, ppc_stfdx);
OP31_fp(759, ppc_stfdux); OP31(759, ppc_stfdux);
OP31(918, ppc_sthbrx); OP31(918, ppc_sthbrx);
if (!is_601) OP31_fp(983, ppc_stfiwx); if (!is_601) OP31(983, ppc_stfiwx);
OP31(310, ppc_eciwx); OP31(310, ppc_eciwx);
OP31(438, ppc_ecowx); OP31(438, ppc_ecowx);
@@ -804,12 +737,6 @@ void initialize_ppc_opcode_table() {
OP63d(i + 30, ppc_fnmsub); OP63d(i + 30, ppc_fnmsub);
OP63d(i + 31, ppc_fnmadd); 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) void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_601, uint64_t tb_freq)
@@ -843,22 +770,19 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC; tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq; tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq;
exec_flags = 0;
exec_timer = false; exec_timer = false;
timebase_counter = 0; timebase_counter = 0;
dec_wr_value = 0; dec_wr_value = 0;
uint32_t new_msr_val;
if (is_601) { if (is_601) {
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */ /* 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 { } else {
new_msr_val = MSR::IP; ppc_state.msr = MSR::IP;
ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL; ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL;
} }
ppc_msr_did_change(new_msr_val, new_msr_val, false);
ppc_mmu_init(); ppc_mmu_init();
@@ -871,6 +795,11 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif #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 = { static map<string, int> SPRName2Num = {
{"XER", SPR::XER}, {"LR", SPR::LR}, {"CTR", SPR::CTR}, {"XER", SPR::XER}, {"LR", SPR::LR}, {"CTR", SPR::CTR},
{"DEC", SPR::DEC_S}, {"PVR", SPR::PVR}, {"SPRG0", SPR::SPRG0}, {"DEC", SPR::DEC_S}, {"PVR", SPR::PVR}, {"SPRG0", SPR::SPRG0},
@@ -913,11 +842,8 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
return ppc_state.pc; return ppc_state.pc;
} }
if (reg_name_u == "MSR") { if (reg_name_u == "MSR") {
if (is_write) { if (is_write)
uint32_t old_msr_val = ppc_state.msr; ppc_state.msr = (uint32_t)val;
uint32_t new_msr_val = (uint32_t)val;
ppc_msr_did_change(old_msr_val, new_msr_val, false);
}
return ppc_state.msr; return ppc_state.msr;
} }
if (reg_name_u == "CR") { if (reg_name_u == "CR") {
+206 -138
View File
@@ -165,7 +165,7 @@ static void ppc_update_fex() {
// Floating Point Arithmetic // Floating Point Arithmetic
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fadd(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fadd(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
max_double_check(val_reg_a, val_reg_b); max_double_check(val_reg_a, val_reg_b);
@@ -193,13 +193,15 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fadd<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fadd<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fadd<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fadd<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fsub(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fsub(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
double ppc_dblresult64_d = val_reg_a - val_reg_b; double ppc_dblresult64_d = val_reg_a - val_reg_b;
@@ -223,13 +225,15 @@ void dppc_interpreter::ppc_fsub(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fsub<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsub<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fsub<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsub<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fdiv(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fdiv(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
double ppc_dblresult64_d; double ppc_dblresult64_d;
@@ -237,17 +241,14 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (is_601 && FPR_INT(reg_b) == 0x8000000000000000 && val_reg_a > 0) { if (is_601 && FPR_INT(reg_b) == 0x8000000000000000 && val_reg_a > 0) {
ppc_dblresult64_d = val_reg_b; ppc_dblresult64_d = val_reg_b;
fpresult_update(ppc_dblresult64_d); fpresult_update(ppc_dblresult64_d);
return 0;
if (rec)
ppc_update_cr1();
return;
} }
ppc_dblresult64_d = val_reg_a / val_reg_b; ppc_dblresult64_d = val_reg_a / val_reg_b;
if (val_reg_b == 0.0) { if (val_reg_b == 0.0) {
ppc_state.fpscr |= FX | VX; ppc_state.fpscr |= FX | VX;
ppc_dblresult64_d = -ppc_dblresult64_d;
} }
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) { if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
@@ -273,13 +274,15 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fdiv<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fdiv<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fdiv<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fdiv<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmul(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmul(uint32_t opcode) {
ppc_grab_regsfpdac(opcode); ppc_grab_regsfpdac(opcode);
double ppc_dblresult64_d = val_reg_a * val_reg_c; double ppc_dblresult64_d = val_reg_a * val_reg_c;
@@ -307,13 +310,15 @@ void dppc_interpreter::ppc_fmul(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmul<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmul<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmul<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmul<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmadd(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmadd(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b); double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
@@ -346,13 +351,15 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmadd<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmadd<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmadd<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmadd<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmsub(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmsub(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b); double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
@@ -388,13 +395,15 @@ void dppc_interpreter::ppc_fmsub(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmsub<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmsub<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmsub<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmsub<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fnmadd(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b); double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
@@ -431,13 +440,15 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fnmadd<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmadd<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fnmadd<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmadd<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fnmsub(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b); double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
@@ -469,13 +480,15 @@ void dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fnmsub<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmsub<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fnmsub<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmsub<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fadds(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fadds(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
max_double_check(val_reg_a, val_reg_b); max_double_check(val_reg_a, val_reg_b);
@@ -501,13 +514,15 @@ void dppc_interpreter::ppc_fadds(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fadds<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fadds<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fadds<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fadds<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fsubs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fsubs(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b); double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
@@ -532,18 +547,21 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fsubs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsubs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fsubs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsubs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fdivs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fdivs(uint32_t opcode) {
ppc_grab_regsfpdab(opcode); ppc_grab_regsfpdab(opcode);
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b); double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
if (val_reg_b == 0.0) { if (val_reg_b == 0.0) {
ppc_state.fpscr |= FX | VX; ppc_state.fpscr |= FX | VX;
ppc_dblresult64_d = -ppc_dblresult64_d;
} }
if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) { if (std::isinf(val_reg_a) && std::isinf(val_reg_b)) {
@@ -572,13 +590,15 @@ void dppc_interpreter::ppc_fdivs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fdivs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fdivs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fdivs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fdivs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmuls(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmuls(uint32_t opcode) {
ppc_grab_regsfpdac(opcode); ppc_grab_regsfpdac(opcode);
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c); double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
@@ -606,13 +626,15 @@ void dppc_interpreter::ppc_fmuls(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmuls<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmuls<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmuls<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmuls<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmadds(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmadds(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b); double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
@@ -641,13 +663,15 @@ void dppc_interpreter::ppc_fmadds(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmadds<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmadds<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmadds<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmadds<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmsubs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmsubs(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b); double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
@@ -675,13 +699,15 @@ void dppc_interpreter::ppc_fmsubs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmsubs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmsubs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmsubs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmsubs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fnmadds(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fnmadds(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b); double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
@@ -712,13 +738,15 @@ void dppc_interpreter::ppc_fnmadds(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fnmadds<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmadds<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fnmadds<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmadds<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fnmsubs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fnmsubs(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
snan_double_check(reg_a, reg_c); snan_double_check(reg_a, reg_c);
@@ -753,13 +781,15 @@ void dppc_interpreter::ppc_fnmsubs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fnmsubs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmsubs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fnmsubs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnmsubs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fabs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fabs(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
uint64_t ppc_result64_d = FPR_INT(reg_b) & ~0x8000000000000000U; uint64_t ppc_result64_d = FPR_INT(reg_b) & ~0x8000000000000000U;
@@ -770,13 +800,15 @@ void dppc_interpreter::ppc_fabs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fabs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fabs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fabs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fabs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fnabs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fnabs(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
uint64_t ppc_result64_d = FPR_INT(reg_b) | 0x8000000000000000U; uint64_t ppc_result64_d = FPR_INT(reg_b) | 0x8000000000000000U;
@@ -787,13 +819,15 @@ void dppc_interpreter::ppc_fnabs(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fnabs<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnabs<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fnabs<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fnabs<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fneg(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fneg(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
uint64_t ppc_result64_d = FPR_INT(reg_b) ^ 0x8000000000000000U; uint64_t ppc_result64_d = FPR_INT(reg_b) ^ 0x8000000000000000U;
@@ -804,13 +838,14 @@ void dppc_interpreter::ppc_fneg(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fneg<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fneg<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fneg<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fneg<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fsel(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fsel(uint32_t opcode) {
ppc_grab_regsfpdabc(opcode); ppc_grab_regsfpdabc(opcode);
double ppc_dblresult64_d = (std::isnan(val_reg_a) || (val_reg_a < 0.0)) ? val_reg_b : val_reg_c; double ppc_dblresult64_d = (std::isnan(val_reg_a) || (val_reg_a < 0.0)) ? val_reg_b : val_reg_c;
@@ -819,13 +854,14 @@ void dppc_interpreter::ppc_fsel(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fsel<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsel<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fsel<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsel<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fsqrt(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
double testd2 = (double)(GET_FPR(reg_b)); double testd2 = (double)(GET_FPR(reg_b));
@@ -840,13 +876,14 @@ void dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fsqrt<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsqrt<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fsqrt<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsqrt<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fsqrts(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fsqrts(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
double testd2 = (double)(GET_FPR(reg_b)); double testd2 = (double)(GET_FPR(reg_b));
@@ -861,13 +898,14 @@ void dppc_interpreter::ppc_fsqrts(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fsqrts<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsqrts<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fsqrts<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fsqrts<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_frsqrte(uint32_t opcode) { uint32_t dppc_interpreter::ppc_frsqrte(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
double testd2 = (double)(GET_FPR(reg_b)); double testd2 = (double)(GET_FPR(reg_b));
@@ -882,13 +920,14 @@ void dppc_interpreter::ppc_frsqrte(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_frsqrte<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_frsqrte<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_frsqrte<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_frsqrte<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_frsp(uint32_t opcode) { uint32_t dppc_interpreter::ppc_frsp(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
double ppc_dblresult64_d = (float)(GET_FPR(reg_b)); double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
@@ -902,13 +941,14 @@ void dppc_interpreter::ppc_frsp(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_frsp<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_frsp<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_frsp<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_frsp<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fres(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fres(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
double start_num = GET_FPR(reg_b); double start_num = GET_FPR(reg_b);
@@ -934,10 +974,11 @@ void dppc_interpreter::ppc_fres(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fres<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fres<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fres<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fres<RC1>(uint32_t opcode);
static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) { static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
@@ -997,32 +1038,35 @@ static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
} }
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fctiw(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fctiw(uint32_t opcode) {
round_to_int(opcode, ppc_state.fpscr & 0x3, rec); round_to_int(opcode, ppc_state.fpscr & 0x3, rec);
return 0;
} }
template void dppc_interpreter::ppc_fctiw<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fctiw<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fctiw<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fctiw<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fctiwz(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fctiwz(uint32_t opcode) {
round_to_int(opcode, 1, rec); round_to_int(opcode, 1, rec);
return 0;
} }
template void dppc_interpreter::ppc_fctiwz<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fctiwz<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fctiwz<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fctiwz<RC1>(uint32_t opcode);
// Floating Point Store and Load // Floating Point Store and Load
void dppc_interpreter::ppc_lfs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfs(uint32_t opcode) {
ppc_grab_regsfpdia(opcode); ppc_grab_regsfpdia(opcode);
uint32_t ea = int32_t(int16_t(opcode)); uint32_t ea = int32_t(int16_t(opcode));
ea += (reg_a) ? val_reg_a : 0; ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea); uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result)); ppc_store_fpresult_flt(reg_d, *(float*)(&result));
return 0;
} }
void dppc_interpreter::ppc_lfsu(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfsu(uint32_t opcode) {
ppc_grab_regsfpdia(opcode); ppc_grab_regsfpdia(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1033,18 +1077,20 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_lfsx(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfsx(uint32_t opcode) {
ppc_grab_regsfpdiab(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); uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result)); ppc_store_fpresult_flt(reg_d, *(float*)(&result));
return 0;
} }
void dppc_interpreter::ppc_lfsux(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfsux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode); ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1052,22 +1098,24 @@ void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea); uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result)); ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
return 0;
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
return; return 0;
} }
} }
void dppc_interpreter::ppc_lfd(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfd(uint32_t opcode) {
ppc_grab_regsfpdia(opcode); ppc_grab_regsfpdia(opcode);
uint32_t ea = int32_t(int16_t(opcode)); uint32_t ea = int32_t(int16_t(opcode));
ea += (reg_a) ? val_reg_a : 0; ea += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea); uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d); ppc_store_fpresult_int(reg_d, ppc_result64_d);
return 0;
} }
void dppc_interpreter::ppc_lfdu(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfdu(uint32_t opcode) {
ppc_grab_regsfpdia(opcode); ppc_grab_regsfpdia(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1078,18 +1126,20 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_lfdx(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfdx(uint32_t opcode) {
ppc_grab_regsfpdiab(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); uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d); ppc_store_fpresult_int(reg_d, ppc_result64_d);
return 0;
} }
void dppc_interpreter::ppc_lfdux(uint32_t opcode) { uint32_t dppc_interpreter::ppc_lfdux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode); ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1099,19 +1149,21 @@ void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_stfs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfs(uint32_t opcode) {
ppc_grab_regsfpsia(opcode); ppc_grab_regsfpsia(opcode);
uint32_t ea = int32_t(int16_t(opcode)); uint32_t ea = int32_t(int16_t(opcode));
ea += (reg_a) ? val_reg_a : 0; ea += (reg_a) ? val_reg_a : 0;
float result = float(GET_FPR(reg_s)); float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result)); mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
return 0;
} }
void dppc_interpreter::ppc_stfsu(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfsu(uint32_t opcode) {
ppc_grab_regsfpsia(opcode); ppc_grab_regsfpsia(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1122,18 +1174,20 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_stfsx(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfsx(uint32_t opcode) {
ppc_grab_regsfpsiab(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)); float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result)); mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
return 0;
} }
void dppc_interpreter::ppc_stfsux(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfsux(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode); ppc_grab_regsfpsiab(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1143,18 +1197,20 @@ void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_stfd(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfd(uint32_t opcode) {
ppc_grab_regsfpsia(opcode); ppc_grab_regsfpsia(opcode);
uint32_t ea = int32_t(int16_t(opcode)); uint32_t ea = int32_t(int16_t(opcode));
ea += reg_a ? val_reg_a : 0; ea += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s)); mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
return 0;
} }
void dppc_interpreter::ppc_stfdu(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfdu(uint32_t opcode) {
ppc_grab_regsfpsia(opcode); ppc_grab_regsfpsia(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1164,17 +1220,19 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_stfdx(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfdx(uint32_t opcode) {
ppc_grab_regsfpsiab(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);
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s)); mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
return 0;
} }
void dppc_interpreter::ppc_stfdux(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfdux(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode); ppc_grab_regsfpsiab(opcode);
if (reg_a != 0) { if (reg_a != 0) {
@@ -1183,47 +1241,51 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea); ppc_store_iresult_reg(reg_a, ea);
} }
else { else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP); ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP, 0);
} }
return 0;
} }
void dppc_interpreter::ppc_stfiwx(uint32_t opcode) { uint32_t dppc_interpreter::ppc_stfiwx(uint32_t opcode) {
ppc_grab_regsfpsiab(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);
mmu_write_vmem<uint32_t>(opcode, ea, uint32_t(FPR_INT(reg_s))); mmu_write_vmem<uint32_t>(opcode, ea, uint32_t(FPR_INT(reg_s)));
return 0;
} }
// Floating Point Register Transfer // Floating Point Register Transfer
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_fmr(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fmr(uint32_t opcode) {
ppc_grab_regsfpdb(opcode); ppc_grab_regsfpdb(opcode);
ppc_store_fpresult_flt(reg_d, GET_FPR(reg_b)); ppc_store_fpresult_flt(reg_d, GET_FPR(reg_b));
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_fmr<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmr<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_fmr<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_fmr<RC1>(uint32_t opcode);
template <field_601 for601, field_rc rec> template <field_601 for601, field_rc rec>
void dppc_interpreter::ppc_mffs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mffs(uint32_t opcode) {
int reg_d = (opcode >> 21) & 31; 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) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_mffs<NOT601, RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mffs<NOT601, RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mffs<NOT601, RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mffs<NOT601, RC1>(uint32_t opcode);
template void dppc_interpreter::ppc_mffs<IS601, RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mffs<IS601, RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mffs<IS601, RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mffs<IS601, RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_mtfsf(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
int reg_b = (opcode >> 11) & 0x1F; int reg_b = (opcode >> 11) & 0x1F;
uint8_t fm = (opcode >> 17) & 0xFF; uint8_t fm = (opcode >> 17) & 0xFF;
@@ -1250,13 +1312,14 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_mtfsf<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsf<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mtfsf<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsf<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_mtfsfi(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mtfsfi(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1C; int crf_d = (opcode >> 21) & 0x1C;
uint32_t imm = (opcode << 16) & 0xF0000000UL; uint32_t imm = (opcode << 16) & 0xF0000000UL;
@@ -1272,13 +1335,14 @@ void dppc_interpreter::ppc_mtfsfi(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_mtfsfi<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsfi<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mtfsfi<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsfi<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F; 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); ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
@@ -1286,13 +1350,14 @@ void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_mtfsb0<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsb0<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mtfsb0<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsb0<RC1>(uint32_t opcode);
template <field_rc rec> template <field_rc rec>
void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F; 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); ppc_state.fpscr |= (0x80000000UL >> crf_d);
@@ -1300,12 +1365,13 @@ void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
if (rec) if (rec)
ppc_update_cr1(); ppc_update_cr1();
return 0;
} }
template void dppc_interpreter::ppc_mtfsb1<RC0>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsb1<RC0>(uint32_t opcode);
template void dppc_interpreter::ppc_mtfsb1<RC1>(uint32_t opcode); template uint32_t dppc_interpreter::ppc_mtfsb1<RC1>(uint32_t opcode);
void dppc_interpreter::ppc_mcrfs(uint32_t opcode) { uint32_t dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1C; int crf_d = (opcode >> 21) & 0x1C;
int crf_s = (opcode >> 16) & 0x1C; int crf_s = (opcode >> 16) & 0x1C;
ppc_state.cr = ( ppc_state.cr = (
@@ -1318,13 +1384,13 @@ void dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN | FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ | FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC | FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI));
)); return 0;
} }
// Floating Point Comparisons // Floating Point Comparisons
void dppc_interpreter::ppc_fcmpo(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fcmpo(uint32_t opcode) {
ppc_grab_regsfpsab(opcode); ppc_grab_regsfpsab(opcode);
uint32_t cmp_c = 0; uint32_t cmp_c = 0;
@@ -1351,10 +1417,11 @@ void dppc_interpreter::ppc_fcmpo(uint32_t opcode) {
ppc_state.fpscr &= ~VE; //kludge to pass tests 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 = (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.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
return 0;
} }
void dppc_interpreter::ppc_fcmpu(uint32_t opcode) { uint32_t dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
ppc_grab_regsfpsab(opcode); ppc_grab_regsfpsab(opcode);
uint32_t cmp_c = 0; uint32_t cmp_c = 0;
@@ -1378,4 +1445,5 @@ void dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
ppc_state.fpscr &= ~VE; //kludge to pass tests 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 = (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_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
return 0;
} }
+20 -16
View File
@@ -36,7 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
//#define TLB_PROFILING // uncomment this to enable SoftTLB profiling //#define TLB_PROFILING // uncomment this to enable SoftTLB profiling
/* pointer to exception handler to be called when a MMU exception is occurred. */ /* pointer to exception handler to be called when a MMU exception is occurred. */
void (*mmu_exception_handler)(Except_Type exception_type, uint32_t srr1_bits); uint32_t (*mmu_exception_handler)(Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags);
/* pointers to BAT update functions. */ /* pointers to BAT update functions. */
std::function<void(uint32_t bat_reg)> ibat_update; std::function<void(uint32_t bat_reg)> ibat_update;
@@ -250,7 +250,7 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
/* instruction fetch from a no-execute segment will cause ISI exception */ /* instruction fetch from a no-execute segment will cause ISI exception */
if ((sr_val & 0x10000000) && is_instr_fetch) { if ((sr_val & 0x10000000) && is_instr_fetch) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x10000000); mmu_exception_handler(Except_Type::EXC_ISI, 0x10000000, 0);
} }
page_index = (la >> 12) & 0xFFFF; page_index = (la >> 12) & 0xFFFF;
@@ -260,11 +260,11 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
if (!search_pteg(calc_pteg_addr(pteg_hash1), &pte_addr, vsid, page_index, 0)) { if (!search_pteg(calc_pteg_addr(pteg_hash1), &pte_addr, vsid, page_index, 0)) {
if (!search_pteg(calc_pteg_addr(~pteg_hash1), &pte_addr, vsid, page_index, 1)) { if (!search_pteg(calc_pteg_addr(~pteg_hash1), &pte_addr, vsid, page_index, 1)) {
if (is_instr_fetch) { if (is_instr_fetch) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000); mmu_exception_handler(Except_Type::EXC_ISI, 0x40000000, 0);
} else { } else {
ppc_state.spr[SPR::DSISR] = 0x40000000 | (is_write << 25); ppc_state.spr[SPR::DSISR] = 0x40000000 | (is_write << 25);
ppc_state.spr[SPR::DAR] = la; ppc_state.spr[SPR::DAR] = la;
mmu_exception_handler(Except_Type::EXC_DSI, 0); mmu_exception_handler(Except_Type::EXC_DSI, 0, 0);
} }
} }
} }
@@ -282,11 +282,11 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
// write access with PP = %11 // write access with PP = %11
if ((key && (!pp || (pp == 1 && is_write))) || (pp == 3 && is_write)) { if ((key && (!pp || (pp == 1 && is_write))) || (pp == 3 && is_write)) {
if (is_instr_fetch) { if (is_instr_fetch) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000); mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000, 0);
} else { } else {
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25); ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
ppc_state.spr[SPR::DAR] = la; ppc_state.spr[SPR::DAR] = la;
mmu_exception_handler(Except_Type::EXC_DSI, 0); mmu_exception_handler(Except_Type::EXC_DSI, 0, 0);
} }
} }
@@ -385,9 +385,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR); mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurITLBMode != mmu_mode) { if (CurITLBMode != mmu_mode) {
switch (mmu_mode) { switch(mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
case 0: // real address mode case 0: // real address mode
pCurITLB1 = &itlb1_mode1[0]; pCurITLB1 = &itlb1_mode1[0];
pCurITLB2 = &itlb2_mode1[0]; pCurITLB2 = &itlb2_mode1[0];
@@ -396,6 +394,10 @@ void mmu_change_mode()
pCurITLB1 = &itlb1_mode2[0]; pCurITLB1 = &itlb1_mode2[0];
pCurITLB2 = &itlb2_mode2[0]; pCurITLB2 = &itlb2_mode2[0];
break; 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 case 3: // user mode with instruction translation enabled
pCurITLB1 = &itlb1_mode3[0]; pCurITLB1 = &itlb1_mode3[0];
pCurITLB2 = &itlb2_mode3[0]; pCurITLB2 = &itlb2_mode3[0];
@@ -408,9 +410,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR); mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurDTLBMode != mmu_mode) { if (CurDTLBMode != mmu_mode) {
switch (mmu_mode) { switch(mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
case 0: // real address mode case 0: // real address mode
pCurDTLB1 = &dtlb1_mode1[0]; pCurDTLB1 = &dtlb1_mode1[0];
pCurDTLB2 = &dtlb2_mode1[0]; pCurDTLB2 = &dtlb2_mode1[0];
@@ -419,6 +419,10 @@ void mmu_change_mode()
pCurDTLB1 = &dtlb1_mode2[0]; pCurDTLB1 = &dtlb1_mode2[0];
pCurDTLB2 = &dtlb2_mode2[0]; pCurDTLB2 = &dtlb2_mode2[0];
break; 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 case 3: // user mode with data translation enabled
pCurDTLB1 = &dtlb1_mode3[0]; pCurDTLB1 = &dtlb1_mode3[0];
pCurDTLB2 = &dtlb2_mode3[0]; pCurDTLB2 = &dtlb2_mode3[0];
@@ -523,7 +527,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
// check block protection // check block protection
// only PP = 0 (no access) causes ISI exception // only PP = 0 (no access) causes ISI exception
if (!bat_res.prot) { if (!bat_res.prot) {
mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000); mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000, 0);
} }
phys_addr = bat_res.phys; phys_addr = bat_res.phys;
flags |= TLBFlags::TLBE_FROM_BAT; // tell the world we come from flags |= TLBFlags::TLBE_FROM_BAT; // tell the world we come from
@@ -584,7 +588,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc); LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25); ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
ppc_state.spr[SPR::DAR] = guest_va; ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0); mmu_exception_handler(Except_Type::EXC_DSI, 0, 0);
} }
phys_addr = bat_res.phys; phys_addr = bat_res.phys;
flags = TLBFlags::PTE_SET_C; // prevent PTE.C updates for BAT flags = TLBFlags::PTE_SET_C; // prevent PTE.C updates for BAT
@@ -1095,7 +1099,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
if (!(tlb1_entry->flags & TLBFlags::PAGE_WRITABLE)) { if (!(tlb1_entry->flags & TLBFlags::PAGE_WRITABLE)) {
ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25); ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25);
ppc_state.spr[SPR::DAR] = guest_va; ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0); mmu_exception_handler(Except_Type::EXC_DSI, 0, 0);
} }
if (!(tlb1_entry->flags & TLBFlags::PTE_SET_C)) { if (!(tlb1_entry->flags & TLBFlags::PTE_SET_C)) {
// perform full page address translation to update PTE.C bit // perform full page address translation to update PTE.C bit
@@ -1132,7 +1136,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
if (!(tlb2_entry->flags & TLBFlags::PAGE_WRITABLE)) { if (!(tlb2_entry->flags & TLBFlags::PAGE_WRITABLE)) {
ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25); ppc_state.spr[SPR::DSISR] = 0x08000000 | (1 << 25);
ppc_state.spr[SPR::DAR] = guest_va; ppc_state.spr[SPR::DAR] = guest_va;
mmu_exception_handler(Except_Type::EXC_DSI, 0); mmu_exception_handler(Except_Type::EXC_DSI, 0, 0);
} }
if (!(tlb2_entry->flags & TLBFlags::PTE_SET_C)) { if (!(tlb2_entry->flags & TLBFlags::PTE_SET_C)) {
+405 -321
View File
File diff suppressed because it is too large. Load diff
+6 -10
View File
@@ -37,7 +37,7 @@ int ntested; // number of tested instructions
int nfailed; // number of failed instructions int nfailed; // number of failed instructions
#if defined(PPC_TESTS) #if defined(PPC_TESTS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) { void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits, uint32_t exec_flags) {
power_on = false; power_on = false;
} }
#endif #endif
@@ -46,7 +46,7 @@ void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2; ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2; ppc_state.gpr[4] = 2;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF; ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_main_opcode(ppc_opcode_grabber, opcode); ppc_main_opcode(opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) { if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl; cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++; nfailed++;
@@ -150,7 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0; ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0; ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode); ppc_main_opcode(opcode);
ntested++; ntested++;
@@ -292,7 +292,7 @@ static void read_test_float_data() {
ppc_state.cr = 0; ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode); ppc_main_opcode(opcode);
ntested++; ntested++;
@@ -302,11 +302,10 @@ static void read_test_float_data() {
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) || if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) || (ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) { (ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x" << ", CR=0x"
<< hex << check_cr << endl; << hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl; << ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl; cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -319,9 +318,6 @@ static void read_test_float_data() {
int main() { int main() {
is_601 = true; is_601 = true;
initialize_ppc_opcode_table(); //kludge 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; cout << "Running DingusPPC emulator tests..." << endl << endl;
+1 -2
View File
@@ -2,7 +2,6 @@ include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/" "${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include") "${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_library(debugger OBJECT ${SOURCES}) add_library(debugger OBJECT ${SOURCES})
+55 -97
View File
@@ -53,7 +53,7 @@ using namespace std;
static uint32_t str2addr(string& addr_str) { static uint32_t str2addr(string& addr_str) {
try { try {
return static_cast<uint32_t>(stoul(addr_str, NULL, 0)); return (uint32_t)stoul(addr_str, NULL, 0);
} catch (invalid_argument& exc) { } catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + addr_str); throw invalid_argument(string("Cannot convert ") + addr_str);
} }
@@ -61,7 +61,7 @@ static uint32_t str2addr(string& addr_str) {
static uint32_t str2num(string& num_str) { static uint32_t str2num(string& num_str) {
try { try {
return static_cast<uint32_t>(stol(num_str, NULL, 0)); return (uint32_t)stol(num_str, NULL, 0);
} catch (invalid_argument& exc) { } catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + num_str); throw invalid_argument(string("Cannot convert ") + num_str);
} }
@@ -69,45 +69,41 @@ static uint32_t str2num(string& num_str) {
static void show_help() { static void show_help() {
cout << "Debugger commands:" << endl; cout << "Debugger commands:" << endl;
cout << " step [N] -- execute single instruction" << endl; cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl; cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl; cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl; cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl; cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl; cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl; cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl; cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GPRs" << endl; cout << " regs -- dump content of the GRPs" << endl;
cout << " fregs -- dump content of the FPRs" << endl; cout << " mregs -- dump content of the MMU registers" << endl;
cout << " mregs -- dump content of the MMU registers" << endl; cout << " set R=X -- assign value X to register R" << endl;
cout << " set R=X -- assign value X to register R" << endl; cout << " if R=loglevel, set the internal" << endl;
cout << " if R=loglevel, set the internal" << endl; cout << " log level to X whose range is -2...9" << 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 << " 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 << " T can be b(byte), w(word), d(double)," << endl; cout << " q(quad) or c(character)." << endl;
cout << " q(quad) or c(character)." << endl; cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " profile C N -- run subcommand C on profile N" << endl; cout << " supported subcommands:" << endl;
cout << " supported subcommands:" << endl; cout << " 'show' - show profile report" << endl;
cout << " 'show' - show profile report" << endl; cout << " 'reset' - reset profile variables" << endl;
cout << " 'reset' - reset profile variables" << endl;
#ifdef PROFILER #ifdef PROFILER
cout << " profiler -- show stats related to the processor" << endl; cout << " profiler -- show stats related to the processor" << endl;
#endif #endif
cout << " disas N,X -- disassemble N instructions starting at address X" << 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 << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl; cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl; cout << " da N,X -- shortcut for disas" << endl;
#ifdef ENABLE_68K_DEBUGGER #ifdef ENABLE_68K_DEBUGGER
cout << " context X -- switch to the debugging context X." << endl; cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl; cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl; cout << " Use 68k for debugging emulated 68k code only." << endl;
#endif #endif
cout << " printenv -- print current NVRAM settings." << endl; cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl; cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl; cout << " quit -- quit the debugger" << endl << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
cout << "Pressing ENTER will repeat last command." << endl; cout << "Pressing ENTER will repeat last command." << endl;
} }
@@ -115,7 +111,7 @@ static void show_help() {
static uint32_t disasm_68k(uint32_t count, uint32_t address) { static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle; csh cs_handle;
uint8_t code[12]{}; uint8_t code[10];
size_t code_size; size_t code_size;
uint64_t dis_addr; uint64_t dis_addr;
@@ -127,7 +123,7 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cs_insn* insn = cs_malloc(cs_handle); cs_insn* insn = cs_malloc(cs_handle);
for (; power_on && count > 0; count--) { 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++) { for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1); code[i] = mem_read_dbg(address + i, 1);
} }
@@ -146,7 +142,7 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cout << uppercase << hex << insn->address << " "; cout << uppercase << hex << insn->address << " ";
cout << setfill(' '); cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl; cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
address = static_cast<uint32_t>(dis_addr); address = dis_addr;
} else { } else {
print_bin: print_bin:
cout << uppercase << hex << address << " "; cout << uppercase << hex << address << " ";
@@ -163,7 +159,7 @@ print_bin:
} }
/* emulator opcode table size --> 512 KB */ /* emulator opcode table size --> 512 KB */
constexpr auto EMU_68K_TABLE_SIZE = 0x80000; #define EMU_68K_TABLE_SIZE 0x80000
/** Execute one emulated 68k instruction. */ /** Execute one emulated 68k instruction. */
void exec_single_68k() void exec_single_68k()
@@ -172,7 +168,7 @@ void exec_single_68k()
/* PPC r24 contains 68k PC advanced by two bytes /* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */ 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 */ /* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000; emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
@@ -182,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; cur_instr_tab_entry = mmu_read_vmem<uint16_t>(NO_OPCODE, cur_68k_pc) * 8 + emu_table_virt;
/* grab the PPC PC too */ /* 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); //printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
@@ -191,7 +187,7 @@ void exec_single_68k()
one by one until the execution goes outside the opcode table. */ 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) { while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single(); 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. /* Getting here means we're outside the emualtor opcode table.
@@ -357,9 +353,9 @@ static void print_gprs() {
int i; int i;
for (i = 0; i < 32; 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 << " : " << cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' '); setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
if (i & 1) { if (i & 1) {
@@ -369,10 +365,10 @@ 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) { for (auto &spr : sprs) {
cout << right << std::setw(5) << setfill(' ') << spr << " : " << cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' '); setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
if (i & 1) { if (i & 1) {
@@ -385,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 << " : " <<
setw(16) << setfill('0') << right << uppercase << hex << ppc_state.fpr[i].int64_r <<
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
}
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
setw(8) << setfill('0') << uppercase << hex << ppc_state.fpscr << setfill(' ') << endl;
}
extern bool is_601; extern bool is_601;
static void print_mmu_regs() static void print_mmu_regs()
{ {
printf(" msr : %08X\n", ppc_state.msr); printf("MSR : 0x%08X\n", ppc_state.msr);
printf("\nBAT registers:\n"); printf("\nBAT registers:\n");
for (int i = 0; i < 4; i++) { 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[528+i*2],
i, ppc_state.spr[529+i*2]); i, ppc_state.spr[529+i*2]);
} }
if (!is_601) { if (!is_601) {
for (int i = 0; i < 4; i++) { 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[536+i*2],
i, ppc_state.spr[537+i*2]); i, ppc_state.spr[537+i*2]);
} }
} }
printf("\n"); 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"); printf("\nSegment registers:\n");
for (int i = 0; i < 16; i++) { 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]);
} }
} }
@@ -479,7 +463,6 @@ void DppcDebugger::enter_debugger() {
uint32_t next_addr_68k; uint32_t next_addr_68k;
#endif #endif
bool cmd_repeat; bool cmd_repeat;
int repeat_count = 0;
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils); unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
@@ -526,7 +509,6 @@ void DppcDebugger::enter_debugger() {
power_off_reason = po_entered_debugger; power_off_reason = po_entered_debugger;
} }
if (!did_message) { if (!did_message) {
cout << endl;
cout << "Welcome to the DingusPPC command line debugger." << endl; cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl; cout << "Please enter a command or 'help'." << endl << endl;
did_message = true; did_message = true;
@@ -574,10 +556,6 @@ void DppcDebugger::enter_debugger() {
cmd_repeat = cmd.empty() && !last_cmd.empty(); cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) { if (cmd_repeat) {
cmd = last_cmd; cmd = last_cmd;
repeat_count++;
}
else {
repeat_count = 1;
} }
if (cmd == "help") { if (cmd == "help") {
cmd = ""; cmd = "";
@@ -585,10 +563,6 @@ void DppcDebugger::enter_debugger() {
} else if (cmd == "quit") { } else if (cmd == "quit") {
cmd = ""; cmd = "";
break; break;
} else if (cmd == "restart") {
cmd = "";
power_on = false;
power_off_reason = po_restart;
} else if (cmd == "profile") { } else if (cmd == "profile") {
cmd = ""; cmd = "";
ss >> sub_cmd; ss >> sub_cmd;
@@ -611,9 +585,6 @@ void DppcDebugger::enter_debugger() {
} else { } else {
print_gprs(); print_gprs();
} }
} else if (cmd == "fregs") {
cmd = "";
print_fprs();
} else if (cmd == "mregs") { } else if (cmd == "mregs") {
cmd = ""; cmd = "";
print_mmu_regs(); print_mmu_regs();
@@ -673,22 +644,15 @@ void DppcDebugger::enter_debugger() {
delete_prompt(); delete_prompt();
} }
for (; --count >= 0;) { for (; --count >= 0;) {
addr = ppc_state.pc;
ppc_exec_single(); ppc_exec_single();
} }
} }
} else if (cmd == "next" || cmd == "ni") { } else if (cmd == "next" || cmd == "ni") {
addr_str = "PC"; 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); ppc_exec_until(addr);
} else if (cmd == "until") { } else if (cmd == "until") {
if (cmd_repeat) { ss >> addr_str;
delete_prompt();
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
}
else {
ss >> addr_str;
}
try { try {
addr = str2addr(addr_str); addr = str2addr(addr_str);
if (context == 2) { if (context == 2) {
@@ -762,7 +726,7 @@ void DppcDebugger::enter_debugger() {
} }
else { else {
addr_str = "R24"; 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); next_addr_68k = disasm_68k(1, addr);
#endif #endif
@@ -773,7 +737,7 @@ void DppcDebugger::enter_debugger() {
} }
else { else {
addr_str = "PC"; 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); next_addr_ppc = disasm(1, addr);
} }
@@ -809,15 +773,9 @@ void DppcDebugger::enter_debugger() {
ss >> var_name; ss >> var_name;
std::istream::sentry se(ss); // skip white space std::istream::sentry se(ss); // skip white space
getline(ss, value); // get everything up to eol getline(ss, value); // get everything up to eol
if (ofnvram->init()) { if (ofnvram->init())
cout << " Cannot open NVRAM" << endl;
continue; continue;
} ofnvram->setenv(var_name, value);
if (!ofnvram->setenv(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
#ifndef _WIN32 #ifndef _WIN32
} else if (cmd == "nvedit") { } else if (cmd == "nvedit") {
cmd = ""; cmd = "";
-2
View File
@@ -8,10 +8,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
+1 -1
View File
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string> #include <string>
#include <vector> #include <vector>
constexpr auto ADB_MAX_DATA_SIZE = 8; #define ADB_MAX_DATA_SIZE 8
/** ADB status. */ /** ADB status. */
enum { enum {
+11 -15
View File
@@ -29,9 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp> #include <loguru.hpp>
AdbMouse::AdbMouse( AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t 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) {
) : 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); EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset(); 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 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}; 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; int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_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;
for (int axis = 0; axis < 2; axis++) { 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 int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
: this->device_class == TABLET ? this->y_abs : this->y_rel; : this->device_class == TABLET ? this->y_abs : this->y_rel;
if (val < (-1 << (bits - 1))) if (val < (-1 << (bits - 1)))
@@ -100,7 +89,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bits = 7; bits = 7;
while (bits_remaining > 0) { 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; val >>= bits;
bits_remaining -= bits; bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1; 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; this->changed = false;
uint8_t count = (uint8_t)(p - out_buf); 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); this->host_obj->set_output_count(count);
return should_update; return should_update;
} }
+4 -6
View File
@@ -50,7 +50,7 @@ public:
virtual int perform_command() = 0; 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 { void pdiag_callback() override {
this->r_error &= 0x7F; this->r_error &= 0x7F;
@@ -62,7 +62,7 @@ public:
void update_intrq(uint8_t new_intrq_state); void update_intrq(uint8_t new_intrq_state);
void signal_data_ready(); void signal_data_ready();
bool has_data() const { bool has_data() {
return data_ptr && xfer_cnt; return data_ptr && xfer_cnt;
} }
@@ -71,9 +71,7 @@ public:
} }
protected: protected:
bool is_selected() const { bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
}
void prepare_xfer(int xfer_size, int block_size); void prepare_xfer(int xfer_size, int block_size);
@@ -84,7 +82,7 @@ protected:
IdeChannel* host_obj = nullptr; IdeChannel* host_obj = nullptr;
// IDE aka task file registers // IDE aka task file registers
uint8_t r_error = 0; uint8_t r_error;
uint8_t r_features; uint8_t r_features;
uint8_t r_sect_count; uint8_t r_sect_count;
uint8_t r_sect_num; uint8_t r_sect_num;
+5 -5
View File
@@ -29,15 +29,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string> #include <string>
constexpr auto ATA_HD_SEC_SIZE = 512; #define ATA_HD_SEC_SIZE 512
constexpr auto SECTORS_PER_INT = 16; #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 // 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 // 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 // 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 class AtaHardDisk : public AtaBaseDevice
{ {
+6 -9
View File
@@ -241,8 +241,7 @@ void AtapiCdrom::perform_packet_command() {
else { else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks 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 if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block = int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from 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? 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 disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
} }
@@ -253,8 +252,7 @@ void AtapiCdrom::perform_packet_command() {
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count); 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 + 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
(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 if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count bytes_received = this->r_byte_count; // confine to r_byte_count
} }
@@ -384,12 +382,11 @@ void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->r_status |= ATA_Status::ERR; this->r_status |= ATA_Status::ERR;
} }
static const PropMap AtapiCdrom_Properties = { static const PropMap AtapiCdromProperties = {
{"cdr_img", new StrProperty("")}, {"cdr_img", new StrProperty("")},
}; };
static const DeviceDescription AtapiCdrom_Descriptor = { static const DeviceDescription AtapiCdromDescriptor =
AtapiCdrom::create, {}, AtapiCdrom_Properties {AtapiCdrom::create, {}, AtapiCdromProperties};
};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor); REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
+4 -4
View File
@@ -31,14 +31,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory> #include <memory>
constexpr auto DEV_ID_CMD646 = 0x646; #define DEV_ID_CMD646 0x646
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master #define MY_DEV_CLASS 0x010180 // mass storage | IDE controller | IDE master
constexpr auto MY_REV_ID = 7; #define MY_REV_ID 7
// Offset for converting addresses of the device control block registers // Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94 // defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel // to the addresses used in IdeChannel
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14; #define DEV_CTRL_BLK_OFFSET 0x14
/** CMD646 control/status registers. */ /** CMD646 control/status registers. */
enum { enum {
+1 -1
View File
@@ -95,7 +95,7 @@ private:
// interrupt stuff // interrupt stuff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
}; };
#endif // IDE_CHANNEL_H #endif // IDE_CHANNEL_H
+2 -2
View File
@@ -123,7 +123,7 @@ public:
void end_pull_data(); void end_pull_data();
void end_push_data(); void end_push_data();
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->int_ctrl = int_ctrl_obj;
this->irq_id = irq_id; this->irq_id = irq_id;
}; };
@@ -163,7 +163,7 @@ private:
// Interrupt related stuff // Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
}; };
#endif // DB_DMA_H #endif // DB_DMA_H
+5 -18
View File
@@ -30,11 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enum IntSrc : uint32_t { enum IntSrc : uint32_t {
INT_UNKNOWN = 0, INT_UNKNOWN = 0,
VIA_CUDA, VIA_CUDA,
VIA2,
SCSI_MESH, SCSI_MESH,
SCSI_CURIO, SCSI_CURIO,
SWIM3, SWIM3,
ESCC,
SCCA, SCCA,
SCCB, SCCB,
ETHERNET, ETHERNET,
@@ -60,7 +58,6 @@ enum IntSrc : uint32_t {
PLANB, PLANB,
VCI, VCI,
PLATINUM, PLATINUM,
DMA_ALL,
DMA_SCSI_MESH, DMA_SCSI_MESH,
DMA_SCSI_CURIO, DMA_SCSI_CURIO,
DMA_SWIM3, DMA_SWIM3,
@@ -83,16 +80,6 @@ enum IntSrc : uint32_t {
USB, USB,
PIPPIN_E, PIPPIN_E,
PIPPIN_F, 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. */ /** Base class for interrupt controllers. */
@@ -102,17 +89,17 @@ public:
virtual ~InterruptCtrl() = default; virtual ~InterruptCtrl() = default;
// register interrupt sources for a device // register interrupt sources for a device
virtual uint64_t register_dev_int(IntSrc src_id) = 0; virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint64_t register_dma_int(IntSrc src_id) = 0; virtual uint32_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt // acknowledge HW interrupt
virtual void ack_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(uint64_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 { typedef struct {
InterruptCtrl *int_ctrl_obj; InterruptCtrl *int_ctrl_obj;
uint64_t irq_id; uint32_t irq_id;
} IntDetails; } IntDetails;
#endif // HW_INTERRUPT_H #endif // HW_INTERRUPT_H
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters. This is helpful especially for calculating video parameters.
*/ */
#include <devices/common/clockgen/athens.h> #include <devices/common/i2c/athens.h>
#include <loguru.hpp> #include <loguru.hpp>
#include <algorithm> #include <algorithm>
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
constexpr auto ATHENS_NUM_REGS = 8; #define ATHENS_NUM_REGS 8
/** Default external crystal oscillator frequency. */ /** Default external crystal oscillator frequency. */
constexpr auto ATHENS_XTAL = 31334400.0f; constexpr auto ATHENS_XTAL = 31334400.0f;
+3 -5
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -27,12 +27,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H #ifndef I2C_H
#define I2C_H #define I2C_H
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept> #include <stdexcept>
#include <cstring>
#include <string> #include <string>
#include <loguru.hpp>
/** Base class for I2C devices */ /** Base class for I2C devices */
class I2CDevice { class I2CDevice {
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file SAA7187 Digital video encoder emulation. */ /** @file SAA7187 Digital video encoder emulation. */
#include <devices/video/saa7187.h> #include <devices/common/i2c/saa7187.h>
#include <loguru.hpp> #include <loguru.hpp>
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr) Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr)
File renamed without changes.
+1 -1
View File
@@ -40,7 +40,7 @@ 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: It's located at physical address 0x5FFFFFFC and contains four bytes:
+0 uint16_t signature = 0xA55A +0 uint16_t signature = 0xA55A
+1 uint8_t machine_type (3 - Power Mac) +1 uint8_t machine_type (3 - Power Mac)
-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
+7 -6
View File
@@ -322,9 +322,6 @@ bool OfConfigChrp::validate()
bool wip = true; bool wip = true;
bool of_part_found = false; bool of_part_found = false;
if (this->nvram_obj == nullptr)
return false;
// search the entire 8KB NVRAM for CHRP OF config partition. // search the entire 8KB NVRAM for CHRP OF config partition.
// Bail out if an unknown partition or free space is encountered. // Bail out if an unknown partition or free space is encountered.
// Skip over known partitions. // Skip over known partitions.
@@ -595,12 +592,16 @@ void OfConfigUtils::printenv() {
} }
} }
bool OfConfigUtils::setenv(string var_name, string value) void OfConfigUtils::setenv(string var_name, string value)
{ {
if (!this->open_container()) if (!this->open_container())
return false; return;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars(); 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
}
} }
+4 -4
View File
@@ -33,9 +33,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class NVram; class NVram;
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */ /** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
constexpr auto OF_NVRAM_OFFSET = 0x1800; #define OF_NVRAM_OFFSET 0x1800
constexpr auto OF_NVRAM_SIG = 0x1275; #define OF_NVRAM_SIG 0x1275
constexpr auto OF_CFG_SIZE = 0x800; #define OF_CFG_SIZE 0x800
// OF Variable types // OF Variable types
enum { enum {
@@ -134,7 +134,7 @@ public:
int init(); int init();
void printenv(); void printenv();
bool setenv(std::string var_name, std::string value); void setenv(std::string var_name, std::string value);
protected: protected:
bool open_container(); bool open_container();
+2 -2
View File
@@ -46,8 +46,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory> #include <memory>
#include <string> #include <string>
constexpr auto BANDIT_DEV = 11; // Bandit's own device number #define BANDIT_DEV (11) // Bandit's own device number
constexpr auto BANDIT_CAR_TYPE = 1 << 0; // Bandit config address type bit #define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
/* Convenient macros for parsing CONFIG_ADDR fields. */ /* Convenient macros for parsing CONFIG_ADDR fields. */
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU) #define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
+2 -4
View File
@@ -191,8 +191,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Io_32_Bit: case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3); this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & 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)", 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));
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
} }
break; break;
@@ -201,8 +200,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Mem_64_Bit_Lo: case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF); this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & 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)", 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));
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
} }
break; break;
+1 -3
View File
@@ -47,9 +47,7 @@ enum {
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2) 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_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (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) 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)
// 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. */ /** PCI Vendor IDs for devices used in Power Macintosh computers. */
+2 -3
View File
@@ -81,8 +81,7 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
HWComponent *hwc = dynamic_cast<HWComponent*>(this); HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F( LOG_F(
// FIXME: need destructors to remove memory regions and downstream devices. // FIXME: need destructors to remove memory regions and downstream devices.
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs " ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor to unregister memory and downstream devices etc.)",
"a working destructor to unregister memory and downstream devices etc.)",
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str() hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
); );
@@ -230,7 +229,7 @@ uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
SIZE_ARG(size) SIZE_ARG(size)
); );
// machine check exception (DEFAULT CATCH!, code=FFF00200) // machine check exception (DEFAULT CATCH!, code=FFF00200)
ppc_exception_handler(Except_Type::EXC_MACHINE_CHECK, 0); ppc_exception_handler(Except_Type::EXC_MACHINE_CHECK, 0, 0);
return 0; return 0;
} }
+1 -1
View File
@@ -380,7 +380,7 @@ void Sc53C94::exec_next_command()
} }
} }
constexpr auto DATA_FIFO_MAX = 16; #define DATA_FIFO_MAX 16
void Sc53C94::fifo_push(const uint8_t data) void Sc53C94::fifo_push(const uint8_t data)
{ {
+1 -1
View File
@@ -290,7 +290,7 @@ private:
// interrupt related stuff // interrupt related stuff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
uint8_t irq = 0; uint8_t irq = 0;
// DMA related stuff // DMA related stuff
+10 -19
View File
@@ -156,14 +156,14 @@ enum ScsiError : int {
}; };
/** Standard SCSI bus timing values measured in ns. */ /** Standard SCSI bus timing values measured in ns. */
constexpr uint64_t BUS_SETTLE_DELAY = 400; #define BUS_SETTLE_DELAY 400
constexpr uint64_t BUS_FREE_DELAY = 800; #define BUS_FREE_DELAY 800
constexpr uint64_t BUS_CLEAR_DELAY = 800; #define BUS_CLEAR_DELAY 800
constexpr uint64_t ARB_DELAY = 2400; #define ARB_DELAY 2400
constexpr uint64_t SEL_ABORT_TIME = 200000; #define SEL_ABORT_TIME 200000
constexpr uint64_t SEL_TIME_OUT = 250000000; #define SEL_TIME_OUT 250000000
constexpr auto SCSI_MAX_DEVS = 8; #define SCSI_MAX_DEVS 8
class ScsiBus; class ScsiBus;
@@ -246,18 +246,9 @@ public:
// low-level state management // low-level state management
void register_device(int id, ScsiDevice* dev_obj); void register_device(int id, ScsiDevice* dev_obj);
int current_phase() { return this->cur_phase; };
int current_phase() const { int get_initiator_id() { return this->initiator_id; };
return this->cur_phase; int get_target_id() { return this->target_id; };
}
int get_initiator_id() const {
return this->initiator_id;
}
int get_target_id() const {
return this->target_id;
}
// reading/writing control lines // reading/writing control lines
void assert_ctrl_line(int id, uint16_t mask); void assert_ctrl_line(int id, uint16_t mask);
+3 -7
View File
@@ -73,10 +73,8 @@ void ScsiBus::change_bus_phase(int initiator_id)
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask) void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
{ {
if (!(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS)) { DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS,
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id); "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
return;
}
uint16_t new_state = 0xFFFFU & mask; 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) void ScsiBus::release_ctrl_line(int id, uint16_t mask)
{ {
if (!(id >= 0 && id < SCSI_MAX_DEVS)) { DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
}
uint16_t new_state = 0; uint16_t new_state = 0;
+2 -2
View File
@@ -58,7 +58,7 @@ enum : int {
SEL_TIMEOUT, SEL_TIMEOUT,
}; };
constexpr auto DATA_FIFO_DEPTH = 16; #define DATA_FIFO_DEPTH 16
class ScsiBusController : public ScsiDevice, public DmaDevice { class ScsiBusController : public ScsiDevice, public DmaDevice {
public: public:
@@ -113,7 +113,7 @@ protected:
// interrupt related stuff // interrupt related stuff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
uint8_t irq = 0; uint8_t irq = 0;
uint8_t int_mask = 0; uint8_t int_mask = 0;
uint8_t int_stat = 0; uint8_t int_stat = 0;
+7 -22
View File
@@ -34,9 +34,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std; using namespace std;
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) { 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) { void ScsiHardDisk::insert_image(std::string filename) {
@@ -226,8 +223,7 @@ void ScsiHardDisk::inquiry() {
int lun; int lun;
if (this->last_selection_has_atention) { if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(), alloc_len, this->last_selection_message);
this->name.c_str(), alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7; lun = this->last_selection_message & 7;
} }
else { else {
@@ -459,19 +455,14 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
return; return;
uint32_t transfer_size = transfer_len; uint32_t transfer_size = transfer_len;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
if (cmd_len == 6 && transfer_len == 0) { if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256; transfer_size = 256;
} }
transfer_size *= this->sector_size; 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; uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size); this->disk_img.read(this->data_buf, device_offset, transfer_size);
@@ -483,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) { void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len; uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) { if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256; transfer_size = 256;
} }
transfer_size *= this->sector_size; 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; uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size; this->incoming_size = transfer_size;
+1 -3
View File
@@ -66,9 +66,7 @@ private:
bool eject_allowed = true; bool eject_allowed = true;
int bytes_out = 0; int bytes_out = 0;
std::unique_ptr<uint8_t[]> data_buf_obj = nullptr; uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
uint8_t* data_buf = nullptr;
uint32_t data_buf_size = 0;
uint8_t error = ScsiError::NO_ERROR; uint8_t error = ScsiError::NO_ERROR;
uint8_t msg_code = 0; uint8_t msg_code = 0;
+1 -1
View File
@@ -301,7 +301,7 @@ 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 // calculate current counter value based on elapsed time and timer frequency
uint64_t cur_time = TimerManager::get_instance()->current_time_ns(); 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; return last_val - diff;
} }
+8 -8
View File
@@ -53,7 +53,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class AdbBus; class AdbBus;
class InterruptCtrl; class InterruptCtrl;
constexpr auto VIA_CLOCK_HZ = 783360; #define VIA_CLOCK_HZ 783360
/** VIA register offsets. */ /** VIA register offsets. */
enum { enum {
@@ -143,16 +143,16 @@ enum {
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge 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. */ /** PRAM addresses within Cuda's internal memory. */
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM #define CUDA_PRAM_START 0x100 // starting address of PRAM
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM #define CUDA_PRAM_END 0x1FF // last byte of PRAM
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW #define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
/** Latest Cuda Firmware version. */ /** Latest Cuda Firmware version. */
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002; #define CUDA_FW_VERSION_MAJOR 0x0002
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029; #define CUDA_FW_VERSION_MINOR 0x0029
class ViaCuda : public HWComponent, public I2CBus { class ViaCuda : public HWComponent, public I2CBus {
public: public:
@@ -207,7 +207,7 @@ private:
// VIA interrupt related stuff // VIA interrupt related stuff
InterruptCtrl* int_ctrl; InterruptCtrl* int_ctrl;
uint64_t irq_id; uint32_t irq_id;
uint8_t _via_ifr; uint8_t _via_ifr;
uint8_t _via_ier; uint8_t _via_ier;
uint8_t old_ifr = 0; uint8_t old_ifr = 0;
+2 -2
View File
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory> #include <memory>
/** Known MACE chip IDs. */ /** Known MACE chip IDs. */
constexpr auto MACE_ID_REV_B0 = 0x0940; // Darwin-0.3 source #define 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_A2 0x0941 // Darwin-0.3 source & Curio datasheet
/** MACE registers offsets. */ /** MACE registers offsets. */
// Refer to the Am79C940 datasheet for details // Refer to the Am79C940 datasheet for details
+8 -28
View File
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
#include <string> #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 #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 get_raw_disk_data(char* buf) = 0;
virtual int export_data(void) = 0; virtual int export_data(void) = 0;
int get_data_size() const { int get_data_size() { return this->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_disk_rec_method() const { int get_sectors_per_side() { return this->num_sectors; };
return this->rec_method; int get_rec_density() { return this->density; };
} uint8_t get_format_byte() { return this->format_byte; };
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;
}
protected: protected:
std::string img_path; std::string img_path;
+2 -3
View File
@@ -67,8 +67,7 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
if (this->cur_track < 0) if (this->cur_track < 0)
this->cur_track = 0; this->cur_track = 0;
else if (this->cur_track >= this->num_tracks) { else if (this->cur_track >= this->num_tracks) {
LOG_F(ERROR, "%s: track:%d is greater than max track:%d", 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->get_name().c_str(), this->cur_track, this->num_tracks - 1);
this->cur_track = this->num_tracks - 1; this->cur_track = this->num_tracks - 1;
} }
this->track_zero = this->cur_track == 0; this->track_zero = this->cur_track == 0;
@@ -284,7 +283,7 @@ uint64_t MacSuperDrive::sync_to_disk()
{ {
uint64_t cur_time_ns, track_time_ns; 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 // 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; cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
+1 -1
View File
@@ -152,7 +152,7 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value) void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
{ {
uint8_t status_addr = 0; uint8_t status_addr;
switch(reg_offset) { switch(reg_offset) {
case Swim3Reg::Timer: case Swim3Reg::Timer:
+1 -1
View File
@@ -147,7 +147,7 @@ private:
// Interrupt related stuff // Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
uint8_t irq = 0; uint8_t irq = 0;
}; };
+36 -49
View File
@@ -75,8 +75,8 @@ AMIC::AMIC() : MMIODevice()
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda")); this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// initialize sound HW // initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma>(new AmicSndOutDma()); 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->init_interrupts(this, 2 << 8);
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm()); this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get()); this->awacs->set_dma_out(this->snd_out_dma.get());
@@ -448,63 +448,50 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
} }
// ======================== Interrupt related stuff ========================== // ======================== Interrupt related stuff ==========================
uint64_t AMIC::register_dev_int(IntSrc src_id) { uint32_t AMIC::register_dev_int(IntSrc src_id) {
switch (src_id) { switch (src_id) {
case IntSrc::VIA_CUDA : return CPU_INT_VIA1 << CPU_INT_SHIFT; case IntSrc::VIA_CUDA:
case IntSrc::VIA2 : return CPU_INT_VIA2 << CPU_INT_SHIFT; return CPU_INT_VIA1;
case IntSrc::ESCC : return CPU_INT_ESCC << CPU_INT_SHIFT; case IntSrc::SCSI_CURIO:
case IntSrc::ETHERNET : return CPU_INT_ENET << CPU_INT_SHIFT; return VIA2_INT_SCSI_IRQ << 8;
case IntSrc::DMA_ALL : return CPU_INT_ALL_DMA << CPU_INT_SHIFT; case IntSrc::SWIM3:
case IntSrc::NMI : return CPU_INT_NMI << CPU_INT_SHIFT; return VIA2_INT_SWIM3 << 8;
case IntSrc::NMI:
case IntSrc::DMA_SCSI_CURIO: return VIA2_INT_SCSI_DRQ << VIA2_INT_SHIFT; return CPU_INT_NMI;
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;
default: default:
ABORT_F("AMIC: unknown interrupt source %d", src_id); ABORT_F("AMIC: unknown interrupt source %d", src_id);
} }
return 0; 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"); ABORT_F("AMIC: register_dma_int() not implemented");
return 0; 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 // dispatch cascaded AMIC interrupts from various sources
// irq_id format: 00DDCCBBAA where // irq_id format: 00DDCCBBAA where
// - AA -> CPU interrupts // - AA -> CPU interrupts
// - BB -> pseudo VIA2 interrupts // - BB -> pseudo VIA2 interrupts
// - CC -> slot interrupts // - CC -> slot interrupts
if (irq_id >> SLOT_INT_SHIFT) { if (irq_id < 0x100) {
this->ack_slot_int(irq_id >> SLOT_INT_SHIFT, irq_line_state); this->ack_cpu_int(irq_id, irq_line_state);
} else if (irq_id >> VIA2_INT_SHIFT) { } else if (irq_id < 0x10000) {
this->ack_via2_int(irq_id >> VIA2_INT_SHIFT, irq_line_state); this->ack_via2_int(irq_id >> 8, irq_line_state);
} else if (irq_id >> CPU_INT_SHIFT) { } else if (irq_id < 0x1000000) {
this->ack_cpu_int(irq_id >> CPU_INT_SHIFT, irq_line_state); this->ack_slot_int(irq_id >> 16, irq_line_state);
} else { } 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! // CAUTION: reverse logic (0 - true, 1 - false) in the IFR register!
if (irq_line_state) { if (irq_line_state) {
this->via2_slot_ifr &= ~slot_int; this->via2_slot_ifr &= ~irq_id;
} else { } 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); uint8_t new_irq = !!(~this->via2_slot_ifr & this->via2_slot_ier & 0x7F);
if (new_irq != this->via2_slot_irq) { if (new_irq != this->via2_slot_irq) {
@@ -522,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) { if (irq_line_state) {
this->via2_ifr |= via2_int; this->via2_ifr |= irq_id;
} else { } else {
this->via2_ifr &= ~via2_int; this->via2_ifr &= ~irq_id;
} }
this->update_via2_irq(); 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 (this->int_ctrl & CPU_INT_MODE) { // 68k interrupt emulation mode?
if (irq_line_state) { if (irq_line_state) {
this->dev_irq_lines |= cpu_int; this->dev_irq_lines |= irq_id;
} else { } else {
this->dev_irq_lines &= ~cpu_int; this->dev_irq_lines &= ~irq_id;
} }
if (!(this->int_ctrl & CPU_INT_FLAG)) { if (!(this->int_ctrl & CPU_INT_FLAG)) {
this->int_ctrl |= CPU_INT_FLAG; this->int_ctrl |= CPU_INT_FLAG;
ppc_assert_int(); 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 { } else {
LOG_F(5, "AMIC: CPU INT already latched"); LOG_F(5, "AMIC: CPU INT already latched");
} }
@@ -551,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) { void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_id >> DMA1_INT_SHIFT) { // DMA Interrupt Flags 1 if (irq_id >= 0x100) { // DMA Interrupt Flags 1
irq_id = (irq_id >> DMA1_INT_SHIFT) & 0xFFU; irq_id = (irq_id >> 8) & 0xFFU;
if (irq_line_state) if (irq_line_state)
this->dma_ifr1 |= irq_id; this->dma_ifr1 |= irq_id;
else else
this->dma_ifr1 &= ~irq_id; this->dma_ifr1 &= ~irq_id;
} else if (irq_id >> DMA0_INT_SHIFT) { // DMA Interrupt Flags 0 } else { // DMA Interrupt Flags 0
irq_id = (irq_id >> DMA0_INT_SHIFT) & 0xFFU; irq_id &= 0xFFU;
if (irq_line_state) if (irq_line_state)
this->dma_ifr0 |= irq_id; this->dma_ifr0 |= irq_id;
else else
@@ -601,7 +588,7 @@ void AmicSndOutDma::update_irq() {
if (new_level != this->irq_level) { if (new_level != this->irq_level) {
this->irq_level = new_level; this->irq_level = new_level;
TimerManager::get_instance()->add_immediate_timer([this] { 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);
}); });
} }
} }
+21 -32
View File
@@ -31,7 +31,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/video/displayid.h> #include <devices/video/displayid.h>
#include <devices/video/pdmonboard.h> #include <devices/video/pdmonboard.h>
#include <atomic>
#include <cinttypes> #include <cinttypes>
#include <memory> #include <memory>
@@ -44,8 +43,7 @@ namespace Swim3 { class Swim3Ctrl; }
/** Interrupt related constants. */ /** Interrupt related constants. */
/** CPU interrupt register bits. */ /** CPU interrupt register bits. */
enum : uint64_t { enum : uint8_t {
CPU_INT_SHIFT = 0,
CPU_INT_VIA1 = 1 << 0, // (R) VIA1 interrupts CPU_INT_VIA1 = 1 << 0, // (R) VIA1 interrupts
CPU_INT_VIA2 = 1 << 1, // (R) pseudo VIA2 interrupts CPU_INT_VIA2 = 1 << 1, // (R) pseudo VIA2 interrupts
CPU_INT_ESCC = 1 << 2, // (R) ESCC interrupt CPU_INT_ESCC = 1 << 2, // (R) ESCC interrupt
@@ -58,8 +56,7 @@ enum : uint64_t {
}; };
/** Pseudo VIA2 interrupt flag/enable register bits. */ /** Pseudo VIA2 interrupt flag/enable register bits. */
enum : uint64_t { enum : uint8_t {
VIA2_INT_SHIFT = 8,
VIA2_INT_SCSI_DRQ = 1 << 0, // (R) SCSI DRQ interrupt VIA2_INT_SCSI_DRQ = 1 << 0, // (R) SCSI DRQ interrupt
VIA2_INT_ALL_SLOT = 1 << 1, // (R) all slot interrupts are signalled here VIA2_INT_ALL_SLOT = 1 << 1, // (R) all slot interrupts are signalled here
VIA2_INT_SCSI_IRQ = 1 << 3, // (R) SCSI IRQ interrupt VIA2_INT_SCSI_IRQ = 1 << 3, // (R) SCSI IRQ interrupt
@@ -69,23 +66,15 @@ enum : uint64_t {
}; };
/** Slot interrupt flag/enable register bits. */ /** Slot interrupt flag/enable register bits. */
enum : uint64_t { enum : uint8_t {
SLOT_INT_SHIFT = 16, SLOT_INT_SLOT_0 = 1 << 2, // (R) ColdFusion Nubus slot 0 interrupt
SLOT_INT_SLOT_0 = 1 << 2, // (R) ColdFusion NuBus slot 0 interrupt SLOT_INT_SLOT_1 = 1 << 3, // (R) ColdFusion Nubus slot 1 interrupt
SLOT_INT_SLOT_1 = 1 << 3, // (R) ColdFusion NuBus slot 1 interrupt SLOT_INT_SLOT_2 = 1 << 4, // (R) ColdFusion Nubus slot 2 interrupt
SLOT_INT_SLOT_2 = 1 << 4, // (R) ColdFusion NuBus slot 2 interrupt
SLOT_INT_SLOT_VDS = 1 << 5, // (R) ColdFusion video direct slot interrupt SLOT_INT_SLOT_VDS = 1 << 5, // (R) ColdFusion video direct slot interrupt
SLOT_INT_SLOT_PDS = 1 << 5, // (R) PDM processor direct slot interrupt SLOT_INT_SLOT_PDS = 1 << 5, // (R) PDM processor direct slot interrupt
SLOT_INT_VBL = 1 << 6, // (R) built-in video VBL interrupt SLOT_INT_VBL = 1 << 6, // (R) built-in video VBL interrupt
}; };
/** DMA interrupt bits. */
enum : uint64_t {
DMA0_INT_SHIFT = 24,
DMA1_INT_SHIFT = 32,
DMA1_INT_SOUND = 1 << 1,
};
/** AMIC sound buffers are located at fixed offsets from DMA base. */ /** AMIC sound buffers are located at fixed offsets from DMA base. */
#define AMIC_SND_BUF0_OFFS 0x10000 #define AMIC_SND_BUF0_OFFS 0x10000
#define AMIC_SND_BUF1_OFFS 0x12000 #define AMIC_SND_BUF1_OFFS 0x12000
@@ -115,9 +104,9 @@ public:
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data); uint8_t **p_data);
void init_interrupts(InterruptCtrl *int_ctrl, uint64_t irq_id) { void init_interrupts(InterruptCtrl *int_ctrl, uint32_t irq_id) {
this->int_ctrl = int_ctrl; this->int_ctrl = int_ctrl;
this->snd_dma_irq_id = irq_id; this->irq_id = irq_id;
}; };
private: private:
@@ -131,7 +120,7 @@ private:
uint32_t cur_buf_pos; uint32_t cur_buf_pos;
InterruptCtrl *int_ctrl = nullptr; InterruptCtrl *int_ctrl = nullptr;
uint64_t snd_dma_irq_id = 0; uint32_t irq_id = 0;
uint8_t irq_level = 0; uint8_t irq_level = 0;
}; };
@@ -299,22 +288,22 @@ public:
} }
// HWComponent methods // HWComponent methods
int device_postinit() override; int device_postinit();
/* MMIODevice methods */ /* MMIODevice methods */
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override; uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override; void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
// InterruptCtrl methods // InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override; uint32_t register_dev_int(IntSrc src_id);
uint64_t register_dma_int(IntSrc src_id) override; uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
protected: protected:
void ack_slot_int(uint8_t slot_int, uint8_t irq_line_state); void ack_slot_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_via2_int(uint8_t via2_int, uint8_t irq_line_state); void ack_via2_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state); void ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state);
void update_via2_irq(); void update_via2_irq();
private: private:
@@ -341,8 +330,8 @@ private:
uint8_t dev_irq_lines = 0; // state of the IRQ lines uint8_t dev_irq_lines = 0; // state of the IRQ lines
// DMA IRQ flag registers // DMA IRQ flag registers
std::atomic<uint8_t> dma_ifr0{0}; uint8_t dma_ifr0 = 0;
std::atomic<uint8_t> dma_ifr1{0}; uint8_t dma_ifr1 = 0;
uint8_t dma_irq = 0; uint8_t dma_irq = 0;
// pseudo VIA2 state // pseudo VIA2 state
+26 -28
View File
@@ -61,7 +61,7 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
// populate my PCI config header // populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE; this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_GRANDCENTRAL; this->device_id = 0x0002;
this->class_rev = 0xFF000002; this->class_rev = 0xFF000002;
this->cache_ln_sz = 8; this->cache_ln_sz = 8;
@@ -252,10 +252,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_GC_DMA_AUDIO_OUT: case MIO_GC_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size); return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_AUDIO_IN: case MIO_GC_DMA_AUDIO_IN:
#if 0 //LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c",
this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
#endif
return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size); return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_SCSI_MESH: case MIO_GC_DMA_SCSI_MESH:
if (this->mesh_dma) { if (this->mesh_dma) {
@@ -434,7 +431,7 @@ void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
#define INT_TO_IRQ_ID(intx) (1 << intx) #define INT_TO_IRQ_ID(intx) (1 << intx)
uint64_t GrandCentral::register_dev_int(IntSrc src_id) { uint32_t GrandCentral::register_dev_int(IntSrc src_id) {
switch (src_id) { switch (src_id) {
case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C); case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C);
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0D); case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0D);
@@ -473,60 +470,61 @@ uint64_t GrandCentral::register_dev_int(IntSrc src_id) {
return 0; return 0;
} }
uint64_t GrandCentral::register_dma_int(IntSrc src_id) { #define DMA_INT_TO_IRQ_ID(intx) (1 << intx)
uint32_t GrandCentral::register_dma_int(IntSrc src_id) {
switch (src_id) { switch (src_id) {
case IntSrc::DMA_SCSI_CURIO : return INT_TO_IRQ_ID(0x00); case IntSrc::DMA_SCSI_CURIO : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01); case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_ETHERNET_Tx: return INT_TO_IRQ_ID(0x02); case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_ETHERNET_Rx: return INT_TO_IRQ_ID(0x03); case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04); case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05); case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06); case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07); case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08); case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09); case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_SCSI_MESH : return INT_TO_IRQ_ID(0x0A); case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x0A);
default: default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id); ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
} }
return 0; return 0;
} }
void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) { void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t irq_line_state) {
// native mode: set IRQ bits in int_events on a 0-to-1 transition // native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions // emulated mode: set IRQ bits in int_events on all transitions
if ((this->int_mask & MACIO_INT_MODE) || if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) { (irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= (uint32_t)irq_id; this->int_events |= irq_id;
} else { } else {
this->int_events &= ~(uint32_t)irq_id; this->int_events &= ~irq_id;
} }
// update IRQ line state // update IRQ line state
if (irq_line_state) { if (irq_line_state) {
this->int_levels |= (uint32_t)irq_id; this->int_levels |= irq_id;
} else { } else {
this->int_levels &= ~(uint32_t)irq_id; this->int_levels &= ~irq_id;
} }
this->signal_cpu_int(irq_id); this->signal_cpu_int(irq_id);
} }
void GrandCentral::ack_int(uint64_t irq_id, uint8_t irq_line_state) { void GrandCentral::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state); this->ack_int_common(irq_id, irq_line_state);
} }
void GrandCentral::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) { void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
this->ack_int_common(irq_id, irq_line_state); this->ack_int_common(irq_id, irq_line_state);
} }
void GrandCentral::signal_cpu_int(uint64_t irq_id) { void GrandCentral::signal_cpu_int(uint32_t irq_id) {
if (this->int_events & this->int_mask) { if (this->int_events & this->int_mask) {
if (!this->cpu_int_latch) { if (!this->cpu_int_latch) {
this->cpu_int_latch = true; this->cpu_int_latch = true;
ppc_assert_int(); ppc_assert_int();
LOG_F(5, "%s: CPU INT asserted, source: 0x%08llx", this->name.c_str(), irq_id); LOG_F(5, "%s: CPU INT asserted, source: %d", this->name.c_str(), irq_id);
} else { } else {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str()); LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
} }
+194 -59
View File
@@ -50,7 +50,7 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
// populate my PCI config header // populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE; this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_HEATHROW; this->device_id = 0x0010;
this->class_rev = 0xFF000001; this->class_rev = 0xFF000001;
this->cache_ln_sz = 8; this->cache_ln_sz = 8;
@@ -106,10 +106,6 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1; this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
} }
void HeathrowIC::set_media_bay_id(uint8_t id) {
this->mb_id = id;
}
void HeathrowIC::notify_bar_change(int bar_num) void HeathrowIC::notify_bar_change(int bar_num)
{ {
if (bar_num) // only BAR0 is supported if (bar_num) // only BAR0 is supported
@@ -299,22 +295,22 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
switch (offset & 0xFC) { switch (offset & 0xFC) {
case MIO_INT_EVENTS2: case MIO_INT_EVENTS2:
value = this->int_events >> 32; value = this->int_events2;
break; break;
case MIO_INT_MASK2: case MIO_INT_MASK2:
value = this->int_mask >> 32; value = this->int_mask2;
break; break;
case MIO_INT_LEVELS2: case MIO_INT_LEVELS2:
value = this->int_levels >> 32; value = this->int_levels2;
break; break;
case MIO_INT_EVENTS1: case MIO_INT_EVENTS1:
value = uint32_t(this->int_events); value = this->int_events1;
break; break;
case MIO_INT_MASK1: case MIO_INT_MASK1:
value = uint32_t(this->int_mask); value = this->int_mask1;
break; break;
case MIO_INT_LEVELS1: case MIO_INT_LEVELS1:
value = uint32_t(int_levels); value = this->int_levels1;
break; break;
case MIO_INT_CLEAR1: case MIO_INT_CLEAR1:
case MIO_INT_CLEAR2: case MIO_INT_CLEAR2:
@@ -343,24 +339,25 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) { void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) { switch (offset & 0xFC) {
case MIO_INT_MASK2: case MIO_INT_MASK2:
this->int_mask |= uint64_t(BYTESWAP_32(value) & ~MACIO_INT_MODE) << 32; this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
this->signal_cpu_int(); this->signal_cpu_int();
break; break;
case MIO_INT_CLEAR2: case MIO_INT_CLEAR2:
this->int_events &= ~(uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL) << 32); this->int_events2 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
clear_cpu_int(); clear_cpu_int();
break; break;
case MIO_INT_MASK1: case MIO_INT_MASK1:
this->int_mask = (this->int_mask & 0x7FFFFFFF00000000ULL) | BYTESWAP_32(value); this->int_mask1 = BYTESWAP_32(value);
// copy IntMode bit to InterruptMask2 register // copy IntMode bit to InterruptMask2 register
this->int_mask |= uint64_t(this->int_mask & MACIO_INT_MODE) << 32; this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
this->signal_cpu_int(); this->signal_cpu_int();
break; break;
case MIO_INT_CLEAR1: case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) { if ((this->int_mask1 & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events = 0; this->int_events1 = 0;
this->int_events2 = 0;
} else { } else {
this->int_events &= ~uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL); this->int_events1 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
} }
clear_cpu_int(); clear_cpu_int();
break; break;
@@ -380,7 +377,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
} }
} }
void HeathrowIC::feature_control(uint32_t value) void HeathrowIC::feature_control(const uint32_t value)
{ {
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value); LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
@@ -393,9 +390,20 @@ void HeathrowIC::feature_control(uint32_t value)
} }
} }
#define INT_TO_IRQ_ID(intx) (1ULL << intx) #define FIRST_INT1_BIT 12 // The first ten are DMA, the next 2 appear to be unused. We'll map 1:1 the INT1 bits 31..12 (0x1F..0x0C) as IRQ_ID bits.
#define FIRST_INT2_BIT 2 // Skip the first two which are Ethernet DMA. We'll map INT2 bits 13..2 (interrupts 45..34 or 0x2D..0x22) as IRQ_ID bits 11..0.
#define FIRST_INT1_IRQ_ID_BIT 12 // Same as INT1_BIT so there won't be any shifting required.
#define FIRST_INT2_IRQ_ID_BIT 0
uint64_t HeathrowIC::register_dev_int(IntSrc src_id) #define INT1_TO_IRQ_ID(int1) (1 << (int1 - FIRST_INT1_BIT + FIRST_INT1_IRQ_ID_BIT))
#define INT2_TO_IRQ_ID(int2) (1 << (int2 - FIRST_INT2_BIT + FIRST_INT2_IRQ_ID_BIT - 32))
#define INT_TO_IRQ_ID(intx) (intx < 32 ? INT1_TO_IRQ_ID(intx) : INT2_TO_IRQ_ID(intx))
#define IS_INT1(irq_id) (irq_id >= 1 << FIRST_INT1_IRQ_ID_BIT)
#define IRQ_ID_TO_INT1_MASK(irq_id) (irq_id <<= (FIRST_INT1_BIT - FIRST_INT1_IRQ_ID_BIT))
#define IRQ_ID_TO_INT2_MASK(irq_id) (irq_id <<= (FIRST_INT2_BIT - FIRST_INT2_IRQ_ID_BIT))
uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
{ {
switch (src_id) { switch (src_id) {
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C); case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
@@ -432,65 +440,191 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
return 0; return 0;
} }
uint64_t HeathrowIC::register_dma_int(IntSrc src_id) #define FIRST_DMA_INT1_BIT 0 // bit 0 is SCSI DMA
#define FIRST_DMA_INT2_BIT 0 // bit 0 is Ethernet DMA Tx
#define FIRST_DMA_INT1_IRQ_ID_BIT 0
#define FIRST_DMA_INT2_IRQ_ID_BIT 16 // There's only 10 INT1 DMA bits but we'll put INT2 DMA bits in the upper 16 bits
#define DMA_INT1_TO_IRQ_ID(int1) (1 << (int1 - FIRST_DMA_INT1_BIT + FIRST_DMA_INT1_IRQ_ID_BIT))
#define DMA_INT2_TO_IRQ_ID(int2) (1 << (int2 - FIRST_DMA_INT2_BIT + FIRST_DMA_INT2_IRQ_ID_BIT - 32))
#define DMA_INT_TO_IRQ_ID(intx) (intx < 32 ? DMA_INT1_TO_IRQ_ID(intx) : DMA_INT2_TO_IRQ_ID(intx))
#define IS_DMA_INT1(irq_id) (irq_id < 1 << FIRST_DMA_INT2_IRQ_ID_BIT)
#define DMA_IRQ_ID_TO_INT1_MASK(irq_id) (irq_id <<= (FIRST_DMA_INT1_BIT - FIRST_DMA_INT1_IRQ_ID_BIT))
#define DMA_IRQ_ID_TO_INT2_MASK(irq_id) (irq_id >>= (FIRST_DMA_INT2_IRQ_ID_BIT - FIRST_DMA_INT2_BIT))
uint32_t HeathrowIC::register_dma_int(IntSrc src_id)
{ {
switch (src_id) { switch (src_id) {
case IntSrc::DMA_SCSI_MESH : return INT_TO_IRQ_ID(0x00); case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01); case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02); case IntSrc::DMA_IDE0 : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_IDE1 : return INT_TO_IRQ_ID(0x03); case IntSrc::DMA_IDE1 : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04); case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05); case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06); case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07); case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08); case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09); case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_ETHERNET_Tx : return INT_TO_IRQ_ID(0x20); case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x20);
case IntSrc::DMA_ETHERNET_Rx : return INT_TO_IRQ_ID(0x21); case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x21);
default: default:
ABORT_F("Heathrow: unknown DMA interrupt source %d", src_id); ABORT_F("Heathrow: unknown DMA interrupt source %d", src_id);
} }
return 0; return 0;
} }
void HeathrowIC::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
{ {
// native mode: set IRQ bits in int_events on a 0-to-1 transition #if 1
// emulated mode: set IRQ bits in int_events on all transitions if (!IS_INT1(irq_id)) { // does this irq_id belong to the second set?
IRQ_ID_TO_INT2_MASK(irq_id);
#if 0 #if 0
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d", LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d",
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events), uint32_t(this->int_levels >> 32), this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state
uint32_t(this->int_levels), uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state );
);
#endif #endif
if ((this->int_mask & MACIO_INT_MODE) || // native mode: set IRQ bits in int_events2 on a 0-to-1 transition
(irq_line_state && !(this->int_levels & irq_id))) { // emulated mode: set IRQ bits in int_events2 on all transitions
this->int_events |= irq_id; if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels2 & irq_id))) {
this->int_events2 |= irq_id;
} else {
this->int_events2 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else { } else {
this->int_events &= ~irq_id; IRQ_ID_TO_INT1_MASK(irq_id);
} // native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// update IRQ line state // emulated mode: set IRQ bits in int_events1 on all transitions
if (irq_line_state) { #if 0
this->int_levels |= irq_id; LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d",
} else { this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state);
this->int_levels &= ~irq_id; #endif
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels1 & irq_id))) {
this->int_events1 |= irq_id;
} else {
this->int_events1 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
} }
this->signal_cpu_int(); this->signal_cpu_int();
#endif
#if 0
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
if (!IS_INT1(irq_id)) {
IRQ_ID_TO_INT2_MASK(irq_id);
this->int_events2 |= irq_id; // signal IRQ line change
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
IRQ_ID_TO_INT1_MASK(irq_id);
this->int_events1 |= irq_id; // signal IRQ line change
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
this->signal_cpu_int();
} else {
LOG_F(WARNING, "%s: native interrupt mode not implemented", this->name.c_str());
}
#endif
} }
void HeathrowIC::ack_int(uint64_t irq_id, uint8_t irq_line_state) void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
{ {
this->ack_int_common(irq_id, irq_line_state); #if 1
} if (!IS_DMA_INT1(irq_id)) {
DMA_IRQ_ID_TO_INT2_MASK(irq_id);
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events2 on all transitions
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels2 & irq_id))) {
this->int_events2 |= irq_id;
} else {
this->int_events2 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
DMA_IRQ_ID_TO_INT1_MASK(irq_id);
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events1 on all transitions
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels1 & irq_id))) {
this->int_events1 |= irq_id;
} else {
this->int_events1 &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
void HeathrowIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) this->signal_cpu_int();
{ #endif
this->ack_int_common(irq_id, irq_line_state);
#if 0
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
if (!IS_DMA_INT1(irq_id)) {
DMA_IRQ_ID_TO_INT2_MASK(irq_id);
this->int_events2 |= irq_id; // signal IRQ line change
this->int_events2 &= this->int_mask2;
// update IRQ line state
if (irq_line_state) {
this->int_levels2 |= irq_id;
} else {
this->int_levels2 &= ~irq_id;
}
} else {
DMA_IRQ_ID_TO_INT1_MASK(irq_id);
this->int_events1 |= irq_id; // signal IRQ line change
this->int_events1 &= this->int_mask1;
// update IRQ line state
if (irq_line_state) {
this->int_levels1 |= irq_id;
} else {
this->int_levels1 &= ~irq_id;
}
}
this->signal_cpu_int();
} else {
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
}
#endif
} }
void HeathrowIC::signal_cpu_int() { void HeathrowIC::signal_cpu_int() {
if (this->int_events & this->int_mask) { if ((this->int_events1 & this->int_mask1) || (this->int_events2 & this->int_mask2)) {
if (!this->cpu_int_latch) { if (!this->cpu_int_latch) {
this->cpu_int_latch = true; this->cpu_int_latch = true;
ppc_assert_int(); ppc_assert_int();
@@ -502,7 +636,8 @@ void HeathrowIC::signal_cpu_int() {
void HeathrowIC::clear_cpu_int() void HeathrowIC::clear_cpu_int()
{ {
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) { if (!(this->int_events1 & this->int_mask1) && !(this->int_events2 & this->int_mask2) &&
this->cpu_int_latch) {
this->cpu_int_latch = false; this->cpu_int_latch = false;
ppc_release_int(); ppc_release_int();
LOG_F(5, "Heathrow: CPU INT latch cleared"); LOG_F(5, "Heathrow: CPU INT latch cleared");
+36 -63
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -70,14 +70,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
#include <memory> #include <memory>
/** PCI device IDs for various MacIO ASICs. */
enum {
MIO_DEV_ID_GRANDCENTRAL = 0x0002,
MIO_DEV_ID_OHARE = 0x0007,
MIO_DEV_ID_HEATHROW = 0x0010,
MIO_DEV_ID_PADDINGTON = 0x0017,
};
/** Interrupt related constants. */ /** Interrupt related constants. */
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers #define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style #define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
@@ -148,21 +140,21 @@ public:
} }
// MMIO device methods // MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override; uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override; void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
// InterruptCtrl methods // InterruptCtrl methods
void attach_iodevice(int dev_num, IobusDevice* dev_obj); uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
uint64_t register_dev_int(IntSrc src_id) override; void attach_iodevice(int dev_num, IobusDevice* dev_obj);
uint64_t register_dma_int(IntSrc src_id) override;
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
protected: protected:
void notify_bar_change(int bar_num); void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state); void ack_int_common(uint32_t irq_id, uint8_t irq_line_state);
void signal_cpu_int(uint64_t irq_id); void signal_cpu_int(uint32_t irq_id);
void clear_cpu_int(); void clear_cpu_int();
private: private:
@@ -216,26 +208,22 @@ public:
} }
// MMIO device methods // MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override; uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override; void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
// InterruptCtrl methods // InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override; uint32_t register_dev_int(IntSrc src_id);
uint64_t register_dma_int(IntSrc src_id) override; uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
protected: protected:
void notify_bar_change(int bar_num); void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state); uint32_t read_ctrl(uint32_t offset, int size);
uint32_t mio_ctrl_read(uint32_t offset, int size); void write_ctrl(uint32_t offset, uint32_t value, int size);
uint32_t mio_ctrl_read_aligned(uint32_t offset);
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
uint32_t dma_read(uint32_t offset, int size); uint32_t dma_read(uint32_t offset, int size);
void dma_write(uint32_t offset, uint32_t value, int size); void dma_write(uint32_t offset, uint32_t value, int size);
void feature_control(const uint32_t value);
void signal_cpu_int(); void signal_cpu_int();
void clear_cpu_int(); void clear_cpu_int();
@@ -247,25 +235,13 @@ private:
std::atomic<uint32_t> int_levels{0}; std::atomic<uint32_t> int_levels{0};
std::atomic<uint32_t> int_events{0}; std::atomic<uint32_t> int_events{0};
bool cpu_int_latch = false; bool cpu_int_latch = false;
uint32_t feat_ctrl = 0; // features control register
// subdevice objects std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
MacioSndCodec* snd_codec; // audio codec instance
NVram* nvram; // NVRAM
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
MeshController* mesh; // MESH SCSI cell instance
EsccController* escc; // ESCC serial controller
IdeChannel* ide_0; // Internal ATA
Swim3::Swim3Ctrl* swim3; // floppy disk controller
// DMA channels
std::unique_ptr<DMAChannel> mesh_dma;
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> snd_out_dma; std::unique_ptr<DMAChannel> snd_out_dma;
uint16_t unsupported_dma_channel_read = 0; NVram* nvram; // NVRAM module
uint16_t unsupported_dma_channel_write = 0; ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
EsccController* escc; // ESCC serial controller
}; };
/** /**
@@ -371,17 +347,15 @@ public:
return std::unique_ptr<HeathrowIC>(new HeathrowIC()); return std::unique_ptr<HeathrowIC>(new HeathrowIC());
} }
void set_media_bay_id(uint8_t id);
// MMIO device methods // MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override; uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override; void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
// InterruptCtrl methods // InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override; uint32_t register_dev_int(IntSrc src_id);
uint64_t register_dma_int(IntSrc src_id) override; uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override; void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
protected: protected:
uint32_t dma_read(uint32_t offset, int size); uint32_t dma_read(uint32_t offset, int size);
@@ -391,24 +365,23 @@ protected:
void mio_ctrl_write(uint32_t offset, uint32_t value, int size); void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
void notify_bar_change(int bar_num); void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
void feature_control(uint32_t value); void feature_control(const uint32_t value);
void signal_cpu_int(); void signal_cpu_int();
void clear_cpu_int(); void clear_cpu_int();
private: private:
uint32_t base_addr = 0; uint32_t base_addr = 0;
std::atomic<uint32_t> int_events2{0};
// interrupt state uint32_t int_mask2 = 0;
uint64_t int_mask = 0; std::atomic<uint32_t> int_levels2{0};
std::atomic<uint64_t> int_levels{0}; std::atomic<uint32_t> int_events1{0};
std::atomic<uint64_t> int_events{0}; uint32_t int_mask1 = 0;
bool cpu_int_latch = false; std::atomic<uint32_t> int_levels1{0};
uint32_t feat_ctrl = 0; // features control register uint32_t feat_ctrl = 0; // features control register
uint32_t aux_ctrl = 0; // aux features control register uint32_t aux_ctrl = 0; // aux features control register
bool cpu_int_latch = false;
uint8_t cpu_id = 0xE0; // CPUID field (LSB of the MIO_HEAT_ID) uint8_t cpu_id = 0xE0; // CPUID field (LSB of the MIO_HEAT_ID)
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID) uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
+92 -260
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,26 +21,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h> #include <cpu/ppc/ppcemu.h>
#include <devices/deviceregistry.h> #include <devices/deviceregistry.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/dbdma.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/viacuda.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/macio.h> #include <devices/ioctrl/macio.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
#include <endianswap.h> #include <endianswap.h>
#include <loguru.hpp> #include <loguru.hpp>
#include <machines/machinebase.h> #include <machines/machinebase.h>
#include <cinttypes> #include <cinttypes>
#include <functional>
#include <memory>
namespace loguru { namespace loguru {
enum : Verbosity { enum : Verbosity {
Verbosity_INTERRUPT = loguru::Verbosity_9, Verbosity_INTERRUPT = loguru::Verbosity_9
Verbosity_DBDMA = loguru::Verbosity_9
}; };
} }
@@ -50,7 +40,7 @@ OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
// populate my PCI config header // populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE; this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_OHARE; this->device_id = 0x0007;
this->class_rev = 0xFF000001; this->class_rev = 0xFF000001;
this->cache_ln_sz = 8; this->cache_ln_sz = 8;
@@ -66,44 +56,17 @@ OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
// connect Cuda // connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda")); this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// find appropriate sound chip, create a DMA output channel for sound, // initialize sound chip and its DMA output channel, then wire them together
// then wire everything together this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_out")); this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_out"));
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx)); this->awacs->set_dma_out(this->snd_out_dma.get());
this->snd_codec->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks( this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec), std::bind(&AwacsScreamer::dma_out_start, this->awacs.get()),
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec) std::bind(&AwacsScreamer::dma_out_stop, this->awacs.get())
); );
// connect SCSI HW and the corresponding DMA channel
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
this->mesh_dma->connect(this->mesh);
this->mesh->connect(this->mesh_dma.get());
// connect IDE HW
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
//this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
// connect serial HW // connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc")); this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
// connect floppy disk HW and initialize its DMA channel
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel("floppy"));
this->swim3->set_dma_channel(this->floppy_dma.get());
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
// connect Ethernet HW
//this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
//this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
//this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
// set EMMO pin status (active low) FIXME: Is there an emmo pin?
//this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
} }
void OHare::notify_bar_change(int bar_num) void OHare::notify_bar_change(int bar_num)
@@ -113,7 +76,8 @@ void OHare::notify_bar_change(int bar_num)
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) { if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
if (this->base_addr) { if (this->base_addr) {
this->host_instance->pci_unregister_mmio_region(this->base_addr, 0x80000, this); LOG_F(WARNING, "%s: deallocating I/O memory not implemented",
this->get_name().c_str());
} }
this->base_addr = this->bars[0] & 0xFFFFFFF0UL; this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this); this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
@@ -123,155 +87,98 @@ void OHare::notify_bar_change(int bar_num)
uint32_t OHare::read(uint32_t rgn_start, uint32_t offset, int size) uint32_t OHare::read(uint32_t rgn_start, uint32_t offset, int size)
{ {
uint32_t value;
LOG_F(9, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
unsigned sub_addr = (offset >> 12) & 0x7F; unsigned sub_addr = (offset >> 12) & 0x7F;
switch (sub_addr) { switch (sub_addr) {
case 0: case 0:
value = mio_ctrl_read(offset, size); return read_ctrl(offset, size);
break;
case 8: case 8:
value = dma_read(offset & 0x7FFF, size); return dma_read(offset & 0x7FFF, size);
break;
case 0x10: // SCSI
value = this->mesh->read((offset >> 4) & 0xF);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
value = this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
break;
}
if ((offset & 0xFF) < 0x60) {
value = 0;
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
break;
}
// fallthrough
case 0x13: // ESCC MacRISC addressing case 0x13: // ESCC MacRISC addressing
value = this->escc->read((offset >> 4) & 0xF); return this->escc->read((offset >> 4) & 0xF);
break; case 0x14: // AWACS
case 0x14: return this->awacs->snd_ctrl_read(offset & 0xFF, size);
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size); case 0x16:
break;
case 0x15: // SWIM3
value = this->swim3->read((offset >> 4) & 0xF);
break;
case 0x16: // VIA-CUDA
case 0x17: case 0x17:
value = this->viacuda->read((offset >> 9) & 0xF); return this->viacuda->read((offset >> 9) & 0xF);
break; case 0x20:
case 0x20: // IDE 0 return 0xFF7FU;
value = this->ide_0->read((offset >> 4) & 0x1F, size);
break;
default: default:
if (sub_addr >= 0x60) { if (sub_addr >= 0x60) {
value = this->nvram->read_byte((offset - 0x60000) >> 4); return this->nvram->read_byte((offset - 0x60000) >> 4);
} else { } else {
value = 0; LOG_F(WARNING, "OHare: read from unimplemented register 0x%X",
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(), this->base_addr + offset);
offset, SIZE_ARG(size));
} }
} }
return value; return 0xFFFFFFFFUL;
} }
void OHare::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) void OHare::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{ {
LOG_F(9, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
unsigned sub_addr = (offset >> 12) & 0x7F; unsigned sub_addr = (offset >> 12) & 0x7F;
switch (sub_addr) { switch (sub_addr) {
case 0: case 0:
this->mio_ctrl_write(offset, value, size); this->write_ctrl(offset, value, size);
break; break;
case 8: case 8:
this->dma_write(offset & 0x7FFF, value, size); this->dma_write(offset & 0x7FFF, value, size);
break; break;
case 0x10: // SCSI
this->mesh->write((offset >> 4) & 0xF, value);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
break;
}
if ((offset & 0xFF) < 0x60) {
LOG_F(ERROR, "%s: SCC write @%x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
break;
}
// fallthrough
case 0x13: // ESCC MacRISC addressing case 0x13: // ESCC MacRISC addressing
this->escc->write((offset >> 4) & 0xF, value); this->escc->write((offset >> 4) & 0xF, value);
break; break;
case 0x14: case 0x14: // AWACS
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size); this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
break; break;
case 0x15: // SWIM3 case 0x16:
this->swim3->write((offset >> 4) & 0xF, value); case 0x17: // VIA-CUDA
break;
case 0x16: // VIA-CUDA
case 0x17:
this->viacuda->write((offset >> 9) & 0xF, value); this->viacuda->write((offset >> 9) & 0xF, value);
break; break;
case 0x20: // IDE 0 case 0x20:
this->ide_0->write((offset >> 4) & 0x1F, value, size); LOG_F(INFO, "OHare: write to IDE0 register at 0x%X", offset);
break; break;
default: default:
if (sub_addr >= 0x60) { if (sub_addr >= 0x60) {
this->nvram->write_byte((offset - 0x60000) >> 4, value); this->nvram->write_byte((offset - 0x60000) >> 4, value);
} else { } else {
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(), LOG_F(WARNING, "OHare: writing to unimplemented device register 0x%X",
offset, SIZE_ARG(size), size * 2, value); this->base_addr + offset);
} }
} }
} }
uint32_t OHare::mio_ctrl_read(uint32_t offset, int size) { uint32_t OHare::read_ctrl(uint32_t offset, int size)
uint32_t value; {
uint32_t res = 0;
switch (offset & 0xFC) { switch (offset & 0xFC) {
case MIO_INT_EVENTS1:
value = this->int_events;
break;
case MIO_INT_MASK1: case MIO_INT_MASK1:
value = this->int_mask; res = this->int_mask;
break; break;
case MIO_INT_LEVELS1: case MIO_INT_LEVELS1:
value = this->int_levels; res = this->int_levels;
break; break;
case MIO_OHARE_ID: // FIXME: HACK: no clue what this register is supposed to contain case MIO_INT_EVENTS1:
value = ~0x00004000; // 1<<14 res = this->int_events;
LOG_F(ERROR, "%s: read OHARE_ID @%02x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
case MIO_OHARE_FEAT_CTRL:
value = this->feat_ctrl;
LOG_F(WARNING, "%s: read FEAT_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break; break;
case MIO_OHARE_ID: // HACK: no clue what this register is supposed to contain
res = 0xFFFFBFFFUL;
default: default:
value = 0; LOG_F(WARNING, "OHare: read from unknown control register at %x", offset);
LOG_F(WARNING, "%s: read @%02x.%c", break;
this->get_name().c_str(), offset, SIZE_ARG(size));
} }
return BYTESWAP_32(value); return BYTESWAP_32(res);
} }
void OHare::mio_ctrl_write(uint32_t offset, uint32_t value, int size) { void OHare::write_ctrl(uint32_t offset, uint32_t value, int size)
{
switch (offset) { switch (offset) {
case MIO_INT_MASK1: case MIO_INT_MASK1:
this->int_mask = BYTESWAP_32(value); this->int_mask = BYTESWAP_32(value);
LOG_F(INTERRUPT, "%s: int_mask:0x%08x", name.c_str(), this->int_mask); LOG_F(INFO, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
this->signal_cpu_int();
break; break;
case MIO_INT_CLEAR1: case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) { if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
@@ -281,64 +188,28 @@ void OHare::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
} }
clear_cpu_int(); clear_cpu_int();
break; break;
case MIO_INT_LEVELS1:
LOG_F(INTERRUPT, "%s: write INT_LEVELS1 @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value); // writing 0x100000 happens often
break;
case MIO_OHARE_ID:
LOG_F(ERROR, "%s: write OHARE_ID @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(WARNING, "%s: write FEAT_CTRL @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
this->feature_control(BYTESWAP_32(value));
break;
default: default:
LOG_F(WARNING, "%s: write @%x.%c = %0*x", LOG_F(WARNING, "OHare: writing to unimplemented control register 0x%X",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value); this->base_addr + offset);
} }
} }
uint32_t OHare::dma_read(uint32_t offset, int size) uint32_t OHare::dma_read(uint32_t offset, int size)
{ {
uint32_t value; switch (offset >> 8) {
int dma_channel = offset >> 8; case 8:
switch (dma_channel) { return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma)
value = this->mesh_dma->reg_read(offset & 0xFF, size);
else
value = 0;
break;
case MIO_OHARE_DMA_FLOPPY:
value = this->floppy_dma->reg_read(offset & 0xFF, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
value = this->snd_out_dma->reg_read(offset & 0xFF, size);
break;
default: default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) { LOG_F(WARNING, "OHare: unsupported DMA channel read, offset=0x%X", offset);
unsupported_dma_channel_read |= (1 << dma_channel);
return 0;
}
value = 0;
} }
return value;
return 0xFFFFFFUL;
} }
void OHare::dma_write(uint32_t offset, uint32_t value, int size) void OHare::dma_write(uint32_t offset, uint32_t value, int size)
{ {
int dma_channel = offset >> 8; switch (offset >> 8) {
case 8:
switch (dma_channel) {
case MIO_OHARE_DMA_MESH:
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_FLOPPY:
this->floppy_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size); this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break; break;
default: default:
@@ -346,106 +217,67 @@ void OHare::dma_write(uint32_t offset, uint32_t value, int size)
} }
} }
void OHare::feature_control(const uint32_t value) uint32_t OHare::register_dev_int(IntSrc src_id)
{ {
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value); LOG_F(ERROR, "OHare: register_dev_int() not implemented");
this->feat_ctrl = value;
if (!(this->feat_ctrl & 1)) {
LOG_F(9, "%s: Monitor sense enabled", this->get_name().c_str());
} else {
LOG_F(9, "%s: Monitor sense disabled", this->get_name().c_str());
}
}
#define INT_TO_IRQ_ID(intx) (1 << intx)
uint64_t OHare::register_dev_int(IntSrc src_id)
{
switch (src_id) {
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D);
// case IntSrc::IDE1 : return INT_TO_IRQ_ID(0x0E);
case IntSrc::SCCA : return INT_TO_IRQ_ID(0x0F);
case IntSrc::SCCB : return INT_TO_IRQ_ID(0x10);
case IntSrc::DAVBUS : return INT_TO_IRQ_ID(0x11);
case IntSrc::VIA_CUDA : return INT_TO_IRQ_ID(0x12);
case IntSrc::SWIM3 : return INT_TO_IRQ_ID(0x13);
// case IntSrc::NMI : return INT_TO_IRQ_ID(0x14);
// case IntSrc::EXT1 : return INT_TO_IRQ_ID(0x15);
case IntSrc::BANDIT1 : return INT_TO_IRQ_ID(0x16);
case IntSrc::PCI_E : return INT_TO_IRQ_ID(0x16); // same interrupt as bandit
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
case IntSrc::PCI_F : return INT_TO_IRQ_ID(0x18);
case IntSrc::PCI_B : return INT_TO_IRQ_ID(0x19);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1A);
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1B);
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x1C);
default:
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
}
return 0; return 0;
} }
uint64_t OHare::register_dma_int(IntSrc src_id) uint32_t OHare::register_dma_int(IntSrc src_id)
{ {
switch (src_id) { LOG_F(ERROR, "OHare: register_dma_int() not implemented");
case IntSrc::DMA_SCSI_MESH: return INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02);
//
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx: return INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx: return INT_TO_IRQ_ID(0x09);
default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
}
return 0; return 0;
} }
void OHare::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) void OHare::ack_int(uint32_t irq_id, uint8_t irq_line_state)
{ {
// native mode: set IRQ bits in int_events on a 0-to-1 transition // native mode: set IRQ bits in int_events1 on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions // emulated mode: set IRQ bits in int_events1 on all transitions
#if 0 #if 1
LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d", LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
); );
#endif #endif
if ((this->int_mask & MACIO_INT_MODE) || if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) { (irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= (uint32_t)irq_id; this->int_events |= irq_id;
} else { } else {
this->int_events &= ~(uint32_t)irq_id; this->int_events &= ~irq_id;
} }
this->int_events &= this->int_mask;
// update IRQ line state // update IRQ line state
if (irq_line_state) { if (irq_line_state) {
this->int_levels |= (uint32_t)irq_id; this->int_levels |= irq_id;
} else { } else {
this->int_levels &= ~(uint32_t)irq_id; this->int_levels &= ~irq_id;
} }
this->signal_cpu_int(); this->signal_cpu_int();
} }
void OHare::ack_int(uint64_t irq_id, uint8_t irq_line_state) void OHare::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
{ {
this->ack_int_common(irq_id, irq_line_state); // native mode: set IRQ bits in int_events1 on a 0-to-1 transition
} // emulated mode: set IRQ bits in int_events1 on all transitions
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= irq_id;
} else {
this->int_events &= ~irq_id;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
} else {
this->int_levels &= ~irq_id;
}
void OHare::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) this->signal_cpu_int();
{
this->ack_int_common(irq_id, irq_line_state);
} }
void OHare::signal_cpu_int() { void OHare::signal_cpu_int() {
if (this->int_events & this->int_mask) { if (this->int_events) {
if (!this->cpu_int_latch) { if (!this->cpu_int_latch) {
this->cpu_int_latch = true; this->cpu_int_latch = true;
ppc_assert_int(); ppc_assert_int();
@@ -457,7 +289,7 @@ void OHare::signal_cpu_int() {
void OHare::clear_cpu_int() void OHare::clear_cpu_int()
{ {
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) { if (!this->int_events) {
this->cpu_int_latch = false; this->cpu_int_latch = false;
ppc_release_int(); ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str()); LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
@@ -465,11 +297,11 @@ void OHare::clear_cpu_int()
} }
static const std::vector<std::string> OHare_Subdevices = { static const std::vector<std::string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0" "NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3"
}; };
static const DeviceDescription OHare_Descriptor = { static const DeviceDescription OHare_Descriptor = {
OHare::create, OHare_Subdevices, { OHare::create, OHare_Subdevices, {}
}}; };
REGISTER_DEVICE(OHare, OHare_Descriptor); REGISTER_DEVICE(OHare, OHare_Descriptor);
+1 -1
View File
@@ -31,7 +31,7 @@ AspenCtrl::AspenCtrl() : MemCtrlBase() {
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for the configuration and status registers // add MMIO region for the configuration and status registers
this->add_mmio_region(0xF8000000, 0x800, this); add_mmio_region(0xF8000000, 0x800, this);
} }
int AspenCtrl::device_postinit() { int AspenCtrl::device_postinit() {
+1 -1
View File
@@ -46,7 +46,7 @@ enum {
GPIO_OUT = 14, // 0x38 GPIO_OUT = 14, // 0x38
}; };
constexpr auto ASPEN_REV_1 = 0x01000000; #define ASPEN_REV_1 0x01000000
/** Aspen RAM bank size bits. */ /** Aspen RAM bank size bits. */
enum { enum {
+1 -1
View File
@@ -37,7 +37,7 @@ HammerheadCtrl::HammerheadCtrl() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for the configuration and status registers // add MMIO region for the configuration and status registers
this->add_mmio_region(0xF8000000, 0x500, this); add_mmio_region(0xF8000000, 0x500, this);
} }
uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size) uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
+4 -4
View File
@@ -38,10 +38,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory> #include <memory>
namespace Hammerhead { namespace Hammerhead {
constexpr auto RISC_MACHINE = 0x3; #define RISC_MACHINE 0x3
constexpr auto MACH_TYPE_TNT = 0x1; #define MACH_TYPE_TNT 0x1
constexpr auto EXTENDED_ID = 0x1; // examine some other registers to get full ID #define EXTENDED_ID 0x1 // examine some other registers to get full ID
constexpr auto HH_CPU_ID_TNT = ((RISC_MACHINE << 4) | (EXTENDED_ID << 3) | MACH_TYPE_TNT); #define HH_CPU_ID_TNT ((RISC_MACHINE << 4) | (EXTENDED_ID << 3) | MACH_TYPE_TNT)
// constants for the MBID field of the MOTHERBOARD_ID register // constants for the MBID field of the MOTHERBOARD_ID register
enum { enum {
+1 -1
View File
@@ -36,7 +36,7 @@ HMC::HMC() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add memory mapped I/O region for the HMC control register // add memory mapped I/O region for the HMC control register
this->add_mmio_region(0x50F40000, 0x10000, this); add_mmio_region(0x50F40000, 0x10000, this);
this->ctrl_reg = 0ULL; this->ctrl_reg = 0ULL;
this->bit_pos = 0; this->bit_pos = 0;
+3 -3
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -75,9 +75,9 @@ public:
int install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_b_size); int install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_b_size);
uint64_t get_control_reg(void) const { uint64_t get_control_reg(void) {
return this->ctrl_reg; return this->ctrl_reg;
} };
protected: protected:
void remap_ram_regions(); void remap_ram_regions();
+2 -2
View File
@@ -46,10 +46,10 @@ MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
this->status = 0x80; this->status = 0x80;
// add PCI/ISA I/O space, 64K for now // add PCI/ISA I/O space, 64K for now
this->add_mmio_region(0xFE000000, 0x10000, this); add_mmio_region(0xFE000000, 0x10000, this);
// add memory mapped I/O region for MPC106 registers // add memory mapped I/O region for MPC106 registers
this->add_mmio_region(0xFEC00000, 0x300000, this); add_mmio_region(0xFEC00000, 0x300000, this);
} }
int MPC106::device_postinit() int MPC106::device_postinit()
+2 -2
View File
@@ -40,10 +40,10 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for VRAM // add MMIO region for VRAM
this->add_mmio_region(VRAM_REGION_BASE, 0x01000000, this); add_mmio_region(VRAM_REGION_BASE, 0x01000000, this);
// add MMIO region for the configuration and status registers // add MMIO region for the configuration and status registers
this->add_mmio_region(PLATINUM_IOREG_BASE, 0x500, this); add_mmio_region(PLATINUM_IOREG_BASE, 0x500, this);
// get VRAM size // get VRAM size
this->vram_megs = GET_INT_PROP("gfxmem_size"); this->vram_megs = GET_INT_PROP("gfxmem_size");
+1 -1
View File
@@ -35,7 +35,7 @@ PsxCtrl::PsxCtrl(int bridge_num, std::string name)
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV); supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// add MMIO region for the PSX control registers // add MMIO region for the PSX control registers
this->add_mmio_region(0xF8000000, 0x70, this); add_mmio_region(0xF8000000, 0x70, this);
this->sys_id = 0x10000000; this->sys_id = 0x10000000;
this->chip_rev = 0; // old PSX, what's about PSX+? this->chip_rev = 0; // old PSX, what's about PSX+?
+1 -4
View File
@@ -394,10 +394,7 @@ bool CharIoSocket::rcv_char_available_now()
int received = (int)recv(this->sockfd, &c, 1, 0); int received = (int)recv(this->sockfd, &c, 1, 0);
if (received == -1) { if (received == -1) {
if (this->acceptfd == -1) { if (this->acceptfd == -1) {
#if 0 //LOG_F(INFO, "socket sock read (not accepted yet) err: %s", strerror(errno)); // this happens once before accept
LOG_F(INFO, "socket sock read (not accepted yet) err: %s",
strerror(errno)); // this happens once before accept
#endif
} }
else { else {
LOG_F(INFO, "socket sock read err: %s", strerror(errno)); // should never happen LOG_F(INFO, "socket sock read err: %s", strerror(errno)); // should never happen
+1 -3
View File
@@ -275,9 +275,7 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
this->read_regs[RR0] |= RR0_SYNC_HUNT; this->read_regs[RR0] |= RR0_SYNC_HUNT;
} }
} }
this->write_regs[WR3] = this->write_regs[WR3] = (this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) | (value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
(this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) |
(value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
return; return;
case WR7: case WR7:
if (this->write_regs[WR15] & WR15_SDLC_HDLC_ENHANCEMENT_ENABLE) { if (this->write_regs[WR15] & WR15_SDLC_HDLC_ENHANCEMENT_ENABLE) {
+6 -11
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -215,8 +215,7 @@ enum
WR3_SYNC_CHARACTER_LOAD_INHIBIT = 1 << 1, WR3_SYNC_CHARACTER_LOAD_INHIBIT = 1 << 1,
WR3_RX_ENABLE = 1 << 0, WR3_RX_ENABLE = 1 << 0,
// WR4 - Transmit/Receiver Miscellaneous Parameters and Modes // WR4 - Transmit/Receiver Miscellaneous Parameters and Modes // Transmit/Receive miscellaneous parameters and codes, clock rate, number of sync characters, stop bits, parity
// Transmit/Receive miscellaneous parameters and codes, clock rate, number of sync characters, stop bits, parity
WR4_CLOCK_RATE = 3 << 6, WR4_CLOCK_RATE = 3 << 6,
WR4_X1_CLOCK_MODE = 0 << 6, WR4_X1_CLOCK_MODE = 0 << 6,
@@ -258,8 +257,7 @@ enum
// WR8 - Transmit buffer // WR8 - Transmit buffer
// WR9 - Master Interrupt Control // WR9 - Master Interrupt Control // Master interrupt control and reset (accessed through either channel), reset bits, control interrupt daisy chain
// Master interrupt control and reset (accessed through either channel), reset bits, control interrupt daisy chain
WR9_RESET_COMMAND_BITS = 3 << 6, WR9_RESET_COMMAND_BITS = 3 << 6,
WR9_NO_RESET = 0 << 6, WR9_NO_RESET = 0 << 6,
@@ -274,8 +272,7 @@ enum
WR9_NO_VECTOR = 1 << 1, WR9_NO_VECTOR = 1 << 1,
WR9_VECTOR_INCLUDES_STATUS = 1 << 0, WR9_VECTOR_INCLUDES_STATUS = 1 << 0,
// WR10 - Miscellaneous Transmitter/Receiver Control Bits // WR10 - Miscellaneous Transmitter/Receiver Control Bits // Miscellaneous transmitter/receiver control bits, NRZI, NRZ, FM encoding, CRC reset
// Miscellaneous transmitter/receiver control bits, NRZI, NRZ, FM encoding, CRC reset
WR10_CRC_PRESET = 1 << 7, WR10_CRC_PRESET = 1 << 7,
WR10_DATA_ENCODING = 3 << 5, WR10_DATA_ENCODING = 3 << 5,
@@ -321,8 +318,7 @@ enum
// WR13 - Upper Byte of Baud Rate Generator Time Constant // WR13 - Upper Byte of Baud Rate Generator Time Constant
// WR14 - Miscellaneous Control Bits // WR14 - Miscellaneous Control Bits // Miscellaneous control bits: baud rate generator, Phase-Locked Loop control, auto echo, local loopback
// Miscellaneous control bits: baud rate generator, Phase-Locked Loop control, auto echo, local loopback
WR14_DPLL_COMMAND_BITS = 7 << 5, WR14_DPLL_COMMAND_BITS = 7 << 5,
WR14_DPLL_NULL_COMMAND = 0 << 5, WR14_DPLL_NULL_COMMAND = 0 << 5,
@@ -339,8 +335,7 @@ enum
WR14_BR_GENERATOR_SOURCE = 1 << 1, WR14_BR_GENERATOR_SOURCE = 1 << 1,
WR14_BR_GENERATOR_ENABLE = 1 << 0, WR14_BR_GENERATOR_ENABLE = 1 << 0,
// WR15 - External/Status Interrupt Control // WR15 - External/Status Interrupt Control // External/Status interrupt control information-control external conditions causing interrupts
// External/Status interrupt control information-control external conditions causing interrupts
WR15_SDLC_HDLC_ENHANCEMENT_ENABLE = 1 << 0, WR15_SDLC_HDLC_ENHANCEMENT_ENABLE = 1 << 0,
WR15_ZERO_COUNT_IE = 1 << 1, WR15_ZERO_COUNT_IE = 1 << 1,
+5 -30
View File
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** AWAC sound device emulation. /** AWAC sound device emulation.
Currently supported audio codecs: Currently supported audio codecs:
- PDM AWACs in NuBus Power Macintosh models - PDM AWACs in Nubus Power Macintosh models
- Screamer AWACs in Beige G3 - Screamer AWACs in Beige G3
*/ */
@@ -185,34 +185,18 @@ int AwacsScreamer::device_postinit() {
} }
uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size) { uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size) {
uint32_t value;
switch (offset) { switch (offset) {
case AWAC_SOUND_CTRL_REG: case AWAC_SOUND_CTRL_REG:
value = this->snd_ctrl_reg; return this->snd_ctrl_reg;
break;
case AWAC_CODEC_CTRL_REG: case AWAC_CODEC_CTRL_REG:
value = this->is_busy; return this->is_busy;
break;
case AWAC_CODEC_STATUS_REG: case AWAC_CODEC_STATUS_REG:
value = (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20); return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20);
break;
case AWAC_CLIP_COUNT:
value = this->clip_count;
this->clip_count = 0;
break;
case AWAC_BYTE_SWAP:
value = this->byte_swap ? 0 : 1;
break;
case AWAC_FRAME_COUNT:
value = this->frame_count;
break;
default: default:
LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(), offset); LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(), offset);
value = 0;
} }
return value; return 0;
} }
void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size) { void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
@@ -233,15 +217,6 @@ void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
if (!subframe) if (!subframe)
this->control_regs[reg_num] = data; this->control_regs[reg_num] = data;
break; break;
case AWAC_CLIP_COUNT:
this->clip_count = BYTESWAP_32(value);
break;
case AWAC_BYTE_SWAP:
this->byte_swap = BYTESWAP_32(value);
break;
case AWAC_FRAME_COUNT:
this->frame_count = BYTESWAP_32(value);
break;
default: default:
LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(), LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(),
offset); offset);
-6
View File
@@ -95,9 +95,6 @@ enum {
AWAC_SOUND_CTRL_REG = 0x00, AWAC_SOUND_CTRL_REG = 0x00,
AWAC_CODEC_CTRL_REG = 0x10, AWAC_CODEC_CTRL_REG = 0x10,
AWAC_CODEC_STATUS_REG = 0x20, AWAC_CODEC_STATUS_REG = 0x20,
AWAC_CLIP_COUNT = 0x30,
AWAC_BYTE_SWAP = 0x40,
AWAC_FRAME_COUNT = 0x50,
}; };
/** Apple source calls this kValidData but doesn't explain /** Apple source calls this kValidData but doesn't explain
@@ -189,9 +186,6 @@ private:
uint32_t snd_ctrl_reg = 0; uint32_t snd_ctrl_reg = 0;
uint16_t control_regs[8] = {}; // control registers, each 12-bits wide uint16_t control_regs[8] = {}; // control registers, each 12-bits wide
uint8_t is_busy = 0; uint8_t is_busy = 0;
uint32_t clip_count = 0;
uint32_t byte_swap = 0;
uint32_t frame_count = 0;
std::unique_ptr<AudioProcessor> audio_proc; std::unique_ptr<AudioProcessor> audio_proc;
}; };
+1 -1
View File
@@ -36,7 +36,7 @@ enum {
}; };
/** Number of internal registers implemented in Burgundy. */ /** Number of internal registers implemented in Burgundy. */
constexpr auto BURGUNDY_NUM_REGS = 123; #define BURGUNDY_NUM_REGS 123
class BurgundyCodec : public MacioSndCodec { class BurgundyCodec : public MacioSndCodec {
public: public:
+1 -2
View File
@@ -223,8 +223,7 @@ int SoundServer::start_out_stream()
{ {
if (is_deterministic) { if (is_deterministic) {
LOG_F(9, "Starting sound output deterministic polling."); LOG_F(9, "Starting sound output deterministic polling.");
impl->deterministic_poll_timer = impl->deterministic_poll_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
return 0; return 0;
} }
return cubeb_stream_start(impl->out_stream); return cubeb_stream_start(impl->out_stream);
+3 -3
View File
@@ -44,9 +44,9 @@ typedef struct {
uint32_t start_lba; uint32_t start_lba;
} TrackDescriptor; } TrackDescriptor;
constexpr auto CDROM_MAX_TRACKS = 100; #define CDROM_MAX_TRACKS 100
constexpr auto LEAD_OUT_TRK_NUM = 0xAA; #define LEAD_OUT_TRK_NUM 0xAA
constexpr auto CDR_STD_DATA_SIZE = 2048; #define CDR_STD_DATA_SIZE 2048
class CdromDrive : public BlockStorageDevice { class CdromDrive : public BlockStorageDevice {
public: public:
+3 -5
View File
@@ -53,8 +53,8 @@ enum DacFlavour {
DACULA, DACULA,
}; };
constexpr auto DACULA_VENDOR_SIERRA = 0x3C; // 14.3 MHz #define DACULA_VENDOR_SIERRA 0x3C // 14.3 MHz
constexpr auto DACULA_VENDOR_ATT = 0x84; // 15 MHz #define DACULA_VENDOR_ATT 0x84 // 15 MHz
constexpr auto VIDEO_XTAL = 14318180.0f; // external crystal oscillator frequency constexpr auto VIDEO_XTAL = 14318180.0f; // external crystal oscillator frequency
@@ -70,9 +70,7 @@ enum RamdacRegs : uint8_t {
CURSOR_POS_HI = 0x10, // cursor position, high-order byte CURSOR_POS_HI = 0x10, // cursor position, high-order byte
CURSOR_POS_LO = 0x11, // cursor position, low-order byte CURSOR_POS_LO = 0x11, // cursor position, low-order byte
MISC_CTRL = 0x20, // miscellaneus control bits ; Dacula: read ; when 1MB VRAM then write (mode&15) else write (mode) MISC_CTRL = 0x20, // miscellaneus control bits ; Dacula: read ; when 1MB VRAM then write (mode&15) else write (mode)
DBL_BUF_CTRL = 0x21, // double buffer control bits ; DBL_BUF_CTRL = 0x21, // double buffer control bits ; Dacula: write 4; Radical: set to 0 if using optional bank (bankb) in Open Firmware or for 2nd page in ndrv
// - Dacula: write 4;
// - Radical: set to 0 if using optional bank (bankb) in Open Firmware or for 2nd page in ndrv
TEST_CTRL = 0x22, // enable/disable DAC tests ; Dacula: write 0 TEST_CTRL = 0x22, // enable/disable DAC tests ; Dacula: write 0
// multipurpose section registers (DACula only) // multipurpose section registers (DACula only)
+1 -2
View File
@@ -398,8 +398,7 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
if (bit_changed(old_value, new_value, ATI_CRTC_ENABLE) if (bit_changed(old_value, new_value, ATI_CRTC_ENABLE)
|| extract_bits(old_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size) != || extract_bits(old_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size) != extract_bits(new_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size)
extract_bits(new_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size)
) { ) {
draw_fb = true; draw_fb = true;
if (bit_set(new_value, ATI_CRTC_ENABLE) && if (bit_set(new_value, ATI_CRTC_ENABLE) &&
+11 -20
View File
@@ -36,6 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Kudos to joevt#3510 for his precious technical help and HW hacking. Kudos to joevt#3510 for his precious technical help and HW hacking.
*/ */
#include <devices/common/i2c/athens.h>
#include <devices/common/i2c/i2c.h> #include <devices/common/i2c/i2c.h>
#include <devices/deviceregistry.h> #include <devices/deviceregistry.h>
#include <devices/ioctrl/macio.h> #include <devices/ioctrl/macio.h>
@@ -321,8 +322,7 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
break; break;
case ControlRegs::MON_SENSE: case ControlRegs::MON_SENSE:
value = (this->cur_mon_id << 6) | this->mon_sense; value = (this->cur_mon_id << 6) | this->mon_sense;
LOG_F(CONTROL, "%s: read MON_SENSE %03x.%c = %0*x", this->name.c_str(), LOG_F(CONTROL, "%s: read MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
break; break;
case ControlRegs::MISC_ENABLES: case ControlRegs::MISC_ENABLES:
value = this->enables; value = this->enables;
@@ -349,8 +349,7 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
details.offset = offset & 3; details.offset = offset & 3;
uint32_t result = pci_conv_rd_data(value, value, details); uint32_t result = pci_conv_rd_data(value, value, details);
if ((offset & 3) || (size != 4)) { if ((offset & 3) || (size != 4)) {
LOG_F(WARNING, "%s: read %s %03x.%c = %08x -> %0*x", this->name.c_str(), LOG_F(WARNING, "%s: read %s %03x.%c = %08x -> %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
} }
return result; return result;
@@ -431,11 +430,9 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::PIPE_DELAY: case ControlRegs::PIPE_DELAY:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0x3FF; this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0x3FF;
if (value & ~0x3FF) if (value & ~0x3FF)
LOG_F(ERROR, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), LOG_F(ERROR, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
else else
LOG_F(CONTROL, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), LOG_F(CONTROL, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) { if (this->display_enabled) {
this->enable_display(); this->enable_display();
} }
@@ -443,11 +440,9 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::HEQ: case ControlRegs::HEQ:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFU; this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFU;
if (value & ~0xFFU) if (value & ~0xFFU)
LOG_F(ERROR, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), LOG_F(ERROR, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
else else
LOG_F(CONTROL, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), LOG_F(CONTROL, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) { if (this->display_enabled) {
this->enable_display(); this->enable_display();
} }
@@ -468,11 +463,9 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::HSERR: case ControlRegs::HSERR:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFF; this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFF;
if (value & ~0xFFF) if (value & ~0xFFF)
LOG_F(ERROR, "%s: write %s %03x.%c = %0*x", this->name.c_str(), LOG_F(ERROR, "%s: write %s %03x.%c = %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
else else
LOG_F(CONTROL, "%s: write %s %03x.%c = %0*x", this->name.c_str(), LOG_F(CONTROL, "%s: write %s %03x.%c = %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) { if (this->display_enabled) {
this->enable_display(); this->enable_display();
} }
@@ -518,11 +511,9 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
break; break;
case ControlRegs::MON_SENSE: { case ControlRegs::MON_SENSE: {
if (value & ~0x3F) if (value & ~0x3F)
LOG_F(ERROR, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), LOG_F(ERROR, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
else else
LOG_F(CONTROL, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), LOG_F(CONTROL, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
offset, SIZE_ARG(size), size * 2, value);
uint8_t dirs = ((value >> 3) & 7) ^ 7; uint8_t dirs = ((value >> 3) & 7) ^ 7;
uint8_t levels = ((value & 7) & dirs) | (dirs ^ 7); uint8_t levels = ((value & 7) & dirs) | (dirs ^ 7);
this->mon_sense = value & 0x3F; this->mon_sense = value & 0x3F;
+1 -1
View File
@@ -24,7 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef CONTROL_VIDEO_H #ifndef CONTROL_VIDEO_H
#define CONTROL_VIDEO_H #define CONTROL_VIDEO_H
#include <devices/common/clockgen/athens.h> #include <devices/common/i2c/athens.h>
#include <devices/common/pci/pcidevice.h> #include <devices/common/pci/pcidevice.h>
#include <devices/video/appleramdac.h> #include <devices/video/appleramdac.h>
#include <devices/video/displayid.h> #include <devices/video/displayid.h>
+2 -2
View File
@@ -26,10 +26,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef IBM_RGB514_DEFS_H #ifndef IBM_RGB514_DEFS_H
#define IBM_RGB514_DEFS_H #define IBM_RGB514_DEFS_H
constexpr auto PLL_ENAB = 1;
namespace Rgb514 { namespace Rgb514 {
#define PLL_ENAB 1
/** RGB514 direct register addresses. */ /** RGB514 direct register addresses. */
enum { enum {
// standard VGA registers // standard VGA registers
+8 -13
View File
@@ -21,11 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file TNT on-board NTSC/PAL video output emulation. */ /** @file TNT on-board NTSC/PAL video output emulation. */
#include <devices/video/sixty6.h>
#include <devices/video/control.h>
#include <devices/common/i2c/saa7187.h>
#include <devices/common/machineid.h> #include <devices/common/machineid.h>
#include <devices/deviceregistry.h> #include <devices/deviceregistry.h>
#include <devices/video/control.h>
#include <devices/video/sixty6.h>
#include <loguru.hpp>
#include <machines/machinebase.h> #include <machines/machinebase.h>
namespace loguru { namespace loguru {
@@ -93,26 +93,22 @@ uint16_t Sixty6Video::iodev_read(uint32_t address)
last_control_1_count++; last_control_1_count++;
} else { } else {
if (last_control_1_count) { if (last_control_1_count) {
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", address, last_control_1_value, last_control_1_count);
address, last_control_1_value, last_control_1_count);
} }
last_control_1_value = value; last_control_1_value = value;
last_control_1_count = 0; last_control_1_count = 0;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", address, last_control_1_value, last_control_1_count);
address, last_control_1_value, last_control_1_count);
} }
break; break;
default: default:
value = 0; value = 0;
LOG_F(ERROR, "Sixty6: read %d:CONTROL_DATA 0x%02x = %02x", LOG_F(ERROR, "Sixty6: read %d:CONTROL_DATA 0x%02x = %02x", address, this->control_addr, value);
address, this->control_addr, value);
} }
break; break;
case Sixty6BaseReg::CONTROL_ADDR: case Sixty6BaseReg::CONTROL_ADDR:
value = this->control_addr; value = this->control_addr;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_ADDR = %02x", LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_ADDR = %02x", address, value);
address, value);
break; break;
} }
return value; return value;
@@ -416,8 +412,7 @@ int Sixty6Video::device_postinit()
this->control_1 |= 0x80; this->control_1 |= 0x80;
else else
this->control_1 &= ~0x80; this->control_1 &= ~0x80;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: interrupt state:%d doit:%d", LOG_F(SIXTY6_INTERRUPT, "Sixty6: interrupt state:%d doit:%d", irq_line_state, ((this->control_1 & 0x40) && this->crtc_on));
irq_line_state, ((this->control_1 & 0x40) && this->crtc_on));
if (this->interrupt_enabled && this->crtc_on) { if (this->interrupt_enabled && this->crtc_on) {
//this->pci_interrupt(irq_line_state); //this->pci_interrupt(irq_line_state);
-1
View File
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SIXTY6_VIDEO_H #define SIXTY6_VIDEO_H
#include <devices/ioctrl/macio.h> #include <devices/ioctrl/macio.h>
#include <devices/video/saa7187.h>
#include <devices/video/videoctrl.h> #include <devices/video/videoctrl.h>
#include <cinttypes> #include <cinttypes>
+1
View File
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Taos video controller emulation. */ /** @file Taos video controller emulation. */
#include <core/bitops.h> #include <core/bitops.h>
#include <devices/common/i2c/athens.h>
#include <devices/deviceregistry.h> #include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h> #include <devices/memctrl/memctrlbase.h>
#include <devices/video/taos.h> #include <devices/video/taos.h>
+4 -5
View File
@@ -28,7 +28,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef TAOS_VIDEO_H #ifndef TAOS_VIDEO_H
#define TAOS_VIDEO_H #define TAOS_VIDEO_H
#include <devices/common/clockgen/athens.h>
#include <devices/common/i2c/i2c.h> #include <devices/common/i2c/i2c.h>
#include <devices/common/mmiodevice.h> #include <devices/common/mmiodevice.h>
#include <devices/video/videoctrl.h> #include <devices/video/videoctrl.h>
@@ -36,10 +35,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
#include <memory> #include <memory>
constexpr auto TAOS_IOREG_BASE = 0xF0800000; #define TAOS_IOREG_BASE 0xF0800000
constexpr auto TAOS_VRAM_REGION_BASE = 0xF0000000; #define TAOS_VRAM_REGION_BASE 0xF0000000
constexpr auto TAOS_CLUT_BASE = 0xF1000000; #define TAOS_CLUT_BASE 0xF1000000
constexpr auto TAOS_CHIP_VERSION = 0xA5000000; #define TAOS_CHIP_VERSION 0xA5000000
/** Taos register definitions. */ /** Taos register definitions. */
// The implemented bits always start with the most significant bit (bit 31). // The implemented bits always start with the most significant bit (bit 31).
+1 -1
View File
@@ -103,7 +103,7 @@ protected:
// interrupt suff // interrupt suff
InterruptCtrl* int_ctrl = nullptr; InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0; uint32_t irq_id = 0;
std::function<void(uint8_t irq_line_state)> vbl_cb = [this](uint8_t irq_line_state) { std::function<void(uint8_t irq_line_state)> vbl_cb = [this](uint8_t irq_line_state) {
if (this->int_ctrl) if (this->int_ctrl)
this->int_ctrl->ack_int(this->irq_id, irq_line_state); this->int_ctrl->ack_int(this->irq_id, irq_line_state);
+10 -14
View File
@@ -60,7 +60,7 @@ typedef struct {
uint32_t ow_expected_checksum; uint32_t ow_expected_checksum;
uint32_t nw_product_id; uint32_t nw_product_id;
uint32_t nw_subconfig_expected_checksum; // checksum of the system config section but without the firmware version and date uint32_t nw_subconfig_expected_checksum; // checksum of the system config section but without the firmware version and date
const char *id_str; // Bootstrap string located at offset 0x30D064 (PCI Macs) or 0x30C064 (NuBus Macs) const char *id_str; // Bootstrap string located at offset 0x30D064 (PCI Macs) or 0x30C064 (Nubus Macs) to machine name and description.
const char *nw_firmware_updater_name; const char *nw_firmware_updater_name;
const char *nw_openfirmware_name; const char *nw_openfirmware_name;
const char *dppc_machine; const char *dppc_machine;
@@ -109,10 +109,10 @@ static rom_info rom_identity[] = {
{ 0x067c32f2, 1024, 0x064dc91d, 0, 0, nullptr , 0, 0, nullptr , nullptr , "Performa 580 & 588" }, { 0x067c32f2, 1024, 0x064dc91d, 0, 0, nullptr , 0, 0, nullptr , nullptr , "Performa 580 & 588" },
{ 0x077d10f3, 2048, 0x5bf10fd1, 0, 0, nullptr , 0, 0, nullptr , nullptr , "Quadra 660av & 840av" }, { 0x077d10f3, 2048, 0x5bf10fd1, 0, 0, nullptr , 0, 0, nullptr , nullptr , "Quadra 660av & 840av" },
{ 0x077d20f2, 4096, 0x9feb69b3, 0, 0, "Boot PDM 601 1.0", 0, 0, "pm6100" , "NuBus Power Mac" , "Power Mac 6100 & 7100 & 8100" }, // Piltdown Man { 0x077d20f2, 4096, 0x9feb69b3, 0, 0, "Boot PDM 601 1.0", 0, 0, "pm6100" , "Nubus Power Mac" , "Power Mac 6100 & 7100 & 8100" }, // Piltdown Man
{ 0x077d22f1, 4096, 0x9c7c98f7, 0, 0, "Boot PDM 601 1.0", 0, 0, "pm9150" , "NuBus Power Mac" , "Workgroup Server 9150-80" }, // Piltdown Man { 0x077d22f1, 4096, 0x9c7c98f7, 0, 0, "Boot PDM 601 1.0", 0, 0, "pm9150" , "Nubus Power Mac" , "Workgroup Server 9150-80" }, // Piltdown Man
{ 0x077d23f1, 4096, 0x9b7a3aad, 0, 0, "Boot PDM 601 1.1", 0, 0, "pm7100" , "NuBus Power Mac" , "Power Mac 7100 (newer)" }, // Piltdown Man { 0x077d23f1, 4096, 0x9b7a3aad, 0, 0, "Boot PDM 601 1.1", 0, 0, "pm7100" , "Nubus Power Mac" , "Power Mac 7100 (newer)" }, // Piltdown Man
{ 0x077d25f1, 4096, 0x9b037f6f, 0, 0, "Boot PDM 601 1.1", 0, 0, "pm9150" , "NuBus Power Mac" , "Workgroup Server 9150-120" }, // Piltdown Man { 0x077d25f1, 4096, 0x9b037f6f, 0, 0, "Boot PDM 601 1.1", 0, 0, "pm9150" , "Nubus Power Mac" , "Workgroup Server 9150-120" }, // Piltdown Man
{ 0x077d26f1, 4096, 0x63abfd3f, 0, 0, "Boot Cordyceps 6", 0, 0, "pm5200" , "Power Mac 5200/6200 series" , "Power Mac & Performa 5200,5300,6200,6300" }, // Cordyceps { 0x077d26f1, 4096, 0x63abfd3f, 0, 0, "Boot Cordyceps 6", 0, 0, "pm5200" , "Power Mac 5200/6200 series" , "Power Mac & Performa 5200,5300,6200,6300" }, // Cordyceps
{ 0x077d28a5, 4096, 0x67a1aa96, 0, 0, "..0.....Boot TNT", 0, 0, nullptr , nullptr , "TNT A5c1" }, { 0x077d28a5, 4096, 0x67a1aa96, 0, 0, "..0.....Boot TNT", 0, 0, nullptr , nullptr , "TNT A5c1" },
{ 0x077d28f1, 4096, 0x96cd923d, 0, 0, "Boot TNT 0.1p..]", 0, 0, "pm7200" , "Power Mac 7xxxx/8xxx series", "Power Mac 7200&7500&8500&9500 v1" }, // TNT Trinitrotoluene { 0x077d28f1, 4096, 0x96cd923d, 0, 0, "Boot TNT 0.1p..]", 0, 0, "pm7200" , "Power Mac 7xxxx/8xxx series", "Power Mac 7200&7500&8500&9500 v1" }, // TNT Trinitrotoluene
@@ -788,13 +788,10 @@ string MachineFactory::machine_name_from_rom(char *rom_data, size_t rom_size) {
(info->nw_product_id && info->nw_product_id == nw_product_id ) (info->nw_product_id && info->nw_product_id == nw_product_id )
) { ) {
int match_count = 1 int match_count = 1
+ (info->ow_expected_checksum + (info->ow_expected_checksum && info->ow_expected_checksum == ow_checksum_stored )
&& info->ow_expected_checksum == ow_checksum_stored) + (info->ow_expected_checksum && info->ow_expected_checksum == ow_checksum_calculated )
+ (info->ow_expected_checksum + (info->nw_subconfig_expected_checksum && info->nw_subconfig_expected_checksum == nw_subconfig_checksum_calculated )
&& info->ow_expected_checksum == ow_checksum_calculated) + (info->id_str && strcmp(rom_id_str, info->id_str) == 0)
+ (info->nw_subconfig_expected_checksum
&& info->nw_subconfig_expected_checksum == nw_subconfig_checksum_calculated)
+ (info->id_str && strcmp(rom_id_str, info->id_str) == 0)
; ;
if (!match_pass) { if (!match_pass) {
@@ -873,8 +870,7 @@ string MachineFactory::machine_name_from_rom(char *rom_data, size_t rom_size) {
if (firmware_version < 0xffff) if (firmware_version < 0xffff)
LOG_F(INFO, " ROM Version: %x.%03x", (firmware_version >> 12) & 15, firmware_version & 0xfff); LOG_F(INFO, " ROM Version: %x.%03x", (firmware_version >> 12) & 15, firmware_version & 0xfff);
else else
LOG_F(INFO, " ROM Version: %x.%x.%03x", LOG_F(INFO, " ROM Version: %x.%x.%03x", firmware_version >> 16, (firmware_version >> 12) & 15, firmware_version & 0xfff);
firmware_version >> 16, (firmware_version >> 12) & 15, firmware_version & 0xfff);
if (has_nw_config) { if (has_nw_config) {
LOG_F(INFO, " Product ID: 0x%04x.%02x 0x%08x = %s%d,%d", LOG_F(INFO, " Product ID: 0x%04x.%02x 0x%08x = %s%d,%d",
nw_product_id >> 8, nw_product_id & 0xff, nw_product_id >> 8, nw_product_id & 0xff,
+2 -6
View File
@@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -113,14 +113,10 @@ static const PropMap pm6500_settings = {
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32}))}, new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32}))},
{"emmo", {"emmo",
new BinProperty(0)}, new BinProperty(0)},
{"hdd_config",
new StrProperty("Ide0:0")},
{"cdr_config",
new StrProperty("Ide0:0")},
}; };
static std::vector<std::string> pm6500_devices = { static std::vector<std::string> pm6500_devices = {
"Psx", "PsxPci1", "ScreamerSnd", "OHare", "AtaHardDisk" /*, "AtapiCdrom" */ "Psx", "PsxPci1", "OHare"
}; };
static const MachineDescription pm6500_descriptor = { static const MachineDescription pm6500_descriptor = {
+1 -1
View File
@@ -25,9 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <cpu/ppc/ppcemu.h> #include <cpu/ppc/ppcemu.h>
#include <devices/common/clockgen/athens.h>
#include <devices/common/hwcomponent.h> #include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h> #include <devices/common/i2c/i2c.h>
#include <devices/common/i2c/athens.h>
#include <devices/common/i2c/i2cprom.h> #include <devices/common/i2c/i2cprom.h>
#include <devices/common/machineid.h> #include <devices/common/machineid.h>
#include <devices/common/scsi/scsihd.h> #include <devices/common/scsi/scsihd.h>
+45 -29
View File
@@ -150,30 +150,46 @@ int initialize_tnt(std::string& id)
return 0; return 0;
} }
// If this is templated, it hits a compiler bug in MSVC, so use #define instead. template <uint32_t cpu>
#define static_const_pm7500_settings(cpu) \ static const PropMap pm7500_settings = {
static const PropMap pm7500_settings_ ## cpu = { \ {"rambank0_size",
{"rambank0_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank1_size" , new IntProperty(16, std::vector<uint32_t>({ 4, 8, 16, 32, 64, 128}))}, \ {"rambank1_size",
{"rambank2_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty(16, std::vector<uint32_t>({ 4, 8, 16, 32, 64, 128}))},
{"rambank3_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ {"rambank2_size",
{"rambank4_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank5_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ {"rambank3_size",
{"rambank6_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank7_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ {"rambank4_size",
{"rambank8_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank9_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ {"rambank5_size",
{"rambank10_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank11_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ {"rambank6_size",
{"rambank12_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"emmo", new BinProperty(0)}, \ {"rambank7_size",
{"cpu", new StrProperty(# cpu, std::vector<std::string>({"601", "604", "604e", "750"}))}, \ new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank8_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank9_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank10_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank11_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank12_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"emmo",
new BinProperty(0)},
{"cpu",
new StrProperty(
cpu == PPC_VER::MPC601 ? "601" :
cpu == PPC_VER::MPC604 ? "604" :
cpu == PPC_VER::MPC604E ? "604e" :
"604e", std::vector<std::string>({"601", "604", "604e", "750"})
)
},
}; };
static_const_pm7500_settings(601)
static_const_pm7500_settings(604)
static_const_pm7500_settings(604e)
static std::vector<std::string> pm7500_devices = { static std::vector<std::string> pm7500_devices = {
"Hammerhead", "Bandit1", "Chaos", "ScsiMesh", "MeshTnt", "GrandCentral", "Hammerhead", "Bandit1", "Chaos", "ScsiMesh", "MeshTnt", "GrandCentral",
"ControlVideo" "ControlVideo"
@@ -192,7 +208,7 @@ static const MachineDescription pm7300_descriptor = {
.name = "pm7300", .name = "pm7300",
.description = "Power Macintosh 7300", .description = "Power Macintosh 7300",
.devices = pm7500_devices, .devices = pm7500_devices,
.settings = pm7500_settings_604e, .settings = pm7500_settings<PPC_VER::MPC604E>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -200,7 +216,7 @@ static const MachineDescription pm7500_descriptor = {
.name = "pm7500", .name = "pm7500",
.description = "Power Macintosh 7500", .description = "Power Macintosh 7500",
.devices = pm7500_devices, .devices = pm7500_devices,
.settings = pm7500_settings_601, .settings = pm7500_settings<PPC_VER::MPC601>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -208,7 +224,7 @@ static const MachineDescription pm8500_descriptor = {
.name = "pm8500", .name = "pm8500",
.description = "Power Macintosh 8500", .description = "Power Macintosh 8500",
.devices = pm8500_devices, .devices = pm8500_devices,
.settings = pm7500_settings_604, .settings = pm7500_settings<PPC_VER::MPC604>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -216,7 +232,7 @@ static const MachineDescription pm9500_descriptor = {
.name = "pm9500", .name = "pm9500",
.description = "Power Macintosh 9500", .description = "Power Macintosh 9500",
.devices = pm9500_devices, .devices = pm9500_devices,
.settings = pm7500_settings_604, .settings = pm7500_settings<PPC_VER::MPC604>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -224,7 +240,7 @@ static const MachineDescription pm7600_descriptor = {
.name = "pm7600", .name = "pm7600",
.description = "Power Macintosh 7600", .description = "Power Macintosh 7600",
.devices = pm7500_devices, .devices = pm7500_devices,
.settings = pm7500_settings_604e, .settings = pm7500_settings<PPC_VER::MPC604E>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -232,7 +248,7 @@ static const MachineDescription pm8600_descriptor = {
.name = "pm8600", .name = "pm8600",
.description = "Power Macintosh 8600", .description = "Power Macintosh 8600",
.devices = pm8500_devices, .devices = pm8500_devices,
.settings = pm7500_settings_604e, .settings = pm7500_settings<PPC_VER::MPC604E>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
@@ -240,7 +256,7 @@ static const MachineDescription pm9600_descriptor = {
.name = "pm9600", .name = "pm9600",
.description = "Power Macintosh 9600", .description = "Power Macintosh 9600",
.devices = pm9500_devices, .devices = pm9500_devices,
.settings = pm7500_settings_604e, .settings = pm7500_settings<PPC_VER::MPC604E>,
.init_func = &initialize_tnt .init_func = &initialize_tnt
}; };
+9 -62
View File
@@ -28,7 +28,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h> #include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h> #include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h> #include <debugger/debugger.h>
#include <devices/common/ofnvram.h>
#include <machines/machinebase.h> #include <machines/machinebase.h>
#include <machines/machinefactory.h> #include <machines/machinefactory.h>
#include <utils/profiler.h> #include <utils/profiler.h>
@@ -38,7 +37,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <csignal> #include <csignal>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <optional>
#include <CLI11.hpp> #include <CLI11.hpp>
#include <loguru.hpp> #include <loguru.hpp>
@@ -62,7 +60,7 @@ static void sigabrt_handler(int signum) {
} }
static string appDescription = string( static string appDescription = string(
"\nDingusPPC - Alpha 1.02 (3/14/2025) " "\nDingusPPC - Alpha 1.01 (10/31/2024) "
"\nWritten by divingkatae, maximumspatium, " "\nWritten by divingkatae, maximumspatium, "
"\njoevt, mihaip, kkaisershot, et. al. " "\njoevt, mihaip, kkaisershot, et. al. "
"\n(c) 2018-2024 The DingusPPC Dev Team. " "\n(c) 2018-2024 The DingusPPC Dev Team. "
@@ -71,8 +69,6 @@ static string appDescription = string(
"\n" "\n"
); );
uint32_t keyboard_id = 0;
/// Check for an existing directory (returns error message if check fails) /// Check for an existing directory (returns error message if check fails)
class WorkingDirectoryValidator : public CLI::detail::ExistingDirectoryValidator { class WorkingDirectoryValidator : public CLI::detail::ExistingDirectoryValidator {
public: public:
@@ -93,11 +89,7 @@ public:
const WorkingDirectoryValidator WorkingDirectory; const WorkingDirectoryValidator WorkingDirectory;
void run_machine( void run_machine(std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode, uint32_t profiling_interval_ms);
std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode
,const std::vector<std::string> &env_vars
,uint32_t profiling_interval_ms
);
int main(int argc, char** argv) { int main(int argc, char** argv) {
@@ -107,15 +99,8 @@ int main(int argc, char** argv) {
app.allow_windows_style_options(); /* we want Windows-style options */ app.allow_windows_style_options(); /* we want Windows-style options */
app.allow_extras(); app.allow_extras();
bool realtime_enabled = false; bool realtime_enabled = false;
bool debugger_enabled = false; bool debugger_enabled = false;
string keyboard_string = "Eng_USA";
const std::map<std::string, int> kbd_map{
{"Eng_USA", 0}, {"Eng_GBR", 1}, {"Fra_FRA", 10}, {"Deu_DEU", 20},
{"Ita_ITA", 30},{"Spa_ESP", 40}, {"Jpn_JPN", 80},
};
string bootrom_path("bootrom.bin"); string bootrom_path("bootrom.bin");
string working_directory_path("."); string working_directory_path(".");
@@ -125,7 +110,6 @@ int main(int argc, char** argv) {
"Run the emulator in real-time"); "Run the emulator in real-time");
execution_mode_group->add_flag("-d,--debugger", debugger_enabled, execution_mode_group->add_flag("-d,--debugger", debugger_enabled,
"Enter the built-in debugger"); "Enter the built-in debugger");
app.add_option("-k,--keyboard", keyboard_string, "Specify keyboard ID");
app.add_option("-w,--workingdir", working_directory_path, "Specifies working directory") app.add_option("-w,--workingdir", working_directory_path, "Specifies working directory")
->check(WorkingDirectory); ->check(WorkingDirectory);
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path") app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
@@ -144,10 +128,6 @@ int main(int argc, char** argv) {
app.add_flag("--log-no-uptime", log_no_uptime, app.add_flag("--log-no-uptime", log_no_uptime,
"Disable the uptime preamble of logged messages"); "Disable the uptime preamble of logged messages");
std::vector<std::string> env_vars;
app.add_option("--setenv", env_vars, "Set Open Firmware variables at startup")
->take_all();
uint32_t profiling_interval_ms = 0; uint32_t profiling_interval_ms = 0;
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
app.add_option("--profiling-interval-ms", profiling_interval_ms, app.add_option("--profiling-interval-ms", profiling_interval_ms,
@@ -199,7 +179,7 @@ int main(int argc, char** argv) {
} }
auto rom_data = std::unique_ptr<char[]>(new char[4 * 1024 * 1024]); auto rom_data = std::unique_ptr<char[]>(new char[4 * 1024 * 1024]);
memset(&rom_data[0], 0, static_cast<size_t>(4 * 1024 * 1024)); memset(&rom_data[0], 0, 4 * 1024 * 1024);
size_t rom_size = MachineFactory::read_boot_rom(bootrom_path, &rom_data[0]); size_t rom_size = MachineFactory::read_boot_rom(bootrom_path, &rom_data[0]);
if (!rom_size) { if (!rom_size) {
return 1; return 1;
@@ -278,16 +258,8 @@ int main(int argc, char** argv) {
// redirect SIGABRT to our own handler // redirect SIGABRT to our own handler
signal(SIGABRT, sigabrt_handler); signal(SIGABRT, sigabrt_handler);
keyboard_id = kbd_map.at(keyboard_string);
while (true) { while (true) {
run_machine( run_machine(machine_str, &rom_data[0], rom_size, execution_mode, profiling_interval_ms);
machine_str,
&rom_data[0],
rom_size,
execution_mode,
env_vars,
profiling_interval_ms);
if (power_off_reason == po_restarting) { if (power_off_reason == po_restarting) {
LOG_F(INFO, "Restarting..."); LOG_F(INFO, "Restarting...");
power_on = true; power_on = true;
@@ -310,41 +282,16 @@ int main(int argc, char** argv) {
return 0; return 0;
} }
void run_machine(std::string machine_str, char* rom_data, void run_machine(std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode,
size_t rom_size,
uint32_t execution_mode,
const std::vector<std::string> &env_vars,
uint32_t uint32_t
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
profiling_interval_ms profiling_interval_ms
#endif #endif
) { ) {
if (MachineFactory::create_machine_for_id(machine_str, rom_data, rom_size) < 0) { if (MachineFactory::create_machine_for_id(machine_str, rom_data, rom_size) < 0) {
return; return;
} }
if (!env_vars.empty()) {
OfConfigUtils ofnvram;
if (!ofnvram.init()) {
for (const auto &env_var : env_vars) {
auto pos = env_var.find('=');
if (pos != std::string::npos) {
std::string name = env_var.substr(0, pos);
std::string value = env_var.substr(pos + 1);
if (ofnvram.setenv(name, value)) {
LOG_F(INFO, "Set Open Firmware variable %s to %s", name.c_str(), value.c_str());
} else {
LOG_F(WARNING, "Cannot set Open Firmware variable %s to %s", name.c_str(), value.c_str());
}
} else {
LOG_F(WARNING, "Invalid format for --setenv: %s", env_var.c_str());
}
}
} else {
LOG_F(WARNING, "Cannot initialize NVRAM wrapper, will not set Open Firmware variables");
}
}
uint32_t deterministic_timer; uint32_t deterministic_timer;
if (is_deterministic) { if (is_deterministic) {
EventManager::get_instance()->disable_input_handlers(); EventManager::get_instance()->disable_input_handlers();
@@ -363,7 +310,7 @@ void run_machine(std::string machine_str, char* rom_data,
// set up system wide event polling using // set up system wide event polling using
// default Macintosh polling rate of 11 ms // default Macintosh polling rate of 11 ms
uint32_t event_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] { uint32_t event_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
EventManager::get_instance()->poll_events(keyboard_id); EventManager::get_instance()->poll_events();
}); });
#ifdef CPU_PROFILING #ifdef CPU_PROFILING
+4 -4
View File
@@ -56,7 +56,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((((uint8_t*)(addr))[0] << 24) | (((uint8_t*)(addr))[1] << 16) | \ ((((uint8_t*)(addr))[0] << 24) | (((uint8_t*)(addr))[1] << 16) | \
(((uint8_t*)(addr))[2] << 8) | ((uint8_t*)(addr))[3] ) (((uint8_t*)(addr))[2] << 8) | ((uint8_t*)(addr))[3] )
/* read an unaligned big-endian QWORD (64bit) */ /* read an unaligned big-endian QWORD (32bit) */
#define READ_QWORD_BE_U(addr) \ #define READ_QWORD_BE_U(addr) \
((uint64_t(((uint8_t*)(addr))[0]) << 56) | (uint64_t(((uint8_t*)(addr))[1]) << 48) | \ ((uint64_t(((uint8_t*)(addr))[0]) << 56) | (uint64_t(((uint8_t*)(addr))[1]) << 48) | \
(uint64_t(((uint8_t*)(addr))[2]) << 40) | (uint64_t(((uint8_t*)(addr))[3]) << 32) | \ (uint64_t(((uint8_t*)(addr))[2]) << 40) | (uint64_t(((uint8_t*)(addr))[3]) << 32) | \
@@ -71,7 +71,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((((uint8_t*)(addr))[3] << 24) | (((uint8_t*)(addr))[2] << 16) | \ ((((uint8_t*)(addr))[3] << 24) | (((uint8_t*)(addr))[2] << 16) | \
(((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] ) (((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] )
/* read an unaligned little-endian QWORD (64bit) */ /* read an unaligned little-endian DWORD (64bit) */
#define READ_QWORD_LE_U(addr) \ #define READ_QWORD_LE_U(addr) \
((uint64_t(((uint8_t*)(addr))[7]) << 56) | (uint64_t(((uint8_t*)(addr))[6]) << 48) | \ ((uint64_t(((uint8_t*)(addr))[7]) << 56) | (uint64_t(((uint8_t*)(addr))[6]) << 48) | \
(uint64_t(((uint8_t*)(addr))[5]) << 40) | (uint64_t(((uint8_t*)(addr))[4]) << 32) | \ (uint64_t(((uint8_t*)(addr))[5]) << 40) | (uint64_t(((uint8_t*)(addr))[4]) << 32) | \
@@ -103,7 +103,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((uint8_t*)(addr))[3] = (uint8_t)(val); \ ((uint8_t*)(addr))[3] = (uint8_t)(val); \
} while (0) } while (0)
/* write an unaligned big-endian QWORD (64bit) */ /* write an unaligned big-endian DWORD (64bit) */
#define WRITE_QWORD_BE_U(addr, val) \ #define WRITE_QWORD_BE_U(addr, val) \
do { \ do { \
((uint8_t*)(addr))[0] = ((uint64_t)(val) >> 56); \ ((uint8_t*)(addr))[0] = ((uint64_t)(val) >> 56); \
@@ -141,7 +141,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((uint8_t*)(addr))[3] = ((val) >> 24); \ ((uint8_t*)(addr))[3] = ((val) >> 24); \
} while (0) } while (0)
/* write an unaligned little-endian QWORD (64bit) */ /* write an unaligned little-endian DWORD (64bit) */
#define WRITE_QWORD_LE_U(addr, val) \ #define WRITE_QWORD_LE_U(addr, val) \
do { \ do { \
((uint8_t*)(addr))[0] = (uint8_t)(val) ; \ ((uint8_t*)(addr))[0] = (uint8_t)(val) ; \
+2 -2
View File
@@ -94,10 +94,10 @@ uint64_t ImgFile::write(const void* buf, uint64_t offset, uint64_t length)
LOG_F(WARNING, "ImgFile::write before disk was opened, ignoring."); LOG_F(WARNING, "ImgFile::write before disk was opened, ignoring.");
return 0; return 0;
} }
impl->stream->seekp(offset, std::ios::beg); impl->stream->seekg(offset, std::ios::beg);
impl->stream->write((const char *)buf, length); impl->stream->write((const char *)buf, length);
#if defined(WIN32) || defined(__APPLE__) || defined(__linux) #if defined(WIN32) || defined(__APPLE__) || defined(__linux)
impl->stream->flush(); impl->stream->flush();
#endif #endif
return uint64_t(impl->stream->tellp()) - offset; return impl->stream->gcount();
} }