Compare commits

..
26 Commits
Author SHA1 Message Date
dingusdev 31ad4b28ed Start fixes 2024-10-06 21:25:07 -07:00
dingusdevandjoevt eb67b6ded0 More fixes
Co-Authored-By: joevt <[email protected]>
2024-10-05 17:17:52 -07:00
dingusdevandjoevt cbaf0477f0 Attempted build fixes
Co-Authored-By: joevt <[email protected]>
2024-10-04 17:43:08 -07:00
dingusdev cbd24165bd Starting Step 4 2024-10-03 21:21:55 -07:00
dingusdevandjoevt e50a1a4d3e Step 3 compiles now
Co-Authored-By: joevt <[email protected]>
2024-10-01 06:41:03 -07:00
dingusdevandjoevt ce122da984 More fixes
Co-Authored-By: joevt <[email protected]>
2024-09-30 19:44:11 -07:00
dingusdevandjoevt 738b40c7b6 Attempted compile fix
Co-Authored-By: joevt <[email protected]>
2024-09-30 19:22:08 -07:00
dingusdev 2a24b1c8f9 Step 3 in progress 2024-09-28 13:05:05 -07:00
dingusdev f1e6a2ce93 Small fixes 2024-09-27 21:37:32 -07:00
dingusdev 11de987ea9 Starting Step 3 2024-09-27 08:04:01 -07:00
dingusdev 804bb3da07 Another day, another compile fix 2024-09-25 07:40:17 -07:00
dingusdev 832d669890 Merge branch 'nuterpreterx' of https://github.com/dingusdev/dingusppc into nuterpreterx 2024-09-25 07:14:25 -07:00
dingusdev 262b7ccf68 Continued fix-ups 2024-09-25 07:14:05 -07:00
dingusdev de61c26484 More fixes 2024-09-25 07:14:05 -07:00
dingusdev cb39be991f Continued clean-up 2024-09-25 07:14:05 -07:00
dingusdev 55f9d08c30 Starting Step 2 - Not compiling yet 2024-09-25 07:14:05 -07:00
dingusdevandjoevt f1a38e21d3 More fixes
4% speedup reported in the benchmark

Co-Authored-By: joevt <[email protected]>
2024-09-25 07:14:05 -07:00
dingusdev 90536f79fe Continued work on polishing up non-globalized code 2024-09-25 07:14:05 -07:00
dingusdev 72308074da Take 2 of removing ppc_cur_instruction 2024-09-25 07:14:05 -07:00
dingusdev b5224ee805 Continued fix-ups 2024-09-24 07:27:52 -07:00
dingusdev 3addc05ec4 More fixes 2024-09-24 06:38:38 -07:00
dingusdev f0cf315030 Continued clean-up 2024-09-23 08:07:30 -07:00
dingusdev 959e92e372 Starting Step 2 - Not compiling yet 2024-09-21 17:56:18 -07:00
dingusdevandjoevt 5ae9fcbd38 More fixes
4% speedup reported in the benchmark

Co-Authored-By: joevt <[email protected]>
2024-09-18 07:15:14 -07:00
dingusdev e2ed352533 Continued work on polishing up non-globalized code 2024-09-17 21:18:54 -07:00
dingusdev 4644ade362 Take 2 of removing ppc_cur_instruction 2024-09-17 08:08:29 -07:00
150 changed files with 9012 additions and 15031 deletions

No files matched your search

