mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
217
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd6cc0f388 | ||
|
|
9291a093d5 | ||
|
|
3db6d07060 | ||
|
|
7fbbde0750 | ||
|
|
87054deb3d | ||
|
|
49a5951647 | ||
|
|
84ded9fc7a | ||
|
|
a01cd9c993 | ||
|
|
fc44cdcc83 | ||
|
|
958d3ee96a | ||
|
|
c2a63bab09 | ||
|
|
392fa87ba4 | ||
|
|
87b8e1759a | ||
|
|
cb946e41b5 | ||
|
|
3f20d0a700 | ||
|
|
767735251b | ||
|
|
6a756df5e3 | ||
|
|
281aaa1902 | ||
|
|
c7f21040ae | ||
|
|
a28ef677fd | ||
|
|
d70adac564 | ||
|
|
c0cd6eb38f | ||
|
|
9329d56d83 | ||
|
|
7919cd0590 | ||
|
|
fb277945c2 | ||
|
|
7daf4aa317 | ||
|
|
f194887d34 | ||
|
|
46549d68a2 | ||
|
|
331b93d4d6 | ||
|
|
3c7fc58ac0 | ||
|
|
c7544d9c2f | ||
|
|
00dd99d851 | ||
|
|
7d7a4b453f | ||
|
|
7ce94a6ab5 | ||
|
|
061b061813 | ||
|
|
9251745d6f | ||
|
|
2f725fe3e4 | ||
|
|
e53296f7a9 | ||
|
|
7c47b9c1e7 | ||
|
|
e66979d30f | ||
|
|
9caef55c19 | ||
|
|
2a9d364b1b | ||
|
|
3eb2d3cba7 | ||
|
|
bde5b71167 | ||
|
|
89e79d05cb | ||
|
|
bb0ca2ac40 | ||
|
|
5672a154cb | ||
|
|
2d65ed47fc | ||
|
|
e344b089b3 | ||
|
|
d5960ca70b | ||
|
|
2106c4ca47 | ||
|
|
ad6a2a9f17 | ||
|
|
1922a20cdd | ||
|
|
f605c484dd | ||
|
|
69c357b70f | ||
|
|
c313a9c8bb | ||
|
|
03e58dac35 | ||
|
|
983e278498 | ||
|
|
3ca7a78a37 | ||
|
|
0f55877137 | ||
|
|
b4d399ffa2 | ||
|
|
8c9f23daf4 | ||
|
|
22827642e4 | ||
|
|
e9fcc51b93 | ||
|
|
f104a634ea | ||
|
|
81ea96a058 | ||
|
|
e052eb4a87 | ||
|
|
d2cd43fcb1 | ||
|
|
4b16cb826e | ||
|
|
40d0aa70da | ||
|
|
212cd58f40 | ||
|
|
5b54cd69ef | ||
|
|
501f24f0d3 | ||
|
|
2a79c9a63c | ||
|
|
f0b03aa1a2 | ||
|
|
de8d6487f9 | ||
|
|
ed56d018b0 | ||
|
|
8c13c30162 | ||
|
|
84e111290f | ||
|
|
1c77057860 | ||
|
|
738e2d3bd1 | ||
|
|
ea5b0d9f52 | ||
|
|
16d9e6c681 | ||
|
|
9ce15be106 | ||
|
|
e3a4539b02 | ||
|
|
c5f45c6f9a | ||
|
|
a8f400287a | ||
|
|
089645e830 | ||
|
|
6d80ead5b1 | ||
|
|
29dcd11648 | ||
|
|
62070659f8 | ||
|
|
87ccfaed53 | ||
|
|
4f3dd797be | ||
|
|
22a15f4780 | ||
|
|
48a65279e1 | ||
|
|
6abe86589b | ||
|
|
07a4166eef | ||
|
|
094d9a9c2f | ||
|
|
4da95a66d7 | ||
|
|
592d32017e | ||
|
|
7d8f4d4e61 | ||
|
|
a5ddb51a3b | ||
|
|
05330bc942 | ||
|
|
6f9ee10de5 | ||
|
|
0c1c59ffa7 | ||
|
|
048b4f5f20 | ||
|
|
085877a8bf | ||
|
|
bc59bf7c43 | ||
|
|
ed6c316c82 | ||
|
|
31b5290ac9 | ||
|
|
0375b6a687 | ||
|
|
d545780071 | ||
|
|
e7e28b4497 | ||
|
|
baa7f8b211 | ||
|
|
2f4a3b955e | ||
|
|
19ca37c4ba | ||
|
|
a4eb658309 | ||
|
|
508ef2eaa9 | ||
|
|
a5ef814ec4 | ||
|
|
ace19c0bdf | ||
|
|
3a9ed2671c | ||
|
|
3c787a87cd | ||
|
|
ce70b0f096 | ||
|
|
a0b43754a7 | ||
|
|
1adbf90e21 | ||
|
|
aa0f43d89f | ||
|
|
478ca1065f | ||
|
|
7628ec92c0 | ||
|
|
7f0acaf3d3 | ||
|
|
5961552ed9 | ||
|
|
2141a72b87 | ||
|
|
9683c660bc | ||
|
|
d8397906c2 | ||
|
|
fd0f8e2ef5 | ||
|
|
60f84ef0d9 | ||
|
|
2f8694e57c | ||
|
|
593230f326 | ||
|
|
680b437b74 | ||
|
|
3189876d41 | ||
|
|
2539faef7e | ||
|
|
42184213e9 | ||
|
|
bb3f4e596e | ||
|
|
014eefdf7e | ||
|
|
d8f7588693 | ||
|
|
2bac606365 | ||
|
|
df8ea1b276 | ||
|
|
9210244c0c | ||
|
|
358f018815 | ||
|
|
14d3874382 | ||
|
|
b230299076 | ||
|
|
79e3d398ba | ||
|
|
2f3938c23f | ||
|
|
0cc1ac5731 | ||
|
|
68b8da2182 | ||
|
|
18a19cd52f | ||
|
|
282940e580 | ||
|
|
dbbaf13a78 | ||
|
|
99641b1b5e | ||
|
|
5cba9c1dae | ||
|
|
180cb0d25f | ||
|
|
df39a59190 | ||
|
|
f0315e98ee | ||
|
|
6c6247b94f | ||
|
|
f61277e46d | ||
|
|
da3a6c71fd | ||
|
|
acfa09af65 | ||
|
|
54fcfca8e9 | ||
|
|
a775007d3a | ||
|
|
2be8e7b542 | ||
|
|
0e83ffe435 | ||
|
|
0c202b0c2d | ||
|
|
81b3c3c4a0 | ||
|
|
7be6cb30ac | ||
|
|
6124dfd897 | ||
|
|
b81de4af48 | ||
|
|
2b19b0b237 | ||
|
|
f417df0630 | ||
|
|
1fe9ffe3e5 | ||
|
|
dc58386237 | ||
|
|
6cc88d3b02 | ||
|
|
5d2f3ca3c0 | ||
|
|
3b29ff9514 | ||
|
|
fc50e3c4f6 | ||
|
|
2df2d089d7 | ||
|
|
4c0c32c02c | ||
|
|
90b2eb712a | ||
|
|
27f5d981da | ||
|
|
ce9e8e7244 | ||
|
|
a3b17d46ce | ||
|
|
246a7f2082 | ||
|
|
2eba8acc23 | ||
|
|
c81c00f918 | ||
|
|
0ca03be001 | ||
|
|
55ea643974 | ||
|
|
599659495b | ||
|
|
9efea80e43 | ||
|
|
4ccfb5d527 | ||
|
|
4f59407cd0 | ||
|
|
2f2c9aadcb | ||
|
|
d21515d964 | ||
|
|
b28549825d | ||
|
|
14ef7564cd | ||
|
|
f04ce09a7d | ||
|
|
2869755819 | ||
|
|
353035e9ca | ||
|
|
660d227ac7 | ||
|
|
b9dcfef551 | ||
|
|
6b74e358dc | ||
|
|
8094fb30f6 | ||
|
|
f753bb1911 | ||
|
|
67596ca49c | ||
|
|
59da71884e | ||
|
|
5d57086795 | ||
|
|
3be46aa44d | ||
|
|
39a643aff6 | ||
|
|
f8bde236b8 | ||
|
|
0ab9380be3 |
No files matched your search
@@ -0,0 +1,78 @@
|
||||
Language: Cpp
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: false
|
||||
#AlignConsecutiveMacros: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
#AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
#BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 100
|
||||
CompactNamespaces: true
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
FixNamespaceComments: true
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: None
|
||||
PenaltyBreakAssignment: 50
|
||||
PenaltyBreakBeforeFirstCallParameter: 0
|
||||
PenaltyBreakComment: 100
|
||||
PenaltyBreakFirstLessLess: 200
|
||||
PenaltyBreakString: 100
|
||||
#PenaltyBreakTemplateDeclaration: 0
|
||||
PenaltyExcessCharacter: 10
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
#SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
#SpaceBeforeCpp11BracedList: true
|
||||
#SpaceBeforeCtorInitializerColon: false
|
||||
#SpaceBeforeInheritanceColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
#SpaceBeforeRangeBasedForLoopColon: false
|
||||
#SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 4
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
#Standard: c++17
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@@ -1,3 +1,7 @@
|
||||
[submodule "thirdparty/cubeb"]
|
||||
path = thirdparty/cubeb
|
||||
url = https://github.com/DingusDevOrg/cubeb.git
|
||||
[submodule "thirdparty/capstone"]
|
||||
path = thirdparty/capstone
|
||||
url = https://github.com/maximumspatium/capstone.git
|
||||
branch = next
|
||||
+111
-23
@@ -11,12 +11,57 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
if (NOT WIN32)
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
else()
|
||||
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/SDL2/include/")
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
|
||||
option(DPPC_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
# Build capstone as static library.
|
||||
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
|
||||
|
||||
# Turn off anything unnecessary.
|
||||
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_CSTOOL OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_DIET OFF CACHE BOOL "")
|
||||
set(CAPSTONE_OSXKERNEL_SUPPORT OFF CACHE BOOL "")
|
||||
|
||||
# Disable unused Capstone architectures.
|
||||
set(CAPSTONE_ARM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_ARM64_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_MIPS_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_PPC_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_SPARC_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_SYSZ_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_XCORE_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_X86_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_TMS320C64X_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_M680X_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_EVM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_MOS65XX_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_WASM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BPF_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_RISCV_SUPPORT OFF CACHE BOOL "")
|
||||
|
||||
ADD_DEFINITIONS(-DENABLE_68K_DEBUGGER)
|
||||
|
||||
add_subdirectory(thirdparty/capstone EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/execution")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
#set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "Build libsoundio example programs")
|
||||
@@ -32,10 +77,16 @@ set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc"
|
||||
"${PROJECT_SOURCE_DIR}/debugger"
|
||||
"${PROJECT_SOURCE_DIR}/utils"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/CLI11/"
|
||||
# ${SDL2_INCLUDE_DIRS})
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
# "${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
# ${LIBSOUNDIO_HEADERS})
|
||||
@@ -52,7 +103,9 @@ file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
|
||||
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
@@ -61,30 +114,65 @@ target_link_libraries(dingusppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/S
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES})
|
||||
target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES})
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
endif()
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
|
||||
@@ -8,8 +8,7 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs,
|
||||
including those of the PowerMac G3 Beige.
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the PowerMac G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
@@ -21,23 +20,46 @@ This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
|
||||
-realtime
|
||||
```
|
||||
-r, --realtime
|
||||
```
|
||||
|
||||
Run the emulator in runtime.
|
||||
|
||||
-debugger
|
||||
```
|
||||
-d, --debugger
|
||||
```
|
||||
|
||||
Enter the interactive debugger.
|
||||
|
||||
You must also provide config.txt.
|
||||
```
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
|
||||
As of now, only the Power Macintosh G3 Beige is implemented.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You'll need to install development tools first.
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you'll need to run
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
```
|
||||
mkdir build
|
||||
@@ -47,9 +69,12 @@ make dingusppc
|
||||
```
|
||||
You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
Due to the incomplete status of the program at this time, only Loguru is needed to compile the program. It is already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
Future versions may drop SDL 2 as a requirement.
|
||||
|
||||
Future versions will include SDL 2 as a requirement.
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
0x3884FFFE, 0x38630002, 0x5486F0BF, 0x7CA50114, 0x41820070, 0x70C60003,
|
||||
0x41820014, 0x7CC903A6, 0x84030004, 0x7CA50114, 0x4200FFF8, 0x5486E13F,
|
||||
0x41820050, 0x80030004, 0x7CC903A6, 0x80C30008, 0x7CA50114, 0x80E3000C,
|
||||
0x7CA53114, 0x85030010, 0x7CA53914, 0x42400028, 0x80030004, 0x7CA54114,
|
||||
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
|
||||
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
|
||||
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::init(argc, argv);
|
||||
|
||||
MPC106* grackle_obj = new MPC106;
|
||||
|
||||
/* we need some RAM */
|
||||
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||
LOG_F(ERROR, "Could not create RAM region");
|
||||
delete(grackle_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mem_write_dword(i*4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mem_write_byte(0x1000+i, rand() % 256);
|
||||
}
|
||||
|
||||
/* 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_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", 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]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
|
||||
+386
-657
File diff suppressed because it is too large.
Load diff
+417
-429
File diff suppressed because it is too large.
Load diff
+6
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,17 +26,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
typedef struct PPCDisasmContext {
|
||||
uint32_t instr_addr;
|
||||
uint32_t instr_code;
|
||||
uint32_t instr_addr;
|
||||
uint32_t instr_code;
|
||||
std::string instr_str;
|
||||
bool simplified; /* true if we should output simplified mnemonics */
|
||||
bool simplified; /* true if we should output simplified mnemonics */
|
||||
} PPCDisasmContext;
|
||||
|
||||
std::string disassemble_single(PPCDisasmContext *ctx);
|
||||
std::string disassemble_single(PPCDisasmContext* ctx);
|
||||
|
||||
int test_ppc_disasm(void);
|
||||
|
||||
/** sign-extend an integer. */
|
||||
#define SIGNEXT(x, sb) ((x) | (((x) & (1 << (sb))) ? ~((1 << (sb))-1) : 0))
|
||||
#define SIGNEXT(x, sb) ((x) | (((x) & (1 << (sb))) ? ~((1 << (sb)) - 1) : 0))
|
||||
|
||||
#endif /* PPCDISASM_H */
|
||||
+147
-210
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,31 +22,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PPCEMU_H
|
||||
#define PPCEMU_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <setjmp.h>
|
||||
#include "endianswap.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
//Uncomment this to help debug the emulator further
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
|
||||
// Uncomment this to help debug the emulator further
|
||||
//#define EXHAUSTIVE_DEBUG 1
|
||||
|
||||
//Uncomment this to have a more graceful approach to illegal opcodes
|
||||
// Uncomment this to have a more graceful approach to illegal opcodes
|
||||
//#define ILLEGAL_OP_SAFE 1
|
||||
|
||||
//Uncomment this to use GCC built-in functions.
|
||||
//#define USE_GCC_BUILTINS 1
|
||||
// Uncomment this to use GCC built-in functions.
|
||||
#define USE_GCC_BUILTINS 1
|
||||
|
||||
//Uncomment this to use Visual Studio built-in functions.
|
||||
// Uncomment this to use Visual Studio built-in functions.
|
||||
//#define USE_VS_BUILTINS 1
|
||||
|
||||
//#define CPU_PROFILING // enable CPU profiling
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
uint64_t int64_r; // double integer representation
|
||||
double dbl64_r; // double floating-point representation
|
||||
uint64_t int64_r; // double integer representation
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +69,7 @@ fpscr = FP Status and Condition Register
|
||||
|
||||
typedef struct struct_ppc_state {
|
||||
FPR_storage fpr[32];
|
||||
uint32_t pc; //Referred as the CIA in the PPC manual
|
||||
uint32_t pc; // Referred as the CIA in the PPC manual
|
||||
uint32_t gpr[32];
|
||||
uint32_t cr;
|
||||
uint32_t fpscr;
|
||||
@@ -73,7 +77,7 @@ typedef struct struct_ppc_state {
|
||||
uint32_t spr[1024];
|
||||
uint32_t msr;
|
||||
uint32_t sr[16];
|
||||
bool reserve; //reserve bit used for lwarx and stcwx
|
||||
bool reserve; // reserve bit used for lwarx and stcwx
|
||||
} SetPRS;
|
||||
|
||||
extern SetPRS ppc_state;
|
||||
@@ -94,10 +98,7 @@ enum SPR : int {
|
||||
};
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum TBR : int {
|
||||
TBL = 0,
|
||||
TBU = 1
|
||||
};
|
||||
enum TBR : int { TBL = 0, TBU = 1 };
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
enum PPC_VER : uint32_t {
|
||||
@@ -147,18 +148,15 @@ SUPERVISOR MODEL
|
||||
536 - 543 are the Data BAT registers
|
||||
**/
|
||||
|
||||
extern uint32_t opcode_value; //used for interpreting opcodes
|
||||
extern uint64_t timebase_counter; //used for storing time base value
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
extern uint64_t timebase_counter; // used for storing time base value
|
||||
|
||||
//Additional steps to prevent overflow?
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
extern int32_t simult_result;
|
||||
extern uint32_t uiadd_result;
|
||||
extern uint32_t uimult_result;
|
||||
|
||||
extern int32_t word_copy_location;
|
||||
extern uint32_t strwrd_replace_value;
|
||||
|
||||
extern uint32_t crf_d;
|
||||
extern uint32_t crf_s;
|
||||
extern uint32_t reg_s;
|
||||
@@ -176,19 +174,19 @@ extern uint32_t rot_mb;
|
||||
extern uint32_t rot_me;
|
||||
extern uint32_t uimm;
|
||||
extern uint32_t grab_sr;
|
||||
extern uint32_t grab_inb; //This is for grabbing the number of immediate bytes for loading and storing
|
||||
extern uint32_t grab_inb; // This is for grabbing the number of immediate bytes for loading and storing
|
||||
extern uint32_t ppc_to;
|
||||
extern int32_t simm;
|
||||
extern int32_t adr_li;
|
||||
extern int32_t br_bd;
|
||||
|
||||
//Used for GP calcs
|
||||
// Used for GP calcs
|
||||
extern uint32_t ppc_result_a;
|
||||
extern uint32_t ppc_result_b;
|
||||
extern uint32_t ppc_result_c;
|
||||
extern uint32_t ppc_result_d;
|
||||
|
||||
//Used for FP calcs
|
||||
// Used for FP calcs
|
||||
extern uint64_t ppc_result64_a;
|
||||
extern uint64_t ppc_result64_b;
|
||||
extern uint64_t ppc_result64_c;
|
||||
@@ -197,12 +195,76 @@ extern uint64_t ppc_result64_d;
|
||||
|
||||
/* The precise end of a basic block. */
|
||||
enum class BB_end_kind {
|
||||
BB_NONE = 0, /* no basic block end is reached */
|
||||
BB_NONE = 0, /* no basic block end is reached */
|
||||
BB_BRANCH = 1, /* a branch instruction is encountered */
|
||||
BB_EXCEPTION, /* an exception is occured */
|
||||
BB_RFI /* the rfi instruction is encountered */
|
||||
};
|
||||
|
||||
enum CR_select : int32_t {
|
||||
CR0_field = (0xF << 28),
|
||||
CR1_field = (0xF << 24),
|
||||
};
|
||||
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
CR_GT = 30,
|
||||
CR_LT = 31 };
|
||||
|
||||
enum CR1_bit : uint32_t {
|
||||
CR1_OX = 24,
|
||||
CR1_VX,
|
||||
CR1_FEX,
|
||||
CR1_FX,
|
||||
};
|
||||
|
||||
enum FPSCR : uint32_t {
|
||||
RN = 0x3,
|
||||
NI = 0x4,
|
||||
XE = 0x8,
|
||||
ZE = 0x10,
|
||||
UE = 0x20,
|
||||
OE = 0x40,
|
||||
VE = 0x80,
|
||||
VXCVI = 0x100,
|
||||
VXSQRT = 0x200,
|
||||
VXSOFT = 0x400,
|
||||
FPRF = 0x1F000,
|
||||
FPCC_FUNAN = 0x10000,
|
||||
FPCC_NEG = 0x8000,
|
||||
FPCC_POS = 0x4000,
|
||||
FPCC_ZERO = 0x2000,
|
||||
FPCC_FPRCD = 0x1000,
|
||||
FI = 0x20000,
|
||||
FR = 0x40000,
|
||||
VXVC = 0x80000,
|
||||
VXIMZ = 0x100000,
|
||||
VXZDZ = 0x200000,
|
||||
VXIDI = 0x400000,
|
||||
VXISI = 0x800000,
|
||||
VXSNAN = 0x1000000,
|
||||
XX = 0x2000000,
|
||||
ZX = 0x4000000,
|
||||
UX = 0x8000000,
|
||||
OX = 0x10000000,
|
||||
VX = 0x20000000,
|
||||
FEX = 0x40000000,
|
||||
FX = 0x80000000
|
||||
};
|
||||
|
||||
//for inf and nan checks
|
||||
enum FPOP : int {
|
||||
DIV = 0x12,
|
||||
SUB = 0x14,
|
||||
ADD = 0x15,
|
||||
MUL = 0x19,
|
||||
FMSUB = 0x1C,
|
||||
FMADD = 0x1D,
|
||||
FNMSUB = 0x1E,
|
||||
FNMADD = 0x1F,
|
||||
};
|
||||
|
||||
/** PowerPC exception types. */
|
||||
enum class Except_Type {
|
||||
EXC_SYSTEM_RESET = 1,
|
||||
@@ -215,10 +277,18 @@ enum class Except_Type {
|
||||
EXC_NO_FPU,
|
||||
EXC_DECR,
|
||||
EXC_SYSCALL = 12,
|
||||
EXC_TRACE = 13
|
||||
EXC_TRACE = 13
|
||||
};
|
||||
|
||||
//extern bool bb_end;
|
||||
/** Programm Exception subclasses. */
|
||||
enum Exc_Cause : uint32_t {
|
||||
FPU_OFF = 1 << (31 - 11),
|
||||
ILLEGAL_OP = 1 << (31 - 12),
|
||||
NOT_ALLOWED = 1 << (31 - 13),
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
// extern bool bb_end;
|
||||
extern BB_end_kind bb_kind;
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
@@ -228,27 +298,35 @@ extern bool grab_return;
|
||||
|
||||
extern bool power_on;
|
||||
|
||||
extern bool is_601; //For PowerPC 601 Emulation
|
||||
extern bool is_gekko; //For GameCube Emulation
|
||||
extern bool is_altivec; //For Altivec Emulation
|
||||
extern bool is_64bit; //For PowerPC G5 Emulation
|
||||
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 bool rc_flag; // Record flag
|
||||
extern bool oe_flag; // Overflow flag
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
//Profiling Stats
|
||||
extern uint32_t mmu_translations_num;
|
||||
extern uint32_t exceptions_performed;
|
||||
extern uint32_t supervisor_inst_num;
|
||||
// Profiling Stats
|
||||
#ifdef CPU_PROFILING
|
||||
extern uint64_t num_executed_instrs;
|
||||
extern uint64_t num_supervisor_instrs;
|
||||
extern uint64_t num_int_loads;
|
||||
extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
//Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase *mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version);
|
||||
extern void ppc_mmu_init(uint32_t cpu_version);
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_opcode4();
|
||||
[[noreturn]] void ppc_illegalop();
|
||||
[[noreturn]] void ppc_fpu_off();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
void ppc_opcode19();
|
||||
@@ -256,7 +334,8 @@ void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
extern bool ppc_confirm_inf_nan(uint64_t input_a, uint64_t input_b, bool is_single, uint32_t op);
|
||||
void initialize_ppc_opcode_tables();
|
||||
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
|
||||
@@ -274,33 +353,24 @@ extern void ppc_grab_regsdauimm();
|
||||
extern void ppc_grab_regsasimm();
|
||||
extern void ppc_grab_regssauimm();
|
||||
|
||||
extern void ppc_grab_regsfpdb(bool int_rep);
|
||||
extern void ppc_grab_regsfpdab(bool int_rep);
|
||||
extern void ppc_grab_regsfpdia(bool int_rep);
|
||||
extern void ppc_grab_regsfpdiab(bool int_rep);
|
||||
extern void ppc_grab_regsfpsia(bool int_rep);
|
||||
extern void ppc_grab_regsfpsiab(bool int_rep);
|
||||
|
||||
extern void ppc_store_result_regd();
|
||||
extern void ppc_store_result_rega();
|
||||
extern void ppc_store_sfpresult(bool int_rep);
|
||||
extern void ppc_store_dfpresult(bool int_rep);
|
||||
|
||||
void ppc_changecrf0(uint32_t set_result);
|
||||
void ppc_fp_changecrf1();
|
||||
|
||||
void ppc_tbr_update();
|
||||
|
||||
/* Exception handlers. */
|
||||
[[noreturn]] 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);
|
||||
[[noreturn]] 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);
|
||||
|
||||
//MEMORY DECLARATIONS
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
|
||||
//The functions used by the PowerPC processor
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
namespace dppc_interpreter {
|
||||
extern void ppc_bcctr();
|
||||
extern void ppc_bcctrl();
|
||||
extern void ppc_bclr();
|
||||
@@ -316,33 +386,15 @@ extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
extern void ppc_add();
|
||||
extern void ppc_adddot();
|
||||
extern void ppc_addo();
|
||||
extern void ppc_addodot();
|
||||
extern void ppc_addc();
|
||||
extern void ppc_addcdot();
|
||||
extern void ppc_addco();
|
||||
extern void ppc_addcodot();
|
||||
extern void ppc_adde();
|
||||
extern void ppc_addedot();
|
||||
extern void ppc_addeo();
|
||||
extern void ppc_addeodot();
|
||||
extern void ppc_addme();
|
||||
extern void ppc_addmedot();
|
||||
extern void ppc_addmeo();
|
||||
extern void ppc_addmeodot();
|
||||
extern void ppc_addze();
|
||||
extern void ppc_addzedot();
|
||||
extern void ppc_addzeo();
|
||||
extern void ppc_addzeodot();
|
||||
extern void ppc_and();
|
||||
extern void ppc_anddot();
|
||||
extern void ppc_andc();
|
||||
extern void ppc_andcdot();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
extern void ppc_cntlzw();
|
||||
extern void ppc_cntlzwdot();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
@@ -350,20 +402,13 @@ extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
extern void ppc_divw();
|
||||
extern void ppc_divwdot();
|
||||
extern void ppc_divwo();
|
||||
extern void ppc_divwodot();
|
||||
extern void ppc_divwu();
|
||||
extern void ppc_divwudot();
|
||||
extern void ppc_divwuo();
|
||||
extern void ppc_divwuodot();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
extern void ppc_eqv();
|
||||
extern void ppc_eqvdot();
|
||||
extern void ppc_extsb();
|
||||
extern void ppc_extsbdot();
|
||||
extern void ppc_extsh();
|
||||
extern void ppc_extshdot();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhzux();
|
||||
@@ -380,33 +425,17 @@ extern void ppc_lwzx();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
extern void ppc_mulhwu();
|
||||
extern void ppc_mulhwudot();
|
||||
extern void ppc_mulhw();
|
||||
extern void ppc_mulhwdot();
|
||||
extern void ppc_mullw();
|
||||
extern void ppc_mullwdot();
|
||||
extern void ppc_mullwo();
|
||||
extern void ppc_mullwodot();
|
||||
extern void ppc_nand();
|
||||
extern void ppc_nanddot();
|
||||
extern void ppc_neg();
|
||||
extern void ppc_negdot();
|
||||
extern void ppc_nego();
|
||||
extern void ppc_negodot();
|
||||
extern void ppc_nor();
|
||||
extern void ppc_nordot();
|
||||
extern void ppc_or();
|
||||
extern void ppc_ordot();
|
||||
extern void ppc_orc();
|
||||
extern void ppc_orcdot();
|
||||
extern void ppc_slw();
|
||||
extern void ppc_slwdot();
|
||||
extern void ppc_srw();
|
||||
extern void ppc_srwdot();
|
||||
extern void ppc_sraw();
|
||||
extern void ppc_srawdot();
|
||||
extern void ppc_srawi();
|
||||
extern void ppc_srawidot();
|
||||
extern void ppc_stbx();
|
||||
extern void ppc_stbux();
|
||||
extern void ppc_stfiwx();
|
||||
@@ -418,25 +447,10 @@ extern void ppc_stwcx();
|
||||
extern void ppc_stwux();
|
||||
extern void ppc_stwbrx();
|
||||
extern void ppc_subf();
|
||||
extern void ppc_subfdot();
|
||||
extern void ppc_subfo();
|
||||
extern void ppc_subfodot();
|
||||
extern void ppc_subfc();
|
||||
extern void ppc_subfcdot();
|
||||
extern void ppc_subfco();
|
||||
extern void ppc_subfcodot();
|
||||
extern void ppc_subfe();
|
||||
extern void ppc_subfedot();
|
||||
extern void ppc_subfeo();
|
||||
extern void ppc_subfeodot();
|
||||
extern void ppc_subfme();
|
||||
extern void ppc_subfmedot();
|
||||
extern void ppc_subfmeo();
|
||||
extern void ppc_subfmeodot();
|
||||
extern void ppc_subfze();
|
||||
extern void ppc_subfzedot();
|
||||
extern void ppc_subfzeo();
|
||||
extern void ppc_subfzeodot();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
@@ -445,7 +459,6 @@ extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
extern void ppc_xor();
|
||||
extern void ppc_xordot();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
@@ -457,6 +470,7 @@ 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();
|
||||
@@ -466,15 +480,10 @@ extern void ppc_mtspr();
|
||||
extern void ppc_mtfsb0();
|
||||
extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
extern void ppc_mtfsb0dot();
|
||||
extern void ppc_mtfsb1dot();
|
||||
extern void ppc_fmr();
|
||||
extern void ppc_mffs();
|
||||
extern void ppc_mffsdot();
|
||||
extern void ppc_mtfsf();
|
||||
extern void ppc_mtfsfdot();
|
||||
extern void ppc_mtfsfi();
|
||||
extern void ppc_mtfsfidot();
|
||||
|
||||
extern void ppc_addi();
|
||||
extern void ppc_addic();
|
||||
@@ -540,11 +549,11 @@ extern void ppc_stfdux();
|
||||
|
||||
extern void ppc_fadd();
|
||||
extern void ppc_fsub();
|
||||
extern void ppc_fmult();
|
||||
extern void ppc_fmul();
|
||||
extern void ppc_fdiv();
|
||||
extern void ppc_fadds();
|
||||
extern void ppc_fsubs();
|
||||
extern void ppc_fmults();
|
||||
extern void ppc_fmuls();
|
||||
extern void ppc_fdivs();
|
||||
extern void ppc_fmadd();
|
||||
extern void ppc_fmsub();
|
||||
@@ -566,127 +575,55 @@ extern void ppc_frsp();
|
||||
extern void ppc_fctiw();
|
||||
extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fadddot();
|
||||
extern void ppc_fsubdot();
|
||||
extern void ppc_fmultdot();
|
||||
extern void ppc_fdivdot();
|
||||
extern void ppc_fmadddot();
|
||||
extern void ppc_fmsubdot();
|
||||
extern void ppc_fnmadddot();
|
||||
extern void ppc_fnmsubdot();
|
||||
extern void ppc_fabsdot();
|
||||
extern void ppc_fnabsdot();
|
||||
extern void ppc_fnegdot();
|
||||
extern void ppc_fseldot();
|
||||
extern void ppc_fsqrtdot();
|
||||
extern void ppc_frsqrtedot();
|
||||
extern void ppc_frspdot();
|
||||
extern void ppc_fctiwdot();
|
||||
extern void ppc_fctiwzdot();
|
||||
|
||||
extern void ppc_fresdot();
|
||||
extern void ppc_faddsdot();
|
||||
extern void ppc_fsubsdot();
|
||||
extern void ppc_fmultsdot();
|
||||
extern void ppc_fdivsdot();
|
||||
extern void ppc_fmaddsdot();
|
||||
extern void ppc_fmsubsdot();
|
||||
extern void ppc_fnmaddsdot();
|
||||
extern void ppc_fnmsubsdot();
|
||||
extern void ppc_fsqrtsdot();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
//Power-specific instructions
|
||||
// Power-specific instructions
|
||||
extern void power_abs();
|
||||
extern void power_absdot();
|
||||
extern void power_abso();
|
||||
extern void power_absodot();
|
||||
extern void power_clcs();
|
||||
extern void power_clcsdot();
|
||||
extern void power_div();
|
||||
extern void power_divdot();
|
||||
extern void power_divo();
|
||||
extern void power_divodot();
|
||||
extern void power_divs();
|
||||
extern void power_divsdot();
|
||||
extern void power_divso();
|
||||
extern void power_divsodot();
|
||||
extern void power_doz();
|
||||
extern void power_dozdot();
|
||||
extern void power_dozo();
|
||||
extern void power_dozodot();
|
||||
extern void power_dozi();
|
||||
extern void power_lscbx();
|
||||
extern void power_lscbxdot();
|
||||
extern void power_maskg();
|
||||
extern void power_maskgdot();
|
||||
extern void power_maskir();
|
||||
extern void power_maskirdot();
|
||||
extern void power_mul();
|
||||
extern void power_muldot();
|
||||
extern void power_mulo();
|
||||
extern void power_mulodot();
|
||||
extern void power_nabs();
|
||||
extern void power_nabsdot();
|
||||
extern void power_nabso();
|
||||
extern void power_nabsodot();
|
||||
extern void power_rlmi();
|
||||
extern void power_rrib();
|
||||
extern void power_rribdot();
|
||||
extern void power_sle();
|
||||
extern void power_sledot();
|
||||
extern void power_sleq();
|
||||
extern void power_sleqdot();
|
||||
extern void power_sliq();
|
||||
extern void power_sliqdot();
|
||||
extern void power_slliq();
|
||||
extern void power_slliqdot();
|
||||
extern void power_sllq();
|
||||
extern void power_sllqdot();
|
||||
extern void power_slq();
|
||||
extern void power_slqdot();
|
||||
extern void power_sraiq();
|
||||
extern void power_sraiqdot();
|
||||
extern void power_sraq();
|
||||
extern void power_sraqdot();
|
||||
extern void power_sre();
|
||||
extern void power_sredot();
|
||||
extern void power_srea();
|
||||
extern void power_sreadot();
|
||||
extern void power_sreq();
|
||||
extern void power_sreqdot();
|
||||
extern void power_sriq();
|
||||
extern void power_sriqdot();
|
||||
extern void power_srliq();
|
||||
extern void power_srliqdot();
|
||||
extern void power_srlq();
|
||||
extern void power_srlqdot();
|
||||
extern void power_srq();
|
||||
extern void power_srqdot();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
//Gekko instructions
|
||||
extern void ppc_psq_l();
|
||||
extern void ppc_psq_lu();
|
||||
extern void ppc_psq_st();
|
||||
extern void ppc_psq_stu();
|
||||
// AltiVec instructions
|
||||
|
||||
//AltiVec instructions
|
||||
// 64-bit instructions
|
||||
|
||||
//64-bit instructions
|
||||
|
||||
//G5+ instructions
|
||||
// G5+ instructions
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
|
||||
|
||||
/* debugging support API */
|
||||
void print_gprs(void); /* print content of the general purpose registers */
|
||||
void print_fprs(void); /* print content of the floating-point registers */
|
||||
uint64_t get_reg(std::string ®_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string ®_name, uint64_t val); /* set reg_name to val */
|
||||
void print_fprs(void); /* print content of the floating-point registers */
|
||||
uint64_t get_reg(std::string& reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string& reg_name, uint64_t val); /* set reg_name to val */
|
||||
|
||||
#endif /* PPCEMU_H */
|
||||
+112
-108
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,156 +21,160 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Handling of low-level PPC exceptions. */
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type,
|
||||
uint32_t srr1_bits)
|
||||
{
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
grab_exception = true;
|
||||
#ifdef PROFILER
|
||||
exceptions_performed++;
|
||||
#endif
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
|
||||
switch(exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0100;
|
||||
break;
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0100;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
if (!(ppc_state.msr & 0x1000)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0200;
|
||||
break;
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
if (!(ppc_state.msr & 0x1000)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0200;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0300;
|
||||
break;
|
||||
case Except_Type::EXC_DSI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0300;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
case Except_Type::EXC_ISI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0900;
|
||||
break;
|
||||
case Except_Type::EXC_DECR:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0900;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0C00;
|
||||
break;
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0C00;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0D00;
|
||||
break;
|
||||
case Except_Type::EXC_TRACE:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0D00;
|
||||
break;
|
||||
|
||||
default:
|
||||
//printf("Unknown exception occured: %X\n", exception_type);
|
||||
//exit(-1);
|
||||
break;
|
||||
default:
|
||||
// printf("Unknown exception occured: %X\n", exception_type);
|
||||
// exit(-1);
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
|
||||
ppc_state.msr &= 0xFFFB1041;
|
||||
/* copy MSR[ILE] to MSR[LE] */
|
||||
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) |
|
||||
((ppc_state.msr >> 16) & 1);
|
||||
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) | ((ppc_state.msr >> 16) & 1);
|
||||
|
||||
if (ppc_state.msr & 0x40) {
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
// perform context synchronization for recoverable exceptions
|
||||
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
|
||||
exception_type != Except_Type::EXC_SYSTEM_RESET) {
|
||||
do_ctx_sync();
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type,
|
||||
uint32_t srr1_bits)
|
||||
{
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
|
||||
switch(exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
exc_descriptor = "System reset exception occured";
|
||||
break;
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
exc_descriptor = "System reset exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
exc_descriptor = "Machine check exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
exc_descriptor = "Machine check exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
case Except_Type::EXC_ISI:
|
||||
if (ppc_state.spr[SPR::DSISR] & 0x40000000)
|
||||
exc_descriptor = "DSI/ISI exception: unmapped memory access";
|
||||
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
|
||||
exc_descriptor = "DSI/ISI exception: access protection violation";
|
||||
else {
|
||||
if (exception_type == Except_Type::EXC_DSI)
|
||||
exc_descriptor = "DSI exception";
|
||||
else
|
||||
exc_descriptor = "ISI exception";
|
||||
}
|
||||
break;
|
||||
case Except_Type::EXC_DSI:
|
||||
case Except_Type::EXC_ISI:
|
||||
if (ppc_state.spr[SPR::DSISR] & 0x40000000)
|
||||
exc_descriptor = "DSI/ISI exception: unmapped memory access";
|
||||
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
|
||||
exc_descriptor = "DSI/ISI exception: access protection violation";
|
||||
else {
|
||||
if (exception_type == Except_Type::EXC_DSI)
|
||||
exc_descriptor = "DSI exception";
|
||||
else
|
||||
exc_descriptor = "ISI exception";
|
||||
}
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
exc_descriptor = "External interrupt exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
exc_descriptor = "External interrupt exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
exc_descriptor = "Alignment exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
exc_descriptor = "Alignment exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
exc_descriptor = "Program exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
exc_descriptor = "Program exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
exc_descriptor = "Floating-Point unavailable exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
exc_descriptor = "Floating-Point unavailable exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
exc_descriptor = "Decrementer exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_DECR:
|
||||
exc_descriptor = "Decrementer exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occured";
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
|
||||
+480
-486
File diff suppressed because it is too large.
Load diff
+779
-1126
File diff suppressed because it is too large.
Load diff
+1709
-325
File diff suppressed because it is too large.
Load diff
+87
-17
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,43 +19,113 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
/** @file PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
|
||||
/** generic PowerPC BAT descriptor (MMU internal state) */
|
||||
typedef struct PPC_BAT_entry {
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
bool valid; /* BAT entry valid for MPC601 */
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t hi_mask; /* mask for high-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
} PPC_BAT_entry;
|
||||
|
||||
/** Block address translation types. */
|
||||
enum BATType : int {
|
||||
IBAT,
|
||||
DBAT
|
||||
};
|
||||
|
||||
extern void ibat_update(uint32_t bat_reg);
|
||||
extern void dbat_update(uint32_t bat_reg);
|
||||
/** TLB types. */
|
||||
enum TLBType : int {
|
||||
ITLB,
|
||||
DTLB
|
||||
};
|
||||
|
||||
extern uint8_t *mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
/** Result of the block address translation. */
|
||||
typedef struct BATResult {
|
||||
bool hit;
|
||||
uint8_t prot;
|
||||
uint32_t phys;
|
||||
} BATResult;
|
||||
|
||||
/** Result of the page address translation. */
|
||||
typedef struct PATResult {
|
||||
uint32_t phys;
|
||||
uint8_t prot;
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
int64_t host_va_offs_r;
|
||||
AddressMapEntry* reg_desc;
|
||||
};
|
||||
int64_t host_va_offs_w;
|
||||
int64_t unused;
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
PAGE_MEM = 1 << 0, // memory page backed by host memory
|
||||
PAGE_IO = 1 << 1, // memory mapped I/O page
|
||||
PAGE_NOPHYS = 1 << 2, // no physical storage for this page (unmapped)
|
||||
TLBE_FROM_BAT = 1 << 3, // TLB entry has been translated with BAT
|
||||
TLBE_FROM_PAT = 1 << 4, // TLB entry has been translated with PAT
|
||||
PAGE_WRITABLE = 1 << 5, // page is writable
|
||||
PTE_SET_C = 1 << 6, // tells if C bit of the PTE needs to be updated
|
||||
};
|
||||
|
||||
extern std::function<void(uint32_t bat_reg)> ibat_update;
|
||||
extern std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
|
||||
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
|
||||
extern void ppc_set_cur_instruction(const uint8_t* ptr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
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 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 uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
|
||||
#endif // PPCMEMORY_H
|
||||
#endif // PPCMMU_H
|
||||
+1073
-1343
File diff suppressed because it is too large.
Load diff
+294
-44
@@ -99,6 +99,98 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1)
|
||||
elif opc_str == "EXTSH.":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1) + 1
|
||||
elif opc_str == "FABS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1)
|
||||
elif opc_str == "FABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
elif opc_str == "FADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
elif opc_str == "FCTIWZ":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1)
|
||||
elif opc_str == "FCTIWZ.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
elif opc_str == "FDIV":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIV.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FDIVS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIVS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FNABS":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
|
||||
elif opc_str == "FNABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1) + 1
|
||||
elif opc_str == "FNEG":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
|
||||
elif opc_str == "FNEG.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "MULHW":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
|
||||
elif opc_str == "MULHW.":
|
||||
@@ -262,51 +354,209 @@ def extract_rot_params(line):
|
||||
pos += 16
|
||||
return (sh, mb, me)
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
out_file.write("\n")
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
|
||||
out_file.write("\n")
|
||||
|
||||
with open("ppcfloattest.txt", "r") as in_file:
|
||||
with open("ppcfloattests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
|
||||
pos = 10
|
||||
checkstring = ''
|
||||
|
||||
while pos < len(line):
|
||||
if (line[pos].isalnum()):
|
||||
checkstring += line[pos]
|
||||
|
||||
if ("RTN" in checkstring):
|
||||
if (line[pos+1:pos+2] == "I"):
|
||||
out_file.write(",round=RNI")
|
||||
checkstring = ''
|
||||
else:
|
||||
out_file.write(",round=RTN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTZ" in checkstring):
|
||||
out_file.write(",round=RTZ")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTPI" in checkstring):
|
||||
out_file.write(",round=RPI")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("VE" in checkstring):
|
||||
out_file.write(",round=VEN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("frD" in checkstring):
|
||||
out_file.write(",frD=0x" + line[pos+4:pos+20])
|
||||
checkstring = ''
|
||||
elif ("frA" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frA=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frA=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frA=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frB" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frB=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frB=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frB=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frC" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frC=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frC=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frC=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("FPSCR" in checkstring):
|
||||
out_file.write(",FPSCR=" + line[pos+3:pos+13])
|
||||
checkstring = ''
|
||||
elif ("CR" in checkstring):
|
||||
out_file.write(",CR=0x0" + line[pos+6:pos+14])
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
|
||||
# reg_id = line[pos:pos+4]
|
||||
# if reg_id.startswith("frD"):
|
||||
# out_file.write(",frD=" + line[pos+4:pos+22])
|
||||
# pos += 24
|
||||
# elif reg_id.startswith("frA"):
|
||||
# out_file.write(",frA=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frB"):
|
||||
# out_file.write(",frB=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frC"):
|
||||
# out_file.write(",frC=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("FPSCR:"):
|
||||
# out_file.write(",FPSCR=" + line[pos+7:pos+17])
|
||||
# pos += 19
|
||||
# elif reg_id.startswith("CR:"):
|
||||
# out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("VE)"):
|
||||
# out_file.write("round=VEN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TN)"):
|
||||
# out_file.write("round=RTN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TZ)"):
|
||||
# out_file.write("round=RTZ" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("NI)"):
|
||||
# out_file.write("round=RNI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("PI)"):
|
||||
# out_file.write("round=RPI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# else:
|
||||
# out_file.write("Unknown reg ID" + reg_id)
|
||||
# break
|
||||
|
||||
out_file.write("\n")
|
||||
@@ -331,9 +331,9 @@
|
||||
0xFFF00100,0xCC1F0008,lfdu,f0,0x8(r31)
|
||||
0xFFF00100,0xC1628398,lfs,f11,-0x7C68(r2)
|
||||
0xFFF00100,0xC5BE0004,lfsu,f13,0x4(r30)
|
||||
0xFFF00100,0xDBC1FFF0,sftd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,sftd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,sftdu,f0,0x8(r24)
|
||||
0xFFF00100,0xDBC1FFF0,stfd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,stfd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,stfdu,f0,0x8(r24)
|
||||
0xFFF00100,0xD01E0110,stfs,f0,0x110(r30)
|
||||
0xFFF00100,0xD58B0004,stfsu,f12,0x4(r11)
|
||||
0xFFF00100,0x7C1C5CAE,lfdx,f0,r28,r11
|
||||
@@ -362,9 +362,21 @@
|
||||
0xFFF00100,0xEDA66279,fmsubs.,f13,f6,f9,f12
|
||||
0xFFF00100,0xEC00637C,fnmsubs,f0,f0,f13,f12
|
||||
0xFFF00100,0xFE0820AF,fsel.,f16,f8,f2,f4
|
||||
0xFFF00100,0xFDA06050,fneg,f13,f12
|
||||
0xFFF00100,0xFD80EA10,fabs,f12,f29
|
||||
0xFFF00100,0xFD600110,fnabs,f11,f0
|
||||
0xFFF00100,0xFD002034,frsqrte,f8,f4
|
||||
0xFFF00100,0x7FF957AE,stfiwx,f31,r25,r10
|
||||
0xFFF00100,0xFC40F818,frsp,f2,f31
|
||||
0xFFF00100,0xFC201019,frsp.,f1,f2
|
||||
0xFFF00100,0xFDA0F81E,fctiwz,f13,f31
|
||||
0xFFF00100,0xFCA0501D,fctiw.,f5,f10
|
||||
0xFFF00100,0xFD9C0080,mcrfs,cr3,cr7
|
||||
0xFFF00100,0xFDFE058E,mtfsf,255,f0
|
||||
0xFFF00100,0xFF80F10C,mtfsfi,cr7,15
|
||||
0xFFF00100,0xFF80F10D,mtfsfi.,cr7,15
|
||||
0xFFF00100,0xFC406890,fmr,f2,f13
|
||||
0xFFF00100,0xFC20E891,fmr.,f1,f29
|
||||
|
||||
# compare instructions
|
||||
0xFFF00100,0x7C15A000,cmpw,r21,r20
|
||||
@@ -384,6 +396,7 @@
|
||||
0xFFF00100,0x7CBC04AA,lswi,r5,r28,0x20
|
||||
0xFFF00100,0x7FEF2C2A,lswx,r31,r15,r5
|
||||
0xFFF00100,0x7E000400,mcrxr,cr4
|
||||
0xFFF00100,0xFDC0008C,mtfsb0,14
|
||||
0xFFF00100,0xFFE0004C,mtfsb1,31
|
||||
0xFFF00100,0xFFE0048F,mffs.,f31
|
||||
0xFFF00100,0x7C2000A6,mfmsr,r1
|
||||
|
||||
|
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+215
-68
@@ -1,72 +1,90 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../ppcemu.h"
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int ntested; /* number of tested instructions */
|
||||
int nfailed; /* number of failed instructions */
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode)
|
||||
{
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
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_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set."
|
||||
<< endl;
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
|
||||
nfailed++;
|
||||
}
|
||||
ntested++;
|
||||
}
|
||||
|
||||
void xer_update_test()
|
||||
{
|
||||
xer_ov_test("ADDCO", 0x7C632414);
|
||||
xer_ov_test("ADDCO.", 0x7C632415);
|
||||
xer_ov_test("ADDO", 0x7C632614);
|
||||
xer_ov_test("ADDO.", 0x7C632615);
|
||||
xer_ov_test("ADDEO", 0x7C632514);
|
||||
xer_ov_test("ADDEO.", 0x7C632515);
|
||||
xer_ov_test("ADDMEO", 0x7C6305D4);
|
||||
xer_ov_test("ADDMEO.", 0x7C6305D5);
|
||||
xer_ov_test("ADDZEO", 0x7C630594);
|
||||
xer_ov_test("ADDZEO.", 0x7C630595);
|
||||
xer_ov_test("DIVWO", 0x7C6327D6);
|
||||
xer_ov_test("DIVWO.", 0x7C6327D7);
|
||||
xer_ov_test("DIVWUO", 0x7C632796);
|
||||
xer_ov_test("DIVWUO.", 0x7C632797);
|
||||
xer_ov_test("MULLWO", 0x7C6325D6);
|
||||
xer_ov_test("MULLWO.", 0x7C6325D7);
|
||||
xer_ov_test("NEGO", 0x7C6304D0);
|
||||
xer_ov_test("NEGO.", 0x7C6304D1);
|
||||
xer_ov_test("SUBFO", 0x7C632450);
|
||||
xer_ov_test("SUBFO.", 0x7C632451);
|
||||
xer_ov_test("SUBFCO", 0x7C632410);
|
||||
xer_ov_test("SUBFCO.", 0x7C632411);
|
||||
xer_ov_test("SUBFEO", 0x7C632510);
|
||||
xer_ov_test("SUBFEO.", 0x7C632511);
|
||||
xer_ov_test("SUBFMEO", 0x7C6305D0);
|
||||
void xer_update_test() {
|
||||
xer_ov_test("ADDCO", 0x7C632414);
|
||||
xer_ov_test("ADDCO.", 0x7C632415);
|
||||
xer_ov_test("ADDO", 0x7C632614);
|
||||
xer_ov_test("ADDO.", 0x7C632615);
|
||||
xer_ov_test("ADDEO", 0x7C632514);
|
||||
xer_ov_test("ADDEO.", 0x7C632515);
|
||||
xer_ov_test("ADDMEO", 0x7C6305D4);
|
||||
xer_ov_test("ADDMEO.", 0x7C6305D5);
|
||||
xer_ov_test("ADDZEO", 0x7C630594);
|
||||
xer_ov_test("ADDZEO.", 0x7C630595);
|
||||
xer_ov_test("DIVWO", 0x7C6327D6);
|
||||
xer_ov_test("DIVWO.", 0x7C6327D7);
|
||||
xer_ov_test("DIVWUO", 0x7C632796);
|
||||
xer_ov_test("DIVWUO.", 0x7C632797);
|
||||
xer_ov_test("MULLWO", 0x7C6325D6);
|
||||
xer_ov_test("MULLWO.", 0x7C6325D7);
|
||||
xer_ov_test("NEGO", 0x7C6304D0);
|
||||
xer_ov_test("NEGO.", 0x7C6304D1);
|
||||
xer_ov_test("SUBFO", 0x7C632450);
|
||||
xer_ov_test("SUBFO.", 0x7C632451);
|
||||
xer_ov_test("SUBFCO", 0x7C632410);
|
||||
xer_ov_test("SUBFCO.", 0x7C632411);
|
||||
xer_ov_test("SUBFEO", 0x7C632510);
|
||||
xer_ov_test("SUBFEO.", 0x7C632511);
|
||||
xer_ov_test("SUBFMEO", 0x7C6305D0);
|
||||
xer_ov_test("SUBFMEO.", 0x7C6305D1);
|
||||
xer_ov_test("SUBFZEO", 0x7C630590);
|
||||
xer_ov_test("SUBFZEO", 0x7C630590);
|
||||
xer_ov_test("SUBFZEO.", 0x7C630591);
|
||||
}
|
||||
|
||||
/** testing vehicle */
|
||||
static void read_test_data()
|
||||
{
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
static void read_test_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
uint32_t opcode, dest, src1, src2, check_xer, check_cr;
|
||||
|
||||
ifstream tfstream("ppcinttests.csv");
|
||||
ifstream tfstream("ppcinttests.csv");
|
||||
if (!tfstream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return;
|
||||
@@ -74,7 +92,7 @@ static void read_test_data()
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while(getline(tfstream, line)) {
|
||||
while (getline(tfstream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
@@ -84,7 +102,7 @@ static void read_test_data()
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while(getline(lnstream, token, ',' )) {
|
||||
while (getline(lnstream, token, ',')) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
@@ -95,9 +113,9 @@ static void read_test_data()
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_xer = 0;
|
||||
check_cr = 0;
|
||||
|
||||
@@ -113,16 +131,17 @@ static void read_test_data()
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno <<
|
||||
". Exiting..." << endl;
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
@@ -131,15 +150,13 @@ static void read_test_data()
|
||||
ntested++;
|
||||
|
||||
if ((tokens[0].rfind("CMP") && (ppc_state.gpr[3] != dest)) ||
|
||||
(ppc_state.spr[SPR::XER] != check_xer) ||
|
||||
(ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=0x" << hex << src1
|
||||
<< ", src2=0x" << hex << src2 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest << ", XER=0x" << hex
|
||||
<< check_xer << ", CR=0x" << hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.gpr[3] << ", XER=0x"
|
||||
<< hex << ppc_state.spr[SPR::XER] << ", CR=0x" << hex
|
||||
<< ppc_state.cr << endl;
|
||||
(ppc_state.spr[SPR::XER] != check_xer) || (ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=0x" << hex << src1 << ", src2=0x"
|
||||
<< hex << src2 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest << ", XER=0x" << hex << check_xer
|
||||
<< ", CR=0x" << hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.gpr[3] << ", XER=0x" << hex
|
||||
<< ppc_state.spr[SPR::XER] << ", CR=0x" << hex << ppc_state.cr << endl;
|
||||
cout << "Test file line #: " << dec << lineno << endl << endl;
|
||||
|
||||
nfailed++;
|
||||
@@ -147,8 +164,131 @@ static void read_test_data()
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
static void read_test_float_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
|
||||
uint32_t opcode, dest, src1, src2, check_xer, check_cr, check_fpscr;
|
||||
uint64_t dest_64, src1_64, src2_64;
|
||||
//float sfp_dest, sfp_src1, sfp_src2, sfp_src3;
|
||||
double dfp_dest, dfp_src1, dfp_src2, dfp_src3;
|
||||
string rounding_mode;
|
||||
|
||||
ifstream tf2stream("ppcfloattests.csv");
|
||||
if (!tf2stream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while (getline(tf2stream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
continue; /* skip empty/comment lines */
|
||||
|
||||
istringstream lnstream(line);
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while (getline(lnstream, token, ',')) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
if (tokens.size() < 5) {
|
||||
cout << "Too few values in line " << lineno << ". Skipping..." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_xer = 0;
|
||||
check_cr = 0;
|
||||
check_fpscr = 0;
|
||||
//sfp_dest = 0.0;
|
||||
//sfp_src1 = 0.0;
|
||||
//sfp_src2 = 0.0;
|
||||
//sfp_src3 = 0.0;
|
||||
dfp_dest = 0.0;
|
||||
dfp_src1 = 0.0;
|
||||
dfp_src2 = 0.0;
|
||||
dfp_src3 = 0.0;
|
||||
dest_64 = 0;
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("frD=", 0) == 0) {
|
||||
dest_64 = stoull(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("frA=", 0) == 0) {
|
||||
dfp_src1 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frB=", 0) == 0) {
|
||||
dfp_src2 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frC=", 0) == 0) {
|
||||
dfp_src3 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
ppc_state.fpscr = 0;
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
ppc_state.fpscr = 0x0;
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
ppc_state.fpscr = 0x1;
|
||||
} else if (rounding_mode.compare("RPI") == 0) {
|
||||
ppc_state.fpscr = 0x2;
|
||||
} else if (rounding_mode.compare("RNI") == 0) {
|
||||
ppc_state.fpscr = 0x3;
|
||||
} else if (rounding_mode.compare("VEN") == 0) {
|
||||
ppc_state.fpscr = FPSCR::VE;
|
||||
} else {
|
||||
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
|
||||
<< ". Exiting..." << endl;
|
||||
exit(0);
|
||||
}
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.fpr[3].dbl64_r = dfp_src1;
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src3;
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
|
||||
ntested++;
|
||||
|
||||
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
|
||||
(ppc_state.fpscr != check_fpscr) ||
|
||||
(ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
|
||||
<< ", CR=0x"
|
||||
<< hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
|
||||
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
|
||||
cout << "Test file line #: " << dec << lineno << endl << endl;
|
||||
|
||||
nfailed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialize_ppc_opcode_tables(); //kludge
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
@@ -163,6 +303,13 @@ int main()
|
||||
|
||||
read_test_data();
|
||||
|
||||
cout << endl << "Float IEEE suport: " << (bool)std::numeric_limits<float>::is_iec559 << endl;
|
||||
cout << endl << "Double IEEE suport: " << (bool)std::numeric_limits<double>::is_iec559 << endl;
|
||||
|
||||
cout << endl << "Testing floating point instructions:" << endl;
|
||||
|
||||
read_test_float_data();
|
||||
|
||||
cout << "... completed." << endl;
|
||||
cout << "--> Tested instructions: " << dec << ntested << endl;
|
||||
cout << "--> Failed: " << dec << nfailed << endl << endl;
|
||||
|
||||
+42
-24
@@ -1,22 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** testing vehicle */
|
||||
static vector<PPCDisasmContext> read_test_data()
|
||||
{
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
static vector<PPCDisasmContext> read_test_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
PPCDisasmContext ctx;
|
||||
vector<PPCDisasmContext> tstvec;
|
||||
|
||||
ifstream tfstream("ppcdisasmtest.csv");
|
||||
ifstream tfstream("ppcdisasmtest.csv");
|
||||
if (!tfstream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return tstvec;
|
||||
@@ -24,18 +44,18 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while(getline(tfstream, line)) {
|
||||
while (getline(tfstream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
continue; // skip empty/comment lines
|
||||
continue; // skip empty/comment lines
|
||||
|
||||
istringstream lnstream(line);
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while(getline(lnstream, token, ',' )) {
|
||||
//cout << "Token: " << token << endl;
|
||||
while (getline(lnstream, token, ',')) {
|
||||
// cout << "Token: " << token << endl;
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
@@ -44,7 +64,7 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx = {0};
|
||||
ctx = {0};
|
||||
ctx.instr_addr = stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = stoul(tokens[1], NULL, 16);
|
||||
|
||||
@@ -64,7 +84,7 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
|
||||
ctx.instr_str = idisasm.str();
|
||||
|
||||
//cout << idisasm.str() << endl;
|
||||
// cout << idisasm.str() << endl;
|
||||
|
||||
tstvec.push_back(ctx);
|
||||
}
|
||||
@@ -72,8 +92,7 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
return tstvec;
|
||||
}
|
||||
|
||||
int test_ppc_disasm()
|
||||
{
|
||||
int test_ppc_disasm() {
|
||||
int i, nfailed;
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
@@ -84,7 +103,7 @@ int test_ppc_disasm()
|
||||
nfailed = 0;
|
||||
|
||||
for (i = 0; i < testdata.size(); i++) {
|
||||
ctx = {0};
|
||||
ctx = {0};
|
||||
ctx.instr_addr = testdata[i].instr_addr;
|
||||
ctx.instr_code = testdata[i].instr_code;
|
||||
ctx.simplified = true;
|
||||
@@ -92,14 +111,13 @@ int test_ppc_disasm()
|
||||
std::string disas = disassemble_single(&ctx);
|
||||
|
||||
if (disas != testdata[i].instr_str) {
|
||||
cout << "Mismatch found, expected={" << testdata[i].instr_str <<
|
||||
"}, got={" << disas << "}" << endl;
|
||||
cout << "Mismatch found, expected={" << testdata[i].instr_str << "}, got={" << disas
|
||||
<< "}" << endl;
|
||||
nfailed++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Tested " << testdata.size() << " instructions. Failed: " <<
|
||||
nfailed << "." << endl;
|
||||
cout << "Tested " << testdata.size() << " instructions. Failed: " << nfailed << "." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+391
-135
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,83 +19,228 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "memaccess.h"
|
||||
#include "utils/profiler.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint32_t str2addr(string& addr_str)
|
||||
{
|
||||
static uint32_t str2addr(string& addr_str) {
|
||||
try {
|
||||
return stoul(addr_str, NULL, 0);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + addr_str);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t str2num(string& num_str)
|
||||
{
|
||||
static uint32_t str2num(string& num_str) {
|
||||
try {
|
||||
return stol(num_str, NULL, 0);
|
||||
}
|
||||
catch (invalid_argument & exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
}
|
||||
|
||||
static void show_help()
|
||||
{
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step -- execute single instruction" << endl;
|
||||
cout << " si -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " profile C N -- run subcommand C on profile N" << endl;
|
||||
cout << " supported subcommands:" << endl;
|
||||
cout << " 'show' - show profile report" << endl;
|
||||
cout << " 'reset' - reset profile variables" << endl;
|
||||
#ifdef PROFILER
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
#endif
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address)
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
csh cs_handle;
|
||||
uint8_t code[10];
|
||||
size_t code_size;
|
||||
uint64_t dis_addr;
|
||||
|
||||
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
|
||||
cout << "Capstone initialization error" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; count > 0; count--) {
|
||||
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
|
||||
for (int i = 0; i < sizeof(code); i++) {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
}
|
||||
|
||||
const uint8_t *code_ptr = code;
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
// catch and handle F-Traps (Nanokernel calls) ourselves because
|
||||
// Capstone will likely return no meaningful assembly for them
|
||||
if ((code[0] & 0xF0) == 0xF0) {
|
||||
goto print_bin;
|
||||
}
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
print_bin:
|
||||
cout << uppercase << hex << address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << "dc.w" << "$" << hex <<
|
||||
((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
|
||||
cs_free(insn, 1);
|
||||
cs_close(&cs_handle);
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
{
|
||||
PPCDisasmContext ctx;
|
||||
string reg;
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
/* PPC r24 contains 68k PC advanced by two bytes
|
||||
as part of instruction prefetching */
|
||||
reg = "R24";
|
||||
cur_68k_pc = get_reg(reg) - 2;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = mem_read_dbg(ctx.instr_addr, 4);
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
/* PPC r29 contains base address of the emulator opcode table */
|
||||
reg = "R29";
|
||||
emu_table_virt = get_reg(reg) & 0xFFF80000;
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
|
||||
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
|
||||
|
||||
/* because the first two PPC instructions for each emulated 68k once
|
||||
are resided in the emulator opcode table, we need to execute them
|
||||
one by one until the execution goes outside the opcode table. */
|
||||
while (ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
|
||||
ppc_exec_single();
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
|
||||
}
|
||||
|
||||
/* Getting here means we're outside the emualtor opcode table.
|
||||
Execute PPC code until we hit the opcode table again. */
|
||||
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
|
||||
}
|
||||
|
||||
/** Execute emulated 68k code until target_addr is reached. */
|
||||
void exec_until_68k(uint32_t target_addr)
|
||||
{
|
||||
string reg;
|
||||
uint32_t emu_table_virt, ppc_pc;
|
||||
|
||||
reg = "R29";
|
||||
emu_table_virt = get_reg(reg) & 0xFFF80000;
|
||||
|
||||
reg = "R24";
|
||||
while (target_addr != (get_reg(reg) - 2)) {
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
|
||||
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
|
||||
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_single();
|
||||
} else {
|
||||
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
|
||||
}
|
||||
reg = "R24";
|
||||
}
|
||||
}
|
||||
|
||||
static void dump_mem(string& params)
|
||||
void print_68k_regs()
|
||||
{
|
||||
int i;
|
||||
string reg;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
reg = "R" + to_string(i + 8);
|
||||
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
reg = "R" + to_string(i + 16);
|
||||
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
reg = "R1";
|
||||
cout << "A7 : " << uppercase << hex << get_reg(reg) << endl;
|
||||
|
||||
reg = "R24";
|
||||
cout << "PC: " << uppercase << hex << get_reg(reg) - 2 << endl;
|
||||
|
||||
reg = "R25";
|
||||
cout << "SR: " << uppercase << hex << ((get_reg(reg) & 0xFF) << 8) << endl;
|
||||
|
||||
reg = "R26";
|
||||
cout << "CCR: " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
#endif // ENABLE_68K_DEBUGGER
|
||||
|
||||
static void dump_mem(string& params) {
|
||||
int cell_size, chars_per_line;
|
||||
bool is_char;
|
||||
uint32_t count, addr;
|
||||
@@ -110,55 +255,52 @@ static void dump_mem(string& params)
|
||||
}
|
||||
|
||||
num_type_str = params.substr(0, params.find_first_of(","));
|
||||
addr_str = params.substr(params.find_first_of(",") + 1);
|
||||
addr_str = params.substr(params.find_first_of(",") + 1);
|
||||
|
||||
is_char = false;
|
||||
|
||||
switch(num_type_str.back()) {
|
||||
case 'b':
|
||||
case 'B':
|
||||
cell_size = 1;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
cell_size = 2;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
cell_size = 4;
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
cell_size = 8;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
cell_size = 1;
|
||||
is_char = true;
|
||||
break;
|
||||
default:
|
||||
cout << "Invalid data type " << num_type_str << endl;
|
||||
return;
|
||||
switch (num_type_str.back()) {
|
||||
case 'b':
|
||||
case 'B':
|
||||
cell_size = 1;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
cell_size = 2;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
cell_size = 4;
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
cell_size = 8;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
cell_size = 1;
|
||||
is_char = true;
|
||||
break;
|
||||
default:
|
||||
cout << "Invalid data type " << num_type_str << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
num_type_str = num_type_str.substr(0, num_type_str.length() - 1);
|
||||
count = str2addr(num_type_str);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
count = str2addr(num_type_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
addr = str2addr(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
@@ -179,13 +321,12 @@ static void dump_mem(string& params)
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << uppercase <<
|
||||
hex << val << " ";
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
@@ -193,20 +334,67 @@ static void dump_mem(string& params)
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
void enter_debugger()
|
||||
{
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_gprs() {
|
||||
string reg_name;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
reg_name = "R" + to_string(i);
|
||||
|
||||
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
}
|
||||
|
||||
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
|
||||
|
||||
for (auto &spr : sprs) {
|
||||
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str;
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
uint32_t addr, inst_grab;
|
||||
std::stringstream ss;
|
||||
int log_level;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
|
||||
while (1) {
|
||||
cout << "ppcdbg> ";
|
||||
cout << "dingusdbg> ";
|
||||
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
@@ -223,21 +411,29 @@ void enter_debugger()
|
||||
}
|
||||
if (cmd == "help") {
|
||||
show_help();
|
||||
}
|
||||
else if (cmd == "quit") {
|
||||
} else if (cmd == "quit") {
|
||||
break;
|
||||
} else if (cmd == "profile") {
|
||||
ss >> sub_cmd;
|
||||
ss >> profile_name;
|
||||
|
||||
if (sub_cmd == "show") {
|
||||
gProfilerObj->print_profile(profile_name);
|
||||
} else if (sub_cmd == "reset") {
|
||||
gProfilerObj->reset_profile(profile_name);
|
||||
} else {
|
||||
cout << "Unknown/empty subcommand " << sub_cmd << endl;
|
||||
}
|
||||
}
|
||||
#ifdef PROFILER
|
||||
else if (cmd == "profiler") {
|
||||
cout << "Number of Supervisor Instructions Executed:" << supervisor_inst_num << endl;
|
||||
cout << "Exception Handler Ran:" << exceptions_performed << endl;
|
||||
cout << "Number of MMU Translations:" << mmu_translations_num << endl;
|
||||
}
|
||||
#endif
|
||||
else if (cmd == "regs") {
|
||||
print_gprs();
|
||||
}
|
||||
else if (cmd == "set") {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
#endif
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
separator_pos = expr_str.find_first_of("=");
|
||||
@@ -256,35 +452,59 @@ void enter_debugger()
|
||||
continue;
|
||||
}
|
||||
loguru::g_stderr_verbosity = log_level;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
addr = str2addr(addr_str);
|
||||
set_reg(reg_expr, addr);
|
||||
}
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
else if (cmd == "step" || cmd == "si") {
|
||||
ppc_exec_single();
|
||||
}
|
||||
else if (cmd == "next" || cmd == "ni") {
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
int count;
|
||||
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
try {
|
||||
count = str2num(expr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
count = 1;
|
||||
}
|
||||
} else {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
for (; --count >= 0;) {
|
||||
ppc_exec_single();
|
||||
}
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
addr = get_reg(addr_str) + 4;
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
else if (cmd == "until") {
|
||||
} else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
else if (cmd == "disas") {
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
@@ -293,42 +513,78 @@ void enter_debugger()
|
||||
cout << "disas: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
inst_num_str = expr_str.substr(0, expr_str.find_first_of(","));
|
||||
inst_grab = stol(inst_num_str, NULL, 0);
|
||||
try {
|
||||
inst_grab = str2num(inst_num_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
addr_str = expr_str.substr(expr_str.find_first_of(",") + 1);
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
if (context == 2 && (addr_str == "pc" || addr_str == "PC")) {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
} else {
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
disasm(inst_grab, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
catch (invalid_argument& exc) {
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
try {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
#endif
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
}
|
||||
else if (cmd == "dump") {
|
||||
} else if (cmd == "dump") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
dump_mem(expr_str);
|
||||
}
|
||||
else {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
} else if (cmd == "context") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str == "ppc" || expr_str == "PPC") {
|
||||
context = 1;
|
||||
} else if (expr_str == "68k" || expr_str == "68K") {
|
||||
context = 2;
|
||||
} else {
|
||||
cout << "Unknown debugging context: " << expr_str << endl;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,6 +1,27 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
void enter_debugger(void);
|
||||
|
||||
#endif // DEBUGGER_H_
|
||||
#endif // DEBUGGER_H_
|
||||
+16
-2
@@ -1,6 +1,20 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
@@ -1,360 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <atirage.h>
|
||||
#include <cstdint>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "endianswap.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "pcidevice.h"
|
||||
#include "displayid.h"
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id) : PCIDevice("ati-rage")
|
||||
{
|
||||
this->vram_size = 0x200000; /* FIXME: hardcoded VRAM size! */
|
||||
|
||||
/*allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
|
||||
/* configure PCI parameters */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[8], 0x0300005C);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
if (this->vram_ptr) {
|
||||
delete this->vram_ptr;
|
||||
}
|
||||
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
uint32_t ATIRage::size_dep_read(uint8_t *buf, uint32_t size)
|
||||
{
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATI Rage read: invalid size %d", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::size_dep_write(uint8_t *buf, uint32_t value, uint32_t size)
|
||||
{
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset)
|
||||
{
|
||||
const char* reg_name;
|
||||
|
||||
switch (reg_offset & ~3) {
|
||||
case ATI_CRTC_H_TOTAL_DISP:
|
||||
reg_name = "CRTC_H_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_H_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_H_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_V_TOTAL_DISP:
|
||||
reg_name = "CRTC_V_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_V_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_V_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
reg_name = "CRTC_OFF_PITCH";
|
||||
break;
|
||||
case ATI_CRTC_INT_CNTL:
|
||||
reg_name = "CRTC_INT_CNTL";
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
reg_name = "CRTC_GEN_CNTL";
|
||||
break;
|
||||
case ATI_DSP_CONFIG:
|
||||
reg_name = "DSP_CONFIG";
|
||||
break;
|
||||
case ATI_DSP_ON_OFF:
|
||||
reg_name = "DSP_ON_OFF";
|
||||
break;
|
||||
case ATI_MEM_BUF_CNTL:
|
||||
reg_name = "MEM_BUF_CNTL";
|
||||
break;
|
||||
case ATI_MEM_ADDR_CFG:
|
||||
reg_name = "MEM_ADDR_CFG";
|
||||
break;
|
||||
case ATI_OVR_CLR:
|
||||
reg_name = "OVR_CLR";
|
||||
break;
|
||||
case ATI_OVR_WID_LEFT_RIGHT:
|
||||
reg_name = "OVR_WID_LEFT_RIGHT";
|
||||
break;
|
||||
case ATI_OVR_WID_TOP_BOTTOM:
|
||||
reg_name = "OVR_WID_TOP_BOTTOM";
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
reg_name = "GP_IO";
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
reg_name = "CLOCK_CNTL";
|
||||
break;
|
||||
case ATI_BUS_CNTL:
|
||||
reg_name = "BUS_CNTL";
|
||||
break;
|
||||
case ATI_EXT_MEM_CNTL:
|
||||
reg_name = "EXT_MEM_CNTL";
|
||||
break;
|
||||
case ATI_MEM_CNTL:
|
||||
reg_name = "MEM_CNTL";
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
reg_name = "DAC_REGS";
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
reg_name = "DAC_CNTL";
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
reg_name = "GEN_TEST_CNTL";
|
||||
break;
|
||||
case ATI_CFG_CHIP_ID:
|
||||
reg_name = "CONFIG_CHIP_ID";
|
||||
break;
|
||||
case ATI_CFG_STAT0:
|
||||
reg_name = "CONFIG_STAT0";
|
||||
break;
|
||||
default:
|
||||
reg_name = "unknown";
|
||||
}
|
||||
|
||||
return reg_name;
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size)
|
||||
{
|
||||
uint32_t res;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
||||
get_reg_name(offset), offset, size,
|
||||
size_dep_read(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
res = size_dep_read(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
size_dep_write(&this->block_io_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
||||
WRITE_WORD_LE_A(&this->block_io_regs[ATI_GP_IO],
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset), offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = size_dep_read(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
LOG_F(INFO, "Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
||||
reg_offs, BYTESWAP_32(value), size);
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x10: /* BAR 0 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
||||
}
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base, 0x01000000, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
default:
|
||||
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t *p_io_base)
|
||||
{
|
||||
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
*p_io_base = io_base;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t *res)
|
||||
{
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - io_base, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - io_base, value, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > 0x01000000) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return size_dep_read(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= 0x7FFC00UL) {
|
||||
/* read from memory-mapped registers */
|
||||
return this->read_reg(offset - 0x7FFC00UL, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > 0x01000000) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
size_dep_write(this->vram_ptr + offset, value, size);
|
||||
} else if (offset >= 0x7FFC00UL) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - 0x7FFC00UL, value, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "pcidevice.h"
|
||||
#include "displayid.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
};
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CLONFIG_STAT1 = 0x0094,
|
||||
ATI_CLONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_VGA_WP_SEL = 0x00B4,
|
||||
ATI_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CFG_CHIP_ID = 0x00E0,
|
||||
ATI_CFG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
};
|
||||
|
||||
class ATIRage : public PCIDevice
|
||||
{
|
||||
public:
|
||||
ATIRage(uint16_t dev_id);
|
||||
~ATIRage();
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::MMIO_DEV; };
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) { return true; };
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* I/O space access methods */
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t *res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) ;
|
||||
|
||||
protected:
|
||||
uint32_t size_dep_read(uint8_t* buf, uint32_t size);
|
||||
void size_dep_write(uint8_t* buf, uint32_t val, uint32_t size);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
private:
|
||||
//uint32_t atirage_membuf_regs[9]; /* ATI Rage Memory Buffer Registers */
|
||||
//uint32_t atirage_scratch_regs[4]; /* ATI Rage Scratch Registers */
|
||||
//uint32_t atirage_cmdfifo_regs[3]; /* ATI Rage Command FIFO Registers */
|
||||
//uint32_t atirage_datapath_regs[12]; /* ATI Rage Data Path Registers*/
|
||||
|
||||
uint8_t block_io_regs[256] = { 0 };
|
||||
|
||||
uint8_t pci_cfg[256] = { 0 }; /* PCI configuration space */
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
uint32_t aperture_base;
|
||||
|
||||
DisplayID* disp_id;
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019-20
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "endianswap.h"
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "soundserver.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
|
||||
static int awac_freqs[8] = {44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350};
|
||||
|
||||
|
||||
AWACDevice::AWACDevice()
|
||||
{
|
||||
this->audio_proc = new AudioProcessor();
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus *i2c_bus = dynamic_cast<I2CBus *>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc);
|
||||
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AWACDevice::~AWACDevice()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
|
||||
delete this->audio_proc;
|
||||
}
|
||||
|
||||
void AWACDevice::set_dma_out(DMAChannel *dma_out_ch)
|
||||
{
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
}
|
||||
|
||||
uint32_t AWACDevice::snd_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
switch(offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) |
|
||||
(AWAC_REV_SCREAMER << 20);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AWACDevice::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch(offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "New sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(INFO, "AWAC subframe = %d, reg = %d, data = %08X\n", subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void convert_data(const uint8_t *in, SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
uint16_t *p_in = (uint16_t *)in;
|
||||
|
||||
for (int i = 0; i < frame_count; i += 2, p_in += 4) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[0]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[1]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[2]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[3]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_silence(SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
for (int i = 0; i < frame_count; i += 2) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static void sound_out_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
int err, frame_count;
|
||||
uint8_t *p_in;
|
||||
uint32_t buf_len, rem_len, got_len;
|
||||
struct SoundIoChannelArea *areas;
|
||||
DMAChannel *dma_ch = (DMAChannel *)outstream->userdata; /* C API baby! */
|
||||
int n_channels = outstream->layout.channel_count;
|
||||
bool stop = false;
|
||||
|
||||
//if (!dma_ch->is_active()) {
|
||||
// soundio_outstream_clear_buffer(outstream);
|
||||
// soundio_outstream_pause(outstream, true);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (frame_count_max > 512) {
|
||||
frame_count = 512;
|
||||
}
|
||||
else {
|
||||
frame_count = frame_count_max;
|
||||
}
|
||||
|
||||
buf_len = (frame_count * n_channels) << 1;
|
||||
//frame_count = frame_count_max;
|
||||
|
||||
//LOG_F(INFO, "frame_count_min=%d", frame_count_min);
|
||||
//LOG_F(INFO, "frame_count_max=%d", frame_count_max);
|
||||
//LOG_F(INFO, "channel count: %d", n_channels);
|
||||
//LOG_F(INFO, "buf_len: %d", buf_len);
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
for (rem_len = buf_len; rem_len > 0; rem_len -= got_len) {
|
||||
if (!dma_ch->get_data(rem_len, &got_len, &p_in)) {
|
||||
//LOG_F(INFO, "SndCallback: got_len = %d", got_len);
|
||||
convert_data(p_in, areas, got_len >> 2);
|
||||
//LOG_F(9, "Converted sound data, len = %d", got_len);
|
||||
} else { /* no more data */
|
||||
//memset(buf, 0, rem_len); /* fill the buffer with silence */
|
||||
//LOG_F(9, "Inserted silence, len = %d", rem_len);
|
||||
|
||||
/* fill the buffer with silence */
|
||||
//LOG_F(ERROR, "rem_len=%d", rem_len);
|
||||
insert_silence(areas, rem_len >> 2);
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
LOG_F(INFO, "pausing result: %s",
|
||||
soundio_strerror(soundio_outstream_pause(outstream, true)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
long AWACDevice::sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
AWACDevice *this_ptr = static_cast<AWACDevice*>(user_data); /* C API baby! */
|
||||
|
||||
if (!this_ptr->dma_out_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!this_ptr->dma_out_ch->get_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
void AWACDevice::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, sound_out_callback,
|
||||
status_callback, (void *)this))) {
|
||||
LOG_F(ERROR, "AWAC: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != awac_freqs[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "AWAC: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_end()
|
||||
{
|
||||
}
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converter (AWAC) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "i2c.h"
|
||||
#include "dbdma.h"
|
||||
#include "soundserver.h"
|
||||
|
||||
/** AWAC registers offsets. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** AWAC manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Apple source calls this kValidData but doesn't explain
|
||||
what it actually means. It seems like it's used to check
|
||||
if the sound codec is available.
|
||||
*/
|
||||
#define AWAC_AVAILABLE 0x40
|
||||
|
||||
|
||||
/** Audio processor chip (TDA7433) emulation. */
|
||||
class AudioProcessor : public I2CDevice {
|
||||
public:
|
||||
AudioProcessor() = default;
|
||||
~AudioProcessor() = default;
|
||||
|
||||
void start_transaction() { this->pos = 0; };
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
if ((sub_addr & 0xF) > 6)
|
||||
return false; /* invalid subaddress -> no acknowledge */
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
LOG_F(INFO, "TDA7433 subaddress = 0x%X, auto increment = %d",
|
||||
this->sub_addr, this->auto_inc);
|
||||
this->pos++;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool send_byte(uint8_t data) {
|
||||
if (!this->pos) {
|
||||
return send_subaddress(data);
|
||||
} else if (this->sub_addr <= 6) {
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X received", data);
|
||||
this->regs[this->sub_addr] = data;
|
||||
if (this->auto_inc) {
|
||||
this->sub_addr++;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; /* invalid sub_addr -> no acknowledge */
|
||||
}
|
||||
};
|
||||
|
||||
bool receive_byte(uint8_t *p_data) {
|
||||
*p_data = this->regs[this->sub_addr];
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X sent", *p_data);
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
||||
uint8_t sub_addr;
|
||||
int pos;
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
|
||||
class AWACDevice : public DMACallback {
|
||||
public:
|
||||
AWACDevice();
|
||||
~AWACDevice();
|
||||
|
||||
void set_dma_out(DMAChannel *dma_out_ch);
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* DMACallback methods */
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
protected:
|
||||
void open_stream(int sample_rate);
|
||||
|
||||
private:
|
||||
static long sound_out_callback(cubeb_stream* stream, void* user_data,
|
||||
void const* input_buffer, void* output_buffer,
|
||||
long req_frames);
|
||||
|
||||
uint32_t snd_ctrl_reg = {0};
|
||||
uint16_t control_regs[8] = {0}; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
AudioProcessor *audio_proc;
|
||||
|
||||
SoundServer *snd_server;
|
||||
|
||||
bool out_stream_ready;
|
||||
int out_sample_rate;
|
||||
|
||||
DMAChannel *dma_out_ch;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWAC_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,78 +25,73 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include "devices/adb.h"
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#include <thirdparty/SDL2/include/SDL_keycode.h>
|
||||
#include <thirdparty/SDL2/include/SDL_mouse.h>
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
//set data streams as clear
|
||||
// set data streams as clear
|
||||
this->adb_mouse_register0 = 0x8080;
|
||||
|
||||
input_stream_len = 0;
|
||||
input_stream_len = 0;
|
||||
output_stream_len = 2;
|
||||
|
||||
adb_keybd_register3 = 0x6201;
|
||||
adb_mouse_register3 = 0x6302;
|
||||
|
||||
keyboard_access_no = adb_encoded;
|
||||
mouse_access_no = adb_relative;
|
||||
mouse_access_no = adb_relative;
|
||||
}
|
||||
|
||||
ADB_Bus::~ADB_Bus() {
|
||||
|
||||
}
|
||||
ADB_Bus::~ADB_Bus() {}
|
||||
|
||||
bool ADB_Bus::listen(int device, int reg) {
|
||||
if (device == keyboard_access_no) {
|
||||
if (adb_keybd_listen(reg)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (device == mouse_access_no) {
|
||||
} else if (device == mouse_access_no) {
|
||||
if (adb_mouse_listen(reg)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::talk(int device, int reg, uint16_t value) {
|
||||
//temp code
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::bus_reset() {
|
||||
//temp code
|
||||
// temp code
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ADB_Bus::set_addr(int dev_addr, int new_addr) {
|
||||
//temp code
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::flush(int dev_addr) {
|
||||
//temp code
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,8 +102,9 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_keybd_evt)) {
|
||||
//Poll our SDL key event for any keystrokes.
|
||||
// Poll our SDL key event for any keystrokes.
|
||||
switch (adb_keybd_evt.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (adb_keybd_evt.key.keysym.sym) {
|
||||
@@ -323,36 +319,36 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
ask_key_pressed = 0x5C;
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
//ask_key_pressed = 0x33;
|
||||
// ask_key_pressed = 0x33;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x40;
|
||||
mod_key_pressed = 0x40;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
//ask_key_pressed = 0x39;
|
||||
// ask_key_pressed = 0x39;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x20;
|
||||
mod_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_RALT:
|
||||
case SDLK_RCTRL: //Temp key for Control key
|
||||
//ask_key_pressed = 0x36;
|
||||
case SDLK_RCTRL: // Temp key for Control key
|
||||
// ask_key_pressed = 0x36;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x8;
|
||||
mod_key_pressed = 0x8;
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
//ask_key_pressed = 0x38;
|
||||
// ask_key_pressed = 0x38;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x4;
|
||||
mod_key_pressed = 0x4;
|
||||
break;
|
||||
case SDLK_LALT:
|
||||
//ask_key_pressed = 0x3A;
|
||||
// ask_key_pressed = 0x3A;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x2;
|
||||
mod_key_pressed = 0x2;
|
||||
break;
|
||||
case SDLK_LCTRL: //Temp key for the Command/Apple key
|
||||
//ask_key_pressed = 0x37;
|
||||
case SDLK_LCTRL: // Temp key for the Command/Apple key
|
||||
// ask_key_pressed = 0x37;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x1;
|
||||
mod_key_pressed = 0x1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -363,15 +359,14 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
adb_keybd_register0 &= (ask_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
else if (adb_keybd_register0 & 0x80) {
|
||||
} else if (adb_keybd_register0 & 0x80) {
|
||||
adb_keybd_register0 &= 0xFF7F;
|
||||
adb_keybd_register0 &= (ask_key_pressed);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
|
||||
//check if mod keys are being pressed
|
||||
// check if mod keys are being pressed
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register0 |= (mod_key_pressed << 8);
|
||||
@@ -386,25 +381,24 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
adb_keybd_register0 |= 0x8000;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
else if (adb_keybd_register0 & 0x80)
|
||||
} else if (adb_keybd_register0 & 0x80)
|
||||
adb_keybd_register0 |= 0x0080;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register2 &= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
confirm_ask_reg_2 = false;
|
||||
confirm_ask_reg_2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((reg != 1)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -414,6 +408,7 @@ bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_mouse_evt)) {
|
||||
if (adb_mouse_evt.motion.x) {
|
||||
this->adb_mouse_register0 &= 0x7F;
|
||||
@@ -421,11 +416,9 @@ bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if (adb_mouse_evt.motion.xrel < 0) {
|
||||
if (adb_mouse_evt.motion.xrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F;
|
||||
}
|
||||
else if (adb_mouse_evt.motion.xrel >= 63) {
|
||||
} else if (adb_mouse_evt.motion.xrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
|
||||
}
|
||||
}
|
||||
@@ -436,15 +429,12 @@ bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if (adb_mouse_evt.motion.yrel < 0) {
|
||||
if (adb_mouse_evt.motion.yrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F00;
|
||||
}
|
||||
else if (adb_mouse_evt.motion.yrel >= 63) {
|
||||
} else if (adb_mouse_evt.motion.yrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F00;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (adb_mouse_evt.type) {
|
||||
@@ -454,17 +444,16 @@ bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
this->adb_mouse_register0 |= 0x8000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (reg == 0) {
|
||||
output_data_stream[0] = (adb_mouse_register0 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register0 & 0xff);
|
||||
}
|
||||
else if (reg == 3) {
|
||||
} else if (reg == 3) {
|
||||
output_data_stream[0] = (adb_mouse_register3 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register3 & 0xff);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -482,4 +471,4 @@ int ADB_Bus::get_input_len() {
|
||||
|
||||
int ADB_Bus::get_output_len() {
|
||||
return output_stream_len;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,18 +23,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ADB_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#endif
|
||||
|
||||
enum adb_default_values {
|
||||
adb_reserved0, adb_reserved1, adb_encoded, adb_relative,
|
||||
adb_absolute, adb_reserved5, adb_reserved6, adb_reserved7,
|
||||
adb_other8, adb_other9, adb_other10, adb_other11,
|
||||
adb_other12, adb_other13, adb_other14, adb_other15
|
||||
enum adb_default_values {
|
||||
adb_reserved0,
|
||||
adb_reserved1,
|
||||
adb_encoded,
|
||||
adb_relative,
|
||||
adb_absolute,
|
||||
adb_reserved5,
|
||||
adb_reserved6,
|
||||
adb_reserved7,
|
||||
adb_other8,
|
||||
adb_other9,
|
||||
adb_other10,
|
||||
adb_other11,
|
||||
adb_other12,
|
||||
adb_other13,
|
||||
adb_other14,
|
||||
adb_other15
|
||||
};
|
||||
|
||||
class ADB_Bus
|
||||
{
|
||||
class ADB_Bus {
|
||||
public:
|
||||
ADB_Bus();
|
||||
~ADB_Bus();
|
||||
@@ -58,29 +72,29 @@ private:
|
||||
int keyboard_access_no;
|
||||
int mouse_access_no;
|
||||
|
||||
//Keyboard Variables
|
||||
// Keyboard Variables
|
||||
|
||||
uint16_t adb_keybd_register0;
|
||||
uint16_t adb_keybd_register2;
|
||||
uint16_t adb_keybd_register3;
|
||||
|
||||
SDL_Event adb_keybd_evt;
|
||||
//SDL_Event adb_keybd_evt;
|
||||
|
||||
uint8_t ask_key_pressed;
|
||||
uint8_t mod_key_pressed;
|
||||
|
||||
bool confirm_ask_reg_2;
|
||||
|
||||
//Mouse Variables
|
||||
SDL_Event adb_mouse_evt;
|
||||
// Mouse Variables
|
||||
//SDL_Event adb_mouse_evt;
|
||||
|
||||
uint16_t adb_mouse_register0;
|
||||
uint16_t adb_mouse_register3;
|
||||
|
||||
uint8_t input_data_stream[16]; //temp buffer
|
||||
uint8_t input_data_stream[16]; // temp buffer
|
||||
int input_stream_len;
|
||||
uint8_t output_data_stream[16]; //temp buffer
|
||||
uint8_t output_data_stream[16]; // temp buffer
|
||||
int output_stream_len;
|
||||
};
|
||||
|
||||
#endif /* ADB_H */
|
||||
#endif /* ADB_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,28 +21,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include "dbdma.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "endianswap.h"
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd *p_cmd)
|
||||
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
|
||||
{
|
||||
/* load DMACmd from physical memory */
|
||||
memcpy((uint8_t *)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16);
|
||||
this->start_cb = start_cb;
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd()
|
||||
{
|
||||
void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
/* load DMACmd from physical memory */
|
||||
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16);
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
|
||||
get_next_cmd(this->cmd_ptr, &cmd_struct);
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; /* clear wake bit (DMA spec, 5.5.3.4) */
|
||||
|
||||
switch(cmd_struct.cmd_key >> 4) {
|
||||
switch (cmd_struct.cmd_key >> 4) {
|
||||
case 0:
|
||||
LOG_F(9, "Executing DMA Command OUTPUT_MORE");
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
@@ -53,11 +59,11 @@ uint8_t DMAChannel::interpret_cmd()
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
//this->dma_cb->dma_push(
|
||||
// this->dma_cb->dma_push(
|
||||
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
|
||||
// cmd_struct.req_count);
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_ptr += 16;
|
||||
break;
|
||||
case 1:
|
||||
@@ -70,11 +76,11 @@ uint8_t DMAChannel::interpret_cmd()
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
//this->dma_cb->dma_push(
|
||||
// this->dma_cb->dma_push(
|
||||
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
|
||||
// cmd_struct.req_count);
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_ptr += 16;
|
||||
break;
|
||||
case 2:
|
||||
@@ -106,8 +112,7 @@ uint8_t DMAChannel::interpret_cmd()
|
||||
}
|
||||
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
if (size != 4) {
|
||||
@@ -115,7 +120,7 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
res = 0; /* ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74) */
|
||||
break;
|
||||
@@ -129,8 +134,7 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size)
|
||||
return res;
|
||||
}
|
||||
|
||||
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint16_t mask, old_stat, new_stat;
|
||||
|
||||
if (size != 4) {
|
||||
@@ -138,12 +142,12 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size)
|
||||
return;
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
value = BYTESWAP_32(value);
|
||||
old_stat = this->ch_stat;
|
||||
|
||||
switch(offset) {
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
|
||||
LOG_F(INFO, "New ChannelStatus value = 0x%X", new_stat);
|
||||
|
||||
@@ -188,13 +192,14 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size)
|
||||
}
|
||||
}
|
||||
|
||||
int DMAChannel::get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
/* dead or idle channel? -> no more data */
|
||||
LOG_F(WARNING, "Dead/idle channel -> no more data");
|
||||
return -1; /* dead or idle channel? -> no more data */
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
/* interpret DBDMA program until we get data or become idle */
|
||||
@@ -206,20 +211,20 @@ int DMAChannel::get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data
|
||||
if (this->queue_len) {
|
||||
if (this->queue_len >= req_len) {
|
||||
LOG_F(9, "Return req_len = %d data", req_len);
|
||||
*p_data = this->queue_data;
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = req_len;
|
||||
this->queue_len -= req_len;
|
||||
this->queue_len -= req_len;
|
||||
this->queue_data += req_len;
|
||||
} else { /* return less data than req_len */
|
||||
LOG_F(9, "Return queue_len = %d data", this->queue_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = this->queue_len;
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = this->queue_len;
|
||||
this->queue_len = 0;
|
||||
}
|
||||
return 0; /* tell the caller there is more data */
|
||||
return DmaPullResult::MoreData; /* tell the caller there is more data */
|
||||
}
|
||||
|
||||
return -1; /* tell the caller there is no more data */
|
||||
return DmaPullResult::NoMoreData; /* tell the caller there is no more data */
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active()
|
||||
@@ -243,11 +248,10 @@ void DMAChannel::start()
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->dma_cb->dma_start();
|
||||
this->start_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::resume()
|
||||
{
|
||||
void DMAChannel::resume() {
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "Cannot resume DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
@@ -256,13 +260,11 @@ void DMAChannel::resume()
|
||||
LOG_F(INFO, "Resuming DMA channel");
|
||||
}
|
||||
|
||||
void DMAChannel::abort()
|
||||
{
|
||||
void DMAChannel::abort() {
|
||||
LOG_F(INFO, "Aborting DMA channel");
|
||||
}
|
||||
|
||||
void DMAChannel::pause()
|
||||
{
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
this->dma_cb->dma_end();
|
||||
this->stop_cb();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,57 +29,55 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DB_DMA_H
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_LO = 12,
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_LO = 12,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
enum {
|
||||
CH_STAT_ACTIVE = 0x400,
|
||||
CH_STAT_DEAD = 0x800,
|
||||
CH_STAT_WAKE = 0x1000,
|
||||
CH_STAT_FLUSH = 0x2000,
|
||||
CH_STAT_PAUSE = 0x4000,
|
||||
CH_STAT_RUN = 0x8000
|
||||
CH_STAT_ACTIVE = 0x400,
|
||||
CH_STAT_DEAD = 0x800,
|
||||
CH_STAT_WAKE = 0x1000,
|
||||
CH_STAT_FLUSH = 0x2000,
|
||||
CH_STAT_PAUSE = 0x4000,
|
||||
CH_STAT_RUN = 0x8000
|
||||
};
|
||||
|
||||
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
|
||||
typedef struct DMACmd {
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits;
|
||||
uint8_t cmd_key;
|
||||
uint32_t address;
|
||||
uint32_t cmd_arg;
|
||||
uint16_t res_count;
|
||||
uint16_t xfer_stat;
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits;
|
||||
uint8_t cmd_key;
|
||||
uint32_t address;
|
||||
uint32_t cmd_arg;
|
||||
uint16_t res_count;
|
||||
uint16_t xfer_stat;
|
||||
} DMACmd;
|
||||
|
||||
class DMACallback {
|
||||
public:
|
||||
virtual void dma_start(void) = 0;
|
||||
virtual void dma_end(void) = 0;
|
||||
//virtual void dma_push(uint8_t *buf, int size) = 0;
|
||||
//virtual void dma_pull(uint8_t *buf, int size) = 0;
|
||||
};
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel {
|
||||
class DMAChannel : public DmaOutChannel {
|
||||
public:
|
||||
DMAChannel(DMACallback *cb) { this->dma_cb = cb; };
|
||||
DMAChannel() = default;
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
bool is_active();
|
||||
bool is_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
|
||||
protected:
|
||||
void get_next_cmd(uint32_t cmd_addr, DMACmd *p_cmd);
|
||||
void get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
uint8_t interpret_cmd(void);
|
||||
|
||||
void start(void);
|
||||
@@ -88,12 +86,14 @@ protected:
|
||||
void pause(void);
|
||||
|
||||
private:
|
||||
DMACallback *dma_cb = 0;
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
std::function<void(void)> start_cb; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb; // DMA channel stop callback
|
||||
|
||||
uint32_t queue_len;
|
||||
uint8_t* queue_data;
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
|
||||
uint32_t queue_len;
|
||||
uint8_t* queue_data;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Core definitions for direct memory access (DMA) emulation. */
|
||||
|
||||
#ifndef DMA_CORE_H
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
MoreData, // data source has more data to be pulled
|
||||
NoMoreData, // data source has no more data to be pulled
|
||||
};
|
||||
|
||||
class DmaOutChannel {
|
||||
public:
|
||||
virtual bool is_active() = 0;
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -37,6 +37,7 @@ enum HWCompType : int {
|
||||
I2C_DEV = 61, /* I2C device */
|
||||
ADB_HOST = 70, /* ADB host */
|
||||
ADB_DEV = 71, /* ADB device */
|
||||
INT_CTRL = 80, /* interrupt controller */
|
||||
SND_SERVER = 100, /* host sound server */
|
||||
};
|
||||
|
||||
@@ -46,8 +47,12 @@ class HWComponent {
|
||||
public:
|
||||
virtual ~HWComponent() = default;
|
||||
|
||||
virtual std::string get_name(void) { return this->name; };
|
||||
virtual void set_name(std::string name) { this->name = name; };
|
||||
virtual std::string get_name(void) {
|
||||
return this->name;
|
||||
};
|
||||
virtual void set_name(std::string name) {
|
||||
this->name = name;
|
||||
};
|
||||
|
||||
virtual bool supports_type(HWCompType type) = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,27 +27,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
public:
|
||||
virtual void start_transaction() = 0;
|
||||
virtual void start_transaction() = 0;
|
||||
virtual bool send_subaddress(uint8_t sub_addr) = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
virtual bool receive_byte(uint8_t *p_data) = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
virtual bool receive_byte(uint8_t* p_data) = 0;
|
||||
};
|
||||
|
||||
/** Base class for I2C hosts */
|
||||
class I2CBus {
|
||||
public:
|
||||
I2CBus() { std::memset(this->dev_list, 0, sizeof(this->dev_list)); };
|
||||
~I2CBus() { std::memset(this->dev_list, 0, sizeof(this->dev_list)); };
|
||||
I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
~I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
|
||||
virtual void register_device(uint8_t dev_addr, I2CDevice *dev_obj) {
|
||||
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
|
||||
if (this->dev_list[dev_addr]) {
|
||||
throw std::invalid_argument(std::string("I2C address already taken!"));
|
||||
}
|
||||
@@ -78,7 +82,7 @@ public:
|
||||
return this->dev_list[dev_addr]->send_byte(data);
|
||||
};
|
||||
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t *p_data) {
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
@@ -86,7 +90,7 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
I2CDevice *dev_list[128]; /* list of registered I2C devices */
|
||||
I2CDevice* dev_list[128]; /* list of registered I2C devices */
|
||||
};
|
||||
|
||||
#endif /* I2C_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,9 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include "hwcomponent.h"
|
||||
#include "mmiodevice.h"
|
||||
|
||||
/**
|
||||
@file Contains definitions for PowerMacintosh machine ID registers.
|
||||
@@ -35,6 +36,39 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Register location and value meaning are board-dependent.
|
||||
*/
|
||||
|
||||
/**
|
||||
Machine ID register for Nubus Power Macs.
|
||||
It's located at physical address 0x5FFFFFFC and contains four bytes:
|
||||
+0 uint16_t signature = 0xA55A
|
||||
+1 uint8_t machine_type (3 - PowerMac)
|
||||
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
|
||||
*/
|
||||
class NubusMacID : public MMIODevice {
|
||||
public:
|
||||
NubusMacID(const uint16_t id) {
|
||||
this->name = "Nubus-Machine-id";
|
||||
this->id[0] = 0xA5;
|
||||
this->id[1] = 0x5A;
|
||||
this->id[2] = (id >> 8) & 0xFF;
|
||||
this->id[3] = id & 0xFF;
|
||||
};
|
||||
~NubusMacID() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
};
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
return (offset < 4 ? this->id[offset] : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint8_t id[4];
|
||||
};
|
||||
|
||||
/**
|
||||
The machine ID for the Gossamer board is accesible at 0xFF000004 (phys).
|
||||
It contains a 16-bit value revealing machine's capabilities like bus speed,
|
||||
@@ -44,7 +78,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) { this->id = id, this->name = "Machine-id"; };
|
||||
GossamerID(const uint16_t id) {
|
||||
this->id = id, this->name = "Machine-id";
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
@@ -52,10 +88,11 @@ public:
|
||||
};
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0); };
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{}; /* not writable */
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,16 +22,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "hwcomponent.h"
|
||||
|
||||
/** Abstract class representing a simple, memory-mapped I/O device */
|
||||
class MMIODevice : public HWComponent {
|
||||
public:
|
||||
virtual uint32_t read(uint32_t reg_start, uint32_t offset, int size) = 0;
|
||||
virtual uint32_t read(uint32_t reg_start, uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual ~MMIODevice() = default;
|
||||
virtual ~MMIODevice() = default;
|
||||
};
|
||||
|
||||
#endif /* MMIO_DEVICE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,12 +19,13 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include "nvram.h"
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
@@ -34,8 +35,7 @@ using namespace std;
|
||||
/** the signature for NVRAM backing file identification. */
|
||||
static char NVRAM_FILE_ID[] = "DINGUSPPCNVRAM";
|
||||
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
{
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size) {
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
@@ -44,35 +44,30 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
this->init();
|
||||
}
|
||||
|
||||
NVram::~NVram()
|
||||
{
|
||||
NVram::~NVram() {
|
||||
this->save();
|
||||
if (this->storage)
|
||||
delete this->storage;
|
||||
}
|
||||
|
||||
uint8_t NVram::read_byte(uint32_t offset)
|
||||
{
|
||||
uint8_t NVram::read_byte(uint32_t offset) {
|
||||
return (this->storage[offset]);
|
||||
}
|
||||
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val)
|
||||
{
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val) {
|
||||
this->storage[offset] = val;
|
||||
}
|
||||
|
||||
void NVram::init() {
|
||||
char sig[sizeof(NVRAM_FILE_ID)];
|
||||
char sig[sizeof(NVRAM_FILE_ID)];
|
||||
uint16_t data_size;
|
||||
|
||||
ifstream f(this->file_name, ios::in | ios::binary);
|
||||
|
||||
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) || \
|
||||
!f.read((char *)&data_size, sizeof(data_size)) || \
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || \
|
||||
data_size != this->ram_size || \
|
||||
!f.read((char *)this->storage, this->ram_size))
|
||||
{
|
||||
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) ||
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
|
||||
!f.read((char*)this->storage, this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file. \n");
|
||||
memset(this->storage, 0, sizeof(this->ram_size));
|
||||
}
|
||||
@@ -80,16 +75,15 @@ void NVram::init() {
|
||||
f.close();
|
||||
}
|
||||
|
||||
void NVram::save()
|
||||
{
|
||||
void NVram::save() {
|
||||
ofstream f(this->file_name, ios::out | ios::binary);
|
||||
|
||||
/* write file identification */
|
||||
f.write(NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID));
|
||||
f.write((char *)&this->ram_size, sizeof(this->ram_size));
|
||||
f.write((char*)&this->ram_size, sizeof(this->ram_size));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char *)this->storage, this->ram_size);
|
||||
f.write((char*)this->storage, this->ram_size);
|
||||
|
||||
f.close();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef NVRAM_H
|
||||
#define NVRAM_H
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
|
||||
@@ -31,22 +31,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
automatically saved to and restored from the dedicated file.
|
||||
*/
|
||||
|
||||
class NVram
|
||||
{
|
||||
class NVram {
|
||||
public:
|
||||
NVram(std::string file_name = "nvram.bin", uint32_t ram_size = 8192);
|
||||
~NVram();
|
||||
|
||||
uint8_t read_byte(uint32_t offset);
|
||||
void write_byte(uint32_t offset, uint8_t value);
|
||||
void write_byte(uint32_t offset, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string file_name; /* file name for the backing file. */
|
||||
uint16_t ram_size; /* NVRAM size. */
|
||||
uint8_t* storage;
|
||||
uint16_t ram_size; /* NVRAM size. */
|
||||
uint8_t* storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
void init();
|
||||
void save();
|
||||
};
|
||||
|
||||
#endif /* NVRAM_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,51 +22,58 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_DEVICE_H
|
||||
#define PCI_DEVICE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "mmiodevice.h"
|
||||
#include "pcihost.h"
|
||||
|
||||
/* convert little-endian DWORD to big-endian DWORD */
|
||||
#define LE2BE(x) (x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24)
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
CFG_REG_CMD = 0x04, // command/status register
|
||||
CFG_REG_BAR0 = 0x10, // base address register 0
|
||||
CFG_REG_BAR1 = 0x14, // base address register 1
|
||||
CFG_REG_BAR2 = 0x18, // base address register 2
|
||||
CFG_REG_BAR3 = 0x1C, // base address register 3
|
||||
CFG_REG_BAR4 = 0x20, // base address register 4
|
||||
CFG_REG_BAR5 = 0x24, // base address register 5
|
||||
CFG_EXP_BASE = 0x30, // expansion ROM base
|
||||
CFG_REG_CMD = 0x04, // command/status register
|
||||
CFG_REG_BAR0 = 0x10, // base address register 0
|
||||
CFG_REG_BAR1 = 0x14, // base address register 1
|
||||
CFG_REG_BAR2 = 0x18, // base address register 2
|
||||
CFG_REG_BAR3 = 0x1C, // base address register 3
|
||||
CFG_REG_BAR4 = 0x20, // base address register 4
|
||||
CFG_REG_BAR5 = 0x24, // base address register 5
|
||||
CFG_EXP_BASE = 0x30, // expansion ROM base
|
||||
};
|
||||
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name) { this->pci_name = name; };
|
||||
PCIDevice(std::string name) {
|
||||
this->pci_name = name;
|
||||
};
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space(void) = 0;
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{ return false; };
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
};
|
||||
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{ return false; };
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/* configuration space access methods */
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size) = 0;
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) = 0;
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size) = 0;
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) = 0;
|
||||
|
||||
virtual void set_host(PCIHost* host_instance) { this->host_instance = host_instance; };
|
||||
virtual void set_host(PCIHost* host_instance) {
|
||||
this->host_instance = host_instance;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost *host_instance; // host bridge instance to call back
|
||||
uint32_t base_addr; // base address register 0
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
uint32_t base_addr; // base address register 0
|
||||
};
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
|
||||
uint8_t MESHController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::BusStatus0:
|
||||
LOG_F(9, "MESH: read from BusStatus0 register");
|
||||
return 0;
|
||||
case MeshReg::MeshID:
|
||||
LOG_F(INFO, "MESH: read from MeshID register");
|
||||
return this->chip_id; // tell them who we are
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: read from unimplemented register at offset %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MESHController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Sequence register", value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to BusStatus1 register", value);
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to IntMask register", value);
|
||||
break;
|
||||
case MeshReg::Interrupt:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Interrupt register", value);
|
||||
break;
|
||||
case MeshReg::SourceID:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SourceID register", value);
|
||||
break;
|
||||
case MeshReg::SyncParms:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SyncParms register", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: write to unimplemented register at offset %d", reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller definitions. */
|
||||
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
class MESHController {
|
||||
public:
|
||||
MESHController(uint8_t mesh_id) { this->chip_id = mesh_id; };
|
||||
~MESHController() = default;
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t chip_id; // Chip ID for the MESH controller
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
@@ -1,46 +1,38 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
|
||||
// The uniquely Gekko opcodes for the processor - ppcgekkoopcodes.cpp
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include "ppcemu.h"
|
||||
|
||||
void ppc_psq_l(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_lu(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_st(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_stu(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller emulation. */
|
||||
|
||||
#include "ncr53c94.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t Ncr53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
LOG_F(9, "NCR53C94: reading from register %d", reg_offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Ncr53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
LOG_F(INFO, "NCR53C94: writing 0x%X to %d register", value, reg_offset);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller definitions. */
|
||||
|
||||
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
|
||||
The corresponding functionality is provided by the 53C94 compatible
|
||||
cell in the custom Curio IC (Am79C950).
|
||||
*/
|
||||
|
||||
#ifndef NCR53C94_H
|
||||
#define NCR53C94_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** NCR 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Status = 4,
|
||||
Interrupt = 5,
|
||||
Seq_Step = 6,
|
||||
FIFO_Flags = 7,
|
||||
Config_1 = 8,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Xfer_Cnt_Hi = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
/** NCR 53C94 write registers */
|
||||
namespace Write {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Dest_Bus_ID = 4,
|
||||
Sel_Timeout = 5,
|
||||
Synch_Period = 6,
|
||||
Synch_Offset = 7,
|
||||
Config_1 = 8,
|
||||
Clk_Conv_Fac = 9,
|
||||
Test_Mode = 0xA,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Chip_ID = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
class Ncr53C94 {
|
||||
public:
|
||||
Ncr53C94() = default;
|
||||
~Ncr53C94() = default;
|
||||
|
||||
// NCR 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
};
|
||||
|
||||
#endif // NCR53C94_H
|
||||
@@ -0,0 +1,558 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** VIA-CUDA combo device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda() {
|
||||
this->name = "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_SR] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 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;
|
||||
|
||||
// PRAM is part of Cuda
|
||||
this->pram_obj = std::unique_ptr<NVram> (new NVram("pram.bin", 256));
|
||||
|
||||
this->adb_obj = new ADB_Bus();
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
void ViaCuda::init() {
|
||||
this->old_tip = 0;
|
||||
this->old_byteack = 0;
|
||||
this->treq = 1;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
this->poll_rate = 11;
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
uint8_t res;
|
||||
|
||||
LOG_F(9, "Read VIA reg %d", reg);
|
||||
|
||||
res = this->via_regs[reg & 0xF];
|
||||
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
res = this->via_regs[VIA_B];
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_T1CL:
|
||||
res = this->via_regs[VIA_T1CL];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_T1;
|
||||
case VIA_T2CL:
|
||||
res = this->via_regs[VIA_T2CL];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_T2;
|
||||
case VIA_SR:
|
||||
res = this->via_regs[VIA_SR];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_SR;
|
||||
case VIA_IFR:
|
||||
res = this->via_regs[VIA_IFR];
|
||||
if (this->via_regs[VIA_IFR] & this->via_regs[VIA_IER])
|
||||
res |= 0x80;
|
||||
break;
|
||||
case VIA_IER:
|
||||
res |= 0x80; /* bit 7 always reads as "1" */
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value) {
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
this->via_regs[VIA_B] = value;
|
||||
write(value);
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
this->via_regs[VIA_DIRB] = value;
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
this->via_regs[VIA_DIRA] = value;
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
this->via_regs[VIA_PCR] = value;
|
||||
break;
|
||||
case VIA_ACR:
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
this->via_regs[VIA_ACR] = value;
|
||||
break;
|
||||
case VIA_IER:
|
||||
this->via_regs[VIA_IER] = (value & 0x80) ? value & 0x7F : this->via_regs[VIA_IER] & ~value;
|
||||
LOG_F(9, "VIA_IER updated to 0x%X", this->via_regs[VIA_IER]);
|
||||
print_enabled_ints();
|
||||
break;
|
||||
default:
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::print_enabled_ints() {
|
||||
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this->via_regs[VIA_IER] & (1 << i))
|
||||
LOG_F(INFO, "VIA %s interrupt enabled", via_int_src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ViaCuda::ready() {
|
||||
return ((this->via_regs[VIA_DIRB] & 0x38) == 0x30);
|
||||
}
|
||||
|
||||
inline void ViaCuda::assert_sr_int() {
|
||||
this->via_regs[VIA_IFR] |= 0x84;
|
||||
}
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
if (!ready()) {
|
||||
LOG_F(WARNING, "Cuda not ready!");
|
||||
return;
|
||||
}
|
||||
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
/* return if there is no state change */
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
LOG_F(9, "Cuda state changed!");
|
||||
|
||||
this->old_tip = new_tip;
|
||||
this->old_byteack = new_byteack;
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
process_packet();
|
||||
|
||||
/* start response transaction */
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
}
|
||||
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
}
|
||||
|
||||
assert_sr_int(); /* send dummy byte as idle acknowledge or attention */
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
|
||||
if (this->in_count < 16) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
assert_sr_int(); /* tell the system we've read the data */
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
assert_sr_int(); /* tell the system we've written the data */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[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++);
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
LOG_F(9, "OutBufHandler: sending next byte 0x%X", this->out_buf[this->out_pos]);
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
} else if (this->is_open_ended) {
|
||||
LOG_F(9, "OutBufHandler: switching to next handler");
|
||||
this->out_handler = this->next_out_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
(this->*out_handler)();
|
||||
} else {
|
||||
LOG_F(9, "Sending last byte");
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::response_header(uint32_t pkt_type, uint32_t pkt_flag) {
|
||||
this->out_buf[0] = pkt_type;
|
||||
this->out_buf[1] = pkt_flag;
|
||||
this->out_buf[2] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_count = 3;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::error_response(uint32_t error) {
|
||||
this->out_buf[0] = CUDA_PKT_ERROR;
|
||||
this->out_buf[1] = error;
|
||||
this->out_buf[2] = this->in_buf[0];
|
||||
this->out_buf[3] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_count = 4;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::process_packet() {
|
||||
if (this->in_count < 2) {
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!");
|
||||
error_response(CUDA_ERR_BAD_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this->in_buf[0]) {
|
||||
case CUDA_PKT_ADB:
|
||||
LOG_F(9, "Cuda: ADB packet received \n");
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
LOG_F(9, "Cuda: pseudo command packet received");
|
||||
LOG_F(9, "Command: 0x%X", this->in_buf[1]);
|
||||
LOG_F(9, "Data count: %d", this->in_count);
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d", this->in_buf[0]);
|
||||
error_response(CUDA_ERR_BAD_PKT);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
int adb_dev = cmd_byte >> 4; // 2 for keyboard, 3 for mouse
|
||||
int cmd = cmd_byte & 0xF;
|
||||
|
||||
if (!cmd) {
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if (cmd == 1) {
|
||||
LOG_F(9, "Cuda: ADB Flush command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if ((cmd & 0xC) == 8) {
|
||||
LOG_F(9, "Cuda: ADB Listen command requested");
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->listen(adb_dev, adb_reg)) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
for (int data_ptr = 0; data_ptr < adb_obj->get_output_len(); data_ptr++) {
|
||||
this->in_buf[(2 + data_ptr)] = adb_obj->get_output_byte(data_ptr);
|
||||
}
|
||||
} else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else if ((cmd & 0xC) == 0xC) {
|
||||
LOG_F(9, "Cuda: ADB Talk command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->talk(adb_dev, adb_reg, this->in_buf[2])) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
uint16_t addr;
|
||||
int i;
|
||||
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
// if starting address is within PRAM region
|
||||
// prepare to transfer PRAM content, othwesise we will send zeroes
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
this->cur_pram_addr = addr - CUDA_PRAM_START;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
} else if (addr >= CUDA_ROM_START) {
|
||||
// HACK: Cuda ROM dump requsted so let's partially fake it
|
||||
this->out_buf[3] = 0; // empty copyright string
|
||||
WRITE_WORD_BE_A(&this->out_buf[4], 0x0019U);
|
||||
WRITE_WORD_BE_A(&this->out_buf[6], CUDA_FW_VERSION_MAJOR);
|
||||
WRITE_WORD_BE_A(&this->out_buf[8], CUDA_FW_VERSION_MINOR);
|
||||
this->out_count += 7;
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
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);
|
||||
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
|
||||
// otherwise, ignore data in in_buf
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr - CUDA_PRAM_START + i) & 0xFF,
|
||||
this->in_buf[4+i]);
|
||||
}
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
// this command is open-ended so set up the corresponding context
|
||||
this->cur_pram_addr = addr;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
this->is_open_ended = true;
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
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]);
|
||||
break;
|
||||
case CUDA_WRITE_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
// transfer data from in_buf to PRAM
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr + i) & 0xFF, this->in_buf[4+i]);
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_FILE_SERVER_FLAG:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: File server flag on");
|
||||
this->file_server = true;
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: File server flag off");
|
||||
this->file_server = false;
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_AUTOPOLL_RATE:
|
||||
this->poll_rate = this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to %d ms", this->poll_rate);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_GET_AUTOPOLL_RATE:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[3] = this->poll_rate;
|
||||
this->out_count++;
|
||||
break;
|
||||
case CUDA_SET_DEVICE_LIST:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->device_mask = ((uint16_t)in_buf[2]) >> 8;
|
||||
this->device_mask += ((uint16_t)in_buf[3]);
|
||||
break;
|
||||
case CUDA_GET_DEVICE_LIST:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
|
||||
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]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
break;
|
||||
case CUDA_COMB_FMT_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
if (this->in_count >= 5) {
|
||||
i2c_comb_transaction(
|
||||
this->in_buf[2], this->in_buf[3], this->in_buf[4], &this->in_buf[5], this->in_count - 5);
|
||||
}
|
||||
break;
|
||||
case CUDA_OUT_PB0: /* undocumented call! */
|
||||
LOG_F(INFO, "Cuda: send %d to PB0", (int)(this->in_buf[2]));
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x! \n", cmd);
|
||||
//exit(0);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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]);
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes) {
|
||||
int op_type = dev_addr & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
/* send data to the target I2C device until there is no more data to send
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (op_type) { /* read request initiate an open ended transaction */
|
||||
this->curr_i2c_addr = dev_addr;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::i2c_handler;
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_comb_transaction(
|
||||
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes) {
|
||||
int op_type = dev_addr1 & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
if ((dev_addr & 0xFE) != (dev_addr1 & 0xFE)) {
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!");
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->send_subaddress(dev_addr, sub_addr)) {
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
/* send data to the target I2C device until there is no more data to send
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!op_type) { /* return dummy response for writes */
|
||||
LOG_F(WARNING, "Combined I2C - write request!");
|
||||
} else {
|
||||
this->curr_i2c_addr = dev_addr;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::i2c_handler;
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -45,10 +45,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "nvram.h"
|
||||
#include "adb.h"
|
||||
#include "i2c.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
@@ -70,6 +72,20 @@ enum {
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
};
|
||||
|
||||
/** IFR and IER register bits */
|
||||
enum {
|
||||
IER_SET = 0x80,
|
||||
IER_CLR = 0x00,
|
||||
|
||||
IFR_CA2 = 0x01,
|
||||
IFR_CA1 = 0x02,
|
||||
IFR_SR = 0x04,
|
||||
IFR_CB2 = 0x08,
|
||||
IFR_CB1 = 0x10,
|
||||
IFR_T2 = 0x20,
|
||||
IFR_T1 = 0x40,
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
@@ -88,14 +104,26 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
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_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. */
|
||||
@@ -103,15 +131,23 @@ 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 */
|
||||
};
|
||||
|
||||
/** 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
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus
|
||||
{
|
||||
/** Latest Cuda Firmware version. */
|
||||
#define CUDA_FW_VERSION_MAJOR 0x0002
|
||||
#define CUDA_FW_VERSION_MINOR 0x0029
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
public:
|
||||
ViaCuda();
|
||||
~ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST);
|
||||
@@ -133,14 +169,18 @@ private:
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
uint8_t poll_rate;
|
||||
int32_t real_time = 0;
|
||||
bool file_server;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
bool is_open_ended;
|
||||
uint8_t curr_i2c_addr;
|
||||
bool is_open_ended; // true if current transaction is open-ended
|
||||
uint8_t curr_i2c_addr; // current I2C address
|
||||
uint8_t cur_pram_addr; // current PRAM address, range 0...FF
|
||||
|
||||
void (ViaCuda::*out_handler)(void);
|
||||
void (ViaCuda::*next_out_handler)(void);
|
||||
|
||||
NVram* pram_obj;
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
ADB_Bus* adb_obj;
|
||||
|
||||
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
|
||||
@@ -150,20 +190,20 @@ private:
|
||||
void assert_sr_int();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
//void cuda_response_packet();
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command(uint8_t cmd_byte, int data_count);
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
void out_buf_handler(void);
|
||||
void i2c_handler(void);
|
||||
|
||||
/* 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 */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) emulation. */
|
||||
|
||||
#include "mace.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) definitions. */
|
||||
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
|
||||
// MACE registers offsets
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
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?
|
||||
};
|
||||
|
||||
class MaceController {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
~MaceController() = default;
|
||||
|
||||
// MACE registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -1,259 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
#include "macio.h"
|
||||
#include "viacuda.h"
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
|
||||
{
|
||||
this->nvram = new NVram();
|
||||
|
||||
this->viacuda = new ViaCuda();
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||
|
||||
this->screamer = new AWACDevice();
|
||||
this->snd_out_dma = new DMAChannel(this->screamer);
|
||||
this->screamer->set_dma_out(this->snd_out_dma);
|
||||
}
|
||||
|
||||
HeathrowIC::~HeathrowIC()
|
||||
{
|
||||
if (this->nvram)
|
||||
delete(this->nvram);
|
||||
|
||||
if (this->viacuda)
|
||||
delete(this->viacuda);
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
|
||||
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case CFG_REG_BAR0: // base address register
|
||||
value = LE2BE(value);
|
||||
if (value == 0xFFFFFFFF) {
|
||||
LOG_F(ERROR, "%s err: BAR0 block size determination not \
|
||||
implemented yet \n", this->name.c_str());
|
||||
}
|
||||
else if (value & 1) {
|
||||
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
||||
}
|
||||
else if (value & 0x06) {
|
||||
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
||||
}
|
||||
else {
|
||||
this->base_addr = value & 0xFFF80000;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
switch(offset >> 8) {
|
||||
case 8:
|
||||
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch(offset >> 8) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
res = mio_ctrl_read(offset, size);
|
||||
break;
|
||||
case 8:
|
||||
res = dma_read(offset - 0x8000, size);
|
||||
break;
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
res = this->viacuda->read((offset - 0x16000) >> 9);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
mio_ctrl_write(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
dma_write(offset - 0x8000, value, size);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->int_clear2;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->int_levels2;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->int_clear1;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
res = 0xF0700000UL;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
this->int_mask2 = value;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
this->int_clear2 = value;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
this->int_levels2 = value;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->int_mask1 = value;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
this->int_levels1 = value;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
this->feat_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Apple memory-mapped I/O controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AMIC::AMIC()
|
||||
{
|
||||
this->name = "Apple Memory-mapped I/O Controller";
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
/* add memory mapped I/O region for the AMIC control registers */
|
||||
if (!mem_ctrl->add_mmio_region(0x50F00000, 0x00040000, this)) {
|
||||
LOG_F(ERROR, "Couldn't register AMIC registers!");
|
||||
}
|
||||
|
||||
this->scsi = std::unique_ptr<Ncr53C94> (new Ncr53C94());
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
|
||||
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
|
||||
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
}
|
||||
|
||||
bool AMIC::supports_type(HWCompType type) {
|
||||
if ((type == HWCompType::MMIO_DEV)
|
||||
|| (type == HWCompType::INT_CTRL)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Interrupt Register
|
||||
void AMIC::process_interrupt(uint32_t cookie) {
|
||||
bool confirm_interrupt = false;
|
||||
uint32_t bit_field = 0;
|
||||
|
||||
if (this->int_ctrl_reg & 0x40) {
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
switch (cookie) {
|
||||
case DEV_ID::VIA_CUDA:
|
||||
if (this->viacuda->read(VIA_IFR)) {
|
||||
bit_field = (1 << VIA1_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
else if (via2_slot_int_enable || via2_int_enable) {
|
||||
bit_field = (1 << VIA2_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::SCC_B:
|
||||
case DEV_ID::SCC_A:
|
||||
bit_field = (1 << SCC_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
case DEV_ID::ETHERNET:
|
||||
bit_field = (1 << Eth_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
case DEV_ID::Swim3_DMA:
|
||||
case DEV_ID::ETHERNET_DMA_OUT:
|
||||
case DEV_ID::ETHERNET_DMA_IN:
|
||||
case DEV_ID::SCC_A_DMA_OUT:
|
||||
case DEV_ID::SCC_A_DMA_IN:
|
||||
case DEV_ID::SCC_B_DMA_OUT:
|
||||
case DEV_ID::SCC_B_DMA_IN:
|
||||
if (dma_int_reg0) {
|
||||
bit_field = (1 << DMA_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::SOUND_DMA_OUT:
|
||||
case DEV_ID::SOUND_DMA_IN:
|
||||
if (dma_int_reg1) {
|
||||
bit_field = (1 << DMA_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::NMI:
|
||||
bit_field = (1 << NMI_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_interrupt(bit_field);
|
||||
}
|
||||
|
||||
uint32_t AMIC::ack_interrupt(uint32_t device_bits) {
|
||||
bool confirm_interrupt = false;
|
||||
bool ack_bit = this->int_ctrl_reg & 0x80;
|
||||
|
||||
if (device_bits & this->int_ctrl_reg)
|
||||
confirm_interrupt = true;
|
||||
|
||||
if (confirm_interrupt && ack_bit)
|
||||
ack_cpu_interrupt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t phase_val;
|
||||
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
process_interrupt(VIA_CUDA);
|
||||
return this->viacuda->read(offset >> 9);
|
||||
case 4: // SCC registers
|
||||
this->escc->read_compat((offset >> 1) & 0xF);
|
||||
this->process_interrupt(SCC_A);
|
||||
return 0;
|
||||
case 0xA: // MACE registers
|
||||
return this->mace->read((offset >> 4) & 0xF);
|
||||
case 0x10: // SCSI registers
|
||||
return this->scsi->read((offset >> 4) & 0xF);
|
||||
case 0x14: // Sound registers
|
||||
switch (offset) {
|
||||
case AMICReg::Snd_Stat_0:
|
||||
case AMICReg::Snd_Stat_1:
|
||||
case AMICReg::Snd_Stat_2:
|
||||
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Phase0:
|
||||
case AMICReg::Snd_Phase1:
|
||||
case AMICReg::Snd_Phase2:
|
||||
// the sound phase register is organized as follows:
|
||||
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
|
||||
// into the DMA buffer and 'p' is an undocumented prescale value
|
||||
// HWInit doesn't care about. Let's hope it will be sufficient
|
||||
// to return 0 for prescale.
|
||||
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
|
||||
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
return this->snd_out_ctrl;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
return this->snd_out_dma->read_stat();
|
||||
}
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::Diag_Reg:
|
||||
return 0xFFU; // this value allows the machine to boot normally
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
return this->scsi_dma_cs;
|
||||
case AMICReg::Int_Ctrl:
|
||||
if (this->int_ctrl_reg & 0x80) {
|
||||
ack_cpu_interrupt();
|
||||
}
|
||||
return this->int_ctrl_reg;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
this->viacuda->write(offset >> 9, value);
|
||||
return;
|
||||
case 4:
|
||||
this->escc->write_compat((offset >> 1) & 0xF, value);
|
||||
return;
|
||||
case 0xA: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x10:
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x14: // Sound registers
|
||||
switch(offset) {
|
||||
case AMICReg::Snd_Ctrl_0:
|
||||
case AMICReg::Snd_Ctrl_1:
|
||||
case AMICReg::Snd_Ctrl_2:
|
||||
// remember values of sound control registers
|
||||
this->imm_snd_regs[offset & 3] = value;
|
||||
// transfer control information to the sound codec when ready
|
||||
if ((this->imm_snd_regs[0] & 0xC0) == PDM_SND_CTRL_VALID) {
|
||||
this->awacs->write_ctrl(
|
||||
(this->imm_snd_regs[1] >> 4) | (this->imm_snd_regs[0] & 0x3F),
|
||||
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
|
||||
);
|
||||
}
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
mask = 0xFF00U >> (8 * (offset & 1));
|
||||
this->snd_buf_size = (this->snd_buf_size & ~mask) |
|
||||
((value & 0xFF) << (8 * ((offset & 1) ^1)));
|
||||
this->snd_buf_size &= ~3; // sound buffer size is always a multiple of 4
|
||||
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(9, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->start_output_dma();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
}
|
||||
}
|
||||
this->snd_out_ctrl = value;
|
||||
return;
|
||||
case AMICReg::Snd_In_Ctrl:
|
||||
LOG_F(INFO, "AMIC Sound In Ctrl updated, val=%x", value);
|
||||
return;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
this->snd_out_dma->write_dma_out_ctrl(value);
|
||||
this->dma_int_reg1 |= 0x2;
|
||||
this->process_interrupt(DEV_ID::SOUND_DMA_OUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
via2_slot_int_enable = value;
|
||||
break;
|
||||
case AMICReg::VIA2_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Interrupt Enable Register updated, val=%x", value);
|
||||
via2_int_enable = value;
|
||||
break;
|
||||
case AMICReg::Video_Mode_Reg:
|
||||
LOG_F(INFO, "AMIC Video Mode Register set to %x", value);
|
||||
break;
|
||||
case AMICReg::Int_Ctrl:
|
||||
LOG_F(INFO, "AMIC Interrupt Control Register set to %X", value);
|
||||
if (value & 0x80) {
|
||||
value &= 0xC0;
|
||||
ack_cpu_interrupt();
|
||||
}
|
||||
this->int_ctrl_reg = value;
|
||||
break;
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
case AMICReg::DMA_Base_Addr_1:
|
||||
case AMICReg::DMA_Base_Addr_2:
|
||||
case AMICReg::DMA_Base_Addr_3:
|
||||
mask = 0xFF000000UL >> (8 * (offset & 3));
|
||||
this->dma_base = (this->dma_base & ~mask) |
|
||||
((value & 0xFF) << (8 * (3 - (offset & 3))));
|
||||
LOG_F(9, "AMIC: DMA base address set to 0x%X", this->dma_base);
|
||||
this->process_interrupt(DEV_ID::PERCH_DMA);
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Xmt_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Transmit DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCSI DMA Ctrl updated, val=%x", value);
|
||||
this->scsi_dma_cs = value;
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Rcv_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SWIM3_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SWIM3 DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch A DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch A DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch B DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch B DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register write, offset=%x, val=%x",
|
||||
offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================== DMA related stuff =============================
|
||||
AmicSndOutDma::AmicSndOutDma()
|
||||
{
|
||||
this->dma_out_ctrl = 0;
|
||||
this->enabled = false;
|
||||
}
|
||||
|
||||
bool AmicSndOutDma::is_active()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AmicSndOutDma::init(uint32_t buf_base, uint32_t buf_samples)
|
||||
{
|
||||
this->out_buf0 = buf_base + AMIC_SND_BUF0_OFFS;
|
||||
this->out_buf1 = buf_base + AMIC_SND_BUF1_OFFS;
|
||||
|
||||
this->out_buf_len = buf_samples * 2 * 2;
|
||||
|
||||
this->snd_buf_num = 0;
|
||||
this->cur_buf_pos = 0;
|
||||
}
|
||||
|
||||
uint8_t AmicSndOutDma::read_stat()
|
||||
{
|
||||
return this->dma_out_ctrl;
|
||||
}
|
||||
|
||||
void AmicSndOutDma::write_dma_out_ctrl(uint8_t value)
|
||||
{
|
||||
// clear interrupt flags
|
||||
value &= ~PDM_DMA_INTS_MASK;
|
||||
this->dma_out_ctrl = value;
|
||||
LOG_F(9, "AMIC: Sound out DMA control set to 0x%X", value);
|
||||
}
|
||||
|
||||
DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
int rem_len = this->out_buf_len - this->cur_buf_pos;
|
||||
if (rem_len <= 0) {
|
||||
if (!this->snd_buf_num) {
|
||||
// signal buffer 0 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF0;
|
||||
// TODO: generate IE0 interrupt if enabled
|
||||
} else {
|
||||
// signal buffer 1 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF1;
|
||||
// TODO: generate IE1 interrupt if enabled
|
||||
}
|
||||
|
||||
// check DMA enable flag after buffer 1 was processed
|
||||
// if it's false stop delivering sound data
|
||||
// this will effectively stop audio playback
|
||||
if (this->snd_buf_num && !this->enabled) {
|
||||
this->cur_buf_pos = 0;
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
this->cur_buf_pos = 0; // reset buffer position
|
||||
this->snd_buf_num ^= 1; // toggle sound buffers
|
||||
rem_len = this->out_buf_len; // buffer size = full buffer
|
||||
}
|
||||
|
||||
uint32_t len = std::min((uint32_t)rem_len, req_len);
|
||||
|
||||
*p_data = mmu_get_dma_mem(
|
||||
(this->snd_buf_num ? this->out_buf1 : this->out_buf0) + this->cur_buf_pos,
|
||||
len);
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Apple memory-mapped I/O controller emulation. */
|
||||
|
||||
#ifndef AMIC_H
|
||||
#define AMIC_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** AMIC sound buffers are located at fixed offsets from DMA base. */
|
||||
#define AMIC_SND_BUF0_OFFS 0x10000
|
||||
#define AMIC_SND_BUF1_OFFS 0x12000
|
||||
|
||||
// PDM HWInit source defines two constants: kExpBit = 0x80 and kCmdBit = 0x40
|
||||
// I don't know what they means but it seems that their combination will
|
||||
// cause sound control parameters to be transferred to the sound chip.
|
||||
#define PDM_SND_CTRL_VALID 0xC0
|
||||
|
||||
#define PDM_DMA_IF1 0x80 // DMA interrupt flag => buffer 1 drained
|
||||
#define PDM_DMA_IF0 0x40 // DMA interrupt flag => buffer 0 drained
|
||||
#define PDM_DMA_INTS_MASK 0xF0 // mask for clearing all interrupt flags
|
||||
|
||||
/** AMIC-specific sound output DMA implementation. */
|
||||
class AmicSndOutDma : public DmaOutChannel {
|
||||
public:
|
||||
AmicSndOutDma();
|
||||
~AmicSndOutDma() = default;
|
||||
|
||||
bool is_active();
|
||||
void init(uint32_t buf_base, uint32_t buf_samples);
|
||||
void enable() { this->enabled = true; };
|
||||
void disable() { this->enabled = false; };
|
||||
uint8_t read_stat();
|
||||
void write_dma_out_ctrl(uint8_t value);
|
||||
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
uint8_t dma_out_ctrl;
|
||||
|
||||
uint32_t out_buf0;
|
||||
uint32_t out_buf1;
|
||||
uint32_t out_buf_len;
|
||||
uint32_t snd_buf_num;
|
||||
uint32_t cur_buf_pos;
|
||||
};
|
||||
|
||||
/* AMIC registers offsets from AMIC base (0x50F00000). */
|
||||
enum AMICReg : uint32_t {
|
||||
// Sound control registers
|
||||
Snd_Ctrl_0 = 0x14000, // audio codec control register 0
|
||||
Snd_Ctrl_1 = 0x14001, // audio codec control register 1
|
||||
Snd_Ctrl_2 = 0x14002, // audio codec control register 2
|
||||
Snd_Stat_0 = 0x14004, // audio codec status register 0
|
||||
Snd_Stat_1 = 0x14005, // audio codec status register 1
|
||||
Snd_Stat_2 = 0x14006, // audio codec status register 2
|
||||
Snd_Buf_Size_Hi = 0x14008, // sound buffer size, high-order byte
|
||||
Snd_Buf_Size_Lo = 0x14009, // sound buffer size, low-order byte
|
||||
Snd_Phase0 = 0x1400C, // high-order byte of the sound phase register
|
||||
Snd_Phase1 = 0x1400D, // middle byte of the sound phase register
|
||||
Snd_Phase2 = 0x1400E, // low-order byte of the sound phase register
|
||||
Snd_Out_Ctrl = 0x14010, // audio codec output control register
|
||||
Snd_In_Ctrl = 0x14011, // audio codec input control register
|
||||
Snd_In_DMA = 0x14014, // sound input DMA status/control register
|
||||
Snd_Out_DMA = 0x14018, // sound output DMA status/control register
|
||||
|
||||
// VIA2 registers
|
||||
VIA2_Slot_INT = 0x26002,
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_INT = 0x26003,
|
||||
VIA2_IER = 0x26013,
|
||||
|
||||
// Video control registers
|
||||
Video_Mode_Reg = 0x28000,
|
||||
|
||||
// Interrupt registers
|
||||
Int_Ctrl = 0x2A000,
|
||||
DMA_Int_0 = 0x2A008,
|
||||
Bus_Error_Int_0 = 0x2A009,
|
||||
DMA_Int_1 = 0x2A00A,
|
||||
Bus_Error_Int_1 = 0x2A00B,
|
||||
|
||||
// Undocumented diagnostics register
|
||||
Diag_Reg = 0x2C000,
|
||||
|
||||
// DMA control registers
|
||||
DMA_Base_Addr_0 = 0x31000,
|
||||
DMA_Base_Addr_1 = 0x31001,
|
||||
DMA_Base_Addr_2 = 0x31002,
|
||||
DMA_Base_Addr_3 = 0x31003,
|
||||
Enet_DMA_Xmt_Ctrl = 0x31C20,
|
||||
SCSI_DMA_Ctrl = 0x32008,
|
||||
Enet_DMA_Rcv_Ctrl = 0x32028,
|
||||
SWIM3_DMA_Ctrl = 0x32068,
|
||||
SCC_DMA_Xmt_A_Ctrl = 0x32088,
|
||||
SCC_DMA_Rcv_A_Ctrl = 0x32098,
|
||||
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
|
||||
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
|
||||
};
|
||||
|
||||
enum AMICIntReg : uint32_t {
|
||||
VIA1_Interrupt = 0,
|
||||
VIA2_Interrupt = 1,
|
||||
SCC_Interrupt = 2,
|
||||
Eth_Interrupt = 3,
|
||||
DMA_Interrupt = 4,
|
||||
NMI_Interrupt = 5,
|
||||
INT_Mode = 6,
|
||||
ACK_Bit = 7,
|
||||
};
|
||||
|
||||
enum {
|
||||
FDC_PENDING = 0x40,
|
||||
};
|
||||
|
||||
/** Apple Memory-mapped I/O controller device. */
|
||||
class AMIC : public MMIODevice, public InterruptCtrl {
|
||||
public:
|
||||
AMIC();
|
||||
~AMIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
void process_interrupt(uint32_t cookie);
|
||||
uint32_t ack_interrupt(uint32_t device_bits);
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void dma_reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
|
||||
|
||||
uint32_t dma_base = 0; // DMA physical base address
|
||||
uint16_t snd_buf_size = 0; // sound buffer size in bytes
|
||||
uint8_t snd_out_ctrl = 0;
|
||||
|
||||
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
uint8_t int_ctrl_reg = 0;
|
||||
uint8_t dma_int_reg0 = 0;
|
||||
uint8_t dma_int_reg1 = 0;
|
||||
uint8_t via2_int_enable = 0;
|
||||
uint8_t via2_slot_int_enable = 0;
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Ncr53C94> scsi;
|
||||
std::unique_ptr<EsccController> escc;
|
||||
std::unique_ptr<MaceController> mace;
|
||||
std::unique_ptr<ViaCuda> viacuda;
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif // AMIC_H
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->screamer->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->screamer.get()),
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer.get())
|
||||
);
|
||||
|
||||
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
|
||||
this->escc = std::unique_ptr<EsccController>(new EsccController());
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_device(DEV_ID dev_id){
|
||||
return (1 << dev_id);
|
||||
};
|
||||
|
||||
void HeathrowIC::process_interrupt(uint32_t cookie) {
|
||||
bool confirm_interrupt = false;
|
||||
uint32_t bit_field = 0;
|
||||
|
||||
switch (cookie) {
|
||||
case DEV_ID::SOUND_DMA_OUT:
|
||||
bit_field = (1 << DEV_ID::SOUND_DMA_OUT);
|
||||
break;
|
||||
case DEV_ID::SCSI0:
|
||||
bit_field = (1 << DEV_ID::SCSI0);
|
||||
break;
|
||||
case DEV_ID::VIA_CUDA:
|
||||
bit_field = (1 << DEV_ID::VIA_CUDA);
|
||||
break;
|
||||
case DEV_ID::SWIM3:
|
||||
bit_field = (1 << DEV_ID::SWIM3);
|
||||
break;
|
||||
case DEV_ID::DAVBUS:
|
||||
bit_field = (1 << DEV_ID::DAVBUS);
|
||||
break;
|
||||
}
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_interrupt(bit_field);
|
||||
};
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
|
||||
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
switch (reg_offs) {
|
||||
case CFG_REG_BAR0: // base address register
|
||||
value = LE2BE(value);
|
||||
if (value == 0xFFFFFFFF) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: BAR0 block size determination not \
|
||||
implemented yet \n",
|
||||
this->name.c_str());
|
||||
} else if (value & 1) {
|
||||
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
||||
} else if (value & 0x06) {
|
||||
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
||||
} else {
|
||||
this->base_addr = value & 0xFFF80000;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
this->ack_interrupt(DEV_ID::SOUND_DMA_OUT);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
res = mio_ctrl_read(offset, size);
|
||||
break;
|
||||
case 8:
|
||||
res = dma_read(offset - 0x8000, size);
|
||||
break;
|
||||
case 0x10:
|
||||
res = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
return this->escc->read_compat((offset >> 4) & 0xF);
|
||||
case 0x13: // ESCC MacRISC
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
res = this->viacuda->read((offset - 0x16000) >> 9);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
mio_ctrl_write(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
dma_write(offset - 0x8000, value, size);
|
||||
break;
|
||||
case 0x10:
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
this->process_interrupt(DEV_ID::SCSI0);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
this->escc->write_compat((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x13: // ESCC MacRISC
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
this->process_interrupt(DEV_ID::VIA_CUDA);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
case 0x10:
|
||||
LOG_F(0, "read from MIO:Int_Events2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::events2);
|
||||
break;
|
||||
case 0x14:
|
||||
LOG_F(0, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask2);
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(0, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear2);
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(0, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::levels2);
|
||||
break;
|
||||
case 0x20:
|
||||
LOG_F(0, "read from MIO:Int_Events1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::events1);
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(0, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask1);
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(0, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear1);
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(0, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::levels1);
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
||||
res = this->macio_id;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = BYTESWAP_32(this->feat_ctrl);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
case 0x10:
|
||||
LOG_F(0, "write %x to MIO:Int_Events2 register \n", value);
|
||||
this->update_reg(REG_ID::events2, value);
|
||||
break;
|
||||
case 0x14:
|
||||
LOG_F(0, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->update_reg(REG_ID::mask2, value);
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(0, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->update_reg(REG_ID::clear2, value);
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(0, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->update_reg(REG_ID::levels2, value);
|
||||
break;
|
||||
case 0x20:
|
||||
LOG_F(0, "write %x to MIO:Int_Events1 register \n", value);
|
||||
this->update_reg(REG_ID::events1, value);
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(0, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->update_reg(REG_ID::mask1, value);
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(0, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->update_reg(REG_ID::clear1, value);
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(0, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->update_reg(REG_ID::levels1, value);
|
||||
break;
|
||||
case 0x34:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case 0x38:
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
||||
this->aux_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x \n", value, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(0, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
if (!(this->feat_ctrl & 1)) {
|
||||
LOG_F(9, "Heathrow: Monitor sense enabled");
|
||||
} else {
|
||||
LOG_F(9, "Heathrow: Monitor sense disabled");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
InterruptCtrl::InterruptCtrl() {
|
||||
}
|
||||
|
||||
void InterruptCtrl::update_reg(REG_ID retrieve_reg, uint32_t bit_setting) {
|
||||
switch (retrieve_reg) {
|
||||
case mask1:
|
||||
int_mask1 = bit_setting;
|
||||
break;
|
||||
case clear1:
|
||||
int_clear1 = bit_setting;
|
||||
int_events1 &= ~int_clear1;
|
||||
break;
|
||||
case events1:
|
||||
int_events1 = bit_setting;
|
||||
break;
|
||||
case levels1:
|
||||
int_levels1 = bit_setting;
|
||||
break;
|
||||
case mask2:
|
||||
int_mask2 = bit_setting;
|
||||
break;
|
||||
case clear2:
|
||||
int_clear2 = bit_setting;
|
||||
int_events2 &= ~int_clear2;
|
||||
break;
|
||||
case events2:
|
||||
int_events2 = bit_setting;
|
||||
break;
|
||||
case levels2:
|
||||
int_levels2 = bit_setting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t InterruptCtrl::retrieve_reg(REG_ID retrieve_reg) {
|
||||
switch (retrieve_reg) {
|
||||
case mask1:
|
||||
return int_mask1;
|
||||
break;
|
||||
case clear1:
|
||||
return int_clear1;
|
||||
break;
|
||||
case events1:
|
||||
return int_events1;
|
||||
break;
|
||||
case levels1:
|
||||
return int_levels1;
|
||||
break;
|
||||
case mask2:
|
||||
return int_mask2;
|
||||
break;
|
||||
case clear2:
|
||||
return int_clear2;
|
||||
break;
|
||||
case events2:
|
||||
return int_events2;
|
||||
break;
|
||||
case levels2:
|
||||
return int_levels2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t InterruptCtrl::ack_interrupt(uint32_t device_bits) {
|
||||
bool confirm_interrupt = false;
|
||||
|
||||
int_events1 |= device_bits;
|
||||
if (int_events1 & int_mask1)
|
||||
confirm_interrupt = true;
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_cpu_interrupt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InterruptCtrl::ack_cpu_interrupt() {
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0x0);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HWINTERRUPT_H
|
||||
#define HWINTERRUPT_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
enum DEV_ID {
|
||||
SCSI_DMA = 0,
|
||||
Swim3_DMA = 1,
|
||||
IDE0_DMA = 2,
|
||||
IDE1_DMA = 3,
|
||||
SCC_A_DMA_OUT = 4,
|
||||
SCC_A_DMA_IN = 5,
|
||||
SCC_B_DMA_OUT = 6,
|
||||
SCC_B_DMA_IN = 7,
|
||||
SOUND_DMA_OUT = 8,
|
||||
SOUND_DMA_IN = 9,
|
||||
VIDEO_OUT = 10,
|
||||
VIDEO_IN = 11,
|
||||
SCSI0 = 12,
|
||||
IDE0 = 13,
|
||||
IDE1 = 14,
|
||||
SCC_A = 15,
|
||||
SCC_B = 16,
|
||||
DAVBUS = 17,
|
||||
VIA_CUDA = 18,
|
||||
SWIM3 = 19,
|
||||
NMI = 20,
|
||||
PERCH_DMA = 21,
|
||||
PERCH = 22,
|
||||
ETHERNET_DMA_OUT = 23,
|
||||
ETHERNET_DMA_IN = 24,
|
||||
ETHERNET = 25,
|
||||
SCSI1 = 26,
|
||||
};
|
||||
|
||||
enum REG_ID {
|
||||
mask1 = 0,
|
||||
clear1 = 1,
|
||||
events1 = 2,
|
||||
levels1 = 3,
|
||||
mask2 = 4,
|
||||
clear2 = 5,
|
||||
events2 = 6,
|
||||
levels2 = 7,
|
||||
};
|
||||
|
||||
class InterruptCtrl {
|
||||
public:
|
||||
InterruptCtrl();
|
||||
~InterruptCtrl() = default;
|
||||
|
||||
uint32_t ack_interrupt(uint32_t device_bits);
|
||||
|
||||
virtual uint32_t register_device(DEV_ID dev_id){
|
||||
return 0;
|
||||
};
|
||||
|
||||
void update_reg(REG_ID retrieve_reg, uint32_t bit_setting);
|
||||
uint32_t retrieve_reg(REG_ID retrieve_reg);
|
||||
|
||||
void ack_cpu_interrupt();
|
||||
|
||||
protected:
|
||||
uint32_t int_events1 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_clear1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t int_events2 = 0;
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_clear2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
};
|
||||
|
||||
#endif /* HWINTERRUPT_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -51,16 +51,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include "hwcomponent.h"
|
||||
#include "pcidevice.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcihost.h"
|
||||
#include "viacuda.h"
|
||||
#include "nvram.h"
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
@@ -75,7 +80,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
escc(serial) register space: 0x00013000, size: 0x00001000
|
||||
escc(compat) register space: 0x00012000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc(MacRISC) register space: 0x00013000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc:ch-a register space: 0x00013020, DMA space: 0x00008400, 0x00008500
|
||||
escc:ch-b register space: 0x00013000, DMA space: 0x00008600, 0x00008700
|
||||
@@ -86,24 +93,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice
|
||||
{
|
||||
class HeathrowIC : public PCIDevice,
|
||||
public InterruptCtrl {
|
||||
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::MMIO_DEV; };
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL);
|
||||
};
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) { return false; };
|
||||
bool supports_io_space(void) {
|
||||
return false;
|
||||
};
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* MMIO device methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
uint32_t register_device(DEV_ID dev_id);
|
||||
void process_interrupt(uint32_t cookie);
|
||||
|
||||
protected:
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
void dma_write(uint32_t offset, uint32_t value, int size);
|
||||
@@ -111,35 +126,41 @@ protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
|
||||
private:
|
||||
uint8_t pci_cfg_hdr[256] = {
|
||||
0x6B, 0x10, // vendor ID: Apple Computer Inc.
|
||||
0x10, 0x00, // device ID: Heathrow Mac I/O
|
||||
0x00, 0x00, // PCI command (set to 0 at power-up?)
|
||||
0x00, 0x00, // PCI status (set to 0 at power-up?)
|
||||
0x01, // revision ID
|
||||
0x6B,
|
||||
0x10, // vendor ID: Apple Computer Inc.
|
||||
0x10,
|
||||
0x00, // device ID: Heathrow Mac I/O
|
||||
0x00,
|
||||
0x00, // PCI command (set to 0 at power-up?)
|
||||
0x00,
|
||||
0x00, // PCI status (set to 0 at power-up?)
|
||||
0x01, // revision ID
|
||||
// class code is reported in OF property "class-code" as 0xff0000
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code
|
||||
0xFF, // class code: unassigned
|
||||
0x00, 0x00, // unknown defaults
|
||||
0x00, 0x00 // unknown defaults
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code
|
||||
0xFF, // class code: unassigned
|
||||
0x00,
|
||||
0x00, // unknown defaults
|
||||
0x00,
|
||||
0x00 // unknown defaults
|
||||
};
|
||||
|
||||
uint32_t int_mask2;
|
||||
uint32_t int_clear2;
|
||||
uint32_t int_levels2;
|
||||
uint32_t int_mask1;
|
||||
uint32_t int_clear1;
|
||||
uint32_t int_levels1;
|
||||
uint32_t feat_ctrl; // features control register
|
||||
|
||||
uint32_t macio_id = 0xF0700008UL;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
/* device cells */
|
||||
ViaCuda *viacuda; /* VIA cell with Cuda MCU attached to it */
|
||||
NVram *nvram; /* NVRAM cell */
|
||||
AWACDevice *screamer; /* Screamer audio codec instance */
|
||||
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
|
||||
std::unique_ptr<NVram> nvram; // NVRAM cell
|
||||
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
|
||||
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
|
||||
std::unique_ptr<EsccController> escc; // ESCC serial controller
|
||||
|
||||
DMAChannel *snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/memctrl/hmc.h>
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Highspeed Memory Controller";
|
||||
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
add_mmio_region(0x50F40000, 0x10000, this);
|
||||
|
||||
this->config_reg = 0ULL;
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
bool HMC::supports_type(HWCompType type) {
|
||||
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->config_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
|
||||
void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint64_t bit;
|
||||
|
||||
switch(offset) {
|
||||
case 0:
|
||||
bit = 1ULL << this->bit_pos++;
|
||||
this->config_reg = (value & 1) ? this->config_reg | bit :
|
||||
this->config_reg & ~bit;
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
this->bit_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Highspeed Memory Controller (HMC) is a custom memory
|
||||
and L2 cache controller designed especially for the
|
||||
first generation of the PowerMacintosh computer.
|
||||
*/
|
||||
|
||||
#ifndef HMC_H
|
||||
#define HMC_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HMC();
|
||||
~HMC() = default;
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t config_reg;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,55 +19,59 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
|
||||
#include "memctrlbase.h"
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase()
|
||||
{
|
||||
for (auto ® : mem_regions) {
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
if (entry)
|
||||
delete(entry);
|
||||
}
|
||||
|
||||
for (auto& reg : mem_regions) {
|
||||
if (reg)
|
||||
delete(reg);
|
||||
delete (reg);
|
||||
}
|
||||
this->mem_regions.clear();
|
||||
this->address_map.clear();
|
||||
}
|
||||
|
||||
|
||||
AddressMapEntry *MemCtrlBase::find_range(uint32_t addr)
|
||||
{
|
||||
for (auto &entry : address_map) {
|
||||
if (addr >= entry.start && addr <= entry.end)
|
||||
return &entry;
|
||||
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
for (auto& entry : address_map) {
|
||||
if (addr >= entry->start && addr <= entry->end)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
||||
uint32_t dest_addr, uint32_t type, uint8_t init_val = 0)
|
||||
{
|
||||
AddressMapEntry entry;
|
||||
bool MemCtrlBase::add_mem_region(
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val = 0) {
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
return false;
|
||||
|
||||
uint8_t *reg_content = new uint8_t[size];
|
||||
uint8_t* reg_content = new uint8_t[size];
|
||||
|
||||
this->mem_regions.push_back(reg_content);
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = type;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = reg_content;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = type;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = reg_content;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -75,32 +79,31 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
bool MemCtrlBase::add_rom_region(uint32_t start_addr, uint32_t size) {
|
||||
return add_mem_region(start_addr, size, 0, RT_ROM);
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
|
||||
return add_mem_region(start_addr, size, 0, RT_RAM);
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr)
|
||||
{
|
||||
AddressMapEntry entry, *ref_entry;
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
AddressMapEntry *entry, *ref_entry;
|
||||
|
||||
ref_entry = find_range(dest_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = ref_entry->type | RT_MIRROR;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = ref_entry->mem_ptr;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = ref_entry->type | RT_MIRROR;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = ref_entry->mem_ptr;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -108,9 +111,8 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr)
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
AddressMapEntry *ref_entry;
|
||||
bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size) {
|
||||
AddressMapEntry* ref_entry;
|
||||
uint32_t cpy_size;
|
||||
|
||||
ref_entry = find_range(reg_addr);
|
||||
@@ -124,23 +126,34 @@ bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t *data, uint32_t size
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size,
|
||||
MMIODevice *dev_instance)
|
||||
{
|
||||
AddressMapEntry entry;
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if another region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
if (find_range(start_addr) || find_range(start_addr + size - 1))
|
||||
return false;
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = 0;
|
||||
entry.type = RT_MMIO;
|
||||
entry.devobj = dev_instance;
|
||||
entry.mem_ptr = 0;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = 0;
|
||||
entry->type = RT_MMIO;
|
||||
entry->devobj = dev_instance;
|
||||
entry->mem_ptr = 0;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_rom_region()
|
||||
{
|
||||
for (auto& entry : address_map) {
|
||||
if (entry->type == RT_ROM) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,27 +22,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MEMORY_CONTROLLER_BASE_H
|
||||
#define MEMORY_CONTROLLER_BASE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "mmiodevice.h"
|
||||
|
||||
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 is 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; /* 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 */
|
||||
} AddressMapEntry;
|
||||
|
||||
|
||||
@@ -55,19 +56,20 @@ public:
|
||||
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_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 set_data(uint32_t reg_addr, const uint8_t *data, uint32_t size);
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry *find_range(uint32_t addr);
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_rom_region();
|
||||
|
||||
protected:
|
||||
bool add_mem_region(uint32_t start_addr, uint32_t size, uint32_t dest_addr,
|
||||
uint32_t type, uint8_t init_val);
|
||||
bool add_mem_region(
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t *> mem_regions;
|
||||
std::vector<AddressMapEntry> address_map;
|
||||
std::vector<uint8_t*> mem_regions;
|
||||
std::vector<AddressMapEntry*> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,20 +24,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include "memreadwrite.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "mpc106.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge")
|
||||
{
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") {
|
||||
this->name = "Grackle";
|
||||
|
||||
/* add PCI/ISA I/O space, 64K for now */
|
||||
@@ -50,13 +49,11 @@ MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge")
|
||||
this->io_space_devs.clear();
|
||||
}
|
||||
|
||||
MPC106::~MPC106()
|
||||
{
|
||||
MPC106::~MPC106() {
|
||||
this->pci_0_bus.clear();
|
||||
}
|
||||
|
||||
bool MPC106::supports_type(HWCompType type)
|
||||
{
|
||||
bool MPC106::supports_type(HWCompType type) {
|
||||
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV ||
|
||||
type == HWCompType::PCI_HOST || type == HWCompType::PCI_DEV) {
|
||||
return true;
|
||||
@@ -65,8 +62,7 @@ bool MPC106::supports_type(HWCompType type)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t result;
|
||||
|
||||
if (reg_start == 0xFE000000) {
|
||||
@@ -78,10 +74,9 @@ uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to read from unmapped PCI I/O space, offset=0x%X", offset);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (offset >= 0x200000) {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_read(size);
|
||||
}
|
||||
}
|
||||
@@ -91,8 +86,7 @@ uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
void MPC106::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
||||
if (reg_start == 0xFE000000) {
|
||||
/* broadcast I/O request to devices that support I/O space
|
||||
until a device returns true that means "request accepted" */
|
||||
@@ -102,26 +96,26 @@ void MPC106::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to write to unmapped PCI I/O space, offset=0x%X", offset);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (offset < 0x200000) {
|
||||
this->config_addr = value;
|
||||
}
|
||||
else {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
} else {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_write(value, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_read(uint32_t size)
|
||||
{
|
||||
uint32_t MPC106::pci_read(uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
if (bus_num) {
|
||||
LOG_F(ERROR, "%s err: read attempt from non-local PCI bus, config_addr = %x \n", \
|
||||
this->name.c_str(), this->config_addr);
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-local PCI bus, config_addr = %x \n",
|
||||
this->name.c_str(),
|
||||
this->config_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -129,13 +123,17 @@ uint32_t MPC106::pci_read(uint32_t size)
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
return this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->pci_0_bus.count(dev_num)) {
|
||||
return this->pci_0_bus[dev_num]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
LOG_F(ERROR, "%s err: read attempt from non-existing PCI device %d \n", this->name.c_str(), dev_num);
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-existing PCI device %d \n",
|
||||
this->name.c_str(),
|
||||
dev_num);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -143,14 +141,16 @@ uint32_t MPC106::pci_read(uint32_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::pci_write(uint32_t value, uint32_t size)
|
||||
{
|
||||
void MPC106::pci_write(uint32_t value, uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
if (bus_num) {
|
||||
LOG_F(ERROR, "%s err: write attempt to non-local PCI bus, config_addr = %x \n",
|
||||
this->name.c_str(), this->config_addr);
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-local PCI bus, config_addr = %x \n",
|
||||
this->name.c_str(),
|
||||
this->config_addr);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,65 +158,37 @@ void MPC106::pci_write(uint32_t value, uint32_t size)
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
if (this->pci_0_bus.count(dev_num)) {
|
||||
this->pci_0_bus[dev_num]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
LOG_F(ERROR, "%s err: write attempt to non-existing PCI device %d \n", \
|
||||
this->name.c_str(), dev_num);
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-existing PCI device %d \n",
|
||||
this->name.c_str(),
|
||||
dev_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "read from Grackle register %08X\n", reg_offs);
|
||||
#endif
|
||||
|
||||
switch(size) {
|
||||
case 1:
|
||||
return this->my_pci_cfg_hdr[reg_offs];
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
case 4:
|
||||
return READ_DWORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MPC106 read error: invalid size parameter %d \n", size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return read_mem(&this->my_pci_cfg_hdr[reg_offs], size);
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "write %08X to Grackle register %08X\n", value, reg_offs);
|
||||
#endif
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
switch(size) {
|
||||
case 1:
|
||||
this->my_pci_cfg_hdr[reg_offs] = value & 0xFF;
|
||||
break;
|
||||
case 2:
|
||||
this->my_pci_cfg_hdr[reg_offs] = (value >> 8) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs+1] = value & 0xFF;
|
||||
break;
|
||||
case 4:
|
||||
this->my_pci_cfg_hdr[reg_offs] = (value >> 24) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs+1] = (value >> 16) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs+2] = (value >> 8) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs+3] = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MPC106 read error: invalid size parameter %d \n", size);
|
||||
}
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
@@ -226,9 +198,8 @@ void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
}
|
||||
}
|
||||
|
||||
bool MPC106::pci_register_device(int dev_num, PCIDevice *dev_instance)
|
||||
{
|
||||
if (this->pci_0_bus.count(dev_num)) // is dev_num already registered?
|
||||
bool MPC106::pci_register_device(int dev_num, PCIDevice* dev_instance) {
|
||||
if (this->pci_0_bus.count(dev_num)) // is dev_num already registered?
|
||||
return false;
|
||||
|
||||
this->pci_0_bus[dev_num] = dev_instance;
|
||||
@@ -242,39 +213,37 @@ bool MPC106::pci_register_device(int dev_num, PCIDevice *dev_instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MPC106::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice *obj)
|
||||
{
|
||||
bool MPC106::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) {
|
||||
// FIXME: add sanity checks!
|
||||
return this->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void MPC106::setup_ram()
|
||||
{
|
||||
void MPC106::setup_ram() {
|
||||
uint32_t mem_start, mem_end, ext_mem_start, ext_mem_end, bank_start, bank_end;
|
||||
uint32_t ram_size = 0;
|
||||
|
||||
uint8_t bank_en = this->my_pci_cfg_hdr[0xA0];
|
||||
uint8_t bank_en = this->my_pci_cfg_hdr[0xA0];
|
||||
|
||||
for (int bank = 0; bank < 8; bank++) {
|
||||
if (bank_en & (1 << bank)) {
|
||||
if (bank < 4) {
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x80]);
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x80]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x88]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x90]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x98]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x90]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x98]);
|
||||
} else {
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x84]);
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x84]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x8C]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x94]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x9C]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x94]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x9C]);
|
||||
}
|
||||
bank_start = (((ext_mem_start >> bank * 8) & 3) << 30) |
|
||||
(((mem_start >> bank * 8) & 0xFF) << 20);
|
||||
bank_end = (((ext_mem_end >> bank * 8) & 3) << 30) |
|
||||
(((mem_end >> bank * 8) & 0xFF) << 20) | 0xFFFFFUL;
|
||||
if (bank && bank_start != ram_size)
|
||||
LOG_F(ERROR, "MPC106 error: RAM not contiguous! \n");
|
||||
ram_size += bank_end + 1;
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous! \n");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
||||
It's the central device in the Gossamer architecture.
|
||||
Manual: https://www.nxp.com/docs/en/reference-manual/MPC106UM.pdf
|
||||
|
||||
This code emulates as much functionality as needed to run PowerMac Beige G3.
|
||||
This implies that
|
||||
- we only support address map B
|
||||
- our virtual device reports revision 4.0 as expected by machine firmware
|
||||
*/
|
||||
|
||||
#ifndef MPC106_H_
|
||||
#define MPC106_H_
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
|
||||
public:
|
||||
MPC106();
|
||||
~MPC106();
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* PCI host bridge API */
|
||||
bool pci_register_device(int dev_num, PCIDevice* dev_instance);
|
||||
|
||||
protected:
|
||||
/* PCI access */
|
||||
uint32_t pci_read(uint32_t size);
|
||||
void pci_write(uint32_t value, uint32_t size);
|
||||
|
||||
/* my own PCI configuration registers access */
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
|
||||
bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
void setup_ram(void);
|
||||
|
||||
private:
|
||||
uint8_t my_pci_cfg_hdr[256] = {
|
||||
0x57, 0x10, // vendor ID: Motorola
|
||||
0x02, 0x00, // device ID: MPC106
|
||||
0x06, 0x00, // PCI command
|
||||
0x80, 0x00, // PCI status
|
||||
0x40, // revision ID: 4.0
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code: host bridge
|
||||
0x06, // class code: bridge device
|
||||
0x08, // cache line size
|
||||
0x00, // latency timer
|
||||
0x00, // header type
|
||||
0x00, // BIST Control
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, // Interrupt line
|
||||
0x00, // Interrupt pin
|
||||
0x00, // MIN GNT
|
||||
0x00, // MAX LAT
|
||||
0x00, // Bus number
|
||||
0x00, // Subordinate bus number
|
||||
0x00, // Discount counter
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // Performance monitor command
|
||||
0x00, 0x00, // Performance monitor mode control
|
||||
0xFF, 0xFF,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 0
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 1
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 2
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 3
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF,
|
||||
|
||||
0x00, 0x00, // Power mgt config 1
|
||||
0x00, // Power mgt config 2
|
||||
0xCD, // default value for ODCR
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, // Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Memory Ending Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Ending Address
|
||||
|
||||
0x00, // Memory bank enable
|
||||
0xFF, 0xFF,
|
||||
0x00, // Memory page mode
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x10, 0x00, 0x00, 0xFF, // PICR1
|
||||
0x0C, 0x06, 0x0C, 0x00, // PICR2
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, // ECC single-bit error counter
|
||||
0x00, // ECC single-bit error trigger
|
||||
0x04, // Alternate OS visible paramaters 1
|
||||
0x01, // Alternate OS visible paramaters 2
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x01, // Error enabling 1
|
||||
0x00, // Error detection 1
|
||||
0xFF,
|
||||
0x00, // 60x bus error status
|
||||
0x00, // Error enabling 2
|
||||
0x00, // Error detection 2
|
||||
0xFF,
|
||||
0x00, // PCI bus error status
|
||||
0x00, 0x00, 0x00, 0x00, // 60x/PCI ERROR address
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF,
|
||||
|
||||
0x42, 0x00, 0xFF, 0x0F, // Emulation support config 1
|
||||
0x00, 0x00, 0x00, 0x00, // Modified memory status (no clear)
|
||||
0x20, 0x00, 0x00, 0x00, // Emulation support config 2
|
||||
0x00, 0x00, 0x00, 0x00, // Modified memory status (clear)
|
||||
|
||||
0x00, 0x00, 0x02, 0xFF, // Memory ctrl config 1
|
||||
0x03, 0x00, 0x00, 0x00, // Memory ctrl config 2
|
||||
0x00, 0x00, 0x00, 0x00, // Memory ctrl config 3
|
||||
0x00, 0x00, 0x10, 0x00 // Memory ctrl config 4
|
||||
};
|
||||
|
||||
uint32_t config_addr;
|
||||
// uint32_t config_data;
|
||||
|
||||
std::unordered_map<int, PCIDevice*> pci_0_bus;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,31 +47,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SPD_EEPROM_H
|
||||
#define SPD_EEPROM_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "i2c.h"
|
||||
#include "hwcomponent.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
enum RAMType : int {
|
||||
SDRAM = 4
|
||||
};
|
||||
#include <cinttypes>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
enum RAMType : int { SDRAM = 4 };
|
||||
|
||||
|
||||
class SpdSdram168 : public HWComponent, public I2CDevice {
|
||||
public:
|
||||
SpdSdram168(uint8_t addr) {
|
||||
this->dev_addr = addr;
|
||||
this->pos = 0;
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
~SpdSdram168() = default;
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::RAM; };
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::RAM;
|
||||
};
|
||||
|
||||
void set_capacity(int capacity_megs) {
|
||||
switch(capacity_megs) {
|
||||
switch (capacity_megs) {
|
||||
case 32:
|
||||
this->eeprom_data[3] = 0xC; /* 12 rows */
|
||||
this->eeprom_data[4] = 0x8; /* 8 columns */
|
||||
@@ -95,11 +96,12 @@ public:
|
||||
default:
|
||||
throw std::invalid_argument(std::string("Unsupported capacity!"));
|
||||
}
|
||||
LOG_F(INFO, "SDRAM capacity set to %dMB, I2C addr = 0x%X",
|
||||
capacity_megs, this->dev_addr);
|
||||
LOG_F(INFO, "SDRAM capacity set to %dMB, I2C addr = 0x%X", capacity_megs, this->dev_addr);
|
||||
};
|
||||
|
||||
void start_transaction() { this->pos = 0; };
|
||||
void start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
@@ -112,7 +114,7 @@ public:
|
||||
return true;
|
||||
};
|
||||
|
||||
bool receive_byte(uint8_t *p_data) {
|
||||
bool receive_byte(uint8_t* p_data) {
|
||||
if (this->pos >= this->eeprom_data[0]) {
|
||||
this->pos = 0; /* attempt to read past SPD data should wrap around */
|
||||
}
|
||||
@@ -123,18 +125,18 @@ public:
|
||||
|
||||
private:
|
||||
uint8_t dev_addr; /* I2C address */
|
||||
int pos; /* actual read position */
|
||||
int pos; /* actual read position */
|
||||
|
||||
/* EEPROM content */
|
||||
uint8_t eeprom_data[256] = {
|
||||
128, /* number of bytes present */
|
||||
8, /* log2(EEPROM size) */
|
||||
128, /* number of bytes present */
|
||||
8, /* log2(EEPROM size) */
|
||||
RAMType::SDRAM, /* memory type */
|
||||
|
||||
/* the following fields will be set up in set_capacity() */
|
||||
0, /* number of row addresses */
|
||||
0, /* number of column addresses */
|
||||
0 /* number of banks */
|
||||
0 /* number of banks */
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
||||
It's the central device in the Gossamer architecture.
|
||||
Manual: https://www.nxp.com/docs/en/reference-manual/MPC106UM.pdf
|
||||
|
||||
This code emulates as much functionality as needed to run PowerMac Beige G3.
|
||||
This implies that
|
||||
- we only support address map B
|
||||
- our virtual device reports revision 4.0 as expected by machine firmware
|
||||
*/
|
||||
|
||||
#ifndef MPC106_H_
|
||||
#define MPC106_H_
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unordered_map>
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
|
||||
|
||||
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost
|
||||
{
|
||||
public:
|
||||
MPC106();
|
||||
~MPC106();
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* PCI host bridge API */
|
||||
bool pci_register_device(int dev_num, PCIDevice *dev_instance);
|
||||
|
||||
protected:
|
||||
/* PCI access */
|
||||
uint32_t pci_read(uint32_t size);
|
||||
void pci_write(uint32_t value, uint32_t size);
|
||||
|
||||
/* my own PCI configuration registers access */
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
bool supports_io_space(void) { return true; };
|
||||
|
||||
bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice *obj);
|
||||
|
||||
void setup_ram(void);
|
||||
|
||||
private:
|
||||
uint8_t my_pci_cfg_hdr[256] = {
|
||||
0x57, 0x10, // vendor ID: Motorola
|
||||
0x02, 0x00, // device ID: MPC106
|
||||
0x06, 0x00, // PCI command
|
||||
0x80, 0x00, // PCI status
|
||||
0x40, // revision ID: 4.0
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code: host bridge
|
||||
0x06, // class code: bridge device
|
||||
0x08, // cache line size
|
||||
0x00, // latency timer
|
||||
0x00, // header type
|
||||
0x00, // BIST Control
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, //Interrupt line
|
||||
0x00, //Interrupt pin
|
||||
0x00, //MIN GNT
|
||||
0x00, //MAX LAT
|
||||
0x00, //Bus number
|
||||
0x00, //Subordinate bus number
|
||||
0x00, //Discount counter
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00, //Performance monitor command
|
||||
0x00, 0x00, //Performance monitor mode control
|
||||
0xFF, 0xFF,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, //Performance monitor counter 0
|
||||
0x00, 0x00, 0x00, 0x00, //Performance monitor counter 1
|
||||
0x00, 0x00, 0x00, 0x00, //Performance monitor counter 2
|
||||
0x00, 0x00, 0x00, 0x00, //Performance monitor counter 3
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x00, 0x00, //Power mgt config 1
|
||||
0x00, //Power mgt config 2
|
||||
0xCD, //default value for ODCR
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //Extended Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //Memory Ending Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //Extended Memory Ending Address
|
||||
|
||||
0x00, //Memory bank enable
|
||||
0xFF, 0xFF,
|
||||
0x00, //Memory page mode
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x10, 0x00, 0x00, 0xFF, // PICR1
|
||||
0x0C, 0x06, 0x0C, 0x00, // PICR2
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, //ECC single-bit error counter
|
||||
0x00, //ECC single-bit error trigger
|
||||
0x04, //Alternate OS visible paramaters 1
|
||||
0x01, //Alternate OS visible paramaters 2
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x01, //Error enabling 1
|
||||
0x00, //Error detection 1
|
||||
0xFF,
|
||||
0x00, //60x bus error status
|
||||
0x00, //Error enabling 2
|
||||
0x00, //Error detection 2
|
||||
0xFF,
|
||||
0x00, //PCI bus error status
|
||||
0x00, 0x00, 0x00, 0x00, //60x/PCI ERROR address
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x42, 0x00, 0xFF, 0x0F, //Emulation support config 1
|
||||
0x00, 0x00, 0x00, 0x00, //Modified memory status (no clear)
|
||||
0x20, 0x00, 0x00, 0x00, //Emulation support config 2
|
||||
0x00, 0x00, 0x00, 0x00, //Modified memory status (clear)
|
||||
|
||||
0x00, 0x00, 0x02, 0xFF, //Memory ctrl config 1
|
||||
0x03, 0x00, 0x00, 0x00, //Memory ctrl config 2
|
||||
0x00, 0x00, 0x00, 0x00, //Memory ctrl config 3
|
||||
0x00, 0x00, 0x10, 0x00 //Memory ctrl config 4
|
||||
};
|
||||
|
||||
uint32_t config_addr;
|
||||
//uint32_t config_data;
|
||||
|
||||
std::unordered_map<int, PCIDevice*> pci_0_bus;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice *dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size,
|
||||
PCIDevice *obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) emulation. */
|
||||
|
||||
#include "escc.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
EsccController::EsccController()
|
||||
{
|
||||
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("A"));
|
||||
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("B"));
|
||||
|
||||
this->reg_ptr = 0;
|
||||
}
|
||||
|
||||
uint8_t EsccController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EsccController::read_compat(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write_compat(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
{
|
||||
if (this->reg_ptr) {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
this->write_regs[reg_num] = value;
|
||||
LOG_F(9, "ESCC: writing 0x%X to Channel %s WR%d", value, this->name.c_str(),
|
||||
reg_num);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) definitions. */
|
||||
|
||||
#ifndef ESCC_H
|
||||
#define ESCC_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** ESCC compatible (aka Macintosh legacy) register addressing */
|
||||
namespace Compat {
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_A_Cmd = 1,
|
||||
Port_B_Data = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
};
|
||||
|
||||
/** ESCC MacRISC style register addressing */
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_B_Data = 1,
|
||||
Port_A_Cmd = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
|
||||
/** LocalTalk registers (same in both addressing schemes) */
|
||||
enum LocalTalkReg : uint8_t {
|
||||
Rec_Count = 8,
|
||||
Start_A = 9,
|
||||
Start_B = 0xA,
|
||||
Detect_AB = 0xB,
|
||||
};
|
||||
|
||||
enum WR0Cmd : uint8_t {
|
||||
Point_High = 1,
|
||||
};
|
||||
|
||||
/** ESCC Channel class. */
|
||||
class EsccChannel {
|
||||
public:
|
||||
EsccChannel(std::string name) { this->name = name; };
|
||||
~EsccChannel() = default;
|
||||
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint8_t write_regs[16];
|
||||
};
|
||||
|
||||
/** ESCC Controller class. */
|
||||
class EsccController {
|
||||
public:
|
||||
EsccController();
|
||||
~EsccController() = default;
|
||||
|
||||
// ESCC MacRISC registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
// ESCC compatible registers access
|
||||
uint8_t read_compat(uint8_t reg_offset);
|
||||
void write_compat(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
void write_internal(EsccChannel* ch, uint8_t value);
|
||||
|
||||
std::unique_ptr<EsccChannel> ch_a;
|
||||
std::unique_ptr<EsccChannel> ch_b;
|
||||
|
||||
int reg_ptr; // register pointer for reading/writing (same for both channels)
|
||||
};
|
||||
|
||||
#endif // ESCC_H
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Currently supported audio codecs:
|
||||
- PDM AWACs in Nubus Power Macintosh models
|
||||
- Screamer AWACs in Beige G3
|
||||
|
||||
Author: Max Poliakovski 2019-21
|
||||
*/
|
||||
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AwacsBase::AwacsBase()
|
||||
{
|
||||
// connect to SoundServer
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AwacsBase::~AwacsBase()
|
||||
{
|
||||
// disconnect from SoundServer
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::set_sample_rate(int sr_id)
|
||||
{
|
||||
if (sr_id > this->max_sr_id) {
|
||||
LOG_F(ERROR, "AWACs: invalid sample rate ID %d!", sr_id);
|
||||
} else {
|
||||
this->cur_sample_rate = this->sr_table[sr_id];
|
||||
}
|
||||
};
|
||||
|
||||
void AwacsBase::start_output_dma()
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(this->cur_sample_rate,
|
||||
(void *)this->dma_out_ch))) {
|
||||
LOG_F(ERROR, "AWACs: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->out_stream_ready = true;
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "AWACs: could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::stop_output_dma()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
}
|
||||
|
||||
//=========================== PDM-style AWACs =================================
|
||||
AwacDevicePdm::AwacDevicePdm() : AwacsBase()
|
||||
{
|
||||
static int pdm_awac_freqs[3] = {22050, 29400, 44100};
|
||||
|
||||
// PDM-style AWACs only supports three sample rates
|
||||
this->sr_table = pdm_awac_freqs;
|
||||
this->max_sr_id = 2;
|
||||
}
|
||||
|
||||
uint32_t AwacDevicePdm::read_stat()
|
||||
{
|
||||
LOG_F(INFO, "AWACs-PDM: status requested!");
|
||||
// TODO: return valid status including manufacturer & device IDs
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwacDevicePdm::write_ctrl(uint32_t addr, uint16_t value)
|
||||
{
|
||||
LOG_F(9, "AWACs-PDM: control updated, addr=0x%X, val=0x%X", addr, value);
|
||||
|
||||
if (addr <= 4) {
|
||||
this->ctrl_regs[addr] = value;
|
||||
} else {
|
||||
LOG_F(ERROR, "AWACs-PDM: invalid control register address %d!", addr);
|
||||
}
|
||||
}
|
||||
|
||||
//============================= Screamer AWACs ================================
|
||||
AwacsScreamer::AwacsScreamer() : AwacsBase()
|
||||
{
|
||||
this->audio_proc = std::unique_ptr<AudioProcessor> (new AudioProcessor());
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc.get());
|
||||
|
||||
static int screamer_freqs[8] = {
|
||||
44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
|
||||
};
|
||||
|
||||
this->sr_table = screamer_freqs;
|
||||
this->max_sr_id = 7;
|
||||
}
|
||||
|
||||
uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20);
|
||||
default:
|
||||
LOG_F(ERROR, "Screamer: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(9, "Screamer: new sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(9, "Screamer subframe = %d, reg = %d, data = %08X\n",
|
||||
subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Screamer: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, (void *)this->dma_out_ch))) {
|
||||
LOG_F(ERROR, "Screamer: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(this->sr_table[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != this->sr_table[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(this->sr_table[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "Screamer: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Screamer: could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::dma_end()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converters (AWACs) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Base class for the AWACs codecs. */
|
||||
class AwacsBase {
|
||||
public:
|
||||
AwacsBase();
|
||||
~AwacsBase();
|
||||
|
||||
void set_dma_out(DmaOutChannel *dma_out_ch) {
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
};
|
||||
|
||||
void set_sample_rate(int sr_id);
|
||||
void start_output_dma();
|
||||
void stop_output_dma();
|
||||
|
||||
protected:
|
||||
SoundServer *snd_server; // SoundServer instance pointer
|
||||
DmaOutChannel *dma_out_ch; // DMA output channel instance pointer
|
||||
|
||||
int *sr_table; // pointer to the table of supported sample rates
|
||||
int max_sr_id; // maximum value for sample rate ID
|
||||
|
||||
bool out_stream_ready;
|
||||
int cur_sample_rate;
|
||||
};
|
||||
|
||||
/** AWACs PDM-style sound codec. */
|
||||
class AwacDevicePdm : public AwacsBase {
|
||||
public:
|
||||
AwacDevicePdm();
|
||||
~AwacDevicePdm() = default;
|
||||
|
||||
uint32_t read_stat(void);
|
||||
void write_ctrl(uint32_t addr, uint16_t value);
|
||||
|
||||
void dma_out_start(uint8_t sample_rate_id);
|
||||
void dma_out_stop();
|
||||
|
||||
private:
|
||||
uint16_t ctrl_regs[5]; // 12-bit wide control registers
|
||||
};
|
||||
|
||||
/** AWACs Screamer registers offsets. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** AWACs Screamer manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Apple source calls this kValidData but doesn't explain
|
||||
what it actually means. It seems like it's used to check
|
||||
if the sound codec is available.
|
||||
*/
|
||||
#define AWAC_AVAILABLE 0x40
|
||||
|
||||
|
||||
/** Audio processor chip (TDA7433) emulation. */
|
||||
class AudioProcessor : public I2CDevice {
|
||||
public:
|
||||
AudioProcessor() = default;
|
||||
~AudioProcessor() = default;
|
||||
|
||||
void start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
if ((sub_addr & 0xF) > 6)
|
||||
return false; /* invalid subaddress -> no acknowledge */
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
LOG_F(9, "TDA7433 subaddress = 0x%X, auto increment = %d",
|
||||
this->sub_addr, this->auto_inc);
|
||||
this->pos++;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool send_byte(uint8_t data) {
|
||||
if (!this->pos) {
|
||||
return send_subaddress(data);
|
||||
} else if (this->sub_addr <= 6) {
|
||||
LOG_F(9, "TDA7433 byte 0x%X received", data);
|
||||
this->regs[this->sub_addr] = data;
|
||||
if (this->auto_inc) {
|
||||
this->sub_addr++;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; /* invalid sub_addr -> no acknowledge */
|
||||
}
|
||||
};
|
||||
|
||||
bool receive_byte(uint8_t* p_data) {
|
||||
*p_data = this->regs[this->sub_addr];
|
||||
LOG_F(9, "TDA7433 byte 0x%X sent", *p_data);
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
||||
uint8_t sub_addr;
|
||||
int pos;
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
/** AWACs Screamer sound codec. */
|
||||
class AwacsScreamer : public AwacsBase {
|
||||
public:
|
||||
AwacsScreamer();
|
||||
~AwacsScreamer() = default;
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
protected:
|
||||
void open_stream(int sample_rate);
|
||||
|
||||
private:
|
||||
uint32_t snd_ctrl_reg = { 0 };
|
||||
uint16_t control_regs[8] = { 0 }; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
|
||||
int out_sample_rate;
|
||||
|
||||
std::unique_ptr<AudioProcessor> audio_proc;
|
||||
};
|
||||
|
||||
#endif /* AWAC_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,9 +19,11 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "soundserver.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include <cubeb/cubeb.h>
|
||||
#ifdef _WIN32
|
||||
#include <objbase.h>
|
||||
@@ -124,9 +126,54 @@ void SoundServer::shutdown()
|
||||
LOG_F(INFO, "Sound Server shut down.");
|
||||
}
|
||||
|
||||
long sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
DmaOutChannel *dma_ch = static_cast<DmaOutChannel*>(user_data); /* C API baby! */
|
||||
|
||||
int SoundServer::open_out_stream(uint32_t sample_rate, cubeb_data_callback data_cb,
|
||||
cubeb_state_callback status_cb, void *user_data)
|
||||
if (!dma_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!dma_ch->pull_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
static void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
int SoundServer::open_out_stream(uint32_t sample_rate, void *user_data)
|
||||
{
|
||||
int res;
|
||||
uint32_t latency_frames;
|
||||
@@ -148,7 +195,7 @@ int SoundServer::open_out_stream(uint32_t sample_rate, cubeb_data_callback data_
|
||||
|
||||
res = cubeb_stream_init(this->cubeb_ctx, &this->out_stream, "SndOut stream",
|
||||
NULL, NULL, NULL, ¶ms, latency_frames,
|
||||
data_cb, status_cb, user_data);
|
||||
sound_out_callback, status_callback, user_data);
|
||||
if (res != CUBEB_OK) {
|
||||
LOG_F(ERROR, "Could not open sound output stream, error: %d", res);
|
||||
return -1;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,9 +34,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SOUND_SERVER_H
|
||||
#define SOUND_SERVER_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
#include <cubeb/cubeb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
enum {
|
||||
SND_SERVER_DOWN = 0,
|
||||
@@ -52,32 +51,19 @@ public:
|
||||
|
||||
int start();
|
||||
void shutdown();
|
||||
int open_out_stream(uint32_t sample_rate, cubeb_data_callback data_cb,
|
||||
cubeb_state_callback status_cb, void *user_data);
|
||||
int open_out_stream(uint32_t sample_rate, void *user_data);
|
||||
int start_out_stream();
|
||||
void close_out_stream();
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::SND_SERVER; };
|
||||
|
||||
#if 0
|
||||
SoundIoDevice *get_out_device() {
|
||||
if (this->status == SND_SERVER_UP) {
|
||||
return this->out_device;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::SND_SERVER;
|
||||
};
|
||||
#endif
|
||||
|
||||
private:
|
||||
int status; /* server status */
|
||||
cubeb *cubeb_ctx;
|
||||
|
||||
cubeb_stream *out_stream;
|
||||
//SoundIo *soundio;
|
||||
//int out_dev_index; /* current output device index */
|
||||
//SoundIoDevice *out_device; /* current output device instance */
|
||||
//SoundIoOutStream *outstream;
|
||||
};
|
||||
|
||||
#endif /* SOUND_SERVER_H */
|
||||
@@ -1,468 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
|
||||
/** VIA-CUDA combo device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cinttypes>
|
||||
#include "viacuda.h"
|
||||
#include "adb.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda()
|
||||
{
|
||||
this->name = "ViaCuda";
|
||||
|
||||
/* FIXME: is this the correct
|
||||
VIA initialization? */
|
||||
this->via_regs[VIA_A] = 0x80;
|
||||
this->via_regs[VIA_DIRB] = 0xFF;
|
||||
this->via_regs[VIA_DIRA] = 0xFF;
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_IER] = 0x7F;
|
||||
|
||||
//PRAM Pre-Initialization
|
||||
this->pram_obj = new NVram("pram.bin", 256);
|
||||
|
||||
this->adb_obj = new ADB_Bus();
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->pram_obj)
|
||||
delete (this->pram_obj);
|
||||
}
|
||||
|
||||
void ViaCuda::init()
|
||||
{
|
||||
this->old_tip = 0;
|
||||
this->old_byteack = 0;
|
||||
this->treq = 1;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
this->poll_rate = 11;
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::read(int reg)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
LOG_F(9, "Read VIA reg %x \n", (uint32_t)reg);
|
||||
|
||||
res = this->via_regs[reg & 0xF];
|
||||
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
res = this->via_regs[VIA_B];
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A! \n");
|
||||
break;
|
||||
case VIA_IER:
|
||||
res |= 0x80; /* bit 7 always reads as "1" */
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value)
|
||||
{
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
this->via_regs[VIA_B] = value;
|
||||
write(value);
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A! \n");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
LOG_F(9, "VIA_DIRB = %x \n", (uint32_t)value);
|
||||
this->via_regs[VIA_DIRB] = value;
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
LOG_F(9, "VIA_DIRA = %x \n", (uint32_t)value);
|
||||
this->via_regs[VIA_DIRA] = value;
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = %x \n", (uint32_t)value);
|
||||
this->via_regs[VIA_PCR] = value;
|
||||
break;
|
||||
case VIA_ACR:
|
||||
LOG_F(9, "VIA_ACR = %x \n", (uint32_t)value);
|
||||
this->via_regs[VIA_ACR] = value;
|
||||
break;
|
||||
case VIA_IER:
|
||||
this->via_regs[VIA_IER] = (value & 0x80) ? value & 0x7F
|
||||
: this->via_regs[VIA_IER] & ~value;
|
||||
LOG_F(INFO, "VIA_IER updated to %d \n", (uint32_t)this->via_regs[VIA_IER]);
|
||||
print_enabled_ints();
|
||||
break;
|
||||
default:
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::print_enabled_ints()
|
||||
{
|
||||
const char *via_int_src[] = { "CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1" };
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this->via_regs[VIA_IER] & (1 << i))
|
||||
LOG_F(INFO, "VIA %s interrupt enabled \n", via_int_src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ViaCuda::ready()
|
||||
{
|
||||
return ((this->via_regs[VIA_DIRB] & 0x38) == 0x30);
|
||||
}
|
||||
|
||||
inline void ViaCuda::assert_sr_int()
|
||||
{
|
||||
this->via_regs[VIA_IFR] |= 0x84;
|
||||
}
|
||||
|
||||
void ViaCuda::write(uint8_t new_state)
|
||||
{
|
||||
if (!ready()) {
|
||||
LOG_F(WARNING, "Cuda not ready! \n");
|
||||
return;
|
||||
}
|
||||
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
/* return if there is no state change */
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
LOG_F(9, "Cuda state changed! \n");
|
||||
|
||||
this->old_tip = new_tip;
|
||||
this->old_byteack = new_byteack;
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
process_packet();
|
||||
|
||||
/* start response transaction */
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
}
|
||||
|
||||
this->in_count = 0;
|
||||
}
|
||||
else {
|
||||
LOG_F(9, "Cuda: enter sync state \n");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
}
|
||||
|
||||
assert_sr_int(); /* send dummy byte as idle acknowledge or attention */
|
||||
}
|
||||
else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
|
||||
if (this->in_count < 16) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
assert_sr_int(); /* tell the system we've read the data */
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Cuda input buffer exhausted! \n");
|
||||
}
|
||||
}
|
||||
else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
assert_sr_int(); /* tell the system we've written the data */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sends zeros to host at infinitum */
|
||||
void ViaCuda::null_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
LOG_F(9, "OutBufHandler: sending next byte 0x%X", this->out_buf[this->out_pos]);
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
}
|
||||
else if (this->is_open_ended) {
|
||||
LOG_F(9, "OutBufHandler: switching to next handler");
|
||||
this->out_handler = this->next_out_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
(this->*out_handler)();
|
||||
}
|
||||
else {
|
||||
LOG_F(9, "Sending last byte");
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::response_header(uint32_t pkt_type, uint32_t pkt_flag)
|
||||
{
|
||||
this->out_buf[0] = pkt_type;
|
||||
this->out_buf[1] = pkt_flag;
|
||||
this->out_buf[2] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_count = 3;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::error_response(uint32_t error)
|
||||
{
|
||||
this->out_buf[0] = CUDA_PKT_ERROR;
|
||||
this->out_buf[1] = error;
|
||||
this->out_buf[2] = this->in_buf[0];
|
||||
this->out_buf[3] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_count = 4;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::process_packet()
|
||||
{
|
||||
if (this->in_count < 2) {
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!\n");
|
||||
error_response(CUDA_ERR_BAD_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this->in_buf[0]) {
|
||||
case CUDA_PKT_ADB:
|
||||
LOG_F(9, "Cuda: ADB packet received \n");
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
LOG_F(9, "Cuda: pseudo command packet received \n");
|
||||
LOG_F(9, "Command: %x \n", (uint32_t)(this->in_buf[1]));
|
||||
LOG_F(9, "Data count: %d \n ", this->in_count);
|
||||
for (int i = 0; i < this->in_count; i++) {
|
||||
LOG_F(9, "%x ,", (uint32_t)(this->in_buf[i]));
|
||||
}
|
||||
pseudo_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d \n", (uint32_t)(this->in_buf[0]));
|
||||
error_response(CUDA_ERR_BAD_PKT);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count)
|
||||
{
|
||||
int adb_dev = cmd_byte >> 4; //2 for keyboard, 3 for mouse
|
||||
int cmd = cmd_byte & 0xF;
|
||||
|
||||
if(!cmd) {
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested\n");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
}
|
||||
else if (cmd == 1) {
|
||||
LOG_F(9, "Cuda: ADB Flush command requested\n");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
}
|
||||
else if ((cmd & 0xC) == 8) {
|
||||
LOG_F(9, "Cuda: ADB Listen command requested\n");
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->listen(adb_dev, adb_reg)){
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
for (int data_ptr = 0; data_ptr < adb_obj->get_output_len(); data_ptr++) {
|
||||
this->in_buf[(2 + data_ptr)] = adb_obj->get_output_byte(data_ptr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
}
|
||||
else if ((cmd & 0xC) == 0xC) {
|
||||
LOG_F(9, "Cuda: ADB Talk command requested\n");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->talk(adb_dev, adb_reg, this->in_buf[2])) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
}
|
||||
else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%x \n", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %dms", this->poll_rate);
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_PRAM:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->read_byte(this->in_buf[2]);
|
||||
break;
|
||||
case CUDA_WRITE_PRAM:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->write_byte(this->in_buf[2], this->in_buf[3]);
|
||||
break;
|
||||
case CUDA_SET_AUTOPOLL_RATE:
|
||||
this->poll_rate = this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to: %d", this->poll_rate);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_GET_AUTOPOLL_RATE:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[3] = this->poll_rate;
|
||||
this->out_count++;
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
break;
|
||||
case CUDA_COMB_FMT_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
if (this->in_count >= 5) {
|
||||
i2c_comb_transaction(this->in_buf[2], this->in_buf[3], this->in_buf[4],
|
||||
&this->in_buf[5], this->in_count - 5);
|
||||
}
|
||||
break;
|
||||
case CUDA_OUT_PB0: /* undocumented call! */
|
||||
LOG_F(INFO, "Cuda: send %d to PB0 \n", (int)(this->in_buf[2]));
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%x \n", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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]);
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf,
|
||||
int in_bytes)
|
||||
{
|
||||
int op_type = dev_addr & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
/* send data to the target I2C device until there is no more data to send
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (op_type) { /* read request initiate an open ended transaction */
|
||||
this->curr_i2c_addr = dev_addr;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::i2c_handler;
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr,
|
||||
uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes)
|
||||
{
|
||||
int op_type = dev_addr1 & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
if ((dev_addr & 0xFE) != (dev_addr1 & 0xFE)) {
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!\n");
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->send_subaddress(dev_addr, sub_addr)) {
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X \n", (int)(dev_addr));
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
/* send data to the target I2C device until there is no more data to send
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!op_type) { /* return dummy response for writes */
|
||||
LOG_F(WARNING, "Combined I2C - write request!");
|
||||
} else {
|
||||
this->curr_i2c_addr = dev_addr;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::i2c_handler;
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
/* Mach64 post dividers. */
|
||||
static const int mach64_post_div[8] = {
|
||||
1, 2, 4, 8, // standard post dividers
|
||||
3, 5, 6, 12 // alternate post dividers
|
||||
};
|
||||
|
||||
/* Human readable Mach64 HW register names for easier debugging. */
|
||||
static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
{0x0000, "CRTC_H_TOTAL_DISP"},
|
||||
{0x0004, "CRTC_H_SYNC_STRT_WID"},
|
||||
{0x0008, "CRTC_V_TOTAL_DISP"},
|
||||
{0x000C, "CRTC_V_SYNC_STRT_WID"},
|
||||
{0x0010, "CRTC_VLINE_CRNT_VLINE"},
|
||||
{0x0014, "CRTC_OFF_PITCH"},
|
||||
{0x0018, "CRTC_INT_CNTL"},
|
||||
{0x001C, "CRTC_GEN_CNTL"},
|
||||
{0x0020, "DSP_CONFIG"},
|
||||
{0x0024, "DSP_ON_OFF"},
|
||||
{0x002C, "MEM_BUF_CNTL"},
|
||||
{0x0034, "MEM_ADDR_CFG"},
|
||||
{0x0040, "OVR_CLR"},
|
||||
{0x0044, "OVR_WID_LEFT_RIGHT"},
|
||||
{0x0048, "OVR_WID_TOP_BOTTOM"},
|
||||
{0x0060, "CUR_CLR0"},
|
||||
{0x0064, "CUR_CLR1"},
|
||||
{0x0068, "CUR_OFFSET"},
|
||||
{0x006C, "CUR_HORZ_VERT_POSN"},
|
||||
{0x0078, "GP_IO"},
|
||||
{0x007C, "HW_DEBUG"},
|
||||
{0x0080, "SCRATCH_REG0"},
|
||||
{0x0084, "SCRATCH_REG1"},
|
||||
{0x0088, "SCRATCH_REG2"},
|
||||
{0x008C, "SCRATCH_REG3"},
|
||||
{0x0090, "CLOCK_CNTL"},
|
||||
{0x00A0, "BUS_CNTL"},
|
||||
{0x00AC, "EXT_MEM_CNTL"},
|
||||
{0x00B0, "MEM_CNTL"},
|
||||
{0x00C0, "DAC_REGS"},
|
||||
{0x00C4, "DAC_CNTL"},
|
||||
{0x00D0, "GEN_TEST_CNTL"},
|
||||
{0x00D4, "CUSTOM_MACRO_CNTL"},
|
||||
{0x00E0, "CONFIG_CHIP_ID"},
|
||||
{0x00E4, "CONFIG_STAT0"},
|
||||
{0x01B4, "SRC_CNTL"},
|
||||
{0x01FC, "SCALE_3D_CNTL"},
|
||||
{0x0310, "FIFO_STAT"},
|
||||
{0x0338, "GUI_STAT"},
|
||||
{0x04C0, "MPP_CONFIG"},
|
||||
{0x04C4, "MPP_STROBE_SEQ"},
|
||||
{0x04C8, "MPP_ADDR"},
|
||||
{0x04CC, "MPP_DATA"},
|
||||
{0x0500, "TVO_CNTL"},
|
||||
{0x0704, "SETUP_CNTL"},
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase()
|
||||
{
|
||||
uint8_t asic_id;
|
||||
|
||||
this->vram_size = vmem_size_mb << 20; // convert MBs to bytes
|
||||
|
||||
/* allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
|
||||
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
|
||||
to operate properly */
|
||||
switch (dev_id) {
|
||||
case ATI_RAGE_GT_DEV_ID:
|
||||
asic_id = 0x9A; // GT-B2U3 fabricated by UMC
|
||||
break;
|
||||
case ATI_RAGE_PRO_DEV_ID:
|
||||
asic_id = 0x5C; // R3B/D/P-A4 fabricated by UMC
|
||||
break;
|
||||
default:
|
||||
asic_id = 0xDD;
|
||||
LOG_F(WARNING, "ATI Rage: bogus ASIC ID assigned!");
|
||||
}
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[8], (0x030000 << 8) | asic_id);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* stuff default values into chip registers */
|
||||
WRITE_DWORD_LE_A(&this->block_io_regs[ATI_CONFIG_CHIP_ID],
|
||||
(asic_id << 24) | dev_id);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID(Disp_Id_Kind::DDC2B);
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
if (this->vram_ptr) {
|
||||
delete this->vram_ptr;
|
||||
}
|
||||
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
auto iter = mach64_reg_names.find(reg_offset & ~3);
|
||||
if (iter != mach64_reg_names.end()) {
|
||||
return iter->second.c_str();
|
||||
} else {
|
||||
return "unknown Mach64 register";
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
uint32_t res;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* reading from internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
!(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
return this->plls[this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2];
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (offset == ATI_DAC_DATA) {
|
||||
this->block_io_regs[ATI_DAC_DATA] =
|
||||
this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
/* autoincrement reading index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_R_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
read_mem(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
res = read_mem(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
write_mem(&this->block_io_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]));
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
if (this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
|
||||
this->crtc_enable();
|
||||
} else {
|
||||
this->crtc_on = false;
|
||||
}
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40));
|
||||
break;
|
||||
case ATI_CUR_OFFSET:
|
||||
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_POSN:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_POSN]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_OFF:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]));
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
||||
WRITE_WORD_LE_A(
|
||||
&this->block_io_regs[ATI_GP_IO],
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
}
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* writing to internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
int pll_addr = this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2;
|
||||
uint8_t pll_data = this->block_io_regs[ATI_CLOCK_CNTL+2];
|
||||
this->plls[pll_addr] = pll_data;
|
||||
LOG_F(INFO, "ATI Rage: PLL #%d set to 0x%02X", pll_addr, pll_data);
|
||||
} else if (offset == ATI_CLOCK_CNTL && size == 1) {
|
||||
LOG_F(INFO, "ATI Rage: CLOCK_SEL = 0x%02X",
|
||||
this->block_io_regs[ATI_CLOCK_CNTL] & 3);
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
switch (offset) {
|
||||
/* writing to read/write index registers resets color component index */
|
||||
case ATI_DAC_W_INDEX:
|
||||
case ATI_DAC_R_INDEX:
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case ATI_DAC_DATA:
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
|
||||
this->block_io_regs[ATI_DAC_W_INDEX],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]);
|
||||
/* autoincrement writing index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_W_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
LOG_F(INFO, "HW cursor: %s", this->block_io_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset),
|
||||
offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
||||
}
|
||||
|
||||
if ((this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
this->fb_ptr = this->vram_ptr + src_offset;
|
||||
this->update_screen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = read_mem(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
||||
reg_offs,
|
||||
BYTESWAP_32(value),
|
||||
size);
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x10: /* BAR 0 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
||||
}
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
break;
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
if (value == 0x00F8FFFFUL) {
|
||||
// return 0 (not implemented) when attempting to size the expansion ROM
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
} else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
write_mem(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
||||
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
*p_io_base = io_base;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - io_base, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - io_base, value, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
LOG_F(8, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return read_mem(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* read from big-endian VRAM region */
|
||||
return read_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), size);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* read from memory-mapped registers, block 0 */
|
||||
return this->read_reg(offset - MM_REGS_0_OFF, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_1_OFF) {
|
||||
/* read from memory-mapped registers, block 1 */
|
||||
return this->read_reg(offset - MM_REGS_1_OFF + 0x400, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(8, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
write_mem(this->vram_ptr + offset, value, size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* write to big-endian VRAM region */
|
||||
write_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), value, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* write to memory-mapped registers, block 0 */
|
||||
this->write_reg(offset - MM_REGS_0_OFF, value, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_1_OFF) {
|
||||
/* write to memory-mapped registers, block 1 */
|
||||
this->write_reg(offset - MM_REGS_1_OFF + 0x400, value, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
float ATIRage::calc_pll_freq(int scale, int fb_div) {
|
||||
return (ATI_XTAL * scale * fb_div) / this->plls[PLL_REF_DIV];
|
||||
}
|
||||
|
||||
void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
if (crtc_index) {
|
||||
LOG_F(ERROR, "CRTC2 not supported yet");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* what = "Pixel format:";
|
||||
|
||||
switch (this->block_io_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
|
||||
case 1:
|
||||
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
|
||||
break;
|
||||
case 2:
|
||||
// check the undocumented DAC_DIRECT bit
|
||||
if (this->block_io_regs[ATI_DAC_CNTL+1] & 4) {
|
||||
LOG_F(INFO, "%s 8 bpp direct color (RGB322)", what);
|
||||
} else {
|
||||
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(INFO, "%s 15 bpp direct color (RGB555)", what);
|
||||
break;
|
||||
case 4:
|
||||
LOG_F(INFO, "%s 16 bpp direct color (RGB565)", what);
|
||||
break;
|
||||
case 5:
|
||||
LOG_F(INFO, "%s 24 bpp direct color (RGB888)", what);
|
||||
break;
|
||||
case 6:
|
||||
LOG_F(INFO, "%s 32 bpp direct color (ARGB8888)", what);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "ATI Rage: CRTC pixel format %d not supported",
|
||||
this->block_io_regs[ATI_CRTC_GEN_CNTL+2] & 7);
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::crtc_enable() {
|
||||
/* active (visible) width is specified in characters (8 px) - 1 */
|
||||
this->active_width = (this->block_io_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
|
||||
/* active (visible) height is specified in lines - 1 */
|
||||
this->active_height =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
|
||||
if ((this->plls[PLL_VCLK_CNTL] & 3) == 3) {
|
||||
/* look up which VPLL ouput is requested */
|
||||
int clock_sel = this->block_io_regs[ATI_CLOCK_CNTL] & 3;
|
||||
|
||||
/* calculate VPLL output frequency */
|
||||
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
|
||||
|
||||
/* calculate post divider's index */
|
||||
/* NOTE: post divider's index has been extended by an additional
|
||||
bit in Rage Pro. This bit is resided in PLL_EXT_CNTL register.
|
||||
*/
|
||||
int post_div_idx = ((this->plls[PLL_EXT_CNTL] >> (clock_sel + 2)) & 4) |
|
||||
((this->plls[VCLK_POST_DIV] >> (clock_sel * 2)) & 3);
|
||||
|
||||
/* pixel clock = source_freq / post_div */
|
||||
this->pixel_clock = vpll_freq / mach64_post_div[post_div_idx];
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total =
|
||||
((READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_H_TOTAL_DISP])
|
||||
& 0x1FFUL) + 1) * 8;
|
||||
|
||||
int vert_total =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
|
||||
this->refresh_rate = pixel_clock / hori_total / vert_total;
|
||||
|
||||
LOG_F(INFO, "ATI Rage: primary CRT controller enabled:");
|
||||
LOG_F(INFO, "Video mode: %s",
|
||||
(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
|
||||
LOG_F(INFO, "Video width: %d px", this->active_width);
|
||||
LOG_F(INFO, "Video height: %d px", this->active_height);
|
||||
verbose_pixel_format(0);
|
||||
LOG_F(INFO, "VPLL frequency: %f MHz", vpll_freq * 1e-6);
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
} else {
|
||||
LOG_F(WARNING, "ATI Rage: VLCK source != VPLL!");
|
||||
}
|
||||
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
uint8_t *src_buf, *src_row, *dst_row, px4;
|
||||
|
||||
int horz_offset = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
|
||||
int vert_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
|
||||
|
||||
src_buf = this->vram_ptr + (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]) * 8);
|
||||
|
||||
int cur_height = 64 - vert_offset;
|
||||
|
||||
uint32_t color0 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
|
||||
uint32_t color1 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
|
||||
|
||||
for (int h = 0; h < cur_height; h++) {
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
src_row = &src_buf[h * 16];
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
px4 = src_row[x];
|
||||
|
||||
for (int p = 0; p < 4; p++, px4 >>= 2, dst_row += 4) {
|
||||
switch(px4 & 3) {
|
||||
case 0: // cursor color 0
|
||||
WRITE_DWORD_BE_A(dst_row, color0);
|
||||
break;
|
||||
case 1: // cursor color 1
|
||||
WRITE_DWORD_BE_A(dst_row, color1);
|
||||
break;
|
||||
case 2: // transparent
|
||||
break;
|
||||
case 3: // 1's complement of display pixel
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
};
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x0010,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CONFIG_STAT1 = 0x0094,
|
||||
ATI_CONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_MEM_VGA_WP_SEL = 0x00B4,
|
||||
ATI_MEM_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CONFIG_CHIP_ID = 0x00E0,
|
||||
ATI_CONFIG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_Y_X_ALIAS1 = 0x00F4,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_DST_X = 0x0104,
|
||||
ATI_DST_Y = 0x0108,
|
||||
ATI_DST_Y_X = 0x010C,
|
||||
ATI_DST_WIDTH = 0x0110,
|
||||
ATI_DST_HEIGHT = 0x0114,
|
||||
ATI_DST_HEIGHT_WIDTH = 0x0118,
|
||||
ATI_DST_X_WIDTH = 0x011C,
|
||||
ATI_DST_BRES_LNTH = 0x0120,
|
||||
ATI_DST_BRES_ERR = 0x0124,
|
||||
ATI_DST_BRES_INC = 0x0128,
|
||||
ATI_DST_BRES_DEC = 0x012C,
|
||||
ATI_DST_CNTL = 0x0130,
|
||||
ATI_DST_Y_X_ALIAS2 = 0x0134,
|
||||
ATI_TRAIL_BRES_ERR = 0x0138,
|
||||
ATI_TRAIL_BRES_INC = 0x013C,
|
||||
ATI_TRAIL_BRES_DEC = 0x0140,
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x0144,
|
||||
ATI_Z_OFF_PITCH = 0x0148,
|
||||
ATI_Z_CNTL = 0x014C,
|
||||
ATI_ALPHA_TST_CNTL = 0x0150,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_SRC_X = 0x0184,
|
||||
ATI_SRC_Y = 0x0188,
|
||||
ATI_SRC_Y_X = 0x018C,
|
||||
ATI_SRC_WIDTH1 = 0x0190,
|
||||
ATI_SRC_HEIGHT1 = 0x0194,
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x0198,
|
||||
ATI_SRC_X_START = 0x019C,
|
||||
ATI_SRC_Y_START = 0x01A0,
|
||||
ATI_SRC_Y_X_START = 0x01A4,
|
||||
ATI_SRC_WIDTH2 = 0x01A8,
|
||||
ATI_SRC_HEIGHT2 = 0x01AC,
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x01B0,
|
||||
ATI_SRC_CNTL = 0x01B4,
|
||||
ATI_SCALE_OFF = 0x01C0,
|
||||
ATI_SCALE_WIDTH = 0x01DC,
|
||||
ATI_SCALE_HEIGHT = 0x01E0,
|
||||
ATI_SCALE_PITCH = 0x01EC,
|
||||
ATI_SCALE_X_INC = 0x01F0,
|
||||
ATI_SCALE_Y_INC = 0x01F4,
|
||||
ATI_SCALE_VACC = 0x01F8,
|
||||
ATI_SCALE_3D_CNTL = 0x01FC,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_PAT_REG0 = 0x0280,
|
||||
ATI_PAT_REG1 = 0x0284,
|
||||
ATI_PAT_CNTL = 0x0288,
|
||||
ATI_SC_LEFT = 0x02A0,
|
||||
ATI_SC_RIGHT = 0x02A4,
|
||||
ATI_SC_LEFT_RIGHT = 0x02A8,
|
||||
ATI_SC_TOP = 0x02AC,
|
||||
ATI_SC_BOTTOM = 0x02B0,
|
||||
ATI_SC_TOP_BOTTOM = 0x02B4,
|
||||
ATI_DP_BKGD_CLR = 0x02C0,
|
||||
ATI_DP_FOG_CLR = 0x02C0,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DP_MIX = 0x02D4,
|
||||
ATI_DP_SRC = 0x02D8,
|
||||
ATI_FRGD_CLR_MIX = 0x02DC,
|
||||
ATI_FRGD_BKGD_CLR = 0x02E0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_USR_DST_PITCH = 0x02F0,
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x02F4,
|
||||
ATI_DP_SET_GUI_ENGINE = 0x02F8,
|
||||
ATI_CLR_CMP_CLR = 0x0300,
|
||||
ATI_CLR_CMP_MSK = 0x0304,
|
||||
ATI_CLR_CMP_CNTL = 0x0308,
|
||||
ATI_FIFO_STAT = 0x0310,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_GUI_TRAJ_CNTL = 0x0330,
|
||||
ATI_GUI_STAT = 0x0338,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
ATI_SETUP_CNTL = 0x0704,
|
||||
};
|
||||
|
||||
/* Mach64 PLL register indices. */
|
||||
enum {
|
||||
PLL_REF_DIV = 2, // reference divider, same for all Mach64 clocks
|
||||
PLL_VCLK_CNTL = 5,
|
||||
VCLK_POST_DIV = 6,
|
||||
VCLK0_FB_DIV = 7, // feedback divider for VCLK0
|
||||
VCLK1_FB_DIV = 8, // feedback divider for VCLK1
|
||||
VCLK2_FB_DIV = 9, // feedback divider for VCLK2
|
||||
VCLK3_FB_DIV = 10, // feedback divider for VCLK3
|
||||
PLL_EXT_CNTL = 11,
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MM_REGS_0_OFF = 0x007FFC00UL; /* offset to memory mapped registers, block 0 */
|
||||
constexpr auto MM_REGS_1_OFF = 0x007FF800UL; /* offset to memory mapped registers, block 1 */
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame buffer */
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
|
||||
~ATIRage();
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
};
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* I/O space access methods */
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
protected:
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
float calc_pll_freq(int scale, int fb_div);
|
||||
void verbose_pixel_format(int crtc_index);
|
||||
void crtc_enable();
|
||||
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
private:
|
||||
uint8_t block_io_regs[2048] = {0};
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
uint32_t aperture_base;
|
||||
|
||||
DisplayID* disp_id;
|
||||
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,11 +19,15 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "displayid.h"
|
||||
/** @file DisplayID class implementation. */
|
||||
|
||||
DisplayID::DisplayID()
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
DisplayID::DisplayID(Disp_Id_Kind id_kind)
|
||||
{
|
||||
this->id_kind = id_kind;
|
||||
|
||||
/* Initialize Apple monitor codes */
|
||||
this->std_sense_code = 6;
|
||||
this->ext_sense_code = 0x2B;
|
||||
@@ -35,9 +39,6 @@ DisplayID::DisplayID()
|
||||
this->last_scl = 1;
|
||||
this->data_out = 0x3000;
|
||||
this->data_ptr = 0;
|
||||
|
||||
/* DDC sense mode is on by default */
|
||||
this->i2c_on = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,15 +49,13 @@ uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
||||
|
||||
if (scl) {
|
||||
this->data_out |= 0x1000;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->data_out &= ~0x1000U;
|
||||
}
|
||||
|
||||
if (sda) {
|
||||
this->data_out |= 0x2000;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->data_out &= ~0x2000U;
|
||||
}
|
||||
|
||||
@@ -66,50 +65,44 @@ uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
||||
|
||||
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs)
|
||||
{
|
||||
uint8_t scl, sda;
|
||||
uint8_t scl, sda;
|
||||
uint16_t result;
|
||||
|
||||
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
|
||||
LOG_F(WARNING, "DisplayID: Hackish Monitor ID Switch activated!");
|
||||
this->i2c_on = false;
|
||||
LOG_F(WARNING, "DisplayID: Monitor sense lines tristated!");
|
||||
}
|
||||
|
||||
if (this->i2c_on) {
|
||||
switch(this->id_kind) {
|
||||
case Disp_Id_Kind::DDC2B:
|
||||
/* if GPIO pins are in the output mode, pick up their values
|
||||
In the input mode, GPIO pins will be read "high" */
|
||||
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
|
||||
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
|
||||
|
||||
return update_ddc_i2c(sda, scl);
|
||||
}
|
||||
else { /* Apple legacy monitor codes (see Technical Note HW30) */
|
||||
case Disp_Id_Kind::AppleSense:
|
||||
switch (dirs & 0x3100) {
|
||||
case 0:
|
||||
result = ((this->std_sense_code & 6) << 11) |
|
||||
((this->std_sense_code & 1) << 8);
|
||||
result = ((this->std_sense_code & 6) << 11) | ((this->std_sense_code & 1) << 8);
|
||||
break;
|
||||
case 0x2000: /* Sense line 2 is low */
|
||||
result = ((this->ext_sense_code & 0x20) << 7) |
|
||||
((this->ext_sense_code & 0x10) << 4);
|
||||
result = ((this->ext_sense_code & 0x20) << 7) | ((this->ext_sense_code & 0x10) << 4);
|
||||
break;
|
||||
case 0x1000: /* Sense line 1 is low */
|
||||
result = ((this->ext_sense_code & 8) << 10) |
|
||||
((this->ext_sense_code & 4) << 6);
|
||||
result = ((this->ext_sense_code & 8) << 10) | ((this->ext_sense_code & 4) << 6);
|
||||
break;
|
||||
case 0x100: /* Sense line 0 is low */
|
||||
result = ((this->ext_sense_code & 2) << 12) |
|
||||
((this->ext_sense_code & 1) << 12);
|
||||
result = ((this->ext_sense_code & 2) << 12) | ((this->ext_sense_code & 1) << 12);
|
||||
break;
|
||||
default:
|
||||
result = 0x3100U;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, uint16_t dirs)
|
||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
bool clk_gone_high = false;
|
||||
|
||||
@@ -127,9 +120,8 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
if (!sda) {
|
||||
LOG_F(9, "DDC-I2C: START condition detected!");
|
||||
this->next_state = I2CState::DEV_ADDR;
|
||||
this->bit_count = 0;
|
||||
}
|
||||
else {
|
||||
this->bit_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "DDC-I2C: STOP condition detected!");
|
||||
this->next_state = I2CState::STOP;
|
||||
}
|
||||
@@ -147,22 +139,20 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
|
||||
case I2CState::ACK:
|
||||
this->bit_count = 0;
|
||||
this->byte = 0;
|
||||
this->byte = 0;
|
||||
switch (this->prev_state) {
|
||||
case I2CState::DEV_ADDR:
|
||||
if ((dev_addr & 0xFE) == 0xA0) {
|
||||
sda = 0; /* send ACK */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG_F(ERROR, "DDC-I2C: unknown device address 0x%X", this->dev_addr);
|
||||
sda = 1; /* send NACK */
|
||||
}
|
||||
if (this->dev_addr & 1) {
|
||||
this->next_state = I2CState::DATA;
|
||||
this->data_ptr = this->edid;
|
||||
this->byte = *(this->data_ptr++);
|
||||
}
|
||||
else {
|
||||
this->data_ptr = this->edid;
|
||||
this->byte = *(this->data_ptr++);
|
||||
} else {
|
||||
this->next_state = I2CState::REG_ADDR;
|
||||
}
|
||||
break;
|
||||
@@ -170,8 +160,7 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
this->next_state = I2CState::DATA;
|
||||
if (!this->reg_addr) {
|
||||
sda = 0; /* send ACK */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG_F(ERROR, "DDC-I2C: unknown register address 0x%X", this->reg_addr);
|
||||
sda = 1; /* send NACK */
|
||||
}
|
||||
@@ -182,12 +171,10 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
if (!sda) {
|
||||
/* load next data byte */
|
||||
this->byte = *(this->data_ptr++);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG_F(ERROR, "DDC-I2C: Oops! NACK received");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sda = 0; /* send ACK */
|
||||
}
|
||||
break;
|
||||
@@ -198,14 +185,13 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
case I2CState::REG_ADDR:
|
||||
this->byte = (this->byte << 1) | this->last_sda;
|
||||
if (this->bit_count++ >= 7) {
|
||||
this->bit_count = 0;
|
||||
this->bit_count = 0;
|
||||
this->prev_state = this->next_state;
|
||||
this->next_state = I2CState::ACK;
|
||||
if (this->prev_state == I2CState::DEV_ADDR) {
|
||||
LOG_F(9, "DDC-I2C: device address received, addr=0x%X", this->byte);
|
||||
this->dev_addr = this->byte;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG_F(9, "DDC-I2C: register address received, addr=0x%X", this->byte);
|
||||
this->reg_addr = this->byte;
|
||||
}
|
||||
@@ -215,7 +201,7 @@ uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, ui
|
||||
case I2CState::DATA:
|
||||
sda = (this->byte >> (7 - this->bit_count)) & 1;
|
||||
if (this->bit_count++ >= 7) {
|
||||
this->bit_count = 0;
|
||||
this->bit_count = 0;
|
||||
this->prev_state = this->next_state;
|
||||
this->next_state = I2CState::ACK;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
video cards.
|
||||
|
||||
DisplayID provides two methods for display identification:
|
||||
- Apple monitor sense codes as described in the Technical Note HW30
|
||||
- Apple monitor sense as described in the Technical Note HW30
|
||||
- Display Data Channel (DDC) standardized by VESA
|
||||
*/
|
||||
|
||||
@@ -35,6 +35,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/* Supported diplay ID methods. */
|
||||
enum class Disp_Id_Kind {
|
||||
AppleSense,
|
||||
DDC2B,
|
||||
};
|
||||
|
||||
/** I2C bus states. */
|
||||
enum I2CState : uint8_t {
|
||||
STOP = 0, /* transaction started */
|
||||
@@ -49,7 +55,7 @@ enum I2CState : uint8_t {
|
||||
|
||||
class DisplayID {
|
||||
public:
|
||||
DisplayID();
|
||||
DisplayID(Disp_Id_Kind id_kind);
|
||||
~DisplayID() = default;
|
||||
|
||||
uint16_t read_monitor_sense(uint16_t data, uint16_t dirs);
|
||||
@@ -59,41 +65,33 @@ protected:
|
||||
uint16_t update_ddc_i2c(uint8_t sda, uint8_t scl);
|
||||
|
||||
private:
|
||||
bool i2c_on;
|
||||
Disp_Id_Kind id_kind;
|
||||
|
||||
uint8_t std_sense_code;
|
||||
uint8_t ext_sense_code;
|
||||
uint8_t std_sense_code;
|
||||
uint8_t ext_sense_code;
|
||||
|
||||
/* DDC I2C variables. */
|
||||
uint8_t next_state;
|
||||
uint8_t prev_state;
|
||||
uint8_t last_sda;
|
||||
uint8_t last_scl;
|
||||
uint8_t next_state;
|
||||
uint8_t prev_state;
|
||||
uint8_t last_sda;
|
||||
uint8_t last_scl;
|
||||
uint16_t data_out;
|
||||
int bit_count; /* number of bits processed so far */
|
||||
uint8_t byte; /* byte value being currently transferred */
|
||||
uint8_t dev_addr; /* current device address */
|
||||
uint8_t reg_addr; /* current register address */
|
||||
uint8_t *data_ptr; /* ptr to data byte to be transferred next */
|
||||
int bit_count; /* number of bits processed so far */
|
||||
uint8_t byte; /* byte value being currently transferred */
|
||||
uint8_t dev_addr; /* current device address */
|
||||
uint8_t reg_addr; /* current register address */
|
||||
uint8_t* data_ptr; /* ptr to data byte to be transferred next */
|
||||
|
||||
uint8_t edid[128] = {
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
|
||||
0x06, 0x10, 0x02, 0x9d, 0x01, 0x01, 0x01, 0x01,
|
||||
0x08, 0x09, 0x01, 0x01, 0x68, 0x20, 0x18, 0x28,
|
||||
0xe8, 0x04, 0x89, 0xa0, 0x57, 0x4a, 0x9b, 0x26,
|
||||
0x12, 0x48, 0x4c, 0x31, 0x2b, 0x80, 0x31, 0x59,
|
||||
0x45, 0x59, 0x61, 0x59, 0xa9, 0x40, 0x01, 0x01,
|
||||
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x60, 0x16,
|
||||
0x40, 0x40, 0x31, 0x70, 0x2b, 0x20, 0x20, 0x40,
|
||||
0x23, 0x00, 0x38, 0xea, 0x10, 0x00, 0x00, 0x18,
|
||||
0x48, 0x3f, 0x40, 0x32, 0x62, 0xb0, 0x32, 0x40,
|
||||
0x40, 0xc2, 0x13, 0x00, 0x38, 0xea, 0x10, 0x00,
|
||||
0x00, 0x18, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x30,
|
||||
0xa0, 0x1e, 0x55, 0x10, 0x00, 0x0a, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc,
|
||||
0x00, 0x53, 0x74, 0x75, 0x64, 0x69, 0x6f, 0x44,
|
||||
0x73, 0x70, 0x6c, 0x79, 0x31, 0x37, 0x00, 0x19
|
||||
};
|
||||
uint8_t edid[128] = {
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x06, 0x10, 0x02, 0x9d, 0x01, 0x01, 0x01,
|
||||
0x01, 0x08, 0x09, 0x01, 0x01, 0x68, 0x20, 0x18, 0x28, 0xe8, 0x04, 0x89, 0xa0, 0x57, 0x4a,
|
||||
0x9b, 0x26, 0x12, 0x48, 0x4c, 0x31, 0x2b, 0x80, 0x31, 0x59, 0x45, 0x59, 0x61, 0x59, 0xa9,
|
||||
0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x60, 0x16, 0x40, 0x40, 0x31, 0x70,
|
||||
0x2b, 0x20, 0x20, 0x40, 0x23, 0x00, 0x38, 0xea, 0x10, 0x00, 0x00, 0x18, 0x48, 0x3f, 0x40,
|
||||
0x32, 0x62, 0xb0, 0x32, 0x40, 0x40, 0xc2, 0x13, 0x00, 0x38, 0xea, 0x10, 0x00, 0x00, 0x18,
|
||||
0x00, 0x00, 0x00, 0xfd, 0x00, 0x30, 0xa0, 0x1e, 0x55, 0x10, 0x00, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x74, 0x75, 0x64, 0x69, 0x6f, 0x44,
|
||||
0x73, 0x70, 0x6c, 0x79, 0x31, 0x37, 0x00, 0x19};
|
||||
|
||||
/* More EDID:
|
||||
00ff ffff ffff ff00 5a63 5151 0341 0000
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class implementation. */
|
||||
|
||||
#include "videoctrl.h"
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase()
|
||||
{
|
||||
LOG_F(INFO, "Create display window...");
|
||||
|
||||
// Create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
640,
|
||||
480,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// Stupidly poll for 10 events.
|
||||
// Otherwise no window will be shown on mac OS!
|
||||
SDL_Event e;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SDL_PollEvent(&e);
|
||||
}
|
||||
|
||||
this->disp_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
640, 480
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
VideoCtrlBase::~VideoCtrlBase()
|
||||
{
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
|
||||
if (this->renderer) {
|
||||
SDL_DestroyRenderer(this->renderer);
|
||||
}
|
||||
|
||||
if (this->display_wnd) {
|
||||
SDL_DestroyWindow(this->display_wnd);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::update_screen()
|
||||
{
|
||||
uint8_t* dst_buf;
|
||||
int dst_pitch;
|
||||
|
||||
//auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
|
||||
// call texture update method (hardcoded for now)
|
||||
// TODO: convert it to a callback
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
|
||||
SDL_UnlockTexture(this->disp_texture);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderCopy(this->renderer, this->disp_texture, NULL, NULL);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// HW cursor data is stored at the beginning of the video memory
|
||||
// HACK: use src_offset to recognize cursor data being ready
|
||||
// Normally, we should check GEN_CUR_ENABLE bit in the GEN_TEST_CNTL register
|
||||
//if (src_offset > 0x400 && READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET])) {
|
||||
// this->draw_hw_cursor(dst_buf + dst_pitch * 20 + 120, dst_pitch);
|
||||
//}
|
||||
|
||||
//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, "Display uodate took: %lld ns", time_elapsed.count());
|
||||
|
||||
SDL_Delay(15);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
uint8_t *src_buf, *src_row, *dst_row, pix;
|
||||
int src_pitch;
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
src_pitch = this->fb_pitch;
|
||||
|
||||
for (int h = 0; h < this->active_height; h++) {
|
||||
src_row = &src_buf[h * src_pitch];
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
|
||||
for (int x = 0; x < this->active_width; x++) {
|
||||
pix = src_row[x];
|
||||
dst_row[0] = this->palette[pix][2]; // B
|
||||
dst_row[1] = this->palette[pix][1]; // G
|
||||
dst_row[2] = this->palette[pix][0]; // R
|
||||
dst_row[3] = 255; // Alpha
|
||||
dst_row += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class definitions. */
|
||||
|
||||
#ifndef VIDEO_CTRL_H
|
||||
#define VIDEO_CTRL_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class VideoCtrlBase {
|
||||
public:
|
||||
VideoCtrlBase();
|
||||
~VideoCtrlBase();
|
||||
|
||||
void update_screen(void);
|
||||
|
||||
void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
protected:
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr;
|
||||
int fb_pitch;
|
||||
|
||||
private:
|
||||
SDL_Window *display_wnd;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *disp_texture;
|
||||
};
|
||||
|
||||
#endif // VIDEO_CTRL_H
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Macros for performing byte swapping for quick endian conversion.
|
||||
|
||||
It will try to use the fast built-in machine instructions first
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(execution OBJECT ${SOURCES})
|
||||
target_link_libraries(execution PRIVATE cubeb)
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <interpreter_loop.h>
|
||||
#include <loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
std::chrono::high_resolution_clock::time_point global; // global timer
|
||||
std::chrono::high_resolution_clock::time_point cuda_timer; // updates every 11 ms
|
||||
std::chrono::high_resolution_clock::time_point disp_timer; // updates every 16 ms
|
||||
|
||||
using namespace std;
|
||||
|
||||
const uint64_t cuda_update = 11000;
|
||||
const uint64_t display_update = 16667;
|
||||
|
||||
bool cuda_priority = 0;
|
||||
bool disp_priority = 0;
|
||||
|
||||
uint64_t elapsed_times[3] = {0}; // Elapsed time to reach a cycle (for display)
|
||||
uint64_t routine_bench[3] = {0}; // Estimated time (in microseconds) to cycle through functions
|
||||
uint64_t routine_runtime[3] = {0, cuda_update, display_update}; // Time to elapse before execution
|
||||
|
||||
enum general_routine_timepoint { OVERALL_UPDATE_TIME, CUDA_UPDATE_TIME, DISPLAY_UPDATE_TIME };
|
||||
|
||||
void round_robin_bench() {
|
||||
// Benchmark how much time elapses during a minimal CPU block
|
||||
|
||||
std::chrono::high_resolution_clock::time_point dummy = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
dppc_interpreter::ppc_ori(); //execute NOPs as a basic test
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point dummy2 = std::chrono::high_resolution_clock::now();
|
||||
routine_bench[OVERALL_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(dummy2 - dummy).count();
|
||||
std::cout << "Initial test: " << routine_bench[OVERALL_UPDATE_TIME] << endl;
|
||||
}
|
||||
|
||||
void interpreter_update_counters() {
|
||||
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
|
||||
elapsed_times[OVERALL_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - global).count();
|
||||
elapsed_times[CUDA_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - cuda_timer).count();
|
||||
elapsed_times[DISPLAY_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - disp_timer).count();
|
||||
|
||||
// Calculate if the threshold for updating a time-critical section has reached or is about to be reached
|
||||
if ((elapsed_times[CUDA_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
|
||||
routine_runtime[CUDA_UPDATE_TIME]) {
|
||||
cuda_priority = true;
|
||||
elapsed_times[CUDA_UPDATE_TIME] = 0;
|
||||
cuda_timer = end;
|
||||
}
|
||||
|
||||
if ((elapsed_times[DISPLAY_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
|
||||
routine_runtime[DISPLAY_UPDATE_TIME]) {
|
||||
disp_priority = true;
|
||||
elapsed_times[DISPLAY_UPDATE_TIME] = 0;
|
||||
disp_timer = end;
|
||||
}
|
||||
}
|
||||
|
||||
void interpreter_main_loop() {
|
||||
// Round robin algorithm goes here
|
||||
round_robin_bench();
|
||||
|
||||
global = std::chrono::high_resolution_clock::now();
|
||||
cuda_timer = global;
|
||||
disp_timer = global;
|
||||
|
||||
for (;;) {
|
||||
if (cuda_priority) {
|
||||
LOG_F(9, "Placeholder for Cuda Update function!\n");
|
||||
cuda_priority = false;
|
||||
}
|
||||
|
||||
if (disp_priority) {
|
||||
LOG_F(9, "Placeholder for Display Update function! \n");
|
||||
disp_priority = false;
|
||||
}
|
||||
|
||||
ppc_exec();
|
||||
|
||||
interpreter_update_counters();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void interpreter_update_counters();
|
||||
void interpreter_main_loop();
|
||||
@@ -1,6 +1,8 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
|
||||
+38
-23
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "machinebase.h"
|
||||
#include "devices/hwcomponent.h"
|
||||
|
||||
std::unique_ptr<MachineBase> gMachineObj = 0;
|
||||
|
||||
|
||||
MachineBase::MachineBase(std::string name)
|
||||
{
|
||||
MachineBase::MachineBase(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
/* initialize internal maps */
|
||||
@@ -17,9 +38,8 @@ MachineBase::MachineBase(std::string name)
|
||||
this->aliases.clear();
|
||||
}
|
||||
|
||||
MachineBase::~MachineBase()
|
||||
{
|
||||
for(auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
MachineBase::~MachineBase() {
|
||||
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
delete it->second;
|
||||
}
|
||||
this->comp_map.clear();
|
||||
@@ -27,8 +47,7 @@ MachineBase::~MachineBase()
|
||||
this->subdev_map.clear();
|
||||
}
|
||||
|
||||
bool MachineBase::add_component(std::string name, HWComponent *dev_obj)
|
||||
{
|
||||
bool MachineBase::add_component(std::string name, HWComponent* dev_obj) {
|
||||
if (this->comp_map.count(name)) {
|
||||
LOG_F(ERROR, "Component %s already exists!", name.c_str());
|
||||
return false;
|
||||
@@ -39,8 +58,7 @@ bool MachineBase::add_component(std::string name, HWComponent *dev_obj)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MachineBase::add_subdevice(std::string name, HWComponent *dev_obj)
|
||||
{
|
||||
bool MachineBase::add_subdevice(std::string name, HWComponent* dev_obj) {
|
||||
if (this->subdev_map.count(name)) {
|
||||
LOG_F(ERROR, "Subdevice %s already exists!", name.c_str());
|
||||
return false;
|
||||
@@ -51,13 +69,11 @@ bool MachineBase::add_subdevice(std::string name, HWComponent *dev_obj)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MachineBase::add_alias(std::string name, std::string alias)
|
||||
{
|
||||
void MachineBase::add_alias(std::string name, std::string alias) {
|
||||
this->aliases[alias] = name;
|
||||
}
|
||||
|
||||
HWComponent *MachineBase::get_comp_by_name(std::string name)
|
||||
{
|
||||
HWComponent* MachineBase::get_comp_by_name(std::string name) {
|
||||
if (this->aliases.count(name)) {
|
||||
name = this->aliases[name];
|
||||
}
|
||||
@@ -73,15 +89,14 @@ HWComponent *MachineBase::get_comp_by_name(std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
HWComponent *MachineBase::get_comp_by_type(HWCompType type)
|
||||
{
|
||||
HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
|
||||
std::string comp_name;
|
||||
bool found = false;
|
||||
|
||||
for(auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
if (it->second->supports_type(type)) {
|
||||
comp_name = it->first;
|
||||
found = true;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -90,10 +105,10 @@ HWComponent *MachineBase::get_comp_by_type(HWCompType type)
|
||||
return this->get_comp_by_name(comp_name);
|
||||
}
|
||||
|
||||
for(auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
|
||||
for (auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
|
||||
if (it->second->supports_type(type)) {
|
||||
comp_name = it->first;
|
||||
found = true;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,27 +27,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_BASE_H
|
||||
#define MACHINE_BASE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "devices/hwcomponent.h"
|
||||
|
||||
class MachineBase
|
||||
{
|
||||
class MachineBase {
|
||||
public:
|
||||
MachineBase(std::string name);
|
||||
~MachineBase();
|
||||
|
||||
bool add_component(std::string name, HWComponent *dev_obj);
|
||||
bool add_subdevice(std::string name, HWComponent *dev_obj);
|
||||
bool add_component(std::string name, HWComponent* dev_obj);
|
||||
bool add_subdevice(std::string name, HWComponent* dev_obj);
|
||||
void add_alias(std::string name, std::string alias);
|
||||
HWComponent *get_comp_by_name(std::string name);
|
||||
HWComponent *get_comp_by_type(HWCompType type);
|
||||
HWComponent* get_comp_by_name(std::string name);
|
||||
HWComponent* get_comp_by_type(HWCompType type);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::map<std::string, HWComponent *>comp_map;
|
||||
std::map<std::string, HWComponent *>subdev_map;
|
||||
std::map<std::string, HWComponent*> comp_map;
|
||||
std::map<std::string, HWComponent*> subdev_map;
|
||||
std::map<std::string, std::string> aliases;
|
||||
};
|
||||
|
||||
|
||||
+216
-70
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,100 +24,105 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "memreadwrite.h"
|
||||
#include "machinefactory.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
Power Macintosh ROM identification string
|
||||
map<string, unique_ptr<BasicProperty>> gMachineSettings;
|
||||
|
||||
is located in the ConfigInfo structure starting at 0x30D064 (PCI Macs)
|
||||
or 0x30C064 (Nubus Macs).
|
||||
/**
|
||||
Power Macintosh ROM identification map.
|
||||
|
||||
Maps Bootstrap string located at offset 0x30D064 (PCI Macs)
|
||||
or 0x30C064 (Nubus Macs) to machine name and description.
|
||||
*/
|
||||
static const map<uint32_t, string> rom_identity = {
|
||||
{0x416C6368, "Performa 6400"}, //Alchemy
|
||||
//{"Come", "PowerBook 2400"}, //Comet
|
||||
{0x436F7264, "Power Mac 5200/6200 series"}, //Cordyceps
|
||||
{0x47617A65, "Power Mac 6500"}, //Gazelle
|
||||
{0x476F7373, "Power Mac G3 Beige"}, //Gossamer
|
||||
{0x47525820, "PowerBook G3 Wallstreet"},
|
||||
//{"Hoop", "PowerBook 3400"}, //Hooper
|
||||
{0x50425820, "PowerBook Pre-G3"},
|
||||
{0x50444D20, "Nubus Power Mac or WGS"}, //Piltdown Man (6100/7100/8100)
|
||||
{0x50697020, "Bandai Pippin"}, //Pippin
|
||||
//{"Powe", "Generic Power Mac"}, //PowerMac?
|
||||
//{"Spar", "20th Anniversay Mac"}, //Spartacus
|
||||
{0x544E5420, "Power Mac 7xxxx/8xxx series"}, //Trinitrotoluene :-)
|
||||
{0x5A616E7A, "Power Mac 4400/7220"}, //Zanzibar
|
||||
//{"????", "A clone, perhaps?"} //N/A (Placeholder ID)
|
||||
static const map<uint32_t, std::tuple<string, const char*>> rom_identity = {
|
||||
{0x416C6368, {"pm6400", "Performa 6400"}}, // Alchemy
|
||||
//{"Come", "PowerBook 2400"}, // Comet
|
||||
{0x436F7264, {"pm5200", "Power Mac 5200/6200 series"}}, // Cordyceps
|
||||
{0x47617A65, {"pm6500", "Power Mac 6500"}}, // Gazelle
|
||||
{0x476F7373, {"pmg3", "Power Mac G3 Beige"}}, // Gossamer
|
||||
{0x47525820, {"pbg3", "PowerBook G3 Wallstreet"}},
|
||||
//{"Hoop", "PowerBook 3400"}, // Hooper
|
||||
{0x50425820, {"pb-preg3", "PowerBook Pre-G3"}},
|
||||
{0x50444D20, {"pm6100", "Nubus Power Mac"}}, // Piltdown Man (6100/7100/8100)
|
||||
{0x50697020, {"pippin", "Bandai Pippin"}}, // Pippin
|
||||
//{"Powe", "Generic Power Mac"}, // PowerMac?
|
||||
{0x544E5420, {"pm7200", "Power Mac 7xxxx/8xxx series"}}, // Trinitrotoluene :-)
|
||||
{0x5A616E7A, {"pm4400", "Power Mac 4400/7220"}}, // Zanzibar
|
||||
};
|
||||
|
||||
static const PropMap GossamerSettings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
};
|
||||
|
||||
int create_machine_for_id(uint32_t id)
|
||||
{
|
||||
switch(id) {
|
||||
case 0x476F7373:
|
||||
create_gossamer();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown machine ID: %X", id);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static const PropMap PDMSettings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
};
|
||||
|
||||
static const map<string, string> PropHelp = {
|
||||
{"rambank1_size", "specifies RAM bank 1 size in MB"},
|
||||
{"rambank2_size", "specifies RAM bank 2 size in MB"},
|
||||
{"rambank3_size", "specifies RAM bank 3 size in MB"},
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
};
|
||||
|
||||
/* Read ROM file content and transfer it to the dedicated ROM region */
|
||||
void load_rom(ifstream& rom_file, uint32_t file_size)
|
||||
{
|
||||
unsigned char *sysrom_mem = new unsigned char[file_size];
|
||||
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
|
||||
{"pm6100", {PDMSettings, create_pdm, "PowerMacintosh 6100"}},
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
};
|
||||
|
||||
rom_file.seekg(0, ios::beg);
|
||||
rom_file.read((char *)sysrom_mem, file_size);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
mem_ctrl->set_data(0xFFC00000, sysrom_mem, file_size);
|
||||
delete[] sysrom_mem;
|
||||
}
|
||||
|
||||
|
||||
int create_machine_for_rom(const char* rom_filepath)
|
||||
{
|
||||
string machine_name_from_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
uint32_t file_size, config_info_offset, rom_id;
|
||||
char rom_id_str[17];
|
||||
|
||||
rom_file.open(rom_filepath, ios::in|ios::binary);
|
||||
string machine_name = "";
|
||||
|
||||
rom_file.open(rom_filepath, ios::in | ios::binary);
|
||||
if (rom_file.fail()) {
|
||||
LOG_F(ERROR, "Cound not open the specified ROM file.");
|
||||
rom_file.close();
|
||||
return -1;
|
||||
goto bail_out;
|
||||
}
|
||||
|
||||
rom_file.seekg(0, rom_file.end);
|
||||
file_size = rom_file.tellg();
|
||||
rom_file.seekg(0, rom_file.beg);
|
||||
|
||||
if (file_size != 0x400000UL){
|
||||
if (file_size != 0x400000UL) {
|
||||
LOG_F(ERROR, "Unxpected ROM File size. Expected size is 4 megabytes.");
|
||||
rom_file.close();
|
||||
return -1;
|
||||
goto bail_out;
|
||||
}
|
||||
|
||||
/* read config info offset from file */
|
||||
config_info_offset = 0;
|
||||
rom_file.seekg(0x300080, ios::beg);
|
||||
rom_file.read((char *)&config_info_offset, 4);
|
||||
rom_file.read((char*)&config_info_offset, 4);
|
||||
config_info_offset = READ_DWORD_BE_A(&config_info_offset);
|
||||
|
||||
/* rewind to ConfigInfo.BootstrapVersion field */
|
||||
@@ -130,20 +135,161 @@ int create_machine_for_rom(const char* rom_filepath)
|
||||
|
||||
if (strncmp(rom_id_str, "Boot", 4) != 0) {
|
||||
LOG_F(ERROR, "Invalid BootstrapVersion string.");
|
||||
rom_file.close();
|
||||
return -1;
|
||||
goto bail_out;
|
||||
}
|
||||
|
||||
/* convert BootstrapVersion string to ROM ID */
|
||||
rom_id = (rom_id_str[5] << 24) | (rom_id_str[6] << 16) |
|
||||
(rom_id_str[7] << 8) | rom_id_str[8];
|
||||
(rom_id_str[7] << 8) | rom_id_str[8];
|
||||
|
||||
LOG_F(INFO, "The machine is identified as... %s\n", rom_identity.at(rom_id).c_str());
|
||||
LOG_F(INFO, "The machine is identified as... %s\n",
|
||||
std::get<1>(rom_identity.at(rom_id)));
|
||||
|
||||
create_machine_for_id(rom_id);
|
||||
|
||||
load_rom(rom_file, file_size);
|
||||
machine_name = std::get<0>(rom_identity.at(rom_id));
|
||||
|
||||
bail_out:
|
||||
rom_file.close();
|
||||
|
||||
return machine_name;
|
||||
}
|
||||
|
||||
int get_machine_settings(string& id, map<string, string> &settings) {
|
||||
try {
|
||||
auto props = get<0>(machines.at(id));
|
||||
|
||||
gMachineSettings.clear();
|
||||
|
||||
for (auto& p : props) {
|
||||
settings[p.first] = p.second->get_string();
|
||||
|
||||
/* populate dynamic machine settings from presets */
|
||||
gMachineSettings[p.first] = unique_ptr<BasicProperty>(p.second->clone());
|
||||
}
|
||||
}
|
||||
catch(out_of_range ex) {
|
||||
LOG_F(ERROR, "Unknown machine id %s", id.c_str());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_machine_settings(map<string, string> &settings) {
|
||||
for (auto& s : settings) {
|
||||
gMachineSettings.at(s.first)->set_string(s.second);
|
||||
}
|
||||
|
||||
/* print machine settings summary */
|
||||
cout << endl << "Machine settings summary: " << endl;
|
||||
|
||||
for (auto& p : gMachineSettings) {
|
||||
cout << p.first << " : " << p.second->get_string() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void list_machines() {
|
||||
cout << endl << "Supported machines:" << endl << endl;
|
||||
|
||||
for (auto& mach : machines) {
|
||||
cout << setw(13) << mach.first << "\t\t" << get<2>(mach.second) << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void list_properties() {
|
||||
cout << endl;
|
||||
|
||||
for (auto& mach : machines) {
|
||||
cout << get<2>(mach.second) << " supported properties:" << endl << endl;
|
||||
|
||||
for (auto& p : get<0>(mach.second)) {
|
||||
cout << setw(13) << p.first << "\t\t" << PropHelp.at(p.first)
|
||||
<< endl;
|
||||
if (p.second->get_type() == PROP_TYPE_INTEGER) {
|
||||
cout << setw(13) << "\t\t\t" "Valid values: " <<
|
||||
dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
/* Read ROM file content and transfer it to the dedicated ROM region */
|
||||
void load_rom(std::ifstream& rom_file, uint32_t file_size) {
|
||||
unsigned char* sysrom_mem = new unsigned char[file_size];
|
||||
|
||||
rom_file.seekg(0, ios::beg);
|
||||
rom_file.read((char*)sysrom_mem, file_size);
|
||||
|
||||
MemCtrlBase* mem_ctrl = dynamic_cast<MemCtrlBase*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
mem_ctrl->set_data(0xFFC00000, sysrom_mem, file_size);
|
||||
delete[] sysrom_mem;
|
||||
}
|
||||
|
||||
/* Read ROM file content and transfer it to the dedicated ROM region */
|
||||
int load_boot_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
size_t file_size;
|
||||
int result;
|
||||
AddressMapEntry *rom_reg;
|
||||
|
||||
rom_file.open(rom_filepath, ios::in | ios::binary);
|
||||
if (rom_file.fail()) {
|
||||
LOG_F(ERROR, "Cound not open the specified ROM file.");
|
||||
rom_file.close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
rom_file.seekg(0, rom_file.end);
|
||||
file_size = rom_file.tellg();
|
||||
rom_file.seekg(0, rom_file.beg);
|
||||
|
||||
if (file_size != 0x400000UL) {
|
||||
LOG_F(ERROR, "Unxpected ROM File size. Expected size is 4 megabytes.");
|
||||
result = -1;
|
||||
} else {
|
||||
unsigned char* sysrom_mem = new unsigned char[file_size];
|
||||
|
||||
rom_file.seekg(0, ios::beg);
|
||||
rom_file.read((char*)sysrom_mem, file_size);
|
||||
|
||||
MemCtrlBase* mem_ctrl = dynamic_cast<MemCtrlBase*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
if ((rom_reg = mem_ctrl->find_rom_region())) {
|
||||
mem_ctrl->set_data(rom_reg->start, sysrom_mem, file_size);
|
||||
} else {
|
||||
ABORT_F("Could not locate physical ROM region!");
|
||||
}
|
||||
|
||||
delete[] sysrom_mem;
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
rom_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int create_machine_for_id(string& id, string& rom_filepath) {
|
||||
try {
|
||||
auto machine = machines.at(id);
|
||||
|
||||
/* build machine and load boot ROM */
|
||||
if (get<1>(machine)(id) < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} catch(out_of_range ex) {
|
||||
LOG_F(ERROR, "Unknown machine id %s", id.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,10 +27,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_FACTORY_H
|
||||
#define MACHINE_FACTORY_H
|
||||
|
||||
#include "machinebase.h"
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
int create_machine_for_rom(const char* rom_filepath);
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
int create_gossamer(void);
|
||||
using namespace std;
|
||||
|
||||
std::string machine_name_from_rom(std::string& rom_filepath);
|
||||
|
||||
int get_machine_settings(string& id, map<string, string> &settings);
|
||||
void set_machine_settings(map<string, string> &settings);
|
||||
int create_machine_for_id(string& id, string& rom_filepath);
|
||||
void list_machines(void);
|
||||
void list_properties(void);
|
||||
|
||||
/* Machine-specific factory functions. */
|
||||
int create_gossamer(string& id);
|
||||
int create_pdm(string& id);
|
||||
|
||||
#endif /* MACHINE_FACTORY_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,34 +24,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "machinebase.h"
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include "devices/machineid.h"
|
||||
#include "devices/soundserver.h"
|
||||
#include "devices/macio.h"
|
||||
#include "devices/viacuda.h"
|
||||
#include "devices/spdram.h"
|
||||
#include "devices/atirage.h"
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs)
|
||||
{
|
||||
#include <string>
|
||||
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
if (!capacity_megs)
|
||||
return;
|
||||
|
||||
gMachineObj->add_component(name, new SpdSdram168(i2c_addr));
|
||||
SpdSdram168 *ram_dimm = dynamic_cast<SpdSdram168 *>(gMachineObj->get_comp_by_name(name));
|
||||
SpdSdram168* ram_dimm = dynamic_cast<SpdSdram168*>(gMachineObj->get_comp_by_name(name));
|
||||
ram_dimm->set_capacity(capacity_megs);
|
||||
|
||||
/* register RAM DIMM with the I2C bus */
|
||||
I2CBus *i2c_bus = dynamic_cast<I2CBus *>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(i2c_addr, ram_dimm);
|
||||
}
|
||||
|
||||
|
||||
int create_gossamer()
|
||||
{
|
||||
int create_gossamer(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "Global machine object not empty!");
|
||||
return -1;
|
||||
@@ -67,19 +68,19 @@ int create_gossamer()
|
||||
gMachineObj->add_alias("Grackle", "PCI_Host");
|
||||
|
||||
/* get raw pointer to MPC106 object */
|
||||
MPC106 *grackle_obj = dynamic_cast<MPC106 *>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
|
||||
/* add the machine ID register */
|
||||
gMachineObj->add_component("MachineID", new GossamerID(0x3d8c));
|
||||
grackle_obj->add_mmio_region(0xFF000004, 4096,
|
||||
dynamic_cast<MMIODevice *>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
grackle_obj->add_mmio_region(
|
||||
0xFF000004, 4096, dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
|
||||
gMachineObj->add_component("SoundServer", new SoundServer());
|
||||
|
||||
/* add the Heathrow I/O controller */
|
||||
gMachineObj->add_component("Heathrow", new HeathrowIC);
|
||||
grackle_obj->pci_register_device(16,
|
||||
dynamic_cast<PCIDevice *>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
grackle_obj->pci_register_device(
|
||||
16, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
|
||||
/* allocate ROM region */
|
||||
if (!grackle_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
||||
@@ -88,14 +89,15 @@ int create_gossamer()
|
||||
}
|
||||
|
||||
/* configure RAM slots */
|
||||
setup_ram_slot("RAM_DIMM_1", 0x57, 64); /* RAM slot 1 -> 64MB by default */
|
||||
setup_ram_slot("RAM_DIMM_2", 0x56, 0); /* RAM slot 2 -> empty by default */
|
||||
setup_ram_slot("RAM_DIMM_3", 0x55, 0); /* RAM slot 3 -> empty by default */
|
||||
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
|
||||
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
|
||||
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
|
||||
|
||||
/* register ATI 3D Rage Pro video card with the PCI host bridge */
|
||||
gMachineObj->add_component("ATIRage", new ATIRage(ATI_RAGE_PRO_DEV_ID));
|
||||
grackle_obj->pci_register_device(18,
|
||||
dynamic_cast<PCIDevice *>(gMachineObj->get_comp_by_name("ATIRage")));
|
||||
gMachineObj->add_component("ATIRage",
|
||||
new ATIRage(ATI_RAGE_PRO_DEV_ID, GET_INT_PROP("gfxmem_size")));
|
||||
grackle_obj->pci_register_device(
|
||||
18, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("ATIRage")));
|
||||
|
||||
/* Init virtual CPU and request MPC750 CPU aka G3 */
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Construct a PDM-style PowerMacintosh machine.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
int create_pdm(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "PDM Factory: global machine object not empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initializing the %s hardware...", id.c_str());
|
||||
|
||||
/* initialize the global machine object */
|
||||
gMachineObj.reset(new MachineBase("PDM"));
|
||||
|
||||
/* register HMC memory controller */
|
||||
gMachineObj->add_component("HMC", new HMC);
|
||||
|
||||
/* start the sound server. */
|
||||
gMachineObj->add_component("SoundServer", new SoundServer());
|
||||
|
||||
/* register AMIC I/O controller */
|
||||
gMachineObj->add_component("AMIC", new AMIC);
|
||||
|
||||
/* get raw pointer to HMC object */
|
||||
HMC* hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
|
||||
|
||||
/* allocate machine ID register and tell we're running PowerMac 6100 */
|
||||
// TODO: add a possibility to select another machine
|
||||
// to be used with the same ROM
|
||||
gMachineObj->add_component("MachineID", new NubusMacID(0x3010));
|
||||
hmc_obj->add_mmio_region(0x5FFFFFFC, 4,
|
||||
dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
|
||||
/* allocate ROM region */
|
||||
if (!hmc_obj->add_rom_region(0x40000000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mirror ROM to 0xFFC00000 for a PowerPC CPU to start */
|
||||
if (!hmc_obj->add_mem_mirror(0xFFC00000, 0x40000000)) {
|
||||
LOG_F(ERROR, "Could not create ROM mirror!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* add 8MB of soldered on-board RAM */
|
||||
if (!hmc_obj->add_ram_region(0x00000000, 0x800000)) {
|
||||
LOG_F(ERROR, "Could not allocate built-in RAM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Init virtual CPU and request MPC601 */
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601);
|
||||
|
||||
LOG_F(INFO, "Initialization completed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
static std::map<std::string, StrProperty> PowerMac6100_Properties = {
|
||||
{"machineid", StrProperty("PowerMacG3")},
|
||||
{"cputype", StrProperty("PPC_MPC750")},
|
||||
{"motherboard", StrProperty("Grackle")},
|
||||
{"ioboard", StrProperty("Heathrow")},
|
||||
{"rambank1", StrProperty("8")},
|
||||
{"minram", StrProperty("32")},
|
||||
{"maxram", StrProperty("256")},
|
||||
{"gfxcard", StrProperty("Nubus_Video")},
|
||||
{"gfxmem", StrProperty("2")}
|
||||
};
|
||||
|
||||
static std::map<std::string, StrProperty> PowerMacG3_Properties = {
|
||||
{"machineid", StrProperty("PowerMacG3")},
|
||||
{"cputype", StrProperty("PPC_MPC750")},
|
||||
{"motherboard", StrProperty("Grackle")},
|
||||
{"ioboard", StrProperty("Heathrow")},
|
||||
{"rambank1", StrProperty("64")},
|
||||
{"minram", StrProperty("32")},
|
||||
{"maxram", StrProperty("256")},
|
||||
{"gfxcard", StrProperty("ATI_Rage_Pro")},
|
||||
{"gfxmem", StrProperty("2")}
|
||||
};
|
||||
|
||||
static std::map<std::string, uint32_t> PPC_CPUs = {
|
||||
{"PPC_MPC601", 0x00010001},
|
||||
{"PPC_MPC603", 0x00030001},
|
||||
{"PPC_MPC604", 0x00040001},
|
||||
{"PPC_MPC603E", 0x00060101},
|
||||
{"PPC_MPC750", 0x00080200}
|
||||
};
|
||||
|
||||
static std::map<std::string, uint32_t> GFX_CARDs = {
|
||||
{"ATI_Rage_Pro", 0x10024750},
|
||||
{"ATI_Rage_128_Pro", 0x10025052}
|
||||
};
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef MACHINE_PROPERTIES_H
|
||||
#define MACHINE_PROPERTIES_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define ILLEGAL_DEVICE_VALUE 0x168A523B
|
||||
|
||||
/** Property types. */
|
||||
enum PropType : int {
|
||||
PROP_TYPE_UNKNOWN = 0,
|
||||
PROP_TYPE_STRING = 1,
|
||||
PROP_TYPE_INTEGER = 2,
|
||||
};
|
||||
|
||||
/** Check types for property values. */
|
||||
enum CheckType : int {
|
||||
CHECK_TYPE_NONE = 0,
|
||||
CHECK_TYPE_RANGE = 1,
|
||||
CHECK_TYPE_LIST = 2,
|
||||
};
|
||||
|
||||
/** Abstract base class for properties. */
|
||||
class BasicProperty {
|
||||
public:
|
||||
BasicProperty(PropType type, string val) {
|
||||
this->type = type;
|
||||
set_string(val);
|
||||
}
|
||||
|
||||
virtual ~BasicProperty() = default;
|
||||
|
||||
/* Clone method for copying derived property objects. */
|
||||
virtual BasicProperty* clone() const = 0;
|
||||
|
||||
string get_string() {
|
||||
return this->val;
|
||||
}
|
||||
|
||||
void set_string(string str) {
|
||||
this->val = str;
|
||||
}
|
||||
|
||||
PropType get_type() {
|
||||
return this->type;
|
||||
}
|
||||
|
||||
protected:
|
||||
PropType type;
|
||||
string val;
|
||||
};
|
||||
|
||||
|
||||
/** Property class that holds a string value. */
|
||||
class StrProperty : public BasicProperty {
|
||||
public:
|
||||
StrProperty(string str)
|
||||
: BasicProperty(PROP_TYPE_STRING, str) {}
|
||||
|
||||
BasicProperty* clone() const { return new StrProperty(*this); }
|
||||
};
|
||||
|
||||
/** Property class that holds an integer value. */
|
||||
class IntProperty : public BasicProperty {
|
||||
public:
|
||||
/* construct an integer property without value check. */
|
||||
IntProperty(uint32_t val)
|
||||
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
||||
{
|
||||
this->int_val = val;
|
||||
this->min = std::numeric_limits<uint32_t>::min();
|
||||
this->max = std::numeric_limits<uint32_t>::max();
|
||||
this->check_type = CHECK_TYPE_NONE;
|
||||
this->vec.clear();
|
||||
}
|
||||
|
||||
/* construct an integer property with a predefined range. */
|
||||
IntProperty(uint32_t val, uint32_t min, uint32_t max)
|
||||
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
||||
{
|
||||
this->int_val = val;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->check_type = CHECK_TYPE_RANGE;
|
||||
this->vec.clear();
|
||||
}
|
||||
|
||||
/* construct an integer property with a list of valid values. */
|
||||
IntProperty(uint32_t val, vector<uint32_t> vec)
|
||||
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
||||
{
|
||||
this->int_val = val;
|
||||
this->min = std::numeric_limits<uint32_t>::min();
|
||||
this->max = std::numeric_limits<uint32_t>::max();
|
||||
this->check_type = CHECK_TYPE_LIST;
|
||||
this->vec = vec;
|
||||
}
|
||||
|
||||
BasicProperty* clone() const { return new IntProperty(*this); }
|
||||
|
||||
uint32_t get_int() {
|
||||
try {
|
||||
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
|
||||
|
||||
/* perform value check */
|
||||
if (!this->check_val(result)) {
|
||||
LOG_F(ERROR, "Invalid property value %d!", result);
|
||||
LOG_F(ERROR, "Valid values: %s!",
|
||||
this->get_valid_values_as_str().c_str());
|
||||
this->set_string(to_string(this->int_val));
|
||||
} else {
|
||||
this->int_val = result;
|
||||
}
|
||||
} catch (string bad_string) {
|
||||
LOG_F(ERROR, "Could not convert string %s to an integer!",
|
||||
bad_string.c_str());
|
||||
}
|
||||
return this->int_val;
|
||||
}
|
||||
|
||||
string get_valid_values_as_str() {
|
||||
stringstream ss;
|
||||
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
ss << "[" << this->min << "..." << this->max << "]";
|
||||
return ss.str();
|
||||
case CHECK_TYPE_LIST: {
|
||||
bool first = true;
|
||||
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
|
||||
if (!first)
|
||||
ss << ", ";
|
||||
ss << *it;
|
||||
first = false;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
default:
|
||||
return string("None");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool check_val(uint32_t val) {
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
if (val < this->min || val > this->max)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
case CHECK_TYPE_LIST:
|
||||
if (find(this->vec.begin(), this->vec.end(), val) != this->vec.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t int_val;
|
||||
CheckType check_type;
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
vector<uint32_t> vec;
|
||||
};
|
||||
|
||||
/** Special map type for specifying machine presets. */
|
||||
typedef map<string, BasicProperty*> PropMap;
|
||||
|
||||
/** Global map that holds settings for the running machine. */
|
||||
extern map<string, unique_ptr<BasicProperty>> gMachineSettings;
|
||||
|
||||
/** Conveniency macros to hide complex casts. */
|
||||
#define GET_STR_PROP(name) \
|
||||
dynamic_cast<StrProperty*>(gMachineSettings.at(name).get())->get_string()
|
||||
|
||||
#define GET_INT_PROP(name) \
|
||||
dynamic_cast<IntProperty*>(gMachineSettings.at(name).get())->get_int()
|
||||
|
||||
#endif /* MACHINE_PROPERTIES_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,131 +19,194 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//The main runfile - main.cpp
|
||||
//This is where the magic begins
|
||||
// The main runfile - main.cpp
|
||||
// This is where the magic begins
|
||||
|
||||
//#define SDL
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
#include "ppcemu.h"
|
||||
#include "debugger/debugger.h"
|
||||
#include "execution/interpreter_loop.h"
|
||||
#include "machines/machinefactory.h"
|
||||
#ifdef SDL
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#endif
|
||||
#include "machines/machineproperties.h"
|
||||
#include "utils/profiler.h"
|
||||
#include "ppcemu.h"
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <CLI11.hpp>
|
||||
#include <SDL.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void sigint_handler(int signum) {
|
||||
enter_debugger();
|
||||
|
||||
std::cout << "DingusPPC - Prototype 5bf4 (7/14/2019) " << endl;
|
||||
std::cout << "Written by divingkatae, (c) 2019. " << endl;
|
||||
std::cout << "This is not intended for general use. " << endl;
|
||||
std::cout << "Use at your own discretion. " << endl;
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
if (argc > 1) {
|
||||
string checker = argv[1];
|
||||
cout << checker << endl;
|
||||
delete gMachineObj.release();
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ((checker == "1") || (checker == "realtime") || \
|
||||
(checker == "-realtime") || (checker == "/realtime")) {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
//Replace the above line with this for maximum debugging detail:
|
||||
//loguru::add_file("dingusppc.log", loguru::Append, loguru::Verbosity_MAX);
|
||||
}
|
||||
else if ((checker == "debugger") || (checker == "/debugger") ||
|
||||
(checker == "-debugger")) {
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
loguru::init(argc, argv);
|
||||
void sigabrt_handler(int signum) {
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
delete gMachineObj.release();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
static string appDescription = string(
|
||||
"\nDingusPPC - Prototype 5bf5 (8/23/2020) "
|
||||
"\nWritten by divingkatae and maximumspatium "
|
||||
"\n(c) 2018-2020 The DingusPPC Dev Team. "
|
||||
"\nThis is not intended for general use. "
|
||||
"\nUse at your own discretion. "
|
||||
"\n"
|
||||
);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
/*
|
||||
Execution Type:
|
||||
0 = Realtime (Interpreter)
|
||||
1 = Realtime (Debugger)
|
||||
2 = Recompiler (to-do)
|
||||
|
||||
The rest will be decided later
|
||||
*/
|
||||
|
||||
uint32_t execution_mode = 0;
|
||||
|
||||
CLI::App app(appDescription);
|
||||
app.allow_windows_style_options(); /* we want Windows-style options */
|
||||
app.allow_extras();
|
||||
|
||||
bool realtime_enabled, debugger_enabled;
|
||||
string machine_str;
|
||||
string bootrom_path("bootrom.bin");
|
||||
|
||||
app.add_flag("-r,--realtime", realtime_enabled,
|
||||
"Run the emulator in real-time");
|
||||
|
||||
app.add_flag("-d,--debugger", debugger_enabled,
|
||||
"Enter the built-in debugger");
|
||||
|
||||
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
|
||||
->check(CLI::ExistingFile);
|
||||
|
||||
CLI::Option* machine_opt = app.add_option("-m,--machine",
|
||||
machine_str, "Specify machine ID");
|
||||
|
||||
auto list_cmd = app.add_subcommand("list",
|
||||
"Display available machine configurations and exit");
|
||||
|
||||
string sub_arg;
|
||||
|
||||
list_cmd->add_option("machines", sub_arg, "List supported machines");
|
||||
list_cmd->add_option("properties", sub_arg, "List available properties");
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
if (*list_cmd) {
|
||||
if (sub_arg == "machines") {
|
||||
list_machines();
|
||||
} else if (sub_arg == "properties") {
|
||||
list_properties();
|
||||
} else {
|
||||
cout << "Unknown list subcommand " << sub_arg << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string rom_file = "rom.bin", disk_file = "disk.img";
|
||||
int ram_size = 64, machine_gestalt = 510, video_card_vendor = 0x1002, video_card_id = 0x4750;
|
||||
if (debugger_enabled) {
|
||||
if (realtime_enabled)
|
||||
cout << "Both realtime and debugger enabled! Using debugger" << endl;
|
||||
execution_mode = 1;
|
||||
}
|
||||
|
||||
std::ifstream config_input("config.txt");
|
||||
std::string line;
|
||||
std::istringstream sin;
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
|
||||
if (!config_input) {
|
||||
LOG_F(ERROR, "Could not open config.txt. Creating a dummy config.txt now.");
|
||||
std::ofstream config_output("config.txt");
|
||||
if (!execution_mode) {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
} else {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::init(argc, argv);
|
||||
}
|
||||
|
||||
config_output.write("rompath=rom.bin\n", 17);
|
||||
config_output.write("diskpath=disk.img\n", 19);
|
||||
config_output.write("ramsize=64\n", 12);
|
||||
config_output.write("machine_gestalt=510\n", 21);
|
||||
config_output.write("video_vendor=0x1002\n", 21);
|
||||
config_output.write("video_card=0x4750\n", 19);
|
||||
|
||||
config_output.close();
|
||||
if (*machine_opt) {
|
||||
LOG_F(INFO, "Machine option was passed in: %s", machine_str.c_str());
|
||||
} else {
|
||||
machine_str = machine_name_from_rom(bootrom_path);
|
||||
if (machine_str.empty()) {
|
||||
LOG_F(ERROR, "Could not autodetect machine");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
while (std::getline(config_input, line)) {
|
||||
sin.str(line.substr(line.find("=") + 1));
|
||||
if (line.find("rompath") != std::string::npos) {
|
||||
sin >> rom_file;
|
||||
}
|
||||
else if (line.find("diskpath") != std::string::npos) {
|
||||
sin >> disk_file;
|
||||
}
|
||||
else if (line.find("ramsize") != std::string::npos) {
|
||||
sin >> ram_size;
|
||||
}
|
||||
else if (line.find("machine_gestalt") != std::string::npos) {
|
||||
sin >> machine_gestalt;
|
||||
}
|
||||
else if (line.find("video_vendor") != std::string::npos) {
|
||||
sin >> video_card_vendor;
|
||||
}
|
||||
else if (line.find("video_card") != std::string::npos) {
|
||||
sin >> video_card_id;
|
||||
}
|
||||
sin.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (create_machine_for_rom(rom_file.c_str())) {
|
||||
goto bail;
|
||||
}
|
||||
|
||||
#ifdef SDL
|
||||
if (SDL_Init(SDL_INIT_AUDIO)){
|
||||
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
|
||||
goto bail;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((checker == "1") || (checker == "realtime") || \
|
||||
(checker == "-realtime") || (checker == "/realtime")) {
|
||||
ppc_exec();
|
||||
} else if ((checker == "debugger") || (checker == "/debugger") ||
|
||||
(checker == "-debugger")) {
|
||||
enter_debugger();
|
||||
LOG_F(INFO, "Machine was autodetected as: %s", machine_str.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cout << " " << endl;
|
||||
std::cout << "Please enter one of the following commands when " << endl;
|
||||
std::cout << "booting up DingusPPC... " << endl;
|
||||
std::cout << " " << endl;
|
||||
std::cout << " " << endl;
|
||||
std::cout << "realtime - Run the emulator in real-time. " << endl;
|
||||
std::cout << "debugger - Enter the interactive debugger. " << endl;
|
||||
|
||||
/* handle overriding of machine settings from command line */
|
||||
map<string, string> settings;
|
||||
if (get_machine_settings(machine_str, settings) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CLI::App sa;
|
||||
sa.allow_extras();
|
||||
|
||||
for (auto& s : settings) {
|
||||
sa.add_option("--" + s.first, s.second);
|
||||
}
|
||||
sa.parse(app.remaining_for_passthrough()); /* TODO: handle exceptions! */
|
||||
|
||||
set_machine_settings(settings);
|
||||
|
||||
cout << "BootROM path: " << bootrom_path << endl;
|
||||
cout << "Execution mode: " << execution_mode << endl;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// initialize global profiler object
|
||||
gProfilerObj.reset(new Profiler());
|
||||
|
||||
if (create_machine_for_id(machine_str, bootrom_path) < 0) {
|
||||
goto bail;
|
||||
}
|
||||
|
||||
// graceful handling of fatal errors
|
||||
loguru::set_fatal_handler([](const loguru::Message& message) {
|
||||
enter_debugger();
|
||||
|
||||
abort();
|
||||
});
|
||||
|
||||
// redirect SIGINT to our own handler
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
// redirect SIGABRT to our own handler
|
||||
signal(SIGABRT, sigabrt_handler);
|
||||
|
||||
switch (execution_mode) {
|
||||
case 0:
|
||||
interpreter_main_loop();
|
||||
break;
|
||||
case 1:
|
||||
enter_debugger();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Invalid EXECUTION MODE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bail:
|
||||
@@ -151,5 +214,7 @@ bail:
|
||||
|
||||
delete gMachineObj.release();
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Set of macros for accessing host memory in units of various sizes
|
||||
and endianness.
|
||||
*/
|
||||
|
||||
#ifndef MEM_ACCESS_H
|
||||
#define MEM_ACCESS_H
|
||||
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian QWORD (64bit) */
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)((addr)))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A(addr) (*(uint16_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian QWORD (64bit) */
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t*)((addr)))
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) \
|
||||
(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned big-endian QWORD (32bit) */
|
||||
#define READ_QWORD_BE_U(addr) \
|
||||
((uint64_t((addr)[0]) << 56) | (uint64_t((addr)[1]) << 48) | \
|
||||
(uint64_t((addr)[2]) << 40) | (uint64_t((addr)[3]) << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | ((addr)[6] << 8) | (addr)[7])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) \
|
||||
(((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (64bit) */
|
||||
#define READ_QWORD_LE_U(addr) \
|
||||
((uint64_t((addr)[7]) << 56) | (uint64_t((addr)[6]) << 48) | \
|
||||
(uint64_t((addr)[5]) << 40) | (uint64_t((addr)[4]) << 32) | \
|
||||
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
||||
|
||||
/* write an aligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)((addr))) = BYTESWAP_32(val))
|
||||
|
||||
/* write an aligned big-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((uint64_t)(val) >> 56) & 0xFF; \
|
||||
(addr)[1] = ((uint64_t)(val) >> 48) & 0xFF; \
|
||||
(addr)[2] = ((uint64_t)(val) >> 40) & 0xFF; \
|
||||
(addr)[3] = ((uint64_t)(val) >> 32) & 0xFF; \
|
||||
(addr)[4] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[5] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[6] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[7] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_A(addr, val) (*((uint16_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
perform byte swapping when necessary so that the source
|
||||
byte order remains unchanged. */
|
||||
inline uint32_t read_mem(const uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_BE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_BE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "READ_MEM: invalid size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
perform byte swapping when necessary so that the destination data
|
||||
will be in the reversed byte order. */
|
||||
inline uint32_t read_mem_rev(const uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "READ_MEM_REV: invalid size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* write the specified value of the specified size to memory pointed
|
||||
to by addr, perform necessary byte swapping so that the byte order
|
||||
of the destination remains unchanged. */
|
||||
inline void write_mem(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "WRITE_MEM: invalid size %d!", size);
|
||||
}
|
||||
}
|
||||
|
||||
/* write the specified value of the specified size to memory pointed
|
||||
to by addr, perform necessary byte swapping so that the destination
|
||||
data in memory will be in the reversed byte order. */
|
||||
inline void write_mem_rev(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_LE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_LE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "WRITE_MEM_REV: invalid size %d!", size);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MEM_ACCESS_H */
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/** @file Set of macros for accessing integers of various sizes and endianness
|
||||
in host memory.
|
||||
*/
|
||||
|
||||
#ifndef MEM_READ_WRITE_H
|
||||
#define MEM_READ_WRITE_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "endianswap.h"
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t *)((addr)))))
|
||||
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t *)((addr)))))
|
||||
|
||||
/* read an aligned big-endian QWORD (64bit) */
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t *)((addr)))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A(addr) (*(uint16_t *)((addr)))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t *)((addr)))
|
||||
|
||||
/* read an aligned little-endian QWORD (64bit) */
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t *)((addr)))
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | \
|
||||
((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned big-endian QWORD (32bit) */
|
||||
#define READ_QWORD_BE_U(addr) (((addr)[0] << 56) | ((addr)[1] << 48) | \
|
||||
((addr)[2] << 40) | ((addr)[3] << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | \
|
||||
((addr)[6] << 8) | (addr)[7])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | \
|
||||
((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_QWORD_LE_U(addr) (((addr)[7] << 56) | ((addr)[6] << 48) | \
|
||||
((addr)[5] << 40) | ((addr)[4] << 32) | \
|
||||
((addr)[3] << 24) | ((addr)[2] << 16) | \
|
||||
((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A(addr,val) (*((uint16_t *)((addr))) = BYTESWAP_16(val))
|
||||
|
||||
/* write an aligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_A(addr,val) (*((uint32_t *)((addr))) = BYTESWAP_32(val))
|
||||
|
||||
/* write an aligned big-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_A(addr,val) (*((uint64_t *)((addr))) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_A(addr,val) (*((uint16_t *)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_A(addr,val) (*((uint32_t *)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_LE_A(addr,val) (*((uint64_t *)((addr))) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
/* write an unaligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
#endif /* MEM_READ_WRITE_H */
|
||||
Vendored
+8258
File diff suppressed because it is too large.
Load diff
+1
Submodule thirdparty/capstone added at bfb2e45d76.
Vendored
+1
-1
Submodule thirdparty/cubeb updated: 524a9c99b4...d512bfa07a.
@@ -1,3 +0,0 @@
|
||||
build/
|
||||
build-win32/
|
||||
build-win64/
|
||||
Loaded 100 of 155 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user