mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
442
Commits
disasm-rebase
..
tnt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5668fc161f | ||
|
|
913944c607 | ||
|
|
8889759f33 | ||
|
|
22988f9e28 | ||
|
|
533edf6ef5 | ||
|
|
9d89c5f64e | ||
|
|
b26baaaeff | ||
|
|
e0b94e0b47 | ||
|
|
d4c08bbe31 | ||
|
|
be4f835e6c | ||
|
|
57b102dae2 | ||
|
|
0e09ecdfa4 | ||
|
|
8fcdc5298a | ||
|
|
3a4f22f459 | ||
|
|
b78f17c161 | ||
|
|
4bba61a920 | ||
|
|
d64f901f85 | ||
|
|
883aac2d05 | ||
|
|
f6e5d72e3c | ||
|
|
c967eb3c65 | ||
|
|
89d453b4be | ||
|
|
ba8e3b657c | ||
|
|
4d87ed9b38 | ||
|
|
d71a7b8694 | ||
|
|
e01d0e3d59 | ||
|
|
1d86375061 | ||
|
|
4525fd50cc | ||
|
|
29ce960dbf | ||
|
|
ac5078f133 | ||
|
|
276cd37cfe | ||
|
|
1500c63e26 | ||
|
|
4c45b3dfa2 | ||
|
|
574677490f | ||
|
|
e47b66e1af | ||
|
|
73aa68bc30 | ||
|
|
3bce7bb1ea | ||
|
|
6d004f0bf8 | ||
|
|
e913f39812 | ||
|
|
3235018260 | ||
|
|
a7e4dc9d83 | ||
|
|
13f18c416d | ||
|
|
400ce0b713 | ||
|
|
289df32817 | ||
|
|
36fa53e8c1 | ||
|
|
86bc91028d | ||
|
|
d83fdd8866 | ||
|
|
646880cbf2 | ||
|
|
8d3427c475 | ||
|
|
827d7f10dd | ||
|
|
932a6ae01e | ||
|
|
4de10898ea | ||
|
|
205b5a4956 | ||
|
|
c946693450 | ||
|
|
f1ed56ae9a | ||
|
|
80a4864a92 | ||
|
|
edd3979647 | ||
|
|
123f820775 | ||
|
|
477ad7ddee | ||
|
|
689fe51d80 | ||
|
|
b39e884d61 | ||
|
|
de65196c4f | ||
|
|
8f528184b8 | ||
|
|
2ce2cae48c | ||
|
|
579a56f749 | ||
|
|
2525398b6e | ||
|
|
e91843034b | ||
|
|
9da4a9ec6a | ||
|
|
cfb8977f09 | ||
|
|
54107b2aac | ||
|
|
8d8cecbaba | ||
|
|
0d3fd01fef | ||
|
|
9f3f46603f | ||
|
|
c77155199b | ||
|
|
1872eca44f | ||
|
|
9aaf441625 | ||
|
|
b9fbd9b7c9 | ||
|
|
5e2f2b12e4 | ||
|
|
b25b526582 | ||
|
|
dea863b6e6 | ||
|
|
00093bdc95 | ||
|
|
298135fd7a | ||
|
|
7c53620a40 | ||
|
|
2edb50a821 | ||
|
|
b5f70feb28 | ||
|
|
25a4fd1107 | ||
|
|
5c177cc50f | ||
|
|
dc34f282b7 | ||
|
|
3258abe190 | ||
|
|
5883524fb8 | ||
|
|
c8d39d5ee5 | ||
|
|
2442bd17b3 | ||
|
|
c864b9b7d9 | ||
|
|
3bdc6f915a | ||
|
|
0899186ffc | ||
|
|
c1208b398e | ||
|
|
4867a68e11 | ||
|
|
d8c3cfc38e | ||
|
|
604b4bc2e5 | ||
|
|
e1e651966e | ||
|
|
c12bab9e27 | ||
|
|
9c4e6c8a86 | ||
|
|
c218badd5a | ||
|
|
d61d1d71eb | ||
|
|
d9d8384d4a | ||
|
|
aefc66d118 | ||
|
|
d4ecb77b24 | ||
|
|
339db4a078 | ||
|
|
8efc61e1b9 | ||
|
|
756d32df07 | ||
|
|
9cd7ca0077 | ||
|
|
7bdad7703c | ||
|
|
087402290d | ||
|
|
9a0c340712 | ||
|
|
fd33c10712 | ||
|
|
9caaf0f538 | ||
|
|
476d893094 | ||
|
|
fff597075d | ||
|
|
793335d9b8 | ||
|
|
f609839894 | ||
|
|
f39188beb1 | ||
|
|
decb8342be | ||
|
|
609fb43726 | ||
|
|
c2991149fd | ||
|
|
99f5aba12e | ||
|
|
cbf4e266e1 | ||
|
|
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 | ||
|
|
2cd002cffa | ||
|
|
6ef0f0baae | ||
|
|
d21fdb25d1 | ||
|
|
f204caa907 | ||
|
|
07340d82dd | ||
|
|
55a14ca28f | ||
|
|
4dcdeb095d | ||
|
|
bcc0e38e9f | ||
|
|
ae78a1f04f | ||
|
|
e59939541e | ||
|
|
f8bde236b8 | ||
|
|
0ab9380be3 | ||
|
|
0fcb1fda72 | ||
|
|
286897398c | ||
|
|
d4c39f13af | ||
|
|
ba81094fa2 | ||
|
|
f7d67a91e0 | ||
|
|
a5c63c1b09 | ||
|
|
d24a71528b | ||
|
|
3b98dee232 | ||
|
|
f2ab933884 | ||
|
|
c0d0187190 | ||
|
|
d0f03f722e | ||
|
|
a5b740eafc | ||
|
|
70f5b45e71 | ||
|
|
64d74228c2 | ||
|
|
3d13bc1ca6 | ||
|
|
7154e51d86 | ||
|
|
add11ecc62 | ||
|
|
8fb2e851d7 | ||
|
|
3461f2e353 | ||
|
|
54a86972cd | ||
|
|
925bcdfe9f | ||
|
|
9f95fde279 | ||
|
|
b6fcd289a3 | ||
|
|
a243c79d0f | ||
|
|
cc5261cfa9 | ||
|
|
a8c6298545 | ||
|
|
695044cf0e | ||
|
|
ec384fb5ea | ||
|
|
1744f13fb4 | ||
|
|
f50f719b02 | ||
|
|
17200d5f35 | ||
|
|
c1dec68afd | ||
|
|
13e90b9cb9 | ||
|
|
b16d1c43ef | ||
|
|
82c4a5dbcf | ||
|
|
4e41af21e8 | ||
|
|
35d6a2e011 | ||
|
|
0d2301c006 | ||
|
|
60ffa5bfac | ||
|
|
945e63bdb2 | ||
|
|
8e34c1657c | ||
|
|
787ebfaff1 | ||
|
|
751efb4cd6 | ||
|
|
9be3250142 | ||
|
|
86d6ddf001 | ||
|
|
0044610038 | ||
|
|
9c8548c238 | ||
|
|
753e445b4b | ||
|
|
75f0e09f5a | ||
|
|
14156dd32b | ||
|
|
d53400ebae | ||
|
|
822f6cafd2 | ||
|
|
4adcd811e3 | ||
|
|
831adfbda0 | ||
|
|
4ceed27ccf | ||
|
|
78fc5c408b | ||
|
|
e31f7873f5 | ||
|
|
392119480e | ||
|
|
94cf232b5e | ||
|
|
71d6966a03 | ||
|
|
85ee6e9a86 | ||
|
|
e09be8126f | ||
|
|
9f5e3fa47a | ||
|
|
cea840fc09 | ||
|
|
0eb557751b | ||
|
|
f5e8c9cbb8 | ||
|
|
31147aada3 | ||
|
|
81cabc5730 | ||
|
|
07badbb1b3 | ||
|
|
cbb46e8f30 | ||
|
|
7978d9d59f | ||
|
|
1e06f724af | ||
|
|
055445e04a | ||
|
|
354409812e | ||
|
|
e08bf39af3 | ||
|
|
160566b8f8 | ||
|
|
5991ef1dca | ||
|
|
c8611dc293 | ||
|
|
51739520b5 | ||
|
|
90779bd9c6 | ||
|
|
d7c0a731f4 | ||
|
|
eef82649f7 | ||
|
|
a3f55d35b4 | ||
|
|
e3a1c3501a | ||
|
|
8bf902d945 | ||
|
|
6c1dc8aaf0 | ||
|
|
baef838f7c | ||
|
|
d91950e582 | ||
|
|
e9a616ffeb | ||
|
|
3ffa680f6d | ||
|
|
f29a63acd4 | ||
|
|
b6768d7168 | ||
|
|
461d859e73 | ||
|
|
403c19ca39 | ||
|
|
02a75f78da | ||
|
|
d20122b3a9 |
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
|
||||
@@ -7,6 +7,9 @@ out/
|
||||
*.o
|
||||
*.d
|
||||
|
||||
# Ignore Visual Studio configuration files
|
||||
CMakeSettings.json
|
||||
|
||||
# Ignore generated executables
|
||||
dingusppc
|
||||
dingusppc.exe
|
||||
@@ -14,3 +17,8 @@ dingusppc.exe
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumb.db
|
||||
|
||||
# IDE ignores
|
||||
build
|
||||
build-*
|
||||
*.user
|
||||
@@ -0,0 +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
|
||||
+160
-13
@@ -4,29 +4,176 @@ project(dingusppc)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
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}/core")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
#set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "Build libsoundio example programs")
|
||||
#set(BUILD_TESTS OFF CACHE BOOL "Build libsoundio tests")
|
||||
#set(BUILD_DYNAMIC_LIBS ON CACHE BOOL "Build libsoundio dynamic libs")
|
||||
#set(BUILD_STATIC_LIBS ON CACHE BOOL "Build libsoundio static libs")
|
||||
|
||||
#add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/libsoundio")
|
||||
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/core"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc"
|
||||
"${PROJECT_SOURCE_DIR}/debugger")
|
||||
"${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})
|
||||
|
||||
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/debugger/*.cpp")
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
|
||||
#get_directory_property(LIBSOUNDIO_LIBS DIRECTORY thirdparty/libsoundio DEFINITION LIBSOUNDIO_LIBS)
|
||||
|
||||
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
|
||||
|
||||
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:cpu_ppc> $<TARGET_OBJECTS:devices>)
|
||||
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:cpu_ppc> $<TARGET_OBJECTS:devices>)
|
||||
if (WIN32)
|
||||
target_link_libraries(dingusppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${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_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_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
endif()
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<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} ${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:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<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)
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"inheritEnvironments": [ "clang_cl_x64" ],
|
||||
"variables": []
|
||||
}
|
||||
]
|
||||
|
||||
+12
-1
@@ -10,7 +10,18 @@ Code
|
||||
|
||||
* Make sure the code can compile for all target systems - Windows, Linux, and macOS/Mac OS X.
|
||||
* All code must be compatible with at least C++11.
|
||||
* Minimize the amount of redundant code
|
||||
* Minimize the amount of redundant code.
|
||||
* Avoid using absolute paths for the headers.
|
||||
* Code should maintain vertical alignment for better readability, for example:
|
||||
|
||||
```C
|
||||
one_hundred = 100;
|
||||
one_thousand = 1000;
|
||||
two_thousand = 2000;
|
||||
```
|
||||
|
||||
* CamelCase for class names, lowercase for variables, UPPERCASE for enumerations
|
||||
* Avoid redundancy in namespaces (i.e. use ViaCuda::read() instead of ViaCuda::cuda_read())
|
||||
|
||||
Issues
|
||||
=======
|
||||
|
||||
@@ -1,35 +1,65 @@
|
||||
# DingusPPC by divingkatae
|
||||
# DingusPPC
|
||||
|
||||
Written by divingkatae and maximumspatium
|
||||
|
||||
Be warned the program is highly unfinished and could use a lot of testing. Any feedback is welcome.
|
||||
|
||||
## PHILOSOPHY OF USE
|
||||
## Philosophy of Use
|
||||
|
||||
Sheepshaver, while technically impressive, is becoming harder to compile and run. While many other PowerPC emus exist, none of them currently attempt emulation of PPC Macs (except for QEMU).
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver has 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.
|
||||
|
||||
## HOW TO USE
|
||||
## Implemented Features
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow OpenFirmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
|
||||
## How to Use
|
||||
|
||||
This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
|
||||
-realtime
|
||||
```
|
||||
-r, --realtime
|
||||
```
|
||||
|
||||
Run the emulator in runtime.
|
||||
|
||||
-debugger
|
||||
```
|
||||
-d, --debugger
|
||||
```
|
||||
|
||||
Enter the interactive debugger.
|
||||
|
||||
## HOW TO COMPILE
|
||||
```
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
You'll need to install development tools first.
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
For example, to build the project in a Unix-like environment, you'll need to run
|
||||
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 need to install development tools first.
|
||||
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
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
|
||||
@@ -39,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, no additional libraries are required.
|
||||
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 @@
|
||||
theme: jekyll-theme-minimal
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(core OBJECT ${SOURCES})
|
||||
target_link_libraries(core)
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Timer management system. */
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include "timermanager.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
if (!timeout || timeout <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", timeout);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + timeout;
|
||||
ti->interval_ns = 0;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
{
|
||||
if (!interval || interval <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", interval);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + interval;
|
||||
ti->interval_ns = interval;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
{
|
||||
TimerInfo* cur_timer = this->timer_queue.top().get();
|
||||
if (cur_timer->id == id) {
|
||||
this->timer_queue.pop();
|
||||
} else {
|
||||
this->timer_queue.remove_by_id(id);
|
||||
}
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t TimerManager::process_timers(uint64_t time_now)
|
||||
{
|
||||
TimerInfo* cur_timer;
|
||||
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
// scan for expired timers
|
||||
cur_timer = this->timer_queue.top().get();
|
||||
while (cur_timer->timeout_ns <= time_now ||
|
||||
cur_timer->timeout_ns <= (time_now + MIN_TIMEOUT_NS)) {
|
||||
timer_cb cb = cur_timer->cb;
|
||||
|
||||
// re-arm cyclic timers
|
||||
if (cur_timer->interval_ns) {
|
||||
auto new_timer = this->timer_queue.top();
|
||||
new_timer->timeout_ns = time_now + cur_timer->interval_ns;
|
||||
this->timer_queue.pop();
|
||||
this->timer_queue.push(new_timer);
|
||||
} else {
|
||||
// remove one-shot timers from queue
|
||||
this->timer_queue.pop();
|
||||
}
|
||||
|
||||
this->cb_active = true;
|
||||
|
||||
// invoke timer callback
|
||||
cb();
|
||||
|
||||
this->cb_active = false;
|
||||
|
||||
// process next timer
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
cur_timer = this->timer_queue.top().get();
|
||||
}
|
||||
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
return cur_timer->timeout_ns - time_now;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 TIMER_MANAGER_H
|
||||
#define TIMER_MANAGER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MIN_TIMEOUT_NS 200
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * 1000
|
||||
|
||||
typedef function<void()> timer_cb;
|
||||
|
||||
/** Extend std::priority_queue as suggested here:
|
||||
https://stackoverflow.com/a/36711682
|
||||
to be able to remove arbitrary elements.
|
||||
*/
|
||||
template <typename T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
|
||||
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
|
||||
public:
|
||||
bool remove_by_id(const uint32_t id){
|
||||
auto it = std::find_if(
|
||||
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == id; });
|
||||
if (it != this->c.end()) {
|
||||
this->c.erase(it);
|
||||
std::make_heap(this->c.begin(), this->c.end(), this->comp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct TimerInfo {
|
||||
uint32_t id;
|
||||
uint64_t timeout_ns; // timer expiry
|
||||
uint64_t interval_ns; // 0 for one-shot timers
|
||||
timer_cb cb; // timer callback
|
||||
} TimerInfo;
|
||||
|
||||
// Custom comparator for sorting our timer queue in ascending order
|
||||
class MyGtComparator {
|
||||
public:
|
||||
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns;
|
||||
}
|
||||
};
|
||||
|
||||
class TimerManager {
|
||||
public:
|
||||
static TimerManager* get_instance() {
|
||||
if (!timer_manager) {
|
||||
timer_manager = new TimerManager();
|
||||
}
|
||||
return timer_manager;
|
||||
};
|
||||
|
||||
// callback for retrieving current time
|
||||
void set_time_now_cb(const function<uint64_t()> &cb) {
|
||||
this->get_time_now = cb;
|
||||
};
|
||||
|
||||
// callback for acknowledging time changes
|
||||
void set_notify_changes_cb(const timer_cb &cb) {
|
||||
this->notify_timer_changes = cb;
|
||||
};
|
||||
|
||||
// return current virtual time in nanoseconds
|
||||
uint64_t current_time_ns() { return get_time_now(); };
|
||||
|
||||
// creating and cancelling timers
|
||||
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
|
||||
void cancel_timer(uint32_t id);
|
||||
|
||||
uint64_t process_timers(uint64_t time_now);
|
||||
|
||||
private:
|
||||
static TimerManager* timer_manager;
|
||||
TimerManager(){}; // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
|
||||
function<uint64_t()> get_time_now;
|
||||
function<void()> notify_timer_changes;
|
||||
|
||||
uint32_t id = 0;
|
||||
bool cb_active = false; // true if a timer callback is executing
|
||||
};
|
||||
|
||||
#endif // TIMER_MANAGER_H
|
||||
@@ -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")
|
||||
|
||||
|
||||
+409
-665
File diff suppressed because it is too large.
Load diff
+507
-420
File diff suppressed because it is too large.
Load diff
+26
-5
@@ -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/>.
|
||||
*/
|
||||
|
||||
#ifndef PPCDISASM_H
|
||||
#define PPCDISASM_H
|
||||
|
||||
@@ -5,17 +26,17 @@
|
||||
#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 */
|
||||
+215
-243
@@ -1,37 +1,56 @@
|
||||
//DingusPPC - Prototype 5bf2
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 on Discord)
|
||||
/*
|
||||
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 PPCEMU_H
|
||||
#define PPCEMU_H
|
||||
|
||||
#include <cinttypes>
|
||||
#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
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -49,39 +68,41 @@ fpscr = FP Status and Condition Register
|
||||
**/
|
||||
|
||||
typedef struct struct_ppc_state {
|
||||
FPR_storage ppc_fpr[32];
|
||||
uint32_t ppc_pc; //Referred as the CIA in the PPC manual
|
||||
uint32_t ppc_gpr[32];
|
||||
uint32_t ppc_cr;
|
||||
uint32_t ppc_fpscr;
|
||||
uint32_t ppc_tbr[2];
|
||||
uint32_t ppc_spr[1024];
|
||||
uint32_t ppc_msr;
|
||||
uint32_t ppc_sr[16];
|
||||
bool ppc_reserve; //reserve bit used for lwarx and stcwx
|
||||
FPR_storage fpr[32];
|
||||
uint32_t pc; // Referred as the CIA in the PPC manual
|
||||
uint32_t gpr[32];
|
||||
uint32_t cr;
|
||||
uint32_t fpscr;
|
||||
uint32_t tbr[2];
|
||||
uint32_t spr[1024];
|
||||
uint32_t msr;
|
||||
uint32_t sr[16];
|
||||
bool reserve; // reserve bit used for lwarx and stcwx
|
||||
} SetPRS;
|
||||
|
||||
extern SetPRS ppc_state;
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum SPR : int {
|
||||
MQ = 0,
|
||||
XER = 1,
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
DEC = 22,
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
PVR = 287
|
||||
};
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum TBR : int {
|
||||
TBL = 0,
|
||||
TBU = 1
|
||||
MQ = 0,
|
||||
XER = 1,
|
||||
RTCU_U = 4, // user RTCU
|
||||
RTCL_U = 5, // user RTCL
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
RTCU_S = 20, // supervisor RTCU
|
||||
RTCL_S = 21, // supervisor RTCL
|
||||
DEC = 22,
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
TBL_U = 268, // user mode TBL
|
||||
TBU_U = 269, // user mode TBU
|
||||
TBL_S = 284, // supervisor TBL
|
||||
TBU_S = 285, // supervisor TBU
|
||||
PVR = 287
|
||||
};
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
@@ -95,16 +116,16 @@ enum PPC_VER : uint32_t {
|
||||
|
||||
/**
|
||||
typedef struct struct_ppc64_state {
|
||||
FPR_storage ppc_fpr [32];
|
||||
uint64_t ppc_pc; //Referred as the CIA in the PPC manual
|
||||
uint64_t ppc_gpr [32];
|
||||
uint32_t ppc_cr;
|
||||
uint32_t ppc_fpscr;
|
||||
uint32_t ppc_tbr [2];
|
||||
uint64_t ppc_spr [1024];
|
||||
uint32_t ppc_msr;
|
||||
uint32_t ppc_sr [16];
|
||||
bool ppc_reserve; //reserve bit used for lwarx and stcwx
|
||||
FPR_storage fpr [32];
|
||||
uint64_t pc; //Referred as the CIA in the PPC manual
|
||||
uint64_t gpr [32];
|
||||
uint32_t cr;
|
||||
uint32_t fpscr;
|
||||
uint32_t tbr [2];
|
||||
uint64_t spr [1024];
|
||||
uint32_t msr;
|
||||
uint32_t sr [16];
|
||||
bool reserve; //reserve bit used for lwarx and stcwx
|
||||
} SetPRS64;
|
||||
|
||||
extern SetPRS64 ppc_state64;
|
||||
@@ -132,18 +153,20 @@ 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
|
||||
|
||||
//Additional steps to prevent overflow?
|
||||
extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint64_t tbr_freq_hz;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
extern int32_t simult_result;
|
||||
extern uint32_t uiadd_result;
|
||||
extern uint32_t uimult_result;
|
||||
|
||||
extern 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;
|
||||
@@ -161,31 +184,94 @@ 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;
|
||||
extern uint64_t ppc_result64_d;
|
||||
|
||||
/* Flags for controlling interpreter execution. */
|
||||
enum {
|
||||
EXEF_BRANCH = 1 << 0,
|
||||
EXEF_EXCEPTION = 1 << 1,
|
||||
EXEF_RFI = 1 << 2,
|
||||
EXEF_TIMER = 1 << 7
|
||||
};
|
||||
|
||||
/* The precise end of a basic block. */
|
||||
enum class BB_end_kind {
|
||||
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. */
|
||||
@@ -200,40 +286,55 @@ enum class Except_Type {
|
||||
EXC_NO_FPU,
|
||||
EXC_DECR,
|
||||
EXC_SYSCALL = 12,
|
||||
EXC_TRACE = 13
|
||||
EXC_TRACE = 13
|
||||
};
|
||||
|
||||
//extern bool bb_end;
|
||||
extern BB_end_kind bb_kind;
|
||||
/** 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 unsigned exec_flags;
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
|
||||
extern bool grab_branch;
|
||||
extern bool grab_exception;
|
||||
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(uint32_t proc_version);
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init(uint32_t cpu_version);
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_opcode4();
|
||||
void ppc_fpu_off();
|
||||
void ppc_ext_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
void ppc_opcode19();
|
||||
@@ -241,7 +342,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);
|
||||
|
||||
@@ -259,29 +361,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();
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type,
|
||||
uint32_t srr1_bits);
|
||||
/* Exception handlers. */
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
|
||||
//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();
|
||||
@@ -297,33 +394,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();
|
||||
@@ -331,20 +410,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();
|
||||
@@ -361,33 +433,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();
|
||||
@@ -399,25 +455,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();
|
||||
@@ -426,7 +467,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();
|
||||
@@ -438,6 +478,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();
|
||||
@@ -447,15 +488,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();
|
||||
@@ -521,11 +557,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();
|
||||
@@ -547,121 +583,57 @@ 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 uint64_t get_virt_time_ns(void);
|
||||
|
||||
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_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 */
|
||||
+162
-67
@@ -1,93 +1,188 @@
|
||||
/*
|
||||
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 Handling of low-level PPC exceptions. */
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <loguru.hpp>
|
||||
#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)
|
||||
{
|
||||
grab_exception = true;
|
||||
#ifdef PROFILER
|
||||
exceptions_performed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
|
||||
switch(exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_msr & 0x1000)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_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.ppc_spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 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.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 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:
|
||||
ABORT_F("Unknown exception occured: %X\n", exception_type);
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.ppc_spr[SPR::SRR1] = (ppc_state.ppc_msr & 0x0000FF73) | srr1_bits;
|
||||
ppc_state.ppc_msr &= 0xFFFB1041;
|
||||
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
|
||||
ppc_state.msr &= 0xFFFB1041;
|
||||
/* copy MSR[ILE] to MSR[LE] */
|
||||
ppc_state.ppc_msr = (ppc_state.ppc_msr & 0xFFFFFFFE) |
|
||||
((ppc_state.ppc_msr >> 16) & 1);
|
||||
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) | ((ppc_state.msr >> 16) & 1);
|
||||
|
||||
if (ppc_state.ppc_msr & 0x40) {
|
||||
if (ppc_state.msr & 0x40) {
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
exec_flags = EXEF_EXCEPTION;
|
||||
|
||||
// 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();
|
||||
|
||||
if (exception_type != Except_Type::EXC_EXT_INT) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[[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;
|
||||
|
||||
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_EXT_INT:
|
||||
exc_descriptor = "External interrupt 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_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_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occured";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occured";
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
+774
-647
File diff suppressed because it is too large.
Load diff
+781
-998
File diff suppressed because it is too large.
Load diff
@@ -1,32 +0,0 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
|
||||
// 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);
|
||||
}
|
||||
+1776
-300
File diff suppressed because it is too large.
Load diff
+109
-20
@@ -1,44 +1,133 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
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 PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#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
|
||||
};
|
||||
|
||||
/** 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 PAGE_SIZE (1 << PAGE_SIZE_BITS)
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1)
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
|
||||
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 uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
|
||||
#endif // PPCMEMORY_H
|
||||
#endif // PPCMMU_H
|
||||
+1317
-1552
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")
|
||||
@@ -64,6 +64,8 @@
|
||||
|
||||
# indexed load/store instructions, primary opcode 0x1F
|
||||
0xFFF00100,0x7D49F02E,lwzx,r10,r9,r30
|
||||
0xFFF00100,0x7C00002E,lwzx,r0,0,r0
|
||||
0xFFF00100,0x7C20082E,lwzx,r1,0,r1
|
||||
0xFFF00100,0x7FAB806E,lwzux,r29,r11,r16
|
||||
0xFFF00100,0x7C0820AE,lbzx,r0,r8,r4
|
||||
0xFFF00100,0x7F47E8EE,lbzux,r26,r7,r29
|
||||
@@ -184,6 +186,16 @@
|
||||
0xFFF00100,0x7D838120,mtcrf,0x38,r12
|
||||
0xFFF00100,0x7D080120,mtcrf,0x80,r8
|
||||
0xFFF00100,0x7E007120,mtcrf,0x07,r16
|
||||
0xFFF00100,0x7C2FF120,mtcr,r1
|
||||
|
||||
# logical operations with the condition register
|
||||
0xFFF00100,0x4C422A02,crand,eq,eq,4*cr1+gt
|
||||
0xFFF00100,0x4FCAF902,crandc,4*cr7+eq,4*cr2+eq,4*cr7+so
|
||||
0xFFF00100,0x4E756242,creqv,4*cr4+so,4*cr5+gt,4*cr3+lt
|
||||
0xFFF00100,0x4F58C9C2,crnand,4*cr6+eq,4*cr6+lt,4*cr6+gt
|
||||
0xFFF00100,0x4C411382,cror,eq,gt,eq
|
||||
0xFFF00100,0x4C402342,crorc,eq,lt,4*cr1+lt
|
||||
0xFFF00100,0x4C003982,crxor,lt,lt,4*cr1+so
|
||||
|
||||
# rotation instructions and their simplified mnemonics
|
||||
#0xFFF00100,0x5084442E,rlwimi,r4,r4,8,16,23
|
||||
@@ -319,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
|
||||
@@ -350,13 +362,26 @@
|
||||
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
|
||||
0xFFF00100,0x7FBFB800,cmp,cr7,r31,r23
|
||||
0xFFF00100,0x7C053040,cmplw,r5,r6
|
||||
0xFFF00100,0x7F804840,cmplw,cr7,r0,r9
|
||||
0xFFF00100,0x2F800000,cmpwi,cr7,r0,0x0
|
||||
0xFFF00100,0x298E0022,cmplwi,cr3,r14,0x22
|
||||
@@ -371,8 +396,11 @@
|
||||
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
|
||||
0xFFF00100,0x7C000124,mtmsr,r0
|
||||
0xFFF00100,0x7FEF01A4,mtsr,15,r31
|
||||
0xFFF00100,0x7C6021E4,mtsrin,r3,r4
|
||||
0xFFF00100,0x7CA305AA,stswi,r5,r3,0x20
|
||||
|
||||
|
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+219
-73
@@ -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.ppc_gpr[3] = 2;
|
||||
ppc_state.ppc_gpr[4] = 2;
|
||||
ppc_state.ppc_spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
if (ppc_state.ppc_spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set."
|
||||
<< endl;
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
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.ppc_gpr[3] = src1;
|
||||
ppc_state.ppc_gpr[4] = src2;
|
||||
ppc_state.ppc_spr[SPR::XER] = 0;
|
||||
ppc_state.ppc_cr = 0;
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
@@ -130,16 +149,14 @@ static void read_test_data()
|
||||
|
||||
ntested++;
|
||||
|
||||
if ((tokens[0].rfind("CMP") && (ppc_state.ppc_gpr[3] != dest)) ||
|
||||
(ppc_state.ppc_spr[SPR::XER] != check_xer) ||
|
||||
(ppc_state.ppc_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.ppc_gpr[3] << ", XER=0x"
|
||||
<< hex << ppc_state.ppc_spr[SPR::XER] << ", CR=0x" << hex
|
||||
<< ppc_state.ppc_cr << endl;
|
||||
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;
|
||||
cout << "Test file line #: " << dec << lineno << endl << endl;
|
||||
|
||||
nfailed++;
|
||||
@@ -147,9 +164,131 @@ static void read_test_data()
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
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;
|
||||
|
||||
@@ -164,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;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
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})
|
||||
+532
-83
@@ -1,75 +1,391 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 <array>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include "ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include "memaccess.h"
|
||||
#include "utils/profiler.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_help()
|
||||
{
|
||||
static uint32_t str2addr(string& addr_str) {
|
||||
try {
|
||||
return stoul(addr_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + addr_str);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t str2num(string& num_str) {
|
||||
try {
|
||||
return stol(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
}
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step -- execute single instruction" << 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 << " memdump -- dump content of the system memory to memdump.bin" << 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 << " go -- exit debugger and continue emulator execution" << 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 << " 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 << " printenv -- print current NVRAM settings." << endl;
|
||||
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
void dump_regs()
|
||||
{
|
||||
for (uint32_t i = 0; i < 32; i++)
|
||||
cout << "GPR " << dec << i << " : " << hex << ppc_state.ppc_gpr[i] << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
cout << "PC: " << hex << ppc_state.ppc_pc << endl;
|
||||
cout << "LR: " << hex << ppc_state.ppc_spr[8] << endl;
|
||||
cout << "CR: " << hex << ppc_state.ppc_cr << endl;
|
||||
cout << "CTR: " << hex << ppc_state.ppc_spr[9] << endl;
|
||||
cout << "XER: " << hex << ppc_state.ppc_spr[1] << endl;
|
||||
cout << "MSR: " << hex << ppc_state.ppc_msr << endl;
|
||||
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);
|
||||
}
|
||||
|
||||
void disasm(uint32_t inst_num = 1UL, uint32_t address = ppc_state.ppc_pc)
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
{
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
/* PPC r24 contains 68k PC advanced by two bytes
|
||||
as part of instruction prefetching */
|
||||
cur_68k_pc = get_reg(string("R24")) - 2;
|
||||
|
||||
/* PPC r29 contains base address of the emulator opcode table */
|
||||
emu_table_virt = get_reg(string("R29")) & 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 */
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
|
||||
//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();
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
}
|
||||
|
||||
/* Getting here means we're outside the emualtor opcode table.
|
||||
Execute PPC code until we hit the opcode table again. */
|
||||
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)
|
||||
{
|
||||
uint32_t emu_table_virt, ppc_pc;
|
||||
|
||||
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
|
||||
|
||||
while (target_addr != (get_reg(string("R24")) - 2)) {
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
|
||||
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
|
||||
ppc_exec_single();
|
||||
} else {
|
||||
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
|
||||
|
||||
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
|
||||
|
||||
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
|
||||
|
||||
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
|
||||
}
|
||||
|
||||
#endif // ENABLE_68K_DEBUGGER
|
||||
|
||||
static void dump_mem(string& params) {
|
||||
int cell_size, chars_per_line;
|
||||
bool is_char;
|
||||
uint32_t count, addr;
|
||||
uint64_t val;
|
||||
string num_type_str, addr_str;
|
||||
size_t separator_pos;
|
||||
|
||||
separator_pos = params.find_first_of(",");
|
||||
if (separator_pos == std::string::npos) {
|
||||
cout << "dump: not enough arguments specified." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
num_type_str = params.substr(0, params.find_first_of(","));
|
||||
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;
|
||||
}
|
||||
|
||||
try {
|
||||
num_type_str = num_type_str.substr(0, num_type_str.length() - 1);
|
||||
count = str2addr(num_type_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
addr = get_reg(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Dumping memory at address " << hex << addr << ":" << endl;
|
||||
|
||||
chars_per_line = 0;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < count; addr += cell_size, i++) {
|
||||
if (chars_per_line + cell_size * 2 > 80) {
|
||||
cout << endl;
|
||||
chars_per_line = 0;
|
||||
}
|
||||
val = mem_read_dbg(addr, cell_size);
|
||||
if (is_char) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
quickinstruction_translate(ppc_state.ppc_pc);
|
||||
|
||||
ctx.instr_addr = ppc_state.ppc_pc;
|
||||
ctx.instr_code = ppc_cur_instruction;
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
cout << hex << ppc_state.ppc_pc << " " << disassemble_single(&ctx) << endl;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void enter_debugger()
|
||||
{
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, inst_string, inst_num_str;
|
||||
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, profile_name, sub_cmd;
|
||||
uint32_t addr, inst_grab;
|
||||
std::stringstream ss;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
cout << "Welcome to the PowerPC debugger." << endl;
|
||||
unique_ptr<OfNvramUtils> ofnvram = unique_ptr<OfNvramUtils>(new OfNvramUtils);
|
||||
ofnvram->init();
|
||||
|
||||
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("");
|
||||
@@ -86,59 +402,192 @@ 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") {
|
||||
dump_regs();
|
||||
}
|
||||
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;
|
||||
reg_expr = expr_str.substr(0, expr_str.find("="));
|
||||
if (reg_expr == "pc") {
|
||||
addr_str = expr_str.substr(expr_str.find("=") + 1);
|
||||
addr = stol(addr_str, NULL, 0);
|
||||
ppc_state.ppc_pc = addr;
|
||||
|
||||
separator_pos = expr_str.find_first_of("=");
|
||||
if (separator_pos == std::string::npos) {
|
||||
cout << "set: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
cout << "Unknown register " << reg_expr << endl;
|
||||
|
||||
try {
|
||||
reg_expr = expr_str.substr(0, expr_str.find_first_of("="));
|
||||
addr_str = expr_str.substr(expr_str.find_first_of("=") + 1);
|
||||
if (reg_expr == "loglevel") {
|
||||
log_level = str2num(addr_str);
|
||||
if (log_level < -2 || log_level > 9) {
|
||||
cout << "Log level must be in the range -2...9!" << endl;
|
||||
continue;
|
||||
}
|
||||
loguru::g_stderr_verbosity = log_level;
|
||||
} else {
|
||||
addr = str2addr(addr_str);
|
||||
set_reg(reg_expr, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
else if (cmd == "step") {
|
||||
ppc_exec_single();
|
||||
}
|
||||
else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
addr = stol(addr_str, NULL, 16);
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
else if (cmd == "disas") {
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
int count;
|
||||
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
cout << "Parsing disas params." << endl;
|
||||
inst_num_str = expr_str.substr(expr_str.find(" ") + 1, expr_str.find(","));
|
||||
inst_grab = stoul(inst_num_str, NULL, 0);
|
||||
addr_str = expr_str.substr(expr_str.find(",") + 1, expr_str.length() - 1);
|
||||
addr = stoul(addr_str, NULL, 16);
|
||||
disasm(inst_grab, addr);
|
||||
try {
|
||||
count = str2num(expr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
count = 1;
|
||||
}
|
||||
} else {
|
||||
count = 1;
|
||||
}
|
||||
else {
|
||||
disasm();
|
||||
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
for (; --count >= 0;) {
|
||||
ppc_exec_single();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
ppc_exec_until(addr);
|
||||
} else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
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 == "go") {
|
||||
ppc_exec(); // won't return!
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
separator_pos = expr_str.find_first_of(",");
|
||||
if (separator_pos == std::string::npos) {
|
||||
cout << "disas: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
inst_num_str = expr_str.substr(0, expr_str.find_first_of(","));
|
||||
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) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
} 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 if (cmd == "dump") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
dump_mem(expr_str);
|
||||
#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 if (cmd == "printenv") {
|
||||
ofnvram->printenv();
|
||||
} else if (cmd == "setenv") {
|
||||
string var_name, value;
|
||||
ss >> var_name;
|
||||
ss >> value;
|
||||
ofnvram->setenv(var_name, value);
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
}
|
||||
last_cmd = cmd;
|
||||
}
|
||||
}
|
||||
}
|
||||
+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_
|
||||
+18
-2
@@ -1,5 +1,21 @@
|
||||
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}/floppy/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
@@ -0,0 +1,472 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** ADB bus definitions
|
||||
|
||||
Simulates Apple Desktop Bus (ADB) bus
|
||||
|
||||
*/
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#include <thirdparty/SDL2/include/SDL_keycode.h>
|
||||
#include <thirdparty/SDL2/include/SDL_mouse.h>
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
// set data streams as clear
|
||||
this->adb_mouse_register0 = 0x8080;
|
||||
|
||||
input_stream_len = 0;
|
||||
output_stream_len = 2;
|
||||
|
||||
adb_keybd_register3 = 0x6201;
|
||||
adb_mouse_register3 = 0x6302;
|
||||
|
||||
keyboard_access_no = adb_encoded;
|
||||
mouse_access_no = adb_relative;
|
||||
}
|
||||
|
||||
bool ADB_Bus::listen(int device, int reg) {
|
||||
if (device == keyboard_access_no) {
|
||||
if (adb_keybd_listen(reg)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (device == mouse_access_no) {
|
||||
if (adb_mouse_listen(reg)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::talk(int device, int reg, uint16_t value) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::bus_reset() {
|
||||
// temp code
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ADB_Bus::set_addr(int dev_addr, int new_addr) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::flush(int dev_addr) {
|
||||
// temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
if (reg == 3) {
|
||||
output_data_stream[0] = (adb_keybd_register3 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register3 & 0xff);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_keybd_evt)) {
|
||||
// Poll our SDL key event for any keystrokes.
|
||||
switch (adb_keybd_evt.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (adb_keybd_evt.key.keysym.sym) {
|
||||
case SDLK_a:
|
||||
ask_key_pressed = 0x00;
|
||||
break;
|
||||
case SDLK_s:
|
||||
ask_key_pressed = 0x01;
|
||||
break;
|
||||
case SDLK_d:
|
||||
ask_key_pressed = 0x02;
|
||||
break;
|
||||
case SDLK_f:
|
||||
ask_key_pressed = 0x03;
|
||||
break;
|
||||
case SDLK_h:
|
||||
ask_key_pressed = 0x04;
|
||||
break;
|
||||
case SDLK_g:
|
||||
ask_key_pressed = 0x05;
|
||||
break;
|
||||
case SDLK_z:
|
||||
ask_key_pressed = 0x06;
|
||||
break;
|
||||
case SDLK_x:
|
||||
ask_key_pressed = 0x07;
|
||||
break;
|
||||
case SDLK_c:
|
||||
ask_key_pressed = 0x08;
|
||||
break;
|
||||
case SDLK_v:
|
||||
ask_key_pressed = 0x09;
|
||||
break;
|
||||
case SDLK_b:
|
||||
ask_key_pressed = 0x0B;
|
||||
break;
|
||||
case SDLK_q:
|
||||
ask_key_pressed = 0x0C;
|
||||
break;
|
||||
case SDLK_w:
|
||||
ask_key_pressed = 0x0D;
|
||||
break;
|
||||
case SDLK_e:
|
||||
ask_key_pressed = 0x0E;
|
||||
break;
|
||||
case SDLK_r:
|
||||
ask_key_pressed = 0x0F;
|
||||
break;
|
||||
case SDLK_y:
|
||||
ask_key_pressed = 0x10;
|
||||
break;
|
||||
case SDLK_t:
|
||||
ask_key_pressed = 0x11;
|
||||
break;
|
||||
case SDLK_1:
|
||||
ask_key_pressed = 0x12;
|
||||
break;
|
||||
case SDLK_2:
|
||||
ask_key_pressed = 0x13;
|
||||
break;
|
||||
case SDLK_3:
|
||||
ask_key_pressed = 0x14;
|
||||
break;
|
||||
case SDLK_4:
|
||||
ask_key_pressed = 0x15;
|
||||
break;
|
||||
case SDLK_6:
|
||||
ask_key_pressed = 0x16;
|
||||
break;
|
||||
case SDLK_5:
|
||||
ask_key_pressed = 0x17;
|
||||
break;
|
||||
case SDLK_EQUALS:
|
||||
ask_key_pressed = 0x18;
|
||||
break;
|
||||
case SDLK_9:
|
||||
ask_key_pressed = 0x19;
|
||||
break;
|
||||
case SDLK_7:
|
||||
ask_key_pressed = 0x1A;
|
||||
break;
|
||||
case SDLK_MINUS:
|
||||
ask_key_pressed = 0x1B;
|
||||
break;
|
||||
case SDLK_8:
|
||||
ask_key_pressed = 0x1C;
|
||||
break;
|
||||
case SDLK_0:
|
||||
ask_key_pressed = 0x1D;
|
||||
break;
|
||||
case SDLK_RIGHTBRACKET:
|
||||
ask_key_pressed = 0x1E;
|
||||
break;
|
||||
case SDLK_o:
|
||||
ask_key_pressed = 0x1F;
|
||||
break;
|
||||
case SDLK_u:
|
||||
ask_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_LEFTBRACKET:
|
||||
ask_key_pressed = 0x21;
|
||||
break;
|
||||
case SDLK_i:
|
||||
ask_key_pressed = 0x22;
|
||||
break;
|
||||
case SDLK_p:
|
||||
ask_key_pressed = 0x23;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
ask_key_pressed = 0x24;
|
||||
break;
|
||||
case SDLK_l:
|
||||
ask_key_pressed = 0x25;
|
||||
break;
|
||||
case SDLK_j:
|
||||
ask_key_pressed = 0x26;
|
||||
break;
|
||||
case SDLK_QUOTE:
|
||||
ask_key_pressed = 0x27;
|
||||
break;
|
||||
case SDLK_k:
|
||||
ask_key_pressed = 0x28;
|
||||
break;
|
||||
case SDLK_SEMICOLON:
|
||||
ask_key_pressed = 0x29;
|
||||
break;
|
||||
case SDLK_BACKSLASH:
|
||||
ask_key_pressed = 0x2A;
|
||||
break;
|
||||
case SDLK_COMMA:
|
||||
ask_key_pressed = 0x2B;
|
||||
break;
|
||||
case SDLK_SLASH:
|
||||
ask_key_pressed = 0x2C;
|
||||
break;
|
||||
case SDLK_n:
|
||||
ask_key_pressed = 0x2D;
|
||||
break;
|
||||
case SDLK_m:
|
||||
ask_key_pressed = 0x2E;
|
||||
break;
|
||||
case SDLK_PERIOD:
|
||||
ask_key_pressed = 0x2F;
|
||||
break;
|
||||
case SDLK_BACKQUOTE:
|
||||
ask_key_pressed = 0x32;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
ask_key_pressed = 0x35;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
ask_key_pressed = 0x3B;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
ask_key_pressed = 0x3C;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
ask_key_pressed = 0x3D;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
ask_key_pressed = 0x3E;
|
||||
break;
|
||||
case SDLK_KP_PERIOD:
|
||||
ask_key_pressed = 0x41;
|
||||
break;
|
||||
case SDLK_KP_MULTIPLY:
|
||||
ask_key_pressed = 0x43;
|
||||
break;
|
||||
case SDLK_KP_PLUS:
|
||||
ask_key_pressed = 0x45;
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
ask_key_pressed = 0x47;
|
||||
break;
|
||||
case SDLK_KP_DIVIDE:
|
||||
ask_key_pressed = 0x4B;
|
||||
break;
|
||||
case SDLK_KP_ENTER:
|
||||
ask_key_pressed = 0x4C;
|
||||
break;
|
||||
case SDLK_KP_MINUS:
|
||||
ask_key_pressed = 0x4E;
|
||||
break;
|
||||
case SDLK_KP_0:
|
||||
ask_key_pressed = 0x52;
|
||||
break;
|
||||
case SDLK_KP_1:
|
||||
ask_key_pressed = 0x53;
|
||||
break;
|
||||
case SDLK_KP_2:
|
||||
ask_key_pressed = 0x54;
|
||||
break;
|
||||
case SDLK_KP_3:
|
||||
ask_key_pressed = 0x55;
|
||||
break;
|
||||
case SDLK_KP_4:
|
||||
ask_key_pressed = 0x56;
|
||||
break;
|
||||
case SDLK_KP_5:
|
||||
ask_key_pressed = 0x57;
|
||||
break;
|
||||
case SDLK_KP_6:
|
||||
ask_key_pressed = 0x58;
|
||||
break;
|
||||
case SDLK_KP_7:
|
||||
ask_key_pressed = 0x59;
|
||||
break;
|
||||
case SDLK_KP_8:
|
||||
ask_key_pressed = 0x5B;
|
||||
break;
|
||||
case SDLK_KP_9:
|
||||
ask_key_pressed = 0x5C;
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
// ask_key_pressed = 0x33;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x40;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
// ask_key_pressed = 0x39;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_RALT:
|
||||
case SDLK_RCTRL: // Temp key for Control key
|
||||
// ask_key_pressed = 0x36;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x8;
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
// ask_key_pressed = 0x38;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x4;
|
||||
break;
|
||||
case SDLK_LALT:
|
||||
// ask_key_pressed = 0x3A;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x2;
|
||||
break;
|
||||
case SDLK_LCTRL: // Temp key for the Command/Apple key
|
||||
// ask_key_pressed = 0x37;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (adb_keybd_register0 & 0x8000) {
|
||||
adb_keybd_register0 &= 0x7FFF;
|
||||
adb_keybd_register0 &= (ask_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
} else if (adb_keybd_register0 & 0x80) {
|
||||
adb_keybd_register0 &= 0xFF7F;
|
||||
adb_keybd_register0 &= (ask_key_pressed);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
|
||||
// check if mod keys are being pressed
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register0 |= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
if (!(adb_keybd_register0 & 0x8000)) {
|
||||
adb_keybd_register0 |= 0x8000;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
} else if (adb_keybd_register0 & 0x80)
|
||||
adb_keybd_register0 |= 0x0080;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register2 &= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
confirm_ask_reg_2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((reg != 1)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if ((reg != 0) | (reg != 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
while (SDL_PollEvent(&adb_mouse_evt)) {
|
||||
if (adb_mouse_evt.motion.x) {
|
||||
this->adb_mouse_register0 &= 0x7F;
|
||||
|
||||
if (adb_mouse_evt.motion.xrel < 0) {
|
||||
if (adb_mouse_evt.motion.xrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F;
|
||||
} else if (adb_mouse_evt.motion.xrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F;
|
||||
} else {
|
||||
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adb_mouse_evt.motion.y) {
|
||||
this->adb_mouse_register0 &= 0x7F00;
|
||||
|
||||
if (adb_mouse_evt.motion.yrel < 0) {
|
||||
if (adb_mouse_evt.motion.yrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F00;
|
||||
} else if (adb_mouse_evt.motion.yrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F00;
|
||||
} else {
|
||||
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (adb_mouse_evt.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
this->adb_mouse_register0 &= 0x7FFF;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
this->adb_mouse_register0 |= 0x8000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (reg == 0) {
|
||||
output_data_stream[0] = (adb_mouse_register0 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register0 & 0xff);
|
||||
} else if (reg == 3) {
|
||||
output_data_stream[0] = (adb_mouse_register3 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register3 & 0xff);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint8_t ADB_Bus::get_input_byte(int offset) {
|
||||
return input_data_stream[offset];
|
||||
}
|
||||
|
||||
uint8_t ADB_Bus::get_output_byte(int offset) {
|
||||
return output_data_stream[offset];
|
||||
}
|
||||
|
||||
int ADB_Bus::get_input_len() {
|
||||
return input_stream_len;
|
||||
}
|
||||
|
||||
int ADB_Bus::get_output_len() {
|
||||
return output_stream_len;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ADB_H
|
||||
#define ADB_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if 0
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#endif
|
||||
|
||||
enum adb_default_values {
|
||||
adb_reserved0,
|
||||
adb_reserved1,
|
||||
adb_encoded,
|
||||
adb_relative,
|
||||
adb_absolute,
|
||||
adb_reserved5,
|
||||
adb_reserved6,
|
||||
adb_reserved7,
|
||||
adb_other8,
|
||||
adb_other9,
|
||||
adb_other10,
|
||||
adb_other11,
|
||||
adb_other12,
|
||||
adb_other13,
|
||||
adb_other14,
|
||||
adb_other15
|
||||
};
|
||||
|
||||
class ADB_Bus {
|
||||
public:
|
||||
ADB_Bus();
|
||||
~ADB_Bus() = default;
|
||||
|
||||
bool listen(int device, int reg);
|
||||
bool talk(int device, int reg, uint16_t value);
|
||||
bool bus_reset();
|
||||
bool set_addr(int dev_addr, int new_addr);
|
||||
bool flush(int dev_addr);
|
||||
|
||||
bool adb_keybd_listen(int reg);
|
||||
bool adb_mouse_listen(int reg);
|
||||
|
||||
uint8_t get_input_byte(int offset);
|
||||
uint8_t get_output_byte(int offset);
|
||||
|
||||
int get_input_len();
|
||||
int get_output_len();
|
||||
|
||||
private:
|
||||
int keyboard_access_no;
|
||||
int mouse_access_no;
|
||||
|
||||
// Keyboard Variables
|
||||
|
||||
uint16_t adb_keybd_register0;
|
||||
uint16_t adb_keybd_register2;
|
||||
uint16_t adb_keybd_register3;
|
||||
|
||||
//SDL_Event adb_keybd_evt;
|
||||
|
||||
uint8_t ask_key_pressed;
|
||||
uint8_t mod_key_pressed;
|
||||
|
||||
bool confirm_ask_reg_2;
|
||||
|
||||
// Mouse Variables
|
||||
//SDL_Event adb_mouse_evt;
|
||||
|
||||
uint16_t adb_mouse_register0;
|
||||
uint16_t adb_mouse_register3;
|
||||
|
||||
uint8_t input_data_stream[16]; // temp buffer
|
||||
int input_stream_len;
|
||||
uint8_t output_data_stream[16]; // temp buffer
|
||||
int output_stream_len;
|
||||
};
|
||||
|
||||
#endif /* ADB_H */
|
||||
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
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 Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <loguru.hpp>
|
||||
|
||||
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
|
||||
{
|
||||
this->start_cb = start_cb;
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
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) {
|
||||
case 0:
|
||||
LOG_F(9, "Executing DMA Command OUTPUT_MORE");
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
if (cmd_struct.cmd_bits & 0x3F) {
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
// 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->cmd_ptr += 16;
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(9, "Executing DMA Command OUTPUT_LAST");
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
if (cmd_struct.cmd_bits & 0x3F) {
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
// 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->cmd_ptr += 16;
|
||||
break;
|
||||
case 2:
|
||||
LOG_F(ERROR, "Unsupported DMA Command INPUT_MORE");
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(ERROR, "Unsupported DMA Command INPUT_LAST");
|
||||
break;
|
||||
case 4:
|
||||
LOG_F(ERROR, "Unsupported DMA Command STORE_QUAD");
|
||||
break;
|
||||
case 5:
|
||||
LOG_F(ERROR, "Unsupported DMA Command LOAD_QUAD");
|
||||
break;
|
||||
case 6:
|
||||
LOG_F(INFO, "Unsupported DMA Command NOP");
|
||||
break;
|
||||
case 7:
|
||||
LOG_F(INFO, "DMA Command: 7 (STOP)");
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported DMA command 0x%X", cmd_struct.cmd_key >> 4);
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
|
||||
return (cmd_struct.cmd_key >> 4);
|
||||
}
|
||||
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Unsupported non-DWORD read from DMA channel");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
res = 0; /* ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74) */
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
res = BYTESWAP_32(this->ch_stat);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint16_t mask, old_stat, new_stat;
|
||||
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Unsupported non-DWORD write to DMA channel");
|
||||
return;
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
old_stat = this->ch_stat;
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
|
||||
LOG_F(INFO, "New ChannelStatus value = 0x%X", new_stat);
|
||||
|
||||
if ((new_stat & CH_STAT_RUN) != (old_stat & CH_STAT_RUN)) {
|
||||
if (new_stat & CH_STAT_RUN) {
|
||||
new_stat |= CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->start();
|
||||
} else {
|
||||
new_stat &= ~CH_STAT_ACTIVE;
|
||||
new_stat &= ~CH_STAT_DEAD;
|
||||
this->ch_stat = new_stat;
|
||||
this->abort();
|
||||
}
|
||||
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
|
||||
new_stat |= CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->resume();
|
||||
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
|
||||
if (new_stat & CH_STAT_PAUSE) {
|
||||
new_stat &= ~CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->pause();
|
||||
}
|
||||
}
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
LOG_F(WARNING, "DMA flush not implemented!");
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
break; /* ingore writes to ChannelStatus */
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->cmd_ptr = value;
|
||||
LOG_F(INFO, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
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 DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
/* interpret DBDMA program until we get data or become idle */
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
/* dequeue data if any */
|
||||
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;
|
||||
*avail_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;
|
||||
this->queue_len = 0;
|
||||
}
|
||||
return DmaPullResult::MoreData; /* tell the caller there is more data */
|
||||
}
|
||||
|
||||
return DmaPullResult::NoMoreData; /* tell the caller there is no more data */
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active()
|
||||
{
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::start()
|
||||
{
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "Cannot start DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Starting DMA channel, stat = 0x%X", this->ch_stat);
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->start_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "Cannot resume DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Resuming DMA channel");
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
LOG_F(INFO, "Aborting DMA channel");
|
||||
}
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
this->stop_cb();
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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 Descriptor-based direct memory access emulation.
|
||||
|
||||
Official documentation can be found in the fifth chapter of the book
|
||||
"Macintosh Technology in the Common Hardware Reference Platform"
|
||||
by Apple Computer, Inc.
|
||||
*/
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
/** 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
|
||||
};
|
||||
|
||||
/** 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;
|
||||
} DMACmd;
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaOutChannel {
|
||||
public:
|
||||
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);
|
||||
|
||||
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);
|
||||
uint8_t interpret_cmd(void);
|
||||
|
||||
void start(void);
|
||||
void resume(void);
|
||||
void abort(void);
|
||||
void pause(void);
|
||||
|
||||
private:
|
||||
std::function<void(void)> start_cb; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb; // DMA channel stop callback
|
||||
|
||||
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,50 @@
|
||||
/*
|
||||
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() { return true; };
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel {
|
||||
public:
|
||||
virtual bool is_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 HW_COMPONENT_H
|
||||
#define HW_COMPONENT_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** types of different HW components */
|
||||
enum HWCompType {
|
||||
UNKNOWN = 0ULL, /* unknown component type */
|
||||
MEM_CTRL = 1ULL << 0, /* memory controller */
|
||||
NVRAM = 1ULL << 1, /* non-volatile random access memory */
|
||||
ROM = 1ULL << 2, /* read-only memory */
|
||||
RAM = 1ULL << 3, /* random access memory */
|
||||
MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */
|
||||
PCI_HOST = 1ULL << 5, /* PCI host */
|
||||
PCI_DEV = 1ULL << 6, /* PCI device */
|
||||
I2C_HOST = 1ULL << 8, /* I2C host */
|
||||
I2C_DEV = 1ULL << 9, /* I2C device */
|
||||
ADB_HOST = 1ULL << 12, /* ADB host */
|
||||
ADB_DEV = 1ULL << 13, /* ADB device */
|
||||
INT_CTRL = 1ULL << 16, /* interrupt controller */
|
||||
SCSI_BUS = 1ULL << 20, /* SCSI bus */
|
||||
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
|
||||
SCSI_DEV = 1ULL << 22, /* SCSI device */
|
||||
SND_SERVER = 1ULL << 31, /* host sound server */
|
||||
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
|
||||
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
|
||||
};
|
||||
|
||||
/** Base class for HW components. */
|
||||
class HWComponent {
|
||||
public:
|
||||
HWComponent() = default;
|
||||
virtual ~HWComponent() = default;
|
||||
|
||||
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) {
|
||||
return !!(this->supported_types & type);
|
||||
};
|
||||
|
||||
virtual void supports_types(uint64_t types) {
|
||||
this->supported_types = types;
|
||||
};
|
||||
|
||||
virtual int device_postinit() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
uint64_t supported_types = HWCompType::UNKNOWN;
|
||||
};
|
||||
|
||||
#endif /* HW_COMPONENT_H */
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 HW_INTERRUPT_H
|
||||
#define HW_INTERRUPT_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** Enumerator for various interrupt sources. */
|
||||
enum IntSrc : int {
|
||||
VIA_CUDA = 1,
|
||||
SCSI1 = 2,
|
||||
SWIM3 = 3,
|
||||
SCC = 4,
|
||||
ETHERNET = 5,
|
||||
NMI = 6,
|
||||
};
|
||||
|
||||
/** Base class for interrupt controllers. */
|
||||
class InterruptCtrl {
|
||||
public:
|
||||
InterruptCtrl() = default;
|
||||
virtual ~InterruptCtrl() = default;
|
||||
|
||||
// register interrupt sources for a device
|
||||
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
|
||||
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
|
||||
|
||||
// acknowledge HW interrupt
|
||||
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
};
|
||||
|
||||
#endif // HW_INTERRUPT_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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 I2C bus emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
/** Base class for I2C hosts */
|
||||
class I2CBus {
|
||||
public:
|
||||
I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
virtual ~I2CBus() = default;
|
||||
|
||||
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!"));
|
||||
}
|
||||
this->dev_list[dev_addr] = dev_obj;
|
||||
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
|
||||
};
|
||||
|
||||
virtual bool start_transaction(uint8_t dev_addr) {
|
||||
if (this->dev_list[dev_addr]) {
|
||||
this->dev_list[dev_addr]->start_transaction();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
|
||||
};
|
||||
|
||||
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->send_byte(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 */
|
||||
}
|
||||
return this->dev_list[dev_addr]->receive_byte(p_data);
|
||||
};
|
||||
|
||||
protected:
|
||||
I2CDevice* dev_list[128]; /* list of registered I2C devices */
|
||||
};
|
||||
|
||||
#endif /* I2C_H */
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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 MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/**
|
||||
@file Contains definitions for PowerMacintosh machine ID registers.
|
||||
|
||||
The machine ID register is a memory-based register containing hardcoded
|
||||
values the system software can read to identify machine/board it's running on.
|
||||
|
||||
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;
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~NubusMacID() = default;
|
||||
|
||||
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,
|
||||
ROM speed, I/O configuration etc.
|
||||
Because the meaning of these bits is poorly documented, the code below
|
||||
simply return a raw value obtained from real hardware.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) {
|
||||
this->id = id, this->name = "Machine-id";
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
};
|
||||
|
||||
#endif /* MACHINE_ID_H */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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 MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** Abstract class representing a simple, memory-mapped I/O device */
|
||||
class MMIODevice : public HWComponent {
|
||||
public:
|
||||
MMIODevice() = default;
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* MMIO_DEVICE_H */
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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 <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
this->name = "NVRAM";
|
||||
|
||||
supports_types(HWCompType::NVRAM);
|
||||
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
this->storage = new uint8_t[ram_size];
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
NVram::~NVram() {
|
||||
this->save();
|
||||
if (this->storage)
|
||||
delete this->storage;
|
||||
}
|
||||
|
||||
uint8_t NVram::read_byte(uint32_t offset) {
|
||||
return (this->storage[offset]);
|
||||
}
|
||||
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val) {
|
||||
this->storage[offset] = val;
|
||||
}
|
||||
|
||||
void NVram::init() {
|
||||
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)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file. \n");
|
||||
memset(this->storage, 0, sizeof(this->ram_size));
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char*)this->storage, this->ram_size);
|
||||
|
||||
f.close();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 NVRAM_H
|
||||
#define NVRAM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
|
||||
It implements a non-volatile random access storage whose content will be
|
||||
automatically saved to and restored from the dedicated file.
|
||||
*/
|
||||
|
||||
class NVram : public HWComponent {
|
||||
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);
|
||||
|
||||
private:
|
||||
std::string file_name; // file name for the backing file
|
||||
uint16_t ram_size; // NVRAM size
|
||||
uint8_t* storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
};
|
||||
|
||||
#endif /* NVRAM_H */
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Utilities for working with the Apple OpenFirmware NVRAM partition. */
|
||||
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void OfNvramUtils::init()
|
||||
{
|
||||
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
}
|
||||
|
||||
bool OfNvramUtils::validate()
|
||||
{
|
||||
int i;
|
||||
OfNvramHdr hdr;
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfNvramHdr); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
}
|
||||
|
||||
// validate partition signature and version
|
||||
if (BYTESWAP_16(hdr.sig) != OF_NVRAM_SIG || hdr.version != 5)
|
||||
return false;
|
||||
|
||||
this->size = hdr.num_pages * 256;
|
||||
|
||||
if (this->size != 0x800)
|
||||
return false;
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
for (i = 0; i < this->size; i++) {
|
||||
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
}
|
||||
|
||||
// verify partition checksum
|
||||
if (this->checksum_partition() ^ 0xFFFFU)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t OfNvramUtils::checksum_partition()
|
||||
{
|
||||
uint32_t acc = 0;
|
||||
|
||||
for (int i = 0; i < this->size; i += 2) {
|
||||
acc += READ_WORD_BE_A(&this->buf[i]);
|
||||
}
|
||||
|
||||
return acc + (acc >> 16);
|
||||
}
|
||||
|
||||
void OfNvramUtils::update_partition()
|
||||
{
|
||||
// set checksum in the header to zero
|
||||
this->buf[4] = 0;
|
||||
this->buf[5] = 0;
|
||||
|
||||
// calculate new checksum
|
||||
uint16_t checksum = this->checksum_partition();
|
||||
checksum = checksum ? ~checksum : 0xFFFFU;
|
||||
|
||||
// stuff it into the header
|
||||
WRITE_WORD_BE_A(&this->buf[4], checksum);
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static const string flag_names[8] = {
|
||||
"little-endian?",
|
||||
"real-mode?",
|
||||
"auto-boot?",
|
||||
"diag-switch?",
|
||||
"fcode-debug?",
|
||||
"oem-banner?",
|
||||
"oem-logo?",
|
||||
"use-nvramrc?"
|
||||
};
|
||||
|
||||
static const map<string, std::tuple<int, uint16_t>> of_vars = {
|
||||
// name, type, offset
|
||||
{"real-base", {OF_VAR_TYPE_INT, 0x10}},
|
||||
{"real-size", {OF_VAR_TYPE_INT, 0x14}},
|
||||
{"virt-base", {OF_VAR_TYPE_INT, 0x18}},
|
||||
{"virt-size", {OF_VAR_TYPE_INT, 0x1C}},
|
||||
{"load-base", {OF_VAR_TYPE_INT, 0x20}},
|
||||
{"pci-probe-list", {OF_VAR_TYPE_INT, 0x24}},
|
||||
{"screen-#columns", {OF_VAR_TYPE_INT, 0x28}},
|
||||
{"screen-#rows", {OF_VAR_TYPE_INT, 0x2C}},
|
||||
{"selftest-#megs", {OF_VAR_TYPE_INT, 0x30}},
|
||||
{"boot-device", {OF_VAR_TYPE_STR, 0x34}},
|
||||
{"boot-file", {OF_VAR_TYPE_STR, 0x38}},
|
||||
{"diag-device", {OF_VAR_TYPE_STR, 0x3C}},
|
||||
{"diag-file", {OF_VAR_TYPE_STR, 0x40}},
|
||||
{"input-device", {OF_VAR_TYPE_STR, 0x44}},
|
||||
{"output-device", {OF_VAR_TYPE_STR, 0x48}},
|
||||
{"oem-banner", {OF_VAR_TYPE_STR, 0x4C}},
|
||||
{"oem-logo", {OF_VAR_TYPE_STR, 0x50}},
|
||||
{"nvramrc", {OF_VAR_TYPE_STR, 0x54}},
|
||||
{"boot-command", {OF_VAR_TYPE_STR, 0x58}},
|
||||
};
|
||||
|
||||
void OfNvramUtils::printenv()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid OpenFirmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
cout << endl;
|
||||
|
||||
// print flags
|
||||
for (i = 0; i < 8; i++) {
|
||||
cout << setw(20) << left << flag_names[i] <<
|
||||
(((of_flags << i) & 0x80) ? "true" : "false") << endl;
|
||||
}
|
||||
|
||||
// print the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
cout << setw(20) << left << var.first;
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
cout << hex << READ_DWORD_BE_A(&this->buf[offset]) << endl;
|
||||
break;
|
||||
case OF_VAR_TYPE_STR:
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
if (str_len) {
|
||||
char value[32] = "";
|
||||
std::memcpy(value, (char *)&(this->buf[str_offset]), str_len);
|
||||
cout << value;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void OfNvramUtils::setenv(string var_name, string value)
|
||||
{
|
||||
int i, flag;
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid OpenFirmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the user tries to change a flag
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (var_name == flag_names[i]) {
|
||||
if (value == "true")
|
||||
flag = 1;
|
||||
else if (value == "false")
|
||||
flag = 0;
|
||||
else {
|
||||
cout << "Invalid property value: " << value << endl;
|
||||
return;
|
||||
}
|
||||
uint8_t flag_bit = 0x80U >> i;
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
if (flag)
|
||||
of_flags |= flag_bit;
|
||||
else
|
||||
of_flags &= ~flag_bit;
|
||||
|
||||
this->buf[12] = of_flags;
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// see if one of the stanard properties should be changed
|
||||
if (of_vars.find(var_name) == of_vars.end()) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto type = std::get<0>(of_vars.at(var_name));
|
||||
auto offset = std::get<1>(of_vars.at(var_name));
|
||||
|
||||
if (type == OF_VAR_TYPE_INT) {
|
||||
cout << "Changing of integer variables not supported yet" << endl;
|
||||
} else {
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
if (value.length() > str_len) {
|
||||
// we're going to allocate additional space
|
||||
// for the new string in the heap between here and top.
|
||||
// TODO: implement removal of dead strings and heap compaction
|
||||
|
||||
OfNvramHdr *hdr = (OfNvramHdr *)&this->buf[0];
|
||||
uint16_t here = READ_WORD_BE_A(&hdr->here);
|
||||
uint16_t top = READ_WORD_BE_A(&hdr->top);
|
||||
|
||||
// check if there is enough space in the heap for the new string
|
||||
if ((top - value.length()) < here) {
|
||||
cout << "No room in the heap!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// allocate required space by lowering top
|
||||
top -= value.length();
|
||||
i = 0;
|
||||
|
||||
// copy new string into NVRAM buffer char by char
|
||||
for(char& ch : value) {
|
||||
this->buf[top + i - OF_NVRAM_OFFSET] = ch;
|
||||
i++;
|
||||
}
|
||||
|
||||
// stuff new values into the variable state
|
||||
WRITE_WORD_BE_A(&this->buf[offset+0], top);
|
||||
WRITE_WORD_BE_A(&this->buf[offset+2], value.length());
|
||||
|
||||
// update partition header
|
||||
WRITE_WORD_BE_A(&hdr->top, top);
|
||||
|
||||
// update physical NVRAM
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
return;
|
||||
} else {
|
||||
// TODO: replace existing string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
/** @file Utilities for working with the Apple OpenFirmware NVRAM partition. */
|
||||
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
|
||||
// OF Variable types
|
||||
enum {
|
||||
OF_VAR_TYPE_INT = 1,
|
||||
OF_VAR_TYPE_STR = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint16_t sig; // partition signature (= 0x1275)
|
||||
uint8_t version; // header version
|
||||
uint8_t num_pages; // number of memory pages
|
||||
uint16_t checksum; // partition checksum
|
||||
uint16_t here; // offset to the next free byte (bottom-up)
|
||||
uint16_t top; // offset to the last free byte (top-down)
|
||||
} OfNvramHdr;
|
||||
|
||||
class OfNvramUtils {
|
||||
public:
|
||||
OfNvramUtils() = default;
|
||||
~OfNvramUtils() = default;
|
||||
|
||||
void init();
|
||||
void printenv();
|
||||
void setenv(std::string var_name, std::string value);
|
||||
|
||||
protected:
|
||||
bool validate();
|
||||
uint16_t checksum_partition();
|
||||
void update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
int size = 0;
|
||||
uint8_t buf[0x800];
|
||||
};
|
||||
|
||||
#endif // OF_NVRAM_H
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI Bridge emulation. */
|
||||
|
||||
#include "bandit.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
|
||||
{
|
||||
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Bandit control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x000000 --> I/O space
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
// base_addr + 0x1000000 --> pass-through memory space (not included below)
|
||||
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
|
||||
|
||||
// prepare the PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0001;
|
||||
this->class_rev = 0x06000003;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 0x16;
|
||||
|
||||
// make several PCI config space registers read-only
|
||||
this->pci_wr_cmd = [](uint16_t cmd) {}; // command register
|
||||
this->pci_wr_cache_lnsz = [](uint8_t val) {}; // cache line size register
|
||||
}
|
||||
|
||||
uint32_t Bandit::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
return BYTESWAP_32(this->addr_mask);
|
||||
default:
|
||||
LOG_F(WARNING, "%s: reading from unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Bandit::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
this->addr_mask = BYTESWAP_32(value);
|
||||
this->verbose_address_space();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: writing to unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Bandit::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
int fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t result, idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
LOG_F(WARNING, "%s: config cycle type 1 not supported yet", this->name.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(ERROR, "%s: invalid IDSEL=0x%X passed", this->name.c_str(), idsel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
result = this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->dev_map.count(idsel)) {
|
||||
result = this->dev_map[idsel]->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(),
|
||||
idsel);
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = this->config_addr;
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to read from unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bandit::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
LOG_F(WARNING, "%s: config cycle type 1 not supported yet", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(ERROR, "%s: invalid IDSEL=0x%X passed", this->name.c_str(), idsel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
this->dev_map[idsel]->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(),
|
||||
idsel);
|
||||
}
|
||||
} else {
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to write to unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Bandit::verbose_address_space()
|
||||
{
|
||||
uint32_t mask;
|
||||
int bit_pos;
|
||||
|
||||
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
|
||||
|
||||
// verbose coarse aka 256MB memory regions
|
||||
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
|
||||
if (this->addr_mask & mask) {
|
||||
uint32_t start_addr = bit_pos << 28;
|
||||
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x0FFFFFFFU);
|
||||
}
|
||||
}
|
||||
|
||||
// verbose fine aka 16MB memory regions
|
||||
for (mask = 0x1, bit_pos = 0; mask != 0x10000UL; mask <<= 1, bit_pos++) {
|
||||
if (this->addr_mask & mask) {
|
||||
uint32_t start_addr = (bit_pos << 24) + 0xF0000000UL;
|
||||
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x00FFFFFFU);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI bridge definitions.
|
||||
|
||||
The Bandit ASIC is a custom ARBus-to-PCI bridge used in the second
|
||||
generation of the Power Macintosh computer equipped with the PCI bus.
|
||||
*/
|
||||
|
||||
#ifndef BANDIT_PCI_H
|
||||
#define BANDIT_PCI_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#define BANDIT_ID_SEL (1 << 0) // Bandit's own IDSEL
|
||||
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
|
||||
#define BANDIT_CONFIG_SPACE 0x00800000 // Bandit Config Space bit
|
||||
|
||||
/** Bandit specific configuration registers. */
|
||||
enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
|
||||
|
||||
class Bandit : public PCIHost, public PCIDevice {
|
||||
public:
|
||||
Bandit(int bridge_num, std::string name);
|
||||
~Bandit() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::PCI_HOST || type == HWCompType::PCI_DEV);
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
// 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 verbose_address_space();
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
uint32_t config_addr;
|
||||
uint32_t addr_mask;
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/common/viacuda.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
PCIDevice::PCIDevice(std::string name)
|
||||
{
|
||||
this->pci_name = name;
|
||||
|
||||
this->pci_rd_stat = []() { return 0; };
|
||||
this->pci_rd_cmd = [this]() { return this->command; };
|
||||
this->pci_rd_bist = []() { return 0; };
|
||||
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
|
||||
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
|
||||
|
||||
this->pci_wr_stat = [](uint16_t val) {};
|
||||
this->pci_wr_cmd = [this](uint16_t cmd) { this->command = cmd; };
|
||||
this->pci_wr_bist = [](uint8_t val) {};
|
||||
this->pci_wr_lat_timer = [this](uint8_t val) { this->lat_timer = val; };
|
||||
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
|
||||
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
result = (this->device_id << 16) | (this->vendor_id);
|
||||
break;
|
||||
case PCI_CFG_STAT_CMD:
|
||||
result = (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
break;
|
||||
case PCI_CFG_CLASS_REV:
|
||||
result = this->class_rev;
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
result = (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
result = this->bars[(reg_offs - 0x10) >> 2];
|
||||
break;
|
||||
case PCI_CFG_SUBSYS_ID:
|
||||
result = (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
result = this->exp_rom_bar;
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
result = (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: attempt to read from reserved/unimplemented register %d",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size == 4) {
|
||||
return BYTESWAP_32(result);
|
||||
} else {
|
||||
return read_mem_rev(((uint8_t *)&result) + (reg_offs & 3), size);
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
if (size == 4) {
|
||||
data = BYTESWAP_32(value);
|
||||
} else {
|
||||
// get current register content as DWORD and update it partially
|
||||
data = BYTESWAP_32(this->pci_cfg_read(reg_offs, 4));
|
||||
write_mem_rev(((uint8_t *)&data) + (reg_offs & 3), value, size);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(data >> 16);
|
||||
this->pci_wr_cmd(data & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(data >> 24);
|
||||
this->pci_wr_lat_timer((data >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(data & 0xFF);
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
if (data == 0xFFFFFFFFUL) {
|
||||
this->do_bar_sizing((reg_offs - 0x10) >> 2);
|
||||
} else {
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, data);
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
if (data == 0xFFFFF800UL) {
|
||||
this->exp_rom_bar = this->exp_bar_cfg;
|
||||
} else {
|
||||
this->exp_rom_bar = (data & 0xFFFFF801UL);
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem(this->exp_rom_bar & 0xFFFFF800UL);
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unmapping of expansion ROM not implemented yet",
|
||||
this->pci_name.c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
this->irq_line = data >> 24;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: attempt to write to reserved/unimplemented register %d",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
}
|
||||
}
|
||||
|
||||
int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
int result = 0;
|
||||
|
||||
this->exp_bar_cfg = 0; // tell the world we got no ROM for now
|
||||
|
||||
try {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
throw std::runtime_error("could not open specified ROM dump image");
|
||||
}
|
||||
|
||||
// validate image file
|
||||
uint8_t buf[4] = { 0 };
|
||||
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 0x55 || buf[1] != 0xAA) {
|
||||
throw std::runtime_error("invalid expansion ROM signature");
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, std::ios::end);
|
||||
this->exp_rom_size = img_file.tellg();
|
||||
|
||||
// verify PCI struct offset
|
||||
uint32_t pci_struct_offset = 0;
|
||||
img_file.seekg(0x18, std::ios::beg);
|
||||
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
|
||||
|
||||
if (pci_struct_offset > this->exp_rom_size) {
|
||||
throw std::runtime_error("invalid PCI structure offset");
|
||||
}
|
||||
|
||||
// verify PCI struct signature
|
||||
img_file.seekg(pci_struct_offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 'P' || buf[1] != 'C' || buf[2] != 'I' || buf[3] != 'R') {
|
||||
throw std::runtime_error("unexpected PCI struct signature");
|
||||
}
|
||||
|
||||
// ROM image ok - go ahead and load it
|
||||
this->exp_rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[this->exp_rom_size]);
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)this->exp_rom_data.get(), this->exp_rom_size);
|
||||
|
||||
// align ROM image size on a 2KB boundary and initialize ROM config
|
||||
this->exp_rom_size = (this->exp_rom_size + 0x7FFU) & 0xFFFFF800UL;
|
||||
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
|
||||
}
|
||||
catch (const std::exception& exc) {
|
||||
LOG_F(ERROR, "PCIDevice: %s", exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
img_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIDevice::do_bar_sizing(int bar_num)
|
||||
{
|
||||
this->bars[bar_num] = this->bars_cfg[bar_num];
|
||||
}
|
||||
|
||||
void PCIDevice::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
if (bar_cfg & 1) {
|
||||
this->bars[bar_num] = (value & 0xFFFFFFFCUL) | 1;
|
||||
} else {
|
||||
if (bar_cfg & 6) {
|
||||
ABORT_F("Invalid or unsupported PCI space type: %d", (bar_cfg >> 1) & 3);
|
||||
}
|
||||
this->bars[bar_num] = (value & 0xFFFFFFF0UL) | (bar_cfg & 0xF);
|
||||
}
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIDevice::map_exp_rom_mem(uint32_t rom_addr)
|
||||
{
|
||||
if (!this->exp_rom_addr || this->exp_rom_addr != rom_addr) {
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, 0x10000, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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_DEVICE_H
|
||||
#define PCI_DEVICE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
|
||||
PCI_CFG_STAT_CMD = 0x04, // command/status register
|
||||
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
|
||||
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
|
||||
PCI_CFG_BAR0 = 0x10, // base address register 0
|
||||
PCI_CFG_BAR1 = 0x14, // base address register 1
|
||||
PCI_CFG_BAR2 = 0x18, // base address register 2
|
||||
PCI_CFG_BAR3 = 0x1C, // base address register 3
|
||||
PCI_CFG_BAR4 = 0x20, // base address register 4
|
||||
PCI_CFG_BAR5 = 0x24, // base address register 5
|
||||
PCI_CFG_CIS_PTR = 0x28, // Cardbus CIS Pointer
|
||||
PCI_CFG_SUBSYS_ID = 0x2C, // Subsysten IDs
|
||||
PCI_CFG_ROM_BAR = 0x30, // expansion ROM base address
|
||||
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt, Int_Pin and Int_Line registers
|
||||
};
|
||||
|
||||
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
||||
enum {
|
||||
PCI_VENDOR_ATI = 0x1002,
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
};
|
||||
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name);
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
};
|
||||
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
};
|
||||
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint16_t()> pci_rd_stat;
|
||||
std::function<void(uint16_t)> pci_wr_stat;
|
||||
std::function<uint16_t()> pci_rd_cmd;
|
||||
std::function<void(uint16_t)> pci_wr_cmd;
|
||||
std::function<uint8_t()> pci_rd_bist;
|
||||
std::function<void(uint8_t)> pci_wr_bist;
|
||||
std::function<uint8_t()> pci_rd_lat_timer;
|
||||
std::function<void(uint8_t)> pci_wr_lat_timer;
|
||||
std::function<uint8_t()> pci_rd_cache_lnsz;
|
||||
std::function<void(uint8_t)> pci_wr_cache_lnsz;
|
||||
|
||||
std::function<void(int)> pci_notify_bar_change;
|
||||
|
||||
int attach_exp_rom_image(const std::string img_path);
|
||||
|
||||
virtual void set_host(PCIHost* host_instance) {
|
||||
this->host_instance = host_instance;
|
||||
};
|
||||
|
||||
protected:
|
||||
void do_bar_sizing(int bar_num);
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void map_exp_rom_mem(uint32_t rom_addr);
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
|
||||
// PCI configuration space state
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint16_t status = 0;
|
||||
uint16_t command = 0;
|
||||
uint8_t hdr_type = 0; // header type
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint8_t max_lat = 0;
|
||||
uint8_t min_gnt = 0;
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
uint32_t bars[6] = { 0 }; // base address registers
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
||||
|
||||
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
||||
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
||||
uint32_t exp_rom_addr = 0; // expansion ROM base address
|
||||
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
|
||||
|
||||
std::unique_ptr<uint8_t[]> exp_rom_data;
|
||||
};
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_num, PCIDevice* dev_instance)
|
||||
{
|
||||
// return false if dev_num already registered
|
||||
if (this->dev_map.count(dev_num))
|
||||
return false;
|
||||
|
||||
this->dev_map[dev_num] = dev_instance;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
|
||||
if (dev_instance->supports_io_space()) {
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
// FIXME: add sanity checks!
|
||||
return mem_ctrl->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
PCIHost() {
|
||||
this->dev_map.clear();
|
||||
io_space_devs.clear();
|
||||
};
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIDevice*> dev_map;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
using namespace MeshScsi;
|
||||
|
||||
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,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 definitions. */
|
||||
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
|
||||
namespace MeshScsi {
|
||||
|
||||
// MESH registers offsets
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
}; // namespace MeshScsi
|
||||
|
||||
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
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 NCR53C94/Am53CF94 SCSI controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id)
|
||||
{
|
||||
this->chip_id = chip_id;
|
||||
this->my_bus_id = my_id;
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
reset_device();
|
||||
}
|
||||
|
||||
int Sc53C94::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sc53C94::reset_device()
|
||||
{
|
||||
// part-unique ID to be read using a magic sequence
|
||||
this->set_xfer_count = this->chip_id << 16;
|
||||
|
||||
this->clk_factor = 2;
|
||||
this->sel_timeout = 0;
|
||||
this->is_initiator = true;
|
||||
|
||||
// clear command FIFO
|
||||
this->cmd_fifo_pos = 0;
|
||||
|
||||
// clear data FIFO
|
||||
this->data_fifo_pos = 0;
|
||||
this->data_fifo[0] = 0;
|
||||
|
||||
this->seq_step = 0;
|
||||
|
||||
this->status = 0;
|
||||
}
|
||||
|
||||
uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t int_status;
|
||||
|
||||
switch (reg_offset) {
|
||||
case Read::Reg53C94::Command:
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
return this->status;
|
||||
case Read::Reg53C94::Int_Status:
|
||||
int_status = this->int_status;
|
||||
this->seq_step = 0;
|
||||
this->int_status = 0;
|
||||
this->update_irq();
|
||||
return int_status;
|
||||
case Read::Reg53C94::Seq_Step:
|
||||
return this->seq_step;
|
||||
case Read::Reg53C94::FIFO_Flags:
|
||||
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
case Read::Reg53C94::Config_3:
|
||||
return this->config3;
|
||||
case Read::Reg53C94::Xfer_Cnt_Hi:
|
||||
if (this->config2 & CFG2_ENF) {
|
||||
return (this->xfer_count >> 16) & 0xFFU;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "SC53C94: reading from register %d", reg_offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch (reg_offset) {
|
||||
case Write::Reg53C94::Command:
|
||||
update_command_reg(value);
|
||||
break;
|
||||
case Write::Reg53C94::FIFO:
|
||||
fifo_push(value);
|
||||
break;
|
||||
case Write::Reg53C94::Dest_Bus_ID:
|
||||
this->target_id = value & 7;
|
||||
break;
|
||||
case Write::Reg53C94::Sel_Timeout:
|
||||
this->sel_timeout = value;
|
||||
break;
|
||||
case Write::Reg53C94::Sync_Offset:
|
||||
this->sync_offset = value;
|
||||
break;
|
||||
case Write::Reg53C94::Clock_Factor:
|
||||
this->clk_factor = value;
|
||||
break;
|
||||
case Write::Reg53C94::Config_1:
|
||||
if ((value & 7) != this->my_bus_id) {
|
||||
ABORT_F("SC53C94: HBA bus ID mismatch!");
|
||||
}
|
||||
this->config1 = value;
|
||||
break;
|
||||
case Write::Reg53C94::Config_2:
|
||||
this->config2 = value;
|
||||
break;
|
||||
case Write::Reg53C94::Config_3:
|
||||
this->config3 = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "SC53C94: writing 0x%X to %d register", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
LOG_F(WARNING, "SC53C94: command register blocked after RESET!");
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Reset Device (chip), Reset Bus and DMA Stop commands execute
|
||||
// immediately while all others are placed into the command FIFO
|
||||
switch (cmd & 0x7F) {
|
||||
case CMD_RESET_DEVICE:
|
||||
case CMD_RESET_BUS:
|
||||
case CMD_DMA_STOP:
|
||||
this->cmd_fifo_pos = 0; // put them at the bottom of the command FIFO
|
||||
}
|
||||
|
||||
if (this->cmd_fifo_pos < 2) {
|
||||
// put new command into the command FIFO
|
||||
this->cmd_fifo[this->cmd_fifo_pos++] = cmd;
|
||||
if (this->cmd_fifo_pos == 1) {
|
||||
exec_command();
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "SC53C94: the top of the command FIFO overwritten!");
|
||||
this->status |= 0x40; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::exec_command()
|
||||
{
|
||||
uint8_t cmd = this->cmd_fifo[0] & 0x7F;
|
||||
bool is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
|
||||
|
||||
if (is_dma_cmd) {
|
||||
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
|
||||
this->xfer_count = this->set_xfer_count & 0xFFFFFFUL;
|
||||
} else { // standard mode: 16-bit
|
||||
this->xfer_count = this->set_xfer_count & 0xFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
// simple commands will be executed immediately
|
||||
// complex commands will be broken into multiple steps
|
||||
// and handled by the sequencer
|
||||
switch (cmd) {
|
||||
case CMD_NOP:
|
||||
this->on_reset = false; // unblock the command register
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_CLEAR_FIFO:
|
||||
this->data_fifo_pos = 0; // set the bottom of the FIFO to zero
|
||||
this->data_fifo[0] = 0;
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_RESET_DEVICE:
|
||||
reset_device();
|
||||
this->on_reset = true; // block the command register
|
||||
return;
|
||||
case CMD_RESET_BUS:
|
||||
LOG_F(INFO, "SC53C94: resetting SCSI bus...");
|
||||
// assert RST line
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
// release RST line after 25 us
|
||||
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(25),
|
||||
[this]() {
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & 0x40)) {
|
||||
LOG_F(INFO, "SC53C94: reset interrupt issued");
|
||||
this->int_status |= INTSTAT_SRST;
|
||||
}
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_SELECT_NO_ATN:
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::CMD_BEGIN, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
sequencer();
|
||||
LOG_F(INFO, "SC53C94: SELECT W/O ATN command started");
|
||||
break;
|
||||
case CMD_ENA_SEL_RESEL:
|
||||
LOG_F(INFO, "SC53C94: ENABLE SELECTION/RESELECTION command executed");
|
||||
exec_next_command();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "SC53C94: invalid/unimplemented command 0x%X", cmd);
|
||||
this->cmd_fifo_pos--; // remove invalid command from FIFO
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::exec_next_command()
|
||||
{
|
||||
if (this->cmd_fifo_pos) { // skip empty command FIFO
|
||||
this->cmd_fifo_pos--; // remove completed command
|
||||
if (this->cmd_fifo_pos) { // is there another command in the FIFO?
|
||||
this->cmd_fifo[0] = this->cmd_fifo[1]; // top -> bottom
|
||||
exec_command(); // execute it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::fifo_push(const uint8_t data)
|
||||
{
|
||||
if (this->data_fifo_pos < 16) {
|
||||
this->data_fifo[this->data_fifo_pos++] = data;
|
||||
} else {
|
||||
LOG_F(ERROR, "SC53C94: data FIFO overflow!");
|
||||
this->status |= 0x40; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
|
||||
void Sc53C94::sequencer()
|
||||
{
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->my_bus_id)) {
|
||||
LOG_F(ERROR, "SC53C94: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->my_bus_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
|
||||
this->next_state = this->cmd_steps->next_step;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "SC53C94: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->my_bus_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->is_initiator = true;
|
||||
this->bus_obj->begin_selection(this->my_bus_id, this->target_id,
|
||||
this->cur_cmd != CMD_SELECT_NO_ATN);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->my_bus_id, this->target_id)) {
|
||||
LOG_F(INFO, "SC53C94: selection completed");
|
||||
this->cmd_steps++;
|
||||
} else { // selection timeout
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
this->bus_obj->disconnect(this->my_bus_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SC53C94: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::update_irq()
|
||||
{
|
||||
uint8_t new_irq = !!(this->int_status != 0);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->status = (this->status & 0x7F) | (new_irq << 7);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
{
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
if (this->target_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SC53C94: ignore notification message, type: %d", msg_type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 NCR53C94/Am53CF94 SCSI controller definitions. */
|
||||
|
||||
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
|
||||
The corresponding functionality is provided by the 53CF94 compatible
|
||||
cell in the custom Curio IC (Am79C950).
|
||||
*/
|
||||
|
||||
#ifndef SC_53C94_H
|
||||
#define SC_53C94_H
|
||||
|
||||
#include "scsi.h"
|
||||
#include "devices/common/hwinterrupt.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Status = 4,
|
||||
Int_Status = 5,
|
||||
Seq_Step = 6,
|
||||
FIFO_Flags = 7,
|
||||
Config_1 = 8,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
|
||||
};
|
||||
};
|
||||
|
||||
/** 53C94 write registers */
|
||||
namespace Write {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Dest_Bus_ID = 4,
|
||||
Sel_Timeout = 5,
|
||||
Sync_Period = 6,
|
||||
Sync_Offset = 7,
|
||||
Config_1 = 8,
|
||||
Clock_Factor = 9,
|
||||
Test_Mode = 0xA,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Am53CF94 extension
|
||||
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
|
||||
Data_Align = 0xF
|
||||
};
|
||||
};
|
||||
|
||||
/** NCR53C94/Am53CF94 commands. */
|
||||
enum {
|
||||
CMD_NOP = 0,
|
||||
CMD_CLEAR_FIFO = 1,
|
||||
CMD_RESET_DEVICE = 2,
|
||||
CMD_RESET_BUS = 3,
|
||||
CMD_DMA_STOP = 4,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_ENA_SEL_RESEL = 0x44,
|
||||
};
|
||||
|
||||
/** Interrupt status register bits. */
|
||||
enum {
|
||||
INTSTAT_SRST = 0x80, // bus reset
|
||||
INTSTAT_ICMD = 0x40, // invalid command
|
||||
INTSTAT_DIS = 0x20, // disconnected
|
||||
INTSTAT_SR = 0x10, // service request
|
||||
INTSTAT_SO = 0x08, // successful operation
|
||||
INTSTAT_RESEL = 0x04, // reselected
|
||||
INTSTAT_SELA = 0x02, // selected as a target with attention
|
||||
INTSTAT_SEL = 0x01, // selected as a target without attention
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
|
||||
};
|
||||
|
||||
/** Sequencer states. */
|
||||
namespace SeqState {
|
||||
enum {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
CMD_BEGIN,
|
||||
CMD_COMPLETE,
|
||||
};
|
||||
};
|
||||
|
||||
/** Sequence descriptor for sequencer commands. */
|
||||
typedef struct {
|
||||
int next_step;
|
||||
int step_num;
|
||||
int status;
|
||||
} SeqDesc;
|
||||
|
||||
class Sc53C94 : public ScsiDevice {
|
||||
public:
|
||||
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
|
||||
~Sc53C94() = default;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
// 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
|
||||
protected:
|
||||
void reset_device();
|
||||
void update_command_reg(uint8_t cmd);
|
||||
void exec_command();
|
||||
void exec_next_command();
|
||||
void fifo_push(const uint8_t data);
|
||||
|
||||
void sequencer();
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
|
||||
void update_irq();
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
uint8_t my_bus_id;
|
||||
ScsiBus* bus_obj;
|
||||
uint32_t my_timer_id;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
uint8_t data_fifo[16];
|
||||
int cmd_fifo_pos;
|
||||
int data_fifo_pos;
|
||||
bool on_reset = false;
|
||||
uint32_t xfer_count;
|
||||
uint32_t set_xfer_count;
|
||||
uint8_t status;
|
||||
uint8_t target_id;
|
||||
uint8_t int_status;
|
||||
uint8_t seq_step;
|
||||
uint8_t sel_timeout;
|
||||
uint8_t sync_offset;
|
||||
uint8_t clk_factor;
|
||||
uint8_t config1;
|
||||
uint8_t config2;
|
||||
uint8_t config3;
|
||||
|
||||
// sequencer state
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
SeqDesc* cmd_steps;
|
||||
bool is_initiator;
|
||||
uint8_t cur_cmd;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus definitions. */
|
||||
|
||||
#ifndef SCSI_H
|
||||
#define SCSI_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** SCSI control signals.
|
||||
Bit positions follow the MESH controller convention for easier mapping.
|
||||
*/
|
||||
enum {
|
||||
SCSI_CTRL_IO = 1 << 0,
|
||||
SCSI_CTRL_CD = 1 << 1,
|
||||
SCSI_CTRL_MSG = 1 << 2,
|
||||
SCSI_CTRL_ATN = 1 << 3,
|
||||
SCSI_CTRL_ACK = 1 << 4,
|
||||
SCSI_CTRL_REQ = 1 << 5,
|
||||
SCSI_CTRL_SEL = 1 << 6,
|
||||
SCSI_CTRL_BSY = 1 << 7,
|
||||
SCSI_CTRL_RST = 1 << 8,
|
||||
};
|
||||
|
||||
enum ScsiPhase : int {
|
||||
BUS_FREE = 0,
|
||||
ARBITRATION,
|
||||
SELECTION,
|
||||
RESELECTION,
|
||||
RESET,
|
||||
};
|
||||
|
||||
enum ScsiMsg : int {
|
||||
CONFIRM_SEL = 1,
|
||||
BUS_PHASE_CHANGE,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
#define BUS_SETTLE_DELAY 400
|
||||
#define BUS_FREE_DELAY 800
|
||||
#define BUS_CLEAR_DELAY 800
|
||||
#define ARB_DELAY 2400
|
||||
#define SEL_ABORT_TIME 200000
|
||||
#define SEL_TIME_OUT 250000000
|
||||
|
||||
#define SCSI_MAX_DEVS 8
|
||||
|
||||
class ScsiDevice : public HWComponent {
|
||||
public:
|
||||
ScsiDevice() = default;
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiMsg msg_type, int param) = 0;
|
||||
|
||||
private:
|
||||
int scsi_id;
|
||||
};
|
||||
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
class ScsiBus : public HWComponent {
|
||||
public:
|
||||
ScsiBus();
|
||||
~ScsiBus() = default;
|
||||
|
||||
// low-level control/status
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
void assert_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_lines(int id);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
|
||||
// high-level control/status
|
||||
bool begin_arbitration(int id);
|
||||
bool end_arbitration(int id);
|
||||
bool begin_selection(int initiator_id, int target_id, bool atn);
|
||||
void confirm_selection(int target_id);
|
||||
bool end_selection(int initiator_id, int target_id);
|
||||
void disconnect(int dev_id);
|
||||
|
||||
protected:
|
||||
void change_bus_phase(int initiator_id);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
// SCSI devices registered with this bus
|
||||
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
|
||||
|
||||
// per-device state of the control lines
|
||||
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS];
|
||||
|
||||
uint16_t ctrl_lines;
|
||||
int cur_phase;
|
||||
int arb_winner_id;
|
||||
int initiator_id;
|
||||
int target_id;
|
||||
uint8_t data_lines;
|
||||
};
|
||||
|
||||
#endif // SCSI_H
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus emulation. */
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
ScsiBus::ScsiBus()
|
||||
{
|
||||
supports_types(HWCompType::SCSI_BUS);
|
||||
|
||||
for(int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
this->devices[i] = nullptr;
|
||||
this->dev_ctrl_lines[i] = 0;
|
||||
}
|
||||
|
||||
this->ctrl_lines = 0; // all control lines released
|
||||
this->data_lines = 0; // data lines released
|
||||
this->arb_winner_id = -1;
|
||||
this->initiator_id = -1;
|
||||
this->target_id = -1;
|
||||
}
|
||||
|
||||
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
{
|
||||
if (this->devices[id] != nullptr) {
|
||||
ABORT_F("ScsiBus: device with ID %d already registered", id);
|
||||
}
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
}
|
||||
|
||||
void ScsiBus::change_bus_phase(int initiator_id)
|
||||
{
|
||||
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
if (i == initiator_id)
|
||||
continue; // don't notify the initiator
|
||||
if (this->devices[i] != nullptr) {
|
||||
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
{
|
||||
uint16_t new_state = 0xFFFFU & mask;
|
||||
|
||||
this->dev_ctrl_lines[initiator_id] = new_state;
|
||||
|
||||
if (new_state == this->ctrl_lines) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->ctrl_lines = new_state;
|
||||
|
||||
if (new_state & SCSI_CTRL_RST) {
|
||||
this->cur_phase = ScsiPhase::RESET;
|
||||
change_bus_phase(initiator_id);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
|
||||
{
|
||||
uint16_t new_state = 0;
|
||||
|
||||
this->dev_ctrl_lines[id] &= ~mask;
|
||||
|
||||
// OR control lines of all devices together
|
||||
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
new_state |= this->dev_ctrl_lines[i];
|
||||
}
|
||||
|
||||
if (this->ctrl_lines & SCSI_CTRL_RST) {
|
||||
if (!(new_state & SCSI_CTRL_RST)) {
|
||||
this->ctrl_lines = new_state;
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
change_bus_phase(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::release_ctrl_lines(int id)
|
||||
{
|
||||
this->release_ctrl_line(id, 0xFFFFUL);
|
||||
}
|
||||
|
||||
bool ScsiBus::begin_arbitration(int initiator_id)
|
||||
{
|
||||
if (this->cur_phase == ScsiPhase::BUS_FREE) {
|
||||
this->data_lines |= 1 << initiator_id;
|
||||
this->cur_phase = ScsiPhase::ARBITRATION;
|
||||
change_bus_phase(initiator_id);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBus::end_arbitration(int initiator_id)
|
||||
{
|
||||
int highest_id = -1;
|
||||
|
||||
// find the highest ID bit on the data lines
|
||||
for (int id = 7; id >= 0; id--) {
|
||||
if (this->data_lines & (1 << id)) {
|
||||
highest_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (highest_id >= 0) {
|
||||
this->arb_winner_id = highest_id;
|
||||
}
|
||||
|
||||
return highest_id == initiator_id;
|
||||
}
|
||||
|
||||
bool ScsiBus::begin_selection(int initiator_id, int target_id, bool atn)
|
||||
{
|
||||
// perform bus integrity checks
|
||||
if (this->cur_phase != ScsiPhase::ARBITRATION || this->arb_winner_id != initiator_id)
|
||||
return false;
|
||||
|
||||
this->data_lines |= (1 << initiator_id) | (1 << target_id);
|
||||
|
||||
if (atn) {
|
||||
assert_ctrl_line(initiator_id, SCSI_CTRL_ATN);
|
||||
}
|
||||
|
||||
this->initiator_id = initiator_id;
|
||||
this->cur_phase = ScsiPhase::SELECTION;
|
||||
change_bus_phase(initiator_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiBus::confirm_selection(int target_id)
|
||||
{
|
||||
this->target_id = target_id;
|
||||
|
||||
// notify initiator about selection confirmation from target
|
||||
if (this->initiator_id >= 0) {
|
||||
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBus::end_selection(int initiator_id, int target_id)
|
||||
{
|
||||
// check for selection confirmation from target
|
||||
return this->target_id == target_id;
|
||||
}
|
||||
|
||||
void ScsiBus::disconnect(int dev_id)
|
||||
{
|
||||
this->release_ctrl_lines(dev_id);
|
||||
if (!(this->ctrl_lines & SCSI_CTRL_BSY) && !(this->ctrl_lines & SCSI_CTRL_SEL)) {
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
change_bus_phase(dev_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,711 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** High-level VIA-CUDA combo device emulation.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda() {
|
||||
this->name = "ViaCuda";
|
||||
|
||||
supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST);
|
||||
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
this->irq = 0; // IRQ is not active
|
||||
|
||||
// intialize counters/timers
|
||||
this->t1_counter = 0xFFFF;
|
||||
this->t1_active = false;
|
||||
this->t2_counter = 0xFFFF;
|
||||
this->t2_active = false;
|
||||
|
||||
// calculate VIA clock duration in ns
|
||||
this->via_clk_dur = 1.0f / VIA_CLOCK_HZ * NS_PER_SEC;
|
||||
|
||||
// PRAM is part of Cuda
|
||||
this->pram_obj = std::unique_ptr<NVram> (new NVram("pram.bin", 256));
|
||||
|
||||
// ADB bus is driven by Cuda
|
||||
this->adb_bus = std::unique_ptr<ADB_Bus> (new ADB_Bus());
|
||||
|
||||
this->cuda_init();
|
||||
|
||||
this->int_ctrl = nullptr;
|
||||
}
|
||||
|
||||
int ViaCuda::device_postinit()
|
||||
{
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::VIA_CUDA);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ViaCuda::cuda_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) {
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
return (this->via_regs[VIA_B]);
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
case VIA_T1CL:
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
|
||||
case VIA_T1CH:
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
|
||||
case VIA_T2CL:
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
|
||||
case VIA_T2CH:
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
case VIA_SR:
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
}
|
||||
|
||||
return (this->via_regs[reg & 0xF]);
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
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);
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
break;
|
||||
case VIA_ACR:
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
break;
|
||||
case VIA_IFR:
|
||||
// for each "1" in value clear the corresponding flags
|
||||
this->_via_ifr &= ~value;
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_IER:
|
||||
if (value & 0x80) {
|
||||
this->_via_ier |= value & 0x7F;
|
||||
} else {
|
||||
this->_via_ier &= ~value;
|
||||
}
|
||||
update_irq();
|
||||
print_enabled_ints();
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_regs[VIA_ACR] & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
this->t1_active = true;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_regs[VIA_ACR] & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
this->t2_active = true;
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last_time)
|
||||
{
|
||||
// calcualte current counter value based on elapsed time and timer frequency
|
||||
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
|
||||
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
|
||||
return last_val - diff;
|
||||
}
|
||||
|
||||
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_ier & (1 << i))
|
||||
LOG_F(INFO, "VIA %s interrupt enabled", via_int_src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ViaCuda::update_irq() {
|
||||
uint8_t new_irq = !!(this->_via_ifr & this->_via_ier & 0x7F);
|
||||
this->_via_ifr = (this->_via_ifr & 0x7F) | (new_irq << 7);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ViaCuda::ready() {
|
||||
return ((this->via_regs[VIA_DIRB] & 0x38) == 0x30);
|
||||
}
|
||||
|
||||
void ViaCuda::assert_sr_int() {
|
||||
this->sr_timer_on = false;
|
||||
this->_via_ifr |= VIA_IF_SR;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t1_int() {
|
||||
this->_via_ifr |= VIA_IF_T1;
|
||||
this->t1_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t2_int() {
|
||||
this->_via_ifr |= VIA_IF_T2;
|
||||
this->t2_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
{
|
||||
switch (line) {
|
||||
case ViaLine::CA1:
|
||||
this->_via_ifr |= VIA_IF_CA1;
|
||||
break;
|
||||
case ViaLine::CA2:
|
||||
this->_via_ifr |= VIA_IF_CA2;
|
||||
break;
|
||||
case ViaLine::CB1:
|
||||
this->_via_ifr |= VIA_IF_CB1;
|
||||
break;
|
||||
case ViaLine::CB2:
|
||||
this->_via_ifr |= VIA_IF_CB1;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Assertion of unknown VIA line requested!");
|
||||
}
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
if (this->sr_timer_on) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
}
|
||||
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
timeout_ns,
|
||||
[this]() { this->assert_sr_int(); });
|
||||
this->sr_timer_on = true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
//assert_sr_int();
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
|
||||
if (this->in_count < sizeof(this->in_buf)) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(71));
|
||||
//assert_sr_int();
|
||||
} 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 next byte after 88 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(88));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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_bus->listen(adb_dev, adb_reg)) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
for (int data_ptr = 0; data_ptr < adb_bus->get_output_len(); data_ptr++) {
|
||||
this->in_buf[(2 + data_ptr)] = adb_bus->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_bus->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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.
|
||||
|
||||
Versatile interface adapter (VIA) is an old I/O controller that can be found
|
||||
in nearly every Macintosh computer. In the 68k era, VIA was used to control
|
||||
various peripheral devices. In a Power Macintosh, its function is limited
|
||||
to the I/O interface with the Cuda MCU. I therefore decided to put VIA
|
||||
emulation code here.
|
||||
|
||||
Cuda MCU is a multipurpose IC built around a custom version of the Motorola
|
||||
MC68HC05 microcontroller. It provides several functions including:
|
||||
- Apple Desktop Bus (ADB) master
|
||||
- I2C bus master
|
||||
- Realtime clock (RTC)
|
||||
- parameter RAM (first generation of the Power Macintosh)
|
||||
- power management
|
||||
|
||||
MC68HC05 doesn't provide any dedicated hardware for serial communication
|
||||
protocols. All signals required for ADB and I2C will be generated by Cuda
|
||||
firmware using bit banging (https://en.wikipedia.org/wiki/Bit_banging).
|
||||
*/
|
||||
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#define VIA_CLOCK_HZ 783360
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
VIA_B = 0x00, /* input/output register B */
|
||||
VIA_A = 0x01, /* input/output register A */
|
||||
VIA_DIRB = 0x02, /* direction B */
|
||||
VIA_DIRA = 0x03, /* direction A */
|
||||
VIA_T1CL = 0x04, /* low-order timer 1 counter */
|
||||
VIA_T1CH = 0x05, /* high-order timer 1 counter */
|
||||
VIA_T1LL = 0x06, /* low-order timer 1 latches */
|
||||
VIA_T1LH = 0x07, /* high-order timer 1 latches */
|
||||
VIA_T2CL = 0x08, /* low-order timer 2 latches */
|
||||
VIA_T2CH = 0x09, /* high-order timer 2 counter */
|
||||
VIA_SR = 0x0A, /* shift register */
|
||||
VIA_ACR = 0x0B, /* auxiliary control register */
|
||||
VIA_PCR = 0x0C, /* periheral control register */
|
||||
VIA_IFR = 0x0D, /* interrupt flag register */
|
||||
VIA_IER = 0x0E, /* interrupt enable register */
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
};
|
||||
|
||||
/** VIA interrupt flags */
|
||||
enum {
|
||||
VIA_IF_CA2 = 1 << 0,
|
||||
VIA_IF_CA1 = 1 << 1,
|
||||
VIA_IF_SR = 1 << 2,
|
||||
VIA_IF_CB2 = 1 << 3,
|
||||
VIA_IF_CB1 = 1 << 4,
|
||||
VIA_IF_T2 = 1 << 5,
|
||||
VIA_IF_T1 = 1 << 6
|
||||
};
|
||||
|
||||
enum class ViaLine {
|
||||
CA1,
|
||||
CA2,
|
||||
CB1,
|
||||
CB2
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
CUDA_BYTEACK = 0x10, /* byte acknowledge: 0 - true, 1 - false */
|
||||
CUDA_TREQ = 0x08 /* Cuda requests transaction from host */
|
||||
};
|
||||
|
||||
/** Cuda packet types. */
|
||||
enum {
|
||||
CUDA_PKT_ADB = 0,
|
||||
CUDA_PKT_PSEUDO = 1,
|
||||
CUDA_PKT_ERROR = 2,
|
||||
CUDA_PKT_TICK = 3,
|
||||
CUDA_PKT_POWER = 4
|
||||
};
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
};
|
||||
|
||||
/** Cuda error codes. */
|
||||
enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
};
|
||||
|
||||
#define CUDA_IN_BUF_SIZE 256
|
||||
|
||||
/** 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
|
||||
|
||||
/** 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() = default;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
uint8_t read(int reg);
|
||||
void write(int reg, uint8_t value);
|
||||
|
||||
void assert_ctrl_line(ViaLine line);
|
||||
|
||||
private:
|
||||
// VIA virtual HW registers
|
||||
uint8_t via_regs[16];
|
||||
|
||||
float via_clk_dur; // one VIA clock duration = 1,27655 us
|
||||
|
||||
// VIA internal state
|
||||
uint32_t sr_timer_id = 0;
|
||||
bool sr_timer_on = false;
|
||||
|
||||
// timer 1 state
|
||||
bool t1_active;
|
||||
uint16_t t1_counter;
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
bool t2_active;
|
||||
uint16_t t2_counter;
|
||||
uint32_t t2_timer_id = 0;
|
||||
uint64_t t2_start_time = 0;
|
||||
|
||||
// VIA interrupt related stuff
|
||||
InterruptCtrl* int_ctrl;
|
||||
uint32_t irq_id;
|
||||
uint8_t _via_ifr;
|
||||
uint8_t _via_ier;
|
||||
uint8_t irq;
|
||||
|
||||
/* Cuda state. */
|
||||
uint8_t old_tip;
|
||||
uint8_t old_byteack;
|
||||
uint8_t treq;
|
||||
uint8_t in_buf[CUDA_IN_BUF_SIZE];
|
||||
int32_t in_count;
|
||||
uint8_t out_buf[16];
|
||||
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; // 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);
|
||||
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
std::unique_ptr<ADB_Bus> adb_bus;
|
||||
|
||||
// VIA methods
|
||||
void print_enabled_ints(); // print enabled VIA interrupts and their sources
|
||||
void init_ints();
|
||||
void update_irq();
|
||||
void assert_sr_int();
|
||||
void assert_t1_int();
|
||||
void assert_t2_int();
|
||||
void schedule_sr_int(uint64_t timeout_ns);
|
||||
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t& last_time);
|
||||
|
||||
// CUDA methods
|
||||
void cuda_init();
|
||||
bool ready();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
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);
|
||||
};
|
||||
|
||||
#endif /* VIACUDA_H */
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
using namespace MaceEnet;
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
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,82 @@
|
||||
/*
|
||||
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
|
||||
namespace MaceEnet {
|
||||
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 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?
|
||||
};
|
||||
|
||||
}; // namespace MaceEnet
|
||||
|
||||
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
|
||||
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
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 Support for reading and writing of various floppy images. */
|
||||
|
||||
#include "floppyimg.h"
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
static FlopImgType identify_image(std::ifstream& img_file)
|
||||
{
|
||||
// WOZ images identification strings
|
||||
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
static uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
|
||||
uint8_t buf[8] = { 0 };
|
||||
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// WOZ files are easily identified
|
||||
if (!std::memcmp(buf, WOZ1_SIG, sizeof(buf))) {
|
||||
return FlopImgType::WOZ1;
|
||||
} else if (!std::memcmp(buf, WOZ2_SIG, sizeof(buf))) {
|
||||
return FlopImgType::WOZ2;
|
||||
} else {
|
||||
for (int offset = 0; offset <=84; offset += 84) {
|
||||
// rewind to logical block 2
|
||||
img_file.seekg(2*BLOCK_SIZE + offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
// check for HFS/MFS signature at the start of the logical block 2
|
||||
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
|
||||
(buf[0] == 0xD2 && buf[1] == 0xD7)) {
|
||||
if (offset) {
|
||||
return FlopImgType::DC42;
|
||||
} else {
|
||||
return FlopImgType::RAW;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FlopImgType::UNKNOWN;
|
||||
}
|
||||
|
||||
static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
|
||||
{
|
||||
uint16_t drNmAlBlks = READ_WORD_BE_A(&mdb_data[18]);
|
||||
uint32_t drAlBlkSiz = READ_DWORD_BE_A(&mdb_data[20]);
|
||||
|
||||
// calculate size of the volume bitmap
|
||||
uint32_t vol_bmp_size = (((drNmAlBlks + 8) >> 3) + 512) & 0xFFFFFE00UL;
|
||||
|
||||
return (drNmAlBlks * drAlBlkSiz + vol_bmp_size + 3*BLOCK_SIZE);
|
||||
}
|
||||
|
||||
//======================= RAW IMAGE CONVERTER ============================
|
||||
RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
/** For raw images, we're going to ensure that the data fits into
|
||||
one of the supported floppy disk sizes as well as image size
|
||||
matches the size of the embedded HFS/MFS volume.
|
||||
Then we'll attempt to guess disk format based on image size.
|
||||
*/
|
||||
int RawFloppyImg::calc_phys_params()
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, img_file.end);
|
||||
this->img_size = img_file.tellg();
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
// verify image size
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too short!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->img_size > MFM_HD_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too big!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read Master Directory Block from logical block 2
|
||||
uint8_t buf[512] = { 0 };
|
||||
|
||||
img_file.seekg(2*BLOCK_SIZE, img_file.beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
img_file.close();
|
||||
|
||||
uint64_t vol_size = 0;
|
||||
|
||||
if (buf[0] == 0x42 && buf[1] == 0x44) {
|
||||
// check HFS volume size
|
||||
vol_size = get_hfs_vol_size(buf);
|
||||
} else if (buf[0] == 0xD2 && buf[1] == 0xD7) {
|
||||
// check MFS volume size
|
||||
} else {
|
||||
LOG_F(ERROR, "RawFloppyImg: unknown volume type!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vol_size > this->img_size) {
|
||||
LOG_F(INFO, "RawFloppyImg: volume size > image size!");
|
||||
LOG_F(INFO, "Volume size: %llu, Image size: %d", vol_size, this->img_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// raw images don't include anything than raw disk data
|
||||
this->data_size = this->img_size;
|
||||
|
||||
// guess disk format from image file size
|
||||
static struct {
|
||||
int capacity;
|
||||
int rec_method;
|
||||
int num_tracks;
|
||||
int num_sectors;
|
||||
int num_sides;
|
||||
int density;
|
||||
} size_to_params[] = {
|
||||
{ 409600, 0, 80, 800, 1, 0}, // 400K GCR
|
||||
{ 819200, 0, 80, 800, 2, 0}, // 800K GCR
|
||||
{ 737280, 1, 80, 1440, 2, 0}, // 720K MFM
|
||||
{1474560, 1, 80, 2880, 2, 1}, // 1440K MFM
|
||||
};
|
||||
|
||||
this->rec_method = -1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (this->img_size == size_to_params[i].capacity) {
|
||||
this->rec_method = size_to_params[i].rec_method;
|
||||
this->num_tracks = size_to_params[i].num_tracks;
|
||||
this->num_sectors = size_to_params[i].num_sectors;
|
||||
this->num_sides = size_to_params[i].num_sides;
|
||||
this->density = size_to_params[i].density;
|
||||
|
||||
// fake format byte for GCR disks
|
||||
if (!this->rec_method) {
|
||||
this->format_byte = (this->num_sides == 2) ? 0x22 : 0x2;
|
||||
} else {
|
||||
// For MFM disks this byte indicates sector size in blocks
|
||||
this->format_byte = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->rec_method == -1) {
|
||||
LOG_F(ERROR, "RawFloppyImg: could't determine disk format from image size!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Retrieve raw disk data. */
|
||||
int RawFloppyImg::get_raw_disk_data(char* buf)
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
img_file.seekg(0, img_file.beg);
|
||||
img_file.read(buf, this->data_size);
|
||||
img_file.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Convert low-level disk data to high-level image data. */
|
||||
int RawFloppyImg::export_data()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv;
|
||||
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "Could not open specified floppy image!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FlopImgType itype = identify_image(img_file);
|
||||
|
||||
img_file.close();
|
||||
|
||||
switch(itype) {
|
||||
case FlopImgType::RAW:
|
||||
LOG_F(INFO, "Raw floppy image");
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
break;
|
||||
case FlopImgType::DC42:
|
||||
LOG_F(INFO, "Disk Copy 4.2 image");
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image\n", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown/unsupported image format!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
delete fconv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fconv;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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 Definitions for working with various floppy images. */
|
||||
|
||||
#ifndef FLOPPY_IMG_H
|
||||
#define FLOPPY_IMG_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
#define BLOCK_SIZE 512 // size in bytes of a logical block
|
||||
|
||||
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
|
||||
|
||||
/** Floppy image types. */
|
||||
enum class FlopImgType {
|
||||
RAW, // raw image without metadata or low-level formatting
|
||||
DC42, // Disk Copy 4.2 image
|
||||
WOZ1, // WOZ v1 image with metadata and low-level data retained
|
||||
WOZ2, // WOZ v2 image with metadata and low-level data retained
|
||||
UNKNOWN, // invalid/unknown image format
|
||||
};
|
||||
|
||||
/** Interface for floppy image converters. */
|
||||
class FloppyImgConverter {
|
||||
public:
|
||||
FloppyImgConverter() = default;
|
||||
virtual ~FloppyImgConverter() = default;
|
||||
|
||||
virtual int calc_phys_params(void) = 0;
|
||||
virtual int get_raw_disk_data(char* buf) = 0;
|
||||
virtual int export_data(void) = 0;
|
||||
|
||||
int get_data_size() { return this->data_size; };
|
||||
int get_disk_rec_method() { return this->rec_method; };
|
||||
int get_number_of_tracks() { return this->num_tracks; };
|
||||
int get_number_of_sides() { return this->num_sides; };
|
||||
int get_sectors_per_side() { return this->num_sectors; };
|
||||
int get_rec_density() { return this->density; };
|
||||
uint8_t get_format_byte() { return this->format_byte; };
|
||||
|
||||
protected:
|
||||
std::string img_path;
|
||||
int img_size;
|
||||
int data_size; // disk data size without image format specific stuff
|
||||
|
||||
int rec_method;
|
||||
int num_tracks;
|
||||
int num_sides;
|
||||
int num_sectors;
|
||||
int density;
|
||||
uint8_t format_byte; // GCR format byte from sector header
|
||||
};
|
||||
|
||||
/** Converter for raw floppy images. */
|
||||
class RawFloppyImg : public FloppyImgConverter {
|
||||
public:
|
||||
RawFloppyImg(std::string& file_path);
|
||||
~RawFloppyImg() = default;
|
||||
|
||||
int calc_phys_params(void);
|
||||
int get_raw_disk_data(char* buf);
|
||||
int export_data(void);
|
||||
};
|
||||
|
||||
extern FloppyImgConverter* open_floppy_image(std::string& img_path);
|
||||
|
||||
#endif // FLOPPY_IMG_H
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Macintosh Superdrive emulation. */
|
||||
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
MacSuperDrive::MacSuperDrive()
|
||||
{
|
||||
this->name = "Superdrive";
|
||||
this->supported_types = HWCompType::FLOPPY_DRV;
|
||||
|
||||
this->media_kind = MediaKind::high_density;
|
||||
this->has_disk = 0; // drive is empty
|
||||
this->eject_latch = 0; // eject latch is off
|
||||
this->drive_mode = RecMethod::MFM; // assume MFM mode by default
|
||||
this->motor_stat = 0; // spindle motor is off
|
||||
this->cur_track = 0; // current head position
|
||||
this->is_ready = 0; // drive not ready
|
||||
}
|
||||
|
||||
void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
{
|
||||
uint8_t new_motor_stat;
|
||||
|
||||
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
|
||||
|
||||
switch(addr) {
|
||||
case CommandAddr::Step_Direction:
|
||||
this->step_dir = value ? -1 : 1;
|
||||
break;
|
||||
case CommandAddr::Do_Step:
|
||||
if (!value) {
|
||||
this->cur_track += this->step_dir;
|
||||
if (this->cur_track < 0)
|
||||
this->cur_track = 0;
|
||||
this->track_zero = this->cur_track == 0;
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Motor_On_Off:
|
||||
new_motor_stat = value ^ 1;
|
||||
if (this->motor_stat != new_motor_stat) {
|
||||
this->motor_stat = new_motor_stat;
|
||||
if (new_motor_stat) {
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
} else {
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Reset_Eject_Latch:
|
||||
if (value) {
|
||||
this->eject_latch = 0;
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Switch_Drive_Mode:
|
||||
if (this->drive_mode != (value ^ 1)) {
|
||||
switch_drive_mode(value ^ 1); // reverse logic
|
||||
this->is_ready = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented command, addr=0x%X", addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
{
|
||||
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
|
||||
|
||||
switch(addr) {
|
||||
case StatusAddr::Step_Status:
|
||||
return 1; // not sure what should be returned here
|
||||
case StatusAddr::Motor_Status:
|
||||
return this->motor_stat ^ 1; // reverse logic
|
||||
case StatusAddr::Eject_Latch:
|
||||
return this->eject_latch;
|
||||
case StatusAddr::Select_Head_0:
|
||||
this->cur_head = 0;
|
||||
return 1; // not sure what should be returned here
|
||||
case StatusAddr::MFM_Support:
|
||||
return 1; // Superdrive does support MFM encoding scheme
|
||||
case StatusAddr::Double_Sided:
|
||||
return 1; // yes, Superdrive is double sided
|
||||
case StatusAddr::Drive_Exists:
|
||||
return 0; // tell the world I'm here
|
||||
case StatusAddr::Disk_In_Drive:
|
||||
return this->has_disk ^ 1; // reverse logic (active low)!
|
||||
case StatusAddr::Write_Protect:
|
||||
return this->wr_protect ^ 1; // reverse logic
|
||||
case StatusAddr::Track_Zero:
|
||||
return this->track_zero ^ 1; // reverse logic
|
||||
case StatusAddr::Select_Head_1:
|
||||
this->cur_head = 1;
|
||||
return 1; // not sure what should be returned here
|
||||
case StatusAddr::Drive_Mode:
|
||||
return this->drive_mode;
|
||||
case StatusAddr::Drive_Ready:
|
||||
return this->is_ready ^ 1; // reverse logic
|
||||
case StatusAddr::Media_Kind:
|
||||
return this->media_kind ^ 1; // reverse logic!
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented status request, addr=0x%X", addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int MacSuperDrive::insert_disk(std::string& img_path, bool write_flag = 0)
|
||||
{
|
||||
if (this->has_disk) {
|
||||
LOG_F(ERROR, "Superdrive: drive is not empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FloppyImgConverter* img_conv = open_floppy_image(img_path);
|
||||
if (img_conv != nullptr) {
|
||||
this->img_conv = std::unique_ptr<FloppyImgConverter>(img_conv);
|
||||
set_disk_phys_params();
|
||||
|
||||
// allocate memory for raw disk data
|
||||
this->disk_data = std::unique_ptr<char[]>(new char[this->img_conv->get_data_size()]);
|
||||
|
||||
// swallow all raw disk data at once!
|
||||
this->img_conv->get_raw_disk_data(this->disk_data.get());
|
||||
|
||||
// disk is write-enabled by default
|
||||
this->wr_protect = write_flag;
|
||||
|
||||
// everything is set up, let's say we got a disk
|
||||
this->has_disk = 1;
|
||||
} else {
|
||||
this->has_disk = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MacSuperDrive::set_disk_phys_params()
|
||||
{
|
||||
this->rec_method = this->img_conv->get_disk_rec_method();
|
||||
this->num_tracks = this->img_conv->get_number_of_tracks();
|
||||
this->num_sides = this->img_conv->get_number_of_sides();
|
||||
this->media_kind = this->img_conv->get_rec_density();
|
||||
this->format_byte = this->img_conv->get_format_byte();
|
||||
|
||||
switch_drive_mode(this->rec_method);
|
||||
}
|
||||
|
||||
void MacSuperDrive::switch_drive_mode(int mode)
|
||||
{
|
||||
if (mode == RecMethod::GCR) {
|
||||
// Apple GCR speeds per group of 16 tracks
|
||||
static int gcr_rpm_per_group[5] = {394, 429, 472, 525, 590};
|
||||
|
||||
// initialize three lookup tables:
|
||||
// sectors per track
|
||||
// rpm per track
|
||||
// logical block number of the first sector in each track
|
||||
// for easier navigation
|
||||
for (int grp = 0, blk_num = 0; grp < 5; grp++) {
|
||||
for (int trk = 0; trk < 16; trk++) {
|
||||
this->sectors_per_track[grp * 16 + trk] = 12 - grp;
|
||||
this->rpm_per_track[grp * 16 + trk] = gcr_rpm_per_group[grp];
|
||||
this->track2lblk[grp * 16 + trk] = blk_num;
|
||||
blk_num += (12 - grp) * this->num_sides;
|
||||
}
|
||||
}
|
||||
|
||||
this->drive_mode = RecMethod::GCR;
|
||||
} else {
|
||||
int sectors_per_track = this->media_kind ? 18 : 9;
|
||||
|
||||
// MFM disks use constant number of sectors per track
|
||||
// and the fixed rotational speed of 300 RPM
|
||||
for (int trk = 0; trk < 80; trk++) {
|
||||
this->sectors_per_track[trk] = sectors_per_track;
|
||||
this->rpm_per_track[trk] = 300;
|
||||
this->track2lblk[trk] = trk * sectors_per_track * 2;
|
||||
}
|
||||
|
||||
this->drive_mode = RecMethod::MFM;
|
||||
}
|
||||
}
|
||||
|
||||
double MacSuperDrive::get_current_track_delay()
|
||||
{
|
||||
return (1.0f / (this->rpm_per_track[this->cur_track] / 60));
|
||||
}
|
||||
|
||||
double MacSuperDrive::get_sector_delay()
|
||||
{
|
||||
return this->get_current_track_delay() / this->sectors_per_track[this->cur_track];
|
||||
}
|
||||
|
||||
void MacSuperDrive::init_track_search(int pos)
|
||||
{
|
||||
if (pos == -1) {
|
||||
// pick random sector number
|
||||
this->cur_sector = this->sectors_per_track[this->cur_track] / 2;
|
||||
} else {
|
||||
this->cur_sector = pos;
|
||||
}
|
||||
}
|
||||
|
||||
SectorHdr MacSuperDrive::next_sector_header()
|
||||
{
|
||||
this->cur_sector++;
|
||||
if (this->cur_sector >= this->sectors_per_track[this->cur_track]) {
|
||||
this->cur_sector = 0;
|
||||
}
|
||||
|
||||
// MFM sector numbering is 1-based so we need to bump sector number
|
||||
int sector_num = this->cur_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
|
||||
|
||||
return SectorHdr {
|
||||
this->cur_track,
|
||||
this->cur_head,
|
||||
sector_num,
|
||||
this->format_byte
|
||||
};
|
||||
}
|
||||
|
||||
char* MacSuperDrive::get_sector_data_ptr(int sector_num)
|
||||
{
|
||||
return this->disk_data.get() +
|
||||
((this->track2lblk[this->cur_track] +
|
||||
(this->cur_head * this->sectors_per_track[this->cur_track]) +
|
||||
sector_num - 1) * 512
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Macintosh Superdrive definitions. */
|
||||
|
||||
#ifndef MAC_SUPERDRIVE_H
|
||||
#define MAC_SUPERDRIVE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace MacSuperdrive {
|
||||
|
||||
/** Apple Drive status request addresses. */
|
||||
enum StatusAddr : uint8_t {
|
||||
Step_Status = 1,
|
||||
Motor_Status = 2,
|
||||
Eject_Latch = 3,
|
||||
Select_Head_0 = 4,
|
||||
MFM_Support = 5,
|
||||
Double_Sided = 6,
|
||||
Drive_Exists = 7,
|
||||
Disk_In_Drive = 8,
|
||||
Write_Protect = 9,
|
||||
Track_Zero = 0xA,
|
||||
Select_Head_1 = 0xC,
|
||||
Drive_Mode = 0xD,
|
||||
Drive_Ready = 0xE,
|
||||
Media_Kind = 0xF
|
||||
};
|
||||
|
||||
/** Apple Drive command addresses. */
|
||||
enum CommandAddr : uint8_t {
|
||||
Step_Direction = 0,
|
||||
Do_Step = 1,
|
||||
Motor_On_Off = 2,
|
||||
Reset_Eject_Latch = 4,
|
||||
Switch_Drive_Mode = 5,
|
||||
};
|
||||
|
||||
/** Type of media currently in the drive. */
|
||||
enum MediaKind : uint8_t {
|
||||
low_density = 0,
|
||||
high_density = 1, // 1 or 2 MB disk
|
||||
};
|
||||
|
||||
/** Disk recording method. */
|
||||
enum RecMethod : int {
|
||||
GCR = 0,
|
||||
MFM = 1
|
||||
};
|
||||
|
||||
typedef struct SectorHdr {
|
||||
int track;
|
||||
int side;
|
||||
int sector;
|
||||
int format;
|
||||
} SectorHdr;
|
||||
|
||||
class MacSuperDrive : public HWComponent {
|
||||
public:
|
||||
MacSuperDrive();
|
||||
~MacSuperDrive() = default;
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
int insert_disk(std::string& img_path, bool write_flag);
|
||||
double get_current_track_delay();
|
||||
double get_sector_delay();
|
||||
void init_track_search(int pos);
|
||||
SectorHdr next_sector_header();
|
||||
char* get_sector_data_ptr(int sector_num);
|
||||
|
||||
protected:
|
||||
void set_disk_phys_params();
|
||||
void switch_drive_mode(int mode);
|
||||
|
||||
private:
|
||||
uint8_t has_disk;
|
||||
uint8_t eject_latch;
|
||||
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
|
||||
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
|
||||
uint8_t is_ready;
|
||||
uint8_t track_zero; // 1 - if head is at track zero
|
||||
int step_dir; // step direction -1/+1
|
||||
int cur_track; // track number the head is currently at
|
||||
int cur_head; // current head number: 1 - upper, 0 - lower
|
||||
int cur_sector; // current sector number
|
||||
|
||||
// physical parameters of the currently inserted disk
|
||||
uint8_t media_kind;
|
||||
uint8_t wr_protect;
|
||||
uint8_t format_byte;
|
||||
int rec_method;
|
||||
int num_tracks;
|
||||
int num_sides;
|
||||
int sectors_per_track[80];
|
||||
int rpm_per_track[80];
|
||||
int track2lblk[80]; // convert track number to first logical block number
|
||||
|
||||
std::unique_ptr<FloppyImgConverter> img_conv;
|
||||
|
||||
std::unique_ptr<char[]> disk_data;
|
||||
};
|
||||
|
||||
}; // namespace MacSuperdrive
|
||||
|
||||
#endif // MAC_SUPERDRIVE_H
|
||||
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Sander-Wozniak Machine 3 (SWIM3) emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace Swim3;
|
||||
|
||||
Swim3Ctrl::Swim3Ctrl()
|
||||
{
|
||||
this->name = "SWIM3";
|
||||
this->supported_types = HWCompType::FLOPPY_CTRL;
|
||||
|
||||
this->setup_reg = 0;
|
||||
this->mode_reg = 0;
|
||||
this->int_reg = 0;
|
||||
this->int_flags = 0;
|
||||
this->int_mask = 0;
|
||||
this->error = 0;
|
||||
this->xfer_cnt = 0;
|
||||
this->first_sec = 0xFF;
|
||||
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
gMachineObj->add_subdevice("Superdrive", this->int_drive.get());
|
||||
}
|
||||
|
||||
int Swim3Ctrl::device_postinit()
|
||||
{
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SWIM3);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status_addr, old_int_flags, old_error;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Error:
|
||||
old_error = this->error;
|
||||
this->error = 0;
|
||||
return old_error;
|
||||
case Swim3Reg::Phase:
|
||||
return this->phase_lines;
|
||||
case Swim3Reg::Setup:
|
||||
return this->setup_reg;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
return ((this->int_drive->status(status_addr) & 1) << 2);
|
||||
}
|
||||
return 4;
|
||||
case Swim3Reg::Interrupt_Flags:
|
||||
old_int_flags = this->int_flags;
|
||||
this->int_flags = 0; // read from this register clears all flags
|
||||
update_irq();
|
||||
return old_int_flags;
|
||||
case Swim3Reg::Current_Track:
|
||||
return this->cur_track;
|
||||
case Swim3Reg::Current_Sector:
|
||||
return this->cur_sector;
|
||||
case Swim3Reg::Gap_Format:
|
||||
return this->format;
|
||||
case Swim3Reg::First_Sector:
|
||||
return this->first_sec;
|
||||
case Swim3Reg::Sectors_To_Xfer:
|
||||
return this->xfer_cnt;
|
||||
case Swim3Reg::Interrupt_Mask:
|
||||
return this->int_mask;
|
||||
default:
|
||||
LOG_F(INFO, "SWIM3: reading from 0x%X register", reg_offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint8_t old_mode_reg;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Param_Data:
|
||||
this->pram = value;
|
||||
break;
|
||||
case Swim3Reg::Phase:
|
||||
this->phase_lines = value & 0xF;
|
||||
if (value & 8) {
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
this->int_drive->command(
|
||||
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
|
||||
(value >> 2) & 1
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Swim3Reg::Setup:
|
||||
this->setup_reg = value;
|
||||
break;
|
||||
case Swim3Reg::Status_Mode0:
|
||||
// ones in value clear the corresponding bits in the mode register
|
||||
if ((this->mode_reg & value) & (SWIM3_GO | SWIM3_GO_STEP)) {
|
||||
if (value & SWIM3_GO_STEP) {
|
||||
stop_stepping();
|
||||
} else {
|
||||
stop_disk_access();
|
||||
}
|
||||
}
|
||||
this->mode_reg &= ~value;
|
||||
break;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
// ones in value set the corresponding bits in the mode register
|
||||
if ((this->mode_reg ^ value) & (SWIM3_GO | SWIM3_GO_STEP)) {
|
||||
if (value & SWIM3_GO_STEP) {
|
||||
start_stepping();
|
||||
} else {
|
||||
start_disk_access();
|
||||
}
|
||||
}
|
||||
this->mode_reg |= value;
|
||||
break;
|
||||
case Swim3Reg::Step:
|
||||
this->step_count = value;
|
||||
break;
|
||||
case Swim3Reg::Gap_Format:
|
||||
this->gap_size = value;
|
||||
break;
|
||||
case Swim3Reg::First_Sector:
|
||||
this->first_sec = value;
|
||||
break;
|
||||
case Swim3Reg::Sectors_To_Xfer:
|
||||
this->xfer_cnt = value;
|
||||
break;
|
||||
case Swim3Reg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "SWIM3: writing 0x%X to register 0x%X", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Swim3Ctrl::update_irq()
|
||||
{
|
||||
if (this->mode_reg & SWIM3_INT_ENA) {
|
||||
uint8_t new_irq = !!(this->int_flags & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Swim3Ctrl::do_step()
|
||||
{
|
||||
if (this->mode_reg & SWIM3_GO_STEP && this->step_count) { // are we still stepping?
|
||||
// instruct the drive to perform single step in current direction
|
||||
this->int_drive->command(MacSuperdrive::CommandAddr::Do_Step, 0);
|
||||
if (--this->step_count == 0) {
|
||||
if (this->step_timer_id) {
|
||||
this->stop_stepping();
|
||||
}
|
||||
this->int_flags |= INT_STEP_DONE;
|
||||
update_irq();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Swim3Ctrl::start_stepping()
|
||||
{
|
||||
if (!this->step_count) {
|
||||
LOG_F(WARNING, "SWIM3: step_count is zero while go_step is active!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: another stepping action is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: stepping attempt while disk access is in progress!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3))
|
||||
!= MacSuperdrive::CommandAddr::Do_Step) {
|
||||
LOG_F(WARNING, "SWIM3: invalid command address on the phase lines!");
|
||||
return;
|
||||
}
|
||||
|
||||
this->mode_reg |= SWIM3_GO_STEP;
|
||||
|
||||
// step count > 1 requires periodic task
|
||||
if (this->step_count > 1) {
|
||||
this->step_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
USECS_TO_NSECS(80),
|
||||
[this]() {
|
||||
this->do_step();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// perform the first step immediately
|
||||
do_step();
|
||||
}
|
||||
|
||||
void Swim3Ctrl::stop_stepping()
|
||||
{
|
||||
// cancel stepping task
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
}
|
||||
this->step_timer_id = 0;
|
||||
this->step_count = 0; // not sure this one is required
|
||||
}
|
||||
|
||||
void Swim3Ctrl::start_disk_access()
|
||||
{
|
||||
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: another disk access is running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
|
||||
LOG_F(ERROR, "SWIM3: disk access attempt while stepping is in progress!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mode_reg & SWIM3_WR_MODE) {
|
||||
LOG_F(ERROR, "SWIM3: writing not implemented yet");
|
||||
return;
|
||||
}
|
||||
|
||||
this->mode_reg |= SWIM3_GO;
|
||||
LOG_F(9, "SWIM3: disk access started!");
|
||||
|
||||
if (this->first_sec == 0xFF) {
|
||||
// $FF means no sector to match ->
|
||||
// generate ID_read interrups as long as the GO bit is set
|
||||
this->int_drive->init_track_search(-1); // start at random sector
|
||||
} else {
|
||||
this->cur_sector = this->first_sec;
|
||||
}
|
||||
|
||||
// HACK: figure out from bits in int_mask register which kind of disk access is requested
|
||||
if (this->int_mask & INT_ID_READ) { // read address header
|
||||
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
// get next sector's address field
|
||||
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
|
||||
// set up the corresponding SWIM3 registers
|
||||
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
|
||||
this->format = addr.format;
|
||||
// generate ID_read interrupt
|
||||
this->int_flags |= INT_ID_READ;
|
||||
update_irq();
|
||||
}
|
||||
);
|
||||
} else { // otherwise, read sector data
|
||||
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
// transfer sector data over DMA
|
||||
this->dma_ch->push_data(this->int_drive->get_sector_data_ptr(this->cur_sector), 512);
|
||||
|
||||
// get next address field
|
||||
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
|
||||
// set up the corresponding SWIM3 registers
|
||||
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
|
||||
this->format = addr.format;
|
||||
|
||||
if (--this->xfer_cnt == 0) {
|
||||
this->stop_disk_access();
|
||||
// generate sector_done interrupt
|
||||
this->int_flags |= INT_SECT_DONE;
|
||||
update_irq();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Swim3Ctrl::stop_disk_access()
|
||||
{
|
||||
// cancel disk access timer
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
}
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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 Sander-Wozniak Machine 3 (SWIM3) definitions. */
|
||||
|
||||
#ifndef SWIM3_H
|
||||
#define SWIM3_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** SWIM3 registers offsets. */
|
||||
namespace Swim3 {
|
||||
|
||||
enum Swim3Reg : uint8_t {
|
||||
Data = 0,
|
||||
Timer = 1,
|
||||
Error = 2,
|
||||
Param_Data = 3,
|
||||
Phase = 4,
|
||||
Setup = 5,
|
||||
Status_Mode0 = 6, // read: Status, write: zeroes to the mode register
|
||||
Handshake_Mode1 = 7, // read: Handshake, write: ones to the mode register
|
||||
Interrupt_Flags = 8,
|
||||
Step = 9,
|
||||
Current_Track = 10,
|
||||
Current_Sector = 11,
|
||||
Gap_Format = 12,
|
||||
First_Sector = 13,
|
||||
Sectors_To_Xfer = 14,
|
||||
Interrupt_Mask = 15
|
||||
};
|
||||
|
||||
/** Mode register bits. */
|
||||
enum {
|
||||
SWIM3_INT_ENA = 0x01,
|
||||
SWIM3_GO = 0x08,
|
||||
SWIM3_WR_MODE = 0x10,
|
||||
SWIM3_GO_STEP = 0x80,
|
||||
};
|
||||
|
||||
/** Interrupt flags. */
|
||||
enum {
|
||||
INT_STEP_DONE = 0x02,
|
||||
INT_ID_READ = 0x04,
|
||||
INT_SECT_DONE = 0x08,
|
||||
};
|
||||
|
||||
class Swim3Ctrl : public HWComponent {
|
||||
public:
|
||||
Swim3Ctrl();
|
||||
~Swim3Ctrl() = default;
|
||||
|
||||
int device_postinit();
|
||||
|
||||
// SWIM3 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
|
||||
protected:
|
||||
void update_irq();
|
||||
void start_stepping();
|
||||
void do_step();
|
||||
void stop_stepping();
|
||||
void start_disk_access();
|
||||
void stop_disk_access();
|
||||
|
||||
private:
|
||||
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
|
||||
|
||||
DmaBidirChannel* dma_ch;
|
||||
|
||||
uint8_t setup_reg;
|
||||
uint8_t mode_reg;
|
||||
uint8_t error;
|
||||
uint8_t phase_lines;
|
||||
uint8_t int_reg;
|
||||
uint8_t int_flags; // interrupt flags
|
||||
uint8_t int_mask;
|
||||
uint8_t pram; // parameter RAM: two nibbles = {late_time, early_time}
|
||||
uint8_t step_count;
|
||||
uint8_t cur_track;
|
||||
uint8_t cur_sector;
|
||||
uint8_t format; // format byte from the last GCR/MFM address field
|
||||
uint8_t first_sec;
|
||||
uint8_t xfer_cnt;
|
||||
uint8_t gap_size;
|
||||
|
||||
int step_timer_id = 0;
|
||||
int access_timer_id = 0;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
};
|
||||
|
||||
}; // namespace Swim3
|
||||
|
||||
#endif // SWIM3_H
|
||||
@@ -1,173 +0,0 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
#include "macio.h"
|
||||
#include "viacuda.h"
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
|
||||
{
|
||||
this->viacuda = new ViaCuda();
|
||||
this->nvram = new NVram();
|
||||
}
|
||||
|
||||
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) {
|
||||
cout << this->name << " err: BAR0 block size determination not "
|
||||
<< "implemented yet" << endl;
|
||||
} else if (value & 1) {
|
||||
cout << this->name << " err: BAR0 I/O space not supported!" << endl;
|
||||
} else if (value & 0x06) {
|
||||
cout << this->name << " err: BAR0 64-bit I/O space not supported!"
|
||||
<< endl;
|
||||
} else {
|
||||
this->base_addr = value & 0xFFF80000;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
cout << this->name << " base address set to " << hex << this->base_addr
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
cout << this->name << ": reading from offset " << hex << offset << endl;
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch(sub_addr) {
|
||||
case 0:
|
||||
res = mio_ctrl_read(offset, size);
|
||||
break;
|
||||
case 8:
|
||||
cout << "DMA channel register space" << endl;
|
||||
break;
|
||||
case 0x14:
|
||||
cout << "AWACS-Screamer register space" << endl;
|
||||
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 {
|
||||
cout << "unmapped I/O space: " << hex << offset << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
cout << this->name << ": writing to offset " << hex << offset << endl;
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch(sub_addr) {
|
||||
case 0:
|
||||
mio_ctrl_write(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
cout << "DMA channel register space" << endl;
|
||||
break;
|
||||
case 0x14:
|
||||
cout << "AWACS-Screamer register space" << endl;
|
||||
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 {
|
||||
cout << "unmapped I/O space: " << hex << offset << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
switch(offset & 0xFF) {
|
||||
case 0x24:
|
||||
cout << "read from MIO:Int_Mask1 register" << endl;
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case 0x28:
|
||||
cout << "read from MIO:Int_Clear1 register" << endl;
|
||||
res = this->int_clear1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
res = 0xF0700000UL;
|
||||
break;
|
||||
case 0x38:
|
||||
cout << "read from MIO:Feat_Ctrl register" << endl;
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
cout << "unknown MIO register at " << hex << offset << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch(offset & 0xFF) {
|
||||
case 0x24:
|
||||
cout << "write " << hex << value << " to MIO:Int_Mask1 register" << endl;
|
||||
this->int_mask1 = value;
|
||||
break;
|
||||
case 0x28:
|
||||
cout << "write " << hex << value << " to MIO:Int_Clear1 register" << endl;
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x38:
|
||||
cout << "write " << hex << value << " to MIO:Feat_Ctrl register" << endl;
|
||||
this->feat_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
cout << "unknown MIO register at " << hex << offset << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,529 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AMIC::AMIC() : MMIODevice()
|
||||
{
|
||||
this->name = "Apple Memory-mapped I/O Controller";
|
||||
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// register I/O devices
|
||||
this->scsi = std::unique_ptr<Sc53C94> (new Sc53C94());
|
||||
gMachineObj->add_subdevice("Curio_SCSI0", this->scsi.get());
|
||||
|
||||
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());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
|
||||
// initialize sound HW
|
||||
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());
|
||||
|
||||
// initialize on-board video
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
this->def_vid = std::unique_ptr<PdmOnboardVideo> (new PdmOnboardVideo());
|
||||
|
||||
// intialize floppy disk HW
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
this->floppy_dma = std::unique_ptr<AmicFloppyDma> (new AmicFloppyDma());
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
gMachineObj->add_subdevice("SWIM3", this->swim3.get());
|
||||
}
|
||||
|
||||
int AMIC::device_postinit()
|
||||
{
|
||||
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!");
|
||||
}
|
||||
|
||||
// AMIC drives the VIA CA1 internally to generate 60.15 Hz interrupts
|
||||
this->pseudo_vbl_tid = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>((1.0f/60.15) * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
this->viacuda->assert_ctrl_line(ViaLine::CA1);
|
||||
});
|
||||
|
||||
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:
|
||||
return this->viacuda->read(offset >> 9);
|
||||
case 4: // SCC registers
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
case 0xA: // MACE registers
|
||||
return this->mace->read((offset >> 4) & 0x1F);
|
||||
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();
|
||||
}
|
||||
break;
|
||||
case 0x16: // SWIM3 registers
|
||||
case 0x17:
|
||||
return this->swim3->read((offset >> 9) & 0xF);
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::Ariel_Config:
|
||||
return this->def_vid->get_vdac_config();
|
||||
case AMICReg::VIA2_IFR:
|
||||
case AMICReg::VIA2_IFR_RBV:
|
||||
return this->via2_ifr;
|
||||
case AMICReg::VIA2_IER:
|
||||
case AMICReg::VIA2_IER_RBV:
|
||||
return this->via2_ier;
|
||||
case AMICReg::Video_Mode:
|
||||
return this->def_vid->get_video_mode();
|
||||
case AMICReg::Monitor_Id:
|
||||
return this->mon_id;
|
||||
case AMICReg::Int_Ctrl:
|
||||
return (this->int_ctrl & 0xC0) | (this->dev_irq_lines & 0x3F);
|
||||
case AMICReg::Diag_Reg:
|
||||
return 0xFFU; // this value allows the machine to boot normally
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
case AMICReg::DMA_Base_Addr_1:
|
||||
case AMICReg::DMA_Base_Addr_2:
|
||||
case AMICReg::DMA_Base_Addr_3:
|
||||
return (this->dma_base >> (3 - (offset & 3)) * 8) & 0xFF;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
return this->scsi_dma_cs;
|
||||
case AMICReg::Floppy_Addr_Ptr_0:
|
||||
case AMICReg::Floppy_Addr_Ptr_1:
|
||||
case AMICReg::Floppy_Addr_Ptr_2:
|
||||
case AMICReg::Floppy_Addr_Ptr_3:
|
||||
return (this->floppy_addr_ptr >> (3 - (offset & 3)) * 8) & 0xFF;
|
||||
case AMICReg::Floppy_DMA_Ctrl:
|
||||
return this->floppy_dma->read_stat();
|
||||
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_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
return;
|
||||
case 0xA: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0x1F, 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]
|
||||
);
|
||||
}
|
||||
return;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
SET_SIZE_BYTE(this->snd_buf_size, offset, value);
|
||||
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);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
case 0x16: // SWIM3 registers
|
||||
case 0x17:
|
||||
this->swim3->write((offset >> 9) & 0xF, value);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::VIA2_IER:
|
||||
if (value & 0x80) {
|
||||
this->via2_ier |= value & 0x7F;
|
||||
} else {
|
||||
this->via2_ier &= ~value;
|
||||
}
|
||||
break;
|
||||
case AMICReg::Ariel_Clut_Index:
|
||||
this->def_vid->set_clut_index(value);
|
||||
break;
|
||||
case AMICReg::Ariel_Clut_Color:
|
||||
this->def_vid->set_clut_color(value);
|
||||
break;
|
||||
case AMICReg::Ariel_Config:
|
||||
this->def_vid->set_vdac_config(value);
|
||||
break;
|
||||
case AMICReg::Video_Mode:
|
||||
this->def_vid->set_video_mode(value);
|
||||
break;
|
||||
case AMICReg::Pixel_Depth:
|
||||
this->def_vid->set_pixel_depth(value);
|
||||
break;
|
||||
case AMICReg::Monitor_Id: {
|
||||
// extract and convert pin directions (0 - input, 1 - output)
|
||||
uint8_t dirs = ~value & 7;
|
||||
if (!dirs && !(value & 8)) {
|
||||
LOG_F(INFO, "AMIC: Monitor sense lines tristated");
|
||||
}
|
||||
// propagate bit 3 to all pins configured as output
|
||||
// set levels of all intput pins to "1"
|
||||
uint8_t levels = (7 ^ dirs) | (((value & 8) ? 7 : 0) & dirs);
|
||||
// read monitor sense lines and store the result in the bits 4-6
|
||||
this->mon_id = (this->mon_id & 0xF) |
|
||||
(this->disp_id->read_monitor_sense(levels, dirs) << 4);
|
||||
}
|
||||
break;
|
||||
case AMICReg::Int_Ctrl:
|
||||
// reset CPU interrupt bit if requested
|
||||
if (value & AMIC_INT_CLR) {
|
||||
this->int_ctrl &= ~AMIC_INT_CLR;
|
||||
}
|
||||
// keep interrupt mode bit
|
||||
// and discard read-only IQR state bits
|
||||
this->int_ctrl |= value & AMIC_INT_MODE;
|
||||
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:
|
||||
SET_ADDR_BYTE(this->dma_base, offset, value);
|
||||
this->dma_base &= 0xFFFC0000UL;
|
||||
LOG_F(9, "AMIC: DMA base address set to 0x%X", this->dma_base);
|
||||
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::Floppy_Addr_Ptr_2:
|
||||
case AMICReg::Floppy_Addr_Ptr_3:
|
||||
SET_ADDR_BYTE(this->floppy_addr_ptr, offset, value);
|
||||
break;
|
||||
case AMICReg::Floppy_Byte_Cnt_Hi:
|
||||
case AMICReg::Floppy_Byte_Cnt_Lo:
|
||||
SET_SIZE_BYTE(this->floppy_byte_cnt, offset, value);
|
||||
break;
|
||||
case AMICReg::Floppy_DMA_Ctrl:
|
||||
if (value & 1) { // RST bit set?
|
||||
this->floppy_addr_ptr = this->dma_base + 0x15000;
|
||||
this->floppy_dma->reset(this->floppy_addr_ptr);
|
||||
}
|
||||
if (value & 2) { // RUN bit set?
|
||||
this->floppy_dma->reinit(this->floppy_addr_ptr, this->floppy_byte_cnt);
|
||||
}
|
||||
this->floppy_dma->write_ctrl(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);
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== Interrupt related stuff ==========================
|
||||
uint32_t AMIC::register_dev_int(IntSrc src_id) {
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1;
|
||||
case IntSrc::SCSI1:
|
||||
return 0x800;
|
||||
case IntSrc::SWIM3:
|
||||
return 0x2000;
|
||||
default:
|
||||
ABORT_F("AMIC: unknown interrupt source %d", src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AMIC::register_dma_int(IntSrc src_id) {
|
||||
ABORT_F("AMIC: register_dma_int() not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
// dispatch AMIC interrupts from various sources
|
||||
if (irq_id < 0x100) {
|
||||
this->ack_cpu_int(irq_id, irq_line_state);
|
||||
} else if (irq_id < 0x10000) {
|
||||
this->ack_via2_int(irq_id >> 8, irq_line_state);
|
||||
} else {
|
||||
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
if (irq_line_state) {
|
||||
this->via2_ifr |= irq_id;
|
||||
} else {
|
||||
this->via2_ifr &= ~irq_id;
|
||||
}
|
||||
uint8_t new_irq = !!(this->via2_ifr & this->via2_ier & 0x7F);
|
||||
this->via2_ifr = (this->via2_ifr & 0x7F) | (new_irq << 7);
|
||||
if (new_irq != this->via2_irq) {
|
||||
this->via2_irq = new_irq;
|
||||
this->ack_cpu_int(2, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
if (this->int_ctrl & AMIC_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_ctrl |= 0x80; // set CPU interrupt bit
|
||||
if (irq_line_state) {
|
||||
this->dev_irq_lines |= irq_id;
|
||||
} else {
|
||||
this->dev_irq_lines &= ~irq_id;
|
||||
}
|
||||
ppc_ext_int();
|
||||
} else {
|
||||
ABORT_F("AMIC: interrupt mode 0 not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
ABORT_F("AMIC: ack_dma_int() not implemented");
|
||||
}
|
||||
|
||||
// ============================ Sound DMA stuff ================================
|
||||
AmicSndOutDma::AmicSndOutDma()
|
||||
{
|
||||
this->dma_out_ctrl = 0;
|
||||
this->enabled = false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ============================ Floppy DMA stuff ===============================
|
||||
void AmicFloppyDma::reset(const uint32_t addr_ptr)
|
||||
{
|
||||
this->stat &= 0x48; // clear interrupt flag, RUN and RST bits
|
||||
this->addr_ptr = addr_ptr;
|
||||
this->byte_count = 0;
|
||||
}
|
||||
|
||||
void AmicFloppyDma::reinit(const uint32_t addr_ptr, const uint16_t byte_cnt)
|
||||
{
|
||||
this->addr_ptr = addr_ptr;
|
||||
this->byte_count = byte_cnt;
|
||||
}
|
||||
|
||||
void AmicFloppyDma::write_ctrl(uint8_t value)
|
||||
{
|
||||
// copy over DIR, IE and RUN bits
|
||||
this->stat = (this->stat & 0x81) | (value & 0x4A);
|
||||
|
||||
// clear interrupt flag if requested
|
||||
if (value & 0x80) {
|
||||
this->stat &= 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
int AmicFloppyDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
len = std::min((int)this->byte_count, len);
|
||||
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len);
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += len;
|
||||
this->byte_count -= len;
|
||||
if (!this->byte_count) {
|
||||
LOG_F(WARNING, "AMIC: DMA interrupts not implemented yet");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DmaPullResult AmicFloppyDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
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/hwinterrupt.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Interrupt related constants. */
|
||||
#define AMIC_INT_CLR 0x80 // clears CPU interrupt
|
||||
#define AMIC_INT_MODE 0x40 // interrupt mode: 0 - native, 1 - 68k-style
|
||||
|
||||
/** 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 mean 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;
|
||||
|
||||
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-specific floppy DMA implementation. */
|
||||
class AmicFloppyDma : public DmaBidirChannel {
|
||||
public:
|
||||
AmicFloppyDma() = default;
|
||||
~AmicFloppyDma() = default;
|
||||
|
||||
void reinit(const uint32_t addr_ptr, const uint16_t byte_cnt);
|
||||
void reset(const uint32_t addr_ptr);
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
|
||||
int push_data(const char* src_ptr, int len);
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
uint32_t addr_ptr;
|
||||
uint16_t byte_count;
|
||||
uint8_t stat;
|
||||
};
|
||||
|
||||
// macro for byte wise updating of AMIC DMA address registers
|
||||
#define SET_ADDR_BYTE(reg, offset, value) \
|
||||
mask = 0xFF000000UL >> (8 * ((offset) & 3)); \
|
||||
(reg) = ((reg) & ~mask) | (((value) & 0xFF) << (8 * (3 - ((offset) & 3))));
|
||||
|
||||
// macro for byte wise updating of AMIC DMA size registers
|
||||
#define SET_SIZE_BYTE(reg, offset, value) \
|
||||
mask = 0xFF00U >> (8 * ((offset) & 1)); \
|
||||
(reg) = ((reg) & ~mask) | (((value) & 0xFF) << (8 * (((offset) & 1) ^ 1)));
|
||||
|
||||
/* 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
|
||||
|
||||
// Video DAC (Ariel II) control registers
|
||||
Ariel_Clut_Index = 0x24000,
|
||||
Ariel_Clut_Color = 0x24001,
|
||||
Ariel_Config = 0x24002,
|
||||
|
||||
// VIA2 registers
|
||||
VIA2_IFR = 0x26003,
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_IER = 0x26013,
|
||||
VIA2_IFR_RBV = 0x27A03, // RBV-compatible mirror for the VIA2_IFR
|
||||
VIA2_IER_RBV = 0x27C13, // RBV-compatible mirror for the VIA2_IER
|
||||
|
||||
// Video control registers
|
||||
Video_Mode = 0x28000,
|
||||
Pixel_Depth = 0x28001,
|
||||
Monitor_Id = 0x28002,
|
||||
|
||||
// Interrupt registers
|
||||
Int_Ctrl = 0x2A000,
|
||||
|
||||
// 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,
|
||||
|
||||
// Floppy (SWIM3) DMA registers
|
||||
Floppy_Addr_Ptr_0 = 0x32060,
|
||||
Floppy_Addr_Ptr_1 = 0x32061,
|
||||
Floppy_Addr_Ptr_2 = 0x32062,
|
||||
Floppy_Addr_Ptr_3 = 0x32063,
|
||||
Floppy_Byte_Cnt_Hi = 0x32064,
|
||||
Floppy_Byte_Cnt_Lo = 0x32065,
|
||||
Floppy_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,
|
||||
};
|
||||
|
||||
/** Apple Memory-mapped I/O controller device. */
|
||||
class AMIC : public MMIODevice, public InterruptCtrl {
|
||||
public:
|
||||
AMIC();
|
||||
~AMIC() = default;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
/* 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);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
void ack_via2_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
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;
|
||||
|
||||
// floppy DMA state
|
||||
uint32_t floppy_addr_ptr;
|
||||
uint16_t floppy_byte_cnt;
|
||||
|
||||
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
|
||||
uint8_t int_ctrl = 0;
|
||||
uint8_t dev_irq_lines = 0; // state of the IRQ lines
|
||||
|
||||
// pseudo VIA2 state
|
||||
uint8_t via2_ier = 0;
|
||||
uint8_t via2_ifr = 0;
|
||||
uint8_t via2_irq = 0;
|
||||
|
||||
uint32_t pseudo_vbl_tid; // ID for the pseudo-VBL timer
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Sc53C94> 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;
|
||||
std::unique_ptr<AmicFloppyDma> floppy_dma;
|
||||
|
||||
// on-board video
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
std::unique_ptr<PdmOnboardVideo> def_vid;
|
||||
uint8_t mon_id;
|
||||
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3;
|
||||
};
|
||||
|
||||
#endif // AMIC_H
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/scsi/sc53c94.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = 0xFF000002;
|
||||
this->cache_ln_sz = 8;
|
||||
this->bars_cfg[0] = 0xFFFE0000UL; // declare 128Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// construct subdevices
|
||||
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
gMachineObj->add_subdevice("NVRAM", this->nvram.get());
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->awacs.get()),
|
||||
std::bind(&AwacsScreamer::dma_end, this->awacs.get())
|
||||
);
|
||||
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
|
||||
this->scsi_0 = std::unique_ptr<Sc53C94> (new Sc53C94());
|
||||
gMachineObj->add_subdevice("Curio_SCSI0", this->scsi_0.get());
|
||||
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
gMachineObj->add_subdevice("SWIM3", this->swim3.get());
|
||||
}
|
||||
|
||||
void GrandCentral::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "GC: deallocating I/O memory not implemented");
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x20000, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (offset & 0x10000) { // Device register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 0: // Curio SCSI
|
||||
return this->scsi_0->read((offset >> 4) & 0xF);
|
||||
case 1: // MACE
|
||||
return this->mace->read((offset >> 4) & 0x1F);
|
||||
case 2: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
}
|
||||
// fallthrough
|
||||
case 3: // ESCC MacRISC addressing
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 4: // AWACS
|
||||
return this->awacs->snd_ctrl_read(offset & 0xFF, size);
|
||||
case 5: // SWIM3
|
||||
return this->swim3->read((offset >> 4) & 0xF);
|
||||
case 6:
|
||||
case 7: // VIA-CUDA
|
||||
return this->viacuda->read((offset >> 9) & 0xF);
|
||||
case 0xA: // Board register 1 (IOBus dev #1)
|
||||
return BYTESWAP_32(0x100);
|
||||
case 0xF: // NVRAM Data (IOBus dev #6)
|
||||
return this->nvram->read_byte(
|
||||
(this->nvram_addr_hi << 5) + ((offset >> 4) & 0x1F));
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented GBUS device #%d", subdev_num - 9);
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 8:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented DMA register at 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else { // Interrupt related registers
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
return BYTESWAP_32(this->int_mask);
|
||||
case MIO_INT_LEVELS1:
|
||||
return BYTESWAP_32(this->int_levels);
|
||||
case MIO_INT_EVENTS1:
|
||||
return BYTESWAP_32(this->int_events);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_F(WARNING, "GC: reading from unmapped I/O memory 0x%X", this->base_addr + offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GrandCentral::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (offset & 0x10000) { // Device register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 0: // Curio SCSI
|
||||
this->scsi_0->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 1: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0x1F, value);
|
||||
break;
|
||||
case 2: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 3: // ESCC MacRISC addressing
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 4: // AWACS
|
||||
this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 5:
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 6:
|
||||
case 7: // VIA-CUDA
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 0xD: // NVRAM High Address (IOBus dev #4)
|
||||
switch (size) {
|
||||
case 4:
|
||||
this->nvram_addr_hi = BYTESWAP_32(value);
|
||||
break;
|
||||
case 2:
|
||||
this->nvram_addr_hi = BYTESWAP_16(value);
|
||||
break;
|
||||
default:
|
||||
this->nvram_addr_hi = value;
|
||||
}
|
||||
break;
|
||||
case 0xF: // NVRAM Data (IOBus dev #6)
|
||||
this->nvram->write_byte(
|
||||
(this->nvram_addr_hi << 5) + ((offset >> 4) & 0x1F), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented GBUS device #%d", subdev_num - 9);
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented DMA register at 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else { // Interrupt related registers
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask = BYTESWAP_32(value);
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events = 0;
|
||||
} else {
|
||||
this->int_events &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: writing to unmapped I/O memory 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 18;
|
||||
case IntSrc::SCSI1:
|
||||
return 1 << 12;
|
||||
case IntSrc::SWIM3:
|
||||
return 1 << 19;
|
||||
default:
|
||||
ABORT_F("GC: unknown interrupt source %d", src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
ABORT_F("GC: register_dma_int() not implemened");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_events |= irq_id; // signal IRQ line change
|
||||
this->int_events &= this->int_mask;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
} else {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
// signal CPU interrupt
|
||||
if (this->int_events) {
|
||||
ppc_ext_int();
|
||||
}
|
||||
} else {
|
||||
ABORT_F("GC: native interrupt mode not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
ABORT_F("GC: ack_dma_int() not implemened");
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/hwcomponent.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.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"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0010;
|
||||
this->class_rev = 0xFF000001;
|
||||
this->cache_ln_sz = 8;
|
||||
this->lat_timer = 0x40;
|
||||
this->bars_cfg[0] = 0xFFF80000UL; // declare 512Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
gMachineObj->add_subdevice("NVRAM", this->nvram.get());
|
||||
|
||||
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());
|
||||
|
||||
// intialize floppy disk HW
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
gMachineObj->add_subdevice("SWIM3", this->swim3.get());
|
||||
}
|
||||
|
||||
void HeathrowIC::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "Heathrow: deallocating I/O memory not implemented");
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
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 0x10:
|
||||
res = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
}
|
||||
// fallthrough
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
return this->swim3->read((offset >> 4 )& 0xF);
|
||||
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);
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
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 & 0xFC) {
|
||||
case MIO_INT_EVENTS2:
|
||||
res = this->int_events2;
|
||||
break;
|
||||
case MIO_INT_MASK2:
|
||||
res = this->int_mask2;
|
||||
break;
|
||||
case MIO_INT_LEVELS2:
|
||||
res = this->int_levels2;
|
||||
break;
|
||||
case MIO_INT_EVENTS1:
|
||||
res = this->int_events1;
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case MIO_INT_LEVELS1:
|
||||
res = this->int_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 = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return BYTESWAP_32(res);
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
case MIO_INT_MASK2:
|
||||
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
|
||||
break;
|
||||
case MIO_INT_CLEAR2:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events2 = 0;
|
||||
} else {
|
||||
this->int_events2 &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask1 = BYTESWAP_32(value);
|
||||
// copy IntMode bit to InterruptMask2 register
|
||||
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events1 = 0;
|
||||
} else {
|
||||
this->int_events1 &= BYTESWAP_32(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(9, "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");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 7;
|
||||
case IntSrc::SCSI1:
|
||||
return 1 << 1;
|
||||
case IntSrc::SWIM3:
|
||||
return 1 << 8;
|
||||
default:
|
||||
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
if (irq_id > 0x200000) {
|
||||
irq_id >>= 21;
|
||||
this->int_events2 |= irq_id; // signal IRQ line change
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels2 |= irq_id;
|
||||
} else {
|
||||
this->int_levels2 &= ~irq_id;
|
||||
}
|
||||
} else {
|
||||
irq_id <<= 11;
|
||||
this->int_events1 |= irq_id; // signal IRQ line change
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels1 |= irq_id;
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
// signal CPU interrupt
|
||||
if (this->int_events1 || this->int_events2) {
|
||||
ppc_ext_int();
|
||||
}
|
||||
} else {
|
||||
ABORT_F("Heathrow: native interrupt mode not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** MacIO device family emulation
|
||||
|
||||
Mac I/O (MIO) is a family of ASICs to bring support for Apple legacy
|
||||
I/O hardware to the PCI-based Power Macintosh. That legacy hardware has
|
||||
existed long before Power Macintosh was introduced. It includes:
|
||||
- versatile interface adapter (VIA)
|
||||
- Sander-Woz integrated machine (SWIM) that is a floppy disk controller
|
||||
- CUDA MCU for ADB, parameter RAM, realtime clock and power management support
|
||||
- serial communication controller (SCC)
|
||||
- Macintosh Enhanced SCSI Hardware (MESH)
|
||||
|
||||
In the 68k Macintosh era, all this hardware was implemented using several
|
||||
custom chips. In a PCI-compatible Power Macintosh, the above devices are part
|
||||
of the MIO chip itself. MIO's functional blocks implementing virtual devices
|
||||
are called "cells", i.e. "VIA cell", "SWIM cell" etc.
|
||||
|
||||
MIO itself is PCI compliant while the legacy hardware it emulates isn't.
|
||||
MIO occupies 512Kb of the PCI memory space divided into registers space and
|
||||
DMA space. Access to emulated legacy devices is accomplished by reading from/
|
||||
writing to MIO's PCI address space at predefined offsets.
|
||||
|
||||
MIO includes a DMA controller that offers 15 DMA channels implementing
|
||||
Apple's own DMA protocol called descriptor-based DMA (DBDMA).
|
||||
|
||||
Official documentation (that is somewhat incomplete and erroneous) can be
|
||||
found in the second chapter of the book "Macintosh Technology in the Common
|
||||
Hardware Reference Platform" by Apple Computer, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include <devices/common/dbdma.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/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Interrupt related constants. */
|
||||
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
|
||||
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
|
||||
|
||||
/** Offsets to common MacIO interrupt registers. */
|
||||
enum {
|
||||
MIO_INT_EVENTS2 = 0x10,
|
||||
MIO_INT_MASK2 = 0x14,
|
||||
MIO_INT_CLEAR2 = 0x18,
|
||||
MIO_INT_LEVELS2 = 0x1C,
|
||||
MIO_INT_EVENTS1 = 0x20,
|
||||
MIO_INT_MASK1 = 0x24,
|
||||
MIO_INT_CLEAR1 = 0x28,
|
||||
MIO_INT_LEVELS1 = 0x2C
|
||||
};
|
||||
|
||||
class GrandCentral : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
GrandCentral();
|
||||
~GrandCentral() = default;
|
||||
|
||||
// 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);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
uint32_t int_levels = 0;
|
||||
uint32_t int_events = 0;
|
||||
|
||||
uint32_t nvram_addr_hi;
|
||||
|
||||
// device cells
|
||||
std::unique_ptr<MaceController> mace;
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
|
||||
std::unique_ptr<NVram> nvram; // NVRAM module
|
||||
std::unique_ptr<EsccController> escc; // ESCC serial controller
|
||||
std::unique_ptr<Sc53C94> scsi_0; // external SCSI
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
|
||||
Heathrow is a MIO-compliant ASIC used in the Gossamer architecture. It's
|
||||
hard-wired to PCI device number 16. Its I/O memory (512Kb) will be configured
|
||||
by the Macintosh firmware to live at 0xF3000000.
|
||||
|
||||
Emulated subdevices and their offsets within Heathrow I/O space:
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
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
|
||||
davbus(sound) register space: 0x00014000, DMA space: 0x00008800, 0x00008900
|
||||
SWIM3(floppy) register space: 0x00015000, DMA space: 0x00008100
|
||||
NVRAM register space: 0x00060000, size: 0x00020000
|
||||
IDE register space: 0x00020000, DMA space: 0x00008b00
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
// 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);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
void dma_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
uint32_t int_events2 = 0;
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
uint32_t int_events1 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t macio_id = 0xF0700008UL;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
/* device cells */
|
||||
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
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "mmiodevice.h"
|
||||
|
||||
/**
|
||||
@file Contains definitions for PowerMacintosh machine ID registers.
|
||||
|
||||
The machine ID register is a memory-based register containing hardcoded
|
||||
values the system software can read to identify machine/board it's running on.
|
||||
|
||||
Register location and value meaning are board-dependent.
|
||||
*/
|
||||
|
||||
/**
|
||||
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,
|
||||
ROM speed, I/O configuration etc.
|
||||
Because the meaning of these bits is poorly documented, the code below
|
||||
simply return a raw value obtained from real hardware.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) { this->id = id, this->name = "Machine-id"; };
|
||||
~GossamerID() = default;
|
||||
|
||||
uint32_t read(uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0); };
|
||||
|
||||
void write(uint32_t offset, uint32_t value, int size) {}; /* not writable */
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
};
|
||||
|
||||
#endif /* MACHINE_ID_H */
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
/** MacIO device family emulation
|
||||
|
||||
Mac I/O (MIO) is a family of ASICs to bring support for Apple legacy
|
||||
I/O hardware to the PCI-based Power Macintosh. That legacy hardware has
|
||||
existed long before Power Macintosh was introduced. It includes:
|
||||
- versatile interface adapter (VIA)
|
||||
- Sander-Woz integrated machine (SWIM) that is a floppy disk controller
|
||||
- CUDA MCU for ADB, parameter RAM, realtime clock and power management support
|
||||
- serial communication controller (SCC)
|
||||
- Macintosh Enhanced SCSI Hardware (MESH)
|
||||
|
||||
In the 68k Macintosh era, all this hardware was implemented using several
|
||||
custom chips. In a PCI-compatible Power Macintosh, the above devices are part
|
||||
of the MIO chip itself. MIO's functional blocks implementing virtual devices
|
||||
are called "cells", i.e. "VIA cell", "SWIM cell" etc.
|
||||
|
||||
MIO itself is PCI compliant while the legacy hardware it emulates isn't.
|
||||
MIO occupies 512Kb of the PCI memory space divided into registers space and
|
||||
DMA space. Access to emulated legacy devices is accomplished by reading from/
|
||||
writing to MIO's PCI address space at predefined offsets.
|
||||
|
||||
MIO includes a DMA controller that offers 15 DMA channels implementing
|
||||
Apple's own DMA protocol called descriptor-based DMA (DBDMA).
|
||||
|
||||
Official documentation (that is somewhat incomplete and erroneous) can be
|
||||
found in the second chapter of the book "Macintosh Technology in the Common
|
||||
Hardware Reference Platform" by Apple Computer, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "pcidevice.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcihost.h"
|
||||
#include "viacuda.h"
|
||||
#include "nvram.h"
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Heathrow is a MIO-compliant ASIC used in the Gossamer architecture. It's
|
||||
hard-wired to PCI device number 16. Its I/O memory (512Kb) will be configured
|
||||
by the Macintosh firmware to live at 0xF3000000.
|
||||
|
||||
Emulated subdevices and their offsets within Heathrow I/O space:
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
escc(serial) 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
|
||||
davbus(sound) register space: 0x00014000, DMA space: 0x00008800, 0x00008900
|
||||
SWIM3(floppy) register space: 0x00015000, DMA space: 0x00008100
|
||||
NVRAM register space: 0x00060000, size: 0x00020000
|
||||
IDE register space: 0x00020000, DMA space: 0x00008b00
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice
|
||||
{
|
||||
public:
|
||||
using PCIDevice::name;
|
||||
|
||||
HeathrowIC();
|
||||
~HeathrowIC();
|
||||
|
||||
void set_host(PCIHost *host_instance) {this->host_instance = host_instance;};
|
||||
|
||||
/* PCI device methods */
|
||||
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);
|
||||
|
||||
/* MMIO device methods */
|
||||
uint32_t read(uint32_t offset, int size);
|
||||
void write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
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
|
||||
// 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
|
||||
};
|
||||
|
||||
uint32_t int_mask1;
|
||||
uint32_t int_clear1;
|
||||
uint32_t feat_ctrl; // features control register
|
||||
|
||||
/* device cells */
|
||||
ViaCuda *viacuda; /* VIA cell with Cuda MCU attached to it */
|
||||
NVram *nvram; /* NVRAM cell */
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Highspeed Memory Controller";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
add_mmio_region(0x50F40000, 0x10000, this);
|
||||
|
||||
this->ctrl_reg = 0ULL;
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
|
||||
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->ctrl_reg = (value & 1) ? this->ctrl_reg | bit :
|
||||
this->ctrl_reg & ~bit;
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
this->bit_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** 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/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** Bit in the HMC control register telling us where the frame bufffer
|
||||
for the on-board video is located. */
|
||||
#define HMC_VBASE_BIT 33
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HMC();
|
||||
~HMC() = default;
|
||||
|
||||
/* 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);
|
||||
|
||||
uint64_t get_control_reg(void) {
|
||||
return this->ctrl_reg;
|
||||
};
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t ctrl_reg;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
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/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
if (entry)
|
||||
delete(entry);
|
||||
}
|
||||
|
||||
for (auto& reg : mem_regions) {
|
||||
if (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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* 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];
|
||||
|
||||
this->mem_regions.push_back(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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
||||
ref_entry = find_range(dest_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
cpy_size = std::min(ref_entry->end - ref_entry->start + 1, size);
|
||||
memcpy(ref_entry->mem_ptr, data, cpy_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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 - 1))
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 MEMORY_CONTROLLER_BASE_H
|
||||
#define MEMORY_CONTROLLER_BASE_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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) */
|
||||
};
|
||||
|
||||
/** 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 */
|
||||
} AddressMapEntry;
|
||||
|
||||
|
||||
/** Base class for memory controllers. */
|
||||
class MemCtrlBase {
|
||||
public:
|
||||
MemCtrlBase() = default;
|
||||
virtual ~MemCtrlBase();
|
||||
virtual bool add_rom_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
||||
|
||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
||||
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_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);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t*> mem_regions;
|
||||
std::vector<AddressMapEntry*> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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. */
|
||||
|
||||
#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 <cstring>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
|
||||
{
|
||||
this->name = "Grackle";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV |
|
||||
HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
// populate PCI config header
|
||||
this->vendor_id = PCI_VENDOR_MOTOROLA;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = 0x06000040;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 6;
|
||||
this->status = 0x80;
|
||||
|
||||
// add PCI/ISA I/O space, 64K for now
|
||||
add_mmio_region(0xFE000000, 0x10000, this);
|
||||
|
||||
// add memory mapped I/O region for MPC106 registers
|
||||
add_mmio_region(0xFEC00000, 0x300000, this);
|
||||
}
|
||||
|
||||
uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t result;
|
||||
|
||||
if (reg_start == 0xFE000000) {
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to read from unmapped PCI I/O space, offset=0x%X", offset);
|
||||
} else {
|
||||
if (offset >= 0x200000) {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_read(size);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: reading from CONFIG_ADDR is ignored for now
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to write to unmapped PCI I/O space, offset=0x%X", offset);
|
||||
} else {
|
||||
if (offset < 0x200000) {
|
||||
this->config_addr = value;
|
||||
} 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) {
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
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
|
||||
return this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
return this->dev_map[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);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
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
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
this->dev_map[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
}
|
||||
|
||||
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) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "write %08X to Grackle register %08X\n", value, reg_offs);
|
||||
#endif
|
||||
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "MPC106: MCCR1[MEMGO] was set! \n");
|
||||
#endif
|
||||
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];
|
||||
|
||||
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]);
|
||||
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]);
|
||||
} else {
|
||||
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]);
|
||||
}
|
||||
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(WARNING, "MPC106: RAM not contiguous! \n");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->add_ram_region(0, ram_size)) {
|
||||
LOG_F(ERROR, "MPC106 RAM allocation failed! \n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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
|
||||
|
||||
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/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() = default;
|
||||
|
||||
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:
|
||||
/* 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;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Platinum Memory/Display Controller emulation. */
|
||||
|
||||
#include <devices/memctrl/platinum.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace Platinum;
|
||||
|
||||
PlatinumCtrl::PlatinumCtrl() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Platinum Memory Controller";
|
||||
|
||||
// add MMIO region for the configuration and status registers
|
||||
add_mmio_region(0xF8000000, 0x500, this);
|
||||
|
||||
// determine actual VRAM size (min. 1MB, max. 4MB)
|
||||
this->vram_size = 1 << 20;
|
||||
|
||||
// insert video memory region into the main memory map
|
||||
this->add_ram_region(0xF1000000UL, this->vram_size);
|
||||
|
||||
// initialize the CPUID register with the following CPU:
|
||||
// PowerPC 601 @ 75 MHz, bus frequency: 37,5 MHz
|
||||
this->cpu_id = (0x3001 << 16) | ClkSrc3 | (CpuSpeed3::CPU_75_BUS_38 << 8);
|
||||
|
||||
this->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
}
|
||||
|
||||
uint32_t PlatinumCtrl::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Platinum: unsupported register access size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case PlatinumReg::CPU_ID:
|
||||
return this->cpu_id;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
return this->dram_refresh;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
case PlatinumReg::BANK_2_BASE:
|
||||
case PlatinumReg::BANK_3_BASE:
|
||||
case PlatinumReg::BANK_4_BASE:
|
||||
case PlatinumReg::BANK_5_BASE:
|
||||
case PlatinumReg::BANK_6_BASE:
|
||||
case PlatinumReg::BANK_7_BASE:
|
||||
return this->bank_base[(offset - PlatinumReg::BANK_0_BASE) >> 4];
|
||||
case PlatinumReg::CACHE_CONFIG:
|
||||
return 0; // report no L2 cache installed
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
return this->fb_addr;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
LOG_F(INFO, "Platinum: display sense read");
|
||||
return (this->cur_mon_id ^ 7);
|
||||
default:
|
||||
LOG_F(WARNING, "Platinum: unknown register read at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
case PlatinumReg::ROM_TIMING:
|
||||
this->rom_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_TIMING:
|
||||
this->dram_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
this->dram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
case PlatinumReg::BANK_2_BASE:
|
||||
case PlatinumReg::BANK_3_BASE:
|
||||
case PlatinumReg::BANK_4_BASE:
|
||||
case PlatinumReg::BANK_5_BASE:
|
||||
case PlatinumReg::BANK_6_BASE:
|
||||
case PlatinumReg::BANK_7_BASE:
|
||||
this->bank_base[(offset - PlatinumReg::BANK_0_BASE) >> 4] = value;
|
||||
break;
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
this->fb_addr = value;
|
||||
LOG_F(INFO, "Platinum: Framebuffer address set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_1:
|
||||
this->fb_config_1 = value;
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_2:
|
||||
this->fb_config_2 = value;
|
||||
break;
|
||||
case PlatinumReg::VMEM_PAGE_MODE:
|
||||
this->vmem_fp_mode = value;
|
||||
break;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
LOG_F(INFO, "Platinum: display sense written with 0x%X", value);
|
||||
this->cur_mon_id = this->display_id->read_monitor_sense(value & 7, value ^ 7);
|
||||
break;
|
||||
case PlatinumReg::FB_RESET:
|
||||
this->fb_reset = value;
|
||||
break;
|
||||
case PlatinumReg::VRAM_REFRESH:
|
||||
this->vram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_CONFIG:
|
||||
this->swatch_config = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_INT_MASK:
|
||||
this->swatch_int_mask = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HAL:
|
||||
LOG_F(INFO, "Swatch HAL set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HFP:
|
||||
LOG_F(INFO, "Swatch HFP set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HPIX:
|
||||
LOG_F(INFO, "Swatch HPIX set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_VAL:
|
||||
LOG_F(INFO, "Swatch VAL set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_VFP:
|
||||
LOG_F(INFO, "Swatch VFP set to 0x%X", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Platinum: unknown register write at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
void PlatinumCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
{
|
||||
if (slot_num < 0 || slot_num >= 4) {
|
||||
ABORT_F("Platinum: invalid DIMM slot %d", slot_num);
|
||||
}
|
||||
|
||||
switch (capacity) {
|
||||
case DRAM_CAP_2MB:
|
||||
case DRAM_CAP_4MB:
|
||||
case DRAM_CAP_8MB:
|
||||
case DRAM_CAP_16MB:
|
||||
case DRAM_CAP_32MB:
|
||||
case DRAM_CAP_64MB:
|
||||
this->bank_size[slot_num * 2 + 0] = capacity;
|
||||
break;
|
||||
case DRAM_CAP_128MB:
|
||||
this->bank_size[slot_num * 2 + 0] = DRAM_CAP_64MB;
|
||||
this->bank_size[slot_num * 2 + 1] = DRAM_CAP_64MB;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Platinum: unsupported DRAM capacity %d", capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void PlatinumCtrl::map_phys_ram()
|
||||
{
|
||||
uint32_t total_ram = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
total_ram += this->bank_size[i];
|
||||
}
|
||||
|
||||
if (total_ram > DRAM_CAP_64MB) {
|
||||
ABORT_F("Platinum: RAM bigger than 64MB not supported yet");
|
||||
}
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("Platinum: could not allocate RAM storage");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Platinum Memory Controller definitions.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Platium is a single chip memory subsystem controller designed especially
|
||||
for the Power Macintosh 7200 computer, code name Catalyst.
|
||||
*/
|
||||
|
||||
#ifndef PLATINUM_MEMCTRL_H
|
||||
#define PLATINUM_MEMCTRL_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/video/displayid.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
namespace Platinum {
|
||||
|
||||
/** Clock source encoding in the CPUID register */
|
||||
enum {
|
||||
ClkSrc0 = 0x0000, // 33 MHz
|
||||
ClkSrc2 = 0x8000, // 20 MHz
|
||||
ClkSrc3 = 0x8040 // 31,3344 MHz
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc0 */
|
||||
enum CpuSpeed0 {
|
||||
CPU_66_BUS_33 = 0,
|
||||
CPU_80_BUS_40_1 = 1,
|
||||
CPU_80_BUS_27_1 = 2,
|
||||
CPU_100_BUS_50 = 3,
|
||||
CPU_100_BUS_33 = 4,
|
||||
CPU_120_BUS_60 = 5,
|
||||
CPU_120_BUS_40 = 6,
|
||||
CPU_120_BUS_30 = 7,
|
||||
CPU_133_BUS_66 = 8,
|
||||
CPU_133_BUS_44 = 9,
|
||||
CPU_133_BUS_33 = 10,
|
||||
CPU_150_BUS_75 = 11,
|
||||
CPU_150_BUS_50 = 12,
|
||||
CPU_150_BUS_37 = 13
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc2 */
|
||||
enum CpuSpeed2 {
|
||||
CPU_40_BUS_20 = 0,
|
||||
CPU_48_BUS_24 = 1,
|
||||
CPU_48_BUS_16 = 2,
|
||||
CPU_60_BUS_30 = 3,
|
||||
CPU_60_BUS_20 = 4,
|
||||
CPU_72_BUS_36 = 5,
|
||||
CPU_72_BUS_24 = 6,
|
||||
CPU_72_BUS_18 = 7,
|
||||
CPU_80_BUS_40_2 = 8,
|
||||
CPU_80_BUS_27_2 = 9,
|
||||
CPU_80_BUS_20 = 10,
|
||||
CPU_90_BUS_45 = 11,
|
||||
CPU_90_BUS_30 = 12,
|
||||
CPU_90_BUS_22 = 13
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc3 */
|
||||
enum CpuSpeed3 {
|
||||
CPU_62_BUS_31 = 0,
|
||||
CPU_75_BUS_38 = 1, // actual bus frequency: 37500000 Hz
|
||||
CPU_75_BUS_25 = 2,
|
||||
CPU_94_BUS_47 = 3,
|
||||
CPU_94_BUS_31 = 4,
|
||||
CPU_113_BUS_56 = 5,
|
||||
CPU_113_BUS_38 = 6, // actual bus frequency: 37500000 Hz
|
||||
CPU_113_BUS_28 = 7,
|
||||
CPU_125_BUS_64 = 8, // actual bus frequency: 63500000 Hz
|
||||
CPU_125_BUS_42 = 9,
|
||||
CPU_125_BUS_31 = 10,
|
||||
CPU_141_BUS_72 = 11, // actual bus frequency: 71500000 Hz
|
||||
CPU_141_BUS_47 = 12,
|
||||
CPU_141_BUS_35 = 13
|
||||
};
|
||||
|
||||
/** Configuration and status register offsets. */
|
||||
enum PlatinumReg : uint32_t {
|
||||
CPU_ID = 0x000,
|
||||
ASIC_REVISION = 0x010,
|
||||
ROM_TIMING = 0x020,
|
||||
CACHE_CONFIG = 0x030,
|
||||
DRAM_TIMING = 0x040,
|
||||
DRAM_REFRESH = 0x050,
|
||||
BANK_0_BASE = 0x060,
|
||||
BANK_1_BASE = 0x070,
|
||||
BANK_2_BASE = 0x080,
|
||||
BANK_3_BASE = 0x090,
|
||||
BANK_4_BASE = 0x0A0,
|
||||
BANK_5_BASE = 0x0B0,
|
||||
BANK_6_BASE = 0x0C0,
|
||||
BANK_7_BASE = 0x0D0,
|
||||
GP_SW_SCRATCH = 0x0E0,
|
||||
PCI_ADDR_MASK = 0x0F0,
|
||||
FB_BASE_ADDR = 0x100,
|
||||
FB_CONFIG_1 = 0x140,
|
||||
FB_CONFIG_2 = 0x150,
|
||||
VMEM_PAGE_MODE = 0x160,
|
||||
MON_ID_SENSE = 0x170,
|
||||
FB_RESET = 0x180,
|
||||
VRAM_REFRESH = 0x1B0,
|
||||
SWATCH_CONFIG = 0x200,
|
||||
SWATCH_INT_MASK = 0x210,
|
||||
SWATCH_HAL = 0x300,
|
||||
SWATCH_HFP = 0x310,
|
||||
SWATCH_HPIX = 0x320,
|
||||
SWATCH_VAL = 0x370,
|
||||
SWATCH_VFP = 0x380,
|
||||
IRIDIUM_CONFIG = 0x4A0,
|
||||
};
|
||||
|
||||
enum {
|
||||
DRAM_CAP_2MB = (1 << 21),
|
||||
DRAM_CAP_4MB = (1 << 22),
|
||||
DRAM_CAP_8MB = (1 << 23),
|
||||
DRAM_CAP_16MB = (1 << 24),
|
||||
DRAM_CAP_32MB = (1 << 25),
|
||||
DRAM_CAP_64MB = (1 << 26),
|
||||
DRAM_CAP_128MB = (1 << 27),
|
||||
};
|
||||
|
||||
// FB_RESET register bits.
|
||||
enum {
|
||||
VRAM_SM_RESET = (1 << 0), // VRAM state machine reset
|
||||
VREFRESH_SM_RESET = (1 << 1), // Video refresh state machine reset
|
||||
SWATCH_RESET = (1 << 2), // Swatch reset
|
||||
};
|
||||
|
||||
}; // namespace Platinum
|
||||
|
||||
class PlatinumCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
PlatinumCtrl();
|
||||
~PlatinumCtrl() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV);
|
||||
}
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
private:
|
||||
uint32_t cpu_id;
|
||||
uint8_t cpu_type; // 0 - MPC601, 1 - 603/604 CPU
|
||||
|
||||
// memory controller state
|
||||
uint32_t rom_timing = 0;
|
||||
uint32_t dram_timing = 0xEFF;
|
||||
uint32_t dram_refresh = 0x1F4;
|
||||
uint32_t bank_base[8];
|
||||
uint32_t bank_size[8] = { 0 };
|
||||
|
||||
// display controller state
|
||||
uint32_t fb_addr = 0xF1000000;
|
||||
uint32_t fb_config_1 = 0x1F00;
|
||||
uint32_t fb_config_2 = 0x1FFF;
|
||||
uint32_t fb_reset = 7;
|
||||
uint32_t vram_refresh = 0x1F4;
|
||||
uint32_t vram_size = 0;
|
||||
uint8_t vmem_fp_mode = 0;
|
||||
uint8_t cur_mon_id = 0;
|
||||
|
||||
// video timing generator (Swatch) state
|
||||
uint32_t swatch_config = 0xFFD;
|
||||
uint32_t swatch_int_mask = 0;
|
||||
|
||||
std::unique_ptr<DisplayID> display_id;
|
||||
};
|
||||
|
||||
#endif // PLATINUM_MEMCTRL_H
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
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 Serial presence detect (SPD) RAM module emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
@description
|
||||
Serial presence detect (SPD) is a standard that prescribes an automatic way
|
||||
to supply various information about a memory module.
|
||||
A SPD-compatible memory module contains a small EEPROM that stores useful
|
||||
information like memory size, configuration, speed, manufacturer etc.
|
||||
The content depends on the module type.
|
||||
|
||||
This EEPROM is accessible via the I2C bus. The EEPROM I2C address will be
|
||||
configured depending on the physical RAM slot the module is inserted to.
|
||||
|
||||
A 168-Pin SDRAM slot includes three specialized pins SA0-SA2 for setting
|
||||
an unique I2C address for each module EEPROM. The SA0-SA2 pins are hardwired
|
||||
differently for each RAM slot. Example:
|
||||
|
||||
Slot SA0-SA2 I2C address
|
||||
A %000 0x50 + %000 = 0x50
|
||||
B %001 0x50 + %001 = 0x51
|
||||
|
||||
Further reading: https://en.wikipedia.org/wiki/Serial_presence_detect
|
||||
*/
|
||||
|
||||
#ifndef SPD_EEPROM_H
|
||||
#define SPD_EEPROM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#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;
|
||||
supports_types(HWCompType::RAM);
|
||||
};
|
||||
|
||||
~SpdSdram168() = default;
|
||||
|
||||
void set_capacity(int capacity_megs) {
|
||||
switch (capacity_megs) {
|
||||
case 32:
|
||||
this->eeprom_data[3] = 0xC; /* 12 rows */
|
||||
this->eeprom_data[4] = 0x8; /* 8 columns */
|
||||
this->eeprom_data[5] = 0x1; /* one bank */
|
||||
break;
|
||||
case 64:
|
||||
this->eeprom_data[3] = 0xC; /* 12 rows */
|
||||
this->eeprom_data[4] = 0x9; /* 9 columns */
|
||||
this->eeprom_data[5] = 0x1; /* one bank */
|
||||
break;
|
||||
case 128:
|
||||
this->eeprom_data[3] = 0xC; /* 12 rows */
|
||||
this->eeprom_data[4] = 0xA; /* 10 columns */
|
||||
this->eeprom_data[5] = 0x1; /* one bank */
|
||||
break;
|
||||
case 256:
|
||||
this->eeprom_data[3] = 0xC; /* 12 rows */
|
||||
this->eeprom_data[4] = 0xA; /* 10 columns */
|
||||
this->eeprom_data[5] = 0x2; /* two banks */
|
||||
break;
|
||||
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);
|
||||
};
|
||||
|
||||
void start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
LOG_F(9, "SDRAM subaddress set to 0x%X", sub_addr);
|
||||
return true;
|
||||
};
|
||||
|
||||
bool send_byte(uint8_t data) {
|
||||
LOG_F(9, "SDRAM byte 0x%X received", data);
|
||||
return true;
|
||||
};
|
||||
|
||||
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 */
|
||||
}
|
||||
LOG_F(9, "SDRAM sending EEPROM byte 0x%X", this->eeprom_data[this->pos]);
|
||||
*p_data = this->eeprom_data[this->pos++];
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t dev_addr; /* I2C address */
|
||||
int pos; /* actual read position */
|
||||
|
||||
/* EEPROM content */
|
||||
uint8_t eeprom_data[256] = {
|
||||
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 */
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* SPD_EEPROM_H */
|
||||
@@ -1,138 +0,0 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
|
||||
#include "memctrlbase.h"
|
||||
|
||||
|
||||
MemCtrlBase::MemCtrlBase(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase()
|
||||
{
|
||||
for (auto ® : mem_regions) {
|
||||
if (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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
|
||||
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;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
cpy_size = std::min(ref_entry->end - ref_entry->start + 1, size);
|
||||
memcpy(ref_entry->mem_ptr, data, cpy_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
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;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef MEMORY_CONTROLLER_BASE_H
|
||||
#define MEMORY_CONTROLLER_BASE_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) */
|
||||
};
|
||||
|
||||
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 */
|
||||
} AddressMapEntry;
|
||||
|
||||
|
||||
/** Base class for memory controllers. */
|
||||
class MemCtrlBase {
|
||||
public:
|
||||
MemCtrlBase(std::string name);
|
||||
virtual ~MemCtrlBase();
|
||||
virtual bool add_rom_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
|
||||
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
||||
|
||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice *dev_instance);
|
||||
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t *data, uint32_t size);
|
||||
|
||||
AddressMapEntry *find_range(uint32_t addr);
|
||||
|
||||
protected:
|
||||
bool add_mem_region(uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
|
||||
|
||||
std::string name;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t *> mem_regions;
|
||||
std::vector<AddressMapEntry> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** Abstract class representing a simple, memory-mapped I/O device */
|
||||
class MMIODevice {
|
||||
public:
|
||||
virtual uint32_t read(uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual ~MMIODevice() = default;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
#endif /* MMIO_DEVICE_H */
|
||||
@@ -1,224 +0,0 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "memreadwrite.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "mpc106.h"
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase("Grackle"), PCIDevice("Grackle PCI host bridge")
|
||||
{
|
||||
/* add memory mapped I/O region for MPC106 registers */
|
||||
add_mmio_region(0xFEC00000, 0x300000, this);
|
||||
|
||||
this->pci_0_bus.clear();
|
||||
}
|
||||
|
||||
MPC106::~MPC106()
|
||||
{
|
||||
this->pci_0_bus.clear();
|
||||
}
|
||||
|
||||
uint32_t MPC106::read(uint32_t offset, int size)
|
||||
{
|
||||
if (offset >= 0x200000) {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_read(size);
|
||||
}
|
||||
|
||||
/* FIXME: reading from CONFIG_ADDR is ignored for now */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (offset < 0x200000) {
|
||||
this->config_addr = value;
|
||||
} 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)
|
||||
{
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
if (bus_num) {
|
||||
std::cout << this->name << " err: read attempt from non-local PCI bus, "
|
||||
<< "config_addr = " << std::hex << this->config_addr << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
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
|
||||
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 {
|
||||
std::cout << this->name << " err: read attempt from non-existing PCI device "
|
||||
<< dev_num << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
std::cout << this->name << " err: write attempt to non-local PCI bus, "
|
||||
<< "config_addr = " << std::hex << this->config_addr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
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
|
||||
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 {
|
||||
std::cout << this->name << " err: write attempt to non-existing PCI device "
|
||||
<< dev_num << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
#ifdef MPC106_DEBUG
|
||||
printf("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:
|
||||
std::cout << "MPC106 read error: invalid size parameter " << size
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
#ifdef MPC106_DEBUG
|
||||
printf("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:
|
||||
std::cout << "MPC106 read error: invalid size parameter " << size
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
std::cout << "MPC106: MCCR1[MEMGO] was set! " << std::endl;
|
||||
#endif
|
||||
setup_ram();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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];
|
||||
|
||||
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]);
|
||||
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]);
|
||||
} else {
|
||||
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]);
|
||||
}
|
||||
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)
|
||||
std::cout << "MPC106 error: RAM not contiguous!" << std::endl;
|
||||
ram_size += bank_end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->add_ram_region(0, ram_size)) {
|
||||
std::cout << "MPC106 RAM allocation failed!" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
//DingusPPC - Prototype 5bf2
|
||||
//Written by divingkatae
|
||||
//(c)2018-20 (theweirdo)
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 on Discord)
|
||||
|
||||
/** 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 "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
|
||||
|
||||
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost
|
||||
{
|
||||
public:
|
||||
using MemCtrlBase::name;
|
||||
|
||||
MPC106();
|
||||
~MPC106();
|
||||
uint32_t read(uint32_t offset, int size);
|
||||
void write(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);
|
||||
|
||||
void set_host(PCIHost *host_instance) {}; // unimplemented for now
|
||||
|
||||
/* PCI host bridge API */
|
||||
//bool pci_register_device(int dev_num, PCIDevice *dev_instance);
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,80 +0,0 @@
|
||||
//DingusPPC
|
||||
//Written by divingkatae and maximum
|
||||
//(c)2018-20 (theweirdo) spatium
|
||||
//Please ask for permission
|
||||
//if you want to distribute this.
|
||||
//(divingkatae#1017 or powermax#2286 on Discord)
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include "nvram.h"
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
this->storage = new uint8_t[ram_size];
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
NVram::~NVram()
|
||||
{
|
||||
this->save();
|
||||
if (this->storage)
|
||||
delete this->storage;
|
||||
}
|
||||
|
||||
uint8_t NVram::read_byte(uint32_t offset)
|
||||
{
|
||||
return (this->storage[offset]);
|
||||
}
|
||||
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val)
|
||||
{
|
||||
this->storage[offset] = val;
|
||||
}
|
||||
|
||||
void NVram::init() {
|
||||
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))
|
||||
{
|
||||
cout << "WARN: Could not restore NVRAM content from the given file." << endl;
|
||||
memset(this->storage, 0, sizeof(this->ram_size));
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char *)this->storage, this->ram_size);
|
||||
|
||||
f.close();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef NVRAM_H
|
||||
#define NVRAM_H
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
|
||||
It implements a non-volatile random access storage whose content will be
|
||||
automatically saved to and restored from the dedicated file.
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
std::string file_name; /* file name for the backing file. */
|
||||
uint16_t ram_size; /* NVRAM size. */
|
||||
uint8_t* storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
};
|
||||
|
||||
#endif /* NVRAM_H */
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef PCI_DEVICE_H
|
||||
#define PCI_DEVICE_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)
|
||||
|
||||
enum {
|
||||
CFG_REG_BAR0 = 0x10 // base address register 0
|
||||
};
|
||||
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name) {this->name = name;};
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
/* 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 void set_host(PCIHost *host_instance) = 0;
|
||||
|
||||
protected:
|
||||
std::string 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 */
|
||||
@@ -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,142 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Character I/O backend implementations. */
|
||||
|
||||
#include <devices/serial/chario.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
bool CharIoNull::rcv_char_available()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int CharIoNull::xmit_char(uint8_t c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoNull::rcv_char(uint8_t *c)
|
||||
{
|
||||
*c = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//======================== STDIO character I/O backend ========================
|
||||
#ifndef _WIN32
|
||||
|
||||
#include<signal.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct sigaction old_act, new_act;
|
||||
struct termios orig_termios;
|
||||
|
||||
void mysig_handler(int signum)
|
||||
{
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act.sa_handler);
|
||||
|
||||
LOG_F(INFO, "Old terminal state restored, SIG#=%d", signum);
|
||||
|
||||
// re-post signal
|
||||
raise(signum);
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_enable()
|
||||
{
|
||||
if (this->stdio_inited)
|
||||
return 0;
|
||||
|
||||
// save original terminal state
|
||||
tcgetattr(STDIN_FILENO, &orig_termios);
|
||||
|
||||
struct termios new_termios = orig_termios;
|
||||
|
||||
new_termios.c_cflag &= ~(CSIZE | PARENB);
|
||||
new_termios.c_cflag |= CS8;
|
||||
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
new_termios.c_iflag &= ~(ICRNL);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
||||
|
||||
// save original signal handler for SIGINT
|
||||
// then redirect SIGINT to new handler
|
||||
memset(&new_act, 0, sizeof(new_act));
|
||||
new_act.sa_handler = mysig_handler;
|
||||
sigaction(SIGINT, &new_act, &old_act);
|
||||
|
||||
this->stdio_inited = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CharIoStdin::rcv_disable()
|
||||
{
|
||||
if (!this->stdio_inited)
|
||||
return;
|
||||
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act.sa_handler);
|
||||
|
||||
this->stdio_inited = false;
|
||||
}
|
||||
|
||||
bool CharIoStdin::rcv_char_available()
|
||||
{
|
||||
fd_set readfds;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(STDIN_FILENO, &readfds);
|
||||
fd_set savefds = readfds;
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
int chr;
|
||||
|
||||
int sel_rv = select(1, &readfds, NULL, NULL, &timeout);
|
||||
return sel_rv > 0;
|
||||
}
|
||||
|
||||
int CharIoStdin::xmit_char(uint8_t c)
|
||||
{
|
||||
write(STDOUT_FILENO, &c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_char(uint8_t *c)
|
||||
{
|
||||
read(STDIN_FILENO, c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Character I/O definitions. */
|
||||
|
||||
#ifndef CHAR_IO_H
|
||||
#define CHAR_IO_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
enum {
|
||||
CHARIO_BE_NULL = 0, // NULL backend: swallows everything, receives nothing
|
||||
CHARIO_BE_STDIO = 1, // STDIO backend: uses STDIN for input and STDOUT for output
|
||||
};
|
||||
|
||||
/** Interface for character I/O backends. */
|
||||
class CharIoBackEnd {
|
||||
public:
|
||||
CharIoBackEnd() = default;
|
||||
virtual ~CharIoBackEnd() = default;
|
||||
|
||||
virtual int rcv_enable() { return 0; };
|
||||
virtual void rcv_disable() {};
|
||||
virtual bool rcv_char_available() = 0;
|
||||
virtual int xmit_char(uint8_t c) = 0;
|
||||
virtual int rcv_char(uint8_t *c) = 0;
|
||||
};
|
||||
|
||||
/** Null character I/O backend. */
|
||||
class CharIoNull : public CharIoBackEnd {
|
||||
public:
|
||||
CharIoNull() = default;
|
||||
~CharIoNull() = default;
|
||||
|
||||
bool rcv_char_available();
|
||||
int xmit_char(uint8_t c);
|
||||
int rcv_char(uint8_t *c);
|
||||
};
|
||||
|
||||
/** Stdin character I/O backend. */
|
||||
class CharIoStdin : public CharIoBackEnd {
|
||||
public:
|
||||
CharIoStdin() { this->stdio_inited = false; };
|
||||
~CharIoStdin() = default;
|
||||
|
||||
int rcv_enable();
|
||||
void rcv_disable();
|
||||
bool rcv_char_available();
|
||||
int xmit_char(uint8_t c);
|
||||
int rcv_char(uint8_t *c);
|
||||
|
||||
private:
|
||||
bool stdio_inited;
|
||||
};
|
||||
|
||||
#endif // CHAR_IO_H
|
||||
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 <devices/serial/chario.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** Remap the compatible addressing scheme to MacRISC one. */
|
||||
const uint8_t compat_to_macrisc[6] = {
|
||||
EsccReg::Port_B_Cmd, EsccReg::Port_A_Cmd,
|
||||
EsccReg::Port_B_Data, EsccReg::Port_A_Data,
|
||||
EsccReg::Enh_Reg_B, EsccReg::Enh_Reg_A
|
||||
};
|
||||
|
||||
EsccController::EsccController()
|
||||
{
|
||||
// allocate channels
|
||||
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("A"));
|
||||
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("B"));
|
||||
|
||||
// attach backends
|
||||
std::string backend_name = GET_STR_PROP("serial_backend");
|
||||
|
||||
this->ch_a->attach_backend(
|
||||
(backend_name == "stdio") ? CHARIO_BE_STDIO : CHARIO_BE_NULL);
|
||||
this->ch_b->attach_backend(CHARIO_BE_NULL);
|
||||
|
||||
this->reg_ptr = 0;
|
||||
}
|
||||
|
||||
void EsccController::reset()
|
||||
{
|
||||
this->master_int_cntrl &= 0xFC;
|
||||
this->master_int_cntrl |= 0xC0;
|
||||
|
||||
this->ch_a->reset(true);
|
||||
this->ch_b->reset(true);
|
||||
}
|
||||
|
||||
uint8_t EsccController::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
if (this->reg_ptr == 2) {
|
||||
// TODO: implement interrupt vector modifications
|
||||
result = this->int_vec;
|
||||
} else {
|
||||
result = this->ch_b->read_reg(this->reg_ptr);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
if (this->reg_ptr == 2) {
|
||||
return this->int_vec;
|
||||
} else {
|
||||
return this->ch_a->read_reg(this->reg_ptr);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_B_Data:
|
||||
return this->ch_b->receive_byte();
|
||||
case EsccReg::Port_A_Data:
|
||||
return this->ch_a->receive_byte();
|
||||
default:
|
||||
LOG_F(9, "ESCC: reading from unimplemented register %d", reg_offset);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
case EsccReg::Port_B_Data:
|
||||
this->ch_b->send_byte(value);
|
||||
break;
|
||||
case EsccReg::Port_A_Data:
|
||||
this->ch_a->send_byte(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "ESCC: writing 0x%X to unimplemented register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
{
|
||||
if (this->reg_ptr) {
|
||||
// chip-specific registers
|
||||
if (this->reg_ptr == 9) {
|
||||
// see if some reset is requested
|
||||
switch(value & 0xC0) {
|
||||
case RESET_CH_B:
|
||||
this->master_int_cntrl &= 0xDF;
|
||||
this->ch_b->reset(false);
|
||||
break;
|
||||
case RESET_CH_A:
|
||||
this->master_int_cntrl &= 0xDF;
|
||||
this->ch_a->reset(false);
|
||||
break;
|
||||
case RESET_ESCC:
|
||||
this->reset();
|
||||
break;
|
||||
}
|
||||
|
||||
this->master_int_cntrl = value & 0x3F;
|
||||
} else if (this->reg_ptr == 2) {
|
||||
this->int_vec = value;
|
||||
} else { // channel-specific registers
|
||||
ch->write_reg(this->reg_ptr, value);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
} else {
|
||||
this->reg_ptr = value & 7;
|
||||
switch(value >> 3) {
|
||||
case WR0Cmd::Point_High:
|
||||
this->reg_ptr |= 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== ESCC Channel methods ==============================
|
||||
void EsccChannel::attach_backend(int id)
|
||||
{
|
||||
switch(id) {
|
||||
case CHARIO_BE_NULL:
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
||||
break;
|
||||
case CHARIO_BE_STDIO:
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoStdin);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "ESCC: unknown backend ID %d, using NULL instead", id);
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::reset(bool hw_reset)
|
||||
{
|
||||
this->chario->rcv_disable();
|
||||
|
||||
this->write_regs[1] &= 0x24;
|
||||
this->write_regs[3] &= 0xFE;
|
||||
this->write_regs[4] |= 0x04;
|
||||
this->write_regs[5] &= 0x61;
|
||||
this->write_regs[15] = 0xF8;
|
||||
|
||||
this->read_regs[0] &= 0x3C;
|
||||
this->read_regs[0] |= 0x44;
|
||||
this->read_regs[1] = 0x06;
|
||||
this->read_regs[3] = 0x00;
|
||||
this->read_regs[10] = 0x00;
|
||||
|
||||
// initialize DPLL
|
||||
this->dpll_active = 0;
|
||||
this->dpll_mode = DpllMode::NRZI;
|
||||
this->dpll_clock_src = 0;
|
||||
|
||||
// initialize Baud Rate Generator (BRG)
|
||||
this->brg_active = 0;
|
||||
this->brg_clock_src = 0;
|
||||
|
||||
if (hw_reset) {
|
||||
this->write_regs[10] = 0;
|
||||
this->write_regs[11] = 8;
|
||||
this->write_regs[14] &= 0xC0;
|
||||
this->write_regs[14] |= 0x20;
|
||||
} else {
|
||||
this->write_regs[10] &= 0x60;
|
||||
this->write_regs[14] &= 0xC3;
|
||||
this->write_regs[14] |= 0x20;
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
switch (reg_num) {
|
||||
case 3:
|
||||
if ((this->write_regs[3] ^ value) & 0x10) {
|
||||
this->write_regs[3] |= 0x10;
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
LOG_F(9, "ESCC: Hunt mode entered.");
|
||||
}
|
||||
if ((this->write_regs[3] ^ value) & 1) {
|
||||
if (value & 1) {
|
||||
this->write_regs[3] |= 0x1;
|
||||
this->chario->rcv_enable();
|
||||
LOG_F(9, "ESCC: receiver enabled.");
|
||||
} else {
|
||||
this->write_regs[3] ^= 0x1;
|
||||
this->chario->rcv_disable();
|
||||
LOG_F(9, "ESCC: receiver disabled.");
|
||||
this->write_regs[3] |= 0x10; // enter HUNT mode
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
}
|
||||
}
|
||||
this->write_regs[3] = (this->write_regs[3] & 0x11) | (value & 0xEE);
|
||||
return;
|
||||
case 7:
|
||||
if (this->write_regs[15] & 1) {
|
||||
this->wr7_enh = value;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
switch (value >> 5) {
|
||||
case DPLL_NULL_CMD:
|
||||
break;
|
||||
case DPLL_ENTER_SRC_MODE:
|
||||
this->dpll_active = 1;
|
||||
this->read_regs[10] &= 0x3F;
|
||||
break;
|
||||
case DPLL_DISABLE:
|
||||
this->dpll_active = 0;
|
||||
// fallthrough
|
||||
case DPLL_RST_MISSING_CLK:
|
||||
this->read_regs[10] &= 0x3F;
|
||||
break;
|
||||
case DPLL_SET_SRC_BGR:
|
||||
this->dpll_clock_src = 0;
|
||||
break;
|
||||
case DPLL_SET_SRC_RTXC:
|
||||
this->dpll_clock_src = 1;
|
||||
break;
|
||||
case DPLL_SET_FM_MODE:
|
||||
this->dpll_mode = DpllMode::FM;
|
||||
break;
|
||||
case DPLL_SET_NRZI_MODE:
|
||||
this->dpll_mode = DpllMode::NRZI;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ESCC: unimplemented DPLL command %d", value >> 5);
|
||||
}
|
||||
if (value & 0x1C) { // Local Loopback, Auto Echo DTR/REQ bits set
|
||||
LOG_F(WARNING, "ESCC: unexpected value in WR14 = 0x%X", value);
|
||||
}
|
||||
if (this->brg_active ^ (value & 1)) {
|
||||
this->brg_active = value & 1;
|
||||
LOG_F(9, "ESCC: BRG %s", this->brg_active ? "enabled" : "disabled");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this->write_regs[reg_num] = value;
|
||||
}
|
||||
|
||||
uint8_t EsccChannel::read_reg(int reg_num)
|
||||
{
|
||||
if (!reg_num) {
|
||||
if (this->chario->rcv_char_available()) {
|
||||
this->read_regs[0] |= 1;
|
||||
}
|
||||
}
|
||||
return this->read_regs[reg_num];
|
||||
}
|
||||
|
||||
void EsccChannel::send_byte(uint8_t value)
|
||||
{
|
||||
// TODO: put one byte into the Data FIFO
|
||||
|
||||
this->chario->xmit_char(value);
|
||||
}
|
||||
|
||||
uint8_t EsccChannel::receive_byte()
|
||||
{
|
||||
// TODO: remove one byte from the Receive FIFO
|
||||
|
||||
uint8_t c;
|
||||
|
||||
this->chario->rcv_char(&c);
|
||||
this->read_regs[0] &= ~1;
|
||||
return c;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 <devices/serial/chario.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** ESCC register positions */
|
||||
/* Please note that the registers below are provided
|
||||
by the Apple I/O controllers for accessing ESCC
|
||||
in a more convenient way. Actual physical addresses
|
||||
are controller dependent.
|
||||
The registers are ordered according with the MacRISC
|
||||
scheme used in the PCI Power Macintosh models.
|
||||
Pre-PCI Macs uses the so-called compatibility
|
||||
addressing. Please use compat_to_macrisc table
|
||||
below for converting from compat to MacRISC.
|
||||
*/
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_B_Data = 1, // direct access to WR8/RR8
|
||||
Port_A_Cmd = 2,
|
||||
Port_A_Data = 3, // direct access to WR8/RR8
|
||||
Enh_Reg_B = 4, // undocumented Apple extension
|
||||
Enh_Reg_A = 5, // undocumented Apple extension
|
||||
};
|
||||
|
||||
extern const uint8_t compat_to_macrisc[6];
|
||||
|
||||
/** LocalTalk LTPC registers provided by a MacIO controller. */
|
||||
enum LocalTalkReg : uint8_t {
|
||||
Rec_Count = 8,
|
||||
Start_A = 9,
|
||||
Start_B = 0xA,
|
||||
Detect_AB = 0xB,
|
||||
};
|
||||
|
||||
enum WR0Cmd : uint8_t {
|
||||
Point_High = 1,
|
||||
};
|
||||
|
||||
/** ESCC reset commands. */
|
||||
enum {
|
||||
RESET_ESCC = 0xC0,
|
||||
RESET_CH_A = 0x80,
|
||||
RESET_CH_B = 0x40
|
||||
};
|
||||
|
||||
/** DPLL commands in WR14. */
|
||||
enum {
|
||||
DPLL_NULL_CMD = 0,
|
||||
DPLL_ENTER_SRC_MODE = 1,
|
||||
DPLL_RST_MISSING_CLK = 2,
|
||||
DPLL_DISABLE = 3,
|
||||
DPLL_SET_SRC_BGR = 4,
|
||||
DPLL_SET_SRC_RTXC = 5,
|
||||
DPLL_SET_FM_MODE = 6,
|
||||
DPLL_SET_NRZI_MODE = 7
|
||||
};
|
||||
|
||||
enum DpllMode : uint8_t {
|
||||
NRZI = 0,
|
||||
FM = 1
|
||||
};
|
||||
|
||||
/** ESCC Channel class. */
|
||||
class EsccChannel {
|
||||
public:
|
||||
EsccChannel(std::string name) { this->name = name; };
|
||||
~EsccChannel() = default;
|
||||
|
||||
void attach_backend(int id);
|
||||
void reset(bool hw_reset);
|
||||
uint8_t read_reg(int reg_num);
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
void send_byte(uint8_t value);
|
||||
uint8_t receive_byte();
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint8_t read_regs[16];
|
||||
uint8_t write_regs[16];
|
||||
uint8_t wr7_enh;
|
||||
uint8_t dpll_active;
|
||||
uint8_t dpll_mode;
|
||||
uint8_t dpll_clock_src;
|
||||
uint8_t brg_active;
|
||||
uint8_t brg_clock_src;
|
||||
|
||||
std::unique_ptr<CharIoBackEnd> chario;
|
||||
};
|
||||
|
||||
/** ESCC Controller class. */
|
||||
class EsccController {
|
||||
public:
|
||||
EsccController();
|
||||
~EsccController() = default;
|
||||
|
||||
// ESCC registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
void reset();
|
||||
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)
|
||||
|
||||
uint8_t master_int_cntrl;
|
||||
uint8_t int_vec;
|
||||
};
|
||||
|
||||
#endif // ESCC_H
|
||||
Loaded 100 of 278 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user