mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
305
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3040d86f1f | ||
|
|
f5dbb4fa43 | ||
|
|
79f1edc102 | ||
|
|
3ecf59233c | ||
|
|
baeed79f12 | ||
|
|
f1c46cdc6d | ||
|
|
0779a171e0 | ||
|
|
b9e94b20b4 | ||
|
|
fd9899ae87 | ||
|
|
ff911cc056 | ||
|
|
7af1235b8e | ||
|
|
06ea4a844e | ||
|
|
813350f14a | ||
|
|
4bcd96e6b1 | ||
|
|
83775309e9 | ||
|
|
2a3b6d9cb7 | ||
|
|
538970d659 | ||
|
|
fce52eacfb | ||
|
|
a832d9cf90 | ||
|
|
e5b8ff49e4 | ||
|
|
5e7c660622 | ||
|
|
d9d7257d46 | ||
|
|
8cecc9b20b | ||
|
|
42e617fde9 | ||
|
|
017a4a48b1 | ||
|
|
bf1c9654c4 | ||
|
|
6c48fc1f91 | ||
|
|
e259d8e2b2 | ||
|
|
3d25cc592d | ||
|
|
da7c8a4579 | ||
|
|
bf2f7e5217 | ||
|
|
5f49182c5b | ||
|
|
d4cb1fe872 | ||
|
|
f8a2b19947 | ||
|
|
2db1cc160e | ||
|
|
b81920fcb2 | ||
|
|
01eb1356f5 | ||
|
|
f964359738 | ||
|
|
36420c55b9 | ||
|
|
aef197841b | ||
|
|
e557bc1709 | ||
|
|
6a53025df9 | ||
|
|
9e70b3ce3f | ||
|
|
398ab2f7f6 | ||
|
|
c5d24e98a3 | ||
|
|
37da4d3162 | ||
|
|
3e9397c478 | ||
|
|
3daa2b73d1 | ||
|
|
79a06c55a4 | ||
|
|
9561edcea2 | ||
|
|
ba34d78a7c | ||
|
|
ecf8e4f1e1 | ||
|
|
2c2ad48a22 | ||
|
|
8d1d22416a | ||
|
|
103a06536c | ||
|
|
f1472e6f0e | ||
|
|
4d9f6f33ee | ||
|
|
d8aa33f207 | ||
|
|
293f594cdc | ||
|
|
f3a5e48216 | ||
|
|
dd5ba1dcfc | ||
|
|
d3483523d6 | ||
|
|
67418b07b0 | ||
|
|
cbe840ff3f | ||
|
|
290c575503 | ||
|
|
19c9266bbe | ||
|
|
811951ab91 | ||
|
|
a3c6d25cc5 | ||
|
|
3ae509f83d | ||
|
|
44fa69be65 | ||
|
|
0a3277b286 | ||
|
|
b2660e2920 | ||
|
|
92bb6d1054 | ||
|
|
619acb0109 | ||
|
|
0e2ffa7863 | ||
|
|
0e03cac082 | ||
|
|
8f3f7cfe70 | ||
|
|
e70ab21787 | ||
|
|
da7d2f9a92 | ||
|
|
d2950ae319 | ||
|
|
0e589ce1f6 | ||
|
|
2f9c2408b2 | ||
|
|
375749c48a | ||
|
|
fdb17a014b | ||
|
|
c5a9f949c9 | ||
|
|
54a1eb49f7 | ||
|
|
b665629168 | ||
|
|
6407f1a566 | ||
|
|
5abd37530d | ||
|
|
0f14a075cc | ||
|
|
fcc912e1a8 | ||
|
|
d94c30a743 | ||
|
|
14b17a6e25 | ||
|
|
b291c28b35 | ||
|
|
3f16b18bbd | ||
|
|
b63b658343 | ||
|
|
a68bd5b07e | ||
|
|
767811b952 | ||
|
|
30d95e1409 | ||
|
|
4138074789 | ||
|
|
41f4af948f | ||
|
|
e4acb57429 | ||
|
|
745f5c85a9 | ||
|
|
60825ce664 | ||
|
|
ee1b1dd873 | ||
|
|
3c1308d006 | ||
|
|
c28408fd80 | ||
|
|
3367db4494 | ||
|
|
ff8e98c26c | ||
|
|
fe80d14e8a | ||
|
|
a8dfc8d15c | ||
|
|
0f4b4c0f67 | ||
|
|
3f6f05694f | ||
|
|
cfde7ee045 | ||
|
|
c8ae8e7407 | ||
|
|
73e9a72f3d | ||
|
|
ad9a9dbf80 | ||
|
|
ab1f9c59bc | ||
|
|
7e8526aa52 | ||
|
|
240f9e194e | ||
|
|
5a6a8fb26f | ||
|
|
2a85161b3a | ||
|
|
3ab8e5c213 | ||
|
|
1b3a6b062c | ||
|
|
f0bb36b9da | ||
|
|
c385b131d7 | ||
|
|
4bfb352b63 | ||
|
|
b50a04fc79 | ||
|
|
dbcdbe7eb3 | ||
|
|
fe424df9a0 | ||
|
|
ca7a8e8163 | ||
|
|
8bcd8829cb | ||
|
|
7a1babc5e9 | ||
|
|
883c404601 | ||
|
|
d94bf01163 | ||
|
|
20ed0f7620 | ||
|
|
32912aac52 | ||
|
|
dc7a97abbf | ||
|
|
b1fd435e2e | ||
|
|
afa7458131 | ||
|
|
ecb397de57 | ||
|
|
d0260d1fdf | ||
|
|
2f951acdee | ||
|
|
9dc3cb978e | ||
|
|
621150f2f4 | ||
|
|
ffade95fb9 | ||
|
|
290d8d3fcd | ||
|
|
265615e9f3 | ||
|
|
b5693f29ce | ||
|
|
cb48f59eeb | ||
|
|
b65c228593 | ||
|
|
1ac01add3a | ||
|
|
09c1248be7 | ||
|
|
25860025b0 | ||
|
|
a3bc3a4d04 | ||
|
|
807f961b56 | ||
|
|
1d75f7ba38 | ||
|
|
04e0dd188c | ||
|
|
008413817a | ||
|
|
0bf6f8b47f | ||
|
|
7aacd5c703 | ||
|
|
688ec133c5 | ||
|
|
ed28c8e9a6 | ||
|
|
e689d62067 | ||
|
|
52631da7c7 | ||
|
|
5bfc9a3f75 | ||
|
|
94ee77e9a4 | ||
|
|
b3975cc11a | ||
|
|
f7b5a440e8 | ||
|
|
798af27514 | ||
|
|
dd1cc7da61 | ||
|
|
39a4c7fc05 | ||
|
|
a2b0ca42d3 | ||
|
|
8955be1eaa | ||
|
|
4931bcb6ff | ||
|
|
9c003a8b64 | ||
|
|
00068dd4af | ||
|
|
dfea8fa2cd | ||
|
|
07f781bf56 | ||
|
|
91f5ccc3f9 | ||
|
|
995da89bda | ||
|
|
d1d496fda9 | ||
|
|
bf7fc5fb5a | ||
|
|
e275635697 | ||
|
|
d8d7ebd40c | ||
|
|
fa6abacf4e | ||
|
|
ef8c83108c | ||
|
|
0b32714200 | ||
|
|
c6f17a846b | ||
|
|
fb02b15063 | ||
|
|
ff3e66ecd7 | ||
|
|
626497bdc0 | ||
|
|
0b018bd0a4 | ||
|
|
9505745006 | ||
|
|
b62bb5ffa4 | ||
|
|
46901d8d03 | ||
|
|
cb1e318a28 | ||
|
|
93bca96794 | ||
|
|
917eec6ff4 | ||
|
|
954a277bb3 | ||
|
|
202446025a | ||
|
|
f2a9f3cb56 | ||
|
|
ad4515721b | ||
|
|
3decd4b9fc | ||
|
|
16117e6c60 | ||
|
|
9bae84ff07 | ||
|
|
4ca03953d7 | ||
|
|
dd31610013 | ||
|
|
8b2c0b0de9 | ||
|
|
6075807998 | ||
|
|
9d5373120d | ||
|
|
6c29738441 | ||
|
|
a8ff30ef36 | ||
|
|
20dfe798ac | ||
|
|
1a8d691777 | ||
|
|
34b4d6387d | ||
|
|
9ca3e5e870 | ||
|
|
0d25f6dc33 | ||
|
|
2735449c75 | ||
|
|
6092882a45 | ||
|
|
345bcf8a73 | ||
|
|
6e18241be6 | ||
|
|
a9fcde836c | ||
|
|
b52a7bebbc | ||
|
|
6033f75521 | ||
|
|
2ea8fee204 | ||
|
|
25a5f193ba | ||
|
|
d9bcb47beb | ||
|
|
398e0b025d | ||
|
|
cbff26539a | ||
|
|
8a280f71ab | ||
|
|
3545296e3a | ||
|
|
b182e01218 | ||
|
|
200a2aa9a7 | ||
|
|
470c9a32f5 | ||
|
|
44343ad591 | ||
|
|
022d5e4e00 | ||
|
|
3dde616c57 | ||
|
|
b82dae7ad6 | ||
|
|
924cc5ed97 | ||
|
|
0570513ff1 | ||
|
|
fd8d89b711 | ||
|
|
17f13e8eb3 | ||
|
|
8e9ee07e9b | ||
|
|
129c5053f6 | ||
|
|
d29e15332c | ||
|
|
7abc8afc97 | ||
|
|
4c3989fa13 | ||
|
|
6a3654e851 | ||
|
|
7c29e41fae | ||
|
|
7e07919d7c | ||
|
|
7d4ebf5bf1 | ||
|
|
79c9b5f63e | ||
|
|
0fee0a5270 | ||
|
|
60d4750d54 | ||
|
|
213dd4c16e | ||
|
|
0d22d5cbd8 | ||
|
|
140c9adb0c | ||
|
|
489bd0dfcf | ||
|
|
e75ee8d32a | ||
|
|
769ef49f67 | ||
|
|
e0677a8a1f | ||
|
|
356e74f8c2 | ||
|
|
3e8121c1f5 | ||
|
|
c2df2e4ad2 | ||
|
|
df36ad8369 | ||
|
|
ad2abf4433 | ||
|
|
0ca4e14195 | ||
|
|
5883b39c2b | ||
|
|
1b7338960f | ||
|
|
d693b0f443 | ||
|
|
5c646e8270 | ||
|
|
65c5d2425e | ||
|
|
f2676e0324 | ||
|
|
48adf99690 | ||
|
|
3c0432053b | ||
|
|
ebc2fcf216 | ||
|
|
25c74f76d2 | ||
|
|
e3839bdea6 | ||
|
|
742a810624 | ||
|
|
dbc10ab027 | ||
|
|
383f6dd9a1 | ||
|
|
be04300846 | ||
|
|
80c1ebe57d | ||
|
|
5996358308 | ||
|
|
380827e09b | ||
|
|
c4be881d52 | ||
|
|
ae56bb3743 | ||
|
|
fd5bcddcb7 | ||
|
|
af8124a525 | ||
|
|
8105defb0b | ||
|
|
7429a4111e | ||
|
|
a537d09c63 | ||
|
|
7fdb11d64f | ||
|
|
5567041c2b | ||
|
|
c94cfe0d40 | ||
|
|
73d5a2374b | ||
|
|
017f559e90 | ||
|
|
29f9ab14ee | ||
|
|
17b2a1a6e4 | ||
|
|
77f1f72122 | ||
|
|
03ec9d9589 | ||
|
|
b813a080da | ||
|
|
2b0b926f52 | ||
|
|
0ac0a5b77e |
No files matched your search
+241
-219
@@ -4,262 +4,284 @@ 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:
|
||||
build-linux:
|
||||
# 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@v3
|
||||
- name: install_dependencies
|
||||
- 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
|
||||
run: |
|
||||
sudo apt-get update -y -qq
|
||||
sudo apt-get install libsdl2-dev
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
sudo apt-get install -y -qq libsdl2-dev ninja-build ccache
|
||||
- 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
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
|
||||
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
|
||||
- name: Build
|
||||
# Build your program with the given configuration
|
||||
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
|
||||
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
|
||||
# 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}}
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
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:
|
||||
cache-name: [msys64-cache]
|
||||
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:
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 45
|
||||
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@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
|
||||
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
|
||||
- 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
|
||||
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)"
|
||||
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 }}
|
||||
|
||||
|
||||
vsbuild-CLANG:
|
||||
build-windows-vsbuild:
|
||||
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@v3
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
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 }}
|
||||
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
|
||||
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'
|
||||
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 -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
|
||||
ccache --show-stats
|
||||
if %errorlevel% neq 0 echo ccache stats unavailable
|
||||
- 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.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 }}
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
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
|
||||
name: DingusPPC-${{ matrix.upload_suffix }}
|
||||
path: ${{github.workspace}}/build/bin
|
||||
retention-days: ${{ github.event_name == 'pull_request' && 7 || 30 }}
|
||||
@@ -41,6 +41,7 @@ ehthumbs.db
|
||||
|
||||
# IDE ignores
|
||||
build
|
||||
build*/
|
||||
build-*
|
||||
*.dir
|
||||
*.user
|
||||
|
||||
+72
-6
@@ -84,6 +84,19 @@ 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/")
|
||||
@@ -138,6 +151,16 @@ 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>
|
||||
@@ -145,9 +168,48 @@ 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.4b"
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING "a1.0.4b"
|
||||
MACOSX_BUNDLE_EXECUTABLE_NAME "DingusPPC"
|
||||
# Placeholder for the icon file:
|
||||
# MACOSX_BUNDLE_ICON_FILE "icon.icns"
|
||||
)
|
||||
|
||||
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 SDL2::SDL2main cubeb)
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 cubeb)
|
||||
target_compile_definitions(dingusppc PRIVATE SDL_MAIN_HANDLED)
|
||||
elseif (EMSCRIPTEN)
|
||||
target_link_libraries(dingusppc PRIVATE
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
|
||||
@@ -159,7 +221,7 @@ elseif (EMSCRIPTEN)
|
||||
"-s EXPORT_NAME=emulator"
|
||||
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
|
||||
else()
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
@@ -183,9 +245,10 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 cubeb)
|
||||
target_compile_definitions(testppc PRIVATE SDL_MAIN_HANDLED)
|
||||
else()
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2main SDL2::SDL2 cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
@@ -208,8 +271,11 @@ if (DPPC_BUILD_BENCHMARKS)
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
|
||||
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
target_compile_definitions(bench1 PRIVATE SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 PRIVATE capstone)
|
||||
@@ -223,7 +289,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:${PROJECT_NAME}>)
|
||||
"$<TARGET_FILE_DIR:$<TARGET_PROPERTY:NAME>>")
|
||||
endif()
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
|
||||
@@ -4,6 +4,7 @@ General
|
||||
* Test your contributions to assure they do not break existing functionality.
|
||||
* Commits to the repo should be done by portions; that is, by individual functionalities of the program.
|
||||
* Don't use any disrespectful language.
|
||||
* Do not use artificial intelligence to make contributions. This is due to authorship issues and licensing issues regarding AI usage.
|
||||
|
||||
Code
|
||||
=======
|
||||
|
||||
+19
-12
@@ -4,10 +4,14 @@
|
||||
## Developers
|
||||
|
||||
- divingkatae
|
||||
- maximumspatium
|
||||
- joevt
|
||||
- mihaip
|
||||
- kkaisershot
|
||||
- maximumspatium
|
||||
- mihaip
|
||||
|
||||
## ATI Rage Support (WIP)
|
||||
|
||||
- Cacodemon345
|
||||
|
||||
## NT4/PPC fork
|
||||
|
||||
@@ -15,21 +19,24 @@
|
||||
|
||||
## DevOps
|
||||
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
- leap0x7b
|
||||
- sdkmap
|
||||
- alicela1n
|
||||
- calmsacibis995
|
||||
- claunia
|
||||
- dressupgeekout
|
||||
- kth5
|
||||
- dyharlan
|
||||
- roytam1
|
||||
- mrpapersonic
|
||||
- Randrianasulu
|
||||
- erichelgeson
|
||||
- jarz
|
||||
- kth5
|
||||
- leap0x7b
|
||||
- lefp
|
||||
- mathstuf
|
||||
- mrpapersonic
|
||||
- Randrianasulu
|
||||
- roytam1
|
||||
- sdkmap
|
||||
- seanm
|
||||
- erichelgeson
|
||||
- alicela1n
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
# DingusPPC
|
||||
|
||||
Written by divingkatae and maximumspatium
|
||||
Written by The DingusPPC Development Team
|
||||
|
||||
(who are Divingkatae, maximumspatium, joevt, mihaip, kkaisershot, Cacodemon345, Wack0, et. al. Check CREDITS.md for more info)
|
||||
|
||||
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 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
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
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.
|
||||
|
||||
## How to Use
|
||||
|
||||
This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
There are a few command line arguments one can enter when starting the program.
|
||||
|
||||
```
|
||||
-r, --realtime
|
||||
@@ -36,23 +44,34 @@ Enter the interactive debugger.
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
Specifies the Boot ROM path. It otherwise looks for bootrom.bin.
|
||||
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
Specify machine ID. Otherwise, the emulator will attempt to determine machine ID from the boot rom otherwise.
|
||||
|
||||
As of now, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
|
||||
As of now, the most complete machines are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3 Beige.
|
||||
|
||||
To go into to the debugger regardless of how you started the emulator, press Control and C on the terminal window.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
At minimum, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
Clone the repository using the appropriate command:
|
||||
|
||||
```
|
||||
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
|
||||
```
|
||||
@@ -65,27 +84,43 @@ For SDL2, Linux users may also have to run:
|
||||
sudo apt install libsdl2-dev
|
||||
```
|
||||
|
||||
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
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.
|
||||
|
||||
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 dingusppc
|
||||
make
|
||||
```
|
||||
You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
For Raspbian, you may also need the following command:
|
||||
You may specify another build type using the variable `CMAKE_BUILD_TYPE`.
|
||||
Each build type should have its own build folder.
|
||||
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
make
|
||||
```
|
||||
|
||||
## 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
|
||||
@@ -100,7 +135,3 @@ make testppc
|
||||
- 2 GB of RAM
|
||||
- 2 GB of Hard Disk Space
|
||||
- Graphics Card with a minimum resolution of 800*600
|
||||
|
||||
## Compiler Requirements
|
||||
|
||||
- Any C++20 compatible compiler
|
||||
+51
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -115,6 +115,54 @@ 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];
|
||||
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
~MouseEvent() = default;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t xrel;
|
||||
uint32_t yrel;
|
||||
int32_t xrel;
|
||||
int32_t yrel;
|
||||
uint32_t xabs;
|
||||
uint32_t yabs;
|
||||
uint8_t buttons_state;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -492,6 +492,8 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
|
||||
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:
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -26,27 +26,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MEM_ACCESS_H
|
||||
#define MEM_ACCESS_H
|
||||
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <core/endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A( addr) (BYTESWAP_16(*((uint16_t*)(addr))))
|
||||
#include <cinttypes>
|
||||
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)(addr))))
|
||||
|
||||
/* read an aligned big-endian QWORD (64bit) */
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)(addr))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A( addr) (*(uint16_t*)(addr))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t*)(addr))
|
||||
|
||||
/* read an aligned little-endian QWORD (64bit) */
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t*)(addr))
|
||||
#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
|
||||
#undef __BIG_ENDIAN__
|
||||
#define __BIG_ENDIAN__ 1
|
||||
#else
|
||||
#undef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__ 1
|
||||
#endif
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U( addr) ((((uint8_t*)(addr))[0] << 8) | ((uint8_t*)(addr))[1])
|
||||
@@ -78,15 +69,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
(uint64_t(((uint8_t*)(addr))[3]) << 24) | ( ((uint8_t*)(addr))[2] << 16) | \
|
||||
( ((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] )
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A( addr, val) (*((uint16_t*)(addr)) = BYTESWAP_16(val))
|
||||
|
||||
/* write an aligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)(addr)) = BYTESWAP_32(val))
|
||||
|
||||
/* write an aligned big-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)(addr)) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
@@ -116,15 +98,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
((uint8_t*)(addr))[7] = (uint8_t)(val) ; \
|
||||
} while (0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_A( addr, val) (*((uint16_t*)(addr)) = (val))
|
||||
|
||||
/* write an aligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)(addr)) = (val))
|
||||
|
||||
/* write an aligned little-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)(addr)) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
@@ -154,6 +127,44 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
((uint8_t*)(addr))[7] = ((uint64_t)(val) >> 56); \
|
||||
} while (0)
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#define READ_WORD_BE_A( addr) (BYTESWAP_16(*((uint16_t*)(addr))))
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)(addr))))
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)(addr))))
|
||||
#define READ_WORD_LE_A( addr) (*(uint16_t*)(addr))
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t*)(addr))
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t*)(addr))
|
||||
#define WRITE_WORD_BE_A( addr, val) (*((uint16_t*)(addr)) = BYTESWAP_16(val))
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)(addr)) = BYTESWAP_32(val))
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)(addr)) = BYTESWAP_64(val))
|
||||
#define WRITE_WORD_LE_A( addr, val) (*((uint16_t*)(addr)) = (val))
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)(addr)) = (val))
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)(addr)) = (val))
|
||||
|
||||
#else // __BIG_ENDIAN__
|
||||
|
||||
#define READ_WORD_LE_A( addr) (BYTESWAP_16(*((uint16_t*)(addr))))
|
||||
#define READ_DWORD_LE_A(addr) (BYTESWAP_32(*((uint32_t*)(addr))))
|
||||
#define READ_QWORD_LE_A(addr) (BYTESWAP_64(*((uint64_t*)(addr))))
|
||||
#define READ_WORD_BE_A( addr) (*(uint16_t*)(addr))
|
||||
#define READ_DWORD_BE_A(addr) (*(uint32_t*)(addr))
|
||||
#define READ_QWORD_BE_A(addr) (*(uint64_t*)(addr))
|
||||
#define WRITE_WORD_LE_A( addr, val) (*((uint16_t*)(addr)) = BYTESWAP_16(val))
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)(addr)) = BYTESWAP_32(val))
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)(addr)) = BYTESWAP_64(val))
|
||||
#define WRITE_WORD_BE_A( addr, val) (*((uint16_t*)(addr)) = (val))
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)(addr)) = (val))
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)(addr)) = (val))
|
||||
|
||||
#endif // __BIG_ENDIAN__
|
||||
|
||||
/* read an aligned native-endian DWORD */
|
||||
#define READ_DWORD_NE_A READ_DWORD_LE_A // native-endian = little-endian for now
|
||||
|
||||
/* write an aligned native-endian DWORD */
|
||||
#define WRITE_DWORD_NE_A WRITE_DWORD_LE_A // native-endian = little-endian for now
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
perform byte swapping when necessary so that the source
|
||||
byte order remains unchanged. */
|
||||
@@ -232,4 +243,4 @@ inline void write_mem_rev(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MEM_ACCESS_H */
|
||||
#endif // MEM_ACCESS_H
|
||||
+38
-54
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -30,55 +30,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
uint32_t TimerManager::add_absolute_timer(uint64_t timeout_ns, uint64_t interval, timer_cb cb)
|
||||
{
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
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(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + delay;
|
||||
ti->timeout_ns = timeout_ns;
|
||||
ti->interval_ns = interval;
|
||||
ti->cb = cb;
|
||||
|
||||
@@ -95,7 +52,23 @@ uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb) {
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(this->get_time_now() + timeout, 0, cb);
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_immediate_timer(timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(0, 0, cb);
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
return TimerManager::add_absolute_timer(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);
|
||||
}
|
||||
|
||||
@@ -122,17 +95,18 @@ 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->id);
|
||||
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());
|
||||
cur_timer->timeout_ns = time_now + cur_timer->interval_ns;
|
||||
this->timer_queue.remove_by_id(cur_timer->id);
|
||||
uint64_t timeout_ns_new = timeout_ns + cur_timer->interval_ns;
|
||||
if (timeout_ns_new <= time_now)
|
||||
timeout_ns_new = time_now + cur_timer->interval_ns;
|
||||
cur_timer->timeout_ns = timeout_ns_new;
|
||||
this->timer_queue.push(cur_timer);
|
||||
} else {
|
||||
// remove one-shot timers from queue
|
||||
this->timer_queue.pop();
|
||||
}
|
||||
|
||||
this->cb_active = true;
|
||||
@@ -156,3 +130,13 @@ uint64_t TimerManager::process_timers()
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
return cur_timer->timeout_ns - time_now;
|
||||
}
|
||||
|
||||
void TimerManager::cancel_all_timers()
|
||||
{
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
while (!this->timer_queue.empty()) {
|
||||
cur_timer = this->timer_queue.top();
|
||||
LOG_F(WARNING, "Canceling timer id:%u ns:%llu", cur_timer->id, cur_timer->timeout_ns);
|
||||
this->timer_queue.pop();
|
||||
}
|
||||
}
|
||||
+11
-5
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -41,6 +41,7 @@ constexpr auto ONE_BILLION_NS = 1000000000;
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
typedef std::function<void()> timer_cb;
|
||||
typedef std::function<void()> notify_changes_cb;
|
||||
|
||||
/** Extend std::priority_queue as suggested here:
|
||||
https://stackoverflow.com/a/36711682
|
||||
@@ -51,6 +52,8 @@ class my_priority_queue : public std::priority_queue<T, Container, Compare> {
|
||||
public:
|
||||
bool remove_by_id(const uint32_t id){
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
if (this->empty())
|
||||
return false;
|
||||
auto el = this->top();
|
||||
if (el->id == id) {
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
@@ -100,7 +103,8 @@ typedef struct TimerInfo {
|
||||
class MyGtComparator {
|
||||
public:
|
||||
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns;
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns ||
|
||||
(l.get()->timeout_ns == r.get()->timeout_ns && l.get()->id > r.get()->id);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,7 +123,7 @@ public:
|
||||
}
|
||||
|
||||
// callback for acknowledging time changes
|
||||
void set_notify_changes_cb(const timer_cb &cb) {
|
||||
void set_notify_changes_cb(const notify_changes_cb &cb) {
|
||||
this->notify_timer_changes = cb;
|
||||
}
|
||||
|
||||
@@ -127,11 +131,13 @@ public:
|
||||
uint64_t current_time_ns() { return get_time_now(); }
|
||||
|
||||
// creating and cancelling timers
|
||||
uint32_t add_absolute_timer(uint64_t timeout_ns, uint64_t interval, timer_cb cb);
|
||||
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);
|
||||
void cancel_all_timers();
|
||||
|
||||
uint64_t process_timers();
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+12
-12
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -259,9 +259,9 @@ const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "de
|
||||
"", "sdr1", "srr0", "srr1", "", "", "", ""};
|
||||
|
||||
const char* spr_index8[32] = {
|
||||
"", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
|
||||
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
|
||||
"", "", "", "", "", "", "", "", "", "", "",
|
||||
"", "tbl_u", "tbu_u", "", "", "sprg0", "sprg1", "sprg2", "sprg3", "sprg4", "sprg5",
|
||||
"sprg6", "sprg7", "", "", "ear", "", "tbl", "tbu", "", "pvr"};
|
||||
|
||||
const char* spr_index16[32] = {
|
||||
"", "", "", "", "", "", "", "",
|
||||
@@ -1176,14 +1176,14 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "tlbld", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
} else if (index == 30) { /* tlbli - 603 only */
|
||||
} else if (index == 31) { /* tlbli - 603 only */
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "tlbli", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
}
|
||||
@@ -1250,10 +1250,10 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
} else {
|
||||
strcpy(opcode, opc_logic[index]);
|
||||
if (!strlen(opcode)) {
|
||||
if (index >= 16 || !strlen(opc_logic[index])) {
|
||||
opc_illegal(ctx);
|
||||
} else {
|
||||
strcpy(opcode, opc_logic[index]);
|
||||
if (rc_set) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1394,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
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+60
-8
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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,6 +37,9 @@ 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,
|
||||
@@ -45,7 +48,7 @@ enum EXEC_MODE:uint32_t {
|
||||
jit = 3
|
||||
};
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
typedef enum { big_end = 0, little_end = 1 } endian_switch;
|
||||
|
||||
typedef void (*PPCOpcode)(uint32_t opcode);
|
||||
|
||||
@@ -79,6 +82,9 @@ 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;
|
||||
@@ -106,6 +112,7 @@ enum SPR : int {
|
||||
SPRG1 = 273,
|
||||
SPRG2 = 274,
|
||||
SPRG3 = 275,
|
||||
EAR = 282,
|
||||
TBL_S = 284, // supervisor TBL
|
||||
TBU_S = 285, // supervisor TBU
|
||||
PVR = 287,
|
||||
@@ -114,6 +121,8 @@ enum SPR : int {
|
||||
PMC2 = 954,
|
||||
SIA = 955,
|
||||
MMCR1 = 956,
|
||||
PMC3 = 957,
|
||||
PMC4 = 958,
|
||||
SDA = 959,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
@@ -170,7 +179,6 @@ 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;
|
||||
@@ -187,6 +195,7 @@ 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 {
|
||||
@@ -351,7 +360,8 @@ enum Po_Cause : int {
|
||||
po_enter_debugger,
|
||||
po_entered_debugger,
|
||||
po_signal_interrupt,
|
||||
po_benchmark_exception
|
||||
po_benchmark_exception,
|
||||
po_endian_switch,
|
||||
};
|
||||
|
||||
extern bool power_on;
|
||||
@@ -365,6 +375,15 @@ 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;
|
||||
|
||||
// Make execution deterministic (ignore external input, used a fixed date, etc.)
|
||||
extern bool is_deterministic;
|
||||
|
||||
@@ -372,7 +391,13 @@ extern bool is_deterministic;
|
||||
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
|
||||
@@ -683,9 +708,36 @@ 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 */
|
||||
|
||||
#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 */
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -119,6 +119,7 @@ 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);
|
||||
@@ -138,6 +139,9 @@ 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. */
|
||||
}
|
||||
}
|
||||
@@ -161,6 +165,8 @@ 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";
|
||||
|
||||
+167
-20
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -58,6 +58,15 @@ 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;
|
||||
|
||||
@@ -65,6 +74,14 @@ bool power_on = false;
|
||||
Po_Cause power_off_reason = po_enter_debugger;
|
||||
|
||||
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
|
||||
|
||||
@@ -95,7 +112,6 @@ 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
|
||||
@@ -185,6 +201,11 @@ 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];
|
||||
@@ -214,6 +235,23 @@ void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_nex
|
||||
}
|
||||
}
|
||||
|
||||
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_on = false;
|
||||
power_off_reason = po_endian_switch;
|
||||
}
|
||||
#else
|
||||
if (newLE) {
|
||||
LOG_F(ERROR, "unsupported endian %s", newLE ? "LE" : "BE");
|
||||
power_on = false;
|
||||
power_off_reason = po_enter_debugger;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
|
||||
|
||||
/** Exception helpers. */
|
||||
@@ -251,7 +289,28 @@ 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() {
|
||||
@@ -297,7 +356,7 @@ typedef enum {
|
||||
} ppc_exec_type_t;
|
||||
|
||||
// inner interpreter loop
|
||||
template <ppc_exec_type_t exec_type>
|
||||
template <ppc_exec_type_t exec_type, endian_switch endian>
|
||||
static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
uint64_t max_cycles = 0;
|
||||
@@ -318,7 +377,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);
|
||||
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
|
||||
}
|
||||
|
||||
opcode = ppc_read_instruction(pc_real);
|
||||
@@ -327,23 +386,42 @@ 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) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
if (endian == big_end)
|
||||
INCPC((int)eb_start - (int)ppc_state.pc);
|
||||
else
|
||||
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start ATPCP); // &pcp
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else { [[likely]]
|
||||
} else [[likely]] {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
if (endian == big_end)
|
||||
INCPC(4);
|
||||
else
|
||||
pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
|
||||
}
|
||||
|
||||
if (exec_type == until)
|
||||
@@ -355,7 +433,8 @@ 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>(uint32_t start_addr, uint32_t size);
|
||||
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);
|
||||
|
||||
// outer interpreter loop
|
||||
void ppc_exec()
|
||||
@@ -367,7 +446,17 @@ void ppc_exec()
|
||||
}
|
||||
|
||||
while (power_on) {
|
||||
ppc_exec_inner<main>(0, 0);
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +471,7 @@ void ppc_exec_single()
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc ATPCP); // &pcp
|
||||
uint32_t opcode = ppc_read_instruction(pc_real);
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
g_icycles++;
|
||||
@@ -399,7 +488,8 @@ void ppc_exec_single()
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
|
||||
// inner interpreter loop
|
||||
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
|
||||
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);
|
||||
|
||||
// outer interpreter loop
|
||||
void ppc_exec_until(volatile uint32_t goal_addr) {
|
||||
@@ -410,7 +500,17 @@ void ppc_exec_until(volatile uint32_t goal_addr) {
|
||||
}
|
||||
|
||||
while (power_on) {
|
||||
ppc_exec_inner<until>(goal_addr, 0);
|
||||
#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;
|
||||
}
|
||||
if (ppc_state.pc == goal_addr)
|
||||
break;
|
||||
}
|
||||
@@ -419,7 +519,8 @@ 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>(uint32_t start_addr, uint32_t size);
|
||||
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);
|
||||
|
||||
// outer interpreter loop
|
||||
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
@@ -431,7 +532,17 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
}
|
||||
|
||||
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
|
||||
ppc_exec_inner<debug>(start_addr, size);
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,12 +919,34 @@ 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();
|
||||
|
||||
@@ -857,9 +990,11 @@ 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) {
|
||||
@@ -868,6 +1003,7 @@ 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);
|
||||
|
||||
@@ -899,7 +1035,10 @@ static map<string, int> SPRName2Num = {
|
||||
{"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}
|
||||
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
|
||||
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
|
||||
// get value from supervisor index same as we do for SPR268 and SPR269
|
||||
{"TBL_U", SPR::TBL_S}, {"TBU_U", SPR::TBU_S},
|
||||
};
|
||||
|
||||
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
@@ -927,6 +1066,9 @@ 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;
|
||||
@@ -982,8 +1124,13 @@ 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];
|
||||
}
|
||||
}
|
||||
|
||||
+31
-38
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -37,7 +37,7 @@ inline static void ppc_update_cr1() {
|
||||
}
|
||||
|
||||
static int32_t round_to_nearest(double f) {
|
||||
return static_cast<int32_t>(static_cast<int64_t> (std::floor(f + 0.5)));
|
||||
return static_cast<int32_t>(std::nearbyint(f));
|
||||
}
|
||||
|
||||
void set_host_rounding_mode(uint8_t mode) {
|
||||
@@ -111,8 +111,8 @@ inline static bool check_qnan(int check_reg) {
|
||||
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
|
||||
}
|
||||
|
||||
static double set_endresult_nan(double ppc_result_d) {
|
||||
ppc_state.fpscr += (FX + VX);
|
||||
static double set_endresult_nan() {
|
||||
ppc_state.fpscr |= (FX | VX);
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
@@ -154,11 +154,11 @@ static void ppc_update_vx() {
|
||||
}
|
||||
|
||||
static void ppc_update_fex() {
|
||||
uint32_t fpscr_check = (ppc_state.fpscr >> 22) & ppc_state.fpscr & 0x0F8;
|
||||
uint32_t fpscr_check = ((ppc_state.fpscr >> 22) & 0x0F8);
|
||||
if (fpscr_check)
|
||||
ppc_state.fpscr |= VX;
|
||||
ppc_state.fpscr |= FEX;
|
||||
else
|
||||
ppc_state.fpscr &= ~VX;
|
||||
ppc_state.fpscr &= ~FEX;
|
||||
}
|
||||
|
||||
// Floating Point Arithmetic
|
||||
@@ -175,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -444,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +634,6 @@ 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)
|
||||
@@ -654,7 +653,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -695,7 +694,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,7 +727,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);
|
||||
ppc_dblresult64_d = set_endresult_nan();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,8 +763,6 @@ 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();
|
||||
}
|
||||
@@ -781,8 +778,6 @@ 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();
|
||||
}
|
||||
@@ -798,8 +793,6 @@ 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();
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -72,7 +72,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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];
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
@@ -87,13 +87,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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];
|
||||
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];
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
@@ -151,7 +151,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define FPR_INT(reg) \
|
||||
ppc_state.fpr[reg].int64_r
|
||||
|
||||
+389
-60
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -21,9 +21,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file PowerPC Memory Management Unit emulation. */
|
||||
|
||||
#include <core/memaccess.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <memaccess.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
|
||||
@@ -85,6 +85,37 @@ AddressMapEntry last_ptab_area;
|
||||
/** Dummy pages for catching writes to physical read-only pages */
|
||||
static std::array<uint64_t, 8192 / sizeof(uint64_t)> dummy_page;
|
||||
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
template <class T>
|
||||
static inline uint32_t mem_munge_constant() {
|
||||
switch (sizeof(T)) {
|
||||
case 1: return 7;
|
||||
case 2: return 6;
|
||||
case 4: return 4;
|
||||
case 8: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static uint32_t mem_munge_address(uint32_t guest_va) {
|
||||
if (sizeof(T) == sizeof(uint64_t)) {
|
||||
// 64 bit access. do nothing, handle later.
|
||||
return guest_va;
|
||||
}
|
||||
|
||||
uint32_t align_offset = guest_va & (sizeof(T) - 1);
|
||||
if (align_offset == 0)
|
||||
return guest_va ^ mem_munge_constant<T>();
|
||||
|
||||
// align the address
|
||||
guest_va &= ~(sizeof(T) - 1);
|
||||
// munge it
|
||||
guest_va ^= mem_munge_constant<T>();
|
||||
// and subtract the offset
|
||||
return guest_va - align_offset;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** 601-style block address translation. */
|
||||
static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
{
|
||||
@@ -171,9 +202,13 @@ static inline uint8_t* calc_pteg_addr(uint32_t hash)
|
||||
|
||||
sdr1_val = ppc_state.spr[SPR::SDR1];
|
||||
|
||||
pteg_addr = sdr1_val & 0xFE000000;
|
||||
pteg_addr |= (sdr1_val & 0x01FF0000) | (((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6));
|
||||
pteg_addr |= (hash & 0x3FF) << 6;
|
||||
pteg_addr = (sdr1_val & 0xFFFF0000) |
|
||||
(((sdr1_val & 0x1FF) << 16) & ((hash & 0x7FC00) << 6)) |
|
||||
((hash & 0x3FF) << 6);
|
||||
#if 0 && SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
if (ppc_state.is_LE)
|
||||
pteg_addr ^= mem_munge_constant<uint32_t>();
|
||||
#endif
|
||||
|
||||
if (pteg_addr >= last_ptab_area.start && pteg_addr <= last_ptab_area.end) {
|
||||
return last_ptab_area.mem_ptr + (pteg_addr - last_ptab_area.start);
|
||||
@@ -195,6 +230,9 @@ static bool search_pteg(uint8_t* pteg_addr, uint8_t** ret_pte_addr, uint32_t vsi
|
||||
{
|
||||
/* construct PTE matching word */
|
||||
uint32_t pte_check = 0x80000000 | (vsid << 7) | (pteg_num << 6) | (page_index >> 10);
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
#endif
|
||||
|
||||
#ifdef MMU_INTEGRITY_CHECKS
|
||||
/* PTEG integrity check that ensures that all matching PTEs have
|
||||
@@ -217,7 +255,12 @@ static bool search_pteg(uint8_t* pteg_addr, uint8_t** ret_pte_addr, uint32_t vsi
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < 8; i++, pteg_addr += 8) {
|
||||
if (pte_check == READ_DWORD_BE_A(pteg_addr)) {
|
||||
if (pte_check == (
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
swap ? (READ_DWORD_LE_A(pteg_addr)) :
|
||||
#endif
|
||||
(READ_DWORD_BE_A(pteg_addr))
|
||||
)) {
|
||||
*ret_pte_addr = pteg_addr;
|
||||
return true;
|
||||
}
|
||||
@@ -269,7 +312,25 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
}
|
||||
}
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
uintptr_t pte_addr2S = (uintptr_t)pte_addr;
|
||||
#if 0 && SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
if (ppc_state.is_LE) {
|
||||
pte_addr2S ^= mem_munge_constant<uint32_t>();
|
||||
pte_addr2S += 4;
|
||||
pte_addr2S ^= mem_munge_constant<uint32_t>();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
pte_addr2S += 4;
|
||||
}
|
||||
|
||||
uint8_t* pte_addr2 = (uint8_t*)pte_addr2S;
|
||||
bool swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
pte_word2 = swap ? (READ_DWORD_LE_A(pte_addr2)) : (READ_DWORD_BE_A(pte_addr2));
|
||||
#else
|
||||
pte_word2 = READ_DWORD_BE_A(pte_addr + 4);
|
||||
#endif
|
||||
|
||||
key = (((sr_val >> 29) & 1) & msr_pr) | (((sr_val >> 30) & 1) & (msr_pr ^ 1));
|
||||
|
||||
@@ -292,10 +353,23 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
|
||||
/* update R and C bits */
|
||||
/* For simplicity, R is set on each access, C is set only for writes */
|
||||
pte_addr[6] |= 0x01;
|
||||
if (is_write) {
|
||||
pte_addr[7] |= 0x80;
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (swap) {
|
||||
pte_addr2[1] |= 0x01;
|
||||
if (is_write) {
|
||||
pte_addr2[0] |= 0x80;
|
||||
}
|
||||
} else {
|
||||
pte_addr2[2] |= 0x01;
|
||||
if (is_write) {
|
||||
pte_addr2[3] |= 0x80;
|
||||
}
|
||||
}
|
||||
#else
|
||||
pte_addr[6] |= 0x01;
|
||||
if (is_write)
|
||||
pte_addr[7] |= 0x80;
|
||||
#endif
|
||||
|
||||
/* return physical address, access protection and C status */
|
||||
return PATResult{
|
||||
@@ -305,7 +379,7 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
};
|
||||
}
|
||||
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio, bool is_dbg) {
|
||||
MMIODevice *devobj = nullptr;
|
||||
uint8_t *host_va = nullptr;
|
||||
uint32_t dev_base = 0;
|
||||
@@ -315,24 +389,27 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
|
||||
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
|
||||
if (!cur_dma_rgn) {
|
||||
if (is_dbg) goto fail;
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
}
|
||||
|
||||
if (addr + size - 1 > cur_dma_rgn->end) {
|
||||
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
|
||||
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
|
||||
cur_dma_rgn->start, cur_dma_rgn->end,
|
||||
uint64_t(cur_dma_rgn->mem_ptr),
|
||||
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
|
||||
);
|
||||
else
|
||||
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
|
||||
cur_dma_rgn->start, cur_dma_rgn->end
|
||||
);
|
||||
if (!is_dbg) {
|
||||
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
|
||||
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
|
||||
cur_dma_rgn->start, cur_dma_rgn->end,
|
||||
uint64_t(cur_dma_rgn->mem_ptr),
|
||||
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
|
||||
);
|
||||
else
|
||||
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
|
||||
cur_dma_rgn->start, cur_dma_rgn->end
|
||||
);
|
||||
}
|
||||
next_dma_rgn = mem_ctrl_instance->find_range(cur_dma_rgn->end + 1);
|
||||
if (next_dma_rgn) {
|
||||
if (!is_dbg && next_dma_rgn) {
|
||||
if (next_dma_rgn->type & (RT_ROM | RT_RAM))
|
||||
LOG_F(WARNING, "next region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
|
||||
next_dma_rgn->start, next_dma_rgn->end,
|
||||
@@ -350,11 +427,13 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
(next_dma_rgn->mem_ptr == cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start + 1) &&
|
||||
(addr + size - 1 <= next_dma_rgn->end)
|
||||
) {
|
||||
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
|
||||
" The regions are the same type and adjacent in host and guest spaces.",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
if (!is_dbg)
|
||||
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
|
||||
" The regions are the same type and adjacent in host and guest spaces.",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
} else {
|
||||
if (is_dbg) goto fail;
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
@@ -362,6 +441,7 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
}
|
||||
|
||||
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {
|
||||
if (is_dbg) goto fail;
|
||||
ABORT_F("SOS: DMA access to a MMIO region 0x%08X..0x%08X (%s) for physical memory 0x%08X..0x%08X is not allowed.",
|
||||
cur_dma_rgn->start, cur_dma_rgn->end, cur_dma_rgn->devobj->get_name().c_str(), addr, addr + size - 1
|
||||
);
|
||||
@@ -377,6 +457,8 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
}
|
||||
|
||||
return MapDmaResult{cur_dma_rgn->type, is_writable, host_va, devobj, dev_base};
|
||||
fail:
|
||||
return MapDmaResult{RT_NONE, false, nullptr, nullptr, 0};
|
||||
}
|
||||
|
||||
// primary ITLB for all MMU modes
|
||||
@@ -733,6 +815,12 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
|
||||
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
{
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
if (ppc_state.is_LE) {
|
||||
vaddr ^= mem_munge_constant<uint32_t>();
|
||||
}
|
||||
#endif
|
||||
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
@@ -1018,26 +1106,66 @@ void mmu_pat_ctx_changed()
|
||||
}
|
||||
}
|
||||
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
#define ARGS_SWAP_MUNGED , bool needs_swap, bool munged
|
||||
#define SWAP_MUNGED , needs_swap, munged
|
||||
#else
|
||||
#define ARGS_SWAP_MUNGED , bool munged
|
||||
#define SWAP_MUNGED , munged
|
||||
#endif
|
||||
#else
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
#define ARGS_SWAP_MUNGED , bool needs_swap, bool munged
|
||||
#define SWAP_MUNGED , needs_swap, munged
|
||||
#else
|
||||
#define ARGS_SWAP_MUNGED
|
||||
#define SWAP_MUNGED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Forward declarations.
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
|
||||
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va ARGS_SWAP_MUNGED);
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value);
|
||||
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value ARGS_SWAP_MUNGED);
|
||||
|
||||
template <class T>
|
||||
inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
{
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool munged = false;
|
||||
#endif
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
if (ppc_state.is_LE) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool needs_swap = false;
|
||||
#endif
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
@@ -1062,30 +1190,69 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + guest_va);
|
||||
} else { // otherwise, it's an access to a memory-mapped device
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_reads_total++;
|
||||
#endif
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(tlb2_entry->rgn_desc);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(opcode, guest_va);
|
||||
|
||||
uint32_t valueLow = tlb2_entry->rgn_desc->devobj->read(
|
||||
tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
4);
|
||||
|
||||
uint32_t valueHigh = tlb2_entry->rgn_desc->devobj->read(
|
||||
tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
4);
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap) {
|
||||
uint32_t temp = valueHigh;
|
||||
valueHigh = BYTESWAP_32(valueLow);
|
||||
valueLow = BYTESWAP_32(temp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
4) << 32) |
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
4)
|
||||
((T)(valueLow) << 32) | valueHigh
|
||||
);
|
||||
}
|
||||
else {
|
||||
return (
|
||||
T value = (
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
sizeof(T))
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
sizeof(T))
|
||||
);
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap && sizeof(T) > 1) {
|
||||
value = BYTESWAP_SIZED(value, sizeof(T));
|
||||
}
|
||||
#endif
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1096,7 +1263,11 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
return read_unaligned<T>(opcode, guest_va, host_va);
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (munged)
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
#endif
|
||||
return read_unaligned<T>(opcode, guest_va, host_va SWAP_MUNGED);
|
||||
}
|
||||
|
||||
// handle aligned memory accesses
|
||||
@@ -1104,11 +1275,23 @@ inline T mmu_read_vmem(uint32_t opcode, uint32_t guest_va)
|
||||
case 1:
|
||||
return *host_va;
|
||||
case 2:
|
||||
return READ_WORD_BE_A(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_WORD_LE_A(host_va)) :
|
||||
#endif
|
||||
(READ_WORD_BE_A(host_va));
|
||||
case 4:
|
||||
return READ_DWORD_BE_A(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_DWORD_LE_A(host_va)) :
|
||||
#endif
|
||||
(READ_DWORD_BE_A(host_va));
|
||||
case 8:
|
||||
return READ_QWORD_BE_A(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_QWORD_LE_A(host_va)) :
|
||||
#endif
|
||||
(READ_QWORD_BE_A(host_va));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,12 +1304,25 @@ template uint64_t mmu_read_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va);
|
||||
template <class T>
|
||||
inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
{
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool munged = false;
|
||||
#endif
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE
|
||||
if (ppc_state.is_LE) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
bool needs_swap = false;
|
||||
#endif
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
@@ -1148,6 +1344,13 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
tlb2_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
}
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_w + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
@@ -1184,25 +1387,61 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(false);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_w + guest_va);
|
||||
} else { // otherwise, it's an access to a memory-mapped device
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_writes_total++;
|
||||
#endif
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap = mem_ctrl_instance->needs_swap_endian(tlb2_entry->rgn_desc);
|
||||
if (needs_swap) {
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
munged ^= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(opcode, guest_va);
|
||||
|
||||
uint32_t valueLow, valueHigh;
|
||||
valueLow = value >> 32;
|
||||
valueHigh = (uint32_t)value;
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap) {
|
||||
valueHigh = BYTESWAP_32(valueLow);
|
||||
valueLow = (uint32_t)value;
|
||||
valueLow = BYTESWAP_32(valueLow);
|
||||
}
|
||||
#endif
|
||||
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
value >> 32, 4);
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
valueLow, 4);
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
(uint32_t)value, 4);
|
||||
static_cast<uint32_t>(guest_va + 4 - tlb2_entry->dev_base_va),
|
||||
valueHigh, 4);
|
||||
} else {
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap && sizeof(T) > 1) {
|
||||
value = BYTESWAP_SIZED(value, sizeof(T));
|
||||
}
|
||||
#endif
|
||||
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
value, sizeof(T));
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
value, sizeof(T));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1212,9 +1451,21 @@ inline void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value)
|
||||
dmem_writes_total++;
|
||||
#endif
|
||||
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
// swap now if needed
|
||||
if (needs_swap && sizeof(T) > 1) {
|
||||
value = BYTESWAP_SIZED(value, sizeof(T));
|
||||
}
|
||||
#endif
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
write_unaligned<T>(opcode, guest_va, host_va, value);
|
||||
// unmunge the guest_va if it was munged
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (munged)
|
||||
guest_va = mem_munge_address<T>(guest_va);
|
||||
#endif
|
||||
write_unaligned<T>(opcode, guest_va, host_va, value SWAP_MUNGED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1242,7 +1493,7 @@ template void mmu_write_vmem<uint32_t>(uint32_t opcode, uint32_t guest_va, uint3
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t opcode, uint32_t guest_va, uint64_t value);
|
||||
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
|
||||
static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va ARGS_SWAP_MUNGED)
|
||||
{
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
@@ -1261,8 +1512,38 @@ static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
for (int i = 0; i < sizeof(T); guest_va++, i++) {
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap) {
|
||||
T value = mmu_read_vmem<uint8_t>(opcode, guest_va);
|
||||
value <<= (i * 8);
|
||||
result |= value;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(opcode, guest_va);
|
||||
}
|
||||
}
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
} else if (sizeof(T) == sizeof(uint64_t) && munged) {
|
||||
// Munged host address for an unaligned 64-bit read.
|
||||
// Check for cross-page read, to read the upper 32 bits correctly.
|
||||
if (((guest_va & 0xFFF) + 12) > 0x1000) {
|
||||
// Add the pre-munged address, as munging is a no-op for uint64_t, but not for uint32_t.
|
||||
result = mmu_read_vmem<uint32_t>(opcode, guest_va + mem_munge_address<uint32_t>(8));
|
||||
} else {
|
||||
result =
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_DWORD_LE_U(host_va + 8)) :
|
||||
#endif
|
||||
(READ_DWORD_BE_U(host_va + 8));
|
||||
}
|
||||
result <<= 32;
|
||||
result |=
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_DWORD_LE_U(host_va)) :
|
||||
#endif
|
||||
(READ_DWORD_BE_U(host_va));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_reads++;
|
||||
@@ -1271,23 +1552,35 @@ static T read_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va)
|
||||
case 1:
|
||||
return *host_va;
|
||||
case 2:
|
||||
return READ_WORD_BE_U(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_WORD_LE_U(host_va)) :
|
||||
#endif
|
||||
(READ_WORD_BE_U(host_va));
|
||||
case 4:
|
||||
return READ_DWORD_BE_U(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_DWORD_LE_U(host_va)) :
|
||||
#endif
|
||||
(READ_DWORD_BE_U(host_va));
|
||||
case 8:
|
||||
return READ_QWORD_BE_U(host_va);
|
||||
return
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
needs_swap ? (READ_QWORD_LE_U(host_va)) :
|
||||
#endif
|
||||
(READ_QWORD_BE_U(host_va));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// explicitely instantiate all required read_unaligned variants
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va);
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t* host_va ARGS_SWAP_MUNGED);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t* host_va ARGS_SWAP_MUNGED);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t* host_va ARGS_SWAP_MUNGED);
|
||||
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value)
|
||||
static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, T value ARGS_SWAP_MUNGED)
|
||||
{
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
@@ -1309,6 +1602,36 @@ static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va
|
||||
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
|
||||
mmu_write_vmem<uint8_t>(opcode, guest_va, (value >> shift) & 0xFF);
|
||||
}
|
||||
#if SUPPORTS_PPC_LITTLE_ENDIAN_MODE || SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
} else if (sizeof(T) == sizeof(uint64_t) && munged) {
|
||||
// Munged host address for an unaligned 64-bit write.
|
||||
// Check for cross-page write, to write the upper 32 bits correctly.
|
||||
uint32_t value32 = (value >> 32);
|
||||
if (((guest_va & 0xFFF) + 12) > 0x1000) {
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
// The value is endianness swapped already if needs_swap is true, so swap it back in that case.
|
||||
if (needs_swap) {
|
||||
value32 = (uint32_t)value;
|
||||
value32 = BYTESWAP_32(value32);
|
||||
}
|
||||
#endif
|
||||
// Add the pre-munged address, as munging is a no-op for uint64_t, but not for uint32_t.
|
||||
mmu_write_vmem<uint32_t>(opcode, guest_va + mem_munge_address<uint32_t>(8), value32);
|
||||
} else {
|
||||
// Not cross-page, so just write via host address.
|
||||
WRITE_DWORD_BE_U(host_va + 8, value32);
|
||||
}
|
||||
// Write the lower 32 bits.
|
||||
#if SUPPORTS_MEMORY_CTRL_ENDIAN_MODE
|
||||
if (needs_swap) {
|
||||
value32 = (value >> 32);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
value32 = (uint32_t)value;
|
||||
}
|
||||
WRITE_DWORD_BE_U(host_va, value32);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_writes++;
|
||||
@@ -1331,9 +1654,9 @@ static void write_unaligned(uint32_t opcode, uint32_t guest_va, uint8_t *host_va
|
||||
}
|
||||
|
||||
// explicitely instantiate all required write_unaligned variants
|
||||
template void write_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint64_t value);
|
||||
template void write_unaligned<uint16_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint16_t value ARGS_SWAP_MUNGED);
|
||||
template void write_unaligned<uint32_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint32_t value ARGS_SWAP_MUNGED);
|
||||
template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint8_t *host_va, uint64_t value ARGS_SWAP_MUNGED);
|
||||
|
||||
|
||||
/* MMU profiling. */
|
||||
@@ -1649,6 +1972,12 @@ void ppc_mmu_init()
|
||||
dbat_update = &ppc_dbat_update;
|
||||
}
|
||||
|
||||
int reg;
|
||||
for (reg = 528; reg <= 535; reg++)
|
||||
ibat_update(reg);
|
||||
for (reg = 536; reg <= 543; reg++)
|
||||
dbat_update(reg);
|
||||
|
||||
// invalidate all IDTLB entries
|
||||
invalidate_tlb_entries(itlb1_mode1);
|
||||
invalidate_tlb_entries(itlb1_mode2);
|
||||
|
||||
+7
-4
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -120,7 +120,10 @@ enum TLBFlags : uint16_t {
|
||||
extern std::function<void(uint32_t bat_reg)> ibat_update;
|
||||
extern std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
|
||||
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio);
|
||||
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 is_dbg = false);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
|
||||
+85
-22
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -799,6 +799,9 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
|
||||
uint32_t reg_s = (opcode >> 21) & 0x1F;
|
||||
uint32_t old_msr_val = ppc_state.msr;
|
||||
uint32_t new_msr_val = ppc_state.gpr[reg_s];
|
||||
if (!is_601) {
|
||||
ppc_change_endian((new_msr_val & MSR::LE) != 0);
|
||||
}
|
||||
ppc_msr_did_change(old_msr_val, new_msr_val);
|
||||
|
||||
// generate External Interrupt Exception
|
||||
@@ -810,6 +813,26 @@ 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::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();
|
||||
}
|
||||
@@ -879,13 +902,11 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
|
||||
static uint32_t decrementer_timer_id = 0;
|
||||
|
||||
static void update_decrementer(bool update_time_stamp, uint32_t oldval, uint32_t newval);
|
||||
|
||||
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");
|
||||
@@ -897,27 +918,58 @@ static void trigger_decrementer_exception() {
|
||||
}
|
||||
}
|
||||
|
||||
static void update_decrementer(uint32_t val) {
|
||||
dec_wr_value = val;
|
||||
dec_wr_timestamp = get_virt_time_ns();
|
||||
static void trigger_timed_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
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() {
|
||||
decrementer_timer_id = 0;
|
||||
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();
|
||||
}
|
||||
|
||||
dec_exception_pending = false;
|
||||
|
||||
if (is_601)
|
||||
return;
|
||||
|
||||
if (decrementer_timer_id) {
|
||||
//LOG_F(WARNING, "decrementer cancel timer");
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
|
||||
}
|
||||
|
||||
if (bit_changed(oldval, newval, 31) && bit_set(newval, 31)) {
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
trigger_immediate_decrementer_exception
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
uint64_t time_out;
|
||||
uint32_t time_out_lo;
|
||||
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
|
||||
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
|
||||
_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);
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
time_out,
|
||||
trigger_decrementer_exception
|
||||
trigger_timed_decrementer_exception
|
||||
);
|
||||
}
|
||||
|
||||
@@ -973,6 +1025,7 @@ 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] =
|
||||
@@ -980,6 +1033,7 @@ 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] =
|
||||
@@ -1045,8 +1099,8 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case SPR::DEC_S:
|
||||
if (is_601)
|
||||
val &= ~0x7F;
|
||||
ppc_state.spr[DEC_S] = val;
|
||||
update_decrementer(val);
|
||||
update_decrementer(true, calc_dec_value(), val);
|
||||
ppc_state.spr[SPR::DEC_S] = val;
|
||||
break;
|
||||
case SPR::TBL_S:
|
||||
update_timebase(0xFFFFFFFF00000000ULL, val);
|
||||
@@ -1082,6 +1136,12 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// FIXME: Unknown SPR should be noop or illegal instruction.
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
@@ -1437,7 +1497,9 @@ 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
|
||||
@@ -2010,7 +2072,7 @@ void dppc_interpreter::ppc_eciwx(uint32_t opcode) {
|
||||
uint32_t ear_enable = 0x80000000;
|
||||
|
||||
// error if EAR[E] != 1
|
||||
if (!(ppc_state.spr[282] && ear_enable)) {
|
||||
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
|
||||
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
|
||||
}
|
||||
|
||||
@@ -2030,7 +2092,8 @@ void dppc_interpreter::ppc_ecowx(uint32_t opcode) {
|
||||
uint32_t ear_enable = 0x80000000;
|
||||
|
||||
// error if EAR[E] != 1
|
||||
if (!(ppc_state.spr[282] && ear_enable)) {
|
||||
if (!(ppc_state.spr[SPR::EAR] & ear_enable)) {
|
||||
ppc_state.spr[SPR::DSISR] = 0x00100000;
|
||||
ppc_exception_handler(Except_Type::EXC_DSI, 0x0);
|
||||
}
|
||||
|
||||
|
||||
@@ -407,6 +407,10 @@
|
||||
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,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -321,7 +321,8 @@ int main() {
|
||||
initialize_ppc_opcode_table(); //kludge
|
||||
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
|
||||
// Also set MSR[FP] bit so we can test FPU instructions.
|
||||
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
|
||||
int new_msr = (MSR::ME | MSR::IP | MSR::FP);
|
||||
ppc_msr_did_change(ppc_state.msr, new_msr, false);
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+199
-24
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -19,13 +19,14 @@ 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>
|
||||
@@ -425,21 +426,150 @@ 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++) {
|
||||
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;
|
||||
disasm(ctx);
|
||||
cout << 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;
|
||||
@@ -493,18 +623,34 @@ static void print_mmu_regs()
|
||||
|
||||
printf("\nBAT registers:\n");
|
||||
|
||||
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]);
|
||||
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");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
@@ -753,6 +899,9 @@ 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
|
||||
@@ -762,7 +911,10 @@ 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") {
|
||||
@@ -869,6 +1021,28 @@ 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;
|
||||
@@ -990,9 +1164,10 @@ void DppcDebugger::enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
ppc_state.pc -= 4;
|
||||
via_obj->assert_int(irq_bit);
|
||||
TimerManager::get_instance()->add_oneshot_timer(0, [irq_bit](){
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
via_obj->assert_int(irq_bit);
|
||||
});
|
||||
#endif
|
||||
} else {
|
||||
if (!cmd.empty()) {
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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->buttons_state |= button_bit;
|
||||
this->aj_buttons_state |= button_bit;
|
||||
else if (event.flags & GAMEPAD_EVENT_UP)
|
||||
this->buttons_state &= ~button_bit;
|
||||
this->aj_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->buttons_state = 0;
|
||||
this->aj_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->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
|
||||
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
|
||||
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
|
||||
mouse_buttons |= (this->aj_buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
|
||||
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
|
||||
this->triggers_changed = false;
|
||||
|
||||
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[2] = ~this->buttons_state >> 8;
|
||||
out_buf[3] = ~this->buttons_state & 0xFF;
|
||||
out_buf[2] = uint8_t(~this->aj_buttons_state >> 8);
|
||||
out_buf[3] = ~this->aj_buttons_state & 0xFF;
|
||||
|
||||
this->host_obj->set_output_count(4);
|
||||
this->buttons_changed = false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
void set_register_3() override;
|
||||
|
||||
private:
|
||||
uint32_t buttons_state = 0;
|
||||
uint32_t aj_buttons_state = 0;
|
||||
bool triggers_changed = false;
|
||||
bool buttons_changed = false;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -38,6 +38,7 @@ 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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -67,7 +67,8 @@ protected:
|
||||
virtual void set_register_3() {}
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t led_state = 0;
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t dev_handler_id = 0;
|
||||
bool got_collision = false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -35,13 +35,18 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
|
||||
if (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 = 1; // enable service requests
|
||||
this->srq_flag = 0; // don't process keyboard service requests yet
|
||||
this->led_state = 0; // LEDs off
|
||||
this->pending_events.clear();
|
||||
}
|
||||
|
||||
@@ -53,6 +58,11 @@ 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;
|
||||
}
|
||||
|
||||
@@ -68,14 +78,7 @@ 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 = 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);
|
||||
}
|
||||
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
|
||||
|
||||
if (this->dev_handler_id != 3) {
|
||||
switch (event->key) {
|
||||
@@ -88,7 +91,31 @@ uint8_t AdbKeyboard::consume_pending_event() {
|
||||
return (key_state << 7) | (event->key & 0x7F);
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_2() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = 0;
|
||||
out_buf[1] = this->led_state & 0x07;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
if (this->host_obj->get_input_count() < 2)
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
this->led_state = in_data[1] & 0x07;
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
void event_handler(const KeyboardEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_2() override;
|
||||
bool get_register_3() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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_state, bool force) {
|
||||
bool AdbMouse::get_register_0(uint8_t buttons, 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_state, bool force) {
|
||||
num_bits = this->num_bits;
|
||||
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
|
||||
}
|
||||
uint8_t buttons_state = ~this->buttons_state;
|
||||
buttons = ~buttons;
|
||||
|
||||
for (int axis = 0; axis < 2; axis++) {
|
||||
int bits = num_bits;
|
||||
@@ -100,7 +100,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
|
||||
bits = 7;
|
||||
|
||||
while (bits_remaining > 0) {
|
||||
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
|
||||
*p = uint8_t((val & ((1 << bits) - 1)) | (((buttons >> button) & 1) << bits) | (*p << (bits + 1)));
|
||||
val >>= bits;
|
||||
bits_remaining -= bits;
|
||||
p = bits == 7 ? &out_buf[2] : p + 1;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -70,7 +70,7 @@ enum DeviceClass {
|
||||
void set_register_3() override;
|
||||
|
||||
protected:
|
||||
bool get_register_0(uint8_t buttons_state, bool force);
|
||||
bool get_register_0(uint8_t buttons, bool force);
|
||||
uint8_t get_buttons_state() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -21,13 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Basic ATA device emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
@@ -110,7 +111,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (is_selected() && this->has_data()) {
|
||||
if (this->is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
@@ -159,7 +160,7 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
break;
|
||||
}
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
if (this->is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
}
|
||||
break;
|
||||
@@ -191,6 +192,66 @@ void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
|
||||
this->r_dev_ctrl = new_ctrl;
|
||||
}
|
||||
|
||||
int AtaBaseDevice::pull_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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//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;
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
} else {
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRQ;
|
||||
}
|
||||
|
||||
return xfer_size;
|
||||
}
|
||||
|
||||
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;
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
} else {
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRQ;
|
||||
}
|
||||
|
||||
return xfer_size;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
|
||||
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
|
||||
return;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -24,9 +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 <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include "endianswap.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
int pull_data(uint8_t *buf, int len) override;
|
||||
int push_data(uint8_t *buf, int len) override;
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
@@ -103,6 +105,7 @@ protected:
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
int chunk_size = 0;
|
||||
bool is_dma_xfer = false;
|
||||
|
||||
std::function<void()> post_xfer_action = nullptr;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -56,7 +56,8 @@ enum ATA_Reg : int {
|
||||
COMMAND = 0x07, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
TIME_CONFIG = 0x20, // Apple ASIC specific timing configuration
|
||||
INT_REG = 0x30, // Interrupt Register (read) 0x40 = int request (KeyLargo only)
|
||||
};
|
||||
|
||||
/** ATAPI specific register offsets. */
|
||||
@@ -131,7 +132,7 @@ enum ATA_Cmd : uint8_t {
|
||||
READ_VERIFY = 0x40,
|
||||
ATAPI_COMMAND_GET_CONFIG = 0x46,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
@@ -146,6 +147,9 @@ 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,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
@@ -162,6 +166,8 @@ public:
|
||||
virtual ~AtaInterface() = default;
|
||||
virtual uint16_t read(const uint8_t reg_addr) = 0;
|
||||
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
|
||||
virtual int pull_data(uint8_t *buf, int len) { return 0; };
|
||||
virtual int push_data(uint8_t *buf, int len) { return 0; };
|
||||
|
||||
virtual int get_device_id() = 0;
|
||||
virtual void pdiag_callback() {}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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,11 +99,15 @@ int AtaHardDisk::perform_command() {
|
||||
break;
|
||||
case READ_MULTIPLE:
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
case READ_SECTOR_NR:
|
||||
case READ_DMA:
|
||||
case READ_DMA_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;
|
||||
uint32_t ints_size = 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;
|
||||
if (this->r_command == READ_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
|
||||
@@ -115,20 +119,34 @@ 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);
|
||||
this->signal_data_ready();
|
||||
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();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WRITE_MULTIPLE:
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
case WRITE_SECTOR_NR:
|
||||
case WRITE_DMA:
|
||||
case WRITE_DMA_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = 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_data_ptr = this->data_ptr;
|
||||
if (this->r_command == WRITE_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
|
||||
@@ -144,10 +162,29 @@ int AtaHardDisk::perform_command() {
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
|
||||
this->cur_fpos += write_len;
|
||||
};
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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();
|
||||
@@ -231,6 +268,12 @@ 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;
|
||||
@@ -245,29 +288,32 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
|
||||
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.
|
||||
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
|
||||
WRITE_WORD_LE_A(&buf_ptr[47], 0x8000 | SECTORS_PER_INT);
|
||||
|
||||
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
|
||||
// logical sectors that shall be transferred per data block for
|
||||
// READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
if (this->sectors_per_int)
|
||||
buf_ptr[59] = 0x100 | this->sectors_per_int;
|
||||
WRITE_WORD_LE_A(&buf_ptr[59], 0x100 | this->sectors_per_int);
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 1], this->cylinders);
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 3], this->heads);
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 6], this->sectors);
|
||||
|
||||
buf_ptr[57] = this->total_sectors & 0xFFFFU;
|
||||
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
|
||||
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
|
||||
|
||||
// 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);
|
||||
|
||||
// report LBA capacity
|
||||
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
|
||||
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
|
||||
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
|
||||
|
||||
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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>
|
||||
@@ -62,7 +62,9 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
|
||||
if (this->data_available()) {
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status |= BSY;
|
||||
this->update_intrq(1); // Is this going to work here? The interrupt happens before returning ret_data.
|
||||
// Is this going to work here?
|
||||
// The interrupt happens before returning ret_data.
|
||||
this->update_intrq(1);
|
||||
}
|
||||
else if (this->status_expected) {
|
||||
this->present_status();
|
||||
@@ -90,11 +92,12 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
if (this->r_status & BSY && this->data_available()) {
|
||||
this->r_byte_count = this->request_data();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
}
|
||||
return this->r_status;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to read unknown register: %x", reg_addr);
|
||||
LOG_F(WARNING, "%s: read from unknown register 0x%X", this->name.c_str(),
|
||||
reg_addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -102,13 +105,22 @@ 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 (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();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +150,7 @@ void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
this->device_control(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
LOG_F(WARNING, "%s: write to unknown register 0x%X", this->name.c_str(), reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +180,7 @@ int AtapiBaseDevice::perform_command() {
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->xfer_cnt = 512;
|
||||
this->status_expected = false;
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
switch (this->r_features) {
|
||||
@@ -193,7 +205,7 @@ int AtapiBaseDevice::perform_command() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::data_out_phase() {
|
||||
void AtapiBaseDevice::data_in_phase() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
|
||||
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
|
||||
this->signal_data_ready();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -43,11 +43,12 @@ public:
|
||||
// methods to be implemented in the particular device
|
||||
int perform_command() override;
|
||||
virtual void perform_packet_command() = 0;
|
||||
virtual int get_config(uint8_t* pkt, uint8_t* buf) = 0;
|
||||
virtual int request_data() = 0;
|
||||
virtual bool data_available() = 0;
|
||||
|
||||
// methods with default implementation
|
||||
virtual void data_out_phase();
|
||||
virtual void data_in_phase();
|
||||
virtual void present_status();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -21,6 +21,7 @@ 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>
|
||||
@@ -28,8 +29,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
@@ -92,7 +93,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
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();
|
||||
this->data_in_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
@@ -100,7 +101,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
if ((this->cmd_pkt[4] & 3) == 2) {
|
||||
@@ -115,12 +116,12 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
case ScsiCommand::READ_CAPACITY:
|
||||
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();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->status_good();
|
||||
@@ -130,7 +131,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
} 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();
|
||||
this->data_in_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
@@ -141,7 +142,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
@@ -152,7 +153,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
@@ -174,7 +175,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
if (this->xfer_cnt > 0) {
|
||||
@@ -204,9 +205,9 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->status_good();
|
||||
#if 0
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
|
||||
USECS_TO_NSECS(100), [this]() { this->data_in_phase(); });
|
||||
#else
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
#endif
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
@@ -228,7 +229,7 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
LOG_F(INFO, "%s: speed set to %d kBps", this->name.c_str(),
|
||||
@@ -312,7 +313,19 @@ void AtapiCdrom::perform_packet_command() {
|
||||
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
this->data_in_phase();
|
||||
break;
|
||||
}
|
||||
case ScsiCommand::GET_CONFIG: {
|
||||
this->xfer_cnt = this->get_config(this->cmd_pkt, this->data_buf);
|
||||
if (this->xfer_cnt == 0) {
|
||||
this->present_status();
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -323,6 +336,29 @@ void AtapiCdrom::perform_packet_command() {
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiCdrom::get_config(uint8_t* pkt, uint8_t* buf) {
|
||||
std::memset(buf, 0, 16);
|
||||
|
||||
// Data length (4 bytes header + 8 bytes for one feature descriptor - 4 bytes for length field)
|
||||
uint32_t data_len = 8;
|
||||
buf[0] = (data_len >> 24) & 0xFF;
|
||||
buf[1] = (data_len >> 16) & 0xFF;
|
||||
buf[2] = (data_len >> 8) & 0xFF;
|
||||
buf[3] = data_len & 0xFF;
|
||||
|
||||
// Feature Descriptor 1 - Set profile to CD-ROM
|
||||
buf[6] = 0;
|
||||
buf[7] = 0x08;
|
||||
|
||||
// Feature Descriptor 2 - Feature Code, Version 0
|
||||
buf[8] = 0x00;
|
||||
buf[9] = 0x01; // Core Feature Code
|
||||
buf[10] = 0x03; // Persist and Current bits set
|
||||
buf[11] = 0x04; // Additional Length
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
int AtapiCdrom::request_data() {
|
||||
// continuation of READ_CD above
|
||||
|
||||
@@ -359,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])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
void perform_packet_command() override;
|
||||
|
||||
int get_config(uint8_t* pkt, uint8_t* buf) override;
|
||||
|
||||
int request_data() override;
|
||||
|
||||
bool data_available() override {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
@@ -81,6 +82,21 @@ 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) {
|
||||
return this->devices[this->cur_dev]->pull_data(buf, len);
|
||||
}
|
||||
|
||||
int IdeChannel::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
|
||||
return this->devices[this->cur_dev]->push_data(buf, len);
|
||||
}
|
||||
|
||||
void IdeChannel::assert_dmareq(uint64_t delay) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
|
||||
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
|
||||
this->channel_obj->xfer_retry();
|
||||
});
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define IDE_CHANNEL_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
@@ -33,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class IdeChannel : public HWComponent
|
||||
class IdeChannel : public HWComponent, public DmaDevice
|
||||
{
|
||||
public:
|
||||
IdeChannel(const std::string name);
|
||||
@@ -41,8 +42,11 @@ public:
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
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;
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
@@ -60,6 +64,8 @@ public:
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
void assert_dmareq(uint64_t delay);
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
@@ -87,8 +93,8 @@ public:
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
virtual uint32_t read(const uint8_t reg_addr, const int size) override;
|
||||
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size) override;
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+173
-136
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -21,14 +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 <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
@@ -60,20 +60,21 @@ DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writabl
|
||||
return cmd_host;
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
void DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
MapDmaResult res;
|
||||
|
||||
if (this->cmd_in_progress) {
|
||||
// return current command if there is data to transfer
|
||||
// if there is data remaining to transfer then the command is not finished
|
||||
if (this->queue_len)
|
||||
return this->cur_cmd;
|
||||
return;
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
bool cmd_is_writable;
|
||||
DMACmd *cmd_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &cmd_is_writable);
|
||||
this->cur_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &this->cur_is_writable);
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
|
||||
|
||||
@@ -88,11 +89,11 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
|
||||
break;
|
||||
}
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
if (this->queue_len) {
|
||||
if (cmd_struct.req_count) {
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->res_count = 0;
|
||||
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->cmd_in_progress = true;
|
||||
switch (this->cur_cmd) {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
@@ -108,23 +109,24 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
this->in_cb();
|
||||
break;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
this->queue_len = 0;
|
||||
this->res_count = 0;
|
||||
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(&cmd_struct, nullptr);
|
||||
this->xfer_quad(false);
|
||||
break;
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6) {
|
||||
LOG_F(ERROR, "%s: Invalid key %d in LOAD_QUAD", this->get_name().c_str(),
|
||||
cmd_struct.cmd_key & 7);
|
||||
}
|
||||
if (!cmd_is_writable)
|
||||
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
|
||||
this->xfer_quad(&cmd_struct, cmd_host);
|
||||
this->xfer_quad(true);
|
||||
break;
|
||||
case DBDMA_Cmd::NOP:
|
||||
this->finish_cmd();
|
||||
@@ -140,30 +142,24 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
|
||||
return this->cur_cmd;
|
||||
}
|
||||
|
||||
void DMAChannel::finish_cmd() {
|
||||
bool branch_taken = false;
|
||||
|
||||
// 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;
|
||||
// save interrupt bits from the completing command before cmd_ptr may change
|
||||
uint8_t saved_cmd_bits = this->cur_host->cmd_bits;
|
||||
|
||||
// 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 (cmd_desc[2] & 3) {
|
||||
if (saved_cmd_bits & 3) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 3) != 3) {
|
||||
if ((saved_cmd_bits & 3) != 3) {
|
||||
uint16_t wt_mask = this->wait_select >> 16;
|
||||
cond = (this->ch_stat & wt_mask) == (this->wait_select & wt_mask);
|
||||
if ((cmd_desc[2] & 3) == 2) {
|
||||
if ((saved_cmd_bits & 3) == 2) {
|
||||
cond = !cond; // wait if cond = false
|
||||
}
|
||||
}
|
||||
@@ -175,50 +171,52 @@ void DMAChannel::finish_cmd() {
|
||||
this->ch_stat &= ~CH_STAT_BT;
|
||||
|
||||
// react to cmd.b (branch) bits
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
if (saved_cmd_bits & 0xC) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0xC) != 0xC) {
|
||||
if ((saved_cmd_bits & 0xC) != 0xC) {
|
||||
uint16_t br_mask = this->branch_select >> 16;
|
||||
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
|
||||
if ((cmd_desc[2] & 0xC) == 0x8) {
|
||||
if ((saved_cmd_bits & 0xC) == 0x8) {
|
||||
cond = !cond; // branch if cond = false
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&this->cur_host->cmd_arg);
|
||||
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);
|
||||
if (this->cur_is_writable)
|
||||
WRITE_WORD_LE_A(&this->cur_host->xfer_stat, this->ch_stat | CH_STAT_ACTIVE);
|
||||
}
|
||||
|
||||
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::NOP && this->cur_is_writable) {
|
||||
WRITE_WORD_LE_A(&this->cur_host->res_count, this->res_count);
|
||||
}
|
||||
|
||||
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();
|
||||
this->update_irq(saved_cmd_bits);
|
||||
}
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
void DMAChannel::xfer_quad(bool is_store) {
|
||||
MapDmaResult res;
|
||||
uint32_t addr;
|
||||
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);
|
||||
|
||||
// parse and fix reqCount
|
||||
uint32_t xfer_size = cmd_desc->req_count & 7;
|
||||
uint32_t xfer_size = req_count & 7;
|
||||
if (xfer_size & 4) {
|
||||
xfer_size = 4;
|
||||
} else if (xfer_size & 2) {
|
||||
@@ -226,9 +224,8 @@ void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
} else {
|
||||
xfer_size = 1;
|
||||
}
|
||||
this->res_count = cmd_desc->req_count; // this is the value that gets written to cmd.resCount
|
||||
this->res_count = 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);
|
||||
@@ -237,14 +234,15 @@ void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
|
||||
// prepare data pointers and perform data transfer
|
||||
if (!cmd_host) {
|
||||
if (is_store) {
|
||||
if (res.type & RT_MMIO) {
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base, cmd_desc->cmd_arg, xfer_size);
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base,
|
||||
BYTESWAP_SIZED(cmd_arg, xfer_size), xfer_size);
|
||||
} else if (res.is_writable) {
|
||||
switch (xfer_size) {
|
||||
case 1: *res.host_va = cmd_desc->cmd_arg; break;
|
||||
case 2: WRITE_WORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
case 4: WRITE_DWORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "SOS: DMA access is not to RAM %08X!\n", addr);
|
||||
@@ -261,30 +259,29 @@ void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
default: value = 0; break;
|
||||
}
|
||||
}
|
||||
WRITE_DWORD_LE_A(&cmd_host->cmd_arg, value);
|
||||
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);
|
||||
}
|
||||
|
||||
if (cmd_desc->cmd_bits & 0xC)
|
||||
if (this->cur_host->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() {
|
||||
// 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;
|
||||
|
||||
void DMAChannel::update_irq(uint8_t cmd_bits) {
|
||||
// STOP doesn't generate interrupts
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.i (interrupt) bits
|
||||
if (cmd_desc[2] & 0x30) {
|
||||
if (cmd_bits & 0x30) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0x30) != 0x30) {
|
||||
if ((cmd_bits & 0x30) != 0x30) {
|
||||
uint16_t int_mask = this->int_select >> 16;
|
||||
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
|
||||
if ((cmd_desc[2] & 0x30) == 0x20) {
|
||||
if ((cmd_bits & 0x30) == 0x20) {
|
||||
cond = !cond; // generate interrupt if cond = false
|
||||
}
|
||||
}
|
||||
@@ -313,6 +310,15 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
result = this->cmd_ptr;
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
result = this->int_select;
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
result = this->branch_select;
|
||||
break;
|
||||
case DMAReg::WAIT_SELECT:
|
||||
result = this->wait_select;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
@@ -325,7 +331,7 @@ 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, old_stat, new_stat;
|
||||
uint16_t mask, data;
|
||||
|
||||
if (size != 4) {
|
||||
ABORT_F("%s: non-DWORD writes to a DMA channel not supported",
|
||||
@@ -333,61 +339,81 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
old_stat = this->ch_stat;
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
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);
|
||||
mask = value >> 16;
|
||||
data = value & 0xFFFF;
|
||||
|
||||
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
|
||||
if ((new_stat & 0xFF) != (old_stat & 0xFF)) {
|
||||
this->ch_stat |= new_stat & 0xFF;
|
||||
}
|
||||
// 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);
|
||||
|
||||
// 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 (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;
|
||||
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);
|
||||
if (this->flush_cb)
|
||||
this->flush_cb();
|
||||
}
|
||||
}
|
||||
this->ch_stat = new_stat;
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
} 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;
|
||||
} 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;
|
||||
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;
|
||||
@@ -400,11 +426,12 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
if (!(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->cmd_ptr = value;
|
||||
LOG_F(9, "%s: CommandPtrLo set to 0x%X", this->get_name().c_str(),
|
||||
this->cmd_ptr);
|
||||
}
|
||||
} else
|
||||
LOG_F(WARNING, "%s: CommandPtrLo update skipped", this->get_name().c_str());
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
this->int_select = value & 0xFF00FFUL;
|
||||
@@ -427,9 +454,11 @@ void DMAChannel::xfer_from_device() {
|
||||
|
||||
this->xfer_dir = DMA_DIR_FROM_DEV;
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
|
||||
if (got_bytes == this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
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) {
|
||||
this->finish_cmd();
|
||||
} else if (got_bytes) {
|
||||
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
|
||||
@@ -445,9 +474,11 @@ void DMAChannel::xfer_to_device() {
|
||||
|
||||
this->xfer_dir = DMA_DIR_TO_DEV;
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
|
||||
if (got_bytes == this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
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) {
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
@@ -464,9 +495,10 @@ void DMAChannel::xfer_retry() {
|
||||
this->xfer_to_device();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_ready() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
|
||||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
|
||||
bool DMAChannel::dma_is_ready() {
|
||||
if (!this->is_active() ||
|
||||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP
|
||||
)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -476,7 +508,7 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
if (!this->is_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;
|
||||
@@ -494,14 +526,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
|
||||
@@ -510,11 +542,11 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
return DmaPullResult::NoMoreData; // tell the caller there is no more data
|
||||
}
|
||||
|
||||
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",
|
||||
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",
|
||||
this->get_name().c_str());
|
||||
return -1;
|
||||
return DmaPushResult::NoData;
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get buffer to fill in or become idle
|
||||
@@ -526,7 +558,7 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
std::memcpy(this->queue_data, src_ptr, len);
|
||||
this->queue_data += len;
|
||||
this->res_count += len;
|
||||
this->res_count -= len;
|
||||
this->queue_len -= len;
|
||||
}
|
||||
|
||||
@@ -535,11 +567,11 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return DmaPushResult::PushedData;
|
||||
}
|
||||
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
if (!this->is_active()) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
@@ -557,7 +589,7 @@ void DMAChannel::end_pull_data() {
|
||||
}
|
||||
|
||||
void DMAChannel::end_push_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
if (!this->is_active()) {
|
||||
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
@@ -574,16 +606,15 @@ void DMAChannel::end_push_data() {
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
return this->is_active();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_in_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return this->is_active();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active() {
|
||||
if ((this->ch_stat & CH_STAT_DEAD) || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@@ -603,6 +634,9 @@ 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();
|
||||
|
||||
@@ -610,9 +644,8 @@ void DMAChannel::start() {
|
||||
// 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();
|
||||
while (!this->cmd_in_progress && this->is_active()) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,20 +662,24 @@ void DMAChannel::resume() {
|
||||
// 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();
|
||||
while (!this->cmd_in_progress && this->is_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;
|
||||
}
|
||||
+21
-9
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -112,18 +112,25 @@ public:
|
||||
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 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;
|
||||
}
|
||||
|
||||
bool is_out_active() override;
|
||||
bool is_in_active() override;
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
|
||||
int push_data(const char* src_ptr, int len) override;
|
||||
DmaPushResult push_data(const char* src_ptr, int len) override;
|
||||
int get_pull_data_remaining() override { return this->queue_len; }
|
||||
int get_push_data_remaining() override { return this->queue_len; }
|
||||
void end_pull_data() override;
|
||||
void end_push_data() override;
|
||||
|
||||
bool is_ready() override;
|
||||
bool dma_is_ready() override;
|
||||
void xfer_retry() override;
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
|
||||
@@ -133,10 +140,10 @@ public:
|
||||
|
||||
protected:
|
||||
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
|
||||
uint8_t interpret_cmd(void);
|
||||
void interpret_cmd(void);
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
|
||||
void update_irq();
|
||||
void xfer_quad(bool is_store);
|
||||
void update_irq(uint8_t cmd_bits);
|
||||
void xfer_from_device();
|
||||
void xfer_to_device();
|
||||
|
||||
@@ -145,6 +152,8 @@ 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
|
||||
@@ -162,7 +171,10 @@ 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;
|
||||
|
||||
+44
-16
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -33,6 +33,11 @@ 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; }
|
||||
@@ -54,7 +59,7 @@ public:
|
||||
DmaInChannel(std::string name) { this->name = name; }
|
||||
|
||||
virtual bool is_in_active() { return true; }
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual DmaPushResult push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; }
|
||||
virtual void end_push_data() {}
|
||||
|
||||
@@ -77,12 +82,23 @@ private:
|
||||
};
|
||||
|
||||
// ---------------------- New DMA API -------------------------
|
||||
enum DmaMsg : unsigned {
|
||||
CH_START = 1,
|
||||
CH_STOP,
|
||||
DATA_AVAIL,
|
||||
/** 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,
|
||||
};
|
||||
|
||||
/** DMA transfer direction constants. */
|
||||
enum XferDir : unsigned {
|
||||
DMA_DIR_UNDEF = 0,
|
||||
DMA_DIR_TO_DEV,
|
||||
@@ -97,10 +113,10 @@ public:
|
||||
~DmaDevice() = default;
|
||||
|
||||
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
|
||||
virtual void notify(DmaMsg msg) {}
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; }
|
||||
virtual int xfer_to(uint8_t *buf, int len) { return len; }
|
||||
virtual int tell_xfer_size() { return 0; }
|
||||
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; }
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
@@ -108,17 +124,29 @@ protected:
|
||||
|
||||
class DmaChannel {
|
||||
public:
|
||||
DmaChannel() = default;
|
||||
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;
|
||||
|
||||
// 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 is_ready() { return false; }
|
||||
virtual bool dma_is_ready() { return false; }
|
||||
virtual void xfer_retry() {}
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
XferDir xfer_dir = DMA_DIR_UNDEF;
|
||||
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;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -93,6 +93,7 @@ enum IntSrc : uint32_t {
|
||||
SLOT_PDS,
|
||||
SLOT_VDS,
|
||||
VBL,
|
||||
VALKYRIE,
|
||||
};
|
||||
|
||||
/** Base class for interrupt controllers. */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+18
-17
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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[8] = {
|
||||
static const string flag_names[] = {
|
||||
"little-endian?",
|
||||
"real-mode?",
|
||||
"auto-boot?",
|
||||
@@ -109,8 +109,10 @@ static const string flag_names[8] = {
|
||||
"fcode-debug?",
|
||||
"oem-banner?",
|
||||
"oem-logo?",
|
||||
"use-nvramrc?"
|
||||
"use-nvramrc?",
|
||||
"f-segment?" // ANS only
|
||||
};
|
||||
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
|
||||
@@ -141,12 +143,12 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
uint8_t of_flags = this->buf[12];
|
||||
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
|
||||
|
||||
// populate flags
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (unsigned i = 0; i < num_flags; i++) {
|
||||
_config_vars.push_back(std::make_pair(flag_names[i],
|
||||
((of_flags << i) & 0x80) ? "true" : "false"));
|
||||
(int32_t(of_flags << i) < 0) ? "true" : "false"));
|
||||
}
|
||||
|
||||
// populate the remaining variables
|
||||
@@ -187,7 +189,7 @@ void OfConfigAppl::update_partition() {
|
||||
|
||||
// calculate new checksum
|
||||
uint16_t checksum = this->checksum_partition();
|
||||
checksum = checksum ? ~checksum : 0xFFFFU;
|
||||
checksum = ~checksum;
|
||||
|
||||
// stuff checksum into the header
|
||||
WRITE_WORD_BE_A(&this->buf[4], checksum);
|
||||
@@ -205,7 +207,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 < 8; i++) {
|
||||
for (i = 0; i < num_flags; i++) {
|
||||
if (var_name == flag_names[i]) {
|
||||
if (value == "true")
|
||||
flag = 1;
|
||||
@@ -215,15 +217,15 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
cout << "Invalid property value: " << value << endl;
|
||||
return false;
|
||||
}
|
||||
uint8_t flag_bit = 0x80U >> i;
|
||||
uint8_t of_flags = this->buf[12];
|
||||
uint32_t flag_bit = 0x80000000U >> i;
|
||||
uint32_t of_flags = READ_DWORD_BE_A(&this->buf[12]);
|
||||
|
||||
if (flag)
|
||||
of_flags |= flag_bit;
|
||||
else
|
||||
of_flags &= ~flag_bit;
|
||||
|
||||
this->buf[12] = of_flags;
|
||||
WRITE_DWORD_BE_A(&this->buf[12], of_flags);
|
||||
this->update_partition();
|
||||
return true;
|
||||
}
|
||||
@@ -248,7 +250,6 @@ 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]);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -28,6 +28,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
enum YosemiteGpioMask: uint8_t {
|
||||
GPIO_FWDET = 2, // FireWire detect
|
||||
};
|
||||
|
||||
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
@@ -51,7 +55,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->pserr_event_dis;
|
||||
return (this->gpio_out_en << 16) | (this->gpio_out_data << 8) | this->pserr_event_dis;
|
||||
case SEC_CLK_CTRL:
|
||||
return this->sec_clock_ctrl;
|
||||
default:
|
||||
@@ -75,8 +79,21 @@ 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 & 0xFFU;
|
||||
this->pserr_event_dis = value & 0x7EU;
|
||||
this->gpio_out_data = (value >> 8) & 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;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -61,6 +61,8 @@ 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
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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,6 +155,10 @@ 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);
|
||||
}
|
||||
@@ -193,11 +197,19 @@ 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;
|
||||
@@ -210,6 +222,9 @@ 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);
|
||||
}
|
||||
|
||||
@@ -219,5 +234,8 @@ 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);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -44,6 +44,28 @@ 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 {
|
||||
@@ -89,6 +111,8 @@ 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;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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,7 +110,8 @@ 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.
|
||||
*/
|
||||
@@ -198,4 +199,14 @@ 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 */
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -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<ScsiDevice*>(this));
|
||||
bus_obj->register_device(7, static_cast<ScsiPhysDevice*>(this));
|
||||
bus_obj->attach_scsi_devices("2");
|
||||
}
|
||||
|
||||
@@ -291,7 +291,11 @@ void MeshController::step_completed() {
|
||||
}
|
||||
|
||||
void MeshController::report_error(const int error) {
|
||||
switch(error) {
|
||||
switch (error) {
|
||||
case ARB_LOST:
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
break;
|
||||
case SEL_TIMEOUT:
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
|
||||
+92
-144
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiPhysDevice("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<ScsiDevice*>(this));
|
||||
bus->register_device(7, static_cast<ScsiPhysDevice*>(this));
|
||||
bus->attach_scsi_devices("");
|
||||
}
|
||||
|
||||
@@ -84,54 +84,67 @@ void Sc53C94::reset_device()
|
||||
|
||||
uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t bus_phase, int_flags;
|
||||
uint8_t value;
|
||||
|
||||
switch (reg_offset) {
|
||||
case Read::Reg53C94::Xfer_Cnt_LSB:
|
||||
return this->xfer_count & 0xFFU;
|
||||
value = this->xfer_count & 0xFFU;
|
||||
break;
|
||||
case Read::Reg53C94::Xfer_Cnt_MSB:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
value = (this->xfer_count >> 8) & 0xFFU;
|
||||
break;
|
||||
case Read::Reg53C94::FIFO:
|
||||
return this->fifo_pop();
|
||||
value = this->fifo_pop();
|
||||
break;
|
||||
case Read::Reg53C94::Command:
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
if (this->config2 & CFG2_ENF) {
|
||||
static bool log_it = true;
|
||||
if (log_it) {
|
||||
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
|
||||
log_it = false;
|
||||
}
|
||||
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
|
||||
} else
|
||||
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
|
||||
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
return (this->status & 0xF8) | bus_phase;
|
||||
value = (this->status & 0xF8) | bus_phase;
|
||||
break;
|
||||
}
|
||||
case Read::Reg53C94::Int_Status:
|
||||
int_flags = this->int_status;
|
||||
value = 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();
|
||||
return int_flags;
|
||||
break;
|
||||
case Read::Reg53C94::Seq_Step:
|
||||
return this->seq_step;
|
||||
value = this->seq_step;
|
||||
break;
|
||||
case Read::Reg53C94::FIFO_Flags:
|
||||
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
value = (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
break;
|
||||
case Read::Reg53C94::Config_1:
|
||||
return this->config1;
|
||||
value = this->config1;
|
||||
break;
|
||||
case Read::Reg53C94::Config_3:
|
||||
return this->config3;
|
||||
value = this->config3;
|
||||
break;
|
||||
case Read::Reg53C94::Config_4:
|
||||
value = this->config4;
|
||||
break;
|
||||
case Read::Reg53C94::Xfer_Cnt_Hi:
|
||||
if (this->config2 & CFG2_ENF) {
|
||||
return (this->xfer_count >> 16) & 0xFFU;
|
||||
value = (this->xfer_count >> 16) & 0xFFU;
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
}
|
||||
return 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
@@ -176,8 +189,13 @@ 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 %d register", this->name.c_str(), value,
|
||||
LOG_F(INFO, "%s: writing 0x%X to register # %d", this->name.c_str(), value,
|
||||
reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -346,8 +364,10 @@ void Sc53C94::exec_command()
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
// 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.
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_XFER_PAD_BYTES:
|
||||
@@ -538,6 +558,7 @@ 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);
|
||||
@@ -553,6 +574,7 @@ 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);
|
||||
@@ -560,30 +582,32 @@ void Sc53C94::sequencer()
|
||||
this->bus_obj->target_xfer_data();
|
||||
break;
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->int_status = INTSTAT_SR | INTSTAT_SO;
|
||||
this->is_dma_xfer = false;
|
||||
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 && this->channel_obj->is_ready()) {
|
||||
this->channel_obj->xfer_retry();
|
||||
break;
|
||||
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();
|
||||
}
|
||||
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()) {
|
||||
if (this->is_dma_cmd && this->channel_obj->dma_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)) {
|
||||
@@ -605,11 +629,13 @@ void Sc53C94::sequencer()
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
this->is_dma_xfer = false;
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_phase_latch();
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -622,12 +648,13 @@ 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->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->is_dma_xfer = this->is_dma_cmd;
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
@@ -640,6 +667,7 @@ 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();
|
||||
}
|
||||
@@ -661,6 +689,19 @@ 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) {
|
||||
@@ -693,8 +734,10 @@ 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)
|
||||
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE) {
|
||||
this->update_phase_latch();
|
||||
this->exec_next_command();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -747,108 +790,13 @@ bool Sc53C94::rcv_data()
|
||||
return true;
|
||||
}
|
||||
|
||||
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 Sc53C94::xfer_from(DmaChannel *ch_obj, 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 bytes_moved;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = std::min(len, (int)(this->xfer_count));
|
||||
@@ -883,12 +831,12 @@ int Sc53C94::xfer_from(uint8_t *buf, int len) {
|
||||
return bytes_moved;
|
||||
}
|
||||
|
||||
int Sc53C94::xfer_to(uint8_t *buf, int len) {
|
||||
int Sc53C94::xfer_to(DmaChannel *ch_obj, uint8_t *buf, int len) {
|
||||
int bytes_moved = 0;
|
||||
|
||||
if (!this->xfer_count || !this->is_dma_cmd) {
|
||||
if (!this->xfer_count || !this->is_dma_xfer) {
|
||||
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
|
||||
return bytes_moved;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = std::min(len, (int)(this->xfer_count));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -54,7 +54,7 @@ namespace Read {
|
||||
//
|
||||
Config_2 = 0xB, // Control Register 2
|
||||
Config_3 = 0xC, // Control Register 3
|
||||
Config_4 = 0xD, // Control Register 4
|
||||
Config_4 = 0xD, // Control Register 4 ; Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
|
||||
//
|
||||
};
|
||||
@@ -150,14 +150,16 @@ enum {
|
||||
INTSTAT_SEL = 0x01, // selected as a target without attention
|
||||
};
|
||||
|
||||
/** Configuration register 1 bits. */
|
||||
enum {
|
||||
/** Configuration register 1 bit definitions. */
|
||||
enum : uint8_t {
|
||||
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
|
||||
};
|
||||
|
||||
/** Configuration register 2 bits. */
|
||||
enum {
|
||||
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
|
||||
/** 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
|
||||
};
|
||||
|
||||
/** Sequencer states. */
|
||||
@@ -194,7 +196,7 @@ typedef struct {
|
||||
|
||||
typedef std::function<void(const uint8_t drq_state)> DrqCb;
|
||||
|
||||
class Sc53C94 : public ScsiDevice, public DmaDevice {
|
||||
class Sc53C94 : public ScsiPhysDevice, public DmaDevice {
|
||||
public:
|
||||
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
|
||||
~Sc53C94() = default;
|
||||
@@ -212,46 +214,27 @@ 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;
|
||||
}
|
||||
|
||||
// ScsiDevice methods
|
||||
// ScsiPhysDevice 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(uint8_t *buf, int len) override;
|
||||
int xfer_to(uint8_t *buf, int len) override;
|
||||
int tell_xfer_size() override {
|
||||
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 {
|
||||
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);
|
||||
@@ -288,6 +271,11 @@ 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
|
||||
uint32_t seq_timer_id = 0;
|
||||
@@ -297,6 +285,7 @@ private:
|
||||
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
|
||||
|
||||
@@ -306,9 +295,7 @@ 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
|
||||
+149
-41
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SCSI_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsiphysinterface.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
@@ -75,11 +76,36 @@ namespace ScsiStatus {
|
||||
/** Standard message codes. */
|
||||
namespace ScsiMessage {
|
||||
enum : uint8_t {
|
||||
COMMAND_COMPLETE = 0,
|
||||
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,
|
||||
|
||||
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,
|
||||
};
|
||||
@@ -88,9 +114,12 @@ namespace ScsiMessage {
|
||||
/** Extended message codes. */
|
||||
namespace ScsiExtMessage {
|
||||
enum : uint8_t {
|
||||
MODIFY_DATA_PTR = 0,
|
||||
SYNCH_XFER_REQ = 1,
|
||||
WIDE_XFER_REQ = 3,
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -105,8 +134,8 @@ enum ScsiCommand : uint8_t {
|
||||
REWIND = 0x01,
|
||||
REQ_SENSE = 0x03,
|
||||
FORMAT_UNIT = 0x04,
|
||||
READ_BLK_LIMITS = 0x05,
|
||||
REASSIGN = 0x07,
|
||||
READ_BLOCK_LIMITS = 0x05,
|
||||
REASSIGN_BLOCKS = 0x07,
|
||||
READ_6 = 0x08,
|
||||
WRITE_6 = 0x0A,
|
||||
SEEK_6 = 0x0B,
|
||||
@@ -117,16 +146,16 @@ enum ScsiCommand : uint8_t {
|
||||
ERASE_6 = 0x19,
|
||||
MODE_SENSE_6 = 0x1A,
|
||||
START_STOP_UNIT = 0x1B,
|
||||
DIAG_RESULTS = 0x1C,
|
||||
SEND_DIAGS = 0x1D,
|
||||
RECEIVE_DIAG_RESULTS = 0x1C,
|
||||
SEND_DIAGNOSTIC = 0x1D,
|
||||
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
READ_CAPACITY_10 = 0x25,
|
||||
READ_CAPACITY = 0x25,
|
||||
READ_10 = 0x28,
|
||||
WRITE_10 = 0x2A,
|
||||
SEEK_10 = 0x2B,
|
||||
VERIFY_WRITE_10 = 0x2E,
|
||||
WRITE_AND_VERIFY = 0x2E,
|
||||
VERIFY_10 = 0x2F,
|
||||
READ_LONG_10 = 0x35,
|
||||
SYNC_CACHE = 0x35,
|
||||
WRITE_BUFFER = 0x3B,
|
||||
READ_BUFFER = 0x3C,
|
||||
GET_CONFIG = 0x46,
|
||||
@@ -142,10 +171,11 @@ enum ScsiCommand : uint8_t {
|
||||
// CD-ROM specific commands
|
||||
READ_TOC = 0x43,
|
||||
SET_CD_SPEED = 0xBB,
|
||||
PLAY_CD = 0xBC,
|
||||
READ_CD = 0xBE,
|
||||
};
|
||||
|
||||
enum ScsiSense : int {
|
||||
enum ScsiSense : uint8_t {
|
||||
NO_SENSE = 0x0,
|
||||
RECOVERED = 0x1,
|
||||
NOT_READY = 0x2,
|
||||
@@ -160,7 +190,7 @@ enum ScsiSense : int {
|
||||
COMPLETED = 0xF
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
enum ScsiError : uint8_t {
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
@@ -174,6 +204,57 @@ enum ScsiError : int {
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
};
|
||||
|
||||
/** 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 = 0xE,
|
||||
POWER_CONDITION = 0x1A,
|
||||
CDROM_CAPABILITIES = 0x2A,
|
||||
VENDOR_PAGE_31 = 0x31,
|
||||
ALL_PAGES = 0x3F,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
constexpr uint64_t BUS_SETTLE_DELAY = 400;
|
||||
constexpr uint64_t BUS_FREE_DELAY = 800;
|
||||
@@ -186,34 +267,65 @@ constexpr auto SCSI_MAX_DEVS = 8;
|
||||
|
||||
class ScsiBus;
|
||||
|
||||
typedef std::function<void()> action_callback;
|
||||
|
||||
class ScsiDevice : public HWComponent {
|
||||
class ScsiPhysDevice : public ScsiPhysInterface, public HWComponent {
|
||||
public:
|
||||
ScsiDevice(std::string name, int my_id) {
|
||||
ScsiPhysDevice(std::string name, int my_id) : ScsiPhysInterface(PHY_ID_SCSI) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
this->scsi_id = my_id;
|
||||
this->lun = 0,
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
}
|
||||
~ScsiDevice() = default;
|
||||
~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) override {
|
||||
this->status = status_code;
|
||||
}
|
||||
|
||||
void set_eject_state(bool eject_allowed) override {
|
||||
this->eject_allowed = eject_allowed;
|
||||
}
|
||||
|
||||
virtual void notify(ScsiNotification notif_type, int param);
|
||||
virtual void next_step();
|
||||
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
|
||||
virtual void switch_phase(const int new_phase);
|
||||
virtual void prepare_xfer();
|
||||
virtual void switch_phase(const int new_phase) override;
|
||||
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();
|
||||
|
||||
@@ -221,8 +333,6 @@ 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
|
||||
@@ -231,18 +341,14 @@ 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;
|
||||
|
||||
int sense;
|
||||
int asc;
|
||||
int ascq;
|
||||
int sksv;
|
||||
int field;
|
||||
bool valid;
|
||||
|
||||
bool last_selection_has_atention = false;
|
||||
bool eject_allowed = true;
|
||||
bool last_selection_has_attention = false;
|
||||
uint8_t last_selection_message = 0;
|
||||
ScsiBus* bus_obj;
|
||||
|
||||
@@ -250,6 +356,9 @@ 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 = {};
|
||||
};
|
||||
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
@@ -269,7 +378,7 @@ public:
|
||||
void attach_scsi_devices(const std::string bus_suffix);
|
||||
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
void register_device(int id, ScsiPhysDevice* dev_obj);
|
||||
|
||||
int current_phase() const {
|
||||
return this->cur_phase;
|
||||
@@ -304,14 +413,13 @@ 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<ScsiDevice*, SCSI_MAX_DEVS> devices;
|
||||
std::array<ScsiPhysDevice*, SCSI_MAX_DEVS> devices;
|
||||
|
||||
// per-device state of the control lines
|
||||
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
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::VERIFY_6);
|
||||
this->enable_cmd(ScsiCommand::VERIFY_10);
|
||||
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() {
|
||||
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_new();
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
case ScsiCommand::WRITE_10:
|
||||
case ScsiCommand::WRITE_12:
|
||||
next_phase = this->write_new();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
case ScsiCommand::VERIFY_10:
|
||||
next_phase = this->verify_sector();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
next_phase = this->start_stop_unit();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
phy_impl->set_eject_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_new() {
|
||||
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");
|
||||
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_new() {
|
||||
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");
|
||||
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::verify_sector() {
|
||||
//TODO: implement the IMMED, BYTCMP, or FIXED bits
|
||||
|
||||
int nblocks = this->get_xfer_len();
|
||||
|
||||
// special case: zero transfer length means 256 blocks for VERIFY_6
|
||||
if (this->cdb_ptr[0] == ScsiCommand::VERIFY_6) {
|
||||
if (!nblocks)
|
||||
nblocks = 256;
|
||||
} else {
|
||||
if ((this->cdb_ptr[1] & 1) && !this->linked_cmds_supported()) {
|
||||
LOG_F(WARNING, "VERIFY: RelAdr bit set");
|
||||
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, "VERIFY: skip because nblocks = 0");
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
auto lba = this->get_lba();
|
||||
auto size = this->blk_dev->get_size_in_blocks();
|
||||
|
||||
if (lba >= size || (uint64_t)lba + (uint64_t)nblocks > size) {
|
||||
LOG_F(WARNING, "VERIFY: out of range");
|
||||
this->invalid_cdb();
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
int ScsiBlockCmds::start_stop_unit() {
|
||||
if (this->cdb_ptr[4] & 1) {
|
||||
if (this->cdb_ptr[4] & 2)
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium load requested");
|
||||
} else {
|
||||
if (this->cdb_ptr[4] & 2) {
|
||||
LOG_F(INFO, "START_STOP_UNIT: medium eject requested");
|
||||
}
|
||||
}
|
||||
return ScsiPhase::STATUS;
|
||||
}
|
||||
|
||||
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");
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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_new();
|
||||
virtual int write_new();
|
||||
virtual int verify_sector();
|
||||
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;
|
||||
|
||||
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
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -49,7 +49,7 @@ ScsiBus::ScsiBus(const std::string name)
|
||||
this->target_id = -1;
|
||||
}
|
||||
|
||||
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
void ScsiBus::register_device(int id, ScsiPhysDevice* dev_obj)
|
||||
{
|
||||
if (this->devices[id] != nullptr) {
|
||||
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
|
||||
@@ -298,18 +298,6 @@ 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);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -113,7 +113,6 @@ void ScsiBusController::sequencer() {
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
}
|
||||
@@ -146,15 +145,16 @@ void ScsiBusController::sequencer() {
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
this->bus_obj->target_next_step();
|
||||
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_REQ);
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
}
|
||||
this->step_completed();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ int ScsiBusController::send_data(uint8_t* dst_ptr, int count) {
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiBusController::xfer_from(uint8_t *buf, int len) {
|
||||
int ScsiBusController::xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) {
|
||||
if (len > this->to_xfer + this->fifo_pos)
|
||||
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -60,9 +60,9 @@ enum : int {
|
||||
|
||||
constexpr auto DATA_FIFO_DEPTH = 16;
|
||||
|
||||
class ScsiBusController : public ScsiDevice, public DmaDevice {
|
||||
class ScsiBusController : public ScsiPhysDevice, public DmaDevice {
|
||||
public:
|
||||
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
|
||||
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiPhysDevice(name, my_bus_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
}
|
||||
~ScsiBusController() = default;
|
||||
@@ -73,17 +73,15 @@ public:
|
||||
virtual void step_completed() = 0;
|
||||
virtual void report_error(const int error) = 0;
|
||||
|
||||
// ScsiDevice methods
|
||||
// ScsiPhysDevice methods
|
||||
void notify(ScsiNotification notif_type, int param) override;
|
||||
bool prepare_data() override { return false; }
|
||||
bool get_more_data() override { return false; }
|
||||
bool has_data() override { return false; }
|
||||
bool rcv_data();
|
||||
int send_data(uint8_t* dst_ptr, int count) override;
|
||||
void process_command() override {}
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
int xfer_from(DmaChannel *ch_obj, uint8_t *buf, int len) override;
|
||||
|
||||
protected:
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
Copyright (C) 2018-26 The DingusPPC Development Team
|
||||
(See CREDITS.MD for more details)
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
(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
|
||||
@@ -21,245 +21,89 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file SCSI CD-ROM emulation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsicdrom.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
static char my_vendor_id[] = "SONY ";
|
||||
static char my_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char my_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : ScsiPhysDevice(name, my_id)
|
||||
{
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->report_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
this->set_phys_dev(this);
|
||||
this->set_cdb_ptr(this->cmd_buf);
|
||||
this->set_buf_ptr(this->data_buf);
|
||||
|
||||
this->init_block_device(1, 0, 1, true);
|
||||
|
||||
// populate device info for INQUIRY
|
||||
this->dev_type = ScsiDevType::CD_ROM;
|
||||
this->is_removable = true; // removable medium
|
||||
this->std_versions = 2; // ISO vers=0, ECMA vers=0, ANSI vers=2 (SCSI-2)
|
||||
this->resp_fmt = 2; // response data format: SCSI-2
|
||||
this->cap_flags = CAP_SYNC_XFER; // supports synchronous transfers
|
||||
this->set_vendor_id(my_vendor_id);
|
||||
this->set_product_id(my_product_id);
|
||||
this->set_revision_id(my_revision_id);
|
||||
|
||||
this->add_page_getter(this, 49, &ScsiCdrom::get_apple_page_49);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
void ScsiCdrom::process_command() {
|
||||
uint32_t lba;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
if (this->verify_cdb() < 0) {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
phy_impl->set_status(ScsiStatus::GOOD);
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
// use internal data buffer by default
|
||||
this->data_ptr = this->data_buf;
|
||||
phy_impl->set_buffer(this->data_buf);
|
||||
|
||||
uint8_t* cmd = this->cmd_buf;
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->bytes_out = this->inquiry(cmd, this->data_buf);
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
if (cmd[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
|
||||
}
|
||||
read(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->bytes_out = read_toc(cmd, this->data_buf);
|
||||
if (this->status == ScsiStatus::GOOD) {
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
|
||||
this->illegal_command(cmd);
|
||||
ScsiCdromCmds::process_command();
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiCdrom::prepare_data()
|
||||
// Apple SCSI/ATAPI driver requests this page in the case of a device error.
|
||||
// PearPC implements it under the name "Apple Features".
|
||||
// I couldn't find any drive whose firmware supports it.
|
||||
int ScsiCdrom::get_apple_page_49(uint8_t subpage, uint8_t ctrl, uint8_t *out_ptr,
|
||||
int avail_len)
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
LOG_F(WARNING, "Page 0x31 requested");
|
||||
|
||||
bool ScsiCdrom::get_more_data() {
|
||||
if (this->data_left()) {
|
||||
this->data_size = this->read_more();
|
||||
this->data_ptr = (uint8_t *)this->data_cache.get();
|
||||
}
|
||||
if (subpage && subpage != 0xFFU)
|
||||
return FORMAT_ERR_BAD_SUBPAGE;
|
||||
|
||||
return this->data_size != 0;
|
||||
}
|
||||
if (ctrl == 3)
|
||||
return FORMAT_ERR_BAD_CONTROL;
|
||||
|
||||
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
|
||||
{
|
||||
if (!check_lun())
|
||||
return;
|
||||
int page_size = 6;
|
||||
|
||||
if (cmd_len == 6 && nblocks == 0)
|
||||
nblocks = 256;
|
||||
if (page_size > avail_len)
|
||||
return FORMAT_ERR_DATA_TOO_BIG;
|
||||
|
||||
this->set_fpos(lba);
|
||||
this->data_ptr = (uint8_t *)this->data_cache.get();
|
||||
this->bytes_out = this->read_begin(nblocks, UINT32_MAX);
|
||||
std::memset(out_ptr, 0, page_size);
|
||||
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
out_ptr[0] = '.';
|
||||
out_ptr[1] = 'A';
|
||||
out_ptr[2] = 'p';
|
||||
out_ptr[3] = 'p';
|
||||
|
||||
int ScsiCdrom::test_unit_ready()
|
||||
{
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
int page_num = cmd_ptr[2];
|
||||
int alloc_len = cmd_ptr[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
|
||||
alloc_len, this->last_selection_message);
|
||||
lun = this->last_selection_message & 7;
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
|
||||
alloc_len, cmd_ptr[1]);
|
||||
lun = cmd_ptr[1] >> 5;
|
||||
}
|
||||
|
||||
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
|
||||
data_ptr[1] = 0x80; // removable media
|
||||
data_ptr[2] = 2; // ANSI version: SCSI-2
|
||||
data_ptr[3] = 1; // response data format
|
||||
data_ptr[4] = 0x1F; // additional length
|
||||
data_ptr[5] = 0;
|
||||
data_ptr[6] = 0;
|
||||
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&data_ptr[8], vendor_info, 8);
|
||||
std::memcpy(&data_ptr[16], prod_info, 16);
|
||||
std::memcpy(&data_ptr[32], rev_info, 4);
|
||||
//std::memcpy(&data_ptr[36], serial_number, 8);
|
||||
//etc.
|
||||
|
||||
if (alloc_len < 36) {
|
||||
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
}
|
||||
else {
|
||||
memset(&data_ptr[36], 0, alloc_len - 36);
|
||||
}
|
||||
|
||||
return alloc_len;
|
||||
}
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiCdrom::mode_sense_6()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
//uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0x80; // medium is write protected
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (this->size_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (this->size_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (this->size_blocks ) & 0xFFU;
|
||||
this->data_buf[ 8] = 0;
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = (this->block_size >> 8) & 0xFFU;
|
||||
this->data_buf[11] = (this->block_size ) & 0xFFU;
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
|
||||
switch (page_code) {
|
||||
case 0x01:
|
||||
this->data_buf[13] = 6; // data size
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
this->data_buf[0] += 7;
|
||||
break;
|
||||
case 0x30:
|
||||
this->data_buf[13] = 22; // data size
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
this->data_buf[0] += 23;
|
||||
break;
|
||||
case 0x31:
|
||||
this->data_buf[13] = 6; // data size
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
this->data_buf[14] = '.';
|
||||
this->data_buf[15] = 'A';
|
||||
this->data_buf[16] = 'p';
|
||||
this->data_buf[17] = 'p';
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->bytes_out = this->data_buf[0];
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
return page_size;
|
||||
}
|
||||
|
||||
void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
@@ -267,7 +111,7 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
if (!param_len)
|
||||
return;
|
||||
|
||||
this->incoming_size = param_len;
|
||||
phy_impl->set_xfer_len(param_len);
|
||||
|
||||
std::memset(&this->data_buf[0], 0, 512);
|
||||
|
||||
@@ -278,37 +122,3 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity_10()
|
||||
{
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str());
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 8;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
int last_lba = (int)this->size_blocks - 1;
|
||||
|
||||
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], this->block_size);
|
||||
|
||||
this->bytes_out = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
Loaded 100 of 220 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user