mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
626
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daca3a27d6 | ||
|
|
26374366c7 | ||
|
|
22798fe14e | ||
|
|
44478b6937 | ||
|
|
57ea3c2e66 | ||
|
|
03595c3940 | ||
|
|
ed48766e5f | ||
|
|
a7f4d418fc | ||
|
|
4093c6e83c | ||
|
|
cf0d361918 | ||
|
|
09da0c6109 | ||
|
|
2f562e7761 | ||
|
|
b07b700b36 | ||
|
|
616d0728fd | ||
|
|
74a49d1568 | ||
|
|
3e545bdef9 | ||
|
|
f1c898b17e | ||
|
|
49f47c5f3f | ||
|
|
888d919ae7 | ||
|
|
e01fea87a9 | ||
|
|
f181e721b0 | ||
|
|
c188d0251a | ||
|
|
d76433f112 | ||
|
|
422639411d | ||
|
|
5d7450df90 | ||
|
|
3234f21cab | ||
|
|
2fb23e210e | ||
|
|
fdf0ebbf6c | ||
|
|
597c077b19 | ||
|
|
71b2e6c1fa | ||
|
|
196154bb7b | ||
|
|
92c558f44b | ||
|
|
ad2fc290ec | ||
|
|
299f0d3a9f | ||
|
|
9fcf5ba51a | ||
|
|
094b3b5312 | ||
|
|
7e5451a97d | ||
|
|
8231ecd466 | ||
|
|
1d33ea2beb | ||
|
|
bee24b166d | ||
|
|
f61854a0ae | ||
|
|
99eb93f9e1 | ||
|
|
be45a6a020 | ||
|
|
b472123746 | ||
|
|
fd2e6c5b09 | ||
|
|
f7280c316b | ||
|
|
cc17035e67 | ||
|
|
654ff0219c | ||
|
|
8862a73ef1 | ||
|
|
5e61b473f0 | ||
|
|
2a64f547cc | ||
|
|
fba2ff4231 | ||
|
|
e64aab1577 | ||
|
|
36dee46e9b | ||
|
|
99e92a5679 | ||
|
|
ec97a671d8 | ||
|
|
31db015105 | ||
|
|
2b6716be5c | ||
|
|
449cc96612 | ||
|
|
bcd443779a | ||
|
|
6b6e92d3d9 | ||
|
|
289ddf10b7 | ||
|
|
699b62373a | ||
|
|
4100a80f96 | ||
|
|
136aeca8f2 | ||
|
|
8d01440558 | ||
|
|
e510c11be2 | ||
|
|
19adb54cd8 | ||
|
|
f2db6bd066 | ||
|
|
1b221bc0bd | ||
|
|
85d0900d7d | ||
|
|
5294a8b71c | ||
|
|
46bc8567e9 | ||
|
|
64fec88436 | ||
|
|
bd5a88f02f | ||
|
|
b61a7c4aea | ||
|
|
2f08a0b327 | ||
|
|
52fa30b71d | ||
|
|
911acb4bc2 | ||
|
|
0bd9d0e973 | ||
|
|
5aaae40d94 | ||
|
|
190718fbee | ||
|
|
37c352955c | ||
|
|
fb56a6b536 | ||
|
|
74b457819a | ||
|
|
0118b347f3 | ||
|
|
101a8d33b0 | ||
|
|
eb3f978c7b | ||
|
|
9ea4a465f4 | ||
|
|
41a34ffab6 | ||
|
|
8002737124 | ||
|
|
7ba8921649 | ||
|
|
a1d9fcfa9d | ||
|
|
648dfcd47b | ||
|
|
f6e208267e | ||
|
|
24ccdabedc | ||
|
|
a189c94980 | ||
|
|
dee225ee8f | ||
|
|
52bb87b72a | ||
|
|
78528a1a16 | ||
|
|
0dd9a3d9b1 | ||
|
|
df02f5053b | ||
|
|
86b0174b13 | ||
|
|
daf3ecde4e | ||
|
|
1e9ec5d7ae | ||
|
|
2537751fa7 | ||
|
|
df1a56305a | ||
|
|
6173a782f2 | ||
|
|
a892842b8f | ||
|
|
58908621e6 | ||
|
|
311538b81d | ||
|
|
14bcb6c08a | ||
|
|
09d374f626 | ||
|
|
072d5ae330 | ||
|
|
3b0e2c677d | ||
|
|
4f05d3dae6 | ||
|
|
d96351763f | ||
|
|
a0dd1884b3 | ||
|
|
a4ff58e9ee | ||
|
|
447941abe0 | ||
|
|
9835b96e87 | ||
|
|
9f4c248e4c | ||
|
|
98ccef732f | ||
|
|
dac50fe0fb | ||
|
|
76e0fab33a | ||
|
|
585c5fd4ca | ||
|
|
a58ce8aeb3 | ||
|
|
8f99510af0 | ||
|
|
13684f7c0b | ||
|
|
5f0358a347 | ||
|
|
647ae456e5 | ||
|
|
1b7ff084ab | ||
|
|
1ed6e25d1b | ||
|
|
db17e19699 | ||
|
|
3de89eaaf7 | ||
|
|
d50152dd1a | ||
|
|
2f02ea4276 | ||
|
|
b2ef809de1 | ||
|
|
c87fc10376 | ||
|
|
a00b87790b | ||
|
|
ca5f81417f | ||
|
|
40a02cc0f7 | ||
|
|
49331635b2 | ||
|
|
0c4da80c93 | ||
|
|
7bc4b8840a | ||
|
|
5a59b97257 | ||
|
|
5a33fba75e | ||
|
|
0c74ebbc45 | ||
|
|
2865a611e7 | ||
|
|
f2be286515 | ||
|
|
2c3a5c3b8f | ||
|
|
c54c1cdb65 | ||
|
|
8abefb8f8d | ||
|
|
6ffe28a8a4 | ||
|
|
7ab44886c4 | ||
|
|
fbfae98d6d | ||
|
|
c7ceb9d6b9 | ||
|
|
3f2b77fd59 | ||
|
|
3050986164 | ||
|
|
c28fd138c2 | ||
|
|
b480903c7a | ||
|
|
46a0e82258 | ||
|
|
a58c9b1a62 | ||
|
|
f3cd5b8b36 | ||
|
|
2065f3588b | ||
|
|
f792b38ea3 | ||
|
|
4f6bd16f3a | ||
|
|
c51ea575ca | ||
|
|
9efac80271 | ||
|
|
eeb576a927 | ||
|
|
3af9729e5b | ||
|
|
de082626ab | ||
|
|
9f1d613a2d | ||
|
|
a085d55d13 | ||
|
|
c2abc89a3b | ||
|
|
aa1d23e08b | ||
|
|
ee9573327c | ||
|
|
f27dd94945 | ||
|
|
6f0d3b48ba | ||
|
|
b665f2cb4e | ||
|
|
ed424ad544 | ||
|
|
50dbd5eccd | ||
|
|
01d7d6bac3 | ||
|
|
ce925f5e56 | ||
|
|
a7403195ba | ||
|
|
3a5c61797c | ||
|
|
467e4df7dc | ||
|
|
24ecdbe75b | ||
|
|
b654424465 | ||
|
|
d91e14abc6 | ||
|
|
a08e70781a | ||
|
|
a24840803c | ||
|
|
7e7522d4b7 | ||
|
|
a61dd5701a | ||
|
|
5b08f283e5 | ||
|
|
50053a52dc | ||
|
|
4a8a712868 | ||
|
|
e41b196977 | ||
|
|
6c59bf4203 | ||
|
|
bb77b2d525 | ||
|
|
293c5a40f3 | ||
|
|
994f8d7155 | ||
|
|
b38d00ce2d | ||
|
|
141a276c5b | ||
|
|
1c1300ce5a | ||
|
|
1ccc8d1a25 | ||
|
|
67b7c86755 | ||
|
|
3ee2ea1871 | ||
|
|
3b4f40635a | ||
|
|
c644d1609f | ||
|
|
d843091a4d | ||
|
|
6fad095730 | ||
|
|
6af8b52376 | ||
|
|
fca6cb11b6 | ||
|
|
753427f262 | ||
|
|
6fbe03adb3 | ||
|
|
f78db220bc | ||
|
|
63248b0fa2 | ||
|
|
cd122ce263 | ||
|
|
e097b7a0a1 | ||
|
|
32b8c8ed43 | ||
|
|
5220b03f0f | ||
|
|
336ea14422 | ||
|
|
56c54e4c8c | ||
|
|
f4c0499078 | ||
|
|
4964008511 | ||
|
|
c5ecdb840d | ||
|
|
0dbcda5710 | ||
|
|
8c0f391548 | ||
|
|
7f57e96335 | ||
|
|
93fae1ee68 | ||
|
|
650c2c88dd | ||
|
|
3f3af68582 | ||
|
|
8cdbd9f81f | ||
|
|
b76bfedf4b | ||
|
|
eecb5a0f42 | ||
|
|
b67644ba35 | ||
|
|
56db0426a4 | ||
|
|
5463c8e6cb | ||
|
|
fd41cafc4b | ||
|
|
8dfdf55dff | ||
|
|
a0e660f6b4 | ||
|
|
cd1d0031e6 | ||
|
|
4216c412b3 | ||
|
|
bd19914132 | ||
|
|
9a6336adb9 | ||
|
|
e3900b9062 | ||
|
|
ea0fb3b410 | ||
|
|
c3939e3b25 | ||
|
|
f0553720d6 | ||
|
|
3c062443f6 | ||
|
|
b9fb0b9c5f | ||
|
|
65512dc434 | ||
|
|
b8915f11a2 | ||
|
|
c0078ce97d | ||
|
|
9971052a78 | ||
|
|
7db0a31cc5 | ||
|
|
5e6f3a51b5 | ||
|
|
c37893847a | ||
|
|
1d37982d02 | ||
|
|
41a314d6d6 | ||
|
|
2dfc160e30 | ||
|
|
5f8a927846 | ||
|
|
97b3b9a6f8 | ||
|
|
cb68b70d52 | ||
|
|
66debbc730 | ||
|
|
9056d53474 | ||
|
|
ca51c34157 | ||
|
|
7fc28baf96 | ||
|
|
439029cafe | ||
|
|
dc5373ae27 | ||
|
|
f9ec73cd05 | ||
|
|
5668fc161f | ||
|
|
1d6f296d10 | ||
|
|
913944c607 | ||
|
|
fd3ff7b703 | ||
|
|
cdc670268a | ||
|
|
4fed6630ec | ||
|
|
06001a778f | ||
|
|
f93df3b5c3 | ||
|
|
fcd2ddcc14 | ||
|
|
51e6ffb24f | ||
|
|
0c77cccb9e | ||
|
|
d928d3ff55 | ||
|
|
4c9001901e | ||
|
|
da25e72668 | ||
|
|
16bf46506a | ||
|
|
0df1b2c408 | ||
|
|
226b51d8db | ||
|
|
cd7624feb5 | ||
|
|
bd24b644c9 | ||
|
|
ed02a06bb8 | ||
|
|
5b7e79b979 | ||
|
|
bfd48eeeb2 | ||
|
|
4225f0aec2 | ||
|
|
6b686e402e | ||
|
|
dd79ec38e4 | ||
|
|
898c677ffb | ||
|
|
a7e06f4e4b | ||
|
|
4b2f3cedc7 | ||
|
|
32891867f2 | ||
|
|
0ab4f4a7f9 | ||
|
|
b47de8b042 | ||
|
|
934f794d20 | ||
|
|
9317719814 | ||
|
|
4676cfeee2 | ||
|
|
8be44dad82 | ||
|
|
617f75851b | ||
|
|
fc3901676b | ||
|
|
fcfb2372b9 | ||
|
|
36098af5eb | ||
|
|
d863fa0c80 | ||
|
|
1f67a57d7b | ||
|
|
9d7d9f3103 | ||
|
|
8d9691cc6f | ||
|
|
6c564cb720 | ||
|
|
4b32e9bd30 | ||
|
|
23a046d889 | ||
|
|
cdb34032bc | ||
|
|
74f4dbd7e6 | ||
|
|
8889759f33 | ||
|
|
372a5dfe1a | ||
|
|
22988f9e28 | ||
|
|
de2b149056 | ||
|
|
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 | ||
|
|
353035e9ca | ||
|
|
660d227ac7 | ||
|
|
b9dcfef551 | ||
|
|
6b74e358dc |
No files matched your search
@@ -0,0 +1,43 @@
|
||||
name: CMake
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: install_dependencies
|
||||
run: |
|
||||
sudo apt-get update -y -qq
|
||||
sudo apt-get install libsdl2-dev
|
||||
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Configure CMake
|
||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
|
||||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
|
||||
|
||||
- name: Build
|
||||
# Build your program with the given configuration
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Test
|
||||
working-directory: ${{github.workspace}}/build
|
||||
# Execute tests defined by the CMake configuration.
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ctest -C ${{env.BUILD_TYPE}}
|
||||
+10
@@ -7,8 +7,14 @@ out/
|
||||
*.o
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
CMakeFiles
|
||||
cmake_install.cmake
|
||||
|
||||
# Ignore Visual Studio configuration files
|
||||
CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore generated executables
|
||||
dingusppc
|
||||
@@ -21,4 +27,8 @@ Thumb.db
|
||||
# IDE ignores
|
||||
build
|
||||
build-*
|
||||
*.dir
|
||||
*.user
|
||||
DerivedData
|
||||
*.xcodeproj/project.xcworkspace
|
||||
*.xcodeproj/xcuserdata
|
||||
@@ -1,3 +1,7 @@
|
||||
[submodule "thirdparty/cubeb"]
|
||||
path = thirdparty/cubeb
|
||||
url = https://github.com/DingusDevOrg/cubeb.git
|
||||
[submodule "thirdparty/capstone"]
|
||||
path = thirdparty/capstone
|
||||
url = https://github.com/maximumspatium/capstone.git
|
||||
branch = next
|
||||
+130
-47
@@ -4,31 +4,85 @@ project(dingusppc)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
#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})
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
|
||||
else() # Windows build relies on vcpkg
|
||||
# pick up system wide vcpkg if exists
|
||||
if (DEFINED ENV{VCPKG_ROOT} AND EXISTS $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
message(STATUS "Using system vcpkg at $ENV{VCPKG_ROOT}")
|
||||
set(vcpkg_toolchain_file $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
|
||||
# check Github Actions vcpkg installation
|
||||
elseif (DEFINED ENV{VCPKG_INSTALLATION_ROOT} AND EXISTS $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
message(STATUS "Using system vcpkg at $ENV{VCPKG_INSTALLATION_ROOT}")
|
||||
set(vcpkg_toolchain_file $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
|
||||
# otherwise, fetch vcpkg from Github
|
||||
else()
|
||||
message(STATUS "Fetching latest vcpkg from Github...")
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(vcpkg GIT_REPOSITORY https://github.com/microsoft/vcpkg.git)
|
||||
FetchContent_MakeAvailable(vcpkg)
|
||||
set(vcpkg_toolchain_file ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake)
|
||||
endif()
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE ${vcpkg_toolchain_file})
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
add_compile_definitions(SDL_MAIN_HANDLED)
|
||||
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)
|
||||
# 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/")
|
||||
|
||||
#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")
|
||||
@@ -37,60 +91,89 @@ add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
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}/utils"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
# "${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
# ${LIBSOUNDIO_HEADERS})
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/CLI11/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
|
||||
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.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:debugger>
|
||||
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>)
|
||||
|
||||
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)
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main 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})
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc PRIVATE capstone)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
|
||||
else()
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(testppc PRIVATE capstone)
|
||||
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 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 PRIVATE capstone)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
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,28 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "x64-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "clang_cl_x64" ],
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"variables": []
|
||||
},
|
||||
{
|
||||
"name": "x64-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Release",
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "clang_cl_x64" ],
|
||||
"variables": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -8,12 +8,11 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs,
|
||||
including those of the PowerMac G3 Beige.
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the PowerMac G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
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.
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
|
||||
## How to Use
|
||||
|
||||
@@ -21,23 +20,46 @@ This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
|
||||
-realtime
|
||||
```
|
||||
-r, --realtime
|
||||
```
|
||||
|
||||
Run the emulator in runtime.
|
||||
|
||||
-debugger
|
||||
```
|
||||
-d, --debugger
|
||||
```
|
||||
|
||||
Enter the interactive debugger.
|
||||
|
||||
You must also provide config.txt.
|
||||
```
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
|
||||
As of now, only the Power Macintosh G3 Beige is implemented.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You'll need to install development tools first.
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you'll need to run
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
```
|
||||
mkdir build
|
||||
@@ -47,9 +69,12 @@ make dingusppc
|
||||
```
|
||||
You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
Due to the incomplete status of the program at this time, only Loguru is needed to compile the program. It is already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
Future versions may drop SDL 2 as a requirement.
|
||||
|
||||
Future versions will include SDL 2 as a requirement.
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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/memctrl/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;
|
||||
}
|
||||
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mmu_write_vmem<uint8_t>(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 PRIVATE SDL2::SDL2)
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Non-standard low-level bitwise operations. */
|
||||
|
||||
#ifndef BIT_OPS_H
|
||||
#define BIT_OPS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if defined(__GNUG__) && !defined(__clang__) // GCC, mybe ICC but not Clang
|
||||
|
||||
# include <x86intrin.h>
|
||||
|
||||
# define ROTL_32(x, n) (_rotl((x), (n)))
|
||||
# define ROTR_32(x, n) (_rotr((x), (n)))
|
||||
|
||||
#elif defined(_MSC_VER) // MSVC
|
||||
|
||||
# include <intrin.h>
|
||||
|
||||
# define ROTL_32(x, n) (_rotl((x), (n)))
|
||||
# define ROTR_32(x, n) (_rotr((x), (n)))
|
||||
|
||||
#else
|
||||
|
||||
// cyclic rotation idioms that modern compilers will
|
||||
// recognize and generate very compact code for
|
||||
// evolving specific machine instructions
|
||||
|
||||
inline unsigned ROTL_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x << n) | (x >> (32 - n));
|
||||
}
|
||||
|
||||
inline unsigned ROTR_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline T extract_bits(T val, int pos, int len) {
|
||||
return (val >> pos) & (((T)1 << len) - 1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void insert_bits(T &old_val, T new_val, int pos, int len) {
|
||||
T mask = (((T)1 << len) - 1) << pos;
|
||||
old_val = (old_val & ~mask) | ((new_val << pos) & mask);
|
||||
}
|
||||
|
||||
/* Return true if the specified bit is different in the given numbers. */
|
||||
static inline bool bit_changed(uint64_t old_val, uint64_t new_val, int bit_num) {
|
||||
return (old_val ^ new_val) & (1ULL << bit_num);
|
||||
}
|
||||
|
||||
static inline bool bit_set(const uint64_t val, const int bit_num) {
|
||||
return !!(val & (1ULL << bit_num));
|
||||
}
|
||||
|
||||
#endif // BIT_OPS_H
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <core/hostevents.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
void EventManager::poll_events()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
events_captured++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we;
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->post_event(we);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
key_downs++;
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
key_ups++;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_motions++;
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 EVENT_MANAGER_H
|
||||
#define EVENT_MANAGER_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
enum EventType : uint16_t {
|
||||
EVENT_UNKNOWN = 0,
|
||||
EVENT_WINDOW = 100,
|
||||
EVENT_KEYBOARD = 200,
|
||||
EVENT_MOUSE = 300,
|
||||
};
|
||||
|
||||
class BaseEvent {
|
||||
public:
|
||||
BaseEvent(EventType type) { this->type = type; };
|
||||
EventType type;
|
||||
};
|
||||
|
||||
class WindowEvent : public BaseEvent {
|
||||
public:
|
||||
WindowEvent() : BaseEvent(EventType::EVENT_WINDOW) {};
|
||||
|
||||
uint16_t sub_type;
|
||||
uint32_t window_id;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
static EventManager* get_instance() {
|
||||
if (!event_manager) {
|
||||
event_manager = new EventManager();
|
||||
}
|
||||
return event_manager;
|
||||
};
|
||||
|
||||
using EventHandler = std::function<void(const BaseEvent&)>;
|
||||
|
||||
void poll_events();
|
||||
|
||||
void register_handler(const EventType event_type, EventHandler&& eh) {
|
||||
this->_handlers[event_type].emplace_back(std::move(eh));
|
||||
};
|
||||
|
||||
void post_event(const BaseEvent& event) {
|
||||
auto type = event.type;
|
||||
|
||||
if( _handlers.find(type) == _handlers.end() )
|
||||
return;
|
||||
|
||||
auto&& handlers = _handlers.at(type);
|
||||
|
||||
for(auto&& handler : handlers)
|
||||
handler(event);
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
|
||||
std::map<EventType, std::list<EventHandler>> _handlers;
|
||||
|
||||
uint64_t events_captured = 0;
|
||||
uint64_t unhandled_events = 0;
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint64_t mouse_motions = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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 MATH_UTILS_H
|
||||
#define MATH_UTILS_H
|
||||
|
||||
inline void _u32xu64(uint32_t a, uint64_t b, uint32_t &hi, uint64_t &lo)
|
||||
{
|
||||
uint64_t p0 = (b & 0xffffffff) * a;
|
||||
uint64_t p1 = (b >> 32) * a;
|
||||
lo = p0 + (p1 << 32);
|
||||
hi = (p1 >> 32) + (lo < p0);
|
||||
}
|
||||
|
||||
inline void _u32xu64(uint32_t a, uint64_t b, uint64_t &hi, uint32_t &lo)
|
||||
{
|
||||
uint64_t p0 = (b & 0xffffffff) * a;
|
||||
uint64_t p1 = (b >> 32) * a;
|
||||
lo = (uint32_t)p0;
|
||||
hi = (p0 >> 32) + p1;
|
||||
}
|
||||
|
||||
inline void _u64xu64(uint64_t a, uint64_t b, uint64_t &hi, uint64_t &lo)
|
||||
{
|
||||
uint32_t p0h; uint64_t p0l; _u32xu64((uint32_t)b, a, p0h, p0l);
|
||||
uint64_t p1h; uint32_t p1l; _u32xu64(b >> 32, a, p1h, p1l);
|
||||
lo = p0l + ((uint64_t)p1l << 32);
|
||||
hi = p0h + p1h + (lo < p0l);
|
||||
}
|
||||
|
||||
#endif // MATH_UTILS_H
|
||||
@@ -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", (long long unsigned)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", (long long unsigned)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,125 @@
|
||||
/*
|
||||
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 USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
#define NS_PER_MSEC 1E6
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
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")
|
||||
|
||||
|
||||
+358
-629
File diff suppressed because it is too large.
Load diff
+76
-38
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -209,8 +209,8 @@ const char* opc_flt_ldst[8] = {/* integer load and store instructions */
|
||||
"lfdu",
|
||||
"stfs",
|
||||
"stfsu",
|
||||
"sftd",
|
||||
"sftdu"};
|
||||
"stfd",
|
||||
"stfdu"};
|
||||
|
||||
const char* opc_flt_ext_arith[32] = {
|
||||
/* integer load and store instructions */
|
||||
@@ -347,10 +347,10 @@ void opc_ar_im(PPCDisasmContext* ctx) {
|
||||
int32_t imm = SIGNEXT(ctx->instr_code & 0xFFFF, 15);
|
||||
|
||||
if (ctx->simplified) {
|
||||
if (((ctx->instr_code >> 26) == 0xE) & !ra) {
|
||||
if (((ctx->instr_code >> 26) == 0xE) && !ra) {
|
||||
fmt_twoop_simm(ctx->instr_str, "li", rd, imm);
|
||||
return;
|
||||
} else if (((ctx->instr_code >> 26) == 0xF) & !ra) {
|
||||
} else if (((ctx->instr_code >> 26) == 0xF) && !ra) {
|
||||
fmt_twoop_simm(ctx->instr_str, "lis", rd, imm);
|
||||
return;
|
||||
}
|
||||
@@ -954,12 +954,12 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
} else if (index == 11) { /* tlbia */
|
||||
ctx->instr_str = my_sprintf("%-8s", "tlbia");
|
||||
} else if (index == 30) { /* tlbld - 603 only */
|
||||
if (!rs & !ra)
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbld", rb);
|
||||
} else if (index == 30) { /* tlbli - 603 only */
|
||||
if (!rs & !ra)
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbli", rb);
|
||||
@@ -973,10 +973,10 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
|
||||
|
||||
if ((index == 0) | (index == 4) | (index == 6) | (index == 16) | (index == 20) |
|
||||
(index == 22) | (index == 24) | (index == 28)) {
|
||||
if ((index == 0) || (index == 4) || (index == 6) || (index == 16) || (index == 20) ||
|
||||
(index == 22) || (index == 24) || (index == 28)) {
|
||||
fmt_threeop(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else if ((index == 5) | (index == 7) | (index == 21) | (index == 23) | (index == 25) | (index == 29)) {
|
||||
} else if ((index == 5) || (index == 7) || (index == 21) || (index == 23) || (index == 25) || (index == 29)) {
|
||||
fmt_threeop_simm(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else {
|
||||
opc_illegal(ctx);
|
||||
@@ -990,7 +990,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((index == 4) | (index == 6) | (index == 16) | (index == 20) | (index == 22) |
|
||||
if ((index == 4) || (index == 6) || (index == 16) || (index == 20) || (index == 22) ||
|
||||
(index == 28)) {
|
||||
fmt_threeop(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else {
|
||||
@@ -1077,7 +1077,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
}
|
||||
}
|
||||
/* eciwx, ecowx, lhbrx, lwbrx, stwbrx, sthbrx */
|
||||
else if ((index == 9) | (index == 13) | (index == 16) | (index == 20) | (index == 24) | (index == 28)) {
|
||||
else if ((index == 9) || (index == 13) || (index == 16) || (index == 20) || (index == 24) || (index == 28)) {
|
||||
if (rc_set) {
|
||||
opc_illegal(ctx);
|
||||
return;
|
||||
@@ -1088,15 +1088,15 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
fmt_threeop(ctx->instr_str, opcode, rs, ra, rb);
|
||||
return;
|
||||
}
|
||||
} else if ((index == 18) | (index == 26)) { /* sync, eieio */
|
||||
} else if ((index == 18) || (index == 26)) { /* sync, eieio */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
return;
|
||||
}
|
||||
/* dcba, dcbf, dcbi, dcbst, dcbt, dcbz, icbi */
|
||||
else if (
|
||||
(index == 1) | (index == 2) | (index == 7) | (index == 8) | (index == 14) |
|
||||
(index == 23) | (index == 30) | (index == 31)) {
|
||||
if (rc_set | (rs != 0)) {
|
||||
(index == 1) || (index == 2) || (index == 7) || (index == 8) || (index == 14) ||
|
||||
(index == 23) || (index == 30) || (index == 31)) {
|
||||
if (rc_set || (rs != 0)) {
|
||||
opc_illegal(ctx);
|
||||
return;
|
||||
} else {
|
||||
@@ -1449,7 +1449,7 @@ void opc_group59(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) | (ra != 0))
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_twoop_flt(ctx->instr_str, "fsqrts", rs, rb);
|
||||
@@ -1462,7 +1462,7 @@ void opc_group59(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) | (ra != 0))
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_twoop_flt(ctx->instr_str, opcode, rs, rb);
|
||||
@@ -1590,7 +1590,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) | (ra != 0))
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_threeop_flt(ctx->instr_str, opcode, rs, ra, rb);
|
||||
@@ -1627,7 +1627,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) | (ra != 0))
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
@@ -1687,20 +1687,32 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
case 12: /* frsp */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "frsp", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "frsp");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 14: /* fctiw */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiw", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fctiw");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 15: /* fctiwz */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiwz", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fctiwz");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 32: /* fcmpo */
|
||||
if (rs & 3)
|
||||
@@ -1725,7 +1737,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
break;
|
||||
case 64:
|
||||
strcpy(opcode, "mcrfs");
|
||||
@@ -1738,31 +1750,52 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
break;
|
||||
case 72: /* fmr */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "fmr", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fmr");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 134: /* mtfsfi */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d", "mtfsfi", (rs >> 2), (rb >> 1));
|
||||
else {
|
||||
strcpy(opcode, "mtfsfi");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
}
|
||||
break;
|
||||
case 136: /* fnabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", "fnabs", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fnabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 264: /* fabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d, f%d", "fabs", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 583: /* mffs */
|
||||
strcpy(opcode, "mffs");
|
||||
@@ -1770,13 +1803,18 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((ra != 0) | (rb != 0))
|
||||
if ((ra != 0) || (rb != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d", opcode, rs);
|
||||
break;
|
||||
case 711: /* mtfsf */
|
||||
ctx->instr_str = my_sprintf("%-8sfm%d, r%d", "mtfsf", fm, rb);
|
||||
strcpy(opcode, "mtfsf");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d", opcode, fm, rb);
|
||||
break;
|
||||
default:
|
||||
opc_illegal(ctx);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+159
-199
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,9 +22,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PPCEMU_H
|
||||
#define PPCEMU_H
|
||||
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "endianswap.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
|
||||
@@ -35,11 +37,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//#define ILLEGAL_OP_SAFE 1
|
||||
|
||||
// Uncomment this to use GCC built-in functions.
|
||||
//#define USE_GCC_BUILTINS 1
|
||||
#define USE_GCC_BUILTINS 1
|
||||
|
||||
// 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);
|
||||
@@ -80,29 +84,37 @@ 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
|
||||
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, // decrementer
|
||||
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,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
};
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum TBR : int { TBL = 0, TBU = 1 };
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
enum PPC_VER : uint32_t {
|
||||
MPC601 = 0x00010001,
|
||||
MPC603 = 0x00030001,
|
||||
MPC604 = 0x00040001,
|
||||
MPC603E = 0x00060101,
|
||||
MPC750 = 0x00080200
|
||||
MPC601 = 0x00010001,
|
||||
MPC603 = 0x00030001,
|
||||
MPC604 = 0x00040001,
|
||||
MPC603E = 0x00060101,
|
||||
MPC603EV = 0x00070101,
|
||||
MPC750 = 0x00080200
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -144,8 +156,16 @@ SUPERVISOR MODEL
|
||||
536 - 543 are the Data BAT registers
|
||||
**/
|
||||
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
extern uint64_t timebase_counter; // used for storing time base value
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
|
||||
extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t dec_wr_timestamp;
|
||||
extern uint64_t rtc_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint32_t dec_wr_value;
|
||||
extern uint32_t tbr_freq_ghz;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
@@ -153,9 +173,6 @@ 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;
|
||||
@@ -191,13 +208,76 @@ 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. */
|
||||
@@ -215,37 +295,54 @@ enum class Except_Type {
|
||||
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_exception;
|
||||
extern bool grab_return;
|
||||
|
||||
extern bool power_on;
|
||||
extern bool int_pin;
|
||||
|
||||
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 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;
|
||||
#ifdef CPU_PROFILING
|
||||
extern uint64_t num_executed_instrs;
|
||||
extern uint64_t num_supervisor_instrs;
|
||||
extern uint64_t num_int_loads;
|
||||
extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
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_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
void ppc_opcode19();
|
||||
@@ -253,7 +350,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);
|
||||
|
||||
@@ -271,31 +369,24 @@ extern void ppc_grab_regsdauimm();
|
||||
extern void ppc_grab_regsasimm();
|
||||
extern void ppc_grab_regssauimm();
|
||||
|
||||
extern void ppc_grab_regsfpdb(bool int_rep);
|
||||
extern void ppc_grab_regsfpdab(bool int_rep);
|
||||
extern void ppc_grab_regsfpdia(bool int_rep);
|
||||
extern void ppc_grab_regsfpdiab(bool int_rep);
|
||||
extern void ppc_grab_regsfpsia(bool int_rep);
|
||||
extern void ppc_grab_regsfpsiab(bool int_rep);
|
||||
|
||||
extern void ppc_store_result_regd();
|
||||
extern void ppc_store_result_rega();
|
||||
extern void ppc_store_sfpresult(bool int_rep);
|
||||
extern void ppc_store_dfpresult(bool int_rep);
|
||||
|
||||
void ppc_changecrf0(uint32_t set_result);
|
||||
void ppc_fp_changecrf1();
|
||||
|
||||
void ppc_tbr_update();
|
||||
|
||||
/* Exception handlers. */
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
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
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
namespace dppc_interpreter {
|
||||
extern void ppc_bcctr();
|
||||
extern void ppc_bcctrl();
|
||||
extern void ppc_bclr();
|
||||
@@ -311,33 +402,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();
|
||||
@@ -345,20 +418,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();
|
||||
@@ -375,33 +441,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();
|
||||
@@ -413,25 +463,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();
|
||||
@@ -440,7 +475,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();
|
||||
@@ -452,6 +486,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();
|
||||
@@ -461,15 +496,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();
|
||||
@@ -535,11 +565,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();
|
||||
@@ -561,111 +591,39 @@ 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
|
||||
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();
|
||||
|
||||
// Gekko instructions
|
||||
extern void ppc_psq_l();
|
||||
extern void ppc_psq_lu();
|
||||
extern void ppc_psq_st();
|
||||
extern void ppc_psq_stu();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
@@ -673,15 +631,17 @@ extern void ppc_psq_stu();
|
||||
|
||||
// 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_gprs(void); /* print content of the general purpose registers */
|
||||
void print_fprs(void); /* print content of the floating-point registers */
|
||||
uint64_t get_reg(std::string& reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string& reg_name, uint64_t val); /* set reg_name to val */
|
||||
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 */
|
||||
+26
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,19 +21,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Handling of low-level PPC exceptions. */
|
||||
|
||||
#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++;
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
@@ -60,7 +61,11 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
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;
|
||||
|
||||
@@ -95,8 +100,7 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
break;
|
||||
|
||||
default:
|
||||
// printf("Unknown exception occured: %X\n", exception_type);
|
||||
// exit(-1);
|
||||
ABORT_F("Unknown exception occured: %X\n", (unsigned)exception_type);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -109,7 +113,19 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
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. */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+640
-595
File diff suppressed because it is too large.
Load diff
+745
-1053
File diff suppressed because it is too large.
Load diff
+1677
-246
File diff suppressed because it is too large.
Load diff
+86
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,13 +19,16 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
/** @file PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
@@ -33,20 +36,89 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** generic PowerPC BAT descriptor (MMU internal state) */
|
||||
typedef struct PPC_BAT_entry {
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
bool valid; /* BAT entry valid for MPC601 */
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t hi_mask; /* mask for high-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
} PPC_BAT_entry;
|
||||
|
||||
/** Block address translation types. */
|
||||
enum BATType : int {
|
||||
IBAT,
|
||||
DBAT
|
||||
};
|
||||
|
||||
extern void ibat_update(uint32_t bat_reg);
|
||||
extern void dbat_update(uint32_t bat_reg);
|
||||
/** TLB types. */
|
||||
enum TLBType : int {
|
||||
ITLB,
|
||||
DTLB
|
||||
};
|
||||
|
||||
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
/** Result of the block address translation. */
|
||||
typedef struct BATResult {
|
||||
bool hit;
|
||||
uint8_t prot;
|
||||
uint32_t phys;
|
||||
} BATResult;
|
||||
|
||||
/** Result of the page address translation. */
|
||||
typedef struct PATResult {
|
||||
uint32_t phys;
|
||||
uint8_t prot;
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define 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, bool* is_writable);
|
||||
|
||||
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);
|
||||
@@ -55,7 +127,7 @@ extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
|
||||
#endif // PPCMEMORY_H
|
||||
#endif // PPCMMU_H
|
||||
+933
-1064
File diff suppressed because it is too large.
Load diff
+294
-44
@@ -99,6 +99,98 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1)
|
||||
elif opc_str == "EXTSH.":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1) + 1
|
||||
elif opc_str == "FABS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1)
|
||||
elif opc_str == "FABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
elif opc_str == "FADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
elif opc_str == "FCTIWZ":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1)
|
||||
elif opc_str == "FCTIWZ.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
elif opc_str == "FDIV":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIV.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FDIVS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIVS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FNABS":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
|
||||
elif opc_str == "FNABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1) + 1
|
||||
elif opc_str == "FNEG":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
|
||||
elif opc_str == "FNEG.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "MULHW":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
|
||||
elif opc_str == "MULHW.":
|
||||
@@ -262,51 +354,209 @@ def extract_rot_params(line):
|
||||
pos += 16
|
||||
return (sh, mb, me)
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
out_file.write("\n")
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
|
||||
out_file.write("\n")
|
||||
|
||||
with open("ppcfloattest.txt", "r") as in_file:
|
||||
with open("ppcfloattests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
|
||||
pos = 10
|
||||
checkstring = ''
|
||||
|
||||
while pos < len(line):
|
||||
if (line[pos].isalnum()):
|
||||
checkstring += line[pos]
|
||||
|
||||
if ("RTN" in checkstring):
|
||||
if (line[pos+1:pos+2] == "I"):
|
||||
out_file.write(",round=RNI")
|
||||
checkstring = ''
|
||||
else:
|
||||
out_file.write(",round=RTN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTZ" in checkstring):
|
||||
out_file.write(",round=RTZ")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTPI" in checkstring):
|
||||
out_file.write(",round=RPI")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("VE" in checkstring):
|
||||
out_file.write(",round=VEN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("frD" in checkstring):
|
||||
out_file.write(",frD=0x" + line[pos+4:pos+20])
|
||||
checkstring = ''
|
||||
elif ("frA" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frA=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frA=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frA=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frB" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frB=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frB=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frB=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frC" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frC=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frC=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frC=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("FPSCR" in checkstring):
|
||||
out_file.write(",FPSCR=" + line[pos+3:pos+13])
|
||||
checkstring = ''
|
||||
elif ("CR" in checkstring):
|
||||
out_file.write(",CR=0x0" + line[pos+6:pos+14])
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
|
||||
# reg_id = line[pos:pos+4]
|
||||
# if reg_id.startswith("frD"):
|
||||
# out_file.write(",frD=" + line[pos+4:pos+22])
|
||||
# pos += 24
|
||||
# elif reg_id.startswith("frA"):
|
||||
# out_file.write(",frA=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frB"):
|
||||
# out_file.write(",frB=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frC"):
|
||||
# out_file.write(",frC=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("FPSCR:"):
|
||||
# out_file.write(",FPSCR=" + line[pos+7:pos+17])
|
||||
# pos += 19
|
||||
# elif reg_id.startswith("CR:"):
|
||||
# out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("VE)"):
|
||||
# out_file.write("round=VEN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TN)"):
|
||||
# out_file.write("round=RTN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TZ)"):
|
||||
# out_file.write("round=RTZ" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("NI)"):
|
||||
# out_file.write("round=RNI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("PI)"):
|
||||
# out_file.write("round=RPI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# else:
|
||||
# out_file.write("Unknown reg ID" + reg_id)
|
||||
# break
|
||||
|
||||
out_file.write("\n")
|
||||
@@ -331,9 +331,9 @@
|
||||
0xFFF00100,0xCC1F0008,lfdu,f0,0x8(r31)
|
||||
0xFFF00100,0xC1628398,lfs,f11,-0x7C68(r2)
|
||||
0xFFF00100,0xC5BE0004,lfsu,f13,0x4(r30)
|
||||
0xFFF00100,0xDBC1FFF0,sftd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,sftd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,sftdu,f0,0x8(r24)
|
||||
0xFFF00100,0xDBC1FFF0,stfd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,stfd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,stfdu,f0,0x8(r24)
|
||||
0xFFF00100,0xD01E0110,stfs,f0,0x110(r30)
|
||||
0xFFF00100,0xD58B0004,stfsu,f12,0x4(r11)
|
||||
0xFFF00100,0x7C1C5CAE,lfdx,f0,r28,r11
|
||||
@@ -362,9 +362,21 @@
|
||||
0xFFF00100,0xEDA66279,fmsubs.,f13,f6,f9,f12
|
||||
0xFFF00100,0xEC00637C,fnmsubs,f0,f0,f13,f12
|
||||
0xFFF00100,0xFE0820AF,fsel.,f16,f8,f2,f4
|
||||
0xFFF00100,0xFDA06050,fneg,f13,f12
|
||||
0xFFF00100,0xFD80EA10,fabs,f12,f29
|
||||
0xFFF00100,0xFD600110,fnabs,f11,f0
|
||||
0xFFF00100,0xFD002034,frsqrte,f8,f4
|
||||
0xFFF00100,0x7FF957AE,stfiwx,f31,r25,r10
|
||||
0xFFF00100,0xFC40F818,frsp,f2,f31
|
||||
0xFFF00100,0xFC201019,frsp.,f1,f2
|
||||
0xFFF00100,0xFDA0F81E,fctiwz,f13,f31
|
||||
0xFFF00100,0xFCA0501D,fctiw.,f5,f10
|
||||
0xFFF00100,0xFD9C0080,mcrfs,cr3,cr7
|
||||
0xFFF00100,0xFDFE058E,mtfsf,255,f0
|
||||
0xFFF00100,0xFF80F10C,mtfsfi,cr7,15
|
||||
0xFFF00100,0xFF80F10D,mtfsfi.,cr7,15
|
||||
0xFFF00100,0xFC406890,fmr,f2,f13
|
||||
0xFFF00100,0xFC20E891,fmr.,f1,f29
|
||||
|
||||
# compare instructions
|
||||
0xFFF00100,0x7C15A000,cmpw,r21,r20
|
||||
@@ -384,6 +396,7 @@
|
||||
0xFFF00100,0x7CBC04AA,lswi,r5,r28,0x20
|
||||
0xFFF00100,0x7FEF2C2A,lswx,r31,r15,r5
|
||||
0xFFF00100,0x7E000400,mcrxr,cr4
|
||||
0xFFF00100,0xFDC0008C,mtfsb0,14
|
||||
0xFFF00100,0xFFE0004C,mtfsb1,31
|
||||
0xFFF00100,0xFFE0048F,mffs.,f31
|
||||
0xFFF00100,0x7C2000A6,mfmsr,r1
|
||||
|
||||
|
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,5 +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/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -117,6 +139,7 @@ static void read_test_data() {
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
@@ -141,7 +164,132 @@ static void read_test_data() {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ntested = 0;
|
||||
@@ -155,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;
|
||||
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+456
-56
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,24 +19,40 @@ 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/ppcdisasm.h"
|
||||
#include "../cpu/ppc/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/hwinterrupt.h>
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include "memaccess.h"
|
||||
#include <utils/profiler.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint32_t str2addr(string& addr_str) {
|
||||
try {
|
||||
return stoul(addr_str, NULL, 0);
|
||||
return (uint32_t)stoul(addr_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + addr_str);
|
||||
}
|
||||
@@ -44,7 +60,7 @@ static uint32_t str2addr(string& addr_str) {
|
||||
|
||||
static uint32_t str2num(string& num_str) {
|
||||
try {
|
||||
return stol(num_str, NULL, 0);
|
||||
return (uint32_t)stol(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
@@ -52,42 +68,174 @@ static uint32_t str2num(string& num_str) {
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step -- execute single instruction" << endl;
|
||||
cout << " si -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " 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 << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " 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;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
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;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = mem_read_dbg(ctx.instr_addr, 4);
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
|
||||
cout << "Capstone initialization error" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; count > 0; count--) {
|
||||
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
|
||||
for (int i = 0; i < sizeof(code); i++) {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
}
|
||||
|
||||
const uint8_t *code_ptr = code;
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
// catch and handle F-Traps (Nanokernel calls) ourselves because
|
||||
// Capstone will likely return no meaningful assembly for them
|
||||
if ((code[0] & 0xF0) == 0xF0) {
|
||||
goto print_bin;
|
||||
}
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
print_bin:
|
||||
cout << uppercase << hex << address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << "dc.w" << "$" << hex <<
|
||||
((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
|
||||
cs_free(insn, 1);
|
||||
cs_close(&cs_handle);
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
{
|
||||
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;
|
||||
@@ -169,7 +317,8 @@ static void dump_mem(string& params) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << uppercase << hex << val << " ";
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -181,18 +330,95 @@ static void dump_mem(string& params) {
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_gprs() {
|
||||
string reg_name;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
reg_name = "R" + to_string(i);
|
||||
|
||||
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
}
|
||||
|
||||
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
|
||||
|
||||
for (auto &spr : sprs) {
|
||||
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct sigaction old_act_sigint, new_act_sigint;
|
||||
static struct sigaction old_act_sigterm, new_act_sigterm;
|
||||
static struct termios orig_termios;
|
||||
|
||||
static 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_sigint.sa_handler);
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
LOG_F(INFO, "Old terminal state restored, SIG#=%d", signum);
|
||||
|
||||
// re-post signal
|
||||
raise(signum);
|
||||
}
|
||||
#endif
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, inst_string, inst_num_str;
|
||||
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;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
|
||||
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("");
|
||||
@@ -211,16 +437,26 @@ void enter_debugger() {
|
||||
show_help();
|
||||
} else if (cmd == "quit") {
|
||||
break;
|
||||
} else if (cmd == "profile") {
|
||||
ss >> sub_cmd;
|
||||
ss >> profile_name;
|
||||
|
||||
if (sub_cmd == "show") {
|
||||
gProfilerObj->print_profile(profile_name);
|
||||
} else if (sub_cmd == "reset") {
|
||||
gProfilerObj->reset_profile(profile_name);
|
||||
} else {
|
||||
cout << "Unknown/empty subcommand " << sub_cmd << endl;
|
||||
}
|
||||
}
|
||||
#ifdef PROFILER
|
||||
else if (cmd == "profiler") {
|
||||
cout << "Number of Supervisor Instructions Executed:" << supervisor_inst_num << endl;
|
||||
cout << "Exception Handler Ran:" << exceptions_performed << endl;
|
||||
cout << "Number of MMU Translations:" << mmu_translations_num << endl;
|
||||
}
|
||||
#endif
|
||||
else if (cmd == "regs") {
|
||||
print_gprs();
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
#endif
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
@@ -248,20 +484,54 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
ppc_exec_single();
|
||||
int count;
|
||||
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
try {
|
||||
count = str2num(expr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
count = 1;
|
||||
}
|
||||
} else {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
for (; --count >= 0;) {
|
||||
ppc_exec_single();
|
||||
}
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
addr = (uint32_t)get_reg(addr_str) + 4;
|
||||
ppc_exec_until(addr);
|
||||
} else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
ppc_exec_until(addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "disas") {
|
||||
} else if (cmd == "go") {
|
||||
power_on = true;
|
||||
ppc_exec(); // won't return!
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
@@ -270,35 +540,165 @@ void enter_debugger() {
|
||||
cout << "disas: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
inst_num_str = expr_str.substr(0, expr_str.find_first_of(","));
|
||||
inst_grab = stol(inst_num_str, NULL, 0);
|
||||
addr_str = expr_str.substr(expr_str.find_first_of(",") + 1);
|
||||
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 */
|
||||
addr = get_reg(addr_str);
|
||||
if (context == 2 && (addr_str == "pc" || addr_str == "PC")) {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
} else {
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
disasm(inst_grab, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
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 = (uint32_t)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") {
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->printenv();
|
||||
} else if (cmd == "setenv") {
|
||||
string var_name, value;
|
||||
ss >> var_name;
|
||||
ss >> value;
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->setenv(var_name, value);
|
||||
#ifndef _WIN32
|
||||
} else if (cmd == "nvedit") {
|
||||
cout << "===== press CNTRL-C to save =====" << endl;
|
||||
|
||||
// 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 &= ~(ISIG | NOFLSH | ICANON | ECHOCTL);
|
||||
new_termios.c_lflag |= NOFLSH | ECHONL;
|
||||
|
||||
// new_termios.c_iflag &= ~(ICRNL | IGNCR);
|
||||
// new_termios.c_iflag |= INLCR;
|
||||
|
||||
// new_termios.c_oflag &= ~(ONOCR | ONLCR);
|
||||
// new_termios.c_oflag |= OPOST | OCRNL | ONLRET;
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
||||
|
||||
// save original signal handler for SIGINT
|
||||
// then redirect SIGINT to new handler
|
||||
memset(&new_act_sigint, 0, sizeof(new_act_sigint));
|
||||
new_act_sigint.sa_handler = mysig_handler;
|
||||
sigaction(SIGINT, &new_act_sigint, &old_act_sigint);
|
||||
|
||||
// save original signal handler for SIGTERM
|
||||
// then redirect SIGTERM to new handler
|
||||
memset(&new_act_sigterm, 0, sizeof(new_act_sigterm));
|
||||
new_act_sigterm.sa_handler = mysig_handler;
|
||||
sigaction(SIGTERM, &new_act_sigterm, &old_act_sigterm);
|
||||
|
||||
getline(cin, inp, '\x03');
|
||||
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act_sigint.sa_handler);
|
||||
|
||||
// restore original signal handler for SIGTERM
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->setenv("nvramrc", inp);
|
||||
#endif
|
||||
#ifdef DEBUG_CPU_INT
|
||||
} else if (cmd == "amicint") {
|
||||
string value;
|
||||
int irq_id;
|
||||
ss >> value;
|
||||
try {
|
||||
irq_id = str2num(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
InterruptCtrl* int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
int_ctrl->ack_int(irq_id, 1);
|
||||
} else if (cmd == "viaint") {
|
||||
string value;
|
||||
int irq_bit;
|
||||
ss >> value;
|
||||
try {
|
||||
irq_bit = str2num(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
ppc_state.pc -= 4;
|
||||
via_obj->assert_int(irq_bit);
|
||||
#endif
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
|
||||
@@ -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 DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
|
||||
+19
-3
@@ -1,6 +1,22 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
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/ata/*.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)
|
||||
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
|
||||
@@ -1,396 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "displayid.h"
|
||||
#include "endianswap.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "pcidevice.h"
|
||||
#include <atirage.h>
|
||||
#include <cstdint>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
this->vram_size = mem_amount << 20;
|
||||
|
||||
/*allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
|
||||
/* configure PCI parameters */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[8], 0x0300005C);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
if (this->vram_ptr) {
|
||||
delete this->vram_ptr;
|
||||
}
|
||||
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
uint32_t ATIRage::size_dep_read(uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATI Rage read: invalid size %d", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::size_dep_write(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
const char* reg_name;
|
||||
|
||||
switch (reg_offset & ~3) {
|
||||
case ATI_CRTC_H_TOTAL_DISP:
|
||||
reg_name = "CRTC_H_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_H_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_H_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_V_TOTAL_DISP:
|
||||
reg_name = "CRTC_V_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_V_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_V_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
reg_name = "CRTC_OFF_PITCH";
|
||||
break;
|
||||
case ATI_CRTC_INT_CNTL:
|
||||
reg_name = "CRTC_INT_CNTL";
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
reg_name = "CRTC_GEN_CNTL";
|
||||
break;
|
||||
case ATI_DSP_CONFIG:
|
||||
reg_name = "DSP_CONFIG";
|
||||
break;
|
||||
case ATI_DSP_ON_OFF:
|
||||
reg_name = "DSP_ON_OFF";
|
||||
break;
|
||||
case ATI_MEM_BUF_CNTL:
|
||||
reg_name = "MEM_BUF_CNTL";
|
||||
break;
|
||||
case ATI_MEM_ADDR_CFG:
|
||||
reg_name = "MEM_ADDR_CFG";
|
||||
break;
|
||||
case ATI_OVR_CLR:
|
||||
reg_name = "OVR_CLR";
|
||||
break;
|
||||
case ATI_OVR_WID_LEFT_RIGHT:
|
||||
reg_name = "OVR_WID_LEFT_RIGHT";
|
||||
break;
|
||||
case ATI_OVR_WID_TOP_BOTTOM:
|
||||
reg_name = "OVR_WID_TOP_BOTTOM";
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
reg_name = "GP_IO";
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
reg_name = "CLOCK_CNTL";
|
||||
break;
|
||||
case ATI_BUS_CNTL:
|
||||
reg_name = "BUS_CNTL";
|
||||
break;
|
||||
case ATI_EXT_MEM_CNTL:
|
||||
reg_name = "EXT_MEM_CNTL";
|
||||
break;
|
||||
case ATI_MEM_CNTL:
|
||||
reg_name = "MEM_CNTL";
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
reg_name = "DAC_REGS";
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
reg_name = "DAC_CNTL";
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
reg_name = "GEN_TEST_CNTL";
|
||||
break;
|
||||
case ATI_CFG_CHIP_ID:
|
||||
reg_name = "CONFIG_CHIP_ID";
|
||||
break;
|
||||
case ATI_CFG_STAT0:
|
||||
reg_name = "CONFIG_STAT0";
|
||||
break;
|
||||
default:
|
||||
reg_name = "unknown";
|
||||
}
|
||||
|
||||
return reg_name;
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
uint32_t res;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_DAC_REGS:
|
||||
if (offset == ATI_DAC_DATA) {
|
||||
this->block_io_regs[ATI_DAC_DATA] =
|
||||
this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
/* autoincrement reading index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_R_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
size_dep_read(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
res = size_dep_read(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
size_dep_write(&this->block_io_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
||||
WRITE_WORD_LE_A(
|
||||
&this->block_io_regs[ATI_GP_IO],
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
switch (offset) {
|
||||
/* writing to read/write index registers resets color component index */
|
||||
case ATI_DAC_W_INDEX:
|
||||
case ATI_DAC_R_INDEX:
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case ATI_DAC_DATA:
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
|
||||
this->block_io_regs[ATI_DAC_W_INDEX],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]);
|
||||
/* autoincrement writing index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_W_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset),
|
||||
offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = size_dep_read(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
||||
reg_offs,
|
||||
BYTESWAP_32(value),
|
||||
size);
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x10: /* BAR 0 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
||||
}
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
default:
|
||||
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
||||
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
*p_io_base = io_base;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - io_base, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - io_base, value, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return size_dep_read(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= MEMMAP_OFFSET) {
|
||||
/* read from memory-mapped registers */
|
||||
return this->read_reg(offset - MEMMAP_OFFSET, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
size_dep_write(this->vram_ptr + offset, value, size);
|
||||
} else if (offset >= MEMMAP_OFFSET) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - MEMMAP_OFFSET, value, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include "displayid.h"
|
||||
#include "pcidevice.h"
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
};
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CLONFIG_STAT1 = 0x0094,
|
||||
ATI_CLONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_VGA_WP_SEL = 0x00B4,
|
||||
ATI_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CFG_CHIP_ID = 0x00E0,
|
||||
ATI_CFG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MEMMAP_OFFSET = 0x007FFC00UL; /* offset to memory mapped registers */
|
||||
|
||||
class ATIRage : public PCIDevice {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t mem_amount);
|
||||
~ATIRage();
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
};
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* I/O space access methods */
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
protected:
|
||||
uint32_t size_dep_read(uint8_t* buf, uint32_t size);
|
||||
void size_dep_write(uint8_t* buf, uint32_t val, uint32_t size);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
private:
|
||||
// uint32_t atirage_membuf_regs[9]; /* ATI Rage Memory Buffer Registers */
|
||||
// uint32_t atirage_scratch_regs[4]; /* ATI Rage Scratch Registers */
|
||||
// uint32_t atirage_cmdfifo_regs[3]; /* ATI Rage Command FIFO Registers */
|
||||
// uint32_t atirage_datapath_regs[12]; /* ATI Rage Data Path Registers*/
|
||||
|
||||
uint8_t block_io_regs[256] = {0};
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
uint32_t aperture_base;
|
||||
|
||||
DisplayID* disp_id;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,289 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019-20
|
||||
*/
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "endianswap.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "soundserver.h"
|
||||
#include <algorithm>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
static int awac_freqs[8] = {44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350};
|
||||
|
||||
|
||||
AWACDevice::AWACDevice()
|
||||
{
|
||||
this->audio_proc = new AudioProcessor();
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc);
|
||||
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AWACDevice::~AWACDevice()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
|
||||
delete this->audio_proc;
|
||||
}
|
||||
|
||||
void AWACDevice::set_dma_out(DMAChannel* dma_out_ch) {
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
}
|
||||
|
||||
uint32_t AWACDevice::snd_ctrl_read(uint32_t offset, int size) {
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AWACDevice::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "New sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(INFO, "AWAC subframe = %d, reg = %d, data = %08X\n", subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void convert_data(const uint8_t *in, SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
uint16_t *p_in = (uint16_t *)in;
|
||||
|
||||
for (int i = 0; i < frame_count; i += 2, p_in += 4) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[0]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[1]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[2]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[3]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_silence(SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
for (int i = 0; i < frame_count; i += 2) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static void sound_out_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
int err, frame_count;
|
||||
uint8_t *p_in;
|
||||
uint32_t buf_len, rem_len, got_len;
|
||||
struct SoundIoChannelArea *areas;
|
||||
DMAChannel *dma_ch = (DMAChannel *)outstream->userdata; /* C API baby! */
|
||||
int n_channels = outstream->layout.channel_count;
|
||||
bool stop = false;
|
||||
|
||||
//if (!dma_ch->is_active()) {
|
||||
// soundio_outstream_clear_buffer(outstream);
|
||||
// soundio_outstream_pause(outstream, true);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (frame_count_max > 512) {
|
||||
frame_count = 512;
|
||||
}
|
||||
else {
|
||||
frame_count = frame_count_max;
|
||||
}
|
||||
|
||||
buf_len = (frame_count * n_channels) << 1;
|
||||
//frame_count = frame_count_max;
|
||||
|
||||
//LOG_F(INFO, "frame_count_min=%d", frame_count_min);
|
||||
//LOG_F(INFO, "frame_count_max=%d", frame_count_max);
|
||||
//LOG_F(INFO, "channel count: %d", n_channels);
|
||||
//LOG_F(INFO, "buf_len: %d", buf_len);
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
for (rem_len = buf_len; rem_len > 0; rem_len -= got_len) {
|
||||
if (!dma_ch->get_data(rem_len, &got_len, &p_in)) {
|
||||
//LOG_F(INFO, "SndCallback: got_len = %d", got_len);
|
||||
convert_data(p_in, areas, got_len >> 2);
|
||||
//LOG_F(9, "Converted sound data, len = %d", got_len);
|
||||
} else { /* no more data */
|
||||
//memset(buf, 0, rem_len); /* fill the buffer with silence */
|
||||
//LOG_F(9, "Inserted silence, len = %d", rem_len);
|
||||
|
||||
/* fill the buffer with silence */
|
||||
//LOG_F(ERROR, "rem_len=%d", rem_len);
|
||||
insert_silence(areas, rem_len >> 2);
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
LOG_F(INFO, "pausing result: %s",
|
||||
soundio_strerror(soundio_outstream_pause(outstream, true)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
long AWACDevice::sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
AWACDevice *this_ptr = static_cast<AWACDevice*>(user_data); /* C API baby! */
|
||||
|
||||
if (!this_ptr->dma_out_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!this_ptr->dma_out_ch->get_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
void AWACDevice::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, sound_out_callback,
|
||||
status_callback, (void *)this))) {
|
||||
LOG_F(ERROR, "AWAC: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != awac_freqs[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "AWAC: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_end()
|
||||
{
|
||||
}
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converter (AWAC) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include "dbdma.h"
|
||||
#include "i2c.h"
|
||||
#include "soundserver.h"
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
|
||||
/** AWAC registers offsets. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** AWAC manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Apple source calls this kValidData but doesn't explain
|
||||
what it actually means. It seems like it's used to check
|
||||
if the sound codec is available.
|
||||
*/
|
||||
#define AWAC_AVAILABLE 0x40
|
||||
|
||||
|
||||
/** Audio processor chip (TDA7433) emulation. */
|
||||
class AudioProcessor : public I2CDevice {
|
||||
public:
|
||||
AudioProcessor() = default;
|
||||
~AudioProcessor() = default;
|
||||
|
||||
void start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
if ((sub_addr & 0xF) > 6)
|
||||
return false; /* invalid subaddress -> no acknowledge */
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
LOG_F(INFO, "TDA7433 subaddress = 0x%X, auto increment = %d", this->sub_addr, this->auto_inc);
|
||||
this->pos++;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool send_byte(uint8_t data) {
|
||||
if (!this->pos) {
|
||||
return send_subaddress(data);
|
||||
} else if (this->sub_addr <= 6) {
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X received", data);
|
||||
this->regs[this->sub_addr] = data;
|
||||
if (this->auto_inc) {
|
||||
this->sub_addr++;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; /* invalid sub_addr -> no acknowledge */
|
||||
}
|
||||
};
|
||||
|
||||
bool receive_byte(uint8_t* p_data) {
|
||||
*p_data = this->regs[this->sub_addr];
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X sent", *p_data);
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
||||
uint8_t sub_addr;
|
||||
int pos;
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
|
||||
class AWACDevice : public DMACallback {
|
||||
public:
|
||||
AWACDevice();
|
||||
~AWACDevice();
|
||||
|
||||
void set_dma_out(DMAChannel* dma_out_ch);
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* DMACallback methods */
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
protected:
|
||||
void open_stream(int sample_rate);
|
||||
|
||||
private:
|
||||
static long sound_out_callback(cubeb_stream* stream, void* user_data,
|
||||
void const* input_buffer, void* output_buffer,
|
||||
long req_frames);
|
||||
|
||||
uint32_t snd_ctrl_reg = {0};
|
||||
uint16_t control_regs[8] = {0}; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
AudioProcessor* audio_proc;
|
||||
|
||||
SoundServer *snd_server;
|
||||
|
||||
bool out_stream_ready;
|
||||
int out_sample_rate;
|
||||
|
||||
DMAChannel *dma_out_ch;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWAC_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,7 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "devices/adb.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
@@ -37,8 +39,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
#endif
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
@@ -55,8 +55,6 @@ ADB_Bus::ADB_Bus() {
|
||||
mouse_access_no = adb_relative;
|
||||
}
|
||||
|
||||
ADB_Bus::~ADB_Bus() {}
|
||||
|
||||
bool ADB_Bus::listen(int device, int reg) {
|
||||
if (device == keyboard_access_no) {
|
||||
if (adb_keybd_listen(reg)) {
|
||||
@@ -404,7 +402,7 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if ((reg != 0) | (reg != 3)) {
|
||||
if ((reg != 0) || (reg != 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -51,7 +51,7 @@ enum adb_default_values {
|
||||
class ADB_Bus {
|
||||
public:
|
||||
ADB_Bus();
|
||||
~ADB_Bus();
|
||||
~ADB_Bus() = default;
|
||||
|
||||
bool listen(int device, int reg);
|
||||
bool talk(int device, int reg, uint16_t value);
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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 Heathrow hard drive controller */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaBaseDevice::AtaBaseDevice(const std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IDE_DEV);
|
||||
|
||||
device_reset();
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_reset(const uint8_t dev_head_val)
|
||||
{
|
||||
this->r_error = 1; // Device 0 passed, Device 1 passed or not present
|
||||
|
||||
this->r_sect_count = 1;
|
||||
this->r_sect_num = 1;
|
||||
this->r_dev_ctrl = 0;
|
||||
|
||||
// set protocol signature
|
||||
if (this->device_type == DEVICE_TYPE_ATAPI) {
|
||||
this->r_cylinder_lo = 0x14;
|
||||
this->r_cylinder_hi = 0xEB;
|
||||
this->r_dev_head = dev_head_val;
|
||||
} else { // assume ATA by default
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_dev_head = 0;
|
||||
this->r_status = DRDY | DSC;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
LOG_F(WARNING, "Retrieving data from %s", this->name.c_str());
|
||||
return 0xFFFFU;
|
||||
case ATA_Reg::ERROR:
|
||||
return this->r_error;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
return this->r_sect_count;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
return this->r_sect_num;
|
||||
case ATA_Reg::CYL_LOW:
|
||||
return this->r_cylinder_lo;
|
||||
case ATA_Reg::CYL_HIGH:
|
||||
return this->r_cylinder_hi;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
return this->r_dev_head;
|
||||
case ATA_Reg::STATUS:
|
||||
// TODO: clear pending interrupt
|
||||
return this->r_status;
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
return this->r_status;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to read unknown IDE register: %x", reg_addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
LOG_F(WARNING, "Pushing data to %s", this->name.c_str());
|
||||
break;
|
||||
case ATA_Reg::FEATURES:
|
||||
this->r_features = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
this->r_sect_count = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
this->r_sect_num = value;
|
||||
break;
|
||||
case ATA_Reg::CYL_LOW:
|
||||
this->r_cylinder_lo = value;
|
||||
break;
|
||||
case ATA_Reg::CYL_HIGH:
|
||||
this->r_cylinder_hi = value;
|
||||
break;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
this->r_dev_head = value;
|
||||
break;
|
||||
case ATA_Reg::COMMAND:
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::DEV_CTRL:
|
||||
if (!(this->r_dev_ctrl & SRST) && (value & SRST)) {
|
||||
LOG_F(INFO, "%s: soft reset triggered", this->name.c_str());
|
||||
this->r_status |= BSY;
|
||||
}
|
||||
this->r_dev_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** @file Base class for ATA devices. */
|
||||
|
||||
#ifndef ATA_BASE_DEVICE_H
|
||||
#define ATA_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class AtaBaseDevice : public HWComponent, public AtaInterface
|
||||
{
|
||||
public:
|
||||
AtaBaseDevice(const std::string name);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr);
|
||||
void write(const uint8_t reg_addr, const uint16_t value);
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
int get_device_id() { return this->my_dev_id; };
|
||||
|
||||
void device_reset(const uint8_t dev_head_val = 0);
|
||||
|
||||
private:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
|
||||
protected:
|
||||
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
|
||||
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
// IDE aka task file registers
|
||||
uint8_t r_error;
|
||||
uint8_t r_features;
|
||||
uint8_t r_sect_count;
|
||||
uint8_t r_sect_num;
|
||||
uint8_t r_cylinder_lo;
|
||||
uint8_t r_cylinder_hi;
|
||||
uint8_t r_dev_head;
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_dev_ctrl;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
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 ATA interface definitions. */
|
||||
|
||||
#ifndef ATA_INTERFACE_H
|
||||
#define ATA_INTERFACE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
namespace ata_interface {
|
||||
|
||||
/** Device IDs according with the Apple ATA zero/one specification. */
|
||||
enum {
|
||||
DEVICE_ID_INVALID = -1,
|
||||
DEVICE_ID_ZERO = 0,
|
||||
DEVICE_ID_ONE = 1
|
||||
};
|
||||
|
||||
/** Device types. */
|
||||
enum {
|
||||
DEVICE_TYPE_UNKNOWN = -1,
|
||||
DEVICE_TYPE_ATA = 0,
|
||||
DEVICE_TYPE_ATAPI = 1,
|
||||
};
|
||||
|
||||
/** ATA register offsets. */
|
||||
enum ATA_Reg : int {
|
||||
DATA = 0x0,
|
||||
ERROR = 0x1, // error (read)
|
||||
FEATURES = 0x1, // features (write)
|
||||
SEC_COUNT = 0x2, // sector count
|
||||
SEC_NUM = 0x3, // sector number
|
||||
CYL_LOW = 0x4, // cylinder low
|
||||
CYL_HIGH = 0x5, // cylinder high
|
||||
DEVICE_HEAD = 0x6, // device/head
|
||||
STATUS = 0x7, // status (read)
|
||||
COMMAND = 0x7, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
};
|
||||
|
||||
/** Status register bits. */
|
||||
enum ATA_Status : int {
|
||||
ERR = 0x1,
|
||||
IDX = 0x2,
|
||||
CORR = 0x4,
|
||||
DRQ = 0x8,
|
||||
DSC = 0x10,
|
||||
DWF = 0x20,
|
||||
DRDY = 0x40,
|
||||
BSY = 0x80
|
||||
};
|
||||
|
||||
/** Error register bits. */
|
||||
enum ATA_Error : int {
|
||||
ANMF = 0x1, //no address mark
|
||||
TK0NF = 0x2, //track 0 not found
|
||||
ABRT = 0x4, //abort command
|
||||
MCR = 0x8,
|
||||
IDNF = 0x10, //id mark not found
|
||||
MC = 0x20, //media change request
|
||||
UNC = 0x40,
|
||||
BBK = 0x80 //bad block
|
||||
};
|
||||
|
||||
/** Bit definition for the device control register. */
|
||||
enum ATA_CTRL : int{
|
||||
IEN = 0x2,
|
||||
SRST = 0x4,
|
||||
HOB = 0x80,
|
||||
};
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : int {
|
||||
NOP = 0x00,
|
||||
RESET_ATAPI = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
READ_LONG = 0x22,
|
||||
READ_SECTOR_EXT = 0x24,
|
||||
WRITE_SECTOR = 0x30,
|
||||
WRITE_SECTOR_NR = 0x31,
|
||||
WRITE_LONG = 0x32,
|
||||
READ_VERIFY = 0x40,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
PACKET = 0xA0,
|
||||
IDFY_PKT_DEV = 0xA1,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
|
||||
/** Interface for ATA devices. */
|
||||
class AtaInterface {
|
||||
public:
|
||||
AtaInterface() = default;
|
||||
virtual ~AtaInterface() = default;
|
||||
virtual uint16_t read(const uint8_t reg_addr) = 0;
|
||||
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
|
||||
|
||||
virtual int get_device_id() = 0;
|
||||
};
|
||||
|
||||
/** Dummy ATA device. */
|
||||
class AtaNullDevice : public AtaInterface {
|
||||
public:
|
||||
AtaNullDevice() = default;
|
||||
~AtaNullDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) {
|
||||
// return all one's except DD7 if no device is present
|
||||
// DD7 corresponds to the BSY bit of the status register
|
||||
// The host should have a pull-down resistor on DD7
|
||||
// to prevent the software from waiting for a long time
|
||||
// for empty slots
|
||||
return 0xFF7FU;
|
||||
};
|
||||
|
||||
void write(const uint8_t reg_addr, const uint16_t val) {};
|
||||
|
||||
// invalid device ID means no real device is present
|
||||
int get_device_id() { return ata_interface::DEVICE_ID_INVALID; };
|
||||
};
|
||||
|
||||
#endif // ATA_INTERFACE_H
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 ATA hard disk emulation. */
|
||||
|
||||
#include <devices/common/ata/atahd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaHardDisk::AtaHardDisk() : AtaBaseDevice("ATA-HD")
|
||||
{
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
this->hdd_img.open(filename, std::fstream::out | std::fstream::in | std::fstream::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
} else {
|
||||
ABORT_F("AtaHardDisk: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
int AtaHardDisk::perform_command()
|
||||
{
|
||||
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
|
||||
this->r_status |= BSY;
|
||||
this->r_status &= ~DRDY;
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RESET_ATAPI:
|
||||
device_reset();
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
break;
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.read(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
break;
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.write(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
break;
|
||||
case DIAGNOSTICS: {
|
||||
this->r_status |= DRQ;
|
||||
int ret_code = this->r_error;
|
||||
this->r_status &= ~DRQ;
|
||||
return ret_code;
|
||||
}
|
||||
break;
|
||||
case IDENTIFY_DEVICE:
|
||||
this->r_status |= DRQ;
|
||||
std::memcpy(buffer, this->hd_id_data, ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRDY;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,46 +1,50 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The uniquely Gekko opcodes for the processor - ppcgekkoopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
void ppc_psq_l() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_lu() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_st() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_stu() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 ATA hard disk definitions. */
|
||||
|
||||
#ifndef ATA_HARD_DISK_H
|
||||
#define ATA_HARD_DISK_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtaHardDisk();
|
||||
~AtaHardDisk() = default;
|
||||
|
||||
void insert_image(std::string filename);
|
||||
int perform_command();
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
char * buffer = new char[1 <<17];
|
||||
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** IDE Channel (aka IDE port) emulation.
|
||||
|
||||
One IDE channel is capable of controlling up to two IDE devices.
|
||||
This class handles device registration and passing of messages
|
||||
from and to the host.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
IdeChannel::IdeChannel(const std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
this->supports_types(HWCompType::IDE_BUS);
|
||||
|
||||
this->devices[0] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
this->devices[1] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from the channel config", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to the channel config", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else {
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
IdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
IdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
REGISTER_DEVICE(Ide1, Ide1_Descriptor);
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 IDE Channel (aka IDE port) definitions. */
|
||||
|
||||
#ifndef IDE_CHANNEL_H
|
||||
#define IDE_CHANNEL_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class IdeChannel : public HWComponent
|
||||
{
|
||||
public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDEO"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
std::unique_ptr<AtaInterface> devices[2];
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <memaccess.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;
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
void DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16, nullptr), 16);
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
bool is_writable, branch_taken = false;
|
||||
|
||||
if (this->cmd_in_progress) {
|
||||
// return current command if there is data to transfer
|
||||
if (this->queue_len)
|
||||
return this->cur_cmd;
|
||||
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
|
||||
// get command code
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i", "b" and "w" bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
if (is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
|
||||
if (cmd_desc[2] & 3) {
|
||||
ABORT_F("DBDMA: cmd.w bit not implemented");
|
||||
}
|
||||
|
||||
// react to cmd.b bit
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0xC) != 0xC) {
|
||||
uint16_t br_mask = this->branch_select >> 16;
|
||||
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
|
||||
if ((cmd_desc[2] & 0xC) == 0x8) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
}
|
||||
}
|
||||
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
// all INPUT and OUTPUT commands update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::STORE_QUAD && is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len & 0xFFFFUL);
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
this->cmd_ptr += 16;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
fetch_cmd(this->cmd_ptr, &cmd_struct);
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
|
||||
|
||||
this->cur_cmd = cmd_struct.cmd_key >> 4;
|
||||
|
||||
switch (this->cur_cmd) {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
case DBDMA_Cmd::OUTPUT_LAST:
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count, &is_writable);
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_in_progress = true;
|
||||
break;
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command STORE_QUAD");
|
||||
break;
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command LOAD_QUAD");
|
||||
break;
|
||||
case DBDMA_Cmd::NOP:
|
||||
LOG_F(ERROR, "Unsupported DMA Command NOP");
|
||||
break;
|
||||
case DBDMA_Cmd::STOP:
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
this->cmd_in_progress = false;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported DMA command 0x%X", this->cur_cmd);
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
|
||||
return this->cur_cmd;
|
||||
}
|
||||
|
||||
void DMAChannel::update_irq() {
|
||||
bool is_writable;
|
||||
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
|
||||
// STOP doesn't generate interrupts
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
if (cmd_desc[2] & 0x30) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0x30) != 0x30) {
|
||||
uint16_t int_mask = this->int_select >> 16;
|
||||
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
|
||||
if ((cmd_desc[2] & 0x30) == 0x20) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
if (size != 4) {
|
||||
ABORT_F("DBDMA: non-DWORD read from a DMA channel not supported");
|
||||
}
|
||||
|
||||
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) {
|
||||
ABORT_F("DBDMA: non-DWORD writes to a DMA channel not supported");
|
||||
}
|
||||
|
||||
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(9, "New ChannelStatus value = 0x%X", new_stat);
|
||||
|
||||
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
|
||||
if ((new_stat & 0xFF) != (old_stat & 0xFF)) {
|
||||
this->ch_stat |= new_stat & 0xFF;
|
||||
}
|
||||
|
||||
// flush bit can be set at the same time the run bit is cleared.
|
||||
// That means we need to update memory before channel operation
|
||||
// is aborted to prevent data loss.
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
this->ch_stat = 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 {
|
||||
this->abort();
|
||||
this->update_irq();
|
||||
new_stat &= ~CH_STAT_ACTIVE;
|
||||
new_stat &= ~CH_STAT_DEAD;
|
||||
this->cmd_in_progress = false;
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
} else if ((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();
|
||||
}
|
||||
}
|
||||
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(9, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
this->branch_select = value & 0xFF00FFUL;
|
||||
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
|
||||
}
|
||||
|
||||
int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "DBDMA: attempt to push data to dead/idle channel");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get buffer to fill in or become idle
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
std::memcpy(this->queue_data, src_ptr, len);
|
||||
this->queue_data += len;
|
||||
this->queue_len -= len;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program if the buffer became exhausted
|
||||
if (!this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
if (this->start_cb)
|
||||
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(9, "Aborting DMA channel");
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_LO = 12,
|
||||
INT_SELECT = 16,
|
||||
BRANCH_SELECT = 20,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
enum : uint16_t {
|
||||
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;
|
||||
|
||||
namespace DBDMA_Cmd {
|
||||
enum : uint8_t {
|
||||
OUTPUT_MORE = 0,
|
||||
OUTPUT_LAST = 1,
|
||||
INPUT_MORE = 2,
|
||||
INPUT_LAST = 3,
|
||||
STORE_QUAD = 4,
|
||||
LOAD_QUAD = 5,
|
||||
NOP = 6,
|
||||
STOP = 7
|
||||
};
|
||||
};
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
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);
|
||||
int push_data(const char* src_ptr, int len);
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
|
||||
protected:
|
||||
void fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
uint8_t interpret_cmd(void);
|
||||
void update_irq();
|
||||
|
||||
void start(void);
|
||||
void resume(void);
|
||||
void abort(void);
|
||||
void pause(void);
|
||||
|
||||
private:
|
||||
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
uint32_t queue_len = 0;
|
||||
uint8_t* queue_data = 0;
|
||||
uint32_t int_select = 0;
|
||||
uint32_t branch_select = 0;
|
||||
|
||||
bool cmd_in_progress = false;
|
||||
uint8_t cur_cmd;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 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;
|
||||
};
|
||||
|
||||
class DmaInChannel {
|
||||
public:
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 */
|
||||
IDE_BUS = 1ULL << 23, /* IDE bus */
|
||||
IDE_DEV = 1ULL << 25, /* IDE device */
|
||||
SND_CODEC = 1ULL << 30, /* Sound codec */
|
||||
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,54 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
//#define DEBUG_CPU_INT // uncomment this to enable hacks for debugging HW interrupts
|
||||
|
||||
/** 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,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/>.
|
||||
*/
|
||||
|
||||
/** @file Athens clock generator emulation. */
|
||||
|
||||
/**
|
||||
Athens (Apple part# 343S1191) is a programmable clock generator ASIC
|
||||
used in the PCI Power Macintosh computers.
|
||||
It has two outputs: system clock and video aka dot clock. Both can be
|
||||
programmed using HW jumpers or I2C interface.
|
||||
This high-level emulator focuses on the Athen's I2C interface providing
|
||||
methods for querying the resulting virtual frequences.
|
||||
This is helpful especially for calculating video parameters.
|
||||
*/
|
||||
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
// set up power on values
|
||||
this->regs[AthensRegs::P2_MUX2] = 0x62;
|
||||
}
|
||||
|
||||
void AthensClocks::start_transaction()
|
||||
{
|
||||
this->pos = 0; // reset read/write position
|
||||
}
|
||||
|
||||
bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(INFO, "Athens: subaddress set to 0x%X", sub_addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AthensClocks::send_byte(uint8_t data)
|
||||
{
|
||||
switch (this->pos) {
|
||||
case 0:
|
||||
this->reg_num = data;
|
||||
this->pos++;
|
||||
break;
|
||||
case 1:
|
||||
if (this->reg_num >= ATHENS_NUM_REGS) {
|
||||
LOG_F(WARNING, "Athens: invalid register number %d", this->reg_num);
|
||||
return false; // return NACK
|
||||
}
|
||||
this->regs[this->reg_num] = data;
|
||||
if (reg_num == 3) {
|
||||
LOG_F(INFO, "Athens: dot clock frequency set to %d Hz", get_dot_freq());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Athens: too much data received!");
|
||||
return false; // return NACK
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AthensClocks::receive_byte(uint8_t* p_data)
|
||||
{
|
||||
*p_data = 0x41; // return my ID (value has been guessed)
|
||||
return true;
|
||||
}
|
||||
|
||||
int AthensClocks::get_sys_freq()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AthensClocks::get_dot_freq()
|
||||
{
|
||||
static std::vector<int> D2_commons = {7, 11, 13, 14, 15, 17, 23, 31};
|
||||
static std::vector<int> N2_commons = {
|
||||
22, 27, 28, 31, 35, 37, 38, 42, 49, 55, 56, 78, 125
|
||||
};
|
||||
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0xC0) {
|
||||
LOG_F(INFO, "Athens: dot clock disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
float out_freq = 0.0f;
|
||||
|
||||
int d2 = this->regs[AthensRegs::D2];
|
||||
int n2 = this->regs[AthensRegs::N2];
|
||||
|
||||
int post_div = 1 << (3 - (this->regs[AthensRegs::P2_MUX2] & 3));
|
||||
|
||||
if (std::find(D2_commons.begin(), D2_commons.end(), d2) == D2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested D2 value %d", d2);
|
||||
}
|
||||
|
||||
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested N2 value %d", d2);
|
||||
}
|
||||
|
||||
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
|
||||
|
||||
switch (mux) {
|
||||
case 0: // clock source -> dot cock VCO
|
||||
out_freq = ATHENS_XTAL * ((float)n2 / (float)(d2 * post_div));
|
||||
break;
|
||||
case 1: // clock source -> system clock VCO
|
||||
LOG_F(WARNING, "Athens: system clock VCO not supported yet!");
|
||||
break;
|
||||
case 2: // clock source -> crystal frequency
|
||||
out_freq = ATHENS_XTAL / post_div;
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(WARNING, "Athens: attempt to use reserved Mux value!");
|
||||
break;
|
||||
}
|
||||
|
||||
return static_cast<int>(out_freq + 0.5f);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 Athens clock generator definitions. */
|
||||
|
||||
#ifndef ATHENS_H
|
||||
#define ATHENS_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ATHENS_NUM_REGS 8
|
||||
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f; // external crystal oscillator frequency
|
||||
|
||||
namespace AthensRegs {
|
||||
|
||||
enum AthensRegs: uint8_t {
|
||||
ID = 0,
|
||||
D2 = 1,
|
||||
N2 = 2,
|
||||
P2_MUX2 = 3,
|
||||
VN_CTRL = 4, // vendor specific control bits
|
||||
BD1 = 5,
|
||||
BN1 = 6,
|
||||
P1 = 7
|
||||
};
|
||||
|
||||
}; // namespace AthensRegs
|
||||
|
||||
class AthensClocks : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
AthensClocks(uint8_t dev_addr);
|
||||
~AthensClocks() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
// methods for querying virtual frequences
|
||||
int get_sys_freq();
|
||||
int get_dot_freq();
|
||||
|
||||
private:
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t reg_num = 0;
|
||||
int pos = 0;
|
||||
|
||||
uint8_t regs[ATHENS_NUM_REGS];
|
||||
};
|
||||
|
||||
#endif // ATHENS_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
@@ -47,9 +47,7 @@ public:
|
||||
I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
~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]) {
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** @file Generic PROM device programmable over I2C. */
|
||||
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
I2CProm::I2CProm(uint8_t dev_addr, int size)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
this->rom_size = size;
|
||||
|
||||
// allocate storage for ROM data
|
||||
this->data = std::unique_ptr<uint8_t[]> (new uint8_t[this->rom_size]);
|
||||
}
|
||||
|
||||
void I2CProm::fill_memory(int start, int size, uint8_t c)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memset(&this->data[start], c, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memcpy(&this->data[start], in_data, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool I2CProm::send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::send_byte(uint8_t data) {
|
||||
LOG_F(9, "I2CRom: 0x%X received", data);
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::receive_byte(uint8_t* p_data) {
|
||||
if (this->pos >= this->rom_size) {
|
||||
this->pos = 0; // attempt to read past last byte should wrap around
|
||||
}
|
||||
*p_data = this->data[this->pos++];
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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 Generic PROM device programmable over I2C. */
|
||||
|
||||
#ifndef I2C_PROM_H
|
||||
#define I2C_PROM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class I2CProm : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
I2CProm(uint8_t dev_addr, int size);
|
||||
~I2CProm() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
// data management methods
|
||||
void fill_memory(int start, int size, uint8_t c);
|
||||
void set_memory(int start, const uint8_t* in_data, int size);
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
|
||||
int rom_size = 0;
|
||||
int pos = 0;
|
||||
uint8_t my_addr = 0xA0;
|
||||
};
|
||||
|
||||
#endif // I2C_PROM_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/**
|
||||
@@ -35,29 +36,57 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Register location and value meaning are board-dependent.
|
||||
*/
|
||||
|
||||
/**
|
||||
Machine ID register for Nubus Power Macs.
|
||||
It's located at physical address 0x5FFFFFFC and contains four bytes:
|
||||
+0 uint16_t signature = 0xA55A
|
||||
+1 uint8_t machine_type (3 - PowerMac)
|
||||
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
|
||||
*/
|
||||
class NubusMacID : public MMIODevice {
|
||||
public:
|
||||
NubusMacID(const uint16_t id) {
|
||||
this->name = "Nubus-Machine-id";
|
||||
this->id[0] = 0xA5;
|
||||
this->id[1] = 0x5A;
|
||||
this->id[2] = (id >> 8) & 0xFF;
|
||||
this->id[3] = id & 0xFF;
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~NubusMacID() = default;
|
||||
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return (offset < 4 ? this->id[offset] : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_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.
|
||||
See machines/machinegossamer.cpp for further details.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) {
|
||||
this->id = id, this->name = "Machine-id";
|
||||
this->id = id;
|
||||
this->name = "Machine-id";
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return ((offset == 4 && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size){}; /* not writable */
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,15 +22,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include "hwcomponent.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:
|
||||
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;
|
||||
MMIODevice() = default;
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual ~MMIODevice() = default;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,12 +19,15 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nvram.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
@@ -34,19 +37,23 @@ using namespace std;
|
||||
/** the signature for NVRAM backing file identification. */
|
||||
static char NVRAM_FILE_ID[] = "DINGUSPPCNVRAM";
|
||||
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size) {
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
{
|
||||
this->name = "NVRAM";
|
||||
|
||||
supports_types(HWCompType::NVRAM);
|
||||
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
this->storage = new uint8_t[ram_size];
|
||||
// allocate memory storage and fill it with zeroes
|
||||
this->storage = std::unique_ptr<uint8_t[]>(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) {
|
||||
@@ -66,9 +73,8 @@ void NVram::init() {
|
||||
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.read((char*)this->storage.get(), this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file.");
|
||||
}
|
||||
|
||||
f.close();
|
||||
@@ -82,7 +88,13 @@ void NVram::save() {
|
||||
f.write((char*)&this->ram_size, sizeof(this->ram_size));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char*)this->storage, this->ram_size);
|
||||
f.write((char*)this->storage.get(), this->ram_size);
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
static const DeviceDescription Nvram_Descriptor = {
|
||||
NVram::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,10 @@ 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 <memory>
|
||||
#include <string>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
@@ -31,18 +34,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
automatically saved to and restored from the dedicated file.
|
||||
*/
|
||||
|
||||
class NVram {
|
||||
class NVram : public HWComponent {
|
||||
public:
|
||||
NVram(std::string file_name = "nvram.bin", uint32_t ram_size = 8192);
|
||||
~NVram();
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<NVram>(new 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;
|
||||
std::string file_name; // file name for the backing file
|
||||
uint16_t ram_size; // NVRAM size
|
||||
std::unique_ptr<uint8_t[]> storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
@@ -0,0 +1,567 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Utilities for working with Apple Open Firmware and CHRP NVRAM partitions. */
|
||||
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static std::string hex2str(uint32_t n)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << setw(8) << setfill('0') << hex << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static uint32_t str2env(string& num_str) {
|
||||
try {
|
||||
return (uint32_t)stoul(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
string num_str2 = string("0x") + num_str;
|
||||
return std::stoul(num_str2, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OfConfigAppl::validate() {
|
||||
int i;
|
||||
OfConfigHdrAppl hdr;
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrAppl); 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 != OF_CFG_SIZE)
|
||||
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 OfConfigAppl::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);
|
||||
}
|
||||
|
||||
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}},
|
||||
};
|
||||
|
||||
const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
this->_config_vars.clear();
|
||||
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
// populate flags
|
||||
for (int i = 0; i < 8; i++) {
|
||||
_config_vars.push_back(std::make_pair(flag_names[i],
|
||||
((of_flags << i) & 0x80) ? "true" : "false"));
|
||||
}
|
||||
|
||||
// populate the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
_config_vars.push_back(std::make_pair(name,
|
||||
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
|
||||
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_offset + str_len) > OF_CFG_SIZE) {
|
||||
cout << "string property too long - skip it" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
char prop_val[OF_CFG_SIZE] = "";
|
||||
memcpy(prop_val, &this->buf[str_offset], str_len);
|
||||
prop_val[str_len] = '\0';
|
||||
|
||||
_config_vars.push_back(std::make_pair(name, prop_val));
|
||||
}
|
||||
}
|
||||
|
||||
return _config_vars;
|
||||
};
|
||||
|
||||
void OfConfigAppl::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 checksum 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]);
|
||||
}
|
||||
}
|
||||
|
||||
bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
int i, flag;
|
||||
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
// 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 false;
|
||||
}
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// see if one of the standard properties should be changed
|
||||
if (of_vars.find(var_name) == of_vars.end()) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
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) {
|
||||
uint32_t num;
|
||||
try {
|
||||
num = str2env(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return false;
|
||||
}
|
||||
WRITE_DWORD_BE_A(&this->buf[offset], num);
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
} else {
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]);
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
|
||||
OfConfigHdrAppl *hdr = (OfConfigHdrAppl *)&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
|
||||
// the heap is grown down from offset 0x2000 and cannot be lower than here (0x185c)
|
||||
uint16_t new_top = top + str_len - value.length();
|
||||
if (new_top < here) {
|
||||
cout << "No room in the heap!" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the old string
|
||||
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET],
|
||||
&this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
|
||||
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
if (type == OF_VAR_TYPE_STR) {
|
||||
uint16_t i_str_offset = READ_WORD_BE_A(&this->buf[offset]);
|
||||
if (i_str_offset < str_offset) {
|
||||
WRITE_WORD_BE_A(&this->buf[offset], i_str_offset + str_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
top = new_top;
|
||||
|
||||
// copy new string into NVRAM buffer char by char
|
||||
i = 0;
|
||||
for(char& ch : value) {
|
||||
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : 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();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
uint8_t OfConfigChrp::checksum_hdr(const uint8_t* data)
|
||||
{
|
||||
uint16_t sum = data[0];
|
||||
|
||||
for (int i = 2; i < 16; i++) {
|
||||
sum += data[i];
|
||||
if (sum >= 256)
|
||||
sum = (sum + 1) & 0xFFU;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::validate()
|
||||
{
|
||||
int i, pos, len;
|
||||
uint8_t sig;
|
||||
bool wip = true;
|
||||
bool of_part_found = false;
|
||||
|
||||
// search the entire 8KB NVRAM for CHRP OF config partition.
|
||||
// Bail out if an unknown partition or free space is encountered.
|
||||
// Skip over known partitions.
|
||||
for (pos = 0; wip && pos < 8192;) {
|
||||
sig = this->nvram_obj->read_byte(pos);
|
||||
switch (sig) {
|
||||
case NVRAM_SIG_OF_ENV:
|
||||
of_part_found = true;
|
||||
// fall-through
|
||||
case NVRAM_SIG_FREE:
|
||||
wip = false;
|
||||
break;
|
||||
case NVRAM_SIG_VPD:
|
||||
case NVRAM_SIG_DIAG:
|
||||
case NVRAM_SIG_OF_CFG:
|
||||
case NVRAM_SIG_MAC_OS:
|
||||
case NVRAM_SIG_ERR_LOG:
|
||||
// skip valid partitions we're not interested in
|
||||
len = (this->nvram_obj->read_byte(pos + 2) << 8) |
|
||||
this->nvram_obj->read_byte(pos + 3);
|
||||
if (!len || (len * 16) >= 8192)
|
||||
break;
|
||||
pos += len * 16;
|
||||
break;
|
||||
default:
|
||||
wip = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!of_part_found)
|
||||
return false;
|
||||
|
||||
OfConfigHdrChrp hdr;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(pos + i);
|
||||
}
|
||||
|
||||
len = BYTESWAP_16(hdr.length) * 16;
|
||||
|
||||
// sanity checks
|
||||
if (hdr.sig != NVRAM_SIG_OF_ENV || len < 16 || len > (4096 + sizeof(OfConfigHdrChrp)))
|
||||
return false;
|
||||
|
||||
// calculate partition header checksum
|
||||
uint8_t chk_sum = this->checksum_hdr((uint8_t*)&hdr);
|
||||
|
||||
if (chk_sum != hdr.checksum)
|
||||
return false;
|
||||
|
||||
len -= sizeof(OfConfigHdrChrp);
|
||||
pos += sizeof(OfConfigHdrChrp);
|
||||
|
||||
this->data_offset = pos;
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
for (i = 0; i < len; i++) {
|
||||
this->buf[i] = this->nvram_obj->read_byte(pos + i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const OfConfigImpl::config_dict& OfConfigChrp::get_config_vars() {
|
||||
int len;
|
||||
|
||||
this->_config_vars.clear();
|
||||
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
for (int pos = 0; pos < 4096;) {
|
||||
char *pname = (char *)&this->buf[pos];
|
||||
|
||||
// scan property name until '=' is encountered
|
||||
// or max length is reached
|
||||
for (len = 0; len < 32; pos++, len++) {
|
||||
if (pname[len] == '=' || pname[len] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
// empty property name -> free space reached
|
||||
if (!len) {
|
||||
this->data_length = pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pname[len] != '=') {
|
||||
cout << "no = sign found or name > 31 chars" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
char prop_name[32];
|
||||
memcpy(prop_name, pname, len);
|
||||
prop_name[len] = '\0';
|
||||
|
||||
pos++; // skip past '='
|
||||
char *pval = (char *)&this->buf[pos];
|
||||
|
||||
// determine property value length
|
||||
for (len = 0; pos < 4096; pos++, len++) {
|
||||
if (pval[len] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
// ensure each property value is null-terminated
|
||||
if (pos >= 4096) {
|
||||
cout << "ran off partition end" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
this->_config_vars.push_back(std::make_pair(prop_name, pval));
|
||||
pos++; // skip past null terminator
|
||||
}
|
||||
|
||||
return this->_config_vars;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::update_partition() {
|
||||
unsigned pos = 0;
|
||||
|
||||
memset(this->buf, 0, 4096);
|
||||
|
||||
for (auto& var : this->_config_vars) {
|
||||
if ((var.first.length() + var.second.length() + 2) >= 4096) {
|
||||
cout << "No room in the partition!" << endl;
|
||||
return false;
|
||||
}
|
||||
memcpy(&this->buf[pos], var.first.c_str(), var.first.length());
|
||||
pos += var.first.length();
|
||||
this->buf[pos++] = '=';
|
||||
memcpy(&this->buf[pos], var.second.c_str(), var.second.length());
|
||||
pos += var.second.length();
|
||||
this->buf[pos++] = '\0';
|
||||
}
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
this->nvram_obj->write_byte(this->data_offset + i, this->buf[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
bool found = false;
|
||||
|
||||
// see if the user tries to change an existing property
|
||||
for (auto& var : this->_config_vars) {
|
||||
if (var.first == var_name) {
|
||||
found = true;
|
||||
|
||||
// see if we're about to change a flag
|
||||
if (var_name.back() == '?') {
|
||||
if (value != "true" && value != "false") {
|
||||
cout << "Flag value can be 'true' or 'false'" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (value.length() > var.second.length()) {
|
||||
unsigned free_space = 4096 - this->data_length;
|
||||
if ((value.length() - var.second.length()) >= free_space) {
|
||||
cout << "No room for new data!" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var.second = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->update_partition();
|
||||
};
|
||||
|
||||
int OfConfigUtils::init()
|
||||
{
|
||||
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
return this->nvram_obj == nullptr;
|
||||
}
|
||||
|
||||
bool OfConfigUtils::open_container() {
|
||||
OfConfigImpl* cfg_obj;
|
||||
|
||||
if (this->cfg_impl == nullptr) {
|
||||
cfg_obj = new OfConfigAppl(this->nvram_obj);
|
||||
if (cfg_obj->validate()) {
|
||||
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
|
||||
return true;
|
||||
} else {
|
||||
delete(cfg_obj);
|
||||
|
||||
cfg_obj = new OfConfigChrp(this->nvram_obj);
|
||||
if (cfg_obj->validate()) {
|
||||
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
|
||||
return true;
|
||||
} else {
|
||||
delete(cfg_obj);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return this->cfg_impl->validate();
|
||||
}
|
||||
|
||||
cout << "No valid Open Firmware partition found!" << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OfConfigUtils::printenv() {
|
||||
OfConfigImpl::config_dict vars;
|
||||
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
for (auto& var : vars) {
|
||||
cout << setw(34) << left << var.first << var.second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void OfConfigUtils::setenv(string var_name, string value)
|
||||
{
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
if (!this->cfg_impl->set_var(var_name, value)) {
|
||||
cout << " Please try again" << endl;
|
||||
} else {
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/CHRP Open Firmware NVRAM partition definitions. */
|
||||
|
||||
#ifndef OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
#define OF_CFG_SIZE 0x800
|
||||
|
||||
// OF Variable types
|
||||
enum {
|
||||
OF_VAR_TYPE_INT = 1, // integer
|
||||
OF_VAR_TYPE_STR = 2, // string
|
||||
OF_VAR_TYPE_FLG = 3, // boolean flag
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint16_t sig; // >nv.1275 partition signature (= 0x1275)
|
||||
uint8_t version; // >nv.version header version (= 5)
|
||||
uint8_t num_pages; // >nv.pages number of memory pages (= 8 pages 0x100 bytes each)
|
||||
uint16_t checksum; // >nv.checksum partition checksum
|
||||
uint16_t here; // >nv.here offset to the next free byte (offset of after last string length; = 0x185c)
|
||||
uint16_t top; // >nv.top offset to the last free byte (offset of string with lowest offset; < 0x2000)
|
||||
} OfConfigHdrAppl;
|
||||
|
||||
/** ================== CHRP NVRAM partition definitions. ================== */
|
||||
|
||||
/** CHRP NVRAM partition signatures. */
|
||||
enum {
|
||||
NVRAM_SIG_OF_CFG = 0x50, // of-config (unused in Power Macintosh)
|
||||
NVRAM_SIG_VPD = 0x52, // of-vpd (unused in Power Macintosh)
|
||||
NVRAM_SIG_DIAG = 0x5F, // diagnostics partition
|
||||
NVRAM_SIG_OF_ENV = 0x70, // common partition with OF environment vars
|
||||
NVRAM_SIG_ERR_LOG = 0x72, // post-err-log
|
||||
NVRAM_SIG_FREE = 0x7F, // free space
|
||||
NVRAM_SIG_MAC_OS = 0xA0, // APL,MacOS75
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t sig; // partition signature, must be 0x70
|
||||
uint8_t checksum; // partition header checksum (sig, length & name)
|
||||
uint16_t length; // partition length in 16-byte blocks
|
||||
char name[12]; // null-terminated partition name
|
||||
} OfConfigHdrChrp;
|
||||
|
||||
// - interface
|
||||
class OfConfigImpl {
|
||||
public:
|
||||
using config_dict = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
virtual ~OfConfigImpl() = default;
|
||||
virtual bool validate() = 0;
|
||||
virtual const config_dict& get_config_vars() = 0;
|
||||
virtual bool set_var(std::string& name, std::string& val) = 0;
|
||||
};
|
||||
|
||||
// Old World implementation
|
||||
class OfConfigAppl : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
~OfConfigAppl() = default;
|
||||
|
||||
bool validate();
|
||||
const config_dict& get_config_vars();
|
||||
bool set_var(std::string& var_name, std::string& value);
|
||||
|
||||
protected:
|
||||
uint16_t checksum_partition();
|
||||
void update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
uint8_t buf[OF_CFG_SIZE];
|
||||
int size = 0;
|
||||
config_dict _config_vars;
|
||||
};
|
||||
|
||||
// New World implementation
|
||||
class OfConfigChrp : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
~OfConfigChrp() = default;
|
||||
|
||||
bool validate();
|
||||
const config_dict& get_config_vars();
|
||||
bool set_var(std::string& var_name, std::string& value);
|
||||
|
||||
protected:
|
||||
uint8_t checksum_hdr(const uint8_t* data);
|
||||
bool update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
uint8_t buf[4096];
|
||||
unsigned data_offset = 0; // offset to the OF config data
|
||||
unsigned data_length = 0; // length of the OF config data
|
||||
config_dict _config_vars;
|
||||
};
|
||||
|
||||
class OfConfigUtils {
|
||||
public:
|
||||
OfConfigUtils() = default;
|
||||
~OfConfigUtils() = default;
|
||||
|
||||
int init();
|
||||
void printenv();
|
||||
void setenv(std::string var_name, std::string value);
|
||||
|
||||
protected:
|
||||
bool open_container();
|
||||
|
||||
private:
|
||||
std::unique_ptr<OfConfigImpl> cfg_impl = nullptr;
|
||||
NVram* nvram_obj = nullptr;
|
||||
};
|
||||
|
||||
#endif // OF_NVRAM_H
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/Chaos ARBus-to-PCI Bridge emulation. */
|
||||
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
const int MultiplyDeBruijnBitPosition2[] =
|
||||
{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
||||
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
|
||||
};
|
||||
|
||||
/** finds the position of the bit that is set */
|
||||
#define WHAT_BIT_SET(val) (MultiplyDeBruijnBitPosition2[(uint32_t)(val * 0x077CB531U) >> 27])
|
||||
|
||||
BanditPciDevice::BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: PCIDevice(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_DEV);
|
||||
|
||||
// prepare the PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = dev_id;
|
||||
this->class_rev = 0x06000000 | (rev & 0xFFU);
|
||||
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
|
||||
|
||||
// set the bits in the fine address space field of the address mask register
|
||||
// that correspond to the 32MB assigned PCI address space of this Bandit.
|
||||
// This initialization is implied by the device functionality.
|
||||
this->addr_mask = 3 << ((bridge_num & 3) * 2);
|
||||
|
||||
// initial PCI number + chip mode: big endian, interrupts & VGA space disabled
|
||||
this->mode_ctrl = ((bridge_num & 3) << 2) | 3;
|
||||
|
||||
this->rd_hold_off_cnt = 8;
|
||||
}
|
||||
|
||||
uint32_t BanditPciDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
return this->addr_mask;
|
||||
case BANDIT_MODE_SELECT:
|
||||
return this->mode_ctrl;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
return this->rd_hold_off_cnt;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BanditPciDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
this->addr_mask = value;
|
||||
this->verbose_address_space();
|
||||
return;
|
||||
case BANDIT_MODE_SELECT:
|
||||
this->mode_ctrl = value;
|
||||
return;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
this->rd_hold_off_cnt = value & 0x1F;
|
||||
return;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void BanditPciDevice::verbose_address_space()
|
||||
{
|
||||
uint32_t mask;
|
||||
int bit_pos;
|
||||
|
||||
if (!this->addr_mask) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
switch (offset >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_READ;
|
||||
if (device) {
|
||||
return pci_conv_rd_data(device->pci_cfg_read(reg_offs, details), details);
|
||||
}
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
return BYTESWAP_32(this->config_addr);
|
||||
|
||||
default: // I/O space
|
||||
return pci_io_read_broadcast(offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_WRITE;
|
||||
if (device) {
|
||||
if (size == 4 && !details.offset) { // aligned DWORD writes -> fast path
|
||||
device->pci_cfg_write(reg_offs, BYTESWAP_32(value), details);
|
||||
return;
|
||||
}
|
||||
// otherwise perform necessary data transformations -> slow path
|
||||
uint32_t old_val = details.size == 4 ? 0 : device->pci_cfg_read(reg_offs, details);
|
||||
uint32_t new_val = pci_conv_wr_data(old_val, value, details);
|
||||
device->pci_cfg_write(reg_offs, new_val, details);
|
||||
return;
|
||||
}
|
||||
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
|
||||
break;
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
break;
|
||||
|
||||
default: // I/O space
|
||||
pci_io_write_broadcast(offset, size, value);
|
||||
}
|
||||
}
|
||||
|
||||
inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
int &dev_num, int &fun_num, uint8_t ®_offs,
|
||||
AccessDetails &details, PCIDevice *&device)
|
||||
{
|
||||
device = NULL;
|
||||
details.size = size;
|
||||
details.offset = offset & 3;
|
||||
fun_num = FUN_NUM();
|
||||
reg_offs = REG_NUM();
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) { // type 1 configuration command
|
||||
details.flags = PCI_CONFIG_TYPE_1;
|
||||
bus_num = BUS_NUM();
|
||||
dev_num = DEV_NUM();
|
||||
device = pci_find_device(bus_num, dev_num, fun_num);
|
||||
return;
|
||||
}
|
||||
details.flags = PCI_CONFIG_TYPE_0;
|
||||
bus_num = 0; // use dummy value for bus number
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
device = this->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
pci_dev_name = GET_STR_PROP(slot.first);
|
||||
if (!pci_dev_name.empty()) {
|
||||
this->attach_pci_device(pci_dev_name, slot.second);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
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);
|
||||
|
||||
// connnect Bandit PCI device
|
||||
this->my_pci_device = unique_ptr<BanditPciDevice>(
|
||||
new BanditPciDevice(bridge_num, name, dev_id, rev)
|
||||
);
|
||||
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
|
||||
}
|
||||
|
||||
Chaos::Chaos(std::string name) : BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Chaos control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
static const PropMap Bandit_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, Bandit_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/Chaos ARBus-to-PCI bridge definitions.
|
||||
|
||||
Bandit is a custom ARBus-to-PCI bridge used in the second generation
|
||||
of the Power Macintosh computer equipped with the PCI bus.
|
||||
|
||||
Chaos is a custom ARBus-to-PCI bridge that provides a specialized
|
||||
PCI-like bus for video called VCI. This 64-bit bus runs at the same
|
||||
frequency as the CPU bus (40-50 MHz) and connects video input/output
|
||||
devices with the CPU bus.
|
||||
|
||||
Chaos seems to be a Bandit variant without PCI configuration space.
|
||||
It's assumed to be present in some PCI Power Macintosh models of the
|
||||
first generation.
|
||||
*/
|
||||
|
||||
#ifndef BANDIT_PCI_H
|
||||
#define BANDIT_PCI_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#define BANDIT_DEV (11) // Bandit's own device number
|
||||
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
|
||||
|
||||
/* Convenient macros for parsing CONFIG_ADDR fields. */
|
||||
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
|
||||
#define DEV_NUM() ((this->config_addr >> 11) & 0x1FU)
|
||||
#define FUN_NUM() ((this->config_addr >> 8) & 0x07U)
|
||||
#define REG_NUM() ((this->config_addr ) & 0xFCU)
|
||||
|
||||
/** Bandit specific configuration registers. */
|
||||
enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
BANDIT_MODE_SELECT = 0x50,
|
||||
BANDIT_ARBUS_RD_HOLD_OFF = 0x58,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
|
||||
|
||||
/*
|
||||
Common functionality for Bandit/Chaos PCI host bridge.
|
||||
*/
|
||||
class BanditHost : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int device_postinit();
|
||||
|
||||
protected:
|
||||
uint32_t config_addr;
|
||||
|
||||
private:
|
||||
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIDevice *&device);
|
||||
};
|
||||
|
||||
/*
|
||||
PCI device for Bandit (but not for Chaos).
|
||||
*/
|
||||
class BanditPciDevice : public PCIDevice {
|
||||
public:
|
||||
BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev);
|
||||
~BanditPciDevice() = default;
|
||||
|
||||
// PCIDevice methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
protected:
|
||||
void verbose_address_space();
|
||||
|
||||
private:
|
||||
uint32_t addr_mask;
|
||||
uint32_t mode_ctrl; // controls various chip modes/features
|
||||
uint32_t rd_hold_off_cnt;
|
||||
};
|
||||
|
||||
/*
|
||||
Bandit HLE emulation class.
|
||||
*/
|
||||
class Bandit : public BanditHost {
|
||||
public:
|
||||
Bandit(int bridge_num, std::string name, int dev_id=1, int rev=3);
|
||||
~Bandit() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
|
||||
};
|
||||
|
||||
static std::unique_ptr<HWComponent> create_psx_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
unique_ptr<BanditPciDevice> my_pci_device;
|
||||
};
|
||||
|
||||
/**
|
||||
Chaos HLE emulation class.
|
||||
*/
|
||||
class Chaos : public BanditHost {
|
||||
public:
|
||||
Chaos(std::string name);
|
||||
~Chaos() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** DEC 21154 PCI-to-PCI bridge emulation. */
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/dec21154.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
// initialize PCI config header
|
||||
this->vendor_id = PCI_VENDOR_DEC;
|
||||
this->device_id = 0x0026;
|
||||
this->class_rev = 0x06040002;
|
||||
this->cache_ln_sz = 0;
|
||||
this->command = 0;
|
||||
this->status = 0x2B0;
|
||||
}
|
||||
|
||||
uint32_t DecPciBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIBridge::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case CHIP_CTRL:
|
||||
return (this->arb_ctrl << 16) | (this-> diag_ctrl << 8) | this->chip_ctrl;
|
||||
case PSERR_EVENT_DIS:
|
||||
return (this->gpio_out_en << 16) | this->pserr_event_dis;
|
||||
case SEC_CLK_CTRL:
|
||||
return this->sec_clock_ctrl;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIBridge::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case CHIP_CTRL:
|
||||
this->chip_ctrl = value & 0xFFU;
|
||||
this->diag_ctrl = (value >> 8) & 0xFFU;
|
||||
this->arb_ctrl = value >> 16;
|
||||
break;
|
||||
case PSERR_EVENT_DIS:
|
||||
this->pserr_event_dis = value & 0xFFU;
|
||||
this->gpio_out_en = (value >> 16) & 0xFFU;
|
||||
break;
|
||||
case SEC_CLK_CTRL:
|
||||
this->sec_clock_ctrl = value & 0xFFFFU;
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Dec21154_Descriptor = {
|
||||
DecPciBridge::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** DEC 21154 PCI-to-PCI bridge definitions. */
|
||||
|
||||
#ifndef DEC_P2P_H
|
||||
#define DEC_P2P_H
|
||||
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
CHIP_CTRL = 0x40,
|
||||
PSERR_EVENT_DIS = 0x64,
|
||||
SEC_CLK_CTRL = 0x68,
|
||||
};
|
||||
|
||||
class DecPciBridge : public PCIBridge {
|
||||
public:
|
||||
DecPciBridge(std::string name);
|
||||
~DecPciBridge() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154"));
|
||||
}
|
||||
|
||||
// PCIDevice methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
private:
|
||||
uint8_t chip_ctrl = 0;
|
||||
uint8_t diag_ctrl = 0;
|
||||
uint16_t arb_ctrl = 0x0200;
|
||||
uint8_t pserr_event_dis = 0;
|
||||
uint8_t gpio_out_data = 0;
|
||||
uint8_t gpio_out_en = 0;
|
||||
uint8_t gpio_in_data = 0;
|
||||
uint16_t sec_clock_ctrl = 0;
|
||||
};
|
||||
|
||||
#endif // DEC_P2P_H
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/pcibridge.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
PCIBridge::PCIBridge(std::string name) : PCIDevice(name)
|
||||
{
|
||||
this->num_bars = 2;
|
||||
this->hdr_type = 1;
|
||||
|
||||
this->pci_rd_primary_bus = [this]() { return this->primary_bus; };
|
||||
this->pci_rd_secondary_bus = [this]() { return this->secondary_bus; };
|
||||
this->pci_rd_subordinate_bus = [this]() { return this->subordinate_bus; };
|
||||
this->pci_rd_sec_latency_timer = [this]() { return this->sec_latency_timer; };
|
||||
this->pci_rd_sec_status = [this]() { return this->sec_status; };
|
||||
this->pci_rd_memory_base = [this]() { return this->memory_base; };
|
||||
this->pci_rd_memory_limit = [this]() { return this->memory_limit; };
|
||||
this->pci_rd_io_base = [this]() { return this->io_base; };
|
||||
this->pci_rd_io_limit = [this]() { return this->io_limit; };
|
||||
this->pci_rd_pref_mem_base = [this]() { return this->pref_mem_base; };
|
||||
this->pci_rd_pref_mem_limit = [this]() { return this->pref_mem_limit; };
|
||||
this->pci_rd_io_base_upper16 = [this]() { return this->io_base_upper16; };
|
||||
this->pci_rd_io_limit_upper16 = [this]() { return this->io_limit_upper16; };
|
||||
this->pci_rd_pref_base_upper32 = [this]() { return this->pref_base_upper32; };
|
||||
this->pci_rd_pref_limit_upper32 = [this]() { return this->pref_limit_upper32; };
|
||||
this->pci_rd_bridge_control = [this]() { return this->bridge_control; };
|
||||
|
||||
this->pci_wr_primary_bus = [this](uint8_t val) { this->primary_bus = val; };
|
||||
this->pci_wr_secondary_bus = [this](uint8_t val) { this->secondary_bus = val; };
|
||||
this->pci_wr_subordinate_bus = [this](uint8_t val) { this->subordinate_bus = val; };
|
||||
|
||||
this->pci_wr_sec_latency_timer = [this](uint8_t val) {
|
||||
this->sec_latency_timer = (this->sec_latency_timer & ~this->sec_latency_timer_cfg) |
|
||||
(val & this->sec_latency_timer_cfg);
|
||||
};
|
||||
|
||||
this->pci_wr_sec_status = [this](uint16_t val) {};
|
||||
|
||||
this->pci_wr_memory_base = [this](uint16_t val) {
|
||||
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
|
||||
this->memory_base_32 = ((this->memory_base & 0xfff0) << 16);
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit = [this](uint16_t val) {
|
||||
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
|
||||
this->memory_limit_32 = ((this->memory_limit & 0xfff0) << 16) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base = [this](uint8_t val) {
|
||||
this->io_base = (val & this->io_cfg) | (this->io_cfg & 15);
|
||||
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) | ((this->io_base & 0xf0) << 8);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit = [this](uint8_t val) {
|
||||
this->io_limit = (val & this->io_cfg) | (this->io_cfg & 15);
|
||||
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
|
||||
((this->io_limit & 0xf0) << 8)) + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_pref_mem_base = [this](uint16_t val) {
|
||||
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
|
||||
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
|
||||
((this->pref_mem_base & 0xfff0) << 16);
|
||||
};
|
||||
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
|
||||
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
|
||||
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
|
||||
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
|
||||
};
|
||||
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
|
||||
if ((this->io_base & 15) == 1)
|
||||
this->io_base_upper16 = val;
|
||||
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) |
|
||||
((this->io_base & 0xf0) << 8);
|
||||
};
|
||||
this->pci_wr_io_limit_upper16 = [this](uint16_t val) {
|
||||
if ((this->io_limit & 15) == 1)
|
||||
this->io_limit_upper16 = val;
|
||||
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
|
||||
((this->io_limit & 0xf0) << 8)) + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_pref_base_upper32 = [this](uint32_t val) {
|
||||
if ((this->pref_mem_cfg & 15) == 1)
|
||||
this->pref_base_upper32 = val;
|
||||
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
|
||||
((this->pref_mem_base & 0xfff0) << 16);
|
||||
};
|
||||
|
||||
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
|
||||
if ((this->pref_mem_cfg & 15) == 1)
|
||||
this->pref_limit_upper32 = val;
|
||||
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
|
||||
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
|
||||
bool PCIBridge::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
// FIXME: constrain region to memory range
|
||||
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
return (this->pci_rd_sec_latency_timer() << 24) |
|
||||
(this->pci_rd_subordinate_bus() << 16) |
|
||||
(this->pci_rd_secondary_bus() << 8) |
|
||||
(this->pci_rd_primary_bus());
|
||||
case PCI_CFG_IO_BASE:
|
||||
return (this->pci_rd_sec_status() << 16) |
|
||||
(this->pci_rd_io_limit() << 8) | (this->pci_rd_io_base());
|
||||
case PCI_CFG_MEMORY_BASE:
|
||||
return (this->pci_rd_memory_limit() << 16) | (this->pci_rd_memory_base());
|
||||
case PCI_CFG_PREF_MEM_BASE:
|
||||
return (this->pci_rd_pref_mem_limit() << 16) | (this->pci_rd_pref_mem_base());
|
||||
case PCI_CFG_PREF_BASE_UPPER32:
|
||||
return this->pci_rd_pref_base_upper32();
|
||||
case PCI_CFG_PREF_LIMIT_UPPER32:
|
||||
return this->pci_rd_pref_limit_upper32();
|
||||
case PCI_CFG_IO_BASE_UPPER16:
|
||||
return (this->pci_rd_io_limit_upper16() << 16) | (this->pci_rd_io_base_upper16());
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
return exp_rom_bar;
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
this->pci_wr_sec_latency_timer(value >> 24);
|
||||
this->pci_wr_subordinate_bus(value >> 16);
|
||||
this->pci_wr_secondary_bus(value >> 8);
|
||||
this->pci_wr_primary_bus(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_IO_BASE:
|
||||
this->pci_wr_sec_status(value >> 16);
|
||||
this->pci_wr_io_limit(value >> 8);
|
||||
this->pci_wr_io_base(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_MEMORY_BASE:
|
||||
this->pci_wr_memory_limit(value >> 16);
|
||||
this->pci_wr_memory_base(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_PREF_MEM_BASE:
|
||||
this->pci_wr_pref_mem_limit(value >> 16);
|
||||
this->pci_wr_pref_mem_base(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_PREF_BASE_UPPER32:
|
||||
this->pci_wr_pref_base_upper32(value);
|
||||
break;
|
||||
case PCI_CFG_PREF_LIMIT_UPPER32:
|
||||
this->pci_wr_pref_limit_upper32(value);
|
||||
break;
|
||||
case PCI_CFG_IO_BASE_UPPER16:
|
||||
this->pci_wr_io_limit_upper16(value >> 16);
|
||||
this->pci_wr_io_base_upper16(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
this->pci_wr_exp_rom_bar(value);
|
||||
break;
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
this->irq_line = value >> 24;
|
||||
this->pci_wr_bridge_control(value >> 16);
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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_BRIDGE_H
|
||||
#define PCI_BRIDGE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
|
||||
PCI_CFG_IO_BASE = 0x1C, // IO_BASE.b, IO_LIMIT.b, SEC_STATUS.w
|
||||
PCI_CFG_MEMORY_BASE = 0x20, // MEMORY_BASE.w, MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_MEM_BASE = 0x24, // PREF_MEMORY_BASE.w, PREF_MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_BASE_UPPER32 = 0x28, // PREF_BASE_UPPER32
|
||||
PCI_CFG_PREF_LIMIT_UPPER32 = 0x2c, // PREF_LIMIT_UPPER32
|
||||
PCI_CFG_IO_BASE_UPPER16 = 0x30, // IO_BASE_UPPER16.w, IO_LIMIT_UPPER16.w
|
||||
// PCI_CFG_CAP_PTR
|
||||
PCI_CFG_BRIDGE_ROM_ADDRESS = 0x38, // BRIDGE_ROM_ADDRESS
|
||||
PCI_CFG_INTERRUPT_LINE = 0x3C, // INTERRUPT_LINE.b, INTERRUPT_PIN.b, BRIDGE_CONTROL.w
|
||||
};
|
||||
|
||||
class PCIBridge : public PCIHost, public PCIDevice {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBridge(std::string name);
|
||||
~PCIBridge() = default;
|
||||
|
||||
// PCIHost methods
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
// PCIDevice methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
// MMIODevice methods
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return 0;
|
||||
};
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { };
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
std::function<uint8_t()> pci_rd_secondary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_secondary_bus;
|
||||
std::function<uint8_t()> pci_rd_subordinate_bus;
|
||||
std::function<void(uint8_t)> pci_wr_subordinate_bus;
|
||||
std::function<uint8_t()> pci_rd_sec_latency_timer;
|
||||
std::function<void(uint8_t)> pci_wr_sec_latency_timer;
|
||||
std::function<uint16_t()> pci_rd_sec_status;
|
||||
std::function<void(uint16_t)> pci_wr_sec_status;
|
||||
std::function<uint8_t()> pci_rd_io_base;
|
||||
std::function<void(uint8_t)> pci_wr_io_base;
|
||||
std::function<uint8_t()> pci_rd_io_limit;
|
||||
std::function<void(uint8_t)> pci_wr_io_limit;
|
||||
std::function<uint16_t()> pci_rd_memory_base;
|
||||
std::function<void(uint16_t)> pci_wr_memory_base;
|
||||
std::function<uint16_t()> pci_rd_memory_limit;
|
||||
std::function<void(uint16_t)> pci_wr_memory_limit;
|
||||
std::function<uint16_t()> pci_rd_pref_mem_base;
|
||||
std::function<void(uint16_t)> pci_wr_pref_mem_base;
|
||||
std::function<uint16_t()> pci_rd_pref_mem_limit;
|
||||
std::function<void(uint16_t)> pci_wr_pref_mem_limit;
|
||||
std::function<uint32_t()> pci_rd_pref_base_upper32;
|
||||
std::function<void(uint32_t)> pci_wr_pref_base_upper32;
|
||||
std::function<uint32_t()> pci_rd_pref_limit_upper32;
|
||||
std::function<void(uint32_t)> pci_wr_pref_limit_upper32;
|
||||
std::function<uint16_t()> pci_rd_io_base_upper16;
|
||||
std::function<void(uint16_t)> pci_wr_io_base_upper16;
|
||||
std::function<uint16_t()> pci_rd_io_limit_upper16;
|
||||
std::function<void(uint16_t)> pci_wr_io_limit_upper16;
|
||||
std::function<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint8_t primary_bus = 0;
|
||||
uint8_t secondary_bus = 0;
|
||||
uint8_t subordinate_bus = 0;
|
||||
uint8_t sec_latency_timer = 0; // if supportss r/w then must reset to 0
|
||||
uint16_t sec_status = 0;
|
||||
uint8_t io_base = 0;
|
||||
uint8_t io_limit = 0;
|
||||
uint16_t memory_base = 0;
|
||||
uint16_t memory_limit = 0;
|
||||
uint16_t pref_mem_base = 0;
|
||||
uint16_t pref_mem_limit = 0;
|
||||
uint32_t pref_base_upper32 = 0;
|
||||
uint32_t pref_limit_upper32 = 0;
|
||||
uint16_t io_base_upper16 = 0;
|
||||
uint16_t io_limit_upper16 = 0;
|
||||
uint16_t bridge_control = 0;
|
||||
|
||||
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
|
||||
uint8_t sec_latency_timer_cfg = 0;
|
||||
|
||||
// 0 = not writable, 0xf0 = supports 16 bit io range, 0xf1 = supports 32 bit I/O range
|
||||
uint8_t io_cfg = 0xf0;
|
||||
|
||||
// 0 = not writable, 0xfff0 = supports 32 bit memory range
|
||||
uint16_t memory_cfg = 0xfff0;
|
||||
|
||||
// 0 = not writable, 0xfff0 = supports 32 bit prefetchable memory range,
|
||||
// 0xfff1 = supports 64 bit prefetchable memory range
|
||||
uint16_t pref_mem_cfg = 0xfff0;
|
||||
|
||||
uint32_t io_base_32 = 0;
|
||||
uint32_t io_limit_32 = 0;
|
||||
uint64_t memory_base_32 = 0;
|
||||
uint64_t memory_limit_32 = 0;
|
||||
uint64_t pref_mem_base_64 = 0;
|
||||
uint64_t pref_mem_limit_64 = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_H */
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
PCIDevice::PCIDevice(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
this->pci_name = name;
|
||||
|
||||
this->pci_rd_stat = [this]() { return this->status; };
|
||||
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, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
return (this->device_id << 16) | (this->vendor_id);
|
||||
case PCI_CFG_STAT_CMD:
|
||||
return (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
case PCI_CFG_CLASS_REV:
|
||||
return this->class_rev;
|
||||
case PCI_CFG_DWORD_3:
|
||||
return (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
case PCI_CFG_SUBSYS_ID:
|
||||
return (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
case PCI_CFG_ROM_BAR:
|
||||
return this->exp_rom_bar;
|
||||
case PCI_CFG_DWORD_15:
|
||||
return (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(value >> 16);
|
||||
this->pci_wr_cmd(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(value >> 24);
|
||||
this->pci_wr_lat_timer((value >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(value & 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:
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
this->pci_wr_exp_rom_bar(value);
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
this->irq_line = value >> 24;
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::setup_bars(std::vector<BarConfig> cfg_data)
|
||||
{
|
||||
for (auto cfg_entry : cfg_data) {
|
||||
if (cfg_entry.bar_num > 5) {
|
||||
ABORT_F("BAR number %d out of range", cfg_entry.bar_num);
|
||||
}
|
||||
this->bars_cfg[cfg_entry.bar_num] = cfg_entry.bar_cfg;
|
||||
}
|
||||
|
||||
this->finish_config_bars();
|
||||
}
|
||||
|
||||
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);
|
||||
size_t exp_rom_image_size = img_file.tellg();
|
||||
if (exp_rom_image_size > 4*1024*1024) {
|
||||
throw std::runtime_error("expansion ROM file too large");
|
||||
}
|
||||
|
||||
// verify PCI struct offset
|
||||
uint16_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 > exp_rom_image_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");
|
||||
}
|
||||
|
||||
// find minimum rom size for the rom file (power of 2 >= 0x800)
|
||||
for (this->exp_rom_size = 1 << 11; this->exp_rom_size < exp_rom_image_size; this->exp_rom_size <<= 1) {}
|
||||
|
||||
// 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(), exp_rom_image_size);
|
||||
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
|
||||
this->pci_name.c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
this->pci_name.c_str(), (int)exp_rom_image_size, this->exp_rom_size);
|
||||
}
|
||||
|
||||
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::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
switch (bars_typ[bar_num]) {
|
||||
case PCIBarType::Unused:
|
||||
return;
|
||||
|
||||
case PCIBarType::Io_16_Bit:
|
||||
case PCIBarType::Io_32_Bit:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_20_Bit:
|
||||
case PCIBarType::Mem_32_Bit:
|
||||
case PCIBarType::Mem_64_Bit_Lo:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_64_Bit_Hi:
|
||||
this->bars[bar_num] = value & bar_cfg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (value != 0xFFFFFFFFUL) // don't notify the device during BAR sizing
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIDevice::finish_config_bars()
|
||||
{
|
||||
for (int bar_num = 0; bar_num < this->num_bars; bar_num++) {
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
|
||||
if (!bar_cfg) // skip unimplemented BARs
|
||||
continue;
|
||||
|
||||
if (bar_cfg & 1) {
|
||||
bars_typ[bar_num] = (bar_cfg & 0xffff0000) ? PCIBarType::Io_32_Bit :
|
||||
PCIBarType::Io_16_Bit;
|
||||
has_io_space = true;
|
||||
}
|
||||
else {
|
||||
int pci_space_type = (bar_cfg >> 1) & 3;
|
||||
switch (pci_space_type) {
|
||||
case 0:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_32_Bit;
|
||||
break;
|
||||
case 1:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_20_Bit;
|
||||
break;
|
||||
case 2:
|
||||
if (bar_num >= num_bars - 1) {
|
||||
ABORT_F("%s: BAR %d cannot be 64-bit",
|
||||
this->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else if (this->bars_cfg[bar_num+1] == 0) {
|
||||
ABORT_F("%s: 64-bit BAR %d has zero for upper 32 bits",
|
||||
this->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else {
|
||||
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
|
||||
bars_typ[bar_num ] = PCIBarType::Mem_64_Bit_Hi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
|
||||
this->pci_name.c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
}
|
||||
|
||||
void PCIDevice::map_exp_rom_mem()
|
||||
{
|
||||
uint32_t rom_addr = this->exp_rom_bar & this->exp_bar_cfg;
|
||||
if (rom_addr) {
|
||||
if (this->exp_rom_addr != rom_addr) {
|
||||
this->unmap_exp_rom_mem();
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = rom_addr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::unmap_exp_rom_mem()
|
||||
{
|
||||
if (this->exp_rom_addr) {
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_unregister_mmio_region(exp_rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_wr_exp_rom_bar(uint32_t data)
|
||||
{
|
||||
if (!this->exp_bar_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data & this->exp_bar_cfg) == this->exp_bar_cfg) {
|
||||
// doing sizing
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
} else {
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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>
|
||||
#include <vector>
|
||||
|
||||
/** 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_CAP_PTR = 0x34, // capabilities pointer
|
||||
PCI_CFG_DWORD_14 = 0x38, // reserved
|
||||
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_DEC = 0x1011,
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
PCI_VENDOR_NVIDIA = 0x10DE,
|
||||
};
|
||||
|
||||
/** PCI BAR types */
|
||||
enum PCIBarType : uint32_t {
|
||||
Unused = 0,
|
||||
Io_16_Bit,
|
||||
Io_32_Bit,
|
||||
Mem_20_Bit, // legacy type for < 1MB memory
|
||||
Mem_32_Bit,
|
||||
Mem_64_Bit_Lo,
|
||||
Mem_64_Bit_Hi
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t bar_num;
|
||||
uint32_t bar_cfg;
|
||||
} BarConfig;
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name);
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return has_io_space;
|
||||
};
|
||||
|
||||
/* 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, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
virtual void set_multi_function(bool is_multi_function) {
|
||||
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
|
||||
}
|
||||
virtual void set_irq_pin(uint8_t irq_pin) {
|
||||
this->irq_pin = irq_pin;
|
||||
}
|
||||
|
||||
// MMIODevice methods
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
|
||||
|
||||
protected:
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void setup_bars(std::vector<BarConfig> cfg_data);
|
||||
void finish_config_bars();
|
||||
void pci_wr_exp_rom_bar(uint32_t data);
|
||||
void map_exp_rom_mem();
|
||||
void unmap_exp_rom_mem();
|
||||
|
||||
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, single function
|
||||
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 cap_ptr = 0;
|
||||
uint8_t max_lat = 0;
|
||||
uint8_t min_gnt = 0;
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
bool has_io_space = false;
|
||||
int num_bars = 6;
|
||||
uint32_t bars[6] = { 0 }; // base address registers
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
||||
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types 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;
|
||||
};
|
||||
|
||||
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
case 0x04: return (uint8_t) value;
|
||||
case 0x05: return (uint8_t)(value >> 8);
|
||||
case 0x06: return (uint8_t)(value >> 16);
|
||||
case 0x07: return (uint8_t)(value >> 24);
|
||||
|
||||
case 0x08: return (uint16_t) value;
|
||||
case 0x09: return (uint16_t) (value >> 8);
|
||||
case 0x0a: return (uint16_t) (value >> 16);
|
||||
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
|
||||
|
||||
case 0x10: return value;
|
||||
case 0x11: return (value >> 8) | (value << 24);
|
||||
case 0x12: return (value >> 16) | (value << 16);
|
||||
case 0x13: return (value >> 24) | (value << 8);
|
||||
|
||||
default: return 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
#define SIZE_ARGS details.size == 4 ? 'l' : details.size == 2 ? 'w' : \
|
||||
details.size == 1 ? 'b' : '0' + details.size
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: read unimplemented config register @%02x.%c", \
|
||||
this->name.c_str(), reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: %s %s register @%02x.%c = %0*x", \
|
||||
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, pci_cfg_log(value, details) \
|
||||
)
|
||||
|
||||
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
|
||||
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
)
|
||||
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
)
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
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/hwcomponent.h>
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIDevice* dev_instance)
|
||||
{
|
||||
// return false if dev_fun_num already registered
|
||||
if (this->dev_map.count(dev_fun_num))
|
||||
return false;
|
||||
|
||||
int fun_num = dev_fun_num & 7;
|
||||
int dev_num = (dev_fun_num >> 3) & 0x1f;
|
||||
bool is_multi_function = fun_num != 0;
|
||||
|
||||
for (int other_fun_num = 0; other_fun_num < 8; other_fun_num++) {
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, other_fun_num))) {
|
||||
is_multi_function = true;
|
||||
if (is_multi_function && other_fun_num == 0) {
|
||||
this->dev_map[DEV_FUN(dev_num, other_fun_num)]->set_multi_function(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->dev_map[dev_fun_num] = dev_instance;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
if (is_multi_function && fun_num == 0) {
|
||||
dev_instance->set_multi_function(true);
|
||||
}
|
||||
|
||||
if (dev_instance->supports_io_space()) {
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
PCIBridge *bridge = dynamic_cast<PCIBridge*>(dev_instance);
|
||||
if (bridge) {
|
||||
this->bridge_devs.push_back(bridge);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool PCIHost::pci_unregister_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->remove_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void PCIHost::attach_pci_device(const std::string& dev_name, int slot_id)
|
||||
{
|
||||
this->attach_pci_device(dev_name, slot_id, "");
|
||||
}
|
||||
|
||||
PCIDevice *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, const std::string& dev_suffix)
|
||||
{
|
||||
if (!DeviceRegistry::device_registered(dev_name)) {
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
WARNING, "%s: specified PCI device %s doesn't exist",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_name.c_str()
|
||||
);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// attempt to create device object
|
||||
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
|
||||
|
||||
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
WARNING, "%s: cannot attach non-PCI device %s",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_name.c_str()
|
||||
);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// add device to the machine object
|
||||
gMachineObj->add_device(dev_name + dev_suffix, std::move(dev_obj));
|
||||
|
||||
PCIDevice *dev = dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
|
||||
|
||||
// register device with the PCI host
|
||||
this->pci_register_device(slot_id, dev);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &res)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res;
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_read_loop (offset, size, res)) {
|
||||
return res;
|
||||
}
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_write_loop(offset, size, value)) {
|
||||
return;
|
||||
}
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, BYTESWAP_SIZED(value, size)
|
||||
);
|
||||
}
|
||||
|
||||
PCIDevice *PCIHost::pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num)
|
||||
{
|
||||
for (auto& bridge : this->bridge_devs) {
|
||||
if (bridge->secondary_bus <= bus_num) {
|
||||
if (bridge->secondary_bus == bus_num) {
|
||||
if (bridge->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
return bridge->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
else if (bridge->subordinate_bus >= bus_num) {
|
||||
return bridge->pci_find_device(bus_num, dev_num, fun_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
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_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum {
|
||||
PCI_CONFIG_DIRECTION = 1,
|
||||
PCI_CONFIG_READ = 0,
|
||||
PCI_CONFIG_WRITE = 1,
|
||||
|
||||
PCI_CONFIG_TYPE = 4,
|
||||
PCI_CONFIG_TYPE_0 = 0,
|
||||
PCI_CONFIG_TYPE_1 = 4,
|
||||
};
|
||||
|
||||
/** PCI config space access details */
|
||||
typedef struct AccessDetails {
|
||||
uint8_t size;
|
||||
uint8_t offset;
|
||||
uint8_t flags;
|
||||
} AccessDetails;
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
class PCIDevice;
|
||||
class PCIBridge;
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
PCIHost() {
|
||||
this->dev_map.clear();
|
||||
io_space_devs.clear();
|
||||
};
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIDevice* dev_instance);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
|
||||
PCIDevice *attach_pci_device(const std::string& dev_name, int slot_id,
|
||||
const std::string& dev_suffix);
|
||||
|
||||
virtual bool pci_io_read_loop (uint32_t offset, int size, uint32_t &res);
|
||||
virtual bool pci_io_write_loop(uint32_t offset, int size, uint32_t value);
|
||||
|
||||
virtual uint32_t pci_io_read_broadcast (uint32_t offset, int size);
|
||||
virtual void pci_io_write_broadcast(uint32_t offset, int size, uint32_t value);
|
||||
|
||||
virtual PCIDevice *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
|
||||
|
||||
virtual uint32_t pci_t1_read(uint8_t dev, uint32_t fun, uint32_t reg, AccessDetails &details) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual void pci_t1_write(uint8_t dev, uint32_t fun, uint32_t reg, uint32_t value,
|
||||
AccessDetails &details) {};
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIDevice*> dev_map;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
std::vector<PCIBridge*> bridge_devs;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
/**
|
||||
Perform size dependent endian swapping for value that is dword from PCI config.
|
||||
|
||||
Unaligned data is handled properly by wrapping around if needed.
|
||||
*/
|
||||
inline uint32_t pci_conv_rd_data(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
// Bytes
|
||||
case 0x04:
|
||||
return value & 0xFF; // 0
|
||||
case 0x05:
|
||||
return (value >> 8) & 0xFF; // 1
|
||||
case 0x06:
|
||||
return (value >> 16) & 0xFF; // 2
|
||||
case 0x07:
|
||||
return (value >> 24) & 0xFF; // 3
|
||||
|
||||
// Words
|
||||
case 0x08:
|
||||
return BYTESWAP_16(value); // 0 1
|
||||
case 0x09:
|
||||
return BYTESWAP_16((value >> 8) & 0xFFFFU); // 1 2
|
||||
case 0x0A:
|
||||
return BYTESWAP_16((value >> 16) & 0xFFFFU); // 2 3
|
||||
case 0x0B:
|
||||
return ((value >> 16) & 0xFF00) | (value & 0xFF); // 3 0
|
||||
|
||||
// Dwords
|
||||
case 0x10:
|
||||
return BYTESWAP_32(value); // 0 1 2 3
|
||||
case 0x11:
|
||||
return ROTL_32(BYTESWAP_32(value), 8); // 1 2 3 0
|
||||
case 0x12:
|
||||
return ROTL_32(BYTESWAP_32(value), 16); // 2 3 0 1
|
||||
case 0x13:
|
||||
return ROTR_32(BYTESWAP_32(value), 8); // 3 0 1 2
|
||||
default:
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Perform size dependent endian swapping for v2, then merge v2 with v1 under
|
||||
control of a mask generated according with the size parameter.
|
||||
|
||||
Unaligned data is handled properly by wrapping around if needed.
|
||||
*/
|
||||
inline uint32_t pci_conv_wr_data(uint32_t v1, uint32_t v2, AccessDetails &details)
|
||||
{
|
||||
switch (details.size << 2 | details.offset) {
|
||||
// Bytes
|
||||
case 0x04:
|
||||
return (v1 & ~0xFF) | (v2 & 0xFF); // 3 2 1 d0
|
||||
case 0x05:
|
||||
return (v1 & ~0xFF00) | ((v2 & 0xFF) << 8); // 3 2 d0 0
|
||||
case 0x06:
|
||||
return (v1 & ~0xFF0000) | ((v2 & 0xFF) << 16); // 3 d0 1 0
|
||||
case 0x07:
|
||||
return (v1 & 0x00FFFFFF) | ((v2 & 0xFF) << 24); // d0 2 1 0
|
||||
|
||||
// Words
|
||||
case 0x08:
|
||||
return (v1 & ~0xFFFF) | BYTESWAP_16(v2); // 3 2 d1 d0
|
||||
case 0x09:
|
||||
return (v1 & ~0xFFFF00) | (BYTESWAP_16(v2) << 8); // 3 d1 d0 0
|
||||
case 0x0a:
|
||||
return (v1 & 0x0000FFFF) | (BYTESWAP_16(v2) << 16); // d1 d0 1 0
|
||||
case 0x0b:
|
||||
return (v1 & 0x00FFFF00) | ((v2 & 0xFF00) << 16) |
|
||||
(v2 & 0xFF); // d0 2 1 d1
|
||||
|
||||
// Dwords
|
||||
case 0x10:
|
||||
return BYTESWAP_32(v2); // d3 d2 d1 d0
|
||||
case 0x11:
|
||||
return ROTL_32(BYTESWAP_32(v2), 8); // d2 d1 d0 d3
|
||||
case 0x12:
|
||||
return ROTL_32(BYTESWAP_32(v2), 16); // d1 d0 d3 d2
|
||||
case 0x13:
|
||||
return ROTR_32(BYTESWAP_32(v2), 8); // d0 d3 d2 d1
|
||||
|
||||
default:
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <core/timermanager.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
|
||||
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 MeshController::reset(bool is_hard_reset)
|
||||
{
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->int_mask = 0;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = 2; // guessed
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MeshController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
return this->bus_obj->test_ctrl_lines(0xFFU);
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::Exception:
|
||||
return 0;
|
||||
case MeshReg::Error:
|
||||
return 0;
|
||||
case MeshReg::IntMask:
|
||||
return this->int_mask;
|
||||
case MeshReg::Interrupt:
|
||||
return this->int_stat;
|
||||
case MeshReg::MeshID:
|
||||
return this->chip_id; // tell them who we are
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: read from unimplemented register at offset 0x%x", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint16_t new_stat;
|
||||
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
perform_command(value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
new_stat = value << 8;
|
||||
if (new_stat != this->bus_stat) {
|
||||
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(new_stat, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(new_stat, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MeshReg::Interrupt:
|
||||
this->int_stat &= ~(value & INT_MASK); // clear requested interrupt bits
|
||||
update_irq();
|
||||
break;
|
||||
case MeshReg::SourceID:
|
||||
this->src_id = value;
|
||||
break;
|
||||
case MeshReg::DestID:
|
||||
this->dst_id = value;
|
||||
break;
|
||||
case MeshReg::SyncParms:
|
||||
this->sync_params = value;
|
||||
break;
|
||||
case MeshReg::SelTimeOut:
|
||||
LOG_F(9, "MESH: selection timeout set to 0x%x", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: write to unimplemented register at offset 0x%x",
|
||||
reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::perform_command(const uint8_t cmd)
|
||||
{
|
||||
this->cur_cmd = cmd;
|
||||
|
||||
this->int_stat &= ~INT_CMD_DONE;
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Select:
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DisReselect:
|
||||
LOG_F(INFO, "MESH: DisReselect command requested");
|
||||
break;
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO command requested");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
|
||||
void MeshController::sequencer()
|
||||
{
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "MESH: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "MESH: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->cur_cmd & 0x20);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "MESH: selection completed");
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
default:
|
||||
ABORT_F("MESH: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::update_irq()
|
||||
{
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Mesh_Descriptor = {
|
||||
MeshController::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Mesh, Mesh_Descriptor);
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
// MESH Sequencer commands.
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF,
|
||||
};
|
||||
|
||||
// Exception register bits.
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
// Interrupt register bits.
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
|
||||
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
this->chip_id = mesh_id;
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
|
||||
}
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
protected:
|
||||
void reset(bool is_hard_reset);
|
||||
void perform_command(const uint8_t cmd);
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void sequencer();
|
||||
void update_irq();
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
uint8_t int_mask;
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t sync_params;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
uint8_t cur_cmd;
|
||||
uint8_t error;
|
||||
uint8_t exception;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
uint16_t bus_stat;
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
@@ -0,0 +1,660 @@
|
||||
/*
|
||||
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 <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice(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 status, int_status;
|
||||
|
||||
switch (reg_offset) {
|
||||
case Read::Reg53C94::Xfer_Cnt_LSB:
|
||||
return this->xfer_count & 0xFFU;
|
||||
case Read::Reg53C94::Xfer_Cnt_MSB:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case Read::Reg53C94::FIFO:
|
||||
return this->fifo_pop();
|
||||
case Read::Reg53C94::Command:
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
return (this->status & 0xF8) | 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_1:
|
||||
return this->config1;
|
||||
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::Xfer_Cnt_LSB:
|
||||
this->set_xfer_count = (this->set_xfer_count & ~0xFFU) | value;
|
||||
break;
|
||||
case Write::Reg53C94::Xfer_Cnt_MSB:
|
||||
this->set_xfer_count = (this->set_xfer_count & ~0xFF00U) | (value << 8);
|
||||
break;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Sc53C94::pseudo_dma_read()
|
||||
{
|
||||
uint16_t data_word;
|
||||
bool is_done = false;
|
||||
|
||||
if (this->data_fifo_pos >= 2) {
|
||||
// remove one word from FIFO
|
||||
data_word = (this->data_fifo[0] << 8) | this->data_fifo[1];
|
||||
this->data_fifo_pos -= 2;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
|
||||
// update DMA status
|
||||
if ((this->cmd_fifo[0] & 0x80)) {
|
||||
this->xfer_count -= 2;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
return data_word;
|
||||
}
|
||||
|
||||
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 |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::exec_command()
|
||||
{
|
||||
uint8_t cmd = this->cur_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;
|
||||
if (!this->xfer_count) {
|
||||
this->xfer_count = 65536;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 data 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_XFER:
|
||||
if (!this->is_initiator) {
|
||||
// clear command FIFO
|
||||
this->cmd_fifo_pos = 0;
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = nullptr;
|
||||
this->cur_state = SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
case CMD_COMPLETE_STEPS:
|
||||
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
|
||||
{SeqState::RCV_STATUS, 0, 0},
|
||||
{SeqState::RCV_MESSAGE, 0, 0},
|
||||
{SeqState::CMD_COMPLETE, 0, INTSTAT_SR}
|
||||
};
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
|
||||
ABORT_F("Sc53C94: complete steps only works in the STATUS phase");
|
||||
}
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = complete_steps_desc;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
break;
|
||||
case CMD_MSG_ACCEPTED:
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_SELECT_NO_ATN:
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "SC53C94: SELECT W/O ATN command started");
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN:
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->bytes_out = 1; // set message length
|
||||
this->cmd_steps = sel_with_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "SC53C94: SELECT WITH ATN command started");
|
||||
break;
|
||||
case CMD_ENA_SEL_RESEL:
|
||||
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;
|
||||
this->update_irq();
|
||||
}
|
||||
}
|
||||
|
||||
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 < DATA_FIFO_MAX) {
|
||||
this->data_fifo[this->data_fifo_pos++] = data;
|
||||
} else {
|
||||
LOG_F(ERROR, "SC53C94: data FIFO overflow!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Sc53C94::fifo_pop()
|
||||
{
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->data_fifo_pos < 1) {
|
||||
LOG_F(ERROR, "SC53C94: data FIFO underflow!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
this->data_fifo_pos--;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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)) {
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "SC53C94: selection completed");
|
||||
} 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;
|
||||
case SeqState::SEND_MSG:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->bytes_out);
|
||||
this->data_fifo_pos -= this->bytes_out;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[this->bytes_out], this->data_fifo_pos);
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
this->data_fifo_pos = 0;
|
||||
break;
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case SeqState::XFER_BEGIN:
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->cmd_fifo[0] & 0x80) {
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
}
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
this->data_fifo_pos = 0;
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
if (!(this->cmd_fifo[0] & 0x80)) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case SeqState::SEND_DATA:
|
||||
break;
|
||||
case SeqState::RCV_DATA:
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
this->cmd_fifo_pos = 0; // clear command FIFO
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->rcv_data();
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
this->bus_obj->target_next_step();
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
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(ScsiBus* bus_obj, 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;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message");
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "SC53C94: ignore notification message, type: %d", msg_type);
|
||||
}
|
||||
}
|
||||
|
||||
int Sc53C94::send_data(uint8_t* dst_ptr, int count)
|
||||
{
|
||||
if (dst_ptr == nullptr || !count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int actual_count = std::min(this->data_fifo_pos, count);
|
||||
|
||||
// move data out of the data FIFO
|
||||
std::memcpy(dst_ptr, this->data_fifo, actual_count);
|
||||
|
||||
// remove the just readed data from the data FIFO
|
||||
this->data_fifo_pos -= actual_count;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
|
||||
} else {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
bool Sc53C94::rcv_data()
|
||||
{
|
||||
int req_count;
|
||||
|
||||
// return if REQ line is negated
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_REQ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this->cmd_fifo[0] & 0x80) && this->cur_bus_phase == ScsiPhase::DATA_IN) {
|
||||
req_count = std::min((int)this->xfer_count, DATA_FIFO_MAX - this->data_fifo_pos);
|
||||
} else {
|
||||
req_count = 1;
|
||||
}
|
||||
|
||||
this->bus_obj->pull_data(this->target_id, &this->data_fifo[this->data_fifo_pos], req_count);
|
||||
this->data_fifo_pos += req_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sc53C94::real_dma_xfer(int direction)
|
||||
{
|
||||
bool is_done = false;
|
||||
|
||||
if (direction) {
|
||||
uint32_t got_bytes;
|
||||
uint8_t* src_ptr;
|
||||
|
||||
while (this->xfer_count) {
|
||||
this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX),
|
||||
&got_bytes, &src_ptr);
|
||||
std::memcpy(this->data_fifo, src_ptr, got_bytes);
|
||||
this->data_fifo_pos = got_bytes;
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
} else { // transfer data from target to host's memory
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Sc53C94_Descriptor = {
|
||||
Sc53C94::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
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 <devices/common/dmacore.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
/** 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_XFER = 0x10,
|
||||
CMD_COMPLETE_STEPS = 0x11,
|
||||
CMD_MSG_ACCEPTED = 0x12,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_SELECT_WITH_ATN = 0x42,
|
||||
CMD_ENA_SEL_RESEL = 0x44,
|
||||
};
|
||||
|
||||
/** Status register bits. **/
|
||||
enum {
|
||||
STAT_TC = 1 << 4, // Terminal count (NCR) / count to zero (AMD)
|
||||
STAT_GE = 1 << 6, // Gross Error (NCR) / Illegal Operation Error (AMD)
|
||||
};
|
||||
|
||||
/** 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,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
|
||||
/** 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;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Sc53C94>(new Sc53C94());
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
// 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
uint16_t pseudo_dma_read();
|
||||
|
||||
// real DMA control
|
||||
void real_dma_xfer(int direction);
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool has_data() { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
|
||||
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);
|
||||
uint8_t fifo_pop();
|
||||
|
||||
void sequencer();
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
|
||||
bool rcv_data();
|
||||
|
||||
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;
|
||||
int bytes_out;
|
||||
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;
|
||||
int cur_bus_phase;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
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 <functional>
|
||||
#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 << 13,
|
||||
SCSI_CTRL_BSY = 1 << 14,
|
||||
SCSI_CTRL_RST = 1 << 15,
|
||||
};
|
||||
|
||||
namespace ScsiPhase {
|
||||
enum : int {
|
||||
BUS_FREE = 0,
|
||||
ARBITRATION,
|
||||
SELECTION,
|
||||
RESELECTION,
|
||||
COMMAND,
|
||||
DATA_IN,
|
||||
DATA_OUT,
|
||||
STATUS,
|
||||
MESSAGE_IN,
|
||||
MESSAGE_OUT,
|
||||
RESET,
|
||||
};
|
||||
};
|
||||
|
||||
namespace ScsiStatus {
|
||||
enum : uint8_t {
|
||||
GOOD = 0,
|
||||
CHECK_CONDITION = 2,
|
||||
};
|
||||
};
|
||||
|
||||
namespace ScsiMessage {
|
||||
enum : uint8_t {
|
||||
COMMAND_COMPLETE = 0,
|
||||
};
|
||||
};
|
||||
|
||||
enum ScsiMsg : int {
|
||||
CONFIRM_SEL = 1,
|
||||
BUS_PHASE_CHANGE,
|
||||
SEND_CMD_BEGIN,
|
||||
SEND_CMD_END,
|
||||
MESSAGE_BEGIN,
|
||||
MESSAGE_END,
|
||||
};
|
||||
|
||||
enum ScsiCommand : int {
|
||||
TEST_UNIT_READY = 0x0,
|
||||
REWIND = 0x1,
|
||||
REQ_SENSE = 0x3,
|
||||
FORMAT = 0x4,
|
||||
READ_BLK_LIMITS = 0x5,
|
||||
READ_6 = 0x8,
|
||||
WRITE_6 = 0xA,
|
||||
SEEK_6 = 0xB,
|
||||
INQUIRY = 0x12,
|
||||
VERIFY_6 = 0x13,
|
||||
MODE_SELECT_6 = 0x15,
|
||||
RELEASE_UNIT = 0x17,
|
||||
ERASE_6 = 0x19,
|
||||
MODE_SENSE_6 = 0x1A,
|
||||
DIAG_RESULTS = 0x1C,
|
||||
SEND_DIAGS = 0x1D,
|
||||
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
READ_CAPACITY_10 = 0x25,
|
||||
READ_10 = 0x28,
|
||||
WRITE_10 = 0x2A,
|
||||
VERIFY_10 = 0x2F,
|
||||
READ_LONG_10 = 0x35,
|
||||
|
||||
// CD-ROM specific commands
|
||||
READ_TOC = 0x43,
|
||||
};
|
||||
|
||||
enum ScsiSense : int {
|
||||
NO_SENSE = 0x0,
|
||||
RECOVERED = 0x1,
|
||||
NOT_READY = 0x2,
|
||||
MEDIUM_ERR = 0x3,
|
||||
HW_ERROR = 0x4,
|
||||
ILLEGAL_REQ = 0x5,
|
||||
UNIT_ATTENTION = 0x6,
|
||||
DATA_PROTECT = 0x7,
|
||||
BLANK_CHECK = 0x8,
|
||||
VOL_OVERFLOW = 0xD,
|
||||
MISCOMPARE = 0xE,
|
||||
COMPLETED = 0xF
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x0,
|
||||
NO_SECTOR = 0x1,
|
||||
WRITE_FAULT = 0x3,
|
||||
DEV_NOT_READY = 0x4,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27
|
||||
};
|
||||
|
||||
/** 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 ScsiBus;
|
||||
|
||||
typedef std::function<void()> action_callback;
|
||||
|
||||
class ScsiDevice : public HWComponent {
|
||||
public:
|
||||
ScsiDevice(int my_id) {
|
||||
this->scsi_id = my_id;
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
};
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
virtual void next_step(ScsiBus* bus_obj);
|
||||
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
|
||||
virtual void switch_phase(const int new_phase);
|
||||
|
||||
virtual bool has_data() { return this->data_size != 0; };
|
||||
virtual int send_data(uint8_t* dst_ptr, int count);
|
||||
virtual int rcv_data(const uint8_t* src_ptr, const int count);
|
||||
|
||||
virtual bool prepare_data() = 0;
|
||||
virtual void process_command() = 0;
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
int scsi_id;
|
||||
int initiator_id;
|
||||
int cur_phase;
|
||||
uint8_t* data_ptr = nullptr;
|
||||
int data_size;
|
||||
int incoming_size;
|
||||
uint8_t status;
|
||||
int sense;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
|
||||
action_callback pre_xfer_action = nullptr;
|
||||
action_callback post_xfer_action = nullptr;
|
||||
};
|
||||
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
class ScsiBus : public HWComponent {
|
||||
public:
|
||||
ScsiBus();
|
||||
~ScsiBus() = default;
|
||||
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
int get_initiator_id() { return this->initiator_id; };
|
||||
int get_target_id() { return this->target_id; };
|
||||
|
||||
// reading/writing control lines
|
||||
void assert_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_lines(int id);
|
||||
uint16_t test_ctrl_lines(uint16_t mask);
|
||||
|
||||
// reading/writing data lines
|
||||
uint8_t get_data_lines() { return this->data_lines; };
|
||||
|
||||
// high-level control/status
|
||||
int switch_phase(int id, int new_phase);
|
||||
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);
|
||||
bool pull_data(const int id, uint8_t* dst_ptr, const int size);
|
||||
bool push_data(const int id, const uint8_t* src_ptr, const int size);
|
||||
void target_next_step();
|
||||
bool negotiate_xfer(int& bytes_in, int& bytes_out);
|
||||
|
||||
protected:
|
||||
void change_bus_phase(int initiator_id);
|
||||
|
||||
private:
|
||||
// SCSI devices registered with this bus
|
||||
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
|
||||
|
||||
// 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,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 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(this, 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;
|
||||
}
|
||||
|
||||
if (new_state & SCSI_CTRL_RST) {
|
||||
this->ctrl_lines |= 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);
|
||||
}
|
||||
} else {
|
||||
this->ctrl_lines = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::release_ctrl_lines(int id)
|
||||
{
|
||||
this->release_ctrl_line(id, 0xFFFFUL);
|
||||
}
|
||||
|
||||
uint16_t ScsiBus::test_ctrl_lines(uint16_t mask)
|
||||
{
|
||||
uint16_t new_state = 0;
|
||||
|
||||
// OR control lines of all devices together
|
||||
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
new_state |= this->dev_ctrl_lines[i];
|
||||
}
|
||||
|
||||
return new_state & mask;
|
||||
}
|
||||
|
||||
int ScsiBus::switch_phase(int id, int new_phase)
|
||||
{
|
||||
int old_phase = this->cur_phase;
|
||||
|
||||
// leave the current phase (low-level)
|
||||
switch (old_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD);
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
}
|
||||
|
||||
// enter new phase (low-level)
|
||||
switch (new_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD);
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
}
|
||||
|
||||
// switch the bus to the new phase (high-level)
|
||||
this->cur_phase = new_phase;
|
||||
change_bus_phase(id);
|
||||
|
||||
return old_phase;
|
||||
}
|
||||
|
||||
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->assert_ctrl_line(initiator_id, SCSI_CTRL_SEL);
|
||||
|
||||
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(this, 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;
|
||||
}
|
||||
|
||||
bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
{
|
||||
if (dst_ptr == nullptr || !size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->devices[id]->send_data(dst_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring T->I data!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
{
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring I->T data!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step(this);
|
||||
}
|
||||
|
||||
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiBus::disconnect(int dev_id)
|
||||
{
|
||||
this->release_ctrl_lines(dev_id);
|
||||
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,364 @@
|
||||
/*
|
||||
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 CD-ROM emulation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsicdrom.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static char cdrom_vendor_sony_id[] = "SONY ";
|
||||
static char cdu8003a_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char cdu8003a_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(int my_id) : ScsiDevice(my_id)
|
||||
{
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
|
||||
this->sector_size = 2048;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
}
|
||||
|
||||
void ScsiCdrom::insert_image(std::string filename)
|
||||
{
|
||||
this->cdr_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_frames = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
|
||||
// create single track descriptor
|
||||
this->tracks[0] = {.trk_num = 1, .adr_ctrl = 0x14, .start_lba = 0};
|
||||
this->num_tracks = 1;
|
||||
|
||||
// create Lead-out descriptor containing all data
|
||||
this->tracks[1] = {.trk_num = LEAD_OUT_TRK_NUM, .adr_ctrl = 0x14,
|
||||
.start_lba = static_cast<uint32_t>(this->total_frames)};
|
||||
} else {
|
||||
ABORT_F("SCSI-CDROM: could not determine file size using stat()");
|
||||
}
|
||||
this->cdr_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba, xfer_len;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
|
||||
switch (cmd_buf[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd_buf[1] & 0x1F) << 16) + (cmd_buf[2] << 8) + cmd_buf[3];
|
||||
this->read(lba, cmd_buf[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->incoming_size = this->cmd_buf[4];
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (this->cmd_buf[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_buf[7]);
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_10");
|
||||
}
|
||||
read(lba, xfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI_CDROM: unsupported command %d", this->cmd_buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiCdrom::prepare_data()
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_CDROM: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiCdrom::read(const uint32_t lba, const uint16_t transfer_len, const uint8_t cmd_len)
|
||||
{
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = lba * this->sector_size;
|
||||
|
||||
this->cdr_img.seekg(device_offset, this->cdr_img.beg);
|
||||
this->cdr_img.read(this->data_buf, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::inquiry()
|
||||
{
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("SCSI_CDROM: invalid page number in INQUIRY");
|
||||
}
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "SCSI_CDROM: more than 36 bytes requested in INQUIRY");
|
||||
}
|
||||
|
||||
this->data_buf[0] = 5; // device type: CD-ROM
|
||||
this->data_buf[1] = 0x80; // removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0x1F; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&this->data_buf[8], cdrom_vendor_sony_id, 8);
|
||||
std::memcpy(&this->data_buf[16], cdu8003a_product_id, 16);
|
||||
std::memcpy(&this->data_buf[32], cdu8003a_revision_id, 4);
|
||||
|
||||
this->bytes_out = 36;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiCdrom::mode_sense()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
int num_blocks = (this->img_size + this->sector_size) / this->sector_size;
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0x80; // medium is write protected
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (num_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (num_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
|
||||
this->data_buf[ 8] = 0;
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[11] = (this->sector_size ) & 0xFFU;
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
|
||||
switch (page_code) {
|
||||
case 0x01:
|
||||
this->data_buf[13] = 6; // data size
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
this->data_buf[0] += 7;
|
||||
break;
|
||||
case 0x30:
|
||||
this->data_buf[13] = 22; // data size
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
this->data_buf[0] += 23;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
|
||||
}
|
||||
|
||||
this->bytes_out = this->data_buf[0];
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_toc()
|
||||
{
|
||||
int tot_tracks;
|
||||
uint8_t start_track = this->cmd_buf[6];
|
||||
uint16_t alloc_len = (this->cmd_buf[7] << 8) + this->cmd_buf[8];
|
||||
bool is_msf = !!(this->cmd_buf[1] & 2);
|
||||
|
||||
if (this->cmd_buf[2] & 0xF) {
|
||||
ABORT_F("SCSI-CDROM: unsupported format in READ_TOC");
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "SCSI-CDROM: zero allocation length passed to READ_TOC");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!start_track) { // special case: track zero (lead-in) as starting track
|
||||
// return all tracks starting with track 1 plus lead-out
|
||||
start_track = 1;
|
||||
tot_tracks = this->num_tracks + 1;
|
||||
} else if (start_track == LEAD_OUT_TRK_NUM) {
|
||||
start_track = this->num_tracks + 1;
|
||||
tot_tracks = 1;
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "SCSI-CDROM: invalid starting track %d in READ_TOC", start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
char* buf_ptr = this->data_buf;
|
||||
|
||||
int data_len = (tot_tracks * 8) + 2;
|
||||
|
||||
// write TOC data header
|
||||
*buf_ptr++ = (data_len >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (data_len >> 0) & 0xFFU;
|
||||
*buf_ptr++ = 1; // 1st track number
|
||||
*buf_ptr++ = this->num_tracks; // last track number
|
||||
|
||||
for (int tx = 0; tx < tot_tracks; tx++) {
|
||||
if ((buf_ptr - this->data_buf + 8) > alloc_len)
|
||||
break; // exit the loop if the output buffer length is exhausted
|
||||
|
||||
TrackDescriptor& td = this->tracks[start_track + tx - 1];
|
||||
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = td.adr_ctrl;
|
||||
*buf_ptr++ = td.trk_num;
|
||||
*buf_ptr++ = 0; // reserved
|
||||
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(td.start_lba + 150);
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = msf.min;
|
||||
*buf_ptr++ = msf.sec;
|
||||
*buf_ptr++ = msf.frm;
|
||||
} else {
|
||||
*buf_ptr++ = (td.start_lba >> 24) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 16) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 0) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity()
|
||||
{
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "SCSI-CDROM: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int last_lba = this->total_frames - 1;
|
||||
|
||||
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
|
||||
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
|
||||
this->data_buf[2] = (last_lba >> 8) & 0xFFU;
|
||||
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
|
||||
this->data_buf[4] = 0;
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->sector_size & 0xFFU;
|
||||
|
||||
this->bytes_out = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
AddrMsf ScsiCdrom::lba_to_msf(const int lba)
|
||||
{
|
||||
return {.min = lba / 4500, .sec = (lba / 75) % 60, .frm = lba % 75};
|
||||
}
|
||||
|
||||
static const PropMap ScsiCdromProperties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription ScsiCdromDescriptor =
|
||||
{ScsiCdrom::create, {}, ScsiCdromProperties};
|
||||
|
||||
REGISTER_DEVICE(ScsiCdrom, ScsiCdromDescriptor);
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 CD-ROM definitions. */
|
||||
|
||||
#ifndef SCSI_CDROM_H
|
||||
#define SCSI_CDROM_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/* Original CD-ROM addressing mode expressed
|
||||
in minutes, seconds and frames */
|
||||
typedef struct {
|
||||
int min;
|
||||
int sec;
|
||||
int frm;
|
||||
} AddrMsf;
|
||||
|
||||
/* Descriptor for CD-ROM tracks in TOC */
|
||||
typedef struct {
|
||||
uint8_t trk_num;
|
||||
uint8_t adr_ctrl;
|
||||
uint32_t start_lba;
|
||||
} TrackDescriptor;
|
||||
|
||||
#define CDROM_MAX_TRACKS 100
|
||||
#define LEAD_OUT_TRK_NUM 0xAA
|
||||
|
||||
class ScsiCdrom : public ScsiDevice {
|
||||
public:
|
||||
ScsiCdrom(int my_id);
|
||||
~ScsiCdrom() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiCdrom>(new ScsiCdrom(3));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
|
||||
virtual void process_command();
|
||||
virtual bool prepare_data();
|
||||
|
||||
protected:
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void inquiry();
|
||||
void mode_sense();
|
||||
void read_toc();
|
||||
void read_capacity();
|
||||
|
||||
private:
|
||||
AddrMsf lba_to_msf(const int lba);
|
||||
|
||||
private:
|
||||
std::fstream cdr_img;
|
||||
uint64_t img_size;
|
||||
int total_frames;
|
||||
int num_tracks;
|
||||
int sector_size;
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
TrackDescriptor tracks[CDROM_MAX_TRACKS];
|
||||
|
||||
char data_buf[1 << 18]; // TODO: proper buffer management
|
||||
};
|
||||
|
||||
#endif // SCSI_CDROM_H
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
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 <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
{
|
||||
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
|
||||
switch (param) {
|
||||
case ScsiPhase::RESET:
|
||||
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
|
||||
break;
|
||||
case ScsiPhase::SELECTION:
|
||||
// check if something tries to select us
|
||||
if (bus_obj->get_data_lines() & (1 << scsi_id)) {
|
||||
LOG_F(9, "ScsiDevice %d selected", this->scsi_id);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
BUS_SETTLE_DELAY,
|
||||
[this, bus_obj]() {
|
||||
// don't confirm selection if BSY or I/O are asserted
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
return;
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
|
||||
bus_obj->confirm_selection(this->scsi_id);
|
||||
this->initiator_id = bus_obj->get_initiator_id();
|
||||
this->bus_obj = bus_obj;
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
if (this->msg_buf[0] != 0x80) {
|
||||
LOG_F(INFO, "ScsiDevice: received message 0x%X", this->msg_buf[0]);
|
||||
}
|
||||
}
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
this->process_command();
|
||||
if (this->prepare_data()) {
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
} else {
|
||||
ABORT_F("ScsiDevice: prepare_data() failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiDevice::switch_phase(const int new_phase)
|
||||
{
|
||||
this->cur_phase = new_phase;
|
||||
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
|
||||
}
|
||||
|
||||
void ScsiDevice::next_step(ScsiBus* bus_obj)
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->process_command();
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->data_size >= this->incoming_size) {
|
||||
if (this->post_xfer_action != nullptr) {
|
||||
this->post_xfer_action();
|
||||
}
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
if (!this->has_data()) {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::BUS_FREE:
|
||||
bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
this->switch_phase(ScsiPhase::BUS_FREE);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ScsiDevice: nothing to do for phase %d", this->cur_phase);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->cur_phase = bus_obj->current_phase();
|
||||
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->data_ptr = this->cmd_buf;
|
||||
this->data_size = bytes_in;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->data_ptr = &this->status;
|
||||
this->data_size = 1;
|
||||
bytes_out = 1;
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
bytes_out = this->data_size;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = bytes_in;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = 1;
|
||||
bytes_out = 1;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
|
||||
}
|
||||
}
|
||||
|
||||
int ScsiDevice::send_data(uint8_t* dst_ptr, const int count)
|
||||
{
|
||||
if (dst_ptr == nullptr || !count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int actual_count = std::min(this->data_size, count);
|
||||
|
||||
std::memcpy(dst_ptr, this->data_ptr, actual_count);
|
||||
this->data_ptr += actual_count;
|
||||
this->data_size -= actual_count;
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
{
|
||||
// accumulating incoming data in the pre-configured buffer
|
||||
std::memcpy(this->data_ptr, src_ptr, count);
|
||||
this->data_ptr += count;
|
||||
this->data_size += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
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 Generic SCSI Hard Disk emulation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsihd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define HDD_SECTOR_SIZE 512
|
||||
|
||||
using namespace std;
|
||||
|
||||
ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) {
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::insert_image(std::string filename) {
|
||||
//We don't want to store everything in memory, but
|
||||
//we want to keep the hard disk available.
|
||||
this->hdd_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE;
|
||||
} else {
|
||||
ABORT_F("ScsiHardDisk: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::process_command() {
|
||||
uint32_t lba = 0;
|
||||
uint16_t transfer_len = 0;
|
||||
uint16_t alloc_len = 0;
|
||||
uint8_t param_len = 0;
|
||||
|
||||
uint8_t page_code = 0;
|
||||
uint8_t subpage_code = 0;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
|
||||
uint8_t* cmd = this->cmd_buf;
|
||||
|
||||
if (cmd[0] != 0 && cmd[0] != 8 && cmd[0] != 0xA && cmd[0] != 0x28
|
||||
&& cmd[0] != 0x2A && cmd[0] != 0x25) {
|
||||
ABORT_F("SCSI-HD: untested command 0x%X", cmd[0]);
|
||||
}
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
rewind();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
alloc_len = cmd[4];
|
||||
req_sense(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
alloc_len = (cmd[3] << 8) + cmd[4];
|
||||
inquiry(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
read(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
read(lba, transfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
write(lba, transfer_len, 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
seek(lba);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
param_len = cmd[4];
|
||||
mode_select_6(param_len);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
page_code = cmd[2] & 0x1F;
|
||||
subpage_code = cmd[3];
|
||||
alloc_len = cmd[4];
|
||||
mode_sense_6(page_code, subpage_code, alloc_len);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
read_capacity_10();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unrecognized command: %x", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiHardDisk::prepare_data() {
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = this->cur_buf_cnt;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
if (!error) {
|
||||
this->img_buffer[0] = ScsiStatus::GOOD;
|
||||
} else {
|
||||
this->img_buffer[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->cur_buf_cnt = 1;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->img_buffer[0] = this->msg_code;
|
||||
this->cur_buf_cnt = 1;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::test_unit_ready() {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
if (alloc_len != 252) {
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
}
|
||||
|
||||
void ScsiHardDisk::inquiry(uint16_t alloc_len) {
|
||||
if (alloc_len >= 48) {
|
||||
uint8_t empty_filler[1 << 17] = {0x0};
|
||||
std::memcpy(img_buffer, empty_filler, (1 << 17));
|
||||
img_buffer[2] = 0x1;
|
||||
img_buffer[3] = 0x2;
|
||||
img_buffer[4] = 0x31;
|
||||
img_buffer[7] = 0x1C;
|
||||
std::memcpy(img_buffer + 8, vendor_info, 8);
|
||||
std::memcpy(img_buffer + 16, prod_info, 16);
|
||||
std::memcpy(img_buffer + 32, rev_info, 8);
|
||||
std::memcpy(img_buffer + 40, serial_info, 8);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
}
|
||||
|
||||
int ScsiHardDisk::send_diagnostic() {
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::mode_select_6(uint8_t param_len) {
|
||||
if (param_len == 0) {
|
||||
return 0x0;
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Mode Select calling for param length of: %d", param_len);
|
||||
return param_len;
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiHardDisk::mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len) {
|
||||
LOG_F(WARNING, "Page Code %d; Subpage Code: %d", page_code, subpage_code);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_capacity_10() {
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-HD: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "SCSI-HD: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t last_lba = this->total_blocks - 1;
|
||||
uint32_t blk_len = HDD_SECTOR_SIZE;
|
||||
|
||||
WRITE_DWORD_BE_A(&img_buffer[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&img_buffer[4], blk_len);
|
||||
|
||||
this->cur_buf_cnt = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
|
||||
void ScsiHardDisk::format() {
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(img_buffer, 0, sizeof(img_buffer));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
this->hdd_img.read(img_buffer, transfer_size);
|
||||
|
||||
this->cur_buf_cnt = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->incoming_size = transfer_size;
|
||||
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->img_buffer, this->incoming_size);
|
||||
};
|
||||
}
|
||||
|
||||
void ScsiHardDisk::seek(uint32_t lba) {
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::rewind() {
|
||||
this->hdd_img.seekg(0, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
static const PropMap SCSI_HD_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
{"hdd_wr_prot", new BinProperty(0)},
|
||||
};
|
||||
|
||||
static const DeviceDescription SCSI_HD_Descriptor =
|
||||
{ScsiHardDisk::create, {}, SCSI_HD_Properties};
|
||||
|
||||
REGISTER_DEVICE(ScsiHD, SCSI_HD_Descriptor);
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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 hard drive definitions. */
|
||||
|
||||
#ifndef SCSI_HD_H
|
||||
#define SCSI_HD_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
class ScsiHardDisk : public ScsiDevice {
|
||||
public:
|
||||
ScsiHardDisk(int my_id);
|
||||
~ScsiHardDisk() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
void process_command();
|
||||
bool prepare_data();
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
int req_sense(uint16_t alloc_len);
|
||||
int send_diagnostic();
|
||||
int mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len);
|
||||
void format();
|
||||
void inquiry(uint16_t alloc_len);
|
||||
void read_capacity_10();
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void seek(uint32_t lba);
|
||||
void rewind();
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
|
||||
char img_buffer[1 << 21]; // TODO: add proper buffer management!
|
||||
|
||||
uint32_t cur_buf_cnt = 0;
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
||||
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
|
||||
char rev_info[8] = {'d', 'i', '0', '0', '0', '0', '0', '1'};
|
||||
char serial_info[8] = {'0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
};
|
||||
|
||||
#endif // SCSI_HD_H
|
||||
@@ -0,0 +1,719 @@
|
||||
/*
|
||||
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 <devices/deviceregistry.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
|
||||
|
||||
// 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 = 1;
|
||||
this->old_byteack = 1;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::update_irq()
|
||||
{
|
||||
uint8_t active_ints = this->_via_ifr & this->_via_ier & 0x7F;
|
||||
if (active_ints != this->old_ifr) {
|
||||
uint8_t new_irq = !!active_ints;
|
||||
this->_via_ifr = (active_ints) | (new_irq << 7);
|
||||
this->old_ifr = active_ints;
|
||||
LOG_F(6, "VIA: assert IRQ, IFR=0x%02X", this->_via_ifr);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::assert_sr_int() {
|
||||
this->sr_timer_on = false;
|
||||
this->_via_ifr |= VIA_IF_SR;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t1_int() {
|
||||
this->_via_ifr |= VIA_IF_T1;
|
||||
this->t1_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t2_int() {
|
||||
this->_via_ifr |= VIA_IF_T2;
|
||||
this->t2_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
void ViaCuda::assert_int(uint8_t flags) {
|
||||
this->_via_ifr |= (flags & 0x7F);
|
||||
update_irq();
|
||||
}
|
||||
#endif
|
||||
|
||||
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) {
|
||||
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 */
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->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
|
||||
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));
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
// 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");
|
||||
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!", 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;
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription ViaCuda_Descriptor = {
|
||||
ViaCuda::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,12 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** VIA-CUDA combo device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
|
||||
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 peripherial devices. In a Power Macintosh, its function is limited
|
||||
to the I/O interface for the Cuda MCU. I therefore decided to put VIA
|
||||
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
|
||||
@@ -45,10 +43,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include "adb.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "i2c.h"
|
||||
#include "nvram.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 {
|
||||
@@ -70,6 +73,24 @@ enum {
|
||||
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 */
|
||||
@@ -88,11 +109,23 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
@@ -103,59 +136,116 @@ 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();
|
||||
~ViaCuda() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST);
|
||||
};
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ViaCuda>(new ViaCuda());
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
uint8_t read(int reg);
|
||||
void write(int reg, uint8_t value);
|
||||
|
||||
void assert_ctrl_line(ViaLine line);
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
void assert_int(uint8_t flags);
|
||||
#endif
|
||||
|
||||
private:
|
||||
uint8_t via_regs[16]; /* VIA virtual registers */
|
||||
// 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 old_ifr = 0;
|
||||
|
||||
/* Cuda state. */
|
||||
uint8_t old_tip;
|
||||
uint8_t old_byteack;
|
||||
uint8_t treq;
|
||||
uint8_t in_buf[16];
|
||||
int32_t in_count;
|
||||
uint8_t out_buf[16];
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
uint8_t poll_rate;
|
||||
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;
|
||||
uint8_t curr_i2c_addr;
|
||||
bool is_open_ended; // true if current transaction is open-ended
|
||||
uint8_t curr_i2c_addr; // current I2C address
|
||||
uint8_t cur_pram_addr; // current PRAM address, range 0...FF
|
||||
|
||||
void (ViaCuda::*out_handler)(void);
|
||||
void (ViaCuda::*next_out_handler)(void);
|
||||
|
||||
NVram* pram_obj;
|
||||
ADB_Bus* adb_obj;
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
std::unique_ptr<ADB_Bus> adb_bus;
|
||||
|
||||
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
|
||||
|
||||
void init();
|
||||
bool ready();
|
||||
// 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();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
// void cuda_response_packet();
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command(uint8_t cmd_byte, int data_count);
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
void out_buf_handler(void);
|
||||
void i2c_handler(void);
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include "dbdma.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
int DMAChannel::get_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)) {
|
||||
LOG_F(WARNING, "Dead/idle channel -> no more data");
|
||||
return -1; /* dead or idle channel? -> no more data */
|
||||
}
|
||||
|
||||
/* 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 0; /* tell the caller there is more data */
|
||||
}
|
||||
|
||||
return -1; /* 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->dma_cb->dma_start();
|
||||
}
|
||||
|
||||
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->dma_cb->dma_end();
|
||||
}
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @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 <cinttypes>
|
||||
|
||||
/** 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;
|
||||
|
||||
class DMACallback {
|
||||
public:
|
||||
virtual void dma_start(void) = 0;
|
||||
virtual void dma_end(void) = 0;
|
||||
//virtual void dma_push(uint8_t *buf, int size) = 0;
|
||||
//virtual void dma_pull(uint8_t *buf, int size) = 0;
|
||||
};
|
||||
|
||||
class DMAChannel {
|
||||
public:
|
||||
DMAChannel(DMACallback* cb) {
|
||||
this->dma_cb = cb;
|
||||
};
|
||||
~DMAChannel() = default;
|
||||
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
bool is_active();
|
||||
|
||||
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:
|
||||
DMACallback* dma_cb = 0;
|
||||
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,69 @@
|
||||
/*
|
||||
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 Device registry implementation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
|
||||
{
|
||||
if (device_registered(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
get_registry()[name] = desc;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceRegistry::device_registered(const string dev_name)
|
||||
{
|
||||
if (get_registry().find(dev_name) != get_registry().end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
|
||||
{
|
||||
auto it = get_registry().find(name);
|
||||
if (it != get_registry().end()) {
|
||||
return it->second.m_create_func();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DeviceDescription& DeviceRegistry::get_descriptor(const std::string& name)
|
||||
{
|
||||
auto it = get_registry().find(name);
|
||||
if (it != get_registry().end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
static DeviceDescription empty_descriptor = {};
|
||||
|
||||
return empty_descriptor;
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** @file Device registry definitions. */
|
||||
|
||||
#ifndef DEVICE_REGISTRY_H
|
||||
#define DEVICE_REGISTRY_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
|
||||
|
||||
struct DeviceDescription {
|
||||
CreateFunc m_create_func;
|
||||
vector<string> subdev_list;
|
||||
PropMap properties;
|
||||
};
|
||||
|
||||
class DeviceRegistry
|
||||
{
|
||||
public:
|
||||
DeviceRegistry() = delete;
|
||||
|
||||
static bool add(const string name, DeviceDescription desc);
|
||||
|
||||
static bool device_registered(const string dev_name);
|
||||
|
||||
static unique_ptr<HWComponent> create(const string& name);
|
||||
|
||||
static DeviceDescription& get_descriptor(const std::string& name);
|
||||
|
||||
private:
|
||||
static map<string, DeviceDescription> & get_registry() {
|
||||
static map<string, DeviceDescription> device_registry;
|
||||
return device_registry;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_DEVICE(dev_name, dev_desc) \
|
||||
static bool dev_name ## _registered = DeviceRegistry::add(#dev_name, (dev_desc))
|
||||
|
||||
#endif // DEVICE_REGISTRY_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 Media Access Controller for Ethernet (MACE) emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/ethernet/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);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Mace_Descriptor = {
|
||||
MaceController::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Mace, Mace_Descriptor);
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 Media Access Controller for Ethernet (MACE) definitions. */
|
||||
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
|
||||
// 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 HWComponent {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
|
||||
}
|
||||
|
||||
// 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,336 @@
|
||||
/*
|
||||
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 Support for reading and writing of various floppy images. */
|
||||
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <machines/machineproperties.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;
|
||||
}
|
||||
|
||||
//======================= RAW IMAGE CONVERTER ============================
|
||||
RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
For raw images, 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);
|
||||
size_t img_size = img_file.tellg();
|
||||
if (img_size > 2*1024*1024) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image size is too large to determine disk format from image size!");
|
||||
return -1;
|
||||
}
|
||||
this->img_size = (int)img_size;
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
img_file.close();
|
||||
|
||||
// verify image size
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image too short!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->img_size > MFM_HD_SIZE) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image too big!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// raw images don't include anything other than raw disk data
|
||||
this->data_size = this->img_size;
|
||||
|
||||
// see if user has specified disk format manually
|
||||
std::string fmt = GET_STR_PROP("fdd_fmt");
|
||||
if (!fmt.empty()) {
|
||||
if (fmt == "GCR_400K") {
|
||||
this->img_size = 409600;
|
||||
} else if (fmt == "GCR_800K") {
|
||||
this->img_size = 819200;
|
||||
} else if (fmt == "MFM_720K") {
|
||||
this->img_size = 737280;
|
||||
} else if (fmt == "MFM_1440K") {
|
||||
this->img_size = 1474560;
|
||||
} else {
|
||||
LOG_F(WARNING, "Invalid floppy disk format %s", fmt.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// ====================== DISK COPY 4.2 IMAGE CONVERTER ======================
|
||||
DiskCopy42Img::DiskCopy42Img(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::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, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, img_file.end);
|
||||
size_t img_size = img_file.tellg();
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
// get data size from image
|
||||
uint8_t buf[4];
|
||||
img_file.seekg(0x40, img_file.beg);
|
||||
img_file.read((char *)&buf, 4);
|
||||
this->data_size = READ_DWORD_BE_U(buf);
|
||||
|
||||
if (this->data_size > img_size) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: invalid data size %d", this->data_size);
|
||||
return -1;
|
||||
}
|
||||
this->img_size = (int)img_size;
|
||||
|
||||
uint8_t disk_format = 0xFFU;
|
||||
|
||||
img_file.seekg(0x50, img_file.beg);
|
||||
img_file.read((char *)&disk_format, 1);
|
||||
img_file.read((char *)&this->format_byte, 1);
|
||||
|
||||
img_file.close();
|
||||
|
||||
this->density = 0; // assume double density by default
|
||||
|
||||
this->num_tracks = 80;
|
||||
this->num_sides = ((this->format_byte >> 5) & 1) + 1;
|
||||
|
||||
switch (disk_format) {
|
||||
case 0:
|
||||
case 1:
|
||||
this->rec_method = 0; // GCR
|
||||
this->num_sectors = 800;
|
||||
break;
|
||||
case 2:
|
||||
this->rec_method = 1; // MFM
|
||||
this->num_sectors = 1440;
|
||||
this->format_byte = 2;
|
||||
break;
|
||||
case 3:
|
||||
this->rec_method = 1; // MFM
|
||||
this->density = 1; // report high density
|
||||
this->num_sectors = 2880;
|
||||
this->format_byte = 2;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "DiskCopy42Img: invalid disk format %X", disk_format);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::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, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
img_file.seekg(0x54, img_file.beg);
|
||||
img_file.read(buf, this->data_size);
|
||||
img_file.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::export_data(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv = nullptr;
|
||||
|
||||
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");
|
||||
fconv = new DiskCopy42Img(img_path);
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown image format - assume RAW");
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
delete fconv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fconv;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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 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);
|
||||
};
|
||||
|
||||
/** Converter for Disk Copy 4.2 images. */
|
||||
class DiskCopy42Img : public FloppyImgConverter {
|
||||
public:
|
||||
DiskCopy42Img(std::string& file_path);
|
||||
~DiskCopy42Img() = 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,375 @@
|
||||
/*
|
||||
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 <core/timermanager.h>
|
||||
#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->eject_latch = 0; // eject latch is off
|
||||
|
||||
this->reset_params();
|
||||
}
|
||||
|
||||
void MacSuperDrive::reset_params()
|
||||
{
|
||||
this->media_kind = MediaKind::high_density;
|
||||
this->has_disk = 0; // drive is empty
|
||||
this->motor_stat = 0; // spindle motor is off
|
||||
this->motor_on_time = 0;
|
||||
this->cur_track = 0; // current head position
|
||||
this->is_ready = 0; // drive not ready
|
||||
|
||||
// come up in the MFM mode by default
|
||||
this->switch_drive_mode(RecMethod::MFM);
|
||||
}
|
||||
|
||||
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->motor_on_time = TimerManager::get_instance()->current_time_ns();
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
this->init_track_search(-1);
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
} else {
|
||||
this->motor_on_time = 0;
|
||||
this->is_ready = 0;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Eject_Disk:
|
||||
if (value) {
|
||||
LOG_F(INFO, "Superdrive: disk ejected");
|
||||
this->eject_latch = 1;
|
||||
this->reset_params();
|
||||
}
|
||||
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:
|
||||
return this->cur_head = 0;
|
||||
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:
|
||||
return this->cur_head = 1;
|
||||
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, int 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;
|
||||
}
|
||||
|
||||
// set up disk timing parameters
|
||||
this->index_delay = MFM_INDX_MARK_DELAY;
|
||||
this->addr_mark_delay = MFM_ADR_MARK_DELAY;
|
||||
|
||||
if (this->media_kind) {
|
||||
this->sector_delay = MFM_HD_SECTOR_DELAY;
|
||||
this->eot_delay = MFM_HD_EOT_DELAY;
|
||||
} else {
|
||||
this->sector_delay = MFM_DD_SECTOR_DELAY;
|
||||
this->eot_delay = MFM_DD_EOT_DELAY;
|
||||
}
|
||||
|
||||
this->drive_mode = RecMethod::MFM;
|
||||
}
|
||||
}
|
||||
|
||||
double MacSuperDrive::get_current_track_delay()
|
||||
{
|
||||
return 60.0f / this->rpm_per_track[this->cur_track];
|
||||
}
|
||||
|
||||
void MacSuperDrive::init_track_search(int pos)
|
||||
{
|
||||
if (pos == -1) {
|
||||
// pick random sector number
|
||||
uint64_t seed = TimerManager::get_instance()->current_time_ns() >> 8;
|
||||
this->cur_sector = seed % this->sectors_per_track[this->cur_track];
|
||||
LOG_F(9, "Superdrive: current sector number set to %d", this->cur_sector);
|
||||
} else {
|
||||
this->cur_sector = pos;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::sync_to_disk()
|
||||
{
|
||||
uint64_t cur_time_ns, track_time_ns;
|
||||
|
||||
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
|
||||
|
||||
// look how much ns have been elapsed since the last motor enabling
|
||||
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
|
||||
|
||||
if (!this->track_start_time ||
|
||||
(cur_time_ns - this->track_start_time) >= track_delay) {
|
||||
// subtract full disk revolutions
|
||||
track_time_ns = cur_time_ns % track_delay;
|
||||
|
||||
this->track_start_time = cur_time_ns - track_time_ns;
|
||||
|
||||
// return delay until the first address mark if we're currently
|
||||
// looking at the end of track
|
||||
if (track_time_ns >= this->eot_delay) {
|
||||
this->next_sector = 0;
|
||||
// CHEAT: don't account for the remaining time of the current track
|
||||
return this->index_delay + this->addr_mark_delay;
|
||||
}
|
||||
|
||||
// return delay until the first address mark
|
||||
// if the first address mark was not reached yet
|
||||
if (track_time_ns < this->index_delay) {
|
||||
this->next_sector = 0;
|
||||
return this->index_delay + this->addr_mark_delay - track_time_ns;
|
||||
}
|
||||
} else {
|
||||
track_time_ns = cur_time_ns - this->track_start_time;
|
||||
}
|
||||
|
||||
// subtract index field delay
|
||||
track_time_ns -= this->index_delay;
|
||||
|
||||
// calculate current sector number from timestamp
|
||||
int cur_sect_num = this->cur_sector = (int)(track_time_ns / this->sector_delay);
|
||||
|
||||
this->sector_start_time = this->track_start_time + cur_sect_num * this->sector_delay +
|
||||
this->index_delay;
|
||||
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
uint64_t diff = track_delay - (cur_time_ns - this->track_start_time);
|
||||
this->next_sector = 0;
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
return diff + this->index_delay + this->addr_mark_delay;
|
||||
} else {
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
uint64_t diff = cur_time_ns - this->sector_start_time;
|
||||
this->sector_start_time += this->sector_delay;
|
||||
return this->sector_delay - diff + this->addr_mark_delay;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::next_addr_mark_delay(uint8_t *next_sect_num)
|
||||
{
|
||||
uint64_t delay;
|
||||
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
this->next_sector = 0;
|
||||
delay = this->index_delay + this->addr_mark_delay;
|
||||
} else {
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
delay = this->addr_mark_delay;
|
||||
}
|
||||
|
||||
if (next_sect_num) {
|
||||
*next_sect_num = this->next_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
|
||||
}
|
||||
|
||||
return delay;
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::next_sector_delay()
|
||||
{
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
this->next_sector = 0;
|
||||
return this->sector_delay + this->index_delay + this->addr_mark_delay;
|
||||
}
|
||||
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
|
||||
return this->sector_delay - this->addr_mark_delay;
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::sector_data_delay()
|
||||
{
|
||||
return MFM_SECT_DATA_DELAY;
|
||||
}
|
||||
|
||||
SectorHdr MacSuperDrive::current_sector_header()
|
||||
{
|
||||
this->cur_sector = this->next_sector;
|
||||
|
||||
// MFM sector numbering is 1-based so we need to bump sector number
|
||||
uint8_t 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,162 @@
|
||||
/*
|
||||
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 <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// convert number of bytes to disk time = nbytes * bits_per_byte * 2 us
|
||||
#define MFM_BYTES_TO_DISK_TIME(bytes) USECS_TO_NSECS((bytes) * 8 * 2)
|
||||
|
||||
// timing constans for MFM disks
|
||||
constexpr uint32_t MFM_INDX_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(146);
|
||||
constexpr uint32_t MFM_ADR_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(22);
|
||||
constexpr uint32_t MFM_SECT_DATA_DELAY = MFM_BYTES_TO_DISK_TIME(514);
|
||||
constexpr uint32_t MFM_DD_SECTOR_DELAY = MFM_BYTES_TO_DISK_TIME(658);
|
||||
constexpr uint32_t MFM_HD_SECTOR_DELAY = MFM_BYTES_TO_DISK_TIME(675);
|
||||
|
||||
constexpr uint32_t MFM_DD_EOT_DELAY = MFM_BYTES_TO_DISK_TIME( 6250 - 182);
|
||||
constexpr uint32_t MFM_HD_EOT_DELAY = MFM_BYTES_TO_DISK_TIME(12500 - 204);
|
||||
|
||||
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,
|
||||
Eject_Disk = 3,
|
||||
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, int write_flag);
|
||||
void init_track_search(int pos);
|
||||
uint64_t sync_to_disk();
|
||||
uint64_t next_addr_mark_delay(uint8_t *next_sect_num);
|
||||
uint64_t next_sector_delay();
|
||||
SectorHdr current_sector_header();
|
||||
char* get_sector_data_ptr(int sector_num);
|
||||
uint64_t sector_data_delay();
|
||||
|
||||
double get_current_track_delay();
|
||||
double get_address_mark_delay();
|
||||
|
||||
protected:
|
||||
void reset_params();
|
||||
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
|
||||
int next_sector; // next sector number
|
||||
|
||||
uint64_t motor_on_time = 0; // time in ns the spindle motor was switched on
|
||||
uint64_t track_start_time = 0;
|
||||
uint64_t sector_start_time = 0;
|
||||
|
||||
// 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
|
||||
|
||||
// timing parameters for MFM disks
|
||||
uint32_t index_delay; // number of ns needed to read the index mark
|
||||
uint32_t addr_mark_delay; // number of ns needed to read an address index mark
|
||||
uint32_t sector_delay; // number of ns needed to read a sector
|
||||
uint32_t eot_delay; // number of ns until end of track gap
|
||||
|
||||
std::unique_ptr<FloppyImgConverter> img_conv;
|
||||
|
||||
std::unique_ptr<char[]> disk_data;
|
||||
};
|
||||
|
||||
}; // namespace MacSuperdrive
|
||||
|
||||
#endif // MAC_SUPERDRIVE_H
|
||||
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
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/deviceregistry.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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->step_count = 0;
|
||||
this->xfer_cnt = 0;
|
||||
this->first_sec = 0xFF;
|
||||
|
||||
this->cur_state = SWIM3_IDLE;
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// if a floppy image was given "insert" it into the virtual superdrive
|
||||
std::string fd_image_path = GET_STR_PROP("fdd_img");
|
||||
int fd_write_prot = GET_BIN_PROP("fdd_wr_prot");
|
||||
if (!fd_image_path.empty()) {
|
||||
this->int_drive->insert_disk(fd_image_path, fd_write_prot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status_addr, rddata_val, old_int_flags, old_error;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Timer:
|
||||
return this->calc_timer_val();
|
||||
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);
|
||||
rddata_val = this->int_drive->status(status_addr) & 1;
|
||||
|
||||
// transfer rddata_val to both bit 2 (RDDATA) and bit 3 (SENSE)
|
||||
// because those signals seem to be historically wired together
|
||||
return (rddata_val << 2) | (rddata_val << 3);
|
||||
}
|
||||
return 0xC; // report both RdData & Sense high
|
||||
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::Step:
|
||||
return this->step_count;
|
||||
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 status_addr;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Timer:
|
||||
this->init_timer(value);
|
||||
break;
|
||||
case Swim3Reg::Param_Data:
|
||||
this->pram = value;
|
||||
break;
|
||||
case Swim3Reg::Phase:
|
||||
this->phase_lines = value & 0xF;
|
||||
if (this->phase_lines & 8) { // CA3 aka LSTRB high -> sending a command to the drive
|
||||
if (this->mode_reg & 2) { // if internal drive is selected
|
||||
this->int_drive->command(
|
||||
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
|
||||
(value >> 2) & 1
|
||||
);
|
||||
}
|
||||
} else if (this->phase_lines == 4 && (this->mode_reg & 2)) {
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
this->rd_line = this->int_drive->status(status_addr) & 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!");
|
||||
|
||||
this->target_sect = this->first_sec;
|
||||
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->int_drive->sync_to_disk(),
|
||||
[this]() {
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Swim3Ctrl::disk_access()
|
||||
{
|
||||
MacSuperdrive::SectorHdr hdr;
|
||||
uint64_t delay;
|
||||
|
||||
switch(this->cur_state) {
|
||||
case SWIM3_ADDR_MARK_SEARCH:
|
||||
hdr = this->int_drive->current_sector_header();
|
||||
// update the corresponding SWIM3 registers
|
||||
this->cur_track = ((hdr.side & 1) << 7) | (hdr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (hdr.sector & 0x7F);
|
||||
this->format = hdr.format;
|
||||
// generate ID_read interrupt
|
||||
this->int_flags |= INT_ID_READ;
|
||||
update_irq();
|
||||
if ((this->cur_sector & 0x7F) == this->target_sect) {
|
||||
// sector matches -> transfer its data
|
||||
this->cur_state = SWIM3_DATA_XFER;
|
||||
delay = this->int_drive->sector_data_delay();
|
||||
} else {
|
||||
// move to next address mark
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
delay = this->int_drive->next_sector_delay();
|
||||
}
|
||||
break;
|
||||
case SWIM3_DATA_XFER:
|
||||
// transfer sector data over DMA
|
||||
this->dma_ch->push_data(this->int_drive->get_sector_data_ptr(this->cur_sector & 0x7F), 512);
|
||||
if (--this->xfer_cnt == 0) {
|
||||
this->stop_disk_access();
|
||||
// generate sector_done interrupt
|
||||
this->int_flags |= INT_SECT_DONE;
|
||||
update_irq();
|
||||
return;
|
||||
}
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
delay = this->int_drive->next_addr_mark_delay(&this->target_sect);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "SWIM3: unknown disk access phase 0x%X", this->cur_state);
|
||||
return;
|
||||
}
|
||||
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay,
|
||||
[this]() {
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
{
|
||||
if (this->timer_val) {
|
||||
LOG_F(WARNING, "SWIM3: attempt to re-arm the timer");
|
||||
}
|
||||
this->timer_val = start_val;
|
||||
if (!this->timer_val) {
|
||||
this->one_us_timer_start = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
|
||||
|
||||
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->timer_val * NS_PER_USEC,
|
||||
[this]() {
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
update_irq();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
uint8_t Swim3Ctrl::calc_timer_val()
|
||||
{
|
||||
if (!this->timer_val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t time_now = TimerManager::get_instance()->current_time_ns();
|
||||
uint64_t us_elapsed = (time_now - this->one_us_timer_start) / NS_PER_USEC;
|
||||
if (us_elapsed > this->timer_val) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this->timer_val - us_elapsed) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
// floppy disk formats properties for the cases
|
||||
// where disk format needs to be specified manually
|
||||
static const std::vector<std::string> FloppyFormats = {
|
||||
"", "GCR_400K", "GCR_800K", "MFM_720K", "MFM_1440K"
|
||||
};
|
||||
|
||||
static const PropMap Swim3_Properties = {
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new BinProperty(0)},
|
||||
{"fdd_fmt",
|
||||
new StrProperty("", FloppyFormats)},
|
||||
};
|
||||
|
||||
static const DeviceDescription Swim3_Descriptor = {
|
||||
Swim3Ctrl::create, {}, Swim3_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Swim3, Swim3_Descriptor);
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
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_TIMER_DONE = 0x01,
|
||||
INT_STEP_DONE = 0x02,
|
||||
INT_ID_READ = 0x04,
|
||||
INT_SECT_DONE = 0x08,
|
||||
};
|
||||
|
||||
// SWIM3 internal states.
|
||||
enum {
|
||||
SWIM3_IDLE,
|
||||
SWIM3_ADDR_MARK_SEARCH,
|
||||
SWIM3_DATA_XFER,
|
||||
};
|
||||
|
||||
class Swim3Ctrl : public HWComponent {
|
||||
public:
|
||||
Swim3Ctrl();
|
||||
~Swim3Ctrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Swim3Ctrl>(new Swim3Ctrl());
|
||||
}
|
||||
|
||||
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 disk_access();
|
||||
void stop_disk_access();
|
||||
void init_timer(const uint8_t start_val);
|
||||
uint8_t calc_timer_val();
|
||||
|
||||
private:
|
||||
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
|
||||
|
||||
DmaBidirChannel* dma_ch;
|
||||
|
||||
uint8_t timer_val = 0; // internal timer that decrements at a 1 us rate
|
||||
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 target_sect;
|
||||
uint8_t format; // format byte from the last GCR/MFM address field
|
||||
uint8_t first_sec;
|
||||
uint8_t xfer_cnt;
|
||||
uint8_t gap_size;
|
||||
uint8_t rd_line;
|
||||
int cur_state;
|
||||
|
||||
int one_us_timer_id = 0;
|
||||
int step_timer_id = 0;
|
||||
int access_timer_id = 0;
|
||||
|
||||
uint64_t one_us_timer_start = 0;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
};
|
||||
|
||||
}; // namespace Swim3
|
||||
|
||||
#endif // SWIM3_H
|
||||
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "macio.h"
|
||||
#include "viacuda.h"
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
this->nvram = new NVram();
|
||||
|
||||
this->viacuda = new ViaCuda();
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||
|
||||
this->screamer = new AWACDevice();
|
||||
this->snd_out_dma = new DMAChannel(this->screamer);
|
||||
this->screamer->set_dma_out(this->snd_out_dma);
|
||||
}
|
||||
|
||||
HeathrowIC::~HeathrowIC() {
|
||||
if (this->nvram)
|
||||
delete (this->nvram);
|
||||
|
||||
if (this->viacuda)
|
||||
delete (this->viacuda);
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
|
||||
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
switch (reg_offs) {
|
||||
case CFG_REG_BAR0: // base address register
|
||||
value = LE2BE(value);
|
||||
if (value == 0xFFFFFFFF) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: BAR0 block size determination not \
|
||||
implemented yet \n",
|
||||
this->name.c_str());
|
||||
} else if (value & 1) {
|
||||
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
||||
} else if (value & 0x06) {
|
||||
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
||||
} else {
|
||||
this->base_addr = value & 0xFFF80000;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
res = mio_ctrl_read(offset, size);
|
||||
break;
|
||||
case 8:
|
||||
res = dma_read(offset - 0x8000, size);
|
||||
break;
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
res = this->viacuda->read((offset - 0x16000) >> 9);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
mio_ctrl_write(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
dma_write(offset - 0x8000, value, size);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->int_clear2;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->int_levels2;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->int_clear1;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
res = 0xF0700000UL;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
this->int_mask2 = value;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
this->int_clear2 = value;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
this->int_levels2 = value;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->int_mask1 = value;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
this->int_levels1 = value;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
this->feat_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 361 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user