+3 -1
View File
@@ -114,7 +114,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
"${PROJECT_SOURCE_DIR}/*.c"
"${PROJECT_SOURCE_DIR}/*.hpp"
"${PROJECT_SOURCE_DIR}/*.h")
"${PROJECT_SOURCE_DIR}/*.h"
"${PROJECT_SOURCE_DIR}/*.include")
if (APPLE)
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
@@ -184,6 +185,7 @@ if (DPPC_BUILD_BENCHMARKS)
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.include"
)
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
# $<TARGET_OBJECTS:cpu_ppc>
-1
View File
@@ -7,7 +7,6 @@
- maximumspatium
- joevt
- mihaip
- kkaisershot
## NT4/PPC fork
+1 -1
View File
@@ -89,7 +89,7 @@ emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DDPPC_BUILD_PPC_TESTS=True ..
cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True ..
make testppc
```
+3 -4
View File
@@ -30,7 +30,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_on = false;
power_off_reason = po_benchmark_exception;
}
#endif
@@ -43,7 +42,7 @@ uint32_t cs_code[] = {
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
0x7C650194, /* 0x4E800020 */ 0x00005AF0
0x7C650194, 0x4E800020
};
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
@@ -76,7 +75,7 @@ int main(int argc, char** argv) {
/* load executable code into RAM at address 0 */
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
mmu_write_vmem<uint32_t>(0, i * 4, cs_code[i]);
mmu_write_vmem<uint32_t>(i * 4, 0, cs_code[i]);
}
srand(0xCAFEBABE);
@@ -86,7 +85,7 @@ int main(int argc, char** argv) {
bool did_lf = false;
for (i = 0; i < test_size; i++) {
uint8_t val = rand() % 256;
mmu_write_vmem<uint8_t>(0, 0x1000+i, val);
mmu_write_vmem<uint8_t>(0x1000 + i, 0, val);
if (i < 64) {
printf("%02x", val);
did_lf = false;
-16
View File
@@ -53,9 +53,6 @@ public:
// Calls all connected slots.
void emit(Args... args) {
if (!_is_enabled) {
return;
}
for (auto const& it : _slots) {
it.second(args...);
}
@@ -69,22 +66,9 @@ public:
_slots.clear();
}
void disable() {
_is_enabled = false;
}
void enable() {
_is_enabled = true;
}
bool is_enabled() {
return _is_enabled;
}
private:
mutable std::map<int, std::function<void(Args...)>> _slots;
mutable unsigned int _current_id { 0 };
mutable bool _is_enabled { true };
};
#endif // CORE_SIGNAL_H
+2 -62
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,19 +35,11 @@ public:
uint32_t window_id;
};
enum : uint16_t {
// Standard SDL window event types are uint8_t's, we add our own custom
// events after that.
WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
};
enum : uint32_t {
MOUSE_EVENT_MOTION = 1 << 0,
MOUSE_EVENT_BUTTON = 1 << 1,
KEYBOARD_EVENT_DOWN = 1 << 0,
KEYBOARD_EVENT_UP = 1 << 1,
GAMEPAD_EVENT_DOWN = 1 << 0,
GAMEPAD_EVENT_UP = 1 << 1,
};
class MouseEvent {
@@ -73,47 +65,6 @@ public:
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 */
enum GamepadButton : uint8_t {
Red = 14,
Green = 15,
Yellow = 9,
Blue = 8,
FrontLeft = 0,
FrontMiddle = 1,
FrontRight = 2,
LeftTrigger = 17,
RightTrigger = 16,
Up = 10,
Down = 13,
Left = 11,
Right = 12,
};
class GamepadEvent {
public:
GamepadEvent() = default;
~GamepadEvent() = default;
uint32_t gamepad_id;
uint32_t flags;
uint8_t button;
};
class EventManager {
public:
static EventManager* get_instance() {
@@ -123,7 +74,7 @@ public:
return event_manager;
};
void poll_events(uint32_t kbd_locale);
void poll_events();
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -140,11 +91,6 @@ public:
_keyboard_signal.connect_method(inst, func);
}
template <typename T>
void add_gamepad_handler(T* inst, void (T::*func)(const GamepadEvent&)) {
_gamepad_signal.connect_method(inst, func);
}
template <typename T>
void add_post_handler(T *inst, void (T::*func)()) {
_post_signal.connect_method(inst, func);
@@ -157,11 +103,6 @@ public:
_post_signal.disconnect_all();
}
void disable_input_handlers() {
_mouse_signal.disable();
_keyboard_signal.disable();
}
private:
static EventManager* event_manager;
EventManager() {}; // private constructor to implement a singleton
@@ -169,7 +110,6 @@ private:
CoreSignal<const WindowEvent&> _window_signal;
CoreSignal<const MouseEvent&> _mouse_signal;
CoreSignal<const KeyboardEvent&> _keyboard_signal;
CoreSignal<const GamepadEvent&> _gamepad_signal;
CoreSignal<> _post_signal;
uint64_t events_captured = 0;
+13 -69
View File
@@ -28,10 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
void EventManager::poll_events(uint32_t kbd_locale) {
void EventManager::poll_events()
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -44,7 +45,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break;
case SDL_WINDOWEVENT: {
WindowEvent we{};
WindowEvent we;
we.sub_type = event.window.event;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
@@ -53,27 +54,17 @@ void EventManager::poll_events(uint32_t kbd_locale) {
case SDL_KEYDOWN:
case SDL_KEYUP: {
// Internal shortcuts, intentionally not sent to the host.
// Control-G: mouse grab
// Internal shortcuts to trigger mouse grab, intentionally not
// sent to the host.
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
toggle_mouse_grab(event.key);
}
return;
}
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we{};
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
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) {
KeyboardEvent ke{};
KeyboardEvent ke;
ke.key = key_code;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
@@ -95,7 +86,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break;
case SDL_MOUSEMOTION: {
MouseEvent me{};
MouseEvent me;
me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel;
me.xabs = event.motion.x;
@@ -106,7 +97,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break;
case SDL_MOUSEBUTTONDOWN: {
MouseEvent me{};
MouseEvent me;
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -123,7 +114,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
break;
case SDL_MOUSEBUTTONUP: {
MouseEvent me{};
MouseEvent me;
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -139,52 +130,6 @@ void EventManager::poll_events(uint32_t kbd_locale) {
}
break;
case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_DOWN;
this->_gamepad_signal.emit(ge);
}
break;
case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
}
ge.gamepad_id = event.cbutton.which;
ge.flags = GAMEPAD_EVENT_UP;
this->_gamepad_signal.emit(ge);
}
break;
default:
unhandled_events++;
}
@@ -195,7 +140,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) {
case SDLK_a: return AdbKey_A;
@@ -330,8 +275,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
//Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
return AdbKey_JIS_Yen;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
-2
View File
@@ -19,8 +19,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cstdint>
#ifndef MATH_UTILS_H
#define MATH_UTILS_H
+15 -15
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -31,16 +31,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <vector>
#include <mutex>
constexpr auto NS_PER_SEC = 1000000000;
constexpr auto USEC_PER_SEC = 1000000;
constexpr auto NS_PER_USEC = 1000;
constexpr auto NS_PER_MSEC = 1000000;
constexpr auto ONE_BILLION_NS = 1000000000;
using namespace std;
#define NS_PER_SEC 1000000000
#define USEC_PER_SEC 1000000
#define NS_PER_USEC 1000
#define NS_PER_MSEC 1000000
#define ONE_BILLION_NS 1000000000
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
typedef std::function<void()> timer_cb;
typedef function<void()> timer_cb;
/** Extend std::priority_queue as suggested here:
https://stackoverflow.com/a/36711682
@@ -99,7 +101,7 @@ typedef struct TimerInfo {
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
return l.get()->timeout_ns > r.get()->timeout_ns;
}
};
@@ -114,7 +116,7 @@ public:
};
// callback for retrieving current time
void set_time_now_cb(const std::function<uint64_t()> &cb) {
void set_time_now_cb(const function<uint64_t()> &cb) {
this->get_time_now = cb;
};
@@ -140,15 +142,13 @@ private:
TimerManager(){}; // private constructor to implement a singleton
// timer queue
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
std::function<uint64_t()> get_time_now;
std::function<void()> notify_timer_changes;
function<uint64_t()> get_time_now;
function<void()> notify_timer_changes;
std::atomic<uint32_t> id{0};
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
bool cb_active = false; // true if a timer callback is executing
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
};
#endif // TIMER_MANAGER_H
+21
View File
@@ -0,0 +1,21 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define OPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODESHIFT(op, __VA_ARGS__) template <field_shift shift> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODE(op, __VA_ARGS__) void dppc_interpreter::ppc_##op(uint32_t instr) {##__VA_ARGS__ }
#define OPCODECARRY(op, __VA_ARGS__) template <field_carry carry, field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define POWEROPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
#define POWEROPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODELOGIC(op, __VA_ARGS__) template <logical_fun logical_op, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODELKAA(op, __VA_ARGS__) template <field_lk l, field_aa a> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODE601L(op, __VA_ARGS__) template <field_lk l, field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define POWEROPCODE(op, __VA_ARGS__) void dppc_interpreter::power_##op(uint32_t instr) {##__VA_ARGS__ }
#define OPCODEMEM(op, __VA_ARGS__) template <class T> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODESHIFTREC(op, __VA_ARGS__) template <field_direction isleft, field_rc rec > void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODE601REC(op, __VA_ARGS__) template <field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define OPCODEEXTSIGN(op, __VA_ARGS__) template <class T, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
#define ppc_store_iresult_reg(reg, ppc_result) ppc_state.gpr[reg] = ppc_result
#define ppc_set_xer(entry) ppc_state.spr[SPR::XER] |= entry#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr)
+1 -6
View File
@@ -3,12 +3,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.include"
)
# The use of volatile is deprecated, but we still need it to avoid function
# parameters being clobbered when using setjmp/longjmp.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-volatile)
endif()
add_library(cpu_ppc OBJECT ${SOURCES})
+3 -637
View File
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// Any shared opcodes are in ppcopcodes.cpp
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcdecodemacros.h"
#include "ppcmmu.h"
#include <stdint.h>
@@ -34,639 +34,5 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
}
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_abs(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsda(opcode);
if (ppc_result_a == 0x80000000) {
ppc_result_d = ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_clcs(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_da(opcode);
switch (reg_a & 15) {
case 0:
case 1:
case 2:
case 3:
case 0xC: //instruction cache line size
case 0xD: //data cache line size
case 0xE: //minimum line size
case 0xF: //maximum line size
ppc_result_d = is_601 ? 0x40 : 0x20; break;
case 4:
case 5:
case 6: ppc_result_d = 0x20; break;
case 7: ppc_result_d = is_601 ? 1 : 0; break;
case 8:
case 9: ppc_result_d = is_601 ? 8 : 4; break;
case 0xA:
case 0xB: ppc_result_d = is_601 ? 0x8000 : 0x4000; break;
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_div(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsdab(opcode);
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
int32_t divisor = ppc_result_b;
int64_t quotient;
int32_t remainder;
if (dividend == -0x80000000 && divisor == -1) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else if (!divisor) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
quotient = dividend / divisor;
remainder = dividend % divisor;
ppc_result_d = uint32_t(quotient);
if (ov) {
if (((quotient >> 31) + 1) & ~1) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
}
if (rec)
ppc_changecrf0(remainder);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_divs(uint32_t opcode) {
uint32_t ppc_result_d;
int32_t remainder;
ppc_grab_regsdab(opcode);
if (!ppc_result_b) { // handle the "anything / 0" case
ppc_result_d = -1;
remainder = ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
ppc_result_d = 0x80000000U;
remainder = 0;
if (ov)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else { // normal signed devision
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
if (rec)
ppc_changecrf0(remainder);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
}
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
ppc_result_b - ppc_result_a : 0;
if (ov) {
if (int32_t(ppc_result_d) < 0) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_dozi(uint32_t opcode) {
uint32_t ppc_result_d;
ppc_grab_regsdasimm(opcode);
if (((int32_t)ppc_result_a) > simm) {
ppc_result_d = 0;
} else {
ppc_result_d = simm - ppc_result_a;
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template <field_rc rec>
void dppc_interpreter::power_lscbx(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
uint32_t bytes_remaining = bytes_to_load;
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
uint32_t ppc_result_d = 0;
bool is_match = false;
// for storing each byte
uint8_t shift_amount = 24;
while (bytes_remaining > 0) {
uint8_t return_value = mmu_read_vmem<uint8_t>(opcode, ea);
ppc_result_d |= return_value << shift_amount;
if (!shift_amount) {
if (reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
reg_d = (reg_d + 1) & 0x1F;
ppc_result_d = 0;
shift_amount = 24;
} else {
shift_amount -= 8;
}
ea++;
bytes_remaining--;
if (return_value == matching_byte) {
is_match = true;
break;
}
}
// store partially loaded register if any
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
if (rec) {
ppc_state.cr =
(ppc_state.cr & 0x0FFFFFFFUL) |
(is_match ? CRx_bit::CR_EQ : 0) |
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
}
}
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_grab_regssab(opcode);
uint32_t mask_start = ppc_result_d & 0x1F;
uint32_t mask_end = ppc_result_b & 0x1F;
uint32_t insert_mask = 0;
if (mask_start < (mask_end + 1)) {
insert_mask = power_rot_mask(mask_start, mask_end);
}
else if (mask_start == (mask_end + 1)) {
insert_mask = 0xFFFFFFFF;
}
else {
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
}
ppc_result_a = insert_mask;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_grab_regssab(opcode);
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_mul(uint32_t opcode) {
ppc_grab_regsdab(opcode);
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);
ppc_state.spr[SPR::MQ] = uint32_t(product);
if (ov) {
if (uint64_t(product >> 31) + 1 & ~1) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
if (ov)
ppc_state.spr[SPR::XER] &= ~XER::OV;
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_mb = (opcode >> 6) & 0x1F;
unsigned rot_me = (opcode >> 1) & 0x1F;
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
if ((opcode & 0x01) == 1)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template <field_rc rec>
void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (int32_t(ppc_result_d) < 0) {
ppc_result_a |= (0x80000000U >> rot_sh);
} else {
ppc_result_a &= ~(0x80000000U >> rot_sh);
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
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_store_iresult_reg(reg_a, ppc_result_a);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
} else {
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1U << rot_sh) - 1)));
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_slq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_result_a = ppc_result_d << rot_sh;
}
if (rec)
ppc_changecrf0(ppc_result_a);
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);
}
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t mask = (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sre(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
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;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
uint32_t r = (rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d);
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r;
}
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_grab_regssash(opcode);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_grab_regssash(opcode);
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = rot_sh ? ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh))) : ppc_result_d;
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
} else {
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_grab_regssab(opcode);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
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;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode);
#include "ppcopmacros.h"
#include "poweropcodes.include"
+531
View File
@@ -0,0 +1,531 @@
POWEROPCODEOVREC (abs, 31, 360,
uint32_t ppc_result_d;
ppc_grab_regsda(instr);
if (ppc_result_a == 0x80000000) {
ppc_result_d = ppc_result_a;
if (ov)
ppc_set_xer(XER::SO | XER::OV);
} else {
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
if (ov)
ppc_unset_xer(XER::OV);
}
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODE31 (clcs, 31, 531,
ppc_grab_da(instr);
uint32_t ppc_result_d = 0;
switch (reg_a) {
case 12: //instruction cache line size
case 13: //data cache line size
case 14: //minimum line size
case 15: //maximum line size
default:
ppc_result_d = is_601 ? 64 : 32; break;
case 7:
case 23:
ppc_result_d = is_601 ? 64 : 0; break;
case 8:
case 9:
case 24:
case 25:
ppc_result_d = is_601 ? 64 : 4; break;
case 10:
case 11:
case 26:
case 27:
ppc_result_d = is_601 ? 64 : 0x4000; break;
}
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODEOVREC (div, 31, 331,
uint32_t ppc_result_d;
ppc_grab_regsdab(instr);
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
int32_t divisor = ppc_result_b;
int64_t quotient;
int32_t remainder;
if (dividend == -0x80000000 && divisor == -1) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_set_xer(XER::SO | XER::OV);
} else if (!divisor) {
remainder = 0;
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
if (ov)
ppc_set_xer(XER::SO | XER::OV);
} else {
quotient = dividend / divisor;
remainder = dividend % divisor;
ppc_result_d = uint32_t(quotient);
if (ov) {
if (((quotient >> 31) + 1) & ~1) {
ppc_set_xer(XER::SO | XER::OV);
} else {
ppc_unset_xer(XER::OV);
}
}
}
if (rec)
ppc_changecrf0(remainder);
ppc_state.gpr[reg_d] = ppc_result_d;
power_store_mq(remainder);
)
POWEROPCODEOVREC (divs, 31, 363,
uint32_t ppc_result_d;
int32_t remainder;
ppc_grab_regsdab(instr);
if (!ppc_result_b) { // handle the "anything / 0" case
ppc_result_d = -1;
remainder = ppc_result_a;
if (ov)
ppc_set_xer(XER::SO | XER::OV);
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
ppc_result_d = 0x80000000U;
remainder = 0;
if (ov)
ppc_set_xer(XER::SO | XER::OV);
} else { // normal signed devision
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
if (ov)
ppc_unset_xer(XER::OV);
}
if (rec)
ppc_changecrf0(remainder);
ppc_state.gpr[reg_d] = ppc_result_d;
power_store_mq(remainder);;
)
POWEROPCODEOVREC (doz, 31, 264,
ppc_grab_regsdab(instr);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
ppc_result_b - ppc_result_a : 0;
if (ov) {
if (int32_t(ppc_result_d) < 0) {
ppc_set_xer(XER::SO | XER::OV);
} else {
ppc_unset_xer(XER::OV);
}
}
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODE (dozi, , 9,
ppc_grab_regsdasimm(instr);
uint32_t ppc_result_d = 0;
if (((int32_t)ppc_result_a) > simm) {
ppc_result_d = 0;
}
else {
ppc_result_d = simm - ppc_result_a;
}
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODEREC (lscbx, 31, 277,
ppc_grab_regsdab(instr);
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
uint32_t bytes_remaining = bytes_to_load;
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
uint32_t ppc_result_d = 0;
bool is_match = false;
// for storing each byte
uint8_t shift_amount = 24;
while (bytes_remaining > 0) {
uint8_t return_value = mmu_read_vmem<uint8_t>(ea, instr);
ppc_result_d |= return_value << shift_amount;
if (!shift_amount) {
if (reg_d != reg_a && reg_d != reg_b) {
ppc_state.gpr[reg_d] = ppc_result_d;
}
reg_d = (reg_d + 1) & 0x1F;
ppc_result_d = 0;
shift_amount = 24;
} else {
shift_amount -= 8;
}
ea++;
bytes_remaining--;
if (return_value == matching_byte) {
is_match = true;
break;
}
}
// store partially loaded register if any
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b) {
ppc_state.gpr[reg_d] = ppc_result_d;
}
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
if (rec) { \
ppc_state.cr = \
(ppc_state.cr & 0x0FFFFFFFUL) | \
(is_match ? CRx_bit::CR_EQ : 0) | \
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
}
)
POWEROPCODEREC (maskg, 31, 29,
ppc_grab_regssab(instr);
uint32_t mask_start = ppc_result_d & 0x1F;
uint32_t mask_end = ppc_result_b & 0x1F;
uint32_t insert_mask = 0;
if (mask_start < (mask_end + 1)) {
insert_mask = power_rot_mask(mask_start, mask_end);
}
else if (mask_start == (mask_end + 1)) {
insert_mask = 0xFFFFFFFF;
}
else {
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
}
ppc_result_a = insert_mask;
if (rec){
ppc_changecrf0(ppc_result_a);
}
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (maskir, 31, 541,
ppc_grab_regssab(instr);
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEOVREC (mul, 31, 107,
ppc_grab_regsdab(instr);
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);
ppc_state.spr[SPR::MQ] = uint32_t(product);
if (ov) {
if (uint64_t(product >> 31) + 1 & ~1) {
ppc_set_xer(XER::SO | XER::OV);
} else {
ppc_unset_xer(XER::OV);
}
}
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODEOVREC (nabs, 31, 488,
ppc_grab_regsda(instr);
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
if (ov)
ppc_unset_xer(XER::OV);
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_state.gpr[reg_d] = ppc_result_d;
)
POWEROPCODE (rlmi, , 22,
ppc_grab_regssab(instr);
unsigned rot_mb = (instr >> 6) & 0x1F;
unsigned rot_me = (instr >> 1) & 0x1F;
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(rot_mb, rot_me);
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
if ((instr & 0x01) == 1)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (rrib, 31, 537,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
if (int32_t(ppc_result_d) < 0) {
ppc_result_a |= (0x80000000U >> rot_sh);
} else {
ppc_result_a &= ~(0x80000000U >> rot_sh);
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sle, 31, 153,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
ppc_state.gpr[reg_a] = ppc_result_a;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sleq, 31, 217,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sliq, 31, 184,
ppc_grab_regssash(instr);
ppc_result_a = ppc_result_d << rot_sh;
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (slliq, 31, 248,
ppc_grab_regssash(instr);
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sllq, 31, 216,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
} else {
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (slq, 31, 152,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_result_a = ppc_result_d << rot_sh;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sraiq, 31, 952,
ppc_grab_regssash(instr);
uint32_t mask = (1 << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sraq, 31, 920,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sre, 31, 665,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (srea, 31, 921,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
uint32_t mask = -1U >> rot_sh;
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
ppc_state.spr[SPR::MQ] = r;
)
POWEROPCODEREC (sreq, 31, 729,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t mask = -1U >> rot_sh;
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (sriq, 31, 696,
ppc_grab_regssash(instr);
ppc_result_a = ppc_result_d >> rot_sh;
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (srliq, 31, 760,
ppc_grab_regssash(instr);
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
unsigned mask = power_rot_mask(rot_sh, 31);
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
ppc_state.spr[SPR::MQ] = r;
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (srlq, 31, 728,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
unsigned mask = power_rot_mask(rot_sh, 31);
if (ppc_result_b & 0x20) {
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
} else {
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
}
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
POWEROPCODEREC (srq, 31, 664,
ppc_grab_regssab(instr);
unsigned rot_sh = ppc_result_b & 0x1F;
if (ppc_result_b & 0x20) {
ppc_result_a = 0;
} else {
ppc_result_a = ppc_result_d >> rot_sh;
}
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
if (rec)
ppc_changecrf0(ppc_result_a);
ppc_state.gpr[reg_a] = ppc_result_a;
)
@@ -23,6 +23,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define PPC_MACROS_H
#include <cinttypes>
#include "ppcemu.h"
#define ppc_set_cr(entry) \
ppc_state.cr |= entry
#define ppc_unset_cr(entry) \
ppc_state.cr &= ~entry
#define ppc_set_xer(entry) \
ppc_state.spr[SPR::XER] |= entry
#define ppc_unset_xer(entry) \
ppc_state.spr[SPR::XER] &= ~entry
#define power_store_mq(entry) \
ppc_state.spr[SPR::MQ] = entry
#define power_store_ctr(entry) \
ppc_state.spr[SPR::CTR] = entry
#define power_store_mq(entry) \
ppc_state.spr[SPR::MQ] = entry
#define ppc_grab_regsdasimm(opcode) \
int reg_d = (opcode >> 21) & 31; \
@@ -54,6 +77,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_crfds(opcode) \
int crf_d = (instr >> 21) & 0x1C; \
int crf_s = (instr >> 16) & 0x1C;
#define ppc_grab_da(opcode)\
int reg_d = (opcode >> 21) & 31;\
int reg_a = (opcode >> 16) & 31;\
@@ -80,7 +107,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab_stswx(opcode) \
int reg_s = (opcode >> 21) & 31; \
@@ -109,41 +136,45 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define ppc_grab_regssash(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
int rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash_stswi(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
int rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsda(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdb(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_store_iresult_reg(reg, ppc_result)\
#define ppc_store_iresult_reg(reg, ppc_result) \
ppc_state.gpr[reg] = ppc_result
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d)\
#define ppc_store_sfpresult_flt(reg, ppc_dblresult64_d)\
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define ppc_store_dfpresult_int(reg, ppc_result64_d)\
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_dfpresult_flt(reg, ppc_dblresult64_d)\
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define ppc_grab_regsfpdb(opcode) \
@@ -153,9 +184,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
#define ppc_grab_regsfpdiab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
@@ -210,4 +238,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
double val_reg_b = GET_FPR(reg_b); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_grab_mtfsf(opcode) \
int reg_b = (opcode >> 11) & 0x1F; \
uint8_t fm = (opcode >> 17) & 0xFF;
#define ppc_grab_mtfsfi(opcode) \
int crf_d = (opcode >> 21) & 0x1C; \
uint32_t imm = (opcode << 16) & 0xF0000000UL;
#define ppc_grab_crfd(opcode) \
int crf_d = (opcode >> 21) & 0x1C;
#endif // PPC_MACROS_H
+24 -232
View File
@@ -47,7 +47,7 @@ enum EXEC_MODE:uint32_t {
enum endian_switch { big_end = 0, little_end = 1 };
typedef void (*PPCOpcode)(uint32_t opcode);
typedef void (*PPCOpcode)(uint32_t);
union FPR_storage {
double dbl64_r; // double floating-point representation
@@ -182,10 +182,9 @@ extern uint32_t rtc_lo, rtc_hi;
/* Flags for controlling interpreter execution. */
enum {
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
EXEF_RFI = 1 << 2, // RFI instruction executed
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2,
};
enum CR_select : int32_t {
@@ -318,7 +317,6 @@ enum Po_Cause : int {
po_enter_debugger,
po_entered_debugger,
po_signal_interrupt,
po_benchmark_exception
};
extern bool power_on;
@@ -327,18 +325,12 @@ extern bool int_pin;
extern bool dec_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation
// Make execution deterministic (ignore external input, used a fixed date, etc.)
extern bool is_deterministic;
// Important Addressing Integers
extern uint32_t ppc_next_instruction_address;
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
inline uint32_t ppc_set_cur_instruction(const uint8_t* ptr) {
return READ_DWORD_BE_A(ptr);
}
@@ -403,18 +395,19 @@ typedef enum {
IS601,
} field_601;
// Placeholder value for cases where we don't have a currently-executing instruction.
constexpr uint32_t NO_OPCODE = 0;
// Function prototypes
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
extern void ppc_mmu_init();
void ppc_illegalop(uint32_t opcode);
void ppc_illegalop(uint32_t null_val=0);
void ppc_fpu_off();
void ppc_assert_int();
void ppc_release_int();
void initialize_ppc_opcode_table();
void initialize_ppc_opcode_tables(bool include_601);
extern double fp_return_double(uint32_t reg);
extern uint64_t fp_return_uint64(uint32_t reg);
void ppc_changecrf0(uint32_t set_result);
void set_host_rounding_mode(uint8_t mode);
@@ -423,8 +416,8 @@ void update_fpscr(uint32_t new_fpscr);
/* Exception handlers. */
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
void ppc_floating_point_exception(uint32_t opcode);
void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
void ppc_floating_point_exception(uint32_t instr);
void ppc_alignment_exception(uint32_t ea, uint32_t instr);
// MEMORY DECLARATIONS
extern MemCtrlBase* mem_ctrl_instance;
@@ -432,227 +425,26 @@ extern MemCtrlBase* mem_ctrl_instance;
extern void add_ctx_sync_action(const std::function<void()> &);
extern void do_ctx_sync(void);
// The functions used by the PowerPC processor
namespace dppc_interpreter {
template <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode);
template <field_lk l> extern void ppc_bclr(uint32_t opcode);
extern void ppc_crand(uint32_t opcode);
extern void ppc_crandc(uint32_t opcode);
extern void ppc_creqv(uint32_t opcode);
extern void ppc_crnand(uint32_t opcode);
extern void ppc_crnor(uint32_t opcode);
extern void ppc_cror(uint32_t opcode);
extern void ppc_crorc(uint32_t opcode);
extern void ppc_crxor(uint32_t opcode);
extern void ppc_isync(uint32_t opcode);
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void 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 void ppc_addme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode);
extern void ppc_cmp(uint32_t opcode);
extern void ppc_cmpl(uint32_t opcode);
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode);
extern void ppc_dcbf(uint32_t opcode);
extern void ppc_dcbi(uint32_t opcode);
extern void ppc_dcbst(uint32_t opcode);
extern void ppc_dcbt(uint32_t opcode);
extern void ppc_dcbtst(uint32_t opcode);
extern void 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 void ppc_divwu(uint32_t opcode);
extern void ppc_eciwx(uint32_t opcode);
extern void ppc_ecowx(uint32_t opcode);
extern void ppc_eieio(uint32_t opcode);
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode);
extern void ppc_icbi(uint32_t opcode);
extern void ppc_mftb(uint32_t opcode);
extern void ppc_lhaux(uint32_t opcode);
extern void ppc_lhax(uint32_t opcode);
extern void ppc_lhbrx(uint32_t opcode);
extern void ppc_lwarx(uint32_t opcode);
extern void ppc_lwbrx(uint32_t opcode);
template <class T> extern void ppc_lzx(uint32_t opcode);
template <class T> extern void ppc_lzux(uint32_t opcode);
extern void ppc_mcrxr(uint32_t opcode);
extern void ppc_mfcr(uint32_t opcode);
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode);
template <field_rc rec> extern void 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 void ppc_neg(uint32_t opcode);
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode);
template <field_rc rec> extern void ppc_sraw(uint32_t opcode);
template <field_rc rec> extern void ppc_srawi(uint32_t opcode);
template <class T> extern void ppc_stx(uint32_t opcode);
template <class T> extern void ppc_stux(uint32_t opcode);
extern void ppc_stfiwx(uint32_t opcode);
extern void ppc_sthbrx(uint32_t opcode);
extern void ppc_stwcx(uint32_t opcode);
extern void ppc_stwbrx(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov> extern void 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 void ppc_subfme(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode);
extern void ppc_sync(uint32_t opcode);
extern void ppc_tlbia(uint32_t opcode);
extern void ppc_tlbie(uint32_t opcode);
extern void ppc_tlbli(uint32_t opcode);
extern void ppc_tlbld(uint32_t opcode);
extern void ppc_tlbsync(uint32_t opcode);
extern void ppc_tw(uint32_t opcode);
extern void ppc_lswi(uint32_t opcode);
extern void ppc_lswx(uint32_t opcode);
extern void ppc_stswi(uint32_t opcode);
extern void ppc_stswx(uint32_t opcode);
extern void ppc_mfsr(uint32_t opcode);
extern void ppc_mfsrin(uint32_t opcode);
extern void ppc_mtsr(uint32_t opcode);
extern void ppc_mtsrin(uint32_t opcode);
extern void ppc_mcrf(uint32_t opcode);
extern void ppc_mtcrf(uint32_t opcode);
extern void ppc_mfmsr(uint32_t opcode);
extern void ppc_mfspr(uint32_t opcode);
extern void ppc_mtmsr(uint32_t opcode);
extern void ppc_mtspr(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb0(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode);
extern void ppc_mcrfs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmr(uint32_t opcode);
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode);
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode);
template <field_shift shift> extern void ppc_addi(uint32_t opcode);
template <field_rc rec> extern void ppc_addic(uint32_t opcode);
template <field_shift shift> extern void 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 void ppc_bc(uint32_t opcode);
extern void ppc_cmpi(uint32_t opcode);
extern void ppc_cmpli(uint32_t opcode);
template <class T> extern void ppc_lz(uint32_t opcode);
template <class T> extern void ppc_lzu(uint32_t opcode);
extern void ppc_lha(uint32_t opcode);
extern void ppc_lhau(uint32_t opcode);
extern void ppc_lmw(uint32_t opcode);
extern void ppc_mulli(uint32_t opcode);
template <field_shift shift> extern void ppc_ori(uint32_t opcode);
extern void ppc_rfi(uint32_t opcode);
extern void ppc_rlwimi(uint32_t opcode);
extern void ppc_rlwinm(uint32_t opcode);
extern void ppc_rlwnm(uint32_t opcode);
extern void ppc_sc(uint32_t opcode);
template <class T> extern void ppc_st(uint32_t opcode);
template <class T> extern void ppc_stu(uint32_t opcode);
extern void ppc_stmw(uint32_t opcode);
extern void ppc_subfic(uint32_t opcode);
extern void ppc_twi(uint32_t opcode);
template <field_shift shift> extern void ppc_xori(uint32_t opcode);
extern void ppc_lfs(uint32_t opcode);
extern void ppc_lfsu(uint32_t opcode);
extern void ppc_lfsx(uint32_t opcode);
extern void ppc_lfsux(uint32_t opcode);
extern void ppc_lfd(uint32_t opcode);
extern void ppc_lfdu(uint32_t opcode);
extern void ppc_lfdx(uint32_t opcode);
extern void ppc_lfdux(uint32_t opcode);
extern void ppc_stfs(uint32_t opcode);
extern void ppc_stfsu(uint32_t opcode);
extern void ppc_stfsx(uint32_t opcode);
extern void ppc_stfsux(uint32_t opcode);
extern void ppc_stfd(uint32_t opcode);
extern void ppc_stfdu(uint32_t opcode);
extern void ppc_stfdx(uint32_t opcode);
extern void ppc_stfdux(uint32_t opcode);
template <field_rc rec> extern void ppc_fadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmul(uint32_t opcode);
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode);
template <field_rc rec> extern void ppc_fadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode);
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode);
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode);
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode);
template <field_rc rec> extern void ppc_fabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode);
template <field_rc rec> extern void ppc_fneg(uint32_t opcode);
template <field_rc rec> extern void ppc_fsel(uint32_t opcode);
template <field_rc rec> extern void ppc_fres(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode);
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode);
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode);
template <field_rc rec> extern void ppc_frsp(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode);
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode);
extern void ppc_fcmpo(uint32_t opcode);
extern void ppc_fcmpu(uint32_t opcode);
// Power-specific instructions
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode);
extern void 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 void power_divs(uint32_t opcode);
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode);
extern void power_dozi(uint32_t opcode);
template <field_rc rec> extern void power_lscbx(uint32_t opcode);
template <field_rc rec> extern void power_maskg(uint32_t opcode);
template <field_rc rec> extern void 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 void power_nabs(uint32_t opcode);
extern void power_rlmi(uint32_t opcode);
template <field_rc rec> extern void power_rrib(uint32_t opcode);
template <field_rc rec> extern void power_sle(uint32_t opcode);
template <field_rc rec> extern void power_sleq(uint32_t opcode);
template <field_rc rec> extern void power_sliq(uint32_t opcode);
template <field_rc rec> extern void power_slliq(uint32_t opcode);
template <field_rc rec> extern void power_sllq(uint32_t opcode);
template <field_rc rec> extern void power_slq(uint32_t opcode);
template <field_rc rec> extern void power_sraiq(uint32_t opcode);
template <field_rc rec> extern void power_sraq(uint32_t opcode);
template <field_rc rec> extern void power_sre(uint32_t opcode);
template <field_rc rec> extern void power_srea(uint32_t opcode);
template <field_rc rec> extern void power_sreq(uint32_t opcode);
template <field_rc rec> extern void power_sriq(uint32_t opcode);
template <field_rc rec> extern void power_srliq(uint32_t opcode);
template <field_rc rec> extern void power_srlq(uint32_t opcode);
template <field_rc rec> extern void power_srq(uint32_t opcode);
} // namespace dppc_interpreter
// AltiVec instructions
// 64-bit instructions
// G5+ instructions
extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode);
extern void ppc_main_opcode(uint32_t instr);
extern void ppc_exec(void);
extern void ppc_exec_single(void);
extern void ppc_exec_until(uint32_t goal_addr);
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
extern PPCOpcode* ppc_opcode_grabber;
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
/* debugging support API */
void print_fprs(void); /* print content of the floating-point registers */
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
// The functions used by the PowerPC processor
#include "ppcmacros_prototypes.h"
namespace dppc_interpreter {
#include "ppcopcodes.include"
#include "poweropcodes.include"
#include "ppcfpopcodes.include"
} // namespace dppc_interpreter
#endif /* PPCEMU_H */
+30 -36
View File
@@ -57,7 +57,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_ISI:
if (exec_flags & ~EXEF_OPC_DECODER) {
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
@@ -66,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags & ~EXEF_OPC_DECODER) {
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -90,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_DECR:
if (exec_flags & ~EXEF_OPC_DECODER) {
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -114,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;
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
ppc_state.msr &= 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */
if (!is_601) {
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
}
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, new_msr_val, false);
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000;
@@ -201,17 +196,16 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
throw std::invalid_argument(exc_descriptor);
}
void ppc_floating_point_exception(uint32_t opcode) {
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
ppc_state.pc, opcode);
void ppc_floating_point_exception(uint32_t instr) {
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x", ppc_state.pc, instr);
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
}
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
void ppc_alignment_exception(uint32_t ea, uint32_t instr)
{
uint32_t dsisr;
switch (opcode & 0xfc000000) {
switch (instr & 0xfc000000) {
case 0x80000000: // lwz
case 0x90000000: // stw
case 0xa0000000: // lhz
@@ -233,11 +227,11 @@ void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
case 0xd4000000: // stfsu
case 0xdc000000: // stfdu
// indirect with immediate index
dsisr = ((opcode >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((opcode >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
dsisr = ((instr >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
| ((instr >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
break;
case 0x7c000000:
switch (opcode & 0xfc0007ff) {
switch (instr & 0xfc0007ff) {
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
case 0x7c0002aa: // lwax (64-bit only)
case 0x7c00042a: // lswx
@@ -271,12 +265,12 @@ void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
case 0x7c00056e: // stfsux
case 0x7c0005ee: // stfdux
indirect_with_index:
dsisr = ((opcode << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
| ((opcode << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
| ((opcode << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
dsisr = ((instr << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
| ((instr << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
| ((instr << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
break;
case 0x7c0007ec:
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
if ((instr & 0xffe007ff) == 0x7c0007ec) // dcbz
goto indirect_with_index;
/* fallthrough */
default:
@@ -287,31 +281,31 @@ indirect_with_index:
unexpected_instruction:
dsisr = 0;
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
opcode);
instr);
}
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
// Undefined for dcbz.
dsisr |= ((opcode >> 16) & 0x000003e0);
dsisr |= ((instr >> 16) & 0x000003e0);
if ((opcode & 0xfc000000) == 0xb8000000) { // lmw
if ((instr & 0xfc000000) == 0xb8000000) { // lmw
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((opcode & 0xfc0007ff) == 0x7c0004aa) { // lswi
"What to set DSISR bits 27-31?", instr);
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
}
else if ((instr & 0xfc0007ff) == 0x7c0004aa) { // lswi
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
}
else if ((opcode & 0xfc0007ff) == 0x7c00042a) { // lswx
"What to set DSISR bits 27-31?", instr);
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
}
else if ((instr & 0xfc0007ff) == 0x7c00042a) { // lswx
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
"What to set DSISR bits 27-31?", opcode);
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
"What to set DSISR bits 27-31?", instr);
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
}
else {
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
dsisr |= ((opcode >> 16) & 0x0000001f);
dsisr |= ((instr >> 16) & 0x0000001f);
}
ppc_state.spr[SPR::DSISR] = dsisr;
+339 -463
View File
@@ -24,9 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcemu.h"
#include "ppcmmu.h"
#include "ppcdisasm.h"
#include "ppcoptablemacros.h"
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
@@ -57,9 +57,6 @@ using namespace dppc_interpreter;
MemCtrlBase* mem_ctrl_instance = 0;
bool is_601 = false;
bool include_601 = false;
bool is_deterministic = false;
bool power_on = false;
Po_Cause power_off_reason = po_enter_debugger;
@@ -154,12 +151,9 @@ public:
op_name_counts.emplace_back(op_name, pair.second);
}
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
std::partial_sort(
op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(),
[](const auto& a, const auto& b) {
return b.second < a.second;
}
);
std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
return b.second < a.second;
});
op_name_counts.resize(top_ops_size);
for (const auto& pair : op_name_counts) {
vars.push_back({.name = "Instruction " + pair.first,
@@ -184,45 +178,32 @@ public:
#endif
/** Opcode lookup table, indexed by
primary opcode (bits 0...5) and modifier (bits 21...31). */
static PPCOpcode OpcodeGrabber[64 * 2048];
/** Opcode lookup tables. */
/** 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];
/** Primary opcode (bits 0...5) lookup table. */
static PPCOpcode OpcodeGrabber[64];
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
}
}
/** Lookup tables for branch instructions. */
static PPCOpcode Opcode16Grabber[4]; // bcla
PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
static PPCOpcode Opcode18Grabber[4]; // bla
/** Instructions decoding tables for integer,
single floating-point, and double-floating point ops respectively */
static PPCOpcode Opcode19Grabber[2048];
static PPCOpcode Opcode31Grabber[2048];
static PPCOpcode Opcode59Grabber[64];
static PPCOpcode Opcode63Grabber[2048];
/** Exception helpers. */
void ppc_illegalop(uint32_t opcode) {
void ppc_illegalop(uint32_t null_val) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
void ppc_fpu_off(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_NO_FPU, Exc_Cause::FPU_OFF);
void ppc_fpu_off() {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_OFF);
}
void ppc_assert_int() {
@@ -241,16 +222,128 @@ void ppc_release_int() {
/** Opcode decoding functions. */
/* Dispatch using primary and modifier opcode */
void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
{
static void ppc_opcode16(uint32_t subop, uint32_t instr) {
Opcode16Grabber[instr & 3](instr);
}
static void ppc_opcode18(uint32_t instr) {
Opcode18Grabber[instr & 3](instr);
}
template<field_601 for601>
void ppc_opcode19(uint32_t instr) {
uint16_t subop_grab = instr & 0x7FF;
switch (subop_grab) {
case 0:
ppc_mcrf(instr);
break;
case 32:
ppc_bclr<LK0>(instr);
break;
case 33:
ppc_bclr<LK1>(instr);
break;
case 66:
ppc_crnor(instr);
break;
case 100:
ppc_rfi(instr);
break;
case 258:
ppc_crandc(instr);
break;
case 300:
ppc_isync(instr);
break;
case 386:
ppc_crxor(instr);
break;
case 450:
ppc_crnand(instr);
break;
case 514:
ppc_crand(instr);
break;
case 578:
ppc_creqv(instr);
break;
case 834:
ppc_crorc(instr);
break;
case 898:
ppc_cror(instr);
break;
case 1056:
ppc_bcctr<LK0, for601>(instr);
break;
case 1057:
ppc_bcctr<LK1, for601>(instr);
break;
default:
ppc_illegalop();
}
}
template void ppc_opcode19<NOT601>(uint32_t);
template void ppc_opcode19<IS601>(uint32_t);
void ppc_opcode31(uint32_t instr) {
}
void ppc_opcode59(uint32_t instr) {
uint16_t subop_grab = instr & 0x3FUL;
Opcode59Grabber[subop_grab](instr);
}
void ppc_opcode63(uint32_t instr) {
uint16_t subop_grab = instr & 0x7FFUL;
Opcode63Grabber[subop_grab](instr);
}
/* Dispatch using main opcode */
void ppc_main_opcode(uint32_t instr) {
#ifdef CPU_PROFILING
num_executed_instrs++;
#if defined(CPU_PROFILING_OPS)
num_opcodes[opcode]++;
num_opcodes[instr]++;
#endif
#endif
opcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
uint32_t opcode = (instr >> 26) & 63;
switch (opcode) {
case 16:
Opcode16Grabber[instr & 3](instr);
break;
case 18:
Opcode16Grabber[instr & 3](instr);
break;
case 19:
if (is_601)
ppc_opcode19<IS601>(instr);
else
ppc_opcode19<NOT601>(instr);
break;
case 31:
uint16_t subop_grab = instr & 0x7FFUL;
Opcode31Grabber[subop_grab](instr);
break;
case 59:
uint16_t subop_grab = instr & 0x7FFUL;
Opcode31Grabber[subop_grab](instr);
break;
case 63:
uint16_t subop_grab = instr & 0x7FFUL;
Opcode31Grabber[subop_grab](instr);
break;
default:
OpcodeGrabber[opcode](instr);
}
#ifdef CPU_PROFILING
uint32_t load_chk = (instr >> 26);
if ((load_chk > 31) && (load_chk < 59))
num_int_loads++;
#endif
}
static long long cpu_now_ns() {
@@ -289,73 +382,60 @@ static void force_cycle_counter_reload()
exec_timer = true;
}
typedef enum {
main,
until,
debug,
} ppc_exec_type_t;
/** Execute PPC code as long as power is on. */
// inner interpreter loop
template <ppc_exec_type_t exec_type>
static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
static void ppc_exec_inner()
{
uint64_t max_cycles = 0;
uint32_t page_start, eb_start, eb_end = 0;
uint32_t opcode;
PPCOpcode* opcode_grabber = ppc_opcode_grabber;
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint8_t* pc_real;
uint32_t instr = 0;
uint32_t i_params[5] = {0};
double f_params[4] = {0};
max_cycles = 0;
while (power_on) {
if (exec_type == debug)
if (ppc_state.pc >= start_addr && ppc_state.pc < start_addr + size)
break;
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
exec_flags = 0;
if (ppc_state.pc >= eb_end) {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
page_start = eb_start & PPC_PAGE_MASK;
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);
instr = ppc_set_cur_instruction(pc_real);
opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode_grabber, opcode);
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]]
max_cycles = process_events();
if (exec_flags) {
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
opcode_grabber = ppc_opcode_grabber;
// interpret execution block
while (power_on && ppc_state.pc < eb_end) {
ppc_main_opcode(instr);
if (g_icycles++ >= max_cycles || exec_timer) {
max_cycles = process_events();
}
// define next execution block
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
if (exec_flags) {
// define next execution block
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
instr = ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
pc_real = mmu_translate_imem(eb_start);
instr = ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
pc_real = mmu_translate_imem(eb_start);
ppc_state.pc += 4;
pc_real += 4;
instr = ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else { [[likely]]
ppc_state.pc += 4;
pc_real += 4;
}
if (exec_type == until)
if (ppc_state.pc == start_addr)
break;
}
}
/** Execute PPC code as long as power is on. */
// inner interpreter loop
template void ppc_exec_inner<main>(uint32_t start_addr, uint32_t size);
// outer interpreter loop
void ppc_exec()
{
@@ -366,7 +446,7 @@ void ppc_exec()
}
while (power_on) {
ppc_exec_inner<main>(0, 0);
ppc_exec_inner();
}
}
@@ -381,9 +461,12 @@ void ppc_exec_single()
return;
}
mmu_translate_imem(ppc_state.pc);
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(ppc_opcode_grabber, opcode);
uint32_t instr = ppc_set_cur_instruction(pc_real);
ppc_main_opcode(instr);
g_icycles++;
process_events();
@@ -398,27 +481,126 @@ void ppc_exec_single()
/** Execute PPC code until goal_addr is reached. */
// inner interpreter loop
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
static void ppc_exec_until_inner(const uint32_t goal_addr)
{
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint8_t* pc_real;
uint32_t instr;
max_cycles = 0;
do {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
exec_flags = 0;
pc_real = mmu_translate_imem(eb_start);
instr = ppc_set_cur_instruction(pc_real);
// interpret execution block
while (power_on && ppc_state.pc < eb_end) {
ppc_main_opcode(instr);
if (g_icycles++ >= max_cycles || exec_timer) {
max_cycles = process_events();
}
if (exec_flags) {
// define next execution block
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
instr = ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
pc_real = mmu_translate_imem(eb_start);
instr = ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else {
ppc_state.pc += 4;
pc_real += 4;
instr = ppc_set_cur_instruction(pc_real);
}
if (ppc_state.pc == goal_addr)
break;
}
} while (power_on && ppc_state.pc != goal_addr);
}
// outer interpreter loop
void ppc_exec_until(volatile uint32_t goal_addr) {
void ppc_exec_until(volatile uint32_t goal_addr)
{
if (setjmp(exc_env)) {
// process low-level exceptions
// LOG_F(9, "PPC-EXEC: low_level exception raised!");
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
}
while (power_on) {
ppc_exec_inner<until>(goal_addr, 0);
if (ppc_state.pc == goal_addr)
break;
}
do {
ppc_exec_until_inner(goal_addr);
} while (power_on && ppc_state.pc != goal_addr);
}
/** Execute PPC code until control is reached the specified region. */
// inner interpreter loop
template void ppc_exec_inner<debug>(uint32_t start_addr, uint32_t size);
static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
{
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint8_t* pc_real;
uint32_t instr = 0;
max_cycles = 0;
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
exec_flags = 0;
pc_real = mmu_translate_imem(eb_start);
instr = ppc_set_cur_instruction(pc_real);
// interpret execution block
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)
&& (ppc_state.pc < eb_end)) {
ppc_main_opcode(instr);
if (g_icycles++ >= max_cycles || exec_timer) {
max_cycles = process_events();
}
if (exec_flags) {
// define next execution block
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
instr = ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
pc_real = mmu_translate_imem(eb_start);
instr = ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else {
ppc_state.pc += 4;
pc_real += 4;
instr = ppc_set_cur_instruction(pc_real);
}
}
}
}
// outer interpreter loop
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
@@ -430,7 +612,7 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
}
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
ppc_exec_inner<debug>(start_addr, size);
ppc_exec_dbg_inner(start_addr, size);
}
}
@@ -440,379 +622,73 @@ Opcode table macros:
- o is for overflow (OV).
- c is for carry CARRY0/CARRY1. It also works for other options:
SHFT0/SHFT1, RIGHT0/LEFT1, uint8_t/uint16_t/uint32_t, and int8_t/int16_t.
- a is for absolute address (AA).
- l is for link register (LK).
- r is for raw (adding custom entries to the table)
*/
#define OP(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
} \
} while (0)
#define 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; \
} \
OpcodeGrabber[opcode] = fn; \
} while (0)
#define OPX(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0)
#define OPX_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1)] = ppc_fpu_off; \
opcode ## Grabber[((subopcode)<<1)] = fn; \
} while (0)
#define OPXd(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
} while (0)
#define 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; \
opcode ## Grabber[((subopcode)<<1)] = fn<RC0>; \
opcode ## Grabber[((subopcode)<<1)+1] = fn<RC1>; \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<RC1, OV1>; \
opcode ## Grabber[((subopcode)<<1)] = fn<RC0, OV0>; \
opcode ## Grabber[((subopcode)<<1)+1] = fn<RC1, OV0>; \
opcode ## Grabber[1024+((subopcode)<<1)] = fn<RC0, OV1>; \
opcode ## Grabber[1024+((subopcode)<<1)+1] = fn<RC1, OV1>; \
} while (0)
#define OPXdc(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
} while (0)
#define 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; \
opcode ## Grabber[((subopcode)<<1)] = fn<carry, RC0>; \
opcode ## Grabber[((subopcode)<<1)+1] = fn<carry, RC1>; \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1, OV0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x400] = fn<carry, RC0, OV1>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x401] = fn<carry, RC1, OV1>; \
opcode ## Grabber[((subopcode)<<1)] = fn<carry, RC0, OV0>; \
opcode ## Grabber[((subopcode)<<1)+1] = fn<carry, RC1, OV0>; \
opcode ## Grabber[1024+((subopcode)<<1)] = fn<carry, RC0, OV1>; \
opcode ## Grabber[1024+((subopcode)<<1)+1] = fn<carry, RC1, OV1>; \
} while (0)
#define OPla(opcode, subopcode, fn) \
do { \
for (uint32_t mod = 0; mod < 512; mod++) { \
OpcodeGrabber[((opcode) << 11) | (mod << 2) | (subopcode)] = fn; \
} \
} while (0)
#define OP31(subopcode, fn) OPX(Opcode31, subopcode, fn)
#define OP31d(subopcode, fn) OPXd(Opcode31, subopcode, fn)
#define OP31od(subopcode, fn) OPXod(Opcode31, subopcode, fn)
#define OP31dc(subopcode, fn, carry) OPXdc(Opcode31, subopcode, fn, carry)
#define OP31cod(subopcode, fn, carry) OPXcod(Opcode31, subopcode, fn, carry)
#define OPr(opcode, mod, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | (mod)] = fn; \
} while (0)
#define OP59d(subopcode, fn) OPXd(Opcode59, 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 OP31od(subopcode, fn) OPXod(31, subopcode, fn)
#define OP31dc(subopcode, fn, carry) OPXdc(31, subopcode, fn, carry)
#define OP31cod(subopcode, fn, carry) OPXcod(31, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX(Opcode63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd(Opcode63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc(Opcode63, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX_fp(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry)
inline void initialize_ppc_opcode_tables(bool include_601) {
std::fill_n(OpcodeGrabber, 64, ppc_illegalop);
std::fill_n(Opcode16Grabber, 3, ppc_illegalop);
std::fill_n(Opcode18Grabber, 3, ppc_illegalop);
std::fill_n(Opcode19Grabber, 2048, ppc_illegalop);
std::fill_n(Opcode31Grabber, 2048, ppc_illegalop);
std::fill_n(Opcode59Grabber, 64, ppc_illegalop);
std::fill_n(Opcode63Grabber, 2048, ppc_illegalop);
#define OP59d(subopcode, fn) \
do { \
OPXd_fp(59, (subopcode), fn); \
} while (0)
#define OP59cd(subopcode, fn) \
do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \
OPXd_fp(59, (ccccc << 5) | (subopcode), fn); \
} \
} while (0)
void initialize_ppc_opcode_table() {
auto opcodeGrabberSize = sizeof(OpcodeGrabber) / sizeof(OpcodeGrabber[0]);
std::fill_n(OpcodeGrabber, opcodeGrabberSize, ppc_illegalop);
std::fill_n(OpcodeGrabberNoFPU, opcodeGrabberSize, ppc_illegalop);
OP(3, ppc_twi);
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
OP(7, ppc_mulli);
OP(8, ppc_subfic);
if (is_601 || include_601) OP(9, power_dozi);
OP(10, ppc_cmpli);
OP(11, ppc_cmpi);
OP(12, ppc_addic<RC0>);
OP(13, ppc_addic<RC1>);
OP(14, ppc_addi<SHFT0>);
OP(15, ppc_addi<SHFT1>);
OP(17, ppc_sc);
OP(20, ppc_rlwimi);
OP(21, ppc_rlwinm);
if (is_601 || include_601) OP(22, power_rlmi);
OP(23, ppc_rlwnm);
OP(24, ppc_ori<SHFT0>);
OP(25, ppc_ori<SHFT1>);
OP(26, ppc_xori<SHFT0>);
OP(27, ppc_xori<SHFT1>);
OP(28, ppc_andirc<SHFT0>);
OP(29, ppc_andirc<SHFT1>);
OP(32, ppc_lz<uint32_t>);
OP(33, ppc_lzu<uint32_t>);
OP(34, ppc_lz<uint8_t>);
OP(35, ppc_lzu<uint8_t>);
OP(36, ppc_st<uint32_t>);
OP(37, ppc_stu<uint32_t>);
OP(38, ppc_st<uint8_t>);
OP(39, ppc_stu<uint8_t>);
OP(40, ppc_lz<uint16_t>);
OP(41, ppc_lzu<uint16_t>);
OP(42, ppc_lha);
OP(43, ppc_lhau);
OP(44, ppc_st<uint16_t>);
OP(45, ppc_stu<uint16_t>);
OP(46, ppc_lmw);
OP(47, ppc_stmw);
OP_fp(48, ppc_lfs);
OP_fp(49, ppc_lfsu);
OP_fp(50, ppc_lfd);
OP_fp(51, ppc_lfdu);
OP_fp(52, ppc_stfs);
OP_fp(53, ppc_stfsu);
OP_fp(54, ppc_stfd);
OP_fp(55, ppc_stfdu);
OPla(16, 0x0, (dppc_interpreter::ppc_bc<LK0, AA0>)); // bc
OPla(16, 0x1, (dppc_interpreter::ppc_bc<LK1, AA0>)); // bcl
OPla(16, 0x2, (dppc_interpreter::ppc_bc<LK0, AA1>)); // bca
OPla(16, 0x3, (dppc_interpreter::ppc_bc<LK1, AA1>)); // bcla
OPla(18, 0x0, (dppc_interpreter::ppc_b<LK0, AA0>)); // b
OPla(18, 0x1, (dppc_interpreter::ppc_b<LK1, AA0>)); // bl
OPla(18, 0x2, (dppc_interpreter::ppc_b<LK0, AA1>)); // ba
OPla(18, 0x3, (dppc_interpreter::ppc_b<LK1, AA1>)); // bla
OPr(19, 0, ppc_mcrf);
OPr(19, 32, ppc_bclr<LK0>);
OPr(19, 33, ppc_bclr<LK1>);
OPr(19, 66, ppc_crnor);
OPr(19, 100, ppc_rfi);
OPr(19, 258, ppc_crandc);
OPr(19, 300, ppc_isync);
OPr(19, 386, ppc_crxor);
OPr(19, 450, ppc_crnand);
OPr(19, 514, ppc_crand);
OPr(19, 578, ppc_creqv);
OPr(19, 834, ppc_crorc);
OPr(19, 898, ppc_cror);
OPr(19, 1056, (is_601 ? ppc_bcctr<LK0, IS601> : ppc_bcctr<LK0, NOT601>));
OPr(19, 1057, (is_601 ? ppc_bcctr<LK1, IS601> : ppc_bcctr<LK1, NOT601>));
OP31(0, ppc_cmp);
OP31(4, ppc_tw);
OP31(32, ppc_cmpl);
OP31cod(8, ppc_subf, CARRY1);
OP31cod(40, ppc_subf, CARRY0);
OP31od(104, ppc_neg);
OP31od(136, ppc_subfe);
OP31od(200, ppc_subfze);
OP31od(232, ppc_subfme);
OP31cod(10, ppc_add, CARRY1);
OP31od(138, ppc_adde);
OP31od(202, ppc_addze);
OP31od(234, ppc_addme);
OP31cod(266, ppc_add, CARRY0);
OP31d(11, ppc_mulhwu);
OP31d(75, ppc_mulhw);
OP31od(235, ppc_mullw);
OP31od(459, ppc_divwu);
OP31od(491, ppc_divw);
OP31(20, ppc_lwarx);
OP31(23, ppc_lzx<uint32_t>);
OP31(55, ppc_lzux<uint32_t>);
OP31(87, ppc_lzx<uint8_t>);
OP31(119, ppc_lzux<uint8_t>);
OP31(279, ppc_lzx<uint16_t>);
OP31(311, ppc_lzux<uint16_t>);
OP31(343, ppc_lhax);
OP31(375, ppc_lhaux);
OP31(533, ppc_lswx);
OP31(534, ppc_lwbrx);
OP31_fp(535, ppc_lfsx);
OP31_fp(567, ppc_lfsux);
OP31(597, ppc_lswi);
OP31_fp(599, ppc_lfdx);
OP31_fp(631, ppc_lfdux);
OP31(790, ppc_lhbrx);
OPr(31, (150<<1) | 1, ppc_stwcx); // No Rc=0 variant.
OP31(151, ppc_stx<uint32_t>);
OP31(183, ppc_stux<uint32_t>);
OP31(215, ppc_stx<uint8_t>);
OP31(247, ppc_stux<uint8_t>);
OP31(407, ppc_stx<uint16_t>);
OP31(439, ppc_stux<uint16_t>);
OP31(661, ppc_stswx);
OP31(662, ppc_stwbrx);
OP31_fp(663, ppc_stfsx);
OP31_fp(695, ppc_stfsux);
OP31(725, ppc_stswi);
OP31_fp(727, ppc_stfdx);
OP31_fp(759, ppc_stfdux);
OP31(918, ppc_sthbrx);
if (!is_601) OP31_fp(983, ppc_stfiwx);
OP31(310, ppc_eciwx);
OP31(438, ppc_ecowx);
OP31dc(24, ppc_shift, LEFT1); // slw
OP31dc(28, ppc_logical, ppc_and);
OP31dc(60, ppc_logical, ppc_andc);
OP31dc(124, ppc_logical, ppc_nor);
OP31dc(284, ppc_logical, ppc_eqv);
OP31dc(316, ppc_logical, ppc_xor);
OP31dc(412, ppc_logical, ppc_orc);
OP31dc(444, ppc_logical, ppc_or);
OP31dc(476, ppc_logical, ppc_nand);
OP31dc(536, ppc_shift, RIGHT0); // srw
OP31d(792, ppc_sraw);
OP31d(824, ppc_srawi);
OP31dc(922, ppc_exts, int16_t);
OP31dc(954, ppc_exts, int8_t);
OP31d(26, ppc_cntlzw);
OP31(19, ppc_mfcr);
OP31(83, ppc_mfmsr);
OP31(144, ppc_mtcrf);
OP31(146, ppc_mtmsr);
OP31(210, ppc_mtsr);
OP31(242, ppc_mtsrin);
OP31(339, ppc_mfspr);
if (!is_601) OP31(371, ppc_mftb);
OP31(467, ppc_mtspr);
OP31(512, ppc_mcrxr);
OP31(595, ppc_mfsr);
OP31(659, ppc_mfsrin);
OP31(54, ppc_dcbst);
OP31(86, ppc_dcbf);
OP31(246, ppc_dcbtst);
OP31(278, ppc_dcbt);
OP31(598, ppc_sync);
OP31(470, ppc_dcbi);
OP31(1014, ppc_dcbz);
if (is_601 || include_601) {
OP31d(29, power_maskg);
OP31od(107, power_mul);
OP31d(152, power_slq);
OP31d(153, power_sle);
OP31d(184, power_sliq);
OP31d(216, power_sllq);
OP31d(217, power_sleq);
OP31d(248, power_slliq);
OP31od(264, power_doz);
OP31d(277, power_lscbx);
OP31od(331, power_div);
OP31od(360, power_abs);
OP31od(363, power_divs);
OP31od(488, power_nabs);
OP31(531, power_clcs);
OP31d(537, power_rrib);
OP31d(541, power_maskir);
OP31d(664, power_srq);
OP31d(665, power_sre);
OP31d(696, power_sriq);
OP31d(728, power_srlq);
OP31d(729, power_sreq);
OP31d(760, power_srliq);
OP31d(920, power_sraq);
OP31d(921, power_srea);
OP31d(952, power_sraiq);
}
OP31(306, ppc_tlbie);
if (!is_601) OP31(370, ppc_tlbia);
if (!is_601) OP31(566, ppc_tlbsync);
OP31(854, ppc_eieio);
OP31(982, ppc_icbi);
if (!is_601) OP31(978, ppc_tlbld);
if (!is_601) OP31(1010, ppc_tlbli);
OP59d(18, ppc_fdivs);
OP59d(20, ppc_fsubs);
OP59d(21, ppc_fadds);
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP59d(22, ppc_fsqrts);
if (!is_601) OP59d(24, ppc_fres);
OP59cd(25, ppc_fmuls);
OP59cd(28, ppc_fmsubs);
OP59cd(29, ppc_fmadds);
OP59cd(30, ppc_fnmsubs);
OP59cd(31, ppc_fnmadds);
OP63(0, ppc_fcmpu);
OP63d(12, ppc_frsp);
OP63d(14, ppc_fctiw);
OP63d(15, ppc_fctiwz);
OP63d(18, ppc_fdiv);
OP63d(20, ppc_fsub);
OP63d(21, ppc_fadd);
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP63d(22, ppc_fsqrt);
if (!is_601) OP63d(26, ppc_frsqrte);
OP63(32, ppc_fcmpo);
OP63d(38, ppc_mtfsb1);
OP63d(40, ppc_fneg);
OP63(64, ppc_mcrfs);
OP63d(70, ppc_mtfsb0);
OP63d(72, ppc_fmr);
OP63d(134, ppc_mtfsfi);
OP63d(136, ppc_fnabs);
OP63d(264, ppc_fabs);
if (is_601) OP63dc(583, ppc_mffs, IS601); else OP63dc(583, ppc_mffs, NOT601);
OP63d(711, ppc_mtfsf);
for (int i = 0; i < 1024; i += 32) {
if (!is_601) OP63d(i + 23, ppc_fsel);
OP63d(i + 25, ppc_fmul);
OP63d(i + 28, ppc_fmsub);
OP63d(i + 29, ppc_fmadd);
OP63d(i + 30, ppc_fnmsub);
OP63d(i + 31, ppc_fnmadd);
}
for (auto i = 0; i < opcodeGrabberSize; i++) {
if (OpcodeGrabberNoFPU[i] != ppc_fpu_off) {
OpcodeGrabberNoFPU[i] = OpcodeGrabber[i];
}
}
#include "ppcopcodes.include"
#include "poweropcodes.include"
#include "ppcfpopcodes.include"
}
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 include_601, uint64_t tb_freq)
{
mem_ctrl_instance = mem_ctrl;
@@ -821,9 +697,8 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
ppc_state.spr[SPR::PVR] = cpu_version;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 & do_include_601;
initialize_ppc_opcode_table();
initialize_ppc_opcode_tables(include_601);
// initialize emulator timers
TimerManager::get_instance()->set_time_now_cb(&get_virt_time_ns);
@@ -850,15 +725,13 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
dec_wr_value = 0;
uint32_t new_msr_val;
if (is_601) {
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */
new_msr_val = (MSR::ME + MSR::IP);
ppc_state.msr = (MSR::ME + MSR::IP);
} else {
new_msr_val = MSR::IP;
ppc_state.msr = MSR::IP;
ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL;
}
ppc_msr_did_change(new_msr_val, new_msr_val, false);
ppc_mmu_init();
@@ -871,6 +744,12 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
#endif
}
void print_fprs() {
for (int i = 0; i < 32; i++) {
cout << "FPR " << dec << i << " : " << ppc_state.fpr[i].dbl64_r << endl;
}
}
static map<string, int> SPRName2Num = {
{"XER", SPR::XER}, {"LR", SPR::LR}, {"CTR", SPR::CTR},
{"DEC", SPR::DEC_S}, {"PVR", SPR::PVR}, {"SPRG0", SPR::SPRG0},
@@ -913,11 +792,8 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
return ppc_state.pc;
}
if (reg_name_u == "MSR") {
if (is_write) {
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = (uint32_t)val;
ppc_msr_did_change(old_msr_val, new_msr_val, false);
}
if (is_write)
ppc_state.msr = (uint32_t)val;
return ppc_state.msr;
}
if (reg_name_u == "CR") {
+37 -1203
View File
File diff suppressed because it is too large. Load diff
+681
View File
@@ -0,0 +1,681 @@
// Floating Point Arithmetic
OPCODEREC (fadd, 63, 21,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
max_double_check(val_reg_a, val_reg_b);
double ppc_dblresult64_d = val_reg_a + val_reg_b;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
ppc_update_fex();
if (rec)
ppc_update_cr1();
)
OPCODEREC (fsub, 63, 20,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = val_reg_a - val_reg_b;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fdiv, 63, 18,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = val_reg_a / val_reg_b;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF (fmul, 63, 25,
ppc_grab_regsfpdac(instr);
snan_double_check(reg_a, reg_c);
double ppc_dblresult64_d = val_reg_a * val_reg_c;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF (fmadd, 63, 29,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF (fmsub, 63, 28,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF (fnmadd, 63, 31,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF (fnmsub, 63, 30,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fadds, 59, 21,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fsubs, 59, 20,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fdivs, 59, 18,
ppc_grab_regsfpdab(instr);
snan_double_check(reg_a, reg_b);
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fmuls, 59, 25,
ppc_grab_regsfpdac(instr);
snan_double_check(reg_a, reg_c);
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fmadds, 59, 29,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fmsubs, 59, 28,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fnmadds, 59, 31,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fnmsubs, 59, 30,
ppc_grab_regsfpdabc(instr);
snan_double_check(reg_a, reg_c);
snan_single_check(reg_b);
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fabs, 63, 264,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC(fnabs, 63, 136,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
ppc_dblresult64_d = -ppc_dblresult64_d;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC(fneg, 63, 40,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double ppc_dblresult64_d = -(GET_FPR(reg_b));
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODERECF(fsel, 63, 23,
ppc_grab_regsfpdabc(instr);
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC(fsqrt, 63, 22,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double testd2 = (double)(GET_FPR(reg_b));
double ppc_dblresult64_d = std::sqrt(testd2);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC(fsqrts, 59, 22,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double testd2 = (double)(GET_FPR(reg_b));
double ppc_dblresult64_d = (float)std::sqrt(testd2);
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (frsqrte, 63, 26,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double testd2 = (double)(GET_FPR(reg_b));
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (frsp, 63, 12,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (rec)
ppc_update_cr1();
)
OPCODEREC (fres, 63, 24,
ppc_grab_regsfpdb(instr);
snan_single_check(reg_b);
double start_num = GET_FPR(reg_b);
double ppc_dblresult64_d = (float)(1.0 / start_num);
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
if (start_num == 0.0) {
ppc_state.fpscr |= FPSCR::ZX;
}
else if (std::isnan(start_num)) {
ppc_state.fpscr |= FPSCR::VXSNAN;
}
else if (std::isinf(start_num)){
ppc_state.fpscr &= 0xFFF9FFFF;
ppc_state.fpscr |= FPSCR::VXSNAN;
}
if (rec)
ppc_update_cr1();
)
OPCODEREC (fctiw, 63, 14,
round_to_int(instr, ppc_state.fpscr & 0x3, rec);
)
OPCODEREC (fctiwz, 63, 15,
round_to_int(instr, 1, rec);
)
// Floating Point Store and Load
OPCODE (lfs, , 48,
ppc_grab_regsfpdia(instr);
uint32_t ea = int32_t(int16_t(instr));
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
)
OPCODE (lfsu, , 49,
ppc_grab_regsfpdia(instr);
if (reg_a) {
uint32_t ea = int32_t(int16_t(instr));
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE31 (lfsx, 31, 535,
ppc_grab_regsfpdiab(instr);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
)
OPCODE31 (lfsux, 31, 567,
ppc_grab_regsfpdiab(instr);
if (reg_a) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE (lfd, , 50,
ppc_grab_regsfpdia(instr);
uint32_t ea = int32_t(int16_t(instr));
ea += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
)
OPCODE (lfdu, , 51,
ppc_grab_regsfpdia(instr);
if (reg_a != 0) {
uint32_t ea = int32_t(int16_t(instr));
ea += val_reg_a;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE31 (lfdx, 31, 599,
ppc_grab_regsfpdiab(instr);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
)
OPCODE31 (lfdux, 31, 631,
ppc_grab_regsfpdiab(instr);
if (reg_a) {
uint32_t ea = val_reg_a + val_reg_b;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE (stfs, , 52,
ppc_grab_regsfpsia(instr);
uint32_t ea = int32_t(int16_t(instr));
ea += (reg_a) ? val_reg_a : 0;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
)
OPCODE (stfsu, , 53,
ppc_grab_regsfpsia(instr);
if (reg_a != 0) {
uint32_t ea = int32_t(int16_t(instr));
ea += val_reg_a;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE31 (stfsx, 31, 663,
ppc_grab_regsfpsiab(instr);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
)
OPCODE31 (stfsux, 31, 695,
ppc_grab_regsfpsiab(instr);
if (reg_a) {
uint32_t ea = val_reg_a + val_reg_b;
float result = float(ppc_state.fpr[reg_s].dbl64_r);
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE (stfd, , 54,
ppc_grab_regsfpsia(instr);
uint32_t ea = int32_t(int16_t(instr));
ea += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
)
OPCODE (stfdu, , 55,
ppc_grab_regsfpsia(instr);
if (reg_a != 0) {
uint32_t ea = int32_t(int16_t(instr));
ea += val_reg_a;
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE31 (stfdx, 31, 727,
ppc_grab_regsfpsiab(instr);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
)
OPCODE31 (stfdux, 31, 759,
ppc_grab_regsfpsiab(instr);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
ppc_state.gpr[reg_a] = ea;
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
)
OPCODE31 (stfiwx, 31, 983,
ppc_grab_regsfpsiab(instr);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint32_t>(ea, instr, uint32_t(ppc_state.fpr[reg_s].int64_r));
)
// Floating Point Register Transfer
OPCODEREC (fmr, 63, 72,
ppc_grab_regsfpdb(instr);
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
if (rec)
ppc_update_cr1();
)
OPCODE601REC (mffs, 63, 583,
int reg_d = (instr >> 21) & 31;
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
if (rec)
ppc_update_cr1();
)
OPCODEREC (mtfsf, 63, 711,
ppc_grab_mtfsf(instr);
uint32_t cr_mask = 0;
if (fm == 0xFFU) { // the fast case
cr_mask = 0xFFFFFFFFUL;
}
else { // the slow case
if (fm & 0x80) cr_mask |= 0xF0000000UL;
if (fm & 0x40) cr_mask |= 0x0F000000UL;
if (fm & 0x20) cr_mask |= 0x00F00000UL;
if (fm & 0x10) cr_mask |= 0x000F0000UL;
if (fm & 0x08) cr_mask |= 0x0000F000UL;
if (fm & 0x04) cr_mask |= 0x00000F00UL;
if (fm & 0x02) cr_mask |= 0x000000F0UL;
if (fm & 0x01) cr_mask |= 0x0000000FUL;
}
// ensure neither FEX nor VX will be changed
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
// copy FPR[reg_b] to FPSCR under control of cr_mask
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
if (rec) {
ppc_update_cr1();
}
)
OPCODEREC (mtfsfi, 63, 134,
ppc_grab_mtfsfi(instr);
// prepare field mask and ensure that neither FEX nor VX will be changed
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
// copy imm to FPSCR[crf_d] under control of the field mask
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
// Update FEX and VX according to the "usual rule"
ppc_update_vx();
ppc_update_fex();
if (rec) {
ppc_update_cr1();
}
)
OPCODE31 (mtfsb0, 63, 70,
int crf_d = (instr >> 21) & 0x1F;
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
}
if (rec)
ppc_update_cr1();
)
OPCODE31 (mtfsb1, 63, 38,
ppc_grab_crfd(instr);
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
ppc_state.fpscr |= (0x80000000UL >> crf_d);
}
if (rec) {
ppc_update_cr1();
}
)
OPCODE31 (mcrfs, 63, 64,
ppc_grab_crfds(instr);
ppc_state.cr = (
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
);
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
// keep only the FPSCR bits that can be explicitly cleared
FPSCR::FX | FPSCR::OX |
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
));
)
// Floating Point Comparisons
OPCODE31 (fcmpo, 63, 32,
ppc_grab_regsfpsab(instr);
uint32_t cmp_c = 0;
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
cmp_c |= CRx_bit::CR_SO;
ppc_state.fpscr |= FX | VX;
if (check_snan(reg_a) || check_snan(reg_b)) {
ppc_state.fpscr |= VXSNAN;
}
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
ppc_state.fpscr |= VXVC;
}
}
else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
}
else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
}
else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
)
OPCODE (fcmpu, 63, 0,
ppc_grab_regsfpsab(instr);
uint32_t cmp_c = 0;
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
cmp_c |= CRx_bit::CR_SO;
if (check_snan(reg_a) || check_snan(reg_b)) {
ppc_state.fpscr |= FX | VX | VXSNAN;
}
}
else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
}
else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
}
else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
)
+111
View File
@@ -0,0 +1,111 @@
/*
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/>.
*/
#undef OPCODE
#define OPCODE(op, grabber, number, ...) \
void ppc_##op(uint32_t instr);
#undef OPCODE31
#define OPCODE31(op, grabber, number, ...) \
void ppc_##op(uint32_t instr);
#undef POWEROPCODE
#define POWEROPCODE(op, grabber, number, ...) \
void power_##op(uint32_t instr);
#undef POWEROPCODE31
#define POWEROPCODE31(op, grabber, number, ...) \
void power_##op(uint32_t instr);
#undef OPCODESHIFT
#define OPCODESHIFT(op, grabber, number, ...) \
template <field_shift shift> \
void ppc_##op(uint32_t instr);
#undef OPCODESHIFTREC
#define OPCODESHIFTREC(op, grabber, number, ...) \
template <field_direction isleft, field_rc rec> \
void ppc_##op(uint32_t instr);
#undef OPCODEOVREC
#define OPCODEOVREC(op, grabber, number, ...) \
template <field_rc rec, field_ov ov> \
void ppc_##op(uint32_t instr);
#undef OPCODEEXTSIGN
#define OPCODEEXTSIGN(op, grabber, number, ...) \
template <class T, field_rc rec> \
void ppc_##op(uint32_t instr);
#undef POWEROPCODEOVREC
#define POWEROPCODEOVREC(op, grabber, number, ...) \
template <field_rc rec, field_ov ov> \
void power_##op(uint32_t instr);
#undef OPCODEREC
#define OPCODEREC(op, grabber, number, ...) \
template <field_rc rec> \
void ppc_##op(uint32_t instr);
#undef OPCODERECF
#define OPCODERECF(op, grabber, number, ...) \
template <field_rc rec> \
void ppc_##op(uint32_t instr);
#undef POWEROPCODEREC
#define POWEROPCODEREC(op, grabber, number, ...) \
template <field_rc rec> \
void power_##op(uint32_t instr);
#undef OPCODELOGIC
#define OPCODELOGIC(op, grabber, number, ...) \
template <logical_fun logical_op, field_rc rec> \
void ppc_##op(uint32_t instr);
#undef OPCODELKAA
#define OPCODELKAA(op, grabber, number, ...) \
template <field_lk l, field_aa a> \
void ppc_##op(uint32_t instr);
#undef OPCODEMEM
#define OPCODEMEM(op, grabber, number, ...) \
template <class T> \
void ppc_##op(uint32_t instr);
#undef OPCODEMEMINDEXED
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
template <class T> \
void ppc_##op(uint32_t instr);
#undef OPCODE601REC
#define OPCODE601REC(op, grabber, number, ...) \
template <field_601 for601, field_rc rec> \
void ppc_##op(uint32_t instr);
#undef OPCODE601L
#define OPCODE601L(op, grabber, number, ...) \
template <field_lk l, field_601 for601> \
void ppc_##op(uint32_t instr);
#undef OPCODEL
#define OPCODEL(op, grabber, number, ...) \
template <field_lk l> \
void ppc_##op(uint32_t instr);
+46 -84
View File
@@ -385,9 +385,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurITLBMode != mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
switch(mmu_mode) {
case 0: // real address mode
pCurITLB1 = &itlb1_mode1[0];
pCurITLB2 = &itlb2_mode1[0];
@@ -396,6 +394,10 @@ void mmu_change_mode()
pCurITLB1 = &itlb1_mode2[0];
pCurITLB2 = &itlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
//LOG_F(ERROR, "instruction mmu mode 1 is invalid!"); // this happens alot. Maybe it's not invalid?
mmu_mode = 3;
case 3: // user mode with instruction translation enabled
pCurITLB1 = &itlb1_mode3[0];
pCurITLB2 = &itlb2_mode3[0];
@@ -408,9 +410,7 @@ void mmu_change_mode()
mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR);
if (CurDTLBMode != mmu_mode) {
switch (mmu_mode) {
case 1: // user mode can't disable translations
mmu_mode = 0;
switch(mmu_mode) {
case 0: // real address mode
pCurDTLB1 = &dtlb1_mode1[0];
pCurDTLB2 = &dtlb2_mode1[0];
@@ -419,6 +419,10 @@ void mmu_change_mode()
pCurDTLB1 = &dtlb1_mode2[0];
pCurDTLB2 = &dtlb2_mode2[0];
break;
case 1:
// user mode can't disable translations
LOG_F(ERROR, "data mmu mode 1 is invalid!");
mmu_mode = 3;
case 3: // user mode with data translation enabled
pCurDTLB1 = &dtlb1_mode3[0];
pCurDTLB2 = &dtlb2_mode3[0];
@@ -980,13 +984,12 @@ void mmu_pat_ctx_changed()
// Forward declarations.
template <class T>
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
template <class T>
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value);
static void write_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr, T value);
template <class T>
inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
{
inline T mmu_read_vmem(uint32_t guest_va, uint32_t instr) {
TLBEntry *tlb1_entry, *tlb2_entry;
uint8_t *host_va;
@@ -1029,7 +1032,7 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
#endif
if (sizeof(T) == 8) {
if (guest_va & 3)
ppc_alignment_exception(opcode, guest_va);
ppc_alignment_exception(guest_va, instr);
return (
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
@@ -1056,7 +1059,7 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
// handle unaligned memory accesses
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
return read_unaligned<T>(opcode, guest_va, host_va);
return read_unaligned<T>(guest_va, host_va, instr);
}
// handle aligned memory accesses
@@ -1073,14 +1076,13 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
}
// explicitely instantiate all required mmu_read_vmem variants
template uint8_t mmu_read_vmem<uint8_t>(uint32_t opcode, uint32_t guest_va);
template uint16_t mmu_read_vmem<uint16_t>(uint32_t opcode, uint32_t guest_va);
template uint32_t mmu_read_vmem<uint32_t>(uint32_t opcode, uint32_t guest_va);
template uint64_t mmu_read_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va);
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va, uint32_t instr);
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va, uint32_t instr);
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va, uint32_t instr);
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va, uint32_t instr);
template <class T>
inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
{
inline void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value) {
TLBEntry *tlb1_entry, *tlb2_entry;
uint8_t *host_va;
@@ -1151,7 +1153,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
#endif
if (sizeof(T) == 8) {
if (guest_va & 3)
ppc_alignment_exception(opcode, guest_va);
ppc_alignment_exception(guest_va, instr);
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
@@ -1174,7 +1176,7 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
// handle unaligned memory accesses
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
write_unaligned<T>(opcode, guest_va, host_va, value);
write_unaligned<T>(guest_va, host_va, instr, value);
return;
}
@@ -1196,17 +1198,16 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
}
// explicitely instantiate all required mmu_write_vmem variants
template void mmu_write_vmem<uint8_t> (uint32_t opcode, uint32_t guest_va, uint8_t value);
template void mmu_write_vmem<uint16_t>(uint32_t opcode, uint32_t guest_va, uint16_t value);
template void mmu_write_vmem<uint32_t>(uint32_t opcode, uint32_t guest_va, uint32_t value);
template void mmu_write_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va, uint64_t value);
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint32_t instr, uint8_t value);
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint32_t instr, uint16_t value);
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t instr, uint32_t value);
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint32_t instr, uint64_t value);
template <class T>
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
{
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr) {
if ((sizeof(T) == 8) && (guest_va & 3)) {
#ifndef PPC_TESTS
ppc_alignment_exception(opcode, guest_va);
ppc_alignment_exception(guest_va, instr);
#endif
}
@@ -1221,7 +1222,7 @@ static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
// Because such accesses suffer a performance penalty, they will be
// presumably very rare so don't waste time optimizing the code below.
for (int i = 0; i < sizeof(T); guest_va++, i++) {
result = (result << 8) | mmu_read_vmem<uint8_t>(opcode, guest_va);
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va, instr);
}
} else {
#ifdef MMU_PROFILING
@@ -1242,16 +1243,16 @@ static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
}
// explicitely instantiate all required read_unaligned variants
template uint16_t read_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template uint32_t read_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template uint64_t read_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
template <class T>
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value)
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t instr, T value)
{
if ((sizeof(T) == 8) && (guest_va & 3)) {
#ifndef PPC_TESTS
ppc_alignment_exception(opcode, guest_va);
ppc_alignment_exception(guest_va, instr);
#endif
}
@@ -1267,7 +1268,7 @@ static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va
uint32_t shift = (sizeof(T) - 1) * 8;
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
mmu_write_vmem<uint8_t>(opcode, guest_va, (value >> shift) & 0xFF);
mmu_write_vmem<uint8_t>(guest_va, instr, ((value >> shift) & 0xFF));
}
} else {
#ifdef MMU_PROFILING
@@ -1291,9 +1292,12 @@ static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va
}
// explicitely instantiate all required write_unaligned variants
template void write_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint16_t value);
template void write_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint32_t value);
template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint64_t value);
template void write_unaligned<uint16_t>(
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint16_t value);
template void write_unaligned<uint32_t>(
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint32_t value);
template void write_unaligned<uint64_t>(
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint64_t value);
/* MMU profiling. */
@@ -1433,19 +1437,19 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
try {
switch (size) {
case 1:
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
break;
case 2:
ret_val = mmu_read_vmem<uint16_t>(NO_OPCODE, virt_addr);
ret_val = mmu_read_vmem<uint16_t>(virt_addr, 0);
break;
case 4:
ret_val = mmu_read_vmem<uint32_t>(NO_OPCODE, virt_addr);
ret_val = mmu_read_vmem<uint32_t>(virt_addr, 0);
break;
case 8:
ret_val = mmu_read_vmem<uint64_t>(NO_OPCODE, virt_addr);
ret_val = mmu_read_vmem<uint64_t>(virt_addr, 0);
break;
default:
ret_val = mmu_read_vmem<uint8_t>(NO_OPCODE, virt_addr);
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
}
} catch (std::invalid_argument& exc) {
/* restore MMU-related CPU state */
@@ -1465,48 +1469,6 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
return ret_val;
}
void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size) {
uint32_t save_dsisr, save_dar;
uint64_t ret_val;
// save MMU-related CPU state
save_dsisr = ppc_state.spr[SPR::DSISR];
save_dar = ppc_state.spr[SPR::DAR];
mmu_exception_handler = dbg_exception_handler;
try {
switch (size) {
case 1:
mmu_write_vmem<uint8_t>(NO_OPCODE, virt_addr, value);
break;
case 2:
mmu_write_vmem<uint16_t>(NO_OPCODE, virt_addr, value);
break;
case 4:
mmu_write_vmem<uint32_t>(NO_OPCODE, virt_addr, uint32_t(value));
break;
case 8:
mmu_write_vmem<uint64_t>(NO_OPCODE, virt_addr, value);
break;
default:
mmu_write_vmem<uint8_t>(NO_OPCODE, virt_addr, value);
}
} catch (std::invalid_argument& exc) {
// restore MMU-related CPU state
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
// rethrow MMU exception
throw exc;
}
// restore MMU-related CPU state
mmu_exception_handler = ppc_exception_handler;
ppc_state.spr[SPR::DSISR] = save_dsisr;
ppc_state.spr[SPR::DAR] = save_dar;
}
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
uint32_t save_dsisr, save_dar;
bool is_mapped;
+2 -3
View File
@@ -126,13 +126,12 @@ extern void mmu_pat_ctx_changed();
extern void tlb_flush_entry(uint32_t ea);
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
template <class T>
extern T mmu_read_vmem(uint32_t opcode, uint32_t guest_va);
extern T mmu_read_vmem(uint32_t guest_va, uint32_t instr);
template <class T>
extern void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value);
extern void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value);
#endif // PPCMMU_H
+10 -1882
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+209
View File
@@ -0,0 +1,209 @@
/*
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/>.
*/
#undef OPCODE
#define OPCODE(op, grabber, number, ...) \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
}
#undef OPCODE31
#define OPCODE31(op, grabber, number, ...) \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
}
#undef POWEROPCODE
#define POWEROPCODE(op, grabber, number, ...) \
void dppc_interpreter::power_##op(uint32_t instr) { \
__VA_ARGS__ \
}
#undef POWEROPCODE31
#define POWEROPCODE31(op, grabber, number, ...) \
void dppc_interpreter::power_##op(uint32_t instr) { \
__VA_ARGS__ \
}
#undef OPCODESHIFT
#define OPCODESHIFT(op, grabber, number, ...) \
template <field_shift shift> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<SHFT0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<SHFT1>(uint32_t instr);
#undef OPCODESHIFTREC
#define OPCODESHIFTREC(op, grabber, number, ...) \
template <field_direction isleft, field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<RIGHT0, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LEFT1, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RIGHT0, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LEFT1, RC1>(uint32_t instr);
#undef OPCODEOVREC
#define OPCODEOVREC(op, grabber, number, ...) \
template <field_rc rec, field_ov ov> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<RC0, OV0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RC1, OV0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RC0, OV1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RC1, OV1>(uint32_t instr);
#undef OPCODEEXTSIGN
#define OPCODEEXTSIGN(op, grabber, number, ...) \
template <class T, field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<int8_t, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<int16_t, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<int8_t, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<int16_t, RC1>(uint32_t instr);
#undef POWEROPCODEOVREC
#define POWEROPCODEOVREC(op, grabber, number, ...) \
template <field_rc rec, field_ov ov> \
void dppc_interpreter::power_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::power_##op<RC0, OV0>(uint32_t instr); \
template void dppc_interpreter::power_##op<RC1, OV0>(uint32_t instr); \
template void dppc_interpreter::power_##op<RC0, OV1>(uint32_t instr); \
template void dppc_interpreter::power_##op<RC1, OV1>(uint32_t instr);
#undef OPCODEREC
#define OPCODEREC(op, grabber, number, ...) \
template <field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
#undef OPCODERECF
#define OPCODERECF(op, grabber, number, ...) \
template <field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
#undef POWEROPCODEREC
#define POWEROPCODEREC(op, grabber, number, ...) \
template <field_rc rec> \
void dppc_interpreter::power_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::power_##op<RC0>(uint32_t instr); \
template void dppc_interpreter::power_##op<RC1>(uint32_t instr);
#undef OPCODELOGIC
#define OPCODELOGIC(op, grabber, number, ...) \
template <logical_fun logical_op, field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<ppc_and, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_andc, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_eqv, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_nand, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_nor, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_or, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_orc, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_xor, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_and, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_andc, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_eqv, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_nand, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_nor, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_or, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_orc, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<ppc_xor, RC1>(uint32_t instr);
#undef OPCODELKAA
#define OPCODELKAA(op, grabber, number, ...) \
template <field_lk l, field_aa a> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<LK0, AA0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK0, AA1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK1, AA0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK1, AA1>(uint32_t instr);
#undef OPCODEMEM
#define OPCODEMEM(op, grabber, number, ...) \
template <class T> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
#undef OPCODEMEMINDEXED
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
template <class T> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
#undef OPCODE601REC
#define OPCODE601REC(op, grabber, number, ...) \
template <field_601 for601, field_rc rec> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<NOT601, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<IS601, RC0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<NOT601, RC1>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<IS601, RC1>(uint32_t instr); \
#undef OPCODE601L
#define OPCODE601L(op, grabber, number, ...) \
template <field_lk l, field_601 for601> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<LK0, NOT601>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK0, IS601>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK1, NOT601>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK1, IS601>(uint32_t instr); \
#undef OPCODEL
#define OPCODEL(op, grabber, number, ...) \
template <field_lk l> \
void dppc_interpreter::ppc_##op(uint32_t instr) { \
__VA_ARGS__ \
} \
template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); \
template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
+156
View File
@@ -0,0 +1,156 @@
/*
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/>.
*/
#undef OPCODE
#define OPCODE(op, grabber, number, ...) \
Opcode##grabber##Grabber[number] = ppc_##op;
#undef OPCODE31
#define OPCODE31(op, grabber, number, ...) \
Opcode##grabber##Grabber[number << 1] = ppc_##op;
#undef POWEROPCODE
#define POWEROPCODE(op, grabber, number, ...) \
if (is_601) \
Opcode##grabber##Grabber[number] = power_##op;
#undef POWEROPCODE31
#define POWEROPCODE31(op, grabber, number, ...) \
if (is_601) \
Opcode##grabber##Grabber[number << 1] = power_##op;
#undef OPCODESHIFT
#define OPCODESHIFT(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<SHFT0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<SHFT1>;
#undef OPCODESHIFTREC
#define OPCODESHIFTREC(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<LEFT1 , RC0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<LEFT1 , RC1>; \
Opcode##grabber##Grabber[number + (1 << 9) ] = ppc_##op<RIGHT0, RC0>; \
Opcode##grabber##Grabber[number + (1 << 9) + 1] = ppc_##op<RIGHT0, RC1>; \
#undef OPCODEOVREC
#define OPCODEOVREC(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<RC0, OV0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<RC1, OV0>; \
Opcode##grabber##Grabber[number + 2] = ppc_##op<RC0, OV1>; \
Opcode##grabber##Grabber[number + 3] = ppc_##op<RC1, OV1>;
#undef OPCODEEXTSIGN
#define OPCODEEXTSIGN(op, grabber, number, ...) \
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<int16_t, RC0>; \
Opcode##grabber##Grabber[( number << 1) + 1] = ppc_##op<int16_t, RC1>; \
Opcode##grabber##Grabber[ (number + 32) << 1 ] = ppc_##op<int8_t, RC0>; \
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<int8_t, RC1>;
#undef POWEROPCODEOVREC
#define POWEROPCODEOVREC(op, grabber, number, ...) \
if (is_601) { \
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0, OV0>; \
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1, OV0>; \
Opcode##grabber##Grabber[(number << 1) + 2] = power_##op<RC0, OV1>; \
Opcode##grabber##Grabber[(number << 1) + 3] = power_##op<RC1, OV1>; \
}
#undef OPCODEREC
#define OPCODEREC(op, grabber, number, ...) \
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<RC0>; \
Opcode##grabber##Grabber[(number << 1) + 1] = ppc_##op<RC1>; \
#undef OPCODERECF
#define OPCODERECF(op, grabber, number, ...) \
for (int i = 0; i < 2048; i += 32) { \
Opcode##grabber##Grabber[(number + i) << 1 ] = ppc_##op<RC0>; \
Opcode##grabber##Grabber[((number + i) << 1) + 1] = ppc_##op<RC1>; \
}
#undef POWEROPCODEREC
#define POWEROPCODEREC(op, grabber, number, ...) \
if (is_601) { \
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0>; \
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1>; \
}
#undef OPCODELOGIC
#define OPCODELOGIC(op, grabber, number, ...) \
Opcode##grabber##Grabber[ number ] = ppc_##op<ppc_and , RC0>; \
Opcode##grabber##Grabber[((number + 1) << 1) ] = ppc_##op<ppc_and , RC1>; \
Opcode##grabber##Grabber[((number + 32) << 1) ] = ppc_##op<ppc_andc, RC0>; \
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<ppc_andc, RC1>; \
Opcode##grabber##Grabber[((number + 96) << 1) ] = ppc_##op<ppc_nor , RC0>; \
Opcode##grabber##Grabber[((number + 96) << 1) + 1] = ppc_##op<ppc_nor , RC1>; \
Opcode##grabber##Grabber[((number + 256) << 1) ] = ppc_##op<ppc_eqv , RC0>; \
Opcode##grabber##Grabber[((number + 256) << 1) + 1] = ppc_##op<ppc_eqv , RC1>; \
Opcode##grabber##Grabber[((number + 288) << 1) ] = ppc_##op<ppc_xor , RC0>; \
Opcode##grabber##Grabber[((number + 288) << 1) + 1] = ppc_##op<ppc_xor , RC1>; \
Opcode##grabber##Grabber[((number + 384) << 1) ] = ppc_##op<ppc_orc , RC0>; \
Opcode##grabber##Grabber[((number + 384) << 1) + 1] = ppc_##op<ppc_orc , RC1>; \
Opcode##grabber##Grabber[((number + 416) << 1) ] = ppc_##op<ppc_or , RC0>; \
Opcode##grabber##Grabber[((number + 416) << 1) + 1] = ppc_##op<ppc_or , RC1>; \
Opcode##grabber##Grabber[((number + 448) << 1) ] = ppc_##op<ppc_nand, RC0>; \
Opcode##grabber##Grabber[((number + 448) << 1) + 1] = ppc_##op<ppc_nand, RC1>; \
#undef OPCODELKAA
#define OPCODELKAA(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, AA0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, AA0>; \
Opcode##grabber##Grabber[number + 2] = ppc_##op<LK0, AA1>; \
Opcode##grabber##Grabber[number + 3] = ppc_##op<LK1, AA1>;
#undef OPCODEMEM
#define OPCODEMEM(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<uint32_t>; \
Opcode##grabber##Grabber[number + 2] = ppc_##op<uint8_t>; \
Opcode##grabber##Grabber[number + 8] = ppc_##op<uint16_t>;
#undef OPCODEMEMINDEXED
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<uint32_t>; \
Opcode##grabber##Grabber[(number << 1) + (1 << 6)] = ppc_##op<uint8_t>; \
Opcode##grabber##Grabber[(number << 1) + (1 << 8)] = ppc_##op<uint16_t>;
#undef OPCODE601REC
#define OPCODE601REC(op, grabber, number, ...) \
if (is_601) { \
Opcode##grabber##Grabber[number ] = ppc_##op<IS601, RC0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<IS601, RC1>; \
} else { \
Opcode##grabber##Grabber[number ] = ppc_##op<NOT601, RC0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<NOT601, RC1>; \
}
#undef OPCODE601L
#define OPCODE601L(op, grabber, number, ...) \
if (is_601) { \
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, IS601>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, IS601>; \
} \
else { \
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, NOT601>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, NOT601>; \
}
#undef OPCODEL
#define OPCODEL(op, grabber, number, ...) \
Opcode##grabber##Grabber[number ] = ppc_##op<LK0>; \
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1>;
+7 -12
View File
@@ -42,11 +42,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
}
#endif
void xer_ov_test(string mnem, uint32_t opcode) {
static void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++;
@@ -150,7 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
ntested++;
@@ -292,7 +292,7 @@ static void read_test_float_data() {
ppc_state.cr = 0;
ppc_main_opcode(ppc_opcode_grabber, opcode);
ppc_main_opcode(opcode);
ntested++;
@@ -302,11 +302,10 @@ static void read_test_float_data() {
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x"
<< hex << check_cr << endl;
<< hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -317,11 +316,7 @@ static void read_test_float_data() {
}
int main() {
is_601 = true;
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
initialize_ppc_opcode_tables(true); //kludge
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/capstone/include")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(debugger OBJECT ${SOURCES})
+59 -121
View File
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcdisasm.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ofnvram.h>
#include "memaccess.h"
@@ -53,7 +52,7 @@ using namespace std;
static uint32_t str2addr(string& addr_str) {
try {
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
return (uint32_t)stoul(addr_str, NULL, 0);
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + addr_str);
}
@@ -61,7 +60,7 @@ static uint32_t str2addr(string& addr_str) {
static uint32_t str2num(string& num_str) {
try {
return static_cast<uint32_t>(stol(num_str, NULL, 0));
return (uint32_t)stol(num_str, NULL, 0);
} catch (invalid_argument& exc) {
throw invalid_argument(string("Cannot convert ") + num_str);
}
@@ -69,45 +68,41 @@ static uint32_t str2num(string& num_str) {
static void show_help() {
cout << "Debugger commands:" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GPRs" << endl;
cout << " fregs -- dump content of the FPRs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
cout << " step [N] -- execute single instruction" << endl;
cout << " N is an optional step count" << endl;
cout << " si [N] -- shortcut for step" << endl;
cout << " next -- same as step but treats subroutine calls" << endl;
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GRPs" << endl;
cout << " mregs -- dump content of the MMU registers" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
cout << " log level to X whose range is -2...9" << endl;
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
cout << " T can be b(byte), w(word), d(double)," << endl;
cout << " q(quad) or c(character)." << endl;
cout << " profile C N -- run subcommand C on profile N" << endl;
cout << " supported subcommands:" << endl;
cout << " 'show' - show profile report" << endl;
cout << " 'reset' - reset profile variables" << endl;
#ifdef PROFILER
cout << " profiler -- show stats related to the processor" << endl;
cout << " profiler -- show stats related to the processor" << endl;
#endif
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
cout << " X can be any number or a known register name" << endl;
cout << " disas with no arguments defaults to disas 1,pc" << endl;
cout << " da N,X -- shortcut for disas" << endl;
#ifdef ENABLE_68K_DEBUGGER
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
cout << " context X -- switch to the debugging context X." << endl;
cout << " X can be either 'ppc' (default) or '68k'" << endl;
cout << " Use 68k for debugging emulated 68k code only." << endl;
#endif
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << " quit -- quit the debugger" << endl << endl;
cout << "Pressing ENTER will repeat last command." << endl;
}
@@ -115,7 +110,7 @@ static void show_help() {
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle;
uint8_t code[12]{};
uint8_t code[10];
size_t code_size;
uint64_t dis_addr;
@@ -127,7 +122,7 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cs_insn* insn = cs_malloc(cs_handle);
for (; power_on && count > 0; count--) {
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1);
}
@@ -146,7 +141,7 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cout << uppercase << hex << insn->address << " ";
cout << setfill(' ');
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
address = static_cast<uint32_t>(dis_addr);
address = dis_addr;
} else {
print_bin:
cout << uppercase << hex << address << " ";
@@ -163,26 +158,26 @@ print_bin:
}
/* emulator opcode table size --> 512 KB */
constexpr auto EMU_68K_TABLE_SIZE = 0x80000;
#define EMU_68K_TABLE_SIZE 0x80000
/** Execute one emulated 68k instruction. */
void exec_single_68k()
void exec_single_68k(uint32_t instr)
{
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
/* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */
cur_68k_pc = static_cast<uint32_t>(get_reg(string("R24")) - 2);
cur_68k_pc = get_reg(string("R24")) - 2;
/* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
/* calculate address of the current opcode table entry as follows:
get_word(68k_PC) * entry_size + table_base */
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>(cur_68k_pc, 0) * 8 + emu_table_virt;
/* grab the PPC PC too */
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
ppc_pc = get_reg(string("PC"));
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
@@ -191,7 +186,7 @@ void exec_single_68k()
one by one until the execution goes outside the opcode table. */
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single();
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
ppc_pc = get_reg(string("PC"));
}
/* Getting here means we're outside the emualtor opcode table.
@@ -357,9 +352,9 @@ static void print_gprs() {
int i;
for (i = 0; i < 32; i++) {
reg_name = "r" + to_string(i);
reg_name = "R" + to_string(i);
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
if (i & 1) {
@@ -369,10 +364,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) {
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
if (i & 1) {
@@ -385,46 +380,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;
static void print_mmu_regs()
{
printf(" msr : %08X\n", ppc_state.msr);
printf("MSR : 0x%08X\n", ppc_state.msr);
printf("\nBAT registers:\n");
for (int i = 0; i < 4; i++) {
printf(" ibat%du : %08X ibat%dl : %08X\n",
printf("IBAT%dU : 0x%08X, IBAT%dL : 0x%08X\n",
i, ppc_state.spr[528+i*2],
i, ppc_state.spr[529+i*2]);
}
if (!is_601) {
for (int i = 0; i < 4; i++) {
printf(" dbat%du : %08X dbat%dl : %08X\n",
printf("DBAT%dU : 0x%08X, DBAT%dL : 0x%08X\n",
i, ppc_state.spr[536+i*2],
i, ppc_state.spr[537+i*2]);
}
}
printf("\n");
printf(" sdr1 : %08X\n", ppc_state.spr[SPR::SDR1]);
printf("SDR1 : 0x%08X\n", ppc_state.spr[SPR::SDR1]);
printf("\nSegment registers:\n");
for (int i = 0; i < 16; i++) {
printf(" %ssr%d : %08X\n", (i < 10) ? " " : "", i, ppc_state.sr[i]);
printf("SR%-2d : 0x%08X\n", i, ppc_state.sr[i]);
}
}
@@ -455,18 +438,7 @@ static void mysig_handler(int signum)
}
#endif
static void delete_prompt() {
#ifndef _WIN32
// move up, carriage return (move to column 0), erase from cursor to end of line
cout << "\e[A\r\e[0K";
#endif
}
DppcDebugger::DppcDebugger() {
}
void DppcDebugger::enter_debugger() {
void enter_debugger() {
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
inst_string, inst_num_str, profile_name, sub_cmd;
uint32_t addr, inst_grab;
@@ -479,7 +451,6 @@ void DppcDebugger::enter_debugger() {
uint32_t next_addr_68k;
#endif
bool cmd_repeat;
int repeat_count = 0;
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
@@ -526,7 +497,6 @@ void DppcDebugger::enter_debugger() {
power_off_reason = po_entered_debugger;
}
if (!did_message) {
cout << endl;
cout << "Welcome to the DingusPPC command line debugger." << endl;
cout << "Please enter a command or 'help'." << endl << endl;
did_message = true;
@@ -574,10 +544,6 @@ void DppcDebugger::enter_debugger() {
cmd_repeat = cmd.empty() && !last_cmd.empty();
if (cmd_repeat) {
cmd = last_cmd;
repeat_count++;
}
else {
repeat_count = 1;
}
if (cmd == "help") {
cmd = "";
@@ -585,10 +551,6 @@ void DppcDebugger::enter_debugger() {
} else if (cmd == "quit") {
cmd = "";
break;
} else if (cmd == "restart") {
cmd = "";
power_on = false;
power_off_reason = po_restart;
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
@@ -611,9 +573,6 @@ void DppcDebugger::enter_debugger() {
} else {
print_gprs();
}
} else if (cmd == "fregs") {
cmd = "";
print_fprs();
} else if (cmd == "mregs") {
cmd = "";
print_mmu_regs();
@@ -661,34 +620,21 @@ void DppcDebugger::enter_debugger() {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
exec_single_68k();
exec_single_68k(0);
}
#endif
} else {
if (cmd_repeat) {
delete_prompt();
}
for (; --count >= 0;) {
addr = ppc_state.pc;
ppc_exec_single();
}
}
} else if (cmd == "next" || cmd == "ni") {
addr_str = "PC";
addr = static_cast<uint32_t>(get_reg(addr_str) + 4);
addr = (uint32_t)get_reg(addr_str) + 4;
ppc_exec_until(addr);
} else if (cmd == "until") {
if (cmd_repeat) {
delete_prompt();
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
}
else {
ss >> addr_str;
}
ss >> addr_str;
try {
addr = str2addr(addr_str);
if (context == 2) {
@@ -757,23 +703,21 @@ void DppcDebugger::enter_debugger() {
if (context == 2) {
#ifdef ENABLE_68K_DEBUGGER
if (cmd_repeat) {
delete_prompt();
addr = next_addr_68k;
}
else {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
addr = get_reg(addr_str) - 2;
}
next_addr_68k = disasm_68k(1, addr);
#endif
} else {
if (cmd_repeat) {
delete_prompt();
addr = next_addr_ppc;
}
else {
addr_str = "PC";
addr = static_cast<uint32_t>(get_reg(addr_str));
addr = (uint32_t)get_reg(addr_str);
}
next_addr_ppc = disasm(1, addr);
}
@@ -809,15 +753,9 @@ void DppcDebugger::enter_debugger() {
ss >> var_name;
std::istream::sentry se(ss); // skip white space
getline(ss, value); // get everything up to eol
if (ofnvram->init()) {
cout << " Cannot open NVRAM" << endl;
if (ofnvram->init())
continue;
}
if (!ofnvram->setenv(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
ofnvram->setenv(var_name, value);
#ifndef _WIN32
} else if (cmd == "nvedit") {
cmd = "";
+1 -17
View File
@@ -22,22 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DEBUGGER_H_
#define DEBUGGER_H_
#include <memory>
class DppcDebugger {
public:
static DppcDebugger* get_instance() {
if (!debugger_obj) {
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
};
void enter_debugger();
private:
inline static std::unique_ptr<DppcDebugger> debugger_obj{nullptr};
explicit DppcDebugger(); // private constructor to implement a singleton
};
void enter_debugger();
#endif // DEBUGGER_H_
-2
View File
@@ -8,10 +8,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.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/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
-100
View File
@@ -1,100 +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/>.
*/
/** @file Apple Desktop Bus AppleJack controller emulation. */
#include <devices/common/adb/adbapplejack.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <loguru.hpp>
AdbAppleJack::AdbAppleJack(std::string name) : AdbMouse(name, AdbMouse::TRACKBALL, 2, 7, 300) {
EventManager::get_instance()->add_gamepad_handler(this, &AdbAppleJack::event_handler);
}
void AdbAppleJack::event_handler(const GamepadEvent& event) {
uint32_t button_bit = 1 << event.button;
if (event.flags & GAMEPAD_EVENT_DOWN)
this->buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
else
this->buttons_changed = true;
}
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
}
bool AdbAppleJack::get_register_0() {
bool changed = this->triggers_changed || this->buttons_changed;
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
// AppleJack triggers always affect the mouse button bits.
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = ~this->buttons_state >> 8;
out_buf[3] = ~this->buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
}
return changed;
}
void AdbAppleJack::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case APPLEJACK_HANDLER_ID: // switch over to AppleJack protocol
this->dev_handler_id = in_data[1];
LOG_F(INFO, "%s: switched to AppleJack mode", this->name.c_str());
break;
default:
this->AdbMouse::set_register_3();
break;
}
}
static const DeviceDescription AdbAppleJack_Descriptor = {
AdbAppleJack::create, {}, {}
};
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
-60
View File
@@ -1,60 +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/>.
*/
/** @file Apple Desktop Bus AppleJack controller definitions. */
#ifndef ADB_APPLEJACK_H
#define ADB_APPLEJACK_H
#include <devices/common/adb/adbmouse.h>
#include <devices/common/hwcomponent.h>
#include <memory>
#include <string>
enum : uint8_t {
APPLEJACK_HANDLER_ID = 0x46,
};
class GamepadEvent;
class AdbAppleJack : public AdbMouse {
public:
AdbAppleJack(std::string name);
~AdbAppleJack() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<AdbAppleJack>(new AdbAppleJack("ADB-APPLEJACK"));
}
void reset() override;
void event_handler(const GamepadEvent& event);
bool get_register_0() override;
void set_register_3() override;
private:
uint32_t buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
#endif // ADB_APPLEJACK_H
+1 -31
View File
@@ -25,8 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/adb/adbdevice.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <sstream>
AdbBus::AdbBus(std::string name) {
this->set_name(name);
@@ -34,30 +32,6 @@ AdbBus::AdbBus(std::string name) {
this->devices.clear();
}
int AdbBus::device_postinit() {
std::string adb_device_list = GET_STR_PROP("adb_devices");
if (adb_device_list.empty())
return 0;
std::string adb_device;
std::istringstream adb_device_stream(adb_device_list);
while (getline(adb_device_stream, adb_device, ',')) {
std::string dev_name = "Adb" + adb_device;
if (dev_name == this->name)
continue; // don't register a second ADB bus
if (DeviceRegistry::device_registered(dev_name)) {
gMachineObj->add_device(dev_name, DeviceRegistry::get_descriptor(dev_name).m_create_func());
} else {
LOG_F(WARNING, "Unknown specified ADB device \"%s\"", adb_device.c_str());
}
}
return 0;
}
void AdbBus::register_device(AdbDevice* dev_obj) {
this->devices.push_back(dev_obj);
}
@@ -128,12 +102,8 @@ uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
return ADB_STAT_OK;
}
static const PropMap AdbBus_Properties = {
{"adb_devices", new StrProperty("Mouse,Keyboard")},
};
static const DeviceDescription AdbBus_Descriptor = {
AdbBus::create, {}, AdbBus_Properties
AdbBus::create, {}, {}
};
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
+1 -3
View File
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <vector>
constexpr auto ADB_MAX_DATA_SIZE = 8;
#define ADB_MAX_DATA_SIZE 8
/** ADB status. */
enum {
@@ -51,8 +51,6 @@ public:
return std::unique_ptr<AdbBus>(new AdbBus("ADB-BUS"));
}
int device_postinit() override;
void register_device(AdbDevice* dev_obj);
uint8_t process_command(const uint8_t* in_data, int data_size);
uint8_t get_output_count() { return this->output_count; };
+14 -29
View File
@@ -28,10 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memaccess.h>
#include <loguru.hpp>
AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution
) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution)
{
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset();
@@ -66,28 +63,17 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
bool AdbMouse::get_register_0() {
if (this->x_rel || this->y_rel || this->changed) {
uint8_t* p;
uint8_t* out_buf = this->host_obj->get_output_buf();
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
int num_bits, total_bits;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
num_bits = total_bits = 7;
} else {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
uint8_t buttons_state = ~this->buttons_state;
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
int bits = this->num_bits;
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
: this->device_class == TABLET ? this->y_abs : this->y_rel;
if (val < (-1 << (bits - 1)))
@@ -100,7 +86,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bits = 7;
while (bits_remaining > 0) {
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
*p = (val & ((1 << bits) - 1)) | (((this->buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -115,17 +101,20 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
this->changed = false;
uint8_t count = (uint8_t)(p - out_buf);
// should never happen, but check just in case
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
count = UINT8_MAX;
// if the mouse is in standard protocol then only send first 2 bytes
// BUGBUG: what should tablet do here?
if (this->device_class == MOUSE && this->dev_handler_id == 1)
count = 2;
this->host_obj->set_output_count(count);
return should_update;
return true;
}
return false;
}
bool AdbMouse::get_register_0() {
return get_register_0(this->buttons_state, false);
}
bool AdbMouse::get_register_1() {
uint8_t* out_buf = this->host_obj->get_output_buf();
// Identifier
@@ -167,10 +156,6 @@ void AdbMouse::set_register_3() {
}
}
uint8_t AdbMouse::get_buttons_state() const {
return this->buttons_state;
}
static const DeviceDescription AdbMouse_Descriptor = {
AdbMouse::create, {}, {}
};
+15 -24
View File
@@ -35,31 +35,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class MouseEvent;
class AdbMouse : public AdbDevice {
public:
enum DeviceClass {
TABLET = 0,
MOUSE = 1,
TRACKBALL = 2,
};
AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution);
public:
AdbMouse(std::string name);
~AdbMouse() = default;
static std::unique_ptr<HWComponent> create() {
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
return std::unique_ptr<AdbMouse>(
new AdbMouse("ADB-MOUSE", device_class, num_buttons, num_bits, resolution));
return std::unique_ptr<AdbMouse>(new AdbMouse("ADB-MOUSE"));
}
void reset() override;
@@ -69,10 +57,6 @@ enum DeviceClass {
bool get_register_1() override;
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons_state, bool force);
uint8_t get_buttons_state() const;
private:
int32_t x_rel = 0;
int32_t y_rel = 0;
@@ -80,10 +64,17 @@ private:
int32_t y_abs = 0;
uint8_t buttons_state = 0;
bool changed = false;
uint8_t device_class;
int num_buttons;
int num_bits;
uint16_t resolution;
#ifdef ABSOLUTE
uint8_t device_class = TABLET;
int num_buttons = 3;
int num_bits = 16;
uint16_t resolution = 72;
#else
uint8_t device_class = MOUSE;
int num_buttons = 3;
int num_bits = 10;
uint16_t resolution = 300;
#endif
};
#endif // ADB_MOUSE_H
+4 -6
View File
@@ -50,7 +50,7 @@ public:
virtual int perform_command() = 0;
int get_device_id() override { return this->my_dev_id; }
int get_device_id() override { return this->my_dev_id; };
void pdiag_callback() override {
this->r_error &= 0x7F;
@@ -62,7 +62,7 @@ public:
void update_intrq(uint8_t new_intrq_state);
void signal_data_ready();
bool has_data() const {
bool has_data() {
return data_ptr && xfer_cnt;
}
@@ -71,9 +71,7 @@ public:
}
protected:
bool is_selected() const {
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
}
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
void prepare_xfer(int xfer_size, int block_size);
@@ -84,7 +82,7 @@ protected:
IdeChannel* host_obj = nullptr;
// IDE aka task file registers
uint8_t r_error = 0;
uint8_t r_error;
uint8_t r_features;
uint8_t r_sect_count;
uint8_t r_sect_num;
-3
View File
@@ -120,7 +120,6 @@ enum ATA_Cmd : uint8_t {
NOP = 0x00,
ATAPI_SOFT_RESET = 0x08,
RECALIBRATE = 0x10,
ATAPI_COMMAND_MODE_SENSE6 = 0x1A,
READ_SECTOR = 0x20,
READ_SECTOR_NR = 0x21,
READ_LONG = 0x22,
@@ -129,7 +128,6 @@ enum ATA_Cmd : uint8_t {
WRITE_SECTOR_NR = 0x31,
WRITE_LONG = 0x32,
READ_VERIFY = 0x40,
ATAPI_COMMAND_GET_CONFIG = 0x46,
FORMAT_TRACKS = 0x50,
IDE_SEEK = 0x70,
DIAGNOSTICS = 0x90,
@@ -137,7 +135,6 @@ enum ATA_Cmd : uint8_t {
ATAPI_PACKET = 0xA0,
ATAPI_IDFY_DEV = 0xA1,
ATAPI_SERVICE = 0xA2,
ATAPI_READ_DVD_STRUCTURE = 0xAD,
READ_MULTIPLE = 0xC4,
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
+4 -5
View File
@@ -326,12 +326,11 @@ done:
heads, sectors);
}
static const PropMap AtaHardDisk_Properties = {
static const PropMap AtaHardDiskProperties = {
{"hdd_img", new StrProperty("")},
};
static const DeviceDescription AtaHardDisk_Descriptor = {
AtaHardDisk::create, {}, AtaHardDisk_Properties
};
static const DeviceDescription AtaHardDiskDescriptor =
{AtaHardDisk::create, {}, AtaHardDiskProperties};
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
REGISTER_DEVICE(AtaHardDisk, AtaHardDiskDescriptor);
+5 -5
View File
@@ -29,15 +29,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
constexpr auto ATA_HD_SEC_SIZE = 512;
constexpr auto SECTORS_PER_INT = 16;
#define ATA_HD_SEC_SIZE 512
#define SECTORS_PER_INT 16
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
constexpr auto ATA_BIOS_LIMIT = 16514064;
#define ATA_BIOS_LIMIT 16514064
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
constexpr auto REAL_CHS_LIMIT = 267382800;
#define REAL_CHS_LIMIT 267382800
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
constexpr auto CHS_LIMIT = 267386880;
#define CHS_LIMIT 267386880
class AtaHardDisk : public AtaBaseDevice
{
+7 -21
View File
@@ -132,19 +132,8 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_6:
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_10:
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
this->xfer_cnt = this->mode_sense_ex(this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
@@ -241,8 +230,7 @@ void AtapiCdrom::perform_packet_command() {
else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block =
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
}
@@ -253,8 +241,7 @@ void AtapiCdrom::perform_packet_command() {
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog + (disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count
}
@@ -384,12 +371,11 @@ void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->r_status |= ATA_Status::ERR;
}
static const PropMap AtapiCdrom_Properties = {
static const PropMap AtapiCdromProperties = {
{"cdr_img", new StrProperty("")},
};
static const DeviceDescription AtapiCdrom_Descriptor = {
AtapiCdrom::create, {}, AtapiCdrom_Properties
};
static const DeviceDescription AtapiCdromDescriptor =
{AtapiCdrom::create, {}, AtapiCdromProperties};
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
-238
View File
@@ -1,238 +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/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller emulation. */
#include <devices/common/ata/cmd646.h>
#include <devices/deviceregistry.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
CmdIdeCtrl::CmdIdeCtrl() : PCIDevice("cmd-ide") {
this->supports_types(HWCompType::PCI_DEV | HWCompType::IDE_HOST);
// set up PCI configuration space header
this->vendor_id = this->subsys_vndr = PCI_VENDOR_SILICON_IMAGE;
this->device_id = this->subsys_id = DEV_ID_CMD646;
this->class_rev = ((MY_DEV_CLASS | this->prog_if) << 8) | MY_REV_ID;
this->max_lat = 4;
this->min_gnt = 2;
this->irq_pin = 1;
this->bars_cfg[0] = 0xFFFFFFF9; // Command block I/O space, primary channel
this->bars_cfg[1] = 0xFFFFFFFD; // Control block I/O space, primary channel
this->bars_cfg[2] = 0xFFFFFFF9; // Command block I/O space, secondary channel
this->bars_cfg[3] = 0xFFFFFFFD; // Control block I/O space, secondary channel
this->bars_cfg[4] = 0xFFFFFFF1; // Bus master I/O space, both channels
this->finish_config_bars();
this->pci_notify_bar_change = [this](int bar_num) {
this->notify_bar_change(bar_num);
};
gMachineObj->add_device("CmdAta0", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta0")));
gMachineObj->add_device("CmdAta1", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta1")));
this->ch0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta0"));
this->ch1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta1"));
this->ch0->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta0 INTRQ updated to %d", intrq_state);
this->update_irq(0, intrq_state);
});
this->ch1->set_irq_callback([this](const uint8_t intrq_state) {
LOG_F(INFO, "CmdAta1 INTRQ updated to %d", intrq_state);
this->update_irq(1, intrq_state);
});
}
uint32_t CmdIdeCtrl::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
if (reg_offs < 64)
return PCIDevice::pci_cfg_read(reg_offs, details);
if (details.size != 1)
ABORT_F("%s: non-byte read from PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
return this->read_config_reg(reg_offs + details.offset);
LOG_F(WARNING, "%s: reading config reg at 0x%X", this->name.c_str(), reg_offs);
return 0;
}
void CmdIdeCtrl::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) {
if (reg_offs < 64) {
PCIDevice::pci_cfg_write(reg_offs, value, details);
return;
}
if (details.size != 1)
ABORT_F("%s: non-byte write to PCI config reg 0x%X", this->name.c_str(),
reg_offs + details.offset);
if (reg_offs < 112)
this->write_config_reg(reg_offs + details.offset, value);
else
LOG_F(WARNING, "%s: writing config reg at 0x%X", this->name.c_str(), reg_offs);
}
void CmdIdeCtrl::notify_bar_change(int bar_num) {
if (bar_num >= 0 && bar_num <= 4)
this->io_bases[bar_num] = this->bars[bar_num] & ~3;
}
bool CmdIdeCtrl::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
*res = 0;
if ((offset & ~7) == this->io_bases[0]) {
*res = this->ch0->read(offset & 7, size);
} else if ((offset & ~7) == this->io_bases[2]) {
*res = this->ch1->read(offset & 7, size);
} else if ((offset & ~3) == this->io_bases[1]) {
*res = this->ch0->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~3) == this->io_bases[3]) {
*res = this->ch1->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
*res = this->read_bus_master_reg(offset & 0xF);
} else {
*res = 0xFFFFFFFFUL;
return false;
}
return true;
}
bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
if ((offset & ~7) == this->io_bases[0]) {
this->ch0->write(offset & 7, value, size);
} else if ((offset & ~7) == this->io_bases[2]) {
this->ch1->write(offset & 7, value, size);
} else if ((offset & ~3) == this->io_bases[1]) {
this->ch0->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~3) == this->io_bases[3]) {
this->ch1->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
} else if ((offset & ~0xF) == this->io_bases[4]) {
this->write_bus_master_reg(offset & 0xF, value & 0xFFU);
} else
return false;
return true;
};
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
switch(reg_offset) {
case ARTTIM0:
return this->addr_setup_time_0;
case DRWTIM0:
return this->data_rw_time_0;
case ARTTIM1:
return this->addr_setup_time_1;
case DRWTIM1:
return this->data_rw_time_1;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_config_reg(uint32_t reg_offset, uint8_t val) {
switch(reg_offset) {
case ARTTIM0:
this->addr_setup_time_0 = val;
LOG_F(9, "%s: ARTTIM0 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM0:
this->data_rw_time_0 = val;
LOG_F(9, "%s: DRWTIM0 set to 0x%X", this->name.c_str(), val);
break;
case ARTTIM1:
this->addr_setup_time_1 = val;
LOG_F(9, "%s: ARTTIM1 set to 0x%X", this->name.c_str(), val);
break;
case DRWTIM1:
this->data_rw_time_1 = val;
LOG_F(9, "%s: DRWTIM1 set to 0x%X", this->name.c_str(), val);
break;
default:
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
uint8_t CmdIdeCtrl::read_bus_master_reg(const uint8_t reg_offset) {
switch(reg_offset) {
case MRDMODE:
return this->mrdmode;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
return 0;
}
void CmdIdeCtrl::write_bus_master_reg(const uint8_t reg_offset, const uint8_t val) {
switch(reg_offset) {
case MRDMODE:
if (val & BM_CH0_INT)
this->mrdmode &= ~BM_CH0_INT;
if (val & BM_CH1_INT)
this->mrdmode &= ~BM_CH1_INT;
this->mrdmode = (this->mrdmode & ~(BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT)) |
(val & (BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT));
LOG_F(INFO, "%s: MRDMODE set to 0x%X", this->name.c_str(), val);
if ((this->mrdmode & BM_CH0_INT) && !(this->mrdmode & BM_BLOCK_CH0_INT))
this->update_irq(0, 1);
if ((this->mrdmode & BM_CH1_INT) && !(this->mrdmode & BM_BLOCK_CH1_INT))
this->update_irq(1, 1);
break;
case UDIDETCR0:
this->udma_time_cr = val;
break;
default:
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
reg_offset);
}
}
void CmdIdeCtrl::update_irq(const int ch_num, const uint8_t irq_level) {
bool forward_irq = !(this->mrdmode & (ch_num ? BM_BLOCK_CH1_INT : BM_BLOCK_CH0_INT));
if (irq_level)
this->mrdmode |= ch_num ? BM_CH1_INT : BM_CH0_INT;
else
this->mrdmode &= ~(ch_num ? BM_CH1_INT : BM_CH0_INT);
if (!irq_level || forward_irq)
this->pci_interrupt(irq_level);
}
static const DeviceDescription CmdIde_Descriptor = {
CmdIdeCtrl::create, {}, {}
};
REGISTER_DEVICE(CmdAta, CmdIde_Descriptor);
-108
View File
@@ -1,108 +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/>.
*/
/** @file CMD646U2 PCI Ultra ATA controller definitions. */
#ifndef CMD646_IDE_H
#define CMD646_IDE_H
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ata/idechannel.h>
#include <devices/common/pci/pcidevice.h>
#include <memory>
constexpr auto DEV_ID_CMD646 = 0x646;
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master
constexpr auto MY_REV_ID = 7;
// Offset for converting addresses of the device control block registers
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
// to the addresses used in IdeChannel
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14;
/** CMD646 control/status registers. */
enum {
ARTTIM0 = 0x53,
DRWTIM0 = 0x54,
ARTTIM1 = 0x55,
DRWTIM1 = 0x56,
};
/** CMD646 bus master registers. */
enum {
MRDMODE = 1, // misnomer, contains interrupt control/status bits (CMD646U2 specific)
UDIDETCR0 = 3, // Ultra DMA timing control register (CMD646U2 specific)
};
/** Bit definitions for the MRDMODE register. */
enum {
BM_CH0_INT = 1 << 2,
BM_CH1_INT = 1 << 3,
BM_BLOCK_CH0_INT = 1 << 4,
BM_BLOCK_CH1_INT = 1 << 5,
};
class CmdIdeCtrl : public PCIDevice {
public:
CmdIdeCtrl();
~CmdIdeCtrl() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<CmdIdeCtrl>(new CmdIdeCtrl());
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) override;
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) override;
private:
void notify_bar_change(int bar_num);
uint8_t read_config_reg(uint32_t reg_offset);
void write_config_reg(uint32_t reg_offset, uint8_t val);
uint8_t read_bus_master_reg(const uint8_t reg_offset);
void write_bus_master_reg(const uint8_t reg_offset, const uint8_t val);
void update_irq(const int ch_num, const uint8_t irq_level);
// on reset, programming interface defaults to
// "both channels operating in native mode"
uint8_t prog_if = 0x0F;
uint32_t io_bases[5] = {};
IdeChannel *ch0 = nullptr;
IdeChannel *ch1 = nullptr;
// unknown default, set it to 2 clocks (60 ns)
uint8_t addr_setup_time_0 = 0x40; // address setup time for drive 0
uint8_t addr_setup_time_1 = 0x40; // address setup time for drive 1
uint8_t data_rw_time_0 = 0x00; // data read/write time for drive 0
uint8_t data_rw_time_1 = 0x00; // data read/write time for drive 1
uint8_t mrdmode = 0;
uint8_t udma_time_cr = 0;
};
#endif // CMD646_IDE_H
+1 -1
View File
@@ -95,7 +95,7 @@ private:
// interrupt stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
};
#endif // IDE_CHANNEL_H
+18 -57
View File
@@ -97,7 +97,6 @@ uint8_t DMAChannel::interpret_cmd() {
switch (this->cur_cmd) {
case DBDMA_Cmd::OUTPUT_MORE:
case DBDMA_Cmd::OUTPUT_LAST:
this->xfer_to_device();
if (this->out_cb)
this->out_cb();
break;
@@ -132,7 +131,6 @@ uint8_t DMAChannel::interpret_cmd() {
case DBDMA_Cmd::STOP:
this->ch_stat &= ~CH_STAT_ACTIVE;
this->cmd_in_progress = false;
this->finish_cmd();
break;
default:
LOG_F(ERROR, "%s: Unsupported DMA command 0x%X", this->get_name().c_str(),
@@ -172,7 +170,9 @@ void DMAChannel::finish_cmd() {
return;
}
this->ch_stat &= ~CH_STAT_BT;
if (res.is_writable)
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
this->ch_stat &= ~CH_STAT_FLUSH;
// react to cmd.b (branch) bits
if (cmd_desc[2] & 0xC) {
@@ -187,29 +187,21 @@ void DMAChannel::finish_cmd() {
if (cond) {
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
branch_taken = true;
this->ch_stat |= CH_STAT_BT;
}
}
if (res.is_writable)
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
this->update_irq();
}
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
this->res_count = 0;
}
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
if (!branch_taken)
this->cmd_ptr += 16;
if (this->cur_cmd < DBDMA_Cmd::STOP) {
this->update_irq();
}
this->cmd_in_progress = false;
}
@@ -301,27 +293,24 @@ void DMAChannel::update_irq() {
}
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
uint32_t result = 0;
if (size != 4) {
ABORT_F("%s: non-DWORD read from a DMA channel not supported",
this->get_name().c_str());
}
switch (offset & ~3) {
switch (offset) {
case DMAReg::CH_CTRL:
result = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
break;
return 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
case DMAReg::CH_STAT:
result = this->ch_stat;
break;
return BYTESWAP_32(this->ch_stat);
case DMAReg::CMD_PTR_LO:
result = this->cmd_ptr;
break;
return BYTESWAP_32(this->cmd_ptr);
default:
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
this->get_name().c_str(), offset);
}
if ((offset & 3) || size != 4)
return BYTESWAP_SIZED(result >> ((offset & 3) * 8), size);
else
return BYTESWAP_32(result);
return 0;
}
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
@@ -338,7 +327,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
switch (offset) {
case DMAReg::CH_CTRL:
mask = value >> 16;
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~(mask & 0xC0FF));
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
LOG_F(9, "%s: New ChannelStatus value = 0x%X", this->get_name().c_str(), new_stat);
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
@@ -376,13 +365,9 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
this->ch_stat = new_stat;
}
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
if (new_stat & CH_STAT_WAKE) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
} else {
LOG_F(ERROR, "%s: Attempt to clear wake status bit 0x%04x", this->get_name().c_str(), CH_STAT_WAKE);
}
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
if (new_stat & CH_STAT_PAUSE) {
new_stat &= ~CH_STAT_ACTIVE;
@@ -435,20 +420,6 @@ void DMAChannel::xfer_from_device() {
this->interpret_cmd();
}
void DMAChannel::xfer_to_device() {
if (this->dev_obj == nullptr)
return;
this->xfer_dir = DMA_DIR_TO_DEV;
if (!this->dev_obj->xfer_to(this->queue_data, this->queue_len)) {
this->queue_len = 0;
this->finish_cmd();
}
this->interpret_cmd();
}
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
{
*avail_len = 0;
@@ -572,7 +543,6 @@ void DMAChannel::start() {
if (this->ch_stat & CH_STAT_PAUSE) {
LOG_F(WARNING, "%s: Cannot start DMA channel, PAUSE bit is set",
this->get_name().c_str());
this->ch_stat &= ~CH_STAT_ACTIVE; // TODO: Test this in Open Firmware.
return;
}
@@ -601,15 +571,6 @@ void DMAChannel::resume() {
}
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
// some DBDMA programs contain commands that don't transfer data
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
// We thus interprete the DBDMA program until a data transfer between
// a device and memory is queued or the channel becomes idle/dead.
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
(this->ch_stat & CH_STAT_ACTIVE)) {
this->interpret_cmd();
}
}
void DMAChannel::abort() {
+2 -3
View File
@@ -123,7 +123,7 @@ public:
void end_pull_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->irq_id = irq_id;
};
@@ -135,7 +135,6 @@ protected:
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
void update_irq();
void xfer_from_device();
void xfer_to_device();
void start(void);
void resume(void);
@@ -163,7 +162,7 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
};
#endif // DB_DMA_H
-1
View File
@@ -99,7 +99,6 @@ public:
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
void notify(DmaMsg msg) {};
virtual int xfer_from(uint8_t *buf, int len) { return len; };
virtual int xfer_to(uint8_t *buf, int len) { return len; };
protected:
DmaChannel* channel_obj = nullptr;
+5 -27
View File
@@ -30,11 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enum IntSrc : uint32_t {
INT_UNKNOWN = 0,
VIA_CUDA,
VIA2,
SCSI_MESH,
SCSI_CURIO,
SWIM3,
ESCC,
SCCA,
SCCB,
ETHERNET,
@@ -60,7 +58,6 @@ enum IntSrc : uint32_t {
PLANB,
VCI,
PLATINUM,
DMA_ALL,
DMA_SCSI_MESH,
DMA_SCSI_CURIO,
DMA_SWIM3,
@@ -74,25 +71,6 @@ enum IntSrc : uint32_t {
DMA_DAVBUS_Rx,
DMA_ETHERNET_Tx,
DMA_ETHERNET_Rx,
FIREWIRE,
PCI_J12,
PCI_J11,
PCI_J10,
PCI_J9,
ATA,
USB,
PIPPIN_E,
PIPPIN_F,
ZIVA,
PCI_CARDBUS,
MEDIA_BAY,
SLOT_ALL,
SLOT_0,
SLOT_1,
SLOT_2,
SLOT_PDS,
SLOT_VDS,
VBL,
};
/** Base class for interrupt controllers. */
@@ -102,17 +80,17 @@ public:
virtual ~InterruptCtrl() = default;
// register interrupt sources for a device
virtual uint64_t register_dev_int(IntSrc src_id) = 0;
virtual uint64_t register_dma_int(IntSrc src_id) = 0;
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt
virtual void ack_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
};
typedef struct {
InterruptCtrl *int_ctrl_obj;
uint64_t irq_id;
uint32_t irq_id;
} IntDetails;
#endif // HW_INTERRUPT_H
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters.
*/
#include <devices/common/clockgen/athens.h>
#include <devices/common/i2c/athens.h>
#include <loguru.hpp>
#include <algorithm>
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
constexpr auto ATHENS_NUM_REGS = 8;
#define ATHENS_NUM_REGS 8
/** Default external crystal oscillator frequency. */
constexpr auto ATHENS_XTAL = 31334400.0f;
+3 -5
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(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
#define I2C_H
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept>
#include <cstring>
#include <string>
#include <loguru.hpp>
/** Base class for I2C devices */
class I2CDevice {
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file SAA7187 Digital video encoder emulation. */
#include <devices/video/saa7187.h>
#include <devices/common/i2c/saa7187.h>
#include <loguru.hpp>
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr)
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:
+0 uint16_t signature = 0xA55A
+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
-5
View File
@@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cpu/ppc/ppcemu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nvram.h>
#include <devices/deviceregistry.h>
@@ -82,10 +81,6 @@ void NVram::init() {
}
void NVram::save() {
if (is_deterministic) {
LOG_F(INFO, "Skipping NVRAM write to \"%s\" in deterministic mode", this->file_name.c_str());
return;
}
ofstream f(this->file_name, ios::out | ios::binary);
/* write file identification */
+7 -6
View File
@@ -322,9 +322,6 @@ bool OfConfigChrp::validate()
bool wip = true;
bool of_part_found = false;
if (this->nvram_obj == nullptr)
return false;
// search the entire 8KB NVRAM for CHRP OF config partition.
// Bail out if an unknown partition or free space is encountered.
// Skip over known partitions.
@@ -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())
return false;
return;
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
return this->cfg_impl->set_var(var_name, value);
if (!this->cfg_impl->set_var(var_name, value)) {
cout << " Please try again" << endl;
} else {
cout << " ok" << endl; // mimic Forth
}
}
+4 -4
View File
@@ -33,9 +33,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class NVram;
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
constexpr auto OF_NVRAM_OFFSET = 0x1800;
constexpr auto OF_NVRAM_SIG = 0x1275;
constexpr auto OF_CFG_SIZE = 0x800;
#define OF_NVRAM_OFFSET 0x1800
#define OF_NVRAM_SIG 0x1275
#define OF_CFG_SIZE 0x800
// OF Variable types
enum {
@@ -134,7 +134,7 @@ public:
int init();
void printenv();
bool setenv(std::string var_name, std::string value);
void setenv(std::string var_name, std::string value);
protected:
bool open_container();
+47 -86
View File
@@ -122,7 +122,7 @@ void BanditPciDevice::verbose_address_space()
return;
}
LOG_F(INFO, "%s address spaces:", this->get_name().c_str());
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
// verbose coarse aka 256MB memory regions
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
@@ -143,21 +143,8 @@ void BanditPciDevice::verbose_address_space()
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
{
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
return pci_io_read_broadcast(offset & 0x007FFFFF, size);
case 4:
case 5:
// CONFIG_ADDR
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
case 6:
// CONFIG_DATA
switch (offset >> 22) {
case 3: // CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
@@ -173,46 +160,18 @@ uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
LOG_READ_NON_EXISTENT_PCI_DEVICE();
return 0xFFFFFFFFUL; // PCI spec §6.1
case 7:
// Interrupt
LOG_F(ERROR, "%s: Interrupt Acknowledge Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
break;
case 2: // CONFIG_ADDR
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
default: // I/O space
return pci_io_read_broadcast(offset, size);
}
return 0;
}
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
{
switch (offset >> 21) {
case 0:
case 1:
case 2:
case 3:
// I/O space
pci_io_write_broadcast(offset & 0x007FFFFF, size, value);
break;
case 4:
case 5:
// CONFIG_ADDR
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
break;
case 6:
// CONFIG_DATA
switch (offset >> 22) {
case 3: // CONFIG_DATA
int bus_num, dev_num, fun_num;
uint8_t reg_offs;
AccessDetails details;
@@ -233,23 +192,12 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
break;
case 7:
// Special
LOG_F(ERROR, "%s: Special Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
case 2: // CONFIG_ADDR
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
// 24-Bit Memory Address
case 15:
// 24-Bit Memory Address or VGA Device Access
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
break;
default: // I/O space
pci_io_write_broadcast(offset, size, value);
}
}
@@ -287,7 +235,32 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
}
int BanditHost::device_postinit() {
return this->pcihost_device_postinit();
std::string pci_dev_name;
static const std::map<std::string, int> pci_slots1 = {
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
};
static const std::map<std::string, int> pci_slots2 = {
{"pci_D2", DEV_FUN(0xD,0)}, {"pci_E2", DEV_FUN(0xE,0)}, {"pci_F2", DEV_FUN(0xF,0)}
};
static const std::map<std::string, int> vci_slots = {
{"vci_D", DEV_FUN(0xD,0)}, {"vci_E", DEV_FUN(0xE,0)}, {"vci_F", DEV_FUN(0xF,0)}
};
for (auto& slot :
this->bridge_num == 0 ? vci_slots :
this->bridge_num == 1 ? pci_slots1 :
this->bridge_num == 2 ? pci_slots2 :
pci_slots1
) {
pci_dev_name = GET_STR_PROP(slot.first);
if (!pci_dev_name.empty()) {
this->attach_pci_device(pci_dev_name, slot.second);
}
}
return 0;
}
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
@@ -304,15 +277,14 @@ Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
// add memory mapped I/O region for Bandit control registers
// This region has the following layout:
// base_addr + 0x00000000 --> I/O space
// base_addr + 0x00800000 --> CONFIG_ADDR
// base_addr + 0x00C00000 --> CONFIG_DATA
// base_addr + 0x00E00000 --> Special(W)/Interrupt(R)
// base_addr + 0x01000000 --> pass-through memory space ; grandcentral exists here for pci1
mem_ctrl->add_mmio_region(base_addr, bridge_num == 1 ? 0x01000000 : 0x02000000, this);
// base_addr + 0x000000 --> I/O space
// base_addr + 0x800000 --> CONFIG_ADDR
// base_addr + 0xC00000 --> CONFIG_DATA
// base_addr + 0x1000000 --> pass-through memory space (not included below)
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
// connnect Bandit PCI device
this->my_pci_device = std::unique_ptr<BanditPciDevice>(
this->my_pci_device = unique_ptr<BanditPciDevice>(
new BanditPciDevice(bridge_num, name, dev_id, rev)
);
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
@@ -374,18 +346,7 @@ static const PropMap Chaos_Properties = {
new StrProperty("")},
{"vci_E",
new StrProperty("")},
};
static const PropMap PsxPci1_Properties = {
{"pci_A1",
new StrProperty("")},
{"pci_B1",
new StrProperty("")},
{"pci_C1",
new StrProperty("")},
{"pci_E1",
new StrProperty("")},
{"pci_F1",
{"vci_F",
new StrProperty("")},
};
@@ -398,7 +359,7 @@ static const DeviceDescription Bandit2_Descriptor = {
};
static const DeviceDescription PsxPci1_Descriptor = {
Bandit::create_psx_first, {}, PsxPci1_Properties
Bandit::create_psx_first, {}, Bandit1_Properties
};
static const DeviceDescription Chaos_Descriptor = {
+9 -6
View File
@@ -46,8 +46,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
constexpr auto BANDIT_DEV = 11; // Bandit's own device number
constexpr auto BANDIT_CAR_TYPE = 1 << 0; // Bandit config address type bit
#define BANDIT_DEV (11) // Bandit's own device number
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
/* Convenient macros for parsing CONFIG_ADDR fields. */
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
@@ -73,11 +73,14 @@ class BanditHost : public PCIHost, public MMIODevice {
public:
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
// MMIODevice methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
// PCIHost methods
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
int device_postinit() override;
// MMIODevice methods
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);
int device_postinit();
protected:
uint32_t config_addr;
-20
View File
@@ -86,28 +86,8 @@ void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetail
}
}
static const PropMap Dec21154Yosemite_Properties = {
{"pci_FireWire",
new StrProperty("")},
{"pci_UltraATA",
new StrProperty("")},
{"pci_J11",
new StrProperty("")},
{"pci_J10",
new StrProperty("")},
{"pci_J9",
new StrProperty("")},
{"pci_USB",
new StrProperty("")},
};
static const DeviceDescription Dec21154_Descriptor = {
DecPciBridge::create, {}, {}
};
static const DeviceDescription Dec21154Yosemite_Descriptor = {
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
};
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
REGISTER_DEVICE(Dec21154Yosemite, Dec21154Yosemite_Descriptor);
-4
View File
@@ -44,10 +44,6 @@ public:
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154"));
}
static std::unique_ptr<HWComponent> create_yosemite() {
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154Yosemite"));
}
// PCIDevice methods
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
+9 -28
View File
@@ -32,6 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
{
this->name = name;
this->pci_name = name;
this->hdr_type = hdr_type;
this->num_bars = num_bars;
@@ -161,17 +162,17 @@ int PCIBase::attach_exp_rom_image(const std::string img_path)
if (exp_rom_image_size == this->exp_rom_size) {
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
this->get_name().c_str(), this->exp_rom_size);
this->pci_name.c_str(), this->exp_rom_size);
}
else {
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
this->get_name().c_str(), (int)exp_rom_image_size, this->exp_rom_size);
this->pci_name.c_str(), (int)exp_rom_image_size, this->exp_rom_size);
}
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "%s: %s", this->get_name().c_str(), exc.what());
LOG_F(ERROR, "%s: %s", this->pci_name.c_str(), exc.what());
result = -1;
}
@@ -191,8 +192,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->pci_name.c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
}
break;
@@ -201,8 +201,7 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->pci_name.c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
}
break;
@@ -240,11 +239,11 @@ void PCIBase::finish_config_bars()
case 2:
if (bar_num >= num_bars - 1) {
ABORT_F("%s: BAR %d cannot be 64-bit",
this->get_name().c_str(), bar_num);
this->pci_name.c_str(), bar_num);
}
else if (this->bars_cfg[bar_num+1] == 0) {
ABORT_F("%s: 64-bit BAR %d has zero for upper 32 bits",
this->get_name().c_str(), bar_num);
this->pci_name.c_str(), bar_num);
}
else {
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
@@ -253,7 +252,7 @@ void PCIBase::finish_config_bars()
break;
default:
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
this->get_name().c_str(), pci_space_type, bar_num);
this->pci_name.c_str(), pci_space_type, bar_num);
} // switch pci_space_type
}
} // for bar_num
@@ -303,21 +302,3 @@ void PCIBase::pci_wr_exp_rom_bar(uint32_t data)
}
}
}
void PCIBase::pci_interrupt(uint8_t irq_line_state) {
if (!(this->command & 0x0400)) {
if (!this->int_details.int_ctrl_obj)
this->host_instance->register_pci_int(this);
if (this->int_details.int_ctrl_obj && this->int_details.irq_id)
this->int_details.int_ctrl_obj->ack_int(this->int_details.irq_id, irq_line_state);
else
LOG_F(ERROR, "Unhandled interrupt from device %s", this->get_name().c_str());
/* A pci device should set the interrupt status bit when an interrupt occurs
* and it should clear the interrupt status bit when its interrupt bits are cleared.
* The interrupt status bit is new to PCI Local Bus Specification Revision 2.3
* and Power Macs use PCI Local Bus Specification Revision 2.0. Some PCI cards
* might not implement this bit.
*/
//this->status |= 0x0008;
}
}
+9 -16
View File
@@ -47,19 +47,16 @@ enum {
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2)
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
// Bridge Control (Type 1 and 2)
// Int_Pin and Int_Line registers (type 0, 1, and 2)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0); Bridge Control (Type 1 and 2); Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
enum {
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_SILICON_IMAGE = 0x1095,
PCI_VENDOR_NVIDIA = 0x10DE,
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_NVIDIA = 0x10DE,
};
/** PCI BAR types */
@@ -79,7 +76,6 @@ typedef struct {
} BarConfig;
class PCIBase : public MMIODevice {
friend class PCIHost;
public:
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
virtual ~PCIBase() = default;
@@ -129,12 +125,10 @@ public:
this->irq_pin = irq_pin;
}
virtual void set_int_details(IntDetails &int_details) {
this->int_details = int_details;
virtual void pci_interrupt(uint8_t irq_line_state) {
this->host_instance->pci_interrupt(irq_line_state, this);
}
virtual void pci_interrupt(uint8_t irq_line_state);
// MMIODevice methods
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
@@ -147,6 +141,7 @@ protected:
void map_exp_rom_mem();
void unmap_exp_rom_mem();
std::string pci_name; // human-readable device name
PCIHost* host_instance; // host bridge instance to call back
// PCI configuration space state (type 0, 1, and 2)
@@ -179,8 +174,6 @@ protected:
// 0 = not writable; 1 = bit is enabled in command register
uint16_t command_cfg = 0xffff - (1<<3) - (1<<7); // disable: special cycles and stepping
IntDetails int_details = { 0 };
};
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
-4
View File
@@ -85,7 +85,3 @@ void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetai
return PCIBase::pci_cfg_write(reg_offs, value, details);
}
}
int PCIBridgeBase::device_postinit() {
return this->pcihost_device_postinit();
}
-3
View File
@@ -68,9 +68,6 @@ public:
std::function<uint16_t()> pci_rd_bridge_control;
std::function<void(uint16_t)> pci_wr_bridge_control;
// HWComponent methods
virtual int device_postinit();
protected:
// PCI configuration space state
uint8_t primary_bus = 0;
+10 -54
View File
@@ -30,7 +30,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
#include <cinttypes>
#include <cpu/ppc/ppcemu.h>
bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
{
@@ -76,18 +75,15 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
if (!this->dev_map.count(dev_fun_num)) {
return;
}
auto dev_instance = this->dev_map[dev_fun_num];
PCIBase* dev_instance = this->dev_map[dev_fun_num];
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
// FIXME: need destructors to remove memory regions and downstream devices.
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs "
"a working destructor to unregister memory and downstream devices etc.)",
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor)",
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
);
this->dev_map.erase(dev_fun_num);
gMachineObj->remove_device(dev_instance); // calls destructor of dev_instance since it is a unique_ptr in the device_map.
delete dev_instance;
}
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
@@ -123,8 +119,9 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
}
// attempt to create device object
MachineFactory::register_device_settings(dev_name);
auto desc = DeviceRegistry::get_descriptor(dev_name);
map<string, string> settings;
MachineFactory::get_device_settings(desc, settings);
auto dev_obj = desc.m_create_func();
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
@@ -141,7 +138,6 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
gMachineObj->add_device(dev_name + dev_suffix, std::move(dev_obj));
PCIBase *dev = dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
dev->set_name(dev->get_name() + dev_suffix);
// register device with the PCI host
this->pci_register_device(slot_id, dev);
@@ -149,16 +145,7 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
return dev;
}
InterruptCtrl *PCIHost::get_interrupt_controller() {
if (!this->int_ctrl) {
InterruptCtrl *int_ctrl_obj =
dynamic_cast<InterruptCtrl*>(gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->int_ctrl = int_ctrl_obj;
}
return this->int_ctrl;
}
bool PCIHost::register_pci_int(PCIBase* dev_instance) {
IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
bool dev_found = false;
int dev_fun_num = 0;
@@ -173,24 +160,10 @@ bool PCIHost::register_pci_int(PCIBase* dev_instance) {
ABORT_F("register_pci_int: requested device not found");
for (auto& irq : this->my_irq_map) {
if (irq.dev_fun_num == dev_fun_num) {
IntDetails new_int_detail;
new_int_detail.int_ctrl_obj = this->get_interrupt_controller();
if (new_int_detail.int_ctrl_obj && irq.int_src)
new_int_detail.irq_id = new_int_detail.int_ctrl_obj->register_dev_int(irq.int_src);
dev_instance->set_int_details(new_int_detail);
return true;
}
if (irq.dev_fun_num == dev_fun_num)
return {this->int_ctrl, irq.irq_id};
}
PCIBridgeBase *self = dynamic_cast<PCIBridgeBase*>(this);
if (self) {
if (!self->int_details.int_ctrl_obj)
self->host_instance->register_pci_int(self);
dev_instance->set_int_details(self->int_details);
return true;
}
return false;
ABORT_F("register_pci_int: no IRQ map for device 0x%X", dev_fun_num);
}
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
@@ -229,8 +202,7 @@ uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
SIZE_ARG(size)
);
// machine check exception (DEFAULT CATCH!, code=FFF00200)
ppc_exception_handler(Except_Type::EXC_MACHINE_CHECK, 0);
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
return 0;
}
@@ -273,19 +245,3 @@ PCIBase *PCIHost::pci_find_device(uint8_t dev_num, uint8_t fun_num)
}
return NULL;
}
int PCIHost::pcihost_device_postinit()
{
std::string pci_dev_name;
for (auto& slot : this->my_irq_map) {
if (slot.slot_name) {
pci_dev_name = GET_STR_PROP(slot.slot_name);
if (!pci_dev_name.empty()) {
this->attach_pci_device(pci_dev_name, slot.dev_fun_num, std::string("@") + slot.slot_name);
}
}
}
return 0;
}
+4 -4
View File
@@ -53,7 +53,7 @@ typedef struct AccessDetails {
typedef struct {
const char * slot_name;
int dev_fun_num;
IntSrc int_src;
uint32_t irq_id;
} PciIrqMap;
class PCIBase;
@@ -86,16 +86,16 @@ public:
virtual PCIBase *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
virtual PCIBase *pci_find_device(uint8_t dev_num, uint8_t fun_num);
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
this->my_irq_map = irq_map;
};
virtual int pcihost_device_postinit();
virtual bool register_pci_int(PCIBase* dev_instance);
virtual IntDetails register_pci_int(PCIBase* dev_instance);
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
this->int_ctrl = int_ctrl_obj;
};
virtual InterruptCtrl *get_interrupt_controller();
protected:
std::unordered_map<int, PCIBase*> dev_map;
+2 -69
View File
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
@@ -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)
{
@@ -751,73 +751,6 @@ void Sc53C94::dma_stop()
}
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
if (len > this->xfer_count + this->data_fifo_pos)
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
if (this->data_fifo_pos) {
int fifo_bytes = std::min(this->data_fifo_pos, len);
std::memcpy(buf, this->data_fifo, fifo_bytes);
this->data_fifo_pos -= fifo_bytes;
this->xfer_count -= fifo_bytes;
len -= fifo_bytes;
buf += fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
}
}
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
this->xfer_count = 0;
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
return 0;
}
return len;
}
int Sc53C94::xfer_to(uint8_t *buf, int len) {
if (!this->xfer_count)
return len;
// Being in the DATA_OUT phase means that we're about to move
// a big chunk of data. The real device uses its FIFO as buffer.
// For simplicity, the code below transfers the whole chunk at once.
// This can be broken into smaller chunks later if desired.
if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
if (this->bus_obj->push_data(this->target_id, buf, len)) {
this->xfer_count -= len;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
len = 0;
} else
LOG_F(WARNING, "%s: xfer_to failed to transfer data", this->name.c_str());
}
if (this->xfer_count) {
// fill in the data FIFO first
uint32_t fifo_bytes = std::min(len, DATA_FIFO_MAX - this->data_fifo_pos);
std::memcpy(&this->data_fifo[this->data_fifo_pos], buf, fifo_bytes);
len -= fifo_bytes;
this->data_fifo_pos += fifo_bytes;
this->xfer_count -= fifo_bytes;
if (!this->xfer_count) {
this->status |= STAT_TC; // signal zero transfer count
this->sequencer();
}
}
return len;
}
static const PropMap Sc53C94_properties = {
{"hdd_img", new StrProperty("")},
{"cdr_img", new StrProperty("")},
+2 -6
View File
@@ -187,7 +187,7 @@ typedef struct {
typedef std::function<void(const uint8_t drq_state)> DrqCb;
class Sc53C94 : public ScsiDevice, public DmaDevice {
class Sc53C94 : public ScsiDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
~Sc53C94() = default;
@@ -235,10 +235,6 @@ public:
int send_data(uint8_t* dst_ptr, int count);
void process_command() {};
// DmaChannel methods
int xfer_from(uint8_t *buf, int len); // Must be marked override!
int xfer_to(uint8_t *buf, int len); // Must be marked override!
protected:
void reset_device();
void update_command_reg(uint8_t cmd);
@@ -290,7 +286,7 @@ private:
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
// DMA related stuff
+10 -19
View File
@@ -156,14 +156,14 @@ enum ScsiError : int {
};
/** Standard SCSI bus timing values measured in ns. */
constexpr uint64_t BUS_SETTLE_DELAY = 400;
constexpr uint64_t BUS_FREE_DELAY = 800;
constexpr uint64_t BUS_CLEAR_DELAY = 800;
constexpr uint64_t ARB_DELAY = 2400;
constexpr uint64_t SEL_ABORT_TIME = 200000;
constexpr uint64_t SEL_TIME_OUT = 250000000;
#define BUS_SETTLE_DELAY 400
#define BUS_FREE_DELAY 800
#define BUS_CLEAR_DELAY 800
#define ARB_DELAY 2400
#define SEL_ABORT_TIME 200000
#define SEL_TIME_OUT 250000000
constexpr auto SCSI_MAX_DEVS = 8;
#define SCSI_MAX_DEVS 8
class ScsiBus;
@@ -246,18 +246,9 @@ public:
// low-level state management
void register_device(int id, ScsiDevice* dev_obj);
int current_phase() const {
return this->cur_phase;
}
int get_initiator_id() const {
return this->initiator_id;
}
int get_target_id() const {
return this->target_id;
}
int current_phase() { return this->cur_phase; };
int get_initiator_id() { return this->initiator_id; };
int get_target_id() { return this->target_id; };
// reading/writing control lines
void assert_ctrl_line(int id, uint16_t mask);
+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)
{
if (!(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
return;
}
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS,
"%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
uint16_t new_state = 0xFFFFU & mask;
@@ -95,9 +93,7 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
{
if (!(id >= 0 && id < SCSI_MAX_DEVS)) {
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
}
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
uint16_t new_state = 0;
+2 -2
View File
@@ -58,7 +58,7 @@ enum : int {
SEL_TIMEOUT,
};
constexpr auto DATA_FIFO_DEPTH = 16;
#define DATA_FIFO_DEPTH 16
class ScsiBusController : public ScsiDevice, public DmaDevice {
public:
@@ -113,7 +113,7 @@ protected:
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
uint8_t int_mask = 0;
uint8_t int_stat = 0;
+8 -24
View File
@@ -34,9 +34,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
this->data_buf_size = 1 << 22;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
void ScsiHardDisk::insert_image(std::string filename) {
@@ -109,6 +106,7 @@ void ScsiHardDisk::process_command() {
case ScsiCommand::WRITE_10:
lba = READ_DWORD_BE_U(&cmd[2]);
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
this->switch_phase(ScsiPhase::DATA_OUT);
break;
case ScsiCommand::READ_BUFFER:
read_buffer();
@@ -226,8 +224,7 @@ void ScsiHardDisk::inquiry() {
int lun;
if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7",
this->name.c_str(), alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(), alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
@@ -459,19 +456,14 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
return;
uint32_t transfer_size = transfer_len;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
std::memset(this->data_buf, 0, transfer_size);
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size);
@@ -483,18 +475,12 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
if (transfer_size > this->data_buf_size) {
while (transfer_size > this->data_buf_size)
this->data_buf_size <<= 1;
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
this->data_buf = this->data_buf_obj.get();
}
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size;
@@ -502,8 +488,6 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
this->post_xfer_action = [this, device_offset]() {
this->disk_img.write(this->data_buf, device_offset, this->incoming_size);
};
this->switch_phase(ScsiPhase::DATA_OUT);
}
void ScsiHardDisk::read_buffer() {
+2 -4
View File
@@ -66,15 +66,13 @@ private:
bool eject_allowed = true;
int bytes_out = 0;
std::unique_ptr<uint8_t[]> data_buf_obj = nullptr;
uint8_t* data_buf = nullptr;
uint32_t data_buf_size = 0;
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
uint8_t error = ScsiError::NO_ERROR;
uint8_t msg_code = 0;
//inquiry info
char vendor_info[8] = {'Q', 'U', 'A', 'N', 'T', 'U', 'M', '\0'};
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
char rev_info[4] = {'d', 'i', '0', '1'};
};
+3 -18
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
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;
}
@@ -751,22 +751,7 @@ void ViaCuda::pseudo_command() {
}
uint32_t ViaCuda::calc_real_time() {
std::chrono::time_point<std::chrono::system_clock> end;
if (is_deterministic) {
// March 24, 2001 was the public release date of Mac OS X.
std::tm tm = {
.tm_sec = 0,
.tm_min = 0,
.tm_hour = 12,
.tm_mday = 24,
.tm_mon = 3 - 1,
.tm_year = 2001 - 1900,
.tm_isdst = 0
};
end = std::chrono::system_clock::from_time_t(std::mktime(&tm));
} else {
end = std::chrono::system_clock::now();
}
auto end = std::chrono::system_clock::now();
auto elapsed_systemclock = end - this->mac_epoch;
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
return uint32_t(elapsed_seconds.count());
@@ -851,7 +836,7 @@ void ViaCuda::i2c_comb_transaction(
}
static const vector<string> Cuda_Subdevices = {
"AdbBus"
"AdbBus", "AdbMouse", "AdbKeyboard"
};
static const DeviceDescription ViaCuda_Descriptor = {
+8 -8
View File
@@ -53,7 +53,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class AdbBus;
class InterruptCtrl;
constexpr auto VIA_CLOCK_HZ = 783360;
#define VIA_CLOCK_HZ 783360
/** VIA register offsets. */
enum {
@@ -143,16 +143,16 @@ enum {
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
};
constexpr auto CUDA_IN_BUF_SIZE = 256;
#define CUDA_IN_BUF_SIZE 256
/** PRAM addresses within Cuda's internal memory. */
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW
#define CUDA_PRAM_START 0x100 // starting address of PRAM
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
/** Latest Cuda Firmware version. */
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
#define CUDA_FW_VERSION_MAJOR 0x0002
#define CUDA_FW_VERSION_MINOR 0x0029
class ViaCuda : public HWComponent, public I2CBus {
public:
@@ -207,7 +207,7 @@ private:
// VIA interrupt related stuff
InterruptCtrl* int_ctrl;
uint64_t irq_id;
uint32_t irq_id;
uint8_t _via_ifr;
uint8_t _via_ier;
uint8_t old_ifr = 0;
+2 -2
View File
@@ -36,7 +36,7 @@ bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
return true;
}
bool DeviceRegistry::device_registered(const std::string dev_name)
bool DeviceRegistry::device_registered(const string dev_name)
{
if (get_registry().find(dev_name) != get_registry().end()) {
return true;
@@ -45,7 +45,7 @@ bool DeviceRegistry::device_registered(const std::string dev_name)
return false;
}
std::unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
{
auto it = get_registry().find(name);
if (it != get_registry().end()) {
+9 -9
View File
@@ -34,12 +34,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class HWComponent;
typedef std::function<std::unique_ptr<HWComponent> ()> CreateFunc;
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
struct DeviceDescription {
CreateFunc m_create_func;
std::vector<std::string> subdev_list;
PropMap properties;
CreateFunc m_create_func;
vector<string> subdev_list;
PropMap properties;
};
class DeviceRegistry
@@ -47,17 +47,17 @@ class DeviceRegistry
public:
DeviceRegistry() = delete;
static bool add(const std::string name, DeviceDescription desc);
static bool add(const string name, DeviceDescription desc);
static bool device_registered(const std::string dev_name);
static bool device_registered(const string dev_name);
static std::unique_ptr<HWComponent> create(const std::string& name);
static unique_ptr<HWComponent> create(const string& name);
static DeviceDescription& get_descriptor(const std::string& name);
private:
static std::map<std::string, DeviceDescription> & get_registry() {
static std::map<std::string, DeviceDescription> device_registry;
static map<string, DeviceDescription> & get_registry() {
static map<string, DeviceDescription> device_registry;
return device_registry;
}
};
+2 -2
View File
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
/** Known MACE chip IDs. */
constexpr auto MACE_ID_REV_B0 = 0x0940; // Darwin-0.3 source
constexpr auto MACE_ID_REV_A2 = 0x0941; // Darwin-0.3 source & Curio datasheet
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
/** MACE registers offsets. */
// Refer to the Am79C940 datasheet for details
+8 -28
View File
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <string>
constexpr auto BLOCK_SIZE = 512; // size in bytes of a logical block
#define BLOCK_SIZE 512 // size in bytes of a logical block
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
@@ -50,33 +50,13 @@ public:
virtual int get_raw_disk_data(char* buf) = 0;
virtual int export_data(void) = 0;
int get_data_size() const {
return this->data_size;
}
int get_disk_rec_method() const {
return this->rec_method;
}
int get_number_of_tracks() const {
return this->num_tracks;
}
int get_number_of_sides() const {
return this->num_sides;
}
int get_sectors_per_side() const {
return this->num_sectors;
}
int get_rec_density() const {
return this->density;
}
uint8_t get_format_byte() const {
return this->format_byte;
}
int get_data_size() { return this->data_size; };
int get_disk_rec_method() { return this->rec_method; };
int get_number_of_tracks() { return this->num_tracks; };
int get_number_of_sides() { return this->num_sides; };
int get_sectors_per_side() { return this->num_sectors; };
int get_rec_density() { return this->density; };
uint8_t get_format_byte() { return this->format_byte; };
protected:
std::string img_path;
+34 -58
View File
@@ -55,6 +55,8 @@ void MacSuperDrive::reset_params()
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
uint8_t new_motor_stat;
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
switch(addr) {
@@ -66,16 +68,26 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
this->cur_track += this->step_dir;
if (this->cur_track < 0)
this->cur_track = 0;
else if (this->cur_track >= this->num_tracks) {
LOG_F(ERROR, "%s: track:%d is greater than max track:%d",
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
this->cur_track = this->num_tracks - 1;
}
this->track_zero = this->cur_track == 0;
}
break;
case CommandAddr::Motor_On_Off:
this->set_motor_stat(value ^ 1);
new_motor_stat = value ^ 1;
if (this->motor_stat != new_motor_stat) {
this->motor_stat = new_motor_stat;
if (new_motor_stat) {
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
this->track_start_time = 0;
this->sector_start_time = 0;
this->init_track_search(-1);
this->is_ready = 1;
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
} else {
this->motor_on_time = 0;
this->is_ready = 0;
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
}
}
break;
case CommandAddr::Eject_Disk:
if (value) {
@@ -83,7 +95,6 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
this->eject_latch = 1;
this->reset_params();
}
break;
case CommandAddr::Reset_Eject_Latch:
if (value) {
this->eject_latch = 0;
@@ -100,78 +111,43 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
}
}
void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
{
if (this->motor_stat != new_motor_stat) {
this->motor_stat = new_motor_stat;
if (new_motor_stat) {
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
this->track_start_time = 0;
this->sector_start_time = 0;
this->init_track_search(-1);
this->is_ready = 1;
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
} else {
this->motor_on_time = 0;
this->is_ready = 0;
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
}
}
}
uint8_t MacSuperDrive::status(uint8_t addr)
{
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
uint8_t value;
switch(addr) {
case StatusAddr::Step_Status:
value = 1; // not sure what should be returned here
break;
return 1; // not sure what should be returned here
case StatusAddr::Motor_Status:
value = this->motor_stat ^ 1; // reverse logic
break;
return this->motor_stat ^ 1; // reverse logic
case StatusAddr::Eject_Latch:
value = this->eject_latch;
break;
return this->eject_latch;
case StatusAddr::Select_Head_0:
value = this->cur_head = 0;
break;
return this->cur_head = 0;
case StatusAddr::MFM_Support:
value = 1; // Superdrive does support MFM encoding scheme
break;
return 1; // Superdrive does support MFM encoding scheme
case StatusAddr::Double_Sided:
value = 1; // yes, Superdrive is double sided
break;
return 1; // yes, Superdrive is double sided
case StatusAddr::Drive_Exists:
value = 0; // tell the world I'm here
break;
return 0; // tell the world I'm here
case StatusAddr::Disk_In_Drive:
value = this->has_disk ^ 1; // reverse logic (active low)!
break;
return this->has_disk ^ 1; // reverse logic (active low)!
case StatusAddr::Write_Protect:
value = this->wr_protect ^ 1; // reverse logic
break;
return this->wr_protect ^ 1; // reverse logic
case StatusAddr::Track_Zero:
value = this->track_zero ^ 1; // reverse logic
break;
return this->track_zero ^ 1; // reverse logic
case StatusAddr::Select_Head_1:
value = this->cur_head = 1;
break;
return this->cur_head = 1;
case StatusAddr::Drive_Mode:
value = this->drive_mode;
break;
return this->drive_mode;
case StatusAddr::Drive_Ready:
value = this->is_ready ^ 1; // reverse logic
break;
return this->is_ready ^ 1; // reverse logic
case StatusAddr::Media_Kind:
value = this->media_kind ^ 1; // reverse logic!
break;
return this->media_kind ^ 1; // reverse logic!
default:
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
value = 0;
return 0;
}
return value;
}
int MacSuperDrive::insert_disk(std::string& img_path, int write_flag = 0)
@@ -284,7 +260,7 @@ uint64_t MacSuperDrive::sync_to_disk()
{
uint64_t cur_time_ns, track_time_ns;
uint64_t track_delay = uint64_t(this->get_current_track_delay() * NS_PER_SEC);
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
// look how much ns have been elapsed since the last motor enabling
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
-1
View File
@@ -102,7 +102,6 @@ public:
void command(uint8_t addr, uint8_t value);
uint8_t status(uint8_t addr);
int insert_disk(std::string& img_path, int write_flag);
void set_motor_stat(uint8_t new_motor_stat);
void init_track_search(int pos);
uint64_t sync_to_disk();
uint64_t next_addr_mark_delay(uint8_t *next_sect_num);
+12 -36
View File
@@ -42,16 +42,6 @@ Swim3Ctrl::Swim3Ctrl()
this->name = "SWIM3";
this->supported_types = HWCompType::FLOPPY_CTRL;
this->reset();
// Attach virtual Superdrive to the internal drive connector
// TODO: make SWIM3/drive wiring user selectable
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
}
void Swim3Ctrl::reset()
{
this->setup_reg = 0;
this->mode_reg = 0;
this->int_reg = 0;
@@ -64,24 +54,10 @@ void Swim3Ctrl::reset()
this->cur_state = SWIM3_IDLE;
this->cur_track = 0xFF;
this->cur_sector = 0x7F;
this->timer_val = 0;
this->phase_lines = 0;
if (this->one_us_timer_id) {
TimerManager::get_instance()->cancel_timer(this->one_us_timer_id);
this->one_us_timer_id = 0;
}
if (this->step_timer_id) {
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
this->step_timer_id = 0;
}
if (this->access_timer_id) {
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
this->access_timer_id = 0;
}
// Attach virtual Superdrive to the internal drive connector
// TODO: make SWIM3/drive wiring user selectable
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
}
int Swim3Ctrl::device_postinit()
@@ -116,8 +92,8 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
case Swim3Reg::Setup:
return this->setup_reg;
case Swim3Reg::Handshake_Mode1:
if (this->mode_reg & SWIM3_DRIVE_1) { // internal drive?
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
if (this->mode_reg & 2) { // internal drive?
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
rddata_val = this->int_drive->status(status_addr) & 1;
// transfer rddata_val to both bit 2 (RDDATA) and bit 3 (SENSE)
@@ -152,7 +128,7 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
{
uint8_t status_addr = 0;
uint8_t status_addr;
switch(reg_offset) {
case Swim3Reg::Timer:
@@ -164,14 +140,14 @@ void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
case Swim3Reg::Phase:
this->phase_lines = value & 0xF;
if (this->phase_lines & 8) { // CA3 aka LSTRB high -> sending a command to the drive
if (this->mode_reg & SWIM3_DRIVE_1) { // if internal drive is selected
if (this->mode_reg & 2) { // if internal drive is selected
this->int_drive->command(
((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3),
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
(value >> 2) & 1
);
}
} else if (this->phase_lines == 4 && (this->mode_reg & SWIM3_DRIVE_1)) {
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
} else if (this->phase_lines == 4 && (this->mode_reg & 2)) {
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
this->rd_line = this->int_drive->status(status_addr) & 1;
}
break;
@@ -263,7 +239,7 @@ void Swim3Ctrl::start_stepping()
return;
}
if ((((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3))
if ((((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3))
!= MacSuperdrive::CommandAddr::Do_Step) {
LOG_F(WARNING, "SWIM3: invalid command address on the phase lines!");
return;
+6 -12
View File
@@ -57,14 +57,10 @@ enum Swim3Reg : uint8_t {
/** Mode register bits. */
enum {
SWIM3_INT_ENA = 0x01,
SWIM3_DRIVE_1 = 0x02,
SWIM3_DRIVE_2 = 0x04,
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
SWIM3_HEAD_SELECT = 0x20,
SWIM3_FORMAT_MODE = 0x40,
SWIM3_GO_STEP = 0x80,
SWIM3_INT_ENA = 0x01,
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
SWIM3_GO_STEP = 0x80,
};
/** Interrupt flags. */
@@ -73,7 +69,6 @@ enum {
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
INT_SENSE = 0x10, // unused by SWIM3 driver
};
// SWIM3 internal states.
@@ -103,7 +98,6 @@ public:
};
protected:
void reset();
void update_irq();
void start_stepping();
void do_step();
@@ -119,7 +113,7 @@ private:
DmaBidirChannel* dma_ch;
uint8_t timer_val; // internal timer that decrements at a 1 us rate
uint8_t timer_val = 0; // internal timer that decrements at a 1 us rate
uint8_t setup_reg;
uint8_t mode_reg;
uint8_t error;
@@ -147,7 +141,7 @@ private:
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq = 0;
};
+40 -67
View File
@@ -75,8 +75,8 @@ AMIC::AMIC() : MMIODevice()
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma>(new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, DMA1_INT_SOUND << DMA1_INT_SHIFT);
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->snd_out_dma->init_interrupts(this, 2 << 8);
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
@@ -132,15 +132,7 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
case 1:
return this->viacuda->read(offset >> 9);
case 4: // SCC registers
if ((offset & 0xF) < 0x0C)
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
else
LOG_F(ERROR, "AMIC SCC read @%x.%c", offset, SIZE_ARG(size));
return 0;
case 0x8:
case 0x9:
LOG_F(WARNING, "AMIC Ethernet ID Rom read @%x.%c", offset, SIZE_ARG(size));
return 0;
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
case 0xA: // MACE registers
return this->mace->read((offset >> 4) & 0x1F);
case 0x10: // SCSI registers
@@ -215,8 +207,6 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
return (this->floppy_addr_ptr >> (3 - (offset & 3)) * 8) & 0xFF;
case AMICReg::Floppy_DMA_Ctrl:
return this->floppy_dma->read_stat();
case SCC_DMA_Xmt_A_Ctrl:
return this->escc_xmit_a_dma->read_stat();
case SCC_DMA_Xmt_B_Ctrl:
return this->escc_xmit_b_dma->read_stat();
default:
@@ -235,12 +225,8 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
case 1:
this->viacuda->write(offset >> 9, value);
return;
case 4: // SCC registers
if ((offset & 0xF) < 0x0C)
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
else
LOG_F(ERROR, "AMIC SCC write @%x.%c = %0*x",
offset, SIZE_ARG(size), size * 2, value);
case 4:
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
return;
case 0xA: // MACE registers
this->mace->write((offset >> 4) & 0x1F, value);
@@ -448,63 +434,50 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
}
// ======================== Interrupt related stuff ==========================
uint64_t AMIC::register_dev_int(IntSrc src_id) {
uint32_t AMIC::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::VIA_CUDA : return CPU_INT_VIA1 << CPU_INT_SHIFT;
case IntSrc::VIA2 : return CPU_INT_VIA2 << CPU_INT_SHIFT;
case IntSrc::ESCC : return CPU_INT_ESCC << CPU_INT_SHIFT;
case IntSrc::ETHERNET : return CPU_INT_ENET << CPU_INT_SHIFT;
case IntSrc::DMA_ALL : return CPU_INT_ALL_DMA << CPU_INT_SHIFT;
case IntSrc::NMI : return CPU_INT_NMI << CPU_INT_SHIFT;
case IntSrc::DMA_SCSI_CURIO: return VIA2_INT_SCSI_DRQ << VIA2_INT_SHIFT;
case IntSrc::SLOT_ALL : return VIA2_INT_ALL_SLOT << VIA2_INT_SHIFT;
case IntSrc::SCSI_CURIO : return VIA2_INT_SCSI_IRQ << VIA2_INT_SHIFT;
case IntSrc::DAVBUS : return VIA2_INT_SOUND << VIA2_INT_SHIFT;
case IntSrc::SWIM3 : return VIA2_INT_SWIM3 << VIA2_INT_SHIFT;
case IntSrc::SLOT_0 : return SLOT_INT_SLOT_0 << SLOT_INT_SHIFT;
case IntSrc::SLOT_1 : return SLOT_INT_SLOT_1 << SLOT_INT_SHIFT;
case IntSrc::SLOT_2 : return SLOT_INT_SLOT_2 << SLOT_INT_SHIFT;
case IntSrc::SLOT_PDS : return SLOT_INT_SLOT_PDS << SLOT_INT_SHIFT;
case IntSrc::SLOT_VDS : return SLOT_INT_SLOT_VDS << SLOT_INT_SHIFT;
case IntSrc::VBL : return SLOT_INT_VBL << SLOT_INT_SHIFT;
case IntSrc::DMA_DAVBUS_Tx : return DMA1_INT_SOUND << DMA1_INT_SHIFT;
case IntSrc::VIA_CUDA:
return CPU_INT_VIA1;
case IntSrc::SCSI_CURIO:
return VIA2_INT_SCSI_IRQ << 8;
case IntSrc::SWIM3:
return VIA2_INT_SWIM3 << 8;
case IntSrc::NMI:
return CPU_INT_NMI;
default:
ABORT_F("AMIC: unknown interrupt source %d", src_id);
}
return 0;
}
uint64_t AMIC::register_dma_int(IntSrc src_id) {
uint32_t AMIC::register_dma_int(IntSrc src_id) {
ABORT_F("AMIC: register_dma_int() not implemented");
return 0;
}
void AMIC::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
// dispatch cascaded AMIC interrupts from various sources
// irq_id format: 00DDCCBBAA where
// - AA -> CPU interrupts
// - BB -> pseudo VIA2 interrupts
// - CC -> slot interrupts
if (irq_id >> SLOT_INT_SHIFT) {
this->ack_slot_int(irq_id >> SLOT_INT_SHIFT, irq_line_state);
} else if (irq_id >> VIA2_INT_SHIFT) {
this->ack_via2_int(irq_id >> VIA2_INT_SHIFT, irq_line_state);
} else if (irq_id >> CPU_INT_SHIFT) {
this->ack_cpu_int(irq_id >> CPU_INT_SHIFT, irq_line_state);
if (irq_id < 0x100) {
this->ack_cpu_int(irq_id, irq_line_state);
} else if (irq_id < 0x10000) {
this->ack_via2_int(irq_id >> 8, irq_line_state);
} else if (irq_id < 0x1000000) {
this->ack_slot_int(irq_id >> 16, irq_line_state);
} else {
ABORT_F("AMIC: unknown interrupt source ID 0x%llX", irq_id);
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
}
}
void AMIC::ack_slot_int(uint8_t slot_int, uint8_t irq_line_state) {
void AMIC::ack_slot_int(uint32_t irq_id, uint8_t irq_line_state) {
// CAUTION: reverse logic (0 - true, 1 - false) in the IFR register!
if (irq_line_state) {
this->via2_slot_ifr &= ~slot_int;
this->via2_slot_ifr &= ~irq_id;
} else {
this->via2_slot_ifr |= slot_int;
this->via2_slot_ifr |= irq_id;
}
uint8_t new_irq = !!(~this->via2_slot_ifr & this->via2_slot_ier & 0x7F);
if (new_irq != this->via2_slot_irq) {
@@ -522,26 +495,26 @@ void AMIC::update_via2_irq() {
}
}
void AMIC::ack_via2_int(uint8_t via2_int, uint8_t irq_line_state) {
void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_line_state) {
this->via2_ifr |= via2_int;
this->via2_ifr |= irq_id;
} else {
this->via2_ifr &= ~via2_int;
this->via2_ifr &= ~irq_id;
}
this->update_via2_irq();
}
void AMIC::ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state) {
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
if (this->int_ctrl & CPU_INT_MODE) { // 68k interrupt emulation mode?
if (irq_line_state) {
this->dev_irq_lines |= cpu_int;
this->dev_irq_lines |= irq_id;
} else {
this->dev_irq_lines &= ~cpu_int;
this->dev_irq_lines &= ~irq_id;
}
if (!(this->int_ctrl & CPU_INT_FLAG)) {
this->int_ctrl |= CPU_INT_FLAG;
ppc_assert_int();
LOG_F(5, "AMIC: CPU INT asserted, source: 0x%02x", cpu_int);
LOG_F(5, "AMIC: CPU INT asserted, source: %d", irq_id);
} else {
LOG_F(5, "AMIC: CPU INT already latched");
}
@@ -551,15 +524,15 @@ void AMIC::ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state) {
}
}
void AMIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
if (irq_id >> DMA1_INT_SHIFT) { // DMA Interrupt Flags 1
irq_id = (irq_id >> DMA1_INT_SHIFT) & 0xFFU;
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_id >= 0x100) { // DMA Interrupt Flags 1
irq_id = (irq_id >> 8) & 0xFFU;
if (irq_line_state)
this->dma_ifr1 |= irq_id;
else
this->dma_ifr1 &= ~irq_id;
} else if (irq_id >> DMA0_INT_SHIFT) { // DMA Interrupt Flags 0
irq_id = (irq_id >> DMA0_INT_SHIFT) & 0xFFU;
} else { // DMA Interrupt Flags 0
irq_id &= 0xFFU;
if (irq_line_state)
this->dma_ifr0 |= irq_id;
else
@@ -601,7 +574,7 @@ void AmicSndOutDma::update_irq() {
if (new_level != this->irq_level) {
this->irq_level = new_level;
TimerManager::get_instance()->add_immediate_timer([this] {
this->int_ctrl->ack_dma_int(this->snd_dma_irq_id, this->irq_level);
this->int_ctrl->ack_dma_int(this->irq_id, this->irq_level);
});
}
}
@@ -781,7 +754,7 @@ DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len
return DmaPullResult::NoMoreData;
};
static std::vector<std::string> Amic_Subdevices = {
static vector<string> Amic_Subdevices = {
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
};
+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/pdmonboard.h>
#include <atomic>
#include <cinttypes>
#include <memory>
@@ -44,8 +43,7 @@ namespace Swim3 { class Swim3Ctrl; }
/** Interrupt related constants. */
/** CPU interrupt register bits. */
enum : uint64_t {
CPU_INT_SHIFT = 0,
enum : uint8_t {
CPU_INT_VIA1 = 1 << 0, // (R) VIA1 interrupts
CPU_INT_VIA2 = 1 << 1, // (R) pseudo VIA2 interrupts
CPU_INT_ESCC = 1 << 2, // (R) ESCC interrupt
@@ -58,8 +56,7 @@ enum : uint64_t {
};
/** Pseudo VIA2 interrupt flag/enable register bits. */
enum : uint64_t {
VIA2_INT_SHIFT = 8,
enum : uint8_t {
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_SCSI_IRQ = 1 << 3, // (R) SCSI IRQ interrupt
@@ -69,23 +66,15 @@ enum : uint64_t {
};
/** Slot interrupt flag/enable register bits. */
enum : uint64_t {
SLOT_INT_SHIFT = 16,
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_2 = 1 << 4, // (R) ColdFusion NuBus slot 2 interrupt
enum : uint8_t {
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_2 = 1 << 4, // (R) ColdFusion Nubus slot 2 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_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. */
#define AMIC_SND_BUF0_OFFS 0x10000
#define AMIC_SND_BUF1_OFFS 0x12000
@@ -115,9 +104,9 @@ public:
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
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->snd_dma_irq_id = irq_id;
this->irq_id = irq_id;
};
private:
@@ -131,7 +120,7 @@ private:
uint32_t cur_buf_pos;
InterruptCtrl *int_ctrl = nullptr;
uint64_t snd_dma_irq_id = 0;
uint32_t irq_id = 0;
uint8_t irq_level = 0;
};
@@ -299,22 +288,22 @@ public:
}
// HWComponent methods
int device_postinit() override;
int device_postinit();
/* MMIODevice methods */
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, 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);
// InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override;
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;
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);
protected:
void ack_slot_int(uint8_t slot_int, uint8_t irq_line_state);
void ack_via2_int(uint8_t via2_int, uint8_t irq_line_state);
void ack_cpu_int(uint8_t cpu_int, uint8_t irq_line_state);
void ack_slot_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_via2_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state);
void update_via2_irq();
private:
@@ -341,8 +330,8 @@ private:
uint8_t dev_irq_lines = 0; // state of the IRQ lines
// DMA IRQ flag registers
std::atomic<uint8_t> dma_ifr0{0};
std::atomic<uint8_t> dma_ifr1{0};
uint8_t dma_ifr0 = 0;
uint8_t dma_ifr1 = 0;
uint8_t dma_irq = 0;
// pseudo VIA2 state
+44 -56
View File
@@ -55,13 +55,13 @@ void NvramDev::iodev_write(uint32_t address, uint16_t value) {
this->nvram->write_byte((addr_hi->iodev_read(0) << 5) + address, value);
}
GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_GRANDCENTRAL;
this->device_id = 0x0002;
this->class_rev = 0xFF000002;
this->cache_ln_sz = 8;
@@ -125,12 +125,7 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
this->curio = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
this->curio_dma = std::unique_ptr<DMAChannel> (new DMAChannel("curio_scsi"));
this->curio_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_CURIO));
this->curio_dma->connect(this->curio);
this->curio->connect(this->curio_dma.get());
//this->curio->set_dma_channel(this->curio_dma.get());
this->curio->set_drq_callback([this](const uint8_t drq_state) {
this->curio_dma->set_stat((drq_state & 1) << 5);
});
this->curio->set_dma_channel(this->curio_dma.get());
// connect Ethernet HW
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
@@ -168,7 +163,7 @@ void GrandCentral::notify_bar_change(int bar_num)
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x20000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
}
}
@@ -186,13 +181,9 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case 1: // MACE
return this->mace->read((offset >> 4) & 0x1F);
case 2: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
if ((offset & 0xFF) < 16) {
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
}
if ((offset & 0xFF) < 0x60) {
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
return 0;
}
// fallthrough
case 3: // ESCC MacRISC addressing
return this->escc->read((offset >> 4) & 0xF);
@@ -252,10 +243,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_GC_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
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));
#endif
//LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_SCSI_MESH:
if (this->mesh_dma) {
@@ -300,15 +288,10 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
this->mace->write((offset >> 4) & 0x1F, value);
break;
case 2: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
if ((offset & 0xFF) < 16) {
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 3: // ESCC MacRISC addressing
this->escc->write((offset >> 4) & 0xF, value);
@@ -405,7 +388,6 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
switch (offset) {
case MIO_INT_MASK1:
this->int_mask = BYTESWAP_32(value);
this->signal_cpu_int(this->int_events & this->int_mask);
break;
case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR))
@@ -434,7 +416,7 @@ void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
#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) {
case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C);
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0D);
@@ -464,69 +446,75 @@ uint64_t GrandCentral::register_dev_int(IntSrc src_id) {
case IntSrc::PLATINUM : return INT_TO_IRQ_ID(0x1E); // EXT10
case IntSrc::PIPPIN_F : return INT_TO_IRQ_ID(0x1D); // EXT9
case IntSrc::PIPPIN_E : return INT_TO_IRQ_ID(0x1E); // EXT10
default:
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
}
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) {
case IntSrc::DMA_SCSI_CURIO : return INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_ETHERNET_Tx: return INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_ETHERNET_Rx: return INT_TO_IRQ_ID(0x03);
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);
case IntSrc::DMA_SCSI_MESH : return INT_TO_IRQ_ID(0x0A);
case IntSrc::DMA_SCSI_CURIO : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x0A);
default:
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
}
return 0;
}
void GrandCentral::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
// native mode: set IRQ bits in int_events on a 0-to-1 transition
// emulated mode: set IRQ bits in int_events on all transitions
void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t 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 1
// if (irq_id & ~(INT_TO_IRQ_ID(0x12) | INT_TO_IRQ_ID(0x1A)))
// 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
// );
//#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= (uint32_t)irq_id;
this->int_events |= irq_id;
} else {
this->int_events &= ~(uint32_t)irq_id;
this->int_events &= ~irq_id;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= (uint32_t)irq_id;
this->int_levels |= irq_id;
} else {
this->int_levels &= ~(uint32_t)irq_id;
this->int_levels &= ~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);
}
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);
}
void GrandCentral::signal_cpu_int(uint64_t irq_id) {
if (this->int_events & this->int_mask) {
void GrandCentral::signal_cpu_int(uint32_t irq_id) {
if (this->int_events) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
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 {
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
}
@@ -534,14 +522,14 @@ void GrandCentral::signal_cpu_int(uint64_t irq_id) {
}
void GrandCentral::clear_cpu_int() {
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
if (!this->int_events) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
}
}
static const std::vector<std::string> GCSubdevices = {
static const vector<string> GCSubdevices = {
"NVRAM", "ViaCuda", "Escc", "ScsiCurio", "Sc53C94", "Mace", "Swim3"
};
+226 -125
View File
@@ -44,13 +44,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_HEATHROW;
this->device_id = 0x0010;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
@@ -88,9 +88,6 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
// connect serial HW
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
// connect DBDMA
this->escc_b_rcv_dma = std::unique_ptr<DMAChannel>(new DMAChannel("DBDMABRx"));
// 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"));
@@ -106,10 +103,6 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
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)
{
if (bar_num) // only BAR0 is supported
@@ -121,7 +114,7 @@ void HeathrowIC::notify_bar_change(int bar_num)
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
}
}
@@ -138,8 +131,6 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ETH_RCV:
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_ESCC_B_RCV:
return this->escc_b_rcv_dma->reg_read(offset & 0xFF, size);
case MIO_OHARE_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
default:
@@ -163,9 +154,6 @@ void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
case MIO_OHARE_DMA_ETH_RCV:
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_ESCC_B_RCV:
this->escc_b_rcv_dma->reg_write(offset & 0xFF, value, size);
break;
case MIO_OHARE_DMA_AUDIO_OUT:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
@@ -176,7 +164,7 @@ void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
uint32_t value;
uint32_t res = 0;
LOG_F(9, "%s: reading from offset %x", this->name.c_str(), offset);
@@ -184,57 +172,48 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
switch (sub_addr) {
case 0:
value = mio_ctrl_read(offset, size);
res = mio_ctrl_read(offset, size);
break;
case 8:
value = dma_read(offset & 0x7FFF, size);
res = dma_read(offset - 0x8000, size);
break;
case 0x10: // SCSI
value = this->mesh->read((offset >> 4) & 0xF);
res = this->mesh->read((offset >> 4) & 0xF);
break;
case 0x11: // Ethernet
value = BYTESWAP_SIZED(this->bmac->read(offset & 0xFFFU), size);
res = BYTESWAP_SIZED(this->bmac->read(offset & 0xFFFU), size);
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;
if ((offset & 0xFF) < 16) {
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
}
// fallthrough
case 0x13: // ESCC MacRISC addressing
value = this->escc->read((offset >> 4) & 0xF);
break;
return this->escc->read((offset >> 4) & 0xF);
case 0x14:
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size);
res = this->snd_codec->snd_ctrl_read(offset - 0x14000, size);
break;
case 0x15: // SWIM3
value = this->swim3->read((offset >> 4) & 0xF);
break;
return this->swim3->read((offset >> 4 )& 0xF);
case 0x16: // VIA-CUDA
case 0x17:
value = this->viacuda->read((offset >> 9) & 0xF);
res = this->viacuda->read((offset - 0x16000) >> 9);
break;
case 0x20: // IDE 0
value = this->ide_0->read((offset >> 4) & 0x1F, size);
res = this->ide_0->read((offset >> 4) & 0x1F, size);
break;
case 0x21: // IDE 1
value = this->ide_1->read((offset >> 4) & 0x1F, size);
res = this->ide_1->read((offset >> 4) & 0x1F, size);
break;
default:
if (sub_addr >= 0x60) {
value = this->nvram->read_byte((offset >> 4) & 0x1FFF);
res = this->nvram->read_byte((offset - 0x60000) >> 4);
} else {
value = 0;
LOG_F(WARNING, "Attempting to read from unmapped I/O space: %x", offset);
}
}
return value;
return res;
}
void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
@@ -244,10 +223,10 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
switch (sub_addr) {
case 0:
this->mio_ctrl_write(offset, value, size);
mio_ctrl_write(offset, value, size);
break;
case 8:
this->dma_write(offset & 0x7FFF, value, size);
dma_write(offset - 0x8000, value, size);
break;
case 0x10: // SCSI
this->mesh->write((offset >> 4) & 0xF, value);
@@ -256,28 +235,23 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
this->bmac->write(offset & 0xFFFU, BYTESWAP_SIZED(value, size));
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 0x0C) {
if ((offset & 0xFF) < 16) {
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
this->escc->write((offset >> 4) & 0xF, value);
break;
case 0x14:
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size);
this->snd_codec->snd_ctrl_write(offset - 0x14000, value, size);
break;
case 0x15: // SWIM3
this->swim3->write((offset >> 4) & 0xF, value);
break;
case 0x16: // VIA-CUDA
case 0x17:
this->viacuda->write((offset >> 9) & 0xF, value);
this->viacuda->write((offset - 0x16000) >> 9, value);
break;
case 0x20: // IDE O
this->ide_0->write((offset >> 4) & 0x1F, value, size);
@@ -295,72 +269,69 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
}
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
uint32_t value;
uint32_t res = 0;
switch (offset & 0xFC) {
case MIO_INT_EVENTS2:
value = this->int_events >> 32;
res = this->int_events2;
break;
case MIO_INT_MASK2:
value = this->int_mask >> 32;
res = this->int_mask2;
break;
case MIO_INT_LEVELS2:
value = this->int_levels >> 32;
res = this->int_levels2;
break;
case MIO_INT_EVENTS1:
value = uint32_t(this->int_events);
res = this->int_events1;
break;
case MIO_INT_MASK1:
value = uint32_t(this->int_mask);
res = this->int_mask1;
break;
case MIO_INT_LEVELS1:
value = uint32_t(int_levels);
res = this->int_levels1;
break;
case MIO_INT_CLEAR1:
case MIO_INT_CLEAR2:
// some Mac OS drivers reads from those write-only registers
// so we return zero here as real HW does
value = 0;
break;
case MIO_OHARE_ID:
LOG_F(9, "read from MIO:ID register at Address %x", ppc_state.pc);
value = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
(this->cpu_id | (this->emmo_pin << 4));
res = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
(this->cpu_id | (this->emmo_pin << 4));
break;
case MIO_OHARE_FEAT_CTRL:
LOG_F(9, "read from MIO:Feat_Ctrl register");
value = this->feat_ctrl;
res = this->feat_ctrl;
break;
default:
value = 0;
LOG_F(WARNING, "read from unknown MIO register at %x", offset);
break;
}
return BYTESWAP_32(value);
return BYTESWAP_32(res);
}
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) {
case MIO_INT_MASK2:
this->int_mask |= uint64_t(BYTESWAP_32(value) & ~MACIO_INT_MODE) << 32;
this->signal_cpu_int();
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
break;
case MIO_INT_CLEAR2:
this->int_events &= ~(uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL) << 32);
this->int_events2 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
clear_cpu_int();
break;
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
this->int_mask |= uint64_t(this->int_mask & MACIO_INT_MODE) << 32;
this->signal_cpu_int();
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
break;
case MIO_INT_CLEAR1:
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events = 0;
if ((this->int_mask1 & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
this->int_events1 = 0;
this->int_events2 = 0;
} else {
this->int_events &= ~uint64_t(BYTESWAP_32(value) & 0x7FFFFFFFUL);
this->int_events1 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
}
clear_cpu_int();
break;
@@ -380,7 +351,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);
@@ -393,21 +364,31 @@ 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) {
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D); // Beige G3 first IDE controller, or Yosemite ata-3
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); // nmiSource in AppleHeathrow/Heathrow.cpp; programmer-switch in B&W G3
case IntSrc::NMI : return INT_TO_IRQ_ID(0x14); // nmiSource in AppleHeathrow/Heathrow.cpp
case IntSrc::PERCH2 : return INT_TO_IRQ_ID(0x15);
case IntSrc::PCI_GPU : return INT_TO_IRQ_ID(0x16);
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
@@ -415,82 +396,202 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x19);
case IntSrc::PERCH1 : return INT_TO_IRQ_ID(0x1A);
case IntSrc::PCI_PERCH : return INT_TO_IRQ_ID(0x1C);
case IntSrc::FIREWIRE : return INT_TO_IRQ_ID(0x15); // Yosemite built-in PCI FireWire
case IntSrc::PCI_J12 : return INT_TO_IRQ_ID(0x16); // Yosemite 32-bit 66MHz slot for GPU
case IntSrc::PCI_J11 : return INT_TO_IRQ_ID(0x17); // Yosemite 64-bit 33MHz slot
case IntSrc::PCI_J10 : return INT_TO_IRQ_ID(0x18); // Yosemite 64-bit 33MHz slot
case IntSrc::PCI_J9 : return INT_TO_IRQ_ID(0x19); // Yosemite 64-bit 33MHz slot
case IntSrc::ATA : return INT_TO_IRQ_ID(0x1A); // Yosemite PCI pci-ata
case IntSrc::USB : return INT_TO_IRQ_ID(0x1C); // Yosemite PCI usb
case IntSrc::ETHERNET : return INT_TO_IRQ_ID(0x2A);
default:
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
}
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) {
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_IDE1 : return INT_TO_IRQ_ID(0x03);
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);
case IntSrc::DMA_ETHERNET_Tx : return INT_TO_IRQ_ID(0x20);
case IntSrc::DMA_ETHERNET_Rx : return INT_TO_IRQ_ID(0x21);
case IntSrc::DMA_SCSI_MESH : return DMA_INT_TO_IRQ_ID(0x00);
case IntSrc::DMA_SWIM3 : return DMA_INT_TO_IRQ_ID(0x01);
case IntSrc::DMA_IDE0 : return DMA_INT_TO_IRQ_ID(0x02);
case IntSrc::DMA_IDE1 : return DMA_INT_TO_IRQ_ID(0x03);
case IntSrc::DMA_SCCA_Tx : return DMA_INT_TO_IRQ_ID(0x04);
case IntSrc::DMA_SCCA_Rx : return DMA_INT_TO_IRQ_ID(0x05);
case IntSrc::DMA_SCCB_Tx : return DMA_INT_TO_IRQ_ID(0x06);
case IntSrc::DMA_SCCB_Rx : return DMA_INT_TO_IRQ_ID(0x07);
case IntSrc::DMA_DAVBUS_Tx : return DMA_INT_TO_IRQ_ID(0x08);
case IntSrc::DMA_DAVBUS_Rx : return DMA_INT_TO_IRQ_ID(0x09);
case IntSrc::DMA_ETHERNET_Tx : return DMA_INT_TO_IRQ_ID(0x20);
case IntSrc::DMA_ETHERNET_Rx : return DMA_INT_TO_IRQ_ID(0x21);
default:
ABORT_F("Heathrow: unknown DMA interrupt source %d", src_id);
}
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
// emulated mode: set IRQ bits in int_events on all transitions
#if 1
if (!IS_INT1(irq_id)) { // does this irq_id belong to the second set?
IRQ_ID_TO_INT2_MASK(irq_id);
#if 0
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events), uint32_t(this->int_levels >> 32),
uint32_t(this->int_levels), uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
);
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d",
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
);
#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= 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;
}
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 {
this->int_events &= ~irq_id;
}
// update IRQ line state
if (irq_line_state) {
this->int_levels |= irq_id;
} else {
this->int_levels &= ~irq_id;
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 0
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d",
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);
#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;
}
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();
#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;
}
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);
// 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;
}
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;
}
}
void HeathrowIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state)
{
this->ack_int_common(irq_id, irq_line_state);
this->signal_cpu_int();
#endif
#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() {
if (this->int_events & this->int_mask) {
if (this->int_events1 || this->int_events2) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -502,7 +603,7 @@ void HeathrowIC::signal_cpu_int() {
void HeathrowIC::clear_cpu_int()
{
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
if (!this->int_events1 && !this->int_events2) {
this->cpu_int_latch = false;
ppc_release_int();
LOG_F(5, "Heathrow: CPU INT latch cleared");
+36 -64
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -70,14 +70,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#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. */
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
@@ -148,21 +140,21 @@ public:
}
// MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, 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);
// 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;
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;
void attach_iodevice(int dev_num, IobusDevice* dev_obj);
protected:
void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
void signal_cpu_int(uint64_t irq_id);
void ack_int_common(uint32_t irq_id, uint8_t irq_line_state);
void signal_cpu_int(uint32_t irq_id);
void clear_cpu_int();
private:
@@ -216,26 +208,22 @@ public:
}
// MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, 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);
// InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override;
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;
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);
protected:
void notify_bar_change(int bar_num);
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
uint32_t mio_ctrl_read(uint32_t offset, 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 read_ctrl(uint32_t offset, int size);
void write_ctrl(uint32_t offset, uint32_t value, int size);
uint32_t dma_read(uint32_t offset, 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 clear_cpu_int();
@@ -247,25 +235,13 @@ private:
std::atomic<uint32_t> int_levels{0};
std::atomic<uint32_t> int_events{0};
bool cpu_int_latch = false;
uint32_t feat_ctrl = 0; // features control register
// subdevice objects
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<AwacsScreamer> awacs; // AWACS audio codec instance
std::unique_ptr<DMAChannel> snd_out_dma;
uint16_t unsupported_dma_channel_read = 0;
uint16_t unsupported_dma_channel_write = 0;
NVram* nvram; // NVRAM module
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());
}
void set_media_bay_id(uint8_t id);
// MMIO device methods
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, 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);
// InterruptCtrl methods
uint64_t register_dev_int(IntSrc src_id) override;
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;
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);
protected:
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 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 clear_cpu_int();
private:
uint32_t base_addr = 0;
// interrupt state
uint64_t int_mask = 0;
std::atomic<uint64_t> int_levels{0};
std::atomic<uint64_t> int_events{0};
bool cpu_int_latch = false;
std::atomic<uint32_t> int_events2{0};
uint32_t int_mask2 = 0;
std::atomic<uint32_t> int_levels2{0};
std::atomic<uint32_t> int_events1{0};
uint32_t int_mask1 = 0;
std::atomic<uint32_t> int_levels1{0};
uint32_t feat_ctrl = 0; // 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 mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
@@ -433,7 +406,6 @@ private:
std::unique_ptr<DMAChannel> floppy_dma;
std::unique_ptr<DMAChannel> enet_xmit_dma;
std::unique_ptr<DMAChannel> enet_rcv_dma;
std::unique_ptr<DMAChannel> escc_b_rcv_dma;
std::unique_ptr<DMAChannel> snd_out_dma;
};
+95 -263
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,36 +21,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.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/serial/escc.h>
#include <devices/sound/awacs.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
#include <functional>
#include <memory>
namespace loguru {
enum : Verbosity {
Verbosity_INTERRUPT = loguru::Verbosity_9,
Verbosity_DBDMA = loguru::Verbosity_9
Verbosity_INTERRUPT = loguru::Verbosity_9
};
}
OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
OHare::OHare() : PCIDevice("mac-io/ohare"), InterruptCtrl()
{
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
// populate my PCI config header
this->vendor_id = PCI_VENDOR_APPLE;
this->device_id = MIO_DEV_ID_OHARE;
this->device_id = 0x0007;
this->class_rev = 0xFF000001;
this->cache_ln_sz = 8;
@@ -66,44 +56,17 @@ OHare::OHare() : PCIDevice("mac-io_ohare"), InterruptCtrl()
// connect Cuda
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
// find appropriate sound chip, create a DMA output channel for sound,
// then wire everything together
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
// initialize sound chip and its DMA output channel, then wire them together
this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
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->snd_codec->set_dma_out(this->snd_out_dma.get());
this->awacs->set_dma_out(this->snd_out_dma.get());
this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
std::bind(&AwacsScreamer::dma_out_start, this->awacs.get()),
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
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)
@@ -113,165 +76,109 @@ void OHare::notify_bar_change(int bar_num)
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
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->pci_name.c_str());
}
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
}
}
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;
switch (sub_addr) {
case 0:
value = mio_ctrl_read(offset, size);
break;
return read_ctrl(offset, size);
case 8:
value = 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
return dma_read(offset & 0x7FFF, size);
case 0x13: // ESCC MacRISC addressing
value = this->escc->read((offset >> 4) & 0xF);
break;
case 0x14:
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size);
break;
case 0x15: // SWIM3
value = this->swim3->read((offset >> 4) & 0xF);
break;
case 0x16: // VIA-CUDA
return this->escc->read((offset >> 4) & 0xF);
case 0x14: // AWACS
return this->awacs->snd_ctrl_read(offset & 0xFF, size);
case 0x16:
case 0x17:
value = this->viacuda->read((offset >> 9) & 0xF);
break;
case 0x20: // IDE 0
value = this->ide_0->read((offset >> 4) & 0x1F, size);
break;
return this->viacuda->read((offset >> 9) & 0xF);
case 0x20:
return 0xFF7FU;
default:
if (sub_addr >= 0x60) {
value = this->nvram->read_byte((offset - 0x60000) >> 4);
return this->nvram->read_byte((offset - 0x60000) >> 4);
} else {
value = 0;
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
offset, SIZE_ARG(size));
LOG_F(WARNING, "OHare: read from unimplemented register 0x%X",
this->base_addr + offset);
}
}
return value;
return 0xFFFFFFFFUL;
}
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;
switch (sub_addr) {
case 0:
this->mio_ctrl_write(offset, value, size);
this->write_ctrl(offset, value, size);
break;
case 8:
this->dma_write(offset & 0x7FFF, value, size);
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
this->escc->write((offset >> 4) & 0xF, value);
break;
case 0x14:
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size);
case 0x14: // AWACS
this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
break;
case 0x15: // SWIM3
this->swim3->write((offset >> 4) & 0xF, value);
break;
case 0x16: // VIA-CUDA
case 0x17:
case 0x16:
case 0x17: // VIA-CUDA
this->viacuda->write((offset >> 9) & 0xF, value);
break;
case 0x20: // IDE 0
this->ide_0->write((offset >> 4) & 0x1F, value, size);
case 0x20:
LOG_F(INFO, "OHare: write to IDE0 register at 0x%X", offset);
break;
default:
if (sub_addr >= 0x60) {
this->nvram->write_byte((offset - 0x60000) >> 4, value);
} else {
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
offset, SIZE_ARG(size), size * 2, value);
LOG_F(WARNING, "OHare: writing to unimplemented device register 0x%X",
this->base_addr + offset);
}
}
}
uint32_t OHare::mio_ctrl_read(uint32_t offset, int size) {
uint32_t value;
uint32_t OHare::read_ctrl(uint32_t offset, int size)
{
uint32_t res = 0;
switch (offset & 0xFC) {
case MIO_INT_EVENTS1:
value = this->int_events;
break;
case MIO_INT_MASK1:
value = this->int_mask;
res = this->int_mask;
break;
case MIO_INT_LEVELS1:
value = this->int_levels;
res = this->int_levels;
break;
case MIO_OHARE_ID: // FIXME: HACK: no clue what this register is supposed to contain
value = ~0x00004000; // 1<<14
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);
case MIO_INT_EVENTS1:
res = this->int_events;
break;
case MIO_OHARE_ID: // HACK: no clue what this register is supposed to contain
res = 0xFFFFBFFFUL;
default:
value = 0;
LOG_F(WARNING, "%s: read @%02x.%c",
this->get_name().c_str(), offset, SIZE_ARG(size));
LOG_F(WARNING, "OHare: read from unknown control register at %x", offset);
break;
}
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) {
case MIO_INT_MASK1:
this->int_mask = BYTESWAP_32(value);
LOG_F(INTERRUPT, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
this->signal_cpu_int();
LOG_F(INFO, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
break;
case MIO_INT_CLEAR1:
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();
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:
LOG_F(WARNING, "%s: write @%x.%c = %0*x",
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(WARNING, "OHare: writing to unimplemented control register 0x%X",
this->base_addr + offset);
}
}
uint32_t OHare::dma_read(uint32_t offset, int size)
{
uint32_t value;
int dma_channel = offset >> 8;
switch (dma_channel) {
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;
switch (offset >> 8) {
case 8:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
default:
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
unsupported_dma_channel_read |= (1 << dma_channel);
return 0;
}
value = 0;
LOG_F(WARNING, "OHare: unsupported DMA channel read, offset=0x%X", offset);
}
return value;
return 0xFFFFFFUL;
}
void OHare::dma_write(uint32_t offset, uint32_t value, int size)
{
int dma_channel = offset >> 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:
switch (offset >> 8) {
case 8:
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
break;
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);
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);
}
LOG_F(ERROR, "OHare: register_dev_int() not implemented");
return 0;
}
uint64_t OHare::register_dma_int(IntSrc src_id)
uint32_t OHare::register_dma_int(IntSrc src_id)
{
switch (src_id) {
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);
}
LOG_F(ERROR, "OHare: register_dma_int() not implemented");
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
// emulated mode: set IRQ bits in int_events on all transitions
#if 0
// 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 1
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
);
#endif
if ((this->int_mask & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels & irq_id))) {
this->int_events |= (uint32_t)irq_id;
this->int_events |= irq_id;
} else {
this->int_events &= ~(uint32_t)irq_id;
this->int_events &= ~irq_id;
}
this->int_events &= this->int_mask;
// update IRQ line state
if (irq_line_state) {
this->int_levels |= (uint32_t)irq_id;
this->int_levels |= irq_id;
} else {
this->int_levels &= ~(uint32_t)irq_id;
this->int_levels &= ~irq_id;
}
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->ack_int_common(irq_id, irq_line_state);
this->signal_cpu_int();
}
void OHare::signal_cpu_int() {
if (this->int_events & this->int_mask) {
if (this->int_events) {
if (!this->cpu_int_latch) {
this->cpu_int_latch = true;
ppc_assert_int();
@@ -457,19 +289,19 @@ void OHare::signal_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;
ppc_release_int();
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
}
}
static const std::vector<std::string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0"
static const vector<string> OHare_Subdevices = {
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3"
};
static const DeviceDescription OHare_Descriptor = {
OHare::create, OHare_Subdevices, {
}};
OHare::create, OHare_Subdevices, {}
};
REGISTER_DEVICE(OHare, OHare_Descriptor);
+1 -1
View File
@@ -31,7 +31,7 @@ AspenCtrl::AspenCtrl() : MemCtrlBase() {
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// 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() {
+1 -1
View File
@@ -46,7 +46,7 @@ enum {
GPIO_OUT = 14, // 0x38
};
constexpr auto ASPEN_REV_1 = 0x01000000;
#define ASPEN_REV_1 0x01000000
/** Aspen RAM bank size bits. */
enum {
+2 -4
View File
@@ -37,7 +37,7 @@ HammerheadCtrl::HammerheadCtrl() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// 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)
@@ -128,13 +128,11 @@ void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value,
void HammerheadCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
{
if (slot_num < 0 || slot_num >= 13) {
if (slot_num < 0 || slot_num >= 26) {
ABORT_F("%s: invalid DIMM slot number %d", this->name.c_str(), slot_num);
}
switch (capacity) {
case 0:
break;
case DRAM_CAP_2MB:
case DRAM_CAP_4MB:
case DRAM_CAP_8MB:
+4 -4
View File
@@ -38,10 +38,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
namespace Hammerhead {
constexpr auto RISC_MACHINE = 0x3;
constexpr auto MACH_TYPE_TNT = 0x1;
constexpr auto 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 RISC_MACHINE 0x3
#define MACH_TYPE_TNT 0x1
#define EXTENDED_ID 0x1 // examine some other registers to get full ID
#define HH_CPU_ID_TNT ((RISC_MACHINE << 4) | (EXTENDED_ID << 3) | MACH_TYPE_TNT)
// constants for the MBID field of the MOTHERBOARD_ID register
enum {
+1 -1
View File
@@ -36,7 +36,7 @@ HMC::HMC() : MemCtrlBase()
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
// 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->bit_pos = 0;
+3 -3
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-25 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -75,9 +75,9 @@ public:
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;
}
};
protected:
void remap_ram_regions();
+58 -7
View File
@@ -45,18 +45,71 @@ MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
this->command = 6;
this->status = 0x80;
// assign PCI device number zero to myself
this->pci_register_device(DEV_FUN(0,0), this);
// 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
this->add_mmio_region(0xFEC00000, 0x300000, this);
add_mmio_region(0xFEC00000, 0x300000, this);
}
int MPC106::device_postinit()
{
// assign PCI device number zero to myself
this->pci_register_device(DEV_FUN(0,0), this);
return this->pcihost_device_postinit();
std::string pci_dev_name;
static const std::map<std::string, int> pci_slots = {
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)},
{"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)},
{"pci_GPU", DEV_FUN(0x12,0)}
};
for (auto& slot : pci_slots) {
pci_dev_name = GET_STR_PROP(slot.first);
if (!pci_dev_name.empty()) {
this->attach_pci_device(pci_dev_name, slot.second, std::string("@") + slot.first);
}
}
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id_PCI_A = this->int_ctrl->register_dev_int(IntSrc::PCI_A );
this->irq_id_PCI_B = this->int_ctrl->register_dev_int(IntSrc::PCI_B );
this->irq_id_PCI_C = this->int_ctrl->register_dev_int(IntSrc::PCI_C );
this->irq_id_PCI_GPU = this->int_ctrl->register_dev_int(IntSrc::PCI_GPU );
this->irq_id_PCI_PERCH = this->int_ctrl->register_dev_int(IntSrc::PCI_PERCH);
return 0;
}
void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
auto it = std::find_if(dev_map.begin(), dev_map.end(),
[&dev](const std::pair<int, PCIBase*> &p) {
return p.second == dev;
}
);
if (it == dev_map.end()) {
LOG_F(ERROR, "Interrupt from unknown device %s", dev->get_name().c_str());
}
else {
uint32_t irq_id;
switch (it->first) {
case DEV_FUN(0x0C,0): irq_id = this->irq_id_PCI_PERCH; break;
case DEV_FUN(0x0D,0): irq_id = this->irq_id_PCI_A ; break;
case DEV_FUN(0x0E,0): irq_id = this->irq_id_PCI_B ; break;
case DEV_FUN(0x0F,0): irq_id = this->irq_id_PCI_C ; break;
case DEV_FUN(0x12,0): irq_id = this->irq_id_PCI_GPU ; break;
default:
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x",
dev->get_name().c_str(), it->first >> 3, it->first & 7);
return;
}
if (this->int_ctrl)
this->int_ctrl->ack_int(irq_id, irq_line_state);
}
}
uint32_t MPC106::read(uint32_t rgn_start, uint32_t offset, int size) {
@@ -304,8 +357,6 @@ static const PropMap Grackle_Properties = {
new StrProperty("")},
{"pci_GPU",
new StrProperty("")},
{"pci_J12",
new StrProperty("")},
};
static const DeviceDescription Grackle_Descriptor = {
Loaded 100 of 150 files, more files were not shown because too many files have changed in this diff. Show more