mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
385
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ad4b28ed | ||
|
|
eb67b6ded0 | ||
|
|
cbaf0477f0 | ||
|
|
cbd24165bd | ||
|
|
e50a1a4d3e | ||
|
|
ce122da984 | ||
|
|
738b40c7b6 | ||
|
|
2a24b1c8f9 | ||
|
|
f1e6a2ce93 | ||
|
|
11de987ea9 | ||
|
|
804bb3da07 | ||
|
|
832d669890 | ||
|
|
262b7ccf68 | ||
|
|
de61c26484 | ||
|
|
cb39be991f | ||
|
|
55f9d08c30 | ||
|
|
f1a38e21d3 | ||
|
|
90536f79fe | ||
|
|
72308074da | ||
|
|
8c42685e26 | ||
|
|
01ceaef8d7 | ||
|
|
55d7c8f09d | ||
|
|
1f59eceacf | ||
|
|
e14ede2510 | ||
|
|
bc05593dd2 | ||
|
|
b5224ee805 | ||
|
|
3addc05ec4 | ||
|
|
f0cf315030 | ||
|
|
959e92e372 | ||
|
|
5ae9fcbd38 | ||
|
|
e2ed352533 | ||
|
|
4644ade362 | ||
|
|
4a71dbe7bb | ||
|
|
aed250a64d | ||
|
|
e2ad753f4a | ||
|
|
2ab23546ea | ||
|
|
9d9e826bb3 | ||
|
|
3c2887f8c3 | ||
|
|
8cc67b09c2 | ||
|
|
bb3e89e3af | ||
|
|
172dab7431 | ||
|
|
78da2457e8 | ||
|
|
7e70432495 | ||
|
|
c6060ad812 | ||
|
|
f09710a5f7 | ||
|
|
de727db4c6 | ||
|
|
671cd0c5da | ||
|
|
ef62e8b965 | ||
|
|
8c44da655c | ||
|
|
b5850f1cd2 | ||
|
|
0a61970b29 | ||
|
|
91a8e83f21 | ||
|
|
825314c869 | ||
|
|
8d9bc66a82 | ||
|
|
52f4d847dd | ||
|
|
ebf4b0e969 | ||
|
|
47237ff87b | ||
|
|
8d95aa5ed3 | ||
|
|
7ee8b9b2f0 | ||
|
|
1f2256ec81 | ||
|
|
0518f2ae2f | ||
|
|
3bf088f2c8 | ||
|
|
bd16b7c69e | ||
|
|
f5c91968a2 | ||
|
|
4e78ac33c5 | ||
|
|
e1acf5d160 | ||
|
|
047515d813 | ||
|
|
bdbeb742d4 | ||
|
|
e7d8e71297 | ||
|
|
a34e0a4737 | ||
|
|
2c026259b1 | ||
|
|
cd36df5500 | ||
|
|
5ea7b8c5f8 | ||
|
|
372b9cae7a | ||
|
|
595478ed6f | ||
|
|
a2776ddae1 | ||
|
|
f9338b8dd9 | ||
|
|
dee7090071 | ||
|
|
2a8e5538b2 | ||
|
|
20b2fb1bef | ||
|
|
f096eef66d | ||
|
|
899000b647 | ||
|
|
76824fb602 | ||
|
|
02af6da599 | ||
|
|
83afae5625 | ||
|
|
e5510dd9ae | ||
|
|
4d7c520f18 | ||
|
|
6f62f9dd98 | ||
|
|
31d7b056af | ||
|
|
9b49603c72 | ||
|
|
f192d11758 | ||
|
|
ae08c083ea | ||
|
|
dab9334c3a | ||
|
|
7fdfd6109f | ||
|
|
7d6e87a0d3 | ||
|
|
a20ebade09 | ||
|
|
8d6f77ea71 | ||
|
|
19ecc4f945 | ||
|
|
ebc618adea | ||
|
|
38669fd83b | ||
|
|
211f8adc0e | ||
|
|
bda85a66df | ||
|
|
babd8d974f | ||
|
|
9fc5bbb951 | ||
|
|
3fe6e3c09e | ||
|
|
289a14dc7a | ||
|
|
ba9fcd100d | ||
|
|
889dc32a0a | ||
|
|
f13f4e0023 | ||
|
|
4a425c4ecf | ||
|
|
293e869acb | ||
|
|
f3d7cd9dd7 | ||
|
|
fd5498e16b | ||
|
|
55f91c5d3f | ||
|
|
0831182e39 | ||
|
|
26153ca8ea | ||
|
|
7855770ca7 | ||
|
|
a81156c3e3 | ||
|
|
f31c71e430 | ||
|
|
7ba7bff3d5 | ||
|
|
11bb10b44b | ||
|
|
378965cc3d | ||
|
|
40b537767d | ||
|
|
e2e78c0682 | ||
|
|
0267fc82c9 | ||
|
|
c4022f466f | ||
|
|
17cdcc5560 | ||
|
|
5eaff7a8ce | ||
|
|
9d44ac0901 | ||
|
|
606c9dd9a8 | ||
|
|
ec7907ed71 | ||
|
|
d1e20a72e3 | ||
|
|
742662e4fc | ||
|
|
d3096ebaac | ||
|
|
c0e28b81a8 | ||
|
|
ce5edcb0c8 | ||
|
|
a3743f0293 | ||
|
|
92580f3515 | ||
|
|
50018010c7 | ||
|
|
e4294d78bf | ||
|
|
b73f5a157d | ||
|
|
ce9a1a6d9e | ||
|
|
a95b06f703 | ||
|
|
226c097b81 | ||
|
|
a18658fc16 | ||
|
|
971f6d79be | ||
|
|
ed67ab81a3 | ||
|
|
07304781ea | ||
|
|
941a405cf8 | ||
|
|
b60d3061b7 | ||
|
|
82e22174d6 | ||
|
|
cf9811d03a | ||
|
|
19f06fb3a2 | ||
|
|
5710758dd7 | ||
|
|
181e1d2e46 | ||
|
|
59fba285b5 | ||
|
|
fdf8543c7e | ||
|
|
86d8ae0911 | ||
|
|
900e58f0ad | ||
|
|
62e80c0c2f | ||
|
|
3483bebdb4 | ||
|
|
11d61359c1 | ||
|
|
30afcb6ddc | ||
|
|
ad45ce8499 | ||
|
|
9a489d13f4 | ||
|
|
721c70166c | ||
|
|
861c2d4f04 | ||
|
|
da203b69c5 | ||
|
|
159fe8d48e | ||
|
|
6adba32238 | ||
|
|
d96da6434f | ||
|
|
5f37421ceb | ||
|
|
6f64e729c8 | ||
|
|
288e088f8a | ||
|
|
3797fdbf1b | ||
|
|
3036f4676d | ||
|
|
e14b6677b2 | ||
|
|
76f966845d | ||
|
|
288d97f24c | ||
|
|
755dd7f60a | ||
|
|
e6d669d187 | ||
|
|
0d1a2d3010 | ||
|
|
51af94f12d | ||
|
|
8d7ca7fb03 | ||
|
|
bc691a9d86 | ||
|
|
2c79171be6 | ||
|
|
e91432f939 | ||
|
|
ea7b9db078 | ||
|
|
a22bc34816 | ||
|
|
2b76d8a53a | ||
|
|
5f6b924004 | ||
|
|
dfd4d82693 | ||
|
|
e5282f9852 | ||
|
|
b2c342e453 | ||
|
|
3aad040f28 | ||
|
|
e722ef3e8a | ||
|
|
e94be9acee | ||
|
|
ae5a1331b6 | ||
|
|
a0052b7b9a | ||
|
|
503ee92528 | ||
|
|
6c3715cc32 | ||
|
|
a5416f521a | ||
|
|
a8023bb41b | ||
|
|
fa01699786 | ||
|
|
5f1150cf4e | ||
|
|
5022ac89b4 | ||
|
|
382246905b | ||
|
|
a5241d27c1 | ||
|
|
4479ecb1bb | ||
|
|
b454ab45fe | ||
|
|
d06d80619e | ||
|
|
9a70c3bdb0 | ||
|
|
103ef6169c | ||
|
|
1a165ff64c | ||
|
|
8cbbb2ed50 | ||
|
|
781d9b46da | ||
|
|
ffa221192d | ||
|
|
751f964139 | ||
|
|
14f75d834a | ||
|
|
96efc99a00 | ||
|
|
45d2c8854d | ||
|
|
c22843f238 | ||
|
|
1c5009fcb0 | ||
|
|
bd63d1dcda | ||
|
|
8aaf211c5b | ||
|
|
8cc5838efe | ||
|
|
4b965c623b | ||
|
|
be27ceed00 | ||
|
|
1d75730d44 | ||
|
|
95d74a6940 | ||
|
|
c6ea3a374e | ||
|
|
e8ce805f2a | ||
|
|
3d898ebdf3 | ||
|
|
f45b7c47c8 | ||
|
|
916cb47b9d | ||
|
|
bce816139b | ||
|
|
24bce16c4d | ||
|
|
a928c67913 | ||
|
|
2b8f510603 | ||
|
|
e8273ecc61 | ||
|
|
e1f31a2da3 | ||
|
|
d897acfd3c | ||
|
|
1e57ac408a | ||
|
|
ef8522e101 | ||
|
|
c71d856a08 | ||
|
|
df7ff76404 | ||
|
|
0d1ce68d19 | ||
|
|
88aa249ce1 | ||
|
|
ff626ae0b5 | ||
|
|
529f23d836 | ||
|
|
cb88bab67d | ||
|
|
67a5c39b1c | ||
|
|
0273867c49 | ||
|
|
1e50d88183 | ||
|
|
29a832c68d | ||
|
|
cb05bd05eb | ||
|
|
4f45d7de35 | ||
|
|
a6ba9a0554 | ||
|
|
9c95bc17fe | ||
|
|
2c94cfee03 | ||
|
|
3c16870f86 | ||
|
|
22f45902ca | ||
|
|
28b1eb8524 | ||
|
|
1c8702d67a | ||
|
|
cf4913deb0 | ||
|
|
bdd441b1b6 | ||
|
|
4c9fe06229 | ||
|
|
e7da98b6bd | ||
|
|
dcdfaabedf | ||
|
|
524daa45a5 | ||
|
|
073b8fd981 | ||
|
|
d7749e0a2c | ||
|
|
7972a0f2a8 | ||
|
|
19dcb43658 | ||
|
|
9ed1a118e6 | ||
|
|
a5a5410515 | ||
|
|
40a4ca31b9 | ||
|
|
7f44ab2262 | ||
|
|
123c927b1a | ||
|
|
74274f164d | ||
|
|
5c2bd0b3bb | ||
|
|
d0a5a1e7be | ||
|
|
077e6ebae5 | ||
|
|
abe0c14301 | ||
|
|
61576d4032 | ||
|
|
782a8d2c3c | ||
|
|
e619dd2493 | ||
|
|
8a1055ed1b | ||
|
|
ff766b10eb | ||
|
|
ceb2276098 | ||
|
|
82f4d05f4b | ||
|
|
8a81cb4f9c | ||
|
|
1504bd2227 | ||
|
|
475f894582 | ||
|
|
7007e002e6 | ||
|
|
9af1b1a720 | ||
|
|
ca9657baf1 | ||
|
|
3e347746f9 | ||
|
|
b5987afaa6 | ||
|
|
ea46d08835 | ||
|
|
789114cc7d | ||
|
|
cf292fafcb | ||
|
|
08fca7de69 | ||
|
|
b42437c458 | ||
|
|
98e1787f93 | ||
|
|
7a0ec0ecd3 | ||
|
|
55b9f8bbe5 | ||
|
|
2968645f2e | ||
|
|
92dea0e404 | ||
|
|
bfd3077bd0 | ||
|
|
2d1616894d | ||
|
|
7c203b40c8 | ||
|
|
2f63a2fa17 | ||
|
|
e3e065a6d7 | ||
|
|
afd8ba8cf2 | ||
|
|
43d87b4791 | ||
|
|
6267685920 | ||
|
|
48882f3fec | ||
|
|
0ac54ea1ea | ||
|
|
4395ce01d7 | ||
|
|
2c097da12d | ||
|
|
5f316dc7a4 | ||
|
|
02a475e113 | ||
|
|
338bbe27a8 | ||
|
|
44564065f6 | ||
|
|
c54ec7be2d | ||
|
|
274e380b34 | ||
|
|
e872f08273 | ||
|
|
a6fda3b787 | ||
|
|
a48851888f | ||
|
|
f1abb66f9a | ||
|
|
c999c51d77 | ||
|
|
6bb5227ee1 | ||
|
|
cefe8698da | ||
|
|
4be6bad526 | ||
|
|
d3c913e384 | ||
|
|
a868f4eee4 | ||
|
|
44da89979f | ||
|
|
a79f07e4dc | ||
|
|
e17a96f5ec | ||
|
|
5062508940 | ||
|
|
9cf91328c1 | ||
|
|
6a30ef7017 | ||
|
|
71dabf5334 | ||
|
|
155b8cdad9 | ||
|
|
96dc02b249 | ||
|
|
eaddcab0ba | ||
|
|
d9b02ecd8d | ||
|
|
b9c12e44a4 | ||
|
|
58ed5bb56e | ||
|
|
094f44e92c | ||
|
|
566706dd62 | ||
|
|
60a76e9348 | ||
|
|
1d9b0f7fa5 | ||
|
|
f55ad323b4 | ||
|
|
78558e4c52 | ||
|
|
c9d4cc3321 | ||
|
|
0f8a464157 | ||
|
|
e4a675babb | ||
|
|
5b4ed01bec | ||
|
|
64df253053 | ||
|
|
d8129bd643 | ||
|
|
60a4738694 | ||
|
|
9ade14e076 | ||
|
|
6aa54b8dda | ||
|
|
0ff911cc26 | ||
|
|
b5b14b2f9d | ||
|
|
2b6f41e0d0 | ||
|
|
9b429cc751 | ||
|
|
ec56dffd19 | ||
|
|
a09f2093b5 | ||
|
|
b15d3be88a | ||
|
|
a26628ed50 | ||
|
|
0b5a798343 | ||
|
|
224ae50e91 | ||
|
|
03d7728d46 | ||
|
|
19ba15f2f1 | ||
|
|
9da9967b83 | ||
|
|
1510c45ecb | ||
|
|
9b76c9fe3e | ||
|
|
ea4564c827 | ||
|
|
0a97e4e038 | ||
|
|
8e19164977 | ||
|
|
ab60bb8d0b | ||
|
|
c7ca4d9b97 |
No files matched your search
+231
-9
@@ -1,43 +1,265 @@
|
||||
name: CMake
|
||||
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
- 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
|
||||
strategy:
|
||||
matrix:
|
||||
cache-name: [msys64-cache]
|
||||
env:
|
||||
MSYSTEM: MINGW64
|
||||
FF_SCRIPT_SECTIONS: '0'
|
||||
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
|
||||
TEST_ARGS: '--no-suite qtest'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up MSYS2
|
||||
run: |
|
||||
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
|
||||
If ( !(Test-Path -Path msys64\var\cache ) ) {
|
||||
mkdir msys64\var\cache
|
||||
}
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
|
||||
Write-Output "Cached installer sig" ;
|
||||
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
|
||||
Write-Output "Mis-matched installer sig, new installer download required" ;
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
} else {
|
||||
Write-Output "Matched installer sig, cached installer still valid"
|
||||
}
|
||||
} else {
|
||||
Write-Output "No cached installer sig, new installer download required" ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
}
|
||||
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
|
||||
Write-Output "Fetching latest installer" ;
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
|
||||
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
|
||||
} else {
|
||||
Write-Output "Using cached installer"
|
||||
}
|
||||
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
|
||||
msys64\var\cache\msys2.exe -y
|
||||
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
|
||||
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
|
||||
taskkill /F /FI "MODULES eq msys-2.0.dll"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
|
||||
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
|
||||
bison \
|
||||
diffutils \
|
||||
flex \
|
||||
tar \
|
||||
doxygen \
|
||||
cmake \
|
||||
wget \
|
||||
git \
|
||||
grep \
|
||||
make \
|
||||
rsync \
|
||||
ninja \
|
||||
glib2-devel \
|
||||
patch \
|
||||
sed \
|
||||
mingw-w64-x86_64-cmake \
|
||||
mingw-w64-x86_64-binutils \
|
||||
mingw-w64-x86_64-doxygen \
|
||||
mingw-w64-x86_64-capstone \
|
||||
mingw-w64-x86_64-ccache \
|
||||
mingw-w64-x86_64-curl \
|
||||
mingw-w64-x86_64-cyrus-sasl \
|
||||
mingw-w64-x86_64-dtc \
|
||||
mingw-w64-x86_64-gcc \
|
||||
mingw-w64-x86_64-glib2 \
|
||||
mingw-w64-x86_64-gnutls \
|
||||
mingw-w64-x86_64-gtk3 \
|
||||
mingw-w64-x86_64-libgcrypt \
|
||||
mingw-w64-x86_64-libjpeg-turbo \
|
||||
mingw-w64-x86_64-libnfs \
|
||||
mingw-w64-x86_64-libpng \
|
||||
mingw-w64-x86_64-libssh \
|
||||
mingw-w64-x86_64-libtasn1 \
|
||||
mingw-w64-x86_64-libusb \
|
||||
mingw-w64-x86_64-lzo2 \
|
||||
mingw-w64-x86_64-libslirp \
|
||||
mingw-w64-x86_64-nettle \
|
||||
mingw-w64-x86_64-clang \
|
||||
mingw-w64-x86_64-ninja \
|
||||
mingw-w64-x86_64-pixman \
|
||||
mingw-w64-x86_64-pkgconf \
|
||||
mingw-w64-x86_64-python \
|
||||
mingw-w64-x86_64-SDL2 \
|
||||
mingw-w64-x86_64-SDL2_image \
|
||||
mingw-w64-x86_64-snappy \
|
||||
mingw-w64-x86_64-spice \
|
||||
mingw-w64-x86_64-usbredir \
|
||||
mingw-w64-x86_64-zstd \
|
||||
mingw-w64-x86_64-make'
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
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)"
|
||||
|
||||
|
||||
vsbuild-CLANG:
|
||||
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 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
nmake
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
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
|
||||
path: ${{github.workspace}}/build/bin
|
||||
@@ -1,10 +1,14 @@
|
||||
# Ignore binary files
|
||||
out/
|
||||
vcpkg/
|
||||
*.bin
|
||||
|
||||
# Ignore compiled object files
|
||||
.vs/
|
||||
.vscode/
|
||||
*.o
|
||||
*.out
|
||||
*.obj
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
@@ -16,6 +20,9 @@ CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore Visual Studio auto-save recovery folder
|
||||
enc_temp_folder/
|
||||
|
||||
# Ignore CodeLite configuration files
|
||||
*.workspace
|
||||
*.workspace.*
|
||||
@@ -30,6 +37,7 @@ dingusppc.exe
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumb.db
|
||||
ehthumbs.db
|
||||
|
||||
# IDE ignores
|
||||
build
|
||||
|
||||
+9
-3
@@ -114,7 +114,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
"${PROJECT_SOURCE_DIR}/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/*.include")
|
||||
|
||||
if (APPLE)
|
||||
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
|
||||
@@ -180,9 +181,14 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_compile_options("-DPPC_BENCHMARKS")
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.include"
|
||||
)
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
# $<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
# DingusPPC
|
||||
|
||||
|
||||
## Developers
|
||||
|
||||
- divingkatae
|
||||
- maximumspatium
|
||||
- joevt
|
||||
- mihaip
|
||||
|
||||
## NT4/PPC fork
|
||||
|
||||
- Wack0
|
||||
|
||||
## DevOps
|
||||
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
- leap0x7b
|
||||
- sdkmap
|
||||
- dressupgeekout
|
||||
- kth5
|
||||
- dyharlan
|
||||
- roytam1
|
||||
|
||||
## Testing
|
||||
|
||||
- LagLifeYT
|
||||
|
||||
## Thanks
|
||||
|
||||
- 68kmla
|
||||
- AppleFritter
|
||||
- Archive.org
|
||||
- Bitsavers
|
||||
- Blitter.net
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
- The developers of other PowerPC Mac emulators, past and present
|
||||
- All those preserving the software and source code of 68k and PowerPC Macs
|
||||
@@ -57,7 +57,15 @@ You will also have to recursive clone or run
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB and Capstone modules are not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
This is because the CubeB, Capstone, and SDL2 modules are not included by default.
|
||||
|
||||
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.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
|
||||
+76
-31
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/memctrl/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <debugger/debugger.h>
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
@@ -38,9 +45,12 @@ uint32_t cs_code[] = {
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
|
||||
constexpr uint32_t test_samples = 200;
|
||||
constexpr uint32_t test_iterations = 5;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
@@ -53,7 +63,7 @@ int main(int argc, char** argv) {
|
||||
MPC106* grackle_obj = new MPC106;
|
||||
|
||||
/* we need some RAM */
|
||||
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||
if (!grackle_obj->add_ram_region(0, 0x1000 + test_size)) {
|
||||
LOG_F(ERROR, "Could not create RAM region");
|
||||
delete(grackle_obj);
|
||||
return -1;
|
||||
@@ -61,51 +71,86 @@ int main(int argc, char** argv) {
|
||||
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
mmu_write_vmem<uint32_t>(i * 4, 0, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mmu_write_vmem<uint8_t>(0x1000+i, rand() % 256);
|
||||
LOG_F(INFO, "Test size: 0x%X", test_size);
|
||||
LOG_F(INFO, "First few bytes:");
|
||||
bool did_lf = false;
|
||||
for (i = 0; i < test_size; i++) {
|
||||
uint8_t val = rand() % 256;
|
||||
mmu_write_vmem<uint8_t>(0x1000 + i, 0, val);
|
||||
if (i < 64) {
|
||||
printf("%02x", val);
|
||||
did_lf = false;
|
||||
if (i % 32 == 31) {
|
||||
printf("\n");
|
||||
did_lf = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!did_lf)
|
||||
printf("\n");
|
||||
|
||||
#if 0
|
||||
/* prepare benchmark code execution */
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
enter_debugger();
|
||||
#endif
|
||||
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
uint32_t checksum = ppc_state.gpr[3];
|
||||
|
||||
// run the clock once for cache fill etc.
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
uint64_t overhead = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
|
||||
if (time_elapsed.count() < overhead)
|
||||
overhead = time_elapsed.count();
|
||||
}
|
||||
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
|
||||
|
||||
for (int theproc = 0; theproc < 2; theproc++) {
|
||||
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
|
||||
for (i = 0; i < test_iterations; i++) {
|
||||
uint64_t best_sample = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
if (time_elapsed.count() < best_sample)
|
||||
best_sample = time_elapsed.count();
|
||||
}
|
||||
if (ppc_state.gpr[3] != checksum)
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
best_sample -= overhead;
|
||||
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
+3
-1
@@ -50,6 +50,8 @@ public:
|
||||
uint32_t flags;
|
||||
uint32_t xrel;
|
||||
uint32_t yrel;
|
||||
uint32_t xabs;
|
||||
uint32_t yabs;
|
||||
uint8_t buttons_state;
|
||||
};
|
||||
|
||||
@@ -114,7 +116,7 @@ private:
|
||||
uint64_t unhandled_events = 0;
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint64_t mouse_motions = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
+35
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -41,7 +41,7 @@ void EventManager::poll_events()
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
power_off_reason = po_quit;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
@@ -56,7 +56,7 @@ void EventManager::poll_events()
|
||||
case SDL_KEYUP: {
|
||||
// Internal shortcuts to trigger mouse grab, intentionally not
|
||||
// sent to the host.
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
toggle_mouse_grab(event.key);
|
||||
}
|
||||
@@ -89,6 +89,8 @@ void EventManager::poll_events()
|
||||
MouseEvent me;
|
||||
me.xrel = event.motion.xrel;
|
||||
me.yrel = event.motion.yrel;
|
||||
me.xabs = event.motion.x;
|
||||
me.yabs = event.motion.y;
|
||||
me.flags = MOUSE_EVENT_MOTION;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
@@ -96,7 +98,16 @@ void EventManager::poll_events()
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 1;
|
||||
Uint8 adb_button;
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT : adb_button = 0; break;
|
||||
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
|
||||
case SDL_BUTTON_RIGHT : adb_button = 1; break;
|
||||
default : adb_button = event.button.button - 1;
|
||||
}
|
||||
me.buttons_state = (this->buttons_state |= (1 << adb_button));
|
||||
me.xabs = event.button.x;
|
||||
me.yabs = event.button.y;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
@@ -104,7 +115,16 @@ void EventManager::poll_events()
|
||||
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 0;
|
||||
Uint8 adb_button;
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT : adb_button = 0; break;
|
||||
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
|
||||
case SDL_BUTTON_RIGHT : adb_button = 1; break;
|
||||
default : adb_button = event.button.button - 1;
|
||||
}
|
||||
me.buttons_state = (this->buttons_state &= ~(1 << adb_button));
|
||||
me.xabs = event.button.x;
|
||||
me.yabs = event.button.y;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
@@ -284,6 +304,16 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
case 0XE8: return AdbKey_6; // E-grave
|
||||
case 0XEC: return AdbKey_LeftBracket; // I-grave
|
||||
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
|
||||
|
||||
// Spanish keyboard
|
||||
case 0XA1: return AdbKey_Comma; // Inverted question mark
|
||||
case 0XBA: return AdbKey_6; // Backslash
|
||||
case 0XE7: return AdbKey_Slash; // C-cedilla
|
||||
case 0XF1: return AdbKey_Semicolon; // N-tilde
|
||||
case 0X4000002f:
|
||||
return AdbKey_LeftBracket; // Acute
|
||||
case 0X40000034:
|
||||
return AdbKey_Semicolon; // Acute
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
+5
-5
@@ -33,11 +33,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
#define NS_PER_MSEC 1E6
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
#define NS_PER_SEC 1000000000
|
||||
#define USEC_PER_SEC 1000000
|
||||
#define NS_PER_USEC 1000
|
||||
#define NS_PER_MSEC 1000000
|
||||
#define ONE_BILLION_NS 1000000000
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
|
||||
// such as names of functions and macros.
|
||||
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
|
||||
#define OPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFT(op, __VA_ARGS__) template <field_shift shift> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE(op, __VA_ARGS__) void dppc_interpreter::ppc_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODECARRY(op, __VA_ARGS__) template <field_carry carry, field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELOGIC(op, __VA_ARGS__) template <logical_fun logical_op, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELKAA(op, __VA_ARGS__) template <field_lk l, field_aa a> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601L(op, __VA_ARGS__) template <field_lk l, field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODE(op, __VA_ARGS__) void dppc_interpreter::power_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODEMEM(op, __VA_ARGS__) template <class T> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFTREC(op, __VA_ARGS__) template <field_direction isleft, field_rc rec > void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601REC(op, __VA_ARGS__) template <field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEEXTSIGN(op, __VA_ARGS__) template <class T, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) ppc_state.gpr[reg] = ppc_result
|
||||
#define ppc_set_xer(entry) ppc_state.spr[SPR::XER] |= entry#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr)
|
||||
@@ -3,6 +3,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.include"
|
||||
)
|
||||
|
||||
add_library(cpu_ppc OBJECT ${SOURCES})
|
||||
+6
-605
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,615 +23,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcdecodemacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = uint32_t(0xFFFFFFFFUL << (31 - rot_me));
|
||||
uint32_t m1 = 0xFFFFFFFFU >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFU << (31 - rot_me);
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
ppc_result_d = 64;
|
||||
break;
|
||||
default:
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
|
||||
uint64_t dividend = ((uint64_t)ppc_result_a << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
|
||||
if ((ppc_result_a == 0x80000000UL && divisor == -1) || !divisor) {
|
||||
ppc_state.spr[SPR::MQ] = 0;
|
||||
ppc_result_d = 0x80000000UL; // -2^31 aka INT32_MIN
|
||||
} else {
|
||||
ppc_result_d = uint32_t(dividend / divisor);
|
||||
ppc_state.spr[SPR::MQ] = dividend % divisor;
|
||||
}
|
||||
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_div<RC0, OV0>();
|
||||
template void dppc_interpreter::power_div<RC0, OV1>();
|
||||
template void dppc_interpreter::power_div<RC1, OV0>();
|
||||
template void dppc_interpreter::power_div<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) >= int32_t(ppc_result_b))\
|
||||
? 0 : ppc_result_b - ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_copied = 0;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
|
||||
// for storing each byte
|
||||
uint32_t bitmask = 0xFF000000;
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_to_load > 0) {
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
|
||||
ppc_result_d = (ppc_result_d & ~bitmask) | (return_value << shift_amount);
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
reg_d = (reg_d + 1) & 31;
|
||||
bitmask = 0xFF000000;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
bitmask >>= 8;
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ppc_effective_address++;
|
||||
bytes_copied++;
|
||||
bytes_to_load--;
|
||||
|
||||
if (return_value == matching_byte)
|
||||
break;
|
||||
}
|
||||
|
||||
// store partiallly loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | bytes_copied;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
uint32_t mask_start = ppc_result_d & 31;
|
||||
uint32_t mask_end = ppc_result_b & 31;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<true>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<true>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
uint32_t ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a & 0x80000000 ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= ((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
} else {
|
||||
ppc_result_a &= ~((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
} else {
|
||||
ppc_result_a = 0;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & rot_sh)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((rot_sh & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = rot_sh;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
#include "ppcopmacros.h"
|
||||
#include "poweropcodes.include"
|
||||
@@ -0,0 +1,531 @@
|
||||
POWEROPCODEOVREC (abs, 31, 360,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(instr);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE31 (clcs, 31, 531,
|
||||
ppc_grab_da(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
default:
|
||||
ppc_result_d = is_601 ? 64 : 32; break;
|
||||
case 7:
|
||||
case 23:
|
||||
ppc_result_d = is_601 ? 64 : 0; break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 24:
|
||||
case 25:
|
||||
ppc_result_d = is_601 ? 64 : 4; break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 26:
|
||||
case 27:
|
||||
ppc_result_d = is_601 ? 64 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (div, 31, 331,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (divs, 31, 363,
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (doz, 31, 264,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (dozi, , 9,
|
||||
ppc_grab_regsdasimm(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (lscbx, 31, 277,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ea, instr);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ea++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec) { \
|
||||
ppc_state.cr = \
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) | \
|
||||
(is_match ? CRx_bit::CR_EQ : 0) | \
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskg, 31, 29,
|
||||
ppc_grab_regssab(instr);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec){
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskir, 31, 541,
|
||||
ppc_grab_regssab(instr);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (mul, 31, 107,
|
||||
ppc_grab_regsdab(instr);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (nabs, 31, 488,
|
||||
ppc_grab_regsda(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (rlmi, , 22,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_mb = (instr >> 6) & 0x1F;
|
||||
unsigned rot_me = (instr >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((instr & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (rrib, 31, 537,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sle, 31, 153,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sleq, 31, 217,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sliq, 31, 184,
|
||||
ppc_grab_regssash(instr);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slliq, 31, 248,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sllq, 31, 216,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slq, 31, 152,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraiq, 31, 952,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraq, 31, 920,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sre, 31, 665,
|
||||
ppc_grab_regssab(instr);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srea, 31, 921,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sreq, 31, 729,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sriq, 31, 696,
|
||||
ppc_grab_regssash(instr);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srliq, 31, 760,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srlq, 31, 728,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srq, 31, 664,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
@@ -23,6 +23,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "ppcemu.h"
|
||||
|
||||
|
||||
#define ppc_set_cr(entry) \
|
||||
ppc_state.cr |= entry
|
||||
|
||||
#define ppc_unset_cr(entry) \
|
||||
ppc_state.cr &= ~entry
|
||||
|
||||
#define ppc_set_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] |= entry
|
||||
|
||||
#define ppc_unset_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] &= ~entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define power_store_ctr(entry) \
|
||||
ppc_state.spr[SPR::CTR] = entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
@@ -36,83 +59,129 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regsasimm(opcode) \
|
||||
#define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regssauimm(opcode) \
|
||||
#define ppc_grab_regssauimm(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfd_regsauimm(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfds(opcode) \
|
||||
int crf_d = (instr >> 21) & 0x1C; \
|
||||
int crf_s = (instr >> 16) & 0x1C;
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define ppc_grab_s(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
int reg_b = (opcode >> 11) & 31;\
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash_stswi(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result;
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) \
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_sfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_store_dfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_dfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
@@ -169,4 +238,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
#define ppc_grab_mtfsf(opcode) \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint8_t fm = (opcode >> 17) & 0xFF;
|
||||
|
||||
#define ppc_grab_mtfsfi(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
uint32_t imm = (opcode << 16) & 0xF0000000UL;
|
||||
|
||||
#define ppc_grab_crfd(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C;
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
+118
-117
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define _CRT_SECURE_NO_WARNINGS /* shut up MSVC regarding the unsafe strcpy/strcat */
|
||||
|
||||
#include "ppcdisasm.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional> /* without this, MSVC doesn't understand std::function */
|
||||
#include <iostream>
|
||||
@@ -286,52 +287,52 @@ const char* spr_index31[32] = {
|
||||
|
||||
/** various formatting helpers. */
|
||||
void fmt_oneop(PPCDisasmContext* ctx, const char* opc, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opc, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opc, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
}
|
||||
|
||||
void fmt_oneop_out(PPCDisasmContext* ctx, const char* opc, int dst) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opc, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opc, dst);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_in(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_in(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_simm(PPCDisasmContext* ctx, const char* opc, int dst, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %s0x%X", opc, dst, (imm < 0) ? "-" : "", abs(imm));
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %s0x%X", opc, dst, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_fromspr(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8spr%d, spr%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s pr%d, spr%d", opc, dst, src);
|
||||
add_reg_in(ctx, "spr%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_tospr(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sspr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s spr%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "spr%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opc, dst, src1);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opc, dst, src1);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_out(ctx, "f%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, r%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, r%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_in(ctx, "r%d", src2);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
@@ -345,32 +346,32 @@ void fmt_threeop_store(PPCDisasmContext* ctx, const char* opc, int dst, int src1
|
||||
}
|
||||
|
||||
void fmt_threeop_crb(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d, crb%d, crb%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d, crb%d, crb%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
void fmt_threeop_uimm(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, 0x%X", opc, dst, src1, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, 0x%X", opc, dst, src1, imm);
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop_simm(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %s0x%X", opc, dst, src1, (imm < 0) ? "-" : "", abs(imm));
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %s0x%X", opc, dst, src1, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d, f%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d, f%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_in(ctx, "f%d", src2);
|
||||
add_reg_out(ctx, "f%d", dst);
|
||||
}
|
||||
|
||||
void fmt_fourop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2, int src3) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d, f%d, f%d", opc, dst, src1, src2, src3);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d, f%d, f%d", opc, dst, src1, src2, src3);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_in(ctx, "f%d", src2);
|
||||
add_reg_in(ctx, "f%d", src3);
|
||||
@@ -379,12 +380,12 @@ void fmt_fourop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, i
|
||||
|
||||
void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int sh, int mb, int me, bool imm) {
|
||||
if (imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, r%d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, r%d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_in(ctx, "r%d", sh);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
@@ -394,7 +395,7 @@ void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int
|
||||
/* Opcodes */
|
||||
|
||||
void opc_illegal(PPCDisasmContext* ctx) {
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", "dc.l", ctx->instr_code);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", "dc.l", ctx->instr_code);
|
||||
}
|
||||
|
||||
void opc_twi(PPCDisasmContext* ctx) {
|
||||
@@ -409,12 +410,12 @@ void opc_twi(PPCDisasmContext* ctx) {
|
||||
|
||||
if (strlen(opcode) > 0) {
|
||||
strcat(opcode, "i");
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0x%X", opcode, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0x%X", opcode, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, 0x%X", "twi", to, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d, 0x%X", "twi", to, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
}
|
||||
|
||||
@@ -478,7 +479,7 @@ void fmt_rot_imm(PPCDisasmContext* ctx, const char* opc, int ra, int rs, int n)
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d", opcode, ra, rs, n);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d", opcode, ra, rs, n);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "r%d", ra);
|
||||
}
|
||||
@@ -492,7 +493,7 @@ void fmt_rot_2imm(PPCDisasmContext* ctx, const char* opc, int ra, int rs, int n,
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d, %d", opcode, ra, rs, n, b);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d", opcode, ra, rs, n, b);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "r%d", ra);
|
||||
}
|
||||
@@ -630,13 +631,13 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!ls) {
|
||||
if ((ctx->instr_code >> 26) & 0x1) {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, 0x%X", "cmpwi", crfd, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, 0x%X", "cmpwi", crfd, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, r%d, %s0x%X", "cmplwi", crfd, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
"%-7s cr%d, r%d, %s0x%X", "cmplwi", crfd, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -645,13 +646,13 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((ctx->instr_code >> 26) & 0x1) {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, 0x%X", "cmpi", crfd, ls, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, %d, r%d, 0x%X", "cmpi", crfd, ls, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, %d, r%d, %s0x%X", "cmpli", crfd, ls, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
"%-7s cr%d, %d, r%d, %s0x%X", "cmpli", crfd, ls, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -668,7 +669,7 @@ void opc_bool_im(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (index == 0) {
|
||||
if (imm == 0 && !ra && !rs && !imm) { /* unofficial, produced by IDA */
|
||||
ctx->instr_str = my_sprintf("%-8s", "nop");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "nop");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -701,7 +702,7 @@ void generic_bcx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi, uint32_t dst)
|
||||
if (ctx->instr_code & 2) {
|
||||
strcat(opcode, "a"); /* add suffix "a" if the AA bit is set */
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi, dst);
|
||||
}
|
||||
|
||||
void generic_bcctrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
@@ -718,7 +719,7 @@ void generic_bcctrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
add_reg_out(ctx, "lr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi);
|
||||
}
|
||||
|
||||
void generic_bclrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
@@ -739,7 +740,7 @@ void generic_bclrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
add_reg_out(ctx, "lr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi);
|
||||
}
|
||||
|
||||
void opc_bcx(PPCDisasmContext* ctx) {
|
||||
@@ -758,7 +759,7 @@ void opc_bcx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", bx_mnem[0], dst);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", bx_mnem[0], dst);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -799,7 +800,7 @@ void opc_bcx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, (ctx->instr_code & 0x8000) ? "-" : "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s0x%08X", opcode, operands, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s %s0x%08X", opcode, operands, dst);
|
||||
}
|
||||
|
||||
void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
@@ -821,7 +822,7 @@ void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s", bcctrx_mnem[ctx->instr_code & 1]);
|
||||
ctx->instr_str = my_sprintf("%-7s ", bcctrx_mnem[ctx->instr_code & 1]);
|
||||
add_reg_in(ctx, "ctr");
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_out(ctx, "lr");
|
||||
@@ -849,7 +850,7 @@ void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s", opcode, operands);
|
||||
ctx->instr_str = my_sprintf("%-7s %s", opcode, operands);
|
||||
}
|
||||
|
||||
void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
@@ -867,7 +868,7 @@ void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s", bclrx_mnem[ctx->instr_code & 1]);
|
||||
ctx->instr_str = my_sprintf("%-7s ", bclrx_mnem[ctx->instr_code & 1]);
|
||||
add_reg_in(ctx, "lr");
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_out(ctx, "lr");
|
||||
@@ -911,21 +912,21 @@ void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s", opcode, operands);
|
||||
ctx->instr_str = my_sprintf("%-7s %s", opcode, operands);
|
||||
}
|
||||
|
||||
void opc_bx(PPCDisasmContext* ctx) {
|
||||
uint32_t dst = ((ctx->instr_code & 2) ? 0 : ctx->instr_addr) +
|
||||
SIGNEXT(ctx->instr_code & 0x3FFFFFC, 25);
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", bx_mnem[ctx->instr_code & 3], dst);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", bx_mnem[ctx->instr_code & 3], dst);
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_in(ctx, "lr");
|
||||
}
|
||||
}
|
||||
|
||||
void opc_sc(PPCDisasmContext* ctx) {
|
||||
ctx->instr_str = my_sprintf("%-8s", "sc");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "sc");
|
||||
}
|
||||
|
||||
void opc_group19(PPCDisasmContext* ctx) {
|
||||
@@ -958,7 +959,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
|
||||
switch (ext_opc) {
|
||||
case 0:
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, cr%d", "mcrf", (rs >> 2), (ra >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, cr%d", "mcrf", (rs >> 2), (ra >> 2));
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -967,7 +968,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 33:
|
||||
if (ctx->simplified && (ra == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crnor", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crnor", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -975,7 +976,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
}
|
||||
return;
|
||||
case 50:
|
||||
ctx->instr_str = my_sprintf("%-8s", "rfi");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "rfi");
|
||||
add_reg_in(ctx, "msr");
|
||||
add_reg_in(ctx, "srr0");
|
||||
add_reg_in(ctx, "srr1");
|
||||
@@ -983,7 +984,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 129:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crandc", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crandc", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -991,15 +992,15 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
}
|
||||
return;
|
||||
case 150:
|
||||
ctx->instr_str = my_sprintf("%-8s", "isync");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "isync");
|
||||
return;
|
||||
case 193:
|
||||
if (ctx->simplified && (rs == ra) && (rs == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", "crclr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d", "crclr", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && ((rs != ra) || (rs != rb))) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crxor", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crxor", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1008,7 +1009,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 225:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crnand", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crnand", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1017,7 +1018,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 257:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crand", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crand", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1026,11 +1027,11 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 289:
|
||||
if (ctx->simplified && (rs == ra) && (rs == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", "crset", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d", "crset", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && ((rs != ra) || (rs != rb))) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "creqv", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "creqv", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1039,7 +1040,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 417:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crorc", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crorc", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1048,12 +1049,12 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 449:
|
||||
if (ctx->simplified && (ra == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d, crb%d", "crmove", rs, ra);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d, crb%d", "crmove", rs, ra);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && (ra != rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "cror", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "cror", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1148,7 +1149,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if ((ra != 0) || (rb != 0) || rc_set)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mtmsr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mtmsr", rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "msr");
|
||||
}
|
||||
@@ -1156,33 +1157,33 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ra & 16)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d", "mtsr", ra, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d", "mtsr", ra, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "sr%d", ra);
|
||||
}
|
||||
} else if (index == 7) { /* mtsrin */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "mtsrin", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "mtsrin", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
std::string reg_name = add_reg_in(ctx, "r%d", rb);
|
||||
uint64_t reg_val = get_reg(reg_name);
|
||||
add_reg_out(ctx, "sr%d", reg_val >> 28);
|
||||
} else if (index == 9) { /* tlbie */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "tlbie", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "tlbie", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
} else if (index == 11) { /* tlbia */
|
||||
ctx->instr_str = my_sprintf("%-8s", "tlbia");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "tlbia");
|
||||
} else if (index == 30) { /* tlbld - 603 only */
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbld", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
} else if (index == 30) { /* tlbli - 603 only */
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbli", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
}
|
||||
@@ -1238,7 +1239,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
fmt_twoop(ctx, opcode, rs, ra);
|
||||
fmt_twoop(ctx, opcode, ra, rs);
|
||||
|
||||
return;
|
||||
|
||||
@@ -1321,7 +1322,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
@@ -1338,7 +1339,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1363,7 +1364,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
} else if ((index == 18) || (index == 26)) { /* sync, eieio */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
ctx->instr_str = my_sprintf("%-7s ", opcode);
|
||||
return;
|
||||
}
|
||||
/* dcba, dcbf, dcbi, dcbst, dcbt, dcbz, icbi */
|
||||
@@ -1375,7 +1376,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8s0, r%d", opcode, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s 0, r%d", opcode, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
else
|
||||
@@ -1383,7 +1384,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
} else if (index == 17) { /* tlbsync */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
ctx->instr_str = my_sprintf("%-7s ", opcode);
|
||||
return;
|
||||
} else {
|
||||
opc_illegal(ctx);
|
||||
@@ -1407,13 +1408,13 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!(rs & 1)) {
|
||||
if ((rs >> 2) == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "cmpw", ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "cmpw", ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1422,7 +1423,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmp", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmp", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1435,14 +1436,14 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
strcpy(opcode, trap_cond[rs]);
|
||||
|
||||
if (strlen(opcode) != 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opcode, ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opcode, ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "tw", rs, ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d, r%d", "tw", rs, ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
@@ -1456,7 +1457,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "lwarx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "lwarx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1483,9 +1484,9 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!(rs & 1)) {
|
||||
if ((rs >> 2) == 0)
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "cmplw", ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "cmplw", ra, rb);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmplw", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmplw", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1496,14 +1497,14 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, %d, r%d, r%d", "cmpl", (rs >> 2), (rs & 1), ra, rb);
|
||||
"%-7s cr%d, %d, r%d, r%d", "cmpl", (rs >> 2), (rs & 1), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
break;
|
||||
case 83: /* mfmsr */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mfmsr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mfmsr", rs);
|
||||
add_reg_in(ctx, "msr");
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
break;
|
||||
@@ -1512,10 +1513,10 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
if (((ctx->instr_code >> 12) & 0xFF) == 0xFF)
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mtcr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mtcr", rs);
|
||||
else
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8s0x%02X, r%d", "mtcrf", (ctx->instr_code >> 12) & 0xFF, rs);
|
||||
"%-7s 0x%02X, r%d", "mtcrf", (ctx->instr_code >> 12) & 0xFF, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -1531,7 +1532,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "xer");
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1544,42 +1545,42 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 0:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index0[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index0[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 8:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index8[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index8[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 16:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index16[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index16[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 29:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index29[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index29[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 30:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index30[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index30[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 31:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index31[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index31[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
@@ -1600,7 +1601,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %d", "mftb", rs, ref_spr);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %d", "mftb", rs, ref_spr);
|
||||
if (ref_spr == 268) {
|
||||
add_reg_in(ctx, "tbl");
|
||||
} else if (ref_spr == 269) {
|
||||
@@ -1616,7 +1617,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 0:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index0[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
if (spr_low == 0x16) { /* decrementer */
|
||||
add_reg_in(ctx, "msr");
|
||||
@@ -1626,35 +1627,35 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 8:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index8[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index8[spr_low]);
|
||||
return;
|
||||
case 16:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index16[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index16[spr_low]);
|
||||
return;
|
||||
case 29:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index29[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index29[spr_low]);
|
||||
return;
|
||||
case 30:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index30[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index30[spr_low]);
|
||||
return;
|
||||
case 31:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index31[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index31[spr_low]);
|
||||
return;
|
||||
@@ -1663,7 +1664,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
fmt_twoop_tospr(ctx, "mtspr", ref_spr, rs);
|
||||
break;
|
||||
case 512: /* mcrxr */
|
||||
ctx->instr_str = my_sprintf("%-8scr%d", "mcrxr", (rs >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d", "mcrxr", (rs >> 2));
|
||||
add_reg_in(ctx, "xer");
|
||||
add_reg_out(ctx, "cr");
|
||||
add_reg_out(ctx, "xer");
|
||||
@@ -1683,7 +1684,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "lswx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "lswx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1705,7 +1706,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ra & 16)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %d", "mfsr", rs, ra);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %d", "mfsr", rs, ra);
|
||||
add_reg_in(ctx, "sr%d", ra);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1718,7 +1719,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
rb = 32;
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, %x", "lswi", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, %x", "lswi", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1728,7 +1729,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
break;
|
||||
case 659: /* mfsrin */
|
||||
{
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "mfsrin", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "mfsrin", rs, rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
std::string reg_name = add_reg_in(ctx, "r%d", rb);
|
||||
uint64_t reg_val = get_reg(reg_name);
|
||||
@@ -1741,7 +1742,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "stswx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "stswx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1759,7 +1760,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
rb = 32;
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, %d", "stswi", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, %d", "stswi", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -2071,7 +2072,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2138,7 +2139,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rs & 3)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, f%d, f%d", "fcmpu", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, f%d, f%d", "fcmpu", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "f%d", ra);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -2153,7 +2154,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2168,7 +2169,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2183,7 +2184,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2193,7 +2194,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rs & 3)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, f%d, f%d", "fcmpo", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, f%d, f%d", "fcmpo", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_in(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -2207,7 +2208,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d", opcode, rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
case 40: /* fneg */
|
||||
@@ -2221,7 +2222,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2229,7 +2230,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
case 64:
|
||||
strcpy(opcode, "mcrfs");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, cr%d", opcode, (rs >> 2), (ra >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, cr%d", opcode, (rs >> 2), (ra >> 2));
|
||||
add_reg_in(ctx, "fpscr");
|
||||
add_reg_out(ctx, "cr");
|
||||
break;
|
||||
@@ -2241,7 +2242,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d", opcode, rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
case 72: /* fmr */
|
||||
@@ -2255,7 +2256,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2270,7 +2271,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
add_reg_out(ctx, "fpscr");
|
||||
}
|
||||
break;
|
||||
@@ -2284,7 +2285,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2299,7 +2300,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2315,7 +2316,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if ((ra != 0) || (rb != 0))
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d", opcode, rs);
|
||||
add_reg_in(ctx, "fpscr");
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2328,7 +2329,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d", opcode, fm, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, f%d", opcode, fm, rb);
|
||||
add_reg_in(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
@@ -2357,11 +2358,11 @@ void opc_intldst(PPCDisasmContext* ctx) {
|
||||
|
||||
if (ra) {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sr%d, %s0x%X(r%d)", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
"%-7s r%d, %s0x%X(r%d)", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sr%d, %s0x%X", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
"%-7s r%d, %s0x%X", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2385,11 +2386,11 @@ void opc_fltldst(PPCDisasmContext* ctx) {
|
||||
|
||||
if (ra) {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sf%d, %s0x%X(r%d)", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
"%-7s f%d, %s0x%X(r%d)", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sf%d, %s0x%X", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
"%-7s f%d, %s0x%X", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+81
-270
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
@@ -46,7 +47,7 @@ enum EXEC_MODE:uint32_t {
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
typedef void (*PPCOpcode)(uint32_t);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
@@ -84,17 +85,18 @@ extern SetPRS ppc_state;
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum SPR : int {
|
||||
MQ = 0,
|
||||
MQ = 0, // MQ (601)
|
||||
XER = 1,
|
||||
RTCU_U = 4, // user RTCU
|
||||
RTCL_U = 5, // user RTCL
|
||||
RTCU_U = 4, // user mode RTCU (601)
|
||||
RTCL_U = 5, // user mode RTCL (601)
|
||||
DEC_U = 6, // user mode decrementer (601)
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
RTCU_S = 20, // supervisor RTCU
|
||||
RTCL_S = 21, // supervisor RTCL
|
||||
DEC = 22, // decrementer
|
||||
RTCU_S = 20, // supervisor RTCU (601)
|
||||
RTCL_S = 21, // supervisor RTCL (601)
|
||||
DEC_S = 22, // supervisor decrementer
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
@@ -183,7 +185,6 @@ enum {
|
||||
EXEF_BRANCH = 1 << 0,
|
||||
EXEF_EXCEPTION = 1 << 1,
|
||||
EXEF_RFI = 1 << 2,
|
||||
EXEF_TIMER = 1 << 7
|
||||
};
|
||||
|
||||
enum CR_select : int32_t {
|
||||
@@ -298,23 +299,19 @@ enum Exc_Cause : uint32_t {
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
#ifdef EXEC_FLAGS_ATOMIC
|
||||
extern std::atomic<unsigned> exec_flags;
|
||||
#else
|
||||
extern unsigned exec_flags;
|
||||
#endif
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
|
||||
extern bool grab_return;
|
||||
|
||||
enum Po_Cause : int {
|
||||
po_none,
|
||||
po_starting_up,
|
||||
po_quit,
|
||||
po_quitting,
|
||||
po_shut_down,
|
||||
po_shutting_down,
|
||||
po_restarting,
|
||||
po_restart,
|
||||
po_restarting,
|
||||
po_disassemble_on,
|
||||
po_disassemble_off,
|
||||
po_enter_debugger,
|
||||
@@ -331,13 +328,10 @@ extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
inline uint32_t ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
return READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
@@ -349,24 +343,68 @@ extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
// instruction enums
|
||||
typedef enum {
|
||||
ppc_and = 1,
|
||||
ppc_andc = 2,
|
||||
ppc_eqv = 3,
|
||||
ppc_nand = 4,
|
||||
ppc_nor = 5,
|
||||
ppc_or = 6,
|
||||
ppc_orc = 7,
|
||||
ppc_xor = 8,
|
||||
} logical_fun;
|
||||
|
||||
typedef enum {
|
||||
LK0,
|
||||
LK1,
|
||||
} field_lk;
|
||||
|
||||
typedef enum {
|
||||
AA0,
|
||||
AA1,
|
||||
} field_aa;
|
||||
|
||||
typedef enum {
|
||||
SHFT0,
|
||||
SHFT1,
|
||||
} field_shift;
|
||||
|
||||
typedef enum {
|
||||
RIGHT0,
|
||||
LEFT1,
|
||||
} field_direction;
|
||||
|
||||
typedef enum {
|
||||
RC0,
|
||||
RC1,
|
||||
} field_rc;
|
||||
|
||||
typedef enum {
|
||||
OV0,
|
||||
OV1,
|
||||
} field_ov;
|
||||
|
||||
typedef enum {
|
||||
CARRY0,
|
||||
CARRY1,
|
||||
} field_carry;
|
||||
|
||||
typedef enum {
|
||||
NOT601,
|
||||
IS601,
|
||||
} field_601;
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq);
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_illegalop(uint32_t null_val=0);
|
||||
void ppc_fpu_off();
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
template <bool for601> void ppc_opcode19();
|
||||
void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables();
|
||||
void initialize_ppc_opcode_tables(bool include_601);
|
||||
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
@@ -378,8 +416,8 @@ void update_fpscr(uint32_t new_fpscr);
|
||||
/* Exception handlers. */
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
void ppc_floating_point_exception();
|
||||
void ppc_alignment_exception(uint32_t ea);
|
||||
void ppc_floating_point_exception(uint32_t instr);
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@@ -387,245 +425,9 @@ extern MemCtrlBase* mem_ctrl_instance;
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
|
||||
enum bool_fun {
|
||||
bool_and = 1,
|
||||
bool_andc = 2,
|
||||
bool_eqv = 3,
|
||||
bool_nand = 4,
|
||||
bool_nor = 5,
|
||||
bool_or = 6,
|
||||
bool_orc = 7,
|
||||
bool_xor = 8,
|
||||
};
|
||||
|
||||
enum field_setting {
|
||||
LK0 = 0,
|
||||
LK1 = 1,
|
||||
AA0 = 0,
|
||||
AA1 = 1,
|
||||
SHFT0 = 0,
|
||||
SHFT1 = 1,
|
||||
RC0 = 0,
|
||||
RC1 = 1,
|
||||
OV0 = 0,
|
||||
OV1 = 1,
|
||||
CARRY0 = 0,
|
||||
CARRY1 = 1,
|
||||
IS601 = 0,
|
||||
NOT601 = 1
|
||||
};
|
||||
|
||||
namespace dppc_interpreter {
|
||||
template <bool l, bool for601> extern void ppc_bcctr();
|
||||
template <bool l> extern void ppc_bclr();
|
||||
extern void ppc_crand();
|
||||
extern void ppc_crandc();
|
||||
extern void ppc_creqv();
|
||||
extern void ppc_crnand();
|
||||
extern void ppc_crnor();
|
||||
extern void ppc_cror();
|
||||
extern void ppc_crorc();
|
||||
extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
template <int bool_op, bool rec> extern void ppc_do_bool();
|
||||
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_add();
|
||||
template <bool rec, bool ov> extern void ppc_adde();
|
||||
template <bool rec, bool ov> extern void ppc_addme();
|
||||
template <bool rec, bool ov> extern void ppc_addze();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
template <bool rec> extern void ppc_cntlzw();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
template <bool rec, bool ov> extern void ppc_divw();
|
||||
template <bool rec, bool ov> extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
template <class T, bool rec>extern void ppc_exts();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhaux();
|
||||
extern void ppc_lhax();
|
||||
extern void ppc_lhbrx();
|
||||
extern void ppc_lwarx();
|
||||
extern void ppc_lwbrx();
|
||||
template <class T> extern void ppc_lzx();
|
||||
template <class T> extern void ppc_lzux();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
template <bool rec> extern void ppc_mulhwu();
|
||||
template <bool rec> extern void ppc_mulhw();
|
||||
template <bool rec, bool ov> extern void ppc_mullw();
|
||||
template <bool rec, bool ov> extern void ppc_neg();
|
||||
template <bool left, bool rec> extern void ppc_shift();
|
||||
template <bool rec> extern void ppc_sraw();
|
||||
template <bool rec> extern void ppc_srawi();
|
||||
template <class T> extern void ppc_stx();
|
||||
template <class T> extern void ppc_stux();
|
||||
extern void ppc_stfiwx();
|
||||
extern void ppc_sthbrx();
|
||||
extern void ppc_stwcx();
|
||||
extern void ppc_stwbrx();
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_subf();
|
||||
template <bool rec, bool ov> extern void ppc_subfe();
|
||||
template <bool rec, bool ov> extern void ppc_subfme();
|
||||
template <bool rec, bool ov> extern void ppc_subfze();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
extern void ppc_tlbli();
|
||||
extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
extern void ppc_stswi();
|
||||
extern void ppc_stswx();
|
||||
|
||||
extern void ppc_mfsr();
|
||||
extern void ppc_mfsrin();
|
||||
extern void ppc_mtsr();
|
||||
extern void ppc_mtsrin();
|
||||
|
||||
extern void ppc_mcrf();
|
||||
extern void ppc_mtcrf();
|
||||
extern void ppc_mfmsr();
|
||||
extern void ppc_mfspr();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
|
||||
template <bool rec> extern void ppc_mtfsb0();
|
||||
template <bool rec> extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
template <bool rec> extern void ppc_fmr();
|
||||
template <bool for601, bool rec> extern void ppc_mffs();
|
||||
template <bool rec> extern void ppc_mtfsf();
|
||||
template <bool rec> extern void ppc_mtfsfi();
|
||||
|
||||
template <bool shift> extern void ppc_addi();
|
||||
template <bool rec> extern void ppc_addic();
|
||||
template <bool shift> extern void ppc_andirc();
|
||||
template <bool l, bool a> extern void ppc_b();
|
||||
template <bool l, bool a> extern void ppc_bc();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
template <class T> extern void ppc_lz();
|
||||
template <class T> extern void ppc_lzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
template <bool shift> extern void ppc_ori();
|
||||
extern void ppc_rfi();
|
||||
extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
template <class T> extern void ppc_st();
|
||||
template <class T> extern void ppc_stu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
template <bool shift> extern void ppc_xori();
|
||||
|
||||
extern void ppc_lfs();
|
||||
extern void ppc_lfsu();
|
||||
extern void ppc_lfsx();
|
||||
extern void ppc_lfsux();
|
||||
extern void ppc_lfd();
|
||||
extern void ppc_lfdu();
|
||||
extern void ppc_lfdx();
|
||||
extern void ppc_lfdux();
|
||||
extern void ppc_stfs();
|
||||
extern void ppc_stfsu();
|
||||
extern void ppc_stfsx();
|
||||
extern void ppc_stfsux();
|
||||
extern void ppc_stfd();
|
||||
extern void ppc_stfdu();
|
||||
extern void ppc_stfdx();
|
||||
extern void ppc_stfdux();
|
||||
|
||||
template <bool rec> extern void ppc_fadd();
|
||||
template <bool rec> extern void ppc_fsub();
|
||||
template <bool rec> extern void ppc_fmul();
|
||||
template <bool rec> extern void ppc_fdiv();
|
||||
template <bool rec> extern void ppc_fadds();
|
||||
template <bool rec> extern void ppc_fsubs();
|
||||
template <bool rec> extern void ppc_fmuls();
|
||||
template <bool rec> extern void ppc_fdivs();
|
||||
template <bool rec> extern void ppc_fmadd();
|
||||
template <bool rec> extern void ppc_fmsub();
|
||||
template <bool rec> extern void ppc_fnmadd();
|
||||
template <bool rec> extern void ppc_fnmsub();
|
||||
template <bool rec> extern void ppc_fmadds();
|
||||
template <bool rec> extern void ppc_fmsubs();
|
||||
template <bool rec> extern void ppc_fnmadds();
|
||||
template <bool rec> extern void ppc_fnmsubs();
|
||||
template <bool rec> extern void ppc_fabs();
|
||||
template <bool rec> extern void ppc_fnabs();
|
||||
template <bool rec> extern void ppc_fneg();
|
||||
template <bool rec> extern void ppc_fsel();
|
||||
template <bool rec> extern void ppc_fres();
|
||||
template <bool rec> extern void ppc_fsqrts();
|
||||
template <bool rec> extern void ppc_fsqrt();
|
||||
template <bool rec> extern void ppc_frsqrte();
|
||||
template <bool rec> extern void ppc_frsp();
|
||||
template <bool rec> extern void ppc_fctiw();
|
||||
template <bool rec> extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
// Power-specific instructions
|
||||
template <bool rec, bool ov> extern void power_abs();
|
||||
extern void power_clcs();
|
||||
template <bool rec, bool ov> extern void power_div();
|
||||
template <bool rec, bool ov> extern void power_divs();
|
||||
template <bool rec, bool ov> extern void power_doz();
|
||||
extern void power_dozi();
|
||||
template <bool rec> extern void power_lscbx();
|
||||
template <bool rec> extern void power_maskg();
|
||||
template <bool rec> extern void power_maskir();
|
||||
template <bool rec, bool ov> extern void power_mul();
|
||||
template <bool rec, bool ov> extern void power_nabs();
|
||||
extern void power_rlmi();
|
||||
template <bool rec> extern void power_rrib();
|
||||
template <bool rec> extern void power_sle();
|
||||
template <bool rec> extern void power_sleq();
|
||||
template <bool rec> extern void power_sliq();
|
||||
template <bool rec> extern void power_slliq();
|
||||
template <bool rec> extern void power_sllq();
|
||||
template <bool rec> extern void power_slq();
|
||||
template <bool rec> extern void power_sraiq();
|
||||
template <bool rec> extern void power_sraq();
|
||||
template <bool rec> extern void power_sre();
|
||||
template <bool rec> extern void power_srea();
|
||||
template <bool rec> extern void power_sreq();
|
||||
template <bool rec> extern void power_sriq();
|
||||
template <bool rec> extern void power_srliq();
|
||||
template <bool rec> extern void power_srlq();
|
||||
template <bool rec> extern void power_srq();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
// 64-bit instructions
|
||||
|
||||
// G5+ instructions
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_main_opcode(uint32_t instr);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
@@ -636,4 +438,13 @@ void print_fprs(void); /* print content of the floating-point
|
||||
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
#include "ppcmacros_prototypes.h"
|
||||
|
||||
namespace dppc_interpreter {
|
||||
#include "ppcopcodes.include"
|
||||
#include "poweropcodes.include"
|
||||
#include "ppcfpopcodes.include"
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
#endif /* PPCEMU_H */
|
||||
+32
-32
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
@@ -56,7 +57,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
|
||||
@@ -65,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
@@ -89,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
@@ -135,7 +136,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
@@ -195,17 +196,16 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
void ppc_floating_point_exception(uint32_t instr) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x", ppc_state.pc, instr);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
switch (instr & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
@@ -226,12 +226,12 @@ void ppc_alignment_exception(uint32_t ea)
|
||||
case 0xcc000000: // lfdu
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
indirect_with_immediate_index:
|
||||
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
// indirect with immediate index
|
||||
dsisr = ((instr >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((instr >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (ppc_cur_instruction & 0xfc0007ff) {
|
||||
switch (instr & 0xfc0007ff) {
|
||||
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
|
||||
case 0x7c0002aa: // lwax (64-bit only)
|
||||
case 0x7c00042a: // lswx
|
||||
@@ -265,12 +265,12 @@ indirect_with_immediate_index:
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
dsisr = ((instr << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((instr << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((instr << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
if ((instr & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
@@ -281,31 +281,31 @@ indirect_with_index:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
instr);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
dsisr |= ((instr >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
if ((instr & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
dsisr |= ((instr >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
|
||||
+301
-548
File diff suppressed because it is too large.
Load diff
+60
-893
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,681 @@
|
||||
// Floating Point Arithmetic
|
||||
OPCODEREC (fadd, 63, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
max_double_check(val_reg_a, val_reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsub, 63, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdiv, 63, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmul, 63, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmadd, 63, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmsub, 63, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmadd, 63, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmsub, 63, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fadds, 59, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsubs, 59, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdivs, 59, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmuls, 59, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmadds, 59, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmsubs, 59, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmadds, 59, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmsubs, 59, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fabs, 63, 264,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fnabs, 63, 136,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fneg, 63, 40,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF(fsel, 63, 23,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrt, 63, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = std::sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrts, 59, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = (float)std::sqrt(testd2);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsqrte, 63, 26,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsp, 63, 12,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fres, 63, 24,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double start_num = GET_FPR(reg_b);
|
||||
double ppc_dblresult64_d = (float)(1.0 / start_num);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (start_num == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::ZX;
|
||||
}
|
||||
else if (std::isnan(start_num)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
else if (std::isinf(start_num)){
|
||||
ppc_state.fpscr &= 0xFFF9FFFF;
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fctiw, 63, 14,
|
||||
round_to_int(instr, ppc_state.fpscr & 0x3, rec);
|
||||
)
|
||||
|
||||
OPCODEREC (fctiwz, 63, 15,
|
||||
round_to_int(instr, 1, rec);
|
||||
)
|
||||
|
||||
// Floating Point Store and Load
|
||||
|
||||
OPCODE (lfs, , 48,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE (lfsu, , 49,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfsx, 31, 535,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE31 (lfsux, 31, 567,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (lfd, , 50,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE (lfdu, , 51,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfdx, 31, 599,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE31 (lfdux, 31, 631,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfs, , 52,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE (stfsu, , 53,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfsx, 31, 663,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE31 (stfsux, 31, 695,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfd, , 54,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += reg_a ? val_reg_a : 0;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE (stfdu, , 55,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfdx, 31, 727,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE31 (stfdux, 31, 759,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfiwx, 31, 983,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
)
|
||||
|
||||
// Floating Point Register Transfer
|
||||
|
||||
OPCODEREC (fmr, 63, 72,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE601REC (mffs, 63, 583,
|
||||
int reg_d = (instr >> 21) & 31;
|
||||
|
||||
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsf, 63, 711,
|
||||
ppc_grab_mtfsf(instr);
|
||||
|
||||
uint32_t cr_mask = 0;
|
||||
|
||||
if (fm == 0xFFU) { // the fast case
|
||||
cr_mask = 0xFFFFFFFFUL;
|
||||
}
|
||||
else { // the slow case
|
||||
if (fm & 0x80) cr_mask |= 0xF0000000UL;
|
||||
if (fm & 0x40) cr_mask |= 0x0F000000UL;
|
||||
if (fm & 0x20) cr_mask |= 0x00F00000UL;
|
||||
if (fm & 0x10) cr_mask |= 0x000F0000UL;
|
||||
if (fm & 0x08) cr_mask |= 0x0000F000UL;
|
||||
if (fm & 0x04) cr_mask |= 0x00000F00UL;
|
||||
if (fm & 0x02) cr_mask |= 0x000000F0UL;
|
||||
if (fm & 0x01) cr_mask |= 0x0000000FUL;
|
||||
}
|
||||
|
||||
// ensure neither FEX nor VX will be changed
|
||||
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy FPR[reg_b] to FPSCR under control of cr_mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsfi, 63, 134,
|
||||
ppc_grab_mtfsfi(instr);
|
||||
|
||||
// prepare field mask and ensure that neither FEX nor VX will be changed
|
||||
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy imm to FPSCR[crf_d] under control of the field mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
|
||||
|
||||
// Update FEX and VX according to the "usual rule"
|
||||
ppc_update_vx();
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb0, 63, 70,
|
||||
int crf_d = (instr >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
|
||||
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb1, 63, 38,
|
||||
ppc_grab_crfd(instr);
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
|
||||
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mcrfs, 63, 64,
|
||||
ppc_grab_crfds(instr);
|
||||
ppc_state.cr = (
|
||||
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
||||
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
|
||||
);
|
||||
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
|
||||
// keep only the FPSCR bits that can be explicitly cleared
|
||||
FPSCR::FX | FPSCR::OX |
|
||||
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
|
||||
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
|
||||
FPSCR::VXVC |
|
||||
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
|
||||
));
|
||||
)
|
||||
|
||||
// Floating Point Comparisons
|
||||
|
||||
OPCODE31 (fcmpo, 63, 32,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
ppc_state.fpscr |= FX | VX;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= VXSNAN;
|
||||
}
|
||||
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
|
||||
ppc_state.fpscr |= VXVC;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
|
||||
OPCODE (fcmpu, 63, 0,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
+98
-588
@@ -81,7 +81,9 @@ AddressMapEntry last_read_area;
|
||||
AddressMapEntry last_write_area;
|
||||
AddressMapEntry last_exec_area;
|
||||
AddressMapEntry last_ptab_area;
|
||||
AddressMapEntry last_dma_area;
|
||||
|
||||
/** Dummy pages for catching writes to physical read-only pages */
|
||||
static std::array<uint64_t, 8192 / sizeof(uint64_t)> dummy_page;
|
||||
|
||||
/** 601-style block address translation. */
|
||||
static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
@@ -135,19 +137,19 @@ static BATResult ppc_block_address_translation(uint32_t la)
|
||||
PPC_BAT_entry *bat_array;
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = (ppc_state.msr & MSR::PR) != 0;
|
||||
|
||||
bat_array = (type == BATType::IBAT) ? ibat_array : dbat_array;
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
// Those bits are mutually exclusive
|
||||
unsigned access_bits = ((msr_pr ^ 1) << 1) | msr_pr;
|
||||
unsigned access_bits = ((!msr_pr) << 1) | msr_pr;
|
||||
|
||||
for (int bat_index = 0; bat_index < 4; bat_index++) {
|
||||
PPC_BAT_entry* bat_entry = &bat_array[bat_index];
|
||||
|
||||
if ((bat_entry->access & access_bits) && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
if ((bat_entry->access & access_bits) != 0 && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
bat_hit = true;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -310,22 +312,28 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
bool is_writable;
|
||||
AddressMapEntry *cur_dma_rgn;
|
||||
|
||||
if (addr >= last_dma_area.start && (addr + size) <= last_dma_area.end) {
|
||||
cur_dma_rgn = &last_dma_area;
|
||||
} else {
|
||||
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
|
||||
if (!cur_dma_rgn || (addr + size) > cur_dma_rgn->end)
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory %08X!\n", addr);
|
||||
|
||||
last_dma_area = *cur_dma_rgn;
|
||||
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
|
||||
if (!cur_dma_rgn) {
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X!",
|
||||
addr, addr + size - 1
|
||||
);
|
||||
}
|
||||
|
||||
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio)
|
||||
ABORT_F("SOS: DMA access to a MMIO region is not allowed");
|
||||
if (addr + size - 1 > cur_dma_rgn->end) {
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!",
|
||||
addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end
|
||||
);
|
||||
}
|
||||
|
||||
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
if (cur_dma_rgn->type & (RT_ROM | RT_RAM)) {
|
||||
host_va = cur_dma_rgn->mem_ptr + (addr - cur_dma_rgn->start);
|
||||
is_writable = last_dma_area.type & RT_RAM;
|
||||
is_writable = cur_dma_rgn->type & RT_RAM;
|
||||
} else { // RT_MMIO
|
||||
devobj = cur_dma_rgn->devobj;
|
||||
dev_base = cur_dma_rgn->start;
|
||||
@@ -364,10 +372,7 @@ uint32_t tlb_size_mask = TLB_SIZE - 1;
|
||||
|
||||
// fake TLB entry for handling of unmapped memory accesses
|
||||
uint64_t UnmappedVal = -1ULL;
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, 0};
|
||||
|
||||
// Dummy page for catching writes to physical read-only pages
|
||||
static std::array<uint64_t, 4096 / sizeof(uint64_t)> dummy_page;
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, {{0}}};
|
||||
|
||||
uint8_t CurITLBMode = {0xFF}; // current ITLB mode
|
||||
uint8_t CurDTLBMode = {0xFF}; // current DTLB mode
|
||||
@@ -377,7 +382,7 @@ void mmu_change_mode()
|
||||
uint8_t mmu_mode;
|
||||
|
||||
// switch ITLB tables first
|
||||
mmu_mode = ((ppc_state.msr >> 4) & 0x2) | ((ppc_state.msr >> 14) & 1);
|
||||
mmu_mode = ((!!(ppc_state.msr & MSR::IR)) << 1) | !!(ppc_state.msr & MSR::PR);
|
||||
|
||||
if (CurITLBMode != mmu_mode) {
|
||||
switch(mmu_mode) {
|
||||
@@ -402,7 +407,7 @@ void mmu_change_mode()
|
||||
}
|
||||
|
||||
// then switch DTLB tables
|
||||
mmu_mode = ((ppc_state.msr >> 3) & 0x2) | ((ppc_state.msr >> 14) & 1);
|
||||
mmu_mode = ((!!(ppc_state.msr & MSR::DR)) << 1) | !!(ppc_state.msr & MSR::PR);
|
||||
|
||||
if (CurDTLBMode != mmu_mode) {
|
||||
switch(mmu_mode) {
|
||||
@@ -433,9 +438,9 @@ static TLBEntry* tlb2_target_entry(uint32_t gp_va)
|
||||
TLBEntry *tlb_entry;
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
tlb_entry = &pCurITLB2[((gp_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
tlb_entry = &pCurITLB2[((gp_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
} else {
|
||||
tlb_entry = &pCurDTLB2[((gp_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
tlb_entry = &pCurDTLB2[((gp_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
}
|
||||
|
||||
// select the target from invalid blocks first
|
||||
@@ -656,9 +661,9 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
|
||||
TLBEntry *tlb_entry;
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
tlb_entry = &pCurITLB2[((guest_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
tlb_entry = &pCurITLB2[((guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
} else {
|
||||
tlb_entry = &pCurDTLB2[((guest_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
tlb_entry = &pCurDTLB2[((guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
}
|
||||
|
||||
if (tlb_entry->tag == tag) {
|
||||
@@ -706,7 +711,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
const uint32_t tag = vaddr & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary ITLB
|
||||
tlb1_entry = &pCurITLB1[(vaddr >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
tlb1_entry = &pCurITLB1[(vaddr >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->tag == tag) { // primary ITLB hit -> fast path
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_itlb_hits++;
|
||||
@@ -736,7 +741,6 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
ppc_set_cur_instruction(host_va);
|
||||
if (paddr)
|
||||
*paddr = tlb1_entry->phys_tag | (vaddr & 0xFFFUL);
|
||||
|
||||
@@ -745,7 +749,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
|
||||
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb1[(tag >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
TLBEntry *tlb_entry = &tlb1[(tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
@@ -754,7 +758,7 @@ static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32
|
||||
|
||||
static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &tlb2, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb2[((tag >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
TLBEntry *tlb_entry = &tlb2[((tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
@@ -792,21 +796,28 @@ static void tlb_flush_entries(std::array<TLBEntry, N> &tlb, TLBFlags type) {
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_entries(TLBFlags type)
|
||||
{
|
||||
TLBEntry *m1_tlb, *m2_tlb, *m3_tlb;
|
||||
int i;
|
||||
|
||||
// Mode 1 is real addressing and thus can't contain any PAT entries by definition.
|
||||
bool flush_mode1 = type != TLBE_FROM_PAT;
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb1_mode2, type);
|
||||
tlb_flush_entries(itlb1_mode3, type);
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb2_mode2, type);
|
||||
tlb_flush_entries(itlb2_mode3, type);
|
||||
} else {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb1_mode2, type);
|
||||
tlb_flush_entries(dtlb1_mode3, type);
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb2_mode2, type);
|
||||
tlb_flush_entries(dtlb2_mode3, type);
|
||||
}
|
||||
@@ -973,20 +984,19 @@ void mmu_pat_ctx_changed()
|
||||
|
||||
// Forward declarations.
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value);
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr, T value);
|
||||
|
||||
template <class T>
|
||||
inline T mmu_read_vmem(uint32_t guest_va)
|
||||
{
|
||||
inline T mmu_read_vmem(uint32_t guest_va, uint32_t instr) {
|
||||
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
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
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++;
|
||||
@@ -1022,7 +1032,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
@@ -1049,7 +1059,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
return read_unaligned<T>(guest_va, host_va);
|
||||
return read_unaligned<T>(guest_va, host_va, instr);
|
||||
}
|
||||
|
||||
// handle aligned memory accesses
|
||||
@@ -1066,21 +1076,20 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_read_vmem variants
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va);
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
{
|
||||
inline void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value) {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
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++;
|
||||
@@ -1144,7 +1153,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
@@ -1167,7 +1176,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
write_unaligned<T>(guest_va, host_va, value);
|
||||
write_unaligned<T>(guest_va, host_va, instr, value);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1189,18 +1198,23 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_write_vmem variants
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint64_t value);
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint32_t instr, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint32_t instr, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t instr, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint32_t instr, uint64_t value);
|
||||
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
{
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr) {
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
T result = 0;
|
||||
|
||||
// is it a misaligned cross-page read?
|
||||
if (((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
if ((sizeof(T) > 1) && ((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_r++;
|
||||
#endif
|
||||
@@ -1208,7 +1222,7 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
for (int i = 0; i < sizeof(T); guest_va++, i++) {
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va);
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va, instr);
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1222,9 +1236,6 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
case 4:
|
||||
return READ_DWORD_BE_U(host_va);
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_alignment_exception(guest_va);
|
||||
}
|
||||
return READ_QWORD_BE_U(host_va);
|
||||
}
|
||||
}
|
||||
@@ -1232,15 +1243,21 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required read_unaligned variants
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t instr, T value)
|
||||
{
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
// is it a misaligned cross-page write?
|
||||
if (((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
if ((sizeof(T) > 1) && ((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_w++;
|
||||
#endif
|
||||
@@ -1251,7 +1268,7 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
uint32_t shift = (sizeof(T) - 1) * 8;
|
||||
|
||||
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
|
||||
mmu_write_vmem<uint8_t>(guest_va, (value >> shift) & 0xFF);
|
||||
mmu_write_vmem<uint8_t>(guest_va, instr, ((value >> shift) & 0xFF));
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1268,9 +1285,6 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
WRITE_DWORD_BE_U(host_va, value);
|
||||
break;
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_alignment_exception(guest_va);
|
||||
}
|
||||
WRITE_QWORD_BE_U(host_va, value);
|
||||
break;
|
||||
}
|
||||
@@ -1278,9 +1292,12 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required write_unaligned variants
|
||||
template void write_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va, uint64_t value);
|
||||
template void write_unaligned<uint16_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint64_t value);
|
||||
|
||||
|
||||
/* MMU profiling. */
|
||||
@@ -1408,512 +1425,6 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
//=================== Old and slow code. Kept for reference =================
|
||||
#if 0
|
||||
template <class T, const bool is_aligned>
|
||||
static inline T read_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr)
|
||||
{
|
||||
if (addr < mru_rgn->start || (addr + sizeof(T)) > mru_rgn->end) {
|
||||
AddressMapEntry* entry = mem_ctrl_instance->find_range(addr);
|
||||
if (entry) {
|
||||
*mru_rgn = *entry;
|
||||
} else {
|
||||
LOG_F(ERROR, "Read from unmapped memory at 0x%08X!", addr);
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
}
|
||||
|
||||
if (mru_rgn->type & (RT_ROM | RT_RAM)) {
|
||||
#ifdef MMU_PROFILING
|
||||
dmem_reads_total++;
|
||||
#endif
|
||||
|
||||
switch(sizeof(T)) {
|
||||
case 1:
|
||||
return *(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
case 2:
|
||||
if (is_aligned) {
|
||||
return READ_WORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
} else {
|
||||
return READ_WORD_BE_U(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
}
|
||||
case 4:
|
||||
if (is_aligned) {
|
||||
return READ_DWORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
} else {
|
||||
return READ_DWORD_BE_U(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
}
|
||||
case 8:
|
||||
if (is_aligned) {
|
||||
return READ_QWORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
}
|
||||
default:
|
||||
LOG_F(ERROR, "READ_PHYS: invalid size %lu passed", sizeof(T));
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
} else if (mru_rgn->type & RT_MMIO) {
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_reads_total++;
|
||||
#endif
|
||||
|
||||
return (mru_rgn->devobj->read(mru_rgn->start,
|
||||
addr - mru_rgn->start, sizeof(T)));
|
||||
} else {
|
||||
LOG_F(ERROR, "READ_PHYS: invalid region type!");
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, const bool is_aligned>
|
||||
static inline void write_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr, T value)
|
||||
{
|
||||
if (addr < mru_rgn->start || (addr + sizeof(T)) > mru_rgn->end) {
|
||||
AddressMapEntry* entry = mem_ctrl_instance->find_range(addr);
|
||||
if (entry) {
|
||||
*mru_rgn = *entry;
|
||||
} else {
|
||||
LOG_F(ERROR, "Write to unmapped memory at 0x%08X!", addr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mru_rgn->type & RT_RAM) {
|
||||
#ifdef MMU_PROFILING
|
||||
dmem_writes_total++;
|
||||
#endif
|
||||
|
||||
switch(sizeof(T)) {
|
||||
case 1:
|
||||
*(mru_rgn->mem_ptr + (addr - mru_rgn->start)) = value;
|
||||
break;
|
||||
case 2:
|
||||
if (is_aligned) {
|
||||
WRITE_WORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start), value);
|
||||
} else {
|
||||
WRITE_WORD_BE_U(mru_rgn->mem_ptr + (addr - mru_rgn->start), value);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (is_aligned) {
|
||||
WRITE_DWORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start), value);
|
||||
} else {
|
||||
WRITE_DWORD_BE_U(mru_rgn->mem_ptr + (addr - mru_rgn->start), value);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (is_aligned) {
|
||||
WRITE_QWORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start), value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid size %lu passed", sizeof(T));
|
||||
return;
|
||||
}
|
||||
} else if (mru_rgn->type & RT_MMIO) {
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_writes_total++;
|
||||
#endif
|
||||
|
||||
mru_rgn->devobj->write(mru_rgn->start, addr - mru_rgn->start, value,
|
||||
sizeof(T));
|
||||
} else {
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid region type!");
|
||||
}
|
||||
}
|
||||
|
||||
/** PowerPC-style MMU data address translation. */
|
||||
static uint32_t ppc_mmu_addr_translate(uint32_t la, int is_write)
|
||||
{
|
||||
uint32_t pa; /* translated physical address */
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
// Those bits are mutually exclusive
|
||||
unsigned access_bits = ((msr_pr ^ 1) << 1) | msr_pr;
|
||||
|
||||
for (int bat_index = 0; bat_index < 4; bat_index++) {
|
||||
PPC_BAT_entry* bat_entry = &dbat_array[bat_index];
|
||||
|
||||
if ((bat_entry->access & access_bits) && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
bat_hit = true;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
bat_transl_total++;
|
||||
#endif
|
||||
|
||||
if (!bat_entry->prot || ((bat_entry->prot & 1) && is_write)) {
|
||||
ppc_state.spr[SPR::DSISR] = 0x08000000 | (is_write << 25);
|
||||
ppc_state.spr[SPR::DAR] = la;
|
||||
mmu_exception_handler(Except_Type::EXC_DSI, 0);
|
||||
}
|
||||
|
||||
// logical to physical translation
|
||||
pa = bat_entry->phys_hi | (la & ~bat_entry->hi_mask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* page address translation */
|
||||
if (!bat_hit) {
|
||||
PATResult pat_res = page_address_translation(la, false, msr_pr, is_write);
|
||||
pa = pat_res.phys;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
ptab_transl_total++;
|
||||
#endif
|
||||
}
|
||||
|
||||
return pa;
|
||||
}
|
||||
|
||||
static void mem_write_unaligned(uint32_t addr, uint32_t value, uint32_t size) {
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to write unaligned %d bytes to 0x%08X", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
// Special case: unaligned cross-page writes
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_w++;
|
||||
#endif
|
||||
|
||||
uint32_t phys_addr;
|
||||
uint32_t shift = (size - 1) * 8;
|
||||
|
||||
// Break misaligned memory accesses into multiple, bytewise accesses
|
||||
// and retranslate on page boundary.
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; shift -= 8, addr++, phys_addr++, i++) {
|
||||
if ((ppc_state.msr & MSR::DR) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
write_phys_mem<uint8_t, false>(&last_write_area, phys_addr,
|
||||
(value >> shift) & 0xFF);
|
||||
}
|
||||
} else {
|
||||
// data address translation if enabled
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
if (size == 2) {
|
||||
write_phys_mem<uint16_t, false>(&last_write_area, addr, value);
|
||||
} else {
|
||||
write_phys_mem<uint32_t, false>(&last_write_area, addr, value);
|
||||
}
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_writes++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
{
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = &pCurDTLB2[((guest_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
if (tlb2_entry->tag == tag) {
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits = 0x3;
|
||||
tlb2_entry[1].lru_bits = 0x2;
|
||||
tlb2_entry[2].lru_bits &= 0x1;
|
||||
tlb2_entry[3].lru_bits &= 0x1;
|
||||
} else if (tlb2_entry[1].tag == tag) {
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits = 0x2;
|
||||
tlb2_entry[1].lru_bits = 0x3;
|
||||
tlb2_entry[2].lru_bits &= 0x1;
|
||||
tlb2_entry[3].lru_bits &= 0x1;
|
||||
tlb2_entry = &tlb2_entry[1];
|
||||
} else if (tlb2_entry[2].tag == tag) {
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits &= 0x1;
|
||||
tlb2_entry[1].lru_bits &= 0x1;
|
||||
tlb2_entry[2].lru_bits = 0x3;
|
||||
tlb2_entry[3].lru_bits = 0x2;
|
||||
tlb2_entry = &tlb2_entry[2];
|
||||
} else if (tlb2_entry[3].tag == tag) {
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits &= 0x1;
|
||||
tlb2_entry[1].lru_bits &= 0x1;
|
||||
tlb2_entry[2].lru_bits = 0x2;
|
||||
tlb2_entry[3].lru_bits = 0x3;
|
||||
tlb2_entry = &tlb2_entry[3];
|
||||
} else { // secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
tlb2_entry = dtlb2_refill(guest_va, 0);
|
||||
}
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
tlb1_entry->phys_tag = tlb2_entry->phys_tag;
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // an attempt to access a memory-mapped device
|
||||
return guest_va - tlb2_entry->dev_base_va;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t mem_grab_unaligned(uint32_t addr, uint32_t size) {
|
||||
uint32_t ret = 0;
|
||||
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to read unaligned %d bytes from 0x%08X", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
// Special case: misaligned cross-page reads
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_r++;
|
||||
#endif
|
||||
|
||||
uint32_t phys_addr;
|
||||
uint32_t res = 0;
|
||||
|
||||
// Break misaligned memory accesses into multiple, bytewise accesses
|
||||
// and retranslate on page boundary.
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; addr++, phys_addr++, i++) {
|
||||
tlb_translate_addr(addr);
|
||||
if ((ppc_state.msr & MSR::DR) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
res = (res << 8) |
|
||||
read_phys_mem<uint8_t, false>(&last_read_area, phys_addr);
|
||||
}
|
||||
return res;
|
||||
|
||||
} else {
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
if (size == 2) {
|
||||
return read_phys_mem<uint16_t, false>(&last_read_area, addr);
|
||||
} else {
|
||||
return read_phys_mem<uint32_t, false>(&last_read_area, addr);
|
||||
}
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_reads++;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mem_write_byte(uint32_t addr, uint8_t value) {
|
||||
mmu_write_vmem<uint8_t>(addr, value);
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
write_phys_mem<uint8_t, true>(&last_write_area, addr, value);
|
||||
}
|
||||
|
||||
void mem_write_word(uint32_t addr, uint16_t value) {
|
||||
mmu_write_vmem<uint16_t>(addr, value);
|
||||
|
||||
if (addr & 1) {
|
||||
mem_write_unaligned(addr, value, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
write_phys_mem<uint16_t, true>(&last_write_area, addr, value);
|
||||
}
|
||||
|
||||
void mem_write_dword(uint32_t addr, uint32_t value) {
|
||||
mmu_write_vmem<uint32_t>(addr, value);
|
||||
|
||||
if (addr & 3) {
|
||||
mem_write_unaligned(addr, value, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
write_phys_mem<uint32_t, true>(&last_write_area, addr, value);
|
||||
}
|
||||
|
||||
void mem_write_qword(uint32_t addr, uint64_t value) {
|
||||
mmu_write_vmem<uint64_t>(addr, value);
|
||||
|
||||
if (addr & 7) {
|
||||
ABORT_F("SOS! Attempt to write unaligned QWORD to 0x%08X\n", addr);
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
write_phys_mem<uint64_t, true>(&last_write_area, addr, value);
|
||||
}
|
||||
|
||||
/** Grab a value from memory into a register */
|
||||
uint8_t mem_grab_byte(uint32_t addr) {
|
||||
tlb_translate_addr(addr);
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
return read_phys_mem<uint8_t, true>(&last_read_area, addr);
|
||||
}
|
||||
|
||||
uint16_t mem_grab_word(uint32_t addr) {
|
||||
tlb_translate_addr(addr);
|
||||
|
||||
if (addr & 1) {
|
||||
return mem_grab_unaligned(addr, 2);
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
return read_phys_mem<uint16_t, true>(&last_read_area, addr);
|
||||
}
|
||||
|
||||
uint32_t mem_grab_dword(uint32_t addr) {
|
||||
tlb_translate_addr(addr);
|
||||
|
||||
if (addr & 3) {
|
||||
return mem_grab_unaligned(addr, 4);
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
return read_phys_mem<uint32_t, true>(&last_read_area, addr);
|
||||
}
|
||||
|
||||
uint64_t mem_grab_qword(uint32_t addr) {
|
||||
tlb_translate_addr(addr);
|
||||
|
||||
if (addr & 7) {
|
||||
ABORT_F("SOS! Attempt to read unaligned QWORD at 0x%08X\n", addr);
|
||||
}
|
||||
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & MSR::DR) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
return read_phys_mem<uint64_t, true>(&last_read_area, addr);
|
||||
}
|
||||
|
||||
/** PowerPC-style MMU instruction address translation. */
|
||||
static uint32_t mmu_instr_translation(uint32_t la)
|
||||
{
|
||||
uint32_t pa; /* translated physical address */
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
// Those bits are mutually exclusive
|
||||
unsigned access_bits = ((msr_pr ^ 1) << 1) | msr_pr;
|
||||
|
||||
for (int bat_index = 0; bat_index < 4; bat_index++) {
|
||||
PPC_BAT_entry* bat_entry = &ibat_array[bat_index];
|
||||
|
||||
if ((bat_entry->access & access_bits) && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
bat_hit = true;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
bat_transl_total++;
|
||||
#endif
|
||||
|
||||
if (!bat_entry->prot) {
|
||||
mmu_exception_handler(Except_Type::EXC_ISI, 0x08000000);
|
||||
}
|
||||
|
||||
// logical to physical translation
|
||||
pa = bat_entry->phys_hi | (la & ~bat_entry->hi_mask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* page address translation */
|
||||
if (!bat_hit) {
|
||||
PATResult pat_res = page_address_translation(la, true, msr_pr, 0);
|
||||
pa = pat_res.phys;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
ptab_transl_total++;
|
||||
#endif
|
||||
}
|
||||
|
||||
return pa;
|
||||
}
|
||||
|
||||
uint8_t* quickinstruction_translate(uint32_t addr) {
|
||||
uint8_t* real_addr;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
exec_reads_total++;
|
||||
#endif
|
||||
|
||||
/* perform instruction address translation if enabled */
|
||||
if (ppc_state.msr & MSR::IR) {
|
||||
addr = mmu_instr_translation(addr);
|
||||
}
|
||||
|
||||
if (addr >= last_exec_area.start && addr <= last_exec_area.end) {
|
||||
real_addr = last_exec_area.mem_ptr + (addr - last_exec_area.start);
|
||||
ppc_set_cur_instruction(real_addr);
|
||||
} else {
|
||||
AddressMapEntry* entry = mem_ctrl_instance->find_range(addr);
|
||||
if (entry && entry->type & (RT_ROM | RT_RAM)) {
|
||||
last_exec_area.start = entry->start;
|
||||
last_exec_area.end = entry->end;
|
||||
last_exec_area.mem_ptr = entry->mem_ptr;
|
||||
real_addr = last_exec_area.mem_ptr + (addr - last_exec_area.start);
|
||||
ppc_set_cur_instruction(real_addr);
|
||||
} else {
|
||||
ABORT_F("Attempt to execute code at %08X!\n", addr);
|
||||
}
|
||||
}
|
||||
|
||||
return real_addr;
|
||||
}
|
||||
#endif // Old and slow code
|
||||
|
||||
uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
uint32_t save_dsisr, save_dar;
|
||||
uint64_t ret_val;
|
||||
@@ -1926,19 +1437,19 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
try {
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
break;
|
||||
case 2:
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr, 0);
|
||||
break;
|
||||
case 4:
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr, 0);
|
||||
break;
|
||||
case 8:
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr, 0);
|
||||
break;
|
||||
default:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
}
|
||||
} catch (std::invalid_argument& exc) {
|
||||
/* restore MMU-related CPU state */
|
||||
@@ -1973,7 +1484,7 @@ bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa) {
|
||||
const uint32_t tag = guest_va & ~0xFFFUL;
|
||||
|
||||
// look up guest virtual address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
|
||||
do {
|
||||
if (tlb1_entry->tag != tag) {
|
||||
@@ -2032,7 +1543,6 @@ void ppc_mmu_init()
|
||||
last_write_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
mmu_exception_handler = ppc_exception_handler;
|
||||
|
||||
|
||||
+8
-21
@@ -81,12 +81,12 @@ typedef struct MapDmaResult {
|
||||
uint32_t dev_base;
|
||||
} MapDmaResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1)
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
constexpr uint32_t PPC_PAGE_SIZE_BITS = 12;
|
||||
constexpr uint32_t PPC_PAGE_SIZE = (1 << PPC_PAGE_SIZE_BITS);
|
||||
constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
constexpr uint32_t TLB2_WAYS = 4;
|
||||
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
@@ -130,21 +130,8 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
|
||||
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
extern T mmu_read_vmem(uint32_t guest_va, uint32_t instr);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t guest_va, T value);
|
||||
|
||||
//====================== Deprecated calls =========================
|
||||
#if 0
|
||||
extern void mem_write_byte(uint32_t addr, uint8_t value);
|
||||
extern void mem_write_word(uint32_t addr, uint16_t value);
|
||||
extern void mem_write_dword(uint32_t addr, uint32_t value);
|
||||
extern void mem_write_qword(uint32_t addr, uint64_t value);
|
||||
extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
extern void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value);
|
||||
|
||||
#endif // PPCMMU_H
|
||||
+28
-1805
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<SHFT0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<SHFT1>(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC1>(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, IS601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, IS601>(uint32_t instr); \
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number] = ppc_##op;
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number << 1] = ppc_##op;
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number] = power_##op;
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number << 1] = power_##op;
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<SHFT0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<SHFT1>;
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LEFT1 , RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LEFT1 , RC1>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) ] = ppc_##op<RIGHT0, RC0>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) + 1] = ppc_##op<RIGHT0, RC1>; \
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<RC1, OV1>;
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<int16_t, RC0>; \
|
||||
Opcode##grabber##Grabber[( number << 1) + 1] = ppc_##op<int16_t, RC1>; \
|
||||
Opcode##grabber##Grabber[ (number + 32) << 1 ] = ppc_##op<int8_t, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<int8_t, RC1>;
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 2] = power_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 3] = power_##op<RC1, OV1>; \
|
||||
}
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = ppc_##op<RC1>; \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
for (int i = 0; i < 2048; i += 32) { \
|
||||
Opcode##grabber##Grabber[(number + i) << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[((number + i) << 1) + 1] = ppc_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number ] = ppc_##op<ppc_and , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 1) << 1) ] = ppc_##op<ppc_and , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) ] = ppc_##op<ppc_andc, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<ppc_andc, RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) ] = ppc_##op<ppc_nor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) + 1] = ppc_##op<ppc_nor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) ] = ppc_##op<ppc_eqv , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) + 1] = ppc_##op<ppc_eqv , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) ] = ppc_##op<ppc_xor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) + 1] = ppc_##op<ppc_xor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) ] = ppc_##op<ppc_orc , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) + 1] = ppc_##op<ppc_orc , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) ] = ppc_##op<ppc_or , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) + 1] = ppc_##op<ppc_or , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) ] = ppc_##op<ppc_nand, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) + 1] = ppc_##op<ppc_nand, RC1>; \
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<LK0, AA1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<LK1, AA1>;
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[number + 8] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 6)] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 8)] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<IS601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<IS601, RC1>; \
|
||||
} else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<NOT601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<NOT601, RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, IS601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, IS601>; \
|
||||
} \
|
||||
else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, NOT601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, NOT601>; \
|
||||
}
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1>;
|
||||
+20
-19
@@ -36,12 +36,17 @@ using namespace std;
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
#if defined(PPC_TESTS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
|
||||
nfailed++;
|
||||
@@ -113,7 +118,7 @@ static void read_test_data() {
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
@@ -123,15 +128,15 @@ static void read_test_data() {
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("rD=", 0) == 0) {
|
||||
dest = stoul(tokens[i].substr(3), NULL, 16);
|
||||
dest = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rA=", 0) == 0) {
|
||||
src1 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src1 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rB=", 0) == 0) {
|
||||
src2 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src2 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("XER=", 0) == 0) {
|
||||
check_xer = stoul(tokens[i].substr(4), NULL, 16);
|
||||
check_xer = (uint32_t)stoul(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
@@ -145,9 +150,7 @@ static void read_test_data() {
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -227,7 +230,7 @@ static void read_test_float_data() {
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
@@ -253,9 +256,9 @@ static void read_test_float_data() {
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
|
||||
check_fpscr = (uint32_t)stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
@@ -289,9 +292,7 @@ static void read_test_float_data() {
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -315,7 +316,7 @@ static void read_test_float_data() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialize_ppc_opcode_tables(); //kludge
|
||||
initialize_ppc_opcode_tables(true); //kludge
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
|
||||
@@ -65,15 +65,15 @@ static vector<PPCDisasmContext> read_test_data() {
|
||||
}
|
||||
|
||||
ctx = {0};
|
||||
ctx.instr_addr = stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = stoul(tokens[1], NULL, 16);
|
||||
ctx.instr_addr = (uint32_t)stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
/* build disassembly string out of comma-separated parts */
|
||||
ostringstream idisasm;
|
||||
|
||||
/* put instruction mnemonic padded with trailing spaces */
|
||||
idisasm << tokens[2];
|
||||
idisasm << setw(8 - tokens[2].length()) << "";
|
||||
idisasm << setw(8 - (int)tokens[2].length()) << " ";
|
||||
|
||||
/* now add comma-separated operands */
|
||||
for (i = 3; i < tokens.size(); i++) {
|
||||
|
||||
+14
-3
@@ -161,7 +161,7 @@ print_bin:
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
void exec_single_68k(uint32_t instr)
|
||||
{
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
@@ -174,7 +174,7 @@ void exec_single_68k()
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc, 0) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
@@ -447,7 +447,9 @@ void enter_debugger() {
|
||||
size_t separator_pos;
|
||||
bool did_message = false;
|
||||
uint32_t next_addr_ppc;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
uint32_t next_addr_68k;
|
||||
#endif
|
||||
bool cmd_repeat;
|
||||
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
@@ -468,6 +470,10 @@ void enter_debugger() {
|
||||
power_off_reason = po_restarting;
|
||||
break;
|
||||
}
|
||||
if (power_off_reason == po_quit) {
|
||||
power_off_reason = po_quitting;
|
||||
break;
|
||||
}
|
||||
power_on = true;
|
||||
|
||||
if (power_off_reason == po_starting_up) {
|
||||
@@ -530,6 +536,11 @@ void enter_debugger() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feof(stdin)) {
|
||||
printf("eof -> quit\n");
|
||||
cmd = "quit";
|
||||
}
|
||||
|
||||
cmd_repeat = cmd.empty() && !last_cmd.empty();
|
||||
if (cmd_repeat) {
|
||||
cmd = last_cmd;
|
||||
@@ -610,7 +621,7 @@ void enter_debugger() {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
exec_single_68k(0);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <memaccess.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
|
||||
@@ -37,8 +38,14 @@ void AdbMouse::event_handler(const MouseEvent& event) {
|
||||
if (event.flags & MOUSE_EVENT_MOTION) {
|
||||
this->x_rel += event.xrel;
|
||||
this->y_rel += event.yrel;
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
if (this->device_class == TABLET)
|
||||
this->changed = true;
|
||||
} else if (event.flags & MOUSE_EVENT_BUTTON) {
|
||||
this->buttons_state = event.buttons_state;
|
||||
this->buttons_state = event.buttons_state & ((1 << this->num_buttons) - 1);
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
this->changed = true;
|
||||
}
|
||||
}
|
||||
@@ -50,38 +57,58 @@ void AdbMouse::reset() {
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->x_abs = 0;
|
||||
this->y_abs = 0;
|
||||
this->buttons_state = 0;
|
||||
this->changed = false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_0() {
|
||||
if (this->x_rel || this->y_rel || this->changed) {
|
||||
uint8_t* p;
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
uint8_t button1_state = (this->buttons_state ^ 1) << 7;
|
||||
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
|
||||
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
|
||||
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
|
||||
|
||||
// report Y-axis motion
|
||||
if (this->y_rel < -64)
|
||||
out_buf[0] = 0x40 | button1_state;
|
||||
else if (this->y_rel > 63)
|
||||
out_buf[0] = 0x3F | button1_state;
|
||||
else
|
||||
out_buf[0] = (this->y_rel & 0x7F) | button1_state;
|
||||
for (int axis = 0; axis < 2; axis++) {
|
||||
int bits = this->num_bits;
|
||||
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
|
||||
: this->device_class == TABLET ? this->y_abs : this->y_rel;
|
||||
if (val < (-1 << (bits - 1)))
|
||||
val = -1 << (bits - 1);
|
||||
else if (val >= (1 << (bits - 1)))
|
||||
val = (1 << (bits - 1)) - 1;
|
||||
int bits_remaining = total_bits;
|
||||
p = &out_buf[axis];
|
||||
int button = axis;
|
||||
bits = 7;
|
||||
|
||||
// report X-axis motion
|
||||
if (this->x_rel < -64)
|
||||
out_buf[1] = 0x40 | 0x80;
|
||||
else if (this->x_rel > 63)
|
||||
out_buf[1] = 0x3F | 0x80;
|
||||
else
|
||||
out_buf[1] = (this->x_rel & 0x7F) | 0x80;
|
||||
while (bits_remaining > 0) {
|
||||
*p = (val & ((1 << bits) - 1)) | (((this->buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
|
||||
val >>= bits;
|
||||
bits_remaining -= bits;
|
||||
p = bits == 7 ? &out_buf[2] : p + 1;
|
||||
button += 2;
|
||||
bits = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// reset accumulated motion data and button change flag
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->changed = false;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
uint8_t count = (uint8_t)(p - out_buf);
|
||||
// should never happen, but check just in case
|
||||
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
|
||||
count = UINT8_MAX;
|
||||
// if the mouse is in standard protocol then only send first 2 bytes
|
||||
// BUGBUG: what should tablet do here?
|
||||
if (this->device_class == MOUSE && this->dev_handler_id == 1)
|
||||
count = 2;
|
||||
this->host_obj->set_output_count(count);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,10 +123,9 @@ bool AdbMouse::get_register_1() {
|
||||
out_buf[2] = 'p';
|
||||
out_buf[3] = 'l';
|
||||
// Slightly higher resolution of 300 units per inch
|
||||
out_buf[4] = 300 >> 8;
|
||||
out_buf[5] = 300 & 0xFF;
|
||||
out_buf[6] = 1; // mouse
|
||||
out_buf[7] = 1; // 1 button
|
||||
WRITE_WORD_BE_A(&out_buf[4], resolution);
|
||||
out_buf[6] = device_class;
|
||||
out_buf[7] = num_buttons;
|
||||
this->host_obj->set_output_count(8);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
//#define ABSOLUTE
|
||||
|
||||
class MouseEvent;
|
||||
|
||||
class AdbMouse : public AdbDevice {
|
||||
|
||||
enum DeviceClass {
|
||||
TABLET = 0,
|
||||
MOUSE = 1,
|
||||
TRACKBALL = 2,
|
||||
};
|
||||
|
||||
public:
|
||||
AdbMouse(std::string name);
|
||||
~AdbMouse() = default;
|
||||
@@ -49,10 +58,23 @@ public:
|
||||
void set_register_3() override;
|
||||
|
||||
private:
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
int32_t x_abs = 0;
|
||||
int32_t y_abs = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
#ifdef ABSOLUTE
|
||||
uint8_t device_class = TABLET;
|
||||
int num_buttons = 3;
|
||||
int num_bits = 16;
|
||||
uint16_t resolution = 72;
|
||||
#else
|
||||
uint8_t device_class = MOUSE;
|
||||
int num_buttons = 3;
|
||||
int num_bits = 10;
|
||||
uint16_t resolution = 300;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // ADB_MOUSE_H
|
||||
@@ -46,6 +46,9 @@ void AtaBaseDevice::device_reset(bool is_soft_reset) {
|
||||
|
||||
// Diagnostic code
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
|
||||
// disable interrupts
|
||||
this->r_dev_ctrl |= ATA_CTRL::IEN;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_set_signature() {
|
||||
@@ -67,10 +70,11 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0)
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
else {
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
} else {
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->update_intrq(1);
|
||||
}
|
||||
}
|
||||
@@ -104,19 +108,20 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
if (is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->post_xfer_action();
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) { // transfer complete?
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public:
|
||||
AtaBaseDevice(const std::string name, uint8_t type);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
void set_host(IdeChannel* host) { this->host_obj = host; };
|
||||
void set_host(IdeChannel* host, uint8_t dev_id) {
|
||||
this->host_obj = host;
|
||||
this->my_dev_id = dev_id;
|
||||
};
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
@@ -89,10 +92,11 @@ protected:
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08;
|
||||
uint8_t r_dev_ctrl = 0x08 | ata_interface::ATA_CTRL::IEN; // disable interrupts
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint16_t *cur_data_ptr = nullptr;
|
||||
alignas(uint16_t)
|
||||
uint8_t data_buf[512] = {};
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
|
||||
@@ -117,33 +117,35 @@ enum ATA_CTRL : uint8_t {
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : uint8_t {
|
||||
NOP = 0x00,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
READ_LONG = 0x22,
|
||||
READ_SECTOR_EXT = 0x24,
|
||||
WRITE_SECTOR = 0x30,
|
||||
WRITE_SECTOR_NR = 0x31,
|
||||
WRITE_LONG = 0x32,
|
||||
READ_VERIFY = 0x40,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
ATAPI_IDFY_DEV = 0xA1,
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
SET_FEATURES = 0xEF,
|
||||
NOP = 0x00,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
READ_LONG = 0x22,
|
||||
READ_SECTOR_EXT = 0x24,
|
||||
WRITE_SECTOR = 0x30,
|
||||
WRITE_SECTOR_NR = 0x31,
|
||||
WRITE_LONG = 0x32,
|
||||
READ_VERIFY = 0x40,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
ATAPI_IDFY_DEV = 0xA1,
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
SET_MULTIPLE_MODE = 0xC6,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
STANDBY_IMMEDIATE_E0 = 0xE0,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
SET_FEATURES = 0xEF,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
|
||||
+124
-48
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -44,6 +45,10 @@ int AtaHardDisk::device_postinit() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (hdd_image_path.empty())
|
||||
return 0;
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
@@ -52,21 +57,24 @@ int AtaHardDisk::device_postinit() {
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (!hdd_image_path.empty()) {
|
||||
this->insert_image(hdd_image_path);
|
||||
}
|
||||
this->insert_image(hdd_image_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
if (!this->hdd_img.open(filename)) {
|
||||
ABORT_F("%s: could not open image file", this->name.c_str());
|
||||
ABORT_F("%s: could not open image file \"%s\"", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
this->img_size = this->hdd_img.size();
|
||||
this->total_sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
uint64_t sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
this->total_sectors = (uint32_t)sectors;
|
||||
if (sectors != this->total_sectors) {
|
||||
ABORT_F("%s: image file \"%s\" is too big", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
this->calc_chs_params();
|
||||
}
|
||||
|
||||
@@ -77,38 +85,79 @@ int AtaHardDisk::perform_command() {
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
case ATAPI_SOFT_RESET: // for ATA devices, is a no-op
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case RECALIBRATE: // is optional in ATA-3; disappeared in >= ATA-4
|
||||
// OF 3.1.1 won't boot off the drive that reports error for this command
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_dev_head &= 0xF0;
|
||||
this->r_sect_num = (this->r_dev_head & ATA_Dev_Head::LBA) ? 0 : 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_MULTIPLE:
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == READ_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
hdd_img.read(buffer, offset, xfer_size);
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
// those commands should generate IRQ for each sector
|
||||
this->prepare_xfer(xfer_size, ATA_HD_SEC_SIZE);
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
break;
|
||||
case WRITE_MULTIPLE:
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->prepare_xfer(sec_count * ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == WRITE_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, this->chunk_size);
|
||||
this->cur_fpos += this->chunk_size;
|
||||
uint64_t write_len = (this->cur_data_ptr - this->data_ptr) * sizeof(this->data_ptr[0]);
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_VERIFY: // verify sectors are readable, just no-op
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
// update fictive disk geometry with parameters from host
|
||||
this->sectors = this->r_sect_count;
|
||||
@@ -116,9 +165,20 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1;
|
||||
this->device_set_signature();
|
||||
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
|
||||
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
|
||||
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
|
||||
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
|
||||
this->name.c_str(), this->r_sect_count);
|
||||
this->r_error |= ABRT;
|
||||
this->r_status |= ERR;
|
||||
} else {
|
||||
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->sectors_per_int = this->r_sect_count;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case FLUSH_CACHE: // used by the XNU kernel driver
|
||||
this->r_status &= ~(BSY | DRQ | ERR);
|
||||
@@ -157,6 +217,11 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case STANDBY_IMMEDIATE_E0:
|
||||
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
|
||||
this->r_status &= ~BSY;
|
||||
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;
|
||||
@@ -174,6 +239,16 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
@@ -204,50 +279,51 @@ uint64_t AtaHardDisk::get_lba() {
|
||||
}
|
||||
|
||||
void AtaHardDisk::calc_chs_params() {
|
||||
unsigned num_blocks, heads, sectors, max_sectors;
|
||||
unsigned num_blocks, heads, sectors, max_sectors, cylinders, max_cylinders;
|
||||
|
||||
LOG_F(INFO, "%s: total sectors %d", this->name.c_str(), this->total_sectors);
|
||||
|
||||
if (this->total_sectors >= REAL_CHS_LIMIT) {
|
||||
heads = 16;
|
||||
sectors = 255;
|
||||
cylinders = 65535;
|
||||
LOG_F(WARNING, "%s: exceeds max CHS translation",
|
||||
this->name.c_str());
|
||||
goto done;
|
||||
}
|
||||
|
||||
// use PC BIOS limit to keep number of sectors small for smaller disks
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT)
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT) {
|
||||
max_sectors = 255;
|
||||
else
|
||||
max_cylinders = 65535;
|
||||
} else {
|
||||
max_sectors = 63;
|
||||
max_cylinders = 16383;
|
||||
}
|
||||
|
||||
num_blocks = this->total_sectors;
|
||||
|
||||
for (heads = 16; heads > 0; heads--)
|
||||
if (!(num_blocks % heads))
|
||||
break;
|
||||
for (sectors = max_sectors; sectors > 0; sectors--)
|
||||
if (!(num_blocks % (heads * sectors)))
|
||||
if (heads * sectors * max_cylinders >= num_blocks) {
|
||||
cylinders = num_blocks / (heads * sectors);
|
||||
goto done;
|
||||
}
|
||||
|
||||
heads = 16;
|
||||
sectors = (num_blocks + heads * max_cylinders - 1) / (heads * max_cylinders);
|
||||
cylinders = (num_blocks + heads * sectors - 1) / (heads * sectors);
|
||||
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation; increased sectors to %d",
|
||||
this->name.c_str(), heads * sectors * cylinders);
|
||||
|
||||
done:
|
||||
this->heads = heads;
|
||||
|
||||
if (!heads) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable number of heads",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
num_blocks /= heads;
|
||||
|
||||
for (sectors = max_sectors; sectors > 0; sectors--) {
|
||||
if (!(num_blocks % sectors)) {
|
||||
if (num_blocks / sectors < 65536)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->sectors = sectors;
|
||||
|
||||
if (!sectors) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
this->cylinders = num_blocks / sectors;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), this->cylinders,
|
||||
this->heads, this->sectors);
|
||||
this->cylinders = cylinders;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), cylinders,
|
||||
heads, sectors);
|
||||
}
|
||||
|
||||
static const PropMap AtaHardDiskProperties = {
|
||||
|
||||
@@ -30,7 +30,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
#define SECTORS_PER_INT 16
|
||||
|
||||
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
|
||||
#define ATA_BIOS_LIMIT 16514064
|
||||
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
|
||||
#define REAL_CHS_LIMIT 267382800
|
||||
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
|
||||
#define CHS_LIMIT 267386880
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
@@ -63,9 +70,9 @@ private:
|
||||
uint8_t heads;
|
||||
uint8_t sectors;
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
|
||||
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
char * buffer = new char[1 <<17];
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -149,6 +149,11 @@ int AtapiBaseDevice::perform_command() {
|
||||
this->r_status |= BSY;
|
||||
|
||||
switch (this->r_command) {
|
||||
case ATAPI_SOFT_RESET:
|
||||
this->device_reset(true);
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_PACKET:
|
||||
this->data_ptr = (uint16_t *)this->cmd_pkt;
|
||||
this->xfer_cnt = sizeof(this->cmd_pkt);
|
||||
|
||||
@@ -55,6 +55,7 @@ protected:
|
||||
uint16_t r_byte_count;
|
||||
bool status_expected = false;
|
||||
|
||||
alignas(uint16_t)
|
||||
uint8_t cmd_pkt[12] = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <string>
|
||||
|
||||
class AtapiCdrom : public AtapiBaseDevice, public CdromDrive {
|
||||
class AtapiCdrom : public CdromDrive, public AtapiBaseDevice {
|
||||
public:
|
||||
AtapiCdrom(std::string name);
|
||||
~AtapiCdrom() = default;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** IDE Channel (aka IDE port) emulation.
|
||||
|
||||
One IDE channel is capable of controlling up to two IDE devices.
|
||||
This class handles device registration and passing of messages
|
||||
|
||||
IdeChannel class handles device registration and passing of messages
|
||||
from and to the host.
|
||||
|
||||
MacioIdeChannel class implements MacIO specific registers
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
@@ -51,62 +55,73 @@ IdeChannel::IdeChannel(const std::string name)
|
||||
this->devices[1] = this->device_stub.get();
|
||||
}
|
||||
|
||||
int IdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
|
||||
if (id < 0 || id >= 2)
|
||||
ABORT_F("%s: invalid device ID", this->name.c_str());
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this);
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this, id);
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from the channel config", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size) {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
|
||||
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to the channel config", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else {
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
this->irq_callback = [this](const uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t MacioIdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else
|
||||
return IdeChannel::read(reg_addr, size);
|
||||
}
|
||||
|
||||
void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else
|
||||
IdeChannel::write(reg_addr, val, size);
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
IdeChannel::create_first, {}, {}
|
||||
MacioIdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
IdeChannel::create_second, {}, {}
|
||||
MacioIdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -38,16 +39,6 @@ public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
@@ -55,26 +46,56 @@ public:
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
};
|
||||
}
|
||||
|
||||
bool is_device1_present() {
|
||||
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
void set_irq_callback(std::function<void(const uint8_t intrq_state)> cb) {
|
||||
this->irq_callback = cb;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
AtaInterface* devices[2];
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
class MacioIdeChannel : public IdeChannel
|
||||
{
|
||||
public:
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
|
||||
~MacioIdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
// interrupt stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
+95
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
@@ -38,6 +39,12 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
void DMAChannel::set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb) {
|
||||
this->in_cb = in_cb;
|
||||
this->out_cb = out_cb;
|
||||
this->flush_cb = flush_cb;
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
@@ -81,11 +88,27 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
|
||||
break;
|
||||
}
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->res_count = 0;
|
||||
this->cmd_in_progress = true;
|
||||
if (this->queue_len) {
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->res_count = 0;
|
||||
this->cmd_in_progress = true;
|
||||
switch (this->cur_cmd) {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
case DBDMA_Cmd::OUTPUT_LAST:
|
||||
if (this->out_cb)
|
||||
this->out_cb();
|
||||
break;
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
this->xfer_from_device();
|
||||
if (this->in_cb)
|
||||
this->in_cb();
|
||||
break;
|
||||
}
|
||||
} else
|
||||
this->finish_cmd();
|
||||
break;
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
@@ -149,6 +172,7 @@ void DMAChannel::finish_cmd() {
|
||||
|
||||
if (res.is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
|
||||
// react to cmd.b (branch) bits
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
@@ -171,8 +195,7 @@ void DMAChannel::finish_cmd() {
|
||||
|
||||
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->res_count);
|
||||
this->queue_len = 0;
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
|
||||
this->res_count = 0;
|
||||
}
|
||||
|
||||
@@ -258,9 +281,11 @@ void DMAChannel::update_irq() {
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (int_ctrl)
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
else
|
||||
if (int_ctrl) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
} else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
@@ -314,9 +339,15 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
// That means we need to update memory before channel operation
|
||||
// is aborted to prevent data loss.
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
|
||||
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
|
||||
!(this->ch_stat & CH_STAT_DEAD)) {
|
||||
this->flush_cb();
|
||||
} else {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
|
||||
@@ -349,7 +380,8 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI:
|
||||
if (value != 0) {
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x", this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
@@ -374,6 +406,20 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_from_device() {
|
||||
if (this->dev_obj == nullptr)
|
||||
return;
|
||||
|
||||
this->xfer_dir = DMA_DIR_FROM_DEV;
|
||||
|
||||
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
@@ -440,6 +486,41 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::end_push_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
|
||||
+12
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -103,12 +103,13 @@ namespace DBDMA_Cmd {
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
class DMAChannel : public DmaBidirChannel, public DmaChannel {
|
||||
public:
|
||||
DMAChannel(std::string name) : DmaBidirChannel(name) {}
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
void set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
|
||||
@@ -117,6 +118,10 @@ public:
|
||||
bool is_in_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
int push_data(const char* src_ptr, int len);
|
||||
int get_pull_data_remaining() { return this->queue_len; }
|
||||
int get_push_data_remaining() { return this->queue_len; }
|
||||
void end_pull_data();
|
||||
void end_push_data();
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
@@ -129,6 +134,7 @@ protected:
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
|
||||
void update_irq();
|
||||
void xfer_from_device();
|
||||
|
||||
void start(void);
|
||||
void resume(void);
|
||||
@@ -138,6 +144,9 @@ protected:
|
||||
private:
|
||||
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
||||
std::function<void(void)> in_cb = nullptr; // DMA channel in callback
|
||||
std::function<void(void)> out_cb = nullptr; // DMA channel out callback
|
||||
std::function<void(void)> flush_cb = nullptr; // DMA channel flush callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
@@ -156,4 +165,4 @@ private:
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
#endif // DB_DMA_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
@@ -39,6 +40,8 @@ public:
|
||||
virtual bool is_out_active() { return true; };
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
virtual int get_pull_data_remaining() { return 1; };
|
||||
virtual void end_pull_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
@@ -52,6 +55,8 @@ public:
|
||||
|
||||
virtual bool is_in_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; };
|
||||
virtual void end_push_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
@@ -71,4 +76,52 @@ private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// ---------------------- New DMA API -------------------------
|
||||
enum DmaMsg : unsigned {
|
||||
CH_START = 1,
|
||||
CH_STOP,
|
||||
DATA_AVAIL,
|
||||
};
|
||||
|
||||
enum XferDir : unsigned {
|
||||
DMA_DIR_UNDEF = 0,
|
||||
DMA_DIR_TO_DEV,
|
||||
DMA_DIR_FROM_DEV,
|
||||
};
|
||||
|
||||
class DmaChannel;
|
||||
|
||||
class DmaDevice {
|
||||
public:
|
||||
DmaDevice() = default;
|
||||
~DmaDevice() = default;
|
||||
|
||||
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; };
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
};
|
||||
|
||||
class DmaChannel {
|
||||
public:
|
||||
DmaChannel() = default;
|
||||
~DmaChannel() = default;
|
||||
|
||||
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
XferDir xfer_dir = DMA_DIR_UNDEF;
|
||||
};
|
||||
|
||||
/*
|
||||
TODO: write CONNECT macro that
|
||||
- constructs both DmaChannel and DmaDevice objects
|
||||
- calls connect() method on both objects
|
||||
- initializes DMA interrupts
|
||||
*/
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -46,6 +46,7 @@ enum HWCompType : uint64_t {
|
||||
SCSI_HOST = 1ULL << 21, // SCSI host adapter
|
||||
SCSI_DEV = 1ULL << 22, // SCSI device
|
||||
IDE_BUS = 1ULL << 23, // IDE bus
|
||||
IDE_HOST = 1ULL << 24, // IDE host controller
|
||||
IDE_DEV = 1ULL << 25, // IDE device
|
||||
SND_CODEC = 1ULL << 30, // sound codec
|
||||
SND_SERVER = 1ULL << 31, // host sound server
|
||||
|
||||
@@ -88,4 +88,9 @@ public:
|
||||
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
InterruptCtrl *int_ctrl_obj;
|
||||
uint32_t irq_id;
|
||||
} IntDetails;
|
||||
|
||||
#endif // HW_INTERRUPT_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -40,14 +40,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
set_name("Athens");
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
// set up power on values
|
||||
// This initialization is not prescribed
|
||||
// but let's set them to acceptable values anyway
|
||||
this->regs[AthensRegs::D2] = 2;
|
||||
this->regs[AthensRegs::N2] = 2;
|
||||
|
||||
// set P2_MUX2 on power up as follows:
|
||||
// - dot clock VCO is disabled
|
||||
// - dot clock = reference clock / 2
|
||||
this->regs[AthensRegs::P2_MUX2] = 0x62;
|
||||
}
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr, const float crystal_freq)
|
||||
: AthensClocks(dev_addr)
|
||||
{
|
||||
this->xtal_freq = crystal_freq;
|
||||
}
|
||||
|
||||
void AthensClocks::start_transaction()
|
||||
{
|
||||
this->pos = 0; // reset read/write position
|
||||
@@ -55,7 +69,7 @@ void AthensClocks::start_transaction()
|
||||
|
||||
bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(INFO, "Athens: subaddress set to 0x%X", sub_addr);
|
||||
LOG_F(INFO, "%s: subaddress set to 0x%X", this->name.c_str(), sub_addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,16 +82,14 @@ bool AthensClocks::send_byte(uint8_t data)
|
||||
break;
|
||||
case 1:
|
||||
if (this->reg_num >= ATHENS_NUM_REGS) {
|
||||
LOG_F(WARNING, "Athens: invalid register number %d", this->reg_num);
|
||||
LOG_F(WARNING, "%s: invalid register number %d", this->name.c_str(),
|
||||
this->reg_num);
|
||||
return false; // return NACK
|
||||
}
|
||||
this->regs[this->reg_num] = data;
|
||||
if (reg_num == 3) {
|
||||
LOG_F(INFO, "Athens: dot clock frequency set to %d Hz", get_dot_freq());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Athens: too much data received!");
|
||||
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
|
||||
return false; // return NACK
|
||||
}
|
||||
return true;
|
||||
@@ -101,8 +113,8 @@ int AthensClocks::get_dot_freq()
|
||||
22, 27, 28, 31, 35, 37, 38, 42, 49, 55, 56, 78, 125
|
||||
};
|
||||
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0xC0) {
|
||||
LOG_F(INFO, "Athens: dot clock disabled");
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0x80) {
|
||||
LOG_F(INFO, "%s: dot clock disabled", this->name.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -114,29 +126,31 @@ int AthensClocks::get_dot_freq()
|
||||
int post_div = 1 << (3 - (this->regs[AthensRegs::P2_MUX2] & 3));
|
||||
|
||||
if (std::find(D2_commons.begin(), D2_commons.end(), d2) == D2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested D2 value %d", d2);
|
||||
LOG_F(WARNING, "%s: untested D2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested N2 value %d", d2);
|
||||
LOG_F(WARNING, "%s: untested N2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
|
||||
|
||||
switch (mux) {
|
||||
case 0: // clock source -> dot cock VCO
|
||||
out_freq = ATHENS_XTAL * ((float)n2 / (float)(d2 * post_div));
|
||||
out_freq = this->xtal_freq * ((float)n2 / (float)(d2 * post_div));
|
||||
break;
|
||||
case 1: // clock source -> system clock VCO
|
||||
LOG_F(WARNING, "Athens: system clock VCO not supported yet!");
|
||||
LOG_F(WARNING, "%s: system clock VCO not supported yet!", this->name.c_str());
|
||||
break;
|
||||
case 2: // clock source -> crystal frequency
|
||||
out_freq = ATHENS_XTAL / post_div;
|
||||
out_freq = this->xtal_freq / post_div;
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(WARNING, "Athens: attempt to use reserved Mux value!");
|
||||
LOG_F(WARNING, "%s: attempt to use reserved Mux value!", this->name.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: dot clock frequency set to %f Hz", this->name.c_str(), out_freq);
|
||||
|
||||
return static_cast<int>(out_freq + 0.5f);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,7 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#define ATHENS_NUM_REGS 8
|
||||
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f; // external crystal oscillator frequency
|
||||
/** Default external crystal oscillator frequency. */
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f;
|
||||
|
||||
namespace AthensRegs {
|
||||
|
||||
@@ -52,6 +53,7 @@ class AthensClocks : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
AthensClocks(uint8_t dev_addr);
|
||||
AthensClocks(uint8_t dev_addr, const float crystal_freq);
|
||||
~AthensClocks() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
@@ -68,8 +70,9 @@ private:
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t reg_num = 0;
|
||||
int pos = 0;
|
||||
float xtal_freq = ATHENS_XTAL;
|
||||
|
||||
uint8_t regs[ATHENS_NUM_REGS];
|
||||
uint8_t regs[ATHENS_NUM_REGS] = {};
|
||||
};
|
||||
|
||||
#endif // ATHENS_H
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
~BoardRegister() = default;
|
||||
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return (!address) ? this->data : 0xFFFFU;
|
||||
return this->data;
|
||||
};
|
||||
|
||||
// appears read-only to guest
|
||||
|
||||
@@ -60,7 +60,7 @@ static uint32_t str2env(string& num_str) {
|
||||
|
||||
bool OfConfigAppl::validate() {
|
||||
int i;
|
||||
OfConfigHdrAppl hdr;
|
||||
OfConfigHdrAppl hdr{};
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
@@ -151,9 +151,9 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
|
||||
// populate the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
auto& name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
@@ -354,7 +354,7 @@ bool OfConfigChrp::validate()
|
||||
if (!of_part_found)
|
||||
return false;
|
||||
|
||||
OfConfigHdrChrp hdr;
|
||||
OfConfigHdrChrp hdr{};
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
|
||||
|
||||
@@ -79,6 +79,8 @@ uint32_t BanditPciDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details
|
||||
return this->mode_ctrl;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
return this->rd_hold_off_cnt;
|
||||
case BANDIT_DELAYED_AACK: // BANDIT_ONS
|
||||
return 0;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
@@ -103,6 +105,9 @@ void BanditPciDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDet
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
this->rd_hold_off_cnt = value & 0x1F;
|
||||
return;
|
||||
case BANDIT_DELAYED_AACK:
|
||||
// implement this for CATALYST and Platinum
|
||||
return;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
@@ -156,7 +161,7 @@ uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
return BYTESWAP_32(this->config_addr);
|
||||
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
|
||||
|
||||
default: // I/O space
|
||||
return pci_io_read_broadcast(offset, size);
|
||||
@@ -188,7 +193,7 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
break;
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
|
||||
break;
|
||||
|
||||
default: // I/O space
|
||||
@@ -213,20 +218,23 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
}
|
||||
details.flags = PCI_CONFIG_TYPE_0;
|
||||
bus_num = 0; // use dummy value for bus number
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
if (is_aspen)
|
||||
dev_num = (this->config_addr >> 11) + 11; // IDSEL = 1 << (dev_num + 11)
|
||||
else {
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
device = pci_find_device(dev_num, fun_num);
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit()
|
||||
{
|
||||
int BanditHost::device_postinit() {
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots1 = {
|
||||
@@ -298,6 +306,23 @@ Chaos::Chaos(std::string name) : BanditHost(0)
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
AspenPci::AspenPci(std::string name) : BanditHost(1) {
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
this->is_aspen = true;
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Aspen PCI control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF2000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
static const PropMap Bandit1_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
@@ -341,7 +366,12 @@ static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, Chaos_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
static const DeviceDescription AspenPci1_Descriptor = {
|
||||
AspenPci::create, {}, Bandit1_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(AspenPci1, AspenPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -60,6 +60,7 @@ enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
BANDIT_MODE_SELECT = 0x50,
|
||||
BANDIT_ARBUS_RD_HOLD_OFF = 0x58,
|
||||
BANDIT_DELAYED_AACK = 0x60,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
@@ -84,6 +85,7 @@ public:
|
||||
protected:
|
||||
uint32_t config_addr;
|
||||
int bridge_num;
|
||||
bool is_aspen = false;
|
||||
|
||||
private:
|
||||
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
@@ -133,8 +135,8 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
std::unique_ptr<BanditPciDevice> my_pci_device;
|
||||
uint32_t base_addr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -150,4 +152,17 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Aspen PCI Bridge HLE emulation class.
|
||||
*/
|
||||
class AspenPci : public BanditHost {
|
||||
public:
|
||||
AspenPci(std::string name);
|
||||
~AspenPci() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -142,7 +142,7 @@ protected:
|
||||
void unmap_exp_rom_mem();
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
|
||||
// PCI configuration space state (type 0, 1, and 2)
|
||||
uint16_t vendor_id;
|
||||
@@ -233,7 +233,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size) \
|
||||
)
|
||||
@@ -241,7 +241,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size), \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -165,14 +165,22 @@ void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
|
||||
|
||||
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_write_loop(offset, size, value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -50,6 +50,10 @@ public:
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
bool supports_io_space() {
|
||||
return true;
|
||||
};
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,8 +34,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
{
|
||||
// return false if dev_fun_num already registered
|
||||
if (this->dev_map.count(dev_fun_num))
|
||||
return false;
|
||||
if (this->dev_map.count(dev_fun_num)) {
|
||||
pci_unregister_device(dev_fun_num);
|
||||
}
|
||||
|
||||
int fun_num = dev_fun_num & 7;
|
||||
int dev_num = (dev_fun_num >> 3) & 0x1f;
|
||||
@@ -69,6 +70,22 @@ bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
void PCIHost::pci_unregister_device(int dev_fun_num)
|
||||
{
|
||||
if (!this->dev_map.count(dev_fun_num)) {
|
||||
return;
|
||||
}
|
||||
PCIBase* dev_instance = this->dev_map[dev_fun_num];
|
||||
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor)",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
|
||||
);
|
||||
|
||||
delete dev_instance;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
@@ -128,6 +145,27 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
return dev;
|
||||
}
|
||||
|
||||
IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
|
||||
bool dev_found = false;
|
||||
int dev_fun_num = 0;
|
||||
|
||||
for (auto& dev : this->dev_map) {
|
||||
if (dev.second == dev_instance) {
|
||||
dev_fun_num = dev.first;
|
||||
dev_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev_found)
|
||||
ABORT_F("register_pci_int: requested device not found");
|
||||
|
||||
for (auto& irq : this->my_irq_map) {
|
||||
if (irq.dev_fun_num == dev_fun_num)
|
||||
return {this->int_ctrl, irq.irq_id};
|
||||
}
|
||||
ABORT_F("register_pci_int: no IRQ map for device 0x%X", dev_fun_num);
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
@@ -151,11 +189,13 @@ bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
|
||||
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res;
|
||||
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_read_loop (offset, size, res)) {
|
||||
if (pci_io_read_loop(offset, size, res))
|
||||
return res;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
@@ -170,9 +210,10 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_write_loop(offset, size, value)) {
|
||||
if (pci_io_write_loop(offset, size, value))
|
||||
return;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -49,6 +50,12 @@ typedef struct AccessDetails {
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
typedef struct {
|
||||
const char * slot_name;
|
||||
int dev_fun_num;
|
||||
uint32_t irq_id;
|
||||
} PciIrqMap;
|
||||
|
||||
class PCIBase;
|
||||
class PCIBridgeBase;
|
||||
|
||||
@@ -61,6 +68,7 @@ public:
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
|
||||
virtual void pci_unregister_device(int dev_fun_num);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
@@ -80,10 +88,22 @@ public:
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
|
||||
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
|
||||
this->my_irq_map = irq_map;
|
||||
};
|
||||
|
||||
virtual IntDetails register_pci_int(PCIBase* dev_instance);
|
||||
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIBase*> dev_map;
|
||||
std::vector<PCIBase*> io_space_devs;
|
||||
std::vector<PCIBridgeBase*> bridge_devs;
|
||||
std::vector<PciIrqMap> my_irq_map;
|
||||
|
||||
InterruptCtrl *int_ctrl = nullptr;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
+140
-109
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
@@ -33,9 +34,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
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->attach_scsi_devices("2");
|
||||
}
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
@@ -44,27 +48,28 @@ int MeshController::device_postinit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::reset(bool is_hard_reset)
|
||||
{
|
||||
void MeshController::reset(bool is_hard_reset) {
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->fifo_cnt = 0;
|
||||
this->fifo_pos = 0;
|
||||
this->int_mask = 0;
|
||||
this->exception = 0;
|
||||
this->xfer_count = 0;
|
||||
this->src_id = 7;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MeshController::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t MeshController::read(uint8_t reg_offset) {
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
return this->xfer_count & 0xFFU;
|
||||
case MeshReg::XferCount1:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case MeshReg::FIFO:
|
||||
return this->fifo_pop();
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
@@ -72,9 +77,9 @@ uint8_t MeshController::read(uint8_t reg_offset)
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::FIFOCount:
|
||||
return this->fifo_cnt;
|
||||
return this->fifo_pos;
|
||||
case MeshReg::Exception:
|
||||
return 0;
|
||||
return this->exception;
|
||||
case MeshReg::Error:
|
||||
return 0;
|
||||
case MeshReg::IntMask:
|
||||
@@ -94,27 +99,27 @@ uint8_t MeshController::read(uint8_t reg_offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint16_t new_stat;
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value) {
|
||||
//uint16_t new_stat;
|
||||
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
this->xfer_count = (this->xfer_count & ~0xFFU) | value;
|
||||
break;
|
||||
case MeshReg::XferCount1:
|
||||
this->xfer_count = (this->xfer_count & ~0xFF00U) | (value << 8);
|
||||
break;
|
||||
case MeshReg::FIFO:
|
||||
this->fifo_push(value);
|
||||
break;
|
||||
case MeshReg::Sequence:
|
||||
perform_command(value);
|
||||
break;
|
||||
case MeshReg::BusStatus0:
|
||||
this->update_bus_status((this->bus_stat & 0xFF00U) | value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
new_stat = value << 8;
|
||||
if (new_stat != this->bus_stat) {
|
||||
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
this->update_bus_status((this->bus_stat & 0xFFU) | (value << 8));
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
this->int_mask = value;
|
||||
@@ -141,28 +146,87 @@ void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::perform_command(const uint8_t cmd)
|
||||
{
|
||||
void MeshController::perform_command(const uint8_t cmd) {
|
||||
this->cur_cmd = cmd;
|
||||
|
||||
this->int_stat &= ~INT_CMD_DONE;
|
||||
|
||||
this->is_dma_cmd = !!(this->cur_cmd & 0x80);
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->exception &= EXC_ARB_LOST;
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Select:
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->assert_atn = !!(this->cur_cmd & 0x20);
|
||||
this->exception &= EXC_SEL_TIMEOUT;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Command:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
|
||||
LOG_F(WARNING, "%s: not in COMMAND phase", this->name.c_str());
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_CMD;
|
||||
if (this->fifo_pos)
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Status:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS)
|
||||
LOG_F(WARNING, "%s: not in STATUS phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_STATUS;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_OUT)
|
||||
LOG_F(WARNING, "%s: not in DATA OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_IN)
|
||||
LOG_F(WARNING, "%s: not in DATA IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_OUT)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_MSG;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_IN)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_MESSAGE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::BusFree:
|
||||
LOG_F(INFO, "MESH: BusFree stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
// generate phase mismatch exception
|
||||
// if the target is still connected
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
|
||||
this->exception |= EXC_PHASE_MM;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
} else // say ok because we got the expected bus free phase
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->update_irq();
|
||||
break;
|
||||
case SeqCmd::EnaParityCheck:
|
||||
this->check_parity = true;
|
||||
break;
|
||||
case SeqCmd::DisParityCheck:
|
||||
this->check_parity = false;
|
||||
break;
|
||||
case SeqCmd::EnaReselect:
|
||||
LOG_F(INFO, "MESH: EnaReselect stub invoked");
|
||||
LOG_F(9, "MESH: EnaReselect stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::DisReselect:
|
||||
@@ -172,95 +236,62 @@ void MeshController::perform_command(const uint8_t cmd)
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->fifo_pos = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
void MeshController::update_bus_status(const uint16_t new_stat) {
|
||||
uint16_t mask;
|
||||
|
||||
// update the lower part (BusStatus0)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF) {
|
||||
for (mask = SCSI_CTRL_REQ; mask >= SCSI_CTRL_IO; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the upper part (BusStatus1)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF00U) {
|
||||
for (mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
|
||||
void MeshController::sequencer()
|
||||
{
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "MESH: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "MESH: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->cur_cmd & 0x20);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "MESH: selection completed");
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
void MeshController::step_completed() {
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void MeshController::report_error(const int error) {
|
||||
switch(error) {
|
||||
case SEL_TIMEOUT:
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("MESH: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::update_irq()
|
||||
{
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
ABORT_F("%s: unhandled error %d", this->name.c_str(), error);
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
static const PropMap Mesh_properties = {
|
||||
|
||||
+78
-110
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,106 +25,96 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define MESH_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class InterruptCtrl;
|
||||
class ScsiBus;
|
||||
|
||||
// Chip ID returned by the MESH ASIC on TNT machines (Apple part 343S1146-a)
|
||||
#define TntMeshID 0xE2
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
#define HeathrowMeshID 4
|
||||
|
||||
namespace MeshScsi {
|
||||
/** MESH registers offsets. */
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
// MESH registers offsets.
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
/** MESH Sequencer commands. */
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0x0,
|
||||
Arbitrate = 0x1,
|
||||
Select = 0x2,
|
||||
Command = 0x3,
|
||||
Status = 0x4,
|
||||
DataOut = 0x5,
|
||||
DataIn = 0x6,
|
||||
MessageOut = 0x7,
|
||||
MessageIn = 0x8,
|
||||
BusFree = 0x9,
|
||||
EnaParityCheck = 0xA,
|
||||
DisParityCheck = 0xB,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF
|
||||
};
|
||||
|
||||
// MESH Sequencer commands.
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
BusFree = 9,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF,
|
||||
};
|
||||
|
||||
// Exception register bits.
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
// Interrupt register bits.
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
|
||||
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
/** Exception register bits. */
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
/** Interrupt register bits. */
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshStub : public HWComponent {
|
||||
class MeshBase {
|
||||
public:
|
||||
MeshBase() = default;
|
||||
~MeshBase() = default;
|
||||
virtual uint8_t read(uint8_t reg_offset) = 0;
|
||||
virtual void write(uint8_t reg_offset, uint8_t value) = 0;
|
||||
};
|
||||
|
||||
class MeshStub : public MeshBase {
|
||||
public:
|
||||
MeshStub() = default;
|
||||
~MeshStub() = default;
|
||||
|
||||
// registers access
|
||||
uint8_t read(uint8_t reg_offset) { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) {};
|
||||
uint8_t read(uint8_t reg_offset) override { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) override {};
|
||||
};
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
class MeshController : public ScsiBusController, public MeshBase {
|
||||
public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
|
||||
this->chip_id = mesh_id;
|
||||
this->set_name("MESH");
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
@@ -134,55 +124,33 @@ public:
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_heathrow() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMeshID));
|
||||
}
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
// MeshBase methods
|
||||
uint8_t read(uint8_t reg_offset) override;
|
||||
void write(uint8_t reg_offset, uint8_t value) override;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
int device_postinit() override;
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
// ScsiBusController methods
|
||||
void step_completed() override;
|
||||
void report_error(const int error) override;
|
||||
|
||||
protected:
|
||||
void reset(bool is_hard_reset);
|
||||
void perform_command(const uint8_t cmd);
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void sequencer();
|
||||
void update_irq();
|
||||
void update_bus_status(const uint16_t new_stat);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
uint8_t int_mask;
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t sync_params;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
uint8_t cur_cmd;
|
||||
uint8_t error;
|
||||
uint8_t fifo_cnt;
|
||||
uint8_t exception;
|
||||
uint32_t xfer_count;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
uint8_t exception = 0;
|
||||
uint16_t bus_stat;
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
bool check_parity = true;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
+102
-40
@@ -43,10 +43,10 @@ Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
|
||||
|
||||
int Sc53C94::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
|
||||
if (this->bus_obj) {
|
||||
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
this->bus_obj->attach_scsi_devices("");
|
||||
ScsiBus* bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
|
||||
if (bus) {
|
||||
bus->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
bus->attach_scsi_devices("");
|
||||
}
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
@@ -59,7 +59,7 @@ int Sc53C94::device_postinit()
|
||||
void Sc53C94::reset_device()
|
||||
{
|
||||
// part-unique ID to be read using a magic sequence
|
||||
this->set_xfer_count = this->chip_id << 16;
|
||||
this->xfer_count = this->chip_id << 16;
|
||||
|
||||
this->clk_factor = 2;
|
||||
this->sel_timeout = 0;
|
||||
@@ -172,7 +172,7 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
// remove one word from FIFO
|
||||
data_word = (this->data_fifo[0] << 8) | this->data_fifo[1];
|
||||
this->data_fifo_pos -= 2;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
|
||||
// update DMA status
|
||||
if (this->is_dma_cmd) {
|
||||
@@ -215,14 +215,14 @@ void Sc53C94::pseudo_dma_write(uint16_t data) {
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP) {
|
||||
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Reset Device (chip), Reset Bus and DMA Stop commands execute
|
||||
// immediately while all others are placed into the command FIFO
|
||||
switch (cmd & 0x7F) {
|
||||
switch (cmd & CMD_OPCODE) {
|
||||
case CMD_RESET_DEVICE:
|
||||
case CMD_RESET_BUS:
|
||||
case CMD_DMA_STOP:
|
||||
@@ -280,9 +280,14 @@ void Sc53C94::exec_command()
|
||||
// assert RST line
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
// release RST line after 25 us
|
||||
if (my_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer_id);
|
||||
my_timer_id = 0;
|
||||
}
|
||||
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(25),
|
||||
[this]() {
|
||||
my_timer_id = 0;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & 0x40)) {
|
||||
@@ -306,9 +311,9 @@ void Sc53C94::exec_command()
|
||||
break;
|
||||
case CMD_COMPLETE_STEPS:
|
||||
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
|
||||
{SeqState::RCV_STATUS, 0, 0},
|
||||
{SeqState::RCV_MESSAGE, 0, 0},
|
||||
{SeqState::CMD_COMPLETE, 0, INTSTAT_SR}
|
||||
{(CMD_COMPLETE_STEPS << 8) + 1, SeqState::RCV_STATUS, 0, 0},
|
||||
{(CMD_COMPLETE_STEPS << 8) + 2, SeqState::RCV_MESSAGE, 0, 0},
|
||||
{(CMD_COMPLETE_STEPS << 8) + 3, SeqState::CMD_COMPLETE, 0, INTSTAT_SR | INTSTAT_SO}
|
||||
};
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
|
||||
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
|
||||
@@ -323,16 +328,15 @@ void Sc53C94::exec_command()
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_SELECT_NO_ATN:
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
{(CMD_SELECT_NO_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{(CMD_SELECT_NO_ATN << 8) + 2, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{(CMD_SELECT_NO_ATN << 8) + 3, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
@@ -342,10 +346,10 @@ void Sc53C94::exec_command()
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN:
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
{(CMD_SELECT_WITH_ATN << 8) + 1, SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{(CMD_SELECT_WITH_ATN << 8) + 2, SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
|
||||
{(CMD_SELECT_WITH_ATN << 8) + 3, SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{(CMD_SELECT_WITH_ATN << 8) + 4, SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->bytes_out = 1; // set message length
|
||||
@@ -376,6 +380,8 @@ void Sc53C94::exec_next_command()
|
||||
}
|
||||
}
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
void Sc53C94::fifo_push(const uint8_t data)
|
||||
{
|
||||
if (this->data_fifo_pos < DATA_FIFO_MAX) {
|
||||
@@ -396,7 +402,7 @@ uint8_t Sc53C94::fifo_pop()
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
this->data_fifo_pos--;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -404,10 +410,16 @@ uint8_t Sc53C94::fifo_pop()
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
if (seq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
}
|
||||
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
@@ -471,7 +483,8 @@ void Sc53C94::sequencer()
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
if (this->drq_cb)
|
||||
this->drq_cb(1);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
@@ -481,7 +494,8 @@ void Sc53C94::sequencer()
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
if (this->drq_cb)
|
||||
this->drq_cb(1);
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
@@ -491,6 +505,7 @@ void Sc53C94::sequencer()
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -522,6 +537,7 @@ void Sc53C94::sequencer()
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -562,7 +578,7 @@ void Sc53C94::update_irq()
|
||||
uint8_t new_irq = !!(this->int_status != 0);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->status = (this->status & 0x7F) | (new_irq << 7);
|
||||
this->status = (this->status & ~STAT_INT) | (new_irq << 7);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
@@ -574,6 +590,7 @@ void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
if (this->target_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
@@ -643,7 +660,7 @@ void Sc53C94::real_dma_xfer_out()
|
||||
{
|
||||
// transfer data from host's memory to target
|
||||
|
||||
while (this->xfer_count) {
|
||||
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),
|
||||
@@ -660,6 +677,16 @@ void Sc53C94::real_dma_xfer_out()
|
||||
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()
|
||||
@@ -668,25 +695,60 @@ void Sc53C94::real_dma_xfer_in()
|
||||
|
||||
// transfer data from target to host's memory
|
||||
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
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->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;
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap Sc53C94_properties = {
|
||||
|
||||
@@ -30,16 +30,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SC_53C94_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class DmaBidirChannel;
|
||||
class InterruptCtrl;
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
/** 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
@@ -181,6 +179,7 @@ namespace SeqState {
|
||||
|
||||
/** Sequence descriptor for sequencer commands. */
|
||||
typedef struct {
|
||||
int seq_id;
|
||||
int next_step;
|
||||
int step_num;
|
||||
int status;
|
||||
@@ -210,8 +209,18 @@ public:
|
||||
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) {
|
||||
@@ -244,7 +253,6 @@ protected:
|
||||
private:
|
||||
uint8_t chip_id = 0;
|
||||
uint8_t my_bus_id = 0;
|
||||
ScsiBus* bus_obj;
|
||||
uint32_t my_timer_id = 0;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
@@ -284,6 +292,7 @@ private:
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch = nullptr;
|
||||
DrqCb drq_cb = nullptr;
|
||||
uint32_t dma_timer_id = 0;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
+13
-10
@@ -142,16 +142,17 @@ enum ScsiSense : int {
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
SAVING_NOT_SUPPORTED = 0x39,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
@@ -199,6 +200,8 @@ public:
|
||||
this->bus_obj = bus_obj_ptr;
|
||||
}
|
||||
|
||||
void report_error(uint8_t sense_key, uint8_t asc);
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
|
||||
@@ -52,7 +52,7 @@ ScsiBus::ScsiBus(const std::string name)
|
||||
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
{
|
||||
if (this->devices[id] != nullptr) {
|
||||
ABORT_F("ScsiBus: device with ID %d already registered", id);
|
||||
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
|
||||
}
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
@@ -73,7 +73,8 @@ void ScsiBus::change_bus_phase(int initiator_id)
|
||||
|
||||
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", initiator_id);
|
||||
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS,
|
||||
"%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
|
||||
|
||||
uint16_t new_state = 0xFFFFU & mask;
|
||||
|
||||
@@ -92,7 +93,7 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
|
||||
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", id);
|
||||
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
|
||||
|
||||
uint16_t new_state = 0;
|
||||
|
||||
@@ -254,7 +255,7 @@ bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
}
|
||||
|
||||
if (!this->devices[id]->send_data(dst_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring T->I data!");
|
||||
LOG_F(ERROR, "%s: error while transferring T->I data!", this->get_name().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -263,11 +264,19 @@ bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
|
||||
bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
{
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring I->T data!");
|
||||
if (!this->devices[id]) {
|
||||
LOG_F(ERROR, "%s: no device %d for push_data %d bytes",
|
||||
this->get_name().c_str(), id, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
if (size) {
|
||||
LOG_F(ERROR, "%s: error while transferring I->T data!", this->get_name().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -277,12 +286,22 @@ int ScsiBus::target_xfer_data() {
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step();
|
||||
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]->next_step();
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->devices[this->target_id]->prepare_xfer(this, bytes_in, 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;
|
||||
}
|
||||
@@ -307,17 +326,22 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we skip ID 3.
|
||||
for (scsi_id = 0; scsi_id < SCSI_MAX_DEVS * 2 && (scsi_id == 3 || this->devices[scsi_id % SCSI_MAX_DEVS]); scsi_id++) {}
|
||||
for (scsi_id = 0; scsi_id < SCSI_MAX_DEVS * 2 && (scsi_id == 3 ||
|
||||
this->devices[scsi_id % SCSI_MAX_DEVS]); scsi_id++) {}
|
||||
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiHD" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
std::string scsi_device_name = "ScsiHD" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiHardDisk *scsi_device = new ScsiHardDisk(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiHardDisk>(scsi_device));
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiHardDisk>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. HDD \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
LOG_F(ERROR, "%s: Too many devices. HDD \"%s\" was not added.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,17 +351,22 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we start at ID 3.
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 && this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 &&
|
||||
this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiCdrom *scsi_device = new ScsiCdrom(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,4 +381,4 @@ static const DeviceDescription ScsiMesh_Descriptor = {
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
|
||||
REGISTER_DEVICE(ScsiMesh, ScsiMesh_Descriptor);
|
||||
REGISTER_DEVICE(ScsiMesh, ScsiMesh_Descriptor);
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Scsi_Bus_Controller;
|
||||
|
||||
void ScsiBusController::seq_defer_state(uint64_t delay_ns) {
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
|
||||
void ScsiBusController::sequencer() {
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
this->step_completed();
|
||||
} else { // arbitration lost
|
||||
LOG_F(ERROR, "%s: arbitration lost!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->report_error(ARB_LOST);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->assert_atn);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "%s: selection completed", this->name.c_str());
|
||||
this->step_completed();
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->report_error(SEL_TIMEOUT);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
if (this->fifo_pos) {
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
|
||||
if (this->to_xfer <= 0)
|
||||
this->step_completed();
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
this->bus_obj->target_xfer_data();
|
||||
if (!this->fifo_pos)
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::XFER_BEGIN:
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
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();
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
if (this->is_initiator)
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::SEND_DATA:
|
||||
if (this->bus_obj->push_data(this->dst_id, this->data_fifo, this->fifo_pos)) {
|
||||
this->to_xfer -= this->fifo_pos;
|
||||
this->fifo_pos = 0;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_DATA:
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
LOG_F(WARNING, "%s: phase mismatch!", this->name.c_str());
|
||||
} else {
|
||||
if (!this->rcv_data()) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(),
|
||||
this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
if (this->dst_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
|
||||
this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
this->cur_bus_phase = param;
|
||||
#if 0
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
|
||||
msg_type);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBusController::rcv_data() {
|
||||
int req_count;
|
||||
|
||||
// return if REQ line is negated
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_REQ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->to_xfer)
|
||||
return false;
|
||||
|
||||
req_count = std::min(this->to_xfer, DATA_FIFO_DEPTH - this->fifo_pos);
|
||||
|
||||
this->bus_obj->pull_data(this->dst_id, &this->data_fifo[this->fifo_pos], req_count);
|
||||
this->fifo_pos += req_count;
|
||||
this->to_xfer -= req_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiBusController::send_data(uint8_t* dst_ptr, int count) {
|
||||
if (dst_ptr == nullptr || !count)
|
||||
return 0;
|
||||
|
||||
int actual_count = std::min(this->fifo_pos, count);
|
||||
|
||||
// move data out of the data FIFO
|
||||
std::memcpy(dst_ptr, this->data_fifo, actual_count);
|
||||
|
||||
// remove the just readed data from the data FIFO
|
||||
this->fifo_pos -= actual_count;
|
||||
this->to_xfer -= actual_count;
|
||||
if (this->fifo_pos > 0)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->fifo_pos);
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiBusController::xfer_from(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());
|
||||
|
||||
if (this->fifo_pos) {
|
||||
int fifo_bytes = std::min(this->fifo_pos, len);
|
||||
std::memcpy(buf, this->data_fifo, fifo_bytes);
|
||||
this->fifo_pos -= fifo_bytes;
|
||||
len -= fifo_bytes;
|
||||
buf += fifo_bytes;
|
||||
}
|
||||
|
||||
int dma_bytes = std::min(this->to_xfer, len);
|
||||
|
||||
if (this->bus_obj->pull_data(this->dst_id, buf, dma_bytes)) {
|
||||
this->to_xfer -= dma_bytes;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->xfer_count = this->to_xfer;
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void ScsiBusController::update_irq() {
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::fifo_push(const uint8_t data) {
|
||||
if (this->fifo_pos < DATA_FIFO_DEPTH) {
|
||||
this->data_fifo[this->fifo_pos++] = data;
|
||||
if (!this->xfer_count)
|
||||
LOG_F(WARNING, "%s: zero xfer_count!", this->name.c_str());
|
||||
if (--this->xfer_count == 0)
|
||||
this->sequencer();
|
||||
} else
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
uint8_t ScsiBusController::fifo_pop() {
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->fifo_pos) {
|
||||
data = this->data_fifo[0];
|
||||
if (--this->fifo_pos)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->fifo_pos);
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->fifo_pos)
|
||||
this->sequencer();
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller definitions. */
|
||||
|
||||
#ifndef SCSI_BUS_CTRL_H
|
||||
#define SCSI_BUS_CTRL_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
namespace Scsi_Bus_Controller {
|
||||
/** SCSI sequencer states. */
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
|
||||
/** Sequencer error codes. */
|
||||
enum : int {
|
||||
ARB_LOST = 1,
|
||||
SEL_TIMEOUT,
|
||||
};
|
||||
|
||||
#define DATA_FIFO_DEPTH 16
|
||||
|
||||
class ScsiBusController : public ScsiDevice, public DmaDevice {
|
||||
public:
|
||||
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
}
|
||||
~ScsiBusController() = default;
|
||||
|
||||
// implements SCSI FSM
|
||||
void sequencer();
|
||||
|
||||
virtual void step_completed() = 0;
|
||||
virtual void report_error(const int error) = 0;
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool get_more_data() { return false; };
|
||||
bool has_data() { return false; };
|
||||
bool rcv_data();
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
|
||||
|
||||
protected:
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void update_irq();
|
||||
void fifo_push(const uint8_t data);
|
||||
uint8_t fifo_pop();
|
||||
|
||||
ScsiBus* bus_obj = nullptr;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
bool is_dma_cmd = false;
|
||||
bool is_initiator = true;
|
||||
bool assert_atn = false;
|
||||
|
||||
// Data FIFO state
|
||||
int fifo_pos = 0;
|
||||
int to_xfer = 0;
|
||||
uint32_t xfer_count = 0;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
int cur_bus_phase = 0;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
uint8_t int_mask = 0;
|
||||
uint8_t int_stat = 0;
|
||||
};
|
||||
|
||||
#endif // SCSI_BUS_CTRL_H
|
||||
@@ -32,19 +32,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
static char cdrom_vendor_sony_id[] = "SONY ";
|
||||
static char cdu8003a_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char cdu8003a_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
|
||||
{
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->report_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba, xfer_len;
|
||||
uint32_t lba;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
@@ -61,55 +60,18 @@ void ScsiCdrom::process_command()
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->incoming_size = cmd[4];
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
this->mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
@@ -119,40 +81,23 @@ void ScsiCdrom::process_command()
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
xfer_len = READ_WORD_BE_U(&cmd[7]);
|
||||
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, xfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_LONG_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
read(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -184,8 +129,11 @@ bool ScsiCdrom::get_more_data() {
|
||||
return this->data_size != 0;
|
||||
}
|
||||
|
||||
void ScsiCdrom::read(const uint32_t lba, uint16_t nblocks, const uint8_t cmd_len)
|
||||
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
|
||||
{
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
if (cmd_len == 6 && nblocks == 0)
|
||||
nblocks = 256;
|
||||
|
||||
@@ -212,10 +160,22 @@ void ScsiCdrom::inquiry() {
|
||||
}
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
LOG_F(ERROR, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
this->data_buf[0] = 5; // device type: CD-ROM
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
LOG_F(9, "%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(9, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
|
||||
alloc_len, cmd_buf[1]);
|
||||
lun = cmd_buf[1] >> 5;
|
||||
}
|
||||
|
||||
this->data_buf[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
|
||||
this->data_buf[1] = 0x80; // removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
@@ -223,11 +183,20 @@ void ScsiCdrom::inquiry() {
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&this->data_buf[8], cdrom_vendor_sony_id, 8);
|
||||
std::memcpy(&this->data_buf[16], cdu8003a_product_id, 16);
|
||||
std::memcpy(&this->data_buf[32], cdu8003a_revision_id, 4);
|
||||
std::memcpy(&this->data_buf[8], vendor_info, 8);
|
||||
std::memcpy(&this->data_buf[16], prod_info, 16);
|
||||
std::memcpy(&this->data_buf[32], rev_info, 4);
|
||||
//std::memcpy(&this->data_buf[36], serial_number, 8);
|
||||
//etc.
|
||||
|
||||
this->bytes_out = 36;
|
||||
if (alloc_len < 36) {
|
||||
LOG_F(ERROR, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
else {
|
||||
memset(&this->data_buf[36], 0, alloc_len - 36);
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
@@ -235,22 +204,20 @@ void ScsiCdrom::inquiry() {
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiCdrom::mode_sense()
|
||||
void ScsiCdrom::mode_sense_6()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
//uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
int num_blocks = this->size_blocks;
|
||||
|
||||
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] = (num_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (num_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
|
||||
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;
|
||||
@@ -278,7 +245,15 @@ void ScsiCdrom::mode_sense()
|
||||
this->data_buf[17] = 'p';
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
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];
|
||||
@@ -287,79 +262,21 @@ void ScsiCdrom::mode_sense()
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_toc()
|
||||
void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
{
|
||||
int tot_tracks;
|
||||
uint8_t start_track = this->cmd_buf[6];
|
||||
uint16_t alloc_len = (this->cmd_buf[7] << 8) + this->cmd_buf[8];
|
||||
bool is_msf = !!(this->cmd_buf[1] & 2);
|
||||
|
||||
if (this->cmd_buf[2] & 0xF) {
|
||||
ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str());
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str());
|
||||
if (!param_len)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!start_track) { // special case: track zero (lead-in) as starting track
|
||||
// return all tracks starting with track 1 plus lead-out
|
||||
start_track = 1;
|
||||
tot_tracks = this->num_tracks + 1;
|
||||
} else if (start_track == LEAD_OUT_TRK_NUM) {
|
||||
start_track = this->num_tracks + 1;
|
||||
tot_tracks = 1;
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(),
|
||||
start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
this->incoming_size = param_len;
|
||||
|
||||
uint8_t* buf_ptr = this->data_buf;
|
||||
std::memset(&this->data_buf[0], 0, 512);
|
||||
|
||||
int data_len = (tot_tracks * 8) + 2;
|
||||
this->post_xfer_action = [this]() {
|
||||
// TODO: parse the received mode parameter list here
|
||||
LOG_F(INFO, "Mode Select: received mode parameter list");
|
||||
};
|
||||
|
||||
// write TOC data header
|
||||
*buf_ptr++ = (data_len >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (data_len >> 0) & 0xFFU;
|
||||
*buf_ptr++ = 1; // 1st track number
|
||||
*buf_ptr++ = this->num_tracks; // last track number
|
||||
|
||||
for (int tx = 0; tx < tot_tracks; tx++) {
|
||||
if ((buf_ptr - this->data_buf + 8) > alloc_len)
|
||||
break; // exit the loop if the output buffer length is exhausted
|
||||
|
||||
TrackDescriptor& td = this->tracks[start_track + tx - 1];
|
||||
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = td.adr_ctrl;
|
||||
*buf_ptr++ = td.trk_num;
|
||||
*buf_ptr++ = 0; // reserved
|
||||
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(td.start_lba + 150);
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = msf.min;
|
||||
*buf_ptr++ = msf.sec;
|
||||
*buf_ptr++ = msf.frm;
|
||||
} else {
|
||||
*buf_ptr++ = (td.start_lba >> 24) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 16) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 0) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity_10()
|
||||
@@ -374,20 +291,21 @@ void ScsiCdrom::read_capacity_10()
|
||||
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;
|
||||
}
|
||||
|
||||
int last_lba = this->size_blocks - 1;
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
|
||||
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
|
||||
this->data_buf[2] = (last_lba >> 8) & 0xFFU;
|
||||
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
|
||||
this->data_buf[4] = 0;
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = (this->block_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->block_size & 0xFFU;
|
||||
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;
|
||||
|
||||
@@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ScsiCdrom : public ScsiDevice, public CdromDrive {
|
||||
class ScsiCdrom : public CdromDrive, public ScsiDevice {
|
||||
public:
|
||||
ScsiCdrom(std::string name, int my_id);
|
||||
~ScsiCdrom() = default;
|
||||
@@ -45,14 +45,20 @@ protected:
|
||||
int test_unit_ready();
|
||||
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
|
||||
void inquiry();
|
||||
void mode_sense();
|
||||
void read_toc();
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6();
|
||||
void read_capacity_10();
|
||||
|
||||
private:
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_buf[2048] = {};
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[9] = "SONY ";
|
||||
char prod_info[17] = "CD-ROM CDU-8003A";
|
||||
char rev_info[5] = "1.9a";
|
||||
};
|
||||
|
||||
#endif // SCSI_CDROM_H
|
||||
@@ -95,6 +95,7 @@ void ScsiDevice::next_step()
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
@@ -221,13 +222,12 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
return count;
|
||||
}
|
||||
|
||||
bool ScsiDevice::check_lun()
|
||||
{
|
||||
bool ScsiDevice::check_lun() {
|
||||
if (this->cmd_buf[1] >> 5 != this->lun) {
|
||||
LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x25; // Logical Unit Not Supported
|
||||
this->asc = ScsiError::INVALID_LUN;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
@@ -237,14 +237,22 @@ bool ScsiDevice::check_lun()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd)
|
||||
{
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd) {
|
||||
LOG_F(ERROR, "%s: unsupported command: 0x%02x", this->name.c_str(), cmd[0]);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x20; // Invalid command operation code
|
||||
this->asc = ScsiError::INVALID_CMD;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
|
||||
void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = sense_key;
|
||||
this->asc = asc;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
+231
-130
@@ -46,17 +46,12 @@ void ScsiHardDisk::insert_image(std::string filename) {
|
||||
uint64_t tb = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
this->total_blocks = static_cast<int>(tb);
|
||||
if (this->total_blocks < 0 || tb != this->total_blocks) {
|
||||
ABORT_F("ScsiHardDisk: file size is too large");
|
||||
ABORT_F("%s: file size is too large", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiHardDisk::process_command() {
|
||||
uint32_t lba = 0;
|
||||
uint16_t transfer_len = 0;
|
||||
uint16_t alloc_len = 0;
|
||||
|
||||
uint8_t page_code = 0;
|
||||
uint8_t subpage_code = 0;
|
||||
uint32_t lba;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
@@ -69,98 +64,53 @@ void ScsiHardDisk::process_command() {
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
alloc_len = cmd[4];
|
||||
req_sense(alloc_len);
|
||||
this->req_sense(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->format();
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
read(lba, transfer_len, 6);
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->write(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
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 = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
read(lba, transfer_len, 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());
|
||||
}
|
||||
this->read(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
write(lba, transfer_len, 10);
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_BUFFER:
|
||||
read_buffer();
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
default:
|
||||
this->illegal_command(cmd);
|
||||
}
|
||||
@@ -182,17 +132,20 @@ bool ScsiHardDisk::prepare_data() {
|
||||
} else {
|
||||
this->data_buf[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->data_size = 1;
|
||||
this->bytes_out = 1;
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_buf[0] = this->msg_code;
|
||||
this->data_size = 1;
|
||||
this->bytes_out = 1;
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -202,11 +155,59 @@ int ScsiHardDisk::test_unit_ready() {
|
||||
}
|
||||
|
||||
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
if (alloc_len != 252) {
|
||||
LOG_F(WARNING, "%s: inappropriate Allocation Length: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
//if (!check_lun())
|
||||
// return;
|
||||
|
||||
//int next_phase;
|
||||
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
lun = this->last_selection_message & 7;
|
||||
}
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
else {
|
||||
lun = cmd_buf[1] >> 5;
|
||||
}
|
||||
|
||||
if (lun == this->lun) {
|
||||
this->status = ScsiStatus::GOOD;
|
||||
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
|
||||
this->data_buf[12] = this->asc; // addition sense code
|
||||
this->data_buf[13] = this->ascq; // additional sense qualifier
|
||||
this->data_buf[15] = this->sksv; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
|
||||
this->data_buf[16] = this->field >> 8; // field pointer
|
||||
this->data_buf[17] = this->field;
|
||||
}
|
||||
else {
|
||||
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
|
||||
this->data_buf[12] = ScsiError::INVALID_LUN; // addition sense code = Logical Unit Not Supported
|
||||
this->data_buf[13] = 0; // additional sense qualifier
|
||||
this->data_buf[15] = 0; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
|
||||
this->data_buf[16] = 0; // field pointer
|
||||
this->data_buf[17] = 0;
|
||||
}
|
||||
|
||||
{
|
||||
// FIXME: there should be a way to set the VALID and ILI bits.
|
||||
this->data_buf[ 0] = 0x70; // Valid:0x80, Error Code:0x7f
|
||||
this->data_buf[ 1] = 0; // segment number
|
||||
this->data_buf[ 3] = 0; // information
|
||||
this->data_buf[ 4] = 0;
|
||||
this->data_buf[ 5] = 0;
|
||||
this->data_buf[ 6] = 0;
|
||||
this->data_buf[ 7] = 10; // additional sense length
|
||||
this->data_buf[ 8] = 0; // command specific information
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = 0;
|
||||
this->data_buf[11] = 0;
|
||||
this->data_buf[14] = 0; // field replaceable unit code
|
||||
this->data_buf[18] = 0; // reserved
|
||||
this->data_buf[19] = 0; // reserved
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len; // Open Firmware 1.0.5 asks for 18 bytes.
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
void ScsiHardDisk::inquiry() {
|
||||
@@ -217,27 +218,45 @@ void ScsiHardDisk::inquiry() {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
if (alloc_len >= 36) {
|
||||
this->data_buf[0] = 0; // device type: Direct-access block device
|
||||
this->data_buf[1] = 0; // non-removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(data_buf + 8, vendor_info, 8);
|
||||
std::memcpy(data_buf + 16, prod_info, 16);
|
||||
std::memcpy(data_buf + 32, rev_info, 4);
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(INFO, "%s: %d bytes requested in INQUIRY", this->name.c_str(), alloc_len);
|
||||
}
|
||||
|
||||
this->bytes_out = 36;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
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(WARNING, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(), alloc_len, cmd_buf[1]);
|
||||
lun = cmd_buf[1] >> 5;
|
||||
}
|
||||
|
||||
this->data_buf[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
|
||||
this->data_buf[1] = 0; // non-removable media; 0x80 = removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0x1F; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&this->data_buf[8], vendor_info, 8);
|
||||
std::memcpy(&this->data_buf[16], prod_info, 16);
|
||||
std::memcpy(&this->data_buf[32], rev_info, 4);
|
||||
//std::memcpy(&this->data_buf[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(&this->data_buf[36], 0, alloc_len - 36);
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
int ScsiHardDisk::send_diagnostic() {
|
||||
@@ -266,51 +285,124 @@ static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
void ScsiHardDisk::mode_sense_6() {
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
|
||||
uint8_t sub_page_code = this->cmd_buf[3];
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0; // medium is write enabled
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
if (page_ctrl == 1) {
|
||||
LOG_F(INFO, "%s: page_ctrl 1 CHANGEABLE VALUES is not implemented", 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 = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (this->total_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (this->total_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (this->total_blocks ) & 0xFFU;
|
||||
if (page_ctrl == 2) {
|
||||
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", 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 = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (page_ctrl == 3) {
|
||||
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = SAVING_NOT_SUPPORTED;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0; // 0:medium is not write protected; 0x80 write protected
|
||||
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], this->total_blocks);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[8], this->sector_size);
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
uint8_t *p_buf = &this->data_buf[12];
|
||||
bool got_page = false;
|
||||
int page_size;
|
||||
|
||||
switch(page_code) {
|
||||
case 1: // read-write error recovery page
|
||||
this->data_buf[13] = 6; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
break;
|
||||
case 3: // Format device page
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 22);
|
||||
if (page_code == 1 || page_code == 0x3f) { // read-write error recovery page
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 8;
|
||||
p_buf[0] = 1; // page code
|
||||
p_buf[1] = page_size - 2; // data size - 1
|
||||
std::memset(&p_buf[2], 0, 6);
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 3 || page_code == 0x3f) { // Format device page
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 24;
|
||||
p_buf[ 0] = 3; // page code
|
||||
p_buf[ 1] = page_size - 2; // data size - 1
|
||||
std::memset(&p_buf[2], 0, 22);
|
||||
// default values taken from Empire 540/1080S manual
|
||||
this->data_buf[15] = 6; // tracks per defect zone
|
||||
this->data_buf[17] = 1; // alternate sectors per zone
|
||||
this->data_buf[23] = 92; // sectors per track in the outermost zone
|
||||
this->data_buf[27] = 1; // interleave factor
|
||||
this->data_buf[29] = 19; // track skew factor
|
||||
this->data_buf[31] = 25; // cylinder skew factor
|
||||
this->data_buf[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
WRITE_WORD_BE_U(&this->data_buf[24], 512); // bytes per sector
|
||||
break;
|
||||
case 0x30: // Copyright page for Apple certified drives
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
};
|
||||
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
|
||||
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
|
||||
WRITE_WORD_BE_U(&p_buf[10], 92); // sectors per track in the outermost zone
|
||||
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
|
||||
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
|
||||
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
|
||||
WRITE_WORD_BE_U(&p_buf[18], 25); // cylinder skew factor
|
||||
p_buf[20] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 24;
|
||||
p_buf[0] = 0x30; // page code
|
||||
p_buf[1] = page_size - 2; // data size - 1
|
||||
std::memcpy(&p_buf[2], Apple_Copyright_Page_Data, 22);
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (!(got_page || page_code == 0x3f)) { // not any of the supported pages or all pages
|
||||
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;
|
||||
bad_sub_page:
|
||||
LOG_F(WARNING, "%s: unsupported page/subpage %02xh/%02xh in MODE_SENSE_6", this->name.c_str(), page_code, sub_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 = 3;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
// adjust for overall mode sense data length
|
||||
this->data_buf[0] += this->data_buf[13] + 1;
|
||||
this->data_buf[0] = p_buf - this->data_buf - 1;
|
||||
|
||||
this->bytes_out = std::min(alloc_len, (uint8_t)this->data_buf[0]);
|
||||
this->bytes_out = std::min((int)alloc_len, (int)this->data_buf[0] + 1);
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
@@ -326,22 +418,28 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
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;
|
||||
|
||||
uint32_t last_lba = this->total_blocks - 1;
|
||||
uint32_t blk_len = this->sector_size;
|
||||
|
||||
WRITE_DWORD_BE_A(&data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&data_buf[4], blk_len);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], blk_len);
|
||||
|
||||
this->bytes_out = 8;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
|
||||
void ScsiHardDisk::format() {
|
||||
LOG_F(WARNING, "%s: attempt to format the disk!", this->name.c_str());
|
||||
|
||||
@@ -354,9 +452,12 @@ void ScsiHardDisk::format() {
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(data_buf, 0, sizeof(data_buf));
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
@@ -365,7 +466,7 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = (uint64_t)lba * this->sector_size;
|
||||
|
||||
this->disk_img.read(data_buf, device_offset, transfer_size);
|
||||
this->disk_img.read(this->data_buf, device_offset, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
static const int sector_size = 512;
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
|
||||
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
|
||||
|
||||
+216
-132
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,30 +47,25 @@ ViaCuda::ViaCuda() {
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
this->via_porta = 0;
|
||||
this->via_portb = 0;
|
||||
this->via_ddrb = 0;
|
||||
this->via_ddra = 0;
|
||||
this->via_acr = 0;
|
||||
this->via_pcr = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
this->via_t1ll = 0xFF;
|
||||
this->via_t1lh = 0xFF;
|
||||
this->via_t2cl = 0xFF;
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
|
||||
// intialize counters/timers
|
||||
this->t1_counter = 0xFFFF;
|
||||
this->t1_active = false;
|
||||
this->t2_counter = 0xFFFF;
|
||||
this->t2_active = false;
|
||||
|
||||
// calculate VIA clock duration in ns
|
||||
this->via_clk_dur = 1.0f / VIA_CLOCK_HZ * NS_PER_SEC;
|
||||
@@ -87,21 +82,32 @@ ViaCuda::ViaCuda() {
|
||||
this->cuda_init();
|
||||
|
||||
this->int_ctrl = nullptr;
|
||||
|
||||
std::tm tm = {
|
||||
.tm_sec = 0,
|
||||
.tm_min = 0,
|
||||
.tm_hour = 0,
|
||||
.tm_mday = 1,
|
||||
.tm_mon = 1 - 1,
|
||||
.tm_year = 1904 - 1900,
|
||||
.tm_isdst = 1 // -1 = Use DST value from local time zone; 0 = not summer; 1 = is summer time
|
||||
};
|
||||
mac_epoch = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer_on) {
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
if (this->t1_active) {
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
if (this->t2_active) {
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
if (this->treq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer_id);
|
||||
@@ -128,24 +134,29 @@ void ViaCuda::cuda_init() {
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
uint8_t value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
return (this->via_regs[VIA_B]);
|
||||
return this->via_portb; //(this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
return this->via_porta;
|
||||
case VIA_DIRB:
|
||||
return this->via_ddrb;
|
||||
case VIA_DIRA:
|
||||
return this->via_ddra;
|
||||
case VIA_T1CL:
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
|
||||
case VIA_T1CH:
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
|
||||
case VIA_T1LL:
|
||||
return this->via_t1ll;
|
||||
case VIA_T1LH:
|
||||
return this->via_t1lh;
|
||||
case VIA_T2CL:
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
@@ -153,37 +164,122 @@ uint8_t ViaCuda::read(int reg) {
|
||||
case VIA_T2CH:
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
case VIA_SR:
|
||||
value = this->via_sr;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
return value;
|
||||
case VIA_ACR:
|
||||
return this->via_acr;
|
||||
case VIA_PCR:
|
||||
return this->via_pcr;
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
}
|
||||
|
||||
return (this->via_regs[reg & 0xF]);
|
||||
return 0; // should never happen!
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
write(value);
|
||||
this->last_orb = value & this->via_ddrb;
|
||||
this->via_portb = (this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
// ensure the proper VIA configuration before calling Cuda
|
||||
if ((this->via_ddrb & 0x38) == 0x30)
|
||||
this->write(this->via_portb);
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
this->via_porta = value;
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
this->via_ddrb = value;
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
this->via_ddra = value;
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
case VIA_T1CL:
|
||||
this->via_t1cl = value;
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_acr & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_t1cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
break;
|
||||
case VIA_T1LH:
|
||||
this->via_t1lh = value;
|
||||
break;
|
||||
case VIA_T2CL:
|
||||
this->via_t2cl = value;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_acr & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->via_sr = value;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_ACR:
|
||||
this->via_acr = value;
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
this->via_pcr = value;
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
break;
|
||||
case VIA_IFR:
|
||||
// for each "1" in value clear the corresponding flags
|
||||
this->_via_ifr &= ~value;
|
||||
@@ -198,68 +294,12 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
update_irq();
|
||||
print_enabled_ints();
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_regs[VIA_ACR] & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
this->t1_active = true;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_regs[VIA_ACR] & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
this->t2_active = true;
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last_time)
|
||||
{
|
||||
// calcualte current counter value based on elapsed time and timer frequency
|
||||
// calculate current counter value based on elapsed time and timer frequency
|
||||
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
|
||||
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
|
||||
return last_val - diff;
|
||||
@@ -287,20 +327,17 @@ void ViaCuda::update_irq()
|
||||
}
|
||||
|
||||
void ViaCuda::assert_sr_int() {
|
||||
this->sr_timer_on = false;
|
||||
this->_via_ifr |= VIA_IF_SR;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t1_int() {
|
||||
this->_via_ifr |= VIA_IF_T1;
|
||||
this->t1_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t2_int() {
|
||||
this->_via_ifr |= VIA_IF_T2;
|
||||
this->t2_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
@@ -333,21 +370,24 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
}
|
||||
|
||||
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
if (this->sr_timer_on) {
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
timeout_ns,
|
||||
[this]() { this->assert_sr_int(); });
|
||||
this->sr_timer_on = true;
|
||||
[this]() {
|
||||
this->sr_timer_id = 0;
|
||||
this->assert_sr_int();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
/* return if there is no state change */
|
||||
// return if there is no state change
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
@@ -356,7 +396,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
@@ -366,7 +406,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
});
|
||||
@@ -375,7 +415,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
@@ -384,9 +424,9 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->via_acr & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->in_count < sizeof(this->in_buf)) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
this->in_buf[this->in_count++] = this->via_sr;
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(71));
|
||||
} else {
|
||||
@@ -402,22 +442,22 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
this->via_sr = 0;
|
||||
}
|
||||
|
||||
/* sends PRAM content to host ad infinitum */
|
||||
void ViaCuda::pram_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
this->via_sr = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
}
|
||||
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
this->via_sr = this->out_buf[this->out_pos++];
|
||||
if (!this->is_open_ended && this->out_pos >= this->out_count) {
|
||||
// tell the host this will be the last byte
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
} else if (this->is_open_ended) {
|
||||
@@ -426,7 +466,7 @@ void ViaCuda::out_buf_handler() {
|
||||
(this->*out_handler)();
|
||||
} else {
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
@@ -473,7 +513,7 @@ void ViaCuda::process_packet() {
|
||||
for (int i = 0; i < this->in_count; i++) {
|
||||
LOG_F(9, "0x%X ,", this->in_buf[i]);
|
||||
}
|
||||
pseudo_command(this->in_buf[1], this->in_count - 2);
|
||||
pseudo_command();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d", this->in_buf[0]);
|
||||
@@ -495,10 +535,7 @@ void ViaCuda::process_adb_command() {
|
||||
}
|
||||
|
||||
void ViaCuda::autopoll_handler() {
|
||||
if (!this->autopoll_enabled)
|
||||
return;
|
||||
|
||||
uint8_t poll_command = this->adb_bus_obj->poll();
|
||||
uint8_t poll_command = this->autopoll_enabled ? this->adb_bus_obj->poll() : 0;
|
||||
|
||||
if (poll_command) {
|
||||
if (!this->old_tip || !this->treq) {
|
||||
@@ -515,17 +552,48 @@ void ViaCuda::autopoll_handler() {
|
||||
}
|
||||
|
||||
// assert TREQ
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ;
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
schedule_sr_int(USECS_TO_NSECS(30));
|
||||
} else if (this->one_sec_mode != 0) {
|
||||
uint32_t this_time = calc_real_time();
|
||||
if (this_time != this->last_time) {
|
||||
/*
|
||||
We'll send a time packet every 4
|
||||
seconds just in case we get out of
|
||||
sync.
|
||||
*/
|
||||
bool send_time = !(this->last_time & 3);
|
||||
if (send_time || this->one_sec_mode < 3) {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = CUDA_GET_REAL_TIME;
|
||||
if (send_time || this->one_sec_mode == 1) {
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
}
|
||||
} else if (this->one_sec_mode == 3) {
|
||||
response_header(CUDA_PKT_TICK, 0);
|
||||
this->out_count = 1;
|
||||
}
|
||||
this->last_time = this_time;
|
||||
|
||||
// assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
schedule_sr_int(USECS_TO_NSECS(30));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
void ViaCuda::pseudo_command() {
|
||||
uint16_t addr;
|
||||
int i;
|
||||
int cmd = this->in_buf[1];
|
||||
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
@@ -556,13 +624,14 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
case CUDA_GET_REAL_TIME:
|
||||
case CUDA_GET_REAL_TIME: {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->real_time >> 24) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->real_time >> 16) & 0xFF);
|
||||
this->out_buf[4] = (uint8_t)((this->real_time >> 8) & 0xFF);
|
||||
this->out_buf[5] = (uint8_t)((this->real_time) & 0xFF);
|
||||
uint32_t this_time = this->calc_real_time();
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
break;
|
||||
}
|
||||
case CUDA_WRITE_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
// if addr is inside PRAM, update PRAM with data from in_buf
|
||||
@@ -587,13 +656,13 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_REAL_TIME:
|
||||
case CUDA_SET_REAL_TIME: {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->real_time = ((uint32_t)in_buf[2]) >> 24;
|
||||
this->real_time += ((uint32_t)in_buf[3]) >> 16;
|
||||
this->real_time += ((uint32_t)in_buf[4]) >> 8;
|
||||
this->real_time += ((uint32_t)in_buf[5]);
|
||||
uint32_t real_time = this->calc_real_time();
|
||||
uint32_t new_time = READ_DWORD_BE_U(&in_buf[2]);
|
||||
this->time_offset = new_time - real_time;
|
||||
break;
|
||||
}
|
||||
case CUDA_WRITE_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
@@ -637,7 +706,11 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
|
||||
break;
|
||||
case CUDA_ONE_SECOND_MODE:
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt - Byte Sent: %d", this->in_buf[2]);
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt Mode: %d", this->in_buf[2]);
|
||||
this->one_sec_mode = this->in_buf[2];
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
@@ -660,8 +733,12 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
power_on = false;
|
||||
power_off_reason = po_restart;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
LOG_F(INFO, "Cuda: system shutdown");
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
|
||||
@@ -673,9 +750,16 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ViaCuda::calc_real_time() {
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed_systemclock = end - this->mac_epoch;
|
||||
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
|
||||
return uint32_t(elapsed_seconds.count());
|
||||
}
|
||||
|
||||
/* sends data from the current I2C to host ad infinitum */
|
||||
void ViaCuda::i2c_handler() {
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_regs[VIA_SR]);
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_sr);
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes) {
|
||||
|
||||
+70
-56
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -48,6 +48,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
class AdbBus;
|
||||
class InterruptCtrl;
|
||||
@@ -56,22 +57,22 @@ class InterruptCtrl;
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
VIA_B = 0x00, /* input/output register B */
|
||||
VIA_A = 0x01, /* input/output register A */
|
||||
VIA_DIRB = 0x02, /* direction B */
|
||||
VIA_DIRA = 0x03, /* direction A */
|
||||
VIA_T1CL = 0x04, /* low-order timer 1 counter */
|
||||
VIA_T1CH = 0x05, /* high-order timer 1 counter */
|
||||
VIA_T1LL = 0x06, /* low-order timer 1 latches */
|
||||
VIA_T1LH = 0x07, /* high-order timer 1 latches */
|
||||
VIA_T2CL = 0x08, /* low-order timer 2 latches */
|
||||
VIA_T2CH = 0x09, /* high-order timer 2 counter */
|
||||
VIA_SR = 0x0A, /* shift register */
|
||||
VIA_ACR = 0x0B, /* auxiliary control register */
|
||||
VIA_PCR = 0x0C, /* periheral control register */
|
||||
VIA_IFR = 0x0D, /* interrupt flag register */
|
||||
VIA_IER = 0x0E, /* interrupt enable register */
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
VIA_B = 0x00, // input/output register B
|
||||
VIA_A = 0x01, // input/output register A
|
||||
VIA_DIRB = 0x02, // direction B
|
||||
VIA_DIRA = 0x03, // direction A
|
||||
VIA_T1CL = 0x04, // low-order timer 1 counter
|
||||
VIA_T1CH = 0x05, // high-order timer 1 counter
|
||||
VIA_T1LL = 0x06, // low-order timer 1 latches
|
||||
VIA_T1LH = 0x07, // high-order timer 1 latches
|
||||
VIA_T2CL = 0x08, // low-order timer 2 latches
|
||||
VIA_T2CH = 0x09, // high-order timer 2 counter
|
||||
VIA_SR = 0x0A, // shift register
|
||||
VIA_ACR = 0x0B, // auxiliary control register
|
||||
VIA_PCR = 0x0C, // periheral control register
|
||||
VIA_IFR = 0x0D, // interrupt flag register
|
||||
VIA_IER = 0x0E, // interrupt enable register
|
||||
VIA_ANH = 0x0F, // input/output register A, no handshake
|
||||
};
|
||||
|
||||
/** VIA interrupt flags */
|
||||
@@ -92,11 +93,11 @@ enum class ViaLine {
|
||||
CB2
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
CUDA_BYTEACK = 0x10, /* byte acknowledge: 0 - true, 1 - false */
|
||||
CUDA_TREQ = 0x08 /* Cuda requests transaction from host */
|
||||
CUDA_TIP = 0x20, // transaction in progress
|
||||
CUDA_BYTEACK = 0x10, // byte acknowledge/handshake
|
||||
CUDA_TREQ = 0x08 // Cuda requests transaction from host
|
||||
};
|
||||
|
||||
/** Cuda packet types. */
|
||||
@@ -110,40 +111,41 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
CUDA_WARM_START = 0x00, // warm start
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, // start/stop device auto-polling
|
||||
CUDA_READ_MCU_MEM = 0x02, // read internal Cuda memory
|
||||
CUDA_GET_REAL_TIME = 0x03, // get real time
|
||||
CUDA_READ_PRAM = 0x07, // read parameter RAM
|
||||
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
|
||||
CUDA_SET_REAL_TIME = 0x09, // set real time
|
||||
CUDA_POWER_DOWN = 0x0A, // power down system
|
||||
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
|
||||
CUDA_RESTART_SYSTEM = 0x11, // restart system
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
|
||||
CUDA_SET_DEVICE_LIST = 0x19, // set device list
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
|
||||
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
|
||||
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
|
||||
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
|
||||
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
|
||||
};
|
||||
|
||||
/** Cuda error codes. */
|
||||
enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
CUDA_ERR_BAD_PKT = 1, // invalid packet type
|
||||
CUDA_ERR_BAD_CMD = 2, // invalid pseudo command
|
||||
CUDA_ERR_BAD_SIZE = 3, // invalid packet size
|
||||
CUDA_ERR_BAD_PAR = 4, // invalid parameter
|
||||
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
|
||||
};
|
||||
|
||||
#define CUDA_IN_BUF_SIZE 256
|
||||
|
||||
/** PRAM addresses within Cuda's internal memory */
|
||||
/** PRAM addresses within Cuda's internal memory. */
|
||||
#define CUDA_PRAM_START 0x100 // starting address of PRAM
|
||||
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
|
||||
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
|
||||
@@ -175,22 +177,30 @@ public:
|
||||
|
||||
private:
|
||||
// VIA virtual HW registers
|
||||
uint8_t via_regs[16];
|
||||
uint8_t via_portb = 0;
|
||||
uint8_t via_porta = 0;
|
||||
uint8_t via_ddrb = 0;
|
||||
uint8_t via_ddra = 0;
|
||||
uint8_t via_t1cl = 0xFF;
|
||||
uint8_t via_t1ll = 0xFF;
|
||||
uint8_t via_t1lh = 0xFF;
|
||||
uint8_t via_t2cl = 0xFF;
|
||||
uint8_t via_sr;
|
||||
uint8_t via_acr = 0;
|
||||
uint8_t via_pcr = 0;
|
||||
|
||||
float via_clk_dur; // one VIA clock duration = 1,27655 us
|
||||
|
||||
// VIA internal state
|
||||
uint32_t sr_timer_id = 0;
|
||||
bool sr_timer_on = false;
|
||||
uint8_t last_orb = 0; // last value written to the ORB register.
|
||||
|
||||
// timer 1 state
|
||||
bool t1_active;
|
||||
uint16_t t1_counter;
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
bool t2_active;
|
||||
uint16_t t2_counter;
|
||||
uint32_t t2_timer_id = 0;
|
||||
uint64_t t2_start_time = 0;
|
||||
@@ -213,7 +223,10 @@ private:
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
uint8_t poll_rate;
|
||||
int32_t real_time = 0;
|
||||
uint32_t last_time = 0;
|
||||
uint32_t time_offset = 0;
|
||||
std::chrono::time_point<std::chrono::system_clock> mac_epoch;
|
||||
uint8_t one_sec_mode = 0;
|
||||
bool file_server;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
@@ -246,7 +259,8 @@ private:
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command();
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
void pseudo_command();
|
||||
uint32_t calc_real_time();
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
@@ -257,8 +271,8 @@ private:
|
||||
|
||||
/* I2C related methods */
|
||||
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(
|
||||
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1,
|
||||
const uint8_t* in_buf, int in_bytes);
|
||||
};
|
||||
|
||||
#endif /* VIACUDA_H */
|
||||
#endif // VIACUDA_H
|
||||
+65
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,11 +32,24 @@ using namespace MaceEnet;
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
return this->rcv_fc;
|
||||
case MaceReg::Interrupt: {
|
||||
uint8_t ret_val = this->int_stat;
|
||||
this->int_stat = 0;
|
||||
LOG_F(9, "%s: all interrupt flags cleared", this->name.c_str());
|
||||
return ret_val;
|
||||
}
|
||||
case MaceReg::Interrupt_Mask:
|
||||
return this->int_mask;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
return this->biu_ctrl;
|
||||
case MaceReg::Chip_ID_Lo:
|
||||
return this->chip_id & 0xFFU;
|
||||
case MaceReg::Chip_ID_Hi:
|
||||
return (this->chip_id >> 8) & 0xFFU;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -45,15 +58,57 @@ uint8_t MaceController::read(uint8_t reg_offset)
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
this->rcv_fc = value;
|
||||
break;
|
||||
case MaceReg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
this->mac_cfg = value;
|
||||
break;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "MACE Reset issued");
|
||||
} else {
|
||||
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
|
||||
if (value & BIU_SWRST) {
|
||||
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
|
||||
value &= ~BIU_SWRST; // acknowledge soft reset
|
||||
}
|
||||
this->biu_ctrl = value;
|
||||
break;
|
||||
case MaceReg::PLS_Config_Ctrl:
|
||||
if (value != 7)
|
||||
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
|
||||
this->name.c_str(), value);
|
||||
break;
|
||||
case MaceReg::Int_Addr_Config:
|
||||
if ((value & IAC_LOGADDR) && (value & IAC_PHYADDR))
|
||||
value &= ~IAC_PHYADDR;
|
||||
if (value & (IAC_LOGADDR | IAC_PHYADDR))
|
||||
this->addr_ptr = 0;
|
||||
this->addr_cfg = value;
|
||||
break;
|
||||
case MaceReg::Log_Addr_Flt:
|
||||
if (this->addr_cfg & IAC_LOGADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->log_addr = (this->log_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 8) {
|
||||
this->addr_cfg &= ~IAC_LOGADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MaceReg::Phys_Addr:
|
||||
if (this->addr_cfg & IAC_PHYADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->phys_addr = (this->phys_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 6) {
|
||||
this->addr_cfg &= ~IAC_PHYADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
LOG_F(INFO, "%s: writing 0x%X to register %d", this->name.c_str(),
|
||||
value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+64
-37
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,58 +24,74 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
/** Known MACE chip IDs. */
|
||||
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
|
||||
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
|
||||
|
||||
// MACE registers offsets
|
||||
/** MACE registers offsets. */
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
namespace MaceEnet {
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 10,
|
||||
BIU_Config_Ctrl = 11,
|
||||
FIFO_Config = 12,
|
||||
MAC_Config_Ctrl = 13,
|
||||
PLS_Config_Ctrl = 14,
|
||||
PHY_Config_Ctrl = 15,
|
||||
Chip_ID_Lo = 16,
|
||||
Chip_ID_Hi = 17,
|
||||
Int_Addr_Config = 18,
|
||||
Log_Addr_Flt = 20,
|
||||
Phys_Addr = 21,
|
||||
Missed_Pkt_Cnt = 24,
|
||||
Runt_Pkt_Cnt = 26, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 27, // not used in Macintosh?
|
||||
User_Test = 29,
|
||||
Rsrvd_Test_1 = 30, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 31, // not used in Macintosh?
|
||||
};
|
||||
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 0x0A,
|
||||
BIU_Config_Ctrl = 0x0B,
|
||||
FIFO_Config = 0x0C,
|
||||
MAC_Config_Ctrl = 0x0D,
|
||||
PLS_Config_Ctrl = 0x0E,
|
||||
PHY_Config_Ctrl = 0x0F,
|
||||
Chip_ID_Lo = 0x10,
|
||||
Chip_ID_Hi = 0x11,
|
||||
Addr_Config = 0x12,
|
||||
Log_Addr_Flt = 0x14,
|
||||
Phys_Addr = 0x15,
|
||||
Missed_Pkt_Cnt = 0x18,
|
||||
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
|
||||
User_Test = 0x1D,
|
||||
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
/** Bit definitions for BIU_Config_Ctrl register. */
|
||||
enum {
|
||||
BIU_SWRST = 1 << 0,
|
||||
};
|
||||
|
||||
/** Bit definitions for the internal configuration register. */
|
||||
enum {
|
||||
IAC_LOGADDR = 1 << 1,
|
||||
IAC_PHYADDR = 1 << 2,
|
||||
IAC_ADDRCHG = 1 << 7
|
||||
};
|
||||
|
||||
}; // namespace MaceEnet
|
||||
|
||||
class MaceController : public HWComponent {
|
||||
class MaceController : public DmaDevice, public HWComponent {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
MaceController(uint16_t id) {
|
||||
this->chip_id = id;
|
||||
this->set_name("MACE");
|
||||
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
|
||||
};
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID_REV_A2));
|
||||
}
|
||||
|
||||
// MACE registers access
|
||||
@@ -84,6 +100,17 @@ public:
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
uint8_t addr_cfg = 0;
|
||||
uint8_t addr_ptr = 0;
|
||||
uint8_t rcv_fc = 1;
|
||||
uint8_t biu_ctrl = 0;
|
||||
uint8_t mac_cfg = 0;
|
||||
uint64_t phys_addr = 0;
|
||||
uint64_t log_addr = 0;
|
||||
|
||||
// interrupt stuff
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t int_mask = 0;
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -311,7 +311,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
if (fconv && fconv->calc_phys_params()) {
|
||||
delete fconv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
MacSuperDrive::MacSuperDrive()
|
||||
MacSuperDrive::MacSuperDrive(std::string name)
|
||||
{
|
||||
this->name = "Superdrive";
|
||||
this->set_name(name);
|
||||
this->supported_types = HWCompType::FLOPPY_DRV;
|
||||
|
||||
this->eject_latch = 0; // eject latch is off
|
||||
@@ -57,7 +57,7 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
{
|
||||
uint8_t new_motor_stat;
|
||||
|
||||
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
|
||||
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
|
||||
|
||||
switch(addr) {
|
||||
case CommandAddr::Step_Direction:
|
||||
@@ -81,17 +81,17 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
this->sector_start_time = 0;
|
||||
this->init_track_search(-1);
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
|
||||
} else {
|
||||
this->motor_on_time = 0;
|
||||
this->is_ready = 0;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Eject_Disk:
|
||||
if (value) {
|
||||
LOG_F(INFO, "Superdrive: disk ejected");
|
||||
LOG_F(INFO, "%s: disk ejected", this->get_name().c_str());
|
||||
this->eject_latch = 1;
|
||||
this->reset_params();
|
||||
}
|
||||
@@ -107,13 +107,13 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented command, addr=0x%X", addr);
|
||||
LOG_F(WARNING, "%s: unimplemented command, addr=0x%X", this->get_name().c_str(), addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
{
|
||||
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
|
||||
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
|
||||
|
||||
switch(addr) {
|
||||
case StatusAddr::Step_Status:
|
||||
@@ -145,7 +145,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
case StatusAddr::Media_Kind:
|
||||
return this->media_kind ^ 1; // reverse logic!
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented status request, addr=0x%X", addr);
|
||||
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
int MacSuperDrive::insert_disk(std::string& img_path, int write_flag = 0)
|
||||
{
|
||||
if (this->has_disk) {
|
||||
LOG_F(ERROR, "Superdrive: drive is not empty!");
|
||||
LOG_F(ERROR, "%s: drive is not empty!", this->get_name().c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ void MacSuperDrive::init_track_search(int pos)
|
||||
// pick random sector number
|
||||
uint64_t seed = TimerManager::get_instance()->current_time_ns() >> 8;
|
||||
this->cur_sector = seed % this->sectors_per_track[this->cur_track];
|
||||
LOG_F(9, "Superdrive: current sector number set to %d", this->cur_sector);
|
||||
LOG_F(9, "%s: current sector number set to %d", this->get_name().c_str(), this->cur_sector);
|
||||
} else {
|
||||
this->cur_sector = pos;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ typedef struct SectorHdr {
|
||||
|
||||
class MacSuperDrive : public HWComponent {
|
||||
public:
|
||||
MacSuperDrive();
|
||||
MacSuperDrive(std::string name);
|
||||
~MacSuperDrive() = default;
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
|
||||
@@ -57,7 +57,7 @@ Swim3Ctrl::Swim3Ctrl()
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
|
||||
}
|
||||
|
||||
int Swim3Ctrl::device_postinit()
|
||||
@@ -410,7 +410,7 @@ static const PropMap Swim3_Properties = {
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new BinProperty(0)},
|
||||
new BinProperty(1)},
|
||||
{"fdd_fmt",
|
||||
new StrProperty("", FloppyFormats)},
|
||||
};
|
||||
|
||||
@@ -219,8 +219,10 @@ enum AMICReg : uint32_t {
|
||||
Ariel_Config = 0x24002,
|
||||
|
||||
// VIA2 registers
|
||||
// = 0x26000,
|
||||
VIA2_Slot_IFR = 0x26002,
|
||||
VIA2_IFR = 0x26003,
|
||||
// = 0x26010,
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_IER = 0x26013,
|
||||
VIA2_IFR_RBV = 0x27A03, // RBV-compatible mirror for the VIA2_IFR
|
||||
@@ -266,8 +268,12 @@ enum AMICReg : uint32_t {
|
||||
Floppy_DMA_Ctrl = 0x32068,
|
||||
|
||||
SCC_DMA_Xmt_A_Ctrl = 0x32088,
|
||||
SCC_RXA_Byte_Cnt_Hi = 0x32094, // 5 bits, read-only
|
||||
SCC_RXA_Byte_Cnt_Lo = 0x32095, // 8 bits, read-only
|
||||
SCC_DMA_Rcv_A_Ctrl = 0x32098,
|
||||
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
|
||||
SCC_RXB_Byte_Cnt_Hi = 0x320B4, // 5 bits, read-only
|
||||
SCC_RXB_Byte_Cnt_Lo = 0x320B5, // 8 bits, read-only
|
||||
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
|
||||
};
|
||||
|
||||
|
||||
@@ -93,17 +93,32 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
this->escc_a_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_tx"));
|
||||
this->escc_a_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_rx"));
|
||||
this->escc_b_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_tx"));
|
||||
this->escc_b_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_rx"));
|
||||
this->escc_a_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Tx));
|
||||
this->escc_a_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Rx));
|
||||
this->escc_b_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Tx));
|
||||
this->escc_b_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Rx));
|
||||
this->escc->set_dma_channel(0, this->escc_a_tx_dma.get());
|
||||
this->escc->set_dma_channel(1, this->escc_a_rx_dma.get());
|
||||
this->escc->set_dma_channel(2, this->escc_b_tx_dma.get());
|
||||
this->escc->set_dma_channel(3, this->escc_b_rx_dma.get());
|
||||
|
||||
// connect MESH (internal SCSI)
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshTnt"));
|
||||
this->mesh = dynamic_cast<MeshBase*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
|
||||
if (this->mesh == nullptr) {
|
||||
LOG_F(WARNING, "%s: Mesh not found, using MeshStub instead", this->name.c_str());
|
||||
this->mesh_stub = std::unique_ptr<MeshStub>(new MeshStub());
|
||||
this->mesh = dynamic_cast<MeshController*>(this->mesh_stub.get());
|
||||
this->mesh = dynamic_cast<MeshBase*>(this->mesh_stub.get());
|
||||
} else {
|
||||
MeshController *mesh_obj =
|
||||
dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
|
||||
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh_scsi"));
|
||||
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
|
||||
this->mesh->set_dma_channel(this->mesh_dma.get());
|
||||
this->mesh_dma->connect(mesh_obj);
|
||||
mesh_obj->connect(this->mesh_dma.get());
|
||||
}
|
||||
|
||||
// connect external SCSI controller (Curio) to its DMA channel
|
||||
@@ -114,6 +129,13 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
|
||||
// connect Ethernet HW
|
||||
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
|
||||
this->enet_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_tx"));
|
||||
this->enet_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Tx));
|
||||
this->enet_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_rx"));
|
||||
this->enet_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Rx));
|
||||
this->enet_tx_dma->connect(this->mace);
|
||||
this->enet_rx_dma->connect(this->mace);
|
||||
this->mace->connect(this->enet_rx_dma.get());
|
||||
|
||||
// connect floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
@@ -206,13 +228,29 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
return this->curio_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_FLOPPY:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ETH_XMIT:
|
||||
return this->enet_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ETH_RCV:
|
||||
return this->enet_rx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
return this->escc_a_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
return this->escc_a_rx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_B_XMIT:
|
||||
return this->escc_b_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_B_RCV:
|
||||
return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_AUDIO_OUT:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_AUDIO_IN:
|
||||
//LOG_F(WARNING, "%s: Unsupported DMA channel MIO_GC_DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
|
||||
//LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
|
||||
return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_SCSI_MESH:
|
||||
return this->mesh_dma->reg_read(offset & 0xFF, size);
|
||||
if (this->mesh_dma) {
|
||||
return this->mesh_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
|
||||
this->name.c_str(), this->base_addr + offset);
|
||||
@@ -285,7 +323,9 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
default: val = 0; break;
|
||||
}
|
||||
if (offset & 15) {
|
||||
LOG_F(ERROR, "%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d", this->name.c_str(), offset, size, value, subdev_num - 9);
|
||||
LOG_F(ERROR,
|
||||
"%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d",
|
||||
this->name.c_str(), offset, size, value, subdev_num - 9);
|
||||
}
|
||||
if (this->iobus_devs[subdev_num - 10] != nullptr) {
|
||||
this->iobus_devs[subdev_num - 10]->iodev_write((offset >> 4) & 0x1F, val);
|
||||
@@ -308,16 +348,38 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
case MIO_GC_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ETH_XMIT:
|
||||
this->enet_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ETH_RCV:
|
||||
this->enet_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
this->escc_a_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_B_XMIT:
|
||||
this->escc_b_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_B_RCV:
|
||||
this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_AUDIO_IN:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel MIO_GC_DMA_AUDIO_IN write @%02x.%c = %0*x", this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN write @%02x.%c = %0*x",
|
||||
this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
//this->snd_in_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_SCSI_MESH:
|
||||
this->mesh_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
if (this->mesh_dma) {
|
||||
this->mesh_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented DMA register at 0x%X",
|
||||
this->name.c_str(), this->base_addr + offset);
|
||||
@@ -414,6 +476,12 @@ uint32_t GrandCentral::register_dma_int(IntSrc src_id) {
|
||||
void GrandCentral::ack_int_common(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events1 on all transitions
|
||||
//#if 1
|
||||
// if (irq_id & ~(INT_TO_IRQ_ID(0x12) | INT_TO_IRQ_ID(0x1A)))
|
||||
// LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
|
||||
// this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
|
||||
// );
|
||||
//#endif
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= irq_id;
|
||||
|
||||
@@ -341,7 +341,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
case MIO_AUX_CTRL:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register", value);
|
||||
this->aux_ctrl = value;
|
||||
break;
|
||||
@@ -443,7 +443,9 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
if (!IS_INT1(irq_id)) { // does this irq_id belong to the second set?
|
||||
IRQ_ID_TO_INT2_MASK(irq_id);
|
||||
#if 0
|
||||
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d", this->name.c_str(), this->int_events1, this->int_events2, this->int_levels1, this->int_levels2, irq_id, irq_line_state);
|
||||
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d",
|
||||
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state
|
||||
);
|
||||
#endif
|
||||
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events2 on all transitions
|
||||
@@ -465,7 +467,8 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events1 on all transitions
|
||||
#if 0
|
||||
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d", this->name.c_str(), this->int_events1, this->int_events2, this->int_levels1, this->int_levels2, irq_id, irq_line_state);
|
||||
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d",
|
||||
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state);
|
||||
#endif
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels1 & irq_id))) {
|
||||
|
||||
+69
-12
@@ -162,8 +162,8 @@ private:
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
uint32_t int_levels = 0;
|
||||
uint32_t int_events = 0;
|
||||
std::atomic<uint32_t> int_levels{0};
|
||||
std::atomic<uint32_t> int_events{0};
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
// IOBus devices
|
||||
@@ -175,18 +175,27 @@ private:
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
std::unique_ptr<MeshStub> mesh_stub = nullptr;
|
||||
|
||||
MaceController* mace;
|
||||
MaceController* mace; // Ethernet cell within Curio
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
EsccController* escc; // ESCC serial controller
|
||||
MeshController* mesh; // internal SCSI (fast)
|
||||
EsccController* escc; // ESCC serial controller cell within Curio
|
||||
MeshBase* mesh; // internal SCSI (fast)
|
||||
Sc53C94* curio; // external SCSI (slow)
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> curio_dma;
|
||||
std::unique_ptr<DMAChannel> mesh_dma;
|
||||
std::unique_ptr<DMAChannel> mesh_dma = nullptr;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_in_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> enet_tx_dma;
|
||||
std::unique_ptr<DMAChannel> enet_rx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_tx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_rx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_tx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_rx_dma;
|
||||
|
||||
uint16_t unsupported_dma_channel_read = 0;
|
||||
uint16_t unsupported_dma_channel_write = 0;
|
||||
};
|
||||
|
||||
class OHare : public PCIDevice, public InterruptCtrl {
|
||||
@@ -223,8 +232,8 @@ private:
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
uint32_t int_levels = 0;
|
||||
uint32_t int_events = 0;
|
||||
std::atomic<uint32_t> int_levels{0};
|
||||
std::atomic<uint32_t> int_events{0};
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
@@ -263,6 +272,54 @@ private:
|
||||
enum {
|
||||
MIO_OHARE_ID = 0x34, // IDs register
|
||||
MIO_OHARE_FEAT_CTRL = 0x38, // feature control register
|
||||
MIO_AUX_CTRL = 0x3C,
|
||||
};
|
||||
|
||||
/** MIO_OHARE_ID bits. */
|
||||
enum {
|
||||
MIO_OH_ID_FP = 0x70000000, // Flat panel ID
|
||||
MIO_OH_ID_MON = 0x00300000, // Monitor ID (mon_id?=1, no s-video/composite=3 but only if fatman exists).
|
||||
MIO_OH_ID_MB = 0x0000F000, // Media Bay ID (0,1=swim, 3=ata, 5=pci, 7=?)
|
||||
MIO_OH_ID_CPU = 0x000000E0, // CPUID field
|
||||
MIO_OH_ID_DISABLE_SCSI_TERMINATORS = 0x00000010, // clear this bit to disable-scsi-terminators - read this bit for emmo_pin
|
||||
MIO_OH_ID_ENABLE_SCSI_TERMINATORS = 0x00000008, // set this bit to enable-scsi-terminators
|
||||
MIO_OH_ID_DO_SCSI_TERMINATORS = 0x00000001, // set this bit to enable or disable scsi-terminators
|
||||
};
|
||||
|
||||
/** MIO_OHARE_FEAT_CTRL bits. */
|
||||
enum {
|
||||
MIO_OH_FC_IN_USE_LED = 1 << 0,
|
||||
MIO_OH_FC_NOT_MB_PWR = 1 << 1,
|
||||
MIO_OH_FC_PCI_MB_EN = 1 << 2,
|
||||
MIO_OH_FC_IDE_MB_EN = 1 << 3,
|
||||
MIO_OH_FC_FLOPPY_EN = 1 << 4,
|
||||
MIO_OH_FC_IDE_INT_EN = 1 << 5,
|
||||
MIO_OH_FC_NOT_IDE0_RESET = 1 << 6,
|
||||
MIO_OH_FC_NOT_MB_RESET = 1 << 7,
|
||||
MIO_OH_FC_IOBUS_EN = 1 << 8,
|
||||
MIO_OH_FC_SCC_CELL_EN = 1 << 9,
|
||||
MIO_OH_FC_SCSI_CELL_EN = 1 << 10,
|
||||
MIO_OH_FC_SWIM_CELL_EN = 1 << 11,
|
||||
MIO_OH_FC_SND_PWR = 1 << 12,
|
||||
MIO_OH_FC_SND_CLK_EN = 1 << 13,
|
||||
MIO_OH_FC_SCC_A_ENABLE = 1 << 14,
|
||||
MIO_OH_FC_SCC_B_ENABLE = 1 << 15,
|
||||
MIO_OH_FC_NOT_PORT_VIA_DESKTOP_VIA = 1 << 16,
|
||||
MIO_OH_FC_NOT_PWM_MON_ID = 1 << 17,
|
||||
MIO_OH_FC_NOT_HOOKPB_MB_CNT = 1 << 18,
|
||||
MIO_OH_FC_NOT_SWIM3_CLONEFLOPPY = 1 << 19,
|
||||
MIO_OH_FC_AUD22RUN = 1 << 20,
|
||||
MIO_OH_FC_SCSI_LINKMODE = 1 << 21,
|
||||
MIO_OH_FC_ARB_BYPASS = 1 << 22,
|
||||
MIO_OH_FC_NOT_IDE1_RESET = 1 << 23,
|
||||
MIO_OH_FC_SLOW_SCC_PCLK = 1 << 24,
|
||||
MIO_OH_FC_RESET_SCC = 1 << 25,
|
||||
MIO_OH_FC_MFDC_CELL_EN = 1 << 26,
|
||||
MIO_OH_FC_USE_MFDC = 1 << 27,
|
||||
MIO_OH_FC_RESVD28 = 1 << 28,
|
||||
MIO_OH_FC_RESVD29 = 1 << 29,
|
||||
MIO_OH_FC_RESVD30 = 1 << 30,
|
||||
MIO_OH_FC_RESVD31 = 1 << 31,
|
||||
};
|
||||
|
||||
/** O'Hare/Heathrow DBDMA channels. */
|
||||
@@ -316,12 +373,12 @@ protected:
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
uint32_t int_events2 = 0;
|
||||
std::atomic<uint32_t> int_events2{0};
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
uint32_t int_events1 = 0;
|
||||
std::atomic<uint32_t> int_levels2{0};
|
||||
std::atomic<uint32_t> int_events1{0};
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
std::atomic<uint32_t> int_levels1{0};
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
@@ -234,7 +234,9 @@ void OHare::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events1 on all transitions
|
||||
#if 1
|
||||
LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d", this->name.c_str(), this->int_mask, this->int_events, this->int_levels, irq_id, irq_line_state);
|
||||
LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
|
||||
this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
|
||||
);
|
||||
#endif
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
@@ -295,7 +297,7 @@ void OHare::clear_cpu_int()
|
||||
}
|
||||
|
||||
static const vector<string> OHare_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "ScsiMesh", "Mesh", "Escc", "Swim3"
|
||||
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription OHare_Descriptor = {
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Aspen Memory Controller emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/aspen.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AspenCtrl::AspenCtrl() : MemCtrlBase() {
|
||||
this->name = "Aspen";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
// add MMIO region for the configuration and status registers
|
||||
add_mmio_region(0xF8000000, 0x800, this);
|
||||
}
|
||||
|
||||
int AspenCtrl::device_postinit() {
|
||||
return this->map_phys_ram();
|
||||
}
|
||||
|
||||
void AspenCtrl::insert_ram_dimm(int bank_num, uint32_t capacity) {
|
||||
if (bank_num < 0 || bank_num > 3)
|
||||
return;
|
||||
|
||||
uint32_t bank_size = capacity << 20; // convert to MB
|
||||
|
||||
switch(bank_size) {
|
||||
case DRAM_CAP_1MB:
|
||||
case DRAM_CAP_4MB:
|
||||
case DRAM_CAP_8MB:
|
||||
case DRAM_CAP_16MB:
|
||||
bank_sizes[bank_num] = bank_size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t AspenCtrl::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint8_t reg_num = (offset >> 2) & 0x1F;
|
||||
uint32_t reg_val;
|
||||
|
||||
switch(reg_num) {
|
||||
case SYSTEM_ID:
|
||||
reg_val = 0x40010000;
|
||||
break;
|
||||
case CHIP_REV:
|
||||
reg_val = ASPEN_REV_1;
|
||||
break;
|
||||
case GPIO_IN:
|
||||
case GPIO_OUT:
|
||||
reg_val = 0;
|
||||
break;
|
||||
case GPIO_ENABLE:
|
||||
reg_val = this->gpio_enable << 24;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: reading from register at 0x%X", this->name.c_str(), offset);
|
||||
reg_val = 0;
|
||||
}
|
||||
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
void AspenCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
uint8_t reg_num = (offset >> 2) & 0x1F;
|
||||
|
||||
switch(reg_num) {
|
||||
case SYSTEM_ID:
|
||||
break; // ignore writes to this read-only register
|
||||
case MEM_CONFIG:
|
||||
if (this->ram_config != value >> 24) {
|
||||
this->ram_config = value >> 24;
|
||||
LOG_F(INFO, "%s: RAM config changed to 0x%X", this->name.c_str(),
|
||||
this->ram_config);
|
||||
}
|
||||
break;
|
||||
case GPIO_ENABLE:
|
||||
this->gpio_enable = value >> 24;
|
||||
break;
|
||||
case GPIO_OUT:
|
||||
LOG_F(INFO, "%s: output 0x%X to GPIO pins", this->name.c_str(), value >> 24);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown register write at offset 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
}
|
||||
}
|
||||
|
||||
int AspenCtrl::map_phys_ram() {
|
||||
uint32_t total_ram = 0, row_mask, col_mask, offset;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
total_ram += this->bank_sizes[i];
|
||||
|
||||
LOG_F(INFO, "%s: total RAM size = %d bytes", this->name.c_str(), total_ram);
|
||||
|
||||
uint32_t addr = 0;
|
||||
|
||||
for (int i = 0; i < 4; addr += DRAM_CAP_16MB, i++) {
|
||||
if (!this->bank_sizes[i])
|
||||
continue;
|
||||
if (!add_ram_region(addr, this->bank_sizes[i])) {
|
||||
LOG_F(ERROR, "%s: could not allocate RAM at 0x%X", this->name.c_str(), addr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(this->bank_sizes[i]) {
|
||||
case DRAM_CAP_1MB:
|
||||
row_mask = (1 << 9) - 1;
|
||||
col_mask = (1 << 9) - 1;
|
||||
break;
|
||||
case DRAM_CAP_4MB:
|
||||
row_mask = (1 << 10) - 1;
|
||||
col_mask = (1 << 10) - 1;
|
||||
break;
|
||||
case DRAM_CAP_8MB:
|
||||
row_mask = (1 << 11) - 1;
|
||||
col_mask = (1 << 10) - 1;
|
||||
break;
|
||||
default: // DRAM_CAP_16MB
|
||||
row_mask = (1 << 11) - 1;
|
||||
col_mask = (1 << 11) - 1;
|
||||
}
|
||||
|
||||
offset = ((0xC01000 >> 13) & row_mask) | ((0xC01000 >> 2) & col_mask);
|
||||
|
||||
if (!this->add_mem_mirror_partial(addr + 0xC01000, addr + offset, offset, 0x1000)) {
|
||||
LOG_F(ERROR, "%s: could not create alias for RAM bank %d",
|
||||
this->name.c_str(), i);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->bank_sizes[i] < DRAM_CAP_16MB) {
|
||||
if (!this->add_mem_mirror_partial(addr + 0xC00000, addr + offset, offset, 0x1000)) {
|
||||
LOG_F(ERROR, "%s: could not create alias for RAM bank %d",
|
||||
this->name.c_str(), i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->bank_sizes[i] < DRAM_CAP_8MB) {
|
||||
if (!this->add_mem_mirror_partial(addr + 0x400000, addr + offset, offset, 0x1000)) {
|
||||
LOG_F(ERROR, "%s: could not create alias for RAM bank %d",
|
||||
this->name.c_str(), i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const DeviceDescription Aspen_Descriptor = {
|
||||
AspenCtrl::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Aspen, Aspen_Descriptor);
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Aspem Memory Controller definitions.
|
||||
|
||||
Aspen is a custom memory controller and PCI bridge
|
||||
designed especially for Pippin.
|
||||
|
||||
Kudos to Keith Kaisershot @ blitter.net for his precious technical help!
|
||||
*/
|
||||
|
||||
#ifndef ASPEN_MEMCTRL_H
|
||||
#define ASPEN_MEMCTRL_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Aspen register definitions. */
|
||||
enum {
|
||||
SYSTEM_ID = 4, // 0x10
|
||||
CHIP_REV = 5, // 0x14
|
||||
MEM_CONFIG = 6, // 0x18
|
||||
GPIO_IN = 12, // 0x30
|
||||
GPIO_ENABLE = 13, // 0x34
|
||||
GPIO_OUT = 14, // 0x38
|
||||
};
|
||||
|
||||
#define ASPEN_REV_1 0x01000000
|
||||
|
||||
/** Aspen RAM bank size bits. */
|
||||
enum {
|
||||
BANK_SIZE_1MB = 0, // 256Kx16, 9 rows x 9 columns
|
||||
BANK_SIZE_4MB = 1, // 1Mx16, 10 rows x 10 columns
|
||||
BANK_SIZE_16MB = 2, // 4Mx16, 11 rows x 11 columns
|
||||
BANK_SIZE_8MB = 3, // 2Mx16, 11 rows x 10 columns
|
||||
};
|
||||
|
||||
class AspenCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
AspenCtrl();
|
||||
~AspenCtrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AspenCtrl>(new AspenCtrl());
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void insert_ram_dimm(int bank_num, uint32_t capacity);
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
|
||||
|
||||
private:
|
||||
int map_phys_ram();
|
||||
|
||||
uint8_t gpio_enable = 0;
|
||||
|
||||
uint32_t bank_sizes[4] = {};
|
||||
uint8_t ram_config = (BANK_SIZE_16MB << 6) | (BANK_SIZE_16MB << 4) |
|
||||
(BANK_SIZE_16MB << 2) | (BANK_SIZE_16MB << 0);
|
||||
};
|
||||
|
||||
#endif // ASPEN_MEMCTRL_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,7 +32,7 @@ using namespace Hammerhead;
|
||||
|
||||
HammerheadCtrl::HammerheadCtrl() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Hammerhead Memory Controller";
|
||||
this->name = "Hammerhead";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
@@ -75,7 +75,8 @@ uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
result = 0; // say there is no L2 cache
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Hammerhead: unknown register read at offset 0x%X", offset);
|
||||
LOG_F(WARNING, "%s: unknown register read at offset 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,35 +99,37 @@ void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value,
|
||||
} else { // update the MSB part
|
||||
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0x00FFU) | (value << 8);
|
||||
}
|
||||
LOG_F(INFO, "Hammerhead: bank base #%d set to 0x%X", offset >> 1, bank_base[offset >> 1]);
|
||||
LOG_F(INFO, "%s: bank base #%d set to 0x%X", this->name.c_str(),
|
||||
offset >> 1, bank_base[offset >> 1]);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case HammerheadReg::MEM_TIMING_0:
|
||||
LOG_F(9, "Hammerhead: MEM_TIMING_0 set to 0x%X", value);
|
||||
LOG_F(9, "%s: MEM_TIMING_0 set to 0x%X", this->name.c_str(), value);
|
||||
break;
|
||||
case HammerheadReg::MEM_TIMING_1:
|
||||
LOG_F(9, "Hammerhead: MEM_TIMING_1 set to 0x%X", value);
|
||||
LOG_F(9, "%s: MEM_TIMING_1 set to 0x%X", this->name.c_str(), value);
|
||||
break;
|
||||
case HammerheadReg::REFRESH_TIMING:
|
||||
LOG_F(9, "Hammerhead: REFRESH_TIMING set to 0x%X", value);
|
||||
LOG_F(9, "%s: REFRESH_TIMING set to 0x%X", this->name.c_str(), value);
|
||||
break;
|
||||
case HammerheadReg::ROM_TIMING:
|
||||
LOG_F(9, "Hammerhead: ROM_TIMING set to 0x%X", value);
|
||||
LOG_F(9, "%s: ROM_TIMING set to 0x%X", this->name.c_str(), value);
|
||||
break;
|
||||
case HammerheadReg::ARBITER_CONFIG:
|
||||
this->arb_config = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Hammerhead: unknown register write at offset 0x%X", offset);
|
||||
LOG_F(WARNING, "%s: unknown register write at offset 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
}
|
||||
}
|
||||
|
||||
void HammerheadCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
{
|
||||
if (slot_num < 0 || slot_num >= 26) {
|
||||
ABORT_F("Hammerhead: invalid DIMM slot number %d", slot_num);
|
||||
ABORT_F("%s: invalid DIMM slot number %d", this->name.c_str(), slot_num);
|
||||
}
|
||||
|
||||
switch (capacity) {
|
||||
@@ -143,7 +146,7 @@ void HammerheadCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
this->bank_size[slot_num * 2 + 1] = DRAM_CAP_64MB;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Hammerhead: unsupported DRAM capacity %d", capacity);
|
||||
ABORT_F("%s: unsupported DRAM capacity %d", this->name.c_str(), capacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,10 +158,10 @@ void HammerheadCtrl::map_phys_ram()
|
||||
total_ram += this->bank_size[i];
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Hammerhead: total RAM size = %d bytes", total_ram);
|
||||
LOG_F(INFO, "%s: total RAM size = %d bytes", this->name.c_str(), total_ram);
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("Hammerhead: could not allocate physical RAM storage");
|
||||
ABORT_F("%s: could not allocate physical RAM storage", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+143
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
@@ -34,7 +35,7 @@ HMC::HMC() : MemCtrlBase()
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
// add memory mapped I/O region for the HMC control register
|
||||
add_mmio_region(0x50F40000, 0x10000, this);
|
||||
|
||||
this->ctrl_reg = 0ULL;
|
||||
@@ -46,7 +47,7 @@ uint32_t HMC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
if (!offset)
|
||||
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
return 0; // FIXME: what should be returned for invalid offsets?
|
||||
}
|
||||
|
||||
void HMC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
@@ -58,13 +59,151 @@ void HMC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
bit = 1ULL << this->bit_pos++;
|
||||
this->ctrl_reg = (value & 1) ? this->ctrl_reg | bit :
|
||||
this->ctrl_reg & ~bit;
|
||||
if (this->bit_pos >= HMC_CTRL_BITS) {
|
||||
this->bit_pos = 0;
|
||||
if (((this->ctrl_reg >> HMC_RAM_CFG_POS) & 3) != this->bank_config) {
|
||||
this->bank_config = (this->ctrl_reg >> HMC_RAM_CFG_POS) & 3;
|
||||
this->remap_ram_regions();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
case 8: // writing to HMCBase + 8 resets internal bit position
|
||||
this->bit_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HMC::remap_ram_regions() {
|
||||
uint32_t bank_b_addr;
|
||||
|
||||
switch (this->bank_config & 3) {
|
||||
case BANK_CFG_128MB:
|
||||
bank_b_addr = BANK_B_START;
|
||||
break;
|
||||
case BANK_CFG_2MB:
|
||||
bank_b_addr = this->mb_bank_size + BANK_SIZE_2MB;
|
||||
break;
|
||||
case BANK_CFG_8MB:
|
||||
bank_b_addr = this->mb_bank_size + BANK_SIZE_8MB;
|
||||
break;
|
||||
case BANK_CFG_32MB:
|
||||
bank_b_addr = this->mb_bank_size + BANK_SIZE_32MB;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->bank_b_size && this->bank_b_start != bank_b_addr) {
|
||||
AddressMapEntry *ref_entry = find_range(this->bank_b_start);
|
||||
if (ref_entry) {
|
||||
ref_entry->end = bank_b_addr + (ref_entry->end - ref_entry->start);
|
||||
ref_entry->start = bank_b_addr;
|
||||
|
||||
this->bank_b_start = bank_b_addr;
|
||||
LOG_F(INFO, "%s: successfully relocated bank B mem region to 0x%X",
|
||||
this->name.c_str(), bank_b_addr);
|
||||
} else
|
||||
LOG_F(ERROR, "%s: failed to relocate bank B mem region to 0x%X",
|
||||
this->name.c_str(), bank_b_addr);
|
||||
}
|
||||
}
|
||||
|
||||
int HMC::install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_b_size) {
|
||||
if (mb_bank_size != BANK_SIZE_4MB && mb_bank_size != BANK_SIZE_8MB) {
|
||||
LOG_F(ERROR, "%s: invalid motherboard bank size %d", this->name.c_str(),
|
||||
mb_bank_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!bank_a_size && bank_b_size) {
|
||||
LOG_F(ERROR, "%s: bank A can't be empty while bank B is not empty",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!this->add_ram_region(BANK_MB_START, mb_bank_size)) {
|
||||
LOG_F(ERROR, "%s: could not allocate motherboard RAM region!", this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->mb_bank_start = BANK_MB_START;
|
||||
this->mb_bank_size = mb_bank_size;
|
||||
this->bank_a_start = -1;
|
||||
this->bank_a_size = bank_a_size;
|
||||
this->bank_b_start = -1;
|
||||
this->bank_b_size = bank_b_size;
|
||||
|
||||
if (bank_a_size) {
|
||||
// create alias for RAM bank A (required for memory sizing)
|
||||
if (!this->add_ram_region(BANK_A_ALIAS, bank_a_size)) {
|
||||
LOG_F(ERROR, "%s: could not allocate region for bank A!",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->bank_a_start = BANK_A_ALIAS;
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t size = bank_a_size;
|
||||
|
||||
// make the main region for the bank A starting right after
|
||||
// the motherboard bank
|
||||
if (bank_a_size > BANK_SIZE_120MB) {
|
||||
// For a full 128MB bank, the lower part of this region is hidden
|
||||
// by the motherboard bank. Set up the partial mirror!
|
||||
offset = mb_bank_size;
|
||||
size = BANK_SIZE_120MB;
|
||||
}
|
||||
|
||||
if (!this->add_mem_mirror_partial(mb_bank_size, BANK_A_ALIAS,
|
||||
offset, size)) {
|
||||
LOG_F(ERROR, "%s: could not create mirror for RAM bank A!",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create additional aliases for bank A if the installed memory is
|
||||
// smaller than 8 MB. That's because HWInit always searches those areas
|
||||
// for the warm start signature.
|
||||
if (bank_a_size < BANK_SIZE_8MB) {
|
||||
for (uint32_t alias_start = BANK_B_START + bank_a_size - BANK_SIZE_8MB;
|
||||
alias_start < BANK_B_START; alias_start += bank_a_size) {
|
||||
if (!this->add_mem_mirror(alias_start, this->bank_a_start)) {
|
||||
LOG_F(ERROR, "%s: could not create alias for RAM bank A!",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bank_b_size) {
|
||||
if (!this->add_ram_region(BANK_B_START, bank_b_size)) {
|
||||
LOG_F(ERROR, "%s: could not allocate region for bank B!",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->bank_b_start = BANK_B_START;
|
||||
|
||||
// Create additional aliases for bank B if the installed memory is
|
||||
// smaller than 8 MB. That's because HWInit always searches those areas
|
||||
// for the warm start signature.
|
||||
if (bank_b_size < BANK_SIZE_8MB) {
|
||||
for (uint32_t alias_start = BANK_A_ALIAS + bank_b_size - BANK_SIZE_8MB;
|
||||
alias_start < BANK_A_ALIAS; alias_start += bank_b_size) {
|
||||
if (!this->add_mem_mirror(alias_start, this->bank_b_start)) {
|
||||
LOG_F(ERROR, "%s: could not create alias for RAM bank B!",
|
||||
this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->remap_ram_regions();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const DeviceDescription Hmc_Descriptor = {
|
||||
HMC::create, {}, {}
|
||||
};
|
||||
|
||||
+39
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -37,9 +37,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Bit in the HMC control register telling us where the frame bufffer
|
||||
for the on-board video is located. */
|
||||
#define HMC_VBASE_BIT 33
|
||||
/* Control register bit definitions. */
|
||||
enum {
|
||||
HMC_CTRL_BITS = 35, // width of the HMC control register
|
||||
HMC_RAM_CFG_POS = 29, // DRAM configuration bits position
|
||||
HMC_VBASE_BIT = 33, // framebuffer base address: 0 - 0x00100000, 1 - 0x0
|
||||
};
|
||||
|
||||
/* Motherboard RAM size constans. */
|
||||
enum {
|
||||
BANK_CFG_128MB = 0, // 12 x 12 address maxtrix (reset config)
|
||||
BANK_CFG_2MB = 1, // 9 x 9 address maxtrix
|
||||
BANK_CFG_8MB = 2, // 10 x 10 address maxtrix
|
||||
BANK_CFG_32MB = 3, // 11 x 11 address maxtrix
|
||||
BANK_SIZE_2MB = 0x200000,
|
||||
BANK_SIZE_4MB = 0x400000,
|
||||
BANK_SIZE_8MB = 0x800000,
|
||||
BANK_SIZE_32MB = 0x2000000,
|
||||
BANK_SIZE_120MB = 0x07800000,
|
||||
BANK_MB_START = 0x00000000, // starting address of the motherboard bank
|
||||
BANK_B_START = 0x08000000,
|
||||
BANK_A_ALIAS = 0x10000000,
|
||||
};
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
@@ -54,13 +73,27 @@ public:
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_b_size);
|
||||
|
||||
uint64_t get_control_reg(void) {
|
||||
return this->ctrl_reg;
|
||||
};
|
||||
|
||||
protected:
|
||||
void remap_ram_regions();
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t ctrl_reg;
|
||||
int bit_pos = 0;
|
||||
uint64_t ctrl_reg = 0;
|
||||
uint8_t bank_config = BANK_CFG_128MB;
|
||||
|
||||
uint32_t mb_bank_start = -1;
|
||||
uint32_t bank_a_start = -1;
|
||||
uint32_t bank_b_start = -1;
|
||||
|
||||
uint32_t mb_bank_size = 0;
|
||||
uint32_t bank_a_size = 0;
|
||||
uint32_t bank_b_size = 0;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,20 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <loguru.hpp>
|
||||
|
||||
static inline bool match_mem_entry(const AddressMapEntry* entry,
|
||||
const uint32_t start, const uint32_t end,
|
||||
MMIODevice* dev_instance)
|
||||
{
|
||||
return start == entry->start && end == entry->end &&
|
||||
(!dev_instance || dev_instance == entry->devobj);
|
||||
}
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
if (entry)
|
||||
@@ -51,6 +43,15 @@ MemCtrlBase::~MemCtrlBase() {
|
||||
}
|
||||
|
||||
|
||||
static inline bool match_mem_entry(const AddressMapEntry* entry,
|
||||
const uint32_t start, const uint32_t end,
|
||||
MMIODevice* dev_instance)
|
||||
{
|
||||
return start == entry->start && end == entry->end &&
|
||||
(!dev_instance || dev_instance == entry->devobj);
|
||||
}
|
||||
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
for (auto& entry : address_map) {
|
||||
if (addr >= entry->start && addr <= entry->end)
|
||||
@@ -149,11 +150,11 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
||||
{
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
// bail out if a memory region for the given range already exists
|
||||
if (!is_range_free(start_addr, size))
|
||||
return false;
|
||||
|
||||
uint8_t* reg_content = new uint8_t[size](); /* () intializer clears the memory to zero */
|
||||
uint8_t* reg_content = new uint8_t[size](); // allocate and clear to zero
|
||||
|
||||
this->mem_regions.push_back(reg_content);
|
||||
|
||||
@@ -164,10 +165,21 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
||||
entry->end = end;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = type;
|
||||
entry->devobj = 0;
|
||||
entry->devobj = nullptr;
|
||||
entry->mem_ptr = reg_content;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
// Keep address_map sorted, that way the RAM region (which starts at 0 and
|
||||
// is most often requested) will be found by find_range on the first
|
||||
// iteration.
|
||||
this->address_map.insert(
|
||||
std::upper_bound(
|
||||
this->address_map.begin(),
|
||||
this->address_map.end(),
|
||||
entry,
|
||||
[](const auto& lhs, const auto& rhs) {
|
||||
return lhs->start < rhs->start;
|
||||
}),
|
||||
entry);
|
||||
|
||||
LOG_F(INFO, "Added mem region 0x%X..0x%X (%s%s%s%s) -> 0x%X", start_addr, end,
|
||||
entry->type & RT_ROM ? "ROM," : "",
|
||||
@@ -191,22 +203,33 @@ bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
bool MemCtrlBase::add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
|
||||
uint32_t offset, uint32_t size) {
|
||||
AddressMapEntry *entry, *ref_entry;
|
||||
|
||||
ref_entry = find_range(dest_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
// use origin's size if no size was specified
|
||||
if (!size)
|
||||
size = ref_entry->end - ref_entry->start + 1;
|
||||
|
||||
if (ref_entry->start + offset + size - 1 > ref_entry->end) {
|
||||
LOG_F(ERROR, "Partial mirror outside the origin, offset=0x%X, size=0x%X",
|
||||
offset, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
uint32_t end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
uint32_t end = start_addr + size - 1;
|
||||
entry->start = start_addr;
|
||||
entry->end = end;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = ref_entry->type | RT_MIRROR;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = ref_entry->mem_ptr;
|
||||
entry->devobj = nullptr;
|
||||
entry->mem_ptr = ref_entry->mem_ptr + offset;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -217,7 +240,7 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
entry->type & RT_MMIO ? "MMIO," : "",
|
||||
entry->type & RT_MIRROR ? "MIRROR," : "",
|
||||
dest_addr,
|
||||
ref_entry->start, ref_entry->end,
|
||||
ref_entry->start + offset, ref_entry->end,
|
||||
ref_entry->devobj ? " (" : "",
|
||||
ref_entry->devobj ? ref_entry->devobj->get_name().c_str() : "",
|
||||
ref_entry->devobj ? ")"
|
||||
@@ -228,6 +251,17 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
return this->add_mem_mirror_common(start_addr, dest_addr);
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
|
||||
uint32_t offset, uint32_t size) {
|
||||
return this->add_mem_mirror_common(start_addr, dest_addr, offset, size);
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
|
||||
AddressMapEntry* ref_entry;
|
||||
uint32_t cpy_size;
|
||||
@@ -249,7 +283,7 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
|
||||
{
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
// bail out if a memory region for the given range already exists
|
||||
if (!is_range_free(start_addr, size))
|
||||
return false;
|
||||
|
||||
@@ -327,3 +361,14 @@ AddressMapEntry* MemCtrlBase::find_rom_region()
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t *MemCtrlBase::get_region_hostmem_ptr(const uint32_t addr) {
|
||||
AddressMapEntry *reg_desc = this->find_range(addr);
|
||||
if (reg_desc == nullptr || reg_desc->type == RT_MMIO)
|
||||
return nullptr;
|
||||
|
||||
if (reg_desc->type == RT_MIRROR)
|
||||
return (addr - reg_desc->mirror) + reg_desc->mem_ptr;
|
||||
else
|
||||
return (addr - reg_desc->start) + reg_desc->mem_ptr;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,8 +28,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
class MMIODevice;
|
||||
|
||||
// Common DRAM capacities.
|
||||
/* Common DRAM capacities. */
|
||||
enum {
|
||||
DRAM_CAP_1MB = (1 << 20),
|
||||
DRAM_CAP_2MB = (1 << 21),
|
||||
DRAM_CAP_4MB = (1 << 22),
|
||||
DRAM_CAP_8MB = (1 << 23),
|
||||
@@ -40,21 +41,21 @@ enum {
|
||||
};
|
||||
|
||||
enum RangeType {
|
||||
RT_ROM = 1, /* read-only memory */
|
||||
RT_RAM = 2, /* random access memory */
|
||||
RT_MMIO = 4, /* memory mapped I/O */
|
||||
RT_MIRROR = 8 /* region mirror (content of another region is acessible
|
||||
at some other address) */
|
||||
RT_ROM = 1, // read-only memory
|
||||
RT_RAM = 2, // random access memory
|
||||
RT_MMIO = 4, // memory mapped I/O
|
||||
RT_MIRROR = 8 // region mirror (content of another region acessible at some
|
||||
// other address)
|
||||
};
|
||||
|
||||
/** Defines the format for the address map entry. */
|
||||
typedef struct AddressMapEntry {
|
||||
uint32_t start; /* first address of the corresponding range */
|
||||
uint32_t end; /* last address of the corresponding range */
|
||||
uint32_t mirror; /* mirror address for RT_MIRROR */
|
||||
uint32_t type; /* range type */
|
||||
MMIODevice* devobj; /* pointer to device object */
|
||||
unsigned char* mem_ptr; /* direct pointer to data for memory objects */
|
||||
uint32_t start; // first address of the corresponding range
|
||||
uint32_t end; // last address of the corresponding range
|
||||
uint32_t mirror; // starting address of the origin for RT_MIRROR
|
||||
uint32_t type; // range type
|
||||
MMIODevice* devobj; // pointer to device object
|
||||
unsigned char* mem_ptr; // direct pointer to data for memory objects
|
||||
} AddressMapEntry;
|
||||
|
||||
|
||||
@@ -66,27 +67,39 @@ public:
|
||||
virtual bool add_rom_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
||||
virtual bool add_mem_mirror_partial(uint32_t start_addr, uint32_t dest_addr,
|
||||
uint32_t offset, uint32_t size);
|
||||
|
||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
||||
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size,
|
||||
MMIODevice* dev_instance);
|
||||
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size,
|
||||
MMIODevice* dev_instance);
|
||||
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size, MMIODevice* dev_instance);
|
||||
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size,
|
||||
MMIODevice* dev_instance);
|
||||
AddressMapEntry* find_range_contains(uint32_t addr, uint32_t size);
|
||||
AddressMapEntry* find_range_overlaps(uint32_t addr, uint32_t size);
|
||||
bool is_range_free(uint32_t addr, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_rom_region();
|
||||
|
||||
uint8_t *get_region_hostmem_ptr(const uint32_t addr);
|
||||
|
||||
protected:
|
||||
bool add_mem_region(
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type,
|
||||
uint8_t init_val
|
||||
);
|
||||
|
||||
bool add_mem_mirror_common(uint32_t start_addr, uint32_t dest_addr,
|
||||
uint32_t offset=0, uint32_t size=0);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t*> mem_regions;
|
||||
std::vector<AddressMapEntry*> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
#endif // MEMORY_CONTROLLER_BASE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,10 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
@@ -60,7 +60,9 @@ int MPC106::device_postinit()
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
|
||||
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)},
|
||||
{"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)},
|
||||
{"pci_GPU", DEV_FUN(0x12,0)}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
@@ -72,6 +74,7 @@ int MPC106::device_postinit()
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
|
||||
this->irq_id_PCI_A = this->int_ctrl->register_dev_int(IntSrc::PCI_A );
|
||||
this->irq_id_PCI_B = this->int_ctrl->register_dev_int(IntSrc::PCI_B );
|
||||
this->irq_id_PCI_C = this->int_ctrl->register_dev_int(IntSrc::PCI_C );
|
||||
@@ -87,7 +90,7 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
|
||||
return p.second == dev;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if (it == dev_map.end()) {
|
||||
LOG_F(ERROR, "Interrupt from unknown device %s", dev->get_name().c_str());
|
||||
}
|
||||
@@ -100,7 +103,8 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
|
||||
case DEV_FUN(0x0F,0): irq_id = this->irq_id_PCI_C ; break;
|
||||
case DEV_FUN(0x12,0): irq_id = this->irq_id_PCI_GPU ; break;
|
||||
default:
|
||||
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x", dev->get_name().c_str(), it->first >> 3, it->first & 7);
|
||||
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x",
|
||||
dev->get_name().c_str(), it->first >> 3, it->first & 7);
|
||||
return;
|
||||
}
|
||||
if (this->int_ctrl)
|
||||
@@ -351,6 +355,8 @@ static const PropMap Grackle_Properties = {
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
{"pci_GPU",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Grackle_Descriptor = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -36,6 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -34,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace Platinum;
|
||||
|
||||
PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase(640, 480) {
|
||||
PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
set_name("Platinum");
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
@@ -444,6 +444,13 @@ void PlatinumCtrl::enable_display() {
|
||||
|
||||
this->stop_refresh_task();
|
||||
|
||||
if (this->active_width <= 0 || this->active_height <= 0 || this->pixel_clock <= 0) {
|
||||
this->blank_on = true;
|
||||
this->crtc_on = false;
|
||||
this->blank_display();
|
||||
return;
|
||||
}
|
||||
|
||||
this->refresh_rate = (double)(this->pixel_clock) / (this->hori_total * this->vert_total);
|
||||
this->start_refresh_task();
|
||||
|
||||
|
||||
+257
-104
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,9 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/serial/chario.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/serial/z85c30.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
@@ -58,13 +60,15 @@ EsccController::EsccController()
|
||||
);
|
||||
this->ch_b->attach_backend(CHARIO_BE_NULL);
|
||||
|
||||
this->reg_ptr = 0;
|
||||
this->master_int_cntrl = 0;
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void EsccController::reset()
|
||||
{
|
||||
this->master_int_cntrl &= 0xFC;
|
||||
this->master_int_cntrl |= 0xC0;
|
||||
this->master_int_cntrl &= (WR9_NO_VECTOR | WR9_VECTOR_INCLUDES_STATUS);
|
||||
this->master_int_cntrl |= WR9_FORCE_HARDWARE_RESET;
|
||||
this->reg_ptr = WR0; // or RR0
|
||||
|
||||
this->ch_a->reset(true);
|
||||
this->ch_b->reset(true);
|
||||
@@ -72,36 +76,33 @@ void EsccController::reset()
|
||||
|
||||
uint8_t EsccController::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
uint8_t value;
|
||||
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
if (this->reg_ptr == 2) {
|
||||
// TODO: implement interrupt vector modifications
|
||||
result = this->int_vec;
|
||||
} else {
|
||||
result = this->ch_b->read_reg(this->reg_ptr);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
value = this->read_internal(this->ch_b.get());
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
if (this->reg_ptr == 2) {
|
||||
return this->int_vec;
|
||||
} else {
|
||||
return this->ch_a->read_reg(this->reg_ptr);
|
||||
}
|
||||
value = this->read_internal(this->ch_a.get());
|
||||
break;
|
||||
case EsccReg::Port_B_Data:
|
||||
return this->ch_b->receive_byte();
|
||||
value = this->ch_b->receive_byte();
|
||||
break;
|
||||
case EsccReg::Port_A_Data:
|
||||
return this->ch_a->receive_byte();
|
||||
value = this->ch_a->receive_byte();
|
||||
break;
|
||||
case EsccReg::Enh_Reg_B:
|
||||
value = this->ch_b->get_enh_reg();
|
||||
break;
|
||||
case EsccReg::Enh_Reg_A:
|
||||
value = this->ch_a->get_enh_reg();
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "ESCC: reading from unimplemented register 0x%x", reg_offset);
|
||||
LOG_F(WARNING, "ESCC: reading from unimplemented register 0x%x", reg_offset);
|
||||
value = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
return value;
|
||||
}
|
||||
|
||||
void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
@@ -119,46 +120,70 @@ void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
case EsccReg::Port_A_Data:
|
||||
this->ch_a->send_byte(value);
|
||||
break;
|
||||
case EsccReg::Enh_Reg_B:
|
||||
this->ch_b->set_enh_reg(value);
|
||||
break;
|
||||
case EsccReg::Enh_Reg_A:
|
||||
this->ch_a->set_enh_reg(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "ESCC: writing 0x%X to unimplemented register 0x%x", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EsccController::read_internal(EsccChannel *ch)
|
||||
{
|
||||
uint8_t value;
|
||||
switch (this->reg_ptr) {
|
||||
case RR2:
|
||||
// TODO: implement interrupt vector modifications
|
||||
value = this->int_vec;
|
||||
break;
|
||||
default:
|
||||
value = ch->read_reg(this->reg_ptr);
|
||||
}
|
||||
this->reg_ptr = RR0; // or WR0
|
||||
return value;
|
||||
}
|
||||
|
||||
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
{
|
||||
if (this->reg_ptr) {
|
||||
// chip-specific registers
|
||||
if (this->reg_ptr == 9) {
|
||||
// see if some reset is requested
|
||||
switch(value & 0xC0) {
|
||||
case RESET_CH_B:
|
||||
this->master_int_cntrl &= 0xDF;
|
||||
this->ch_b->reset(false);
|
||||
break;
|
||||
case RESET_CH_A:
|
||||
this->master_int_cntrl &= 0xDF;
|
||||
this->ch_a->reset(false);
|
||||
break;
|
||||
case RESET_ESCC:
|
||||
this->reset();
|
||||
break;
|
||||
}
|
||||
|
||||
this->master_int_cntrl = value & 0x3F;
|
||||
} else if (this->reg_ptr == 2) {
|
||||
this->int_vec = value;
|
||||
} else { // channel-specific registers
|
||||
ch->write_reg(this->reg_ptr, value);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
} else {
|
||||
this->reg_ptr = value & 7;
|
||||
switch(value >> 3) {
|
||||
case WR0Cmd::Point_High:
|
||||
this->reg_ptr |= 8;
|
||||
switch (this->reg_ptr) {
|
||||
// chip-specific registers
|
||||
case WR0:
|
||||
this->reg_ptr = value & WR0_REGISTER_SELECTION_CODE;
|
||||
switch (value & WR0_COMMAND_CODES) {
|
||||
case WR0_COMMAND_POINT_HIGH:
|
||||
this->reg_ptr |= WR8; // or RR8
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case WR2:
|
||||
this->int_vec = value;
|
||||
break;
|
||||
case WR9:
|
||||
// see if some reset is requested
|
||||
switch (value & WR9_RESET_COMMAND_BITS) {
|
||||
case WR9_CHANNEL_RESET_B:
|
||||
this->master_int_cntrl &= ~WR9_INTERRUPT_MASKING_WITHOUT_INTACK;
|
||||
this->ch_b->reset(false);
|
||||
break;
|
||||
case WR9_CHANNEL_RESET_A:
|
||||
this->master_int_cntrl &= ~WR9_INTERRUPT_MASKING_WITHOUT_INTACK;
|
||||
this->ch_a->reset(false);
|
||||
break;
|
||||
case WR9_FORCE_HARDWARE_RESET:
|
||||
this->reset();
|
||||
break;
|
||||
}
|
||||
|
||||
this->master_int_cntrl = value & WR9_INTERRUPT_CONTROL_BITS;
|
||||
break;
|
||||
default:
|
||||
// channel-specific registers
|
||||
ch->write_reg(this->reg_ptr, value);
|
||||
}
|
||||
this->reg_ptr = WR0; // or RR0
|
||||
}
|
||||
|
||||
// ======================== ESCC Channel methods ==============================
|
||||
@@ -187,17 +212,23 @@ void EsccChannel::reset(bool hw_reset)
|
||||
{
|
||||
this->chario->rcv_disable();
|
||||
|
||||
this->write_regs[1] &= 0x24;
|
||||
this->write_regs[3] &= 0xFE;
|
||||
this->write_regs[4] |= 0x04;
|
||||
this->write_regs[5] &= 0x61;
|
||||
this->write_regs[15] = 0xF8;
|
||||
/*
|
||||
We use hex values here instead of enums to more
|
||||
easily compare with the z85c30 data sheet.
|
||||
*/
|
||||
|
||||
this->read_regs[0] &= 0x3C;
|
||||
this->read_regs[0] |= 0x44;
|
||||
this->read_regs[1] = 0x06;
|
||||
this->read_regs[3] = 0x00;
|
||||
this->read_regs[10] = 0x00;
|
||||
this->write_regs[WR0] = 0;
|
||||
this->write_regs[WR1] &= 0x24;
|
||||
this->write_regs[WR3] &= 0xFE;
|
||||
this->write_regs[WR4] |= 0x04;
|
||||
this->write_regs[WR5] &= 0x61;
|
||||
this->write_regs[WR15] = 0xF8;
|
||||
|
||||
this->read_regs[RR0] &= 0x38;
|
||||
this->read_regs[RR0] |= 0x44;
|
||||
this->read_regs[RR1] = 0x06 | RR1_ALL_SENT; // HACK: also set ALL_SENT flag.
|
||||
this->read_regs[RR3] = 0x00;
|
||||
this->read_regs[RR10] = 0x00;
|
||||
|
||||
// initialize DPLL
|
||||
this->dpll_active = 0;
|
||||
@@ -209,81 +240,84 @@ void EsccChannel::reset(bool hw_reset)
|
||||
this->brg_clock_src = 0;
|
||||
|
||||
if (hw_reset) {
|
||||
this->write_regs[10] = 0;
|
||||
this->write_regs[11] = 8;
|
||||
this->write_regs[14] &= 0xC0;
|
||||
this->write_regs[14] |= 0x20;
|
||||
this->write_regs[WR9] &= 0x03; // clear all except (WR9_NO_VECTOR | WR9_VECTOR_INCLUDES_STATUS)
|
||||
this->write_regs[WR9] |= 0xC0; // set WR9_FORCE_HARDWARE_RESET
|
||||
this->write_regs[WR10] = 0;
|
||||
this->write_regs[WR11] = 8;
|
||||
this->write_regs[WR14] &= 0xC0;
|
||||
} else {
|
||||
this->write_regs[10] &= 0x60;
|
||||
this->write_regs[14] &= 0xC3;
|
||||
this->write_regs[14] |= 0x20;
|
||||
this->write_regs[WR9] &= ~0x20; // clear WR9_INTERRUPT_MASKING_WITHOUT_INTACK
|
||||
this->write_regs[WR10] &= 0x60;
|
||||
this->write_regs[WR14] &= 0xC3;
|
||||
}
|
||||
this->write_regs[WR14] |= 0x20;
|
||||
}
|
||||
|
||||
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
switch (reg_num) {
|
||||
case 3:
|
||||
if ((this->write_regs[3] ^ value) & 0x10) {
|
||||
this->write_regs[3] |= 0x10;
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
case WR3:
|
||||
if ((this->write_regs[WR3] ^ value) & WR3_ENTER_HUNT_MODE) {
|
||||
this->write_regs[WR3] |= WR3_ENTER_HUNT_MODE;
|
||||
this->read_regs[RR0] |= RR0_SYNC_HUNT;
|
||||
LOG_F(9, "%s: Hunt mode entered.", this->name.c_str());
|
||||
}
|
||||
if ((this->write_regs[3] ^ value) & 1) {
|
||||
if (value & 1) {
|
||||
this->write_regs[3] |= 0x1;
|
||||
if ((this->write_regs[WR3] ^ value) & WR3_RX_ENABLE) {
|
||||
if (value & WR3_RX_ENABLE) {
|
||||
this->write_regs[WR3] |= WR3_RX_ENABLE;
|
||||
this->chario->rcv_enable();
|
||||
LOG_F(9, "%s: receiver enabled.", this->name.c_str());
|
||||
} else {
|
||||
this->write_regs[3] ^= 0x1;
|
||||
this->write_regs[WR3] ^= WR3_RX_ENABLE;
|
||||
this->chario->rcv_disable();
|
||||
LOG_F(9, "%s: receiver disabled.", this->name.c_str());
|
||||
this->write_regs[3] |= 0x10; // enter HUNT mode
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
this->write_regs[WR3] |= WR3_ENTER_HUNT_MODE;
|
||||
this->read_regs[RR0] |= RR0_SYNC_HUNT;
|
||||
}
|
||||
}
|
||||
this->write_regs[3] = (this->write_regs[3] & 0x11) | (value & 0xEE);
|
||||
this->write_regs[WR3] = (this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) | (value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
|
||||
return;
|
||||
case 7:
|
||||
if (this->write_regs[15] & 1) {
|
||||
case WR7:
|
||||
if (this->write_regs[WR15] & WR15_SDLC_HDLC_ENHANCEMENT_ENABLE) {
|
||||
this->wr7_enh = value;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
switch (value >> 5) {
|
||||
case DPLL_NULL_CMD:
|
||||
case WR8:
|
||||
this->send_byte(value);
|
||||
return;
|
||||
case WR14:
|
||||
switch (value & WR14_DPLL_COMMAND_BITS) {
|
||||
case WR14_DPLL_NULL_COMMAND:
|
||||
break;
|
||||
case DPLL_ENTER_SRC_MODE:
|
||||
case WR14_DPLL_ENTER_SEARCH_MODE:
|
||||
this->dpll_active = 1;
|
||||
this->read_regs[10] &= 0x3F;
|
||||
this->read_regs[RR10] &= ~(RR10_TWO_CLOCKS_MISSING | RR10_ONE_CLOCK_MISSING);
|
||||
break;
|
||||
case DPLL_DISABLE:
|
||||
case WR14_DPLL_RESET_MISSING_CLOCK:
|
||||
this->read_regs[RR10] &= ~(RR10_TWO_CLOCKS_MISSING | RR10_ONE_CLOCK_MISSING);
|
||||
break;
|
||||
case WR14_DPLL_DISABLE_DPLL:
|
||||
this->dpll_active = 0;
|
||||
// fallthrough
|
||||
case DPLL_RST_MISSING_CLK:
|
||||
this->read_regs[10] &= 0x3F;
|
||||
break;
|
||||
case DPLL_SET_SRC_BGR:
|
||||
case WR14_DPLL_SET_SOURCE_BR_GENERATOR:
|
||||
this->dpll_clock_src = 0;
|
||||
break;
|
||||
case DPLL_SET_SRC_RTXC:
|
||||
case WR14_DPLL_SET_SOURCE_RTXC:
|
||||
this->dpll_clock_src = 1;
|
||||
break;
|
||||
case DPLL_SET_FM_MODE:
|
||||
case WR14_DPLL_SET_FM_MODE:
|
||||
this->dpll_mode = DpllMode::FM;
|
||||
break;
|
||||
case DPLL_SET_NRZI_MODE:
|
||||
case WR14_DPLL_SET_NRZI_MODE:
|
||||
this->dpll_mode = DpllMode::NRZI;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented DPLL command %d", this->name.c_str(), value >> 5);
|
||||
}
|
||||
if (value & 0x1C) { // Local Loopback, Auto Echo DTR/REQ bits set
|
||||
if (value & (WR14_LOCAL_LOOPBACK | WR14_AUTO_ECHO | WR14_DTR_REQUEST_FUNCTION)) {
|
||||
LOG_F(WARNING, "%s: unexpected value in WR14 = 0x%X", this->name.c_str(), value);
|
||||
}
|
||||
if (this->brg_active ^ (value & 1)) {
|
||||
this->brg_active = value & 1;
|
||||
if (this->brg_active ^ (value & WR14_BR_GENERATOR_ENABLE)) {
|
||||
this->brg_active = value & WR14_BR_GENERATOR_ENABLE;
|
||||
LOG_F(9, "%s: BRG %s", this->name.c_str(), this->brg_active ? "enabled" : "disabled");
|
||||
}
|
||||
return;
|
||||
@@ -294,10 +328,16 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
|
||||
uint8_t EsccChannel::read_reg(int reg_num)
|
||||
{
|
||||
if (!reg_num) {
|
||||
switch (reg_num) {
|
||||
case RR0:
|
||||
if (this->chario->rcv_char_available()) {
|
||||
this->read_regs[0] |= 1;
|
||||
return this->read_regs[RR0] |= RR0_RX_CHARACTER_AVAILABLE;
|
||||
} else {
|
||||
return this->read_regs[RR0] &= ~RR0_RX_CHARACTER_AVAILABLE;
|
||||
}
|
||||
break;
|
||||
case RR8:
|
||||
return this->receive_byte();
|
||||
}
|
||||
return this->read_regs[reg_num];
|
||||
}
|
||||
@@ -306,6 +346,7 @@ void EsccChannel::send_byte(uint8_t value)
|
||||
{
|
||||
// TODO: put one byte into the Data FIFO
|
||||
|
||||
this->write_regs[WR8] = value;
|
||||
this->chario->xmit_char(value);
|
||||
}
|
||||
|
||||
@@ -320,10 +361,122 @@ uint8_t EsccChannel::receive_byte()
|
||||
} else {
|
||||
c = 0;
|
||||
}
|
||||
this->read_regs[0] &= ~1;
|
||||
this->read_regs[RR0] &= ~RR0_RX_CHARACTER_AVAILABLE;
|
||||
this->read_regs[RR8] = c;
|
||||
return c;
|
||||
}
|
||||
|
||||
uint8_t EsccChannel::get_enh_reg()
|
||||
{
|
||||
return this->enh_reg;
|
||||
}
|
||||
|
||||
void EsccChannel::set_enh_reg(uint8_t value)
|
||||
{
|
||||
uint8_t changed_bits = value ^ this->enh_reg;
|
||||
if (changed_bits & 0x10) {
|
||||
if (value & 0x10)
|
||||
LOG_F(ERROR, "%s: CTS connected to GPIO; DCD connected to GND", this->name.c_str());
|
||||
else
|
||||
LOG_F(INFO, "%s: CTS connected to TRXC_In_l; DCD connected to GPIO", this->name.c_str());
|
||||
this->enh_reg = value & 0x10;
|
||||
} else if (changed_bits & ~0x10) {
|
||||
if (value & ~0x10)
|
||||
LOG_F(ERROR, "%s: Ignoring attempt to set Enh_Reg bits 0x%02x", this->name.c_str(), value & ~0x10);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::dma_start_tx()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EsccChannel::dma_start_rx()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EsccChannel::dma_stop_tx()
|
||||
{
|
||||
if (this->timer_id_tx) {
|
||||
TimerManager::get_instance()->cancel_timer(this->timer_id_tx);
|
||||
this->timer_id_tx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::dma_stop_rx()
|
||||
{
|
||||
if (this->timer_id_rx) {
|
||||
TimerManager::get_instance()->cancel_timer(this->timer_id_rx);
|
||||
this->timer_id_rx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::dma_in_tx()
|
||||
{
|
||||
LOG_F(ERROR, "%s: Unexpected DMA INPUT command for transmit.", this->name.c_str());
|
||||
}
|
||||
|
||||
void EsccChannel::dma_in_rx()
|
||||
{
|
||||
if (dma_ch[1]->get_push_data_remaining()) {
|
||||
this->timer_id_rx = TimerManager::get_instance()->add_oneshot_timer(
|
||||
0,
|
||||
[this]() {
|
||||
this->timer_id_rx = 0;
|
||||
char c = receive_byte();
|
||||
int xx = dma_ch[1]->push_data(&c, 1);
|
||||
this->dma_in_rx();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::dma_out_tx()
|
||||
{
|
||||
this->timer_id_tx = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10,
|
||||
[this]() {
|
||||
this->timer_id_tx = 0;
|
||||
uint8_t *data;
|
||||
uint32_t avail_len;
|
||||
|
||||
if (dma_ch[1]->pull_data(256, &avail_len, &data) == MoreData) {
|
||||
while(avail_len) {
|
||||
this->send_byte(*data++);
|
||||
avail_len--;
|
||||
}
|
||||
this->dma_out_tx();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void EsccChannel::dma_out_rx()
|
||||
{
|
||||
LOG_F(ERROR, "%s: Unexpected DMA OUTPUT command for receive.", this->name.c_str());
|
||||
}
|
||||
|
||||
void EsccChannel::dma_flush_tx()
|
||||
{
|
||||
this->dma_stop_tx();
|
||||
this->timer_id_tx = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10,
|
||||
[this]() {
|
||||
this->timer_id_tx = 0;
|
||||
dma_ch[1]->end_pull_data();
|
||||
});
|
||||
}
|
||||
|
||||
void EsccChannel::dma_flush_rx()
|
||||
{
|
||||
this->dma_stop_rx();
|
||||
this->timer_id_rx = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10,
|
||||
[this]() {
|
||||
this->timer_id_rx = 0;
|
||||
dma_ch[1]->end_push_data();
|
||||
});
|
||||
}
|
||||
|
||||
static const vector<string> CharIoBackends = {"null", "stdio", "socket"};
|
||||
|
||||
static const PropMap Escc_Properties = {
|
||||
|
||||
+64
-35
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ESCC_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/serial/chario.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -63,29 +64,6 @@ enum LocalTalkReg : uint8_t {
|
||||
Detect_AB = 0xB,
|
||||
};
|
||||
|
||||
enum WR0Cmd : uint8_t {
|
||||
Point_High = 1,
|
||||
};
|
||||
|
||||
/** ESCC reset commands. */
|
||||
enum {
|
||||
RESET_ESCC = 0xC0,
|
||||
RESET_CH_A = 0x80,
|
||||
RESET_CH_B = 0x40
|
||||
};
|
||||
|
||||
/** DPLL commands in WR14. */
|
||||
enum {
|
||||
DPLL_NULL_CMD = 0,
|
||||
DPLL_ENTER_SRC_MODE = 1,
|
||||
DPLL_RST_MISSING_CLK = 2,
|
||||
DPLL_DISABLE = 3,
|
||||
DPLL_SET_SRC_BGR = 4,
|
||||
DPLL_SET_SRC_RTXC = 5,
|
||||
DPLL_SET_FM_MODE = 6,
|
||||
DPLL_SET_NRZI_MODE = 7
|
||||
};
|
||||
|
||||
enum DpllMode : uint8_t {
|
||||
NRZI = 0,
|
||||
FM = 1
|
||||
@@ -103,17 +81,68 @@ public:
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
void send_byte(uint8_t value);
|
||||
uint8_t receive_byte();
|
||||
uint8_t get_enh_reg();
|
||||
void set_enh_reg(uint8_t value);
|
||||
|
||||
void set_dma_channel(int dir_index, DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch[dir_index] = dma_ch;
|
||||
auto dbdma_ch = dynamic_cast<DMAChannel*>(dma_ch);
|
||||
if (dbdma_ch) {
|
||||
switch (dir_index) {
|
||||
case 0:
|
||||
dbdma_ch->set_callbacks(
|
||||
std::bind(&EsccChannel::dma_start_tx, this),
|
||||
std::bind(&EsccChannel::dma_stop_tx, this)
|
||||
);
|
||||
dbdma_ch->set_data_callbacks(
|
||||
std::bind(&EsccChannel::dma_in_tx, this),
|
||||
std::bind(&EsccChannel::dma_out_tx, this),
|
||||
std::bind(&EsccChannel::dma_flush_tx, this)
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
dbdma_ch->set_callbacks(
|
||||
std::bind(&EsccChannel::dma_start_rx, this),
|
||||
std::bind(&EsccChannel::dma_stop_rx, this)
|
||||
);
|
||||
dbdma_ch->set_data_callbacks(
|
||||
std::bind(&EsccChannel::dma_in_rx, this),
|
||||
std::bind(&EsccChannel::dma_out_rx, this),
|
||||
std::bind(&EsccChannel::dma_flush_rx, this)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t timer_id_tx = 0;
|
||||
uint32_t timer_id_rx = 0;
|
||||
|
||||
void dma_start_tx();
|
||||
void dma_stop_tx();
|
||||
void dma_in_tx();
|
||||
void dma_out_tx();
|
||||
void dma_flush_tx();
|
||||
|
||||
void dma_start_rx();
|
||||
void dma_stop_rx();
|
||||
void dma_in_rx();
|
||||
void dma_out_rx();
|
||||
void dma_flush_rx();
|
||||
|
||||
DmaBidirChannel* dma_ch[2];
|
||||
|
||||
std::string name;
|
||||
uint8_t read_regs[16];
|
||||
uint8_t write_regs[16];
|
||||
uint8_t wr7_enh;
|
||||
uint8_t read_regs[16] = {};
|
||||
uint8_t write_regs[16] = {};
|
||||
uint8_t wr7_enh = 0;
|
||||
uint8_t dpll_active;
|
||||
uint8_t dpll_mode;
|
||||
DpllMode dpll_mode;
|
||||
uint8_t dpll_clock_src;
|
||||
uint8_t brg_active;
|
||||
uint8_t brg_clock_src;
|
||||
uint8_t enh_reg = 0;
|
||||
|
||||
std::unique_ptr<CharIoBackEnd> chario;
|
||||
};
|
||||
@@ -132,25 +161,25 @@ public:
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
void dma_start();
|
||||
void dma_stop();
|
||||
void set_dma_channel(int ch_index, DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch[ch_index] = dma_ch;
|
||||
void set_dma_channel(int ch_dir_index, DmaBidirChannel *dma_ch) {
|
||||
switch (ch_dir_index >> 1) {
|
||||
case 0: ch_a->set_dma_channel(ch_dir_index & 1, dma_ch); break;
|
||||
case 1: ch_b->set_dma_channel(ch_dir_index & 1, dma_ch); break;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
void reset();
|
||||
void write_internal(EsccChannel* ch, uint8_t value);
|
||||
uint8_t read_internal(EsccChannel* ch);
|
||||
|
||||
std::unique_ptr<EsccChannel> ch_a;
|
||||
std::unique_ptr<EsccChannel> ch_b;
|
||||
|
||||
int reg_ptr; // register pointer for reading/writing (same for both channels)
|
||||
|
||||
uint8_t master_int_cntrl;
|
||||
uint8_t int_vec;
|
||||
|
||||
DmaBidirChannel* dma_ch[4];
|
||||
uint8_t master_int_cntrl = 0;
|
||||
uint8_t int_vec = 0;
|
||||
};
|
||||
|
||||
#endif // ESCC_H
|
||||
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Register definitions for Z85C30. */
|
||||
|
||||
#ifndef Z85C30_H
|
||||
#define Z85C30_H
|
||||
|
||||
enum
|
||||
{
|
||||
WR0 = 0,
|
||||
WR1,
|
||||
WR2,
|
||||
WR3,
|
||||
WR4,
|
||||
WR5,
|
||||
WR6,
|
||||
WR7,
|
||||
WR8,
|
||||
WR9,
|
||||
WR10,
|
||||
WR11,
|
||||
WR12,
|
||||
WR13,
|
||||
WR14,
|
||||
WR15,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RR0 = 0,
|
||||
RR1,
|
||||
RR2,
|
||||
RR3,
|
||||
RR4,
|
||||
RR5,
|
||||
RR6,
|
||||
RR7,
|
||||
RR8,
|
||||
RR9,
|
||||
RR10,
|
||||
RR11,
|
||||
RR12,
|
||||
RR13,
|
||||
RR14,
|
||||
RR15,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
// RR0 - Transmit/Receive Buffer Status and External Status
|
||||
|
||||
RR0_RX_CHARACTER_AVAILABLE = 1 << 0,
|
||||
RR0_ZERO_COUNT = 1 << 1,
|
||||
RR0_TX_BUFFER_EMPTY = 1 << 2,
|
||||
RR0_DCD = 1 << 3,
|
||||
RR0_SYNC_HUNT = 1 << 4,
|
||||
RR0_CTS = 1 << 5,
|
||||
RR0_TX_UNDERRUN_EOM = 1 << 6,
|
||||
RR0_BREAK_ABORT = 1 << 7,
|
||||
|
||||
// RR1 - Special Receive Condition status, residue codes, error conditions
|
||||
|
||||
RR1_ALL_SENT = 1 << 0,
|
||||
RR1_RESIDUE_CODE_2 = 1 << 1,
|
||||
RR1_RESIDUE_CODE_1 = 1 << 2,
|
||||
RR1_RESIDUE_CODE_0 = 1 << 3,
|
||||
RR1_PARITY_ERROR = 1 << 4,
|
||||
RR1_RX_OVERRUN_ERROR = 1 << 5,
|
||||
RR1_CRC_FRAMING_ERROR = 1 << 6,
|
||||
RR1_END_OF_FRAME_SDLC = 1 << 7,
|
||||
|
||||
// RR2 - Modified (Channel B only) interrupt vector and Unmodified interrupt vector (Channel A only)
|
||||
|
||||
RR2_V0 = 1 << 0,
|
||||
RR2_V1 = 1 << 1,
|
||||
RR2_V2 = 1 << 2,
|
||||
RR2_V3 = 1 << 3,
|
||||
RR2_V4 = 1 << 4,
|
||||
RR2_V5 = 1 << 5,
|
||||
RR2_V6 = 1 << 6,
|
||||
RR2_V7 = 1 << 7,
|
||||
|
||||
// RR3 - Interrupt Pending bits (Channel A only)
|
||||
|
||||
RR3_CHANNEL_B_EXT_STAT_IP = 1 << 0,
|
||||
RR3_CHANNEL_B_TX_IP = 1 << 1,
|
||||
RR3_CHANNEL_B_RX_IP = 1 << 2,
|
||||
RR3_CHANNEL_A_EXT_STAT_IP = 1 << 3,
|
||||
RR3_CHANNEL_A_TX_IP = 1 << 4,
|
||||
RR3_CHANNEL_A_RX_IP = 1 << 5,
|
||||
// 0 = 1 << 6,
|
||||
// 0 = 1 << 7,
|
||||
|
||||
// RR6 - 14-bit frame byte count (LSB)
|
||||
|
||||
// RR7 - 14-bit frame byte count (MSB), frame status
|
||||
|
||||
RR7_FIFO_OVERFLOW_STATUS = 1 << 7,
|
||||
RR7_NORMAL = 0 << 7,
|
||||
RR7_FIFO_OVERFLOWED_DURING_OPERATION = 1 << 7,
|
||||
RR7_FIFO_DATA_AVAILABLE_STATUS = 1 << 6,
|
||||
RR7_STATUS_READS_COME_FROM_SCC = 0 << 6,
|
||||
RR7_STATUS_READS_COME_FROM_10_X_9_BIT_FIFO = 1 << 6,
|
||||
RR7_FRAME_BYTE_COUNT_MSB = 0x3F,
|
||||
|
||||
// RR8 - Receive Data // Receive buffer
|
||||
|
||||
// RR10 - Miscellaneous XMTR, RCVR status parameters
|
||||
|
||||
// 0 = 1 << 0,
|
||||
RR10_ON_LOOP = 1 << 1,
|
||||
// 0 = 1 << 2,
|
||||
// 0 = 1 << 3,
|
||||
RR10_LOOP_SENDING = 1 << 4,
|
||||
// 0 = 1 << 5,
|
||||
RR10_TWO_CLOCKS_MISSING = 1 << 6,
|
||||
RR10_ONE_CLOCK_MISSING = 1 << 7,
|
||||
|
||||
// RR12 - Lower byte of baud rate generator time constant
|
||||
|
||||
// RR13 - Upper byte of baud rate generator time constant
|
||||
|
||||
// RR15 - External/Status interrupt control information
|
||||
|
||||
RR15_SDLC_HDLC_ENHANCEMENT_STATUS = 1 << 0,
|
||||
RR15_ZERO_COUNT_IE = 1 << 1,
|
||||
RR15_10_X_19_BIT_FRAME_STATUS_FIFO_ENABLE_STATUS = 1 << 2,
|
||||
RR15_DCD_IE = 1 << 3,
|
||||
RR15_SYNC_HUNT_IE = 1 << 4,
|
||||
RR15_CTS_IE = 1 << 5,
|
||||
RR15_TX_UNDERRUN_EOM_IE = 1 << 6,
|
||||
RR15_BREAK_ABORT_IE = 1 << 7,
|
||||
|
||||
// WR0 - Command Register // Command Register, (Register Pointers), CRC initialization, resets for various modes
|
||||
|
||||
WR0_CRC_RESET_CODES = 3 << 6,
|
||||
WR0_RESET_NULL_CODE = 0 << 6,
|
||||
WR0_RESET_RX_CRC_CHECKER = 1 << 6,
|
||||
WR0_RESET_TX_CRC_GENERATOR = 2 << 6,
|
||||
WR0_RESET_TX_UNDERRUN_EOM_LATCH = 3 << 6,
|
||||
WR0_COMMAND_CODES = 7 << 3,
|
||||
WR0_COMMAND_NULL_CODE = 0 << 3,
|
||||
WR0_COMMAND_POINT_HIGH = 1 << 3, // add 8 to Register Selection Code
|
||||
WR0_COMMAND_RESET_EXT_STATUS_INTERRUPTS = 2 << 3,
|
||||
WR0_COMMAND_SEND_ABORT_SDLC = 3 << 3,
|
||||
WR0_COMMAND_ENABLE_INT_ON_NEXT_RX_CHARACTER = 4 << 3,
|
||||
WR0_COMMAND_RESET_TXINT_PENDING = 5 << 3,
|
||||
WR0_COMMAND_ERROR_RESET = 6 << 3,
|
||||
WR0_COMMAND_RESET_HIGHEST_IUS = 7 << 3,
|
||||
WR0_REGISTER_SELECTION_CODE = 7 << 0,
|
||||
WR0_REGISTER_0 = 0 << 0,
|
||||
WR0_REGISTER_1 = 1 << 0,
|
||||
WR0_REGISTER_2 = 2 << 0,
|
||||
WR0_REGISTER_3 = 3 << 0,
|
||||
WR0_REGISTER_4 = 4 << 0,
|
||||
WR0_REGISTER_5 = 5 << 0,
|
||||
WR0_REGISTER_6 = 6 << 0,
|
||||
WR0_REGISTER_7 = 7 << 0,
|
||||
|
||||
// WR1 - Transmit/Receive Interrupt and Data Transfer Mode Definition // Interrupt conditions, Wait/DMA request control
|
||||
|
||||
WR1_WAIT_DMA_REQUEST_ENABLE = 1 << 7,
|
||||
WR1_WAIT_DMA_REQUEST_FUNCTION = 1 << 6,
|
||||
WR1_WAIT_DMA_REQUEST_ON_RECEIVE_TRANSMIT = 1 << 5,
|
||||
WR1_RECEIVE_INTERRUPT_MODES = 3 << 3,
|
||||
WR1_RX_INT_DISABLE = 0 << 3,
|
||||
WR1_RX_INT_ON_FIRST_CHARACTER_OR_SPECIAL_CONDITION = 1 << 3,
|
||||
WR1_INT_ON_ALL_RX_CHARACTERS_OR_SPECIAL_CONDITION = 2 << 3,
|
||||
WR1_RX_INT_ON_SPECIAL_CONDITION_ONLY = 3 << 3,
|
||||
WR1_PARITY_IS_SPECIAL_CONDITION = 1 << 2,
|
||||
WR1_TX_INT_ENABLE = 1 << 1,
|
||||
WR1_EXT_INT_ENABLE = 1 << 0,
|
||||
|
||||
// WR2 - Interrupt Vector // Interrupt vector (access through either channel)
|
||||
|
||||
WR2_V0 = 1 << 0,
|
||||
WR2_V1 = 1 << 1,
|
||||
WR2_V2 = 1 << 2,
|
||||
WR2_V3 = 1 << 3,
|
||||
WR2_V4 = 1 << 4,
|
||||
WR2_V5 = 1 << 5,
|
||||
WR2_V6 = 1 << 6,
|
||||
WR2_V7 = 1 << 7,
|
||||
|
||||
// WR3 - Receive Parameters and Control // Receive/Control parameters, number of bits per character, Rx CRC enable
|
||||
|
||||
WR3_RECEIVER_BITS_PER_CHARACTER = 3 << 6,
|
||||
WR3_BITS_PER_CHARACTER_5 = 0 << 6,
|
||||
WR3_BITS_PER_CHARACTER_7 = 1 << 6,
|
||||
WR3_BITS_PER_CHARACTER_6 = 2 << 6,
|
||||
WR3_BITS_PER_CHARACTER_8 = 3 << 6,
|
||||
WR3_AUTO_ENABLES = 1 << 5,
|
||||
WR3_ENTER_HUNT_MODE = 1 << 4,
|
||||
WR3_RX_CRC_ENABLE = 1 << 3,
|
||||
WR3_ADDRESS_SEARCH_MODE_SDLC = 1 << 2,
|
||||
WR3_SYNC_CHARACTER_LOAD_INHIBIT = 1 << 1,
|
||||
WR3_RX_ENABLE = 1 << 0,
|
||||
|
||||
// WR4 - Transmit/Receiver Miscellaneous Parameters and Modes // Transmit/Receive miscellaneous parameters and codes, clock rate, number of sync characters, stop bits, parity
|
||||
|
||||
WR4_CLOCK_RATE = 3 << 6,
|
||||
WR4_X1_CLOCK_MODE = 0 << 6,
|
||||
WR4_X16_CLOCK_MODE = 1 << 6,
|
||||
WR4_X32_CLOCK_MODE = 2 << 6,
|
||||
WR4_X64_CLOCK_MODE = 3 << 6,
|
||||
WR4_SYNC_MODE = 3 << 4,
|
||||
WR4_MONOSYNC = 0 << 4,
|
||||
WR4_BISYNC = 1 << 4,
|
||||
WR4_SDLC_MODE = 2 << 4,
|
||||
WR4_EXTERNAL_SYNC_MODE = 3 << 4,
|
||||
WR4_STOP_BITS = 3 << 2,
|
||||
WR4_SYNC_MODES_ENABLE = 0 << 2,
|
||||
WR4_STOP_BITS_PER_CHARACTER_1 = 1 << 2,
|
||||
WR4_STOP_BITS_PER_CHARACTER_1_AND_HALF = 2 << 2,
|
||||
WR4_STOP_BITS_PER_CHARACTER_2 = 3 << 2,
|
||||
WR4_PARITY = 1 << 1,
|
||||
WR4_PARITY_ODD = 0 << 1,
|
||||
WR4_PARITY_EVEN = 1 << 1,
|
||||
WR4_PARITY_ENABLE = 1 << 0,
|
||||
|
||||
// WR5 - Transmit Parameter and Controls // Transmit parameters and control, number of Tx bits per character, Tx CRC enable
|
||||
|
||||
WR5_DTR = 1 << 7,
|
||||
WR5_TX_BITS_PER_CHARACTER = 3 << 5,
|
||||
WR5_TX_5_BITS_OR_LESS_PER_CHARACTER = 0 << 5,
|
||||
WR5_TX_7_BITS_PER_CHARACTER = 1 << 5,
|
||||
WR5_TX_6_BITS_PER_CHARACTER = 2 << 5,
|
||||
WR5_TX_8_BITS_PER_CHARACTER = 3 << 5,
|
||||
WR5_SEND_BREAK = 1 << 4,
|
||||
WR5_TX_ENABLE = 1 << 3,
|
||||
WR5_SDLC_CRC16 = 1 << 2,
|
||||
WR5_RTS = 1 << 1,
|
||||
WR5_TX_CRC_ENABLE = 1 << 0,
|
||||
|
||||
// WR6 - Sync Characters or SDLC Address Field // Sync character (1st byte) or SDLC address
|
||||
|
||||
// WR7 - Sync Character or SDLCFlag/SDLC Option Register // SYNC character (2nd byte) or SDLC flag
|
||||
|
||||
// WR8 - Transmit buffer
|
||||
|
||||
// WR9 - Master Interrupt Control // Master interrupt control and reset (accessed through either channel), reset bits, control interrupt daisy chain
|
||||
|
||||
WR9_RESET_COMMAND_BITS = 3 << 6,
|
||||
WR9_NO_RESET = 0 << 6,
|
||||
WR9_CHANNEL_RESET_B = 1 << 6,
|
||||
WR9_CHANNEL_RESET_A = 2 << 6,
|
||||
WR9_FORCE_HARDWARE_RESET = 3 << 6,
|
||||
WR9_INTERRUPT_CONTROL_BITS = 0x3F,
|
||||
WR9_INTERRUPT_MASKING_WITHOUT_INTACK = 1 << 5,
|
||||
WR9_STATUS_HIGH_STATUS_LOW = 1 << 4,
|
||||
WR9_MASTER_INTERRUPT_ENABLE = 1 << 3,
|
||||
WR9_DISABLE_LOWER_CHAIN = 1 << 2,
|
||||
WR9_NO_VECTOR = 1 << 1,
|
||||
WR9_VECTOR_INCLUDES_STATUS = 1 << 0,
|
||||
|
||||
// WR10 - Miscellaneous Transmitter/Receiver Control Bits // Miscellaneous transmitter/receiver control bits, NRZI, NRZ, FM encoding, CRC reset
|
||||
|
||||
WR10_CRC_PRESET = 1 << 7,
|
||||
WR10_DATA_ENCODING = 3 << 5,
|
||||
WR10_NRZ = 0 << 5,
|
||||
WR10_NRZI = 1 << 5,
|
||||
WR10_FM1 = 2 << 5,
|
||||
WR10_FM0 = 3 << 5,
|
||||
WR10_GO_ACTIVE_ON_POLL = 1 << 4,
|
||||
WR10_MARK_FLAG_IDLE = 1 << 3,
|
||||
WR10_FLAG_IDLE = 0 << 3,
|
||||
WR10_MARK_IDLE = 1 << 3,
|
||||
WR10_ABORT_FLAG_ON_UNDERRUN = 1 << 2,
|
||||
WR10_FLAG_ON_UNDERRUN = 0 << 2,
|
||||
WR10_ABORT_ON_UNDERRUN = 1 << 2,
|
||||
WR10_LOOP_MODE = 1 << 1,
|
||||
WR10_SYNC_SIZE = 1 << 0,
|
||||
WR10_SYNC_6_BIT = 0 << 0,
|
||||
WR10_SYNC_8_BIT = 1 << 0,
|
||||
|
||||
// WR11 - Clock Mode Control // Clock mode control, source of Rx and Tx clocks
|
||||
|
||||
WR11_RTXC_XTAL_NO_XTAL = 1 << 7,
|
||||
WR11_RTXC_NO_XTAL = 0 << 7,
|
||||
WR11_RTXC_XTAL = 1 << 7,
|
||||
WR11_RECEIVER_CLOCK = 3 << 5,
|
||||
WR11_RECEIVE_CLOCK_RTXC_PIN = 0 << 5,
|
||||
WR11_RECEIVE_CLOCK_TRXC_PIN = 1 << 5,
|
||||
WR11_RECEIVE_CLOCK_BR_GENERATOR_OUTPUT = 2 << 5,
|
||||
WR11_RECEIVE_CLOCK_DPLL_OUTPUT = 3 << 5,
|
||||
WR11_TRANSMIT_CLOCK = 3 << 3,
|
||||
WR11_TRANSMIT_CLOCK_RTXC_PIN = 0 << 3,
|
||||
WR11_TRANSMIT_CLOCK_TRXC_PIN = 1 << 3,
|
||||
WR11_TRANSMIT_CLOCK_BR_GENERATOR_OUTPUT = 2 << 3,
|
||||
WR11_TRANSMIT_CLOCK_DPLL_OUTPUT = 3 << 3,
|
||||
WR11_TRXC_O_I = 1 << 2,
|
||||
WR11_TRXC_OUTPUT_SOURCE = 3 << 0,
|
||||
WR11_TRXC_OUT_XTAL_OUTPUT = 0 << 0,
|
||||
WR11_TRXC_OUT_TRANSMIT_CLOCK = 1 << 0,
|
||||
WR11_TRXC_OUT_BR_GENERATOR_OUTPUT = 2 << 0,
|
||||
WR11_TRXC_OUT_DPLL_OUTPUT = 3 << 0,
|
||||
|
||||
// WR12 - Lower Byte of Baud Rate Generator Time Constant
|
||||
|
||||
// WR13 - Upper Byte of Baud Rate Generator Time Constant
|
||||
|
||||
// WR14 - Miscellaneous Control Bits // Miscellaneous control bits: baud rate generator, Phase-Locked Loop control, auto echo, local loopback
|
||||
|
||||
WR14_DPLL_COMMAND_BITS = 7 << 5,
|
||||
WR14_DPLL_NULL_COMMAND = 0 << 5,
|
||||
WR14_DPLL_ENTER_SEARCH_MODE = 1 << 5,
|
||||
WR14_DPLL_RESET_MISSING_CLOCK = 2 << 5,
|
||||
WR14_DPLL_DISABLE_DPLL = 3 << 5,
|
||||
WR14_DPLL_SET_SOURCE_BR_GENERATOR = 4 << 5,
|
||||
WR14_DPLL_SET_SOURCE_RTXC = 5 << 5,
|
||||
WR14_DPLL_SET_FM_MODE = 6 << 5,
|
||||
WR14_DPLL_SET_NRZI_MODE = 7 << 5,
|
||||
WR14_LOCAL_LOOPBACK = 1 << 4,
|
||||
WR14_AUTO_ECHO = 1 << 3,
|
||||
WR14_DTR_REQUEST_FUNCTION = 1 << 2,
|
||||
WR14_BR_GENERATOR_SOURCE = 1 << 1,
|
||||
WR14_BR_GENERATOR_ENABLE = 1 << 0,
|
||||
|
||||
// WR15 - External/Status Interrupt Control // External/Status interrupt control information-control external conditions causing interrupts
|
||||
|
||||
WR15_SDLC_HDLC_ENHANCEMENT_ENABLE = 1 << 0,
|
||||
WR15_ZERO_COUNT_IE = 1 << 1,
|
||||
WR15_10_X_19_BIT_FRAME_STATUS_FIFO_ENABLE = 1 << 2,
|
||||
WR15_DCD_IE = 1 << 3,
|
||||
WR15_SYNC_HUNT_IE = 1 << 4,
|
||||
WR15_CTS_IE = 1 << 5,
|
||||
WR15_TX_UNDERRUN_EOM_IE = 1 << 6,
|
||||
WR15_BREAK_ABORT_IE = 1 << 7,
|
||||
};
|
||||
|
||||
#endif // Z85C30_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -53,7 +53,7 @@ void AwacsBase::set_sample_rate(int sr_id) {
|
||||
} else {
|
||||
this->cur_sample_rate = this->sr_table[sr_id];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void AwacsBase::dma_out_start() {
|
||||
int err;
|
||||
@@ -103,8 +103,7 @@ void AwacsBase::dma_out_pause() {
|
||||
static const char sound_input_data[2048] = {0};
|
||||
static int sound_in_status = 0x10;
|
||||
|
||||
void AwacsBase::dma_in_data()
|
||||
{
|
||||
void AwacsBase::dma_in_data() {
|
||||
// transfer data from sound input device
|
||||
this->dma_in_ch->push_data(sound_input_data, sizeof(sound_input_data));
|
||||
|
||||
|
||||
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user