mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7708f987d5 | ||
|
|
4d5062c601 | ||
|
|
152b371253 | ||
|
|
a0c3f9f76c | ||
|
|
0b26a593cd | ||
|
|
23d0fb33d0 | ||
|
|
b9e45e075b | ||
|
|
b24227b139 | ||
|
|
48571a6ac4 | ||
|
|
155234ad89 |
No files matched your search
@@ -16,13 +16,6 @@ CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore CodeLite configuration files
|
||||
*.workspace
|
||||
*.workspace.*
|
||||
compile_commands.json
|
||||
*.session
|
||||
*.tags
|
||||
|
||||
# Ignore generated executables
|
||||
dingusppc
|
||||
dingusppc.exe
|
||||
|
||||
+12
-43
@@ -1,23 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(dingusppc)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(PlatformGlob)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
if (NOT WIN32 AND NOT EMSCRIPTEN)
|
||||
if (NOT WIN32)
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
|
||||
elseif (WIN32) # Windows build relies on vcpkg
|
||||
else() # Windows build relies on vcpkg
|
||||
# pick up system wide vcpkg if exists
|
||||
if (DEFINED ENV{VCPKG_ROOT} AND EXISTS $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
message(STATUS "Using system vcpkg at $ENV{VCPKG_ROOT}")
|
||||
@@ -43,12 +40,6 @@ elseif (WIN32) # Windows build relies on vcpkg
|
||||
add_compile_definitions(SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
message(STATUS "Targeting Emscripten")
|
||||
# loguru tries to include excinfo.h, which is not available under Emscripten.
|
||||
add_compile_definitions(LOGURU_STACKTRACES=0)
|
||||
endif()
|
||||
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
|
||||
@@ -92,12 +83,11 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
@@ -111,15 +101,10 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/CLI11/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
|
||||
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
|
||||
if (APPLE)
|
||||
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
|
||||
list(APPEND SOURCES ${APPLE_SOURCES})
|
||||
endif()
|
||||
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
|
||||
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
|
||||
|
||||
@@ -133,27 +118,11 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
|
||||
elseif (EMSCRIPTEN)
|
||||
target_link_libraries(dingusppc PRIVATE
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
|
||||
"-gsource-map"
|
||||
# 256 MB max for emulated Mac RAM, plus 32 MB of emulator overhead
|
||||
"-s INITIAL_MEMORY=301989888"
|
||||
"-s MODULARIZE"
|
||||
"-s EXPORT_ES6"
|
||||
"-s EXPORT_NAME=emulator"
|
||||
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
|
||||
else()
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
find_library(COCOA_LIBRARY Cocoa)
|
||||
target_link_libraries(dingusppc PRIVATE ${COCOA_LIBRARY})
|
||||
endif()
|
||||
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc PRIVATE capstone)
|
||||
endif()
|
||||
|
||||
@@ -6,9 +6,9 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
## Philosophy of Use
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the PowerMac G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
@@ -44,7 +44,7 @@ Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
|
||||
As of now, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
|
||||
As of now, only the Power Macintosh G3 Beige is implemented.
|
||||
|
||||
## How to Compile
|
||||
|
||||
@@ -57,7 +57,7 @@ You will also have to recursive clone or run
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB and Capstone modules are not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
@@ -69,6 +69,8 @@ make dingusppc
|
||||
```
|
||||
You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
Future versions may drop SDL 2 as a requirement.
|
||||
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
@@ -81,7 +83,7 @@ emulation. To build the tests, use the following terminal commands:
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True ..
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
make testppc
|
||||
```
|
||||
|
||||
@@ -95,4 +97,5 @@ make testppc
|
||||
|
||||
## Compiler Requirements
|
||||
|
||||
- Any C++20 compatible compiler
|
||||
- GCC 4.7 or newer (i.e. CodeBlocks 13.12 or newer)
|
||||
- Visual Studio 2013 or newer
|
||||
@@ -0,0 +1 @@
|
||||
theme: jekyll-theme-minimal
|
||||
@@ -1,21 +0,0 @@
|
||||
# Detect platform suffix
|
||||
if (EMSCRIPTEN)
|
||||
set(PLATFORM_SUFFIX "_js$")
|
||||
else()
|
||||
set(PLATFORM_SUFFIX "_sdl|_cubeb$")
|
||||
endif()
|
||||
|
||||
# Function to perform a platform-specific glob
|
||||
function(platform_glob RESULT_VAR)
|
||||
set(PLATFORM_SOURCES)
|
||||
foreach(GLOB_PATTERN ${ARGN})
|
||||
file(GLOB GLOB_RESULT ${GLOB_PATTERN})
|
||||
foreach(FILE_PATH ${GLOB_RESULT})
|
||||
get_filename_component(BASE_NAME ${FILE_PATH} NAME_WE)
|
||||
if("${BASE_NAME}" MATCHES ${PLATFORM_SUFFIX} OR NOT "${BASE_NAME}" MATCHES "_js$|_sdl|_cubeb$")
|
||||
list(APPEND PLATFORM_SOURCES ${FILE_PATH})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
set(${RESULT_VAR} ${PLATFORM_SOURCES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
+2
-6
@@ -2,11 +2,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(core OBJECT ${SOURCES})
|
||||
if (EMSCRIPTEN)
|
||||
target_link_libraries(core PRIVATE)
|
||||
else()
|
||||
target_link_libraries(core PRIVATE SDL2::SDL2)
|
||||
endif()
|
||||
target_link_libraries(core PRIVATE SDL2::SDL2)
|
||||
+3
-18
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if defined(__GNUG__) && !defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) // GCC, mybe ICC but not Clang
|
||||
#if defined(__GNUG__) && !defined(__clang__) // GCC, mybe ICC but not Clang
|
||||
|
||||
# include <x86intrin.h>
|
||||
|
||||
@@ -60,12 +60,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
template <class T>
|
||||
inline T extract_bits(T val, int pos, int len) {
|
||||
return (val >> pos) & ((len == sizeof(T) * 8) ? (T)-1 : ((T)1 << len) - 1);
|
||||
return (val >> pos) & (((T)1 << len) - 1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void insert_bits(T &old_val, T new_val, int pos, int len) {
|
||||
T mask = ((len == sizeof(T) * 8) ? (T)-1 : ((T)1 << len) - 1) << pos;
|
||||
T mask = (((T)1 << len) - 1) << pos;
|
||||
old_val = (old_val & ~mask) | ((new_val << pos) & mask);
|
||||
}
|
||||
|
||||
@@ -78,19 +78,4 @@ static inline bool bit_set(const uint64_t val, const int bit_num) {
|
||||
return !!(val & (1ULL << bit_num));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void clear_bit(T &val, const int bit_num) {
|
||||
val &= ~((T)1 << bit_num);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void set_bit(T &val, const int bit_num) {
|
||||
val |= ((T)1 << bit_num);
|
||||
}
|
||||
|
||||
static inline uint32_t extract_with_wrap_around(uint32_t val, int pos, int size) {
|
||||
return (uint32_t)((((uint64_t)val << 32) | val) >> ((8 - (pos & 3) - size) << 3)) &
|
||||
((1LL << (size << 3)) - 1);
|
||||
}
|
||||
|
||||
#endif // BIT_OPS_H
|
||||
@@ -58,14 +58,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect(int id) {
|
||||
_slots.erase(id);
|
||||
}
|
||||
|
||||
void disconnect_all() {
|
||||
_slots.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::map<int, std::function<void(Args...)>> _slots;
|
||||
mutable unsigned int _current_id { 0 };
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <core/hostevents.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
void EventManager::poll_events()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
events_captured++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we;
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
key_downs++;
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
key_ups++;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseEvent me;
|
||||
me.xrel = event.motion.xrel;
|
||||
me.yrel = event.motion.yrel;
|
||||
me.flags = MOUSE_EVENT_MOTION;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 1;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 0;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
|
||||
// perform post-processing
|
||||
this->_post_signal.emit();
|
||||
}
|
||||
@@ -94,13 +94,6 @@ public:
|
||||
_post_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
void disconnect_handlers() {
|
||||
_window_signal.disconnect_all();
|
||||
_mouse_signal.disconnect_all();
|
||||
_keyboard_signal.disconnect_all();
|
||||
_post_signal.disconnect_all();
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <core/hostevents.h>
|
||||
#include <core/coresignal.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/adb/adbkeyboard.h>
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
|
||||
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
|
||||
|
||||
void EventManager::poll_events()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
events_captured++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we;
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
// 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;
|
||||
}
|
||||
int key_code = get_sdl_event_key_code(event.key);
|
||||
if (key_code != -1) {
|
||||
KeyboardEvent ke;
|
||||
ke.key = key_code;
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
key_downs++;
|
||||
} else {
|
||||
ke.flags = KEYBOARD_EVENT_UP;
|
||||
key_ups++;
|
||||
}
|
||||
// Caps Lock is a special case, since it's a toggle key
|
||||
if (ke.key == AdbKey_CapsLock) {
|
||||
ke.flags = SDL_GetModState() & KMOD_CAPS ?
|
||||
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
|
||||
}
|
||||
this->_keyboard_signal.emit(ke);
|
||||
} else {
|
||||
LOG_F(WARNING, "Unknown key %x pressed", event.key.keysym.sym);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseEvent me;
|
||||
me.xrel = event.motion.xrel;
|
||||
me.yrel = event.motion.yrel;
|
||||
me.flags = MOUSE_EVENT_MOTION;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 1;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 0;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
|
||||
// perform post-processing
|
||||
this->_post_signal.emit();
|
||||
}
|
||||
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
{
|
||||
switch (event.keysym.sym) {
|
||||
case SDLK_a: return AdbKey_A;
|
||||
case SDLK_b: return AdbKey_B;
|
||||
case SDLK_c: return AdbKey_C;
|
||||
case SDLK_d: return AdbKey_D;
|
||||
case SDLK_e: return AdbKey_E;
|
||||
case SDLK_f: return AdbKey_F;
|
||||
case SDLK_g: return AdbKey_G;
|
||||
case SDLK_h: return AdbKey_H;
|
||||
case SDLK_i: return AdbKey_I;
|
||||
case SDLK_j: return AdbKey_J;
|
||||
case SDLK_k: return AdbKey_K;
|
||||
case SDLK_l: return AdbKey_L;
|
||||
case SDLK_m: return AdbKey_M;
|
||||
case SDLK_n: return AdbKey_N;
|
||||
case SDLK_o: return AdbKey_O;
|
||||
case SDLK_p: return AdbKey_P;
|
||||
case SDLK_q: return AdbKey_Q;
|
||||
case SDLK_r: return AdbKey_R;
|
||||
case SDLK_s: return AdbKey_S;
|
||||
case SDLK_t: return AdbKey_T;
|
||||
case SDLK_u: return AdbKey_U;
|
||||
case SDLK_v: return AdbKey_V;
|
||||
case SDLK_w: return AdbKey_W;
|
||||
case SDLK_x: return AdbKey_X;
|
||||
case SDLK_y: return AdbKey_Y;
|
||||
case SDLK_z: return AdbKey_Z;
|
||||
|
||||
case SDLK_1: return AdbKey_1;
|
||||
case SDLK_2: return AdbKey_2;
|
||||
case SDLK_3: return AdbKey_3;
|
||||
case SDLK_4: return AdbKey_4;
|
||||
case SDLK_5: return AdbKey_5;
|
||||
case SDLK_6: return AdbKey_6;
|
||||
case SDLK_7: return AdbKey_7;
|
||||
case SDLK_8: return AdbKey_8;
|
||||
case SDLK_9: return AdbKey_9;
|
||||
case SDLK_0: return AdbKey_0;
|
||||
|
||||
case SDLK_ESCAPE: return AdbKey_Escape;
|
||||
case SDLK_BACKQUOTE: return AdbKey_Grave;
|
||||
case SDLK_MINUS: return AdbKey_Minus;
|
||||
case SDLK_EQUALS: return AdbKey_Equal;
|
||||
case SDLK_LEFTBRACKET: return AdbKey_LeftBracket;
|
||||
case SDLK_RIGHTBRACKET: return AdbKey_RightBracket;
|
||||
case SDLK_BACKSLASH: return AdbKey_Backslash;
|
||||
case SDLK_SEMICOLON: return AdbKey_Semicolon;
|
||||
case SDLK_QUOTE: return AdbKey_Quote;
|
||||
case SDLK_COMMA: return AdbKey_Comma;
|
||||
case SDLK_PERIOD: return AdbKey_Period;
|
||||
case SDLK_SLASH: return AdbKey_Slash;
|
||||
|
||||
// Convert shifted variants to unshifted
|
||||
case SDLK_EXCLAIM: return AdbKey_1;
|
||||
case SDLK_AT: return AdbKey_2;
|
||||
case SDLK_HASH: return AdbKey_3;
|
||||
case SDLK_DOLLAR: return AdbKey_4;
|
||||
case SDLK_UNDERSCORE: return AdbKey_Minus;
|
||||
case SDLK_PLUS: return AdbKey_Equal;
|
||||
case SDLK_COLON: return AdbKey_Semicolon;
|
||||
case SDLK_QUOTEDBL: return AdbKey_Quote;
|
||||
case SDLK_LESS: return AdbKey_Comma;
|
||||
case SDLK_GREATER: return AdbKey_Period;
|
||||
case SDLK_QUESTION: return AdbKey_Slash;
|
||||
|
||||
case SDLK_TAB: return AdbKey_Tab;
|
||||
case SDLK_RETURN: return AdbKey_Return;
|
||||
case SDLK_SPACE: return AdbKey_Space;
|
||||
case SDLK_BACKSPACE: return AdbKey_Delete;
|
||||
|
||||
case SDLK_DELETE: return AdbKey_ForwardDelete;
|
||||
case SDLK_INSERT: return AdbKey_Help;
|
||||
case SDLK_HOME: return AdbKey_Home;
|
||||
case SDLK_HELP: return AdbKey_Home;
|
||||
case SDLK_END: return AdbKey_End;
|
||||
case SDLK_PAGEUP: return AdbKey_PageUp;
|
||||
case SDLK_PAGEDOWN: return AdbKey_PageDown;
|
||||
|
||||
case SDLK_LCTRL: return AdbKey_Control;
|
||||
case SDLK_RCTRL: return AdbKey_Control;
|
||||
case SDLK_LSHIFT: return AdbKey_Shift;
|
||||
case SDLK_RSHIFT: return AdbKey_Shift;
|
||||
case SDLK_LALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_Option;
|
||||
case SDLK_LGUI: return AdbKey_Command;
|
||||
case SDLK_RGUI: return AdbKey_Command;
|
||||
case SDLK_MENU: return AdbKey_Grave;
|
||||
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
|
||||
|
||||
case SDLK_UP: return AdbKey_ArrowUp;
|
||||
case SDLK_DOWN: return AdbKey_ArrowDown;
|
||||
case SDLK_LEFT: return AdbKey_ArrowLeft;
|
||||
case SDLK_RIGHT: return AdbKey_ArrowRight;
|
||||
;
|
||||
case SDLK_KP_0: return AdbKey_Keypad0;
|
||||
case SDLK_KP_1: return AdbKey_Keypad1;
|
||||
case SDLK_KP_2: return AdbKey_Keypad2;
|
||||
case SDLK_KP_3: return AdbKey_Keypad3;
|
||||
case SDLK_KP_4: return AdbKey_Keypad4;
|
||||
case SDLK_KP_5: return AdbKey_Keypad5;
|
||||
case SDLK_KP_6: return AdbKey_Keypad6;
|
||||
case SDLK_KP_7: return AdbKey_Keypad7;
|
||||
case SDLK_KP_9: return AdbKey_Keypad9;
|
||||
case SDLK_KP_8: return AdbKey_Keypad8;
|
||||
case SDLK_KP_PERIOD: return AdbKey_KeypadDecimal;
|
||||
case SDLK_KP_PLUS: return AdbKey_KeypadPlus;
|
||||
case SDLK_KP_MINUS: return AdbKey_KeypadMinus;
|
||||
case SDLK_KP_MULTIPLY: return AdbKey_KeypadMultiply;
|
||||
case SDLK_KP_DIVIDE: return AdbKey_KeypadDivide;
|
||||
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
|
||||
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
|
||||
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
|
||||
;
|
||||
case SDLK_F1: return AdbKey_F1;
|
||||
case SDLK_F2: return AdbKey_F2;
|
||||
case SDLK_F3: return AdbKey_F3;
|
||||
case SDLK_F4: return AdbKey_F4;
|
||||
case SDLK_F5: return AdbKey_F5;
|
||||
case SDLK_F6: return AdbKey_F6;
|
||||
case SDLK_F7: return AdbKey_F7;
|
||||
case SDLK_F8: return AdbKey_F8;
|
||||
case SDLK_F9: return AdbKey_F9;
|
||||
case SDLK_F10: return AdbKey_F10;
|
||||
case SDLK_F11: return AdbKey_F11;
|
||||
case SDLK_F12: return AdbKey_F12;
|
||||
case SDLK_PRINTSCREEN: return AdbKey_F13;
|
||||
case SDLK_SCROLLLOCK: return AdbKey_F14;
|
||||
case SDLK_PAUSE: return AdbKey_F15;
|
||||
|
||||
//International keyboard support
|
||||
|
||||
//Japanese keyboard
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
|
||||
return AdbKey_JIS_Yen;
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
|
||||
return AdbKey_JIS_Underscore;
|
||||
case 0XBC:
|
||||
return AdbKey_JIS_KP_Comma;
|
||||
case 0X89:
|
||||
return AdbKey_JIS_Eisu;
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL2):
|
||||
return AdbKey_JIS_Kana;
|
||||
|
||||
//German keyboard
|
||||
case 0XB4: return AdbKey_Slash;
|
||||
case 0X5E: return AdbKey_ISO1;
|
||||
case 0XDF: return AdbKey_Minus; //Eszett
|
||||
case 0XE4: return AdbKey_LeftBracket; //A-umlaut
|
||||
case 0XF6: return AdbKey_Semicolon; //O-umlaut
|
||||
case 0XFC: return AdbKey_LeftBracket; //U-umlaut
|
||||
|
||||
// French keyboard
|
||||
case 0X29: return AdbKey_Minus; // Right parenthesis
|
||||
case 0X43: return AdbKey_KeypadMultiply; // Star/Mu
|
||||
//0XB2 is superscript 2. Which Mac key should this one map to?
|
||||
case 0XF9: return AdbKey_Quote; // U-grave
|
||||
|
||||
// Italian keyboard
|
||||
case 0XE0: return AdbKey_9; // A-grave
|
||||
case 0XE8: return AdbKey_6; // E-grave
|
||||
case 0XEC: return AdbKey_LeftBracket; // I-grave
|
||||
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void toggle_mouse_grab(const SDL_KeyboardEvent &event) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.windowID);
|
||||
if (SDL_GetRelativeMouseMode()) {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_SetWindowTitle(window, "DingusPPC Display");
|
||||
} else {
|
||||
// If the mouse is initially outside the window, move it to the middle,
|
||||
// so that clicks are handled by the window (instead making it lose
|
||||
// focus, at least with macOS hosts).
|
||||
int mouse_x, mouse_y, window_x, window_y, window_width, window_height;
|
||||
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||
SDL_GetWindowPosition(window, &window_x, &window_y);
|
||||
SDL_GetWindowSize(window, &window_width, &window_height);
|
||||
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
|
||||
mouse_y < window_y || mouse_y >= window_y + window_height) {
|
||||
SDL_WarpMouseInWindow(window, window_width / 2, window_height / 2);
|
||||
}
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDL_SetWindowTitle(window, "DingusPPC Display (Mouse Grabbed)");
|
||||
}
|
||||
}
|
||||
+26
-19
@@ -26,12 +26,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
if (!timeout || timeout <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", (long long unsigned)timeout);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
@@ -56,7 +59,7 @@ uint32_t TimerManager::add_immediate_timer(timer_cb cb) {
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now();
|
||||
ti->timeout_ns = this->get_time_now() + 10;
|
||||
ti->interval_ns = 0;
|
||||
ti->cb = cb;
|
||||
|
||||
@@ -75,6 +78,11 @@ uint32_t TimerManager::add_immediate_timer(timer_cb cb) {
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
if (!interval || interval <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns",
|
||||
(long long unsigned)interval);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
@@ -101,35 +109,37 @@ uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb) {
|
||||
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
{
|
||||
this->timer_queue.remove_by_id(id);
|
||||
TimerInfo* cur_timer = this->timer_queue.top().get();
|
||||
if (cur_timer->id == id) {
|
||||
this->timer_queue.pop();
|
||||
} else {
|
||||
this->timer_queue.remove_by_id(id);
|
||||
}
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t TimerManager::process_timers()
|
||||
uint64_t TimerManager::process_timers(uint64_t time_now)
|
||||
{
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
uint64_t time_now = get_time_now();
|
||||
TimerInfo* cur_timer;
|
||||
|
||||
{ // mtx scope
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
// scan for expired timers
|
||||
cur_timer = this->timer_queue.top();
|
||||
} // ] mtx scope
|
||||
while (cur_timer->timeout_ns <= time_now) {
|
||||
cur_timer = this->timer_queue.top().get();
|
||||
while (cur_timer->timeout_ns <= time_now ||
|
||||
cur_timer->timeout_ns <= (time_now + MIN_TIMEOUT_NS)) {
|
||||
timer_cb cb = cur_timer->cb;
|
||||
|
||||
// re-arm cyclic timers
|
||||
if (cur_timer->interval_ns) {
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
cur_timer->timeout_ns = time_now + cur_timer->interval_ns;
|
||||
this->timer_queue.remove_by_id(cur_timer->id);
|
||||
this->timer_queue.push(cur_timer);
|
||||
auto new_timer = this->timer_queue.top();
|
||||
new_timer->timeout_ns = time_now + cur_timer->interval_ns;
|
||||
this->timer_queue.pop();
|
||||
this->timer_queue.push(new_timer);
|
||||
} else {
|
||||
// remove one-shot timers from queue
|
||||
this->timer_queue.pop();
|
||||
@@ -143,14 +153,11 @@ uint64_t TimerManager::process_timers()
|
||||
this->cb_active = false;
|
||||
|
||||
// process next timer
|
||||
{ // [ mtx scope
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
cur_timer = this->timer_queue.top();
|
||||
} // ] mtx scope
|
||||
cur_timer = this->timer_queue.top().get();
|
||||
}
|
||||
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
|
||||
+7
-34
@@ -22,17 +22,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef TIMER_MANAGER_H
|
||||
#define TIMER_MANAGER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MIN_TIMEOUT_NS 200
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
@@ -52,43 +52,16 @@ template <typename T, class Container = std::vector<T>, class Compare = std::les
|
||||
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
|
||||
public:
|
||||
bool remove_by_id(const uint32_t id){
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
auto el = this->top();
|
||||
if (el->id == id) {
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return true;
|
||||
}
|
||||
auto it = std::find_if(
|
||||
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == id; });
|
||||
if (it != this->c.end()) {
|
||||
this->c.erase(it);
|
||||
std::make_heap(this->c.begin(), this->c.end(), this->comp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
void push(T val)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
std::priority_queue<T, Container, Compare>::push(val);
|
||||
};
|
||||
|
||||
T pop()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
T val = std::priority_queue<T, Container, Compare>::top();
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return val;
|
||||
};
|
||||
|
||||
std::recursive_mutex& get_mtx()
|
||||
{
|
||||
return mtx;
|
||||
}
|
||||
|
||||
private:
|
||||
std::recursive_mutex mtx;
|
||||
};
|
||||
|
||||
typedef struct TimerInfo {
|
||||
@@ -135,7 +108,7 @@ public:
|
||||
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(uint32_t id);
|
||||
|
||||
uint64_t process_timers();
|
||||
uint64_t process_timers(uint64_t time_now);
|
||||
|
||||
private:
|
||||
static TimerManager* timer_manager;
|
||||
@@ -147,8 +120,8 @@ private:
|
||||
function<uint64_t()> get_time_now;
|
||||
function<void()> notify_timer_changes;
|
||||
|
||||
std::atomic<uint32_t> id{0};
|
||||
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
|
||||
uint32_t id = 0;
|
||||
bool cb_active = false; // true if a timer callback is executing
|
||||
};
|
||||
|
||||
#endif // TIMER_MANAGER_H
|
||||
@@ -1,8 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||
)
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(cpu_ppc OBJECT ${SOURCES})
|
||||
+127
-250
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,9 +23,14 @@ 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 "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
@@ -40,37 +45,29 @@ inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = uint32_t(0xFFFFFFFFUL << (31 - rot_me));
|
||||
uint32_t m2 = (uint32_t)(0xFFFFFFFFUL << (31 - rot_me));
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
if (oe_flag)
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
ppc_grab_regsda();
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
@@ -82,113 +79,87 @@ void dppc_interpreter::power_clcs() {
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
|
||||
|
||||
uint64_t dividend = ((uint64_t)ppc_result_a << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
|
||||
if ((ppc_result_a == 0x80000000UL && divisor == -1) || !divisor) {
|
||||
ppc_state.spr[SPR::MQ] = 0;
|
||||
ppc_result_d = 0x80000000UL; // -2^31 aka INT32_MIN
|
||||
} else {
|
||||
ppc_result_d = uint32_t(dividend / divisor);
|
||||
ppc_state.spr[SPR::MQ] = dividend % divisor;
|
||||
}
|
||||
|
||||
if (ov)
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_div<RC0, OV0>();
|
||||
template void dppc_interpreter::power_div<RC0, OV1>();
|
||||
template void dppc_interpreter::power_div<RC1, OV0>();
|
||||
template void dppc_interpreter::power_div<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
|
||||
if (ov)
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) >= int32_t(ppc_result_b))\
|
||||
? 0 : ppc_result_b - ppc_result_a;
|
||||
ppc_grab_regsdab();
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ppc_result_b - ppc_result_a;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
ppc_grab_regsdasimm();
|
||||
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);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : ppc_result_a + ppc_result_b;
|
||||
//ppc_result_d = 0xFFFFFFFF;
|
||||
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7f);
|
||||
uint32_t bytes_copied = 0;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
uint8_t matching_byte = (uint8_t)((ppc_state.spr[SPR::XER] & 0xFF00) >> 8);
|
||||
|
||||
// for storing each byte
|
||||
uint32_t bitmask = 0xFF000000;
|
||||
uint8_t shift_amount = 24;
|
||||
uint32_t bitmask = 0xFF000000;
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_to_load > 0) {
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
|
||||
ppc_result_d = (ppc_result_d & ~bitmask) | (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);
|
||||
// return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & ~(bitmask)) | (return_value << shift_amount);
|
||||
ppc_store_result_regd();
|
||||
if (bitmask == 0x000000FF) {
|
||||
reg_d = (reg_d + 1) & 31;
|
||||
//ppc_result_d = 0xFFFFFFFF;
|
||||
bitmask = 0xFF000000;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
bitmask >>= 8;
|
||||
shift_amount -= 8;
|
||||
}
|
||||
@@ -201,22 +172,15 @@ void dppc_interpreter::power_lscbx() {
|
||||
break;
|
||||
}
|
||||
|
||||
// store partiallly 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] & 0xFFFFFF80) | bytes_copied;
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | bytes_copied;
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_start = ppc_result_d & 31;
|
||||
uint32_t mask_end = ppc_result_b & 31;
|
||||
uint32_t insert_mask = 0;
|
||||
@@ -233,71 +197,48 @@ void dppc_interpreter::power_maskg() {
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<true>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
ppc_grab_regssab();
|
||||
ppc_result_a = (ppc_result_d & ppc_result_b) | (~(ppc_result_b) & ppc_result_a);
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<true>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_grab_regsdab();
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
uint32_t ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a & 0x80000000 ? ppc_result_a : -ppc_result_a;
|
||||
ppc_grab_regsda();
|
||||
ppc_result_d = (0x80000000 | ppc_result_a);
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
@@ -307,15 +248,14 @@ void dppc_interpreter::power_rlmi() {
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= ((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
@@ -323,37 +263,29 @@ void dppc_interpreter::power_rrib() {
|
||||
ppc_result_a &= ~((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
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_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
@@ -361,35 +293,27 @@ void dppc_interpreter::power_sleq() {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
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)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
@@ -397,18 +321,14 @@ void dppc_interpreter::power_slliq() {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
@@ -420,18 +340,14 @@ void dppc_interpreter::power_sllq() {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
@@ -440,22 +356,18 @@ void dppc_interpreter::power_slq() {
|
||||
ppc_result_a = 0;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
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));
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
@@ -463,18 +375,14 @@ void dppc_interpreter::power_sraiq() {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
@@ -486,38 +394,30 @@ void dppc_interpreter::power_sraq() {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << ppc_result_b) | (ppc_result_d >> (ppc_result_b)));
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
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.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
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)));
|
||||
@@ -528,74 +428,58 @@ void dppc_interpreter::power_srea() {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((rot_sh & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = rot_sh;
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
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.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (rot_sh)));
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
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)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
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) {
|
||||
@@ -605,18 +489,14 @@ void dppc_interpreter::power_srlq() {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
@@ -625,13 +505,10 @@ void dppc_interpreter::power_srq() {
|
||||
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.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
+207
-735
File diff suppressed because it is too large.
Load diff
@@ -24,15 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef struct PPCDisasmContext {
|
||||
uint32_t instr_addr;
|
||||
uint32_t instr_code;
|
||||
std::string instr_str;
|
||||
bool simplified; /* true if we should output simplified mnemonics */
|
||||
std::vector<std::string> regs_in;
|
||||
std::vector<std::string> regs_out;
|
||||
} PPCDisasmContext;
|
||||
|
||||
std::string disassemble_single(PPCDisasmContext* ctx);
|
||||
|
||||
+255
-237
@@ -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)
|
||||
@@ -24,16 +24,24 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
|
||||
// Uncomment this to help debug the emulator further
|
||||
//#define EXHAUSTIVE_DEBUG 1
|
||||
|
||||
// Uncomment this to have a more graceful approach to illegal opcodes
|
||||
//#define ILLEGAL_OP_SAFE 1
|
||||
|
||||
// Uncomment this to use GCC built-in functions.
|
||||
#define USE_GCC_BUILTINS 1
|
||||
|
||||
// Uncomment this to use Visual Studio built-in functions.
|
||||
//#define USE_VS_BUILTINS 1
|
||||
|
||||
//#define CPU_PROFILING // enable CPU profiling
|
||||
|
||||
/** type of compiler used during execution */
|
||||
@@ -100,19 +108,9 @@ enum SPR : int {
|
||||
SRR1 = 27,
|
||||
TBL_U = 268, // user mode TBL
|
||||
TBU_U = 269, // user mode TBU
|
||||
SPRG0 = 272,
|
||||
SPRG1 = 273,
|
||||
SPRG2 = 274,
|
||||
SPRG3 = 275,
|
||||
TBL_S = 284, // supervisor TBL
|
||||
TBU_S = 285, // supervisor TBU
|
||||
PVR = 287,
|
||||
MMCR0 = 952,
|
||||
PMC1 = 953,
|
||||
PMC2 = 954,
|
||||
SIA = 955,
|
||||
MMCR1 = 956,
|
||||
SDA = 959,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
};
|
||||
@@ -124,9 +122,7 @@ enum PPC_VER : uint32_t {
|
||||
MPC604 = 0x00040001,
|
||||
MPC603E = 0x00060101,
|
||||
MPC603EV = 0x00070101,
|
||||
MPC750 = 0x00080200,
|
||||
MPC604E = 0x00090202,
|
||||
MPC970MP = 0x00440100,
|
||||
MPC750 = 0x00080200
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -168,6 +164,8 @@ SUPERVISOR MODEL
|
||||
536 - 543 are the Data BAT registers
|
||||
**/
|
||||
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
|
||||
extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t dec_wr_timestamp;
|
||||
@@ -178,6 +176,47 @@ extern uint32_t tbr_freq_ghz;
|
||||
extern uint64_t tbr_period_ns;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
extern int32_t simult_result;
|
||||
extern uint32_t uiadd_result;
|
||||
extern uint32_t uimult_result;
|
||||
|
||||
extern uint32_t crf_d;
|
||||
extern uint32_t crf_s;
|
||||
extern uint32_t reg_s;
|
||||
extern uint32_t reg_d;
|
||||
extern uint32_t reg_a;
|
||||
extern uint32_t reg_b;
|
||||
extern uint32_t reg_c;
|
||||
extern uint32_t xercon;
|
||||
extern uint32_t cmp_c;
|
||||
extern uint32_t crm;
|
||||
extern uint32_t br_bo;
|
||||
extern uint32_t br_bi;
|
||||
extern uint32_t rot_sh;
|
||||
extern uint32_t rot_mb;
|
||||
extern uint32_t rot_me;
|
||||
extern uint32_t uimm;
|
||||
extern uint32_t grab_sr;
|
||||
extern uint32_t grab_inb; // This is for grabbing the number of immediate bytes for loading and storing
|
||||
extern uint32_t ppc_to;
|
||||
extern int32_t simm;
|
||||
extern int32_t adr_li;
|
||||
extern int32_t br_bd;
|
||||
|
||||
// Used for GP calcs
|
||||
extern uint32_t ppc_result_a;
|
||||
extern uint32_t ppc_result_b;
|
||||
extern uint32_t ppc_result_c;
|
||||
extern uint32_t ppc_result_d;
|
||||
|
||||
// Used for FP calcs
|
||||
extern uint64_t ppc_result64_a;
|
||||
extern uint64_t ppc_result64_b;
|
||||
extern uint64_t ppc_result64_c;
|
||||
extern uint64_t ppc_result64_d;
|
||||
|
||||
/* Flags for controlling interpreter execution. */
|
||||
enum {
|
||||
EXEF_BRANCH = 1 << 0,
|
||||
@@ -191,14 +230,11 @@ enum CR_select : int32_t {
|
||||
CR1_field = (0xF << 24),
|
||||
};
|
||||
|
||||
// Define bit masks for CR0.
|
||||
// To use them in other CR fields, just right shift it by 4*CR_num bits.
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 1UL << 28,
|
||||
CR_EQ = 1UL << 29,
|
||||
CR_GT = 1UL << 30,
|
||||
CR_LT = 1UL << 31
|
||||
};
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
CR_GT = 30,
|
||||
CR_LT = 31 };
|
||||
|
||||
enum CR1_bit : uint32_t {
|
||||
CR1_OX = 24,
|
||||
@@ -208,71 +244,49 @@ enum CR1_bit : uint32_t {
|
||||
};
|
||||
|
||||
enum FPSCR : uint32_t {
|
||||
RN_MASK = 0x3,
|
||||
NI = 1UL << 2,
|
||||
XE = 1UL << 3,
|
||||
ZE = 1UL << 4,
|
||||
UE = 1UL << 5,
|
||||
OE = 1UL << 6,
|
||||
VE = 1UL << 7,
|
||||
VXCVI = 1UL << 8,
|
||||
VXSQRT = 1UL << 9,
|
||||
VXSOFT = 1UL << 10,
|
||||
FPCC_FUNAN = 1UL << 12,
|
||||
FPCC_ZERO = 1UL << 13,
|
||||
FPCC_POS = 1UL << 14,
|
||||
FPCC_NEG = 1UL << 15,
|
||||
FPCC_MASK = FPCC_NEG | FPCC_POS | FPCC_ZERO | FPCC_FUNAN,
|
||||
FPRCD = 1UL << 16,
|
||||
FPRF_MASK = FPRCD | FPCC_MASK,
|
||||
FI = 1UL << 17,
|
||||
FR = 1UL << 18,
|
||||
VXVC = 1UL << 19,
|
||||
VXIMZ = 1UL << 20,
|
||||
VXZDZ = 1UL << 21,
|
||||
VXIDI = 1UL << 22,
|
||||
VXISI = 1UL << 23,
|
||||
VXSNAN = 1UL << 24,
|
||||
XX = 1UL << 25,
|
||||
ZX = 1UL << 26,
|
||||
UX = 1UL << 27,
|
||||
OX = 1UL << 28,
|
||||
VX = 1UL << 29,
|
||||
FEX = 1UL << 30,
|
||||
FX = 1UL << 31
|
||||
};
|
||||
|
||||
enum MSR : int {
|
||||
LE = 0x1, //little endian mode
|
||||
RI = 0x2,
|
||||
DR = 0x10,
|
||||
IR = 0x20,
|
||||
IP = 0x40,
|
||||
FE1 = 0x100,
|
||||
BE = 0x200,
|
||||
SE = 0x400,
|
||||
FE0 = 0x800,
|
||||
ME = 0x1000,
|
||||
FP = 0x2000,
|
||||
PR = 0x4000,
|
||||
EE = 0x8000, //external interrupt
|
||||
ILE = 0x10000,
|
||||
POW = 0x40000
|
||||
};
|
||||
|
||||
enum XER : uint32_t {
|
||||
CA = 1UL << 29,
|
||||
OV = 1UL << 30,
|
||||
SO = 1UL << 31
|
||||
RN = 0x3,
|
||||
NI = 0x4,
|
||||
XE = 0x8,
|
||||
ZE = 0x10,
|
||||
UE = 0x20,
|
||||
OE = 0x40,
|
||||
VE = 0x80,
|
||||
VXCVI = 0x100,
|
||||
VXSQRT = 0x200,
|
||||
VXSOFT = 0x400,
|
||||
FPRF = 0x1F000,
|
||||
FPCC_FUNAN = 0x10000,
|
||||
FPCC_NEG = 0x8000,
|
||||
FPCC_POS = 0x4000,
|
||||
FPCC_ZERO = 0x2000,
|
||||
FPCC_FPRCD = 0x1000,
|
||||
FI = 0x20000,
|
||||
FR = 0x40000,
|
||||
VXVC = 0x80000,
|
||||
VXIMZ = 0x100000,
|
||||
VXZDZ = 0x200000,
|
||||
VXIDI = 0x400000,
|
||||
VXISI = 0x800000,
|
||||
VXSNAN = 0x1000000,
|
||||
XX = 0x2000000,
|
||||
ZX = 0x4000000,
|
||||
UX = 0x8000000,
|
||||
OX = 0x10000000,
|
||||
VX = 0x20000000,
|
||||
FEX = 0x40000000,
|
||||
FX = 0x80000000
|
||||
};
|
||||
|
||||
//for inf and nan checks
|
||||
enum FPOP : int {
|
||||
DIV = 0x12,
|
||||
SUB = 0x14,
|
||||
ADD = 0x15,
|
||||
SQRT = 0x16,
|
||||
MUL = 0x19
|
||||
DIV = 0x12,
|
||||
SUB = 0x14,
|
||||
ADD = 0x15,
|
||||
MUL = 0x19,
|
||||
FMSUB = 0x1C,
|
||||
FMADD = 0x1D,
|
||||
FNMSUB = 0x1E,
|
||||
FNMADD = 0x1F,
|
||||
};
|
||||
|
||||
/** PowerPC exception types. */
|
||||
@@ -290,7 +304,7 @@ enum class Except_Type {
|
||||
EXC_TRACE = 13
|
||||
};
|
||||
|
||||
/** Program Exception subclasses. */
|
||||
/** Programm Exception subclasses. */
|
||||
enum Exc_Cause : uint32_t {
|
||||
FPU_OFF = 1 << (31 - 11),
|
||||
ILLEGAL_OP = 1 << (31 - 12),
|
||||
@@ -298,32 +312,13 @@ enum Exc_Cause : uint32_t {
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
#ifdef EXEC_FLAGS_ATOMIC
|
||||
extern std::atomic<unsigned> exec_flags;
|
||||
#else
|
||||
extern unsigned exec_flags;
|
||||
#endif
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
|
||||
extern bool grab_return;
|
||||
|
||||
enum Po_Cause : int {
|
||||
po_none,
|
||||
po_starting_up,
|
||||
po_shut_down,
|
||||
po_shutting_down,
|
||||
po_restarting,
|
||||
po_restart,
|
||||
po_disassemble_on,
|
||||
po_disassemble_off,
|
||||
po_enter_debugger,
|
||||
po_entered_debugger,
|
||||
po_signal_interrupt,
|
||||
};
|
||||
|
||||
extern bool power_on;
|
||||
extern Po_Cause power_off_reason;
|
||||
extern bool int_pin;
|
||||
extern bool dec_exception_pending;
|
||||
|
||||
@@ -331,15 +326,14 @@ extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
extern bool rc_flag; // Record flag
|
||||
extern bool oe_flag; // Overflow flag
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
#ifdef CPU_PROFILING
|
||||
extern uint64_t num_executed_instrs;
|
||||
@@ -361,7 +355,7 @@ void ppc_release_int();
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
template <bool for601> void ppc_opcode19();
|
||||
void ppc_opcode19();
|
||||
void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
@@ -371,15 +365,29 @@ void initialize_ppc_opcode_tables();
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
|
||||
extern void ppc_grab_regsda();
|
||||
extern void ppc_grab_regsdb();
|
||||
|
||||
extern void ppc_grab_regssa();
|
||||
extern void ppc_grab_regssb();
|
||||
|
||||
extern void ppc_grab_regsdab();
|
||||
extern void ppc_grab_regssab();
|
||||
|
||||
extern void ppc_grab_regsdasimm();
|
||||
extern void ppc_grab_regsdauimm();
|
||||
extern void ppc_grab_regsasimm();
|
||||
extern void ppc_grab_regssauimm();
|
||||
|
||||
extern void ppc_store_result_regd();
|
||||
extern void ppc_store_result_rega();
|
||||
|
||||
void ppc_changecrf0(uint32_t set_result);
|
||||
void set_host_rounding_mode(uint8_t mode);
|
||||
void update_fpscr(uint32_t new_fpscr);
|
||||
void ppc_fp_changecrf1();
|
||||
|
||||
/* 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();
|
||||
void ppc_alignment_exception(uint32_t ea);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@@ -388,38 +396,11 @@ extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
|
||||
enum bool_fun {
|
||||
bool_and = 1,
|
||||
bool_andc = 2,
|
||||
bool_eqv = 3,
|
||||
bool_nand = 4,
|
||||
bool_nor = 5,
|
||||
bool_or = 6,
|
||||
bool_orc = 7,
|
||||
bool_xor = 8,
|
||||
};
|
||||
|
||||
enum field_setting {
|
||||
LK0 = 0,
|
||||
LK1 = 1,
|
||||
AA0 = 0,
|
||||
AA1 = 1,
|
||||
SHFT0 = 0,
|
||||
SHFT1 = 1,
|
||||
RC0 = 0,
|
||||
RC1 = 1,
|
||||
OV0 = 0,
|
||||
OV1 = 1,
|
||||
CARRY0 = 0,
|
||||
CARRY1 = 1,
|
||||
IS601 = 0,
|
||||
NOT601 = 1
|
||||
};
|
||||
|
||||
namespace dppc_interpreter {
|
||||
template <bool l, bool for601> extern void ppc_bcctr();
|
||||
template <bool l> extern void ppc_bclr();
|
||||
extern void ppc_bcctr();
|
||||
extern void ppc_bcctrl();
|
||||
extern void ppc_bclr();
|
||||
extern void ppc_bclrl();
|
||||
extern void ppc_crand();
|
||||
extern void ppc_crandc();
|
||||
extern void ppc_creqv();
|
||||
@@ -430,55 +411,72 @@ extern void ppc_crorc();
|
||||
extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
template <int bool_op, bool rec> extern void ppc_do_bool();
|
||||
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_add();
|
||||
template <bool rec, bool ov> extern void ppc_adde();
|
||||
template <bool rec, bool ov> extern void ppc_addme();
|
||||
template <bool rec, bool ov> extern void ppc_addze();
|
||||
extern void ppc_add();
|
||||
extern void ppc_addc();
|
||||
extern void ppc_adde();
|
||||
extern void ppc_addme();
|
||||
extern void ppc_addze();
|
||||
extern void ppc_and();
|
||||
extern void ppc_andc();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
template <bool rec> extern void ppc_cntlzw();
|
||||
extern void ppc_cntlzw();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
template <bool rec, bool ov> extern void ppc_divw();
|
||||
template <bool rec, bool ov> extern void ppc_divwu();
|
||||
extern void ppc_divw();
|
||||
extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
template <class T, bool rec>extern void ppc_exts();
|
||||
extern void ppc_eqv();
|
||||
extern void ppc_extsb();
|
||||
extern void ppc_extsh();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhzux();
|
||||
extern void ppc_lhzx();
|
||||
extern void ppc_lhaux();
|
||||
extern void ppc_lhax();
|
||||
extern void ppc_lhbrx();
|
||||
extern void ppc_lwarx();
|
||||
extern void ppc_lbzux();
|
||||
extern void ppc_lbzx();
|
||||
extern void ppc_lwbrx();
|
||||
template <class T> extern void ppc_lzx();
|
||||
template <class T> extern void ppc_lzux();
|
||||
extern void ppc_lwzux();
|
||||
extern void ppc_lwzx();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
template <bool rec> extern void ppc_mulhwu();
|
||||
template <bool rec> extern void ppc_mulhw();
|
||||
template <bool rec, bool ov> extern void ppc_mullw();
|
||||
template <bool rec, bool ov> extern void ppc_neg();
|
||||
template <bool left, bool rec> extern void ppc_shift();
|
||||
template <bool rec> extern void ppc_sraw();
|
||||
template <bool rec> extern void ppc_srawi();
|
||||
template <class T> extern void ppc_stx();
|
||||
template <class T> extern void ppc_stux();
|
||||
extern void ppc_mulhwu();
|
||||
extern void ppc_mulhw();
|
||||
extern void ppc_mullw();
|
||||
extern void ppc_nand();
|
||||
extern void ppc_neg();
|
||||
extern void ppc_nor();
|
||||
extern void ppc_or();
|
||||
extern void ppc_orc();
|
||||
extern void ppc_slw();
|
||||
extern void ppc_srw();
|
||||
extern void ppc_sraw();
|
||||
extern void ppc_srawi();
|
||||
extern void ppc_stbx();
|
||||
extern void ppc_stbux();
|
||||
extern void ppc_stfiwx();
|
||||
extern void ppc_sthx();
|
||||
extern void ppc_sthux();
|
||||
extern void ppc_sthbrx();
|
||||
extern void ppc_stwx();
|
||||
extern void ppc_stwcx();
|
||||
extern void ppc_stwux();
|
||||
extern void ppc_stwbrx();
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_subf();
|
||||
template <bool rec, bool ov> extern void ppc_subfe();
|
||||
template <bool rec, bool ov> extern void ppc_subfme();
|
||||
template <bool rec, bool ov> extern void ppc_subfze();
|
||||
extern void ppc_subf();
|
||||
extern void ppc_subfc();
|
||||
extern void ppc_subfe();
|
||||
extern void ppc_subfme();
|
||||
extern void ppc_subfze();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
@@ -486,6 +484,7 @@ extern void ppc_tlbli();
|
||||
extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
extern void ppc_xor();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
@@ -504,39 +503,58 @@ extern void ppc_mfspr();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
|
||||
template <bool rec> extern void ppc_mtfsb0();
|
||||
template <bool rec> extern void ppc_mtfsb1();
|
||||
extern void ppc_mtfsb0();
|
||||
extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
template <bool rec> extern void ppc_fmr();
|
||||
template <bool for601, bool rec> extern void ppc_mffs();
|
||||
template <bool rec> extern void ppc_mtfsf();
|
||||
template <bool rec> extern void ppc_mtfsfi();
|
||||
extern void ppc_fmr();
|
||||
extern void ppc_mffs();
|
||||
extern void ppc_mtfsf();
|
||||
extern void ppc_mtfsfi();
|
||||
|
||||
template <bool shift> extern void ppc_addi();
|
||||
template <bool rec> extern void ppc_addic();
|
||||
template <bool shift> extern void ppc_andirc();
|
||||
template <bool l, bool a> extern void ppc_b();
|
||||
template <bool l, bool a> extern void ppc_bc();
|
||||
extern void ppc_addi();
|
||||
extern void ppc_addic();
|
||||
extern void ppc_addicdot();
|
||||
extern void ppc_addis();
|
||||
extern void ppc_andidot();
|
||||
extern void ppc_andisdot();
|
||||
extern void ppc_b();
|
||||
extern void ppc_ba();
|
||||
extern void ppc_bl();
|
||||
extern void ppc_bla();
|
||||
extern void ppc_bc();
|
||||
extern void ppc_bca();
|
||||
extern void ppc_bcl();
|
||||
extern void ppc_bcla();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
template <class T> extern void ppc_lz();
|
||||
template <class T> extern void ppc_lzu();
|
||||
extern void ppc_lbz();
|
||||
extern void ppc_lbzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lhz();
|
||||
extern void ppc_lhzu();
|
||||
extern void ppc_lwz();
|
||||
extern void ppc_lwzu();
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
template <bool shift> extern void ppc_ori();
|
||||
extern void ppc_ori();
|
||||
extern void ppc_oris();
|
||||
extern void ppc_rfi();
|
||||
extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
template <class T> extern void ppc_st();
|
||||
template <class T> extern void ppc_stu();
|
||||
extern void ppc_stb();
|
||||
extern void ppc_stbu();
|
||||
extern void ppc_sth();
|
||||
extern void ppc_sthu();
|
||||
extern void ppc_stw();
|
||||
extern void ppc_stwu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
template <bool shift> extern void ppc_xori();
|
||||
extern void ppc_xori();
|
||||
extern void ppc_xoris();
|
||||
|
||||
extern void ppc_lfs();
|
||||
extern void ppc_lfsu();
|
||||
@@ -555,66 +573,66 @@ extern void ppc_stfdu();
|
||||
extern void ppc_stfdx();
|
||||
extern void ppc_stfdux();
|
||||
|
||||
template <bool rec> extern void ppc_fadd();
|
||||
template <bool rec> extern void ppc_fsub();
|
||||
template <bool rec> extern void ppc_fmul();
|
||||
template <bool rec> extern void ppc_fdiv();
|
||||
template <bool rec> extern void ppc_fadds();
|
||||
template <bool rec> extern void ppc_fsubs();
|
||||
template <bool rec> extern void ppc_fmuls();
|
||||
template <bool rec> extern void ppc_fdivs();
|
||||
template <bool rec> extern void ppc_fmadd();
|
||||
template <bool rec> extern void ppc_fmsub();
|
||||
template <bool rec> extern void ppc_fnmadd();
|
||||
template <bool rec> extern void ppc_fnmsub();
|
||||
template <bool rec> extern void ppc_fmadds();
|
||||
template <bool rec> extern void ppc_fmsubs();
|
||||
template <bool rec> extern void ppc_fnmadds();
|
||||
template <bool rec> extern void ppc_fnmsubs();
|
||||
template <bool rec> extern void ppc_fabs();
|
||||
template <bool rec> extern void ppc_fnabs();
|
||||
template <bool rec> extern void ppc_fneg();
|
||||
template <bool rec> extern void ppc_fsel();
|
||||
template <bool rec> extern void ppc_fres();
|
||||
template <bool rec> extern void ppc_fsqrts();
|
||||
template <bool rec> extern void ppc_fsqrt();
|
||||
template <bool rec> extern void ppc_frsqrte();
|
||||
template <bool rec> extern void ppc_frsp();
|
||||
template <bool rec> extern void ppc_fctiw();
|
||||
template <bool rec> extern void ppc_fctiwz();
|
||||
extern void ppc_fadd();
|
||||
extern void ppc_fsub();
|
||||
extern void ppc_fmul();
|
||||
extern void ppc_fdiv();
|
||||
extern void ppc_fadds();
|
||||
extern void ppc_fsubs();
|
||||
extern void ppc_fmuls();
|
||||
extern void ppc_fdivs();
|
||||
extern void ppc_fmadd();
|
||||
extern void ppc_fmsub();
|
||||
extern void ppc_fnmadd();
|
||||
extern void ppc_fnmsub();
|
||||
extern void ppc_fmadds();
|
||||
extern void ppc_fmsubs();
|
||||
extern void ppc_fnmadds();
|
||||
extern void ppc_fnmsubs();
|
||||
extern void ppc_fabs();
|
||||
extern void ppc_fnabs();
|
||||
extern void ppc_fneg();
|
||||
extern void ppc_fsel();
|
||||
extern void ppc_fres();
|
||||
extern void ppc_fsqrts();
|
||||
extern void ppc_fsqrt();
|
||||
extern void ppc_frsqrte();
|
||||
extern void ppc_frsp();
|
||||
extern void ppc_fctiw();
|
||||
extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
// Power-specific instructions
|
||||
template <bool rec, bool ov> extern void power_abs();
|
||||
extern void power_abs();
|
||||
extern void power_clcs();
|
||||
template <bool rec, bool ov> extern void power_div();
|
||||
template <bool rec, bool ov> extern void power_divs();
|
||||
template <bool rec, bool ov> extern void power_doz();
|
||||
extern void power_div();
|
||||
extern void power_divs();
|
||||
extern void power_doz();
|
||||
extern void power_dozi();
|
||||
template <bool rec> extern void power_lscbx();
|
||||
template <bool rec> extern void power_maskg();
|
||||
template <bool rec> extern void power_maskir();
|
||||
template <bool rec, bool ov> extern void power_mul();
|
||||
template <bool rec, bool ov> extern void power_nabs();
|
||||
extern void power_lscbx();
|
||||
extern void power_maskg();
|
||||
extern void power_maskir();
|
||||
extern void power_mul();
|
||||
extern void power_nabs();
|
||||
extern void power_rlmi();
|
||||
template <bool rec> extern void power_rrib();
|
||||
template <bool rec> extern void power_sle();
|
||||
template <bool rec> extern void power_sleq();
|
||||
template <bool rec> extern void power_sliq();
|
||||
template <bool rec> extern void power_slliq();
|
||||
template <bool rec> extern void power_sllq();
|
||||
template <bool rec> extern void power_slq();
|
||||
template <bool rec> extern void power_sraiq();
|
||||
template <bool rec> extern void power_sraq();
|
||||
template <bool rec> extern void power_sre();
|
||||
template <bool rec> extern void power_srea();
|
||||
template <bool rec> extern void power_sreq();
|
||||
template <bool rec> extern void power_sriq();
|
||||
template <bool rec> extern void power_srliq();
|
||||
template <bool rec> extern void power_srlq();
|
||||
template <bool rec> extern void power_srq();
|
||||
extern void power_rrib();
|
||||
extern void power_sle();
|
||||
extern void power_sleq();
|
||||
extern void power_sliq();
|
||||
extern void power_slliq();
|
||||
extern void power_sllq();
|
||||
extern void power_slq();
|
||||
extern void power_sraiq();
|
||||
extern void power_sraq();
|
||||
extern void power_sre();
|
||||
extern void power_srea();
|
||||
extern void power_sreq();
|
||||
extern void power_sriq();
|
||||
extern void power_srliq();
|
||||
extern void power_srlq();
|
||||
extern void power_srq();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
+3
-121
@@ -43,7 +43,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
if (!(ppc_state.msr & MSR::ME)) {
|
||||
if (!(ppc_state.msr & 0x1000)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
@@ -115,9 +115,9 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
|
||||
ppc_state.msr &= 0xFFFB1041;
|
||||
/* copy MSR[ILE] to MSR[LE] */
|
||||
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
|
||||
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) | ((ppc_state.msr >> 16) & 1);
|
||||
|
||||
if (ppc_state.msr & MSR::IP) {
|
||||
if (ppc_state.msr & 0x40) {
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
@@ -194,121 +194,3 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
case 0xa8000000: // lha
|
||||
case 0xb0000000: // sth
|
||||
case 0xb8000000: // lmw
|
||||
case 0xc0000000: // lfs
|
||||
case 0xc8000000: // lfd
|
||||
case 0xd0000000: // stfs
|
||||
case 0xd8000000: // stfd
|
||||
case 0x84000000: // lwzu
|
||||
case 0x94000000: // stwu
|
||||
case 0xa4000000: // lhzu
|
||||
case 0xac000000: // lhau
|
||||
case 0xb4000000: // sthu
|
||||
case 0xbc000000: // stmw
|
||||
case 0xc4000000: // lfsu
|
||||
case 0xcc000000: // lfdu
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
indirect_with_immediate_index:
|
||||
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (ppc_cur_instruction & 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
|
||||
case 0x7c0004aa: // lswi
|
||||
case 0x7c00052a: // stswx
|
||||
case 0x7c0005aa: // stswi
|
||||
case 0x7c0002ea: // lwaux (64 bit only)
|
||||
case 0x7c00012c: // stwcx
|
||||
case 0x7c00042c: // lwbrx
|
||||
case 0x7c00052c: // stwbrx
|
||||
case 0x7c00062c: // lhbrx
|
||||
case 0x7c00072c: // sthbrx
|
||||
case 0x7c00026c: // eciwx // MPC7451
|
||||
case 0x7c00036c: // ecowx // MPC7451
|
||||
case 0x7c00002e: // lwzx
|
||||
case 0x7c00012e: // stwx
|
||||
case 0x7c00022e: // lhzx
|
||||
case 0x7c0002ae: // lhax
|
||||
case 0x7c00032e: // sthx
|
||||
case 0x7c00042e: // lfsx
|
||||
case 0x7c0004ae: // lfdx
|
||||
case 0x7c00052e: // stfsx
|
||||
case 0x7c0005ae: // stfdx
|
||||
case 0x7c00006e: // lwzux
|
||||
case 0x7c00016e: // stwux
|
||||
case 0x7c00026e: // lhzux
|
||||
case 0x7c0002ee: // lhaux
|
||||
case 0x7c00036e: // sthux
|
||||
case 0x7c00046e: // lfsux
|
||||
case 0x7c0004ee: // lfdux
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
goto unexpected_instruction;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
ppc_state.spr[SPR::DAR] = ea;
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
+288
-489
File diff suppressed because it is too large.
Load diff
+619
-617
File diff suppressed because it is too large.
Load diff
@@ -1,172 +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 PPC_MACROS_H
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsdauimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regssauimm(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result;
|
||||
|
||||
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_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) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpdia(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsia(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsiab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
double db_test_a = GET_FPR(reg_a); \
|
||||
double db_test_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdac(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_regsfpdabc(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
+288
-219
@@ -22,19 +22,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file PowerPC Memory Management Unit emulation. */
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <memaccess.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <loguru.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
//#define MMU_PROFILING // uncomment this to enable MMU profiling
|
||||
//#define TLB_PROFILING // uncomment this to enable SoftTLB profiling
|
||||
|
||||
/* pointer to exception handler to be called when a MMU exception is occurred. */
|
||||
void (*mmu_exception_handler)(Except_Type exception_type, uint32_t srr1_bits);
|
||||
|
||||
@@ -46,6 +43,9 @@ std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
PPC_BAT_entry ibat_array[4] = {{0}};
|
||||
PPC_BAT_entry dbat_array[4] = {{0}};
|
||||
|
||||
//#define MMU_PROFILING // uncomment this to enable MMU profiling
|
||||
//#define TLB_PROFILING // uncomment this to enable SoftTLB profiling
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
|
||||
/* global variables for lightweight MMU profiling */
|
||||
@@ -77,11 +77,15 @@ uint64_t num_entry_replacements = 0; // number of entry replacements
|
||||
#endif // TLB_PROFILING
|
||||
|
||||
/** remember recently used physical memory regions for quicker translation. */
|
||||
AddressMapEntry last_read_area;
|
||||
AddressMapEntry last_write_area;
|
||||
AddressMapEntry last_exec_area;
|
||||
AddressMapEntry last_ptab_area;
|
||||
AddressMapEntry last_dma_area;
|
||||
AddressMapEntry last_read_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_write_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
/** 601-style block address translation. */
|
||||
static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
@@ -91,7 +95,7 @@ static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
unsigned key;
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = !!(ppc_state.msr & 0x4000);
|
||||
|
||||
// I/O controller interface takes precedence over BAT in 601
|
||||
// Report BAT miss if T bit is set in the corresponding SR
|
||||
@@ -130,12 +134,12 @@ static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
template <const BATType type>
|
||||
static BATResult ppc_block_address_translation(uint32_t la)
|
||||
{
|
||||
uint32_t pa = 0; // translated physical address
|
||||
uint8_t prot = 0; // protection bits for the translated address
|
||||
uint32_t pa; // translated physical address
|
||||
uint8_t prot; // protection bits for the translated address
|
||||
PPC_BAT_entry *bat_array;
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = !!(ppc_state.msr & 0x4000);
|
||||
|
||||
bat_array = (type == BATType::IBAT) ? ibat_array : dbat_array;
|
||||
|
||||
@@ -367,7 +371,7 @@ uint64_t UnmappedVal = -1ULL;
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, 0};
|
||||
|
||||
// Dummy page for catching writes to physical read-only pages
|
||||
static std::array<uint64_t, 4096 / sizeof(uint64_t)> dummy_page;
|
||||
static std::array<uint8_t, 4096> dummy_page;
|
||||
|
||||
uint8_t CurITLBMode = {0xFF}; // current ITLB mode
|
||||
uint8_t CurDTLBMode = {0xFF}; // current DTLB mode
|
||||
@@ -389,10 +393,6 @@ 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];
|
||||
@@ -414,10 +414,6 @@ 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];
|
||||
@@ -511,7 +507,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
uint16_t flags = 0;
|
||||
|
||||
/* instruction address translation if enabled */
|
||||
if (ppc_state.msr & MSR::IR) {
|
||||
if (ppc_state.msr & 0x20) {
|
||||
// attempt block address translation first
|
||||
if (is_601) {
|
||||
bat_res = mpc601_block_address_translation(guest_va);
|
||||
@@ -528,7 +524,8 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
flags |= TLBFlags::TLBE_FROM_BAT; // tell the world we come from
|
||||
} else {
|
||||
// page address translation
|
||||
PATResult pat_res = page_address_translation(guest_va, true, !!(ppc_state.msr & MSR::PR), 0);
|
||||
PATResult pat_res = page_address_translation(guest_va, true,
|
||||
!!(ppc_state.msr & 0x4000), 0);
|
||||
phys_addr = pat_res.phys;
|
||||
flags = TLBFlags::TLBE_FROM_PAT; // tell the world we come from
|
||||
}
|
||||
@@ -549,7 +546,6 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
|
||||
(phys_addr - rgn_desc->start);
|
||||
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
|
||||
} else {
|
||||
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
|
||||
}
|
||||
@@ -557,7 +553,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
return tlb_entry;
|
||||
}
|
||||
|
||||
static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = false)
|
||||
static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
{
|
||||
BATResult bat_res;
|
||||
uint32_t phys_addr;
|
||||
@@ -567,7 +563,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
// attempt block address translation first
|
||||
if (is_601) {
|
||||
bat_res = mpc601_block_address_translation(guest_va);
|
||||
@@ -577,9 +573,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
if (bat_res.hit) {
|
||||
// check block protection
|
||||
if (!bat_res.prot || ((bat_res.prot & 1) && is_write)) {
|
||||
if (!is_dbg)
|
||||
LOG_F(9, "BAT DSI exception in TLB2 refill!");
|
||||
if (!is_dbg)
|
||||
LOG_F(9, "Attempt to write to read-only region, LA=0x%08X, PC=0x%08X!", guest_va, ppc_state.pc);
|
||||
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
|
||||
ppc_state.spr[SPR::DAR] = guest_va;
|
||||
@@ -593,7 +587,8 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
}
|
||||
} else {
|
||||
// page address translation
|
||||
PATResult pat_res = page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), is_write);
|
||||
PATResult pat_res = page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), is_write);
|
||||
phys_addr = pat_res.phys;
|
||||
flags = TLBFlags::TLBE_FROM_PAT; // tell the world we come from
|
||||
if (pat_res.prot <= 2 || pat_res.prot == 6) {
|
||||
@@ -627,15 +622,13 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
(phys_addr - rgn_desc->start);
|
||||
if (rgn_desc->type == RT_ROM) {
|
||||
// redirect writes to the dummy page for ROM regions
|
||||
tlb_entry->host_va_offs_w = (int64_t)&dummy_page - tag;
|
||||
tlb_entry->host_va_offs_w = (int64_t)&dummy_page - guest_va;
|
||||
} else {
|
||||
tlb_entry->host_va_offs_w = tlb_entry->host_va_offs_r;
|
||||
}
|
||||
}
|
||||
tlb_entry->phys_tag = phys_addr & ~0xFFFUL;
|
||||
return tlb_entry;
|
||||
} else {
|
||||
if (!is_dbg) {
|
||||
static uint32_t last_phys_addr = -1;
|
||||
static uint32_t first_phys_addr = -1;
|
||||
if (phys_addr != last_phys_addr + 4) {
|
||||
@@ -646,7 +639,6 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write, bool is_dbg = fal
|
||||
LOG_F(WARNING, "Access to unmapped physical memory, phys_addr=0x%08X", first_phys_addr);
|
||||
}
|
||||
last_phys_addr = phys_addr;
|
||||
}
|
||||
return &UnmappedMem;
|
||||
}
|
||||
}
|
||||
@@ -694,7 +686,7 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
|
||||
return tlb_entry;
|
||||
}
|
||||
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr)
|
||||
{
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
@@ -732,59 +724,63 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
tlb1_entry->phys_tag = tlb2_entry->phys_tag;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
ppc_set_cur_instruction(host_va);
|
||||
if (paddr)
|
||||
*paddr = tlb1_entry->phys_tag | (vaddr & 0xFFFUL);
|
||||
|
||||
return host_va;
|
||||
}
|
||||
|
||||
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb1[(tag >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
}
|
||||
}
|
||||
|
||||
static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &tlb2, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb2[((tag >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tlb_flush_entry(uint32_t ea)
|
||||
{
|
||||
const uint32_t tag = ea & ~0xFFFUL;
|
||||
tlb_flush_primary_entry(itlb1_mode1, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode1, tag);
|
||||
tlb_flush_primary_entry(itlb1_mode2, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode2, tag);
|
||||
tlb_flush_primary_entry(itlb1_mode3, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode3, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode1, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode1, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode2, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode2, tag);
|
||||
tlb_flush_primary_entry(dtlb1_mode3, tag);
|
||||
tlb_flush_secondary_entry(dtlb2_mode3, tag);
|
||||
}
|
||||
TLBEntry *tlb_entry, *tlb1, *tlb2;
|
||||
|
||||
template <std::size_t N>
|
||||
static void tlb_flush_entries(std::array<TLBEntry, N> &tlb, TLBFlags type) {
|
||||
for (auto &tlb_el : tlb) {
|
||||
if (tlb_el.tag != TLB_INVALID_TAG && tlb_el.flags & type) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
const uint32_t tag = ea & ~0xFFFUL;
|
||||
|
||||
for (int m = 0; m < 6; m++) {
|
||||
switch (m) {
|
||||
case 0:
|
||||
tlb1 = &itlb1_mode1[0];
|
||||
tlb2 = &itlb2_mode1[0];
|
||||
break;
|
||||
case 1:
|
||||
tlb1 = &itlb1_mode2[0];
|
||||
tlb2 = &itlb2_mode2[0];
|
||||
break;
|
||||
case 2:
|
||||
tlb1 = &itlb1_mode3[0];
|
||||
tlb2 = &itlb2_mode3[0];
|
||||
break;
|
||||
case 3:
|
||||
tlb1 = &dtlb1_mode1[0];
|
||||
tlb2 = &dtlb2_mode1[0];
|
||||
break;
|
||||
case 4:
|
||||
tlb1 = &dtlb1_mode2[0];
|
||||
tlb2 = &dtlb2_mode2[0];
|
||||
break;
|
||||
default:
|
||||
case 5:
|
||||
tlb1 = &dtlb1_mode3[0];
|
||||
tlb2 = &dtlb2_mode3[0];
|
||||
break;
|
||||
}
|
||||
|
||||
// flush primary TLB
|
||||
tlb_entry = &tlb1[(ea >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
}
|
||||
|
||||
// flush secondary TLB
|
||||
tlb_entry = &tlb2[((ea >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -796,19 +792,53 @@ void tlb_flush_entries(TLBFlags type)
|
||||
int i;
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
tlb_flush_entries(itlb1_mode2, type);
|
||||
tlb_flush_entries(itlb1_mode3, type);
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
tlb_flush_entries(itlb2_mode2, type);
|
||||
tlb_flush_entries(itlb2_mode3, type);
|
||||
m1_tlb = &itlb1_mode1[0];
|
||||
m2_tlb = &itlb1_mode2[0];
|
||||
m3_tlb = &itlb1_mode3[0];
|
||||
} else {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
tlb_flush_entries(dtlb1_mode2, type);
|
||||
tlb_flush_entries(dtlb1_mode3, type);
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
tlb_flush_entries(dtlb2_mode2, type);
|
||||
tlb_flush_entries(dtlb2_mode3, type);
|
||||
m1_tlb = &dtlb1_mode1[0];
|
||||
m2_tlb = &dtlb1_mode2[0];
|
||||
m3_tlb = &dtlb1_mode3[0];
|
||||
}
|
||||
|
||||
// Flush entries from the primary TLBs
|
||||
for (i = 0; i < TLB_SIZE; i++) {
|
||||
if (m1_tlb[i].flags & type) {
|
||||
m1_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m2_tlb[i].flags & type) {
|
||||
m2_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m3_tlb[i].flags & type) {
|
||||
m3_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
m1_tlb = &itlb2_mode1[0];
|
||||
m2_tlb = &itlb2_mode2[0];
|
||||
m3_tlb = &itlb2_mode3[0];
|
||||
} else {
|
||||
m1_tlb = &dtlb2_mode1[0];
|
||||
m2_tlb = &dtlb2_mode2[0];
|
||||
m3_tlb = &dtlb2_mode3[0];
|
||||
}
|
||||
|
||||
// Flush entries from the secondary TLBs
|
||||
for (i = 0; i < TLB_SIZE * TLB2_WAYS; i++) {
|
||||
if (m1_tlb[i].flags & type) {
|
||||
m1_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m2_tlb[i].flags & type) {
|
||||
m2_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m3_tlb[i].flags & type) {
|
||||
m3_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,6 +1001,36 @@ void mmu_pat_ctx_changed()
|
||||
}
|
||||
}
|
||||
|
||||
void mmu_print_regs()
|
||||
{
|
||||
LOG_SCOPE_FUNCTION(INFO);
|
||||
LOG_F(INFO, "MSR = 0x%X", ppc_state.msr);
|
||||
|
||||
LOG_F(INFO, "BAT registers:");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
LOG_F(INFO, "IBAT%dU = 0x%X, IBAT%dL = 0x%X",
|
||||
i, ppc_state.spr[528+i*2],
|
||||
i, ppc_state.spr[529+i*2]);
|
||||
}
|
||||
|
||||
if (!is_601) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
LOG_F(INFO, "DBAT%dU = 0x%X, DBAT%dL = 0x%X",
|
||||
i, ppc_state.spr[536+i*2],
|
||||
i, ppc_state.spr[537+i*2]);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s", "");
|
||||
LOG_F(INFO, "SDR1 = 0x%X", ppc_state.spr[SPR::SDR1]);
|
||||
LOG_F(INFO, "Segment registers:");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
LOG_F(INFO, "SR%d = 0x%X", i, ppc_state.sr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Forward declarations.
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
|
||||
@@ -1021,22 +1081,24 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
iomem_reads_total++;
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
4) << 32) |
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
4)
|
||||
);
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
{
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
4) << 32) |
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
guest_va + 4 - tlb2_entry->dev_base_va,
|
||||
4)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
sizeof(T))
|
||||
);
|
||||
}
|
||||
@@ -1092,7 +1154,8 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
}
|
||||
if (!(tlb1_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
tlb1_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
|
||||
// don't forget to update the secondary TLB as well
|
||||
@@ -1130,7 +1193,8 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
if (!(tlb2_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
page_address_translation(guest_va, false, !!(ppc_state.msr & MSR::PR), true);
|
||||
page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
tlb2_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
|
||||
@@ -1143,18 +1207,21 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
iomem_writes_total++;
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
{
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
value >> 32, 4);
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
guest_va + 4 - tlb2_entry->dev_base_va,
|
||||
(uint32_t)value, 4);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
value >> 32, 4);
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
(uint32_t)value, 4);
|
||||
} else {
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
value, sizeof(T));
|
||||
}
|
||||
return;
|
||||
@@ -1223,7 +1290,7 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
return READ_DWORD_BE_U(host_va);
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
return READ_QWORD_BE_U(host_va);
|
||||
}
|
||||
@@ -1269,7 +1336,7 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
break;
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
WRITE_QWORD_BE_U(host_va, value);
|
||||
break;
|
||||
@@ -1527,7 +1594,7 @@ static uint32_t ppc_mmu_addr_translate(uint32_t la, int is_write)
|
||||
uint32_t pa; /* translated physical address */
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = !!(ppc_state.msr & 0x4000);
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
@@ -1588,7 +1655,7 @@ static void mem_write_unaligned(uint32_t addr, uint32_t value, uint32_t size) {
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; shift -= 8, addr++, phys_addr++, i++) {
|
||||
if ((ppc_state.msr & MSR::DR) && (!i || !(addr & 0xFFF))) {
|
||||
if ((ppc_state.msr & 0x10) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1597,7 +1664,7 @@ static void mem_write_unaligned(uint32_t addr, uint32_t value, uint32_t size) {
|
||||
}
|
||||
} else {
|
||||
// data address translation if enabled
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1662,10 +1729,9 @@ static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
tlb1_entry->phys_tag = tlb2_entry->phys_tag;
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // an attempt to access a memory-mapped device
|
||||
return guest_va - tlb2_entry->dev_base_va;
|
||||
return guest_va - tlb2_entry->rgn_desc->start;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1692,7 +1758,7 @@ static uint32_t mem_grab_unaligned(uint32_t addr, uint32_t size) {
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; addr++, phys_addr++, i++) {
|
||||
tlb_translate_addr(addr);
|
||||
if ((ppc_state.msr & MSR::DR) && (!i || !(addr & 0xFFF))) {
|
||||
if ((ppc_state.msr & 0x10) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1703,7 +1769,7 @@ static uint32_t mem_grab_unaligned(uint32_t addr, uint32_t size) {
|
||||
|
||||
} else {
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1725,7 +1791,7 @@ void mem_write_byte(uint32_t addr, uint8_t value) {
|
||||
mmu_write_vmem<uint8_t>(addr, value);
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1741,7 +1807,7 @@ void mem_write_word(uint32_t addr, uint16_t value) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1757,7 +1823,7 @@ void mem_write_dword(uint32_t addr, uint32_t value) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1772,7 +1838,7 @@ void mem_write_qword(uint32_t addr, uint64_t value) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
@@ -1784,7 +1850,7 @@ uint8_t mem_grab_byte(uint32_t addr) {
|
||||
tlb_translate_addr(addr);
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1799,7 +1865,7 @@ uint16_t mem_grab_word(uint32_t addr) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1814,7 +1880,7 @@ uint32_t mem_grab_dword(uint32_t addr) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1829,7 +1895,7 @@ uint64_t mem_grab_qword(uint32_t addr) {
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
@@ -1842,7 +1908,7 @@ static uint32_t mmu_instr_translation(uint32_t la)
|
||||
uint32_t pa; /* translated physical address */
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = !!(ppc_state.msr & 0x4000);
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
@@ -1890,7 +1956,7 @@ uint8_t* quickinstruction_translate(uint32_t addr) {
|
||||
#endif
|
||||
|
||||
/* perform instruction address translation if enabled */
|
||||
if (ppc_state.msr & MSR::IR) {
|
||||
if (ppc_state.msr & 0x20) {
|
||||
addr = mmu_instr_translation(addr);
|
||||
}
|
||||
|
||||
@@ -1958,82 +2024,8 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
|
||||
uint32_t save_dsisr, save_dar;
|
||||
bool is_mapped;
|
||||
|
||||
/* 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 {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
|
||||
do {
|
||||
if (tlb1_entry->tag != tag) {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
if (tlb2_entry == nullptr) {
|
||||
// secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
tlb2_entry = dtlb2_refill(guest_va, 0, true);
|
||||
if (tlb2_entry->flags & PAGE_NOPHYS) {
|
||||
is_mapped = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
}
|
||||
else {
|
||||
tlb1_entry = tlb2_entry;
|
||||
}
|
||||
}
|
||||
guest_pa = tlb1_entry->phys_tag | (guest_va & 0xFFFUL);
|
||||
is_mapped = true;
|
||||
} while (0);
|
||||
} catch (std::invalid_argument& exc) {
|
||||
LOG_F(WARNING, "Unmapped address 0x%08X", guest_va);
|
||||
is_mapped = false;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
return is_mapped;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
static void invalidate_tlb_entries(std::array<TLBEntry, N> &tlb) {
|
||||
for (auto &tlb_el : tlb) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
tlb_el.phys_tag = 0;
|
||||
tlb_el.reserved = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_mmu_init()
|
||||
{
|
||||
last_read_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_write_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
mmu_exception_handler = ppc_exception_handler;
|
||||
|
||||
if (is_601) {
|
||||
@@ -2046,19 +2038,96 @@ void ppc_mmu_init()
|
||||
}
|
||||
|
||||
// invalidate all IDTLB entries
|
||||
invalidate_tlb_entries(itlb1_mode1);
|
||||
invalidate_tlb_entries(itlb1_mode2);
|
||||
invalidate_tlb_entries(itlb1_mode3);
|
||||
invalidate_tlb_entries(itlb2_mode1);
|
||||
invalidate_tlb_entries(itlb2_mode2);
|
||||
invalidate_tlb_entries(itlb2_mode3);
|
||||
for (auto &tlb_el : itlb1_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb1_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb1_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
// invalidate all DTLB entries
|
||||
invalidate_tlb_entries(dtlb1_mode1);
|
||||
invalidate_tlb_entries(dtlb1_mode2);
|
||||
invalidate_tlb_entries(dtlb1_mode3);
|
||||
invalidate_tlb_entries(dtlb2_mode1);
|
||||
invalidate_tlb_entries(dtlb2_mode2);
|
||||
invalidate_tlb_entries(dtlb2_mode3);
|
||||
for (auto &tlb_el : dtlb1_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb1_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb1_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
|
||||
+4
-6
@@ -26,10 +26,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
class MMIODevice;
|
||||
#include <vector>
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
@@ -102,8 +102,6 @@ typedef struct TLBEntry {
|
||||
int64_t dev_base_va;
|
||||
};
|
||||
};
|
||||
uint32_t phys_tag;
|
||||
uint32_t reserved;
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
@@ -125,9 +123,9 @@ extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
|
||||
extern void ppc_set_cur_instruction(const uint8_t* ptr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t 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);
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
|
||||
+1141
-804
File diff suppressed because it is too large.
Load diff
Executable → Regular
+187
-73
@@ -1,5 +1,3 @@
|
||||
import re
|
||||
|
||||
def gen_ppc_opcode(opc_str, imm):
|
||||
if opc_str == "ADD":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x10A << 1)
|
||||
@@ -102,53 +100,53 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
elif opc_str == "EXTSH.":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1) + 1
|
||||
elif opc_str == "FABS":
|
||||
return (0x3F << 26) + (3 << 21) + (0 << 16) + (4 << 11) + (0x108 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1)
|
||||
elif opc_str == "FABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (0 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
elif opc_str == "FADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11) + (0x20 << 1)
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11)
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1)
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
elif opc_str == "FCTIWZ":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1)
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1)
|
||||
elif opc_str == "FCTIWZ.":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
elif opc_str == "FDIV":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIV.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FDIVS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIVS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FNABS":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
|
||||
elif opc_str == "FNABS.":
|
||||
@@ -157,40 +155,42 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
|
||||
elif opc_str == "FNEG.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FMSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x18 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "MULHW":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
|
||||
elif opc_str == "MULHW.":
|
||||
@@ -403,8 +403,6 @@ if __name__ == "__main__":
|
||||
|
||||
out_file.write("\n")
|
||||
|
||||
floatRE = re.compile('^([\w]+\.?) +(?:\((\w+)\) )?:: (?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?FPSCR: (0x\w+) \| CR: (0x\w+)$')
|
||||
|
||||
with open("ppcfloattest.txt", "r") as in_file:
|
||||
with open("ppcfloattests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
@@ -412,37 +410,153 @@ if __name__ == "__main__":
|
||||
lineno += 1
|
||||
|
||||
line = line.strip()
|
||||
|
||||
p = floatRE.match(line)
|
||||
if p:
|
||||
opcode = p.group(1).upper();
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
|
||||
if p.group(2) == "RTNI":
|
||||
out_file.write(",round=RNI")
|
||||
elif p.group(2) == "RTN":
|
||||
out_file.write(",round=RTN")
|
||||
elif p.group(2) == "RTZ":
|
||||
pos = 10
|
||||
checkstring = ''
|
||||
|
||||
while pos < len(line):
|
||||
if (line[pos].isalnum()):
|
||||
checkstring += line[pos]
|
||||
|
||||
if ("RTN" in checkstring):
|
||||
if (line[pos+1:pos+2] == "I"):
|
||||
out_file.write(",round=RNI")
|
||||
checkstring = ''
|
||||
else:
|
||||
out_file.write(",round=RTN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTZ" in checkstring):
|
||||
out_file.write(",round=RTZ")
|
||||
elif p.group(2) == "RTPI":
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTPI" in checkstring):
|
||||
out_file.write(",round=RPI")
|
||||
elif p.group(2) == "VE":
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("VE" in checkstring):
|
||||
out_file.write(",round=VEN")
|
||||
elif p.group(2) != None:
|
||||
print("Warning: line: [%d] unknown round \"%s\"\n" % (lineno, p.group(2)))
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("frD" in checkstring):
|
||||
out_file.write(",frD=0x" + line[pos+4:pos+20])
|
||||
checkstring = ''
|
||||
elif ("frA" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frA=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frA=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frA=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frB" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frB=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frB=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frB=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frC" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frC=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frC=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frC=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("FPSCR" in checkstring):
|
||||
out_file.write(",FPSCR=" + line[pos+3:pos+13])
|
||||
checkstring = ''
|
||||
elif ("CR" in checkstring):
|
||||
out_file.write(",CR=0x0" + line[pos+6:pos+14])
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
|
||||
if p.group(3) != None:
|
||||
out_file.write(",%s=%s" % (p.group(3), p.group(4)))
|
||||
if p.group(5) != None:
|
||||
out_file.write(",%s=%s" % (p.group(5), p.group(6)))
|
||||
if p.group(7) != None:
|
||||
out_file.write(",%s=%s" % (p.group(7), p.group(8)))
|
||||
if p.group(9) != None:
|
||||
out_file.write(",%s=%s" % (p.group(9), p.group(10)))
|
||||
# reg_id = line[pos:pos+4]
|
||||
# if reg_id.startswith("frD"):
|
||||
# out_file.write(",frD=" + line[pos+4:pos+22])
|
||||
# pos += 24
|
||||
# elif reg_id.startswith("frA"):
|
||||
# out_file.write(",frA=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frB"):
|
||||
# out_file.write(",frB=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frC"):
|
||||
# out_file.write(",frC=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("FPSCR:"):
|
||||
# out_file.write(",FPSCR=" + line[pos+7:pos+17])
|
||||
# pos += 19
|
||||
# elif reg_id.startswith("CR:"):
|
||||
# out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("VE)"):
|
||||
# out_file.write("round=VEN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TN)"):
|
||||
# out_file.write("round=RTN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TZ)"):
|
||||
# out_file.write("round=RTZ" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("NI)"):
|
||||
# out_file.write("round=RNI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("PI)"):
|
||||
# out_file.write("round=RPI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# else:
|
||||
# out_file.write("Unknown reg ID" + reg_id)
|
||||
# break
|
||||
|
||||
out_file.write(",FPSCR=%s" % p.group(11))
|
||||
out_file.write(",CR=%s" % p.group(12))
|
||||
out_file.write("\n")
|
||||
else:
|
||||
print("Warning: line: [%d] \"%s\"\n" % (lineno, line))
|
||||
out_file.write("\n")
|
||||
+2015
-2015
File diff suppressed because it is too large.
Load diff
+2054
-2054
File diff suppressed because it is too large.
Load diff
+36
-63
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,20 +21,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cfenv>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
int ntested; /* number of tested instructions */
|
||||
int nfailed; /* number of failed instructions */
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
@@ -166,38 +164,14 @@ static void read_test_data() {
|
||||
}
|
||||
}
|
||||
|
||||
double double_from_string(string str) {
|
||||
if (str == "snan")
|
||||
return std::numeric_limits<double>::signaling_NaN();
|
||||
if (str == "qnan")
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
if (str == "-FLT_MAX")
|
||||
return -std::numeric_limits<float>::max();
|
||||
if (str == "-FLT_MIN")
|
||||
return -std::numeric_limits<float>::min();
|
||||
if (str == "-DBL_MAX")
|
||||
return -std::numeric_limits<double>::max();
|
||||
if (str == "-DBL_MIN")
|
||||
return -std::numeric_limits<double>::min();
|
||||
if (str == "FLT_MIN")
|
||||
return std::numeric_limits<float>::min();
|
||||
if (str == "FLT_MAX")
|
||||
return std::numeric_limits<float>::max();
|
||||
if (str == "DBL_MIN")
|
||||
return std::numeric_limits<double>::min();
|
||||
if (str == "DBL_MAX")
|
||||
return std::numeric_limits<double>::max();
|
||||
return stod(str, NULL);
|
||||
}
|
||||
|
||||
static void read_test_float_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
|
||||
uint32_t opcode, src1, src2, check_cr, check_fpscr;
|
||||
uint64_t dest_64;
|
||||
uint32_t opcode, dest, src1, src2, check_xer, check_cr, check_fpscr;
|
||||
uint64_t dest_64, src1_64, src2_64;
|
||||
//float sfp_dest, sfp_src1, sfp_src2, sfp_src3;
|
||||
double dfp_src1, dfp_src2, dfp_src3;
|
||||
double dfp_dest, dfp_src1, dfp_src2, dfp_src3;
|
||||
string rounding_mode;
|
||||
|
||||
ifstream tf2stream("ppcfloattests.csv");
|
||||
@@ -212,7 +186,7 @@ static void read_test_float_data() {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
continue; // skip empty/comment lines
|
||||
continue; /* skip empty/comment lines */
|
||||
|
||||
istringstream lnstream(line);
|
||||
|
||||
@@ -231,27 +205,46 @@ static void read_test_float_data() {
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_xer = 0;
|
||||
check_cr = 0;
|
||||
check_fpscr = 0;
|
||||
//sfp_dest = 0.0;
|
||||
//sfp_src1 = 0.0;
|
||||
//sfp_src2 = 0.0;
|
||||
//sfp_src3 = 0.0;
|
||||
dfp_dest = 0.0;
|
||||
dfp_src1 = 0.0;
|
||||
dfp_src2 = 0.0;
|
||||
dfp_src3 = 0.0;
|
||||
dest_64 = 0;
|
||||
|
||||
// switch to default rounding
|
||||
fesetround(FE_TONEAREST);
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("frD=", 0) == 0) {
|
||||
dest_64 = stoull(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("frA=", 0) == 0) {
|
||||
dfp_src1 = double_from_string(tokens[i].substr(4));
|
||||
dfp_src1 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frB=", 0) == 0) {
|
||||
dfp_src2 = double_from_string(tokens[i].substr(4));
|
||||
dfp_src2 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frC=", 0) == 0) {
|
||||
dfp_src3 = double_from_string(tokens[i].substr(4));
|
||||
dfp_src3 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
ppc_state.fpscr = 0;
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
ppc_state.fpscr = 0x0;
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
ppc_state.fpscr = 0x1;
|
||||
} else if (rounding_mode.compare("RPI") == 0) {
|
||||
ppc_state.fpscr = 0x2;
|
||||
} else if (rounding_mode.compare("RNI") == 0) {
|
||||
ppc_state.fpscr = 0x3;
|
||||
} else if (rounding_mode.compare("VEN") == 0) {
|
||||
ppc_state.fpscr = FPSCR::VE;
|
||||
} else {
|
||||
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
|
||||
<< ". Exiting..." << endl;
|
||||
exit(0);
|
||||
}
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
@@ -263,31 +256,14 @@ static void read_test_float_data() {
|
||||
}
|
||||
}
|
||||
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
update_fpscr(0);
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
update_fpscr(1);
|
||||
} else if (rounding_mode.compare("RPI") == 0) {
|
||||
update_fpscr(2);
|
||||
} else if (rounding_mode.compare("RNI") == 0) {
|
||||
update_fpscr(3);
|
||||
} else if (rounding_mode.compare("VEN") == 0) {
|
||||
update_fpscr(FPSCR::VE);
|
||||
} else {
|
||||
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
|
||||
<< ". Exiting..." << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.fpr[3].dbl64_r = 0;
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src1;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[6].dbl64_r = dfp_src3;
|
||||
ppc_state.fpr[3].dbl64_r = dfp_src1;
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src3;
|
||||
|
||||
ppc_state.cr = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
@@ -295,9 +271,6 @@ static void read_test_float_data() {
|
||||
|
||||
ntested++;
|
||||
|
||||
// switch to default rounding
|
||||
fesetround(FE_TONEAREST);
|
||||
|
||||
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
|
||||
(ppc_state.fpscr != check_fpscr) ||
|
||||
(ppc_state.cr != check_cr)) {
|
||||
|
||||
+35
-163
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -77,7 +77,6 @@ static void show_help() {
|
||||
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;
|
||||
@@ -108,7 +107,7 @@ static void show_help() {
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
|
||||
static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
csh cs_handle;
|
||||
uint8_t code[10];
|
||||
size_t code_size;
|
||||
@@ -116,12 +115,12 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
|
||||
|
||||
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
|
||||
cout << "Capstone initialization error" << endl;
|
||||
return address;
|
||||
return;
|
||||
}
|
||||
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; power_on && count > 0; count--) {
|
||||
for (; count > 0; count--) {
|
||||
/* 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);
|
||||
@@ -154,7 +153,6 @@ print_bin:
|
||||
|
||||
cs_free(insn, 1);
|
||||
cs_close(&cs_handle);
|
||||
return address;
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
@@ -181,10 +179,10 @@ void exec_single_68k()
|
||||
|
||||
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
|
||||
|
||||
/* because the first two PPC instructions for each emulated 68k opcode
|
||||
/* because the first two PPC instructions for each emulated 68k once
|
||||
are resided in the emulator opcode table, we need to execute them
|
||||
one by one until the execution goes outside the opcode table. */
|
||||
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
|
||||
while (ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
|
||||
ppc_exec_single();
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
}
|
||||
@@ -201,8 +199,8 @@ void exec_until_68k(uint32_t target_addr)
|
||||
|
||||
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
|
||||
|
||||
while (power_on && target_addr != (get_reg(string("R24")) - 2)) {
|
||||
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
|
||||
while (target_addr != (get_reg(string("R24")) - 2)) {
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
|
||||
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
|
||||
ppc_exec_single();
|
||||
@@ -332,19 +330,17 @@ static void dump_mem(string& params) {
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
static uint32_t disasm(uint32_t count, uint32_t address) {
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
|
||||
for (int i = 0; power_on && i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
|
||||
cout << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_addr;
|
||||
cout << ": " << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_code;
|
||||
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << endl;
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
return ctx.instr_addr;
|
||||
}
|
||||
|
||||
static void print_gprs() {
|
||||
@@ -355,7 +351,7 @@ static void print_gprs() {
|
||||
reg_name = "R" + to_string(i);
|
||||
|
||||
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
@@ -368,7 +364,7 @@ static void print_gprs() {
|
||||
|
||||
for (auto &spr : sprs) {
|
||||
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
@@ -380,43 +376,11 @@ static void print_gprs() {
|
||||
}
|
||||
}
|
||||
|
||||
extern bool is_601;
|
||||
|
||||
static void print_mmu_regs()
|
||||
{
|
||||
printf("MSR : 0x%08X\n", ppc_state.msr);
|
||||
|
||||
printf("\nBAT registers:\n");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
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 : 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 : 0x%08X\n", ppc_state.spr[SPR::SDR1]);
|
||||
printf("\nSegment registers:\n");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("SR%-2d : 0x%08X\n", i, ppc_state.sr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
static struct sigaction old_act_sigint, new_act_sigint;
|
||||
static struct sigaction old_act_sigterm, new_act_sigterm;
|
||||
@@ -445,103 +409,35 @@ void enter_debugger() {
|
||||
std::stringstream ss;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
bool did_message = false;
|
||||
uint32_t next_addr_ppc;
|
||||
uint32_t next_addr_68k;
|
||||
bool cmd_repeat;
|
||||
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
#ifndef _WIN32
|
||||
struct winsize win_size_previous;
|
||||
ioctl(0, TIOCGWINSZ, &win_size_previous);
|
||||
#endif
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
|
||||
while (1) {
|
||||
if (power_off_reason == po_shut_down) {
|
||||
power_off_reason = po_shutting_down;
|
||||
break;
|
||||
}
|
||||
if (power_off_reason == po_restart) {
|
||||
power_off_reason = po_restarting;
|
||||
break;
|
||||
}
|
||||
power_on = true;
|
||||
cout << "dingusdbg> ";
|
||||
|
||||
if (power_off_reason == po_starting_up) {
|
||||
power_off_reason = po_none;
|
||||
cmd = "go";
|
||||
}
|
||||
else if (power_off_reason == po_disassemble_on) {
|
||||
inp = "si 1000000000";
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
ss.str(inp);
|
||||
ss >> cmd;
|
||||
}
|
||||
else if (power_off_reason == po_disassemble_off) {
|
||||
power_off_reason = po_none;
|
||||
cmd = "go";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (power_off_reason == po_enter_debugger) {
|
||||
power_off_reason = po_entered_debugger;
|
||||
}
|
||||
if (!did_message) {
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
did_message = true;
|
||||
}
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
|
||||
printf("%08X: dingusdbg> ", ppc_state.pc);
|
||||
cmd = "";
|
||||
getline(cin, inp, '\n');
|
||||
ss.str(inp);
|
||||
ss >> cmd;
|
||||
|
||||
while (power_on) {
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
|
||||
cmd = "";
|
||||
std::cin.clear();
|
||||
getline(cin, inp, '\n');
|
||||
ss.str(inp);
|
||||
ss >> cmd;
|
||||
|
||||
#ifndef _WIN32
|
||||
struct winsize win_size_current;
|
||||
ioctl(0, TIOCGWINSZ, &win_size_current);
|
||||
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
|
||||
win_size_previous = win_size_current;
|
||||
if (cmd.empty()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (power_off_reason == po_signal_interrupt) {
|
||||
power_off_reason = po_enter_debugger;
|
||||
// ignore command if interrupt happens because the input line is probably incomplete.
|
||||
last_cmd = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd_repeat = cmd.empty() && !last_cmd.empty();
|
||||
if (cmd_repeat) {
|
||||
if (cmd.empty() && !last_cmd.empty()) {
|
||||
cmd = last_cmd;
|
||||
cout << cmd << endl;
|
||||
}
|
||||
if (cmd == "help") {
|
||||
cmd = "";
|
||||
show_help();
|
||||
} else if (cmd == "quit") {
|
||||
cmd = "";
|
||||
break;
|
||||
} else if (cmd == "profile") {
|
||||
cmd = "";
|
||||
ss >> sub_cmd;
|
||||
ss >> profile_name;
|
||||
|
||||
@@ -554,7 +450,6 @@ void enter_debugger() {
|
||||
}
|
||||
}
|
||||
else if (cmd == "regs") {
|
||||
cmd = "";
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
@@ -562,9 +457,6 @@ void enter_debugger() {
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "mregs") {
|
||||
cmd = "";
|
||||
print_mmu_regs();
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
@@ -637,9 +529,8 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "go") {
|
||||
cmd = "";
|
||||
power_on = true;
|
||||
ppc_exec();
|
||||
ppc_exec(); // won't return!
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
@@ -678,10 +569,10 @@ void enter_debugger() {
|
||||
try {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
next_addr_68k = disasm_68k(inst_grab, addr);
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
next_addr_ppc = disasm(inst_grab, addr);
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
@@ -691,24 +582,14 @@ void enter_debugger() {
|
||||
try {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
if (cmd_repeat) {
|
||||
addr = next_addr_68k;
|
||||
}
|
||||
else {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
}
|
||||
next_addr_68k = disasm_68k(1, addr);
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
#endif
|
||||
} else {
|
||||
if (cmd_repeat) {
|
||||
addr = next_addr_ppc;
|
||||
}
|
||||
else {
|
||||
addr_str = "PC";
|
||||
addr = (uint32_t)get_reg(addr_str);
|
||||
}
|
||||
next_addr_ppc = disasm(1, addr);
|
||||
disasm(1, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
@@ -720,7 +601,6 @@ void enter_debugger() {
|
||||
dump_mem(expr_str);
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
} else if (cmd == "context") {
|
||||
cmd = "";
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str == "ppc" || expr_str == "PPC") {
|
||||
@@ -732,22 +612,18 @@ void enter_debugger() {
|
||||
}
|
||||
#endif
|
||||
} else if (cmd == "printenv") {
|
||||
cmd = "";
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->printenv();
|
||||
} else if (cmd == "setenv") {
|
||||
cmd = "";
|
||||
string var_name, value;
|
||||
ss >> var_name;
|
||||
std::istream::sentry se(ss); // skip white space
|
||||
getline(ss, value); // get everything up to eol
|
||||
ss >> value;
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->setenv(var_name, value);
|
||||
#ifndef _WIN32
|
||||
} else if (cmd == "nvedit") {
|
||||
cmd = "";
|
||||
cout << "===== press CNTRL-C to save =====" << endl;
|
||||
|
||||
// save original terminal state
|
||||
@@ -797,7 +673,6 @@ void enter_debugger() {
|
||||
#endif
|
||||
#ifdef DEBUG_CPU_INT
|
||||
} else if (cmd == "amicint") {
|
||||
cmd = "";
|
||||
string value;
|
||||
int irq_id;
|
||||
ss >> value;
|
||||
@@ -811,7 +686,6 @@ void enter_debugger() {
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
int_ctrl->ack_int(irq_id, 1);
|
||||
} else if (cmd == "viaint") {
|
||||
cmd = "";
|
||||
string value;
|
||||
int irq_bit;
|
||||
ss >> value;
|
||||
@@ -826,10 +700,8 @@ void enter_debugger() {
|
||||
via_obj->assert_int(irq_bit);
|
||||
#endif
|
||||
} else {
|
||||
if (!cmd.empty()) {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
cmd = "";
|
||||
}
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
}
|
||||
last_cmd = cmd;
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,6 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
void enter_debugger();
|
||||
void enter_debugger(void);
|
||||
|
||||
#endif // DEBUGGER_H_
|
||||
+16
-39
@@ -1,46 +1,23 @@
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(PlatformGlob)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
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/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.h"
|
||||
file(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/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
if (EMSCRIPTEN)
|
||||
target_link_libraries(devices PRIVATE)
|
||||
else()
|
||||
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
|
||||
endif()
|
||||
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
|
||||
@@ -0,0 +1,472 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** ADB bus definitions
|
||||
|
||||
Simulates Apple Desktop Bus (ADB) bus
|
||||
|
||||
*/
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#include <thirdparty/SDL2/include/SDL_keycode.h>
|
||||
#include <thirdparty/SDL2/include/SDL_mouse.h>
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
// set data streams as clear
|
||||
this->adb_mouse_register0 = 0x8080;
|
||||
|
||||
input_stream_len = 0;
|
||||
output_stream_len = 2;
|
||||
|
||||
adb_keybd_register3 = 0x6201;
|
||||
adb_mouse_register3 = 0x6302;
|
||||
|
||||
keyboard_access_no = adb_encoded;
|
||||
mouse_access_no = adb_relative;
|
||||
}
|
||||
|
||||
bool ADB_Bus::listen(int device, int reg) {
|
||||
if (device == keyboard_access_no) {
|
||||
if (adb_keybd_listen(reg)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (device == mouse_access_no) {
|
||||
if (adb_mouse_listen(reg)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::talk(int device, int reg, uint16_t value) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::bus_reset() {
|
||||
// temp code
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ADB_Bus::set_addr(int dev_addr, int new_addr) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::flush(int dev_addr) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
if (reg == 3) {
|
||||
output_data_stream[0] = (adb_keybd_register3 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register3 & 0xff);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_keybd_evt)) {
|
||||
// Poll our SDL key event for any keystrokes.
|
||||
switch (adb_keybd_evt.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (adb_keybd_evt.key.keysym.sym) {
|
||||
case SDLK_a:
|
||||
ask_key_pressed = 0x00;
|
||||
break;
|
||||
case SDLK_s:
|
||||
ask_key_pressed = 0x01;
|
||||
break;
|
||||
case SDLK_d:
|
||||
ask_key_pressed = 0x02;
|
||||
break;
|
||||
case SDLK_f:
|
||||
ask_key_pressed = 0x03;
|
||||
break;
|
||||
case SDLK_h:
|
||||
ask_key_pressed = 0x04;
|
||||
break;
|
||||
case SDLK_g:
|
||||
ask_key_pressed = 0x05;
|
||||
break;
|
||||
case SDLK_z:
|
||||
ask_key_pressed = 0x06;
|
||||
break;
|
||||
case SDLK_x:
|
||||
ask_key_pressed = 0x07;
|
||||
break;
|
||||
case SDLK_c:
|
||||
ask_key_pressed = 0x08;
|
||||
break;
|
||||
case SDLK_v:
|
||||
ask_key_pressed = 0x09;
|
||||
break;
|
||||
case SDLK_b:
|
||||
ask_key_pressed = 0x0B;
|
||||
break;
|
||||
case SDLK_q:
|
||||
ask_key_pressed = 0x0C;
|
||||
break;
|
||||
case SDLK_w:
|
||||
ask_key_pressed = 0x0D;
|
||||
break;
|
||||
case SDLK_e:
|
||||
ask_key_pressed = 0x0E;
|
||||
break;
|
||||
case SDLK_r:
|
||||
ask_key_pressed = 0x0F;
|
||||
break;
|
||||
case SDLK_y:
|
||||
ask_key_pressed = 0x10;
|
||||
break;
|
||||
case SDLK_t:
|
||||
ask_key_pressed = 0x11;
|
||||
break;
|
||||
case SDLK_1:
|
||||
ask_key_pressed = 0x12;
|
||||
break;
|
||||
case SDLK_2:
|
||||
ask_key_pressed = 0x13;
|
||||
break;
|
||||
case SDLK_3:
|
||||
ask_key_pressed = 0x14;
|
||||
break;
|
||||
case SDLK_4:
|
||||
ask_key_pressed = 0x15;
|
||||
break;
|
||||
case SDLK_6:
|
||||
ask_key_pressed = 0x16;
|
||||
break;
|
||||
case SDLK_5:
|
||||
ask_key_pressed = 0x17;
|
||||
break;
|
||||
case SDLK_EQUALS:
|
||||
ask_key_pressed = 0x18;
|
||||
break;
|
||||
case SDLK_9:
|
||||
ask_key_pressed = 0x19;
|
||||
break;
|
||||
case SDLK_7:
|
||||
ask_key_pressed = 0x1A;
|
||||
break;
|
||||
case SDLK_MINUS:
|
||||
ask_key_pressed = 0x1B;
|
||||
break;
|
||||
case SDLK_8:
|
||||
ask_key_pressed = 0x1C;
|
||||
break;
|
||||
case SDLK_0:
|
||||
ask_key_pressed = 0x1D;
|
||||
break;
|
||||
case SDLK_RIGHTBRACKET:
|
||||
ask_key_pressed = 0x1E;
|
||||
break;
|
||||
case SDLK_o:
|
||||
ask_key_pressed = 0x1F;
|
||||
break;
|
||||
case SDLK_u:
|
||||
ask_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_LEFTBRACKET:
|
||||
ask_key_pressed = 0x21;
|
||||
break;
|
||||
case SDLK_i:
|
||||
ask_key_pressed = 0x22;
|
||||
break;
|
||||
case SDLK_p:
|
||||
ask_key_pressed = 0x23;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
ask_key_pressed = 0x24;
|
||||
break;
|
||||
case SDLK_l:
|
||||
ask_key_pressed = 0x25;
|
||||
break;
|
||||
case SDLK_j:
|
||||
ask_key_pressed = 0x26;
|
||||
break;
|
||||
case SDLK_QUOTE:
|
||||
ask_key_pressed = 0x27;
|
||||
break;
|
||||
case SDLK_k:
|
||||
ask_key_pressed = 0x28;
|
||||
break;
|
||||
case SDLK_SEMICOLON:
|
||||
ask_key_pressed = 0x29;
|
||||
break;
|
||||
case SDLK_BACKSLASH:
|
||||
ask_key_pressed = 0x2A;
|
||||
break;
|
||||
case SDLK_COMMA:
|
||||
ask_key_pressed = 0x2B;
|
||||
break;
|
||||
case SDLK_SLASH:
|
||||
ask_key_pressed = 0x2C;
|
||||
break;
|
||||
case SDLK_n:
|
||||
ask_key_pressed = 0x2D;
|
||||
break;
|
||||
case SDLK_m:
|
||||
ask_key_pressed = 0x2E;
|
||||
break;
|
||||
case SDLK_PERIOD:
|
||||
ask_key_pressed = 0x2F;
|
||||
break;
|
||||
case SDLK_BACKQUOTE:
|
||||
ask_key_pressed = 0x32;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
ask_key_pressed = 0x35;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
ask_key_pressed = 0x3B;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
ask_key_pressed = 0x3C;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
ask_key_pressed = 0x3D;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
ask_key_pressed = 0x3E;
|
||||
break;
|
||||
case SDLK_KP_PERIOD:
|
||||
ask_key_pressed = 0x41;
|
||||
break;
|
||||
case SDLK_KP_MULTIPLY:
|
||||
ask_key_pressed = 0x43;
|
||||
break;
|
||||
case SDLK_KP_PLUS:
|
||||
ask_key_pressed = 0x45;
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
ask_key_pressed = 0x47;
|
||||
break;
|
||||
case SDLK_KP_DIVIDE:
|
||||
ask_key_pressed = 0x4B;
|
||||
break;
|
||||
case SDLK_KP_ENTER:
|
||||
ask_key_pressed = 0x4C;
|
||||
break;
|
||||
case SDLK_KP_MINUS:
|
||||
ask_key_pressed = 0x4E;
|
||||
break;
|
||||
case SDLK_KP_0:
|
||||
ask_key_pressed = 0x52;
|
||||
break;
|
||||
case SDLK_KP_1:
|
||||
ask_key_pressed = 0x53;
|
||||
break;
|
||||
case SDLK_KP_2:
|
||||
ask_key_pressed = 0x54;
|
||||
break;
|
||||
case SDLK_KP_3:
|
||||
ask_key_pressed = 0x55;
|
||||
break;
|
||||
case SDLK_KP_4:
|
||||
ask_key_pressed = 0x56;
|
||||
break;
|
||||
case SDLK_KP_5:
|
||||
ask_key_pressed = 0x57;
|
||||
break;
|
||||
case SDLK_KP_6:
|
||||
ask_key_pressed = 0x58;
|
||||
break;
|
||||
case SDLK_KP_7:
|
||||
ask_key_pressed = 0x59;
|
||||
break;
|
||||
case SDLK_KP_8:
|
||||
ask_key_pressed = 0x5B;
|
||||
break;
|
||||
case SDLK_KP_9:
|
||||
ask_key_pressed = 0x5C;
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
// ask_key_pressed = 0x33;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x40;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
// ask_key_pressed = 0x39;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_RALT:
|
||||
case SDLK_RCTRL: // Temp key for Control key
|
||||
// ask_key_pressed = 0x36;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x8;
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
// ask_key_pressed = 0x38;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x4;
|
||||
break;
|
||||
case SDLK_LALT:
|
||||
// ask_key_pressed = 0x3A;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x2;
|
||||
break;
|
||||
case SDLK_LCTRL: // Temp key for the Command/Apple key
|
||||
// ask_key_pressed = 0x37;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (adb_keybd_register0 & 0x8000) {
|
||||
adb_keybd_register0 &= 0x7FFF;
|
||||
adb_keybd_register0 &= (ask_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
} else if (adb_keybd_register0 & 0x80) {
|
||||
adb_keybd_register0 &= 0xFF7F;
|
||||
adb_keybd_register0 &= (ask_key_pressed);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
|
||||
// check if mod keys are being pressed
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register0 |= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
if (!(adb_keybd_register0 & 0x8000)) {
|
||||
adb_keybd_register0 |= 0x8000;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
} else if (adb_keybd_register0 & 0x80)
|
||||
adb_keybd_register0 |= 0x0080;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register2 &= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
confirm_ask_reg_2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((reg != 1)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if ((reg != 0) || (reg != 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_mouse_evt)) {
|
||||
if (adb_mouse_evt.motion.x) {
|
||||
this->adb_mouse_register0 &= 0x7F;
|
||||
|
||||
if (adb_mouse_evt.motion.xrel < 0) {
|
||||
if (adb_mouse_evt.motion.xrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F;
|
||||
} else if (adb_mouse_evt.motion.xrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F;
|
||||
} else {
|
||||
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adb_mouse_evt.motion.y) {
|
||||
this->adb_mouse_register0 &= 0x7F00;
|
||||
|
||||
if (adb_mouse_evt.motion.yrel < 0) {
|
||||
if (adb_mouse_evt.motion.yrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F00;
|
||||
} else if (adb_mouse_evt.motion.yrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F00;
|
||||
} else {
|
||||
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (adb_mouse_evt.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
this->adb_mouse_register0 &= 0x7FFF;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
this->adb_mouse_register0 |= 0x8000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (reg == 0) {
|
||||
output_data_stream[0] = (adb_mouse_register0 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register0 & 0xff);
|
||||
} else if (reg == 3) {
|
||||
output_data_stream[0] = (adb_mouse_register3 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register3 & 0xff);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint8_t ADB_Bus::get_input_byte(int offset) {
|
||||
return input_data_stream[offset];
|
||||
}
|
||||
|
||||
uint8_t ADB_Bus::get_output_byte(int offset) {
|
||||
return output_data_stream[offset];
|
||||
}
|
||||
|
||||
int ADB_Bus::get_input_len() {
|
||||
return input_stream_len;
|
||||
}
|
||||
|
||||
int ADB_Bus::get_output_len() {
|
||||
return output_stream_len;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 ADB_H
|
||||
#define ADB_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#endif
|
||||
|
||||
enum adb_default_values {
|
||||
adb_reserved0,
|
||||
adb_reserved1,
|
||||
adb_encoded,
|
||||
adb_relative,
|
||||
adb_absolute,
|
||||
adb_reserved5,
|
||||
adb_reserved6,
|
||||
adb_reserved7,
|
||||
adb_other8,
|
||||
adb_other9,
|
||||
adb_other10,
|
||||
adb_other11,
|
||||
adb_other12,
|
||||
adb_other13,
|
||||
adb_other14,
|
||||
adb_other15
|
||||
};
|
||||
|
||||
class ADB_Bus {
|
||||
public:
|
||||
ADB_Bus();
|
||||
~ADB_Bus() = default;
|
||||
|
||||
bool listen(int device, int reg);
|
||||
bool talk(int device, int reg, uint16_t value);
|
||||
bool bus_reset();
|
||||
bool set_addr(int dev_addr, int new_addr);
|
||||
bool flush(int dev_addr);
|
||||
|
||||
bool adb_keybd_listen(int reg);
|
||||
bool adb_mouse_listen(int reg);
|
||||
|
||||
uint8_t get_input_byte(int offset);
|
||||
uint8_t get_output_byte(int offset);
|
||||
|
||||
int get_input_len();
|
||||
int get_output_len();
|
||||
|
||||
private:
|
||||
int keyboard_access_no;
|
||||
int mouse_access_no;
|
||||
|
||||
// Keyboard Variables
|
||||
|
||||
uint16_t adb_keybd_register0;
|
||||
uint16_t adb_keybd_register2;
|
||||
uint16_t adb_keybd_register3;
|
||||
|
||||
//SDL_Event adb_keybd_evt;
|
||||
|
||||
uint8_t ask_key_pressed;
|
||||
uint8_t mod_key_pressed;
|
||||
|
||||
bool confirm_ask_reg_2;
|
||||
|
||||
// Mouse Variables
|
||||
//SDL_Event adb_mouse_evt;
|
||||
|
||||
uint16_t adb_mouse_register0;
|
||||
uint16_t adb_mouse_register3;
|
||||
|
||||
uint8_t input_data_stream[16]; // temp buffer
|
||||
int input_stream_len;
|
||||
uint8_t output_data_stream[16]; // temp buffer
|
||||
int output_stream_len;
|
||||
};
|
||||
|
||||
#endif /* ADB_H */
|
||||
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Apple Desktop Bus emulation. */
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
@@ -36,16 +35,6 @@ void AdbBus::register_device(AdbDevice* dev_obj) {
|
||||
this->devices.push_back(dev_obj);
|
||||
}
|
||||
|
||||
uint8_t AdbBus::poll() {
|
||||
for (auto dev : this->devices) {
|
||||
uint8_t dev_poll = dev->poll();
|
||||
if (dev_poll) {
|
||||
return dev_poll;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
|
||||
uint8_t dev_addr, dev_reg;
|
||||
|
||||
@@ -86,17 +75,13 @@ uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
|
||||
|
||||
this->got_answer = false;
|
||||
|
||||
for (auto dev : this->devices) {
|
||||
for (auto dev : this->devices)
|
||||
this->got_answer = dev->talk(dev_addr, dev_reg);
|
||||
if (this->got_answer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->got_answer)
|
||||
return ADB_STAT_TIMEOUT;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: unsupported ADB command 0x%X", this->name.c_str(), cmd_byte);
|
||||
ABORT_F("%s: unsupported ADB command 0x%X", this->name.c_str(), cmd_byte);
|
||||
}
|
||||
|
||||
return ADB_STAT_OK;
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ADB_BUS_H
|
||||
#define ADB_BUS_H
|
||||
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -55,11 +56,6 @@ public:
|
||||
uint8_t process_command(const uint8_t* in_data, int data_size);
|
||||
uint8_t get_output_count() { return this->output_count; };
|
||||
|
||||
// Polls devices that have a service request flag set. Returns the talk
|
||||
// command corresponding to the first device that responded with data, or
|
||||
// 0 if no device responded.
|
||||
uint8_t poll();
|
||||
|
||||
// callbacks meant to be called by devices
|
||||
const uint8_t* get_input_buf() { return this->input_buf; };
|
||||
uint8_t* get_output_buf() { return this->output_buf; };
|
||||
|
||||
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
AdbDevice::AdbDevice(std::string name) {
|
||||
@@ -39,21 +39,6 @@ int AdbDevice::device_postinit() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
uint8_t AdbDevice::poll() {
|
||||
if (!this->srq_flag) {
|
||||
return 0;
|
||||
}
|
||||
bool has_data = this->get_register_0();
|
||||
if (!has_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register 0 in bits 0-1 (both 0)
|
||||
// Talk command in bits 2-3 (both 1)
|
||||
// Device address in bits 4-7
|
||||
return 0xC | (this->my_addr << 4);
|
||||
}
|
||||
|
||||
bool AdbDevice::talk(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
if (dev_addr == this->my_addr && !this->got_collision) {
|
||||
// see if another device already responded to this command
|
||||
|
||||
@@ -24,8 +24,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ADB_DEVICE_H
|
||||
#define ADB_DEVICE_H
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
/** Common ADB device addresses/types. */
|
||||
@@ -49,10 +52,6 @@ public:
|
||||
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual uint8_t get_address() { return this->my_addr; };
|
||||
|
||||
// Attempts to poll the device. Returns the talk command corresponding to
|
||||
// the device if it has data, 0 otherwise.
|
||||
uint8_t poll();
|
||||
|
||||
protected:
|
||||
uint8_t gen_random_address();
|
||||
|
||||
|
||||
@@ -22,10 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Apple Desktop Bus Keyboard emulation. */
|
||||
|
||||
#include <devices/common/adb/adbkeyboard.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
EventManager::get_instance()->add_keyboard_handler(this, &AdbKeyboard::event_handler);
|
||||
@@ -34,50 +31,21 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
}
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
if (event.flags & KEYBOARD_EVENT_DOWN) {
|
||||
}
|
||||
else if (event.flags & KEYBOARD_EVENT_UP) {
|
||||
}
|
||||
}
|
||||
|
||||
void AdbKeyboard::reset() {
|
||||
this->my_addr = ADB_ADDR_KBD;
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 1;
|
||||
this->exc_event_flag = 2;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->pending_events.clear();
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_0() {
|
||||
if (this->pending_events.empty()) {
|
||||
return false;
|
||||
}
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = this->consume_pending_event();
|
||||
out_buf[1] = this->consume_pending_event();
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t AdbKeyboard::consume_pending_event() {
|
||||
if (this->pending_events.empty()) {
|
||||
// In most cases we have only one pending event when the host polls us,
|
||||
// but we need to fill two entries of the output buffer. We need to set
|
||||
// the key status bit to 1 (released), and the key to a non-existent
|
||||
// one (0x7F). Otherwise if we leave it empty, the host will think that
|
||||
// the 'a' key (code 0) is pressed (status 0).
|
||||
return 0xFF;
|
||||
}
|
||||
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
|
||||
this->pending_events.pop_front();
|
||||
|
||||
uint8_t key_state = 0;
|
||||
if (event->flags & KEYBOARD_EVENT_DOWN) {
|
||||
key_state = 0;
|
||||
} else if (event->flags & KEYBOARD_EVENT_UP) {
|
||||
key_state = 1;
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
|
||||
}
|
||||
|
||||
return (key_state << 7) | (event->key & 0x7F);
|
||||
return false;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
|
||||
@@ -24,15 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ADB_KEYBOARD_H
|
||||
#define ADB_KEYBOARD_H
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class KeyboardEvent;
|
||||
|
||||
class AdbKeyboard : public AdbDevice {
|
||||
public:
|
||||
AdbKeyboard(std::string name);
|
||||
@@ -51,130 +49,10 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
std::deque<std::unique_ptr<KeyboardEvent>> pending_events;
|
||||
|
||||
uint8_t consume_pending_event();
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
};
|
||||
|
||||
// ADB Extended Keyboard raw key codes (most of which eventually became virtual
|
||||
// key codes, see HIToolbox/Events.h).
|
||||
enum AdbKey {
|
||||
AdbKey_A = 0x00,
|
||||
AdbKey_B = 0x0b,
|
||||
AdbKey_C = 0x08,
|
||||
AdbKey_D = 0x02,
|
||||
AdbKey_E = 0x0e,
|
||||
AdbKey_F = 0x03,
|
||||
AdbKey_G = 0x05,
|
||||
AdbKey_H = 0x04,
|
||||
AdbKey_I = 0x22,
|
||||
AdbKey_J = 0x26,
|
||||
AdbKey_K = 0x28,
|
||||
AdbKey_L = 0x25,
|
||||
AdbKey_M = 0x2e,
|
||||
AdbKey_N = 0x2d,
|
||||
AdbKey_O = 0x1f,
|
||||
AdbKey_P = 0x23,
|
||||
AdbKey_Q = 0x0c,
|
||||
AdbKey_R = 0x0f,
|
||||
AdbKey_S = 0x01,
|
||||
AdbKey_T = 0x11,
|
||||
AdbKey_U = 0x20,
|
||||
AdbKey_V = 0x09,
|
||||
AdbKey_W = 0x0d,
|
||||
AdbKey_X = 0x07,
|
||||
AdbKey_Y = 0x10,
|
||||
AdbKey_Z = 0x06,
|
||||
|
||||
AdbKey_1 = 0x12,
|
||||
AdbKey_2 = 0x13,
|
||||
AdbKey_3 = 0x14,
|
||||
AdbKey_4 = 0x15,
|
||||
AdbKey_5 = 0x17,
|
||||
AdbKey_6 = 0x16,
|
||||
AdbKey_7 = 0x1a,
|
||||
AdbKey_8 = 0x1c,
|
||||
AdbKey_9 = 0x19,
|
||||
AdbKey_0 = 0x1d,
|
||||
|
||||
AdbKey_Minus = 0x1b,
|
||||
AdbKey_Equal = 0x18,
|
||||
AdbKey_LeftBracket = 0x21,
|
||||
AdbKey_RightBracket = 0x1e,
|
||||
AdbKey_Backslash = 0x2a,
|
||||
AdbKey_Semicolon = 0x29,
|
||||
AdbKey_Quote = 0x27,
|
||||
AdbKey_Comma = 0x2b,
|
||||
AdbKey_Period = 0x2f,
|
||||
AdbKey_Slash = 0x2c,
|
||||
|
||||
AdbKey_Tab = 0x30,
|
||||
AdbKey_Return = 0x24,
|
||||
AdbKey_Space = 0x31,
|
||||
AdbKey_Delete = 0x33,
|
||||
|
||||
AdbKey_ForwardDelete = 0x75,
|
||||
AdbKey_Help = 0x72,
|
||||
AdbKey_Home = 0x73,
|
||||
AdbKey_End = 0x77,
|
||||
AdbKey_PageUp = 0x74,
|
||||
AdbKey_PageDown = 0x79,
|
||||
|
||||
AdbKey_Grave = 0x32,
|
||||
AdbKey_Escape = 0x35,
|
||||
AdbKey_Control = 0x36,
|
||||
AdbKey_Shift = 0x38,
|
||||
AdbKey_Option = 0x3a,
|
||||
AdbKey_Command = 0x37,
|
||||
AdbKey_CapsLock = 0x39,
|
||||
|
||||
AdbKey_ArrowUp = 0x3e,
|
||||
AdbKey_ArrowDown = 0x3d,
|
||||
AdbKey_ArrowLeft = 0x3b,
|
||||
AdbKey_ArrowRight = 0x3c,
|
||||
|
||||
AdbKey_Keypad0 = 0x52,
|
||||
AdbKey_Keypad1 = 0x53,
|
||||
AdbKey_Keypad2 = 0x54,
|
||||
AdbKey_Keypad3 = 0x55,
|
||||
AdbKey_Keypad4 = 0x56,
|
||||
AdbKey_Keypad5 = 0x57,
|
||||
AdbKey_Keypad6 = 0x58,
|
||||
AdbKey_Keypad7 = 0x59,
|
||||
AdbKey_Keypad9 = 0x5c,
|
||||
AdbKey_Keypad8 = 0x5b,
|
||||
AdbKey_KeypadDecimal = 0x41,
|
||||
AdbKey_KeypadPlus = 0x45,
|
||||
AdbKey_KeypadMinus = 0x4e,
|
||||
AdbKey_KeypadMultiply = 0x43,
|
||||
AdbKey_KeypadDivide = 0x4b,
|
||||
AdbKey_KeypadEnter = 0x4c,
|
||||
AdbKey_KeypadEquals = 0x51,
|
||||
AdbKey_KeypadClear = 0x47,
|
||||
|
||||
AdbKey_F1 = 0x7a,
|
||||
AdbKey_F2 = 0x78,
|
||||
AdbKey_F3 = 0x63,
|
||||
AdbKey_F4 = 0x76,
|
||||
AdbKey_F5 = 0x60,
|
||||
AdbKey_F6 = 0x61,
|
||||
AdbKey_F7 = 0x62,
|
||||
AdbKey_F8 = 0x64,
|
||||
AdbKey_F9 = 0x65,
|
||||
AdbKey_F10 = 0x6d,
|
||||
AdbKey_F11 = 0x67,
|
||||
AdbKey_F12 = 0x6f,
|
||||
AdbKey_F13 = 0x69,
|
||||
AdbKey_F14 = 0x6b,
|
||||
AdbKey_F15 = 0x71,
|
||||
|
||||
AdbKey_ISO1= 0x0A,
|
||||
|
||||
AdbKey_JIS_Yen = 0x5D,
|
||||
AdbKey_JIS_Underscore = 0x5E,
|
||||
AdbKey_JIS_KP_Comma = 0x5F,
|
||||
AdbKey_JIS_Eisu = 0x66,
|
||||
AdbKey_JIS_Kana = 0x68,
|
||||
};
|
||||
|
||||
#endif // ADB_KEYBOARD_H
|
||||
#endif // ADB_KEYBOARD_H
|
||||
@@ -22,10 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Apple Desktop Bus Mouse emulation. */
|
||||
|
||||
#include <devices/common/adb/adbmouse.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
|
||||
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
|
||||
@@ -88,22 +85,6 @@ bool AdbMouse::get_register_0() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_1() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
// Identifier
|
||||
out_buf[0] = 'a';
|
||||
out_buf[1] = 'p';
|
||||
out_buf[2] = 'p';
|
||||
out_buf[3] = 'l';
|
||||
// Slightly higher resolution of 300 units per inch
|
||||
out_buf[4] = 300 >> 8;
|
||||
out_buf[5] = 300 & 0xFF;
|
||||
out_buf[6] = 1; // mouse
|
||||
out_buf[7] = 1; // 1 button
|
||||
this->host_obj->set_output_count(8);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbMouse::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
@@ -117,9 +98,10 @@ void AdbMouse::set_register_3() {
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 4: // switch over to extended mouse protocol
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 4: // extended mouse protocol isn't supported yet
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
|
||||
@@ -24,14 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ADB_MOUSE_H
|
||||
#define ADB_MOUSE_H
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class MouseEvent;
|
||||
|
||||
class AdbMouse : public AdbDevice {
|
||||
public:
|
||||
AdbMouse(std::string name);
|
||||
@@ -45,7 +44,6 @@ public:
|
||||
void event_handler(const MouseEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_1() override;
|
||||
void set_register_3() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -62,22 +62,8 @@ void AtaBaseDevice::device_set_signature() {
|
||||
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
uint16_t ret_data = this->get_data();
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0)
|
||||
this->r_status &= ~DRQ;
|
||||
else {
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
} else {
|
||||
return 0xFFFFU;
|
||||
}
|
||||
LOG_F(WARNING, "Retrieving data from %s", this->name.c_str());
|
||||
return 0xFFFFU;
|
||||
case ATA_Reg::ERROR:
|
||||
return this->r_error;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
@@ -91,7 +77,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
return this->r_dev_head;
|
||||
case ATA_Reg::STATUS:
|
||||
this->update_intrq(0);
|
||||
// TODO: clear pending interrupt
|
||||
return this->r_status;
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
return this->r_status;
|
||||
@@ -104,23 +90,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->post_xfer_action();
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) { // transfer complete?
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->signal_data_ready();
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_F(WARNING, "Pushing data to %s", this->name.c_str());
|
||||
break;
|
||||
case ATA_Reg::FEATURES:
|
||||
this->r_features = value;
|
||||
@@ -181,15 +151,3 @@ void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
|
||||
this->intrq_state = new_intrq_state;
|
||||
this->host_obj->report_intrq(new_intrq_state);
|
||||
}
|
||||
|
||||
void AtaBaseDevice::prepare_xfer(int xfer_size, int block_size) {
|
||||
this->chunk_cnt = std::min(xfer_size, block_size);
|
||||
this->xfer_cnt = xfer_size;
|
||||
this->chunk_size = block_size;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::signal_data_ready() {
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
@@ -25,14 +25,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATA_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include "endianswap.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
class IdeChannel;
|
||||
|
||||
class AtaBaseDevice : public HWComponent, public AtaInterface
|
||||
{
|
||||
@@ -57,7 +55,6 @@ public:
|
||||
virtual void device_set_signature();
|
||||
void device_control(const uint8_t new_ctrl);
|
||||
void update_intrq(uint8_t new_intrq_state);
|
||||
void signal_data_ready();
|
||||
|
||||
bool has_data() {
|
||||
return data_ptr && xfer_cnt;
|
||||
@@ -70,8 +67,6 @@ public:
|
||||
protected:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
|
||||
void prepare_xfer(int xfer_size, int block_size);
|
||||
|
||||
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
|
||||
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
|
||||
uint8_t intrq_state = 0; // INTRQ deasserted
|
||||
@@ -91,14 +86,10 @@ protected:
|
||||
uint8_t r_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08;
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint16_t *cur_data_ptr = nullptr;
|
||||
uint8_t data_buf[512] = {};
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
int chunk_size = 0;
|
||||
|
||||
std::function<void()> post_xfer_action = nullptr;
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint8_t data_buf[512] = {};
|
||||
int data_pos = 0;
|
||||
int xfer_cnt = 0;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -79,11 +79,6 @@ enum ATAPI_Features : uint8_t {
|
||||
OVERLAP = 1 << 1
|
||||
};
|
||||
|
||||
/** Device/Head register bits. */
|
||||
enum ATA_Dev_Head : uint8_t {
|
||||
LBA = 1 << 6,
|
||||
};
|
||||
|
||||
/** Status register bits. */
|
||||
enum ATA_Status : uint8_t {
|
||||
ERR = 0x01,
|
||||
@@ -139,7 +134,6 @@ enum ATA_Cmd : uint8_t {
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
|
||||
+50
-199
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,140 +22,82 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file ATA hard disk emulation. */
|
||||
|
||||
#include <devices/common/ata/atahd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaHardDisk::AtaHardDisk(std::string name) : AtaBaseDevice(name, DEVICE_TYPE_ATA) {
|
||||
}
|
||||
|
||||
int AtaHardDisk::device_postinit() {
|
||||
std::string hdd_config = GET_STR_PROP("hdd_config");
|
||||
if (hdd_config.empty()) {
|
||||
LOG_F(ERROR, "%s: hdd_config property is empty", this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
parse_device_path(hdd_config, bus_id, dev_num);
|
||||
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (!hdd_image_path.empty()) {
|
||||
this->insert_image(hdd_image_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
AtaHardDisk::AtaHardDisk() : AtaBaseDevice("ATA-HD", DEVICE_TYPE_ATA) {
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
if (!this->hdd_img.open(filename)) {
|
||||
ABORT_F("%s: could not open image file", this->name.c_str());
|
||||
}
|
||||
this->hdd_img.open(filename, std::fstream::out | std::fstream::in | std::fstream::binary);
|
||||
|
||||
this->img_size = this->hdd_img.size();
|
||||
this->total_sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
this->calc_chs_params();
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
} else {
|
||||
ABORT_F("AtaHardDisk: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
int AtaHardDisk::perform_command() {
|
||||
int AtaHardDisk::perform_command()
|
||||
{
|
||||
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
|
||||
this->r_status |= BSY;
|
||||
this->r_error = 0;
|
||||
|
||||
this->r_status &= ~DRDY;
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
break;
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
hdd_img.read(buffer, offset, xfer_size);
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
// those commands should generate IRQ for each sector
|
||||
this->prepare_xfer(xfer_size, ATA_HD_SEC_SIZE);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
break;
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.read(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
break;
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->prepare_xfer(sec_count * ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, this->chunk_size);
|
||||
this->cur_fpos += this->chunk_size;
|
||||
};
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
}
|
||||
break;
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.write(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
// update fictive disk geometry with parameters from host
|
||||
this->sectors = this->r_sect_count;
|
||||
this->heads = (this->r_dev_head & 0xF) + 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1;
|
||||
this->device_set_signature();
|
||||
break;
|
||||
case FLUSH_CACHE: // used by the XNU kernel driver
|
||||
this->r_status &= ~(BSY | DRQ | ERR);
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case DIAGNOSTICS: {
|
||||
this->r_status |= DRQ;
|
||||
int ret_code = this->r_error;
|
||||
this->r_status &= ~DRQ;
|
||||
return ret_code;
|
||||
}
|
||||
break;
|
||||
case IDENTIFY_DEVICE:
|
||||
this->prepare_identify_info();
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->prepare_xfer(ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
this->signal_data_ready();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
if (this->r_features == 3) {
|
||||
switch(this->r_sect_count >> 3) {
|
||||
case 0:
|
||||
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(INFO, "%s: PIO transfer mode set to 0x%X", this->name.c_str(),
|
||||
this->r_sect_count & 7);
|
||||
break;
|
||||
case 4:
|
||||
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
|
||||
this->r_sect_count & 7);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
|
||||
this->name.c_str(), this->r_features);
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
this->r_status |= DRQ;
|
||||
std::memcpy(buffer, this->hd_id_data, ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
|
||||
@@ -163,98 +105,7 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRDY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaHardDisk::prepare_identify_info() {
|
||||
uint16_t *buf_ptr = (uint16_t *)this->data_buf;
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
|
||||
buf_ptr[57] = this->total_sectors & 0xFFFFU;
|
||||
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
|
||||
|
||||
// report LBA capacity
|
||||
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
|
||||
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
|
||||
}
|
||||
|
||||
uint64_t AtaHardDisk::get_lba() {
|
||||
if (this->r_dev_head & ATA_Dev_Head::LBA) {
|
||||
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
|
||||
(this->r_cylinder_lo << 8) | (this->r_sect_num);
|
||||
} else { // translate old fashioned CHS addressing to LBA
|
||||
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
|
||||
uint8_t h = this->r_dev_head & 0xF;
|
||||
uint8_t s = this->r_sect_num;
|
||||
|
||||
if (!s) {
|
||||
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
|
||||
return -1ULL;
|
||||
} else
|
||||
return (this->heads * c + h) * this->sectors + s - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void AtaHardDisk::calc_chs_params() {
|
||||
unsigned num_blocks, heads, sectors, max_sectors;
|
||||
|
||||
LOG_F(INFO, "%s: total sectors %d", this->name.c_str(), this->total_sectors);
|
||||
|
||||
// use PC BIOS limit to keep number of sectors small for smaller disks
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT)
|
||||
max_sectors = 255;
|
||||
else
|
||||
max_sectors = 63;
|
||||
|
||||
num_blocks = this->total_sectors;
|
||||
|
||||
for (heads = 16; heads > 0; heads--)
|
||||
if (!(num_blocks % heads))
|
||||
break;
|
||||
|
||||
this->heads = heads;
|
||||
|
||||
if (!heads) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable number of heads",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
num_blocks /= heads;
|
||||
|
||||
for (sectors = max_sectors; sectors > 0; sectors--) {
|
||||
if (!(num_blocks % sectors)) {
|
||||
if (num_blocks / sectors < 65536)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->sectors = sectors;
|
||||
|
||||
if (!sectors) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
this->cylinders = num_blocks / sectors;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), this->cylinders,
|
||||
this->heads, this->sectors);
|
||||
}
|
||||
|
||||
static const PropMap AtaHardDiskProperties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtaHardDiskDescriptor =
|
||||
{AtaHardDisk::create, {}, AtaHardDiskProperties};
|
||||
|
||||
REGISTER_DEVICE(AtaHardDisk, AtaHardDiskDescriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,44 +25,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATA_HARD_DISK_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
#define ATA_BIOS_LIMIT 16514064
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtaHardDisk(std::string name);
|
||||
AtaHardDisk();
|
||||
~AtaHardDisk() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AtaHardDisk>(new AtaHardDisk("ATA-HD"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void insert_image(std::string filename);
|
||||
int perform_command() override;
|
||||
|
||||
protected:
|
||||
void prepare_identify_info();
|
||||
uint64_t get_lba();
|
||||
void calc_chs_params();
|
||||
|
||||
private:
|
||||
ImgFile hdd_img;
|
||||
uint64_t img_size = 0;
|
||||
uint32_t total_sectors = 0;
|
||||
uint64_t cur_fpos = 0;
|
||||
|
||||
// fictive disk geometry for CHS-to-LBA translation
|
||||
uint16_t cylinders;
|
||||
uint8_t heads;
|
||||
uint8_t sectors;
|
||||
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
char * buffer = new char[1 <<17];
|
||||
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
|
||||
@@ -162,6 +162,7 @@ int AtapiBaseDevice::perform_command() {
|
||||
this->data_buf[0] = 0xC0;
|
||||
this->data_buf[1] = 0x85;
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->data_pos = 0;
|
||||
this->xfer_cnt = 512;
|
||||
this->status_expected = false;
|
||||
this->data_out_phase();
|
||||
@@ -195,6 +196,12 @@ void AtapiBaseDevice::data_out_phase() {
|
||||
this->signal_data_ready();
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::signal_data_ready() {
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::present_status() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO;
|
||||
this->r_int_reason |= ATAPI_Int_Reason::CoD;
|
||||
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATAPI_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
@@ -48,6 +49,7 @@ public:
|
||||
|
||||
// methods with default implementation
|
||||
virtual void data_out_phase();
|
||||
virtual void signal_data_ready();
|
||||
virtual void present_status();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/atapicdrom.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/scsi/scsi.h> // ATAPI CDROM reuses SCSI commands (sic!)
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
@@ -34,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtapiCdrom::AtapiCdrom(std::string name) : CdromDrive(), AtapiBaseDevice(name) {
|
||||
AtapiCdrom::AtapiCdrom(std::string name) : AtapiBaseDevice(name) {
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->status_error(sense_key, asc);
|
||||
@@ -280,7 +279,7 @@ uint16_t AtapiCdrom::get_data() {
|
||||
// For Mode 1 CD-ROMs:
|
||||
int area_start;
|
||||
int area_end = 0;
|
||||
|
||||
|
||||
ret_data = 0xffff;
|
||||
|
||||
if (this->sector_areas & 0x80) {
|
||||
|
||||
@@ -32,7 +32,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
+58
-112
@@ -24,8 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
@@ -39,18 +37,9 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
|
||||
void DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
if (is_writable) *is_writable = res.is_writable;
|
||||
DMACmd* cmd_host = (DMACmd*)res.host_va;
|
||||
p_cmd->req_count = READ_WORD_LE_A(&cmd_host->req_count);
|
||||
p_cmd->cmd_bits = cmd_host->cmd_bits;
|
||||
p_cmd->cmd_key = cmd_host->cmd_key;
|
||||
p_cmd->address = READ_DWORD_LE_A(&cmd_host->address);
|
||||
p_cmd->cmd_arg = READ_DWORD_LE_A(&cmd_host->cmd_arg);
|
||||
p_cmd->res_count = READ_WORD_LE_A(&cmd_host->res_count);
|
||||
p_cmd->xfer_stat = READ_WORD_LE_A(&cmd_host->xfer_stat);
|
||||
return cmd_host;
|
||||
memcpy((uint8_t*)p_cmd, res.host_va, 16);
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
@@ -65,8 +54,7 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
bool cmd_is_writable;
|
||||
DMACmd *cmd_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &cmd_is_writable);
|
||||
fetch_cmd(this->cmd_ptr, &cmd_struct);
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
|
||||
|
||||
@@ -78,29 +66,23 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->res_count = 0;
|
||||
this->cmd_in_progress = true;
|
||||
break;
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
LOG_F(ERROR, "%s: Invalid key %d in STORE_QUAD", this->get_name().c_str(),
|
||||
cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, nullptr);
|
||||
LOG_F(9, "Invalid key %d in STORE_QUAD", cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, true);
|
||||
break;
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6) {
|
||||
LOG_F(ERROR, "%s: Invalid key %d in LOAD_QUAD", this->get_name().c_str(),
|
||||
cmd_struct.cmd_key & 7);
|
||||
}
|
||||
if (!cmd_is_writable)
|
||||
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
|
||||
this->xfer_quad(&cmd_struct, cmd_host);
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
LOG_F(9, "Invalid key %d in LOAD_QUAD", cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, false);
|
||||
break;
|
||||
case DBDMA_Cmd::NOP:
|
||||
this->finish_cmd();
|
||||
@@ -110,8 +92,7 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
this->cmd_in_progress = false;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: Unsupported DMA command 0x%X", this->get_name().c_str(),
|
||||
this->cur_cmd);
|
||||
LOG_F(ERROR, "Unsupported DMA command 0x%X", this->cur_cmd);
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
@@ -120,6 +101,7 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
}
|
||||
|
||||
void DMAChannel::finish_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
bool branch_taken = false;
|
||||
|
||||
// obtain real pointer to the descriptor of the command to be finished
|
||||
@@ -130,7 +112,7 @@ void DMAChannel::finish_cmd() {
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i" interrupt, "b" branch, and "w" wait bits
|
||||
// perform actions under control of "i", "b" and "w" bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.w (wait) bits
|
||||
if (cmd_desc[2] & 3) {
|
||||
@@ -169,11 +151,9 @@ void DMAChannel::finish_cmd() {
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
// 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->res_count);
|
||||
this->queue_len = 0;
|
||||
this->res_count = 0;
|
||||
// all INPUT and OUTPUT commands update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::STORE_QUAD && res.is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len & 0xFFFFUL);
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
@@ -182,8 +162,9 @@ void DMAChannel::finish_cmd() {
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, const bool is_store) {
|
||||
MapDmaResult res;
|
||||
uint8_t *src, *dst;
|
||||
uint32_t addr;
|
||||
|
||||
// parse and fix reqCount
|
||||
@@ -195,47 +176,38 @@ void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
} else {
|
||||
xfer_size = 1;
|
||||
}
|
||||
this->res_count = cmd_desc->req_count; // this is the value that gets written to cmd.resCount
|
||||
|
||||
addr = cmd_desc->address;
|
||||
if (addr & (xfer_size - 1)) {
|
||||
LOG_F(ERROR, "%s: QUAD address 0x%08x is not aligned!", this->get_name().c_str(), addr);
|
||||
addr &= ~(xfer_size - 1);
|
||||
}
|
||||
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
addr = cmd_desc->address & ~(xfer_size - 1);
|
||||
|
||||
// prepare data pointers and perform data transfer
|
||||
if (!cmd_host) {
|
||||
if (is_store) {
|
||||
res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
src = res.host_va + 8; // move src to cmd.data32
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
if (res.type & RT_MMIO) {
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base, cmd_desc->cmd_arg, xfer_size);
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base,
|
||||
read_mem_rev(src, xfer_size), xfer_size);
|
||||
} else if (res.is_writable) {
|
||||
switch (xfer_size) {
|
||||
case 1: *res.host_va = cmd_desc->cmd_arg; break;
|
||||
case 2: WRITE_WORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
case 4: WRITE_DWORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "SOS: DMA access is not to RAM %08X!\n", addr);
|
||||
std::memcpy(res.host_va, src, xfer_size);
|
||||
}
|
||||
} else {
|
||||
uint32_t value;
|
||||
if (res.type & RT_MMIO) {
|
||||
value = res.dev_obj->read(res.dev_base, addr - res.dev_base, xfer_size);
|
||||
} else {
|
||||
switch (xfer_size) {
|
||||
case 1: value = *res.host_va; break;
|
||||
case 2: value = READ_WORD_LE_A(res.host_va); break;
|
||||
case 4: value = READ_DWORD_LE_A(res.host_va); break;
|
||||
default: value = 0; break;
|
||||
res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
if (res.is_writable) {
|
||||
dst = res.host_va + 8; // move dst to cmd.data32
|
||||
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
if (res.type & RT_MMIO) {
|
||||
write_mem_rev(dst,
|
||||
res.dev_obj->read(res.dev_base, addr - res.dev_base, xfer_size),
|
||||
xfer_size);
|
||||
} else {
|
||||
std::memcpy(dst, res.host_va, xfer_size);
|
||||
}
|
||||
}
|
||||
WRITE_DWORD_LE_A(&cmd_host->cmd_arg, value);
|
||||
}
|
||||
|
||||
if (cmd_desc->cmd_bits & 0xC)
|
||||
ABORT_F("%s: cmd_bits.b should be zero for LOAD/STORE_QUAD!",
|
||||
this->get_name().c_str());
|
||||
ABORT_F("DBDMA: cmd_bits.b should be zero for LOAD/STORE_QUAD!");
|
||||
|
||||
this->finish_cmd();
|
||||
}
|
||||
@@ -258,10 +230,7 @@ void DMAChannel::update_irq() {
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (int_ctrl)
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,8 +238,7 @@ void DMAChannel::update_irq() {
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
if (size != 4) {
|
||||
ABORT_F("%s: non-DWORD read from a DMA channel not supported",
|
||||
this->get_name().c_str());
|
||||
ABORT_F("DBDMA: non-DWORD read from a DMA channel not supported");
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
@@ -281,8 +249,7 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
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);
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -292,8 +259,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint16_t mask, old_stat, new_stat;
|
||||
|
||||
if (size != 4) {
|
||||
ABORT_F("%s: non-DWORD writes to a DMA channel not supported",
|
||||
this->get_name().c_str());
|
||||
ABORT_F("DBDMA: non-DWORD writes to a DMA channel not supported");
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
@@ -303,7 +269,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
|
||||
LOG_F(9, "%s: New ChannelStatus value = 0x%X", this->get_name().c_str(), new_stat);
|
||||
LOG_F(9, "New ChannelStatus value = 0x%X", new_stat);
|
||||
|
||||
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
|
||||
if ((new_stat & 0xFF) != (old_stat & 0xFF)) {
|
||||
@@ -347,16 +313,13 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI:
|
||||
if (value != 0) {
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x", this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
case DMAReg::CMD_PTR_HI: // Mac OS X writes this optional register with zero
|
||||
LOG_F(9, "CommandPtrHi set to 0x%X", value);
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->cmd_ptr = value;
|
||||
LOG_F(9, "%s: CommandPtrLo set to 0x%X", this->get_name().c_str(),
|
||||
this->cmd_ptr);
|
||||
LOG_F(9, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
@@ -369,8 +332,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->wait_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +342,7 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Dead/idle channel -> no more data", this->get_name().c_str());
|
||||
LOG_F(WARNING, "Dead/idle channel -> no more data");
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
@@ -392,18 +354,15 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
// dequeue data if any
|
||||
if (this->queue_len) {
|
||||
if (this->queue_len >= req_len) {
|
||||
LOG_F(9, "%s: Return req_len = %d data", this->get_name().c_str(), req_len);
|
||||
LOG_F(9, "Return req_len = %d data", req_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = req_len;
|
||||
this->queue_len -= req_len;
|
||||
this->res_count += req_len;
|
||||
this->queue_data += req_len;
|
||||
} else { // return less data than req_len
|
||||
LOG_F(9, "%s: Return queue_len = %d data", this->get_name().c_str(),
|
||||
this->queue_len);
|
||||
LOG_F(9, "Return queue_len = %d data", this->queue_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = this->queue_len;
|
||||
this->res_count += this->queue_len;
|
||||
this->queue_len = 0;
|
||||
}
|
||||
return DmaPullResult::MoreData; // tell the caller there is more data
|
||||
@@ -414,8 +373,7 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
|
||||
int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "%s: attempt to push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
LOG_F(WARNING, "DBDMA: attempt to push data to dead/idle channel");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -428,7 +386,6 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
std::memcpy(this->queue_data, src_ptr, len);
|
||||
this->queue_data += len;
|
||||
this->res_count += len;
|
||||
this->queue_len -= len;
|
||||
}
|
||||
|
||||
@@ -440,16 +397,7 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool DMAChannel::is_in_active() {
|
||||
bool DMAChannel::is_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
@@ -460,18 +408,17 @@ bool DMAChannel::is_in_active() {
|
||||
|
||||
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());
|
||||
LOG_F(WARNING, "Cannot start DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
}
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
|
||||
// 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
|
||||
@@ -484,22 +431,21 @@ void DMAChannel::start() {
|
||||
|
||||
void DMAChannel::resume() {
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "%s: Cannot resume DMA channel, PAUSE bit is set",
|
||||
this->get_name().c_str());
|
||||
LOG_F(WARNING, "Cannot resume DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
|
||||
LOG_F(INFO, "Resuming DMA channel");
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
LOG_F(9, "%s: Aborting DMA channel", this->get_name().c_str());
|
||||
LOG_F(9, "Aborting DMA channel");
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "%s: Pausing DMA channel", this->get_name().c_str());
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
+14
-38
@@ -30,58 +30,37 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
class InterruptCtrl;
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_HI = 8, // not implemented
|
||||
CMD_PTR_HI = 8,
|
||||
CMD_PTR_LO = 12,
|
||||
INT_SELECT = 16,
|
||||
BRANCH_SELECT = 20,
|
||||
WAIT_SELECT = 24,
|
||||
// TANSFER_MODES = 28,
|
||||
// DATA_2_PTR_HI = 32, // not implemented
|
||||
// DATA_2_PTR_LO = 36,
|
||||
// RESERVED_1 = 40,
|
||||
// ADDRESS_HI = 44,
|
||||
// RESERVED_2_0 = 48,
|
||||
// RESERVED_2_1 = 52,
|
||||
// RESERVED_2_2 = 56,
|
||||
// RESERVED_2_3 = 60,
|
||||
// UNIMPLEMENTED = 64,
|
||||
// UNDEFINED = 128,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
enum : uint16_t {
|
||||
CH_STAT_S0 = 0x0001, // general purpose status and control
|
||||
CH_STAT_S1 = 0x0002, // general purpose status and control
|
||||
CH_STAT_S2 = 0x0004, // general purpose status and control
|
||||
CH_STAT_S3 = 0x0008, // general purpose status and control
|
||||
CH_STAT_S4 = 0x0010, // general purpose status and control
|
||||
CH_STAT_S5 = 0x0020, // general purpose status and control
|
||||
CH_STAT_S6 = 0x0040, // general purpose status and control
|
||||
CH_STAT_S7 = 0x0080, // general purpose status and control
|
||||
CH_STAT_BT = 0x0100, // hardware status bit
|
||||
CH_STAT_ACTIVE = 0x0400, // hardware status bit
|
||||
CH_STAT_DEAD = 0x0800, // hardware status bit
|
||||
CH_STAT_WAKE = 0x1000, // command bit set by software and cleared by hardware once the action has been performed
|
||||
CH_STAT_FLUSH = 0x2000, // command bit set by software and cleared by hardware once the action has been performed
|
||||
CH_STAT_PAUSE = 0x4000, // control bit set and cleared by software
|
||||
CH_STAT_RUN = 0x8000 // control bit set and cleared by software
|
||||
CH_STAT_ACTIVE = 0x400,
|
||||
CH_STAT_DEAD = 0x800,
|
||||
CH_STAT_WAKE = 0x1000,
|
||||
CH_STAT_FLUSH = 0x2000,
|
||||
CH_STAT_PAUSE = 0x4000,
|
||||
CH_STAT_RUN = 0x8000
|
||||
};
|
||||
|
||||
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
|
||||
typedef struct DMACmd {
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits; // wait: & 3, branch: & 0xC, interrupt: & 0x30, reserved: & 0xc0
|
||||
uint8_t cmd_key; // key: & 7, reserved: & 8, cmd: >> 4
|
||||
uint8_t cmd_bits;
|
||||
uint8_t cmd_key;
|
||||
uint32_t address;
|
||||
uint32_t cmd_arg;
|
||||
uint16_t res_count;
|
||||
@@ -105,16 +84,14 @@ typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
public:
|
||||
DMAChannel(std::string name) : DmaBidirChannel(name) {}
|
||||
DMAChannel() = default;
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
|
||||
|
||||
bool is_out_active();
|
||||
bool is_in_active();
|
||||
bool is_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
int push_data(const char* src_ptr, int len);
|
||||
|
||||
@@ -124,10 +101,10 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
|
||||
void fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
uint8_t interpret_cmd(void);
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
|
||||
void xfer_quad(const DMACmd *cmd_desc, const bool is_store);
|
||||
void update_irq();
|
||||
|
||||
void start(void);
|
||||
@@ -143,7 +120,6 @@ private:
|
||||
uint32_t cmd_ptr = 0;
|
||||
uint32_t queue_len = 0;
|
||||
uint8_t* queue_data = 0;
|
||||
uint32_t res_count = 0;
|
||||
uint32_t int_select = 0;
|
||||
uint32_t branch_select = 0;
|
||||
uint32_t wait_select = 0;
|
||||
|
||||
@@ -24,8 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DMA_CORE_H
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
MoreData, // data source has more data to be pulled
|
||||
@@ -34,41 +33,18 @@ enum DmaPullResult : int {
|
||||
|
||||
class DmaOutChannel {
|
||||
public:
|
||||
DmaOutChannel(std::string name) { this->name = name; };
|
||||
|
||||
virtual bool is_out_active() { return true; };
|
||||
virtual bool is_active() { return true; };
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class DmaInChannel {
|
||||
public:
|
||||
DmaInChannel(std::string name) { this->name = name; };
|
||||
|
||||
virtual bool is_in_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
|
||||
public:
|
||||
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
|
||||
DmaInChannel(name + std::string(" In")) { this->name = name; };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -39,8 +39,6 @@ enum HWCompType : uint64_t {
|
||||
I2C_DEV = 1ULL << 9, // I2C device
|
||||
ADB_HOST = 1ULL << 12, // ADB host
|
||||
ADB_DEV = 1ULL << 13, // ADB device
|
||||
IOBUS_HOST = 1ULL << 14, // IOBus host
|
||||
IOBUS_DEV = 1ULL << 15, // IOBus device
|
||||
INT_CTRL = 1ULL << 16, // interrupt controller
|
||||
SCSI_BUS = 1ULL << 20, // SCSI bus
|
||||
SCSI_HOST = 1ULL << 21, // SCSI host adapter
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,49 +28,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** Enumerator for various interrupt sources. */
|
||||
enum IntSrc : uint32_t {
|
||||
INT_UNKNOWN = 0,
|
||||
VIA_CUDA,
|
||||
SCSI_MESH,
|
||||
SCSI_CURIO,
|
||||
SWIM3,
|
||||
SCCA,
|
||||
SCCB,
|
||||
ETHERNET,
|
||||
NMI,
|
||||
EXT1,
|
||||
IDE0,
|
||||
IDE1,
|
||||
DAVBUS,
|
||||
PERCH1,
|
||||
PERCH2,
|
||||
PCI_A,
|
||||
PCI_B,
|
||||
PCI_C,
|
||||
PCI_D,
|
||||
PCI_E,
|
||||
PCI_F,
|
||||
PCI_GPU,
|
||||
PCI_PERCH,
|
||||
BANDIT1,
|
||||
BANDIT2,
|
||||
CONTROL,
|
||||
SIXTY6,
|
||||
PLANB,
|
||||
VCI,
|
||||
PLATINUM,
|
||||
DMA_SCSI_MESH,
|
||||
DMA_SCSI_CURIO,
|
||||
DMA_SWIM3,
|
||||
DMA_IDE0,
|
||||
DMA_IDE1,
|
||||
DMA_SCCA_Tx,
|
||||
DMA_SCCA_Rx,
|
||||
DMA_SCCB_Tx,
|
||||
DMA_SCCB_Rx,
|
||||
DMA_DAVBUS_Tx,
|
||||
DMA_DAVBUS_Rx,
|
||||
DMA_ETHERNET_Tx,
|
||||
DMA_ETHERNET_Rx,
|
||||
VIA_CUDA = 1,
|
||||
SCSI1 = 2,
|
||||
SWIM3 = 3,
|
||||
SCC = 4,
|
||||
ETHERNET = 5,
|
||||
NMI = 6,
|
||||
IDE0 = 7,
|
||||
IDE1 = 8,
|
||||
};
|
||||
|
||||
/** Base class for interrupt controllers. */
|
||||
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
I2CProm::I2CProm(uint8_t dev_addr, int size)
|
||||
{
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 SAA7187 Digital video encoder emulation. */
|
||||
|
||||
#include <devices/common/i2c/saa7187.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
}
|
||||
|
||||
void Saa7187VideoEncoder::start_transaction()
|
||||
{
|
||||
LOG_F(INFO, "Saa7187: start_transaction");
|
||||
this->pos = 0; // reset read/write position
|
||||
}
|
||||
|
||||
bool Saa7187VideoEncoder::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(ERROR, "Saa7187: send_subaddress 0x%02x", sub_addr);
|
||||
//this->pos = sub_addr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Saa7187VideoEncoder::send_byte(uint8_t data)
|
||||
{
|
||||
if (this->pos == 0) {
|
||||
this->reg_num = data;
|
||||
LOG_F(INFO, "Saa7187: write 0x%02x", data);
|
||||
}
|
||||
else {
|
||||
if (this->reg_num < Saa7187Regs::last_reg) {
|
||||
this->regs[this->reg_num] = data;
|
||||
LOG_F(INFO, "Saa7187: write 0x%02x = 0x%02x", this->reg_num, data);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "Saa7187: write 0x%02x = 0x%02x", this->reg_num, data);
|
||||
}
|
||||
this->reg_num++;
|
||||
}
|
||||
this->pos++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Saa7187VideoEncoder::receive_byte(uint8_t* p_data)
|
||||
{
|
||||
LOG_F(ERROR, "Saa7187: receive_byte");
|
||||
*p_data = 0x00;
|
||||
return true;
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 SAA7187 Digital video encoder definitions. */
|
||||
|
||||
#ifndef SAA7187_H
|
||||
#define SAA7187_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
namespace Saa7187Regs {
|
||||
|
||||
enum Saa7187Regs : uint8_t { // i2c address is 0x44; fatman is at 0x46?
|
||||
IPC = 0x3a, // Input port control
|
||||
FMT0 = 0x01,
|
||||
FMT1 = 0x02,
|
||||
VUV2C = 0x04,
|
||||
VY2C = 0x08,
|
||||
CBENB = 0x80,
|
||||
OSDY0 = 0x42, // OSD LUT, 8 colors
|
||||
OSDU0 ,
|
||||
OSDV0 ,
|
||||
CHPS = 0x5a, // Chrominance phase
|
||||
GAINU = 0x5b, // Gain U
|
||||
GAINV = 0x5c, // Gain V
|
||||
BLCKL = 0x5d, // Gain U MSB, black level
|
||||
BLCKL0_5 = 0x3f,
|
||||
GAINU8 = 0x80,
|
||||
BLNNL = 0x5e, // Gain V MSB, blanking level
|
||||
BLNNL0_5 = 0x3f,
|
||||
GAINV8 = 0x80,
|
||||
CCRS = 0x60, // Cross-colour select
|
||||
CCRS0 = 0x40,
|
||||
CCRS1 = 0x80,
|
||||
SCTRL = 0x61, // Standard control
|
||||
FISE = 0x01,
|
||||
PAL = 0x02,
|
||||
SCBW = 0x04,
|
||||
RTCE = 0x08,
|
||||
YGS = 0x10,
|
||||
INPI1 = 0x20,
|
||||
DOWN = 0x40,
|
||||
BSTA = 0x62, // Burst amplitude
|
||||
BSTA0_6 = 0x7f,
|
||||
SQP = 0x80,
|
||||
FSC0 = 0x63, // Subcarrier 0
|
||||
FSC8 = 0x64, // Subcarrier 1
|
||||
FSC16 = 0x65, // Subcarrier 2
|
||||
FSC24 = 0x66, // Subcarrier 3
|
||||
// 0x25555555 = NTSC
|
||||
// 0x26798c0c = PAL
|
||||
L21O0 = 0x67, // Line 21 odd 0
|
||||
L21O1 = 0x68, // Line 21 odd 1
|
||||
L21E0 = 0x69, // Line 21 even 0
|
||||
L21E1 = 0x6a, // Line 21 even 1
|
||||
SCCLN = 0x6b, // CC line
|
||||
SCCLN0_4 = 0x1f,
|
||||
RCTRL = 0x6c, // RCV port control
|
||||
PRCV2 = 0x01,
|
||||
ORCV2 = 0x02,
|
||||
CBLF = 0x04,
|
||||
PRCV1 = 0x08,
|
||||
ORCV1 = 0x10,
|
||||
TRCV2 = 0x20,
|
||||
SRCV10 = 0x40,
|
||||
RCV11 = 0x80,
|
||||
RCM_CC = 0x6d, // RCM, CC mode
|
||||
CCEN0 = 0x01,
|
||||
CCEN1 = 0x02,
|
||||
SRCM10 = 0x04,
|
||||
SRCM11 = 0x08,
|
||||
HTRIG0 = 0x6e, // Horizontal trigger
|
||||
HTRIG8 = 0x6f, // Horizontal trigger
|
||||
HTRIG8_10 = 0x07,
|
||||
RES_VTRIG = 0x70, // fsc reset mode, Vertical trigger
|
||||
VTRIG0_4 = 0x1f,
|
||||
SBLBN = 0x20,
|
||||
PHRES0 = 0x40,
|
||||
HRES1 = 0x80,
|
||||
BMRQ0 = 0x71, // Begin master request
|
||||
EMRQ0 = 0x72, // End master request
|
||||
BMRQ8_EMRQ8 = 0x73, // MSBs master request
|
||||
BMRQ08_10 = 0x07,
|
||||
EMRQ08_10 = 0x70,
|
||||
BRCV0 = 0x77, // Begin RCV2 output
|
||||
ERCV0 = 0x78, // End RCV2 output
|
||||
BRCV8_ERCV8 = 0x79, // MSBs RCV2 output
|
||||
BRCV08_10 = 0x07,
|
||||
ERCV08_10 = 0x70,
|
||||
FLEN = 0x7a, // Field length
|
||||
FAL = 0x7b, // First active line
|
||||
LAL = 0x7c, // Last active line
|
||||
FLEN8_FAL8_LAL8 = 0x7d, // MSBs field control
|
||||
FLEN8_9 = 0x03,
|
||||
FAL8 = 0x10,
|
||||
LAL8 = 0x20,
|
||||
last_reg = 0x7e,
|
||||
};
|
||||
|
||||
}; // namespace Saa7187Regs
|
||||
|
||||
class Saa7187VideoEncoder : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
Saa7187VideoEncoder(uint8_t dev_addr);
|
||||
~Saa7187VideoEncoder() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
private:
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t reg_num = 0;
|
||||
int pos = 0;
|
||||
|
||||
uint8_t regs[Saa7187Regs::last_reg] = {0};
|
||||
};
|
||||
|
||||
#endif // SAA7187_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,14 +24,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
@file Contains definitions for Power Macintosh machine ID registers.
|
||||
@file Contains definitions for PowerMacintosh machine ID registers.
|
||||
|
||||
The machine ID register is a memory-based register containing hardcoded
|
||||
values the system software can read to identify machine/board it's running on.
|
||||
@@ -43,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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)
|
||||
+1 uint8_t machine_type (3 - PowerMac)
|
||||
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
|
||||
*/
|
||||
class NubusMacID : public MMIODevice {
|
||||
@@ -59,14 +56,7 @@ public:
|
||||
~NubusMacID() = default;
|
||||
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
if (size == 4 && offset == 0) {
|
||||
return *(uint32_t*)this->id;
|
||||
}
|
||||
if (size == 1 && offset < 4) {
|
||||
return this->id[offset];
|
||||
}
|
||||
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
|
||||
return 0;
|
||||
return (offset < 4 ? this->id[offset] : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
@@ -76,36 +66,6 @@ private:
|
||||
uint8_t id[4];
|
||||
};
|
||||
|
||||
/**
|
||||
TNT-style machines and derivatives provide two board registers
|
||||
telling whether some particular piece of HW is installed or not.
|
||||
Both board registers are attached to the IOBus of the I/O controller.
|
||||
See machines/machinetnt.cpp for further details.
|
||||
**/
|
||||
class BoardRegister : public HWComponent, public IobusDevice {
|
||||
public:
|
||||
BoardRegister(std::string name, const uint16_t data) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IOBUS_DEV);
|
||||
this->data = data;
|
||||
};
|
||||
~BoardRegister() = default;
|
||||
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return (!address) ? this->data : 0xFFFFU;
|
||||
};
|
||||
|
||||
// appears read-only to guest
|
||||
void iodev_write(uint32_t address, uint16_t value) {};
|
||||
|
||||
void update_bits(const uint16_t val, const uint16_t mask) {
|
||||
this->data = (this->data & ~mask) | (val & mask);
|
||||
};
|
||||
|
||||
private:
|
||||
uint16_t data;
|
||||
};
|
||||
|
||||
/**
|
||||
The machine ID for the Gossamer board is accesible at 0xFF000004 (phys).
|
||||
It contains a 16-bit value revealing machine's capabilities like bus speed,
|
||||
@@ -132,4 +92,4 @@ private:
|
||||
uint16_t id;
|
||||
};
|
||||
|
||||
#endif // MACHINE_ID_H
|
||||
#endif /* MACHINE_ID_H */
|
||||
@@ -36,7 +36,4 @@ public:
|
||||
virtual ~MMIODevice() = default;
|
||||
};
|
||||
|
||||
#define SIZE_ARG(size) (size == 4 ? 'l' : size == 2 ? 'w' : \
|
||||
size == 1 ? 'b' : '0' + size)
|
||||
|
||||
#endif /* MMIO_DEVICE_H */
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
@@ -73,8 +74,7 @@ void NVram::init() {
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
|
||||
!f.read((char*)this->storage.get(), this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file \"%s\".", this->file_name.c_str());
|
||||
memset(this->storage.get(), 0, this->ram_size);
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file.");
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
@@ -22,8 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** Utilities for working with Apple Open Firmware and CHRP NVRAM partitions. */
|
||||
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
|
||||
@@ -24,14 +24,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class NVram;
|
||||
|
||||
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -143,17 +144,14 @@ uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIBase *device;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_READ;
|
||||
if (device) {
|
||||
uint32_t value = device->pci_cfg_read(reg_offs, details);
|
||||
// bytes 4 to 7 are random on bandit but
|
||||
// we choose to repeat bytes 0 to 3 like grackle
|
||||
return pci_conv_rd_data(value, value, details);
|
||||
return pci_conv_rd_data(device->pci_cfg_read(reg_offs, details), details);
|
||||
}
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
return BYTESWAP_32(this->config_addr);
|
||||
@@ -170,7 +168,7 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIBase *device;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_WRITE;
|
||||
if (device) {
|
||||
@@ -198,8 +196,9 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
|
||||
inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
int &dev_num, int &fun_num, uint8_t ®_offs,
|
||||
AccessDetails &details, PCIBase *&device)
|
||||
AccessDetails &details, PCIDevice *&device)
|
||||
{
|
||||
device = NULL;
|
||||
details.size = size;
|
||||
details.offset = offset & 3;
|
||||
fun_num = FUN_NUM();
|
||||
@@ -218,35 +217,23 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
device = pci_find_device(dev_num, fun_num);
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
device = this->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots1 = {
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"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
|
||||
) {
|
||||
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);
|
||||
@@ -256,7 +243,7 @@ int BanditHost::device_postinit()
|
||||
}
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: BanditHost(bridge_num)
|
||||
: BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
@@ -282,7 +269,7 @@ Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
|
||||
}
|
||||
|
||||
Chaos::Chaos(std::string name) : BanditHost(0)
|
||||
Chaos::Chaos(std::string name) : BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
@@ -298,7 +285,7 @@ Chaos::Chaos(std::string name) : BanditHost(0)
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
static const PropMap Bandit1_Properties = {
|
||||
static const PropMap Bandit_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
@@ -307,41 +294,18 @@ static const PropMap Bandit1_Properties = {
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap Bandit2_Properties = {
|
||||
{"pci_D2",
|
||||
new StrProperty("")},
|
||||
{"pci_E2",
|
||||
new StrProperty("")},
|
||||
{"pci_F2",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap Chaos_Properties = {
|
||||
{"vci_D",
|
||||
new StrProperty("")},
|
||||
{"vci_E",
|
||||
new StrProperty("")},
|
||||
{"vci_F",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, Bandit1_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit2_Descriptor = {
|
||||
Bandit::create_second, {}, Bandit2_Properties
|
||||
Bandit::create_first, {}, Bandit_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, Bandit1_Properties
|
||||
Bandit::create_psx_first, {}, Bandit_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, Chaos_Properties
|
||||
Chaos::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -70,11 +70,6 @@ enum {
|
||||
*/
|
||||
class BanditHost : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
|
||||
|
||||
// PCIHost methods
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
|
||||
// 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);
|
||||
@@ -83,12 +78,11 @@ public:
|
||||
|
||||
protected:
|
||||
uint32_t config_addr;
|
||||
int bridge_num;
|
||||
|
||||
private:
|
||||
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIBase *&device);
|
||||
PCIDevice *&device);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -124,17 +118,13 @@ public:
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
|
||||
};
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
|
||||
};
|
||||
|
||||
static std::unique_ptr<HWComponent> create_psx_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
std::unique_ptr<BanditPciDevice> my_pci_device;
|
||||
unique_ptr<BanditPciDevice> my_pci_device;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/dec21154.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/pci/pcibase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
this->pci_rd_stat = [this]() { return this->status; };
|
||||
this->pci_rd_cmd = [this]() { return this->command; };
|
||||
this->pci_rd_bist = []() { return 0; };
|
||||
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
|
||||
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
|
||||
|
||||
this->pci_wr_stat = [](uint16_t val) {};
|
||||
this->pci_wr_cmd = [this](uint16_t cmd) {
|
||||
/*
|
||||
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
|
||||
Or the mmio regions should be enabled/disabled.
|
||||
*/
|
||||
this->command = cmd & this->command_cfg;
|
||||
};
|
||||
this->pci_wr_bist = [](uint8_t val) {};
|
||||
this->pci_wr_lat_timer = [this](uint8_t val) { this->lat_timer = val; };
|
||||
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
|
||||
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
|
||||
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
return (this->device_id << 16) | (this->vendor_id);
|
||||
case PCI_CFG_STAT_CMD:
|
||||
return (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
case PCI_CFG_CLASS_REV:
|
||||
return this->class_rev;
|
||||
case PCI_CFG_DWORD_3:
|
||||
return (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(value >> 16);
|
||||
this->pci_wr_cmd(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(value >> 24);
|
||||
this->pci_wr_lat_timer((value >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(value & 0xFF);
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBase::setup_bars(std::vector<BarConfig> cfg_data)
|
||||
{
|
||||
for (auto cfg_entry : cfg_data) {
|
||||
if (cfg_entry.bar_num > this->num_bars) {
|
||||
ABORT_F("BAR number %d out of range", cfg_entry.bar_num);
|
||||
}
|
||||
this->bars_cfg[cfg_entry.bar_num] = cfg_entry.bar_cfg;
|
||||
}
|
||||
|
||||
this->finish_config_bars();
|
||||
}
|
||||
|
||||
int PCIBase::attach_exp_rom_image(const std::string img_path)
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
int result = 0;
|
||||
|
||||
this->exp_bar_cfg = 0; // tell the world we got no ROM for now
|
||||
|
||||
try {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
throw std::runtime_error("could not open specified ROM dump image");
|
||||
}
|
||||
|
||||
// validate image file
|
||||
uint8_t buf[4] = { 0 };
|
||||
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 0x55 || buf[1] != 0xAA) {
|
||||
throw std::runtime_error("invalid expansion ROM signature");
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, std::ios::end);
|
||||
size_t exp_rom_image_size = img_file.tellg();
|
||||
if (exp_rom_image_size > 4*1024*1024) {
|
||||
throw std::runtime_error("expansion ROM file too large");
|
||||
}
|
||||
|
||||
// verify PCI struct offset
|
||||
uint16_t pci_struct_offset = 0;
|
||||
img_file.seekg(0x18, std::ios::beg);
|
||||
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
|
||||
|
||||
if (pci_struct_offset > exp_rom_image_size) {
|
||||
throw std::runtime_error("invalid PCI structure offset");
|
||||
}
|
||||
|
||||
// verify PCI struct signature
|
||||
img_file.seekg(pci_struct_offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 'P' || buf[1] != 'C' || buf[2] != 'I' || buf[3] != 'R') {
|
||||
throw std::runtime_error("unexpected PCI struct signature");
|
||||
}
|
||||
|
||||
// find minimum rom size for the rom file (power of 2 >= 0x800)
|
||||
for (this->exp_rom_size = 1 << 11; this->exp_rom_size < exp_rom_image_size; this->exp_rom_size <<= 1) {}
|
||||
|
||||
// ROM image ok - go ahead and load it
|
||||
this->exp_rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[this->exp_rom_size]);
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)this->exp_rom_data.get(), exp_rom_image_size);
|
||||
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
|
||||
this->pci_name.c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
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->pci_name.c_str(), exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
img_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIBase::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
switch (bars_typ[bar_num]) {
|
||||
case PCIBarType::Unused:
|
||||
return;
|
||||
|
||||
case PCIBarType::Io_16_Bit:
|
||||
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->pci_name.c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
|
||||
}
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_20_Bit:
|
||||
case PCIBarType::Mem_32_Bit:
|
||||
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->pci_name.c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
|
||||
}
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_64_Bit_Hi:
|
||||
this->bars[bar_num] = value & bar_cfg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (value != 0xFFFFFFFFUL) // don't notify the device during BAR sizing
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIBase::finish_config_bars()
|
||||
{
|
||||
for (int bar_num = 0; bar_num < this->num_bars; bar_num++) {
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
|
||||
if (!bar_cfg) // skip unimplemented BARs
|
||||
continue;
|
||||
|
||||
if (bar_cfg & 1) {
|
||||
bars_typ[bar_num] = (bar_cfg & 0xffff0000) ? PCIBarType::Io_32_Bit :
|
||||
PCIBarType::Io_16_Bit;
|
||||
has_io_space = true;
|
||||
}
|
||||
else {
|
||||
int pci_space_type = (bar_cfg >> 1) & 3;
|
||||
switch (pci_space_type) {
|
||||
case 0:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_32_Bit;
|
||||
break;
|
||||
case 1:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_20_Bit;
|
||||
break;
|
||||
case 2:
|
||||
if (bar_num >= num_bars - 1) {
|
||||
ABORT_F("%s: BAR %d cannot be 64-bit",
|
||||
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->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else {
|
||||
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
|
||||
bars_typ[bar_num ] = PCIBarType::Mem_64_Bit_Hi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
|
||||
this->pci_name.c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
}
|
||||
|
||||
void PCIBase::map_exp_rom_mem()
|
||||
{
|
||||
uint32_t rom_addr = this->exp_rom_bar & this->exp_bar_cfg;
|
||||
if (rom_addr) {
|
||||
if (this->exp_rom_addr != rom_addr) {
|
||||
this->unmap_exp_rom_mem();
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = rom_addr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBase::unmap_exp_rom_mem()
|
||||
{
|
||||
if (this->exp_rom_addr) {
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_unregister_mmio_region(exp_rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBase::pci_wr_exp_rom_bar(uint32_t data)
|
||||
{
|
||||
if (!this->exp_bar_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data & this->exp_bar_cfg) == this->exp_bar_cfg) {
|
||||
// doing sizing
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
} else {
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 PCI_BASE_H
|
||||
#define PCI_BASE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space header types */
|
||||
enum PCIHeaderType : uint8_t {
|
||||
PCI_HEADER_TYPE_0 = 0, // PCI Device
|
||||
PCI_HEADER_TYPE_1 = 1, // PCI-PCI Bridge
|
||||
PCI_HEADER_TYPE_2 = 2, // PCI-To-Cardbus Bridge
|
||||
};
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
|
||||
PCI_CFG_STAT_CMD = 0x04, // command/status register
|
||||
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
|
||||
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
|
||||
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 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_NVIDIA = 0x10DE,
|
||||
};
|
||||
|
||||
/** PCI BAR types */
|
||||
enum PCIBarType : uint32_t {
|
||||
Unused = 0,
|
||||
Io_16_Bit,
|
||||
Io_32_Bit,
|
||||
Mem_20_Bit, // legacy type for < 1MB memory
|
||||
Mem_32_Bit,
|
||||
Mem_64_Bit_Lo,
|
||||
Mem_64_Bit_Hi
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t bar_num;
|
||||
uint32_t bar_cfg;
|
||||
} BarConfig;
|
||||
|
||||
class PCIBase : public MMIODevice {
|
||||
public:
|
||||
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
|
||||
virtual ~PCIBase() = default;
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return has_io_space;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
};
|
||||
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
};
|
||||
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint16_t()> pci_rd_stat;
|
||||
std::function<void(uint16_t)> pci_wr_stat;
|
||||
std::function<uint16_t()> pci_rd_cmd;
|
||||
std::function<void(uint16_t)> pci_wr_cmd;
|
||||
std::function<uint8_t()> pci_rd_bist;
|
||||
std::function<void(uint8_t)> pci_wr_bist;
|
||||
std::function<uint8_t()> pci_rd_lat_timer;
|
||||
std::function<void(uint8_t)> pci_wr_lat_timer;
|
||||
std::function<uint8_t()> pci_rd_cache_lnsz;
|
||||
std::function<void(uint8_t)> pci_wr_cache_lnsz;
|
||||
|
||||
std::function<void(int)> pci_notify_bar_change;
|
||||
|
||||
int attach_exp_rom_image(const std::string img_path);
|
||||
|
||||
virtual void set_host(PCIHost* host_instance) {
|
||||
this->host_instance = host_instance;
|
||||
}
|
||||
|
||||
virtual void set_multi_function(bool is_multi_function) {
|
||||
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
|
||||
}
|
||||
|
||||
virtual void set_irq_pin(uint8_t irq_pin) {
|
||||
this->irq_pin = irq_pin;
|
||||
}
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state) {
|
||||
this->host_instance->pci_interrupt(irq_line_state, this);
|
||||
}
|
||||
|
||||
// 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) { }
|
||||
|
||||
protected:
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void setup_bars(std::vector<BarConfig> cfg_data);
|
||||
void finish_config_bars();
|
||||
void pci_wr_exp_rom_bar(uint32_t data);
|
||||
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)
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint16_t command = 0;
|
||||
uint16_t status = 0;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t hdr_type; // header type, single function
|
||||
uint8_t cap_ptr = 0; // capabilities ptr
|
||||
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
bool has_io_space = false;
|
||||
int num_bars; // number of BARs. Type 0:6, type 1:2, type 2:1 (4K)
|
||||
uint32_t bars[6] = { 0 }; // BARs (base address registers)
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for BARs
|
||||
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for BARs
|
||||
|
||||
// PCI configuration space state (type 0 and 1)
|
||||
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
||||
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
||||
uint32_t exp_rom_addr = 0; // expansion ROM base address
|
||||
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
|
||||
|
||||
std::unique_ptr<uint8_t[]> exp_rom_data;
|
||||
|
||||
// 0 = not writable; 1 = bit is enabled in command register
|
||||
uint16_t command_cfg = 0xffff - (1<<3) - (1<<7); // disable: special cycles and stepping
|
||||
};
|
||||
|
||||
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
case 0x04: return (uint8_t) value;
|
||||
case 0x05: return (uint8_t)(value >> 8);
|
||||
case 0x06: return (uint8_t)(value >> 16);
|
||||
case 0x07: return (uint8_t)(value >> 24);
|
||||
|
||||
case 0x08: return (uint16_t) value;
|
||||
case 0x09: return (uint16_t) (value >> 8);
|
||||
case 0x0a: return (uint16_t) (value >> 16);
|
||||
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
|
||||
|
||||
case 0x10: return value;
|
||||
case 0x11: return (value >> 8) | (value << 24);
|
||||
case 0x12: return (value >> 16) | (value << 16);
|
||||
case 0x13: return (value >> 24) | (value << 8);
|
||||
|
||||
default: return 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: read unimplemented config register @%02x.%c", \
|
||||
this->name.c_str(), reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size) \
|
||||
); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: %s %s register @%02x.%c = %0*x", \
|
||||
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size), \
|
||||
details.size * 2, pci_cfg_log(value, details) \
|
||||
)
|
||||
|
||||
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
|
||||
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size) \
|
||||
)
|
||||
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size), \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
)
|
||||
|
||||
#endif /* PCI_BASE_H */
|
||||
@@ -20,12 +20,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1, 2)
|
||||
PCIBridge::PCIBridge(std::string name) : PCIDevice(name)
|
||||
{
|
||||
this->num_bars = 2;
|
||||
this->hdr_type = 1;
|
||||
|
||||
this->pci_rd_primary_bus = [this]() { return this->primary_bus; };
|
||||
this->pci_rd_secondary_bus = [this]() { return this->secondary_bus; };
|
||||
this->pci_rd_subordinate_bus = [this]() { return this->subordinate_bus; };
|
||||
this->pci_rd_sec_latency_timer = [this]() { return this->sec_latency_timer; };
|
||||
this->pci_rd_sec_status = [this]() { return this->sec_status; };
|
||||
this->pci_rd_memory_base = [this]() { return this->memory_base; };
|
||||
this->pci_rd_memory_limit = [this]() { return this->memory_limit; };
|
||||
this->pci_rd_io_base = [this]() { return this->io_base; };
|
||||
@@ -36,6 +42,18 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
|
||||
this->pci_rd_io_limit_upper16 = [this]() { return this->io_limit_upper16; };
|
||||
this->pci_rd_pref_base_upper32 = [this]() { return this->pref_base_upper32; };
|
||||
this->pci_rd_pref_limit_upper32 = [this]() { return this->pref_limit_upper32; };
|
||||
this->pci_rd_bridge_control = [this]() { return this->bridge_control; };
|
||||
|
||||
this->pci_wr_primary_bus = [this](uint8_t val) { this->primary_bus = val; };
|
||||
this->pci_wr_secondary_bus = [this](uint8_t val) { this->secondary_bus = val; };
|
||||
this->pci_wr_subordinate_bus = [this](uint8_t val) { this->subordinate_bus = val; };
|
||||
|
||||
this->pci_wr_sec_latency_timer = [this](uint8_t val) {
|
||||
this->sec_latency_timer = (this->sec_latency_timer & ~this->sec_latency_timer_cfg) |
|
||||
(val & this->sec_latency_timer_cfg);
|
||||
};
|
||||
|
||||
this->pci_wr_sec_status = [this](uint16_t val) {};
|
||||
|
||||
this->pci_wr_memory_base = [this](uint16_t val) {
|
||||
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
|
||||
@@ -94,14 +112,33 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
|
||||
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
|
||||
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
|
||||
bool PCIBridge::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
// FIXME: constrain region to memory range
|
||||
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
return (this->pci_rd_sec_latency_timer() << 24) |
|
||||
(this->pci_rd_subordinate_bus() << 16) |
|
||||
(this->pci_rd_secondary_bus() << 8) |
|
||||
(this->pci_rd_primary_bus());
|
||||
case PCI_CFG_IO_BASE:
|
||||
return (this->pci_rd_sec_status() << 16) |
|
||||
(this->pci_rd_io_limit() << 8) | (this->pci_rd_io_base());
|
||||
@@ -115,21 +152,29 @@ uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
return this->pci_rd_pref_limit_upper32();
|
||||
case PCI_CFG_IO_BASE_UPPER16:
|
||||
return (this->pci_rd_io_limit_upper16() << 16) | (this->pci_rd_io_base_upper16());
|
||||
case PCI_CFG_DWORD_13:
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
return exp_rom_bar;
|
||||
default:
|
||||
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
this->pci_wr_sec_latency_timer(value >> 24);
|
||||
this->pci_wr_subordinate_bus(value >> 16);
|
||||
this->pci_wr_secondary_bus(value >> 8);
|
||||
this->pci_wr_primary_bus(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_IO_BASE:
|
||||
this->pci_wr_sec_status(value >> 16);
|
||||
@@ -157,9 +202,12 @@ void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
this->pci_wr_exp_rom_bar(value);
|
||||
break;
|
||||
default:
|
||||
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
this->irq_line = value >> 24;
|
||||
this->pci_wr_bridge_control(value >> 16);
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,36 +22,63 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_BRIDGE_H
|
||||
#define PCI_BRIDGE_H
|
||||
|
||||
#include <devices/common/pci/pcibridgebase.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
|
||||
PCI_CFG_IO_BASE = 0x1C, // IO_BASE.b, IO_LIMIT.b, SEC_STATUS.w
|
||||
PCI_CFG_MEMORY_BASE = 0x20, // MEMORY_BASE.w, MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_MEM_BASE = 0x24, // PREF_MEMORY_BASE.w, PREF_MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_BASE_UPPER32 = 0x28, // PREF_BASE_UPPER32
|
||||
PCI_CFG_PREF_LIMIT_UPPER32 = 0x2c, // PREF_LIMIT_UPPER32
|
||||
PCI_CFG_IO_BASE_UPPER16 = 0x30, // IO_BASE_UPPER16.w, IO_LIMIT_UPPER16.w
|
||||
// PCI_CFG_CAP_PTR
|
||||
PCI_CFG_BRIDGE_ROM_ADDRESS = 0x38, // BRIDGE_ROM_ADDRESS
|
||||
PCI_CFG_INTERRUPT_LINE = 0x3C, // INTERRUPT_LINE.b, INTERRUPT_PIN.b, BRIDGE_CONTROL.w
|
||||
};
|
||||
|
||||
class PCIBridge : public PCIBridgeBase {
|
||||
class PCIBridge : public PCIHost, public PCIDevice {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBridge(std::string name);
|
||||
~PCIBridge() = default;
|
||||
|
||||
// PCIBase methods
|
||||
// PCIHost methods
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
// PCIDevice methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
// 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) { };
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
std::function<uint8_t()> pci_rd_secondary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_secondary_bus;
|
||||
std::function<uint8_t()> pci_rd_subordinate_bus;
|
||||
std::function<void(uint8_t)> pci_wr_subordinate_bus;
|
||||
std::function<uint8_t()> pci_rd_sec_latency_timer;
|
||||
std::function<void(uint8_t)> pci_wr_sec_latency_timer;
|
||||
std::function<uint16_t()> pci_rd_sec_status;
|
||||
std::function<void(uint16_t)> pci_wr_sec_status;
|
||||
std::function<uint8_t()> pci_rd_io_base;
|
||||
std::function<void(uint8_t)> pci_wr_io_base;
|
||||
std::function<uint8_t()> pci_rd_io_limit;
|
||||
@@ -72,9 +99,16 @@ public:
|
||||
std::function<void(uint16_t)> pci_wr_io_base_upper16;
|
||||
std::function<uint16_t()> pci_rd_io_limit_upper16;
|
||||
std::function<void(uint16_t)> pci_wr_io_limit_upper16;
|
||||
std::function<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint8_t primary_bus = 0;
|
||||
uint8_t secondary_bus = 0;
|
||||
uint8_t subordinate_bus = 0;
|
||||
uint8_t sec_latency_timer = 0; // if supportss r/w then must reset to 0
|
||||
uint16_t sec_status = 0;
|
||||
uint8_t io_base = 0;
|
||||
uint8_t io_limit = 0;
|
||||
uint16_t memory_base = 0;
|
||||
@@ -85,8 +119,12 @@ protected:
|
||||
uint32_t pref_limit_upper32 = 0;
|
||||
uint16_t io_base_upper16 = 0;
|
||||
uint16_t io_limit_upper16 = 0;
|
||||
uint16_t bridge_control = 0;
|
||||
|
||||
// 0 = not writable, 0xf0 = supports 16 bit I/O range, 0xf1 = supports 32 bit I/O range
|
||||
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
|
||||
uint8_t sec_latency_timer_cfg = 0;
|
||||
|
||||
// 0 = not writable, 0xf0 = supports 16 bit io range, 0xf1 = supports 32 bit I/O range
|
||||
uint8_t io_cfg = 0xf0;
|
||||
|
||||
// 0 = not writable, 0xfff0 = supports 32 bit memory range
|
||||
@@ -96,13 +134,14 @@ protected:
|
||||
// 0xfff1 = supports 64 bit prefetchable memory range
|
||||
uint16_t pref_mem_cfg = 0xfff0;
|
||||
|
||||
// calculated address ranges
|
||||
uint32_t io_base_32 = 0;
|
||||
uint32_t io_limit_32 = 0;
|
||||
uint64_t memory_base_32 = 0;
|
||||
uint64_t memory_limit_32 = 0;
|
||||
uint64_t pref_mem_base_64 = 0;
|
||||
uint64_t pref_mem_limit_64 = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_H */
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/pci/pcibridgebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars) : PCIBase(name, hdr_type, num_bars)
|
||||
{
|
||||
this->pci_rd_primary_bus = [this]() { return this->primary_bus; };
|
||||
this->pci_rd_secondary_bus = [this]() { return this->secondary_bus; };
|
||||
this->pci_rd_subordinate_bus = [this]() { return this->subordinate_bus; };
|
||||
this->pci_rd_sec_latency_timer = [this]() { return this->sec_latency_timer; };
|
||||
this->pci_rd_sec_status = [this]() { return this->sec_status; };
|
||||
this->pci_rd_bridge_control = [this]() { return this->bridge_control; };
|
||||
|
||||
this->pci_wr_primary_bus = [this](uint8_t val) { this->primary_bus = val; };
|
||||
this->pci_wr_secondary_bus = [this](uint8_t val) { this->secondary_bus = val; };
|
||||
this->pci_wr_subordinate_bus = [this](uint8_t val) { this->subordinate_bus = val; };
|
||||
this->pci_wr_sec_latency_timer = [this](uint8_t val) {
|
||||
this->sec_latency_timer = (this->sec_latency_timer & ~this->sec_latency_timer_cfg) |
|
||||
(val & this->sec_latency_timer_cfg);
|
||||
};
|
||||
this->pci_wr_sec_status = [this](uint16_t val) {};
|
||||
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
|
||||
bool PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
// FIXME: constrain region to memory range
|
||||
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIBridgeBase::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
uint32_t PCIBridgeBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
return (this->pci_rd_sec_latency_timer() << 24) |
|
||||
(this->pci_rd_subordinate_bus() << 16) |
|
||||
(this->pci_rd_secondary_bus() << 8) |
|
||||
(this->pci_rd_primary_bus());
|
||||
case PCI_CFG_DWORD_15:
|
||||
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
|
||||
default:
|
||||
return PCIBase::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
this->pci_wr_sec_latency_timer(value >> 24);
|
||||
this->pci_wr_subordinate_bus(value >> 16);
|
||||
this->pci_wr_secondary_bus(value >> 8);
|
||||
this->pci_wr_primary_bus(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
this->irq_line = value >> 24;
|
||||
this->pci_wr_bridge_control(value >> 16);
|
||||
break;
|
||||
default:
|
||||
return PCIBase::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 PCI_BRIDGE_BASE_H
|
||||
#define PCI_BRIDGE_BASE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcibase.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets (type 1 and 2) */
|
||||
enum {
|
||||
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
|
||||
};
|
||||
|
||||
class PCIBridgeBase : public PCIHost, public PCIBase {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars);
|
||||
~PCIBridgeBase() = default;
|
||||
|
||||
// PCIHost methods
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
|
||||
// PCIBase methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
std::function<uint8_t()> pci_rd_secondary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_secondary_bus;
|
||||
std::function<uint8_t()> pci_rd_subordinate_bus;
|
||||
std::function<void(uint8_t)> pci_wr_subordinate_bus;
|
||||
std::function<uint8_t()> pci_rd_sec_latency_timer;
|
||||
std::function<void(uint8_t)> pci_wr_sec_latency_timer;
|
||||
std::function<uint16_t()> pci_rd_sec_status;
|
||||
std::function<void(uint16_t)> pci_wr_sec_status;
|
||||
std::function<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint8_t primary_bus = 0;
|
||||
uint8_t secondary_bus = 0;
|
||||
uint8_t subordinate_bus = 0;
|
||||
uint8_t sec_latency_timer = 0; // if supportss r/w then must reset to 0
|
||||
uint16_t sec_status = 0;
|
||||
uint16_t bridge_control = 0;
|
||||
|
||||
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
|
||||
uint8_t sec_latency_timer_cfg = 0xff;
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_BASE_H */
|
||||
@@ -1,223 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/pci/pcicardbusbridge.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
typedef struct {
|
||||
// CardBus Registers
|
||||
/* 0x00 */ uint32_t Event;
|
||||
/* 0x04 */ uint32_t Mask;
|
||||
/* 0x08 */ uint32_t PresentState;
|
||||
/* 0x0C */ uint32_t Force;
|
||||
/* 0x10 */ uint32_t Control;
|
||||
/* 0x14 */ uint32_t Reserved[4];
|
||||
/* 0x20 */ uint32_t UserDefined20h[504];
|
||||
|
||||
// 16-Bit Registers
|
||||
/* 0x800 */ uint8_t IDAndRevision;
|
||||
/* 0x801 */ uint8_t IFStatus;
|
||||
/* 0x802 */ uint8_t PowerAndResetDrvControl;
|
||||
/* 0x803 */ uint8_t InterruptAndGeneralControl;
|
||||
/* 0x804 */ uint8_t CardStatusChange;
|
||||
/* 0x805 */ uint8_t CardStatusChangeInterruptConfiguration;
|
||||
/* 0x806 */ uint8_t AddressWindowEnable;
|
||||
/* 0x807 */ uint8_t IOControl;
|
||||
/* 0x808 */ uint16_t IOAdd0Start;
|
||||
/* 0x80A */ uint16_t IOAdd0Stop;
|
||||
/* 0x80C */ uint16_t IOAdd1Start;
|
||||
/* 0x80E */ uint16_t IOAdd1Stop;
|
||||
/* 0x810 */ uint16_t SysMemAdd0Start;
|
||||
/* 0x812 */ uint16_t SysMemAdd0Stop;
|
||||
/* 0x814 */ uint16_t CardMemoryOffsetAdd0;
|
||||
/* 0x816 */ uint16_t UserDefined814h;
|
||||
/* 0x818 */ uint16_t SysMemAdd1Start;
|
||||
/* 0x81A */ uint16_t SysMemAdd1Stop;
|
||||
/* 0x81C */ uint16_t CardMemoryOffsetAdd1;
|
||||
/* 0x81E */ uint16_t UserDefined81Ch;
|
||||
/* 0x820 */ uint16_t SysMemAdd2Start;
|
||||
/* 0x822 */ uint16_t SysMemAdd2Stop;
|
||||
/* 0x824 */ uint16_t CardMemoryOffsetAdd2;
|
||||
/* 0x826 */ uint16_t UserDefined824h;
|
||||
/* 0x828 */ uint16_t SysMemAdd3Start;
|
||||
/* 0x82A */ uint16_t SysMemAdd3Stop;
|
||||
/* 0x82C */ uint16_t CardMemoryOffsetAdd3;
|
||||
/* 0x82E */ uint16_t UserDefined82Ch;
|
||||
/* 0x830 */ uint16_t SysMemAdd4Start;
|
||||
/* 0x832 */ uint16_t SysMemAdd4Stop;
|
||||
/* 0x834 */ uint16_t CardMemoryOffsetAdd4;
|
||||
/* 0x836 */ uint16_t UserDefined834h;
|
||||
/* 0x838 */ uint32_t UserDefined838h[4];
|
||||
/* 0x840 */ uint8_t SysMemAdd0MappingStartUp;
|
||||
/* 0x841 */ uint8_t SysMemAdd1MappingStartUp;
|
||||
/* 0x842 */ uint8_t SysMemAdd2MappingStartUp;
|
||||
/* 0x843 */ uint8_t SysMemAdd3MappingStartUp;
|
||||
/* 0x844 */ uint8_t SysMemAdd4MappingStartUp;
|
||||
/* 0x845 */ uint8_t UserDefined845h;
|
||||
/* 0x846 */ uint16_t UserDefined846h;
|
||||
/* 0x848 */ uint32_t UserDefined848h[494];
|
||||
} CardBusStatusAnfControlRegisters;
|
||||
|
||||
PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_2, 1)
|
||||
{
|
||||
this->pci_rd_memory_base_0 = [this]() { return this->memory_base_0 ; };
|
||||
this->pci_rd_memory_limit_0 = [this]() { return this->memory_limit_0 ; };
|
||||
this->pci_rd_memory_base_1 = [this]() { return this->memory_base_1 ; };
|
||||
this->pci_rd_memory_limit_1 = [this]() { return this->memory_limit_1 ; };
|
||||
this->pci_rd_io_base_0 = [this]() { return this->io_base_0 ; };
|
||||
this->pci_rd_io_limit_0 = [this]() { return this->io_limit_0 ; };
|
||||
this->pci_rd_io_base_1 = [this]() { return this->io_base_1 ; };
|
||||
this->pci_rd_io_limit_1 = [this]() { return this->io_limit_1 ; };
|
||||
|
||||
this->pci_wr_memory_base_0 = [this](uint32_t val) {
|
||||
this->memory_base_0 = val & this->memory_0_cfg;
|
||||
this->memory_base_0_32 = this->memory_base_0;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit_0 = [this](uint32_t val) {
|
||||
this->memory_limit_0 = val & this->memory_0_cfg;
|
||||
this->memory_limit_0_32 = this->memory_limit_0 + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_base_1 = [this](uint32_t val) {
|
||||
this->memory_base_1 = val & this->memory_1_cfg;
|
||||
this->memory_base_1_32 = this->memory_base_1;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit_1 = [this](uint32_t val) {
|
||||
this->memory_limit_1 = val & this->memory_1_cfg;
|
||||
this->memory_limit_1_32 = this->memory_limit_1 + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base_0 = [this](uint32_t val) {
|
||||
this->io_base_0 = (val & this->io_0_cfg) | (io_0_cfg & 3);
|
||||
this->io_base_0_32 = (this->io_base_0 & ~3);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit_0 = [this](uint32_t val) {
|
||||
this->io_limit_0 = (val & this->io_0_cfg);
|
||||
this->io_limit_0_32 = this->io_limit_0 + 4;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base_1 = [this](uint32_t val) {
|
||||
this->io_base_1 = (val & this->io_1_cfg) | (io_1_cfg & 3);
|
||||
this->io_base_1_32 = (this->io_base_1 & ~3);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit_1 = [this](uint32_t val) {
|
||||
this->io_limit_1 = (val & this->io_1_cfg);
|
||||
this->io_limit_1_32 = this->io_limit_1 + 4;
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
case PCI_CFG_CB_CAPABILITIES:
|
||||
return (this->pci_rd_sec_status() << 16) | cap_ptr;
|
||||
case PCI_CFG_CB_MEMORY_BASE_0:
|
||||
return this->pci_rd_memory_base_0();
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_0:
|
||||
return this->pci_rd_memory_limit_0();
|
||||
case PCI_CFG_CB_MEMORY_BASE_1:
|
||||
return this->pci_rd_memory_base_0();
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_1:
|
||||
return this->pci_rd_memory_limit_0();
|
||||
case PCI_CFG_CB_IO_BASE_0:
|
||||
return this->pci_rd_io_base_0();
|
||||
case PCI_CFG_CB_IO_LIMIT_0:
|
||||
return this->pci_rd_io_limit_0();
|
||||
case PCI_CFG_CB_IO_BASE_1:
|
||||
return this->pci_rd_io_base_0();
|
||||
case PCI_CFG_CB_IO_LIMIT_1:
|
||||
return this->pci_rd_io_limit_0();
|
||||
case PCI_CFG_CB_SUBSYSTEM_IDS:
|
||||
return (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
case PCI_CFG_CB_LEGACY_MODE_BASE:
|
||||
return this->legacy_mode_base;
|
||||
default:
|
||||
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
}
|
||||
|
||||
void PCICardbusBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
break;
|
||||
case PCI_CFG_CB_CAPABILITIES:
|
||||
this->pci_wr_sec_status(value >> 16);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_BASE_0:
|
||||
this->pci_wr_memory_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_0:
|
||||
this->pci_wr_memory_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_BASE_1:
|
||||
this->pci_wr_memory_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_1:
|
||||
this->pci_wr_memory_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_BASE_0:
|
||||
this->pci_wr_io_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_LIMIT_0:
|
||||
this->pci_wr_io_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_BASE_1:
|
||||
this->pci_wr_io_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_LIMIT_1:
|
||||
this->pci_wr_io_limit_0(value);
|
||||
break;
|
||||
/*
|
||||
case PCI_CFG_CB_LEGACY_MODE_BASE:
|
||||
this->legacy_mode_base = value;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool PCICardbusBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
|
||||
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
|
||||
) return false;
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
|
||||
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
|
||||
) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 PCI_CARDBUSBRIDGE_H
|
||||
#define PCI_CARDBUSBRIDGE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcibridgebase.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_CB_CAPABILITIES = 0x14, // CB_CAPABILITIES.b, 0.b, CB_SEC_STATUS.w
|
||||
PCI_CFG_CB_MEMORY_BASE_0 = 0x1C,
|
||||
PCI_CFG_CB_MEMORY_LIMIT_0 = 0x20,
|
||||
PCI_CFG_CB_MEMORY_BASE_1 = 0x24,
|
||||
PCI_CFG_CB_MEMORY_LIMIT_1 = 0x28,
|
||||
PCI_CFG_CB_IO_BASE_0 = 0x2C,
|
||||
PCI_CFG_CB_IO_LIMIT_0 = 0x30,
|
||||
PCI_CFG_CB_IO_BASE_1 = 0x34,
|
||||
PCI_CFG_CB_IO_LIMIT_1 = 0x38,
|
||||
PCI_CFG_CB_SUBSYSTEM_IDS = 0x40, // CB_SUBSYSTEM_VENDOR_ID.w, CB_SUBSYSTEM_ID.w
|
||||
PCI_CFG_CB_LEGACY_MODE_BASE = 0x44,
|
||||
};
|
||||
|
||||
class PCICardbusBridge : public PCIBridgeBase {
|
||||
public:
|
||||
PCICardbusBridge(std::string name);
|
||||
~PCICardbusBridge() = default;
|
||||
|
||||
// PCIBase methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint32_t()> pci_rd_memory_base_0;
|
||||
std::function<void(uint32_t)> pci_wr_memory_base_0;
|
||||
std::function<uint32_t()> pci_rd_memory_limit_0;
|
||||
std::function<void(uint32_t)> pci_wr_memory_limit_0;
|
||||
std::function<uint32_t()> pci_rd_memory_base_1;
|
||||
std::function<void(uint32_t)> pci_wr_memory_base_1;
|
||||
std::function<uint32_t()> pci_rd_memory_limit_1;
|
||||
std::function<void(uint32_t)> pci_wr_memory_limit_1;
|
||||
std::function<uint32_t()> pci_rd_io_base_0;
|
||||
std::function<void(uint32_t)> pci_wr_io_base_0;
|
||||
std::function<uint32_t()> pci_rd_io_limit_0;
|
||||
std::function<void(uint32_t)> pci_wr_io_limit_0;
|
||||
std::function<uint32_t()> pci_rd_io_base_1;
|
||||
std::function<void(uint32_t)> pci_wr_io_base_1;
|
||||
std::function<uint32_t()> pci_rd_io_limit_1;
|
||||
std::function<void(uint32_t)> pci_wr_io_limit_1;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint32_t memory_base_0 = 0;
|
||||
uint32_t memory_limit_0 = 0;
|
||||
uint32_t memory_base_1 = 0;
|
||||
uint32_t memory_limit_1 = 0;
|
||||
uint32_t io_base_0 = 0;
|
||||
uint32_t io_limit_0 = 0;
|
||||
uint32_t io_base_1 = 0;
|
||||
uint32_t io_limit_1 = 0;
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint32_t legacy_mode_base = 0;
|
||||
|
||||
// 0 = not writable
|
||||
uint32_t memory_0_cfg = 0xfffff000;
|
||||
uint32_t memory_1_cfg = 0xfffff000;
|
||||
|
||||
// 0 = not writable, 0x0000fffc = supports 16 bit I/O range, 0xfffffffd = supports 32 bit I/O range
|
||||
uint32_t io_0_cfg = 0x0000fffc;
|
||||
uint32_t io_1_cfg = 0x0000fffc;
|
||||
|
||||
// calculated address ranges
|
||||
uint32_t memory_base_0_32 = 0;
|
||||
uint32_t memory_limit_0_32 = 0;
|
||||
uint32_t memory_base_1_32 = 0;
|
||||
uint32_t memory_limit_1_32 = 0;
|
||||
uint32_t io_base_0_32 = 0;
|
||||
uint32_t io_limit_0_32 = 0;
|
||||
uint32_t io_base_1_32 = 0;
|
||||
uint32_t io_limit_1_32 = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_CARDBUSBRIDGE_H */
|
||||
@@ -20,20 +20,47 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
PCIDevice::PCIDevice(std::string name) : PCIBase(name, PCI_HEADER_TYPE_0, 6)
|
||||
PCIDevice::PCIDevice(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
this->pci_name = name;
|
||||
|
||||
this->pci_rd_stat = [this]() { return this->status; };
|
||||
this->pci_rd_cmd = [this]() { return this->command; };
|
||||
this->pci_rd_bist = []() { return 0; };
|
||||
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
|
||||
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
|
||||
|
||||
this->pci_wr_stat = [](uint16_t val) {};
|
||||
this->pci_wr_cmd = [this](uint16_t cmd) { this->command = cmd; };
|
||||
this->pci_wr_bist = [](uint8_t val) {};
|
||||
this->pci_wr_lat_timer = [this](uint8_t val) { this->lat_timer = val; };
|
||||
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
|
||||
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
return (this->device_id << 16) | (this->vendor_id);
|
||||
case PCI_CFG_STAT_CMD:
|
||||
return (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
case PCI_CFG_CLASS_REV:
|
||||
return this->class_rev;
|
||||
case PCI_CFG_DWORD_3:
|
||||
return (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
@@ -45,18 +72,27 @@ uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
return (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
case PCI_CFG_ROM_BAR:
|
||||
return this->exp_rom_bar;
|
||||
case PCI_CFG_DWORD_13:
|
||||
return cap_ptr;
|
||||
case PCI_CFG_DWORD_15:
|
||||
return (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
default:
|
||||
return PCIBase::pci_cfg_read(reg_offs, details);
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(value >> 16);
|
||||
this->pci_wr_cmd(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(value >> 24);
|
||||
this->pci_wr_lat_timer((value >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(value & 0xFF);
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
@@ -72,6 +108,212 @@ void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
|
||||
this->irq_line = value >> 24;
|
||||
break;
|
||||
default:
|
||||
PCIBase::pci_cfg_write(reg_offs, value, details);
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::setup_bars(std::vector<BarConfig> cfg_data)
|
||||
{
|
||||
for (auto cfg_entry : cfg_data) {
|
||||
if (cfg_entry.bar_num > 5) {
|
||||
ABORT_F("BAR number %d out of range", cfg_entry.bar_num);
|
||||
}
|
||||
this->bars_cfg[cfg_entry.bar_num] = cfg_entry.bar_cfg;
|
||||
}
|
||||
|
||||
this->finish_config_bars();
|
||||
}
|
||||
|
||||
int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
int result = 0;
|
||||
|
||||
this->exp_bar_cfg = 0; // tell the world we got no ROM for now
|
||||
|
||||
try {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
throw std::runtime_error("could not open specified ROM dump image");
|
||||
}
|
||||
|
||||
// validate image file
|
||||
uint8_t buf[4] = { 0 };
|
||||
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 0x55 || buf[1] != 0xAA) {
|
||||
throw std::runtime_error("invalid expansion ROM signature");
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, std::ios::end);
|
||||
size_t exp_rom_image_size = img_file.tellg();
|
||||
if (exp_rom_image_size > 4*1024*1024) {
|
||||
throw std::runtime_error("expansion ROM file too large");
|
||||
}
|
||||
|
||||
// verify PCI struct offset
|
||||
uint16_t pci_struct_offset = 0;
|
||||
img_file.seekg(0x18, std::ios::beg);
|
||||
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
|
||||
|
||||
if (pci_struct_offset > exp_rom_image_size) {
|
||||
throw std::runtime_error("invalid PCI structure offset");
|
||||
}
|
||||
|
||||
// verify PCI struct signature
|
||||
img_file.seekg(pci_struct_offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 'P' || buf[1] != 'C' || buf[2] != 'I' || buf[3] != 'R') {
|
||||
throw std::runtime_error("unexpected PCI struct signature");
|
||||
}
|
||||
|
||||
// find minimum rom size for the rom file (power of 2 >= 0x800)
|
||||
for (this->exp_rom_size = 1 << 11; this->exp_rom_size < exp_rom_image_size; this->exp_rom_size <<= 1) {}
|
||||
|
||||
// ROM image ok - go ahead and load it
|
||||
this->exp_rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[this->exp_rom_size]);
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)this->exp_rom_data.get(), exp_rom_image_size);
|
||||
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
|
||||
this->pci_name.c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
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, "PCIDevice: %s", exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
img_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIDevice::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
switch (bars_typ[bar_num]) {
|
||||
case PCIBarType::Unused:
|
||||
return;
|
||||
|
||||
case PCIBarType::Io_16_Bit:
|
||||
case PCIBarType::Io_32_Bit:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_20_Bit:
|
||||
case PCIBarType::Mem_32_Bit:
|
||||
case PCIBarType::Mem_64_Bit_Lo:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_64_Bit_Hi:
|
||||
this->bars[bar_num] = value & bar_cfg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (value != 0xFFFFFFFFUL) // don't notify the device during BAR sizing
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIDevice::finish_config_bars()
|
||||
{
|
||||
for (int bar_num = 0; bar_num < this->num_bars; bar_num++) {
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
|
||||
if (!bar_cfg) // skip unimplemented BARs
|
||||
continue;
|
||||
|
||||
if (bar_cfg & 1) {
|
||||
bars_typ[bar_num] = (bar_cfg & 0xffff0000) ? PCIBarType::Io_32_Bit :
|
||||
PCIBarType::Io_16_Bit;
|
||||
has_io_space = true;
|
||||
}
|
||||
else {
|
||||
int pci_space_type = (bar_cfg >> 1) & 3;
|
||||
switch (pci_space_type) {
|
||||
case 0:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_32_Bit;
|
||||
break;
|
||||
case 1:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_20_Bit;
|
||||
break;
|
||||
case 2:
|
||||
if (bar_num >= num_bars - 1) {
|
||||
ABORT_F("%s: BAR %d cannot be 64-bit",
|
||||
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->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else {
|
||||
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
|
||||
bars_typ[bar_num ] = PCIBarType::Mem_64_Bit_Hi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
|
||||
this->pci_name.c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
}
|
||||
|
||||
void PCIDevice::map_exp_rom_mem()
|
||||
{
|
||||
uint32_t rom_addr = this->exp_rom_bar & this->exp_bar_cfg;
|
||||
if (rom_addr) {
|
||||
if (this->exp_rom_addr != rom_addr) {
|
||||
this->unmap_exp_rom_mem();
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = rom_addr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::unmap_exp_rom_mem()
|
||||
{
|
||||
if (this->exp_rom_addr) {
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_unregister_mmio_region(exp_rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_wr_exp_rom_bar(uint32_t data)
|
||||
{
|
||||
if (!this->exp_bar_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data & this->exp_bar_cfg) == this->exp_bar_cfg) {
|
||||
// doing sizing
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
} else {
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_DEVICE_H
|
||||
#define PCI_DEVICE_H
|
||||
|
||||
#include <devices/common/pci/pcibase.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
|
||||
PCI_CFG_STAT_CMD = 0x04, // command/status register
|
||||
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
|
||||
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
|
||||
PCI_CFG_BAR0 = 0x10, // base address register 0
|
||||
PCI_CFG_BAR1 = 0x14, // base address register 1
|
||||
PCI_CFG_BAR2 = 0x18, // base address register 2
|
||||
PCI_CFG_BAR3 = 0x1C, // base address register 3
|
||||
PCI_CFG_BAR4 = 0x20, // base address register 4
|
||||
@@ -33,23 +46,203 @@ enum {
|
||||
PCI_CFG_CIS_PTR = 0x28, // Cardbus CIS Pointer
|
||||
PCI_CFG_SUBSYS_ID = 0x2C, // Subsysten IDs
|
||||
PCI_CFG_ROM_BAR = 0x30, // expansion ROM base address
|
||||
PCI_CFG_CAP_PTR = 0x34, // capabilities pointer
|
||||
PCI_CFG_DWORD_14 = 0x38, // reserved
|
||||
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt, Int_Pin and Int_Line registers
|
||||
};
|
||||
|
||||
class PCIDevice : public PCIBase {
|
||||
/** 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_NVIDIA = 0x10DE,
|
||||
};
|
||||
|
||||
/** PCI BAR types */
|
||||
enum PCIBarType : uint32_t {
|
||||
Unused = 0,
|
||||
Io_16_Bit,
|
||||
Io_32_Bit,
|
||||
Mem_20_Bit, // legacy type for < 1MB memory
|
||||
Mem_32_Bit,
|
||||
Mem_64_Bit_Lo,
|
||||
Mem_64_Bit_Hi
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t bar_num;
|
||||
uint32_t bar_cfg;
|
||||
} BarConfig;
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name);
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return has_io_space;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
};
|
||||
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
};
|
||||
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint16_t()> pci_rd_stat;
|
||||
std::function<void(uint16_t)> pci_wr_stat;
|
||||
std::function<uint16_t()> pci_rd_cmd;
|
||||
std::function<void(uint16_t)> pci_wr_cmd;
|
||||
std::function<uint8_t()> pci_rd_bist;
|
||||
std::function<void(uint8_t)> pci_wr_bist;
|
||||
std::function<uint8_t()> pci_rd_lat_timer;
|
||||
std::function<void(uint8_t)> pci_wr_lat_timer;
|
||||
std::function<uint8_t()> pci_rd_cache_lnsz;
|
||||
std::function<void(uint8_t)> pci_wr_cache_lnsz;
|
||||
|
||||
std::function<void(int)> pci_notify_bar_change;
|
||||
|
||||
int attach_exp_rom_image(const std::string img_path);
|
||||
|
||||
virtual void set_host(PCIHost* host_instance) {
|
||||
this->host_instance = host_instance;
|
||||
};
|
||||
|
||||
virtual void set_multi_function(bool is_multi_function) {
|
||||
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
|
||||
}
|
||||
virtual void set_irq_pin(uint8_t irq_pin) {
|
||||
this->irq_pin = irq_pin;
|
||||
}
|
||||
|
||||
// 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) { }
|
||||
|
||||
protected:
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void setup_bars(std::vector<BarConfig> cfg_data);
|
||||
void finish_config_bars();
|
||||
void pci_wr_exp_rom_bar(uint32_t data);
|
||||
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
|
||||
uint8_t max_lat = 0;
|
||||
uint8_t min_gnt = 0;
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint16_t status = 0;
|
||||
uint16_t command = 0;
|
||||
uint8_t hdr_type = 0; // header type, single function
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint8_t cap_ptr = 0;
|
||||
uint8_t max_lat = 0;
|
||||
uint8_t min_gnt = 0;
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
bool has_io_space = false;
|
||||
int num_bars = 6;
|
||||
uint32_t bars[6] = { 0 }; // base address registers
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
||||
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for base address registers
|
||||
|
||||
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
||||
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
||||
uint32_t exp_rom_addr = 0; // expansion ROM base address
|
||||
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
|
||||
|
||||
std::unique_ptr<uint8_t[]> exp_rom_data;
|
||||
};
|
||||
|
||||
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
case 0x04: return (uint8_t) value;
|
||||
case 0x05: return (uint8_t)(value >> 8);
|
||||
case 0x06: return (uint8_t)(value >> 16);
|
||||
case 0x07: return (uint8_t)(value >> 24);
|
||||
|
||||
case 0x08: return (uint16_t) value;
|
||||
case 0x09: return (uint16_t) (value >> 8);
|
||||
case 0x0a: return (uint16_t) (value >> 16);
|
||||
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
|
||||
|
||||
case 0x10: return value;
|
||||
case 0x11: return (value >> 8) | (value << 24);
|
||||
case 0x12: return (value >> 16) | (value << 16);
|
||||
case 0x13: return (value >> 24) | (value << 8);
|
||||
|
||||
default: return 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
#define SIZE_ARGS details.size == 4 ? 'l' : details.size == 2 ? 'w' : \
|
||||
details.size == 1 ? 'b' : '0' + details.size
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: read unimplemented config register @%02x.%c", \
|
||||
this->name.c_str(), reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: %s %s register @%02x.%c = %0*x", \
|
||||
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, pci_cfg_log(value, details) \
|
||||
)
|
||||
|
||||
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
|
||||
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
)
|
||||
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
)
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,16 +22,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIDevice* dev_instance)
|
||||
{
|
||||
// return false if dev_fun_num already registered
|
||||
if (this->dev_map.count(dev_fun_num))
|
||||
@@ -61,7 +59,7 @@ bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
PCIBridgeBase *bridge = dynamic_cast<PCIBridgeBase*>(dev_instance);
|
||||
PCIBridge *bridge = dynamic_cast<PCIBridge*>(dev_instance);
|
||||
if (bridge) {
|
||||
this->bridge_devs.push_back(bridge);
|
||||
}
|
||||
@@ -69,7 +67,7 @@ bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
@@ -77,7 +75,7 @@ bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBa
|
||||
return mem_ctrl->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIHost::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
bool PCIHost::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
@@ -90,7 +88,7 @@ void PCIHost::attach_pci_device(const std::string& dev_name, int slot_id)
|
||||
this->attach_pci_device(dev_name, slot_id, "");
|
||||
}
|
||||
|
||||
PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, const std::string& dev_suffix)
|
||||
PCIDevice *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, const std::string& dev_suffix)
|
||||
{
|
||||
if (!DeviceRegistry::device_registered(dev_name)) {
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
@@ -102,10 +100,7 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
}
|
||||
|
||||
// attempt to create device object
|
||||
auto desc = DeviceRegistry::get_descriptor(dev_name);
|
||||
map<string, string> settings;
|
||||
MachineFactory::get_device_settings(desc, settings);
|
||||
auto dev_obj = desc.m_create_func();
|
||||
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
|
||||
|
||||
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
@@ -120,7 +115,7 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
// add device to the machine object
|
||||
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));
|
||||
PCIDevice *dev = dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
|
||||
|
||||
// register device with the PCI host
|
||||
this->pci_register_device(slot_id, dev);
|
||||
@@ -160,7 +155,7 @@ uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
SIZE_ARG(size)
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
|
||||
return 0;
|
||||
@@ -177,30 +172,24 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
SIZE_ARG(size),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, BYTESWAP_SIZED(value, size)
|
||||
);
|
||||
}
|
||||
|
||||
PCIBase *PCIHost::pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num)
|
||||
PCIDevice *PCIHost::pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num)
|
||||
{
|
||||
for (auto& bridge : this->bridge_devs) {
|
||||
if (bridge->secondary_bus <= bus_num) {
|
||||
if (bridge->secondary_bus == bus_num) {
|
||||
return bridge->pci_find_device(dev_num, fun_num);
|
||||
if (bridge->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
return bridge->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
if (bridge->subordinate_bus >= bus_num) {
|
||||
else if (bridge->subordinate_bus >= bus_num) {
|
||||
return bridge->pci_find_device(bus_num, dev_num, fun_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PCIBase *PCIHost::pci_find_device(uint8_t dev_num, uint8_t fun_num)
|
||||
{
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
return this->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,8 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -38,7 +40,7 @@ enum {
|
||||
PCI_CONFIG_TYPE = 4,
|
||||
PCI_CONFIG_TYPE_0 = 0,
|
||||
PCI_CONFIG_TYPE_1 = 4,
|
||||
}; // PCIAccessFlags
|
||||
};
|
||||
|
||||
/** PCI config space access details */
|
||||
typedef struct AccessDetails {
|
||||
@@ -49,8 +51,8 @@ typedef struct AccessDetails {
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
class PCIBase;
|
||||
class PCIBridgeBase;
|
||||
class PCIDevice;
|
||||
class PCIBridge;
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
@@ -60,14 +62,14 @@ public:
|
||||
};
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIDevice* dev_instance);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
|
||||
PCIBase *attach_pci_device(const std::string& dev_name, int slot_id,
|
||||
const std::string& dev_suffix);
|
||||
PCIDevice *attach_pci_device(const std::string& dev_name, int slot_id,
|
||||
const std::string& dev_suffix);
|
||||
|
||||
virtual bool pci_io_read_loop (uint32_t offset, int size, uint32_t &res);
|
||||
virtual bool pci_io_write_loop(uint32_t offset, int size, uint32_t value);
|
||||
@@ -75,25 +77,29 @@ public:
|
||||
virtual uint32_t pci_io_read_broadcast (uint32_t offset, int size);
|
||||
virtual void pci_io_write_broadcast(uint32_t offset, int size, uint32_t value);
|
||||
|
||||
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 PCIDevice *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
virtual uint32_t pci_t1_read(uint8_t dev, uint32_t fun, uint32_t reg, AccessDetails &details) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual void pci_t1_write(uint8_t dev, uint32_t fun, uint32_t reg, uint32_t value,
|
||||
AccessDetails &details) {};
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIBase*> dev_map;
|
||||
std::vector<PCIBase*> io_space_devs;
|
||||
std::vector<PCIBridgeBase*> bridge_devs;
|
||||
std::unordered_map<int, PCIDevice*> dev_map;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
std::vector<PCIBridge*> bridge_devs;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
/**
|
||||
Perform size dependent endian swapping for value that is dword from PCI config or any other dword little endian register.
|
||||
Perform size dependent endian swapping for value that is dword from PCI config.
|
||||
|
||||
Unaligned data is handled properly by using bytes from the next dword.
|
||||
Unaligned data is handled properly by wrapping around if needed.
|
||||
*/
|
||||
inline uint32_t pci_conv_rd_data(uint32_t value, uint32_t value2, AccessDetails &details) {
|
||||
inline uint32_t pci_conv_rd_data(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
// Bytes
|
||||
case 0x04:
|
||||
@@ -113,20 +119,17 @@ inline uint32_t pci_conv_rd_data(uint32_t value, uint32_t value2, AccessDetails
|
||||
case 0x0A:
|
||||
return BYTESWAP_16((value >> 16) & 0xFFFFU); // 2 3
|
||||
case 0x0B:
|
||||
return ((value >> 16) & 0xFF00) | (value2 & 0xFF); // 3 4
|
||||
return ((value >> 16) & 0xFF00) | (value & 0xFF); // 3 0
|
||||
|
||||
// Dwords
|
||||
case 0x10:
|
||||
return BYTESWAP_32(value); // 0 1 2 3
|
||||
return BYTESWAP_32(value); // 0 1 2 3
|
||||
case 0x11:
|
||||
value = (uint32_t)((((uint64_t)value2 << 32) | value) >> 8);
|
||||
return BYTESWAP_32(value); // 1 2 3 4
|
||||
return ROTL_32(BYTESWAP_32(value), 8); // 1 2 3 0
|
||||
case 0x12:
|
||||
value = (uint32_t)((((uint64_t)value2 << 32) | value) >> 16);
|
||||
return BYTESWAP_32(value); // 2 3 4 5
|
||||
return ROTL_32(BYTESWAP_32(value), 16); // 2 3 0 1
|
||||
case 0x13:
|
||||
value = (uint32_t)((((uint64_t)value2 << 32) | value) >> 24);
|
||||
return BYTESWAP_32(value); // 3 4 5 6
|
||||
return ROTR_32(BYTESWAP_32(value), 8); // 3 0 1 2
|
||||
default:
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
@@ -35,11 +34,11 @@ using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("Scsi0"));
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI_MESH);
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -175,7 +174,6 @@ void MeshController::perform_command(const uint8_t cmd)
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
@@ -263,18 +261,8 @@ void MeshController::update_irq()
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap Mesh_properties = {
|
||||
{"hdd_img2", new StrProperty("")},
|
||||
{"cdr_img2", new StrProperty("")},
|
||||
static const DeviceDescription Mesh_Descriptor = {
|
||||
MeshController::create, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Mesh_Tnt_Descriptor = {
|
||||
MeshController::create_for_tnt, {}, Mesh_properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Mesh_Heathrow_Descriptor = {
|
||||
MeshController::create_for_heathrow, {}, Mesh_properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(MeshTnt, Mesh_Tnt_Descriptor);
|
||||
REGISTER_DEVICE(MeshHeathrow, Mesh_Heathrow_Descriptor);
|
||||
REGISTER_DEVICE(Mesh, Mesh_Descriptor);
|
||||
@@ -24,18 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class InterruptCtrl;
|
||||
class ScsiBus;
|
||||
|
||||
// Chip ID returned by the MESH ASIC on TNT machines (Apple part 343S1146-a)
|
||||
#define TntMeshID 0xE2
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
|
||||
@@ -109,16 +104,6 @@ enum SeqState : uint32_t {
|
||||
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshStub : public HWComponent {
|
||||
public:
|
||||
MeshStub() = default;
|
||||
~MeshStub() = default;
|
||||
|
||||
// registers access
|
||||
uint8_t read(uint8_t reg_offset) { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) {};
|
||||
};
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
@@ -129,11 +114,7 @@ public:
|
||||
};
|
||||
~MeshController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_tnt() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(TntMeshID));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_heathrow() {
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
|
||||
}
|
||||
|
||||
@@ -144,10 +125,6 @@ public:
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
|
||||
protected:
|
||||
void reset(bool is_hard_reset);
|
||||
void perform_command(const uint8_t cmd);
|
||||
@@ -180,9 +157,6 @@ private:
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file NCR53C94/Am53CF94 SCSI controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
@@ -33,7 +32,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)
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice(my_id)
|
||||
{
|
||||
this->chip_id = chip_id;
|
||||
this->my_bus_id = my_id;
|
||||
@@ -43,15 +42,12 @@ Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
|
||||
|
||||
int Sc53C94::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
|
||||
if (this->bus_obj) {
|
||||
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
this->bus_obj->attach_scsi_devices("");
|
||||
}
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("Scsi0"));
|
||||
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI_CURIO);
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -113,7 +109,7 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
LOG_F(INFO, "SC53C94: reading from register %d", reg_offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -147,7 +143,7 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
break;
|
||||
case Write::Reg53C94::Config_1:
|
||||
if ((value & 7) != this->my_bus_id) {
|
||||
ABORT_F("%s: HBA bus ID mismatch!", this->name.c_str());
|
||||
ABORT_F("SC53C94: HBA bus ID mismatch!");
|
||||
}
|
||||
this->config1 = value;
|
||||
break;
|
||||
@@ -158,8 +154,7 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
this->config3 = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "%s: writing 0x%X to %d register", this->name.c_str(), value,
|
||||
reg_offset);
|
||||
LOG_F(INFO, "SC53C94: writing 0x%X to %d register", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +180,6 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "SC53C94: FIFO underrun %d", data_fifo_pos);
|
||||
data_word = 0;
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
@@ -216,7 +207,7 @@ void Sc53C94::pseudo_dma_write(uint16_t data) {
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
|
||||
LOG_F(WARNING, "SC53C94: command register blocked after RESET!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,7 +227,7 @@ void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
exec_command();
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: the top of the command FIFO overwritten!", this->name.c_str());
|
||||
LOG_F(ERROR, "SC53C94: the top of the command FIFO overwritten!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
@@ -276,7 +267,7 @@ void Sc53C94::exec_command()
|
||||
this->on_reset = true; // block the command register
|
||||
return;
|
||||
case CMD_RESET_BUS:
|
||||
LOG_F(INFO, "%s: resetting SCSI bus...", this->name.c_str());
|
||||
LOG_F(INFO, "SC53C94: resetting SCSI bus...");
|
||||
// assert RST line
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
// release RST line after 25 us
|
||||
@@ -286,8 +277,8 @@ void Sc53C94::exec_command()
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & 0x40)) {
|
||||
LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str());
|
||||
this->int_status = INTSTAT_SRST;
|
||||
LOG_F(INFO, "SC53C94: reset interrupt issued");
|
||||
this->int_status |= INTSTAT_SRST;
|
||||
}
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -295,7 +286,7 @@ void Sc53C94::exec_command()
|
||||
if (!this->is_initiator) {
|
||||
// clear command FIFO
|
||||
this->cmd_fifo_pos = 0;
|
||||
this->int_status = INTSTAT_ICMD;
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->seq_step = 0;
|
||||
@@ -311,7 +302,7 @@ void Sc53C94::exec_command()
|
||||
{SeqState::CMD_COMPLETE, 0, INTSTAT_SR}
|
||||
};
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
|
||||
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
|
||||
ABORT_F("Sc53C94: complete steps only works in the STATUS phase");
|
||||
}
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = complete_steps_desc;
|
||||
@@ -323,7 +314,7 @@ void Sc53C94::exec_command()
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
@@ -338,7 +329,7 @@ void Sc53C94::exec_command()
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str());
|
||||
LOG_F(9, "SC53C94: SELECT W/O ATN command started");
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN:
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
|
||||
@@ -352,15 +343,15 @@ void Sc53C94::exec_command()
|
||||
this->cmd_steps = sel_with_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str());
|
||||
LOG_F(9, "SC53C94: SELECT WITH ATN command started");
|
||||
break;
|
||||
case CMD_ENA_SEL_RESEL:
|
||||
exec_next_command();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: invalid/unimplemented command 0x%X", this->name.c_str(), cmd);
|
||||
LOG_F(ERROR, "SC53C94: invalid/unimplemented command 0x%X", cmd);
|
||||
this->cmd_fifo_pos--; // remove invalid command from FIFO
|
||||
this->int_status = INTSTAT_ICMD;
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
}
|
||||
}
|
||||
@@ -381,7 +372,7 @@ void Sc53C94::fifo_push(const uint8_t data)
|
||||
if (this->data_fifo_pos < DATA_FIFO_MAX) {
|
||||
this->data_fifo[this->data_fifo_pos++] = data;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: data FIFO overflow!", this->name.c_str());
|
||||
LOG_F(ERROR, "SC53C94: data FIFO overflow!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
@@ -391,7 +382,7 @@ uint8_t Sc53C94::fifo_pop()
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->data_fifo_pos < 1) {
|
||||
LOG_F(ERROR, "%s: data FIFO underflow!", this->name.c_str());
|
||||
LOG_F(ERROR, "SC53C94: data FIFO underflow!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
@@ -429,7 +420,7 @@ void Sc53C94::sequencer()
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->my_bus_id)) {
|
||||
LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str());
|
||||
LOG_F(ERROR, "SC53C94: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->my_bus_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
@@ -443,7 +434,7 @@ void Sc53C94::sequencer()
|
||||
this->next_state = this->cmd_steps->next_step;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "%s: arbitration lost!", this->name.c_str());
|
||||
LOG_F(INFO, "SC53C94: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->my_bus_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
@@ -459,10 +450,10 @@ void Sc53C94::sequencer()
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->my_bus_id, this->target_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "%s: selection completed", this->name.c_str());
|
||||
LOG_F(9, "SC53C94: selection completed");
|
||||
} else { // selection timeout
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
this->bus_obj->disconnect(this->my_bus_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
@@ -470,27 +461,22 @@ void Sc53C94::sequencer()
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->bytes_out);
|
||||
this->data_fifo_pos -= this->bytes_out;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[this->bytes_out], this->data_fifo_pos);
|
||||
}
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
}
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
this->data_fifo_pos = 0;
|
||||
break;
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -521,7 +507,7 @@ void Sc53C94::sequencer()
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -531,7 +517,7 @@ void Sc53C94::sequencer()
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
this->cmd_fifo_pos = 0; // clear command FIFO
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->rcv_data();
|
||||
@@ -553,7 +539,7 @@ void Sc53C94::sequencer()
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(), this->cur_state);
|
||||
ABORT_F("SC53C94: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,12 +563,10 @@ void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
|
||||
this->name.c_str());
|
||||
LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message");
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
this->cur_bus_phase = param;
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
@@ -590,8 +574,7 @@ void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
|
||||
msg_type);
|
||||
LOG_F(9, "SC53C94: ignore notification message, type: %d", msg_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +593,7 @@ int Sc53C94::send_data(uint8_t* dst_ptr, int count)
|
||||
this->data_fifo_pos -= actual_count;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
|
||||
} else if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
|
||||
} else {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
@@ -639,38 +622,20 @@ bool Sc53C94::rcv_data()
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sc53C94::real_dma_xfer_out()
|
||||
{
|
||||
// transfer data from host's memory to target
|
||||
|
||||
while (this->xfer_count) {
|
||||
uint32_t got_bytes;
|
||||
uint8_t* src_ptr;
|
||||
this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX),
|
||||
&got_bytes, &src_ptr);
|
||||
std::memcpy(this->data_fifo, src_ptr, got_bytes);
|
||||
this->data_fifo_pos = got_bytes;
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::real_dma_xfer_in()
|
||||
void Sc53C94::real_dma_xfer(int direction)
|
||||
{
|
||||
bool is_done = false;
|
||||
|
||||
// transfer data from target to host's memory
|
||||
if (direction) {
|
||||
uint32_t got_bytes;
|
||||
uint8_t* src_ptr;
|
||||
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
while (this->xfer_count) {
|
||||
this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX),
|
||||
&got_bytes, &src_ptr);
|
||||
std::memcpy(this->data_fifo, src_ptr, got_bytes);
|
||||
this->data_fifo_pos = got_bytes;
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
@@ -681,21 +646,31 @@ void Sc53C94::real_dma_xfer_in()
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
} else { // transfer data from target to host's memory
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap Sc53C94_properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Sc53C94_Descriptor = {
|
||||
Sc53C94::create, {}, Sc53C94_properties
|
||||
Sc53C94::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
|
||||
+72
-115
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,117 +29,76 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SC_53C94_H
|
||||
#define SC_53C94_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class DmaBidirChannel;
|
||||
class InterruptCtrl;
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
/** 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0, // Current Transfer Count Register LSB
|
||||
Xfer_Cnt_MSB = 1, // Current Transfer Count Register MSB
|
||||
FIFO = 2, // FIFO Register
|
||||
Command = 3, // Command Register
|
||||
Status = 4, // Status Register
|
||||
Int_Status = 5, // Interrupt Status Register
|
||||
Seq_Step = 6, // Internal State Register
|
||||
FIFO_Flags = 7, // Current FIFO/Internal State Register
|
||||
Config_1 = 8, // Control Register 1
|
||||
//
|
||||
//
|
||||
Config_2 = 0xB, // Control Register 2
|
||||
Config_3 = 0xC, // Control Register 3
|
||||
Config_4 = 0xD, // Control Register 4
|
||||
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
|
||||
//
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Status = 4,
|
||||
Int_Status = 5,
|
||||
Seq_Step = 6,
|
||||
FIFO_Flags = 7,
|
||||
Config_1 = 8,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
|
||||
};
|
||||
};
|
||||
|
||||
/** 53C94 write registers */
|
||||
namespace Write {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0, // Start Transfer Count Register LSB
|
||||
Xfer_Cnt_MSB = 1, // Start Transfer Count Register MSB
|
||||
FIFO = 2, // FIFO Register
|
||||
Command = 3, // Command Register
|
||||
Dest_Bus_ID = 4, // SCSI Destination ID Register (DID)
|
||||
Sel_Timeout = 5, // SCSI Timeout Register
|
||||
Sync_Period = 6, // Synchronous Transfer Period Register
|
||||
Sync_Offset = 7, // Synchronous Offset Register
|
||||
Config_1 = 8, // Control Register 1
|
||||
Clock_Factor = 9, // Clock Factor Register
|
||||
Test_Mode = 0xA, // Forced Test Mode Register
|
||||
Config_2 = 0xB, // Control Register 2
|
||||
Config_3 = 0xC, // Control Register 3
|
||||
Config_4 = 0xD, // Control Register 4 ; Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Start Transfer Count Register High ; Am53CF94 extension
|
||||
Data_Align = 0xF, // Data Alignment Register
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Dest_Bus_ID = 4,
|
||||
Sel_Timeout = 5,
|
||||
Sync_Period = 6,
|
||||
Sync_Offset = 7,
|
||||
Config_1 = 8,
|
||||
Clock_Factor = 9,
|
||||
Test_Mode = 0xA,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
|
||||
Data_Align = 0xF
|
||||
};
|
||||
};
|
||||
|
||||
/** NCR53C94/Am53CF94 commands. */
|
||||
enum {
|
||||
// General Commands
|
||||
CMD_NOP = 0x00, // no interrupt
|
||||
CMD_CLEAR_FIFO = 0x01, // no interrupt
|
||||
CMD_RESET_DEVICE = 0x02, // no interrupt
|
||||
CMD_RESET_BUS = 0x03,
|
||||
|
||||
// Initiator commands
|
||||
CMD_XFER = 0x10,
|
||||
CMD_COMPLETE_STEPS = 0x11,
|
||||
CMD_MSG_ACCEPTED = 0x12,
|
||||
//CMD_TRANSFER_PAD_BYTES = 0x18,
|
||||
CMD_SET_ATN = 0x1A, // no interrupt
|
||||
//CMD_RESET_ATN = 0x1B, // no interrupt
|
||||
|
||||
// Target commands
|
||||
//CMD_SEND_MESSAGE = 0x20,
|
||||
//CMD_SEND_STATUS = 0x21,
|
||||
//CMD_SEND_DATA = 0x22,
|
||||
//CMD_DISCONNECT_STEPS = 0x23,
|
||||
//CMD_TERMINATE_STEPS = 0x24,
|
||||
//CMD_TARGET_COMMAND_COMPLETE_STEPS = 0x25,
|
||||
//CMD_DISCONNECT = 0x27, // no interrupt
|
||||
//CMD_RECEIVE_MESSAGE_STEPS = 0x28,
|
||||
//CMD_RECEIVE_COMMAND = 0x29,
|
||||
//CMD_RECEIVE_DATA = 0x2A,
|
||||
//CMD_RECEIVE_COMMAND_STEPS = 0x2B,
|
||||
CMD_DMA_STOP = 0x04, // no interrupt
|
||||
CMD_ACCESS_FIFO_COMMAND = 0x05,
|
||||
|
||||
// Idle Commands
|
||||
//CMD_RESELECT_STEPS = 0x40,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_SELECT_WITH_ATN = 0x42,
|
||||
//CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
|
||||
CMD_ENA_SEL_RESEL = 0x44, // no interrupt
|
||||
//CMD_DISABLE_SEL_RESEL = 0x45,
|
||||
//CMD_SELECT_WITH_ATN3_STEPS = 0x46,
|
||||
//CMD_RESELECT_WITH_ATN3_STEPS = 0x47,
|
||||
|
||||
// Flags
|
||||
CMD_OPCODE = 0x7F,
|
||||
CMD_ISDMA = 0x80,
|
||||
CMD_NOP = 0,
|
||||
CMD_CLEAR_FIFO = 1,
|
||||
CMD_RESET_DEVICE = 2,
|
||||
CMD_RESET_BUS = 3,
|
||||
CMD_DMA_STOP = 4,
|
||||
CMD_XFER = 0x10,
|
||||
CMD_COMPLETE_STEPS = 0x11,
|
||||
CMD_MSG_ACCEPTED = 0x12,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_SELECT_WITH_ATN = 0x42,
|
||||
CMD_ENA_SEL_RESEL = 0x44,
|
||||
};
|
||||
|
||||
/** Status register bits. **/
|
||||
enum {
|
||||
//SCSI_CTRL_IO = 0x01, // Input/Output
|
||||
//SCSI_CTRL_CD = 0x02, // Command/Data
|
||||
//SCSI_CTRL_MSG = 0x04, // Message
|
||||
//STAT_GCV = 0x08, // Group Code Valid
|
||||
STAT_TC = 0x10, // Terminal count (NCR) / count to zero (AMD)
|
||||
//STAT_PE = 0x20, // Parity Error
|
||||
STAT_GE = 0x40, // Gross Error (NCR) / Illegal Operation Error (AMD)
|
||||
STAT_INT = 0x80, // Interrupt
|
||||
STAT_TC = 1 << 4, // Terminal count (NCR) / count to zero (AMD)
|
||||
STAT_GE = 1 << 6, // Gross Error (NCR) / Illegal Operation Error (AMD)
|
||||
};
|
||||
|
||||
/** Interrupt status register bits. */
|
||||
@@ -207,8 +166,7 @@ public:
|
||||
void pseudo_dma_write(uint16_t data);
|
||||
|
||||
// real DMA control
|
||||
void real_dma_xfer_out();
|
||||
void real_dma_xfer_in();
|
||||
void real_dma_xfer(int direction);
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
@@ -221,7 +179,6 @@ public:
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool get_more_data() { return false; };
|
||||
bool has_data() { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
@@ -242,39 +199,39 @@ protected:
|
||||
void update_irq();
|
||||
|
||||
private:
|
||||
uint8_t chip_id = 0;
|
||||
uint8_t my_bus_id = 0;
|
||||
uint8_t chip_id;
|
||||
uint8_t my_bus_id;
|
||||
ScsiBus* bus_obj;
|
||||
uint32_t my_timer_id = 0;
|
||||
uint32_t my_timer_id;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
uint8_t data_fifo[16];
|
||||
int cmd_fifo_pos = 0;
|
||||
int data_fifo_pos = 0;
|
||||
int bytes_out = 0;
|
||||
int cmd_fifo_pos;
|
||||
int data_fifo_pos;
|
||||
int bytes_out;
|
||||
bool on_reset = false;
|
||||
uint32_t xfer_count = 0;
|
||||
uint32_t set_xfer_count = 0;
|
||||
uint8_t status = 0;
|
||||
uint8_t target_id = 0;
|
||||
uint8_t int_status = 0;
|
||||
uint8_t seq_step = 0;
|
||||
uint8_t sel_timeout = 0;
|
||||
uint8_t sync_offset = 0;
|
||||
uint8_t clk_factor = 0;
|
||||
uint8_t config1 = 0;
|
||||
uint8_t config2 = 0;
|
||||
uint8_t config3 = 0;
|
||||
uint32_t xfer_count;
|
||||
uint32_t set_xfer_count;
|
||||
uint8_t status;
|
||||
uint8_t target_id;
|
||||
uint8_t int_status;
|
||||
uint8_t seq_step;
|
||||
uint8_t sel_timeout;
|
||||
uint8_t sync_offset;
|
||||
uint8_t clk_factor;
|
||||
uint8_t config1;
|
||||
uint8_t config2;
|
||||
uint8_t config3;
|
||||
|
||||
// sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = 0;
|
||||
uint32_t next_state = 0;
|
||||
SeqDesc* cmd_steps = nullptr;
|
||||
bool is_initiator = false;
|
||||
uint8_t cur_cmd = 0;
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
SeqDesc* cmd_steps;
|
||||
bool is_initiator;
|
||||
uint8_t cur_cmd;
|
||||
bool is_dma_cmd = false;
|
||||
int cur_bus_phase = 0;
|
||||
int cur_bus_phase;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
@@ -282,7 +239,7 @@ private:
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch = nullptr;
|
||||
DmaBidirChannel* dma_ch;
|
||||
DrqCb drq_cb = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -73,12 +73,6 @@ namespace ScsiStatus {
|
||||
namespace ScsiMessage {
|
||||
enum : uint8_t {
|
||||
COMMAND_COMPLETE = 0,
|
||||
|
||||
TARGET_ROUTINE_NUMBER_MASK = 0x07,
|
||||
LOGICAL_UNIT_NUMBER_MASK = 0x07,
|
||||
IS_TARGET_ROUTINE_NuMBER = 0x20,
|
||||
HAS_DISCONNECT_PRIVILEDGE = 0x40,
|
||||
IDENTIFY = 0x80,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -95,7 +89,7 @@ enum ScsiCommand : uint8_t {
|
||||
TEST_UNIT_READY = 0x00,
|
||||
REWIND = 0x01,
|
||||
REQ_SENSE = 0x03,
|
||||
FORMAT_UNIT = 0x04,
|
||||
FORMAT = 0x04,
|
||||
READ_BLK_LIMITS = 0x05,
|
||||
READ_6 = 0x08,
|
||||
WRITE_6 = 0x0A,
|
||||
@@ -170,11 +164,8 @@ typedef std::function<void()> action_callback;
|
||||
|
||||
class ScsiDevice : public HWComponent {
|
||||
public:
|
||||
ScsiDevice(std::string name, int my_id) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
ScsiDevice(int my_id) {
|
||||
this->scsi_id = my_id;
|
||||
this->lun = 0,
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
};
|
||||
~ScsiDevice() = default;
|
||||
@@ -185,14 +176,10 @@ public:
|
||||
virtual void switch_phase(const int new_phase);
|
||||
|
||||
virtual bool has_data() { return this->data_size != 0; };
|
||||
virtual int xfer_data();
|
||||
virtual int send_data(uint8_t* dst_ptr, int count);
|
||||
virtual int rcv_data(const uint8_t* src_ptr, const int count);
|
||||
virtual bool check_lun();
|
||||
void illegal_command(const uint8_t* cmd);
|
||||
|
||||
virtual bool prepare_data() = 0;
|
||||
virtual bool get_more_data() = 0;
|
||||
virtual void process_command() = 0;
|
||||
|
||||
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
|
||||
@@ -203,22 +190,14 @@ protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
int scsi_id;
|
||||
int lun;
|
||||
int initiator_id;
|
||||
int cur_phase;
|
||||
uint8_t* data_ptr = nullptr;
|
||||
int data_size;
|
||||
int incoming_size;
|
||||
uint8_t status;
|
||||
|
||||
int sense;
|
||||
int asc;
|
||||
int ascq;
|
||||
int sksv;
|
||||
int field;
|
||||
|
||||
bool last_selection_has_atention = false;
|
||||
uint8_t last_selection_message = 0;
|
||||
ScsiBus* bus_obj;
|
||||
|
||||
action_callback pre_xfer_action = nullptr;
|
||||
@@ -231,16 +210,14 @@ public:
|
||||
ScsiBus(const std::string name);
|
||||
~ScsiBus() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_ScsiMesh() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("ScsiMesh"));
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("SCSIO"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_ScsiCurio() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("ScsiCurio"));
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("SCSI1"));
|
||||
}
|
||||
|
||||
void attach_scsi_devices(const std::string bus_suffix);
|
||||
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
@@ -266,7 +243,6 @@ public:
|
||||
void disconnect(int dev_id);
|
||||
bool pull_data(const int id, uint8_t* dst_ptr, const int size);
|
||||
bool push_data(const int id, const uint8_t* src_ptr, const int size);
|
||||
int target_xfer_data();
|
||||
void target_next_step();
|
||||
bool negotiate_xfer(int& bytes_in, int& bytes_out);
|
||||
|
||||
@@ -281,7 +257,7 @@ private:
|
||||
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
|
||||
|
||||
uint16_t ctrl_lines;
|
||||
int cur_phase = ScsiPhase::BUS_FREE;
|
||||
int cur_phase;
|
||||
int arb_winner_id;
|
||||
int initiator_id;
|
||||
int target_id;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,14 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsihd.h>
|
||||
#include <devices/common/scsi/scsicdrom.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <sstream>
|
||||
|
||||
ScsiBus::ScsiBus(const std::string name)
|
||||
{
|
||||
@@ -73,8 +69,6 @@ void ScsiBus::change_bus_phase(int initiator_id)
|
||||
|
||||
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", initiator_id);
|
||||
|
||||
uint16_t new_state = 0xFFFFU & mask;
|
||||
|
||||
this->dev_ctrl_lines[initiator_id] |= new_state;
|
||||
@@ -92,8 +86,6 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
|
||||
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", id);
|
||||
|
||||
uint16_t new_state = 0;
|
||||
|
||||
this->dev_ctrl_lines[id] &= ~mask;
|
||||
@@ -149,9 +141,6 @@ int ScsiBus::switch_phase(int id, int new_phase)
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG | SCSI_CTRL_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
// enter new phase (low-level)
|
||||
@@ -168,9 +157,6 @@ int ScsiBus::switch_phase(int id, int new_phase)
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG | SCSI_CTRL_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
// switch the bus to the new phase (high-level)
|
||||
@@ -271,10 +257,6 @@ bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiBus::target_xfer_data() {
|
||||
return this->devices[this->target_id]->xfer_data();
|
||||
}
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step();
|
||||
@@ -296,60 +278,13 @@ void ScsiBus::disconnect(int dev_id)
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
{
|
||||
std::string path;
|
||||
int scsi_id;
|
||||
std::string image_path;
|
||||
|
||||
image_path = GET_STR_PROP("hdd_img" + bus_suffix);
|
||||
if (!image_path.empty()) {
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we skip ID 3.
|
||||
for (scsi_id = 0; scsi_id < SCSI_MAX_DEVS * 2 && (scsi_id == 3 || this->devices[scsi_id % SCSI_MAX_DEVS]); scsi_id++) {}
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiHD" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
ScsiHardDisk *scsi_device = new ScsiHardDisk(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiHardDisk>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. HDD \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image_path = GET_STR_PROP("cdr_img" + bus_suffix);
|
||||
if (!image_path.empty()) {
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we start at ID 3.
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 && this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
ScsiCdrom *scsi_device = new ScsiCdrom(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription ScsiCurio_Descriptor = {
|
||||
ScsiBus::create_ScsiCurio, {}, {}
|
||||
static const DeviceDescription Scsi0_Descriptor = {
|
||||
ScsiBus::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription ScsiMesh_Descriptor = {
|
||||
ScsiBus::create_ScsiMesh, {}, {}
|
||||
static const DeviceDescription Scsi1_Descriptor = {
|
||||
ScsiBus::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
|
||||
REGISTER_DEVICE(ScsiMesh, ScsiMesh_Descriptor);
|
||||
REGISTER_DEVICE(Scsi0, Scsi0_Descriptor);
|
||||
REGISTER_DEVICE(Scsi1, Scsi1_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,7 +28,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -36,12 +39,39 @@ static char cdrom_vendor_sony_id[] = "SONY ";
|
||||
static char cdu8003a_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char cdu8003a_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
|
||||
ScsiCdrom::ScsiCdrom(int my_id) : ScsiDevice(my_id)
|
||||
{
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
|
||||
this->sector_size = 2048;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
}
|
||||
|
||||
void ScsiCdrom::insert_image(std::string filename)
|
||||
{
|
||||
this->cdr_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_frames = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
|
||||
// create single track descriptor
|
||||
this->tracks[0] = {.trk_num = 1, .adr_ctrl = 0x14, .start_lba = 0};
|
||||
this->num_tracks = 1;
|
||||
|
||||
// create Lead-out descriptor containing all data
|
||||
this->tracks[1] = {.trk_num = LEAD_OUT_TRK_NUM, .adr_ctrl = 0x14,
|
||||
.start_lba = static_cast<uint32_t>(this->total_frames)};
|
||||
} else {
|
||||
ABORT_F("SCSI-CDROM: could not determine file size using stat()");
|
||||
}
|
||||
this->cdr_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba, xfer_len;
|
||||
@@ -52,108 +82,44 @@ void ScsiCdrom::process_command()
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
|
||||
// use internal data buffer by default
|
||||
this->data_ptr = this->data_buf;
|
||||
|
||||
uint8_t* cmd = this->cmd_buf;
|
||||
|
||||
switch (cmd[0]) {
|
||||
switch (cmd_buf[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
lba = ((cmd_buf[1] & 0x1F) << 16) + (cmd_buf[2] << 8) + cmd_buf[3];
|
||||
this->read(lba, cmd_buf[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->incoming_size = cmd[4];
|
||||
this->incoming_size = this->cmd_buf[4];
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
this->eject_allowed = (this->cmd_buf[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity_10();
|
||||
this->read_capacity();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
xfer_len = READ_WORD_BE_U(&cmd[7]);
|
||||
if (cmd[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
|
||||
lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_buf[7]);
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_10");
|
||||
}
|
||||
read(lba, xfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_LONG_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
default:
|
||||
this->illegal_command(cmd);
|
||||
ABORT_F("SCSI_CDROM: unsupported command %d", this->cmd_buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,58 +127,55 @@ bool ScsiCdrom::prepare_data()
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
|
||||
LOG_F(WARNING, "SCSI_CDROM: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScsiCdrom::get_more_data() {
|
||||
if (this->data_left()) {
|
||||
this->data_size = this->read_more();
|
||||
this->data_ptr = (uint8_t *)this->data_cache.get();
|
||||
void ScsiCdrom::read(const uint32_t lba, const uint16_t transfer_len, const uint8_t cmd_len)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return this->data_size != 0;
|
||||
}
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = lba * this->sector_size;
|
||||
|
||||
void ScsiCdrom::read(const uint32_t lba, uint16_t nblocks, const uint8_t cmd_len)
|
||||
{
|
||||
if (cmd_len == 6 && nblocks == 0)
|
||||
nblocks = 256;
|
||||
|
||||
this->set_fpos(lba);
|
||||
this->data_ptr = (uint8_t *)this->data_cache.get();
|
||||
this->bytes_out = this->read_begin(nblocks, UINT32_MAX);
|
||||
this->cdr_img.seekg(device_offset, this->cdr_img.beg);
|
||||
this->cdr_img.read(this->data_buf, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
int ScsiCdrom::test_unit_ready()
|
||||
void ScsiCdrom::inquiry()
|
||||
{
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
void ScsiCdrom::inquiry() {
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
ABORT_F("SCSI_CDROM: invalid page number in INQUIRY");
|
||||
}
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
LOG_F(WARNING, "SCSI_CDROM: more than 36 bytes requested in INQUIRY");
|
||||
}
|
||||
|
||||
this->data_buf[0] = 5; // device type: CD-ROM
|
||||
@@ -238,9 +201,9 @@ static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
void ScsiCdrom::mode_sense()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
//uint8_t alloc_len = this->cmd_buf[4];
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
int num_blocks = this->size_blocks;
|
||||
int num_blocks = (this->img_size + this->sector_size) / this->sector_size;
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
@@ -253,8 +216,8 @@ void ScsiCdrom::mode_sense()
|
||||
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
|
||||
this->data_buf[ 8] = 0;
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = (this->block_size >> 8) & 0xFFU;
|
||||
this->data_buf[11] = (this->block_size ) & 0xFFU;
|
||||
this->data_buf[10] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[11] = (this->sector_size ) & 0xFFU;
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
|
||||
@@ -269,16 +232,8 @@ void ScsiCdrom::mode_sense()
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
this->data_buf[0] += 23;
|
||||
break;
|
||||
case 0x31:
|
||||
this->data_buf[13] = 6; // data size
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
this->data_buf[14] = '.';
|
||||
this->data_buf[15] = 'A';
|
||||
this->data_buf[16] = 'p';
|
||||
this->data_buf[17] = 'p';
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
|
||||
}
|
||||
|
||||
this->bytes_out = this->data_buf[0];
|
||||
@@ -295,11 +250,11 @@ void ScsiCdrom::read_toc()
|
||||
bool is_msf = !!(this->cmd_buf[1] & 2);
|
||||
|
||||
if (this->cmd_buf[2] & 0xF) {
|
||||
ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str());
|
||||
ABORT_F("SCSI-CDROM: unsupported format in READ_TOC");
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str());
|
||||
LOG_F(WARNING, "SCSI-CDROM: zero allocation length passed to READ_TOC");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -313,15 +268,14 @@ void ScsiCdrom::read_toc()
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(),
|
||||
start_track);
|
||||
LOG_F(ERROR, "SCSI-CDROM: invalid starting track %d in READ_TOC", start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* buf_ptr = this->data_buf;
|
||||
char* buf_ptr = this->data_buf;
|
||||
|
||||
int data_len = (tot_tracks * 8) + 2;
|
||||
|
||||
@@ -362,23 +316,23 @@ void ScsiCdrom::read_toc()
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity_10()
|
||||
void ScsiCdrom::read_capacity()
|
||||
{
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str());
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
LOG_F(ERROR, "SCSI-CDROM: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int last_lba = this->size_blocks - 1;
|
||||
int last_lba = this->total_frames - 1;
|
||||
|
||||
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
|
||||
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
|
||||
@@ -386,11 +340,25 @@ void ScsiCdrom::read_capacity_10()
|
||||
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
|
||||
this->data_buf[4] = 0;
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = (this->block_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->block_size & 0xFFU;
|
||||
this->data_buf[6] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->sector_size & 0xFFU;
|
||||
|
||||
this->bytes_out = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
AddrMsf ScsiCdrom::lba_to_msf(const int lba)
|
||||
{
|
||||
return {.min = lba / 4500, .sec = (lba / 75) % 60, .frm = lba % 75};
|
||||
}
|
||||
|
||||
static const PropMap ScsiCdromProperties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription ScsiCdromDescriptor =
|
||||
{ScsiCdrom::create, {}, ScsiCdromProperties};
|
||||
|
||||
REGISTER_DEVICE(ScsiCdrom, ScsiCdromDescriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,34 +25,65 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SCSI_CDROM_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ScsiCdrom : public ScsiDevice, public CdromDrive {
|
||||
/* Original CD-ROM addressing mode expressed
|
||||
in minutes, seconds and frames */
|
||||
typedef struct {
|
||||
int min;
|
||||
int sec;
|
||||
int frm;
|
||||
} AddrMsf;
|
||||
|
||||
/* Descriptor for CD-ROM tracks in TOC */
|
||||
typedef struct {
|
||||
uint8_t trk_num;
|
||||
uint8_t adr_ctrl;
|
||||
uint32_t start_lba;
|
||||
} TrackDescriptor;
|
||||
|
||||
#define CDROM_MAX_TRACKS 100
|
||||
#define LEAD_OUT_TRK_NUM 0xAA
|
||||
|
||||
class ScsiCdrom : public ScsiDevice {
|
||||
public:
|
||||
ScsiCdrom(std::string name, int my_id);
|
||||
ScsiCdrom(int my_id);
|
||||
~ScsiCdrom() = default;
|
||||
|
||||
virtual void process_command() override;
|
||||
virtual bool prepare_data() override;
|
||||
virtual bool get_more_data() override;
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiCdrom>(new ScsiCdrom(3));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
|
||||
virtual void process_command();
|
||||
virtual bool prepare_data();
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void inquiry();
|
||||
void mode_sense();
|
||||
void read_toc();
|
||||
void read_capacity_10();
|
||||
void read_capacity();
|
||||
|
||||
private:
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_buf[2048] = {};
|
||||
AddrMsf lba_to_msf(const int lba);
|
||||
|
||||
private:
|
||||
std::fstream cdr_img;
|
||||
uint64_t img_size;
|
||||
int total_frames;
|
||||
int num_tracks;
|
||||
int sector_size;
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
TrackDescriptor tracks[CDROM_MAX_TRACKS];
|
||||
|
||||
char data_buf[1 << 18]; // TODO: proper buffer management
|
||||
};
|
||||
|
||||
#endif // SCSI_CDROM_H
|
||||
@@ -48,12 +48,16 @@ void ScsiDevice::notify(ScsiMsg msg_type, int param)
|
||||
this->initiator_id = this->bus_obj->get_initiator_id();
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
this->last_selection_has_atention = true;
|
||||
this->last_selection_message = this->msg_buf[0];
|
||||
//LOG_F(SCSIDEVICE, "%s: received message:0x%02x", this->get_name().c_str(), this->msg_buf[0]);
|
||||
if (this->msg_buf[0] != 0x80) {
|
||||
LOG_F(INFO, "ScsiDevice: received message 0x%X", this->msg_buf[0]);
|
||||
}
|
||||
}
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
this->process_command();
|
||||
if (this->prepare_data()) {
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
} else {
|
||||
this->last_selection_has_atention = false;
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
ABORT_F("ScsiDevice: prepare_data() failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,6 +75,10 @@ void ScsiDevice::switch_phase(const int new_phase)
|
||||
void ScsiDevice::next_step()
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->process_command();
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->data_size >= this->incoming_size) {
|
||||
if (this->post_xfer_action != nullptr) {
|
||||
@@ -84,22 +92,9 @@ void ScsiDevice::next_step()
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::COMMAND:
|
||||
this->process_command();
|
||||
if (this->cur_phase != ScsiPhase::COMMAND) {
|
||||
if (this->prepare_data()) {
|
||||
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
} else {
|
||||
ABORT_F("ScsiDevice: prepare_data() failed");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::BUS_FREE:
|
||||
this->bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
@@ -117,8 +112,7 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->data_ptr = this->cmd_buf;
|
||||
this->data_size = 0;
|
||||
bytes_out = 0;
|
||||
this->data_size = bytes_in;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->data_ptr = &this->status;
|
||||
@@ -133,7 +127,6 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = bytes_in;
|
||||
bytes_out = 0;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_ptr = this->msg_buf;
|
||||
@@ -145,42 +138,6 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
}
|
||||
}
|
||||
|
||||
static const int CmdGroupLen[8] = {6, 10, 10, -1, -1, 12, -1, -1};
|
||||
|
||||
int ScsiDevice::xfer_data() {
|
||||
this->cur_phase = bus_obj->current_phase();
|
||||
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
if (this->bus_obj->pull_data(this->initiator_id, this->msg_buf, 1)) {
|
||||
if (this->msg_buf[0] & 0x80) {
|
||||
LOG_F(9, "%s: IDENTIFY MESSAGE received, code = 0x%X",
|
||||
this->name.c_str(), this->msg_buf[0]);
|
||||
this->next_step();
|
||||
} else {
|
||||
ABORT_F("%s: unsupported message received, code = 0x%X",
|
||||
this->name.c_str(), this->msg_buf[0]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::COMMAND:
|
||||
if (this->bus_obj->pull_data(this->initiator_id, this->cmd_buf, 1)) {
|
||||
int cmd_len = CmdGroupLen[this->cmd_buf[0] >> 5];
|
||||
if (cmd_len < 0) {
|
||||
ABORT_F("%s: unsupported command received, code = 0x%X",
|
||||
this->name.c_str(), this->msg_buf[0]);
|
||||
}
|
||||
if (this->bus_obj->pull_data(this->initiator_id, &this->cmd_buf[1], cmd_len - 1))
|
||||
this->next_step();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("ScsiDevice: unhandled phase %d in xfer_data()", this->cur_phase);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScsiDevice::send_data(uint8_t* dst_ptr, const int count)
|
||||
{
|
||||
if (dst_ptr == nullptr || !count) {
|
||||
@@ -193,18 +150,6 @@ int ScsiDevice::send_data(uint8_t* dst_ptr, const int count)
|
||||
this->data_ptr += actual_count;
|
||||
this->data_size -= actual_count;
|
||||
|
||||
// attempt to return the requested amount of data
|
||||
// when data_size drops down to zero
|
||||
if (!this->data_size) {
|
||||
if (this->get_more_data() && count > actual_count) {
|
||||
dst_ptr += actual_count;
|
||||
actual_count = std::min(this->data_size, count - actual_count);
|
||||
std::memcpy(dst_ptr, this->data_ptr, actual_count);
|
||||
this->data_ptr += actual_count;
|
||||
this->data_size -= actual_count;
|
||||
}
|
||||
}
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
@@ -215,36 +160,5 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
this->data_ptr += count;
|
||||
this->data_size += count;
|
||||
|
||||
if (this->cur_phase == ScsiPhase::COMMAND)
|
||||
this->next_step();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool ScsiDevice::check_lun()
|
||||
{
|
||||
if (this->cmd_buf[1] >> 5 != this->lun) {
|
||||
LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x25; // Logical Unit Not Supported
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd)
|
||||
{
|
||||
LOG_F(ERROR, "%s: unsupported command: 0x%02x", this->name.c_str(), cmd[0]);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x20; // Invalid command operation code
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
+133
-162
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,39 +21,48 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Generic SCSI Hard Disk emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsihd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define HDD_SECTOR_SIZE 512
|
||||
|
||||
using namespace std;
|
||||
|
||||
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
|
||||
ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) {
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::insert_image(std::string filename) {
|
||||
//We don't want to store everything in memory, but
|
||||
//we want to keep the hard disk available.
|
||||
if (!this->disk_img.open(filename))
|
||||
ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str());
|
||||
this->hdd_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
this->img_size = this->disk_img.size();
|
||||
uint64_t tb = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
this->total_blocks = static_cast<int>(tb);
|
||||
if (this->total_blocks < 0 || tb != this->total_blocks) {
|
||||
ABORT_F("ScsiHardDisk: file size is too large");
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE;
|
||||
} else {
|
||||
ABORT_F("SCSI-HD: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::process_command() {
|
||||
uint32_t lba = 0;
|
||||
uint16_t transfer_len = 0;
|
||||
uint16_t alloc_len = 0;
|
||||
uint8_t param_len = 0;
|
||||
|
||||
uint8_t page_code = 0;
|
||||
uint8_t subpage_code = 0;
|
||||
@@ -72,124 +81,82 @@ void ScsiHardDisk::process_command() {
|
||||
test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
rewind();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
alloc_len = cmd[4];
|
||||
req_sense(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->format();
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
read(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
read(lba, transfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
write(lba, transfer_len, 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
case ScsiCommand::SEEK_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
seek(lba);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
param_len = cmd[4];
|
||||
mode_select_6(param_len);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_BUFFER:
|
||||
read_buffer();
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
default:
|
||||
this->illegal_command(cmd);
|
||||
LOG_F(WARNING, "SCSI-HD: unrecognized command: %x", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiHardDisk::prepare_data() {
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
if (!error) {
|
||||
this->data_buf[0] = ScsiStatus::GOOD;
|
||||
this->img_buffer[0] = ScsiStatus::GOOD;
|
||||
} else {
|
||||
this->data_buf[0] = ScsiStatus::CHECK_CONDITION;
|
||||
this->img_buffer[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->data_size = 1;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_buf[0] = this->msg_code;
|
||||
this->img_buffer[0] = this->msg_code;
|
||||
this->data_size = 1;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
|
||||
LOG_F(WARNING, "SCSI-HD: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -203,8 +170,7 @@ int ScsiHardDisk::test_unit_ready() {
|
||||
|
||||
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
if (alloc_len != 252) {
|
||||
LOG_F(WARNING, "%s: inappropriate Allocation Length: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
}
|
||||
@@ -214,29 +180,28 @@ void ScsiHardDisk::inquiry() {
|
||||
int alloc_len = cmd_buf[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
ABORT_F("SCSI-HD: invalid page number in INQUIRY");
|
||||
}
|
||||
|
||||
if (alloc_len >= 36) {
|
||||
this->data_buf[0] = 0; // device type: Direct-access block device
|
||||
this->data_buf[1] = 0; // non-removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(data_buf + 8, vendor_info, 8);
|
||||
std::memcpy(data_buf + 16, prod_info, 16);
|
||||
std::memcpy(data_buf + 32, rev_info, 4);
|
||||
this->img_buffer[0] = 0; // device type: Direct-access block device
|
||||
this->img_buffer[1] = 0; // non-removable media
|
||||
this->img_buffer[2] = 2; // ANSI version: SCSI-2
|
||||
this->img_buffer[3] = 1; // response data format
|
||||
this->img_buffer[4] = 0; // additional length
|
||||
this->img_buffer[5] = 0;
|
||||
this->img_buffer[6] = 0;
|
||||
this->img_buffer[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(img_buffer + 8, vendor_info, 8);
|
||||
std::memcpy(img_buffer + 16, prod_info, 16);
|
||||
std::memcpy(img_buffer + 32, rev_info, 4);
|
||||
|
||||
this->bytes_out = 36;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
LOG_F(WARNING, "Allocation length too small: %d", alloc_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,21 +209,14 @@ int ScsiHardDisk::send_diagnostic() {
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
void ScsiHardDisk::mode_select_6(uint8_t param_len) {
|
||||
if (!param_len) {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
int ScsiHardDisk::mode_select_6(uint8_t param_len) {
|
||||
if (param_len == 0) {
|
||||
return 0x0;
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Mode Select calling for param length of: %d", param_len);
|
||||
return param_len;
|
||||
}
|
||||
|
||||
this->incoming_size = param_len;
|
||||
|
||||
std::memset(&this->data_buf[0], 0xDD, this->sector_size);
|
||||
|
||||
this->post_xfer_action = [this]() {
|
||||
// TODO: parse the received mode parameter list here
|
||||
};
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
@@ -268,49 +226,48 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0; // medium is write enabled
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
this->img_buffer[ 0] = 13; // initial data size
|
||||
this->img_buffer[ 1] = 0; // medium type
|
||||
this->img_buffer[ 2] = 0; // medium is write enabled
|
||||
this->img_buffer[ 3] = 8; // block description length
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (this->total_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (this->total_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (this->total_blocks ) & 0xFFU;
|
||||
WRITE_DWORD_BE_A(&this->data_buf[8], this->sector_size);
|
||||
this->img_buffer[ 4] = 0; // density code
|
||||
this->img_buffer[ 5] = (this->total_blocks >> 16) & 0xFFU;
|
||||
this->img_buffer[ 6] = (this->total_blocks >> 8) & 0xFFU;
|
||||
this->img_buffer[ 7] = (this->total_blocks ) & 0xFFU;
|
||||
this->img_buffer[ 8] = 0;
|
||||
this->img_buffer[ 9] = 0; // sector size MSB
|
||||
this->img_buffer[10] = 2; // sector size
|
||||
this->img_buffer[11] = 0; // sector size LSB
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
this->img_buffer[12] = page_code;
|
||||
|
||||
switch(page_code) {
|
||||
case 1: // read-write error recovery page
|
||||
this->data_buf[13] = 6; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
break;
|
||||
case 3: // Format device page
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 22);
|
||||
this->img_buffer[13] = 22; // data size - 1
|
||||
std::memset(&this->img_buffer[14], 0, 22);
|
||||
// default values taken from Empire 540/1080S manual
|
||||
this->data_buf[15] = 6; // tracks per defect zone
|
||||
this->data_buf[17] = 1; // alternate sectors per zone
|
||||
this->data_buf[23] = 92; // sectors per track in the outermost zone
|
||||
this->data_buf[27] = 1; // interleave factor
|
||||
this->data_buf[29] = 19; // track skew factor
|
||||
this->data_buf[31] = 25; // cylinder skew factor
|
||||
this->data_buf[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
WRITE_WORD_BE_U(&this->data_buf[24], 512); // bytes per sector
|
||||
this->img_buffer[15] = 6; // tracks per defect zone
|
||||
this->img_buffer[17] = 1; // alternate sectors per zone
|
||||
this->img_buffer[23] = 92; // sectors per track in the outermost zone
|
||||
this->img_buffer[27] = 1; // interleave factor
|
||||
this->img_buffer[29] = 19; // track skew factor
|
||||
this->img_buffer[31] = 25; // cylinder skew factor
|
||||
this->img_buffer[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
WRITE_WORD_BE_U(&this->img_buffer[24], 512); // bytes per sector
|
||||
break;
|
||||
case 0x30: // Copyright page for Apple certified drives
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
this->img_buffer[13] = 22; // data size - 1
|
||||
std::memcpy(&this->img_buffer[14], Apple_Copyright_Page_Data, 22);
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
|
||||
};
|
||||
|
||||
// adjust for overall mode sense data length
|
||||
this->data_buf[0] += this->data_buf[13] + 1;
|
||||
this->img_buffer[0] += this->img_buffer[13] + 1;
|
||||
|
||||
this->bytes_out = std::min(alloc_len, (uint8_t)this->data_buf[0]);
|
||||
this->bytes_out = std::min(alloc_len, (uint8_t)this->img_buffer[0]);
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
@@ -319,11 +276,11 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str());
|
||||
ABORT_F("SCSI-HD: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
LOG_F(ERROR, "SCSI-HD: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
@@ -331,10 +288,10 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
}
|
||||
|
||||
uint32_t last_lba = this->total_blocks - 1;
|
||||
uint32_t blk_len = this->sector_size;
|
||||
uint32_t blk_len = HDD_SECTOR_SIZE;
|
||||
|
||||
WRITE_DWORD_BE_A(&data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&data_buf[4], blk_len);
|
||||
WRITE_DWORD_BE_A(&img_buffer[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&img_buffer[4], blk_len);
|
||||
|
||||
this->bytes_out = 8;
|
||||
|
||||
@@ -343,29 +300,22 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
|
||||
|
||||
void ScsiHardDisk::format() {
|
||||
LOG_F(WARNING, "%s: attempt to format the disk!", this->name.c_str());
|
||||
|
||||
if (this->cmd_buf[1] & 0x10)
|
||||
ABORT_F("%s: defect list isn't supported yet", this->name.c_str());
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(NS_PER_SEC, [this]() {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
});
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(data_buf, 0, sizeof(data_buf));
|
||||
std::memset(img_buffer, 0, sizeof(img_buffer));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = (uint64_t)lba * this->sector_size;
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->disk_img.read(data_buf, device_offset, transfer_size);
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
this->hdd_img.read(img_buffer, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
|
||||
@@ -379,16 +329,27 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = (uint64_t)lba * this->sector_size;
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->incoming_size = transfer_size;
|
||||
|
||||
this->post_xfer_action = [this, device_offset]() {
|
||||
this->disk_img.write(this->data_buf, device_offset, this->incoming_size);
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->img_buffer, this->incoming_size);
|
||||
};
|
||||
}
|
||||
|
||||
void ScsiHardDisk::seek(uint32_t lba) {
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::rewind() {
|
||||
this->hdd_img.seekg(0, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_buffer() {
|
||||
uint8_t mode = this->cmd_buf[1];
|
||||
uint32_t alloc_len = (this->cmd_buf[6] << 24) | (this->cmd_buf[7] << 16) |
|
||||
@@ -396,13 +357,23 @@ void ScsiHardDisk::read_buffer() {
|
||||
|
||||
switch(mode) {
|
||||
case 0: // Combined header and data mode
|
||||
WRITE_DWORD_BE_A(&this->data_buf[0], 0x10000); // report buffer size of 64K
|
||||
WRITE_DWORD_BE_A(&this->img_buffer[0], 0x10000); // report buffer size of 64K
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported mode %d in READ_BUFFER", this->name.c_str(), mode);
|
||||
ABORT_F("SCSI-HD: unsupported mode %d in READ_BUFFER", mode);
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
static const PropMap SCSI_HD_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
{"hdd_wr_prot", new BinProperty(0)},
|
||||
};
|
||||
|
||||
static const DeviceDescription SCSI_HD_Descriptor =
|
||||
{ScsiHardDisk::create, {}, SCSI_HD_Properties};
|
||||
|
||||
REGISTER_DEVICE(ScsiHD, SCSI_HD_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,27 +25,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SCSI_HD_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
class ScsiHardDisk : public ScsiDevice {
|
||||
public:
|
||||
ScsiHardDisk(std::string name, int my_id);
|
||||
ScsiHardDisk(int my_id);
|
||||
~ScsiHardDisk() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
void process_command();
|
||||
bool prepare_data();
|
||||
bool get_more_data() { return false; };
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
int req_sense(uint16_t alloc_len);
|
||||
int send_diagnostic();
|
||||
void mode_select_6(uint8_t param_len);
|
||||
int test_unit_ready();
|
||||
int req_sense(uint16_t alloc_len);
|
||||
int send_diagnostic();
|
||||
int mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6();
|
||||
void format();
|
||||
@@ -58,17 +62,17 @@ protected:
|
||||
void read_buffer();
|
||||
|
||||
private:
|
||||
ImgFile disk_img;
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
static const int sector_size = 512;
|
||||
int bytes_out = 0;
|
||||
|
||||
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
|
||||
char img_buffer[1 << 21]; // TODO: add proper buffer management!
|
||||
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
uint32_t cur_buf_cnt = 0;
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
||||
|
||||
+13
-34
@@ -24,8 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -34,6 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -89,26 +88,6 @@ ViaCuda::ViaCuda() {
|
||||
this->int_ctrl = nullptr;
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer_on) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
}
|
||||
if (this->t1_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
}
|
||||
if (this->t2_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
}
|
||||
if (this->treq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer_id);
|
||||
this->treq_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ViaCuda::device_postinit()
|
||||
{
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
@@ -363,12 +342,11 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
process_packet();
|
||||
|
||||
// start response transaction
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -495,20 +473,25 @@ void ViaCuda::process_adb_command() {
|
||||
}
|
||||
|
||||
void ViaCuda::autopoll_handler() {
|
||||
uint8_t adb_status, output_size;
|
||||
|
||||
if (!this->autopoll_enabled)
|
||||
return;
|
||||
|
||||
uint8_t poll_command = this->adb_bus_obj->poll();
|
||||
// send TALK R0 command to address 3 (mouse)
|
||||
uint8_t in_data[2] = { 0x3C, 0};
|
||||
|
||||
if (poll_command) {
|
||||
adb_status = this->adb_bus_obj->process_command(in_data, 1);
|
||||
|
||||
if (adb_status == ADB_STAT_OK) {
|
||||
if (!this->old_tip || !this->treq) {
|
||||
LOG_F(WARNING, "Cuda transaction probably in progress");
|
||||
}
|
||||
|
||||
// prepare autopoll packet
|
||||
response_header(CUDA_PKT_ADB, ADB_STAT_OK | ADB_STAT_AUTOPOLL);
|
||||
this->out_buf[2] = poll_command; // put the proper ADB command
|
||||
uint8_t output_size = this->adb_bus_obj->get_output_count();
|
||||
response_header(CUDA_PKT_ADB, adb_status | ADB_STAT_AUTOPOLL);
|
||||
this->out_buf[2] = 0x3C; // put the proper ADB command
|
||||
output_size = this->adb_bus_obj->get_output_count();
|
||||
if (output_size) {
|
||||
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
|
||||
this->out_count += output_size;
|
||||
@@ -655,14 +638,10 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
LOG_F(INFO, "Cuda: send %d to PB0", (int)(this->in_buf[2]));
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
LOG_F(INFO, "Cuda: system restart");
|
||||
power_on = false;
|
||||
power_off_reason = po_restart;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
|
||||
//exit(0);
|
||||
|
||||
@@ -43,15 +43,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class AdbBus;
|
||||
class InterruptCtrl;
|
||||
|
||||
#define VIA_CLOCK_HZ 783360
|
||||
|
||||
/** VIA register offsets. */
|
||||
@@ -155,7 +154,7 @@ enum {
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
public:
|
||||
ViaCuda();
|
||||
~ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ViaCuda>(new ViaCuda());
|
||||
@@ -206,7 +205,6 @@ private:
|
||||
uint8_t old_tip;
|
||||
uint8_t old_byteack;
|
||||
uint8_t treq;
|
||||
uint32_t treq_timer_id = 0;
|
||||
uint8_t in_buf[CUDA_IN_BUF_SIZE];
|
||||
int32_t in_count;
|
||||
uint8_t out_buf[16];
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
|
||||
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DEVICE_REGISTRY_H
|
||||
#define DEVICE_REGISTRY_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <functional>
|
||||
@@ -32,8 +33,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class HWComponent;
|
||||
|
||||
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
|
||||
|
||||
struct DeviceDescription {
|
||||
|
||||
@@ -25,13 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machineproperties.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
static FlopImgType identify_image(ImgFile& img_file)
|
||||
static FlopImgType identify_image(std::ifstream& img_file)
|
||||
{
|
||||
// WOZ images identification strings
|
||||
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
@@ -39,7 +39,8 @@ static FlopImgType identify_image(ImgFile& img_file)
|
||||
|
||||
uint8_t buf[8] = { 0 };
|
||||
|
||||
img_file.read((char *)buf, 0, sizeof(buf));
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// WOZ files are easily identified
|
||||
if (!std::memcmp(buf, WOZ1_SIG, sizeof(buf))) {
|
||||
@@ -49,7 +50,8 @@ static FlopImgType identify_image(ImgFile& img_file)
|
||||
} else {
|
||||
for (int offset = 0; offset <=84; offset += 84) {
|
||||
// rewind to logical block 2
|
||||
img_file.read((char *)buf, 2*BLOCK_SIZE + offset, sizeof(buf));
|
||||
img_file.seekg(2*BLOCK_SIZE + offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// check for HFS/MFS signature at the start of the logical block 2
|
||||
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
|
||||
@@ -77,22 +79,26 @@ RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
|
||||
*/
|
||||
int RawFloppyImg::calc_phys_params()
|
||||
{
|
||||
ImgFile img_file;
|
||||
std::ifstream img_file;
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
size_t img_size = img_file.size();
|
||||
img_file.close();
|
||||
img_file.seekg(0, img_file.end);
|
||||
size_t img_size = img_file.tellg();
|
||||
if (img_size > 2*1024*1024) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image size is too large to determine disk format from image size!");
|
||||
return -1;
|
||||
}
|
||||
this->img_size = (int)img_size;
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
img_file.close();
|
||||
|
||||
// verify image size
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
@@ -171,15 +177,17 @@ int RawFloppyImg::calc_phys_params()
|
||||
/** Retrieve raw disk data. */
|
||||
int RawFloppyImg::get_raw_disk_data(char* buf)
|
||||
{
|
||||
ImgFile img_file;
|
||||
std::ifstream img_file;
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
img_file.read(buf, 0, this->data_size);
|
||||
img_file.seekg(0, img_file.beg);
|
||||
img_file.read(buf, this->data_size);
|
||||
img_file.close();
|
||||
|
||||
return 0;
|
||||
@@ -198,20 +206,24 @@ DiskCopy42Img::DiskCopy42Img(std::string& file_path) : FloppyImgConverter()
|
||||
}
|
||||
|
||||
int DiskCopy42Img::calc_phys_params() {
|
||||
ImgFile img_file;
|
||||
std::ifstream img_file;
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
size_t img_size = img_file.size();
|
||||
img_file.seekg(0, img_file.end);
|
||||
size_t img_size = img_file.tellg();
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
// get data size from image
|
||||
uint8_t buf[4];
|
||||
img_file.read((char *)&buf, 0x40, 4);
|
||||
img_file.seekg(0x40, img_file.beg);
|
||||
img_file.read((char *)&buf, 4);
|
||||
this->data_size = READ_DWORD_BE_U(buf);
|
||||
|
||||
if (this->data_size > img_size) {
|
||||
@@ -223,8 +235,9 @@ int DiskCopy42Img::calc_phys_params() {
|
||||
|
||||
uint8_t disk_format = 0xFFU;
|
||||
|
||||
img_file.read((char *)&disk_format, 0x50, 1);
|
||||
img_file.read((char *)&this->format_byte, 0x51, 1);
|
||||
img_file.seekg(0x50, img_file.beg);
|
||||
img_file.read((char *)&disk_format, 1);
|
||||
img_file.read((char *)&this->format_byte, 1);
|
||||
|
||||
img_file.close();
|
||||
|
||||
@@ -259,15 +272,17 @@ int DiskCopy42Img::calc_phys_params() {
|
||||
}
|
||||
|
||||
int DiskCopy42Img::get_raw_disk_data(char* buf) {
|
||||
ImgFile img_file;
|
||||
std::ifstream img_file;
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
img_file.read(buf, 0x54, this->data_size);
|
||||
img_file.seekg(0x54, img_file.beg);
|
||||
img_file.read(buf, this->data_size);
|
||||
img_file.close();
|
||||
|
||||
return 0;
|
||||
@@ -281,11 +296,12 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv = nullptr;
|
||||
|
||||
ImgFile img_file;
|
||||
std::ifstream img_file;
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "Could not open specified floppy image (%s)!", img_path.c_str());
|
||||
LOG_F(ERROR, "Could not open specified floppy image!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
@@ -32,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -24,15 +24,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SWIM3_H
|
||||
#define SWIM3_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class DmaBidirChannel;
|
||||
class InterruptCtrl;
|
||||
|
||||
/** SWIM3 registers offsets. */
|
||||
namespace Swim3 {
|
||||
|
||||
|
||||
+17
-56
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -53,8 +53,8 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
// connect internal SCSI controller
|
||||
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
|
||||
this->curio_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
|
||||
this->scsi->set_dma_channel(this->curio_dma.get());
|
||||
this->scsi_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
|
||||
this->scsi->set_dma_channel(this->scsi_dma.get());
|
||||
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
|
||||
if (drq_state & 1)
|
||||
via2_ifr |= VIA2_INT_SCSI_DRQ;
|
||||
@@ -65,8 +65,6 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
this->escc_xmit_b_dma = std::unique_ptr<AmicSerialXmitDma>(new AmicSerialXmitDma("EsccBXmit"));
|
||||
this->escc_xmit_a_dma = std::unique_ptr<AmicSerialXmitDma>(new AmicSerialXmitDma("EsccAXmit"));
|
||||
|
||||
// connect Ethernet HW
|
||||
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
|
||||
@@ -91,14 +89,6 @@ AMIC::AMIC() : MMIODevice()
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
}
|
||||
|
||||
AMIC::~AMIC()
|
||||
{
|
||||
if (this->pseudo_vbl_tid) {
|
||||
TimerManager::get_instance()->cancel_timer(this->pseudo_vbl_tid);
|
||||
this->pseudo_vbl_tid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int AMIC::device_postinit()
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
@@ -199,7 +189,7 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
case AMICReg::DMA_Base_Addr_3:
|
||||
return (this->dma_base >> (3 - (offset & 3)) * 8) & 0xFF;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
return this->curio_dma->read_stat();
|
||||
return this->scsi_dma->read_stat();
|
||||
case AMICReg::Floppy_Addr_Ptr_0:
|
||||
case AMICReg::Floppy_Addr_Ptr_1:
|
||||
case AMICReg::Floppy_Addr_Ptr_2:
|
||||
@@ -207,8 +197,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_B_Ctrl:
|
||||
return this->escc_xmit_b_dma->read_stat();
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
|
||||
}
|
||||
@@ -259,16 +247,18 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
|
||||
return;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->dma_out_start();
|
||||
} else {
|
||||
LOG_F(INFO, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
this->awacs->dma_out_pause();
|
||||
}
|
||||
}
|
||||
this->snd_out_ctrl = value;
|
||||
@@ -381,16 +371,13 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
if (value & 1) { // RST bit set?
|
||||
this->scsi_addr_ptr = this->scsi_dma_base;
|
||||
this->curio_dma->reset(this->scsi_addr_ptr);
|
||||
this->scsi_dma->reset(this->scsi_addr_ptr);
|
||||
}
|
||||
if (value & 2) { // RUN bit set?
|
||||
this->curio_dma->reinit(this->scsi_dma_base);
|
||||
if (value & (1 << 6))
|
||||
this->scsi->real_dma_xfer_out();
|
||||
else
|
||||
this->scsi->real_dma_xfer_in();
|
||||
this->scsi_dma->reinit(this->scsi_dma_base);
|
||||
this->scsi->real_dma_xfer((value >> 6) & 1);
|
||||
}
|
||||
this->curio_dma->write_ctrl(value);
|
||||
this->scsi_dma->write_ctrl(value);
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Rcv_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
|
||||
@@ -415,14 +402,12 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch A DMA Ctrl updated, val=%x", value);
|
||||
this->escc_xmit_a_dma->write_ctrl(value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch A DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch B DMA Ctrl updated, val=%x", value);
|
||||
this->escc_xmit_b_dma->write_ctrl(value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch B DMA Ctrl updated, val=%x", value);
|
||||
@@ -438,7 +423,7 @@ uint32_t AMIC::register_dev_int(IntSrc src_id) {
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return CPU_INT_VIA1;
|
||||
case IntSrc::SCSI_CURIO:
|
||||
case IntSrc::SCSI1:
|
||||
return VIA2_INT_SCSI_IRQ << 8;
|
||||
case IntSrc::SWIM3:
|
||||
return VIA2_INT_SWIM3 << 8;
|
||||
@@ -546,7 +531,7 @@ void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
}
|
||||
|
||||
// ============================ Sound DMA stuff ================================
|
||||
AmicSndOutDma::AmicSndOutDma() : DmaOutChannel("SndOut")
|
||||
AmicSndOutDma::AmicSndOutDma()
|
||||
{
|
||||
this->dma_out_ctrl = 0;
|
||||
this->enabled = false;
|
||||
@@ -586,8 +571,8 @@ void AmicSndOutDma::write_dma_out_ctrl(uint8_t value)
|
||||
this->dma_out_ctrl &= ~(value & PDM_DMA_INTS_MASK);
|
||||
this->update_irq();
|
||||
}
|
||||
// update sound output DMA interrupt enable bits
|
||||
this->dma_out_ctrl = (this->dma_out_ctrl & 0xF1U) | (value & 0x0EU);
|
||||
// enable sound output DMA interrupts
|
||||
this->dma_out_ctrl |= value & 0x0FU;
|
||||
}
|
||||
|
||||
DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
@@ -613,6 +598,7 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
// if it's false stop delivering sound data
|
||||
// this will effectively stop audio playback
|
||||
if (this->snd_buf_num && !this->enabled) {
|
||||
this->cur_buf_pos = 0;
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
@@ -729,33 +715,8 @@ DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
|
||||
// =========================== Serial DMA stuff ===============================
|
||||
void AmicSerialXmitDma::write_ctrl(const uint8_t value)
|
||||
{
|
||||
if (value & 1) { // RST bit set?
|
||||
this->stat &= 0x7C; // clear IF, RUN and RST bits
|
||||
}
|
||||
|
||||
// copy PAUSE to FROZEN
|
||||
this->stat = (this->stat & 0xDF) | ((value & 0x10) << 1);
|
||||
|
||||
// copy over RELOAD, PAUSE, IE, CONT and RUN bits
|
||||
this->stat = (this->stat & 0xA1) | (value & 0x5E);
|
||||
|
||||
// clear interrupt flag if requested
|
||||
if (value & 0x80) {
|
||||
this->stat &= 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
return DmaPullResult::NoMoreData;
|
||||
};
|
||||
|
||||
static vector<string> Amic_Subdevices = {
|
||||
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
"Scsi0", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription Amic_Descriptor = {
|
||||
|
||||
+14
-36
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,9 +24,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef AMIC_H
|
||||
#define AMIC_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
@@ -34,12 +38,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class EsccController;
|
||||
class MaceController;
|
||||
class Sc53C94;
|
||||
class ViaCuda;
|
||||
namespace Swim3 { class Swim3Ctrl; }
|
||||
|
||||
/** Interrupt related constants. */
|
||||
|
||||
/** CPU interrupt register bits. */
|
||||
@@ -127,7 +125,7 @@ private:
|
||||
/** AMIC-specific floppy DMA implementation. */
|
||||
class AmicFloppyDma : public DmaBidirChannel {
|
||||
public:
|
||||
AmicFloppyDma() : DmaBidirChannel("floppy") {}
|
||||
AmicFloppyDma() = default;
|
||||
~AmicFloppyDma() = default;
|
||||
|
||||
void reinit(const uint32_t addr_ptr, const uint16_t byte_cnt);
|
||||
@@ -145,28 +143,10 @@ private:
|
||||
uint8_t stat;
|
||||
};
|
||||
|
||||
/** AMIC specific Serial Transmit DMA channel. */
|
||||
class AmicSerialXmitDma : public DmaOutChannel {
|
||||
public:
|
||||
AmicSerialXmitDma(std::string name) : DmaOutChannel(name) {}
|
||||
~AmicSerialXmitDma() = default;
|
||||
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
uint32_t addr_ptr;
|
||||
uint16_t byte_count;
|
||||
uint8_t stat;
|
||||
};
|
||||
|
||||
/** AMIC-specific SCSI DMA implementation. */
|
||||
class AmicScsiDma : public DmaBidirChannel {
|
||||
public:
|
||||
AmicScsiDma() : DmaBidirChannel("Scsi") {}
|
||||
AmicScsiDma() = default;
|
||||
~AmicScsiDma() = default;
|
||||
|
||||
void reinit(const uint32_t addr_ptr);
|
||||
@@ -275,7 +255,7 @@ enum AMICReg : uint32_t {
|
||||
class AMIC : public MMIODevice, public InterruptCtrl {
|
||||
public:
|
||||
AMIC();
|
||||
~AMIC();
|
||||
~AMIC() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AMIC>(new AMIC());
|
||||
@@ -336,7 +316,7 @@ private:
|
||||
uint8_t via2_slot_ifr = 0x7F; // reverse logic
|
||||
uint8_t via2_slot_irq = 0; // normal logic
|
||||
|
||||
uint32_t pseudo_vbl_tid = 0; // ID for the pseudo-VBL timer
|
||||
uint32_t pseudo_vbl_tid; // ID for the pseudo-VBL timer
|
||||
|
||||
// AMIC subdevice instances
|
||||
Sc53C94* scsi;
|
||||
@@ -345,12 +325,10 @@ private:
|
||||
ViaCuda* viacuda;
|
||||
Swim3::Swim3Ctrl* swim3;
|
||||
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
std::unique_ptr<AmicFloppyDma> floppy_dma;
|
||||
std::unique_ptr<AmicScsiDma> curio_dma;
|
||||
std::unique_ptr<AmicSerialXmitDma> escc_xmit_b_dma;
|
||||
std::unique_ptr<AmicSerialXmitDma> escc_xmit_a_dma;
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
std::unique_ptr<AmicFloppyDma> floppy_dma;
|
||||
std::unique_ptr<AmicScsiDma> scsi_dma;
|
||||
|
||||
// on-board video
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
|
||||
Loaded 100 of 174 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user