Compare commits

..
3 Commits
Author SHA1 Message Date
dingusdev 5bc1260dbb Start MTSPR/MFSPR refactor 2026-02-11 08:02:40 -07:00
dingusdev e46414721d Name DSISR bits 2026-01-22 19:07:43 -07:00
dingusdev 79784cd36c Initial improvements 2026-01-21 21:17:52 -07:00
224 changed files with 6599 additions and 14025 deletions

No files matched your search

+220 -248
View File
@@ -4,290 +4,262 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build-linux:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/linux
key: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: linux-ccache-${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Install dependencies
- uses: actions/checkout@v3
- name: install_dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq libsdl2-dev ninja-build ccache
sudo apt-get install libsdl2-dev
- name: init_submodules
run: git submodule update --init --recursive
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/linux
CCACHE_BASEDIR: ${{ github.workspace }}
run: cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-LINUX
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-macos:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- runner: macos-latest
arch: arm64
brew_prefix: /opt/homebrew
- runner: macos-15-intel
arch: x86_64
brew_prefix: /usr/local
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
key: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: macos-${{ matrix.runner }}-${{ matrix.arch }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew install sdl2 ccache ninja
- name: Configure CMake
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/${{ matrix.arch }}
CCACHE_BASEDIR: ${{ github.workspace }}
run: |
export PATH="${{ matrix.brew_prefix }}/opt/ccache/libexec:$PATH"
cmake -S . -B ${{github.workspace}}/build -GNinja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
- name: ccache stats
run: ccache --show-stats || true
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-macOS-${{ matrix.arch }}
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
build-windows-msys2:
run: ctest -C ${{env.BUILD_TYPE}}
build-windows:
runs-on: windows-latest
timeout-minutes: 45
strategy:
matrix:
cache-name: [msys64-cache]
env:
MSYSTEM: MINGW64
FF_SCRIPT_SECTIONS: '0'
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
TEST_ARGS: '--no-suite qtest'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: recursive
- name: Cache ccache
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/msys
key: windows-msys-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: windows-msys-ccache-${{ env.BUILD_TYPE }}-
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
cmake
ninja
git
mingw-w64-x86_64-cmake
mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-ninja
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-ccache
uses: actions/checkout@v2
- name: Set up MSYS2
run: |
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
If ( !(Test-Path -Path msys64\var\cache ) ) {
mkdir msys64\var\cache
}
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
Write-Output "Cached installer sig" ;
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
Write-Output "Mis-matched installer sig, new installer download required" ;
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
} else {
Write-Output "Matched installer sig, cached installer still valid"
}
} else {
Write-Output "No cached installer sig, new installer download required" ;
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
Remove-Item -Path msys64\var\cache\msys2.exe
}
}
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
Write-Output "Fetching latest installer" ;
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
} else {
Write-Output "Using cached installer"
}
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
msys64\var\cache\msys2.exe -y
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
taskkill /F /FI "MODULES eq msys-2.0.dll"
- name: Install dependencies
run: |
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
bison \
diffutils \
flex \
tar \
doxygen \
cmake \
wget \
git \
grep \
make \
rsync \
ninja \
glib2-devel \
patch \
sed \
mingw-w64-x86_64-cmake \
mingw-w64-x86_64-binutils \
mingw-w64-x86_64-doxygen \
mingw-w64-x86_64-capstone \
mingw-w64-x86_64-ccache \
mingw-w64-x86_64-curl \
mingw-w64-x86_64-cyrus-sasl \
mingw-w64-x86_64-dtc \
mingw-w64-x86_64-gcc \
mingw-w64-x86_64-glib2 \
mingw-w64-x86_64-gnutls \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-libgcrypt \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-libnfs \
mingw-w64-x86_64-libpng \
mingw-w64-x86_64-libssh \
mingw-w64-x86_64-libtasn1 \
mingw-w64-x86_64-libusb \
mingw-w64-x86_64-lzo2 \
mingw-w64-x86_64-libslirp \
mingw-w64-x86_64-nettle \
mingw-w64-x86_64-clang \
mingw-w64-x86_64-ninja \
mingw-w64-x86_64-pixman \
mingw-w64-x86_64-pkgconf \
mingw-w64-x86_64-python \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-SDL2_image \
mingw-w64-x86_64-snappy \
mingw-w64-x86_64-spice \
mingw-w64-x86_64-usbredir \
mingw-w64-x86_64-zstd \
mingw-w64-x86_64-make'
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: msys2 {0}
run: |
echo "Running build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
export CHERE_INVOKING=yes
export MSYS=winsymlinks:native
export CCACHE_BASEDIR="${GITHUB_WORKSPACE}"
export CCACHE_DIR="${GITHUB_WORKSPACE}/.ccache/msys"
export CCACHE_DEPEND=1
ccache --zero-stats || true
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
ccache --show-stats || true
echo "Finished build at $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Test
shell: msys2 {0}
run: |
Write-Output "Running build at $(Get-Date -Format u)"
$env:CHERE_INVOKING = 'yes' # Preserve the current working directory
$env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
$env:CCACHE_BASEDIR = "$env:CI_PROJECT_DIR"
$env:CCACHE_DIR = "$env:CCACHE_BASEDIR/ccache"
$env:CCACHE_MAXSIZE = "500M"
$env:CCACHE_DEPEND = 1 # cache misses are too expensive with preprocessor mode
$env:CC = "ccache gcc"
mkdir build
cd build
ctest --output-on-failure --parallel
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: DingusPPC-MSYS
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --zero-stats"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True .. && ninja"
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --show-stats"
Write-Output "Finished build at $(Get-Date -Format u)"
build-windows-vsbuild:
vsbuild-CLANG:
runs-on: windows-latest
timeout-minutes: 45
env:
VCPKG_FEATURE_FLAGS: binarycaching
strategy:
fail-fast: false
matrix:
include:
- name: clang
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: CLANG
- name: msvc
generator: Ninja
cmake_args: ""
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSVC
- name: msbuild
generator: Ninja
cmake_args: -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl
ccache_args: -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
upload_suffix: MSBUILD
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
# Configures MSVC/Clang environment natively for all subsequent steps
- name: Setup MSVC Developer Command Prompt
uses: TheMrMilchmann/setup-msvc-dev@v4
with:
arch: x64
- uses: actions/checkout@v3
- name: Setup msbuild
uses: microsoft/setup-msbuild@v3
- name: Install vcpkg packages
shell: cmd
run: '"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows'
- name: Install Ninja
if: matrix.generator == 'Ninja'
run: choco install ninja -y
- name: Cache ccache
if: matrix.generator == 'Ninja'
uses: actions/cache@v5
with:
path: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
key: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: vsbuild-${{ matrix.name }}-ccache-${{ env.BUILD_TYPE }}-
- name: Install ccache
if: matrix.generator == 'Ninja'
run: choco install ccache -y
- name: Configure & Build
shell: cmd
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache/vsbuild-${{ matrix.name }}
CCACHE_BASEDIR: ${{ github.workspace }}
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
mkdir build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cd build
cmake -S .. -B . -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DDPPC_68K_DEBUGGER=ON -DDPPC_BUILD_PPC_TESTS=ON ${{ matrix.ccache_args }} -DCMAKE_TOOLCHAIN_FILE=%VCPKG_INSTALLATION_ROOT%\scripts\buildsystems\vcpkg.cmake
cmake --build . --config ${{ env.BUILD_TYPE }} --parallel
cd ..
- name: ccache stats
if: matrix.generator == 'Ninja'
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: cmd
run: |
ccache --show-stats
if %errorlevel% neq 0 echo ccache stats unavailable
- name: Test
working-directory: ${{github.workspace}}/build
shell: cmd
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-${{ github.job }}-${{ matrix.name }}
path: |
${{ github.workspace }}/build/Testing/Temporary/LastTest.log
${{ github.workspace }}/build/CMakeFiles/CMakeOutput.log
${{ github.workspace }}/build/CMakeFiles/CMakeError.log
if-no-files-found: ignore
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v4
with:
name: DingusPPC-${{ matrix.upload_suffix }}
name: DingusPPC-CLANG
path: ${{github.workspace}}/build/bin
vsbuild-MSVC:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
nmake
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-MSVC
path: ${{github.workspace}}/build/bin
vsbuild-MSVC-MSBUILD:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup msbuild
if: inputs.configuration != 'CMake'
uses: microsoft/setup-msbuild@v1
- name: Setup VCPKG
run: |
vcpkg integrate install
vcpkg install pthread:x64-windows
vcpkg install pthreads:x64-windows
vcpkg install pthread-stubs:x64-windows
vcpkg install pthreadpool:x64-windows
vcpkg install
- name: init_submodules
run: git submodule update --init --recursive
- name: Build
shell: cmd
run: |
mkdir build
cd build
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
msbuild dingusppc.sln
- name: Upload artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: DingusPPC-MSBUILD
path: ${{github.workspace}}/build/bin
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
-1
View File
@@ -41,7 +41,6 @@ ehthumbs.db
# IDE ignores
build
build*/
build-*
*.dir
*.user
+24 -95
View File
@@ -84,19 +84,6 @@ if (DPPC_68K_DEBUGGER)
add_subdirectory(thirdparty/capstone EXCLUDE_FROM_ALL)
endif()
option (DPPC_SUPPORT_PPC_LE "Enable PPC little endian mode" OFF)
option (DPPC_SUPPORT_MEM_LE "Enable memory controller little endian mode" OFF)
if (DPPC_SUPPORT_PPC_LE)
ADD_DEFINITIONS(-DSUPPORTS_PPC_LITTLE_ENDIAN_MODE=1)
else()
ADD_DEFINITIONS(-DSUPPORTS_PPC_LITTLE_ENDIAN_MODE=0)
endif()
if (DPPC_SUPPORT_MEM_LE)
ADD_DEFINITIONS(-DSUPPORTS_MEMORY_CTRL_ENDIAN_MODE=1)
else()
ADD_DEFINITIONS(-DSUPPORTS_MEMORY_CTRL_ENDIAN_MODE=0)
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/core")
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
@@ -151,16 +138,6 @@ endif()
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
if (APPLE)
add_executable(dingusppc MACOSX_BUNDLE ${SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
else()
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
@@ -168,55 +145,9 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
endif()
if (APPLE)
# Identify if we are targeting iOS or macOS
if (IOS)
set(BUNDLE_ID "com.dingusdev.dingusppc-ios")
message(STATUS "Configuring for iOS Bundle")
else()
set(BUNDLE_ID "com.dingusdev.dingusppc")
message(STATUS "Configuring for macOS Bundle")
endif()
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "${BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "DingusPPC"
MACOSX_BUNDLE_BUNDLE_VERSION "alpha 1.0.4c"
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4c"
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
# Placeholder for the icon file:
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
)
if (NOT IOS)
set_target_properties(dingusppc PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/cmake/DingusPPCInfo.plist.in"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${BUNDLE_ID}"
)
endif()
find_library(COCOA_LIBRARY Cocoa)
find_library(IOKIT_LIBRARY IOKit)
find_library(COREAUDIO_LIBRARY CoreAudio)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
target_link_libraries(dingusppc PRIVATE
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREAUDIO_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
)
if (IOS)
target_link_libraries(dingusppc PRIVATE "-framework Foundation" "-framework UIKit")
endif()
endif()
if (WIN32)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(dingusppc PRIVATE SDL_MAIN_HANDLED)
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
elseif (EMSCRIPTEN)
target_link_libraries(dingusppc PRIVATE
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
@@ -228,7 +159,7 @@ elseif (EMSCRIPTEN)
"-s EXPORT_NAME=emulator"
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
else()
target_link_libraries(dingusppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -252,10 +183,9 @@ if (DPPC_BUILD_PPC_TESTS)
$<TARGET_OBJECTS:loguru>)
if (WIN32)
target_link_libraries(testppc PRIVATE SDL2::SDL2 cubeb)
target_compile_definitions(testppc PRIVATE SDL_MAIN_HANDLED)
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
else()
target_link_libraries(testppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
@@ -265,26 +195,25 @@ if (DPPC_BUILD_PPC_TESTS)
endif()
if (DPPC_BUILD_BENCHMARKS)
file(GLOB BENCH_CPU_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h")
foreach(BENCHMARK bench1 bench2)
add_executable(${BENCHMARK} "benchmark/${BENCHMARK}.cpp" ${BENCH_CPU_SOURCES}
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_compile_definitions(${BENCHMARK} PRIVATE PPC_BENCHMARKS)
target_link_libraries(${BENCHMARK} PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (WIN32)
target_compile_definitions(${BENCHMARK} PRIVATE SDL_MAIN_HANDLED)
endif()
if (DPPC_68K_DEBUGGER)
target_link_libraries(${BENCHMARK} PRIVATE capstone)
endif()
endforeach()
add_compile_options("-DPPC_BENCHMARKS")
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
)
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
# $<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT})
if (DPPC_68K_DEBUGGER)
target_link_libraries(bench1 PRIVATE capstone)
endif()
endif()
if (DPPC_BUILD_PPC_TESTS)
@@ -294,7 +223,7 @@ if (DPPC_BUILD_PPC_TESTS)
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
"$<TARGET_FILE_DIR:$<TARGET_PROPERTY:NAME>>")
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif()
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
-6
View File
@@ -5,12 +5,6 @@ General
* Commits to the repo should be done by portions; that is, by individual functionalities of the program.
* Don't use any disrespectful language.
AI Usage
=======
* Do not use artificial intelligence to make contributions. This is due to authorship issues and licensing issues regarding AI usage.
* Do not use artificial intelligence to write up issues or pull requests.
Code
=======
+15 -24
View File
@@ -4,14 +4,10 @@
## Developers
- divingkatae
- joevt
- kkaisershot
- maximumspatium
- joevt
- mihaip
## ATI Rage Support (WIP)
- Cacodemon345
- kkaisershot
## NT4/PPC fork
@@ -19,25 +15,21 @@
## DevOps
- alicela1n
- calmsacibis995
- claunia
- dressupgeekout
- dyharlan
- erichelgeson
- jarz
- kth5
- leap0x7b
- lefp
- mathstuf
- mrpapersonic
- probonopd
- Randrianasulu
- roytam1
- sdkmap
- seanm
- Waqar144
- webspacecreations
- leap0x7b
- sdkmap
- dressupgeekout
- kth5
- dyharlan
- roytam1
- mrpapersonic
- Randrianasulu
- lefp
- mathstuf
- seanm
- erichelgeson
- alicela1n
## Testing
@@ -59,7 +51,6 @@
- Blitter.net
- Emaculation
- GitHub
- pagetable.com
- PenguinPPC
- VirtuallyFun
- The makers of Loguru, SDL2, Capstone, and CLI11
+13 -36
View File
@@ -1,24 +1,18 @@
# DingusPPC
Written by The DingusPPC Development Team
(who are Divingkatae, maximumspatium, joevt, mihaip, kkaisershot, Cacodemon345, Wack0, et. al. Check CREDITS.md for more info)
Written by divingkatae and maximumspatium
Be warned the program is highly unfinished and could use a lot of testing. Any feedback is welcome.
## 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 PowerPC 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 NuBus and 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 NuBus and Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
## Implemented Features
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World
PowerPC Macs, and the Pippin.
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World PowerPC Macs, and the Pippin.
This emulator has a debugging environment, complete with a disassembler.
@@ -29,10 +23,10 @@ This program currently uses the command prompt to work.
There are a few command line arguments one can enter when starting the program.
```
-r, --run
-r, --realtime
```
Run the emulator. Currently only goes to an interpreter.
Run the emulator in runtime.
```
-d, --debugger
@@ -71,7 +65,6 @@ git clone https://github.com/dingusdev/dingusppc
If this is from a mirror, replace the argument with the source you want to use instead.
You will also have to recursive clone or run
```
git submodule update --init --recursive
```
@@ -84,43 +77,27 @@ For SDL2, Linux users may also have to run:
sudo apt install libsdl2-dev
```
macOS users can use Homebrew or MacPorts to install SDL2.
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
For Raspbian, you may also need the following command:
```
sudo apt install doxygen graphviz
```
To build the project in a Unix-like environment, create a build folder, change the directory to the build folder,
and use `cmake` to create the `Makefile` files in that build folder.
Use `make` to do the building. You don't need to execute `cmake` again unless you add/remove/change options or
source files.
CLI11 and loguru 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:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
make dingusppc
```
You may specify another build type using the variable CMAKE_BUILD_TYPE.
You may specify another build type using the variable `CMAKE_BUILD_TYPE`.
Each build type should have its own build folder.
For Raspbian, you may also need the following command:
```
mkdir build-debug
cd build-debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
sudo apt install doxygen graphviz
```
## Testing
DingusPPC includes a test suite for verifying the correctness of its PowerPC CPU
emulation. To build the tests, use the following terminal commands:
```
mkdir build
cd build
+5 -52
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -29,7 +29,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_off(po_benchmark_exception);
power_on = false;
power_off_reason = po_benchmark_exception;
}
#endif
@@ -114,54 +115,6 @@ int main(int argc, char** argv) {
power_on = true;
ppc_exec_until(0xC4);
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
#ifdef _MSC_VER
#pragma message("PPC endian mode enabled")
#else
#warning PPC endian mode enabled
#endif
LOG_F(INFO, "PPC endian mode enabled");
#else
#ifdef _MSC_VER
#pragma message("PPC endian mode disabled")
#else
#warning PPC endian mode disabled
#endif
LOG_F(INFO, "PPC endian mode disabled");
#endif
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
#ifdef _MSC_VER
#pragma message("Memory endian mode enabled")
#else
#warning Memory endian mode enabled
#endif
LOG_F(INFO, "Memory endian mode enabled");
#else
#ifdef _MSC_VER
#pragma message("Memory endian mode disabled")
#else
#warning Memory endian mode disabled
#endif
LOG_F(INFO, "Memory endian mode disabled");
#endif
#ifdef LOG_INSTRUCTIONS
#ifdef _MSC_VER
#pragma message("Log instructions enabled")
#else
#warning Log instructions enabled
#endif
LOG_F(INFO, "Log instructions enabled");
#else
#ifdef _MSC_VER
#pragma message("Log instructions disabled")
#else
#warning Log instructions disabled
#endif
LOG_F(INFO, "Log instructions disabled");
#endif
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
uint32_t checksum = ppc_state.gpr[3];
-119
View File
@@ -1,119 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Replay floating-point instructions and input registers captured while BeOS
// PR1 GLTeapot renders. This measures the real opcode dispatcher and handlers,
// including FPSCR maintenance, without guest boot, display, or timer overhead.
#include <cpu/ppc/ppcemu.h>
#include <thirdparty/loguru/loguru.hpp>
#include <algorithm>
#include <cfenv>
#include <chrono>
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <vector>
#include "bench2_data.h"
#if defined(PPC_BENCHMARKS)
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
power_off(po_benchmark_exception);
}
#endif
static void replay_sample(const FpuSample& sample) {
if ((ppc_state.fpscr ^ sample.fpscr) & FPSCR::RN_MASK)
set_host_rounding_mode(sample.fpscr & FPSCR::RN_MASK);
ppc_state.fpscr = sample.fpscr;
ppc_state.cr = sample.cr;
ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r = sample.d;
ppc_state.fpr[(sample.opcode >> 16) & 31].int64_r = sample.a;
ppc_state.fpr[(sample.opcode >> 11) & 31].int64_r = sample.b;
ppc_state.fpr[(sample.opcode >> 6) & 31].int64_r = sample.c;
ppc_main_opcode(ppc_opcode_grabber, sample.opcode);
}
static uint64_t check_replay() {
uint64_t hash = 1469598103934665603ULL;
auto mix = [&hash](uint64_t value) { hash = (hash ^ value) * 1099511628211ULL; };
std::feclearexcept(FE_ALL_EXCEPT);
for (const auto& sample : fpu_samples) {
replay_sample(sample);
mix(ppc_state.fpr[(sample.opcode >> 21) & 31].int64_r);
mix(ppc_state.fpscr);
mix(ppc_state.cr);
}
return hash;
}
int main(int argc, char** argv) {
if (argc > 2 || (argc == 2 && std::strcmp(argv[1], "--check"))) {
fprintf(stderr, "Usage: %s [--check]\n", argv[0]);
return 2;
}
loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
is_601 = false;
initialize_ppc_opcode_table();
ppc_msr_did_change(ppc_state.msr, MSR::ME | MSR::IP | MSR::FP, false);
set_host_rounding_mode(0);
power_on = true;
const uint64_t expected = check_replay();
constexpr size_t sample_count = sizeof(fpu_samples) / sizeof(fpu_samples[0]);
printf("GLTeapot FPU replay: %zu samples, checksum %016" PRIx64 "\n", sample_count, expected);
if (!power_on)
return 1;
if (argc == 2 && !std::strcmp(argv[1], "--check"))
return 0;
constexpr unsigned passes = 10000;
constexpr unsigned trials = 9;
// Warm the dispatcher, handlers and captured input data.
for (unsigned pass = 0; pass < 100; pass++)
for (const auto& sample : fpu_samples)
replay_sample(sample);
std::vector<double> times;
for (unsigned trial = 0; trial < trials; trial++) {
std::feclearexcept(FE_ALL_EXCEPT);
auto start = std::chrono::steady_clock::now();
for (unsigned pass = 0; pass < passes; pass++)
for (const auto& sample : fpu_samples)
replay_sample(sample);
auto end = std::chrono::steady_clock::now();
if (!power_on || check_replay() != expected) {
fprintf(stderr, "FPU replay changed its result during timing\n");
return 1;
}
double ns = std::chrono::duration<double, std::nano>(end - start).count() /
(uint64_t(passes) * sample_count);
times.push_back(ns);
printf("Trial %u: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
trial + 1, ns, 1000.0 / ns);
}
std::sort(times.begin(), times.end());
double median = times[times.size() / 2];
printf("Median: %.3f ns/FPU instruction, %.3f million FPU instructions/s\n",
median, 1000.0 / median);
return 0;
}
File diff suppressed because it is too large. Load diff
-70
View File
@@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>CD-ROM image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.iso-image</string>
<string>com.roxio.disk-image-toast</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>Toast disk image</string>
<key>UTTypeIdentifier</key>
<string>com.roxio.disk-image-toast</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>toast</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -52,7 +52,7 @@ public:
}
// Calls all connected slots.
void emit(Args... args) const {
void emit(Args... args) {
if (!_is_enabled) {
return;
}
@@ -77,7 +77,7 @@ public:
_is_enabled = true;
}
bool is_enabled() const {
bool is_enabled() {
return _is_enabled;
}
+5 -30
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/coresignal.h>
#include <cinttypes>
#include <string>
class WindowEvent {
public:
@@ -63,8 +62,8 @@ public:
~MouseEvent() = default;
uint32_t flags;
int32_t xrel;
int32_t yrel;
uint32_t xrel;
uint32_t yrel;
uint32_t xabs;
uint32_t yabs;
uint8_t buttons_state;
@@ -120,20 +119,6 @@ public:
uint8_t button;
};
enum class CdromInsertionResult {
SUCCESS,
NO_DRIVE,
MEDIA_PRESENT,
IMAGE_OPEN_FAILED,
};
class CdromImageEvent {
public:
std::string image_path;
CdromInsertionResult result = CdromInsertionResult::NO_DRIVE;
bool handled = false;
};
class EventManager {
public:
static EventManager* get_instance() {
@@ -146,9 +131,6 @@ public:
void poll_events();
void set_keyboard_locale(uint32_t keyboard_id);
void post_keyboard_state_events();
void post_cdrom_event(CdromImageEvent& event) {
_cdrom_signal.emit(event);
}
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
@@ -170,11 +152,6 @@ public:
_gamepad_signal.connect_method(inst, func);
}
template <typename T>
void add_cdrom_handler(T* inst, void (T::*func)(CdromImageEvent&)) {
_cdrom_signal.connect_method(inst, func);
}
template <typename T>
void add_post_handler(T *inst, void (T::*func)()) {
_post_signal.connect_method(inst, func);
@@ -185,7 +162,6 @@ public:
_mouse_signal.disconnect_all();
_keyboard_signal.disconnect_all();
_gamepad_signal.disconnect_all();
_cdrom_signal.disconnect_all();
_post_signal.disconnect_all();
}
@@ -203,7 +179,6 @@ private:
CoreSignal<const MouseEvent&> _mouse_signal;
CoreSignal<const KeyboardEvent&> _keyboard_signal;
CoreSignal<const GamepadEvent&> _gamepad_signal;
CoreSignal<CdromImageEvent&> _cdrom_signal;
CoreSignal<> _post_signal;
uint64_t events_captured = 0;
+41 -131
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -32,20 +32,6 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_l
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
bool g_swap_command_option = false;
static AdbKey swap_command_option(AdbKey key)
{
if (!g_swap_command_option)
return key;
switch (key) {
case AdbKey_Option: return AdbKey_Command;
case AdbKey_RightOption: return AdbKey_Command;
case AdbKey_Command: return AdbKey_Option;
default: return key;
}
}
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
this->kbd_locale = keyboard_id;
}
@@ -58,7 +44,8 @@ void EventManager::poll_events() {
switch (event.type) {
case SDL_QUIT:
power_off(po_quit);
power_on = false;
power_off_reason = po_quit;
break;
case SDL_WINDOWEVENT: {
@@ -138,56 +125,21 @@ void EventManager::poll_events() {
}
return;
}
// Control-Alt-Shift-+: speed up icnt_factor
if (event.key.keysym.sym == SDLK_EQUALS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
int icnt_counter_val = increment_icnt_factor();
LOG_F(INFO, "Incremented icnt_factor: %d", icnt_counter_val);
}
return;
}
// Control-Alt-Shift--: slow down icnt_factor
if (event.key.keysym.sym == SDLK_MINUS &&
(event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT | KMOD_LSHIFT)
) {
if (event.type == SDL_KEYUP) {
int icnt_counter_val = decrement_icnt_factor();
LOG_F(INFO, "Decremented icnt_factor: %d", icnt_counter_val);
}
return;
}
// Control-Alt-R: g_realtime toggle
if (event.key.keysym.sym == SDLK_r && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LALT)) {
if (event.type == SDL_KEYUP) {
bool g_realtime_status = toggle_g_realtime();
LOG_F(INFO, "g_realtime: %s", g_realtime_status ? "enabled" : "disabled");
}
return;
}
// Control-L: log toggle
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
loguru::Verbosity new_verbosity = loguru::g_stderr_verbosity;
if (new_verbosity < loguru::Verbosity_INFO)
new_verbosity = loguru::Verbosity_INFO;
else if (new_verbosity < loguru::Verbosity_MAX)
new_verbosity = loguru::Verbosity_MAX;
else
new_verbosity = loguru::Verbosity_OFF;
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
LOG_F(INFO, "g_stderr_verbosity: %d", new_verbosity);
loguru::g_stderr_verbosity = new_verbosity;
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
loguru::Verbosity_INFO
:
loguru::Verbosity_MAX;
}
return;
}
// Control-D: debugger
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
power_off(po_enter_debugger);
power_on = false;
power_off_reason = po_enter_debugger;
}
return;
}
@@ -323,35 +275,6 @@ void EventManager::poll_events() {
}
break;
case SDL_DROPFILE: {
const char* path = event.drop.file;
// TODO: Distinguish CD-ROM and floppy images once dynamic
// floppy insertion is supported.
CdromImageEvent cdrom_event{};
cdrom_event.image_path = path;
this->post_cdrom_event(cdrom_event);
switch (cdrom_event.result) {
case CdromInsertionResult::SUCCESS:
LOG_F(INFO, "Inserted CD-ROM image: %s", path);
break;
case CdromInsertionResult::NO_DRIVE:
LOG_F(ERROR, "Cannot insert CD-ROM image; no CD-ROM drive is available: %s",
path);
break;
case CdromInsertionResult::MEDIA_PRESENT:
LOG_F(ERROR, "Cannot insert CD-ROM image; eject the current media first: %s",
path);
break;
case CdromInsertionResult::IMAGE_OPEN_FAILED:
LOG_F(ERROR, "Cannot insert CD-ROM image: %s", path);
break;
}
SDL_free(event.drop.file);
}
break;
default:
unhandled_events++;
}
@@ -362,7 +285,6 @@ void EventManager::poll_events() {
}
void EventManager::post_keyboard_state_events() {
int count;
int numkeys;
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
int modstate = SDL_GetModState();
@@ -378,54 +300,46 @@ void EventManager::post_keyboard_state_events() {
} Modifier_t;
static Modifier_t modifiers[] = {
{ SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift },
{ SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift },
{ SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control },
{ SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl },
{ SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option },
{ SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption },
{ SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command },
{ SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command },
// { SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear },
{ SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock },
// { SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? },
// { SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 },
{ SDL_SCANCODE_UNKNOWN },
SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift ,
SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift ,
SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control ,
SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl,
SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option ,
SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption ,
SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command ,
SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command ,
// SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear ,
SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock ,
// SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? ,
// SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 ,
SDL_SCANCODE_UNKNOWN
};
LOG_F(INFO, "Current keyboard state:");
LOG_F(INFO, " Modifiers:");
count = 0;
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
if (!(modstate & mod->keymod))
continue;
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(mod->scancode));
count++;
ke.key = swap_command_option(mod->adbkey);
LOG_F(INFO, " mod:%s", SDL_GetScancodeName(mod->scancode));
ke.key = mod->adbkey;
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
}
if (!count)
LOG_F(INFO, " (none)");
LOG_F(INFO, " Keys and Modifiers:");
count = 0;
for (int i = 0; i < numkeys; i++) {
if (!states[i])
continue;
count++;
scancode = (SDL_Scancode)i;
Modifier_t *mod = modifiers;
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
if (mod->scancode == scancode) {
LOG_F(INFO, " Modifier: %s", SDL_GetScancodeName(scancode));
LOG_F(INFO, " ignore:%s", SDL_GetScancodeName(scancode));
continue;
}
LOG_F(INFO, " Key: %s", SDL_GetScancodeName(scancode));
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
keyevent.keysym.scancode = scancode;
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
keyevent.keysym.mod = modstate;
@@ -436,11 +350,9 @@ void EventManager::post_keyboard_state_events() {
ke.flags = KEYBOARD_EVENT_DOWN;
this->_keyboard_signal.emit(ke);
} else {
LOG_F(WARNING, " Unknown key %x pressed", keyevent.keysym.sym);
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
}
}
if (!count)
LOG_F(INFO, " (none)");
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
@@ -527,10 +439,10 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_RCTRL: return AdbKey_RightControl;
case SDLK_LSHIFT: return AdbKey_Shift;
case SDLK_RSHIFT: return AdbKey_RightShift;
case SDLK_LALT: return swap_command_option(AdbKey_Option);
case SDLK_RALT: return swap_command_option(AdbKey_RightOption);
case SDLK_LGUI: return swap_command_option(AdbKey_Command);
case SDLK_RGUI: return swap_command_option(AdbKey_Command);
case SDLK_LALT: return AdbKey_Option;
case SDLK_RALT: return AdbKey_RightOption;
case SDLK_LGUI: return AdbKey_Command;
case SDLK_RGUI: return AdbKey_Command;
case SDLK_MENU: return AdbKey_Grave;
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
@@ -574,14 +486,12 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDLK_SCROLLLOCK: return AdbKey_F14;
case SDLK_PAUSE: return AdbKey_F15;
// International keyboard support
//International keyboard support
// Japanese keyboard
//Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
else
return -1;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
@@ -591,18 +501,18 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL2):
return AdbKey_JIS_Kana;
// German keyboard
//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
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?
//0XB2 is superscript 2. Which Mac key should this one map to?
case 0XF9: return AdbKey_Quote; // U-grave
// Italian keyboard
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+64 -56
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -30,49 +30,78 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
TimerManager* TimerManager::timer_manager;
void TimerManager::add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb)
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
{
if (ti.active)
LOG_F(ERROR, "Timer %p is already active; cancel it before rescheduling", (void*)&ti);
TimerInfo* ti = new TimerInfo;
ti.timeout_ns = timeout_ns;
ti.interval_ns = interval;
ti.active = true;
ti.cb = cb;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + timeout;
ti->interval_ns = 0;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(&ti);
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
void TimerManager::add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb)
{
TimerManager::add_absolute_timer(ti, this->get_time_now() + timeout, 0, cb);
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->interval_ns = 0;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
void TimerManager::add_immediate_timer(TimerInfo &ti, timer_cb cb)
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
{
TimerManager::add_absolute_timer(ti, 0, 0, cb);
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + delay;
ti->interval_ns = interval;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb)
{
TimerManager::add_absolute_timer(ti, this->get_time_now() + delay, interval, cb);
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb) {
return this->add_cyclic_timer(interval, interval, cb);
}
void TimerManager::add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb)
void TimerManager::cancel_timer(uint32_t id)
{
this->add_cyclic_timer(ti, interval, interval, cb);
}
void TimerManager::cancel_timer(TimerInfo &ti)
{
this->timer_queue.remove_by_id(&ti);
ti.active = false;
this->timer_queue.remove_by_id(id);
if (!this->cb_active) {
this->notify_timer_changes();
}
@@ -80,7 +109,7 @@ void TimerManager::cancel_timer(TimerInfo &ti)
uint64_t TimerManager::process_timers()
{
TimerInfo *cur_timer;
std::shared_ptr<TimerInfo> cur_timer;
uint64_t time_now = get_time_now();
{ // mtx scope
@@ -93,33 +122,23 @@ uint64_t TimerManager::process_timers()
cur_timer = this->timer_queue.top();
} // ] mtx scope
while (cur_timer->timeout_ns <= time_now) {
this->timer_queue.remove_by_id(cur_timer);
uint64_t timeout_ns = cur_timer->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());
uint64_t timeout_ns_new = timeout_ns + cur_timer->interval_ns;
if (timeout_ns_new <= time_now) {
// Skip missed periods without changing the timer's phase.
// Rebasing deadlines on time_now would align timers that
// have the same period.
const uint64_t periods_to_skip =
((time_now - timeout_ns_new) / cur_timer->interval_ns) + 1;
timeout_ns_new += periods_to_skip * cur_timer->interval_ns;
}
cur_timer->timeout_ns = timeout_ns_new;
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);
} else {
// One-shot callbacks may immediately reuse their TimerInfo.
cur_timer->active = false;
// remove one-shot timers from queue
this->timer_queue.pop();
}
this->cb_active = true;
// invoke timer callback
cb(time_now, timeout_ns);
cb();
this->cb_active = false;
@@ -134,17 +153,6 @@ uint64_t TimerManager::process_timers()
} // ] mtx scope
}
// return next timer's expiry
return cur_timer->timeout_ns;
}
void TimerManager::cancel_all_timers()
{
TimerInfo *cur_timer;
while (!this->timer_queue.empty()) {
cur_timer = this->timer_queue.top();
LOG_F(WARNING, "Canceling timer id:%llu ns:%llu", uint64_t(cur_timer), cur_timer->timeout_ns);
this->timer_queue.pop();
cur_timer->active = false;
}
// return time slice in nanoseconds until next timer's expiry
return cur_timer->timeout_ns - time_now;
}
+21 -27
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -40,8 +40,7 @@ constexpr auto ONE_BILLION_NS = 1000000000;
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
typedef std::function<void(uint64_t timeout_ns, uint64_t time_now)> timer_cb;
typedef std::function<void()> notify_changes_cb;
typedef std::function<void()> timer_cb;
/** Extend std::priority_queue as suggested here:
https://stackoverflow.com/a/36711682
@@ -50,17 +49,15 @@ typedef std::function<void()> notify_changes_cb;
template <typename T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
public:
bool remove_by_id(T id){
bool remove_by_id(const uint32_t id){
std::lock_guard<std::recursive_mutex> lk(mtx);
if (this->empty())
return false;
auto el = this->top();
if (el == id) {
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; });
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);
@@ -93,18 +90,17 @@ private:
};
typedef struct TimerInfo {
uint32_t id;
uint64_t timeout_ns; // timer expiry
uint64_t interval_ns; // 0 for one-shot timers
bool active = false; // maintained by TimerManager while queued
timer_cb cb; // timer callback
} TimerInfo;
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const TimerInfo *l, const TimerInfo *r) const {
return l->timeout_ns > r->timeout_ns ||
(l->timeout_ns == r->timeout_ns && l > r);
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
return l.get()->timeout_ns > r.get()->timeout_ns;
}
};
@@ -123,23 +119,19 @@ public:
}
// callback for acknowledging time changes
void set_notify_changes_cb(const notify_changes_cb &cb) {
void set_notify_changes_cb(const timer_cb &cb) {
this->notify_timer_changes = cb;
}
// return current virtual time in nanoseconds
uint64_t current_time_ns() const { return get_time_now(); }
uint64_t current_time_ns() { return get_time_now(); }
// Adding requires an inactive timer; cancel before rescheduling.
// One-shot timers become inactive before their callback runs.
// Cyclic timers remain active until canceled, including during callbacks.
void add_absolute_timer(TimerInfo &ti, uint64_t timeout_ns, uint64_t interval, timer_cb cb);
void add_oneshot_timer(TimerInfo &ti, uint64_t timeout, timer_cb cb);
void add_immediate_timer(TimerInfo &ti, timer_cb cb);
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, timer_cb cb);
void add_cyclic_timer(TimerInfo &ti, uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(TimerInfo &ti);
void cancel_all_timers();
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
uint32_t add_immediate_timer(timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
void cancel_timer(uint32_t id);
uint64_t process_timers();
@@ -148,11 +140,13 @@ private:
TimerManager(){} // private constructor to implement a singleton
// timer queue
my_priority_queue<TimerInfo*, std::vector<TimerInfo*>, MyGtComparator> timer_queue;
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
std::function<uint64_t()> get_time_now;
std::function<void()> notify_timer_changes;
std::atomic<uint32_t> id{0};
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
bool cb_active = false; // true if a timer callback is executing
};
+6 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -23,10 +23,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// Any shared opcodes are in ppcopcodes.cpp
#include <core/bitops.h>
#include <cpu/ppc/ppcdechelpers.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
#include <stdint.h>
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
-215
View File
@@ -1,215 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PPC_DECODE_HELPERS_H
#define PPC_DECODE_HELPERS_H
#include <cinttypes>
// ============== Helpers for extracting operands from opcodes ================
#define decode_ops_sa(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
int reg_a = (opcode >> 16) & 0x1F;
#define decode_ops_da(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
int reg_a = (opcode >> 16) & 0x1F;
#define decode_ops_sab(opcode) \
decode_ops_sa(opcode); \
int reg_b = (opcode >> 11) & 0x1F;
#define decode_ops_dab(opcode) \
decode_ops_da(opcode); \
int reg_b = (opcode >> 11) & 0x1F;
#define decode_ops_dasimm(opcode) \
decode_ops_da(opcode); \
int32_t simm = int32_t(int16_t(opcode));
#define decode_ops_sauimm(opcode) \
decode_ops_sa(opcode); \
uint32_t uimm = uint16_t(opcode);
#define decode_ops_dauimm(opcode) \
decode_ops_da(opcode); \
uint32_t uimm = uint16_t(opcode);
// ================= Helpers for the original interpreter =====================
// The helpers below do the same work as those above but also pre-load some
// register values and place them into local variables.
// That significantly reduces interpreter code.
#define ppc_grab_regsdasimm(opcode) \
decode_ops_dasimm(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdauimm(opcode) \
decode_ops_dauimm(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsasimm(opcode) \
int reg_a = (opcode >> 16) & 0x1F; \
int32_t simm = int32_t(int16_t(opcode)); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssauimm(opcode) \
decode_ops_sauimm(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_crfd_regsauimm(opcode) \
int crf_d = (opcode >> 21) & 0x1C; \
int reg_a = (opcode >> 16) & 0x1F; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_da(opcode) \
decode_ops_da(opcode)
#define ppc_grab_dab(opcode) \
decode_ops_dab(opcode)
#define ppc_grab_s(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
#define ppc_grab_regsdab(opcode) \
decode_ops_dab(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab(opcode) \
decode_ops_sab(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab_stswx(opcode) \
decode_ops_sab(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsab(opcode) \
int reg_a = (opcode >> 16) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
decode_ops_sa(opcode); \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssa_stmw(opcode) \
decode_ops_sa(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash(opcode) \
decode_ops_sa(opcode); \
unsigned rot_sh = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash_stswi(opcode) \
decode_ops_sa(opcode); \
unsigned rot_sh = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsda(opcode) \
decode_ops_da(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdb(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
uint32_t reg_b = (opcode >> 11) & 0x1F; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdb(opcode) \
int reg_d = (opcode >> 21) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F;
#define ppc_grab_regsfpdiab(opcode) \
decode_ops_dab(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdia(opcode) \
decode_ops_da(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsia(opcode) \
decode_ops_sa(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsiab(opcode) \
decode_ops_sab(opcode); \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpsab(opcode) \
int reg_a = (opcode >> 16) & 0x1F; \
int reg_b = (opcode >> 11) & 0x1F; \
int crf_d = (opcode >> 21) & 0x1C; \
double db_test_a = GET_FPR(reg_a); \
double db_test_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdab(opcode) \
decode_ops_dab(opcode); \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdac(opcode) \
decode_ops_da(opcode); \
int reg_c = (opcode >> 6) & 0x1F; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_grab_regsfpdabc(opcode) \
decode_ops_dab(opcode); \
int reg_c = (opcode >> 6) & 0x1F; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_store_iresult_reg(reg, ppc_result) \
ppc_state.gpr[reg] = ppc_result
#define ppc_store_fpresult_int(reg, ppc_result64_d) \
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d) \
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
#endif // PPC_DECODE_HELPERS_H
+13 -20
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -259,9 +259,9 @@ const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "de
"", "sdr1", "srr0", "srr1", "", "", "", ""};
const char* spr_index8[32] = {
"", "", "", "", "", "", "", "", "", "", "",
"", "tbl_u", "tbu_u", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
"", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
const char* spr_index16[32] = {
"", "", "", "", "", "", "", "",
@@ -392,13 +392,6 @@ void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int
}
}
void fmt_rotateinsert(PPCDisasmContext* ctx, const char* opc, int dst, int src, int sh, int mb, int me) {
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
add_reg_in(ctx, "r%d", dst);
add_reg_in(ctx, "r%d", src);
add_reg_out(ctx, "r%d", dst);
}
/* Opcodes */
void opc_illegal(PPCDisasmContext* ctx) {
@@ -529,7 +522,7 @@ void opc_rlwimi(PPCDisasmContext* ctx) {
add_reg_out(ctx, "cr");
}
fmt_rotateinsert(ctx, opcode, ra, rs, sh, mb, me);
fmt_rotateop(ctx, opcode, ra, rs, sh, mb, me, true);
}
void opc_rlwinm(PPCDisasmContext* ctx) {
@@ -1183,14 +1176,14 @@ void opc_group31(PPCDisasmContext* ctx) {
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%d", "tlbld", rb);
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
add_reg_in(ctx, "r%d", rb);
}
} else if (index == 31) { /* tlbli - 603 only */
} else if (index == 30) { /* tlbli - 603 only */
if (!rs && !ra)
opc_illegal(ctx);
else {
ctx->instr_str = my_sprintf("%-7s r%d", "tlbli", rb);
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
add_reg_in(ctx, "r%d", rb);
}
}
@@ -1257,10 +1250,10 @@ void opc_group31(PPCDisasmContext* ctx) {
add_reg_out(ctx, "cr");
}
} else {
if (index >= 16 || !strlen(opc_logic[index])) {
strcpy(opcode, opc_logic[index]);
if (!strlen(opcode)) {
opc_illegal(ctx);
} else {
strcpy(opcode, opc_logic[index]);
if (rc_set) {
strcat(opcode, ".");
add_reg_out(ctx, "cr");
@@ -1401,9 +1394,9 @@ void opc_group31(PPCDisasmContext* ctx) {
break;
}
auto ref_spr = (((ctx->instr_code >> 11) & 31) << 5) | ((ctx->instr_code >> 16) & 31);
auto spr_high = (ctx->instr_code >> 11) & 31;
auto spr_low = (ctx->instr_code >> 16) & 31;
auto ref_spr = (spr_high << 5) | spr_low;
switch (ext_opc) {
case 0: /* cmp */
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+26 -97
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -22,9 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef PPCEMU_H
#define PPCEMU_H
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <memaccess.h>
#include <atomic>
#include <cinttypes>
@@ -37,9 +37,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
//#define CPU_PROFILING // enable CPU profiling
// Uncomment this to enable logging of executed instructions.
//#define LOG_INSTRUCTIONS
/** type of compiler used during execution */
enum EXEC_MODE:uint32_t {
interpreter = 0,
@@ -48,7 +45,7 @@ enum EXEC_MODE:uint32_t {
jit = 3
};
typedef enum { big_end = 0, little_end = 1 } endian_switch;
enum endian_switch { big_end = 0, little_end = 1 };
typedef void (*PPCOpcode)(uint32_t opcode);
@@ -82,9 +79,6 @@ typedef struct struct_ppc_state {
uint32_t msr;
uint32_t sr[16];
bool reserve; // reserve bit used for lwarx and stcwx
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
bool is_LE;
#endif
} SetPRS;
extern SetPRS ppc_state;
@@ -112,7 +106,7 @@ enum SPR : int {
SPRG1 = 273,
SPRG2 = 274,
SPRG3 = 275,
EAR = 282,
EAR = 282,
TBL_S = 284, // supervisor TBL
TBU_S = 285, // supervisor TBU
PVR = 287,
@@ -126,9 +120,6 @@ enum SPR : int {
SDA = 959,
HID0 = 1008,
HID1 = 1009,
THRM1 = 1020,
THRM2 = 1021,
THRM3 = 1022,
};
/** symbolic names for common PPC processors */
@@ -182,6 +173,7 @@ SUPERVISOR MODEL
536 - 543 are the Data BAT registers
**/
extern uint64_t timebase_counter;
extern uint64_t tbr_wr_timestamp;
extern uint64_t dec_wr_timestamp;
extern uint64_t rtc_timestamp;
@@ -198,7 +190,6 @@ enum {
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
EXEF_RFI = 1 << 2, // RFI instruction executed
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
EXEF_SLEEP = 1 << 4, // Processor is waiting in power-saving mode
};
enum CR_select : int32_t {
@@ -313,6 +304,11 @@ enum XER : uint32_t {
SO = 1UL << 31
};
enum DSISR : uint32_t {
PROT = 1UL << 27,
STORE = 1UL << 25
};
//for inf and nan checks
enum FPOP : int {
DIV = 0x12,
@@ -324,22 +320,17 @@ enum FPOP : int {
/** PowerPC exception types. */
enum class Except_Type {
EXC_SYSTEM_RESET = 0x01,
EXC_MACHINE_CHECK = 0x02,
EXC_DSI = 0x03,
EXC_ISI = 0x04,
EXC_EXT_INT = 0x05,
EXC_ALIGNMENT = 0x06,
EXC_PROGRAM = 0x07,
EXC_NO_FPU = 0x08,
EXC_DECR = 0x09,
EXC_SYSCALL = 0x0C,
EXC_TRACE = 0x0D,
EXC_FP_ASSIST = 0x0E,
EXC_PERF_MON_INT = 0x0F,
EXC_INST_ADDR_BP = 0x13,
EXC_SYS_MGMT_INT = 0x14,
EXC_THRM_MGMT_INT = 0x17,
EXC_SYSTEM_RESET = 1,
EXC_MACHINE_CHECK,
EXC_DSI,
EXC_ISI,
EXC_EXT_INT,
EXC_ALIGNMENT,
EXC_PROGRAM,
EXC_NO_FPU,
EXC_DECR,
EXC_SYSCALL = 12,
EXC_TRACE = 13
};
/** Program Exception subclasses. */
@@ -368,20 +359,13 @@ enum Po_Cause : int {
po_enter_debugger,
po_entered_debugger,
po_signal_interrupt,
po_benchmark_exception,
po_endian_switch,
po_benchmark_exception
};
extern bool power_on;
extern Po_Cause power_off_reason;
void p_set_power_off_reason(const char* file, int line, Po_Cause new_reason);
void p_power_off(const char* file, int line, Po_Cause new_reason);
#define set_power_off_reason(r) p_set_power_off_reason(__FILE__, __LINE__, r)
#define power_off(r) p_power_off(__FILE__, __LINE__, r)
extern bool int_pin;
extern bool dec_exception_pending;
extern bool thrm_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
@@ -389,30 +373,14 @@ extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation
enum class PPCPowMode : uint8_t {
None,
Unconditional,
HID0,
};
extern PPCPowMode ppc_pow_mode;
extern uint32_t ppc_pow_hid0_mask;
// Enable deterministic timing and non-persistent state. The selected mode may
// still permit external input.
// Make execution deterministic (ignore external input, used a fixed date, etc.)
extern bool is_deterministic;
// Important Addressing Integers
extern uint32_t ppc_next_instruction_address;
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
extern MemCtrlBase* mem_ctrl_instance;
bool needs_swap = mem_ctrl_instance->needs_swap_endian(false);
return needs_swap ? READ_DWORD_LE_A(ptr) : READ_DWORD_BE_A(ptr);
#else
return READ_DWORD_BE_A(ptr);
#endif
}
// Profiling Stats
@@ -723,48 +691,9 @@ extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
extern PPCOpcode* ppc_opcode_grabber;
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
extern void ppc_change_endian(bool newLE);
/* debugging support API */
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
/* icnt_factor control */
extern int increment_icnt_factor();
extern int decrement_icnt_factor();
extern int get_icnt_factor();
/* realtime clock control */
extern bool g_realtime;
extern bool toggle_g_realtime();
/* force_cycle_counter_reload */
static void force_cycle_counter_reload();
#ifdef LOG_INSTRUCTIONS
typedef struct {
uint64_t cycle;
uint32_t addr;
uint32_t paddr;
uint32_t ins;
uint32_t msr;
uint32_t msr_after;
uint32_t flags_before;
uint32_t flags_after;
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
uint32_t reserved4;
uint32_t reserved5;
uint32_t reserved6;
uint32_t reserved7;
} InstructionRec; // 64 bytes
#define InstructionLogSize 0x1000000
extern InstructionRec InstructionLog[InstructionLogSize];
extern uint64_t InstructionNumber;
void dumpinstructionlog();
#endif
#endif /* PPCEMU_H */
+41 -25
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -39,11 +39,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
case Except_Type::EXC_DSI:
case Except_Type::EXC_ALIGNMENT:
case Except_Type::EXC_PROGRAM:
case Except_Type::EXC_NO_FPU:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0100;
break;
case Except_Type::EXC_MACHINE_CHECK:
@@ -51,6 +48,12 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
/* TODO: handle internal checkstop */
}
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0200;
break;
case Except_Type::EXC_DSI:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0300;
break;
case Except_Type::EXC_ISI:
@@ -59,28 +62,56 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
}
ppc_next_instruction_address = 0x0400;
break;
case Except_Type::EXC_EXT_INT:
case Except_Type::EXC_DECR:
case Except_Type::EXC_THRM_MGMT_INT:
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
}
ppc_next_instruction_address = 0x0500;
break;
case Except_Type::EXC_ALIGNMENT:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0600;
break;
case Except_Type::EXC_PROGRAM:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0700;
break;
case Except_Type::EXC_NO_FPU:
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0800;
break;
case Except_Type::EXC_DECR:
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
}
ppc_next_instruction_address = 0x0900;
break;
case Except_Type::EXC_SYSCALL:
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0C00;
break;
case Except_Type::EXC_TRACE:
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0D00;
break;
default:
ABORT_F("Unknown exception occurred: %X\n", (unsigned)exception_type);
break;
}
ppc_next_instruction_address = uint32_t(exception_type) << 8;
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
uint32_t old_msr_val = ppc_state.msr;
@@ -88,7 +119,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
/* copy MSR[ILE] to MSR[LE] */
if (!is_601) {
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, new_msr_val, false);
@@ -108,9 +138,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
mmu_change_mode();
if (exception_type != Except_Type::EXC_EXT_INT && exception_type != Except_Type::EXC_DECR) {
if (!power_on && power_off_reason == po_endian_switch) [[unlikely]] {
power_on = true;
}
longjmp(exc_env, 2); /* return to the main execution loop. */
}
}
@@ -134,8 +161,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
exc_descriptor = "DSI/ISI exception: unmapped memory access";
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
exc_descriptor = "DSI/ISI exception: access protection violation";
else if (ppc_state.spr[SPR::DSISR] & 0x00100000)
exc_descriptor = "DSI exception: External access is disabled";
else {
if (exception_type == Except_Type::EXC_DSI)
exc_descriptor = "DSI exception";
@@ -171,15 +196,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
case Except_Type::EXC_TRACE:
exc_descriptor = "Trace exception occurred";
break;
case Except_Type::EXC_THRM_MGMT_INT:
exc_descriptor = "Thermal management interrupt exception occurred";
break;
default:
char buffer[100];
snprintf(buffer, sizeof(buffer), "Exception 0x%X occurred", int(exception_type));
exc_descriptor = buffer;
}
throw std::invalid_argument(exc_descriptor);
+52 -293
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -36,7 +36,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#ifdef __APPLE__
#include <ctime>
#include <mach/mach_time.h>
#undef EXC_SYSCALL
static struct mach_timebase_info timebase_info;
static uint64_t
ConvertHostTimeToNanos2(uint64_t host_time)
{
if (timebase_info.numer == timebase_info.denom)
return host_time;
long double answer = host_time;
answer *= timebase_info.numer;
answer /= timebase_info.denom;
return (uint64_t)answer;
}
#endif
using namespace std;
@@ -46,67 +58,13 @@ MemCtrlBase* mem_ctrl_instance = 0;
bool is_601 = false;
bool include_601 = false;
PPCPowMode ppc_pow_mode = PPCPowMode::None;
uint32_t ppc_pow_hid0_mask = 0;
// 603/7xx HID0 power-saving mode bits. They are selected in HID0,
// then entered by setting MSR[POW] with mtmsr.
static constexpr uint32_t HID0_DOZE = 0x00800000;
static constexpr uint32_t HID0_NAP = 0x00400000;
static constexpr uint32_t HID0_SLEEP = 0x00200000;
static constexpr uint32_t HID0_POWER_SAVE_MASK = HID0_DOZE | HID0_NAP | HID0_SLEEP;
bool is_deterministic = false;
bool power_on = false;
Po_Cause power_off_reason = po_enter_debugger;
const char * get_po_name(Po_Cause reason) {
#define onename(x) case x: return #x;
switch (reason) {
onename(po_none)
onename(po_starting_up)
onename(po_quit)
onename(po_quitting)
onename(po_shut_down)
onename(po_shutting_down)
onename(po_restart)
onename(po_restarting)
onename(po_disassemble_on)
onename(po_disassemble_off)
onename(po_enter_debugger)
onename(po_entered_debugger)
onename(po_signal_interrupt)
onename(po_benchmark_exception)
onename(po_endian_switch)
default: return "unknown";
}
#undef onename
}
void p_set_power_off_reason(const char* file, int line, Po_Cause new_reason) {
if (new_reason != power_off_reason) {
power_off_reason = new_reason;
#if 1
LOG_F(INFO, "power_off_reason changed to %s at \"%s\":%d", get_po_name(new_reason), file, line);
#endif
}
}
void p_power_off(const char* file, int line, Po_Cause new_reason) {
power_on = false;
p_set_power_off_reason(file, line, new_reason);
}
SetPRS ppc_state;
#ifdef LOG_INSTRUCTIONS
uint32_t pcp;
#define ATPCP , &pcp
#define INCPC(amount) do { pc_real += (amount); pcp += (amount); } while(0)
#else
#define ATPCP
#define INCPC(amount) pc_real += (amount)
#endif
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
@@ -116,10 +74,14 @@ unsigned exec_flags; // execution control flags
volatile bool exec_timer;
bool int_pin = false; // interrupt request pin state: true - asserted
bool dec_exception_pending = false;
bool thrm_exception_pending = false;
/* copy of local variable bb_start_la. Need for correct
calculation of CPU cycles after setjmp that clobbers
non-volatile local variables. */
uint32_t glob_bb_start_la;
/* variables related to virtual time */
bool g_realtime = false;
const bool g_realtime = false;
uint64_t g_nanoseconds_base;
uint64_t g_icycles;
int icnt_factor;
@@ -133,6 +95,7 @@ uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a
uint32_t tbr_freq_shift; // If 32 bits is not sufficient, then include a shift.
uint64_t tbr_period_ns; // TBR/RTC period in ns expressed as a 64 bit value
// with 32 fractional bits (<1 Hz minimum).
uint64_t timebase_counter; // internal timebase counter
uint64_t dec_wr_timestamp; // stores vCPU virtual time of the last DEC write
uint32_t dec_wr_value; // last value written to the DEC register
uint32_t rtc_lo; // MPC601 RTC lower, counts nanoseconds
@@ -222,11 +185,6 @@ public:
#endif
#ifdef LOG_INSTRUCTIONS
InstructionRec InstructionLog[InstructionLogSize] = {0};
uint64_t InstructionNumber = 0;
#endif
/** Opcode lookup table, indexed by
primary opcode (bits 0...5) and modifier (bits 21...31). */
static PPCOpcode OpcodeGrabber[64 * 2048];
@@ -250,43 +208,17 @@ void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_nex
ppc_next_instruction_address = ppc_state.pc + 4;
}
#else
power_off(po_endian_switch);
power_on = false;
power_off_reason = po_endian_switch;
#endif
}
}
void ppc_change_endian(bool newLE) {
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
if (ppc_state.is_LE != newLE) {
LOG_F(INFO, "changed endian to %s", newLE ? "LE" : "BE");
ppc_state.is_LE = newLE;
power_off(po_endian_switch);
}
#else
if (newLE) {
LOG_F(ERROR, "unsupported endian %s", newLE ? "LE" : "BE");
power_off(po_enter_debugger);
}
#endif
}
PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
/** Exception helpers. */
void ppc_illegalop(uint32_t opcode) {
// Zero values are used as sentinels in the TNT ROM and are thus somewhat
// common, don't log them.
// Example: ciexit in Old World Open Firmware uses opcode 0.
if (opcode) {
PPCDisasmContext ctx;
ctx.instr_code = opcode;
ctx.instr_addr = 0;
ctx.simplified = false;
auto op_name = disassemble_single(&ctx);
LOG_F(WARNING, "Illegal opcode exception raised for 0x%08x (decoded as %s). The PC was 0x%08x.", opcode, op_name.c_str(), ppc_state.pc);
}
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
@@ -319,33 +251,12 @@ void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
num_opcodes[opcode]++;
#endif
#endif
#ifdef LOG_INSTRUCTIONS
if (InstructionNumber && !InstructionLog[(InstructionNumber - 1) & (InstructionLogSize - 1)].flags_after) {
// This happens for all exceptions except EXC_EXT_INT && EXC_DECR
//LOG_F(ERROR, "previous instruction did not complete");
}
InstructionRec * irec = &InstructionLog[InstructionNumber & (InstructionLogSize - 1)];
irec->cycle = InstructionNumber++;
irec->addr = ppc_state.pc;
irec->paddr = pcp;
irec->ins = opcode;
irec->msr = ppc_state.msr;
irec->flags_before = exec_flags | (exec_timer << 7);
irec->flags_after = 0;
#endif
opcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
#ifdef LOG_INSTRUCTIONS
irec->flags_after = exec_flags | (exec_timer << 7) | 0x80000000;
irec->msr_after = ppc_state.msr;
#endif
}
static long long cpu_now_ns() {
#ifdef __APPLE__
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
return ConvertHostTimeToNanos2(mach_absolute_time());
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
@@ -361,49 +272,16 @@ uint64_t get_virt_time_ns()
}
}
void set_virt_time_ns(uint64_t time_now)
{
if (g_realtime) {
g_nanoseconds_base = cpu_now_ns() - time_now - 5000;
} else {
g_icycles = time_now >> icnt_factor;
}
uint64_t time_new = get_virt_time_ns();
if (g_realtime && time_new > time_now) {
g_nanoseconds_base += 2 * (time_new - time_now);
time_new = get_virt_time_ns();
}
LOG_F(INFO, "time before: %lld after: %lld change: %lld", time_now, time_new, time_new - time_now);
}
static constexpr uint64_t TIMER_POLL_INTERVAL_NS = 500'000;
static uint64_t process_events()
{
exec_timer = false;
uint64_t next_ns = TimerManager::get_instance()->process_timers();
if (g_realtime) {
uint64_t time_now = get_virt_time_ns();
uint64_t delay_ns;
if (next_ns) {
delay_ns = next_ns > time_now ? next_ns - time_now : 0;
} else {
delay_ns = TIMER_POLL_INTERVAL_NS;
}
// Host time and the instruction counter advance independently. Schedule
// a relative instruction batch, capped so long deadlines still poll.
// Comparing an absolute wall-time deadline with g_icycles can otherwise
// make a fast interpreter process timers after every instruction.
return g_icycles + (std::min(delay_ns, TIMER_POLL_INTERVAL_NS) >> icnt_factor) + 1;
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
if (slice_ns == 0) {
// execute 25.000 cycles
// if there are no pending timers
return g_icycles + 25000;
}
return (
(
next_ns ?
next_ns
:
get_virt_time_ns() + TIMER_POLL_INTERVAL_NS
) >> icnt_factor
) + 1;
return g_icycles + (slice_ns >> icnt_factor) + 1;
}
static void force_cycle_counter_reload()
@@ -412,40 +290,6 @@ static void force_cycle_counter_reload()
exec_timer = true;
}
int increment_icnt_factor()
{
uint64_t time_now = get_virt_time_ns();
icnt_factor += 1;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
return icnt_factor;
}
int decrement_icnt_factor()
{
if (icnt_factor > 0) {
uint64_t time_now = get_virt_time_ns();
icnt_factor -= 1;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
}
return icnt_factor;
}
int get_icnt_factor()
{
return icnt_factor;
}
bool toggle_g_realtime()
{
uint64_t time_now = get_virt_time_ns();
g_realtime = !g_realtime;
set_virt_time_ns(time_now);
force_cycle_counter_reload();
return g_realtime;
}
typedef enum {
main,
until,
@@ -453,7 +297,7 @@ typedef enum {
} ppc_exec_type_t;
// inner interpreter loop
template <ppc_exec_type_t exec_type, endian_switch endian>
template <ppc_exec_type_t exec_type>
static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
{
uint64_t max_cycles = 0;
@@ -474,7 +318,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
exec_flags = 0;
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
pc_real = mmu_translate_imem(eb_start);
}
opcode = ppc_read_instruction(pc_real);
@@ -483,42 +327,23 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
max_cycles = process_events();
if (exec_flags) {
if ((exec_flags & EXEF_SLEEP) && !(exec_flags & EXEF_EXCEPTION)) [[unlikely]] {
while (power_on && (exec_flags & EXEF_SLEEP)) {
max_cycles = process_events();
if (!(exec_flags & EXEF_SLEEP)) {
break;
}
if (max_cycles > g_icycles) {
g_icycles = max_cycles;
} else {
g_icycles++;
}
}
}
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
opcode_grabber = ppc_opcode_grabber;
}
// define next execution block
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
if (endian == big_end)
INCPC((int)eb_start - (int)ppc_state.pc);
else
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
pc_real += (int)eb_start - (int)ppc_state.pc;
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
pc_real = mmu_translate_imem(eb_start);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else [[likely]] {
} else { [[likely]]
ppc_state.pc += 4;
if (endian == big_end)
INCPC(4);
else
pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
pc_real += 4;
}
if (exec_type == until)
@@ -530,8 +355,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
/** Execute PPC code as long as power is on. */
// inner interpreter loop
template void ppc_exec_inner<main, big_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<main, little_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<main>(uint32_t start_addr, uint32_t size);
// outer interpreter loop
void ppc_exec()
@@ -543,17 +367,7 @@ void ppc_exec()
}
while (power_on) {
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
if (ppc_state.is_LE)
ppc_exec_inner<main, little_end>(0, 0);
else
#endif
[[likely]] {
ppc_exec_inner<main, big_end>(0, 0);
}
if (!power_on && power_off_reason == po_endian_switch) [[unlikely]] {
power_on = true;
}
ppc_exec_inner<main>(0, 0);
}
}
@@ -568,7 +382,7 @@ void ppc_exec_single()
return;
}
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(ppc_opcode_grabber, opcode);
g_icycles++;
@@ -585,8 +399,7 @@ void ppc_exec_single()
/** Execute PPC code until goal_addr is reached. */
// inner interpreter loop
template void ppc_exec_inner<until, big_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<until, little_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
// outer interpreter loop
void ppc_exec_until(volatile uint32_t goal_addr) {
@@ -597,17 +410,7 @@ void ppc_exec_until(volatile uint32_t goal_addr) {
}
while (power_on) {
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
if (ppc_state.is_LE)
ppc_exec_inner<until, little_end>(goal_addr, 0);
else
#endif
[[likely]] {
ppc_exec_inner<until, big_end>(goal_addr, 0);
}
if (!power_on && power_off_reason == po_endian_switch) [[unlikely]] {
power_on = true;
}
ppc_exec_inner<until>(goal_addr, 0);
if (ppc_state.pc == goal_addr)
break;
}
@@ -616,8 +419,7 @@ void ppc_exec_until(volatile uint32_t goal_addr) {
/** Execute PPC code until control is reached the specified region. */
// inner interpreter loop
template void ppc_exec_inner<debug, big_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<debug, little_end>(uint32_t start_addr, uint32_t size);
template void ppc_exec_inner<debug>(uint32_t start_addr, uint32_t size);
// outer interpreter loop
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
@@ -629,17 +431,7 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
}
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
if (ppc_state.is_LE)
ppc_exec_inner<debug, little_end>(start_addr, size);
else
#endif
[[likely]] {
ppc_exec_inner<debug, big_end>(start_addr, size);
}
if (!power_on && power_off_reason == po_endian_switch) [[unlikely]] {
power_on = true;
}
ppc_exec_inner<debug>(start_addr, size);
}
}
@@ -1016,34 +808,12 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
{
mem_ctrl_instance = mem_ctrl;
int_pin = false;
std::memset(&ppc_state, 0, sizeof(ppc_state));
set_host_rounding_mode(0);
ppc_state.spr[SPR::PVR] = cpu_version;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 & do_include_601;
ppc_pow_mode = PPCPowMode::None;
ppc_pow_hid0_mask = 0;
switch (cpu_version) {
case PPC_VER::MPC603:
case PPC_VER::MPC603E:
case PPC_VER::MPC603EV:
case PPC_VER::MPC750:
// 603/7xx enter power-saving modes through HID0 doze/nap/sleep
// bits selected before MSR[POW] is set.
ppc_pow_mode = PPCPowMode::HID0;
ppc_pow_hid0_mask = HID0_POWER_SAVE_MASK;
break;
case PPC_VER::MPC604:
case PPC_VER::MPC604E:
// 604-family processors use MSR[POW] directly.
ppc_pow_mode = PPCPowMode::Unconditional;
break;
default:
break;
}
initialize_ppc_opcode_table();
@@ -1052,6 +822,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
TimerManager::get_instance()->set_notify_changes_cb(&force_cycle_counter_reload);
// initialize time base facility
#ifdef __APPLE__
mach_timebase_info(&timebase_info);
#endif
g_nanoseconds_base = cpu_now_ns();
g_icycles = 0;
@@ -1084,11 +857,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
exec_flags = 0;
exec_timer = false;
timebase_counter = 0;
dec_wr_value = 0;
#ifdef LOG_INSTRUCTIONS
pcp = 0;
#endif
uint32_t new_msr_val;
if (is_601) {
@@ -1097,7 +868,6 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
} else {
new_msr_val = MSR::IP;
ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL;
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
ppc_msr_did_change(new_msr_val, new_msr_val, false);
@@ -1124,16 +894,13 @@ static map<string, int> SPRName2Num = {
{"DBAT2L", 541}, {"DBAT3U", 542}, {"DBAT3L", 543},
{"HID0", SPR::HID0}, {"HID1", SPR::HID1}, {"IABR", 1010},
{"DABR", 1013}, {"L2CR", 1017}, {"ICTC", 1019},
{"THRM1", SPR::THRM1}, {"THRM2", SPR::THRM2}, {"THRM3", SPR::THRM3},
{"THRM1", 1020}, {"THRM2", 1021}, {"THRM3", 1022},
{"PIR", 1023}, {"TBL", SPR::TBL_S}, {"TBU", SPR::TBU_S},
{"SDR1", SPR::SDR1}, {"MQ", SPR::MQ}, {"RTCU", SPR::RTCU_S},
{"RTCL", SPR::RTCL_S}, {"DSISR", SPR::DSISR}, {"DAR", SPR::DAR},
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4}, {"EAR", SPR::EAR},
// get value from supervisor index same as we do for SPR268 and SPR269
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
};
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
@@ -1161,9 +928,6 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
if (is_write) {
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = (uint32_t)val;
if (!is_601) {
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
ppc_msr_did_change(old_msr_val, new_msr_val, false);
}
return ppc_state.msr;
@@ -1219,13 +983,8 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
case SPR::TBL_U : reg_num = SPR::TBL_S ; break;
case SPR::TBU_U : reg_num = SPR::TBU_S ; break;
}
if (is_write) {
if (is_write)
ppc_state.spr[reg_num] = (uint32_t)val;
if (reg_num == SPR::HID0)
if (is_601) {
ppc_change_endian((val & 0x10000000) != 0);
}
}
return ppc_state.spr[reg_num];
}
}
+59 -88
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,19 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// The floating point opcodes for the processor - ppcfpopcodes.cpp
#include <cpu/ppc/ppcdechelpers.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
#include <stdlib.h>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <cmath>
#include <stdlib.h>
#if defined(__APPLE__) && defined(__aarch64__)
#include <arm_acle.h>
#endif
#include <cfloat>
inline static void ppc_update_cr1() {
// copy FPSCR[FX|FEX|VX|OX] to CR1
@@ -42,7 +37,7 @@ inline static void ppc_update_cr1() {
}
static int32_t round_to_nearest(double f) {
return static_cast<int32_t>(std::nearbyint(f));
return static_cast<int32_t>(static_cast<int64_t> (std::floor(f + 0.5)));
}
void set_host_rounding_mode(uint8_t mode) {
@@ -116,31 +111,11 @@ inline static bool check_qnan(int check_reg) {
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
}
static double set_endresult_nan() {
ppc_state.fpscr |= (FX | VX);
static double set_endresult_nan(double ppc_result_d) {
ppc_state.fpscr += (FX + VX);
return std::numeric_limits<double>::quiet_NaN();
}
#if FE_ALL_EXCEPT
static int test_and_clear_fp_exceptions() {
#if defined(__APPLE__) && defined(__aarch64__)
// Darwin's FE_* masks match the ARM64 FPSR exception bits. Preserve
// other status bits and avoid a second register read when clearing.
uint64_t fpsr = __arm_rsr64("fpsr");
int exceptions = fpsr & FE_ALL_EXCEPT;
if (exceptions) {
fpsr &= ~uint64_t(FE_ALL_EXCEPT);
__arm_wsr64("fpsr", fpsr);
}
#else
int exceptions = std::fetestexcept(FE_ALL_EXCEPT);
if (exceptions)
std::feclearexcept(FE_ALL_EXCEPT);
#endif
return exceptions;
}
#endif
static void fpresult_update(double set_result) {
if (std::isnan(set_result)) {
ppc_state.fpscr |= FPCC_FUNAN | FPRCD;
@@ -152,18 +127,18 @@ static void fpresult_update(double set_result) {
} else {
ppc_state.fpscr |= FPCC_ZERO;
}
#if FE_ALL_EXCEPT
int exceptions = test_and_clear_fp_exceptions();
if (exceptions & FE_OVERFLOW) {
if (std::fetestexcept(FE_OVERFLOW)) {
ppc_state.fpscr |= (OX + FX);
}
if (exceptions & FE_UNDERFLOW) {
if (std::fetestexcept(FE_UNDERFLOW)) {
ppc_state.fpscr |= (UX + FX);
}
if (exceptions & FE_DIVBYZERO) {
if (std::fetestexcept(FE_DIVBYZERO)) {
ppc_state.fpscr |= (ZX + FX);
}
#endif
std::feclearexcept(FE_ALL_EXCEPT);
if (std::isinf(set_result))
ppc_state.fpscr |= FPCC_FUNAN;
@@ -179,11 +154,11 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = ((ppc_state.fpscr >> 22) & 0x0F8);
uint32_t fpscr_check = (ppc_state.fpscr >> 22) & ppc_state.fpscr & 0x0F8;
if (fpscr_check)
ppc_state.fpscr |= FEX;
ppc_state.fpscr |= VX;
else
ppc_state.fpscr &= ~FEX;
ppc_state.fpscr &= ~VX;
}
// Floating Point Arithmetic
@@ -200,7 +175,7 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -231,7 +206,7 @@ void dppc_interpreter::ppc_fsub(uint32_t opcode) {
if ((val_reg_a == inf) && (val_reg_b == inf)) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -280,7 +255,7 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if ((val_reg_a == 0.0) && (val_reg_b == 0.0)) {
ppc_state.fpscr |= VXZDZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -311,7 +286,7 @@ void dppc_interpreter::ppc_fmul(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -346,7 +321,7 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -354,7 +329,7 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -384,7 +359,7 @@ void dppc_interpreter::ppc_fmsub(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -392,7 +367,7 @@ void dppc_interpreter::ppc_fmsub(uint32_t opcode) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -430,7 +405,7 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -438,18 +413,18 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
if (snan_single_check(reg_a) || snan_single_check(reg_b) || snan_single_check(reg_c)) {
uint64_t qnan = 0x7FFC000000000000;
ppc_store_fpresult_int(reg_d, qnan);
}
else {
} else {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
@@ -469,7 +444,7 @@ void dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -477,7 +452,7 @@ void dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -509,7 +484,7 @@ void dppc_interpreter::ppc_fadds(uint32_t opcode) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -540,7 +515,7 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
((val_reg_a == -inf) && (val_reg_b == -inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -576,7 +551,7 @@ void dppc_interpreter::ppc_fdivs(uint32_t opcode) {
if ((val_reg_a == 0.0) && (val_reg_b == 0.0)) {
ppc_state.fpscr |= VXZDZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -610,7 +585,7 @@ void dppc_interpreter::ppc_fmuls(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -648,7 +623,7 @@ void dppc_interpreter::ppc_fmadds(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -659,6 +634,7 @@ void dppc_interpreter::ppc_fmadds(uint32_t opcode) {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
fpresult_update(ppc_dblresult64_d);
if (rec)
@@ -678,7 +654,7 @@ void dppc_interpreter::ppc_fmsubs(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -719,7 +695,7 @@ void dppc_interpreter::ppc_fnmadds(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -752,7 +728,7 @@ void dppc_interpreter::ppc_fnmsubs(uint32_t opcode) {
(std::isinf(val_reg_c) && (val_reg_a == 0.0))) {
ppc_state.fpscr |= VXIMZ;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan();
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
}
}
@@ -788,6 +764,8 @@ void dppc_interpreter::ppc_fabs(uint32_t opcode) {
ppc_store_fpresult_int(reg_d, ppc_result64_d);
snan_single_check(reg_d);
if (rec)
ppc_update_cr1();
}
@@ -803,6 +781,8 @@ void dppc_interpreter::ppc_fnabs(uint32_t opcode) {
ppc_store_fpresult_int(reg_d, ppc_result64_d);
snan_single_check(reg_d);
if (rec)
ppc_update_cr1();
}
@@ -818,6 +798,8 @@ void dppc_interpreter::ppc_fneg(uint32_t opcode) {
ppc_store_fpresult_int(reg_d, ppc_result64_d);
snan_single_check(reg_d);
if (rec)
ppc_update_cr1();
}
@@ -1049,7 +1031,7 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1070,7 +1052,7 @@ void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
}
@@ -1094,7 +1076,7 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1115,7 +1097,7 @@ void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1138,7 +1120,7 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1159,7 +1141,7 @@ void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1180,7 +1162,7 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1199,7 +1181,7 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ea);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1264,9 +1246,6 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
// copy FPR[reg_b] to FPSCR under control of cr_mask
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (FPR_INT(reg_b) & cr_mask);
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1303,9 +1282,6 @@ void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
}
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1320,9 +1296,6 @@ void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
ppc_state.fpscr |= (0x80000000UL >> crf_d);
}
ppc_update_vx();
ppc_update_fex();
if (rec)
ppc_update_cr1();
}
@@ -1343,10 +1316,8 @@ void dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI));
ppc_update_vx();
ppc_update_fex();
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
));
}
// Floating Point Comparisons
+213
View File
@@ -0,0 +1,213 @@
/*
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_crfd_regsauimm(opcode) \
int crf_d = (opcode >> 21) & 0x1C; \
int reg_a = (opcode >> 16) & 31; \
uint32_t uimm = uint16_t(opcode); \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_da(opcode)\
int reg_d = (opcode >> 21) & 31;\
int reg_a = (opcode >> 16) & 31;\
#define ppc_grab_dab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31;
#define ppc_grab_s(opcode) \
int reg_s = (opcode >> 21) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
#define ppc_grab_regsdab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssab(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
#define ppc_grab_regssab_stswx(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsab(opcode) \
int reg_a = (opcode >> 16) & 31;\
int reg_b = (opcode >> 11) & 31;\
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_grab_regssa(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssa_stmw(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssash_stswi(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
unsigned rot_sh = (opcode >> 11) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regssb(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
#define ppc_grab_regsda(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_a = (opcode >> 16) & 31; \
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsdb(opcode) \
int reg_d = (opcode >> 21) & 31; \
uint32_t reg_b = (opcode >> 11) & 31; \
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
#define ppc_store_iresult_reg(reg, ppc_result)\
ppc_state.gpr[reg] = ppc_result
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d)\
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
#define ppc_grab_regsfpdb(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_b = (opcode >> 11) & 31;
#define GET_FPR(reg) \
ppc_state.fpr[(reg)].dbl64_r
#define FPR_INT(reg) \
ppc_state.fpr[reg].int64_r
#define ppc_grab_regsfpdiab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpdia(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsia(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a];
#define ppc_grab_regsfpsiab(opcode) \
int reg_s = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
uint32_t val_reg_b = ppc_state.gpr[reg_b];
#define ppc_grab_regsfpsab(opcode) \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
int crf_d = (opcode >> 21) & 0x1C; \
double db_test_a = GET_FPR(reg_a); \
double db_test_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdab(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b);
#define ppc_grab_regsfpdac(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_c = (opcode >> 6) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_c = GET_FPR(reg_c);
#define ppc_grab_regsfpdabc(opcode) \
int reg_d = (opcode >> 21) & 31; \
int reg_a = (opcode >> 16) & 31; \
int reg_b = (opcode >> 11) & 31; \
int reg_c = (opcode >> 6) & 31; \
double val_reg_a = GET_FPR(reg_a); \
double val_reg_b = GET_FPR(reg_b); \
double val_reg_c = GET_FPR(reg_c);
#endif // PPC_MACROS_H
+361 -726
View File
File diff suppressed because it is too large. Load diff
+39 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,6 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef PPCMMU_H
#define PPCMMU_H
#include <devices/memctrl/memctrlbase.h>
#include <cinttypes>
#include <functional>
@@ -71,7 +73,6 @@ typedef struct PATResult {
/** DMA memory mapping result. */
typedef struct MapDmaResult {
uint32_t type;
uint32_t size;
bool is_writable;
// for memory regions
uint8_t* host_va;
@@ -83,20 +84,47 @@ typedef struct MapDmaResult {
constexpr uint32_t PPC_PAGE_SIZE_BITS = 12;
constexpr uint32_t PPC_PAGE_SIZE = (1 << PPC_PAGE_SIZE_BITS);
constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
constexpr uint32_t TLB_SIZE = 4096;
constexpr uint32_t TLB2_WAYS = 4;
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
typedef struct TLBEntry {
uint32_t tag;
uint16_t flags;
uint16_t lru_bits;
union {
struct { // for memory pages
int64_t host_va_offs_r;
int64_t host_va_offs_w;
};
struct { // for MMIO pages
AddressMapEntry* rgn_desc;
int64_t dev_base_va;
};
};
uint32_t phys_tag;
uint32_t reserved;
} TLBEntry;
enum TLBFlags : uint16_t {
PAGE_MEM = 1 << 0, // memory page backed by host memory
PAGE_IO = 1 << 1, // memory mapped I/O page
PAGE_NOPHYS = 1 << 2, // no physical storage for this page (unmapped)
TLBE_FROM_BAT = 1 << 3, // TLB entry has been translated with BAT
TLBE_FROM_PAT = 1 << 4, // TLB entry has been translated with PAT
PAGE_WRITABLE = 1 << 5, // page is writable
PTE_SET_C = 1 << 6, // tells if C bit of the PTE needs to be updated
};
extern std::function<void(uint32_t bat_reg)> ibat_update;
extern std::function<void(uint32_t bat_reg)> dbat_update;
extern PPC_BAT_entry ibat_array[4];
extern PPC_BAT_entry dbat_array[4];
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size,
bool allow_mmio = false, bool allow_partial = false, bool is_dbg = false);
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio);
extern void mmu_change_mode(void);
extern void mmu_pat_ctx_changed();
extern void tlb_flush_all_pat();
extern void mmu_dcbz(uint32_t opcode, uint32_t guest_va);
extern void tlb_flush_entry(uint32_t ea);
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
+211 -292
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,16 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <core/bitops.h>
#include <core/timermanager.h>
#include <core/mathutils.h>
#include <cpu/ppc/ppcdechelpers.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
#include <cinttypes>
#include <vector>
static int junction_temperature = 24;
static TimerInfo thermal_timer;
//Extract the registers desired and the values of the registers.
// Affects CR Field 0 - For integer operations
@@ -52,14 +48,30 @@ void ppc_changecrf0(uint32_t set_result) {
}
// Affects the XER register's Carry Bit
inline static void ppc_carry(uint64_t ppc_result_l) {
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~XER::CA) | ((ppc_result_l >> (32 - 29)) & XER::CA);
inline static void ppc_carry(uint32_t a, uint32_t b) {
if (b < a) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
}
inline static void ppc_carry_sub(uint32_t a, uint32_t b) {
if (b >= a) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
}
// Affects the XER register's SO and OV Bits
inline static void ppc_setsoov(uint32_t a, uint32_t b, uint32_t d) {
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~XER::OV) |
((int32_t((a ^ b) & (a ^ d)) < 0) ? (XER::SO | XER::OV) : 0);
if (int32_t((a ^ b) & (a ^ d)) < 0) {
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
} else {
ppc_state.spr[SPR::XER] &= ~XER::OV;
}
}
typedef std::function<void()> CtxSyncCallback;
@@ -99,9 +111,8 @@ template void dppc_interpreter::ppc_addi<SHFT1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_addic(uint32_t opcode) {
ppc_grab_regsdasimm(opcode);
uint64_t ppc_result_l = uint64_t(ppc_result_a) + uint32_t(simm);
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t ppc_result_d = (ppc_result_a + simm);
ppc_carry(ppc_result_a, ppc_result_d);
if (rec)
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
@@ -113,10 +124,10 @@ template void dppc_interpreter::ppc_addic<RC1>(uint32_t opcode);
template <field_carry carry, field_rc rec, field_ov ov>
void dppc_interpreter::ppc_add(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint64_t ppc_result_l = uint64_t(ppc_result_a) + ppc_result_b;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
uint32_t ppc_result_d = ppc_result_a + ppc_result_b;
if (carry)
ppc_carry(ppc_result_l);
ppc_carry(ppc_result_a, ppc_result_d);
if (ov)
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
if (rec)
@@ -137,9 +148,14 @@ template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_adde(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(ppc_result_a) + ppc_result_b + xer_ca;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t ppc_result_d = ppc_result_a + ppc_result_b + xer_ca;
if ((ppc_result_d < ppc_result_a) || (xer_ca && (ppc_result_d == ppc_result_a))) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (ov)
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
if (rec)
@@ -157,9 +173,14 @@ template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_addme(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(ppc_result_a) + xer_ca + uint32_t(-1);
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t ppc_result_d = ppc_result_a + xer_ca - 1;
if (((xer_ca - 1) < 0xFFFFFFFFUL) || (ppc_result_d < ppc_result_a)) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (ov)
ppc_setsoov(ppc_result_a, 0, ppc_result_d);
if (rec)
@@ -176,10 +197,15 @@ template void dppc_interpreter::ppc_addme<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_addze(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(ppc_result_a) + xer_ca;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t grab_xer = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint32_t ppc_result_d = ppc_result_a + grab_xer;
if (ppc_result_d < ppc_result_a) {
ppc_state.spr[SPR::XER] |= XER::CA;
} else {
ppc_state.spr[SPR::XER] &= ~XER::CA;
}
if (ov)
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
if (rec)
@@ -195,19 +221,21 @@ template void dppc_interpreter::ppc_addze<RC1, OV1>(uint32_t opcode);
void dppc_interpreter::ppc_subfic(uint32_t opcode) {
ppc_grab_regsdasimm(opcode);
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + uint32_t(simm) + 1;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t ppc_result_d = simm - ppc_result_a;
if (simm == -1)
ppc_state.spr[SPR::XER] |= XER::CA;
else
ppc_carry(~ppc_result_a, ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
}
template <field_carry carry, field_rc rec, field_ov ov>
void dppc_interpreter::ppc_subf(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + ppc_result_b + 1;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
uint32_t ppc_result_d = ppc_result_b - ppc_result_a;
if (carry)
ppc_carry(ppc_result_l);
ppc_carry_sub(ppc_result_a, ppc_result_b);
if (ov)
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
if (rec)
@@ -228,10 +256,13 @@ template void dppc_interpreter::ppc_subf<CARRY1, RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_subfe(uint32_t opcode) {
ppc_grab_regsdab(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + ppc_result_b + xer_ca;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint32_t ppc_result_d = ~ppc_result_a + ppc_result_b + grab_ca;
if (grab_ca && ppc_result_b == 0xFFFFFFFFUL)
ppc_state.spr[SPR::XER] |= XER::CA;
else
ppc_carry(~ppc_result_a, ppc_result_d);
if (ov)
ppc_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
if (rec)
@@ -248,10 +279,14 @@ template void dppc_interpreter::ppc_subfe<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_subfme(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + xer_ca + uint32_t(-1);
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint32_t ppc_result_d = ~ppc_result_a + grab_ca - 1;
if (ppc_result_a == 0xFFFFFFFFUL && !grab_ca)
ppc_state.spr[SPR::XER] &= ~XER::CA;
else
ppc_state.spr[SPR::XER] |= XER::CA;
if (ov) {
if (ppc_result_d == ppc_result_a && int32_t(ppc_result_d) > 0)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
@@ -273,10 +308,14 @@ template void dppc_interpreter::ppc_subfme<RC1, OV1>(uint32_t opcode);
template <field_rc rec, field_ov ov>
void dppc_interpreter::ppc_subfze(uint32_t opcode) {
ppc_grab_regsda(opcode);
uint32_t xer_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint64_t ppc_result_l = uint64_t(uint32_t(~ppc_result_a)) + xer_ca;
uint32_t ppc_result_d = uint32_t(ppc_result_l);
ppc_carry(ppc_result_l);
uint32_t grab_ca = !!(ppc_state.spr[SPR::XER] & XER::CA);
uint32_t ppc_result_d = ~ppc_result_a + grab_ca;
if (!ppc_result_d && grab_ca) // special case: ppc_result_d = 0 and CA=1
ppc_state.spr[SPR::XER] |= XER::CA;
else
ppc_state.spr[SPR::XER] &= ~XER::CA;
if (ov) {
if (ppc_result_d && ppc_result_d == ppc_result_a)
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
@@ -691,12 +730,11 @@ void dppc_interpreter::ppc_mtsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_s(opcode);
int reg_s = (opcode >> 21) & 0x1F;
uint32_t grab_sr = (opcode >> 16) & 0x0F;
if (ppc_state.sr[grab_sr] != ppc_result_d) {
ppc_state.sr[grab_sr] = ppc_result_d;
if (ppc_state.sr[grab_sr] != ppc_state.gpr[reg_s]) {
ppc_state.sr[grab_sr] = ppc_state.gpr[reg_s];
mmu_pat_ctx_changed();
}
}
@@ -707,7 +745,6 @@ void dppc_interpreter::ppc_mtsrin(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_regssb(opcode);
uint32_t grab_sr = ppc_result_b >> 28;
@@ -723,7 +760,6 @@ void dppc_interpreter::ppc_mfsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
int reg_d = (opcode >> 21) & 0x1F;
uint32_t grab_sr = (opcode >> 16) & 0x0F;
@@ -736,7 +772,6 @@ void dppc_interpreter::ppc_mfsrin(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_regsdb(opcode);
uint32_t grab_sr = ppc_result_b >> 28;
@@ -749,7 +784,6 @@ void dppc_interpreter::ppc_mfmsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
uint32_t reg_d = (opcode >> 21) & 0x1F;
ppc_state.gpr[reg_d] = ppc_state.msr;
@@ -761,14 +795,10 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
#endif
if (ppc_state.msr & MSR::PR) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
return;
}
ppc_grab_s(opcode);
uint32_t reg_s = (opcode >> 21) & 0x1F;
uint32_t old_msr_val = ppc_state.msr;
uint32_t new_msr_val = ppc_result_d;
if (!is_601) {
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
uint32_t new_msr_val = ppc_state.gpr[reg_s];
ppc_msr_did_change(old_msr_val, new_msr_val);
// generate External Interrupt Exception
@@ -780,29 +810,6 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
dec_exception_pending = false;
//LOG_F(WARNING, "MTMSR: decrementer exception triggered");
ppc_exception_handler(Except_Type::EXC_DECR, 0);
} else if ((ppc_state.msr & MSR::EE) && thrm_exception_pending) {
thrm_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
} else if (ppc_state.msr & MSR::POW) [[unlikely]] {
bool enter_sleep = false;
switch (ppc_pow_mode) {
case PPCPowMode::Unconditional:
enter_sleep = true;
break;
case PPCPowMode::HID0:
enter_sleep = (ppc_state.spr[SPR::HID0] & ppc_pow_hid0_mask) != 0;
break;
case PPCPowMode::None:
break;
}
if (enter_sleep) {
exec_flags |= EXEF_SLEEP;
ppc_next_instruction_address = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
} else {
mmu_change_mode();
}
} else {
mmu_change_mode();
}
@@ -872,11 +879,13 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
tbr_wr_timestamp = get_virt_time_ns();
}
static TimerInfo decrementer_timer;
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
static uint32_t decrementer_timer_id = 0;
static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
static void trigger_decrementer_exception() {
decrementer_timer_id = 0;
dec_wr_value = -1;
dec_wr_timestamp = get_virt_time_ns();
if (ppc_state.msr & MSR::EE) {
dec_exception_pending = false;
//LOG_F(WARNING, "decrementer exception triggered");
@@ -888,100 +897,30 @@ static void trigger_decrementer_exception(uint64_t = 0, uint64_t = 0) {
}
}
static void trigger_timed_decrementer_exception(uint64_t, uint64_t) {
uint32_t new_val = calc_dec_value();
if (new_val >= 0 && new_val != uint32_t(-1)) {
new_val = -1;
}
update_decrementer(true, new_val, new_val);
trigger_decrementer_exception();
}
static void trigger_immediate_decrementer_exception(uint64_t, uint64_t) {
update_decrementer(false, ppc_state.spr[SPR::DEC_S], ppc_state.spr[SPR::DEC_S]);
trigger_decrementer_exception();
}
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval) {
if (update_time_stamp) {
dec_wr_value = newval;
dec_wr_timestamp = get_virt_time_ns();
}
static void update_decrementer(uint32_t val) {
dec_wr_value = val;
dec_wr_timestamp = get_virt_time_ns();
dec_exception_pending = false;
if (decrementer_timer.active) {
TimerManager::get_instance()->cancel_timer(decrementer_timer);
}
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
TimerManager::get_instance()->add_immediate_timer(decrementer_timer,
trigger_immediate_decrementer_exception
);
if (is_601)
return;
}
// A count of zero should timeout after one tick so add one to the count
// but make sure the count doesn't overflow.
if (is_601) {
if (newval < uint32_t(-0x80))
newval += 0x80;
} else {
if (newval < uint32_t(-1))
newval += 1;
if (decrementer_timer_id) {
//LOG_F(WARNING, "decrementer cancel timer");
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
}
uint64_t time_out;
uint32_t time_out_lo;
_u32xu64(newval, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "new decrementer value: 0x%08X, interrupt after %llu ns", newval, time_out);
TimerManager::get_instance()->add_oneshot_timer(decrementer_timer,
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
time_out,
trigger_timed_decrementer_exception
trigger_decrementer_exception
);
}
static void update_thermal(uint64_t, uint64_t) {
uint32_t val = ppc_state.spr[SPR::THRM3];
auto sampled_interval_timer_value = (val >> 1) & 0x1FFF;
auto enabled = val & 1;
bool interrupt = false;
for (int the_reg = 0; the_reg < 2; the_reg++) {
val = ppc_state.spr[SPR::THRM1 + the_reg];
uint32_t t_interrupt; // = (val >> 31) & 1;
uint32_t t_int_valid; // = (val >> 30) & 1;
uint32_t threshold = (val >> 23) & 0x7F;
uint32_t t_int_direction = (val >> 2) & 1;
uint32_t t_int_enable = (val >> 1) & 1;
uint32_t valid = (val >> 0) & 1;
if (!valid) {
t_interrupt = 0;
t_int_valid = 0;
} else {
t_interrupt = t_int_direction ?
junction_temperature < threshold
:
junction_temperature > threshold;
t_int_valid = 1;
interrupt |= t_int_enable && t_interrupt;
}
ppc_state.spr[SPR::THRM1 + the_reg] = (t_interrupt << 31) | (t_int_valid << 30) | (val & 0x3FFFFFFF);
}
if (interrupt && enabled) {
if (ppc_state.msr & MSR::EE) {
thrm_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
}
else {
thrm_exception_pending = true;
}
}
}
void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_grab_dab(opcode);
uint32_t ref_spr = (reg_b << 5) | reg_a;
@@ -997,17 +936,20 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
}
switch (ref_spr) {
case SPR::XER:
case SPR::LR:
case SPR::CTR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::MQ:
if (!(is_601 || include_601)) {
ppc_illegalop(opcode);
return;
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
case SPR::RTCL_U:
if (!is_601) {
ppc_illegalop(opcode);
return;
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
calc_rtcl_value();
ppc_state.gpr[reg_d] =
@@ -1016,8 +958,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
break;
case SPR::RTCU_U:
if (!is_601) {
ppc_illegalop(opcode);
return;
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
calc_rtcl_value();
ppc_state.gpr[reg_d] =
@@ -1026,8 +967,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
break;
case SPR::DEC_U:
if (!is_601) {
ppc_illegalop(opcode);
return;
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
// fallthrough
case SPR::DEC_S:
@@ -1038,7 +978,6 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
break;
}
case SPR::TBL_U:
case SPR::TBL_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
@@ -1046,7 +985,6 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
break;
}
case SPR::TBU_U:
case SPR::TBU_S: {
uint64_t tbr_value = calc_tbr_value();
ppc_state.gpr[reg_d] =
@@ -1054,17 +992,23 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
break;
}
case SPR::THRM1:
case SPR::THRM2: {
uint32_t val = ppc_state.spr[ref_spr];
ppc_state.gpr[reg_d] = val;
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::PVR:
case SPR::EAR:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
}
case SPR::THRM3:
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
break;
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MFSPR: %d", ref_spr);
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
}
}
@@ -1086,22 +1030,29 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
uint32_t val = ppc_state.gpr[reg_d];
switch (ref_spr) {
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::LR:
case SPR::CTR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::MQ:
if (is_601 || include_601)
ppc_state.spr[ref_spr] = val;
else
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
break;
case SPR::RTCL_U:
case SPR::RTCU_U:
case SPR::DEC_U:
if (!is_601) {
ppc_illegalop(opcode);
if (is_601) {
ppc_state.spr[ref_spr] = val;
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
break;
case SPR::XER:
ppc_state.spr[ref_spr] = val & 0xe000ff7f;
break;
case SPR::SDR1:
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
@@ -1121,8 +1072,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case SPR::DEC_S:
if (is_601)
val &= ~0x7F;
update_decrementer(true, calc_dec_value(), val);
ppc_state.spr[SPR::DEC_S] = val;
ppc_state.spr[DEC_S] = val;
update_decrementer(val);
break;
case SPR::TBL_S:
update_timebase(0xFFFFFFFF00000000ULL, val);
@@ -1134,6 +1085,19 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
ppc_state.spr[TBL_S] = (uint32_t)tbr_wr_value;
ppc_state.spr[TBU_S] = val;
break;
case SPR::DSISR:
case SPR::DAR:
case SPR::SRR0:
case SPR::SRR1:
case SPR::EAR:
ppc_state.spr[ref_spr] = val;
break;
case SPR::SPRG0:
case SPR::SPRG1:
case SPR::SPRG2:
case SPR::SPRG3:
ppc_state.spr[ref_spr] = val;
break;
case SPR::PVR:
break;
case 528:
@@ -1144,10 +1108,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case 533:
case 534:
case 535:
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
ibat_update(ref_spr);
}
ppc_state.spr[ref_spr] = val;
ibat_update(ref_spr);
break;
case 536:
case 537:
@@ -1157,38 +1119,12 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
case 541:
case 542:
case 543:
if (ppc_state.spr[ref_spr] != val) {
ppc_state.spr[ref_spr] = val;
dbat_update(ref_spr);
}
break;
case SPR::HID0:
ppc_state.spr[ref_spr] = val;
if (is_601) {
ppc_change_endian((val & 0x10000000) != 0);
}
dbat_update(ref_spr);
break;
case SPR::THRM1:
case SPR::THRM2: {
ppc_state.spr[ref_spr] = val & 0x3F800007;
if (thermal_timer.active)
TimerManager::get_instance()->cancel_timer(thermal_timer);
TimerManager::get_instance()->add_oneshot_timer(thermal_timer, USECS_TO_NSECS(20), update_thermal);
break;
}
case SPR::THRM3: {
ppc_state.spr[ref_spr] = val & 0x00003FFF;
ppc_state.spr[SPR::THRM1] &= ~(3<<30);
ppc_state.spr[SPR::THRM2] &= ~(3<<30);
if (thermal_timer.active)
TimerManager::get_instance()->cancel_timer(thermal_timer);
TimerManager::get_instance()->add_oneshot_timer(thermal_timer, USECS_TO_NSECS(20), update_thermal);
break;
}
default:
// FIXME: Unknown SPR should be noop or illegal instruction.
LOG_F(ERROR, "Mystery SPR in MTSPR: %d", ref_spr);
ppc_state.spr[ref_spr] = val;
}
}
@@ -1211,7 +1147,7 @@ void dppc_interpreter::ppc_mftb(uint32_t opcode) {
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
break;
default:
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1542,24 +1478,18 @@ void dppc_interpreter::ppc_rfi(uint32_t opcode) {
(msr_bits_to_replace & ~msr_bits_to_clear);
uint32_t new_msr_val = (ppc_state.msr & ~(msr_bits_to_replace | msr_bits_to_clear)) |
bits_from_srr1;
if (!is_601) {
ppc_change_endian((new_msr_val & MSR::LE) != 0);
}
ppc_msr_did_change(ppc_state.msr, new_msr_val);
// setting MSR[EE] may enable pending exceptions
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending || thrm_exception_pending)) {
if ((ppc_state.msr & MSR::EE) && (int_pin || dec_exception_pending)) {
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & ~3UL;
if (int_pin) // check for pending external exceptions (higher priority)
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
else if (dec_exception_pending) {
else {
dec_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_DECR, 0);
}
else if (thrm_exception_pending) {
thrm_exception_pending = false;
ppc_exception_handler(Except_Type::EXC_THRM_MGMT_INT, 0);
}
ppc_state.spr[SPR::SRR0] = save_srr0;
return;
}
@@ -1579,25 +1509,27 @@ void dppc_interpreter::ppc_sc(uint32_t opcode) {
}
void dppc_interpreter::ppc_tw(uint32_t opcode) {
ppc_grab_regsab(opcode);
uint32_t reg_a = (opcode >> 11) & 0x1F;
uint32_t reg_b = (opcode >> 16) & 0x1F;
uint32_t ppc_to = (opcode >> 21) & 0x1F;
if (((int32_t(ppc_result_a) < int32_t(ppc_result_b)) && (ppc_to & 0x10)) ||
((int32_t(ppc_result_a) > int32_t(ppc_result_b)) && (ppc_to & 0x08)) ||
((int32_t(ppc_result_a) == int32_t(ppc_result_b)) && (ppc_to & 0x04)) ||
((ppc_result_a < ppc_result_b) && (ppc_to & 0x02)) ||
((ppc_result_a > ppc_result_b) && (ppc_to & 0x01))) {
if (((int32_t(ppc_state.gpr[reg_a]) < int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x10)) ||
((int32_t(ppc_state.gpr[reg_a]) > int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x08)) ||
((int32_t(ppc_state.gpr[reg_a]) == int32_t(ppc_state.gpr[reg_b])) && (ppc_to & 0x04)) ||
((ppc_state.gpr[reg_a] < ppc_state.gpr[reg_b]) && (ppc_to & 0x02)) ||
((ppc_state.gpr[reg_a] > ppc_state.gpr[reg_b]) && (ppc_to & 0x01))) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
}
}
void dppc_interpreter::ppc_twi(uint32_t opcode) {
ppc_grab_regsasimm(opcode);
int32_t simm = int32_t(int16_t(opcode));
uint32_t reg_a = (opcode >> 16) & 0x1F;
uint32_t ppc_to = (opcode >> 21) & 0x1F;
if (((int32_t(ppc_result_a) < simm) && (ppc_to & 0x10)) ||
((int32_t(ppc_result_a) > simm) && (ppc_to & 0x08)) ||
((int32_t(ppc_result_a) == simm) && (ppc_to & 0x04)) ||
(ppc_result_a < uint32_t(simm) && (ppc_to & 0x02)) ||
(ppc_result_a > uint32_t(simm) && (ppc_to & 0x01))) {
if (((int32_t(ppc_state.gpr[reg_a]) < simm) && (ppc_to & 0x10)) ||
((int32_t(ppc_state.gpr[reg_a]) > simm) && (ppc_to & 0x08)) ||
((int32_t(ppc_state.gpr[reg_a]) == simm) && (ppc_to & 0x04)) ||
(ppc_state.gpr[reg_a] < uint32_t(simm) && (ppc_to & 0x02)) ||
(ppc_state.gpr[reg_a] > uint32_t(simm) && (ppc_to & 0x01))) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
}
}
@@ -1653,7 +1585,12 @@ void dppc_interpreter::ppc_dcbz(uint32_t opcode) {
ea &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
mmu_dcbz(opcode, ea);
// the following is not especially efficient but necessary
// to make BlockZero under Mac OS 8.x and later to work
mmu_write_vmem<uint64_t>(opcode, ea + 0, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 8, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 16, 0);
mmu_write_vmem<uint64_t>(opcode, ea + 24, 0);
}
@@ -1696,17 +1633,13 @@ void dppc_interpreter::ppc_stu(uint32_t opcode) {
ppc_grab_regssa(opcode);
if (reg_a != 0) {
uint32_t ea = ppc_result_a + int32_t(int16_t(opcode));
uint32_t ea = int32_t(int16_t(opcode));
ea += ppc_result_a;
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
}
else if (is_601) {
// MPC601 permits RA=0 for POWER compatibility and suppresses the update.
uint32_t ea = int32_t(int16_t(opcode));
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1727,13 +1660,8 @@ void dppc_interpreter::ppc_stux(uint32_t opcode) {
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
ppc_state.gpr[reg_a] = ea;
}
else if (is_601) {
// MPC601 permits RA=0 for POWER compatibility and suppresses the update.
uint32_t ea = ppc_result_b;
mmu_write_vmem<T>(opcode, ea, ppc_result_d);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1800,8 +1728,8 @@ void dppc_interpreter::ppc_lz(uint32_t opcode) {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdasimm(opcode);
uint32_t ea = simm;
ppc_grab_regsda(opcode);
uint32_t ea = int32_t(int16_t(opcode));
ea += reg_a ? ppc_result_a : 0;
uint32_t ppc_result_d = mmu_read_vmem<T>(opcode, ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
@@ -1816,16 +1744,16 @@ void dppc_interpreter::ppc_lzu(uint32_t opcode) {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdasimm(opcode);
uint32_t ea = simm;
if ((reg_a != reg_d) && (reg_a != 0)) {
ppc_grab_regsda(opcode);
uint32_t ea = int32_t(int16_t(opcode));
if ((reg_a != reg_d) && reg_a != 0) {
ea += ppc_result_a;
uint32_t ppc_result_d = mmu_read_vmem<T>(opcode, ea);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_result_a = ea;
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1861,7 +1789,7 @@ void dppc_interpreter::ppc_lzux(uint32_t opcode) {
ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1873,8 +1801,8 @@ void dppc_interpreter::ppc_lha(uint32_t opcode) {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdasimm(opcode);
uint32_t ea = simm;
ppc_grab_regsda(opcode);
uint32_t ea = int32_t(int16_t(opcode));
ea += (reg_a ? ppc_result_a : 0);
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
@@ -1884,16 +1812,16 @@ void dppc_interpreter::ppc_lhau(uint32_t opcode) {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdasimm(opcode);
ppc_grab_regsda(opcode);
if ((reg_a != reg_d) && reg_a != 0) {
uint32_t ea = simm;
uint32_t ea = int32_t(int16_t(opcode));
ea += ppc_result_a;
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
ppc_result_a = ea;
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
} else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1906,11 +1834,11 @@ void dppc_interpreter::ppc_lhaux(uint32_t opcode) {
uint32_t ea = ppc_result_a + ppc_result_b;
int16_t val = mmu_read_vmem<uint16_t>(opcode, ea);
ppc_store_iresult_reg(reg_d, int32_t(val));
ppc_result_a = ea;
uint32_t ppc_result_a = ea;
ppc_store_iresult_reg(reg_a, ppc_result_a);
}
else {
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
@@ -1960,8 +1888,8 @@ void dppc_interpreter::ppc_lmw(uint32_t opcode) {
#ifdef CPU_PROFILING
num_int_loads++;
#endif
ppc_grab_regsdasimm(opcode);
uint32_t ea = simm;
ppc_grab_regsda(opcode);
uint32_t ea = int32_t(int16_t(opcode));
ea += (reg_a ? ppc_result_a : 0);
// How many words to load in memory - using a do-while for this
do {
@@ -2018,7 +1946,7 @@ void dppc_interpreter::ppc_lswx(uint32_t opcode) {
if ((reg_d == 0 && reg_a == 0) || (reg_d == reg_a) || (reg_d == reg_b)) {
// UNTESTED! Does invalid form really cause exception?
// G4 doesn't do exception
ppc_illegalop(opcode);
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
*/
@@ -2123,9 +2051,8 @@ void dppc_interpreter::ppc_eciwx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
if (!(ppc_state.spr[282] && ear_enable)) {
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
return;
}
ppc_grab_regsdab(opcode);
@@ -2144,10 +2071,8 @@ void dppc_interpreter::ppc_ecowx(uint32_t opcode) {
uint32_t ear_enable = 0x80000000;
// error if EAR[E] != 1
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
ppc_state.spr[SPR::DSISR] = 0x00100000;
if (!(ppc_state.spr[282] && ear_enable)) {
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
return;
}
ppc_grab_regssab(opcode);
@@ -2171,13 +2096,7 @@ void dppc_interpreter::ppc_tlbie(uint32_t opcode) {
return;
}
// Ideally we would get the effective address via ppc_state.gpr[(opcode >> 11) & 0x1F]
// and use that to identify entries to flush. But that is CPU-dependent (e.g.
// on the 750 only bits 14-19 are used to find matching entries) and does not
// map cleanly to the layout of our virtual TLB. The PowerPC specification
// allows an implementation to be more lax and flush the entire TLB, so we
// do that instead.
tlb_flush_all_pat();
tlb_flush_entry(ppc_state.gpr[(opcode >> 11) & 0x1F]);
}
void dppc_interpreter::ppc_tlbia(uint32_t opcode) {
-4
View File
@@ -407,10 +407,6 @@
0xFFF00100,0x7D453D2A,stswx,r10,r5,r7
0xFFF00100,0x7C0002E4,tlbia
0xFFF00100,0x7C004A64,tlbie,r9
0xFFF00100,0x7C202FA4,tlbld,r5
0xFFF00100,0x7C6007A4,tlbld,r0
0xFFF00100,0x7C203FE4,tlbli,r7
0xFFF00100,0x7C40FFE4,tlbli,r31
# various simplified (extended) mnemonics
0xFFF00100,0x60000000,nop
1 # Test data for PowerPC disassembler supplied as comma-separated values
407 0xFFF00100,0x7C00003A,maskg,r0,r0,r0 0xFFF00100,0x7C430C32,rrib,r3,r2,r1
408 0xFFF00100,0x7E3EE43A,maskir,r30,r17,r28 0xFFF00100,0x7C430C33,rrib.,r3,r2,r1
409 0xFFF00100,0x58411800,rlmi,r1,r2,r3,0,0 0xFFF00100,0x7C410132,sle,r1,r2,r0
0xFFF00100,0x58411801,rlmi.,r1,r2,r3,0,0
0xFFF00100,0x7C430C32,rrib,r3,r2,r1
0xFFF00100,0x7C430C33,rrib.,r3,r2,r1
0xFFF00100,0x7C410132,sle,r1,r2,r0
410 0xFFF00100,0x7C410133,sle.,r1,r2,r0
411 0xFFF00100,0x7C4101B2,sleq,r1,r2,r0
412 0xFFF00100,0x7C4101B3,sleq.,r1,r2,r0
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+33 -224
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,14 +19,13 @@ 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/memaccess.h>
#include <core/timermanager.h>
#include <cpu/ppc/ppcdisasm.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/ofnvram.h>
#include "memaccess.h"
#include <utils/profiler.h>
#include <array>
@@ -58,8 +57,6 @@ using namespace std;
#define COUT08X COUT0_X(8)
#define COUT04X COUT0_X(4)
extern bool g_auto_grab_mouse;
static uint32_t str2addr(string& addr_str) {
try {
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
@@ -118,8 +115,6 @@ static void show_help() {
cout << " printenv -- print current NVRAM settings." << endl;
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
cout << endl;
cout << " autograbmouse H -- auto grab the mouse if H is not zero." << endl;
cout << endl;
cout << " restart -- restart the machine" << endl;
cout << " quit -- quit the debugger" << endl;
cout << endl;
@@ -430,150 +425,21 @@ static void patch_mem(string& params) {
}
}
static uint32_t disasm(PPCDisasmContext &ctx) {
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
bool needs_swap = false;
if (mem_ctrl_instance != nullptr)
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
#endif
uint8_t* real_addr = mmu_translate_imem(ctx.instr_addr);
ctx.instr_code =
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
needs_swap ? READ_DWORD_LE_A(real_addr) :
#endif
READ_DWORD_BE_A(real_addr);
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << dec;
return ctx.instr_addr;
}
static uint32_t 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++) {
disasm(ctx);
cout << endl;
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
cout << COUT08X << ctx.instr_addr;
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
}
return ctx.instr_addr;
}
static void disasm_in(PPCDisasmContext &ctx, uint32_t address) {
ctx.instr_addr = address;
ctx.simplified = true;
disasm(ctx);
if (ctx.regs_in.size() > 0 || ctx.regs_out.size() > 0) {
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
}
}
static void disasm_out(PPCDisasmContext &ctx) {
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << get_reg(reg_name);
}
cout << " }" << dec;
}
cout << endl;
}
#ifdef LOG_INSTRUCTIONS
void dumpinstructionlog(uint64_t num) {
if (InstructionNumber == 0)
return;
if (num > InstructionNumber) {
num = InstructionNumber;
}
if (num > InstructionLogSize) {
num = InstructionLogSize;
}
printf("Dumping last %llu of %llu instructions:\n", num, InstructionNumber);
uint64_t i, end;
i = (InstructionNumber - num) & (InstructionLogSize - 1);
end = (InstructionNumber) & (InstructionLogSize - 1);
do {
if (!power_on)
break;
InstructionRec * irec = &InstructionLog[i];
PPCDisasmContext ctx;
ctx.kinds = 0;
ctx.level = 0;
ctx.simplified = true;
ctx.instr_code = irec->ins;
ctx.instr_addr = irec->addr;
std::string name = get_name(irec->addr, irec->paddr, nullptr, nullptr, 0);
cout << COUT08X << ctx.instr_addr;
if (irec->paddr != irec->addr) {
cout << "->" << COUT08X << irec->paddr;
}
if (!name.empty()) {
cout << " " << setw(27) << left << setfill(' ') << name;
}
cout << ": " << COUT08X << ctx.instr_code;
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << dec;
if (ctx.instr_str.length() < 28)
cout << setw(28 - (int)ctx.instr_str.length()) << " ";
cout << " ;";
bool got_msr = false;
if (ctx.regs_in.size() > 0) {
cout << " in{" << COUTX;
for (auto & reg_name : ctx.regs_in) {
cout << " " << reg_name << ":";
if (reg_name == "msr") {
cout << irec->msr;
got_msr = true;
}
else
cout << "?";
}
cout << " }" << dec;
}
if (ctx.regs_out.size() > 0) {
cout << " out{" << COUTX;
for (auto & reg_name : ctx.regs_out) {
cout << " " << reg_name << ":" << "?";
}
cout << " }" << dec;
}
if (!got_msr) {
cout << " misc{" << COUTX;
cout << " " << "msr" << ":";
cout << irec->msr;
cout << " }" << dec;
}
cout << endl;
i++;
if (i >= InstructionLogSize)
i = 0;
} while (i != end);
}
#endif
static void print_gprs() {
string reg_name;
int i;
@@ -627,34 +493,18 @@ static void print_mmu_regs()
printf("\nBAT registers:\n");
for (int i = 0; i < 4 + (is_601 ? 0 : 4); i++) {
PPC_BAT_entry *bat_entry = i < 4 ? ibat_array : dbat_array;
bat_entry = &bat_entry[i & 3];
printf(" %sbat%du : %08X %sbat%dl : %08X",
is_601 ? "" : i < 4 ? "i" : "d",
i & 3, ppc_state.spr[528+i*2],
is_601 ? "" : i < 4 ? "i" : "d",
i & 3, ppc_state.spr[529+i*2]
);
if (!is_601 || bat_entry->valid) {
printf(" ; range : %08X..%08X -> %08X..%08X access : %s%s protection : %s%s",
bat_entry->bepi, bat_entry->bepi + ~bat_entry->hi_mask,
bat_entry->phys_hi, bat_entry->phys_hi + ~bat_entry->hi_mask,
bat_entry->access & 2 ? is_601 ? "Ks" : "Vs" : "__",
bat_entry->access & 1 ? is_601 ? "Ku" : "Vp" : "__",
bat_entry->prot & 2 ? "P" : "_",
bat_entry->prot & 1 ? "P" : "_"
);
if (is_601) {
printf(" (%s)", "valid");
}
} else {
printf(" ; range : %8s..%8s -> %8s..%8s access : %s%s protection : %s%s",
"", "", "", "", "__", "__", "_", "_"
);
printf(" (%s)", "invalid");
for (int i = 0; i < 4; i++) {
printf(" ibat%du : %08X ibat%dl : %08X\n",
i, ppc_state.spr[528+i*2],
i, ppc_state.spr[529+i*2]);
}
if (!is_601) {
for (int i = 0; i < 4; i++) {
printf(" dbat%du : %08X dbat%dl : %08X\n",
i, ppc_state.spr[536+i*2],
i, ppc_state.spr[537+i*2]);
}
printf("\n");
}
printf("\n");
@@ -730,21 +580,21 @@ void DppcDebugger::enter_debugger() {
while (1) {
if (power_off_reason == po_shut_down) {
set_power_off_reason(po_shutting_down);
power_off_reason = po_shutting_down;
break;
}
if (power_off_reason == po_restart) {
set_power_off_reason(po_restarting);
power_off_reason = po_restarting;
break;
}
if (power_off_reason == po_quit) {
set_power_off_reason(po_quitting);
power_off_reason = po_quitting;
break;
}
power_on = true;
if (power_off_reason == po_starting_up) {
set_power_off_reason(po_none);
power_off_reason = po_none;
cmd = "go";
}
else if (power_off_reason == po_disassemble_on) {
@@ -755,13 +605,13 @@ void DppcDebugger::enter_debugger() {
ss >> cmd;
}
else if (power_off_reason == po_disassemble_off) {
set_power_off_reason(po_none);
power_off_reason = po_none;
cmd = "go";
}
else
{
if (power_off_reason == po_enter_debugger) {
set_power_off_reason(po_entered_debugger);
power_off_reason = po_entered_debugger;
}
if (!did_message) {
cout << endl;
@@ -798,7 +648,7 @@ void DppcDebugger::enter_debugger() {
}
if (power_off_reason == po_signal_interrupt) {
set_power_off_reason(po_enter_debugger);
power_off_reason = po_enter_debugger;
// ignore command if interrupt happens because the input line is probably incomplete.
last_cmd = "";
continue;
@@ -825,7 +675,8 @@ void DppcDebugger::enter_debugger() {
break;
} else if (cmd == "restart") {
cmd = "";
power_off(po_restart);
power_on = false;
power_off_reason = po_restart;
} else if (cmd == "profile") {
cmd = "";
ss >> sub_cmd;
@@ -902,9 +753,6 @@ void DppcDebugger::enter_debugger() {
delete_prompt();
}
for (; --count >= 0;) {
addr_str = "R24";
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
disasm_68k(1, addr);
exec_single_68k();
}
#endif
@@ -914,10 +762,7 @@ void DppcDebugger::enter_debugger() {
}
for (; --count >= 0;) {
addr = ppc_state.pc;
PPCDisasmContext ctx;
disasm_in(ctx, addr);
ppc_exec_single();
disasm_out(ctx);
}
}
} else if (cmd == "next" || cmd == "ni") {
@@ -1024,28 +869,6 @@ void DppcDebugger::enter_debugger() {
cout << exc.what() << endl;
}
}
#ifdef LOG_INSTRUCTIONS
} else if (cmd == "dumpinstructionlog") {
cmd = "";
uint64_t count;
expr_str = "";
ss >> expr_str;
if (expr_str.length() > 0) {
try {
count = str2num(expr_str);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
count = 0;
}
} else {
count = InstructionNumber;
}
if (count)
dumpinstructionlog(count);
} else if (cmd == "clearinstructionlog") {
cmd = "";
InstructionNumber = 0;
#endif
} else if (cmd == "dump") {
expr_str = "";
ss >> expr_str;
@@ -1167,24 +990,10 @@ void DppcDebugger::enter_debugger() {
cout << exc.what() << endl;
continue;
}
static TimerInfo viaint_timer;
TimerManager::get_instance()->add_oneshot_timer(viaint_timer, 0, [irq_bit](uint64_t, uint64_t){
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
via_obj->assert_int(irq_bit);
});
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
ppc_state.pc -= 4;
via_obj->assert_int(irq_bit);
#endif
} else if (cmd == "autograbmouse") {
cmd = "";
string value;
int num;
ss >> value;
try {
num = str2num(value);
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
continue;
}
g_auto_grab_mouse = num;
} else {
if (!cmd.empty()) {
cout << "Unknown command: " << cmd << endl;
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+13 -10
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -35,9 +35,9 @@ void AdbAppleJack::event_handler(const GamepadEvent& event) {
uint32_t button_bit = 1 << event.button;
if (event.flags & GAMEPAD_EVENT_DOWN)
this->aj_buttons_state |= button_bit;
this->buttons_state |= button_bit;
else if (event.flags & GAMEPAD_EVENT_UP)
this->aj_buttons_state &= ~button_bit;
this->buttons_state &= ~button_bit;
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
this->triggers_changed = true;
@@ -47,7 +47,7 @@ void AdbAppleJack::event_handler(const GamepadEvent& event) {
void AdbAppleJack::reset() {
this->AdbMouse::reset();
this->aj_buttons_state = 0;
this->buttons_state = 0;
this->triggers_changed = false;
this->buttons_changed = false;
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
@@ -58,16 +58,16 @@ bool AdbAppleJack::get_register_0() {
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
// AppleJack triggers always affect the mouse button bits.
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
this->triggers_changed = false;
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[2] = uint8_t(~this->aj_buttons_state >> 8);
out_buf[3] = ~this->aj_buttons_state & 0xFF;
out_buf[2] = ~this->buttons_state >> 8;
out_buf[3] = ~this->buttons_state & 0xFF;
this->host_obj->set_output_count(4);
this->buttons_changed = false;
@@ -77,6 +77,9 @@ bool AdbAppleJack::get_register_0() {
}
void AdbAppleJack::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -52,7 +52,7 @@ public:
void set_register_3() override;
private:
uint32_t aj_buttons_state = 0;
uint32_t buttons_state = 0;
bool triggers_changed = false;
bool buttons_changed = false;
};
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -38,7 +38,6 @@ enum {
ADB_STAT_SRQ_ACTIVE = 1 << 0,
ADB_STAT_TIMEOUT = 1 << 1,
ADB_STAT_AUTOPOLL = 1 << 6,
ADB_STAT_RESPONSE = 1 << 7,
};
class AdbDevice; // forward declaration to prevent compiler errors
+4 -25
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Base class for Apple Desktop Bus devices. */
#include <loguru.hpp>
#include <core/timermanager.h>
#include <devices/common/adb/adbdevice.h>
#include <devices/common/adb/adbbus.h>
@@ -93,8 +92,7 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
this->set_register_2();
break;
case 3:
if (this->host_obj->get_input_count() >= 2) // ensure we got enough data
this->set_register_3();
this->set_register_3();
break;
}
}
@@ -109,25 +107,6 @@ bool AdbDevice::get_register_3() {
return true;
}
void AdbDevice::set_register_3() {
const uint8_t* in_data = this->host_obj->get_input_buf();
uint8_t new_addr = in_data[0] & 0xF;
switch (in_data[1]) {
case 0:
this->my_addr = new_addr;
this->srq_flag = !!(in_data[0] & 0x20);
break;
case 0xFE: // move to a new address if there was no collision
if (!this->got_collision) {
this->my_addr = new_addr;
}
break;
default:
LOG_F(WARNING, "ADB Device: unknown handler ID = 0x%X", in_data[1]);
}
}
uint8_t AdbDevice::gen_random_address() {
return TimerManager::get_instance()->current_time_ns() & 0xF;
}
+5 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -64,11 +64,10 @@ protected:
virtual void set_register_0() {}
virtual void set_register_1() {}
virtual void set_register_2() {}
virtual void set_register_3();
virtual void set_register_3() {}
uint8_t exc_event_flag = 0;
uint8_t srq_flag = 0;
uint8_t led_state = 0;
uint8_t srq_flag = 0;
uint8_t my_addr = 0;
uint8_t dev_handler_id = 0;
bool got_collision = false;
+25 -58
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -34,22 +34,15 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
}
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
this->keys_down.set(event.key, !(event.flags & KEYBOARD_EVENT_UP));
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
if (this->pending_events.size() == 1) {
this->srq_flag = 1;
}
}
void AdbKeyboard::reset() {
this->my_addr = ADB_ADDR_KBD;
this->dev_handler_id = 2; // Extended ADB keyboard
this->exc_event_flag = 1;
this->srq_flag = 0; // don't process keyboard service requests yet
this->led_state = 7; // LEDs off (active low)
this->srq_flag = 1; // enable service requests
this->pending_events.clear();
this->keys_down.reset();
}
bool AdbKeyboard::get_register_0() {
@@ -60,11 +53,6 @@ bool AdbKeyboard::get_register_0() {
out_buf[0] = this->consume_pending_event();
out_buf[1] = this->consume_pending_event();
this->host_obj->set_output_count(2);
if (this->pending_events.empty()) {
this->srq_flag = 0;
}
return true;
}
@@ -80,7 +68,14 @@ uint8_t AdbKeyboard::consume_pending_event() {
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
this->pending_events.pop_front();
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
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);
}
if (this->dev_handler_id != 3) {
switch (event->key) {
@@ -93,61 +88,33 @@ uint8_t AdbKeyboard::consume_pending_event() {
return (key_state << 7) | (event->key & 0x7F);
}
bool AdbKeyboard::get_register_2() {
// Register 2 reflects the current modifier keys, and a zero value means
// that the key is held down.
static const struct {
uint8_t key;
uint8_t bit;
} reg2_keys[] = {
{ AdbKey_Delete, 14 },
{ AdbKey_CapsLock, 13 },
{ AdbKey_Power, 12 },
{ AdbKey_Control, 11 },
{ AdbKey_RightControl, 11 },
{ AdbKey_Shift, 10 },
{ AdbKey_RightShift, 10 },
{ AdbKey_Option, 9 },
{ AdbKey_RightOption, 9 },
{ AdbKey_Command, 8 },
{ AdbKey_KeypadClear, 7 },
{ AdbKey_F14, 6 }, // Scroll Lock
};
uint16_t reg2 = 0xFFF8 | this->led_state;
for (const auto& key : reg2_keys) {
if (this->keys_down[key.key])
reg2 &= ~(1 << key.bit);
}
uint8_t* out_buf = this->host_obj->get_output_buf();
out_buf[0] = reg2 >> 8;
out_buf[1] = reg2 & 0xFF;
this->host_obj->set_output_count(2);
return true;
void AdbKeyboard::set_register_2() {
}
void AdbKeyboard::set_register_2() {
if (this->host_obj->get_input_count() < 2)
void AdbKeyboard::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
this->led_state = in_data[1] & 0x07;
}
void AdbKeyboard::set_register_3() {
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case 0:
this->my_addr = in_data[0] & 0xF;
this->srq_flag = !!(in_data[0] & 0x20);
break;
case 1:
case 2:
this->dev_handler_id = in_data[1];
break;
case 3: // extended keyboard protocol isn't supported yet
break;
case 0xFE: // move to a new address if there was no collision
if (!this->got_collision) {
this->my_addr = in_data[0] & 0xF;
}
break;
default:
this->AdbDevice::set_register_3();
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
}
}
+3 -7
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -27,7 +27,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/adb/adbdevice.h>
#include <devices/common/hwcomponent.h>
#include <bitset>
#include <deque>
#include <memory>
#include <string>
@@ -47,14 +46,12 @@ public:
void event_handler(const KeyboardEvent& event);
bool get_register_0() override;
bool get_register_2() override;
void set_register_2() override;
void set_register_3() override;
private:
std::deque<std::unique_ptr<KeyboardEvent>> pending_events;
std::bitset<128> keys_down;
uint8_t consume_pending_event();
};
@@ -130,7 +127,6 @@ enum AdbKey {
AdbKey_Option = 0x3a,
AdbKey_Command = 0x37,
AdbKey_CapsLock = 0x39,
AdbKey_Power = 0x7f,
AdbKey_RightControl = 0x7d,
AdbKey_RightShift = 0x7b,
+20 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,11 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Apple Desktop Bus Mouse emulation. */
#include <core/memaccess.h>
#include <devices/common/adb/adbmouse.h>
#include <devices/common/adb/adbbus.h>
#include <devices/deviceregistry.h>
#include <core/hostevents.h>
#include <memaccess.h>
#include <loguru.hpp>
AdbMouse::AdbMouse(
@@ -66,7 +66,7 @@ void AdbMouse::reset() {
this->changed = false;
}
bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
bool should_update = this->x_rel || this->y_rel || this->changed || force;
if (should_update) {
@@ -84,7 +84,7 @@ bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
num_bits = this->num_bits;
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
}
buttons = ~buttons;
uint8_t buttons_state = ~this->buttons_state;
for (int axis = 0; axis < 2; axis++) {
int bits = num_bits;
@@ -100,7 +100,7 @@ bool AdbMouse::get_register_0(uint8_t buttons, bool force) {
bits = 7;
while (bits_remaining > 0) {
*p = uint8_t((val & ((1 << bits) - 1)) | (((buttons >> button) & 1) << bits) | (*p << (bits + 1)));
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
val >>= bits;
bits_remaining -= bits;
p = bits == 7 ? &out_buf[2] : p + 1;
@@ -142,16 +142,28 @@ bool AdbMouse::get_register_1() {
}
void AdbMouse::set_register_3() {
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
return;
const uint8_t* in_data = this->host_obj->get_input_buf();
switch (in_data[1]) {
case 0:
this->my_addr = in_data[0] & 0xF;
this->srq_flag = !!(in_data[0] & 0x20);
break;
case 1:
case 2:
case 4: // switch over to extended mouse protocol
this->dev_handler_id = in_data[1];
break;
case 0xFE: // move to a new address if there was no collision
if (!this->got_collision) {
this->my_addr = in_data[0] & 0xF;
}
break;
default:
this->AdbDevice::set_register_3();
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
}
}
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -70,7 +70,7 @@ enum DeviceClass {
void set_register_3() override;
protected:
bool get_register_0(uint8_t buttons, bool force);
bool get_register_0(uint8_t buttons_state, bool force);
uint8_t get_buttons_state() const;
private:
+16 -61
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -77,13 +77,8 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
this->r_status &= ~DRQ;
} else {
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
if (!this->read_data_timer.active) {
TimerManager::get_instance()->add_oneshot_timer(this->read_data_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->update_intrq(1);
}
);
}
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
}
}
return ret_data;
@@ -126,25 +121,17 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
this->xfer_cnt = 0;
this->r_status &= ~DRQ;
//LOG_F(INFO, "%s: write complete", name.c_str());
if (this->write_done_timer.active)
LOG_F(ERROR, "%s: write_done_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(write_done_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->r_status &= ~BSY;
this->update_intrq(1);
}
);
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->r_status &= ~BSY;
this->update_intrq(1);
});
} else {
this->cur_data_ptr = this->data_ptr;
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
if (this->write_more_timer.active)
LOG_F(ERROR, "%s: write_more_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(this->write_more_timer,
USECS_TO_NSECS(100), [this](uint64_t, uint64_t) {
this->signal_data_ready();
}
);
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
this->signal_data_ready();
});
}
}
}
@@ -211,24 +198,17 @@ int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
int xfer_size = std::min(this->xfer_cnt, len);
if (this->xfer_cnt != len) {
LOG_F(9, "%s: DMA pull size differs from descriptor, remaining=%d requested=%d",
this->name.c_str(), this->xfer_cnt, len);
}
if (this->xfer_cnt != len)
LOG_F(WARNING, "%s: xfer_cnt != len", this->name.c_str());
//for (int i = 0; i < xfer_size >> 1; i++)
// this->data_ptr[i] = BYTESWAP_16(this->data_ptr[i]);
std::memcpy(buf, this->data_ptr, xfer_size);
this->data_ptr = (uint16_t *)((uint8_t *)this->data_ptr + xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
this->is_dma_xfer = false;
this->data_ptr = nullptr;
if (this->dma_pull_timer.active)
LOG_F(ERROR, "%s: dma_pull_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(dma_pull_timer, 500, [this](uint64_t, uint64_t) {
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
@@ -241,32 +221,7 @@ int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
}
int AtaBaseDevice::push_data(uint8_t *buf, int len) {
if (!this->xfer_cnt || !this->is_dma_xfer)
return 0;
int xfer_size = std::min(this->xfer_cnt, len);
std::memcpy(this->cur_data_ptr, buf, xfer_size);
this->cur_data_ptr = (uint16_t *)((uint8_t *)this->cur_data_ptr + xfer_size);
this->xfer_cnt -= xfer_size;
if (!this->xfer_cnt) {
this->post_xfer_action();
this->is_dma_xfer = false;
this->data_ptr = nullptr;
this->cur_data_ptr = nullptr;
if (this->dma_push_timer.active)
LOG_F(ERROR, "%s: dma_push_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(dma_push_timer, 500, [this](uint64_t, uint64_t) {
this->r_status &= ~(BSY | DRQ);
this->update_intrq(1);
});
} else {
this->r_status &= ~BSY;
this->r_status |= DRQ;
}
return xfer_size;
return 0;
}
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
+4 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,10 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATA_BASE_DEVICE_H
#define ATA_BASE_DEVICE_H
#include <core/endianswap.h>
#include <core/timermanager.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/hwcomponent.h>
#include "endianswap.h"
#include <cinttypes>
#include <string>
@@ -109,12 +108,6 @@ protected:
bool is_dma_xfer = false;
std::function<void()> post_xfer_action = nullptr;
TimerInfo read_data_timer;
TimerInfo write_done_timer;
TimerInfo write_more_timer;
TimerInfo dma_pull_timer;
TimerInfo dma_push_timer;
};
#endif // ATA_BASE_DEVICE_H
+4 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -132,7 +132,7 @@ enum ATA_Cmd : uint8_t {
READ_VERIFY = 0x40,
ATAPI_COMMAND_GET_CONFIG = 0x46,
FORMAT_TRACKS = 0x50,
SEEK = 0x70,
IDE_SEEK = 0x70,
DIAGNOSTICS = 0x90,
INIT_DEV_PARAM = 0x91,
ATAPI_PACKET = 0xA0,
@@ -147,8 +147,6 @@ enum ATA_Cmd : uint8_t {
WRITE_DMA = 0xCA,
WRITE_DMA_NR = 0xCB,
STANDBY_IMMEDIATE = 0xE0,
IDLE_IMMEDIATE = 0xE1,
CHECK_POWER_MODE = 0xE5,
SLEEP = 0xE6,
FLUSH_CACHE = 0xE7, // ATA-5
WRITE_BUFFER_DMA = 0xE9,
+18 -63
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,12 +21,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file ATA hard disk emulation. */
#include <core/memaccess.h>
#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 <bitset>
#include <cstring>
@@ -99,15 +99,11 @@ int AtaHardDisk::perform_command() {
break;
case READ_MULTIPLE:
case READ_SECTOR:
case READ_SECTOR_NR:
case READ_DMA:
case READ_DMA_NR: {
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;
bool is_dma_cmd = this->r_command == READ_DMA ||
this->r_command == READ_DMA_NR;
uint32_t ints_size = is_dma_cmd ? xfer_size : ATA_HD_SEC_SIZE;
uint32_t ints_size = ATA_HD_SEC_SIZE;
if (this->r_command == READ_MULTIPLE) {
if (!this->sectors_per_int) {
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
@@ -119,34 +115,20 @@ int AtaHardDisk::perform_command() {
}
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, ints_size);
if (is_dma_cmd) {
this->is_dma_xfer = true;
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY | DSC;
// TODO: Model ATA DMAREQ as a latched signal instead of relying
// on this delay to avoid racing DBDMA command startup.
this->host_obj->assert_dmareq(500);
} else {
// PIO commands generate IRQ for each sector or multiple block.
this->signal_data_ready();
}
this->signal_data_ready();
}
break;
case WRITE_MULTIPLE:
case WRITE_SECTOR:
case WRITE_SECTOR_NR:
case WRITE_DMA:
case WRITE_DMA_NR: {
case WRITE_SECTOR_NR: {
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
bool is_dma_cmd = this->r_command == WRITE_DMA ||
this->r_command == WRITE_DMA_NR;
uint32_t ints_size = is_dma_cmd ? xfer_size : ATA_HD_SEC_SIZE;
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
this->data_ptr = (uint16_t *)this->buffer;
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
this->data_ptr = (uint16_t *)this->buffer;
this->cur_data_ptr = this->data_ptr;
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
uint32_t ints_size = ATA_HD_SEC_SIZE;
if (this->r_command == WRITE_MULTIPLE) {
if (!this->sectors_per_int) {
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
@@ -162,29 +144,10 @@ int AtaHardDisk::perform_command() {
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
this->cur_fpos += write_len;
};
if (is_dma_cmd) {
this->is_dma_xfer = true;
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY | DSC;
// TODO: Model ATA DMAREQ as a latched signal instead of relying
// on this delay to avoid racing DBDMA command startup.
this->host_obj->assert_dmareq(500);
} else {
this->r_status |= DRQ;
this->r_status &= ~BSY;
}
this->r_status |= DRQ;
this->r_status &= ~BSY;
}
break;
case CHECK_POWER_MODE:
this->r_sect_count = 0xFF; // always active or idle
this->r_status |= DRDY;
this->r_status &= ~BSY;
break;
case SEEK:
this->r_status |= DSC;
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case DIAGNOSTICS:
this->r_error = 1; // device 0 passed, device 1 passed or not present
this->device_set_signature();
@@ -268,12 +231,6 @@ int AtaHardDisk::perform_command() {
this->r_status &= ~BSY;
this->update_intrq(1);
break;
case IDLE_IMMEDIATE:
LOG_F(INFO, "%s: immediate idle requested", this->name.c_str());
this->r_status &= ~(BSY | DRQ | ERR);
this->r_status |= DRDY;
this->update_intrq(1);
break;
default:
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
this->r_status &= ~BSY;
@@ -289,7 +246,7 @@ void AtaHardDisk::prepare_identify_info() {
std::memset(this->data_buf, 0, sizeof(this->data_buf));
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
WRITE_WORD_LE_A(&buf_ptr[49], 0x0300); // report DMA and LBA support
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
// Maximum number of logical sectors per data block that the device supports
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
@@ -307,8 +264,8 @@ void AtaHardDisk::prepare_identify_info() {
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
// report validity for the MWDMA fields
WRITE_WORD_LE_A(&buf_ptr[53], 0x0002);
// report validity for the advanced PIO and MWDMA fields
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
@@ -316,8 +273,6 @@ void AtaHardDisk::prepare_identify_info() {
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
WRITE_WORD_LE_A(&buf_ptr[65], 120); // minimum MWDMA cycle time (ns)
WRITE_WORD_LE_A(&buf_ptr[66], 120); // recommended MWDMA cycle time (ns)
}
uint64_t AtaHardDisk::get_lba() {
+3 -6
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef ATA_HARD_DISK_H
#define ATA_HARD_DISK_H
#include <core/timermanager.h>
#include <devices/common/ata/atabasedevice.h>
#include <utils/imgfile.h>
@@ -75,8 +74,6 @@ private:
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
char * buffer = new char[1 <<17];
TimerInfo signal_ready_timer;
};
#endif // ATA_HARD_DISK_H
+20 -69
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,10 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Basic ATAPI interface emulation. */
#include <core/endianswap.h>
#include <devices/common/ata/atabasedevice.h>
#include <devices/common/ata/atapibasedevice.h>
#include <devices/common/ata/atadefs.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <cinttypes>
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace ata_interface;
AtapiBaseDevice::AtapiBaseDevice(const std::string name)
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI), ScsiPhysInterface(PHY_ID_ATAPI) {
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI) {
}
void AtapiBaseDevice::device_set_signature() {
@@ -62,9 +62,7 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
if (this->data_available()) {
this->r_status &= ~DRQ;
this->r_status |= BSY;
// Is this going to work here?
// The interrupt happens before returning ret_data.
this->update_intrq(1);
this->update_intrq(1); // Is this going to work here? The interrupt happens before returning ret_data.
}
else if (this->status_expected) {
this->present_status();
@@ -90,14 +88,13 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
case ATA_Reg::STATUS:
this->update_intrq(0);
case ATA_Reg::ALT_STATUS:
if ((this->r_status & BSY) && this->data_available()) {
if (this->r_status & BSY && this->data_available()) {
this->r_byte_count = this->request_data();
this->data_in_phase();
this->data_out_phase();
}
return this->r_status;
default:
LOG_F(WARNING, "%s: read from unknown register 0x%X", this->name.c_str(),
reg_addr);
LOG_F(WARNING, "Attempted to read unknown register: %x", reg_addr);
return 0;
}
}
@@ -105,22 +102,13 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) {
case ATA_Reg::DATA:
if (!(this->r_int_reason & ATAPI_Int_Reason::IO)) { // host --> device?
if (this->r_int_reason & ATAPI_Int_Reason::CoD) { // command phase?
if (this->xfer_cnt > 0) {
*this->data_ptr++ = BYTESWAP_16(value);
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0) {
this->r_status &= ~DRQ;
this->perform_packet_command();
}
}
} else { // data-out phase
if (this->xfer_cnt > 0) {
*this->data_ptr++ = BYTESWAP_16(value);
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0)
this->r_status &= ~DRQ;
if (has_data()) {
*this->data_ptr++ = BYTESWAP_16(value);
this->xfer_cnt -= 2;
if (this->xfer_cnt <= 0) {
this->r_status &= ~DRQ;
if (this->r_int_reason & CoD) {
this->perform_packet_command();
}
}
}
@@ -150,7 +138,7 @@ void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
this->device_control(value);
break;
default:
LOG_F(WARNING, "%s: write to unknown register 0x%X", this->name.c_str(), reg_addr);
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
}
}
@@ -180,7 +168,7 @@ int AtapiBaseDevice::perform_command() {
this->data_ptr = (uint16_t *)this->data_buf;
this->xfer_cnt = 512;
this->status_expected = false;
this->data_in_phase();
this->data_out_phase();
break;
case SET_FEATURES:
switch (this->r_features) {
@@ -201,14 +189,12 @@ int AtapiBaseDevice::perform_command() {
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), this->r_command);
this->r_error |= ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
this->r_status &= ~BSY;
this->update_intrq(1);
}
return 0;
}
void AtapiBaseDevice::data_in_phase() {
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
void AtapiBaseDevice::data_out_phase() {
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
this->signal_data_ready();
}
@@ -220,38 +206,3 @@ void AtapiBaseDevice::present_status() {
this->r_status &= ~BSY;
this->update_intrq(1);
}
void AtapiBaseDevice::switch_phase(const int new_phase) {
switch(new_phase) {
case ScsiPhase::DATA_IN:
this->data_in_phase();
break;
case ScsiPhase::DATA_OUT:
this->r_int_reason &= ATAPI_Int_Reason::IO; // host->device
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
this->signal_data_ready();
break;
case ScsiPhase::STATUS:
this->present_status();
break;
default:
LOG_F(WARNING, "ATAPI PHY: unsupported phase %d switch_phase", new_phase);
}
}
void AtapiBaseDevice::set_status(uint8_t status_code, uint8_t sense_key) {
switch(status_code) {
case ScsiStatus::GOOD:
this->status_expected = true;
this->r_error = 0;
this->r_status &= ~ATA_Status::ERR;
break;
case ScsiStatus::CHECK_CONDITION:
this->status_expected = true;
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
break;
default:
LOG_F(WARNING, "ATAPI PHY: unsupported status %d set_status", status_code);
}
}
+5 -25
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -25,13 +25,11 @@ 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/scsi/scsi.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <cinttypes>
#include <string>
class AtapiBaseDevice : public AtaBaseDevice, public ScsiPhysInterface
class AtapiBaseDevice : public AtaBaseDevice
{
public:
AtapiBaseDevice(const std::string name);
@@ -42,24 +40,6 @@ public:
uint16_t read(const uint8_t reg_addr) override;
void write(const uint8_t reg_addr, const uint16_t value) override;
// ScsiPhysInterface methods
void set_lock_state(bool is_locked) override {};
void set_xfer_len(uint64_t len) override {
this->xfer_cnt = len;
this->r_byte_count = len;
}
void set_buffer(uint8_t *buf_ptr) override {
this->data_ptr = (uint16_t*)buf_ptr;
}
void set_status(uint8_t status_code, uint8_t sense_key) override;
void switch_phase(const int new_phase) override;
void set_read_more_data_cb(more_data_cb_t cb) override {};
void set_write_more_data_cb(more_data_cb_t cb) override {};
void set_post_xfer_action(action_callback cb) override {};
// methods to be implemented in the particular device
int perform_command() override;
virtual void perform_packet_command() = 0;
@@ -68,7 +48,7 @@ public:
virtual bool data_available() = 0;
// methods with default implementation
virtual void data_in_phase();
virtual void data_out_phase();
virtual void present_status();
protected:
+185 -50
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,13 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file ATAPI CDROM implementation. */
#include <core/memaccess.h>
#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>
#include <machines/machineproperties.h>
#include <memaccess.h>
#include <cstring>
#include <string>
@@ -35,23 +36,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace ata_interface;
static char cdrom_vendor_id[] = "DINGUS ";
static char cdrom_product_id[] = "DINGUS CD-ROM ";
static char cdrom_revision_id[] = "1.0 ";
AtapiCdrom::AtapiCdrom(std::string name) : AtapiBaseDevice(name) {
this->set_phys_dev(this);
this->set_cdb_ptr(this->cmd_pkt);
this->set_buf_ptr(this->data_buf);
// populate device info for INQUIRY
this->dev_type = ScsiDevType::CD_ROM;
this->is_removable = true; // removable medium
this->std_versions = 2; // ANSI version: SCSI-2
this->resp_fmt = 0x21; // ATAPI Version + response data format
this->set_vendor_id(cdrom_vendor_id);
this->set_product_id(cdrom_product_id);
this->set_revision_id(cdrom_revision_id);
AtapiCdrom::AtapiCdrom(std::string name) : CdromDrive(), AtapiBaseDevice(name) {
this->set_error_callback(
[this](uint8_t sense_key, uint8_t asc) {
this->status_error(sense_key, asc);
}
);
}
int AtapiCdrom::device_postinit() {
@@ -67,17 +57,11 @@ int AtapiCdrom::device_postinit() {
parse_device_path(cdr_config, bus_id, dev_num);
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
if (!bus_obj) {
LOG_F(ERROR, "%s: cdr_config device path %s does not specify a known IDE bus",
this->name.c_str(), cdr_config.c_str());
return -1;
}
bus_obj->register_device(dev_num, this);
std::string cdr_image_path = GET_STR_PROP("cdr_img");
if (!cdr_image_path.empty()) {
if (!this->insert_image(cdr_image_path))
return -1;
this->insert_image(cdr_image_path);
}
return 0;
@@ -93,24 +77,168 @@ void AtapiCdrom::perform_packet_command() {
LOG_F(WARNING, "%s: doing_sector_areas reset", this->name.c_str());
}
// Assume successful command execution
if (this->cmd_pkt[0] == ScsiCommand::REQ_SENSE) {
// For REQ_SENSE we only set the status, status_good() also resets
// sense_key, which we'll need to return.
this->set_status(ScsiStatus::GOOD, 0);
} else {
this->status_good();
}
switch (this->cmd_pkt[0]) {
case ScsiCommand::READ_CD:
{
// READ_CD currently bypasses the shared CD-ROM command dispatcher.
if (!this->ready_for_command()) {
case ScsiCommand::TEST_UNIT_READY:
if (this->medium_present())
this->status_good();
else
this->status_error(ScsiSense::NOT_READY, ScsiError::MEDIUM_NOT_PRESENT);
this->present_status();
break;
case ScsiCommand::REQ_SENSE:
xfer_len = this->request_sense(this->data_buf, this->sense_key, this->asc, this->ascq);
if (!xfer_len) {
this->present_status();
} else {
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::INQUIRY:
this->xfer_cnt = this->inquiry(this->cmd_pkt, this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
break;
case ScsiCommand::START_STOP_UNIT:
if ((this->cmd_pkt[4] & 3) == 2) {
LOG_F(WARNING, "CD-ROM eject requested");
}
this->status_good();
this->present_status();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
LOG_F(INFO, "%s: medium removal %s", this->name.c_str(),
this->cmd_pkt[4] & 1 ? "prevented" : "allowed");
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CAPACITY_10:
this->xfer_cnt = this->report_capacity(this->data_buf);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
break;
case ScsiCommand::READ_TOC:
this->status_good();
xfer_len = this->read_toc(this->cmd_pkt, this->data_buf);
if (!xfer_len) {
this->present_status();
} else {
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
this->data_ptr = (uint16_t*)this->data_buf;
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_6:
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_10:
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::READ_6:
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
xfer_len = this->cmd_pkt[4];
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_out_phase();
break;
case ScsiCommand::READ_10:
if (this->xfer_cnt > 0) {
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
this->present_status();
break;
}
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
#if 0
TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
#else
this->data_out_phase();
#endif
break;
case ScsiCommand::READ_12:
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
// if transfer length is zero then just complete command
if (xfer_len == 0) {
this->status_good();
this->present_status();
break;
}
if (this->r_features & ATAPI_Features::DMA) {
LOG_F(WARNING, "ATAPI DMA transfer requsted");
}
this->set_fpos(lba);
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_out_phase();
break;
case ScsiCommand::SET_CD_SPEED:
LOG_F(INFO, "%s: speed set to %d kBps", this->name.c_str(),
READ_WORD_BE_U(&this->cmd_pkt[2]));
this->status_good();
this->present_status();
break;
case ScsiCommand::READ_CD:
{
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
if (this->cmd_pkt[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
@@ -185,7 +313,7 @@ void AtapiCdrom::perform_packet_command() {
this->data_ptr = (uint16_t*)this->data_cache.get();
this->status_good();
this->data_in_phase();
this->data_out_phase();
break;
}
case ScsiCommand::GET_CONFIG: {
@@ -196,12 +324,15 @@ void AtapiCdrom::perform_packet_command() {
this->xfer_cnt = std::min((int)this->r_byte_count, this->xfer_cnt);
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_in_phase();
this->data_out_phase();
}
break;
}
default:
ScsiCdromCmds::process_command();
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
this->cmd_pkt[0]);
this->status_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CMD);
this->present_status();
}
}
@@ -264,11 +395,11 @@ uint16_t AtapiCdrom::get_data() {
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
AddrMsf msf = lba_to_msf(this->current_block + 150);
uint8_t header[4]{
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
(uint8_t)msf.min,
(uint8_t)msf.sec,
(uint8_t)msf.frm,
0x01 // Mode 1
};
};
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
}
}
@@ -325,14 +456,18 @@ uint16_t AtapiCdrom::get_data() {
}
void AtapiCdrom::status_good() {
this->status_expected = true;
this->r_error = 0;
this->sense_key = 0;
this->set_status(ScsiStatus::GOOD, this->sense_key);
this->r_status &= ~ATA_Status::ERR;
}
void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
this->status_expected = true;
this->sense_key = sense_key;
this->asc = asc;
this->set_status(ScsiStatus::CHECK_CONDITION, this->sense_key);
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
this->r_status |= ATA_Status::ERR;
}
static const PropMap AtapiCdrom_Properties = {
+9 -13
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -25,11 +25,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define ATAPI_CDROM_H
#include <devices/common/ata/atapibasedevice.h>
#include <devices/common/scsi/scsicdromcmds.h>
#include <devices/storage/cdromdrive.h>
#include <string>
class AtapiCdrom : public AtapiBaseDevice, public ScsiCdromCmds {
class AtapiCdrom : public CdromDrive, public AtapiBaseDevice {
public:
AtapiCdrom(std::string name);
~AtapiCdrom() = default;
@@ -38,17 +38,10 @@ public:
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
}
bool is_device_ready() override { return this->medium_present(); }
uint8_t not_ready_reason() override { return ScsiError::MEDIUM_NOT_PRESENT; }
int device_postinit() override;
void perform_packet_command() override;
void set_lock_state(bool is_locked) override {
this->drive_locked = is_locked ? 1 : 0;
}
int get_config(uint8_t* pkt, uint8_t* buf) override;
int request_data() override;
@@ -61,8 +54,11 @@ public:
void status_error(uint8_t sense_key, uint8_t asc);
uint16_t get_data();
private:
uint8_t sense_key = 0;
uint8_t asc = 0;
uint8_t ascq = 0;
bool doing_sector_areas = false;
uint8_t sector_areas;
uint32_t current_block;
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+6 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -82,18 +82,16 @@ void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int siz
}
}
int IdeChannel::xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) {
int IdeChannel::xfer_from(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->pull_data(buf, len);
}
int IdeChannel::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
int IdeChannel::xfer_to(uint8_t *buf, int len) {
return this->devices[this->cur_dev]->push_data(buf, len);
}
void IdeChannel::assert_dmareq(uint64_t delay) {
if (this->dmareq_timer.active)
LOG_F(WARNING, "%s: dmareq_timer is already active", this->get_name().c_str());
TimerManager::get_instance()->add_oneshot_timer(this->dmareq_timer, delay, [this](uint64_t, uint64_t) {
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
this->channel_obj->xfer_retry();
});
+5 -8
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef IDE_CHANNEL_H
#define IDE_CHANNEL_H
#include <core/timermanager.h>
#include <devices/common/ata/atadefs.h>
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
@@ -46,8 +45,8 @@ public:
virtual uint32_t read(const uint8_t reg_addr, const int size);
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size);
int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) override;
int xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) override;
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
void assert_pdiag() {
this->devices[0]->pdiag_callback();
@@ -75,8 +74,6 @@ private:
AtaInterface* devices[2];
std::unique_ptr<AtaInterface> device_stub;
TimerInfo dmareq_timer;
};
/** This class models an IDE channel specific to MacIO ASICs. */
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+209 -191
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,15 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Descriptor-based direct memory access emulation. */
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <core/timermanager.h>
#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 <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <memaccess.h>
#include <cinttypes>
#include <cstring>
@@ -40,6 +39,12 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
this->stop_cb = stop_cb;
}
void DMAChannel::set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb) {
this->in_cb = in_cb;
this->out_cb = out_cb;
this->flush_cb = flush_cb;
}
/* Load DMACmd from physical memory. */
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
@@ -55,21 +60,20 @@ DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writabl
return cmd_host;
}
void DMAChannel::interpret_cmd() {
uint8_t DMAChannel::interpret_cmd() {
DMACmd cmd_struct;
MapDmaResult res;
if (this->cmd_in_progress) {
// if there is data remaining to transfer then the command is not finished
// return current command if there is data to transfer
if (this->queue_len)
return;
return this->cur_cmd;
// if there is no data remaining to transfer then the command is finished
// and the program should procede to the next command
this->finish_cmd();
}
this->cur_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &this->cur_is_writable);
bool cmd_is_writable;
DMACmd *cmd_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &cmd_is_writable);
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
@@ -84,40 +88,43 @@ void DMAChannel::interpret_cmd() {
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
break;
}
if (cmd_struct.req_count) {
this->queue_len = cmd_struct.req_count;
if (this->queue_len) {
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
this->queue_data = res.host_va;
this->res_count = cmd_struct.req_count;
this->queue_len = cmd_struct.req_count; // don't set queue_len until all the other fields are set
this->res_count = 0;
this->cmd_in_progress = true;
switch (this->cur_cmd) {
case DBDMA_Cmd::OUTPUT_MORE:
case DBDMA_Cmd::OUTPUT_LAST:
this->xfer_to_device();
if (this->out_cb)
this->out_cb();
break;
case DBDMA_Cmd::INPUT_MORE:
case DBDMA_Cmd::INPUT_LAST:
this->xfer_from_device();
if (this->in_cb)
this->in_cb();
break;
}
} else {
this->queue_len = 0;
this->res_count = 0;
} else
this->finish_cmd();
}
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(true);
this->xfer_quad(&cmd_struct, nullptr);
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);
}
this->xfer_quad(false);
if (!cmd_is_writable)
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
this->xfer_quad(&cmd_struct, cmd_host);
break;
case DBDMA_Cmd::NOP:
this->finish_cmd();
@@ -133,45 +140,30 @@ void DMAChannel::interpret_cmd() {
this->ch_stat |= CH_STAT_DEAD;
this->ch_stat &= ~CH_STAT_ACTIVE;
}
}
void DMAChannel::interpret_until_blocked() {
// Execute ready commands until a transfer is queued or the channel becomes idle/dead.
while (this->is_active()) {
this->interpret_cmd();
if (this->cmd_in_progress)
break;
}
}
void DMAChannel::update_cmd() {
if (this->cur_is_writable) {
if (this->cur_cmd < DBDMA_Cmd::STOP)
WRITE_WORD_LE_A(&this->cur_host->xfer_stat, this->ch_stat | CH_STAT_ACTIVE);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP)
WRITE_WORD_LE_A(&this->cur_host->res_count, this->res_count);
}
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
return this->cur_cmd;
}
void DMAChannel::finish_cmd() {
bool branch_taken = false;
// save interrupt bits from the completing command before cmd_ptr may change
uint8_t saved_cmd_bits = this->cur_host->cmd_bits;
// obtain real pointer to the descriptor of the command to be finished
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
uint8_t *cmd_desc = res.host_va;
// get command code
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
if (this->cur_cmd < DBDMA_Cmd::STOP) {
// react to cmd.w (wait) bits
if (saved_cmd_bits & 3) {
if (cmd_desc[2] & 3) {
bool cond = true;
if ((saved_cmd_bits & 3) != 3) {
if ((cmd_desc[2] & 3) != 3) {
uint16_t wt_mask = this->wait_select >> 16;
cond = (this->ch_stat & wt_mask) == (this->wait_select & wt_mask);
if ((saved_cmd_bits & 3) == 2) {
if ((cmd_desc[2] & 3) == 2) {
cond = !cond; // wait if cond = false
}
}
@@ -183,44 +175,50 @@ void DMAChannel::finish_cmd() {
this->ch_stat &= ~CH_STAT_BT;
// react to cmd.b (branch) bits
if (saved_cmd_bits & 0xC) {
if (cmd_desc[2] & 0xC) {
bool cond = true;
if ((saved_cmd_bits & 0xC) != 0xC) {
if ((cmd_desc[2] & 0xC) != 0xC) {
uint16_t br_mask = this->branch_select >> 16;
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
if ((saved_cmd_bits & 0xC) == 0x8) {
if ((cmd_desc[2] & 0xC) == 0x8) {
cond = !cond; // branch if cond = false
}
}
if (cond) {
this->cmd_ptr = READ_DWORD_LE_A(&this->cur_host->cmd_arg);
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
branch_taken = true;
this->ch_stat |= CH_STAT_BT;
}
}
if (res.is_writable)
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
}
this->update_cmd();
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
this->res_count = 0;
}
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
this->cmd_ptr += 16;
// use the interrupt bits saved before cmd_ptr was advanced or branched
if (this->cur_cmd < DBDMA_Cmd::STOP) {
this->update_irq(saved_cmd_bits);
this->update_irq();
}
this->cmd_in_progress = false;
}
void DMAChannel::xfer_quad(bool is_store) {
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
MapDmaResult res;
uint32_t addr = READ_DWORD_LE_A(&this->cur_host->address);
uint16_t req_count = READ_WORD_LE_A (&this->cur_host->req_count);
uint32_t cmd_arg = READ_DWORD_LE_A(&this->cur_host->cmd_arg);
uint32_t addr;
// parse and fix reqCount
uint32_t xfer_size = req_count & 7;
uint32_t xfer_size = cmd_desc->req_count & 7;
if (xfer_size & 4) {
xfer_size = 4;
} else if (xfer_size & 2) {
@@ -228,8 +226,9 @@ void DMAChannel::xfer_quad(bool is_store) {
} else {
xfer_size = 1;
}
this->res_count = req_count; // this is the value that gets written to cmd.resCount
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);
@@ -238,15 +237,14 @@ void DMAChannel::xfer_quad(bool is_store) {
res = mmu_map_dma_mem(addr, xfer_size, true);
// prepare data pointers and perform data transfer
if (is_store) {
if (!cmd_host) {
if (res.type & RT_MMIO) {
res.dev_obj->write(res.dev_base, addr - res.dev_base,
BYTESWAP_SIZED(cmd_arg, xfer_size), xfer_size);
res.dev_obj->write(res.dev_base, addr - res.dev_base, cmd_desc->cmd_arg, xfer_size);
} else if (res.is_writable) {
switch (xfer_size) {
case 1: *res.host_va = cmd_arg; break;
case 2: WRITE_WORD_LE_A(res.host_va, cmd_arg); break;
case 4: WRITE_DWORD_LE_A(res.host_va, cmd_arg); break;
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);
@@ -263,39 +261,38 @@ void DMAChannel::xfer_quad(bool is_store) {
default: value = 0; break;
}
}
if (!this->cur_is_writable)
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
else
WRITE_DWORD_LE_A(&this->cur_host->cmd_arg, value);
WRITE_DWORD_LE_A(&cmd_host->cmd_arg, value);
}
if (this->cur_host->cmd_bits & 0xC)
if (cmd_desc->cmd_bits & 0xC)
ABORT_F("%s: cmd_bits.b should be zero for LOAD/STORE_QUAD!",
this->get_name().c_str());
this->finish_cmd();
}
void DMAChannel::update_irq(uint8_t cmd_bits) {
void DMAChannel::update_irq() {
// obtain real pointer to the descriptor of the completed command
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
uint8_t *cmd_desc = res.host_va;
// STOP doesn't generate interrupts
if (this->cur_cmd < DBDMA_Cmd::STOP) {
// react to cmd.i (interrupt) bits
if (cmd_bits & 0x30) {
if (cmd_desc[2] & 0x30) {
bool cond = true;
if ((cmd_bits & 0x30) != 0x30) {
if ((cmd_desc[2] & 0x30) != 0x30) {
uint16_t int_mask = this->int_select >> 16;
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
if ((cmd_bits & 0x30) == 0x20) {
if ((cmd_desc[2] & 0x30) == 0x20) {
cond = !cond; // generate interrupt if cond = false
}
}
if (cond) {
if (this->int_ctrl) {
if (!this->interrupt_timer.active) {
TimerManager::get_instance()->add_immediate_timer(this->interrupt_timer, [this](uint64_t, uint64_t) {
this->int_ctrl->ack_dma_int(this->irq_id, 1);
});
}
if (int_ctrl) {
TimerManager::get_instance()->add_immediate_timer([this] {
this->int_ctrl->ack_dma_int(this->irq_id, 1);
});
} else
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
}
@@ -337,88 +334,69 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
}
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
uint16_t mask, data;
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());
}
value = BYTESWAP_32(value);
value = BYTESWAP_32(value);
old_stat = this->ch_stat;
switch (offset) {
case DMAReg::CH_CTRL:
mask = value >> 16;
data = value & 0xFFFF;
mask = value >> 16;
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~(mask & 0xC0FF));
LOG_F(9, "%s: New ChannelStatus value = 0x%X", this->get_name().c_str(), new_stat);
// update general purpose channel status & control bits s0...s7
// if requested (needed for interrupt generation)
if (mask & 0xFF)
this->ch_stat = (this->ch_stat & ~(mask & 0xFF)) | (data & mask & 0xFF);
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
if ((new_stat & 0xFF) != (old_stat & 0xFF)) {
this->ch_stat |= new_stat & 0xFF;
}
// flush bit can be set at the same time the run bit is cleared.
// That means we need to update memory before channel operation
// is aborted to prevent data loss.
if (mask & CH_STAT_FLUSH) {
// FLUSH=1 should update memory for INPUT_MORE & INPUT_LAST commands
// when the channel is active and not dead.
// Setting FLUSH to 0 has no effect.
if (data & CH_STAT_FLUSH) {
if (
(this->cur_cmd == DBDMA_Cmd::INPUT_MORE || this->cur_cmd == DBDMA_Cmd::INPUT_LAST) &&
this->is_active()
) {
this->ch_stat |= CH_STAT_FLUSH;
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_FLUSH);
this->update_cmd();
}
if (new_stat & CH_STAT_FLUSH) {
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
!(this->ch_stat & CH_STAT_DEAD)) {
this->flush_cb();
} else {
// NOTE: because this implementation doesn't currently support
// partial memory updates no special action is taken here
new_stat &= ~CH_STAT_FLUSH;
}
this->ch_stat &= ~CH_STAT_FLUSH;
this->ch_stat = new_stat;
}
if (mask & CH_STAT_RUN) {
if (data & CH_STAT_RUN) {
// some drivers clear the PAUSE bit while setting the RUN bit.
// Clear the PAUSE bit without resuming the channel operation
// in this case.
if (mask & CH_STAT_PAUSE) {
if (data & CH_STAT_PAUSE)
ABORT_F("%s: Attempt to set both run and pause bits at the same time",
this->get_name().c_str());
else
this->ch_stat &= ~CH_STAT_PAUSE;
}
if (!(this->ch_stat & CH_STAT_ACTIVE)) {
this->ch_stat |= CH_STAT_ACTIVE | CH_STAT_RUN;
this->start();
}
if ((new_stat & CH_STAT_RUN) != (old_stat & CH_STAT_RUN)) {
if (new_stat & CH_STAT_RUN) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->start();
} else {
if (this->ch_stat & CH_STAT_ACTIVE) {
this->abort();
this->update_irq(this->cur_host->cmd_bits);
this->cmd_in_progress = false;
}
this->ch_stat &= ~(CH_STAT_RUN | CH_STAT_ACTIVE | CH_STAT_DEAD);
this->abort();
this->update_irq();
new_stat &= ~CH_STAT_ACTIVE;
new_stat &= ~CH_STAT_DEAD;
this->cmd_in_progress = false;
this->ch_stat = new_stat;
}
} else if (mask & CH_STAT_PAUSE) {
if (data & CH_STAT_PAUSE) {
if (this->ch_stat & CH_STAT_ACTIVE)
this->pause();
this->ch_stat |= CH_STAT_PAUSE;
this->ch_stat &= ~CH_STAT_ACTIVE;
} else {
this->ch_stat &= ~CH_STAT_PAUSE;
if (!(this->ch_stat & CH_STAT_ACTIVE) && this->is_paused) {
this->is_paused = false;
this->ch_stat |= CH_STAT_ACTIVE;
this->resume();
}
}
} else if (mask & CH_STAT_WAKE) {
if (data & CH_STAT_WAKE && !(this->ch_stat & CH_STAT_ACTIVE)) {
this->ch_stat |= CH_STAT_ACTIVE;
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
if (new_stat & CH_STAT_WAKE) {
new_stat |= CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->resume();
} else {
LOG_F(ERROR, "%s: Attempt to clear wake status bit 0x%04x", this->get_name().c_str(), CH_STAT_WAKE);
}
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
if (new_stat & CH_STAT_PAUSE) {
new_stat &= ~CH_STAT_ACTIVE;
this->ch_stat = new_stat;
this->pause();
}
}
break;
@@ -431,12 +409,11 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
}
break;
case DMAReg::CMD_PTR_LO:
if (!(this->ch_stat & CH_STAT_ACTIVE)) { // DBDMA spec 5.5.4 (disagrees with 2.9.1.3)
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%s", this->get_name().c_str(),
this->cmd_ptr, (this->ch_stat & CH_STAT_RUN) ? " while running!" : "");
} else
LOG_F(WARNING, "%s: CommandPtrLo update skipped", this->get_name().c_str());
LOG_F(9, "%s: CommandPtrLo set to 0x%X", this->get_name().c_str(),
this->cmd_ptr);
}
break;
case DMAReg::INT_SELECT:
this->int_select = value & 0xFF00FFUL;
@@ -459,18 +436,16 @@ void DMAChannel::xfer_from_device() {
this->xfer_dir = DMA_DIR_FROM_DEV;
int got_bytes = this->dev_obj->xfer_from(this, this->queue_data, this->queue_len);
this->queue_data += got_bytes;
this->res_count -= got_bytes;
this->queue_len -= got_bytes;
if (!this->queue_len) {
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
} else if (got_bytes) {
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
this->get_name().c_str());
}
this->interpret_until_blocked();
this->interpret_cmd();
}
void DMAChannel::xfer_to_device() {
@@ -479,15 +454,13 @@ void DMAChannel::xfer_to_device() {
this->xfer_dir = DMA_DIR_TO_DEV;
int got_bytes = this->dev_obj->xfer_to(this, this->queue_data, this->queue_len);
this->queue_data += got_bytes;
this->res_count -= got_bytes;
this->queue_len -= got_bytes;
if (!this->queue_len) {
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
if (got_bytes == this->queue_len) {
this->queue_len = 0;
this->finish_cmd();
}
this->interpret_until_blocked();
this->interpret_cmd();
}
void DMAChannel::xfer_retry() {
@@ -500,10 +473,9 @@ void DMAChannel::xfer_retry() {
this->xfer_to_device();
}
bool DMAChannel::dma_is_ready() {
if (!this->is_active() ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP
)
bool DMAChannel::is_ready() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
return false;
return true;
@@ -513,14 +485,16 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
{
*avail_len = 0;
if (!this->is_active()) {
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());
return DmaPullResult::NoMoreData;
}
// interpret DBDMA program until we get data or become idle
this->interpret_until_blocked();
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
this->interpret_cmd();
}
// dequeue data if any
if (this->queue_len) {
@@ -529,14 +503,14 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
*p_data = this->queue_data;
*avail_len = req_len;
this->queue_len -= req_len;
this->res_count -= 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);
*p_data = this->queue_data;
*avail_len = this->queue_len;
this->res_count -= this->queue_len;
this->res_count += this->queue_len;
this->queue_len = 0;
}
return DmaPullResult::MoreData; // tell the caller there is more data
@@ -545,42 +519,80 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
return DmaPullResult::NoMoreData; // tell the caller there is no more data
}
DmaPushResult DMAChannel::push_data(const char* src_ptr, int len) {
if (!this->is_active()) {
LOG_F(WARNING, "%s: Attempt to push data to dead/idle channel",
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());
return DmaPushResult::NoData;
return -1;
}
// interpret DBDMA program until we get buffer to fill in or become idle
this->interpret_until_blocked();
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
this->interpret_cmd();
}
if (this->queue_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->res_count += len;
this->queue_len -= len;
}
// proceed with the DBDMA program if the buffer became exhausted
if (!this->queue_len) {
this->interpret_until_blocked();
this->interpret_cmd();
}
return DmaPushResult::PushedData;
return 0;
}
void DMAChannel::end_pull_data() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
// dead or idle channel? -> no more data
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
this->get_name().c_str());
return;
}
if (this->queue_len) {
this->queue_len = 0;
} else {
this->ch_stat &= ~CH_STAT_FLUSH;
}
// proceed with the DBDMA program
this->interpret_cmd();
}
void DMAChannel::end_push_data() {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
this->get_name().c_str());
return;
}
if (this->queue_len) {
this->queue_len = 0;
} else {
this->ch_stat &= ~CH_STAT_FLUSH;
}
// proceed with the DBDMA program
this->interpret_cmd();
}
bool DMAChannel::is_out_active() {
return this->is_active();
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
return false;
}
else {
return true;
}
}
bool DMAChannel::is_in_active() {
return this->is_active();
}
bool DMAChannel::is_active() {
if ((this->ch_stat & CH_STAT_DEAD) || !(this->ch_stat & CH_STAT_ACTIVE)) {
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
return false;
}
else {
@@ -600,13 +612,17 @@ void DMAChannel::start() {
this->cmd_in_progress = false;
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_START);
if (this->start_cb)
this->start_cb();
this->interpret_until_blocked();
// some DBDMA programs contain commands that don't transfer data
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
// We thus interprete the DBDMA program until a data transfer between
// a device and memory is queued or the channel becomes idle/dead.
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
(this->ch_stat & CH_STAT_ACTIVE)) {
this->interpret_cmd();
}
}
void DMAChannel::resume() {
@@ -618,22 +634,24 @@ void DMAChannel::resume() {
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
this->interpret_until_blocked();
// some DBDMA programs contain commands that don't transfer data
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
// We thus interprete the DBDMA program until a data transfer between
// a device and memory is queued or the channel becomes idle/dead.
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
(this->ch_stat & CH_STAT_ACTIVE)) {
this->interpret_cmd();
}
}
void DMAChannel::abort() {
LOG_F(9, "%s: Aborting DMA channel", this->get_name().c_str());
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_STOP);
if (this->stop_cb)
this->stop_cb();
}
void DMAChannel::pause() {
LOG_F(INFO, "%s: Pausing DMA channel", this->get_name().c_str());
if (this->dev_obj != nullptr)
this->dev_obj->notify(this, DMA_MSG_STOP);
if (this->stop_cb)
this->stop_cb();
this->is_paused = true;
}
+17 -25
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -29,7 +29,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DB_DMA_H
#define DB_DMA_H
#include <core/timermanager.h>
#include <devices/common/dmacore.h>
#include <cinttypes>
@@ -110,23 +109,21 @@ public:
~DMAChannel() = default;
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
void set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb);
uint32_t reg_read(uint32_t offset, int size);
void reg_write(uint32_t offset, uint32_t value, int size);
void set_stat(uint8_t new_stat) {
this->ch_stat = (this->ch_stat & 0xff00) | new_stat;
}
void update_ch_stat(uint8_t mask, uint8_t new_val) {
this->ch_stat = (this->ch_stat & ~mask) | new_val;
}
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
bool is_out_active() override;
bool is_in_active() override;
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
DmaPushResult push_data(const char* src_ptr, int len) override;
int push_data(const char* src_ptr, int len) override;
int get_pull_data_remaining() override { return this->queue_len; }
int get_push_data_remaining() override { return this->queue_len; }
void end_pull_data() override;
void end_push_data() override;
bool dma_is_ready() override;
bool is_ready() override;
void xfer_retry() override;
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
@@ -136,12 +133,10 @@ public:
protected:
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
void interpret_cmd(void);
void interpret_until_blocked();
void update_cmd();
uint8_t interpret_cmd(void);
void finish_cmd();
void xfer_quad(bool is_store);
void update_irq(uint8_t cmd_bits);
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
void update_irq();
void xfer_from_device();
void xfer_to_device();
@@ -150,11 +145,12 @@ protected:
void abort(void);
void pause(void);
bool is_active();
private:
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
std::function<void(void)> in_cb = nullptr; // DMA channel in callback
std::function<void(void)> out_cb = nullptr; // DMA channel out callback
std::function<void(void)> flush_cb = nullptr; // DMA channel flush callback
uint16_t ch_stat = 0;
uint32_t cmd_ptr = 0;
@@ -166,15 +162,11 @@ private:
uint32_t wait_select = 0;
bool cmd_in_progress = false;
bool is_paused = false;
uint8_t cur_cmd;
DMACmd * cur_host = nullptr; // host virtual address of current command
bool cur_is_writable = false; // current command is writable
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint64_t irq_id = 0;
TimerInfo interrupt_timer;
};
#endif // DB_DMA_H
+19 -43
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -33,11 +33,6 @@ enum DmaPullResult : int {
NoMoreData, // data source has no more data to be pulled
};
enum DmaPushResult : int {
NoData = -1, // data source is not running
PushedData = 0, // data was pushed
};
class DmaOutChannel {
public:
DmaOutChannel(std::string name) { this->name = name; }
@@ -45,6 +40,8 @@ public:
virtual bool is_out_active() { return true; }
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
virtual int get_pull_data_remaining() { return 1; }
virtual void end_pull_data() {}
std::string get_name(void) { return this->name; }
@@ -57,7 +54,9 @@ public:
DmaInChannel(std::string name) { this->name = name; }
virtual bool is_in_active() { return true; }
virtual DmaPushResult push_data(const char* src_ptr, int len) = 0;
virtual int push_data(const char* src_ptr, int len) = 0;
virtual int get_push_data_remaining() { return 1; }
virtual void end_push_data() {}
std::string get_name(void) { return this->name; }
@@ -78,23 +77,12 @@ private:
};
// ---------------------- New DMA API -------------------------
/** DMA channel types. */
enum DmaChannelType : unsigned {
DMA_CH_TYPE_UNDEF = 0,
DMA_CH_TYPE_IN, // unidirectional channel, host <--- device
DMA_CH_TYPE_OUT, // unidirectional channel, host ---> device
DMA_CH_TYPE_BIDIR, // bidirectional channel, host <--> device
};
/** DMA messages. */
enum DmaMsg : unsigned {
DMA_MSG_START = 1,
DMA_MSG_STOP,
DMA_MSG_FLUSH,
DMA_MSG_DATA_AVAIL,
CH_START = 1,
CH_STOP,
DATA_AVAIL,
};
/** DMA transfer direction constants. */
enum XferDir : unsigned {
DMA_DIR_UNDEF = 0,
DMA_DIR_TO_DEV,
@@ -109,10 +97,10 @@ public:
~DmaDevice() = default;
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
virtual void notify(DmaChannel *ch_obj, DmaMsg msg) {}
virtual int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) { return len; }
virtual int xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) { return len; }
virtual int tell_xfer_size(DmaChannel *ch_obj) { return 0; }
virtual void notify(DmaMsg msg) {}
virtual int xfer_from(uint8_t *buf, int len) { return len; }
virtual int xfer_to(uint8_t *buf, int len) { return len; }
virtual int tell_xfer_size() { return 0; }
protected:
DmaChannel* channel_obj = nullptr;
@@ -120,29 +108,17 @@ protected:
class DmaChannel {
public:
DmaChannel(const uint32_t id = 1) { this->ch_id = id; }
DmaChannel(const DmaChannelType type, const uint32_t id = 1) {
this->ch_type = type;
this->ch_id = id;
}
DmaChannel() = default;
~DmaChannel() = default;
// setters/getters
void set_id(const uint32_t id) { this->ch_id = id; }
uint32_t get_id() { return this->ch_id; }
void set_type(const DmaChannelType type) { this->ch_type = type; }
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; }
virtual void notify(DmaMsg msg) {}
virtual bool dma_is_ready() { return false; }
virtual bool is_ready() { return false; }
virtual void xfer_retry() {}
protected:
DmaDevice* dev_obj = nullptr;
uint32_t ch_id = 0; // support for several channels per device
DmaChannelType ch_type = DMA_CH_TYPE_BIDIR;
XferDir xfer_dir = DMA_DIR_UNDEF;
DmaDevice* dev_obj = nullptr;
XferDir xfer_dir = DMA_DIR_UNDEF;
};
/*
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -93,7 +93,6 @@ enum IntSrc : uint32_t {
SLOT_PDS,
SLOT_VDS,
VBL,
VALKYRIE,
};
/** Base class for interrupt controllers. */
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,12 +19,12 @@ 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/memaccess.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <fstream>
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+17 -18
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,11 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** Utilities for working with Apple Open Firmware and CHRP NVRAM partitions. */
#include <core/endianswap.h>
#include <core/memaccess.h>
#include <devices/common/ofnvram.h>
#include <devices/common/nvram.h>
#include <endianswap.h>
#include <machines/machinebase.h>
#include <memaccess.h>
#include <cinttypes>
#include <cstring>
@@ -85,7 +85,7 @@ bool OfConfigAppl::validate() {
}
// verify partition checksum
if (this->checksum_partition() != 0xFFFFU)
if (this->checksum_partition() ^ 0xFFFFU)
return false;
return true;
@@ -101,7 +101,7 @@ uint16_t OfConfigAppl::checksum_partition() {
return acc + (acc >> 16);
}
static const string flag_names[] = {
static const string flag_names[8] = {
"little-endian?",
"real-mode?",
"auto-boot?",
@@ -109,10 +109,8 @@ static const string flag_names[] = {
"fcode-debug?",
"oem-banner?",
"oem-logo?",
"use-nvramrc?",
"f-segment?" // ANS only
"use-nvramrc?"
};
constexpr int num_flags = sizeof(flag_names) / sizeof(flag_names[0]);
static const map<string, std::tuple<int, uint16_t>> of_vars = {
// name, type, offset
@@ -143,12 +141,12 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
if (!this->validate())
return _config_vars;
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
uint8_t of_flags = this->buf[12];
// populate flags
for (unsigned i = 0; i < num_flags; i++) {
for (int i = 0; i < 8; i++) {
_config_vars.push_back(std::make_pair(flag_names[i],
(int32_t(of_flags << i) < 0) ? "true" : "false"));
((of_flags << i) & 0x80) ? "true" : "false"));
}
// populate the remaining variables
@@ -189,7 +187,7 @@ void OfConfigAppl::update_partition() {
// calculate new checksum
uint16_t checksum = this->checksum_partition();
checksum = ~checksum;
checksum = checksum ? ~checksum : 0xFFFFU;
// stuff checksum into the header
WRITE_WORD_BE_A(&this->buf[4], checksum);
@@ -207,7 +205,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
return false;
// check if the user tries to change a flag
for (i = 0; i < num_flags; i++) {
for (i = 0; i < 8; i++) {
if (var_name == flag_names[i]) {
if (value == "true")
flag = 1;
@@ -217,15 +215,15 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
cout << "Invalid property value: " << value << endl;
return false;
}
uint32_t flag_bit = 0x80000000U >> i;
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
uint8_t flag_bit = 0x80U >> i;
uint8_t of_flags = this->buf[12];
if (flag)
of_flags |= flag_bit;
else
of_flags &= ~flag_bit;
WRITE_DWORD_BE_A(&this->buf[12], of_flags);
this->buf[12] = of_flags;
this->update_partition();
return true;
}
@@ -250,6 +248,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
}
WRITE_DWORD_BE_A(&this->buf[offset], num);
this->update_partition();
cout << " ok" << endl; // mimic Forth
} else {
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]);
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -21,10 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** Bandit/Chaos ARBus-to-PCI Bridge emulation. */
#include <core/endianswap.h>
#include <devices/common/pci/bandit.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+6 -25
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -28,12 +28,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
enum YosemiteGpioMask: uint8_t {
GPIO_FWDET = 2, // FireWire detect
};
constexpr uint32_t my_rev_id = 2;
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
{
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
@@ -41,7 +35,7 @@ DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
// initialize PCI config header
this->vendor_id = PCI_VENDOR_DEC;
this->device_id = 0x0026;
this->class_rev = DEVTYPE_PCI2PCI_BRIDGE | my_rev_id;
this->class_rev = 0x06040002;
this->cache_ln_sz = 0;
this->command = 0;
this->status = 0x2B0;
@@ -57,7 +51,7 @@ uint32_t DecPciBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
case CHIP_CTRL:
return (this->arb_ctrl << 16) | (this-> diag_ctrl << 8) | this->chip_ctrl;
case PSERR_EVENT_DIS:
return (this->gpio_out_en << 16) | (this->gpio_out_data << 8) | this->pserr_event_dis;
return (this->gpio_out_en << 16) | this->pserr_event_dis;
case SEC_CLK_CTRL:
return this->sec_clock_ctrl;
default:
@@ -81,21 +75,8 @@ void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetail
this->arb_ctrl = value >> 16;
break;
case PSERR_EVENT_DIS:
this->pserr_event_dis = value & 0x7EU;
this->gpio_out_data = (value >> 8) & 0xFFU;
this->pserr_event_dis = value & 0xFFU;
this->gpio_out_en = (value >> 16) & 0xFFU;
{
uint8_t bits_to_set = gpio_out_data >> 4;
uint8_t bits_to_clr = gpio_out_data & 0xFU;
this->gpio_out_data_val |= bits_to_set;
this->gpio_out_data_val &= ~bits_to_clr;
}
{
uint8_t bits_to_set = gpio_out_en >> 4;
uint8_t bits_to_clr = gpio_out_en & 0xFU;
this->gpio_out_en_val |= bits_to_set;
this->gpio_out_en_val &= ~bits_to_clr;
}
break;
case SEC_CLK_CTRL:
this->sec_clock_ctrl = value & 0xFFFFU;
+3 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -61,8 +61,6 @@ private:
uint8_t gpio_out_en = 0;
uint8_t gpio_in_data = 0;
uint16_t sec_clock_ctrl = 0;
uint8_t gpio_out_data_val = 0;
uint8_t gpio_out_en_val = 0;
};
#endif // DEC_P2P_H
+5 -5
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,10 +19,10 @@ 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/endianswap.h>
#include <core/memaccess.h>
#include <devices/common/pci/pcibase.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <fstream>
+13 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define PCI_BASE_H
#include <devices/common/mmiodevice.h>
#include <devices/common/pci/pcidefs.h>
#include <devices/common/pci/pcihost.h>
#include <cinttypes>
@@ -53,6 +52,16 @@ enum {
// Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
enum {
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_SILICON_IMAGE = 0x1095,
PCI_VENDOR_NVIDIA = 0x10DE,
};
/** PCI BAR types */
enum PCIBarType : uint32_t {
Unused = 0,
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,8 +19,8 @@ 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/memaccess.h>
#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)
{
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+6 -24
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,8 +19,8 @@ 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/memaccess.h>
#include <devices/common/pci/pcicardbusbridge.h>
#include <memaccess.h>
typedef struct {
// CardBus Registers
@@ -155,10 +155,6 @@ uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &detail
return (this->subsys_id << 16) | (this->subsys_vndr);
case PCI_CFG_CB_LEGACY_MODE_BASE:
return this->legacy_mode_base;
case PCI_CFG_CB_SOCKET_DMA_0:
return this->dreq_pin;
case PCI_CFG_CB_SOCKET_DMA_1:
return this->dma_base;
default:
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
}
@@ -197,19 +193,11 @@ void PCICardbusBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDe
case PCI_CFG_CB_IO_LIMIT_1:
this->pci_wr_io_limit_0(value);
break;
#if 0
// FIXME: handle legacy_mode_base and dma_base changes here
/*
case PCI_CFG_CB_LEGACY_MODE_BASE:
this->legacy_mode_base = value;
break;
case PCI_CFG_CB_SOCKET_DMA_0:
this->dreq_pin = value & DREQ_PIN_MASK;
break;
case PCI_CFG_CB_SOCKET_DMA_1:
this->dma_base = (value & DDMA_EXTMODE_MASK) | (value & (0xFFFF & ~DDMA_EXTMODE_MASK));
break;
#endif
*/
default:
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
break;
@@ -222,9 +210,6 @@ bool PCICardbusBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res
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;
#if 0
// FIXME: check legacy_mode_base and dma_base here
#endif
return this->pci_io_read_loop(offset, size, *res);
}
@@ -234,8 +219,5 @@ bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t si
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
) return false;
#if 0
// FIXME: check legacy_mode_base and dma_base here
#endif
return this->pci_io_write_loop(offset, size, value);
}
+3 -27
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -44,28 +44,6 @@ enum {
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,
PCI_CFG_CB_SOCKET_DMA_0 = 0x94,
PCI_CFG_CB_SOCKET_DMA_1 = 0x98,
};
/** PC Card bits */
enum {
DREQ_PIN_MASK = 3,
DREQ_NO_DMA = 0, // 0 = Socket is not configured for DMA
DREQ_USES_SPKR = 1,
DREQ_USES_IOIS16 = 2,
DREQ_USES_INPACK = 3,
DDMA_BASE_MASK = (0xFFF0),
DDMA_EXTMODE_MASK = (1 << 3),
DDMA_EXTMODE_DISABLE = (0 << 3),
DDMA_EXTMODE_ENABLE = (1 << 3),
DDMA_XFERSIZE_8_BITS = (0 << 1),
DDMA_XFERSIZE_16_BITS = (1 << 1),
DDMA_XFERSIZE_2 = (2 << 1),
DDMA_XFERSIZE_3 = (3 << 1),
DDMA_ENABLE = (1 << 0),
DDMA_DISABLE = (0 << 0),
};
class PCICardbusBridge : public PCIBridgeBase {
@@ -111,8 +89,6 @@ protected:
uint16_t subsys_id = 0;
uint16_t subsys_vndr = 0;
uint32_t legacy_mode_base = 0;
uint32_t dreq_pin = DREQ_NO_DMA;
uint32_t dma_base = 0 | DDMA_EXTMODE_DISABLE | DDMA_XFERSIZE_8_BITS | DDMA_DISABLE;
// 0 = not writable
uint32_t memory_0_cfg = 0xfffff000;
-72
View File
@@ -1,72 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PCI_DEFS_H
#define PCI_DEFS_H
#include <cinttypes>
/** PCI device class/subclass/programming interface definitions. */
enum : uint8_t {
DEVCLASS_UNCLASSIFIED = 0x00, // unclassified/legacy devices
DEVCLASS_MASS_STORAGE_CTRL = 0x01, // mass storage controllers
SUBCLASS_IDE_CTRL = 0x01, // IDE controller
PROGIF_BUS_MASTER = 0x80, // bus master (DMA) capable
DEVCLASS_DISPLAY_CTRL = 0x03, // display controllers
SUBCLASS_VGA_COMPAT = 0x00, // VGA-compatible display controller
SUBCLASS_NON_VGA = 0x80, // non-VGA display controller
DEVCLASS_BRIDGE_DEVICE = 0x06, // various bridge devices
SUBCLASS_HOST_BRIDGE = 0x00, // host-to-PCI bridge
SUBCLASS_PCI2PCI_BRIDGE = 0x04, // PCI-to-PCI bridge
DEVCLASS_SERIAL_BUS_CTRL = 0x0C, // serial bus controllers
SUBCLASS_USB_CTRL = 0x03, // Universal serial bus (USB) controller
PROGIF_OHCI = 0x10, // conforms to the OpenHCI specification
DEVCLASS_UNASSIGNED = 0xFF
};
/** Some common PCI device type definitions. */
enum : uint32_t {
DEVTYPE_HOST2PCI_BRIDGE = (DEVCLASS_BRIDGE_DEVICE << 24) |
(SUBCLASS_HOST_BRIDGE << 16),
DEVTYPE_PCI2PCI_BRIDGE = (DEVCLASS_BRIDGE_DEVICE << 24) |
(SUBCLASS_PCI2PCI_BRIDGE << 16),
DEVTYPE_VGA_COMPAT_VIDCTRL = (DEVCLASS_DISPLAY_CTRL << 24) |
(SUBCLASS_VGA_COMPAT << 16),
DEVTYPE_IDE_CTRL_BUS_MASTER = (DEVCLASS_MASS_STORAGE_CTRL << 24) |
(SUBCLASS_IDE_CTRL << 16) | (PROGIF_BUS_MASTER << 8),
DEVTYPE_USB_OHCI_CTRL = (DEVCLASS_SERIAL_BUS_CTRL << 24) |
(SUBCLASS_USB_CTRL << 16) | (PROGIF_OHCI << 8),
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
enum : uint16_t {
PCI_VENDOR_ATI = 0x1002,
PCI_VENDOR_DEC = 0x1011,
PCI_VENDOR_OPTi = 0x1045,
PCI_VENDOR_TI = 0x104C, // common abbreviation for Texas Instruments
PCI_VENDOR_MOTOROLA = 0x1057,
PCI_VENDOR_APPLE = 0x106B,
PCI_VENDOR_SILICON_IMAGE = 0x1095,
PCI_VENDOR_NVIDIA = 0x10DE,
PCI_VENDOR_IXMICRO = 0x10E0, // also known as Integrated Micro Solutions
};
#endif // PCI_DEFS_H
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-23 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+4 -4
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -19,13 +19,13 @@ 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/endianswap.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/pci/pcibridge.h>
#include <devices/common/pci/pcihost.h>
#include <devices/deviceregistry.h>
#include <machines/machinefactory.h>
#include <machines/machinebase.h>
#include <endianswap.h>
#include <loguru.hpp>
#include <cinttypes>
+5 -16
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -23,9 +23,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define PCI_HOST_H
#include <core/bitops.h>
#include <core/endianswap.h>
#include <devices/common/hwinterrupt.h>
#include <devices/memctrl/memctrlbase.h>
#include <endianswap.h>
#include <cinttypes>
#include <string>
@@ -110,8 +110,7 @@ protected:
// 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 or any other dword little endian register.
Unaligned data is handled properly by using bytes from the next dword.
*/
@@ -199,14 +198,4 @@ inline uint32_t pci_conv_wr_data(uint32_t v1, uint32_t v2, AccessDetails &detail
}
}
/** Merge val_hi and val_lo into a QWORD, then extract a portion
indicated by pos and size and return the right-justified result.
This macro is a variant of pci_conv_rd_data() with less code
aiming to simplify spanning reads from PCI registers.
No endian swappping is performed.
*/
#define REG_READ_HELPER(val_hi, val_lo, pos, size) \
((((uint64_t)(val_hi) << 32) | (val_lo)) >> (8 - (pos) - (size)) * 8) & \
((1ULL << ((size) * 8)) - 1) // apply size-dependent mask
#endif /* PCI_HOST_H */
+4 -11
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -37,7 +37,7 @@ using namespace MeshScsi;
int MeshController::device_postinit() {
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
if (bus_obj) {
bus_obj->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
bus_obj->attach_scsi_devices("2");
}
@@ -51,16 +51,10 @@ int MeshController::device_postinit() {
void MeshController::reset(bool is_hard_reset) {
this->cur_cmd = SeqCmd::NoOperation;
this->fifo_pos = 0;
this->to_xfer = 0;
this->int_stat = 0;
this->int_mask = 0;
this->exception = 0;
this->xfer_count = 0;
this->src_id = 7;
this->check_parity = true;
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
update_irq();
if (is_hard_reset) {
this->bus_stat = 0;
@@ -129,7 +123,6 @@ void MeshController::write(uint8_t reg_offset, uint8_t value) {
break;
case MeshReg::IntMask:
this->int_mask = value;
update_irq();
break;
case MeshReg::Interrupt:
this->int_stat &= ~(value & INT_MASK); // clear requested interrupt bits
+3 -3
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
+166 -110
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <cstring>
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiPhysDevice("SC53C94", my_id), DmaDevice()
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
@@ -45,7 +45,7 @@ int Sc53C94::device_postinit()
{
ScsiBus* bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
if (bus) {
bus->register_device(7, static_cast<ScsiPhysDevice*>(this));
bus->register_device(7, static_cast<ScsiDevice*>(this));
bus->attach_scsi_devices("");
}
@@ -78,73 +78,60 @@ void Sc53C94::reset_device()
this->cur_step = 0;
this->seq_step = 0;
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
this->int_status = 0;
}
uint8_t Sc53C94::read(uint8_t reg_offset)
{
uint8_t value;
uint8_t bus_phase, int_flags;
switch (reg_offset) {
case Read::Reg53C94::Xfer_Cnt_LSB:
value = this->xfer_count & 0xFFU;
break;
return this->xfer_count & 0xFFU;
case Read::Reg53C94::Xfer_Cnt_MSB:
value = (this->xfer_count >> 8) & 0xFFU;
break;
return (this->xfer_count >> 8) & 0xFFU;
case Read::Reg53C94::FIFO:
value = this->fifo_pop();
break;
return this->fifo_pop();
case Read::Reg53C94::Command:
value = this->cmd_fifo[0];
break;
case Read::Reg53C94::Status: {
uint8_t bus_phase;
if (this->config2 & CFG2_ENF)
bus_phase = this->phase_latch;
else
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
if (this->config2 & CFG2_ENF) {
static bool log_it = true;
if (log_it) {
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
log_it = false;
}
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
} else
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
value = (this->status & 0xF8) | bus_phase;
break;
}
return (this->status & 0xF8) | bus_phase;
case Read::Reg53C94::Int_Status:
value = this->int_status;
int_flags = this->int_status;
if (this->irq) {
this->status &= ~(STAT_GE | STAT_PE | STAT_GCV);
this->int_status = 0;
this->seq_step = 0;
}
if (this->phase_latch_closed)
this->phase_latch_closed = false; // open the bus phase latch
this->update_irq();
break;
return int_flags;
case Read::Reg53C94::Seq_Step:
value = this->seq_step;
break;
return this->seq_step;
case Read::Reg53C94::FIFO_Flags:
value = (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
break;
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
case Read::Reg53C94::Config_1:
value = this->config1;
break;
return this->config1;
case Read::Reg53C94::Config_3:
value = this->config3;
break;
case Read::Reg53C94::Config_4:
value = this->config4;
break;
return this->config3;
case Read::Reg53C94::Xfer_Cnt_Hi:
if (this->config2 & CFG2_ENF) {
value = (this->xfer_count >> 16) & 0xFFU;
} else {
value = 0;
return (this->xfer_count >> 16) & 0xFFU;
}
break;
default:
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
}
return value;
return 0;
}
void Sc53C94::write(uint8_t reg_offset, uint8_t value)
@@ -189,13 +176,8 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
case Write::Reg53C94::Config_3:
this->config3 = value;
break;
case Write::Reg53C94::Config_4:
this->config4 = value;
if (value)
LOG_F(WARNING, "%s: config 4 set to 0x%X", this->name.c_str(), value);
break;
default:
LOG_F(INFO, "%s: writing 0x%X to register # %d", this->name.c_str(), value,
LOG_F(INFO, "%s: writing 0x%X to %d register", this->name.c_str(), value,
reg_offset);
}
}
@@ -252,7 +234,7 @@ void Sc53C94::pseudo_dma_write(uint16_t data) {
void Sc53C94::update_command_reg(uint8_t cmd)
{
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP && (cmd & CMD_OPCODE) != CMD_CLEAR_FIFO) {
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP) {
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
return;
}
@@ -306,7 +288,6 @@ void Sc53C94::exec_command()
exec_next_command();
break;
case CMD_CLEAR_FIFO:
this->on_reset = false; // unblock the command register
this->data_fifo_pos = 0; // set the bottom of the data FIFO to zero
this->data_fifo[0] = 0;
exec_next_command();
@@ -314,19 +295,20 @@ void Sc53C94::exec_command()
case CMD_RESET_DEVICE:
reset_device();
this->on_reset = true; // block the command register
this->update_irq();
return;
case CMD_RESET_BUS:
LOG_F(INFO, "%s: resetting SCSI bus...", this->name.c_str());
// assert RST line
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
// release RST line after 25 us
if (my_timer.active) {
TimerManager::get_instance()->cancel_timer(this->my_timer);
if (my_timer_id) {
TimerManager::get_instance()->cancel_timer(this->my_timer_id);
my_timer_id = 0;
}
TimerManager::get_instance()->add_oneshot_timer(my_timer,
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(25),
[this](uint64_t, uint64_t) {
[this]() {
my_timer_id = 0;
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
});
if (!(config1 & CFG1_DISR)) {
@@ -364,10 +346,8 @@ void Sc53C94::exec_command()
if (this->is_initiator) {
this->bus_obj->target_next_step();
}
// SCSI Manager expects this function to generate an interrupt.
// Don't set INTSTAT_SR or INISTAT_SO bits - that will confuse
// the SCSI driver in Open Firmware!
// Let's hope the target hung up already causing INTSTAT_DIS to be set.
this->int_status |= INTSTAT_SR;
this->update_irq();
exec_next_command();
break;
case CMD_XFER_PAD_BYTES:
@@ -475,22 +455,25 @@ uint8_t Sc53C94::fifo_pop()
void Sc53C94::seq_defer_state(uint64_t delay_ns)
{
if (this->seq_timer.active) {
TimerManager::get_instance()->cancel_timer(this->seq_timer);
if (this->seq_timer_id) {
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
this->seq_timer_id = 0;
}
if (delay_ns) {
TimerManager::get_instance()->add_oneshot_timer(this->seq_timer,
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this](uint64_t, uint64_t) {
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
} else {
TimerManager::get_instance()->add_immediate_timer(this->seq_timer,
[this](uint64_t, uint64_t) {
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
[this]() {
// re-enter the sequencer with the state specified in next_state
this->seq_timer_id = 0;
this->cur_state = this->next_state;
this->sequencer();
});
@@ -555,7 +538,6 @@ void Sc53C94::sequencer()
break;
case SeqState::SEND_MSG:
case SeqState::SEND_MSG_EX:
this->is_dma_xfer = this->is_dma_cmd;
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
@@ -571,7 +553,6 @@ void Sc53C94::sequencer()
}
break;
case SeqState::SEND_CMD:
this->is_dma_xfer = this->is_dma_cmd;
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
if (this->drq_cb)
this->drq_cb(1);
@@ -579,32 +560,30 @@ void Sc53C94::sequencer()
this->bus_obj->target_xfer_data();
break;
case SeqState::CMD_COMPLETE:
this->is_dma_xfer = false;
this->int_status = INTSTAT_SR | INTSTAT_SO;
this->cur_state = SeqState::IDLE;
this->update_phase_latch();
this->update_irq();
exec_next_command();
break;
case SeqState::XFER_BEGIN:
this->is_dma_xfer = this->is_dma_cmd;
this->cur_bus_phase = this->bus_obj->current_phase();
switch (this->cur_bus_phase) {
case ScsiPhase::DATA_OUT:
if (this->is_dma_cmd) {
if (this->channel_obj->dma_is_ready())
this->channel_obj->xfer_retry();
} else {
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
this->data_fifo_pos = 0;
this->cur_state = SeqState::XFER_END;
this->sequencer();
}
break;
case ScsiPhase::DATA_IN:
if (this->is_dma_cmd && this->channel_obj->dma_is_ready()) {
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
this->data_fifo_pos = 0;
this->cur_state = SeqState::XFER_END;
this->sequencer();
break;
case ScsiPhase::DATA_IN:
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
this->channel_obj->xfer_retry();
break;
}
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->cur_state = SeqState::RCV_DATA;
this->rcv_data();
if (!(this->is_dma_cmd)) {
@@ -626,13 +605,11 @@ void Sc53C94::sequencer()
}
break;
case SeqState::XFER_END:
this->is_dma_xfer = false;
if (this->is_initiator) {
this->bus_obj->target_next_step();
}
this->cur_state = SeqState::IDLE;
this->update_phase_latch();
this->int_status = INTSTAT_SR;
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
break;
@@ -645,13 +622,12 @@ void Sc53C94::sequencer()
this->int_status = INTSTAT_SR;
this->update_irq();
} else {
this->is_dma_xfer = this->is_dma_cmd;
this->rcv_data();
}
break;
case SeqState::RCV_STATUS:
case SeqState::RCV_MESSAGE:
this->is_dma_xfer = this->is_dma_cmd;
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
this->rcv_data();
if (this->is_initiator) {
if (this->cur_state == SeqState::RCV_STATUS) {
@@ -664,7 +640,6 @@ void Sc53C94::sequencer()
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
this->int_status = INTSTAT_SO;
this->cur_state = SeqState::CMD_COMPLETE;
this->sequencer();
}
@@ -686,26 +661,14 @@ void Sc53C94::update_irq()
}
}
void Sc53C94::update_phase_latch() {
if (this->config2 & CFG2_ENF) {
if (this->phase_latch_closed) {
LOG_F(WARNING, "%s: ignored update of the closed bus phase latch",
this->name.c_str());
} else {
this->phase_latch = bus_obj->test_ctrl_lines(
SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
this->phase_latch_closed = true;
}
}
}
void Sc53C94::notify(ScsiNotification notif_type, int param)
{
switch (notif_type) {
case ScsiNotification::CONFIRM_SEL:
if (this->target_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer);
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
this->seq_timer_id = 0;
this->cur_state = SeqState::SEL_END;
this->sequencer();
} else {
@@ -730,10 +693,8 @@ void Sc53C94::notify(ScsiNotification notif_type, int param)
this->seq_step = this->cur_step;
this->int_status = this->cmd_steps->status;
this->update_irq();
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE) {
this->update_phase_latch();
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE)
this->exec_next_command();
}
}
}
break;
@@ -786,13 +747,108 @@ bool Sc53C94::rcv_data()
return true;
}
int Sc53C94::xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) {
void Sc53C94::real_dma_xfer_out()
{
// transfer data from host's memory to target
if (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();
}
}
if (this->xfer_count) {
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
10000,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->dma_timer_id = 0;
this->real_dma_xfer_out();
});
}
}
void Sc53C94::real_dma_xfer_in()
{
bool is_done = false;
// transfer data from target to host's memory
if (this->xfer_count && this->data_fifo_pos) {
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
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();
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
10000,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->dma_timer_id = 0;
this->real_dma_xfer_in();
});
}
}
void Sc53C94::dma_wait() {
if (this->cur_bus_phase == ScsiPhase::DATA_IN && this->cur_state == SeqState::RCV_DATA) {
real_dma_xfer_in();
}
else if (this->cur_bus_phase == ScsiPhase::DATA_OUT && this->cur_state == SeqState::SEND_DATA) {
real_dma_xfer_out();
}
else {
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
10000,
[this]() {
this->dma_timer_id = 0;
this->dma_wait();
});
}
}
void Sc53C94::dma_start()
{
dma_wait();
}
void Sc53C94::dma_stop()
{
if (this->dma_timer_id) {
TimerManager::get_instance()->cancel_timer(this->dma_timer_id);
this->dma_timer_id = 0;
}
}
int Sc53C94::xfer_from(uint8_t *buf, int len) {
int bytes_moved = 0;
if (this->cur_cmd != CMD_XFER || !this->is_dma_cmd ||
this->cur_bus_phase != ScsiPhase::DATA_IN) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return 0;
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
@@ -827,12 +883,12 @@ int Sc53C94::xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) {
return bytes_moved;
}
int Sc53C94::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
int Sc53C94::xfer_to(uint8_t *buf, int len) {
int bytes_moved = 0;
if (!this->xfer_count || !this->is_dma_xfer) {
if (!this->xfer_count || !this->is_dma_cmd) {
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
return 0;
return bytes_moved;
}
len = std::min(len, (int)(this->xfer_count));
+38 -26
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -29,7 +29,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef SC_53C94_H
#define SC_53C94_H
#include <core/timermanager.h>
#include <devices/common/scsi/scsi.h>
#include <devices/common/dbdma.h>
@@ -55,7 +54,7 @@ namespace Read {
//
Config_2 = 0xB, // Control Register 2
Config_3 = 0xC, // Control Register 3
Config_4 = 0xD, // Control Register 4 ; Am53CF94 extension
Config_4 = 0xD, // Control Register 4
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
//
};
@@ -151,16 +150,14 @@ enum {
INTSTAT_SEL = 0x01, // selected as a target without attention
};
/** Configuration register 1 bit definitions. */
enum : uint8_t {
/** Configuration register 1 bits. */
enum {
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
};
/** Configuration register 2 bit definitions. */
enum : uint8_t {
CFG2_ENF = 0x40, // Am53CF94: enable extended chip features
// ASC: enable phase latch (EPL)
CFG2_S2FE = 0x08, // enable SCSI-2 features
/** Configuration register 2 bits. */
enum {
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
};
/** Sequencer states. */
@@ -197,7 +194,7 @@ typedef struct {
typedef std::function<void(const uint8_t drq_state)> DrqCb;
class Sc53C94 : public ScsiPhysDevice, public DmaDevice {
class Sc53C94 : public ScsiDevice, public DmaDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
~Sc53C94() = default;
@@ -215,27 +212,46 @@ public:
uint16_t pseudo_dma_read();
void pseudo_dma_write(uint16_t data);
// real DMA control
void real_dma_xfer_out();
void real_dma_xfer_in();
void dma_start();
void dma_wait();
void dma_stop();
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
auto dbdma_ch = dynamic_cast<DMAChannel*>(dma_ch);
if (dbdma_ch) {
dbdma_ch->set_callbacks(
std::bind(&Sc53C94::dma_start, this),
std::bind(&Sc53C94::dma_stop, this)
);
}
}
void set_drq_callback(DrqCb cb) {
this->drq_cb = cb;
}
// ScsiPhysDevice methods
// ScsiDevice methods
void notify(ScsiNotification notif_type, int param) override;
bool prepare_data() override { return false; }
bool get_more_data() override { return false; }
bool has_data() override { return this->data_fifo_pos != 0; }
int send_data(uint8_t* dst_ptr, int count) override;
void process_command() override {}
// DmaDevice methods
int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) override;
int xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) override;
int tell_xfer_size(DmaChannel *ch_obj) override {
int xfer_from(uint8_t *buf, int len) override;
int xfer_to(uint8_t *buf, int len) override;
int tell_xfer_size() override {
return this->xfer_count;
}
protected:
void reset_device();
void update_command_reg(uint8_t cmd);
void update_phase_latch();
void exec_command();
void exec_next_command();
void fifo_push(const uint8_t data);
@@ -251,7 +267,7 @@ protected:
private:
uint8_t chip_id = 0;
uint8_t my_bus_id = 0;
TimerInfo my_timer;
uint32_t my_timer_id = 0;
uint8_t cmd_fifo[2];
uint8_t data_fifo[DATA_FIFO_MAX];
@@ -272,21 +288,15 @@ private:
uint8_t config1 = 0;
uint8_t config2 = 0;
uint8_t config3 = 0;
uint8_t config4 = 0;
// bus phase latch
bool phase_latch_closed = false;
uint8_t phase_latch = 0;
// sequencer state
TimerInfo seq_timer;
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;
bool is_dma_cmd = false;
bool is_dma_xfer = false;
int cur_bus_phase = 0;
uint8_t cur_step = 0; // internal step counter for multistep commands
@@ -296,7 +306,9 @@ private:
uint8_t irq = 0;
// DMA related stuff
DmaBidirChannel* dma_ch = nullptr;
DrqCb drq_cb = nullptr;
uint32_t dma_timer_id = 0;
};
#endif // SC_53C94_H
+47 -162
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -24,9 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef SCSI_H
#define SCSI_H
#include <core/timermanager.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/scsiphysinterface.h>
#include <array>
#include <cinttypes>
@@ -77,36 +75,11 @@ namespace ScsiStatus {
/** Standard message codes. */
namespace ScsiMessage {
enum : uint8_t {
COMMAND_COMPLETE = 0x00,
EXTENDED_MESSAGE = 0x01,
SAVE_POINTERS = 0x02,
RESTORE_POINTERS = 0x03,
DISCONNECT = 0x04,
INITIATOR_ERROR = 0x05,
ABORT_TASK_SET = 0x06,
MESSAGE_REJECT = 0x07,
NOP = 0x08,
MSG_PARITY_ERROR = 0x09,
LINKED_CMD_COMPLETE = 0x0A,
LINKED_FLG_CMD_COMPLETE = 0x0B,
TARGET_RESET = 0x0C,
ABORT_TASK = 0x0D,
CLEAR_TASK_SET = 0x0E,
INITIATE_RECOVERY = 0x0F, // SCSI-II only
RELEASE_RECOVERY = 0x10, // SCSI-II only
TERMINATE_IO_PROC = 0x11, // SCSI-II only
CLEAR_ACA = 0x16,
LOGICAL_UNIT_RESET = 0x17,
SIMPLE_QUEUE_TAG = 0x20,
HEAD_OF_QUEUE_TAG = 0x21,
ORDERED_QUEUE_TAG = 0x22,
IGNORE_WIDE_RESIDUE = 0x23,
ACA = 0x24,
QAS_REQUEST = 0x55,
COMMAND_COMPLETE = 0,
TARGET_ROUTINE_NUMBER_MASK = 0x07,
LOGICAL_UNIT_NUMBER_MASK = 0x07,
IS_TARGET_ROUTINE_NUMBER = 0x20,
IS_TARGET_ROUTINE_NuMBER = 0x20,
HAS_DISCONNECT_PRIVILEDGE = 0x40,
IDENTIFY = 0x80,
};
@@ -115,12 +88,9 @@ namespace ScsiMessage {
/** Extended message codes. */
namespace ScsiExtMessage {
enum : uint8_t {
MODIFY_DATA_PTR = 0,
SYNCH_XFER_REQ = 1,
EXTENDED_IDENTIFY = 2, // SCSI-I only
WIDE_XFER_REQ = 3,
PPR_REQ = 4,
MODIFY_BIDI_DATA_PTR = 5,
MODIFY_DATA_PTR = 0,
SYNCH_XFER_REQ = 1,
WIDE_XFER_REQ = 3,
};
}
@@ -135,8 +105,8 @@ enum ScsiCommand : uint8_t {
REWIND = 0x01,
REQ_SENSE = 0x03,
FORMAT_UNIT = 0x04,
READ_BLOCK_LIMITS = 0x05,
REASSIGN_BLOCKS = 0x07,
READ_BLK_LIMITS = 0x05,
REASSIGN = 0x07,
READ_6 = 0x08,
WRITE_6 = 0x0A,
SEEK_6 = 0x0B,
@@ -147,16 +117,16 @@ enum ScsiCommand : uint8_t {
ERASE_6 = 0x19,
MODE_SENSE_6 = 0x1A,
START_STOP_UNIT = 0x1B,
RECEIVE_DIAG_RESULTS = 0x1C,
SEND_DIAGNOSTIC = 0x1D,
DIAG_RESULTS = 0x1C,
SEND_DIAGS = 0x1D,
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
READ_CAPACITY = 0x25,
READ_CAPACITY_10 = 0x25,
READ_10 = 0x28,
WRITE_10 = 0x2A,
SEEK_10 = 0x2B,
WRITE_AND_VERIFY = 0x2E,
VERIFY_WRITE_10 = 0x2E,
VERIFY_10 = 0x2F,
SYNC_CACHE = 0x35,
READ_LONG_10 = 0x35,
WRITE_BUFFER = 0x3B,
READ_BUFFER = 0x3C,
GET_CONFIG = 0x46,
@@ -172,19 +142,16 @@ enum ScsiCommand : uint8_t {
// CD-ROM specific commands
READ_TOC = 0x43,
SET_CD_SPEED = 0xBB,
PLAY_CD = 0xBC,
READ_CD = 0xBE,
// vendor specific commands
VENDOR_09 = 0x09,
EJECT = 0xC0,
READ_CDDA = 0xD8, //TOSHIBA
READ_CDDA_MSF = 0xD9, //TOSHIBA
};
/** START STOP UNIT command flags in CDB byte 4. */
namespace ScsiStartStopUnit {
enum : uint8_t {
START = 1 << 0,
LOAD_EJECT = 1 << 1,
};
}
enum ScsiSense : uint8_t {
enum ScsiSense : int {
NO_SENSE = 0x0,
RECOVERED = 0x1,
NOT_READY = 0x2,
@@ -199,7 +166,7 @@ enum ScsiSense : uint8_t {
COMPLETED = 0xF
};
enum ScsiError : uint8_t {
enum ScsiError : int {
NO_ERROR = 0x00,
NO_SECTOR = 0x01,
WRITE_FAULT = 0x03,
@@ -209,61 +176,8 @@ enum ScsiError : uint8_t {
INVALID_CDB = 0x24,
INVALID_LUN = 0x25,
WRITE_PROTECT = 0x27,
MEDIUM_CHANGED = 0x28,
SAVING_NOT_SUPPORTED = 0x39,
MEDIUM_NOT_PRESENT = 0x3A,
REMOVAL_PREVENTED = 0x53,
};
/** SCSI device types used in INQUIRY. */
namespace ScsiDevType {
enum : uint8_t {
DIRECT_ACCESS = 0,
SEQ_ACCESS = 1,
PRINTER = 2,
PROCESSOR = 3,
WRITE_ONCE = 4,
CD_ROM = 5,
SCANNER = 6,
OPT_MEMORY = 7,
MEDIUM_CHANGER = 8,
COMMUNICATION = 9,
UNKNOWN = 0x1F
};
};
/** SCSI device capacity flags. */
enum : uint8_t {
CAP_REL_ADDR = 1 << 7, // device supports relative addressing
CAP_W32_XFER = 1 << 6, // device supports 32-bit wide transfers
CAP_W16_XFER = 1 << 5, // device supports 16-bit wide transfers
CAP_SYNC_XFER = 1 << 4, // device supports synchronous transfers
CAP_LINKED_CMDS = 1 << 3, // device supports linked commands
CAP_CMD_QUEUE = 1 << 1, // device supports command queuing
CAP_CMD_SRST = 1 << 0, // device supports soft resets
};
/** Page control values for MODE SENSE. */
namespace PageControl {
enum : uint8_t {
CURRENT_VALUES = 0,
CHANGEABLE_VALUES = 1,
DEFAULT_VALUES = 2,
SAVED_VALUES = 3
};
};
/** Page numbers for MODE SENSE and MODE SELECT. */
enum ModePage : uint8_t {
ERROR_RECOVERY = 0x1,
DEV_FORMAT_PARAMS = 0x3,
RIGID_DISK_GEOMETRY = 0x4,
CDROM_PARAMS = 0xD,
CDROM_AUDIO_CONTROL = 0xE,
POWER_CONDITION = 0x1A,
CDROM_CAPABILITIES = 0x2A,
VENDOR_PAGE_31 = 0x31,
ALL_PAGES = 0x3F,
};
/** Standard SCSI bus timing values measured in ns. */
@@ -278,65 +192,34 @@ constexpr auto SCSI_MAX_DEVS = 8;
class ScsiBus;
class ScsiPhysDevice : public ScsiPhysInterface, public HWComponent {
typedef std::function<void()> action_callback;
class ScsiDevice : public HWComponent {
public:
ScsiPhysDevice(std::string name, int my_id) : ScsiPhysInterface(PHY_ID_SCSI) {
ScsiDevice(std::string name, int my_id) {
this->set_name(name);
supports_types(HWCompType::SCSI_DEV);
this->scsi_id = my_id;
this->lun = 0,
this->cur_phase = ScsiPhase::BUS_FREE;
}
~ScsiPhysDevice() = default;
// ScsiPhysInterface methods
bool last_sel_has_attention() override {
return this->last_selection_has_attention;
}
uint8_t last_sel_msg() override {
return this->last_selection_message;
}
void set_xfer_len(uint64_t len) override {
this->xfer_len = len;
}
void set_buffer(uint8_t *bptr) override {
this->buf_ptr = bptr;
}
void set_read_more_data_cb(more_data_cb_t cb) override {
this->read_more_data = cb;
}
void set_write_more_data_cb(more_data_cb_t cb) override {
this->write_more_data = cb;
}
void set_post_xfer_action(action_callback cb) override {
this->post_xfer_action = cb;
}
void set_status(uint8_t status_code, uint8_t sense_key) override {
this->status = status_code;
}
void set_lock_state(bool is_locked) override {
this->eject_allowed = !is_locked;
}
~ScsiDevice() = default;
virtual void notify(ScsiNotification notif_type, int param);
virtual void next_step();
virtual void prepare_xfer();
virtual void switch_phase(const int new_phase) override;
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
virtual void switch_phase(const int new_phase);
virtual bool allow_phase_change();
virtual bool has_data() { return this->data_size != 0; }
virtual 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;
virtual void process_message();
@@ -344,6 +227,8 @@ public:
this->bus_obj = bus_obj_ptr;
}
void report_error(uint8_t sense_key, uint8_t asc);
protected:
uint8_t cmd_buf[16] = {};
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
@@ -352,14 +237,18 @@ protected:
int initiator_id;
int cur_phase;
uint8_t* data_ptr = nullptr;
uint8_t* buf_ptr = nullptr;
int xfer_len;
int data_size;
int incoming_size;
uint8_t status;
bool eject_allowed = true;
bool last_selection_has_attention = false;
int sense;
int asc;
int ascq;
int sksv;
int field;
bool valid;
bool last_selection_has_atention = false;
uint8_t last_selection_message = 0;
ScsiBus* bus_obj;
@@ -367,11 +256,6 @@ protected:
action_callback pre_xfer_action = nullptr;
action_callback post_xfer_action = nullptr;
more_data_cb_t read_more_data = {};
more_data_cb_t write_more_data = {};
TimerInfo bus_settle_timer;
};
/** This class provides a higher level abstraction for the SCSI bus. */
@@ -391,7 +275,7 @@ public:
void attach_scsi_devices(const std::string bus_suffix);
// low-level state management
void register_device(int id, ScsiPhysDevice* dev_obj);
void register_device(int id, ScsiDevice* dev_obj);
int current_phase() const {
return this->cur_phase;
@@ -426,13 +310,14 @@ public:
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);
protected:
void change_bus_phase(int initiator_id);
private:
// SCSI devices registered with this bus
std::array<ScsiPhysDevice*, SCSI_MAX_DEVS> devices;
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
// per-device state of the control lines
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
-294
View File
@@ -1,294 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/memaccess.h>
#include <devices/common/scsi/scsiblockcmds.h>
#include <loguru.hpp>
ScsiBlockCmds::ScsiBlockCmds() {
this->enable_cmd(ScsiCommand::READ_6);
this->enable_cmd(ScsiCommand::READ_10);
this->enable_cmd(ScsiCommand::READ_12);
this->enable_cmd(ScsiCommand::WRITE_6);
this->enable_cmd(ScsiCommand::WRITE_10);
this->enable_cmd(ScsiCommand::WRITE_12);
this->enable_cmd(ScsiCommand::START_STOP_UNIT);
this->enable_cmd(ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL);
this->enable_cmd(ScsiCommand::READ_CAPACITY);
this->add_page_getter(this, ModePage::ERROR_RECOVERY,
&ScsiBlockCmds::get_error_recovery_page);
}
void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags,
uint8_t density_code, bool is_apple_compliant)
{
this->medium_type = medium_type;
this->device_flags = dev_flags;
phy_impl->set_read_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->blk_dev->get_remaining_size()) {
*dsize = this->blk_dev->read_more();
*dptr = this->blk_dev->get_cache_ptr();
return true;
} else
return false;
}
);
if (this->blk_dev->medium_writable()) {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) -> bool {
if (this->blk_dev->get_remaining_size()) {
*dsize = this->blk_dev->write_more();
*dptr = this->blk_dev->get_cache_ptr();
return true;
} else
return false;
}
);
} else {
phy_impl->set_write_more_data_cb(
[this](int* dsize, uint8_t** dptr) {
return false;
}
);
}
if (is_apple_compliant)
this->add_page_getter(this, 0x30, &ScsiBlockCmds::get_apple_copyright_page);
}
void ScsiBlockCmds::process_command() {
if (!this->ready_for_command()) {
phy_impl->switch_phase(ScsiPhase::STATUS);
return;
}
int next_phase;
// use non-disk buffer by default
phy_impl->set_buffer(this->buf_ptr);
switch(this->cdb_ptr[0]) {
case ScsiCommand::READ_6:
case ScsiCommand::READ_10:
case ScsiCommand::READ_12:
next_phase = this->read();
break;
case ScsiCommand::WRITE_6:
case ScsiCommand::WRITE_10:
case ScsiCommand::WRITE_12:
next_phase = this->write();
break;
case ScsiCommand::START_STOP_UNIT:
next_phase = this->start_stop_unit();
break;
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
phy_impl->set_lock_state((this->cdb_ptr[4] & 1) != 0);
next_phase = ScsiPhase::STATUS;
break;
case ScsiCommand::READ_CAPACITY:
next_phase = this->read_capacity();
break;
default:
ScsiCommonCmds::process_command();
return;
}
phy_impl->switch_phase(next_phase);
}
int ScsiBlockCmds::read() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for READ_6
if (this->cdb_ptr[0] == ScsiCommand::READ_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "READ: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->blk_dev->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->blk_dev->read_begin(nblocks));
phy_impl->set_buffer(this->blk_dev->get_cache_ptr());
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::write() {
int nblocks = this->get_xfer_len();
// special case: zero transfer length means 256 blocks for WRITE_6
if (this->cdb_ptr[0] == ScsiCommand::WRITE_6) {
if (!nblocks)
nblocks = 256;
} else {
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "WRITE: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
}
// go directly to the STATUS phase if nblocks = 0
if (!nblocks) {
LOG_F(WARNING, "WRITE: skip data transfer because nblocks = 0");
return ScsiPhase::STATUS;
}
this->blk_dev->set_fpos(this->get_lba());
phy_impl->set_xfer_len(this->blk_dev->write_begin(nblocks));
phy_impl->set_buffer(this->blk_dev->get_cache_ptr());
phy_impl->set_post_xfer_action([this]() {
this->blk_dev->write_cache();
}
);
return ScsiPhase::DATA_OUT;
}
int ScsiBlockCmds::start_stop_unit() {
if (this->cdb_ptr[4] & ScsiStartStopUnit::START) {
if (this->cdb_ptr[4] & ScsiStartStopUnit::LOAD_EJECT)
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
} else {
if (this->cdb_ptr[4] & ScsiStartStopUnit::LOAD_EJECT)
this->eject_medium();
}
return ScsiPhase::STATUS;
}
void ScsiBlockCmds::eject_medium() {
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
}
int ScsiBlockCmds::read_capacity() {
uint32_t lba = this->get_lba();
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
LOG_F(WARNING, "READ_CAPACITY: RelAdr bit set but it should not be");
this->set_field_pointer(1);
this->set_bit_pointer(0);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
if (!(this->cdb_ptr[8] & 1) && lba) {
LOG_F(ERROR, "READ_CAPACITY: non-zero LBA for PMI=0");
this->set_field_pointer(2);
this->invalid_cdb();
return ScsiPhase::STATUS;
}
uint32_t last_lba = (uint32_t)std::min(
this->blk_dev->get_size_in_blocks() - 1, (uint64_t)0xFFFFFFFFU);
uint32_t blk_len = this->blk_dev->get_block_size();
WRITE_DWORD_BE_A(&this->buf_ptr[0], last_lba);
WRITE_DWORD_BE_A(&this->buf_ptr[4], blk_len);
phy_impl->set_xfer_len(8);
return ScsiPhase::DATA_IN;
}
int ScsiBlockCmds::format_block_descriptors(uint8_t* out_ptr) {
uint32_t nblocks = (uint32_t)std::min(
this->blk_dev->get_size_in_blocks(), (uint64_t)0xFFFFFFFFU);
WRITE_DWORD_BE_A(&out_ptr[0], nblocks);
WRITE_DWORD_BE_A(&out_ptr[4], (this->density_code << 24) |
(this->blk_dev->get_block_size() & 0xFFFFFF));
return 8;
}
int ScsiBlockCmds::get_error_recovery_page(uint8_t ctrl, uint8_t subpage,
uint8_t *out_ptr, int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 6;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memset(out_ptr, 0, page_size);
return page_size;
}
uint32_t ScsiBlockCmds::get_lba() {
int cmd_len = this->get_cdb_length(this->cdb_ptr[0]);
switch(cmd_len) {
case 6:
return ((this->cdb_ptr[1] & 0x1F) << 16) | READ_WORD_BE_A(&this->cdb_ptr[2]);
case 10:
case 12:
return READ_DWORD_BE_U(&this->cdb_ptr[2]);
default:
ABORT_F("unsupported command length %d in get_lba", cmd_len);
}
}
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
int ScsiBlockCmds::get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len)
{
if (subpage && subpage != 0xFFU)
return FORMAT_ERR_BAD_SUBPAGE;
if (ctrl == 3)
return FORMAT_ERR_BAD_CONTROL;
int page_size = 22;
if (page_size > avail_len)
return FORMAT_ERR_DATA_TOO_BIG;
std::memcpy(out_ptr, Apple_Copyright_Page_Data, page_size);
return page_size;
}
-77
View File
@@ -1,77 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SCSI_BLOCK_COMMANDS_H
#define SCSI_BLOCK_COMMANDS_H
#include <devices/common/scsi/scsi.h>
#include <devices/common/scsi/scsicommoncmds.h>
#include <devices/storage/blockstoragedevice.h>
#include <cinttypes>
/** Base class for SCSI block device commands. */
class ScsiBlockCmds : public ScsiCommonCmds {
public:
ScsiBlockCmds();
~ScsiBlockCmds() = default;
void set_phys_block_dev(BlockStorageDevice *blk_dev_obj) {
this->blk_dev = blk_dev_obj;
}
void init_block_device(uint8_t medium_type, uint8_t dev_flags,
uint8_t density_code, bool is_apple_compliant);
virtual int read();
virtual int write();
virtual int start_stop_unit();
virtual int read_capacity();
void get_medium_type(uint8_t& medium_type, uint8_t& dev_flags) override {
medium_type = this->medium_type;
dev_flags = this->device_flags;
}
int format_block_descriptors(uint8_t* out_ptr) override;
int get_error_recovery_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len);
// this page is supported by a bunch of Apple-certified HD and CD-ROM devices
// so implement it here for reusability
int get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
int avail_len);
protected:
virtual void process_command() override;
virtual void eject_medium();
uint32_t get_lba();
BlockStorageDevice* blk_dev = nullptr;
uint8_t medium_type = 0;
uint8_t device_flags = 0;
uint8_t density_code = 0;
};
#endif // SCSI_BLOCK_COMMANDS_H
+33 -59
View File
@@ -1,9 +1,9 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(You may also contact divingkxt or powermax2286 on Discord)
(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
@@ -31,7 +31,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes>
#include <sstream>
#include <vector>
ScsiBus::ScsiBus(const std::string name)
{
@@ -50,7 +49,7 @@ ScsiBus::ScsiBus(const std::string name)
this->target_id = -1;
}
void ScsiBus::register_device(int id, ScsiPhysDevice* dev_obj)
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
{
if (this->devices[id] != nullptr) {
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
@@ -299,6 +298,18 @@ void ScsiBus::target_next_step()
}
}
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
{
if (target_id < 0) {
LOG_F(ERROR, "%s: target_id is not set yet.", this->get_name().c_str());
}
else {
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
}
return true;
}
void ScsiBus::disconnect(int dev_id)
{
this->release_ctrl_lines(dev_id);
@@ -339,65 +350,28 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
}
}
int default_cdrom_id = -1;
std::string cdr_config = GET_STR_PROP("cdr_config");
if (!cdr_config.empty()) {
std::string bus_id;
uint32_t dev_num;
parse_device_path(cdr_config, bus_id, dev_num);
// Only consume SCSI paths; other buses handle their own CD-ROM configuration.
if (bus_id.starts_with("Scsi")) {
auto bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name_optional(bus_id));
if (!bus_obj)
ABORT_F("cdr_config device path %s does not specify a known SCSI bus", cdr_config.c_str());
if (dev_num >= SCSI_MAX_DEVS)
ABORT_F("Invalid SCSI ID in cdr_config device path %s", cdr_config.c_str());
if (bus_obj == this) {
if (this->devices[dev_num])
ABORT_F("%s: cdr_config SCSI ID %u is already occupied", bus_id.c_str(), dev_num);
default_cdrom_id = dev_num;
}
}
}
image_path = GET_STR_PROP("cdr_img" + bus_suffix);
std::vector<std::string> cdrom_paths;
if (!image_path.empty()) {
// Keep empty entries, including the last one, as empty CD-ROM drives.
size_t start = 0;
size_t end;
do {
end = image_path.find(':', start);
cdrom_paths.push_back(image_path.substr(start, end - start));
start = end + 1;
} while (end != std::string::npos);
} else if (default_cdrom_id >= 0) {
cdrom_paths.push_back("");
}
for (const auto& path : cdrom_paths) {
if (default_cdrom_id >= 0) {
scsi_id = default_cdrom_id;
default_cdrom_id = -1;
} else {
// do two passes because we start at ID 3.
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);
if (!path.empty() && !scsi_device->insert_image(path))
ABORT_F("Could not insert CD-ROM image, %s", path.c_str());
}
else {
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.",
this->get_name().c_str(), path.c_str());
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());
}
}
}
}
Loaded 100 of 224 files, more files were not shown because too many files have changed in this diff. Show more